commit
42c2e0f68a
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@ -0,0 +1 @@
|
||||
*.html linguist-detectable=false
|
118
.github/workflows/build.yml
vendored
Normal file
118
.github/workflows/build.yml
vendored
Normal file
@ -0,0 +1,118 @@
|
||||
name: Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "*"
|
||||
pull_request:
|
||||
branches:
|
||||
- "*"
|
||||
types: [opened, synchronize, reopened]
|
||||
jobs:
|
||||
build:
|
||||
name: Build binaries
|
||||
runs-on: windows-2022
|
||||
strategy:
|
||||
matrix:
|
||||
configuration:
|
||||
- Debug
|
||||
- Release
|
||||
steps:
|
||||
- name: Wait for previous workflows
|
||||
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop')
|
||||
uses: softprops/turnstyle@v1
|
||||
with:
|
||||
poll-interval-seconds: 10
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Set up git config
|
||||
run: git config --global url."https://".insteadOf git://
|
||||
|
||||
- name: Check out files
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
submodules: true
|
||||
fetch-depth: 0
|
||||
# NOTE - If LFS ever starts getting used during builds, switch this to true!
|
||||
lfs: false
|
||||
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/setup-msbuild@v1.0.2
|
||||
|
||||
- name: Generate project files
|
||||
#run: tools/premake5 vs2022 --ci-build
|
||||
run: tools/premake5 vs2022
|
||||
|
||||
- name: Set up problem matching
|
||||
uses: ammaraskar/msvc-problem-matcher@master
|
||||
|
||||
- name: Build ${{matrix.configuration}} binaries
|
||||
run: msbuild /m /v:minimal /p:Configuration=${{matrix.configuration}} /p:Platform=x64 build/h1-mod.sln
|
||||
|
||||
- name: Upload ${{matrix.configuration}} binaries
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: ${{matrix.configuration}} binaries
|
||||
path: |
|
||||
build/bin/x64/${{matrix.configuration}}/h1-mod.exe
|
||||
build/bin/x64/${{matrix.configuration}}/h1-mod.pdb
|
||||
|
||||
- name: Upload ${{matrix.configuration}} data artifacts
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: ${{matrix.configuration}} data artifacts
|
||||
path: |
|
||||
data/*
|
||||
deploy:
|
||||
name: Deploy artifacts
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop')
|
||||
steps:
|
||||
- name: Setup main environment
|
||||
if: github.ref == 'refs/heads/main'
|
||||
run: echo "H1_MOD_MASTER_PATH=${{ secrets.H1_MOD_MASTER_SSH_PATH }}" >> $GITHUB_ENV
|
||||
|
||||
- name: Setup develop environment
|
||||
if: github.ref == 'refs/heads/develop'
|
||||
run: echo "H1_MOD_MASTER_PATH=${{ secrets.H1_MOD_MASTER_SSH_PATH_DEV }}" >> $GITHUB_ENV
|
||||
|
||||
- name: Download Release binaries
|
||||
uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: Release binaries
|
||||
|
||||
- name: Download Release data artifacts
|
||||
uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: Release data artifacts
|
||||
path: data
|
||||
|
||||
- name: Install SSH key
|
||||
uses: shimataro/ssh-key-action@v2
|
||||
with:
|
||||
key: ${{ secrets.H1_MOD_MASTER_SSH_PRIVATE_KEY }}
|
||||
known_hosts: 'just-a-placeholder-so-we-dont-get-errors'
|
||||
|
||||
- name: Add known hosts
|
||||
run: ssh-keyscan -H ${{ secrets.H1_MOD_MASTER_SSH_ADDRESS }} >> ~/.ssh/known_hosts
|
||||
|
||||
- name: Wait for previous workflows
|
||||
uses: softprops/turnstyle@v1
|
||||
with:
|
||||
poll-interval-seconds: 10
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Remove old data files
|
||||
run: ssh ${{ secrets.H1_MOD_MASTER_SSH_USER }}@${{ secrets.H1_MOD_MASTER_SSH_ADDRESS }} rm -rf ${{ env.H1_MOD_MASTER_PATH }}/h1-mod/data/*
|
||||
|
||||
- name: Upload h1-mod binary
|
||||
run: rsync -avz h1-mod.exe ${{ secrets.H1_MOD_MASTER_SSH_USER }}@${{ secrets.H1_MOD_MASTER_SSH_ADDRESS }}:${{ env.H1_MOD_MASTER_PATH }}/h1-mod/
|
||||
|
||||
- name: Upload data files
|
||||
run: rsync -avz ./data/ ${{ secrets.H1_MOD_MASTER_SSH_USER }}@${{ secrets.H1_MOD_MASTER_SSH_ADDRESS }}:${{ env.H1_MOD_MASTER_PATH }}/h1-mod/data/
|
||||
|
||||
- name: Publish changes
|
||||
run: ssh ${{ secrets.H1_MOD_MASTER_SSH_USER }}@${{ secrets.H1_MOD_MASTER_SSH_ADDRESS }} ${{ secrets.H1_MOD_MASTER_SSH_CHANGE_PUBLISH_COMMAND }}
|
15
.gitmodules
vendored
15
.gitmodules
vendored
@ -28,19 +28,20 @@
|
||||
[submodule "deps/stb"]
|
||||
path = deps/stb
|
||||
url = https://github.com/nothings/stb.git
|
||||
branch = develop
|
||||
[submodule "deps/libtomcrypt"]
|
||||
path = deps/libtomcrypt
|
||||
url = git://github.com/libtom/libtomcrypt.git
|
||||
branch = develop
|
||||
[submodule "deps/zlib"]
|
||||
path = deps/zlib
|
||||
url = git://github.com/madler/zlib.git
|
||||
url = https://github.com/libtom/libtomcrypt.git
|
||||
branch = develop
|
||||
[submodule "deps/libtommath"]
|
||||
path = deps/libtommath
|
||||
url = git://github.com/libtom/libtommath.git
|
||||
url = https://github.com/libtom/libtommath.git
|
||||
branch = develop
|
||||
[submodule "deps/protobuf"]
|
||||
path = deps/protobuf
|
||||
url = git://github.com/protocolbuffers/protobuf.git
|
||||
url = https://github.com/protocolbuffers/protobuf.git
|
||||
branch = 3.17.x
|
||||
[submodule "deps/zlib"]
|
||||
path = deps/zlib
|
||||
url = https://github.com/madler/zlib.git
|
||||
branch = develop
|
||||
|
674
LICENSE
Normal file
674
LICENSE
Normal file
@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
26
README.md
26
README.md
@ -1,13 +1,18 @@
|
||||
# H1-Mod 1.4
|
||||

|
||||
[](https://github.com/h1-mod/h1-mod/issues?q=is%3Aissue+is%3Aopen+label%3Abug)
|
||||
[](https://github.com/h1-mod/h1-mod/actions)
|
||||
[](https://ci.appveyor.com/project/h1-mod/h1-mod)
|
||||
[](https://discord.gg/RzzXu5EVnh)
|
||||
|
||||
- *Note: Multiplayer support is in progress!*
|
||||
# H1-Mod
|
||||
|
||||
<p align="center">
|
||||
<img alig src="https://cdn.discordapp.com/attachments/895680402142941194/938488726391242842/splash.png"/>
|
||||
<img src="assets/github/banner.png?raw=true" />
|
||||
</p>
|
||||
|
||||
Proof of concept for an Modern Warfare Remastered client. <br>
|
||||
[This project is based on S1x](https://github.com/XLabsProject/s1x-client)
|
||||
A client for Call of Duty: Modern Warfare Remastered.
|
||||
|
||||
[This project is based on S1x.](https://github.com/XLabsProject/s1x-client)
|
||||
|
||||
## Compile from source
|
||||
|
||||
@ -24,11 +29,12 @@ Proof of concept for an Modern Warfare Remastered client. <br>
|
||||
|
||||
## Credits:
|
||||
|
||||
- [XLabsProject - S1x](https://github.com/XLabsProject/s1x-client), Project base.
|
||||
- [quaK](https://github.com/Joelrau), Helping in alot of stuff.
|
||||
- [fed - h2-mod](https://github.com/fedddddd/h2-mod), [Dvars](https://github.com/skkuull/h1-mod/blob/main/src/client/game/dvars.cpp) and [patches](https://github.com/skkuull/h1-mod/blob/main/src/client/component/patches.cpp).
|
||||
|
||||
- [XLabsProject](https://github.com/XLabsProject) - codebase and iw6x/s1x research
|
||||
- [quaK](https://github.com/Joelrau) - lots of insight and help
|
||||
- [fed](https://github.com/fedddddd) - fixed DW/networking, work from [h2-mod](https://github.com/fedddddd/h2-mod)
|
||||
- [Skull](https://github.com/skkuull) + [mjkzy](https://github.com/mjkzy) - porting code from s1x
|
||||
- [momo5502](https://github.com/momo5502) - Arxan/Steam research, developer of XLabsProject :D
|
||||
|
||||
## Disclaimer
|
||||
|
||||
This software has been made for learning purposes.
|
||||
This software has been created purely for the purposes of academic research. It is not intended to be used to attack other systems. Project maintainers are not responsible or liable for misuse of the software. Use responsibly.
|
||||
|
BIN
assets/github/banner.png
Normal file
BIN
assets/github/banner.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 742 KiB |
0
data/.gitkeep
Normal file
0
data/.gitkeep
Normal file
272
data/ui_scripts/discord/__init__.lua
Normal file
272
data/ui_scripts/discord/__init__.lua
Normal file
@ -0,0 +1,272 @@
|
||||
if (game:issingleplayer() or Engine.InFrontend()) then
|
||||
return
|
||||
end
|
||||
|
||||
local container = LUI.UIVerticalList.new({
|
||||
topAnchor = true,
|
||||
rightAnchor = true,
|
||||
top = 20,
|
||||
right = 200,
|
||||
width = 200,
|
||||
spacing = 5,
|
||||
})
|
||||
|
||||
function canasktojoin(userid)
|
||||
history = history or {}
|
||||
if (history[userid] ~= nil) then
|
||||
return false
|
||||
end
|
||||
|
||||
history[userid] = true
|
||||
game:ontimeout(function()
|
||||
history[userid] = nil
|
||||
end, 15000)
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function truncatename(name, length)
|
||||
if (#name <= length - 3) then
|
||||
return name
|
||||
end
|
||||
|
||||
return name:sub(1, length - 3) .. "..."
|
||||
end
|
||||
|
||||
function addrequest(request)
|
||||
if (not canasktojoin(request.userid)) then
|
||||
return
|
||||
end
|
||||
|
||||
if (container.temp) then
|
||||
container:removeElement(container.temp)
|
||||
container.temp = nil
|
||||
end
|
||||
|
||||
local invite = LUI.UIElement.new({
|
||||
leftAnchor = true,
|
||||
rightAnchor = true,
|
||||
height = 75,
|
||||
})
|
||||
|
||||
invite:registerAnimationState("move_in", {
|
||||
leftAnchor = true,
|
||||
height = 75,
|
||||
width = 200,
|
||||
left = -220,
|
||||
})
|
||||
|
||||
invite:animateToState("move_in", 100)
|
||||
|
||||
local background = LUI.UIImage.new({
|
||||
topAnchor = true,
|
||||
leftAnchor = true,
|
||||
rightAnchor = true,
|
||||
bottomAnchor = true,
|
||||
top = 1,
|
||||
left = 1,
|
||||
bottom = -1,
|
||||
right = -1,
|
||||
material = RegisterMaterial("white"),
|
||||
color = {
|
||||
r = 0,
|
||||
b = 0,
|
||||
g = 0,
|
||||
},
|
||||
alpha = 0.6,
|
||||
})
|
||||
|
||||
local border = LUI.UIImage.new({
|
||||
topAnchor = true,
|
||||
leftAnchor = true,
|
||||
rightAnchor = true,
|
||||
bottomAnchor = true,
|
||||
material = RegisterMaterial("btn_focused_rect_innerglow"),
|
||||
})
|
||||
|
||||
border:setup9SliceImage(10, 5, 0.25, 0.12)
|
||||
|
||||
local paddingvalue = 10
|
||||
local padding = LUI.UIElement.new({
|
||||
topAnchor = true,
|
||||
leftAnchor = true,
|
||||
rightAnchor = true,
|
||||
bottomAnchor = true,
|
||||
top = paddingvalue,
|
||||
left = paddingvalue,
|
||||
right = -paddingvalue,
|
||||
bottom = -paddingvalue,
|
||||
})
|
||||
|
||||
local avatarmaterial = discord.getavatarmaterial(request.userid)
|
||||
local avatar = LUI.UIImage.new({
|
||||
leftAnchor = true,
|
||||
topAnchor = true,
|
||||
width = 32,
|
||||
height = 32,
|
||||
left = 1,
|
||||
material = RegisterMaterial(avatarmaterial)
|
||||
})
|
||||
|
||||
local username = LUI.UIText.new({
|
||||
leftAnchor = true,
|
||||
topAnchor = true,
|
||||
height = 12,
|
||||
left = 32 + paddingvalue,
|
||||
color = Colors.white,
|
||||
alignment = LUI.Alignment.Left,
|
||||
rightAnchor = true,
|
||||
font = CoD.TextSettings.BodyFontBold.Font
|
||||
})
|
||||
|
||||
username:setText(string.format("%s^7#%s requested to join your game!",
|
||||
truncatename(request.username, 18), request.discriminator))
|
||||
|
||||
local buttons = LUI.UIElement.new({
|
||||
leftAnchor = true,
|
||||
rightAnchor = true,
|
||||
topAnchor = true,
|
||||
top = 37,
|
||||
height = 18,
|
||||
})
|
||||
|
||||
local createbutton = function(text, left)
|
||||
local button = LUI.UIElement.new({
|
||||
leftAnchor = left,
|
||||
rightAnchor = not left,
|
||||
topAnchor = true,
|
||||
height = 18,
|
||||
width = 85,
|
||||
material = RegisterMaterial("btn_focused_rect_innerglow"),
|
||||
})
|
||||
|
||||
local center = LUI.UIText.new({
|
||||
rightAnchor = true,
|
||||
height = 12,
|
||||
width = 85,
|
||||
top = -6.5,
|
||||
alignment = LUI.Alignment.Center,
|
||||
font = CoD.TextSettings.BodyFontBold.Font
|
||||
})
|
||||
|
||||
button:setup9SliceImage(10, 5, 0.25, 0.12)
|
||||
center:setText(text)
|
||||
button:addElement(center)
|
||||
|
||||
return button
|
||||
end
|
||||
|
||||
buttons:addElement(createbutton("[F1] Accept", true))
|
||||
buttons:addElement(createbutton("[F2] Deny"))
|
||||
|
||||
local fadeouttime = 50
|
||||
local timeout = 10 * 1000 - fadeouttime
|
||||
|
||||
local function close()
|
||||
container:processEvent({
|
||||
name = "update_navigation",
|
||||
dispatchToChildren = true
|
||||
})
|
||||
invite:animateToState("fade_out", fadeouttime)
|
||||
invite:addElement(LUI.UITimer.new(fadeouttime + 50, "remove"))
|
||||
|
||||
invite:registerEventHandler("remove", function()
|
||||
container:removeElement(invite)
|
||||
if (container.temp) then
|
||||
container:removeElement(container.temp)
|
||||
container.temp = nil
|
||||
end
|
||||
local temp = LUI.UIElement.new({})
|
||||
container.temp = temp
|
||||
container:addElement(temp)
|
||||
end)
|
||||
end
|
||||
|
||||
buttons:registerEventHandler("keydown_", function(element, event)
|
||||
if (event.key == "F1") then
|
||||
close()
|
||||
discord.respond(request.userid, discord.reply.yes)
|
||||
end
|
||||
|
||||
if (event.key == "F2") then
|
||||
close()
|
||||
discord.respond(request.userid, discord.reply.no)
|
||||
end
|
||||
end)
|
||||
|
||||
invite:registerAnimationState("fade_out", {
|
||||
leftAnchor = true,
|
||||
rightAnchor = true,
|
||||
height = 75,
|
||||
alpha = 0,
|
||||
left = 0
|
||||
})
|
||||
|
||||
invite:addElement(LUI.UITimer.new(timeout, "end_invite"))
|
||||
invite:registerEventHandler("end_invite", function()
|
||||
close()
|
||||
discord.respond(request.userid, discord.reply.ignore)
|
||||
end)
|
||||
|
||||
local bar = LUI.UIImage.new({
|
||||
bottomAnchor = true,
|
||||
leftAnchor = true,
|
||||
bottom = -3,
|
||||
left = 3,
|
||||
width = 200 - 6,
|
||||
material = RegisterMaterial("white"),
|
||||
height = 2,
|
||||
color = {
|
||||
r = 92 / 255,
|
||||
g = 206 / 255,
|
||||
b = 113 / 255,
|
||||
}
|
||||
})
|
||||
|
||||
bar:registerAnimationState("closing", {
|
||||
bottomAnchor = true,
|
||||
leftAnchor = true,
|
||||
bottom = -3,
|
||||
left = 3,
|
||||
width = 0,
|
||||
height = 2,
|
||||
})
|
||||
|
||||
bar:animateToState("closing", timeout)
|
||||
|
||||
avatar:registerEventHandler("update", function()
|
||||
local avatarmaterial = discord.getavatarmaterial(request.userid)
|
||||
avatar:setImage(RegisterMaterial(avatarmaterial))
|
||||
end)
|
||||
|
||||
avatar:addElement(LUI.UITimer.new(100, "update"))
|
||||
|
||||
invite:addElement(background)
|
||||
invite:addElement(bar)
|
||||
invite:addElement(border)
|
||||
invite:addElement(padding)
|
||||
padding:addElement(username)
|
||||
padding:addElement(avatar)
|
||||
padding:addElement(buttons)
|
||||
|
||||
container:addElement(invite)
|
||||
end
|
||||
|
||||
container:registerEventHandler("keydown", function(element, event)
|
||||
local first = container:getFirstChild()
|
||||
|
||||
if (not first) then
|
||||
return
|
||||
end
|
||||
|
||||
first:processEvent({
|
||||
name = "keydown_",
|
||||
key = event.key
|
||||
})
|
||||
end)
|
||||
|
||||
LUI.roots.UIRoot0:registerEventHandler("discord_join_request", function(element, event)
|
||||
addrequest(event.request)
|
||||
end)
|
||||
|
||||
LUI.roots.UIRoot0:addElement(container)
|
11
data/ui_scripts/extra_gamemodes/__init__.lua
Normal file
11
data/ui_scripts/extra_gamemodes/__init__.lua
Normal file
@ -0,0 +1,11 @@
|
||||
Cac.GameModes.Data = {
|
||||
Standard = {
|
||||
Label = Engine.Localize("@MPUI_STANDARD_CAPS"),
|
||||
Image = "h1_ui_icon_playlist_standard",
|
||||
List =
|
||||
{
|
||||
"dm", "war", "sd", "dom", "conf", "sab", "koth", "hp", "gun",
|
||||
"dd", "ctf" -- missing gamemodes from UI
|
||||
}
|
||||
}
|
||||
}
|
6
data/ui_scripts/hud_info/__init__.lua
Normal file
6
data/ui_scripts/hud_info/__init__.lua
Normal file
@ -0,0 +1,6 @@
|
||||
if (game:issingleplayer()) then
|
||||
return
|
||||
end
|
||||
|
||||
require("settings")
|
||||
require("hud")
|
198
data/ui_scripts/hud_info/hud.lua
Normal file
198
data/ui_scripts/hud_info/hud.lua
Normal file
@ -0,0 +1,198 @@
|
||||
local mphud = luiglobals.require("LUI.mp_hud.MPHud")
|
||||
local barheight = 16
|
||||
local textheight = 13
|
||||
local textoffsety = barheight / 2 - textheight / 2
|
||||
|
||||
function createinfobar()
|
||||
local infobar = LUI.UIElement.new({
|
||||
left = 213,
|
||||
top = -6,
|
||||
height = barheight,
|
||||
width = 70,
|
||||
leftAnchor = true,
|
||||
topAnchor = true
|
||||
})
|
||||
|
||||
infobar:registerAnimationState("minimap_on", {
|
||||
left = 213,
|
||||
top = -6,
|
||||
height = barheight,
|
||||
width = 70,
|
||||
leftAnchor = true,
|
||||
topAnchor = true
|
||||
})
|
||||
|
||||
infobar:registerAnimationState("minimap_off", {
|
||||
left = 0,
|
||||
top = 0,
|
||||
height = barheight,
|
||||
width = 70,
|
||||
leftAnchor = true,
|
||||
topAnchor = true
|
||||
})
|
||||
|
||||
infobar:registerAnimationState("hud_on", {
|
||||
alpha = 1
|
||||
})
|
||||
|
||||
infobar:registerAnimationState("hud_off", {
|
||||
alpha = 0
|
||||
})
|
||||
|
||||
return infobar
|
||||
end
|
||||
|
||||
function updateinfobarvisibility()
|
||||
local root = Engine.GetLuiRoot()
|
||||
local menus = root:AnyActiveMenusInStack()
|
||||
local infobar = root.infobar
|
||||
|
||||
if (not infobar) then
|
||||
return
|
||||
end
|
||||
|
||||
if (menus or Game.InKillCam()) then
|
||||
infobar:animateToState("hud_off")
|
||||
else
|
||||
infobar:animateToState("hud_on")
|
||||
end
|
||||
|
||||
local validstates = {
|
||||
"hud_on",
|
||||
"active",
|
||||
"nosignal",
|
||||
"scrambled"
|
||||
}
|
||||
|
||||
infobar:animateToState("minimap_off")
|
||||
for i = 1, #validstates do
|
||||
if (validstates[i] == root.hud.minimap.current_state) then
|
||||
infobar:animateToState("minimap_on")
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function populateinfobar(infobar)
|
||||
elementoffset = 0
|
||||
|
||||
if (Engine.GetDvarBool("cg_infobar_fps")) then
|
||||
infobar:addElement(infoelement({
|
||||
label = "FPS: ",
|
||||
getvalue = function()
|
||||
return game:getfps()
|
||||
end,
|
||||
width = 70,
|
||||
interval = 100
|
||||
}))
|
||||
end
|
||||
|
||||
if (Engine.GetDvarBool("cg_infobar_ping")) then
|
||||
infobar:addElement(infoelement({
|
||||
label = "Latency: ",
|
||||
getvalue = function()
|
||||
return game:getping() .. " ms"
|
||||
end,
|
||||
width = 115,
|
||||
interval = 100
|
||||
}))
|
||||
end
|
||||
|
||||
updateinfobarvisibility()
|
||||
end
|
||||
|
||||
function infoelement(data)
|
||||
local container = LUI.UIElement.new({
|
||||
bottomAnchor = true,
|
||||
leftAnchor = true,
|
||||
topAnchor = true,
|
||||
width = data.width,
|
||||
left = elementoffset
|
||||
})
|
||||
|
||||
elementoffset = elementoffset + data.width + 10
|
||||
|
||||
local background = LUI.UIImage.new({
|
||||
bottomAnchor = true,
|
||||
leftAnchor = true,
|
||||
topAnchor = true,
|
||||
rightAnchor = true,
|
||||
material = luiglobals.RegisterMaterial("white"),
|
||||
color = luiglobals.Colors.black,
|
||||
alpha = 0.5
|
||||
})
|
||||
|
||||
local labelfont = CoD.TextSettings.FontBold110
|
||||
|
||||
local label = LUI.UIText.new({
|
||||
left = 5,
|
||||
top = textoffsety,
|
||||
font = labelfont.Font,
|
||||
height = textheight,
|
||||
leftAnchor = true,
|
||||
topAnchor = true,
|
||||
color = {
|
||||
r = 0.8,
|
||||
g = 0.8,
|
||||
b = 0.8
|
||||
}
|
||||
})
|
||||
|
||||
label:setText(data.label)
|
||||
|
||||
local _, _, left = luiglobals.GetTextDimensions(data.label, labelfont.Font, textheight)
|
||||
local value = LUI.UIText.new({
|
||||
left = left + 5,
|
||||
top = textoffsety,
|
||||
font = labelfont.Font,
|
||||
height = textheight,
|
||||
leftAnchor = true,
|
||||
topAnchor = true,
|
||||
color = {
|
||||
r = 0.6,
|
||||
g = 0.6,
|
||||
b = 0.6
|
||||
}
|
||||
})
|
||||
|
||||
value:addElement(LUI.UITimer.new(data.interval, "update"))
|
||||
value:setText(data.getvalue())
|
||||
value:addEventHandler("update", function()
|
||||
value:setText(data.getvalue())
|
||||
end)
|
||||
|
||||
container:addElement(background)
|
||||
container:addElement(label)
|
||||
container:addElement(value)
|
||||
|
||||
return container
|
||||
end
|
||||
|
||||
local updatehudvisibility = mphud.updateHudVisibility
|
||||
mphud.updateHudVisibility = function(a1, a2)
|
||||
updatehudvisibility(a1, a2)
|
||||
updateinfobarvisibility()
|
||||
end
|
||||
|
||||
LUI.onmenuopen("mp_hud", function(hud)
|
||||
if (Engine.InFrontend()) then
|
||||
return
|
||||
end
|
||||
|
||||
local infobar = createinfobar()
|
||||
local root = Engine.GetLuiRoot()
|
||||
root.infobar = infobar
|
||||
root.hud = hud
|
||||
populateinfobar(infobar)
|
||||
|
||||
root:registerEventHandler("update_hud_infobar_settings", function()
|
||||
infobar:removeAllChildren()
|
||||
populateinfobar(infobar)
|
||||
end)
|
||||
|
||||
root:processEvent({
|
||||
name = "update_hud_infobar_settings"
|
||||
})
|
||||
|
||||
hud.static.scalable:addElement(infobar)
|
||||
end)
|
142
data/ui_scripts/hud_info/settings.lua
Normal file
142
data/ui_scripts/hud_info/settings.lua
Normal file
@ -0,0 +1,142 @@
|
||||
local pcdisplay = luiglobals.require("LUI.PCDisplay")
|
||||
|
||||
game:addlocalizedstring("LUA_MENU_FPS", "FPS Counter")
|
||||
game:addlocalizedstring("LUA_MENU_FPS_DESC", "Show FPS Counter.")
|
||||
|
||||
game:addlocalizedstring("LUA_MENU_LATENCY", "Server Latency")
|
||||
game:addlocalizedstring("LUA_MENU_LATENCY_DESC", "Show server latency.")
|
||||
|
||||
game:addlocalizedstring("LUA_MENU_RED_DOT_BRIGHTNESS", "Red dot Brightness")
|
||||
game:addlocalizedstring("LUA_MENU_RED_DOT_BRIGHTNESS_DESC", "Adjust the brightness of red dot reticles.")
|
||||
|
||||
function createdivider(menu, text)
|
||||
local element = LUI.UIElement.new({
|
||||
leftAnchor = true,
|
||||
rightAnchor = true,
|
||||
left = 0,
|
||||
right = 0,
|
||||
topAnchor = true,
|
||||
bottomAnchor = false,
|
||||
top = 0,
|
||||
bottom = 33.33
|
||||
})
|
||||
|
||||
element.scrollingToNext = true
|
||||
element:addElement(LUI.MenuBuilder.BuildRegisteredType("h1_option_menu_titlebar", {
|
||||
title_bar_text = text
|
||||
}))
|
||||
|
||||
menu.list:addElement(element)
|
||||
end
|
||||
|
||||
pcdisplay.CreateOptions = function(menu)
|
||||
LUI.Options.AddButtonOptionVariant(menu, luiglobals.GenericButtonSettings.Variants.Select,
|
||||
"@LUA_MENU_COLORBLIND_FILTER", "@LUA_MENU_COLOR_BLIND_DESC", LUI.Options.GetRenderColorBlindText,
|
||||
LUI.Options.RenderColorBlindToggle, LUI.Options.RenderColorBlindToggle)
|
||||
|
||||
if Engine.IsMultiplayer() and Engine.GetDvarType("cg_paintballFx") == luiglobals.DvarTypeTable.DvarBool then
|
||||
LUI.Options.AddButtonOptionVariant(menu, luiglobals.GenericButtonSettings.Variants.Select,
|
||||
"@LUA_MENU_PAINTBALL", "@LUA_MENU_PAINTBALL_DESC",
|
||||
LUI.Options.GetDvarEnableTextFunc("cg_paintballFx", false), LUI.Options.ToggleDvarFunc("cg_paintballFx"),
|
||||
LUI.Options.ToggleDvarFunc("cg_paintballFx"))
|
||||
end
|
||||
|
||||
LUI.Options.AddButtonOptionVariant(menu, luiglobals.GenericButtonSettings.Variants.Select, "@LUA_MENU_BLOOD",
|
||||
"@LUA_MENU_BLOOD_DESC", LUI.Options.GetDvarEnableTextFunc("cg_blood", false), LUI.Options
|
||||
.ToggleProfiledataFunc("showblood", Engine.GetControllerForLocalClient(0)), LUI.Options
|
||||
.ToggleProfiledataFunc("showblood", Engine.GetControllerForLocalClient(0)))
|
||||
|
||||
if not Engine.IsMultiplayer() then
|
||||
LUI.Options.AddButtonOptionVariant(menu, luiglobals.GenericButtonSettings.Variants.Select,
|
||||
"@LUA_MENU_CROSSHAIR", "@LUA_MENU_CROSSHAIR_DESC",
|
||||
LUI.Options.GetDvarEnableTextFunc("cg_drawCrosshairOption", false),
|
||||
LUI.Options.ToggleDvarFunc("cg_drawCrosshairOption"), LUI.Options.ToggleDvarFunc("cg_drawCrosshairOption"))
|
||||
|
||||
LUI.Options.CreateOptionButton(menu, "cg_drawDamageFeedbackOption", "@LUA_MENU_HIT_MARKER",
|
||||
"@LUA_MENU_HIT_MARKER_DESC", {{
|
||||
text = "@LUA_MENU_ENABLED",
|
||||
value = true
|
||||
}, {
|
||||
text = "@LUA_MENU_DISABLED",
|
||||
value = false
|
||||
}})
|
||||
end
|
||||
|
||||
if Engine.IsMultiplayer() then
|
||||
LUI.Options.AddButtonOptionVariant(menu, luiglobals.GenericButtonSettings.Variants.Select,
|
||||
"@MENU_DISPLAY_KILLSTREAK_COUNTER", "@MENU_DISPLAY_KILLSTREAK_COUNTER_DESC",
|
||||
pcdisplay.GetDisplayKillstreakCounterText, pcdisplay.DisplayKillstreakCounterToggle,
|
||||
pcdisplay.DisplayKillstreakCounterToggle)
|
||||
|
||||
LUI.Options.AddButtonOptionVariant(menu, luiglobals.GenericButtonSettings.Variants.Select,
|
||||
"@MENU_DISPLAY_MEDAL_SPLASHES", "@MENU_DISPLAY_MEDAL_SPLASHES_DESC", pcdisplay.GetDisplayMedalSplashesText,
|
||||
pcdisplay.DisplayMedalSplashesToggle, pcdisplay.DisplayMedalSplashesToggle)
|
||||
|
||||
LUI.Options.AddButtonOptionVariant(menu, luiglobals.GenericButtonSettings.Variants.Select,
|
||||
"@MENU_DISPLAY_WEAPON_EMBLEMS", "@MENU_DISPLAY_WEAPON_EMBLEMS_DESC", pcdisplay.GetDisplayWeaponEmblemsText,
|
||||
pcdisplay.DisplayWeaponEmblemsToggle, pcdisplay.DisplayWeaponEmblemsToggle)
|
||||
end
|
||||
|
||||
LUI.Options.AddButtonOptionVariant(menu, luiglobals.GenericButtonSettings.Variants.Common, "@MENU_BRIGHTNESS",
|
||||
"@MENU_BRIGHTNESS_DESC1", nil, nil, nil, pcdisplay.OpenBrightnessMenu, nil, nil, nil)
|
||||
|
||||
|
||||
local reddotbounds = {
|
||||
step = 0.2,
|
||||
max = 4,
|
||||
min = 0.2
|
||||
}
|
||||
|
||||
LUI.Options.AddButtonOptionVariant(
|
||||
menu,
|
||||
GenericButtonSettings.Variants.Slider,
|
||||
"@LUA_MENU_RED_DOT_BRIGHTNESS",
|
||||
"@LUA_MENU_RED_DOT_BRIGHTNESS_DESC",
|
||||
function()
|
||||
return (Engine.GetDvarFloat( "r_redDotBrightnessScale" ) -
|
||||
reddotbounds.min) / (reddotbounds.max - reddotbounds.min)
|
||||
end,
|
||||
function()
|
||||
Engine.SetDvarFloat("r_redDotBrightnessScale",
|
||||
math.min(reddotbounds.max,
|
||||
math.max(reddotbounds.min, Engine.GetDvarFloat("r_redDotBrightnessScale") - reddotbounds.step))
|
||||
)
|
||||
end,
|
||||
function()
|
||||
Engine.SetDvarFloat("r_redDotBrightnessScale",
|
||||
math.min(reddotbounds.max,
|
||||
math.max(reddotbounds.min, Engine.GetDvarFloat("r_redDotBrightnessScale") + reddotbounds.step))
|
||||
)
|
||||
end
|
||||
)
|
||||
|
||||
createdivider(menu, "TELEMETRY")
|
||||
|
||||
LUI.Options.CreateOptionButton(menu, "cg_infobar_ping", "@LUA_MENU_LATENCY", "@LUA_MENU_LATENCY_DESC", {{
|
||||
text = "@LUA_MENU_ENABLED",
|
||||
value = true
|
||||
}, {
|
||||
text = "@LUA_MENU_DISABLED",
|
||||
value = false
|
||||
}}, nil, nil, function(value)
|
||||
Engine.SetDvarBool("cg_infobar_ping", value)
|
||||
Engine.GetLuiRoot():processEvent({
|
||||
name = "update_hud_infobar_settings"
|
||||
})
|
||||
end)
|
||||
|
||||
LUI.Options.CreateOptionButton(menu, "cg_infobar_fps", "@LUA_MENU_FPS", "@LUA_MENU_FPS_DESC", {{
|
||||
text = "@LUA_MENU_ENABLED",
|
||||
value = true
|
||||
}, {
|
||||
text = "@LUA_MENU_DISABLED",
|
||||
value = false
|
||||
}}, nil, nil, function(value)
|
||||
Engine.SetDvarBool("cg_infobar_fps", value)
|
||||
Engine.GetLuiRoot():processEvent({
|
||||
name = "update_hud_infobar_settings"
|
||||
})
|
||||
end)
|
||||
|
||||
LUI.Options.InitScrollingList(menu.list, nil)
|
||||
end
|
3
data/ui_scripts/mods/__init__.lua
Normal file
3
data/ui_scripts/mods/__init__.lua
Normal file
@ -0,0 +1,3 @@
|
||||
if (game:issingleplayer()) then
|
||||
require("loading")
|
||||
end
|
123
data/ui_scripts/mods/loading.lua
Normal file
123
data/ui_scripts/mods/loading.lua
Normal file
@ -0,0 +1,123 @@
|
||||
game:addlocalizedstring("MENU_MODS", "MODS")
|
||||
game:addlocalizedstring("MENU_MODS_DESC", "Load installed mods.")
|
||||
game:addlocalizedstring("LUA_MENU_MOD_DESC_DEFAULT", "Load &&1.")
|
||||
game:addlocalizedstring("LUA_MENU_MOD_DESC", "&&1\nAuthor: &&2\nVersion: &&3")
|
||||
game:addlocalizedstring("LUA_MENU_LOADED_MOD", "Loaded mod: ^2&&1")
|
||||
game:addlocalizedstring("LUA_MENU_AVAILABLE_MODS", "Available mods")
|
||||
game:addlocalizedstring("LUA_MENU_UNLOAD", "Unload")
|
||||
game:addlocalizedstring("LUA_MENU_UNLOAD_DESC", "Unload the currently loaded mod.")
|
||||
|
||||
function createdivider(menu, text)
|
||||
local element = LUI.UIElement.new({
|
||||
leftAnchor = true,
|
||||
rightAnchor = true,
|
||||
left = 0,
|
||||
right = 0,
|
||||
topAnchor = true,
|
||||
bottomAnchor = false,
|
||||
top = 0,
|
||||
bottom = 33.33
|
||||
})
|
||||
|
||||
element.scrollingToNext = true
|
||||
element:addElement(LUI.MenuBuilder.BuildRegisteredType("h1_option_menu_titlebar", {
|
||||
title_bar_text = Engine.ToUpperCase(text)
|
||||
}))
|
||||
|
||||
element.text = element:getFirstChild():getFirstChild():getNextSibling()
|
||||
|
||||
menu.list:addElement(element)
|
||||
return element
|
||||
end
|
||||
|
||||
function string:truncate(length)
|
||||
if (#self <= length) then
|
||||
return self
|
||||
end
|
||||
|
||||
return self:sub(1, length - 3) .. "..."
|
||||
end
|
||||
|
||||
LUI.addmenubutton("main_campaign", {
|
||||
index = 6,
|
||||
text = "@MENU_MODS",
|
||||
description = Engine.Localize("@MENU_MODS_DESC"),
|
||||
callback = function()
|
||||
LUI.FlowManager.RequestAddMenu(nil, "mods_menu")
|
||||
end
|
||||
})
|
||||
|
||||
function getmodname(path)
|
||||
local name = path
|
||||
game:addlocalizedstring(name, name)
|
||||
game:addlocalizedstring("LUA_MENU_MOD_DESC_DEFAULT", "Load &&1.")
|
||||
local desc = Engine.Localize("LUA_MENU_MOD_DESC_DEFAULT", name)
|
||||
local infofile = path .. "/info.json"
|
||||
|
||||
if (io.fileexists(infofile)) then
|
||||
pcall(function()
|
||||
local data = json.decode(io.readfile(infofile))
|
||||
game:addlocalizedstring(data.description, data.description)
|
||||
game:addlocalizedstring(data.author, data.author)
|
||||
game:addlocalizedstring(data.version, data.version)
|
||||
desc = Engine.Localize("@LUA_MENU_MOD_DESC",
|
||||
data.description, data.author, data.version)
|
||||
name = data.name
|
||||
end)
|
||||
end
|
||||
|
||||
return name, desc
|
||||
end
|
||||
|
||||
LUI.MenuBuilder.registerType("mods_menu", function(a1)
|
||||
local menu = LUI.MenuTemplate.new(a1, {
|
||||
menu_title = "@MENU_MODS",
|
||||
exclusiveController = 0,
|
||||
menu_width = 400,
|
||||
menu_top_indent = LUI.MenuTemplate.spMenuOffset,
|
||||
showTopRightSmallBar = true
|
||||
})
|
||||
|
||||
local modfolder = game:getloadedmod()
|
||||
if (modfolder ~= "") then
|
||||
local name = getmodname(modfolder)
|
||||
createdivider(menu, Engine.Localize("@LUA_MENU_LOADED_MOD", name:truncate(24)))
|
||||
|
||||
menu:AddButton("@LUA_MENU_UNLOAD", function()
|
||||
Engine.Exec("unloadmod")
|
||||
end, nil, true, nil, {
|
||||
desc_text = Engine.Localize("@LUA_MENU_UNLOAD_DESC")
|
||||
})
|
||||
end
|
||||
|
||||
createdivider(menu, Engine.Localize("@LUA_MENU_AVAILABLE_MODS"))
|
||||
|
||||
if (io.directoryexists("mods")) then
|
||||
local mods = io.listfiles("mods/")
|
||||
for i = 1, #mods do
|
||||
if (io.directoryexists(mods[i]) and not io.directoryisempty(mods[i])) then
|
||||
local name, desc = getmodname(mods[i])
|
||||
|
||||
if (mods[i] ~= modfolder) then
|
||||
game:addlocalizedstring(name, name)
|
||||
menu:AddButton(name, function()
|
||||
Engine.Exec("loadmod " .. mods[i])
|
||||
end, nil, true, nil, {
|
||||
desc_text = desc
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
menu:AddBackButton(function(a1)
|
||||
Engine.PlaySound(CoD.SFX.MenuBack)
|
||||
LUI.FlowManager.RequestLeaveMenu(a1)
|
||||
end)
|
||||
|
||||
LUI.Options.InitScrollingList(menu.list, nil)
|
||||
menu:CreateBottomDivider()
|
||||
menu.optionTextInfo = LUI.Options.AddOptionTextInfo(menu)
|
||||
|
||||
return menu
|
||||
end)
|
13
data/ui_scripts/patches/__init__.lua
Normal file
13
data/ui_scripts/patches/__init__.lua
Normal file
@ -0,0 +1,13 @@
|
||||
if (game:issingleplayer()) then
|
||||
return
|
||||
end
|
||||
|
||||
-- defined in mp_hud/hudutils.lua
|
||||
function GetGameModeName()
|
||||
return Engine.Localize(Engine.TableLookup(GameTypesTable.File,
|
||||
GameTypesTable.Cols.Ref, GameX.GetGameMode(), GameTypesTable.Cols.Name))
|
||||
end
|
||||
|
||||
function NeverAllowChangeTeams()
|
||||
return false
|
||||
end
|
6
data/ui_scripts/server_list/__init__.lua
Normal file
6
data/ui_scripts/server_list/__init__.lua
Normal file
@ -0,0 +1,6 @@
|
||||
if (not LUI.mp_menus) then
|
||||
return
|
||||
end
|
||||
|
||||
require("lobby")
|
||||
require("serverlist")
|
69
data/ui_scripts/server_list/lobby.lua
Normal file
69
data/ui_scripts/server_list/lobby.lua
Normal file
@ -0,0 +1,69 @@
|
||||
local Lobby = luiglobals.Lobby
|
||||
local MPLobbyOnline = LUI.mp_menus.MPLobbyOnline
|
||||
|
||||
game:addlocalizedstring("LUA_MENU_SERVERLIST", "SERVER LIST")
|
||||
|
||||
function LeaveLobby(f5_arg0)
|
||||
LeaveXboxLive()
|
||||
if Lobby.IsInPrivateParty() == false or Lobby.IsPrivatePartyHost() then
|
||||
LUI.FlowManager.RequestLeaveMenuByName("menu_xboxlive")
|
||||
Engine.ExecNow("clearcontrollermap")
|
||||
end
|
||||
end
|
||||
|
||||
function menu_xboxlive(f16_arg0, f16_arg1)
|
||||
local menu = LUI.MPLobbyBase.new(f16_arg0, {
|
||||
menu_title = "@PLATFORM_UI_HEADER_PLAY_MP_CAPS",
|
||||
memberListState = Lobby.MemberListStates.Prelobby
|
||||
})
|
||||
|
||||
menu:setClass(LUI.MPLobbyOnline)
|
||||
|
||||
local serverListButton = menu:AddButton("@LUA_MENU_SERVERLIST", function(a1, a2)
|
||||
LUI.FlowManager.RequestAddMenu(a1, "menu_systemlink_join", true, nil)
|
||||
end)
|
||||
serverListButton:setDisabledRefreshRate(500)
|
||||
if Engine.IsCoreMode() then
|
||||
menu:AddCACButton()
|
||||
menu:AddBarracksButton()
|
||||
menu:AddPersonalizationButton()
|
||||
menu:AddDepotButton()
|
||||
end
|
||||
|
||||
local privateMatchButton = menu:AddButton("@MENU_PRIVATE_MATCH", MPLobbyOnline.OnPrivateMatch,
|
||||
MPLobbyOnline.disablePrivateMatchButton)
|
||||
privateMatchButton:rename("menu_xboxlive_private_match")
|
||||
privateMatchButton:setDisabledRefreshRate(500)
|
||||
if not Engine.IsCoreMode() then
|
||||
local leaderboardButton = menu:AddButton("@LUA_MENU_LEADERBOARD", "OpLeaderboardMain")
|
||||
leaderboardButton:rename("OperatorMenu_leaderboard")
|
||||
end
|
||||
|
||||
menu:AddOptionsButton()
|
||||
local natType = Lobby.GetNATType()
|
||||
if natType then
|
||||
local natTypeText = Engine.Localize("NETWORK_YOURNATTYPE", natType)
|
||||
local properties = CoD.CreateState(nil, nil, 2, -62, CoD.AnchorTypes.BottomRight)
|
||||
properties.width = 250
|
||||
properties.height = CoD.TextSettings.BodyFontVeryTiny.Height
|
||||
properties.font = CoD.TextSettings.BodyFontVeryTiny.Font
|
||||
properties.color = luiglobals.Colors.white
|
||||
properties.alpha = 0.25
|
||||
local self = LUI.UIText.new(properties)
|
||||
self:setText(natTypeText)
|
||||
menu:addElement(self)
|
||||
end
|
||||
|
||||
menu.isSignInMenu = true
|
||||
menu:registerEventHandler("gain_focus", LUI.MPLobbyOnline.OnGainFocus)
|
||||
menu:registerEventHandler("player_joined", luiglobals.Cac.PlayerJoinedEvent)
|
||||
menu:registerEventHandler("exit_live_lobby", LeaveLobby)
|
||||
|
||||
if Engine.IsCoreMode() then
|
||||
Engine.ExecNow("eliteclan_refresh", Engine.GetFirstActiveController())
|
||||
end
|
||||
|
||||
return menu
|
||||
end
|
||||
|
||||
LUI.MenuBuilder.m_types_build["menu_xboxlive"] = menu_xboxlive
|
190
data/ui_scripts/server_list/serverlist.lua
Normal file
190
data/ui_scripts/server_list/serverlist.lua
Normal file
@ -0,0 +1,190 @@
|
||||
local Lobby = luiglobals.Lobby
|
||||
local SystemLinkJoinMenu = LUI.mp_menus.SystemLinkJoinMenu
|
||||
|
||||
if (not SystemLinkJoinMenu) then
|
||||
return
|
||||
end
|
||||
|
||||
game:addlocalizedstring("MENU_NUMPLAYERS", "Players")
|
||||
game:addlocalizedstring("MENU_PING", "Ping")
|
||||
|
||||
local columns = {
|
||||
{
|
||||
offset = 10,
|
||||
text = "@MENU_HOST_NAME",
|
||||
dataindex = 0
|
||||
},
|
||||
{
|
||||
offset = 500,
|
||||
text = "@MENU_MAP",
|
||||
dataindex = 1
|
||||
},
|
||||
{
|
||||
offset = 700,
|
||||
text = "@MENU_TYPE1",
|
||||
dataindex = 3
|
||||
},
|
||||
{
|
||||
offset = 950,
|
||||
text = "@MENU_NUMPLAYERS",
|
||||
dataindex = 2
|
||||
},
|
||||
{
|
||||
offset = 1100,
|
||||
text = "@MENU_PING",
|
||||
dataindex = 4
|
||||
}
|
||||
}
|
||||
|
||||
function textlength(text, font, height)
|
||||
local _, _, width = luiglobals.GetTextDimensions(text, font, height)
|
||||
return width
|
||||
end
|
||||
|
||||
function trimtext(text, font, height, maxwidth)
|
||||
if (maxwidth < 0) then
|
||||
return text
|
||||
end
|
||||
|
||||
while (textlength(text, font, height) > maxwidth) do
|
||||
text = text:sub(1, #text - 1)
|
||||
end
|
||||
|
||||
return text
|
||||
end
|
||||
|
||||
SystemLinkJoinMenu.AddHeaderButton = function(menu, f12_arg1, width)
|
||||
local state = CoD.CreateState(0, f12_arg1, nil, nil, CoD.AnchorTypes.TopLeft)
|
||||
state.width = width
|
||||
local element = LUI.UIElement.new(state)
|
||||
local button = SystemLinkJoinMenu.CreateButton("header", 24)
|
||||
|
||||
button:addElement(LUI.Divider.new(CoD.CreateState(nil, 0, nil, nil, CoD.AnchorTypes.TopLeftRight), 40,
|
||||
LUI.Divider.Grey))
|
||||
button:makeNotFocusable()
|
||||
button:addElement(LUI.Divider.new(CoD.CreateState(nil, 0, nil, nil, CoD.AnchorTypes.BottomLeftRight), 40,
|
||||
LUI.Divider.Grey))
|
||||
|
||||
button.m_eventHandlers = {}
|
||||
|
||||
for i = 1, #columns do
|
||||
SystemLinkJoinMenu.MakeText(button.textHolder, columns[i].offset, Engine.Localize(columns[i].text), nil)
|
||||
end
|
||||
|
||||
element:addElement(button)
|
||||
menu:addElement(element)
|
||||
end
|
||||
|
||||
SystemLinkJoinMenu.AddServerButton = function(menu, controller, index)
|
||||
local button = SystemLinkJoinMenu.CreateButton(index or "header", 24)
|
||||
button:makeFocusable()
|
||||
button.index = index
|
||||
button:addEventHandler("button_action", SystemLinkJoinMenu.OnJoinGame)
|
||||
|
||||
local gettext = function(i)
|
||||
local text = Lobby.GetServerData(controller, index, columns[i].dataindex)
|
||||
|
||||
local islast = not columns[i + 1]
|
||||
local end_ = islast and 1130 or columns[i + 1].offset
|
||||
local maxlength = end_ - columns[i].offset
|
||||
|
||||
if (maxlength < 0) then
|
||||
maxlength = columns[i].offset - end_
|
||||
end
|
||||
|
||||
if (not islast) then
|
||||
maxlength = maxlength - 50
|
||||
end
|
||||
|
||||
return trimtext(text, CoD.TextSettings.TitleFontSmall.Font, 14, maxlength)
|
||||
end
|
||||
|
||||
for i = 1, #columns do
|
||||
SystemLinkJoinMenu.MakeText(button.textHolder, columns[i].offset, gettext(i), luiglobals.Colors.h1.medium_grey)
|
||||
end
|
||||
|
||||
menu.list:addElement(button)
|
||||
return button
|
||||
end
|
||||
|
||||
SystemLinkJoinMenu.MakeText = function(menu, f5_arg1, text, color)
|
||||
local state = CoD.CreateState(f5_arg1, nil, f5_arg1 + 200, nil, CoD.AnchorTypes.Left)
|
||||
state.font = CoD.TextSettings.TitleFontSmall.Font
|
||||
state.top = -6
|
||||
state.height = 14
|
||||
state.alignment = nil
|
||||
state.glow = LUI.GlowState.None
|
||||
state.color = color
|
||||
|
||||
local el = LUI.UIText.new(state)
|
||||
el:registerAnimationState("focused", {
|
||||
color = luiglobals.Colors.white
|
||||
})
|
||||
|
||||
el:registerEventHandler("focused", function(element, event)
|
||||
element:animateToState("focused", 0)
|
||||
end)
|
||||
|
||||
el:registerEventHandler("unfocused", function(element, event)
|
||||
element:animateToState("default", 0)
|
||||
end)
|
||||
|
||||
el:setText(text)
|
||||
menu:addElement(el)
|
||||
end
|
||||
|
||||
function menu_systemlink_join(f19_arg0, f19_arg1)
|
||||
local width = 1145
|
||||
|
||||
local menu = LUI.MenuTemplate.new(f19_arg0, {
|
||||
menu_title = "@PLATFORM_SYSTEM_LINK_TITLE",
|
||||
menu_width = width,
|
||||
menu_top_indent = 20,
|
||||
disableDeco = true,
|
||||
spacing = 1
|
||||
})
|
||||
|
||||
SystemLinkJoinMenu.AddHeaderButton(menu, 80, width)
|
||||
SystemLinkJoinMenu.AddLowerCounter(menu, width)
|
||||
SystemLinkJoinMenu.UpdateCounterText(menu, nil)
|
||||
Lobby.BuildServerList(Engine.GetFirstActiveController())
|
||||
|
||||
menu.list:registerEventHandler(LUI.UIScrollIndicator.UpdateEvent, function(element, event)
|
||||
SystemLinkJoinMenu.UpdateCounterText(menu, event)
|
||||
end)
|
||||
|
||||
SystemLinkJoinMenu.UpdateGameList(menu)
|
||||
menu:registerEventHandler("updateGameList", SystemLinkJoinMenu.UpdateGameList)
|
||||
|
||||
LUI.ButtonHelperText.ClearHelperTextObjects(menu.help, {
|
||||
side = "all"
|
||||
})
|
||||
|
||||
menu:AddHelp({
|
||||
name = "add_button_helper_text",
|
||||
button_ref = "button_alt1",
|
||||
helper_text = Engine.Localize("@MENU_SB_TOOLTIP_BTN_REFRESH"),
|
||||
side = "right",
|
||||
clickable = true,
|
||||
priority = -1000
|
||||
}, function(f21_arg0, f21_arg1)
|
||||
SystemLinkJoinMenu.RefreshServers(f21_arg0, f21_arg1, menu)
|
||||
end)
|
||||
|
||||
menu:AddHelp({
|
||||
name = "add_button_helper_text",
|
||||
button_ref = "button_action",
|
||||
helper_text = Engine.Localize("@MENU_JOIN_GAME1"),
|
||||
side = "left",
|
||||
clickable = false,
|
||||
priority = -1000
|
||||
}, nil, nil, true)
|
||||
|
||||
menu:AddBackButton()
|
||||
|
||||
Lobby.RefreshServerList(Engine.GetFirstActiveController())
|
||||
|
||||
return menu
|
||||
end
|
||||
|
||||
LUI.MenuBuilder.m_types_build["menu_systemlink_join"] = menu_systemlink_join
|
171
data/ui_scripts/stats/__init__.lua
Normal file
171
data/ui_scripts/stats/__init__.lua
Normal file
@ -0,0 +1,171 @@
|
||||
if (game:issingleplayer() or not Engine.InFrontend()) then
|
||||
return
|
||||
end
|
||||
|
||||
game:addlocalizedstring("LUA_MENU_STATS", "Stats")
|
||||
game:addlocalizedstring("LUA_MENU_STATS_DESC", "Edit player stats settings.")
|
||||
|
||||
game:addlocalizedstring("LUA_MENU_UNLOCKALL_ITEMS", "Unlock all items")
|
||||
game:addlocalizedstring("LUA_MENU_UNLOCKALL_ITEMS_DESC",
|
||||
"Whether items should be locked based on the player's stats or always unlocked.")
|
||||
|
||||
game:addlocalizedstring("LUA_MENU_UNLOCKALL_LOOT", "Unlock all loot")
|
||||
game:addlocalizedstring("LUA_MENU_UNLOCKALL_LOOT_DESC",
|
||||
"Whether loot should be locked based on the player's stats or always unlocked.")
|
||||
|
||||
game:addlocalizedstring("LUA_MENU_UNLOCKALL_CLASSES", "Unlock all classes")
|
||||
game:addlocalizedstring("LUA_MENU_UNLOCKALL_CLASSES_DESC",
|
||||
"Whether classes should be locked based on the player's stats or always unlocked.")
|
||||
|
||||
game:addlocalizedstring("LUA_MENU_PRESTIGE", "Prestige")
|
||||
game:addlocalizedstring("LUA_MENU_PRESTIGE_DESC", "Edit prestige level.")
|
||||
game:addlocalizedstring("LUA_MENU_RANK", "Rank")
|
||||
game:addlocalizedstring("LUA_MENU_RANK_DESC", "Edit rank.")
|
||||
|
||||
game:addlocalizedstring("LUA_MENU_UNSAVED_CHANGES", "You have unsaved changes, are you sure you want to exit?")
|
||||
game:addlocalizedstring("LUA_MENU_SAVE", "Save changes")
|
||||
game:addlocalizedstring("LUA_MENU_SAVE_DESC", "Save changes.")
|
||||
game:addlocalizedstring("LUA_MENU_SETTINGS", "Settings")
|
||||
game:addlocalizedstring("LUA_MENU_EDIT_STATS", "Edit Stats")
|
||||
|
||||
function createdivider(menu, text)
|
||||
local element = LUI.UIElement.new({
|
||||
leftAnchor = true,
|
||||
rightAnchor = true,
|
||||
left = 0,
|
||||
right = 0,
|
||||
topAnchor = true,
|
||||
bottomAnchor = false,
|
||||
top = 0,
|
||||
bottom = 33.33
|
||||
})
|
||||
|
||||
element.scrollingToNext = true
|
||||
element:addElement(LUI.MenuBuilder.BuildRegisteredType("h1_option_menu_titlebar", {
|
||||
title_bar_text = Engine.ToUpperCase(Engine.Localize(text))
|
||||
}))
|
||||
|
||||
menu.list:addElement(element)
|
||||
end
|
||||
|
||||
local personalizationbutton = LUI.MPLobbyBase.AddPersonalizationButton
|
||||
LUI.MPLobbyBase.AddPersonalizationButton = function(menu)
|
||||
personalizationbutton(menu)
|
||||
menu:AddButton("@LUA_MENU_STATS", function()
|
||||
LUI.FlowManager.RequestAddMenu(nil, "stats_menu")
|
||||
end)
|
||||
end
|
||||
|
||||
LUI.MenuBuilder.registerType("stats_menu", function(a1)
|
||||
local menu = LUI.MenuTemplate.new(a1, {
|
||||
menu_title = Engine.ToUpperCase(Engine.Localize("@LUA_MENU_STATS")),
|
||||
menu_width = luiglobals.GenericMenuDims.OptionMenuWidth
|
||||
})
|
||||
|
||||
createdivider(menu, "@LUA_MENU_SETTINGS")
|
||||
|
||||
LUI.Options.CreateOptionButton(menu, "cg_unlockall_items", "@LUA_MENU_UNLOCKALL_ITEMS",
|
||||
"@LUA_MENU_UNLOCKALL_ITEMS_DESC", {{
|
||||
text = "@LUA_MENU_ENABLED",
|
||||
value = true
|
||||
}, {
|
||||
text = "@LUA_MENU_DISABLED",
|
||||
value = false
|
||||
}}, nil, nil)
|
||||
|
||||
LUI.Options.CreateOptionButton(menu, "cg_unlockall_loot", "@LUA_MENU_UNLOCKALL_LOOT",
|
||||
"@LUA_MENU_UNLOCKALL_LOOT_DESC", {{
|
||||
text = "@LUA_MENU_ENABLED",
|
||||
value = true
|
||||
}, {
|
||||
text = "@LUA_MENU_DISABLED",
|
||||
value = false
|
||||
}}, nil, nil)
|
||||
|
||||
LUI.Options.CreateOptionButton(menu, "cg_unlockall_classes", "@LUA_MENU_UNLOCKALL_CLASSES",
|
||||
"@LUA_MENU_UNLOCKALL_CLASSES_DESC", {{
|
||||
text = "@LUA_MENU_ENABLED",
|
||||
value = true
|
||||
}, {
|
||||
text = "@LUA_MENU_DISABLED",
|
||||
value = false
|
||||
}}, nil, nil)
|
||||
|
||||
createdivider(menu, "@LUA_MENU_EDIT_STATS")
|
||||
|
||||
local prestige = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "prestige") or 0
|
||||
local experience = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "experience") or 0
|
||||
local rank = Lobby.GetRankForXP(experience, prestige)
|
||||
|
||||
prestigeeditbutton(menu, function(value)
|
||||
Engine.SetPlayerData(0, CoD.StatsGroup.Ranked, "prestige", tonumber(value))
|
||||
end)
|
||||
|
||||
rankeditbutton(menu, function(value)
|
||||
local rank = tonumber(value)
|
||||
local prestige = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "prestige") or 0
|
||||
local experience = rank == 0 and 0 or Rank.GetRankMaxXP(tonumber(value) - 1, prestige)
|
||||
|
||||
Engine.SetPlayerData(0, CoD.StatsGroup.Ranked, "experience", experience)
|
||||
end)
|
||||
|
||||
LUI.Options.InitScrollingList(menu.list, nil)
|
||||
LUI.Options.AddOptionTextInfo(menu)
|
||||
|
||||
menu:AddBackButton()
|
||||
|
||||
return menu
|
||||
end)
|
||||
|
||||
function prestigeeditbutton(menu, callback)
|
||||
local options = {}
|
||||
local max = Lobby.GetMaxPrestigeLevel()
|
||||
local prestige = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "prestige") or 0
|
||||
|
||||
for i = 0, max do
|
||||
game:addlocalizedstring("LUA_MENU_" .. i, i .. "")
|
||||
|
||||
table.insert(options, {
|
||||
text = "@" .. i,
|
||||
value = i .. ""
|
||||
})
|
||||
end
|
||||
|
||||
Engine.SetDvarFromString("ui_prestige_level", prestige .. "")
|
||||
|
||||
LUI.Options.CreateOptionButton(menu, "ui_prestige_level", "@LUA_MENU_PRESTIGE", "@LUA_MENU_PRESTIGE_DESC", options,
|
||||
nil, nil, callback)
|
||||
end
|
||||
|
||||
function rankeditbutton(menu, callback)
|
||||
local options = {}
|
||||
local prestige = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "prestige") or 0
|
||||
local experience = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "experience") or 0
|
||||
|
||||
local rank = Lobby.GetRankForXP(experience, prestige)
|
||||
local max = Rank.GetMaxRank(prestige)
|
||||
local maxprestige = Lobby.GetMaxPrestigeLevel()
|
||||
|
||||
for i = 0, max do
|
||||
game:addlocalizedstring("LUA_MENU_" .. i, i .. "")
|
||||
|
||||
table.insert(options, {
|
||||
text = "@" .. (i + 1),
|
||||
value = i .. ""
|
||||
})
|
||||
end
|
||||
|
||||
Engine.SetDvarFromString("ui_rank_level_", rank .. "")
|
||||
|
||||
return LUI.Options.CreateOptionButton(menu, "ui_rank_level_", "@LUA_MENU_RANK", "@LUA_MENU_RANK_DESC", options, nil,
|
||||
nil, callback)
|
||||
end
|
||||
|
||||
local isclasslocked = Cac.IsCustomClassLocked
|
||||
Cac.IsCustomClassLocked = function(...)
|
||||
if (Engine.GetDvarBool("cg_unlockall_classes")) then
|
||||
return false
|
||||
end
|
||||
|
||||
return isclasslocked(...)
|
||||
end
|
2
deps/GSL
vendored
2
deps/GSL
vendored
@ -1 +1 @@
|
||||
Subproject commit 4377f6e603c64a86c934f1546aa9db482f2e1a4e
|
||||
Subproject commit d9fc52e20e32fcc804502480a781120b210afd41
|
2
deps/asmjit
vendored
2
deps/asmjit
vendored
@ -1 +1 @@
|
||||
Subproject commit 6efd4d563dee6832224295fa3bbf1647964246c4
|
||||
Subproject commit 06d0badec53710a4f572cf5642881ce570c5d274
|
2
deps/libtomcrypt
vendored
2
deps/libtomcrypt
vendored
@ -1 +1 @@
|
||||
Subproject commit 673f5ce29015a9bba3c96792920a10601b5b0718
|
||||
Subproject commit 06a81aeb227424182125363f7554fad5146d6d2a
|
2
deps/libtommath
vendored
2
deps/libtommath
vendored
@ -1 +1 @@
|
||||
Subproject commit 04e9d1e7a0493910b2eb5e757d623870692ada04
|
||||
Subproject commit 4b47368501321c795d5b54d87a5bab35a21a7940
|
2
deps/lua
vendored
2
deps/lua
vendored
@ -1 +1 @@
|
||||
Subproject commit 8426d9b4d4df1da3c5b2d759e509ae1c50a86667
|
||||
Subproject commit d61b0c60287c38008d312ddd11724a15b1737f7b
|
2
deps/rapidjson
vendored
2
deps/rapidjson
vendored
@ -1 +1 @@
|
||||
Subproject commit e4bde977440d4a00f820b6586899e48a972d2493
|
||||
Subproject commit 232389d4f1012dddec4ef84861face2d2ba85709
|
2
deps/sol2
vendored
2
deps/sol2
vendored
@ -1 +1 @@
|
||||
Subproject commit 50b62c9346750b7c2c406c9e4c546f96b0bf021d
|
||||
Subproject commit 2198d9374d260f168d53b6248e49068a6307227d
|
2
deps/zlib
vendored
2
deps/zlib
vendored
@ -1 +1 @@
|
||||
Subproject commit 2014a993addbc8f1b9785d97f55fd189792c2f78
|
||||
Subproject commit ec3df00224d4b396e2ac6586ab5d25f673caa4c2
|
@ -264,6 +264,7 @@ filter {}
|
||||
|
||||
filter "configurations:Debug"
|
||||
optimize "Debug"
|
||||
buildoptions {"/bigobj"}
|
||||
defines {"DEBUG", "_DEBUG"}
|
||||
filter {}
|
||||
|
||||
@ -302,7 +303,7 @@ targetname "h1-mod"
|
||||
pchheader "std_include.hpp"
|
||||
pchsource "src/client/std_include.cpp"
|
||||
|
||||
linkoptions {"/IGNORE:4254", "/DYNAMICBASE:NO", "/SAFESEH:NO", "/LARGEADDRESSAWARE", "/LAST:.main", "/PDBCompress"}
|
||||
linkoptions {"/IGNORE:4254", "/DYNAMICBASE:NO", "/SAFESEH:NO", "/LARGEADDRESSAWARE", "/PDBCompress"}
|
||||
|
||||
files {"./src/client/**.rc", "./src/client/**.hpp", "./src/client/**.cpp", "./src/client/resources/**.*"}
|
||||
|
||||
@ -320,6 +321,10 @@ if _OPTIONS["copy-to"] then
|
||||
postbuildcommands {"copy /y \"$(TargetPath)\" \"" .. _OPTIONS["copy-to"] .. "\""}
|
||||
end
|
||||
|
||||
if _OPTIONS["debug-dir"] then
|
||||
debugdir ( _OPTIONS["debug-dir"] )
|
||||
end
|
||||
|
||||
dependencies.imports()
|
||||
|
||||
project "tlsdll"
|
||||
|
145
src/client/component/arxan.cpp
Normal file
145
src/client/component/arxan.cpp
Normal file
@ -0,0 +1,145 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
#include "scheduler.hpp"
|
||||
#include "game/game.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
|
||||
namespace arxan
|
||||
{
|
||||
namespace
|
||||
{
|
||||
utils::hook::detour nt_close_hook;
|
||||
utils::hook::detour nt_query_information_process_hook;
|
||||
|
||||
NTSTATUS WINAPI nt_query_information_process_stub(const HANDLE handle, const PROCESSINFOCLASS info_class,
|
||||
const PVOID info,
|
||||
const ULONG info_length, const PULONG ret_length)
|
||||
{
|
||||
auto* orig = static_cast<decltype(NtQueryInformationProcess)*>(nt_query_information_process_hook.
|
||||
get_original());
|
||||
const auto status = orig(handle, info_class, info, info_length, ret_length);
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
if (info_class == ProcessBasicInformation)
|
||||
{
|
||||
static DWORD explorer_pid = 0;
|
||||
if (!explorer_pid)
|
||||
{
|
||||
auto* const shell_window = GetShellWindow();
|
||||
GetWindowThreadProcessId(shell_window, &explorer_pid);
|
||||
}
|
||||
|
||||
static_cast<PPROCESS_BASIC_INFORMATION>(info)->Reserved3 = PVOID(DWORD64(explorer_pid));
|
||||
}
|
||||
else if (info_class == 30) // ProcessDebugObjectHandle
|
||||
{
|
||||
*static_cast<HANDLE*>(info) = nullptr;
|
||||
|
||||
return 0xC0000353;
|
||||
}
|
||||
else if (info_class == 7) // ProcessDebugPort
|
||||
{
|
||||
*static_cast<HANDLE*>(info) = nullptr;
|
||||
}
|
||||
else if (info_class == 31)
|
||||
{
|
||||
*static_cast<ULONG*>(info) = 1;
|
||||
}
|
||||
|
||||
//https://docs.microsoft.com/en-us/windows/win32/api/winternl/nf-winternl-ntqueryinformationprocess
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
NTSTATUS NTAPI nt_close_stub(const HANDLE handle)
|
||||
{
|
||||
char info[16];
|
||||
if (NtQueryObject(handle, OBJECT_INFORMATION_CLASS(4), &info, 2, nullptr) >= 0 && size_t(handle) != 0x12345)
|
||||
{
|
||||
auto* orig = static_cast<decltype(NtClose)*>(nt_close_hook.get_original());
|
||||
return orig(handle);
|
||||
}
|
||||
|
||||
return STATUS_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
LONG WINAPI exception_filter(const LPEXCEPTION_POINTERS info)
|
||||
{
|
||||
if (info->ExceptionRecord->ExceptionCode == STATUS_INVALID_HANDLE)
|
||||
{
|
||||
return EXCEPTION_CONTINUE_EXECUTION;
|
||||
}
|
||||
|
||||
return EXCEPTION_CONTINUE_SEARCH;
|
||||
}
|
||||
|
||||
void hide_being_debugged()
|
||||
{
|
||||
auto* const peb = PPEB(__readgsqword(0x60));
|
||||
peb->BeingDebugged = false;
|
||||
*reinterpret_cast<PDWORD>(LPSTR(peb) + 0xBC) &= ~0x70;
|
||||
}
|
||||
|
||||
void remove_hardware_breakpoints()
|
||||
{
|
||||
CONTEXT context;
|
||||
ZeroMemory(&context, sizeof(context));
|
||||
context.ContextFlags = CONTEXT_DEBUG_REGISTERS;
|
||||
|
||||
auto* const thread = GetCurrentThread();
|
||||
GetThreadContext(thread, &context);
|
||||
|
||||
context.Dr0 = 0;
|
||||
context.Dr1 = 0;
|
||||
context.Dr2 = 0;
|
||||
context.Dr3 = 0;
|
||||
context.Dr6 = 0;
|
||||
context.Dr7 = 0;
|
||||
|
||||
SetThreadContext(thread, &context);
|
||||
}
|
||||
|
||||
BOOL WINAPI set_thread_context_stub(const HANDLE thread, CONTEXT* context)
|
||||
{
|
||||
return SetThreadContext(thread, context);
|
||||
}
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void* load_import(const std::string& library, const std::string& function) override
|
||||
{
|
||||
if (function == "SetThreadContext")
|
||||
{
|
||||
//return set_thread_context_stub;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void post_load() override
|
||||
{
|
||||
hide_being_debugged();
|
||||
scheduler::loop(hide_being_debugged, scheduler::pipeline::async);
|
||||
|
||||
const utils::nt::library ntdll("ntdll.dll");
|
||||
nt_close_hook.create(ntdll.get_proc<void*>("NtClose"), nt_close_stub);
|
||||
nt_query_information_process_hook.create(ntdll.get_proc<void*>("NtQueryInformationProcess"),
|
||||
nt_query_information_process_stub);
|
||||
// https://www.geoffchappell.com/studies/windows/win32/ntdll/api/index.htm
|
||||
AddVectoredExceptionHandler(1, exception_filter);
|
||||
}
|
||||
|
||||
void post_unpack() override
|
||||
{
|
||||
// cba to implement sp, not sure if it's even needed
|
||||
if (game::environment::is_sp()) return;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(arxan::component)
|
@ -89,7 +89,7 @@ namespace auth
|
||||
return utils::string::va("0x%lX", value);
|
||||
}
|
||||
|
||||
int send_connect_data_stub(game::netsrc_t sock, game::netadr_s* adr, const char* format, const int len)
|
||||
bool send_connect_data(game::netsrc_t sock, game::netadr_s* adr, const char* format, const int len)
|
||||
{
|
||||
std::string connect_string(format, len);
|
||||
game::SV_Cmd_TokenizeString(connect_string.data());
|
||||
@ -189,7 +189,29 @@ namespace auth
|
||||
a.call_aligned(direct_connect);
|
||||
a.popad64();
|
||||
|
||||
a.jmp(0x140488CE2); // H1MP64(1.4)
|
||||
a.jmp(0x1CAF64_b);
|
||||
});
|
||||
}
|
||||
|
||||
void* get_send_connect_data_stub()
|
||||
{
|
||||
return utils::hook::assemble([](utils::hook::assembler& a)
|
||||
{
|
||||
const auto false_ = a.newLabel();
|
||||
const auto original = a.newLabel();
|
||||
|
||||
a.mov(ecx, eax);
|
||||
a.lea(r8, qword_ptr(rbp, 0x4C0));
|
||||
a.mov(r9d, ebx);
|
||||
a.lea(rdx, qword_ptr(rsp, 0x30));
|
||||
|
||||
a.pushad64();
|
||||
a.call_aligned(send_connect_data);
|
||||
a.test(al, al);
|
||||
a.popad64();
|
||||
|
||||
a.mov(rbx, qword_ptr(rsp, 0x9F0));
|
||||
a.jmp(0x12D446_b);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -212,25 +234,20 @@ namespace auth
|
||||
// Patch steam id bit check
|
||||
if (game::environment::is_sp())
|
||||
{
|
||||
utils::hook::jump(0x140475C17, 0x140475C6A); // H1(1.4)
|
||||
utils::hook::jump(0x140476AFF, 0x140476B40); // H1(1.4)
|
||||
utils::hook::jump(0x140476FA4, 0x140476FF2); // H1(1.4)
|
||||
utils::hook::jump(0x4FA1B3_b, 0x4FA21A_b, true);
|
||||
utils::hook::jump(0x4FB272_b, 0x4FB2B7_b, true);
|
||||
utils::hook::jump(0x4FB781_b, 0x4FB7D3_b, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
utils::hook::jump(0x140571E07, 0x140571E5A); // H1(1.4)
|
||||
utils::hook::jump(0x14004B223, 0x14004B4F2); // H1(1.4)
|
||||
utils::hook::jump(0x14004B4AD, 0x14004B4F2); // H1(1.4)
|
||||
utils::hook::jump(0x140572F6F, 0x140572FB0); // H1(1.4)
|
||||
utils::hook::jump(0x140573470, 0x1405734B6); // H1(1.4)
|
||||
// kill "disconnected from steam" error
|
||||
utils::hook::nop(0x1D61DF_b, 0x11);
|
||||
|
||||
utils::hook::jump(0x140488BC1, get_direct_connect_stub(), true); // H1(1.4)
|
||||
utils::hook::call(0x140250ED2, send_connect_data_stub); // H1(1.4)
|
||||
utils::hook::jump(0x1CAE70_b, get_direct_connect_stub(), true);
|
||||
utils::hook::jump(0x12D426_b, get_send_connect_data_stub(), true);
|
||||
|
||||
// Check for sending connect packet
|
||||
utils::hook::set(0x14059A6E0, 0xC301B0);
|
||||
// Don't instantly timeout the connecting client ? not sure about this
|
||||
utils::hook::set(0x14025136B, 0xC3);
|
||||
utils::hook::set(0x12D93C_b, 0xC3);
|
||||
}
|
||||
|
||||
command::add("guid", []()
|
||||
|
@ -15,7 +15,7 @@ namespace binding
|
||||
|
||||
int get_num_keys()
|
||||
{
|
||||
return SELECT_VALUE(102, 103);
|
||||
return 110;
|
||||
}
|
||||
|
||||
int key_write_bindings_to_buffer_stub(int /*localClientNum*/, char* buffer, const int buffer_size)
|
||||
@ -83,7 +83,7 @@ namespace binding
|
||||
int key_get_binding_for_cmd_stub(const char* command)
|
||||
{
|
||||
// original binds
|
||||
for (auto i = 0; i <= get_num_keys(); i++)
|
||||
for (auto i = 0; i < get_num_keys(); i++)
|
||||
{
|
||||
if (game::command_whitelist[i] && !strcmp(command, game::command_whitelist[i]))
|
||||
{
|
||||
@ -95,22 +95,50 @@ namespace binding
|
||||
return get_num_keys() + get_binding_for_custom_command(command);
|
||||
}
|
||||
|
||||
void cl_execute_key_stub(const int local_client_num, int key, const int down, const int time)
|
||||
|
||||
std::optional<std::string> get_custom_binding_for_key(int key)
|
||||
{
|
||||
key -= get_num_keys();
|
||||
|
||||
if (static_cast<size_t>(key) < custom_binds.size() && !custom_binds[key].empty())
|
||||
{
|
||||
return {custom_binds[key]};
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void cl_execute_key_stub(const int local_client_num, int key, const int down, const unsigned int time)
|
||||
{
|
||||
if (key >= get_num_keys())
|
||||
{
|
||||
key -= get_num_keys();
|
||||
|
||||
if (static_cast<size_t>(key) < custom_binds.size() && !custom_binds[key].empty())
|
||||
const auto bind = get_custom_binding_for_key(key);
|
||||
if (!bind.has_value())
|
||||
{
|
||||
game::Cbuf_AddText(local_client_num, utils::string::va("%s\n", custom_binds[key].data()));
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
return game::Cbuf_AddText(local_client_num, 0, utils::string::va("%s\n", bind.value().data()));
|
||||
}
|
||||
|
||||
cl_execute_key_hook.invoke<void>(local_client_num, key, down, time);
|
||||
}
|
||||
|
||||
const char* cmd_get_binding_for_key_stub(unsigned int key)
|
||||
{
|
||||
if (key >= static_cast<unsigned int>(get_num_keys()))
|
||||
{
|
||||
const auto bind = get_custom_binding_for_key(key);
|
||||
if (!bind.has_value())
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
return utils::string::va("%s", bind.value().data());
|
||||
}
|
||||
|
||||
return game::command_whitelist[key];
|
||||
}
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
@ -124,13 +152,19 @@ namespace binding
|
||||
}
|
||||
|
||||
// write all bindings to config file
|
||||
utils::hook::call(SELECT_VALUE(0x1401881DB, 0x14025032F), key_write_bindings_to_buffer_stub); // H1(1.4)
|
||||
utils::hook::jump(SELECT_VALUE(0x1AC980_b, 0x199ED0_b), key_write_bindings_to_buffer_stub);
|
||||
|
||||
// links a custom command to an index
|
||||
utils::hook::jump(SELECT_VALUE(0x140343C00, 0x1404041E0), key_get_binding_for_cmd_stub); // H1(1.4)
|
||||
utils::hook::jump(SELECT_VALUE(0x377280_b, 0x1572B0_b), key_get_binding_for_cmd_stub);
|
||||
|
||||
// execute custom binds
|
||||
cl_execute_key_hook.create(SELECT_VALUE(0x140183C70, 0x14024ACF0), &cl_execute_key_stub); // H1(1.4)
|
||||
cl_execute_key_hook.create(SELECT_VALUE(0x1A8350_b, 0x130610_b), &cl_execute_key_stub);
|
||||
|
||||
if (game::environment::is_sp())
|
||||
{
|
||||
// called from getcommandfromkey in gsc
|
||||
utils::hook::jump(0x3772E0_b, cmd_get_binding_for_key_stub);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "party.hpp"
|
||||
|
||||
#include "game/game.hpp"
|
||||
#include "game/scripting/execution.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
#include <utils/string.hpp>
|
||||
@ -18,30 +19,22 @@ namespace bots
|
||||
{
|
||||
bool can_add()
|
||||
{
|
||||
if (party::get_client_count() < *game::mp::svs_numclients)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return party::get_client_count() < *game::mp::svs_numclients
|
||||
&& game::SV_Loaded() && !game::VirtualLobby_Loaded();
|
||||
}
|
||||
|
||||
// TODO: when scripting comes, fix this to use better notifies
|
||||
void bot_team_join(const int entity_num)
|
||||
{
|
||||
scheduler::once([entity_num]()
|
||||
const game::scr_entref_t entref{static_cast<uint16_t>(entity_num), 0};
|
||||
scheduler::once([entref]()
|
||||
{
|
||||
game::SV_ExecuteClientCommand(&game::mp::svs_clients[entity_num],
|
||||
utils::string::va("lui 68 2 %i", *game::mp::sv_serverId_value),
|
||||
false);
|
||||
|
||||
// scheduler the select class call
|
||||
scheduler::once([entity_num]()
|
||||
scripting::notify(entref, "luinotifyserver", {"team_select", 2});
|
||||
scheduler::once([entref]()
|
||||
{
|
||||
game::SV_ExecuteClientCommand(&game::mp::svs_clients[entity_num],
|
||||
utils::string::va("lui 5 %i %i", (rand() % 5) + 10,
|
||||
*game::mp::sv_serverId_value), false);
|
||||
}, scheduler::pipeline::server, 1s);
|
||||
}, scheduler::pipeline::server, 1s);
|
||||
auto* _class = utils::string::va("class%d", utils::cryptography::random::get_integer() % 5);
|
||||
scripting::notify(entref, "luinotifyserver", {"class_select", _class});
|
||||
}, scheduler::pipeline::server, 2s);
|
||||
}, scheduler::pipeline::server, 2s);
|
||||
}
|
||||
|
||||
void spawn_bot(const int entity_num)
|
||||
@ -60,16 +53,21 @@ namespace bots
|
||||
return;
|
||||
}
|
||||
|
||||
// SV_BotGetRandomName
|
||||
const auto* const bot_name = game::SV_BotGetRandomName();
|
||||
auto* bot_ent = game::SV_AddBot(bot_name);
|
||||
static auto first_bot = true;
|
||||
|
||||
const auto bot_name = game::SV_BotGetRandomName();
|
||||
const auto bot_ent = game::SV_AddBot(bot_name);
|
||||
|
||||
if (bot_ent)
|
||||
{
|
||||
spawn_bot(bot_ent->s.entityNum);
|
||||
}
|
||||
else if (can_add()) // workaround since first bot won't ever spawn
|
||||
else
|
||||
{
|
||||
add_bot();
|
||||
scheduler::once([]()
|
||||
{
|
||||
add_bot();
|
||||
}, scheduler::pipeline::server, 100ms);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -86,7 +84,10 @@ namespace bots
|
||||
|
||||
command::add("spawnBot", [](const command::params& params)
|
||||
{
|
||||
if (!game::SV_Loaded() || game::VirtualLobby_Loaded()) return;
|
||||
if (!can_add())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto num_bots = 1;
|
||||
if (params.size() == 2)
|
||||
@ -94,7 +95,9 @@ namespace bots
|
||||
num_bots = atoi(params.get(1));
|
||||
}
|
||||
|
||||
for (auto i = 0; i < (num_bots > *game::mp::svs_numclients ? *game::mp::svs_numclients : num_bots); i++)
|
||||
num_bots = std::min(num_bots, *game::mp::svs_numclients);
|
||||
|
||||
for (auto i = 0; i < num_bots; i++)
|
||||
{
|
||||
scheduler::once(add_bot, scheduler::pipeline::server, 100ms * i);
|
||||
}
|
||||
@ -103,4 +106,4 @@ namespace bots
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(bots::component)
|
||||
REGISTER_COMPONENT(bots::component)
|
||||
|
@ -27,14 +27,33 @@ namespace branding
|
||||
const auto* const build_num = ui_get_formatted_build_number_hook.invoke<const char*>();
|
||||
return utils::string::va("%s (%s)", VERSION, build_num);
|
||||
}
|
||||
|
||||
void draw_branding()
|
||||
{
|
||||
const auto font = game::R_RegisterFont("fonts/fira_mono_bold.ttf", 20);
|
||||
if (font)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
game::R_AddCmdDrawText("H1-Mod: " VERSION " (" __DATE__ " " __TIME__ ")", 0x7FFFFFFF, font, 10.f,
|
||||
5.f + static_cast<float>(font->pixelHeight), 1.f, 1.f, 0.0f, color, 0);
|
||||
#else
|
||||
game::R_AddCmdDrawText("H1-Mod: " VERSION, 0x7FFFFFFF, font, 10.f,
|
||||
5.f + static_cast<float>(font->pixelHeight), 1.f, 1.f, 0.0f, color, 0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_start() override
|
||||
{
|
||||
scheduler::loop(draw_branding, scheduler::pipeline::renderer);
|
||||
}
|
||||
|
||||
void post_unpack() override
|
||||
{
|
||||
|
||||
if (game::environment::is_dedi())
|
||||
{
|
||||
return;
|
||||
@ -46,20 +65,10 @@ namespace branding
|
||||
localized_strings::override("MENU_MULTIPLAYER_CAPS", "H1-MOD: MULTIPLAYER");
|
||||
}
|
||||
|
||||
dvars::override::set_string("version", utils::string::va("H1-Mod %s", VERSION));
|
||||
|
||||
ui_get_formatted_build_number_hook.create(
|
||||
SELECT_VALUE(0x1403B1C40, 0x1404E74C0), ui_get_formatted_build_number_stub);
|
||||
|
||||
scheduler::loop([]()
|
||||
{
|
||||
const auto font = game::R_RegisterFont("fonts/fira_mono_bold.ttf", 20);
|
||||
|
||||
game::R_AddCmdDrawText("H1-Mod: " VERSION, 0x7FFFFFFF, font, 10.f,
|
||||
5.f + static_cast<float>(font->pixelHeight), 1.f, 1.f, 0.0f, color, 0);
|
||||
}, scheduler::pipeline::renderer);
|
||||
SELECT_VALUE(0x406EC0_b, 0x1DF300_b), ui_get_formatted_build_number_stub);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(branding::component)
|
||||
REGISTER_COMPONENT(branding::component)
|
46
src/client/component/bullet.cpp
Normal file
46
src/client/component/bullet.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "game/game.hpp"
|
||||
#include "game/dvars.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
|
||||
namespace bullet
|
||||
{
|
||||
namespace
|
||||
{
|
||||
game::dvar_t* bg_surface_penetration;
|
||||
utils::hook::detour bg_get_surface_penetration_depth_hook;
|
||||
|
||||
float bg_get_surface_penetration_depth_stub(game::Weapon weapon, bool is_alternate, int surface_type)
|
||||
{
|
||||
if (bg_surface_penetration->current.value > 0.0f)
|
||||
{
|
||||
return bg_surface_penetration->current.value;
|
||||
}
|
||||
|
||||
return bg_get_surface_penetration_depth_hook.invoke<float>(weapon, is_alternate, surface_type);
|
||||
}
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
if (game::environment::is_sp())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bg_surface_penetration = dvars::register_float("bg_surfacePenetration", 0.0f,
|
||||
0.0f, std::numeric_limits<float>::max(), 0,
|
||||
"Set to a value greater than 0 to override the surface penetration depth");
|
||||
|
||||
bg_get_surface_penetration_depth_hook.create(0x2E1110_b, &bg_get_surface_penetration_depth_stub);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(bullet::component)
|
52
src/client/component/chat.cpp
Normal file
52
src/client/component/chat.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "localized_strings.hpp"
|
||||
#include "dvars.hpp"
|
||||
|
||||
#include "game/game.hpp"
|
||||
#include "game/dvars.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
|
||||
namespace chat
|
||||
{
|
||||
namespace
|
||||
{
|
||||
game::Font_s* ui_get_font_handle_stub()
|
||||
{
|
||||
return game::R_RegisterFont("fonts/defaultBold.otf", 24);
|
||||
}
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
if (!game::environment::is_mp())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// use better font
|
||||
utils::hook::inject(0x0F6F61_b, reinterpret_cast<void*>(0x2E6F588_b));
|
||||
utils::hook::inject(0x18A980_b, reinterpret_cast<void*>(0x2E6F588_b));
|
||||
utils::hook::call(0x33EDEC_b, ui_get_font_handle_stub);
|
||||
|
||||
// set text style to 0 (non-blurry)
|
||||
utils::hook::set<uint8_t>(0x18A9F2_b, 0);
|
||||
utils::hook::set<uint8_t>(0x0F7151_b, 0);
|
||||
utils::hook::set<uint8_t>(0x33EE0E_b, 0);
|
||||
|
||||
localized_strings::override("EXE_SAY", "^3Match^7");
|
||||
localized_strings::override("EXE_SAYTEAM", "^5Team^7");
|
||||
|
||||
// move chat position on the screen above menu splashes
|
||||
dvars::override::register_vec2("cg_hudChatPosition", 5, 200, 0, 640, game::DVAR_FLAG_SAVED);
|
||||
dvars::override::register_int("cg_chatHeight", 5, 0, 8, game::DVAR_FLAG_SAVED);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(chat::component)
|
@ -96,8 +96,7 @@ namespace colors
|
||||
const size_t unk, const size_t unk2)
|
||||
{
|
||||
// CL_GetClientName (CL_GetClientNameAndClantag?)
|
||||
const auto result = reinterpret_cast<size_t(*)(int, int, char*, int, size_t, size_t)>(0x14025BAA0)( // H1 (1.4)
|
||||
local_client_num, index, buf, size, unk, unk2);
|
||||
const auto result = utils::hook::invoke<size_t>(0x343BA0_b, local_client_num, index, buf, size, unk, unk2);
|
||||
|
||||
utils::string::strip(buf, buf, size);
|
||||
|
||||
@ -110,11 +109,11 @@ namespace colors
|
||||
|
||||
if (index == '8')
|
||||
{
|
||||
*color = *reinterpret_cast<DWORD*>(SELECT_VALUE(0x14F142FF8, 0x14FE70634)); // H1(1.4)
|
||||
*color = *reinterpret_cast<DWORD*>(SELECT_VALUE(0xF79D288_b, 0xEA749B4_b));
|
||||
}
|
||||
else if (index == '9')
|
||||
{
|
||||
*color = *reinterpret_cast<DWORD*>(SELECT_VALUE(0x14F142FFC, 0x14FE70638)); // H1(1.4)
|
||||
*color = *reinterpret_cast<DWORD*>(SELECT_VALUE(0xF79D28C_b, 0xEA749B8_b));
|
||||
}
|
||||
else if (index == ':')
|
||||
{
|
||||
@ -122,7 +121,7 @@ namespace colors
|
||||
}
|
||||
else if (index == ';')
|
||||
{
|
||||
*color = *reinterpret_cast<DWORD*>(SELECT_VALUE(0x14F143004, 0x14FE70640)); // H1(1.4)
|
||||
*color = *reinterpret_cast<DWORD*>(SELECT_VALUE(0xF79D294_b, 0xEA749C0_b));
|
||||
}
|
||||
else if (index == '<')
|
||||
{
|
||||
@ -148,17 +147,17 @@ namespace colors
|
||||
if (!game::environment::is_sp())
|
||||
{
|
||||
// allows colored name in-game
|
||||
utils::hook::jump(0x140503810, com_clean_name_stub); // H1(1.4)
|
||||
utils::hook::jump(0x5AEDF0_b, com_clean_name_stub, true);
|
||||
|
||||
// don't apply colors to overhead names
|
||||
utils::hook::call(0x1400AB416, get_client_name_stub); // H1(1.4)
|
||||
utils::hook::call(0xF7B85_b, get_client_name_stub);
|
||||
|
||||
// patch I_CleanStr
|
||||
utils::hook::jump(0x140503D00, i_clean_str_stub); // H1(1.4)
|
||||
utils::hook::jump(0x5AF2E0_b, i_clean_str_stub, true);
|
||||
}
|
||||
|
||||
// force new colors
|
||||
utils::hook::jump(SELECT_VALUE(0x140524BD0, 0x1406206A0), rb_lookup_color_stub); // H1(1.4)
|
||||
utils::hook::jump(SELECT_VALUE(0x5B17E0_b, 0x6C9460_b), rb_lookup_color_stub, true);
|
||||
|
||||
// add colors
|
||||
add(0, 0, 0); // 0 - Black
|
||||
|
@ -1,22 +1,29 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "command.hpp"
|
||||
#include "console.hpp"
|
||||
#include "game_console.hpp"
|
||||
#include "fastfiles.hpp"
|
||||
#include "scheduler.hpp"
|
||||
#include "logfile.hpp"
|
||||
|
||||
#include "game/game.hpp"
|
||||
#include "game/dvars.hpp"
|
||||
|
||||
#include "game/scripting/execution.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
#include <utils/string.hpp>
|
||||
#include <utils/memory.hpp>
|
||||
#include "utils/io.hpp"
|
||||
#include <game/dvars.hpp>
|
||||
#include <utils/io.hpp>
|
||||
|
||||
namespace command
|
||||
{
|
||||
namespace
|
||||
{
|
||||
utils::hook::detour client_command_hook;
|
||||
utils::hook::detour parse_commandline_hook;
|
||||
|
||||
std::unordered_map<std::string, std::function<void(params&)>> handlers;
|
||||
std::unordered_map<std::string, std::function<void(int, params_sv&)>> handlers_sv;
|
||||
@ -32,8 +39,13 @@ namespace command
|
||||
}
|
||||
}
|
||||
|
||||
void client_command(const int client_num, void* a2)
|
||||
void client_command(const int client_num)
|
||||
{
|
||||
if (!logfile::client_command_stub(client_num))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
params_sv params = {};
|
||||
|
||||
const auto command = utils::string::to_lower(params[0]);
|
||||
@ -42,7 +54,7 @@ namespace command
|
||||
handlers_sv[command](client_num, params);
|
||||
}
|
||||
|
||||
client_command_hook.invoke<void>(client_num, a2);
|
||||
client_command_hook.invoke<void>(client_num);
|
||||
}
|
||||
|
||||
// Shamelessly stolen from Quake3
|
||||
@ -58,8 +70,8 @@ namespace command
|
||||
static std::string comand_line_buffer = GetCommandLineA();
|
||||
auto* command_line = comand_line_buffer.data();
|
||||
|
||||
auto& com_num_console_lines = *reinterpret_cast<int*>(0x142623FB4); //H1(1.4)
|
||||
auto* com_console_lines = reinterpret_cast<char**>(0x142623FC0); //H1(1.4)
|
||||
auto& com_num_console_lines = *reinterpret_cast<int*>(0x35634B8_b);
|
||||
auto* com_console_lines = reinterpret_cast<char**>(0x35634C0_b);
|
||||
|
||||
auto inq = false;
|
||||
com_console_lines[0] = command_line;
|
||||
@ -91,7 +103,7 @@ namespace command
|
||||
void parse_commandline_stub()
|
||||
{
|
||||
parse_command_line();
|
||||
reinterpret_cast<void(*)()>(0x1400D8210)(); // mwr: test
|
||||
parse_commandline_hook.invoke<void>();
|
||||
}
|
||||
|
||||
game::dvar_t* dvar_command_stub()
|
||||
@ -103,23 +115,39 @@ namespace command
|
||||
return 0;
|
||||
}
|
||||
|
||||
const auto dvar = game::Dvar_FindVar(args[0]);
|
||||
auto dvar = game::Dvar_FindVar(args[0]);
|
||||
if (dvar == nullptr)
|
||||
{
|
||||
const auto hash = static_cast<int>(std::strtoull(args[0], nullptr, 16));
|
||||
dvar = game::Dvar_FindMalleableVar(hash);
|
||||
}
|
||||
|
||||
if (dvar)
|
||||
{
|
||||
if (args.size() == 1)
|
||||
{
|
||||
const auto current = game::Dvar_ValueToString(dvar, dvar->current);
|
||||
const auto reset = game::Dvar_ValueToString(dvar, dvar->reset);
|
||||
const auto current = game::Dvar_ValueToString(dvar, true, dvar->current);
|
||||
const auto reset = game::Dvar_ValueToString(dvar, true, dvar->reset);
|
||||
|
||||
console::info("\"%s\" is: \"%s\" default: \"%s\" hash: 0x%08lX",
|
||||
args[0], current, reset, dvar->hash);
|
||||
const auto info = dvars::get_dvar_info_from_hash(dvar->hash);
|
||||
std::string desc{};
|
||||
std::string name = args[0];
|
||||
|
||||
if (info.has_value())
|
||||
{
|
||||
name = info.value().name;
|
||||
desc = info.value().description;
|
||||
}
|
||||
|
||||
console::info("\"%s\" is: \"%s\" default: \"%s\" hash: 0x%08lX type: %i\n",
|
||||
name.data(), current, reset, dvar->hash, dvar->type);
|
||||
|
||||
console::info("%s\n", desc.data());
|
||||
console::info(" %s\n", dvars::dvar_get_domain(dvar->type, dvar->domain).data());
|
||||
}
|
||||
else
|
||||
{
|
||||
char command[0x1000] = { 0 };
|
||||
char command[0x1000] = {0};
|
||||
game::Dvar_GetCombinedString(command, 1);
|
||||
game::Dvar_SetCommand(dvar->hash, "", command);
|
||||
}
|
||||
@ -129,6 +157,202 @@ namespace command
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void client_println(int client_num, const std::string& text)
|
||||
{
|
||||
if (game::environment::is_sp())
|
||||
{
|
||||
game::CG_GameMessage(0, text.data());
|
||||
}
|
||||
else
|
||||
{
|
||||
game::SV_GameSendServerCommand(client_num, game::SV_CMD_RELIABLE,
|
||||
utils::string::va("f \"%s\"", text.data()));
|
||||
}
|
||||
}
|
||||
|
||||
bool check_cheats(int client_num)
|
||||
{
|
||||
if (!game::Dvar_FindVar("sv_cheats")->current.enabled)
|
||||
{
|
||||
client_println(client_num, "Cheats are not enabled on this server");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void cmd_give_weapon(const int client_num, const std::vector<std::string>& params)
|
||||
{
|
||||
if (params.size() < 2)
|
||||
{
|
||||
client_println(client_num, "You did not specify a weapon name");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
const auto& arg = params[1];
|
||||
const auto player = scripting::entity({static_cast<uint16_t>(client_num), 0});
|
||||
auto ps = game::SV_GetPlayerstateForClientNum(client_num);
|
||||
|
||||
if (arg == "ammo")
|
||||
{
|
||||
const auto weapon = player.call("getcurrentweapon").as<std::string>();
|
||||
player.call("givemaxammo", {weapon});
|
||||
}
|
||||
else if (arg == "allammo")
|
||||
{
|
||||
const auto weapons = player.call("getweaponslistall").as<scripting::array>();
|
||||
for (auto i = 0; i < weapons.size(); i++)
|
||||
{
|
||||
player.call("givemaxammo", {weapons[i]});
|
||||
}
|
||||
}
|
||||
else if (arg == "health")
|
||||
{
|
||||
if (params.size() > 2)
|
||||
{
|
||||
const auto amount = atoi(params[2].data());
|
||||
const auto health = player.get("health").as<int>();
|
||||
player.set("health", {health + amount});
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto amount = SELECT_VALUE(
|
||||
game::Dvar_FindVar("g_player_maxhealth")->current.integer,
|
||||
atoi(game::Dvar_FindVar("scr_player_maxhealth")->current.string)
|
||||
);
|
||||
player.set("health", {amount});
|
||||
}
|
||||
}
|
||||
else if (arg == "all")
|
||||
{
|
||||
const auto type = game::XAssetType::ASSET_TYPE_WEAPON;
|
||||
fastfiles::enum_assets(type, [&player, type](const game::XAssetHeader header)
|
||||
{
|
||||
const auto asset = game::XAsset{type, header};
|
||||
const auto asset_name = game::DB_GetXAssetName(&asset);
|
||||
|
||||
player.call("giveweapon", {asset_name});
|
||||
}, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto wp = game::G_GetWeaponForName(arg.data());
|
||||
if (wp)
|
||||
{
|
||||
if (game::G_GivePlayerWeapon(ps, wp, 0, 0, 0, 0, 0, 0))
|
||||
{
|
||||
game::G_InitializeAmmo(ps, wp, 0);
|
||||
game::G_SelectWeapon(0, wp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
client_println(client_num, "Weapon does not exist");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void cmd_drop_weapon(int client_num)
|
||||
{
|
||||
try
|
||||
{
|
||||
const auto player = scripting::entity({static_cast<uint16_t>(client_num), 0});
|
||||
const auto weapon = player.call("getcurrentweapon");
|
||||
player.call("dropitem", {weapon});
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void cmd_take_weapon(int client_num, const std::vector<std::string>& params)
|
||||
{
|
||||
if (params.size() < 2)
|
||||
{
|
||||
client_println(client_num, "You did not specify a weapon name");
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& weapon = params[1];
|
||||
|
||||
try
|
||||
{
|
||||
const auto player = scripting::entity({static_cast<uint16_t>(client_num), 0});
|
||||
if (weapon == "all"s)
|
||||
{
|
||||
player.call("takeallweapons");
|
||||
}
|
||||
else
|
||||
{
|
||||
player.call("takeweapon", {weapon});
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void cmd_kill(int client_num)
|
||||
{
|
||||
scheduler::once([client_num]()
|
||||
{
|
||||
try
|
||||
{
|
||||
const auto player = scripting::entity({static_cast<uint16_t>(client_num), 0});
|
||||
player.call(SELECT_VALUE("kill", "suicide"));
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}, scheduler::pipeline::server);
|
||||
}
|
||||
|
||||
void toggle_entity_flag(int client_num, int value, const std::string& name)
|
||||
{
|
||||
game::mp::g_entities[client_num].flags ^= value;
|
||||
client_println(client_num, utils::string::va("%s %s",
|
||||
name.data(),
|
||||
game::mp::g_entities[client_num].flags & value
|
||||
? "^2on"
|
||||
: "^1off"));
|
||||
}
|
||||
|
||||
void toggle_entity_flag(int value, const std::string& name)
|
||||
{
|
||||
game::sp::g_entities[0].flags ^= value;
|
||||
client_println(0, utils::string::va("%s %s",
|
||||
name.data(),
|
||||
game::sp::g_entities[0].flags & value
|
||||
? "^2on"
|
||||
: "^1off"));
|
||||
}
|
||||
|
||||
void toggle_client_flag(int client_num, int value, const std::string& name)
|
||||
{
|
||||
game::mp::g_entities[client_num].client->flags ^= value;
|
||||
client_println(client_num, utils::string::va("%s %s",
|
||||
name.data(),
|
||||
game::mp::g_entities[client_num].client->flags & value
|
||||
? "^2on"
|
||||
: "^1off"));
|
||||
}
|
||||
|
||||
void toggle_client_flag(int value, const std::string& name)
|
||||
{
|
||||
game::sp::g_entities[0].client->flags ^= value;
|
||||
client_println(0, utils::string::va("%s %s",
|
||||
name.data(),
|
||||
game::sp::g_entities[0].client->flags & value
|
||||
? "^2on"
|
||||
: "^1off"));
|
||||
}
|
||||
}
|
||||
|
||||
void read_startup_variable(const std::string& dvar)
|
||||
@ -136,8 +360,8 @@ namespace command
|
||||
// parse the commandline if it's not parsed
|
||||
parse_command_line();
|
||||
|
||||
auto& com_num_console_lines = *reinterpret_cast<int*>(0x142623FB4); //H1(1.4)
|
||||
auto* com_console_lines = reinterpret_cast<char**>(0x142623FC0); //H1(1.4)
|
||||
auto& com_num_console_lines = *reinterpret_cast<int*>(0x35634B8_b);
|
||||
auto* com_console_lines = reinterpret_cast<char**>(0x35634C0_b);
|
||||
|
||||
for (int i = 0; i < com_num_console_lines; i++)
|
||||
{
|
||||
@ -185,6 +409,16 @@ namespace command
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::string> params::get_all() const
|
||||
{
|
||||
std::vector<std::string> params_;
|
||||
for (auto i = 0; i < this->size(); i++)
|
||||
{
|
||||
params_.push_back(this->get(i));
|
||||
}
|
||||
return params_;
|
||||
}
|
||||
|
||||
params_sv::params_sv()
|
||||
: nesting_(game::sv_cmd_args->nesting)
|
||||
{
|
||||
@ -217,6 +451,16 @@ namespace command
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::string> params_sv::get_all() const
|
||||
{
|
||||
std::vector<std::string> params_;
|
||||
for (auto i = 0; i < this->size(); i++)
|
||||
{
|
||||
params_.push_back(this->get(i));
|
||||
}
|
||||
return params_;
|
||||
}
|
||||
|
||||
void add_raw(const char* name, void (*callback)())
|
||||
{
|
||||
game::Cmd_AddCommandInternal(name, callback, utils::memory::get_allocator()->allocate<game::cmd_function_s>());
|
||||
@ -230,8 +474,6 @@ namespace command
|
||||
|
||||
void add(const char* name, const std::function<void(const params&)>& callback)
|
||||
{
|
||||
static game::cmd_function_s cmd_test;
|
||||
|
||||
const auto command = utils::string::to_lower(name);
|
||||
|
||||
if (handlers.find(command) == handlers.end())
|
||||
@ -243,9 +485,9 @@ namespace command
|
||||
void add(const char* name, const std::function<void()>& callback)
|
||||
{
|
||||
add(name, [callback](const params&)
|
||||
{
|
||||
callback();
|
||||
});
|
||||
{
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
void add_sv(const char* name, std::function<void(int, const params_sv&)> callback)
|
||||
@ -269,7 +511,7 @@ namespace command
|
||||
}
|
||||
else
|
||||
{
|
||||
game::Cbuf_AddText(0, command.data());
|
||||
game::Cbuf_AddText(0, 0, command.data());
|
||||
}
|
||||
}
|
||||
|
||||
@ -284,12 +526,12 @@ namespace command
|
||||
}
|
||||
else
|
||||
{
|
||||
utils::hook::call(0x1400D728F, &parse_commandline_stub); // MWR TEST
|
||||
utils::hook::jump(0x14041D750, dvar_command_stub);
|
||||
|
||||
parse_commandline_hook.create(0x157D50_b, parse_commandline_stub);
|
||||
add_commands_mp();
|
||||
}
|
||||
|
||||
utils::hook::jump(SELECT_VALUE(0x3A7C80_b, 0x4E9F40_b), dvar_command_stub, true);
|
||||
|
||||
add_commands_generic();
|
||||
}
|
||||
|
||||
@ -297,35 +539,11 @@ namespace command
|
||||
static void add_commands_generic()
|
||||
{
|
||||
add("quit", game::Quit);
|
||||
//add("quit_hard", utils::nt::raise_hard_exception); /* this command delivers you to a windows blue screen, its quit hard from windows xD */
|
||||
add("crash", []()
|
||||
{
|
||||
*reinterpret_cast<int*>(1) = 0;
|
||||
});
|
||||
|
||||
/*add("consoleList", [](const params& params)
|
||||
{
|
||||
const std::string input = params.get(1);
|
||||
|
||||
std::vector<std::string> matches;
|
||||
game_console::find_matches(input, matches, false);
|
||||
|
||||
for (auto& match : matches)
|
||||
{
|
||||
auto* dvar = game::Dvar_FindVar(match.c_str());
|
||||
if (!dvar)
|
||||
{
|
||||
console::info("[CMD]\t %s\n", match.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
console::info("[DVAR]\t%s \"%s\"\n", match.c_str(), game::Dvar_ValueToString(dvar, dvar->current, 0));
|
||||
}
|
||||
}
|
||||
|
||||
console::info("Total %i matches\n", matches.size());
|
||||
});*/
|
||||
|
||||
add("commandDump", [](const params& argument)
|
||||
{
|
||||
console::info("================================ COMMAND DUMP =====================================\n");
|
||||
@ -359,7 +577,7 @@ namespace command
|
||||
console::info("================================ END COMMAND DUMP =================================\n");
|
||||
});
|
||||
|
||||
/*add("listassetpool", [](const params& params)
|
||||
add("listassetpool", [](const params& params)
|
||||
{
|
||||
if (params.size() < 2)
|
||||
{
|
||||
@ -383,14 +601,14 @@ namespace command
|
||||
console::info("Listing assets in pool %s\n", game::g_assetNames[type]);
|
||||
|
||||
const std::string filter = params.get(2);
|
||||
enum_assets(type, [type, filter](const game::XAssetHeader header)
|
||||
fastfiles::enum_assets(type, [type, filter](const game::XAssetHeader header)
|
||||
{
|
||||
const auto asset = game::XAsset{type, header};
|
||||
const auto* const asset_name = game::DB_GetXAssetName(&asset);
|
||||
//const auto entry = game::DB_FindXAssetEntry(type, asset_name);
|
||||
//TODO: display which zone the asset is from
|
||||
|
||||
if (!filter.empty() && !game_console::match_compare(filter, asset_name, false))
|
||||
if (!filter.empty() && !utils::string::match_compare(filter, asset_name, false))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -408,24 +626,24 @@ namespace command
|
||||
return;
|
||||
}
|
||||
|
||||
const auto* dvarName = params.get(1);
|
||||
const auto* dvar = game::Dvar_FindVar(dvarName);
|
||||
const auto name = params.get(1);
|
||||
const auto dvar = game::Dvar_FindVar(name);
|
||||
|
||||
if (dvar == nullptr)
|
||||
{
|
||||
console::info("%s doesn't exist\n", dvarName);
|
||||
console::info("%s doesn't exist\n", name);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dvar->type != game::dvar_type::string
|
||||
&& dvar->type != game::dvar_type::enumeration)
|
||||
{
|
||||
console::info("%s is not a string-based dvar\n", dvar->hash);
|
||||
console::info("%s is not a string-based dvar\n", name);
|
||||
return;
|
||||
}
|
||||
|
||||
execute(dvar->current.string);
|
||||
});*/
|
||||
});
|
||||
}
|
||||
|
||||
static void add_commands_sp()
|
||||
@ -437,11 +655,7 @@ namespace command
|
||||
return;
|
||||
}
|
||||
|
||||
game::sp::g_entities[0].flags ^= 1;
|
||||
game::CG_GameMessage(0, utils::string::va("godmode %s",
|
||||
game::sp::g_entities[0].flags & 1
|
||||
? "^2on"
|
||||
: "^1off"));
|
||||
toggle_entity_flag(1, "godmode");
|
||||
});
|
||||
|
||||
add("demigod", []()
|
||||
@ -451,11 +665,7 @@ namespace command
|
||||
return;
|
||||
}
|
||||
|
||||
game::sp::g_entities[0].flags ^= 2;
|
||||
game::CG_GameMessage(0, utils::string::va("demigod mode %s",
|
||||
game::sp::g_entities[0].flags & 2
|
||||
? "^2on"
|
||||
: "^1off"));
|
||||
toggle_entity_flag(2, "demigod mode");
|
||||
});
|
||||
|
||||
add("notarget", []()
|
||||
@ -465,11 +675,7 @@ namespace command
|
||||
return;
|
||||
}
|
||||
|
||||
game::sp::g_entities[0].flags ^= 4;
|
||||
game::CG_GameMessage(0, utils::string::va("notarget %s",
|
||||
game::sp::g_entities[0].flags & 4
|
||||
? "^2on"
|
||||
: "^1off"));
|
||||
toggle_entity_flag(4, "notarget");
|
||||
});
|
||||
|
||||
add("noclip", []()
|
||||
@ -479,11 +685,7 @@ namespace command
|
||||
return;
|
||||
}
|
||||
|
||||
game::sp::g_entities[0].client->flags ^= 1;
|
||||
game::CG_GameMessage(0, utils::string::va("noclip %s",
|
||||
game::sp::g_entities[0].client->flags & 1
|
||||
? "^2on"
|
||||
: "^1off"));
|
||||
toggle_client_flag(1, "noclip");
|
||||
});
|
||||
|
||||
add("ufo", []()
|
||||
@ -493,154 +695,143 @@ namespace command
|
||||
return;
|
||||
}
|
||||
|
||||
game::sp::g_entities[0].client->flags ^= 2;
|
||||
game::CG_GameMessage(0, utils::string::va("ufo %s",
|
||||
game::sp::g_entities[0].client->flags & 2
|
||||
? "^2on"
|
||||
: "^1off"));
|
||||
toggle_client_flag(2, "ufo");
|
||||
});
|
||||
|
||||
add("dropweapon", [](const params& params)
|
||||
{
|
||||
if (!game::SV_Loaded())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
cmd_drop_weapon(0);
|
||||
});
|
||||
|
||||
add("take", [](const params& params)
|
||||
{
|
||||
if (!game::SV_Loaded())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
cmd_take_weapon(0, params.get_all());
|
||||
});
|
||||
|
||||
add("kill", [](const params& params)
|
||||
{
|
||||
if (!game::SV_Loaded())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
cmd_kill(0);
|
||||
});
|
||||
|
||||
add("give", [](const params& params)
|
||||
{
|
||||
if (!game::SV_Loaded())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
cmd_give_weapon(0, params.get_all());
|
||||
});
|
||||
}
|
||||
|
||||
static void add_commands_mp()
|
||||
{
|
||||
//client_command_hook.create(0x1402E98F0, &client_command);
|
||||
client_command_hook.create(0x4132E0_b, &client_command);
|
||||
|
||||
/*add_sv("god", [](const int client_num, const params_sv&)
|
||||
add_sv("god", [](const int client_num, const params_sv&)
|
||||
{
|
||||
if (!game::Dvar_FindVar("sv_cheats")->current.enabled)
|
||||
if (!check_cheats(client_num))
|
||||
{
|
||||
game::SV_GameSendServerCommand(client_num, game::SV_CMD_RELIABLE,
|
||||
"f \"Cheats are not enabled on this server\"");
|
||||
return;
|
||||
}
|
||||
|
||||
game::mp::g_entities[client_num].flags ^= 1;
|
||||
game::SV_GameSendServerCommand(client_num, game::SV_CMD_RELIABLE,
|
||||
utils::string::va("f \"godmode %s\"",
|
||||
game::mp::g_entities[client_num].flags & 1
|
||||
? "^2on"
|
||||
: "^1off"));
|
||||
toggle_entity_flag(client_num, 1, "godmode");
|
||||
});
|
||||
|
||||
add_sv("demigod", [](const int client_num, const params_sv&)
|
||||
{
|
||||
if (!game::Dvar_FindVar("sv_cheats")->current.enabled)
|
||||
if (!check_cheats(client_num))
|
||||
{
|
||||
game::SV_GameSendServerCommand(client_num, game::SV_CMD_RELIABLE,
|
||||
"f \"Cheats are not enabled on this server\"");
|
||||
return;
|
||||
}
|
||||
|
||||
game::mp::g_entities[client_num].flags ^= 2;
|
||||
game::SV_GameSendServerCommand(client_num, game::SV_CMD_RELIABLE,
|
||||
utils::string::va("f \"demigod mode %s\"",
|
||||
game::mp::g_entities[client_num].flags & 2
|
||||
? "^2on"
|
||||
: "^1off"));
|
||||
toggle_entity_flag(client_num, 2, "demigod mode");
|
||||
});
|
||||
|
||||
add_sv("notarget", [](const int client_num, const params_sv&)
|
||||
{
|
||||
if (!game::Dvar_FindVar("sv_cheats")->current.enabled)
|
||||
if (!check_cheats(client_num))
|
||||
{
|
||||
game::SV_GameSendServerCommand(client_num, game::SV_CMD_RELIABLE,
|
||||
"f \"Cheats are not enabled on this server\"");
|
||||
return;
|
||||
}
|
||||
|
||||
game::mp::g_entities[client_num].flags ^= 4;
|
||||
game::SV_GameSendServerCommand(client_num, game::SV_CMD_RELIABLE,
|
||||
utils::string::va("f \"notarget %s\"",
|
||||
game::mp::g_entities[client_num].flags & 4
|
||||
? "^2on"
|
||||
: "^1off"));
|
||||
toggle_entity_flag(client_num, 4, "notarget");
|
||||
});
|
||||
|
||||
add_sv("noclip", [](const int client_num, const params_sv&)
|
||||
{
|
||||
if (!game::Dvar_FindVar("sv_cheats")->current.enabled)
|
||||
if (!check_cheats(client_num))
|
||||
{
|
||||
game::SV_GameSendServerCommand(client_num, game::SV_CMD_RELIABLE,
|
||||
"f \"Cheats are not enabled on this server\"");
|
||||
return;
|
||||
}
|
||||
|
||||
game::mp::g_entities[client_num].client->flags ^= 1;
|
||||
game::SV_GameSendServerCommand(client_num, game::SV_CMD_RELIABLE,
|
||||
utils::string::va("f \"noclip %s\"",
|
||||
game::mp::g_entities[client_num].client->flags & 1
|
||||
? "^2on"
|
||||
: "^1off"));
|
||||
toggle_client_flag(client_num, 1, "noclip");
|
||||
});
|
||||
|
||||
add_sv("ufo", [](const int client_num, const params_sv&)
|
||||
{
|
||||
if (!game::Dvar_FindVar("sv_cheats")->current.enabled)
|
||||
if (!check_cheats(client_num))
|
||||
{
|
||||
game::SV_GameSendServerCommand(client_num, game::SV_CMD_RELIABLE,
|
||||
"f \"Cheats are not enabled on this server\"");
|
||||
return;
|
||||
}
|
||||
|
||||
game::mp::g_entities[client_num].client->flags ^= 2;
|
||||
game::SV_GameSendServerCommand(client_num, game::SV_CMD_RELIABLE,
|
||||
utils::string::va("f \"ufo %s\"",
|
||||
game::mp::g_entities[client_num].client->flags & 2
|
||||
? "^2on"
|
||||
: "^1off"));
|
||||
toggle_client_flag(client_num, 2, "ufo");
|
||||
});
|
||||
|
||||
add_sv("give", [](const int client_num, const params_sv& params)
|
||||
{
|
||||
if (!game::Dvar_FindVar("sv_cheats")->current.enabled)
|
||||
if (!check_cheats(client_num))
|
||||
{
|
||||
game::SV_GameSendServerCommand(client_num, game::SV_CMD_RELIABLE,
|
||||
"f \"Cheats are not enabled on this server\"");
|
||||
return;
|
||||
}
|
||||
|
||||
if (params.size() < 2)
|
||||
cmd_give_weapon(client_num, params.get_all());
|
||||
});
|
||||
|
||||
add_sv("dropweapon", [](const int client_num, const params_sv& params)
|
||||
{
|
||||
if (!check_cheats(client_num))
|
||||
{
|
||||
game::SV_GameSendServerCommand(client_num, game::SV_CMD_RELIABLE,
|
||||
"f \"You did not specify a weapon name\"");
|
||||
return;
|
||||
}
|
||||
|
||||
auto ps = game::SV_GetPlayerstateForClientNum(client_num);
|
||||
const auto wp = game::G_GetWeaponForName(params.get(1));
|
||||
if (wp)
|
||||
{
|
||||
if (game::G_GivePlayerWeapon(ps, wp, 0, 0, 0, 0, 0, 0))
|
||||
{
|
||||
game::G_InitializeAmmo(ps, wp, 0);
|
||||
game::G_SelectWeapon(client_num, wp);
|
||||
}
|
||||
}
|
||||
cmd_drop_weapon(client_num);
|
||||
});
|
||||
|
||||
add_sv("take", [](const int client_num, const params_sv& params)
|
||||
{
|
||||
if (!game::Dvar_FindVar("sv_cheats")->current.enabled)
|
||||
if (!check_cheats(client_num))
|
||||
{
|
||||
game::SV_GameSendServerCommand(client_num, game::SV_CMD_RELIABLE,
|
||||
"f \"Cheats are not enabled on this server\"");
|
||||
return;
|
||||
}
|
||||
|
||||
if (params.size() < 2)
|
||||
cmd_take_weapon(client_num, params.get_all());
|
||||
});
|
||||
|
||||
add_sv("kill", [](const int client_num, const params_sv& params)
|
||||
{
|
||||
if (!check_cheats(client_num))
|
||||
{
|
||||
game::SV_GameSendServerCommand(client_num, game::SV_CMD_RELIABLE,
|
||||
"f \"You did not specify a weapon name\"");
|
||||
return;
|
||||
}
|
||||
|
||||
auto ps = game::SV_GetPlayerstateForClientNum(client_num);
|
||||
const auto wp = game::G_GetWeaponForName(params.get(1));
|
||||
if (wp)
|
||||
{
|
||||
game::G_TakePlayerWeapon(ps, wp);
|
||||
}
|
||||
});*/
|
||||
cmd_kill(client_num);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ namespace command
|
||||
int size() const;
|
||||
const char* get(int index) const;
|
||||
std::string join(int index) const;
|
||||
std::vector<std::string> get_all() const;
|
||||
|
||||
const char* operator[](const int index) const
|
||||
{
|
||||
@ -28,6 +29,7 @@ namespace command
|
||||
int size() const;
|
||||
const char* get(int index) const;
|
||||
std::string join(int index) const;
|
||||
std::vector<std::string> get_all() const;
|
||||
|
||||
const char* operator[](const int index) const
|
||||
{
|
||||
|
@ -1,14 +1,18 @@
|
||||
#include <std_include.hpp>
|
||||
#include "console.hpp"
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "game/game.hpp"
|
||||
|
||||
#include "command.hpp"
|
||||
#include "rcon.hpp"
|
||||
#include "version.hpp"
|
||||
|
||||
#include <utils/thread.hpp>
|
||||
#include <utils/flags.hpp>
|
||||
#include <utils/concurrency.hpp>
|
||||
#include <utils/hook.hpp>
|
||||
|
||||
#define OUTPUT_HANDLE GetStdHandle(STD_OUTPUT_HANDLE)
|
||||
|
||||
namespace game_console
|
||||
{
|
||||
void print(int type, const std::string& data);
|
||||
@ -18,26 +22,40 @@ namespace console
|
||||
{
|
||||
namespace
|
||||
{
|
||||
using message_queue = std::queue<std::string>;
|
||||
utils::concurrency::container<message_queue> messages;
|
||||
utils::hook::detour printf_hook;
|
||||
std::recursive_mutex print_mutex;
|
||||
|
||||
bool native_console()
|
||||
struct
|
||||
{
|
||||
static const auto flag = utils::flags::has_flag("nativeconsole");
|
||||
return flag;
|
||||
bool kill;
|
||||
std::thread thread;
|
||||
HANDLE kill_event;
|
||||
char buffer[512]{};
|
||||
int cursor;
|
||||
std::int32_t history_index = -1;
|
||||
std::deque<std::string> history{};
|
||||
} con{};
|
||||
|
||||
void set_cursor_pos(int x)
|
||||
{
|
||||
CONSOLE_SCREEN_BUFFER_INFO info{};
|
||||
GetConsoleScreenBufferInfo(OUTPUT_HANDLE, &info);
|
||||
info.dwCursorPosition.X = static_cast<short>(x);
|
||||
SetConsoleCursorPosition(OUTPUT_HANDLE, info.dwCursorPosition);
|
||||
}
|
||||
|
||||
void hide_console()
|
||||
void show_cursor(const bool show)
|
||||
{
|
||||
auto* const con_window = GetConsoleWindow();
|
||||
CONSOLE_CURSOR_INFO info{};
|
||||
GetConsoleCursorInfo(OUTPUT_HANDLE, &info);
|
||||
info.bVisible = show;
|
||||
SetConsoleCursorInfo(OUTPUT_HANDLE, &info);
|
||||
}
|
||||
|
||||
DWORD process;
|
||||
GetWindowThreadProcessId(con_window, &process);
|
||||
|
||||
if (!native_console() && (process == GetCurrentProcessId() || IsDebuggerPresent()))
|
||||
{
|
||||
ShowWindow(con_window, SW_HIDE);
|
||||
}
|
||||
template <typename... Args>
|
||||
int invoke_printf(const char* fmt, Args&&... args)
|
||||
{
|
||||
return printf_hook.invoke<int>(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
std::string format(va_list* ap, const char* message)
|
||||
@ -45,244 +63,268 @@ namespace console
|
||||
static thread_local char buffer[0x1000];
|
||||
|
||||
const auto count = _vsnprintf_s(buffer, sizeof(buffer), sizeof(buffer), message, *ap);
|
||||
if (count < 0)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
if (count < 0) return {};
|
||||
return {buffer, static_cast<size_t>(count)};
|
||||
}
|
||||
|
||||
void dispatch_message(const int type, const std::string& message)
|
||||
uint8_t get_attribute(const int type)
|
||||
{
|
||||
if (native_console())
|
||||
switch (type)
|
||||
{
|
||||
printf("%s\n", message.data());
|
||||
case con_type_info:
|
||||
return 7; // white
|
||||
case con_type_warning:
|
||||
return 6; // yellow
|
||||
case con_type_error:
|
||||
return 4; // red
|
||||
case con_type_debug:
|
||||
return 3; // cyan
|
||||
}
|
||||
|
||||
return 7;
|
||||
}
|
||||
|
||||
void update()
|
||||
{
|
||||
std::lock_guard _0(print_mutex);
|
||||
|
||||
show_cursor(false);
|
||||
set_cursor_pos(0);
|
||||
invoke_printf("%s", con.buffer);
|
||||
set_cursor_pos(con.cursor);
|
||||
show_cursor(true);
|
||||
}
|
||||
|
||||
void clear_output()
|
||||
{
|
||||
std::lock_guard _0(print_mutex);
|
||||
|
||||
show_cursor(false);
|
||||
set_cursor_pos(0);
|
||||
|
||||
for (auto i = 0; i < std::strlen(con.buffer); i++)
|
||||
{
|
||||
invoke_printf(" ");
|
||||
}
|
||||
|
||||
set_cursor_pos(con.cursor);
|
||||
show_cursor(true);
|
||||
}
|
||||
|
||||
int dispatch_message(const int type, const std::string& message)
|
||||
{
|
||||
if (rcon::message_redirect(message))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::lock_guard _0(print_mutex);
|
||||
|
||||
clear_output();
|
||||
set_cursor_pos(0);
|
||||
|
||||
SetConsoleTextAttribute(OUTPUT_HANDLE, get_attribute(type));
|
||||
const auto res = invoke_printf("%s", message.data());
|
||||
SetConsoleTextAttribute(OUTPUT_HANDLE, get_attribute(con_type_info));
|
||||
|
||||
game_console::print(type, message);
|
||||
|
||||
if (message.size() <= 0 || message[message.size() - 1] != '\n')
|
||||
{
|
||||
invoke_printf("\n");
|
||||
}
|
||||
|
||||
update();
|
||||
return res;
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
std::lock_guard _0(print_mutex);
|
||||
|
||||
clear_output();
|
||||
strncpy_s(con.buffer, "", sizeof(con.buffer));
|
||||
|
||||
con.cursor = 0;
|
||||
set_cursor_pos(0);
|
||||
}
|
||||
|
||||
size_t get_max_input_length()
|
||||
{
|
||||
CONSOLE_SCREEN_BUFFER_INFO info{};
|
||||
GetConsoleScreenBufferInfo(OUTPUT_HANDLE, &info);
|
||||
const auto columns = static_cast<size_t>(info.srWindow.Right - info.srWindow.Left - 1);
|
||||
return std::max(size_t(0), std::min(columns, sizeof(con.buffer)));
|
||||
}
|
||||
|
||||
void handle_resize()
|
||||
{
|
||||
clear();
|
||||
update();
|
||||
}
|
||||
|
||||
void handle_input(const INPUT_RECORD record)
|
||||
{
|
||||
if (record.EventType == WINDOW_BUFFER_SIZE_EVENT)
|
||||
{
|
||||
handle_resize();
|
||||
return;
|
||||
}
|
||||
|
||||
game_console::print(type, message);
|
||||
messages.access([&message](message_queue& msgs)
|
||||
if (record.EventType != KEY_EVENT || !record.Event.KeyEvent.bKeyDown)
|
||||
{
|
||||
msgs.emplace(message);
|
||||
});
|
||||
}
|
||||
|
||||
void append_text(const char* text)
|
||||
{
|
||||
dispatch_message(con_type_info, text);
|
||||
}
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
component()
|
||||
{
|
||||
hide_console();
|
||||
|
||||
if (native_console())
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
setvbuf(stderr, nullptr, _IONBF, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
(void)_pipe(this->handles_, 1024, _O_TEXT);
|
||||
(void)_dup2(this->handles_[1], 1);
|
||||
(void)_dup2(this->handles_[1], 2);
|
||||
}
|
||||
}
|
||||
|
||||
void post_start() override
|
||||
{
|
||||
this->terminate_runner_ = false;
|
||||
|
||||
this->console_runner_ = utils::thread::create_named_thread("Console IO", [this]
|
||||
{
|
||||
if (native_console())
|
||||
{
|
||||
this->native_input();
|
||||
}
|
||||
else
|
||||
{
|
||||
this->runner();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void pre_destroy() override
|
||||
{
|
||||
this->terminate_runner_ = true;
|
||||
|
||||
printf("\r\n");
|
||||
_flushall();
|
||||
|
||||
if (this->console_runner_.joinable())
|
||||
{
|
||||
this->console_runner_.join();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->console_thread_.joinable())
|
||||
std::lock_guard _0(print_mutex);
|
||||
|
||||
const auto key = record.Event.KeyEvent.wVirtualKeyCode;
|
||||
switch (key)
|
||||
{
|
||||
this->console_thread_.join();
|
||||
case VK_UP:
|
||||
{
|
||||
if (++con.history_index >= con.history.size())
|
||||
{
|
||||
con.history_index = static_cast<int>(con.history.size()) - 1;
|
||||
}
|
||||
|
||||
clear();
|
||||
|
||||
if (con.history_index != -1)
|
||||
{
|
||||
strncpy_s(con.buffer, con.history.at(con.history_index).data(), sizeof(con.buffer));
|
||||
con.cursor = static_cast<int>(strlen(con.buffer));
|
||||
}
|
||||
|
||||
update();
|
||||
break;
|
||||
}
|
||||
|
||||
#ifndef NATIVE_CONSOLE
|
||||
_close(this->handles_[0]);
|
||||
_close(this->handles_[1]);
|
||||
#endif
|
||||
|
||||
messages.access([&](message_queue& msgs)
|
||||
case VK_DOWN:
|
||||
{
|
||||
msgs = {};
|
||||
});
|
||||
}
|
||||
|
||||
void post_unpack() override
|
||||
{
|
||||
// Redirect input (]command)
|
||||
utils::hook::jump(SELECT_VALUE(0x1403E34C0, 0x1405141E0), append_text); // H1(1.4)
|
||||
|
||||
this->initialize();
|
||||
}
|
||||
|
||||
private:
|
||||
volatile bool console_initialized_ = false;
|
||||
volatile bool terminate_runner_ = false;
|
||||
|
||||
std::thread console_runner_;
|
||||
std::thread console_thread_;
|
||||
|
||||
int handles_[2]{};
|
||||
|
||||
void initialize()
|
||||
{
|
||||
this->console_thread_ = utils::thread::create_named_thread("Console", [this]()
|
||||
{
|
||||
if (!native_console() && (game::environment::is_dedi() || !utils::flags::has_flag("noconsole")))
|
||||
if (--con.history_index < -1)
|
||||
{
|
||||
game::Sys_ShowConsole();
|
||||
con.history_index = -1;
|
||||
}
|
||||
|
||||
if (!game::environment::is_dedi())
|
||||
clear();
|
||||
|
||||
if (con.history_index != -1)
|
||||
{
|
||||
// Hide that shit
|
||||
ShowWindow(console::get_window(), SW_MINIMIZE);
|
||||
strncpy_s(con.buffer, con.history.at(con.history_index).data(), sizeof(con.buffer));
|
||||
con.cursor = static_cast<int>(strlen(con.buffer));
|
||||
}
|
||||
|
||||
update();
|
||||
break;
|
||||
}
|
||||
case VK_LEFT:
|
||||
{
|
||||
if (con.cursor > 0)
|
||||
{
|
||||
messages.access([&](message_queue&)
|
||||
con.cursor--;
|
||||
set_cursor_pos(con.cursor);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case VK_RIGHT:
|
||||
{
|
||||
if (con.cursor < std::strlen(con.buffer))
|
||||
{
|
||||
con.cursor++;
|
||||
set_cursor_pos(con.cursor);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case VK_RETURN:
|
||||
{
|
||||
if (con.history_index != -1)
|
||||
{
|
||||
const auto itr = con.history.begin() + con.history_index;
|
||||
|
||||
if (*itr == con.buffer)
|
||||
{
|
||||
this->console_initialized_ = true;
|
||||
});
|
||||
}
|
||||
|
||||
MSG msg;
|
||||
while (!this->terminate_runner_)
|
||||
{
|
||||
if (PeekMessageA(&msg, nullptr, NULL, NULL, PM_REMOVE))
|
||||
{
|
||||
if (msg.message == WM_QUIT)
|
||||
{
|
||||
command::execute("quit", false);
|
||||
break;
|
||||
}
|
||||
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->log_messages();
|
||||
std::this_thread::sleep_for(1ms);
|
||||
con.history.erase(con.history.begin() + con.history_index);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void log_messages()
|
||||
{
|
||||
/*while*/
|
||||
if (this->console_initialized_ && !messages.get_raw().empty())
|
||||
{
|
||||
std::queue<std::string> message_queue_copy;
|
||||
|
||||
if (con.buffer[0])
|
||||
{
|
||||
messages.access([&](message_queue& msgs)
|
||||
{
|
||||
message_queue_copy = std::move(msgs);
|
||||
msgs = {};
|
||||
});
|
||||
con.history.push_front(con.buffer);
|
||||
}
|
||||
|
||||
while (!message_queue_copy.empty())
|
||||
if (con.history.size() > 10)
|
||||
{
|
||||
log_message(message_queue_copy.front());
|
||||
message_queue_copy.pop();
|
||||
con.history.erase(con.history.begin() + 10);
|
||||
}
|
||||
|
||||
con.history_index = -1;
|
||||
|
||||
game::Cbuf_AddText(0, 0, con.buffer);
|
||||
|
||||
con.cursor = 0;
|
||||
|
||||
clear_output();
|
||||
SetConsoleTextAttribute(OUTPUT_HANDLE, get_attribute(7)); // green
|
||||
invoke_printf("]%s\r\n", con.buffer);
|
||||
SetConsoleTextAttribute(OUTPUT_HANDLE, get_attribute(con_type_info));
|
||||
strncpy_s(con.buffer, "", sizeof(con.buffer));
|
||||
break;
|
||||
}
|
||||
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
static void log_message(const std::string& message)
|
||||
{
|
||||
OutputDebugStringA(message.data());
|
||||
game::Conbuf_AppendText(message.data());
|
||||
}
|
||||
|
||||
void runner()
|
||||
{
|
||||
char buffer[1024];
|
||||
|
||||
while (!this->terminate_runner_ && this->handles_[0])
|
||||
case VK_BACK:
|
||||
{
|
||||
const auto len = _read(this->handles_[0], buffer, sizeof(buffer));
|
||||
if (len > 0)
|
||||
if (con.cursor <= 0)
|
||||
{
|
||||
dispatch_message(con_type_info, std::string(buffer, len));
|
||||
}
|
||||
else
|
||||
{
|
||||
std::this_thread::sleep_for(1ms);
|
||||
break;
|
||||
}
|
||||
|
||||
clear_output();
|
||||
|
||||
std::memmove(con.buffer + con.cursor - 1, con.buffer + con.cursor,
|
||||
strlen(con.buffer) + 1 - con.cursor);
|
||||
con.cursor--;
|
||||
|
||||
update();
|
||||
break;
|
||||
}
|
||||
|
||||
std::this_thread::yield();
|
||||
}
|
||||
|
||||
void native_input()
|
||||
{
|
||||
std::string cmd;
|
||||
|
||||
while (!this->terminate_runner_)
|
||||
default:
|
||||
{
|
||||
std::getline(std::cin, cmd);
|
||||
command::execute(cmd);
|
||||
const auto c = record.Event.KeyEvent.uChar.AsciiChar;
|
||||
if (!c)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (std::strlen(con.buffer) + 1 >= get_max_input_length())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
std::memmove(con.buffer + con.cursor + 1,
|
||||
con.buffer + con.cursor, std::strlen(con.buffer) + 1 - con.cursor);
|
||||
con.buffer[con.cursor] = c;
|
||||
con.cursor++;
|
||||
|
||||
update();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::this_thread::yield();
|
||||
}
|
||||
};
|
||||
|
||||
HWND get_window()
|
||||
{
|
||||
return *reinterpret_cast<HWND*>((SELECT_VALUE(0x14CF56C00, 0x14DDFC2D0))); // H1(1.4)
|
||||
}
|
||||
int __cdecl printf_stub(const char* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
const auto result = format(&ap, fmt);
|
||||
va_end(ap);
|
||||
|
||||
void set_title(std::string title)
|
||||
{
|
||||
SetWindowText(get_window(), title.data());
|
||||
}
|
||||
|
||||
void set_size(const int width, const int height)
|
||||
{
|
||||
RECT rect;
|
||||
GetWindowRect(get_window(), &rect);
|
||||
|
||||
SetWindowPos(get_window(), nullptr, rect.left, rect.top, width, height, 0);
|
||||
|
||||
auto* const logo_window = *reinterpret_cast<HWND*>(SELECT_VALUE(0x14CF56C10, 0x14DDFC2E0)); // H1(1.4)
|
||||
SetWindowPos(logo_window, nullptr, 5, 5, width - 25, 60, 0);
|
||||
return dispatch_message(con_type_info, result);
|
||||
}
|
||||
}
|
||||
|
||||
void print(const int type, const char* fmt, ...)
|
||||
@ -294,6 +336,86 @@ namespace console
|
||||
|
||||
dispatch_message(type, result);
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
component()
|
||||
{
|
||||
ShowWindow(GetConsoleWindow(), SW_HIDE);
|
||||
}
|
||||
|
||||
void post_unpack() override
|
||||
{
|
||||
printf_hook.create(printf, printf_stub);
|
||||
|
||||
ShowWindow(GetConsoleWindow(), SW_SHOW);
|
||||
SetConsoleTitle("H1-Mod: " VERSION);
|
||||
|
||||
con.kill_event = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
|
||||
con.thread = utils::thread::create_named_thread("Console", []()
|
||||
{
|
||||
const auto handle = GetStdHandle(STD_INPUT_HANDLE);
|
||||
HANDLE handles[2] = {handle, con.kill_event};
|
||||
MSG msg{};
|
||||
|
||||
INPUT_RECORD record{};
|
||||
DWORD num_events{};
|
||||
|
||||
while (!con.kill)
|
||||
{
|
||||
const auto result = MsgWaitForMultipleObjects(2, handles, FALSE, INFINITE, QS_ALLINPUT);
|
||||
if (con.kill)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (result)
|
||||
{
|
||||
case WAIT_OBJECT_0:
|
||||
{
|
||||
if (!ReadConsoleInput(handle, &record, 1, &num_events) || num_events == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
handle_input(record);
|
||||
break;
|
||||
}
|
||||
case WAIT_OBJECT_0 + 1:
|
||||
{
|
||||
if (!PeekMessageA(&msg, GetConsoleWindow(), NULL, NULL, PM_REMOVE))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (msg.message == WM_QUIT)
|
||||
{
|
||||
command::execute("quit", false);
|
||||
break;
|
||||
}
|
||||
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void pre_destroy() override
|
||||
{
|
||||
con.kill = true;
|
||||
SetEvent(con.kill_event);
|
||||
|
||||
if (con.thread.joinable())
|
||||
{
|
||||
con.thread.join();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(console::component)
|
||||
|
@ -9,6 +9,7 @@ namespace console
|
||||
enum console_type
|
||||
{
|
||||
con_type_error = 1,
|
||||
con_type_debug = 2,
|
||||
con_type_warning = 3,
|
||||
con_type_info = 7
|
||||
};
|
||||
@ -21,6 +22,14 @@ namespace console
|
||||
print(con_type_error, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void debug(const char* fmt, Args&&... args)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
print(con_type_debug, fmt, std::forward<Args>(args)...);
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void warn(const char* fmt, Args&&... args)
|
||||
{
|
||||
|
@ -26,7 +26,7 @@ namespace dedicated
|
||||
initialized = true;
|
||||
|
||||
// R_LoadGraphicsAssets
|
||||
reinterpret_cast<void(*)()>(0x1405DF4B0)();
|
||||
utils::hook::invoke<void>(0x686310_b);
|
||||
}
|
||||
|
||||
void send_heartbeat()
|
||||
@ -83,8 +83,8 @@ namespace dedicated
|
||||
{
|
||||
if (game::Live_SyncOnlineDataFlags(0) == 0)
|
||||
{
|
||||
game::Cbuf_AddText(client, command);
|
||||
game::Cbuf_AddText(client, "\n");
|
||||
game::Cbuf_AddText(client, 0, command);
|
||||
game::Cbuf_AddText(client, 0, "\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -99,8 +99,8 @@ namespace dedicated
|
||||
|
||||
for (const auto& command : queue)
|
||||
{
|
||||
game::Cbuf_AddText(0, command.data());
|
||||
game::Cbuf_AddText(0, "\n");
|
||||
game::Cbuf_AddText(0, 0, command.data());
|
||||
game::Cbuf_AddText(0, 0, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,12 +126,16 @@ namespace dedicated
|
||||
|
||||
void kill_server()
|
||||
{
|
||||
for (auto i = 0; i < *game::mp::svs_numclients; ++i)
|
||||
const auto* svs_clients = *game::mp::svs_clients;
|
||||
if (svs_clients != nullptr)
|
||||
{
|
||||
if (game::mp::svs_clients[i].header.state >= 3)
|
||||
for (auto i = 0; i < *game::mp::svs_numclients; ++i)
|
||||
{
|
||||
game::SV_GameSendServerCommand(i, game::SV_CMD_CAN_IGNORE,
|
||||
utils::string::va("r \"%s\"", "EXE_ENDOFGAME"));
|
||||
if (svs_clients[i].header.state >= 3)
|
||||
{
|
||||
game::SV_GameSendServerCommand(i, game::SV_CMD_CAN_IGNORE,
|
||||
utils::string::va("r \"%s\"", "EXE_ENDOFGAME"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -156,6 +160,23 @@ namespace dedicated
|
||||
|
||||
game::Com_Error(game::ERR_DROP, "%s", buffer);
|
||||
}
|
||||
|
||||
utils::hook::detour ui_set_active_menu_hook;
|
||||
void ui_set_active_menu_stub(void* localClientNum, int menu)
|
||||
{
|
||||
static auto done = false;
|
||||
if (done && (menu == 6 || menu == 7))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (menu == 6 || menu == 7)
|
||||
{
|
||||
done = true;
|
||||
}
|
||||
|
||||
ui_set_active_menu_hook.invoke<void>(localClientNum, menu);
|
||||
}
|
||||
}
|
||||
|
||||
void initialize()
|
||||
@ -185,10 +206,10 @@ namespace dedicated
|
||||
#endif
|
||||
|
||||
// Register dedicated dvar
|
||||
dvars::register_bool("dedicated", true, game::DVAR_FLAG_READ);
|
||||
dvars::register_bool("dedicated", true, game::DVAR_FLAG_READ, "Dedicated server");
|
||||
|
||||
// Add lanonly mode
|
||||
dvars::register_bool("sv_lanOnly", false, game::DVAR_FLAG_NONE);
|
||||
dvars::register_bool("sv_lanOnly", false, game::DVAR_FLAG_NONE, "Don't send heartbeat");
|
||||
|
||||
// Disable VirtualLobby
|
||||
dvars::override::register_bool("virtualLobbyEnabled", false, game::DVAR_FLAG_READ);
|
||||
@ -197,96 +218,113 @@ namespace dedicated
|
||||
dvars::override::register_bool("r_preloadShaders", false, game::DVAR_FLAG_READ);
|
||||
|
||||
// Stop crashing from sys_errors
|
||||
utils::hook::jump(0x140511520, sys_error_stub);
|
||||
utils::hook::jump(0x1D8710_b, sys_error_stub, true);
|
||||
|
||||
// Hook R_SyncGpu
|
||||
utils::hook::jump(0x1405E12F0, sync_gpu_stub);
|
||||
utils::hook::jump(0x688620_b, sync_gpu_stub, true);
|
||||
|
||||
utils::hook::jump(0x140254800, init_dedicated_server);
|
||||
utils::hook::jump(0x135600_b, init_dedicated_server, true);
|
||||
|
||||
// delay startup commands until the initialization is done
|
||||
utils::hook::call(0x1400D72D6, execute_startup_command);
|
||||
utils::hook::jump(0x157DD3_b, utils::hook::assemble([](utils::hook::assembler& a)
|
||||
{
|
||||
a.lea(r8, qword_ptr(rsp, 0x20));
|
||||
a.xor_(ecx, ecx);
|
||||
|
||||
// delay console commands until the initialization is done
|
||||
utils::hook::call(0x1400D808C, execute_console_command);
|
||||
utils::hook::nop(0x1400D80A4, 5);
|
||||
a.pushad64();
|
||||
a.call_aligned(execute_startup_command);
|
||||
a.popad64();
|
||||
|
||||
a.jmp(0x157DDF_b);
|
||||
}), true);//
|
||||
|
||||
// delay console commands until the initialization is done // COULDN'T FOUND
|
||||
// utils::hook::call(0x1400D808C, execute_console_command);
|
||||
// utils::hook::nop(0x1400D80A4, 5);
|
||||
|
||||
// patch GScr_SetDynamicDvar to behave better
|
||||
gscr_set_dynamic_dvar_hook.create(0x14036B600, &gscr_set_dynamic_dvar);
|
||||
gscr_set_dynamic_dvar_hook.create(0x43CF60_b, &gscr_set_dynamic_dvar);
|
||||
|
||||
utils::hook::nop(0x1404ED90E, 5); // don't load config file
|
||||
utils::hook::nop(0x140403D92, 5); // ^
|
||||
utils::hook::set<uint8_t>(0x1400DC1D0, 0xC3); // don't save config file
|
||||
utils::hook::set<uint8_t>(0x140274710, 0xC3); // disable self-registration
|
||||
utils::hook::set<uint8_t>(0x140515890, 0xC3); // init sound system (1)
|
||||
utils::hook::set<uint8_t>(0x1406574F0, 0xC3); // init sound system (2)
|
||||
utils::hook::set<uint8_t>(0x140620D10, 0xC3); // render thread
|
||||
utils::hook::set<uint8_t>(0x14025B850, 0xC3); // called from Com_Frame, seems to do renderer stuff
|
||||
utils::hook::set<uint8_t>(0x1402507B0, 0xC3); // CL_CheckForResend, which tries to connect to the local server constantly
|
||||
utils::hook::set<uint8_t>(0x1405D5178, 0x00); // r_loadForRenderer default to 0
|
||||
utils::hook::set<uint8_t>(0x14050C2D0, 0xC3); // recommended settings check - TODO: Check hook
|
||||
utils::hook::set<uint8_t>(0x140514C00, 0xC3); // some mixer-related function called on shutdown
|
||||
utils::hook::set<uint8_t>(0x140409830, 0xC3); // dont load ui gametype stuff
|
||||
utils::hook::nop(0x189514_b, 248); // don't load config file
|
||||
utils::hook::nop(0x156C46_b, 5); // ^
|
||||
utils::hook::set<uint8_t>(0x17F470_b, 0xC3); // don't save config file
|
||||
utils::hook::set<uint8_t>(0x351AA0_b, 0xC3); // disable self-registration
|
||||
utils::hook::set<uint8_t>(0x5BF4E0_b, 0xC3); // init sound system (1)
|
||||
utils::hook::set<uint8_t>(0x701820_b, 0xC3); // init sound system (2)
|
||||
utils::hook::set<uint8_t>(0x701850_b, 0xC3); // init sound system (3)
|
||||
utils::hook::set<uint8_t>(0x6C9B10_b, 0xC3); // render thread
|
||||
utils::hook::set<uint8_t>(0x343950_b, 0xC3); // called from Com_Frame, seems to do renderer stuff
|
||||
utils::hook::set<uint8_t>(0x12CCA0_b, 0xC3); // CL_CheckForResend, which tries to connect to the local server constantly
|
||||
utils::hook::set<uint8_t>(0x67ADCE_b, 0x00); // r_loadForRenderer default to 0
|
||||
utils::hook::set<uint8_t>(0x5B7AF0_b, 0xC3); // recommended settings check
|
||||
utils::hook::set<uint8_t>(0x5BE850_b, 0xC3); // some mixer-related function called on shutdown
|
||||
utils::hook::set<uint8_t>(0x4DEA50_b, 0xC3); // dont load ui gametype stuff
|
||||
|
||||
utils::hook::nop(0x140481B06, 6); // unknown check in SV_ExecuteClientMessage
|
||||
utils::hook::nop(0x140480FAC, 4); // allow first slot to be occupied
|
||||
utils::hook::nop(0x14025619B, 2); // properly shut down dedicated servers
|
||||
utils::hook::nop(0x14025615E, 2); // ^
|
||||
utils::hook::nop(0x1402561C0, 5); // don't shutdown renderer
|
||||
utils::hook::nop(0x54ED81_b, 6); // unknown check in SV_ExecuteClientMessage
|
||||
utils::hook::nop(0x54E337_b, 4); // allow first slot to be occupied
|
||||
utils::hook::nop(0x13ABCB_b, 2); // properly shut down dedicated servers
|
||||
utils::hook::nop(0x13AB8E_b, 2); // ^
|
||||
utils::hook::nop(0x13ABF0_b, 5); // don't shutdown renderer
|
||||
|
||||
utils::hook::set<uint8_t>(0x140091840, 0xC3); // something to do with blendShapeVertsView
|
||||
utils::hook::nop(0x140659A0D, 8); // sound thing
|
||||
utils::hook::set<uint8_t>(0xAA290_b, 0xC3); // something to do with blendShapeVertsView
|
||||
utils::hook::nop(0x70465D_b, 8); // sound thing
|
||||
|
||||
// (COULD NOT FIND IN H1)
|
||||
// utils::hook::set<uint8_t>(0x1404D6960, 0xC3); // cpu detection stuff?
|
||||
utils::hook::set<uint8_t>(0x1405E97F0, 0xC3); // gfx stuff during fastfile loading
|
||||
utils::hook::set<uint8_t>(0x1405E9700, 0xC3); // ^
|
||||
utils::hook::set<uint8_t>(0x1405E9790, 0xC3); // ^
|
||||
utils::hook::set<uint8_t>(0x1402C1180, 0xC3); // ^
|
||||
utils::hook::set<uint8_t>(0x1405E9750, 0xC3); // ^
|
||||
utils::hook::set<uint8_t>(0x1405AD5B0, 0xC3); // directx stuff
|
||||
utils::hook::set<uint8_t>(0x1405DB150, 0xC3); // ^
|
||||
utils::hook::set<uint8_t>(0x140625220, 0xC3); // ^ - mutex
|
||||
utils::hook::set<uint8_t>(0x1405DB650, 0xC3); // ^
|
||||
utils::hook::set<uint8_t>(0x1D8A20_b, 0xC3); // cpu detection stuff?
|
||||
utils::hook::set<uint8_t>(0x690F30_b, 0xC3); // gfx stuff during fastfile loading
|
||||
utils::hook::set<uint8_t>(0x690E00_b, 0xC3); // ^
|
||||
utils::hook::set<uint8_t>(0x690ED0_b, 0xC3); // ^
|
||||
utils::hook::set<uint8_t>(0x39B980_b, 0xC3); // ^
|
||||
utils::hook::set<uint8_t>(0x690E50_b, 0xC3); // ^
|
||||
utils::hook::set<uint8_t>(0x651BA0_b, 0xC3); // directx stuff
|
||||
utils::hook::set<uint8_t>(0x681950_b, 0xC3); // ^
|
||||
utils::hook::set<uint8_t>(0x6CE390_b, 0xC3); // ^ - mutex
|
||||
utils::hook::set<uint8_t>(0x681ED0_b, 0xC3); // ^
|
||||
|
||||
utils::hook::set<uint8_t>(0x14008B5F0, 0xC3); // rendering stuff
|
||||
utils::hook::set<uint8_t>(0x1405DB8B0, 0xC3); // ^
|
||||
utils::hook::set<uint8_t>(0x1405DB9C0, 0xC3); // ^
|
||||
utils::hook::set<uint8_t>(0x1405DC050, 0xC3); // ^
|
||||
utils::hook::set<uint8_t>(0x1405DCBA0, 0xC3); // ^
|
||||
utils::hook::set<uint8_t>(0x1405DD240, 0xC3); // ^
|
||||
utils::hook::set<uint8_t>(0x0A3CD0_b, 0xC3); // rendering stuff
|
||||
utils::hook::set<uint8_t>(0x682150_b, 0xC3); // ^
|
||||
utils::hook::set<uint8_t>(0x682260_b, 0xC3); // ^
|
||||
utils::hook::set<uint8_t>(0x6829C0_b, 0xC3); // ^
|
||||
utils::hook::set<uint8_t>(0x6834A0_b, 0xC3); // ^
|
||||
utils::hook::set<uint8_t>(0x683B40_b, 0xC3); // ^
|
||||
|
||||
// shaders
|
||||
utils::hook::set<uint8_t>(0x1400916A0, 0xC3); // ^
|
||||
utils::hook::set<uint8_t>(0x140091610, 0xC3); // ^
|
||||
utils::hook::set<uint8_t>(0x14061ACC0, 0xC3); // ^ - mutex
|
||||
utils::hook::set<uint8_t>(0x0AA090_b, 0xC3); // ^
|
||||
utils::hook::set<uint8_t>(0x0A9FE0_b, 0xC3); // ^
|
||||
utils::hook::set<uint8_t>(0x6C38D0_b, 0xC3); // ^ - mutex
|
||||
|
||||
utils::hook::set<uint8_t>(0x140516080, 0xC3); // idk
|
||||
utils::hook::set<uint8_t>(0x1405AE5F0, 0xC3); // ^
|
||||
utils::hook::set<uint8_t>(0x5BFD10_b, 0xC3); // idk
|
||||
utils::hook::set<uint8_t>(0x652E10_b, 0xC3); // ^
|
||||
|
||||
utils::hook::set<uint8_t>(0x1405E0B30, 0xC3); // R_Shutdown
|
||||
utils::hook::set<uint8_t>(0x1405AE400, 0xC3); // shutdown stuff
|
||||
utils::hook::set<uint8_t>(0x1405E0C00, 0xC3); // ^
|
||||
utils::hook::set<uint8_t>(0x1405DFE50, 0xC3); // ^
|
||||
utils::hook::set<uint8_t>(0x687D20_b, 0xC3); // R_Shutdown
|
||||
utils::hook::set<uint8_t>(0x652BA0_b, 0xC3); // shutdown stuff
|
||||
utils::hook::set<uint8_t>(0x687DF0_b, 0xC3); // ^
|
||||
utils::hook::set<uint8_t>(0x686DE0_b, 0xC3); // ^
|
||||
|
||||
// utils::hook::set<uint8_t>(0x1404B67E0, 0xC3); // sound crashes (H1 - questionable, function looks way different)
|
||||
|
||||
utils::hook::set<uint8_t>(0x14048B660, 0xC3); // disable host migration
|
||||
utils::hook::set<uint8_t>(0x556250_b, 0xC3); // disable host migration
|
||||
|
||||
utils::hook::set<uint8_t>(0x14042B2E0, 0xC3); // render synchronization lock
|
||||
utils::hook::set<uint8_t>(0x14042B210, 0xC3); // render synchronization unlock
|
||||
utils::hook::set<uint8_t>(0x4F7C10_b, 0xC3); // render synchronization lock
|
||||
utils::hook::set<uint8_t>(0x4F7B40_b, 0xC3); // render synchronization unlock
|
||||
|
||||
utils::hook::set<uint8_t>(0x140176D2D, 0xEB); // LUI: Unable to start the LUI system due to errors in main.lua
|
||||
utils::hook::set<uint8_t>(0x27AA9D_b, 0xEB); // LUI: Unable to start the LUI system due to errors in main.lua
|
||||
utils::hook::set<uint8_t>(0x27AAC5_b, 0xEB); // LUI: Unable to start the LUI system due to errors in depot.lua
|
||||
utils::hook::set<uint8_t>(0x27AADC_b, 0xEB); // ^
|
||||
|
||||
utils::hook::nop(0x140506ECE, 5); // Disable sound pak file loading
|
||||
utils::hook::nop(0x140506ED6, 2); // ^
|
||||
utils::hook::set<uint8_t>(0x1402C5910, 0xC3); // Disable image pak file loading
|
||||
utils::hook::nop(0x5B25BE_b, 5); // Disable sound pak file loading
|
||||
utils::hook::nop(0x5B25C6_b, 2); // ^
|
||||
utils::hook::set<uint8_t>(0x3A0BA0_b, 0xC3); // Disable image pak file loading
|
||||
|
||||
// Reduce min required memory
|
||||
utils::hook::set<uint64_t>(0x14050C717, 0x80000000);
|
||||
utils::hook::set<uint64_t>(0x5B7F37_b, 0x80000000);
|
||||
|
||||
utils::hook::set(0x1402BF7F0, 0xC3); // some loop
|
||||
utils::hook::set(0x14007E150, 0xC3); // related to shader caching / techsets / fastfiles
|
||||
utils::hook::set<uint8_t>(0x399E10_b, 0xC3); // some loop
|
||||
utils::hook::set<uint8_t>(0x1D48B0_b, 0xC3); // related to shader caching / techsets / fastfilesc
|
||||
utils::hook::set<uint8_t>(0x3A1940_b, 0xC3); // DB_ReadPackedLoadedSounds
|
||||
|
||||
// Workaround for server spamming 'exec default_xboxlive.cfg' when not running
|
||||
ui_set_active_menu_hook.create(0x1E4D80_b, ui_set_active_menu_stub);
|
||||
|
||||
// initialize the game after onlinedataflags is 32 (workaround)
|
||||
scheduler::schedule([=]()
|
||||
@ -318,14 +356,14 @@ namespace dedicated
|
||||
execute_startup_command_queue();
|
||||
execute_console_command_queue();
|
||||
|
||||
// Send heartbeat to dpmaster
|
||||
// Send heartbeat to master
|
||||
scheduler::once(send_heartbeat, scheduler::pipeline::server);
|
||||
scheduler::loop(send_heartbeat, scheduler::pipeline::server, 10min);
|
||||
command::add("heartbeat", send_heartbeat);
|
||||
}, scheduler::pipeline::main, 1s);
|
||||
|
||||
command::add("killserver", kill_server);
|
||||
com_quit_f_hook.create(0x1400DA640, &kill_server);
|
||||
com_quit_f_hook.create(0x17CD00_b, &kill_server);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include <std_include.hpp>
|
||||
#include "console.hpp"
|
||||
#include "loader/component_loader.hpp"
|
||||
#include "game/game.hpp"
|
||||
#include "scheduler.hpp"
|
||||
@ -20,9 +19,9 @@ namespace dedicated_info
|
||||
scheduler::loop([]()
|
||||
{
|
||||
auto* sv_running = game::Dvar_FindVar("sv_running");
|
||||
if (!sv_running || !sv_running->current.enabled)
|
||||
if (!sv_running || !sv_running->current.enabled || (*game::mp::svs_clients) == nullptr)
|
||||
{
|
||||
console::set_title("H1-Mod Dedicated Server");
|
||||
SetConsoleTitle("H1-Mod Dedicated Server");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -33,12 +32,14 @@ namespace dedicated_info
|
||||
auto bot_count = 0;
|
||||
auto client_count = 0;
|
||||
|
||||
for (auto i = 0; i < sv_maxclients->current.integer; i++)
|
||||
const auto svs_clients = *game::mp::svs_clients;
|
||||
|
||||
for (auto i = 0; i < *game::mp::svs_numclients; i++)
|
||||
{
|
||||
auto* client = &game::mp::svs_clients[i];
|
||||
const auto client = svs_clients[i];
|
||||
auto* self = &game::mp::g_entities[i];
|
||||
|
||||
if (client->header.state >= 1 && self && self->client)
|
||||
if (client.header.state >= 1 && self && self->client)
|
||||
{
|
||||
client_count++;
|
||||
if (game::SV_BotIsBot(i))
|
||||
@ -54,9 +55,10 @@ namespace dedicated_info
|
||||
utils::string::strip(sv_hostname->current.string, cleaned_hostname.data(),
|
||||
static_cast<int>(strlen(sv_hostname->current.string)) + 1);
|
||||
|
||||
console::set_title(utils::string::va("%s on %s [%d/%d] (%d)", cleaned_hostname.data(),
|
||||
mapname->current.string, client_count,
|
||||
sv_maxclients->current.integer, bot_count));
|
||||
SetConsoleTitle(utils::string::va("%s on %s [%d/%d] (%d)", cleaned_hostname.data(),
|
||||
mapname->current.string, client_count,
|
||||
sv_maxclients->current.integer, bot_count)
|
||||
);
|
||||
}, scheduler::pipeline::main, 1s);
|
||||
}
|
||||
};
|
||||
|
@ -297,7 +297,7 @@ namespace demonware
|
||||
|
||||
if (server)
|
||||
{
|
||||
server->handle_input(buf, len, {s, to, tolen});
|
||||
server->handle_input(buf, len, { s, to, tolen });
|
||||
return len;
|
||||
}
|
||||
|
||||
@ -425,9 +425,9 @@ namespace demonware
|
||||
}
|
||||
}
|
||||
|
||||
void bd_logger_stub(char* a1, void* a2, void* a3, void* a4, const char* function, ...)
|
||||
void bd_logger_stub()
|
||||
{
|
||||
|
||||
//printf("logged\n");
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
@ -481,6 +481,39 @@ namespace demonware
|
||||
printf("bdAuth: Unknown error\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
utils::hook::detour handle_auth_reply_hook;
|
||||
bool handle_auth_reply_stub(void* a1, void* a2, void* a3)
|
||||
{
|
||||
// Skip bdAuth::validateResponseSignature
|
||||
utils::hook::set(0x7D4AB0_b, 0xC301B0);
|
||||
// Skip bdAuth::processPlatformData
|
||||
utils::hook::set(0x7D55C0_b, 0xC301B0);
|
||||
|
||||
return handle_auth_reply_hook.invoke<bool>(a1, a2, a3);
|
||||
}
|
||||
|
||||
void* allocate_somewhere_near(uint8_t* base_address)
|
||||
{
|
||||
const size_t PAGE_SIZE = 0x1000;
|
||||
size_t offset = 0;
|
||||
while (true)
|
||||
{
|
||||
offset += PAGE_SIZE;
|
||||
auto res = VirtualAlloc(base_address - offset, PAGE_SIZE, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
|
||||
if (res)
|
||||
{
|
||||
std::memset(res, 0, PAGE_SIZE);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void request_start_match_stub()
|
||||
{
|
||||
const auto* args = "StartServer";
|
||||
game::UI_RunMenuScript(0, &args);
|
||||
}
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
@ -505,6 +538,11 @@ namespace demonware
|
||||
|
||||
void post_load() override
|
||||
{
|
||||
if (game::environment::is_sp())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
server_thread = utils::thread::create_named_thread("Demonware", server_main);
|
||||
}
|
||||
|
||||
@ -537,57 +575,45 @@ namespace demonware
|
||||
|
||||
void post_unpack() override
|
||||
{
|
||||
/*
|
||||
mwr has upgraded some networking methods and the gethostbyname import from winsock library is no longer used
|
||||
gethostbyname has been replaced with getaddrinfo
|
||||
btw, still you can't get online..
|
||||
*/
|
||||
utils::hook::jump(SELECT_VALUE(0x140610320, 0x1407400B0), bd_logger_stub); // H1MP64(1.4)
|
||||
|
||||
if (game::environment::is_sp())
|
||||
{
|
||||
utils::hook::set<uint8_t>(0x1405FCA00, 0xC3); // bdAuthSteam H1(1.4)
|
||||
utils::hook::set<uint8_t>(0x140333A00, 0xC3); // dwNet H1(1.4)
|
||||
utils::hook::set<uint8_t>(0x68DDA0_b, 0xC3); // bdAuthSteam
|
||||
utils::hook::set<uint8_t>(0x366600_b, 0xC3); // dwNet
|
||||
return;
|
||||
}
|
||||
|
||||
utils::hook::set<uint8_t>(0x140715039, 0x0); // CURLOPT_SSL_VERIFYPEER H1MP64(1.4)
|
||||
utils::hook::set<uint8_t>(0x140715025, 0xAF); // CURLOPT_SSL_VERIFYHOST H1MP64(1.4)
|
||||
utils::hook::set<uint8_t>(0x14095433C, 0x0); // HTTPS -> HTTP [MWR OK][S1X: 0x14088D0E8]
|
||||
utils::hook::set<uint8_t>(0x7C0AD9_b, 0x0); // CURLOPT_SSL_VERIFYPEER
|
||||
utils::hook::set<uint8_t>(0x7C0AC5_b, 0xAF); // CURLOPT_SSL_VERIFYHOST
|
||||
utils::hook::set<uint8_t>(0xA1327C_b, 0x0); // HTTPS -> HTTP
|
||||
|
||||
//HTTPS -> HTTP
|
||||
utils::hook::inject(0x14006DDA9, "http://prod.umbrella.demonware.net/v1.0/"); // ---> [H1MP1.4 - S1X: 0x14003852E]
|
||||
utils::hook::inject(0x14006E11C, "http://prod.umbrella.demonware.net/v1.0/"); // ---> [H1MP1.4 - S1X: 0x14003884F]
|
||||
utils::hook::inject(0x14006E2FB, "http://prod.umbrella.demonware.net/v1.0/"); // ---> [H1MP1.4 - S1X: 0x140038A07]
|
||||
utils::hook::inject(0x14006E9A9, "http://prod.uno.demonware.net/v1.0/");
|
||||
utils::hook::inject(0x14006ED49, "http://prod.uno.demonware.net/v1.0/");
|
||||
utils::hook::inject(0x140728170, "http://%s:%d/auth/");
|
||||
std::memcpy(reinterpret_cast<void*>(0x8D0298_b),
|
||||
"http://prod.umbrella.demonware.net/v1.0/", sizeof("http://prod.umbrella.demonware.net/v1.0/"));
|
||||
std::memcpy(reinterpret_cast<void*>(0x8D05A8_b),
|
||||
"http://prod.uno.demonware.net/v1.0/", sizeof("http://prod.uno.demonware.net/v1.0/"));
|
||||
std::memcpy(reinterpret_cast<void*>(0x9EDB08_b), "http://%s:%d/auth/", sizeof("http://%s:%d/auth/"));
|
||||
|
||||
utils::hook::set<uint8_t>(0x14047F290, 0xC3); // SV_SendMatchData H1MP64(1.4)
|
||||
utils::hook::set<uint8_t>(0x140598990, 0xC3); // Live_CheckForFullDisconnect H1MP64(1.4)
|
||||
// utils::hook::set<uint8_t>(0x19F8C0_b, 0xC3); // SV_SendMatchData, not sure
|
||||
utils::hook::nop(0x19BB67_b, 5); // LiveStorage_SendMatchDataComplete (crashes at the end of match)
|
||||
utils::hook::nop(0x19BC3F_b, 5); // LiveStorage_GettingStoreConfigComplete probably (crashes randomly)
|
||||
utils::hook::nop(0x19BC48_b, 5); // similar to above (crashes in killcam)
|
||||
utils::hook::set<uint8_t>(0x1A3340_b, 0xC3); // Live_CheckForFullDisconnect
|
||||
|
||||
#ifdef DEBUG
|
||||
// yes
|
||||
utils::hook::call(0x140727BEB, l);
|
||||
utils::hook::call(0x140727AFC, i);
|
||||
utils::hook::call(0x140727E49, h);
|
||||
utils::hook::call(0x140727E30, g);
|
||||
utils::hook::call(0x140727E37, f);
|
||||
utils::hook::call(0x140727DF2, e);
|
||||
utils::hook::call(0x140727DF9, d);
|
||||
utils::hook::call(0x140727CFC, c);
|
||||
utils::hook::call(0x140727C82, b);
|
||||
utils::hook::call(0x140727E6A, a);
|
||||
#endif
|
||||
// Checks X-Signature header or something
|
||||
utils::hook::set(0x140728380, 0xC301B0);
|
||||
// Checks extended_data and extra_data in json object
|
||||
utils::hook::set(0x140728E90, 0xC301B0);
|
||||
// Update check
|
||||
utils::hook::set(0x1403A5390, 0xC301B0);
|
||||
|
||||
// Remove some while loop in demonware that freezes the rendering for a few secs at launch
|
||||
utils::hook::nop(0x14057DBC5, 5);
|
||||
// Remove some while loop that freezes the rendering for a few secs while connecting
|
||||
utils::hook::nop(0x625555_b, 5);
|
||||
|
||||
handle_auth_reply_hook.create(0x7AC600_b, handle_auth_reply_stub);
|
||||
|
||||
// Skip update check in Live_SyncOnlineDataFlags
|
||||
utils::hook::set(0x47A6D0_b, 0xC301B0);
|
||||
// Remove update failed popup
|
||||
utils::hook::set(0x47B2B0_b, 0xC301B0);
|
||||
|
||||
// xpartygo -> just start the match
|
||||
utils::hook::jump(0x355B80_b, request_start_match_stub);
|
||||
|
||||
utils::hook::set(0x396AD0_b, 0xC301B0); // DB_IsZoneLoaded("ffotd")
|
||||
utils::hook::set(0x4DD600_b, 0xC300B0); // dont use ffotd
|
||||
utils::hook::set(0x4DD5B0_b, 0xC300B0); // dont dl ffotd
|
||||
}
|
||||
|
||||
void pre_destroy() override
|
||||
|
@ -7,11 +7,23 @@
|
||||
#include "command.hpp"
|
||||
#include "network.hpp"
|
||||
#include "party.hpp"
|
||||
#include "materials.hpp"
|
||||
#include "discord.hpp"
|
||||
|
||||
#include "game/ui_scripting/execution.hpp"
|
||||
|
||||
#include <utils/string.hpp>
|
||||
#include <utils/cryptography.hpp>
|
||||
#include <utils/http.hpp>
|
||||
|
||||
#include <discord_rpc.h>
|
||||
|
||||
#define DEFAULT_AVATAR "discord_default_avatar"
|
||||
#define AVATAR "discord_avatar_%s"
|
||||
|
||||
#define DEFAULT_AVATAR_URL "https://cdn.discordapp.com/embed/avatars/0.png"
|
||||
#define AVATAR_URL "https://cdn.discordapp.com/avatars/%s/%s.png?size=128"
|
||||
|
||||
namespace discord
|
||||
{
|
||||
namespace
|
||||
@ -20,15 +32,13 @@ namespace discord
|
||||
|
||||
void update_discord()
|
||||
{
|
||||
Discord_RunCallbacks();
|
||||
|
||||
if (!game::CL_IsCgameInitialized() || game::VirtualLobby_Loaded())
|
||||
{
|
||||
discord_presence.details = game::environment::is_sp() ? "Singleplayer" : "Multiplayer";
|
||||
discord_presence.details = SELECT_VALUE("Singleplayer", "Multiplayer");
|
||||
discord_presence.state = "Main Menu";
|
||||
|
||||
auto firingRangeDvar = game::Dvar_FindVar("virtualLobbyInFiringRange");
|
||||
if (firingRangeDvar && firingRangeDvar->current.enabled == 1)
|
||||
const auto in_firing_range = game::Dvar_FindVar("virtualLobbyInFiringRange");
|
||||
if (in_firing_range && in_firing_range->current.enabled == 1)
|
||||
{
|
||||
discord_presence.state = "Firing Range";
|
||||
}
|
||||
@ -36,20 +46,27 @@ namespace discord
|
||||
discord_presence.partySize = 0;
|
||||
discord_presence.partyMax = 0;
|
||||
discord_presence.startTimestamp = 0;
|
||||
discord_presence.largeImageKey = game::environment::is_sp() ? "menu_singleplayer" : "menu_multiplayer";
|
||||
discord_presence.largeImageKey = SELECT_VALUE("menu_singleplayer", "menu_multiplayer");
|
||||
|
||||
// set to blank when in lobby
|
||||
discord_presence.matchSecret = "";
|
||||
discord_presence.joinSecret = "";
|
||||
discord_presence.partyId = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
static char details[0x80] = {0};
|
||||
const auto map = game::Dvar_FindVar("mapname")->current.string;
|
||||
const auto mapname = game::UI_SafeTranslateString(utils::string::va("PRESENCE_%s%s", (game::environment::is_sp() ? "SP_" : ""), map));
|
||||
const auto mapname = game::UI_SafeTranslateString(
|
||||
utils::string::va("PRESENCE_%s%s", SELECT_VALUE("SP_", ""), map));
|
||||
|
||||
if (game::environment::is_mp())
|
||||
{
|
||||
const auto gametype = game::UI_GetGameTypeDisplayName(game::Dvar_FindVar("g_gametype")->current.string);
|
||||
const auto gametype = game::UI_GetGameTypeDisplayName(
|
||||
game::Dvar_FindVar("g_gametype")->current.string);
|
||||
strcpy_s(details, 0x80, utils::string::va("%s on %s", gametype, mapname));
|
||||
|
||||
discord_presence.details = utils::string::va("%s on %s", gametype, mapname);
|
||||
|
||||
char clean_hostname[0x100] = {0};
|
||||
static char clean_hostname[0x80] = {0};
|
||||
utils::string::strip(game::Dvar_FindVar("sv_hostname")->current.string,
|
||||
clean_hostname, sizeof(clean_hostname));
|
||||
auto max_clients = party::server_client_count();
|
||||
@ -59,9 +76,41 @@ namespace discord
|
||||
{
|
||||
strcpy_s(clean_hostname, "Private Match");
|
||||
max_clients = game::Dvar_FindVar("sv_maxclients")->current.integer;
|
||||
discord_presence.partyPrivacy = DISCORD_PARTY_PRIVATE;
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto server_net_info = party::get_state_host();
|
||||
const auto server_ip_port = utils::string::va("%i.%i.%i.%i:%i",
|
||||
static_cast<int>(server_net_info.ip[0]),
|
||||
static_cast<int>(server_net_info.ip[1]),
|
||||
static_cast<int>(server_net_info.ip[2]),
|
||||
static_cast<int>(server_net_info.ip[3]),
|
||||
static_cast<int>(ntohs(server_net_info.port))
|
||||
);
|
||||
|
||||
static char join_secret[0x80] = {0};
|
||||
strcpy_s(join_secret, 0x80, server_ip_port);
|
||||
|
||||
static char party_id[0x80] = {0};
|
||||
const auto server_ip_port_hash = utils::cryptography::sha1::compute(server_ip_port, true).substr(0, 8);
|
||||
strcpy_s(party_id, 0x80, server_ip_port_hash.data());
|
||||
|
||||
discord_presence.partyId = party_id;
|
||||
discord_presence.joinSecret = join_secret;
|
||||
discord_presence.partyPrivacy = DISCORD_PARTY_PUBLIC;
|
||||
}
|
||||
|
||||
const auto client_state = *game::mp::client_state;
|
||||
if (client_state != nullptr)
|
||||
{
|
||||
discord_presence.partySize = client_state->num_players;
|
||||
}
|
||||
else
|
||||
{
|
||||
discord_presence.partySize = 0;
|
||||
}
|
||||
|
||||
discord_presence.partySize = *reinterpret_cast<int*>(0x1429864C4);
|
||||
discord_presence.partyMax = max_clients;
|
||||
discord_presence.state = clean_hostname;
|
||||
discord_presence.largeImageKey = map;
|
||||
@ -70,9 +119,11 @@ namespace discord
|
||||
{
|
||||
discord_presence.state = "";
|
||||
discord_presence.largeImageKey = map;
|
||||
discord_presence.details = mapname;
|
||||
strcpy_s(details, 0x80, mapname);
|
||||
}
|
||||
|
||||
discord_presence.details = details;
|
||||
|
||||
if (!discord_presence.startTimestamp)
|
||||
{
|
||||
discord_presence.startTimestamp = std::chrono::duration_cast<std::chrono::seconds>(
|
||||
@ -82,6 +133,51 @@ namespace discord
|
||||
|
||||
Discord_UpdatePresence(&discord_presence);
|
||||
}
|
||||
|
||||
void download_user_avatar(const std::string& id, const std::string& avatar)
|
||||
{
|
||||
const auto data = utils::http::get_data(
|
||||
utils::string::va(AVATAR_URL, id.data(), avatar.data()));
|
||||
if (data.has_value())
|
||||
{
|
||||
materials::add(utils::string::va(AVATAR, id.data()), data.value());
|
||||
}
|
||||
}
|
||||
|
||||
bool has_default_avatar = false;
|
||||
void download_default_avatar()
|
||||
{
|
||||
const auto data = utils::http::get_data(DEFAULT_AVATAR_URL);
|
||||
if (data.has_value())
|
||||
{
|
||||
has_default_avatar = true;
|
||||
materials::add(DEFAULT_AVATAR, data.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string get_avatar_material(const std::string& id)
|
||||
{
|
||||
const auto avatar_name = utils::string::va(AVATAR, id.data());
|
||||
if (materials::exists(avatar_name))
|
||||
{
|
||||
return avatar_name;
|
||||
}
|
||||
|
||||
if (has_default_avatar)
|
||||
{
|
||||
return DEFAULT_AVATAR;
|
||||
}
|
||||
|
||||
return "black";
|
||||
}
|
||||
|
||||
void respond(const std::string& id, int reply)
|
||||
{
|
||||
scheduler::once([=]()
|
||||
{
|
||||
Discord_Respond(id.data(), reply);
|
||||
}, scheduler::pipeline::async);
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
@ -99,16 +195,23 @@ namespace discord
|
||||
handlers.ready = ready;
|
||||
handlers.errored = errored;
|
||||
handlers.disconnected = errored;
|
||||
handlers.joinGame = nullptr;
|
||||
handlers.spectateGame = nullptr;
|
||||
handlers.joinRequest = nullptr;
|
||||
|
||||
if (game::environment::is_mp())
|
||||
{
|
||||
handlers.joinGame = join_game;
|
||||
handlers.joinRequest = join_request;
|
||||
}
|
||||
|
||||
Discord_Initialize("947125042930667530", &handlers, 1, nullptr);
|
||||
|
||||
scheduler::once(download_default_avatar, scheduler::pipeline::async);
|
||||
|
||||
scheduler::once([]()
|
||||
{
|
||||
scheduler::once(update_discord, scheduler::pipeline::async);
|
||||
scheduler::loop(update_discord, scheduler::pipeline::async, 5s);
|
||||
scheduler::loop(Discord_RunCallbacks, scheduler::pipeline::async, 1s);
|
||||
}, scheduler::pipeline::main);
|
||||
|
||||
initialized_ = true;
|
||||
@ -127,14 +230,11 @@ namespace discord
|
||||
private:
|
||||
bool initialized_ = false;
|
||||
|
||||
static void ready(const DiscordUser* /*request*/)
|
||||
static void ready(const DiscordUser* request)
|
||||
{
|
||||
ZeroMemory(&discord_presence, sizeof(discord_presence));
|
||||
|
||||
discord_presence.instance = 1;
|
||||
|
||||
console::info("Discord: Ready\n");
|
||||
|
||||
console::info("Discord: Ready on %s (%s)\n", request->username, request->userId);
|
||||
Discord_UpdatePresence(&discord_presence);
|
||||
}
|
||||
|
||||
@ -142,7 +242,58 @@ namespace discord
|
||||
{
|
||||
console::error("Discord: Error (%i): %s\n", error_code, message);
|
||||
}
|
||||
|
||||
static void join_game(const char* join_secret)
|
||||
{
|
||||
console::info("Discord: Join game called with join secret: %s\n", join_secret);
|
||||
|
||||
std::string secret = join_secret;
|
||||
scheduler::once([=]()
|
||||
{
|
||||
game::netadr_s target{};
|
||||
if (game::NET_StringToAdr(secret.data(), &target))
|
||||
{
|
||||
console::info("Discord: Connecting to server: %s\n", secret.data());
|
||||
party::connect(target);
|
||||
}
|
||||
}, scheduler::pipeline::main);
|
||||
}
|
||||
|
||||
static void join_request(const DiscordUser* request)
|
||||
{
|
||||
console::info("Discord: join_request from %s (%s)\n", request->username, request->userId);
|
||||
|
||||
if (game::Com_InFrontend() || !ui_scripting::lui_running())
|
||||
{
|
||||
Discord_Respond(request->userId, DISCORD_REPLY_IGNORE);
|
||||
return;
|
||||
}
|
||||
|
||||
std::string user_id = request->userId;
|
||||
std::string avatar = request->avatar;
|
||||
std::string discriminator = request->discriminator;
|
||||
std::string username = request->username;
|
||||
|
||||
scheduler::once([=]()
|
||||
{
|
||||
const ui_scripting::table request_table{};
|
||||
request_table.set("avatar", avatar);
|
||||
request_table.set("discriminator", discriminator);
|
||||
request_table.set("userid", user_id);
|
||||
request_table.set("username", username);
|
||||
|
||||
ui_scripting::notify("discord_join_request",
|
||||
{
|
||||
{"request", request_table}
|
||||
});
|
||||
}, scheduler::pipeline::lui);
|
||||
|
||||
if (!materials::exists(utils::string::va(AVATAR, user_id.data())))
|
||||
{
|
||||
download_user_avatar(user_id, avatar);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(discord::component)
|
||||
REGISTER_COMPONENT(discord::component)
|
||||
|
7
src/client/component/discord.hpp
Normal file
7
src/client/component/discord.hpp
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
namespace discord
|
||||
{
|
||||
std::string get_avatar_material(const std::string& id);
|
||||
void respond(const std::string& id, int reply);
|
||||
}
|
147
src/client/component/dvar_cheats.cpp
Normal file
147
src/client/component/dvar_cheats.cpp
Normal file
@ -0,0 +1,147 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "console.hpp"
|
||||
#include "scheduler.hpp"
|
||||
|
||||
#include "game/game.hpp"
|
||||
#include "game/dvars.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
#include <utils/string.hpp>
|
||||
|
||||
namespace dvar_cheats
|
||||
{
|
||||
void apply_sv_cheats(const game::dvar_t* dvar, const game::DvarSetSource source, game::dvar_value* value)
|
||||
{
|
||||
static const auto sv_cheats_hash = game::generateHashValue("sv_cheats");
|
||||
|
||||
if (dvar && dvar->hash == sv_cheats_hash)
|
||||
{
|
||||
// if dedi, do not allow internal to change value so servers can allow cheats if they want to
|
||||
if (game::environment::is_dedi() && source == game::DvarSetSource::DVAR_SOURCE_INTERNAL)
|
||||
{
|
||||
value->enabled = dvar->current.enabled;
|
||||
}
|
||||
|
||||
// if sv_cheats was enabled and it changes to disabled, we need to reset all cheat dvars
|
||||
else if (dvar->current.enabled && !value->enabled)
|
||||
{
|
||||
for (auto i = 0; i < *game::dvarCount; ++i)
|
||||
{
|
||||
const auto var = &game::dvarPool[i];
|
||||
if (var && (var->flags & game::DvarFlags::DVAR_FLAG_CHEAT))
|
||||
{
|
||||
game::Dvar_Reset(var, game::DvarSetSource::DVAR_SOURCE_INTERNAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool dvar_flag_checks(const game::dvar_t* dvar, const game::DvarSetSource source)
|
||||
{
|
||||
const auto info = dvars::get_dvar_info_from_hash(dvar->hash);
|
||||
const auto name = info.has_value()
|
||||
? info.value().name.data()
|
||||
: utils::string::va("0x%lX", dvar->hash);
|
||||
|
||||
if ((dvar->flags & game::DvarFlags::DVAR_FLAG_WRITE))
|
||||
{
|
||||
console::error("%s is write protected\n", name);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((dvar->flags & game::DvarFlags::DVAR_FLAG_READ))
|
||||
{
|
||||
console::error("%s is read only\n", name);
|
||||
return false;
|
||||
}
|
||||
|
||||
// only check cheat/replicated values when the source is external
|
||||
if (source == game::DvarSetSource::DVAR_SOURCE_EXTERNAL)
|
||||
{
|
||||
const auto cl_ingame = game::Dvar_FindVar("cl_ingame");
|
||||
const auto sv_running = game::Dvar_FindVar("sv_running");
|
||||
|
||||
if ((dvar->flags & game::DvarFlags::DVAR_FLAG_REPLICATED) && (cl_ingame && cl_ingame->current.enabled) && (
|
||||
sv_running && !sv_running->current.enabled))
|
||||
{
|
||||
console::error("%s can only be changed by the server\n", name);
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto sv_cheats = game::Dvar_FindVar("sv_cheats");
|
||||
if ((dvar->flags & game::DvarFlags::DVAR_FLAG_CHEAT) && (sv_cheats && !sv_cheats->current.enabled))
|
||||
{
|
||||
console::error("%s is cheat protected\n", name);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// pass all the flag checks, allow dvar to be changed
|
||||
return true;
|
||||
}
|
||||
|
||||
void* get_dvar_flag_checks_stub()
|
||||
{
|
||||
return utils::hook::assemble([](utils::hook::assembler& a)
|
||||
{
|
||||
const auto can_set_value = a.newLabel();
|
||||
const auto zero_source = a.newLabel();
|
||||
|
||||
a.pushad64();
|
||||
a.mov(r8, rdi);
|
||||
a.mov(edx, esi);
|
||||
a.mov(rcx, rbx);
|
||||
a.call_aligned(apply_sv_cheats); // check if we are setting sv_cheats
|
||||
a.popad64();
|
||||
a.cmp(esi, 0);
|
||||
a.jz(zero_source); // if the SetSource is 0 (INTERNAL) ignore flag checks
|
||||
|
||||
a.pushad64();
|
||||
a.mov(edx, esi); // source
|
||||
a.mov(rcx, rbx); // dvar
|
||||
a.call_aligned(dvar_flag_checks); // protect read/write/cheat/replicated dvars
|
||||
a.cmp(al, 1);
|
||||
a.jz(can_set_value);
|
||||
|
||||
// if we get here, we are non-zero source and CANNOT set values
|
||||
a.popad64(); // if I do this before the jz it won't work. for some reason the popad64 is affecting the ZR flag
|
||||
a.jmp(0x18655C_b);
|
||||
|
||||
// if we get here, we are non-zero source and CAN set values
|
||||
a.bind(can_set_value);
|
||||
a.popad64(); // if I do this before the jz it won't work. for some reason the popad64 is affecting the ZR flag
|
||||
a.cmp(esi, 1);
|
||||
a.jmp(0x1861EE_b);
|
||||
|
||||
// if we get here, we are zero source and ignore flags
|
||||
a.bind(zero_source);
|
||||
a.jmp(0x18628F_b);
|
||||
});
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
if (game::environment::is_sp())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
utils::hook::nop(0x1861D4_b, 8); // let our stub handle zero-source sets
|
||||
utils::hook::jump(0x1861DF_b, get_dvar_flag_checks_stub(), true); // check extra dvar flags when setting values
|
||||
|
||||
scheduler::once([]()
|
||||
{
|
||||
dvars::register_bool("sv_cheats", false, game::DvarFlags::DVAR_FLAG_REPLICATED,
|
||||
"Allow cheat commands and dvars on this server");
|
||||
}, scheduler::pipeline::main);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(dvar_cheats::component)
|
@ -35,7 +35,6 @@ namespace dvars
|
||||
|
||||
struct dvar_vector3 : dvar_base
|
||||
{
|
||||
|
||||
float x{};
|
||||
float y{};
|
||||
float z{};
|
||||
@ -43,6 +42,12 @@ namespace dvars
|
||||
float max{};
|
||||
};
|
||||
|
||||
struct dvar_enum : dvar_base
|
||||
{
|
||||
const char* const* value_list{};
|
||||
int default_index{};
|
||||
};
|
||||
|
||||
struct dvar_int : dvar_base
|
||||
{
|
||||
int value{};
|
||||
@ -139,6 +144,7 @@ namespace dvars
|
||||
static std::unordered_map<std::string, dvar_string> register_string_overrides;
|
||||
static std::unordered_map<std::string, dvar_vector2> register_vector2_overrides;
|
||||
static std::unordered_map<std::string, dvar_vector3> register_vector3_overrides;
|
||||
static std::unordered_map<std::string, dvar_enum> register_enum_overrides;
|
||||
|
||||
static std::unordered_map<std::string, bool> set_bool_overrides;
|
||||
static std::unordered_map<std::string, float> set_float_overrides;
|
||||
@ -210,6 +216,16 @@ namespace dvars
|
||||
register_vector3_overrides[name] = std::move(values);
|
||||
}
|
||||
|
||||
void register_enum(const std::string& name, /*const char* const* value_list, int default_index,*/
|
||||
const unsigned int flags)
|
||||
{
|
||||
dvar_enum values;
|
||||
//values.value_list = value_list;
|
||||
//values.default_index = default_index;
|
||||
values.flags = flags;
|
||||
register_enum_overrides[name] = std::move(values);
|
||||
}
|
||||
|
||||
void set_bool(const std::string& name, const bool value)
|
||||
{
|
||||
set_bool_overrides[name] = value;
|
||||
@ -237,11 +253,15 @@ namespace dvars
|
||||
}
|
||||
|
||||
utils::hook::detour dvar_register_bool_hook;
|
||||
utils::hook::detour dvar_register_bool_hashed_hook;
|
||||
utils::hook::detour dvar_register_float_hook;
|
||||
utils::hook::detour dvar_register_float_hashed_hook;
|
||||
utils::hook::detour dvar_register_int_hook;
|
||||
utils::hook::detour dvar_register_int_hashed_hook;
|
||||
utils::hook::detour dvar_register_string_hook;
|
||||
utils::hook::detour dvar_register_vector2_hook;
|
||||
utils::hook::detour dvar_register_vector3_hook;
|
||||
utils::hook::detour dvar_register_enum_hook;
|
||||
|
||||
utils::hook::detour dvar_set_bool_hook;
|
||||
utils::hook::detour dvar_set_float_hook;
|
||||
@ -261,6 +281,18 @@ namespace dvars
|
||||
return dvar_register_bool_hook.invoke<game::dvar_t*>(hash, name, value, flags);
|
||||
}
|
||||
|
||||
game::dvar_t* dvar_register_bool_hashed(const int hash, const char* name, bool value, unsigned int flags)
|
||||
{
|
||||
auto* var = find_dvar(override::register_bool_overrides, hash);
|
||||
if (var)
|
||||
{
|
||||
value = var->value;
|
||||
flags = var->flags;
|
||||
}
|
||||
|
||||
return dvar_register_bool_hashed_hook.invoke<game::dvar_t*>(hash, name, value, flags);
|
||||
}
|
||||
|
||||
game::dvar_t* dvar_register_float(const int hash, const char* name, float value, float min, float max, unsigned int flags)
|
||||
{
|
||||
auto* var = find_dvar(override::register_float_overrides, hash);
|
||||
@ -275,6 +307,20 @@ namespace dvars
|
||||
return dvar_register_float_hook.invoke<game::dvar_t*>(hash, name, value, min, max, flags);
|
||||
}
|
||||
|
||||
game::dvar_t* dvar_register_float_hashed(const int hash, const char* name, float value, float min, float max, unsigned int flags)
|
||||
{
|
||||
auto* var = find_dvar(override::register_float_overrides, hash);
|
||||
if (var)
|
||||
{
|
||||
value = var->value;
|
||||
min = var->min;
|
||||
max = var->max;
|
||||
flags = var->flags;
|
||||
}
|
||||
|
||||
return dvar_register_float_hashed_hook.invoke<game::dvar_t*>(hash, name, value, min, max, flags);
|
||||
}
|
||||
|
||||
game::dvar_t* dvar_register_int(const int hash, const char* name, int value, int min, int max, unsigned int flags)
|
||||
{
|
||||
auto* var = find_dvar(override::register_int_overrides, hash);
|
||||
@ -289,6 +335,20 @@ namespace dvars
|
||||
return dvar_register_int_hook.invoke<game::dvar_t*>(hash, name, value, min, max, flags);
|
||||
}
|
||||
|
||||
game::dvar_t* dvar_register_int_hashed(const int hash, const char* name, int value, int min, int max, unsigned int flags)
|
||||
{
|
||||
auto* var = find_dvar(override::register_int_overrides, hash);
|
||||
if (var)
|
||||
{
|
||||
value = var->value;
|
||||
min = var->min;
|
||||
max = var->max;
|
||||
flags = var->flags;
|
||||
}
|
||||
|
||||
return dvar_register_int_hashed_hook.invoke<game::dvar_t*>(hash, name, value, min, max, flags);
|
||||
}
|
||||
|
||||
game::dvar_t* dvar_register_string(const int hash, const char* name, const char* value, unsigned int flags)
|
||||
{
|
||||
auto* var = find_dvar(override::register_string_overrides, hash);
|
||||
@ -334,6 +394,19 @@ namespace dvars
|
||||
return dvar_register_vector3_hook.invoke<game::dvar_t*>(hash, name, x, y, z, min, max, flags);
|
||||
}
|
||||
|
||||
game::dvar_t* dvar_register_enum(const int hash, const char* name, const char* const value_list, int default_index, unsigned int flags)
|
||||
{
|
||||
auto* var = find_dvar(override::register_enum_overrides, hash);
|
||||
if (var)
|
||||
{
|
||||
//value_list = var->value_list;
|
||||
//default_index = var->default_index;
|
||||
flags = var->flags;
|
||||
}
|
||||
|
||||
return dvar_register_enum_hook.invoke<game::dvar_t*>(hash, name, value_list, default_index, flags);
|
||||
}
|
||||
|
||||
void dvar_set_bool(game::dvar_t* dvar, bool boolean)
|
||||
{
|
||||
const auto disabled = find_dvar(disable::set_bool_disables, dvar->hash);
|
||||
@ -424,18 +497,26 @@ namespace dvars
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
dvar_register_bool_hook.create(SELECT_VALUE(0x1403C47E0, 0x1404FA540), &dvar_register_bool);
|
||||
dvar_register_float_hook.create(SELECT_VALUE(0x1403C4BB0, 0x1404FA910), &dvar_register_float);
|
||||
dvar_register_int_hook.create(SELECT_VALUE(0x1403C4CC0, 0x1404FAA20), &dvar_register_int);
|
||||
dvar_register_string_hook.create(SELECT_VALUE(0x1403C4DA0, 0x1404FAB00), &dvar_register_string);
|
||||
dvar_register_vector2_hook.create(SELECT_VALUE(0x1403C4E80, 0x1404FABE0), &dvar_register_vector2);
|
||||
dvar_register_vector3_hook.create(SELECT_VALUE(0x1403C4FC0, 0x1404FACE0), &dvar_register_vector3);
|
||||
dvar_register_bool_hook.create(SELECT_VALUE(0x419220_b, 0x182340_b), &dvar_register_bool);
|
||||
dvar_register_float_hook.create(SELECT_VALUE(0x4195F0_b, 0x1827F0_b), &dvar_register_float);
|
||||
dvar_register_int_hook.create(SELECT_VALUE(0x419700_b, 0x182A10_b), &dvar_register_int);
|
||||
dvar_register_string_hook.create(SELECT_VALUE(0x4197E0_b, 0x182BD0_b), &dvar_register_string);
|
||||
dvar_register_vector2_hook.create(SELECT_VALUE(0x4198C0_b, 0x182CB0_b), &dvar_register_vector2);
|
||||
dvar_register_vector3_hook.create(SELECT_VALUE(0x419A00_b, 0x182DB0_b), &dvar_register_vector3);
|
||||
dvar_register_enum_hook.create(SELECT_VALUE(0x419500_b, 0x182700_b), &dvar_register_enum);
|
||||
|
||||
dvar_set_bool_hook.create(SELECT_VALUE(0x1403C7020, 0x1404FCDF0), &dvar_set_bool);
|
||||
dvar_set_float_hook.create(SELECT_VALUE(0x1403C7420, 0x1404FD360), &dvar_set_float);
|
||||
dvar_set_int_hook.create(SELECT_VALUE(0x1403C76C0, 0x1404FD5E0), &dvar_set_int);
|
||||
dvar_set_string_hook.create(SELECT_VALUE(0x1403C7900, 0x1404FD8D0), &dvar_set_string);
|
||||
dvar_set_from_string_hook.create(SELECT_VALUE(0x1403C7620, 0x1404FD520), &dvar_set_from_string);
|
||||
if (!game::environment::is_sp())
|
||||
{
|
||||
dvar_register_bool_hashed_hook.create(SELECT_VALUE(0x0, 0x182420_b), &dvar_register_bool_hashed);
|
||||
dvar_register_float_hashed_hook.create(SELECT_VALUE(0x0, 0x182900_b), &dvar_register_float_hashed);
|
||||
dvar_register_int_hashed_hook.create(SELECT_VALUE(0x0, 0x182AF0_b), &dvar_register_int_hashed);
|
||||
}
|
||||
|
||||
dvar_set_bool_hook.create(SELECT_VALUE(0x41B820_b, 0x185520_b), &dvar_set_bool);
|
||||
dvar_set_float_hook.create(SELECT_VALUE(0x41BC60_b, 0x185AA0_b), &dvar_set_float);
|
||||
dvar_set_int_hook.create(SELECT_VALUE(0x41BEE0_b, 0x185D10_b), &dvar_set_int);
|
||||
dvar_set_string_hook.create(SELECT_VALUE(0x41C0F0_b, 0x186080_b), &dvar_set_string);
|
||||
dvar_set_from_string_hook.create(SELECT_VALUE(0x41BE20_b, 0x185C60_b), &dvar_set_from_string);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ namespace dvars
|
||||
void register_string(const std::string& name, const std::string& value, const unsigned int flags);
|
||||
void register_vec2(const std::string& name, float x, float y, float min, float max, const unsigned int flags);
|
||||
void register_vec3(const std::string& name, float x, float y, float z, float min, float max, const unsigned int flags);
|
||||
void register_enum(const std::string& name, /*const char* const* value_list, int default_index,*/ const unsigned int flags);
|
||||
|
||||
void set_bool(const std::string& name, bool boolean);
|
||||
void set_float(const std::string& name, float fl);
|
||||
|
@ -84,9 +84,10 @@ namespace exception
|
||||
|
||||
void display_error_dialog()
|
||||
{
|
||||
std::string error_str = utils::string::va("Fatal error (0x%08X) at 0x%p.\n"
|
||||
std::string error_str = utils::string::va("Fatal error (0x%08X) at 0x%p (0x%p).\n"
|
||||
"A minidump has been written.\n\n",
|
||||
exception_data.code, exception_data.address);
|
||||
exception_data.code, exception_data.address,
|
||||
reinterpret_cast<uint64_t>(exception_data.address) - game::base_address);
|
||||
|
||||
if (!system_check::is_valid())
|
||||
{
|
||||
@ -176,6 +177,7 @@ namespace exception
|
||||
line("Clean game: "s + (system_check::is_valid() ? "Yes" : "No"));
|
||||
line(utils::string::va("Exception: 0x%08X", exceptioninfo->ExceptionRecord->ExceptionCode));
|
||||
line(utils::string::va("Address: 0x%llX", exceptioninfo->ExceptionRecord->ExceptionAddress));
|
||||
line(utils::string::va("Base: 0x%llX", game::base_address));
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4996)
|
||||
@ -253,7 +255,7 @@ namespace exception
|
||||
void post_unpack() override
|
||||
{
|
||||
dvars::cg_legacyCrashHandling = dvars::register_bool("cg_legacyCrashHandling",
|
||||
false, game::DVAR_FLAG_SAVED, true);
|
||||
false, game::DVAR_FLAG_SAVED, "Disable new crash handling");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -1,12 +1,16 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
#include "fastfiles.hpp"
|
||||
|
||||
#include "game/dvars.hpp"
|
||||
|
||||
#include "fastfiles.hpp"
|
||||
#include "command.hpp"
|
||||
#include "console.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
#include <utils/concurrency.hpp>
|
||||
#include <utils/io.hpp>
|
||||
#include <utils/string.hpp>
|
||||
|
||||
namespace fastfiles
|
||||
{
|
||||
@ -15,16 +19,69 @@ namespace fastfiles
|
||||
namespace
|
||||
{
|
||||
utils::hook::detour db_try_load_x_file_internal_hook;
|
||||
utils::hook::detour db_find_xasset_header_hook;
|
||||
game::dvar_t* g_dump_scripts;
|
||||
|
||||
void db_try_load_x_file_internal(const char* zone_name, const int flags)
|
||||
{
|
||||
printf("Loading fastfile %s\n", zone_name);
|
||||
console::info("Loading fastfile %s\n", zone_name);
|
||||
current_fastfile.access([&](std::string& fastfile)
|
||||
{
|
||||
fastfile = zone_name;
|
||||
});
|
||||
db_try_load_x_file_internal_hook.invoke<void>(zone_name, flags);
|
||||
}
|
||||
|
||||
void dump_gsc_script(const std::string& name, game::XAssetHeader header)
|
||||
{
|
||||
if (!g_dump_scripts->current.enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::string buffer;
|
||||
buffer.append(header.scriptfile->name, strlen(header.scriptfile->name) + 1);
|
||||
buffer.append(reinterpret_cast<char*>(&header.scriptfile->compressedLen), 4);
|
||||
buffer.append(reinterpret_cast<char*>(&header.scriptfile->len), 4);
|
||||
buffer.append(reinterpret_cast<char*>(&header.scriptfile->bytecodeLen), 4);
|
||||
buffer.append(header.scriptfile->buffer, header.scriptfile->compressedLen);
|
||||
buffer.append(header.scriptfile->bytecode, header.scriptfile->bytecodeLen);
|
||||
|
||||
const auto out_name = utils::string::va("gsc_dump/%s.gscbin", name.data());
|
||||
utils::io::write_file(out_name, buffer);
|
||||
|
||||
console::info("Dumped %s\n", out_name);
|
||||
}
|
||||
|
||||
game::XAssetHeader db_find_xasset_header_stub(game::XAssetType type, const char* name, int allow_create_default)
|
||||
{
|
||||
const auto start = game::Sys_Milliseconds();
|
||||
const auto result = db_find_xasset_header_hook.invoke<game::XAssetHeader>(type, name, allow_create_default);
|
||||
const auto diff = game::Sys_Milliseconds() - start;
|
||||
|
||||
if (type == game::XAssetType::ASSET_TYPE_SCRIPTFILE)
|
||||
{
|
||||
dump_gsc_script(name, result);
|
||||
}
|
||||
|
||||
if (diff > 100)
|
||||
{
|
||||
console::print(
|
||||
result.data == nullptr
|
||||
? console::con_type_error
|
||||
: console::con_type_warning,
|
||||
"Waited %i msec for %sasset \"%s\", of type \"%s\"\n",
|
||||
diff,
|
||||
result.data == nullptr
|
||||
? "missing "
|
||||
: "",
|
||||
name,
|
||||
game::g_assetNames[type]
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
std::string get_current_fastfile()
|
||||
@ -35,13 +92,27 @@ namespace fastfiles
|
||||
});
|
||||
}
|
||||
|
||||
void enum_assets(const game::XAssetType type,
|
||||
const std::function<void(game::XAssetHeader)>& callback, const bool includeOverride)
|
||||
{
|
||||
game::DB_EnumXAssets_Internal(type, static_cast<void(*)(game::XAssetHeader, void*)>([](game::XAssetHeader header, void* data)
|
||||
{
|
||||
const auto& cb = *static_cast<const std::function<void(game::XAssetHeader)>*>(data);
|
||||
cb(header);
|
||||
}), &callback, includeOverride);
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
db_try_load_x_file_internal_hook.create(
|
||||
SELECT_VALUE(0x1401CDDD0, 0x1402BFFE0), &db_try_load_x_file_internal);
|
||||
SELECT_VALUE(0x1F5700_b, 0x39A620_b), &db_try_load_x_file_internal);
|
||||
|
||||
db_find_xasset_header_hook.create(game::DB_FindXAssetHeader, db_find_xasset_header_stub);
|
||||
|
||||
g_dump_scripts = dvars::register_bool("g_dumpScripts", false, game::DVAR_FLAG_NONE, "Dump GSC scripts");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -5,4 +5,7 @@
|
||||
namespace fastfiles
|
||||
{
|
||||
std::string get_current_fastfile();
|
||||
|
||||
void enum_assets(const game::XAssetType type,
|
||||
const std::function<void(game::XAssetHeader)>& callback, const bool includeOverride);
|
||||
}
|
||||
|
90
src/client/component/filesystem.cpp
Normal file
90
src/client/component/filesystem.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
#include "filesystem.hpp"
|
||||
#include "game_module.hpp"
|
||||
|
||||
#include "game/game.hpp"
|
||||
#include "dvars.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
#include <utils/string.hpp>
|
||||
#include <utils/io.hpp>
|
||||
|
||||
namespace filesystem
|
||||
{
|
||||
file::file(std::string name)
|
||||
: name_(std::move(name))
|
||||
{
|
||||
char* buffer{};
|
||||
const auto size = game::FS_ReadFile(this->name_.data(), &buffer);
|
||||
|
||||
if (size >= 0 && buffer)
|
||||
{
|
||||
this->valid_ = true;
|
||||
this->buffer_.append(buffer, size);
|
||||
game::FS_FreeFile(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
bool file::exists() const
|
||||
{
|
||||
return this->valid_;
|
||||
}
|
||||
|
||||
const std::string& file::get_buffer() const
|
||||
{
|
||||
return this->buffer_;
|
||||
}
|
||||
|
||||
const std::string& file::get_name() const
|
||||
{
|
||||
return this->name_;
|
||||
}
|
||||
|
||||
std::unordered_set<std::string>& get_search_paths()
|
||||
{
|
||||
static std::unordered_set<std::string> search_paths{};
|
||||
return search_paths;
|
||||
}
|
||||
|
||||
std::string read_file(const std::string& path)
|
||||
{
|
||||
for (const auto& search_path : get_search_paths())
|
||||
{
|
||||
const auto path_ = search_path + "/" + path;
|
||||
if (utils::io::file_exists(path_))
|
||||
{
|
||||
return utils::io::read_file(path_);
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
bool read_file(const std::string& path, std::string* data)
|
||||
{
|
||||
for (const auto& search_path : get_search_paths())
|
||||
{
|
||||
const auto path_ = search_path + "/" + path;
|
||||
if (utils::io::read_file(path_, data))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
get_search_paths().insert(".");
|
||||
get_search_paths().insert("h1-mod");
|
||||
get_search_paths().insert("data");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(filesystem::component)
|
23
src/client/component/filesystem.hpp
Normal file
23
src/client/component/filesystem.hpp
Normal file
@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
namespace filesystem
|
||||
{
|
||||
class file
|
||||
{
|
||||
public:
|
||||
file(std::string name);
|
||||
|
||||
bool exists() const;
|
||||
const std::string& get_buffer() const;
|
||||
const std::string& get_name() const;
|
||||
|
||||
private:
|
||||
bool valid_ = false;
|
||||
std::string name_;
|
||||
std::string buffer_;
|
||||
};
|
||||
|
||||
std::unordered_set<std::string>& get_search_paths();
|
||||
std::string read_file(const std::string& path);
|
||||
bool read_file(const std::string& path, std::string* data);
|
||||
}
|
136
src/client/component/fonts.cpp
Normal file
136
src/client/component/fonts.cpp
Normal file
@ -0,0 +1,136 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "fonts.hpp"
|
||||
#include "console.hpp"
|
||||
#include "filesystem.hpp"
|
||||
|
||||
#include "game/game.hpp"
|
||||
#include "game/dvars.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
#include <utils/memory.hpp>
|
||||
#include <utils/io.hpp>
|
||||
#include <utils/string.hpp>
|
||||
#include <utils/image.hpp>
|
||||
#include <utils/concurrency.hpp>
|
||||
|
||||
namespace fonts
|
||||
{
|
||||
namespace
|
||||
{
|
||||
struct font_data_t
|
||||
{
|
||||
std::unordered_map<std::string, game::TTF*> fonts;
|
||||
std::unordered_map<std::string, std::string> raw_fonts;
|
||||
};
|
||||
|
||||
utils::concurrency::container<font_data_t> font_data;
|
||||
|
||||
game::TTF* create_font(const std::string& name, const std::string& data)
|
||||
{
|
||||
const auto font = utils::memory::get_allocator()->allocate<game::TTF>();
|
||||
font->name = utils::memory::get_allocator()->duplicate_string(name);
|
||||
font->buffer = utils::memory::get_allocator()->duplicate_string(data);
|
||||
font->len = static_cast<int>(data.size());
|
||||
font->fontFace = 0;
|
||||
return font;
|
||||
}
|
||||
|
||||
void free_font(game::TTF* font)
|
||||
{
|
||||
utils::memory::get_allocator()->free(font->buffer);
|
||||
utils::memory::get_allocator()->free(font->name);
|
||||
utils::memory::get_allocator()->free(font);
|
||||
}
|
||||
|
||||
game::TTF* load_font(const std::string& name)
|
||||
{
|
||||
return font_data.access<game::TTF*>([&](font_data_t& data_) -> game::TTF*
|
||||
{
|
||||
if (const auto i = data_.fonts.find(name); i != data_.fonts.end())
|
||||
{
|
||||
return i->second;
|
||||
}
|
||||
|
||||
std::string data{};
|
||||
if (const auto i = data_.raw_fonts.find(name); i != data_.raw_fonts.end())
|
||||
{
|
||||
data = i->second;
|
||||
}
|
||||
|
||||
if (data.empty() && !filesystem::read_file(name, &data))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const auto material = create_font(name, data);
|
||||
data_.fonts[name] = material;
|
||||
|
||||
return material;
|
||||
});
|
||||
}
|
||||
|
||||
game::TTF* try_load_font(const std::string& name)
|
||||
{
|
||||
try
|
||||
{
|
||||
return load_font(name);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
console::error("Failed to load font %s: %s\n", name.data(), e.what());
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
game::TTF* db_find_xasset_header_stub(game::XAssetType type, const char* name, int create_default)
|
||||
{
|
||||
auto result = try_load_font(name);
|
||||
if (result == nullptr)
|
||||
{
|
||||
result = game::DB_FindXAssetHeader(type, name, create_default).ttf;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
void add(const std::string& name, const std::string& data)
|
||||
{
|
||||
font_data.access([&](font_data_t& data_)
|
||||
{
|
||||
data_.raw_fonts[name] = data;
|
||||
});
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
font_data.access([&](font_data_t& data_)
|
||||
{
|
||||
for (auto& font : data_.fonts)
|
||||
{
|
||||
free_font(font.second);
|
||||
}
|
||||
|
||||
data_.fonts.clear();
|
||||
utils::hook::set<int>(SELECT_VALUE(0xF793E38_b, 0xE962188_b), 0); // reset registered font count
|
||||
});
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
if (game::environment::is_dedi())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
utils::hook::call(SELECT_VALUE(0x55C596_b, 0x67F6E6_b), db_find_xasset_header_stub);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(fonts::component)
|
7
src/client/component/fonts.hpp
Normal file
7
src/client/component/fonts.hpp
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
namespace fonts
|
||||
{
|
||||
void add(const std::string& name, const std::string& data);
|
||||
void clear();
|
||||
}
|
@ -1,8 +1,11 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "fps.hpp"
|
||||
|
||||
#include "game/game.hpp"
|
||||
#include "game/dvars.hpp"
|
||||
#include "dvars.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
#include <utils/string.hpp>
|
||||
@ -12,6 +15,8 @@ namespace fps
|
||||
{
|
||||
namespace
|
||||
{
|
||||
utils::hook::detour sub_5D6810_hook;
|
||||
|
||||
game::dvar_t* cg_drawfps;
|
||||
game::dvar_t* cg_drawping;
|
||||
|
||||
@ -85,38 +90,35 @@ namespace fps
|
||||
cg_perf.previous_ms = cg_perf.current_ms;
|
||||
|
||||
perf_calc_fps(&cg_perf, cg_perf.frame_ms);
|
||||
|
||||
utils::hook::invoke<void>(SELECT_VALUE(0x1405487A0, 0x1406575A0)); // H1(1.4)
|
||||
}
|
||||
|
||||
void cg_draw_fps()
|
||||
{
|
||||
if (cg_drawfps->current.integer > 0)
|
||||
{
|
||||
const auto fps = static_cast<std::int32_t>(static_cast<float>(1000.0f / static_cast<float>(cg_perf.
|
||||
average))
|
||||
+ 9.313225746154785e-10);
|
||||
const auto fps = fps::get_fps();
|
||||
|
||||
const auto font = game::R_RegisterFont("fonts/fira_mono_regular.ttf", 25);
|
||||
const auto fps_string = utils::string::va("%i", fps);
|
||||
if (font)
|
||||
{
|
||||
const auto fps_string = utils::string::va("%i", fps);
|
||||
|
||||
const auto x = (game::ScrPlace_GetViewPlacement()->realViewportSize[0] - 15.0f) - game::R_TextWidth(
|
||||
fps_string, 0x7FFFFFFF, font);
|
||||
const auto y = font->pixelHeight + 10.f;
|
||||
const auto x = (game::ScrPlace_GetViewPlacement()->realViewportSize[0] - 15.0f) -
|
||||
game::R_TextWidth(fps_string, 0x7FFFFFFF, font);
|
||||
const auto y = font->pixelHeight + 10.f;
|
||||
|
||||
const auto fps_color = fps >= 60 ? fps_color_good : (fps >= 30 ? fps_color_ok : fps_color_bad);
|
||||
game::R_AddCmdDrawText(fps_string, 0x7FFFFFFF, font, x, y, 1.f, 1.f, 0.0f, fps_color, 6);
|
||||
const auto fps_color = fps >= 60 ? fps_color_good : (fps >= 30 ? fps_color_ok : fps_color_bad);
|
||||
game::R_AddCmdDrawText(fps_string, 0x7FFFFFFF, font, x, y, 1.f, 1.f, 0.0f, fps_color, 6);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cg_draw_ping()
|
||||
{
|
||||
if (cg_drawping->current.integer > 0 && game::CL_IsCgameInitialized())
|
||||
if (cg_drawping->current.integer > 0 && game::CL_IsCgameInitialized() && !game::VirtualLobby_Loaded() && *game::mp::client_state)
|
||||
{
|
||||
const auto ping = *reinterpret_cast<int*>(0x142D106F0);
|
||||
|
||||
const auto font = game::R_RegisterFont("fonts/consolefont", 20);
|
||||
const auto ping_string = utils::string::va("Ping: %i", ping);
|
||||
const auto ping_string = utils::string::va("Ping: %i", (*game::mp::client_state)->ping);
|
||||
|
||||
const auto x = (game::ScrPlace_GetViewPlacement()->realViewportSize[0] - 375.0f) - game::R_TextWidth(
|
||||
ping_string, 0x7FFFFFFF, font);
|
||||
@ -126,12 +128,24 @@ namespace fps
|
||||
}
|
||||
}
|
||||
|
||||
game::dvar_t* cg_draw_fps_register_stub(const char* name, const char** _enum, const int value, unsigned int /*flags*/,
|
||||
const char* desc)
|
||||
game::dvar_t* cg_draw_fps_register_stub()
|
||||
{
|
||||
cg_drawfps = dvars::register_int("cg_drawFps", 0, 0, 2, game::DVAR_FLAG_SAVED, false);
|
||||
cg_drawfps = dvars::register_int("cg_drawFps", 0, 0, 2, game::DVAR_FLAG_SAVED, "Draw frames per second");
|
||||
return cg_drawfps;
|
||||
}
|
||||
|
||||
void sub_5D6810_stub()
|
||||
{
|
||||
perf_update();
|
||||
sub_5D6810_hook.invoke<void>();
|
||||
}
|
||||
}
|
||||
|
||||
int get_fps()
|
||||
{
|
||||
return static_cast<std::int32_t>(static_cast<float>(1000.0f / static_cast<float>(cg_perf.
|
||||
average))
|
||||
+ 9.313225746154785e-10);
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
@ -146,27 +160,50 @@ namespace fps
|
||||
|
||||
// fps setup
|
||||
cg_perf.perf_start = std::chrono::high_resolution_clock::now();
|
||||
utils::hook::call(SELECT_VALUE(0x14018D261, 0x14025B747), &perf_update);
|
||||
|
||||
// change cg_drawfps flags to saved
|
||||
utils::hook::call(SELECT_VALUE(0x140139F48, 0x140222A46), &cg_draw_fps_register_stub);
|
||||
if (game::environment::is_mp())
|
||||
{
|
||||
utils::hook::jump(SELECT_VALUE(0, 0x343847_b), utils::hook::assemble([](utils::hook::assembler& a)
|
||||
{
|
||||
a.pushad64();
|
||||
a.call_aligned(perf_update);
|
||||
a.popad64();
|
||||
|
||||
a.call(0x702250_b);
|
||||
a.mov(edx, 3);
|
||||
a.xor_(ecx, ecx);
|
||||
a.jmp(0x343853_b);
|
||||
}), true);
|
||||
|
||||
// Don't register cg_drawfps
|
||||
utils::hook::nop(0x31D74F_b, 0x1C);
|
||||
utils::hook::nop(0x31D76F_b, 0x7);
|
||||
}
|
||||
else
|
||||
{
|
||||
sub_5D6810_hook.create(0x5D6810_b, sub_5D6810_stub);
|
||||
|
||||
// Don't register cg_drawfps
|
||||
utils::hook::nop(0x15C97D_b, 0x20);
|
||||
utils::hook::nop(0x15C9A1_b, 0x7);
|
||||
}
|
||||
|
||||
scheduler::loop(cg_draw_fps, scheduler::pipeline::renderer);
|
||||
|
||||
if (game::environment::is_sp())
|
||||
{
|
||||
cg_drawfps = dvars::register_int("cg_drawFps", 0, 0, 2, game::DVAR_FLAG_SAVED, false);
|
||||
}
|
||||
cg_drawfps = dvars::register_int("cg_drawFps", 0, 0, 2, game::DVAR_FLAG_SAVED, "Draw frames per second");
|
||||
|
||||
if (game::environment::is_mp())
|
||||
{
|
||||
// fix ping value
|
||||
utils::hook::nop(0x14025AC41, 2);
|
||||
utils::hook::nop(0x342C6C_b, 2);
|
||||
|
||||
cg_drawping = dvars::register_int("cg_drawPing", 0, 0, 1, game::DVAR_FLAG_SAVED, true);
|
||||
cg_drawping = dvars::register_int("cg_drawPing", 0, 0, 1, game::DVAR_FLAG_SAVED, "Choose to draw ping");
|
||||
|
||||
scheduler::loop(cg_draw_ping, scheduler::pipeline::renderer);
|
||||
}
|
||||
|
||||
dvars::register_bool("cg_infobar_fps", false, game::DVAR_FLAG_SAVED, "Show server latency");
|
||||
dvars::register_bool("cg_infobar_ping", false, game::DVAR_FLAG_SAVED, "Show FPS counter");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
6
src/client/component/fps.hpp
Normal file
6
src/client/component/fps.hpp
Normal file
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
namespace fps
|
||||
{
|
||||
int get_fps();
|
||||
}
|
@ -56,10 +56,10 @@ namespace game_console
|
||||
std::deque<std::string> history{};
|
||||
|
||||
std::string fixed_input{};
|
||||
std::vector<std::string> matches{};
|
||||
std::vector<dvars::dvar_info> matches{};
|
||||
|
||||
float color_white[4] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
float color_title[4] = {0.9f, 0.9f, 0.5f, 1.0f};
|
||||
float color_title[4] = {0.3f, 0.7f, 0.3f, 1.0f};
|
||||
|
||||
void clear()
|
||||
{
|
||||
@ -159,38 +159,32 @@ namespace game_console
|
||||
con.globals.x = game::R_TextWidth(str, 0, console_font) + con.globals.x + 6.0f;
|
||||
}
|
||||
|
||||
void draw_hint_box(const int lines, float* color, [[maybe_unused]] float offset_x = 0.0f,
|
||||
float draw_hint_box(const int lines, float* color, [[maybe_unused]] float offset_x = 0.0f,
|
||||
[[maybe_unused]] float offset_y = 0.0f)
|
||||
{
|
||||
const auto _h = lines * con.globals.font_height + 12.0f;
|
||||
const auto _y = con.globals.y - 3.0f + con.globals.font_height + 12.0f;
|
||||
const auto _y = con.globals.y - 3.0f + con.globals.font_height + 12.0f + offset_y;
|
||||
const auto _w = (con.screen_max[0] - con.screen_min[0]) - ((con.globals.x - 6.0f) - con.screen_min[0]);
|
||||
|
||||
draw_box(con.globals.x - 6.0f, _y, _w, _h, color);
|
||||
return _h;
|
||||
}
|
||||
|
||||
void draw_hint_text(const int line, const char* text, float* color, const float offset = 0.0f)
|
||||
void draw_hint_text(const int line, const char* text, float* color, const float offset_x = 0.0f, const float offset_y = 0.0f)
|
||||
{
|
||||
const auto _y = con.globals.font_height + con.globals.y + (con.globals.font_height * (line + 1)) + 15.0f;
|
||||
const auto _y = con.globals.font_height + con.globals.y + (con.globals.font_height * (line + 1)) + 15.0f + offset_y;
|
||||
|
||||
game::R_AddCmdDrawText(text, 0x7FFFFFFF, console_font, con.globals.x + offset, _y, 1.0f, 1.0f, 0.0f, color, 0);
|
||||
game::R_AddCmdDrawText(text, 0x7FFFFFFF, console_font, con.globals.x + offset_x, _y, 1.0f, 1.0f, 0.0f, color, 0);
|
||||
}
|
||||
|
||||
bool match_compare(const std::string& input, const std::string& text, const bool exact)
|
||||
{
|
||||
if (exact && text == input) return true;
|
||||
if (!exact && text.find(input) != std::string::npos) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void find_matches(std::string input, std::vector<std::string>& suggestions, const bool exact)
|
||||
void find_matches(std::string input, std::vector<dvars::dvar_info>& suggestions, const bool exact)
|
||||
{
|
||||
input = utils::string::to_lower(input);
|
||||
|
||||
for (const auto& dvar : dvars::dvar_list)
|
||||
{
|
||||
auto name = utils::string::to_lower(dvar);
|
||||
if (game::Dvar_FindVar(name.data()) && match_compare(input, name, exact))
|
||||
auto name = utils::string::to_lower(dvar.name);
|
||||
if (game::Dvar_FindVar(name.data()) && utils::string::match_compare(input, name, exact))
|
||||
{
|
||||
suggestions.push_back(dvar);
|
||||
}
|
||||
@ -203,7 +197,7 @@ namespace game_console
|
||||
|
||||
if (suggestions.size() == 0 && game::Dvar_FindVar(input.data()))
|
||||
{
|
||||
suggestions.push_back(input.data());
|
||||
suggestions.push_back({input, ""});
|
||||
}
|
||||
|
||||
game::cmd_function_s* cmd = (*game::cmd_functions);
|
||||
@ -213,9 +207,9 @@ namespace game_console
|
||||
{
|
||||
std::string name = utils::string::to_lower(cmd->name);
|
||||
|
||||
if (match_compare(input, name, exact))
|
||||
if (utils::string::match_compare(input, name, exact))
|
||||
{
|
||||
suggestions.push_back(cmd->name);
|
||||
suggestions.push_back({cmd->name, ""});
|
||||
}
|
||||
|
||||
if (exact && suggestions.size() > 1)
|
||||
@ -275,56 +269,79 @@ namespace game_console
|
||||
if (matches.size() > 24)
|
||||
{
|
||||
draw_hint_box(1, dvars::con_inputHintBoxColor->current.vector);
|
||||
draw_hint_text(0, utils::string::va("%i matches (too many to show here)", matches.size()),
|
||||
draw_hint_text(0, utils::string::va("%i matches (too many to show here). Press SHIFT + TAB to show them", matches.size()),
|
||||
dvars::con_inputDvarMatchColor->current.vector);
|
||||
|
||||
if (game::playerKeys[0].keys[game::keyNum_t::K_SHIFT].down && game::playerKeys[0].keys[game::keyNum_t::K_TAB].down)
|
||||
{
|
||||
console::info("]%s\n", con.buffer);
|
||||
for (int i = 0; i < matches.size(); i++)
|
||||
{
|
||||
console::info("\t%s\n", matches[i].name.data());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (matches.size() == 1)
|
||||
{
|
||||
auto* const dvar = game::Dvar_FindVar(matches[0].data());
|
||||
const auto line_count = dvar ? 2 : 1;
|
||||
auto* const dvar = game::Dvar_FindVar(matches[0].name.data());
|
||||
const auto line_count = dvar ? 3 : 1;
|
||||
|
||||
draw_hint_box(line_count, dvars::con_inputHintBoxColor->current.vector);
|
||||
draw_hint_text(0, matches[0].data(), dvar
|
||||
const auto height = draw_hint_box(line_count, dvars::con_inputHintBoxColor->current.vector);
|
||||
draw_hint_text(0, matches[0].name.data(), dvar
|
||||
? dvars::con_inputDvarMatchColor->current.vector
|
||||
: dvars::con_inputCmdMatchColor->current.vector);
|
||||
|
||||
if (dvar)
|
||||
{
|
||||
const auto offset = (con.screen_max[0] - con.globals.x) / 2.5f;
|
||||
const auto offset = (con.screen_max[0] - con.globals.x) / 4.f;
|
||||
|
||||
draw_hint_text(0, game::Dvar_ValueToString(dvar, dvar->current),
|
||||
draw_hint_text(0, game::Dvar_ValueToString(dvar, true, dvar->current),
|
||||
dvars::con_inputDvarValueColor->current.vector, offset);
|
||||
draw_hint_text(1, " default", dvars::con_inputDvarInactiveValueColor->current.vector);
|
||||
draw_hint_text(1, game::Dvar_ValueToString(dvar, dvar->reset),
|
||||
draw_hint_text(1, game::Dvar_ValueToString(dvar, true, dvar->reset),
|
||||
dvars::con_inputDvarInactiveValueColor->current.vector, offset);
|
||||
draw_hint_text(2, matches[0].description.data(),
|
||||
color_white, 0);
|
||||
|
||||
const auto offset_y = height + 3.f;
|
||||
const auto line_count_ = dvar->type == game::dvar_type::enumeration
|
||||
? dvar->domain.enumeration.stringCount + 1
|
||||
: 1;
|
||||
|
||||
draw_hint_box(line_count_, dvars::con_inputHintBoxColor->current.vector, 0, offset_y);
|
||||
draw_hint_text(0, dvars::dvar_get_domain(dvar->type, dvar->domain).data(),
|
||||
dvars::con_inputCmdMatchColor->current.vector, 0, offset_y);
|
||||
}
|
||||
|
||||
strncpy_s(con.globals.auto_complete_choice, matches[0].data(), 64);
|
||||
strncpy_s(con.globals.auto_complete_choice, matches[0].name.data(), 64);
|
||||
con.globals.may_auto_complete = true;
|
||||
}
|
||||
else if (matches.size() > 1)
|
||||
{
|
||||
draw_hint_box(static_cast<int>(matches.size()), dvars::con_inputHintBoxColor->current.vector);
|
||||
|
||||
const auto offset = (con.screen_max[0] - con.globals.x) / 2.5f;
|
||||
const auto offset = (con.screen_max[0] - con.globals.x) / 4.f;
|
||||
|
||||
for (size_t i = 0; i < matches.size(); i++)
|
||||
{
|
||||
auto* const dvar = game::Dvar_FindVar(matches[i].data());
|
||||
auto* const dvar = game::Dvar_FindVar(matches[i].name.data());
|
||||
|
||||
draw_hint_text(static_cast<int>(i), matches[i].data(),
|
||||
draw_hint_text(static_cast<int>(i), matches[i].name.data(),
|
||||
dvar
|
||||
? dvars::con_inputDvarMatchColor->current.vector
|
||||
: dvars::con_inputCmdMatchColor->current.vector);
|
||||
|
||||
if (dvar)
|
||||
{
|
||||
draw_hint_text(static_cast<int>(i), game::Dvar_ValueToString(dvar, dvar->current),
|
||||
draw_hint_text(static_cast<int>(i), game::Dvar_ValueToString(dvar, true, dvar->current),
|
||||
dvars::con_inputDvarValueColor->current.vector, offset);
|
||||
|
||||
draw_hint_text(static_cast<int>(i), matches[i].description.data(),
|
||||
dvars::con_inputDvarValueColor->current.vector, offset * 1.5f);
|
||||
}
|
||||
}
|
||||
|
||||
strncpy_s(con.globals.auto_complete_choice, matches[0].data(), 64);
|
||||
strncpy_s(con.globals.auto_complete_choice, matches[0].name.data(), 64);
|
||||
con.globals.may_auto_complete = true;
|
||||
}
|
||||
}
|
||||
@ -383,7 +400,7 @@ namespace game_console
|
||||
const auto width = (con.screen_max[0] - con.screen_min[0]) - 12.0f;
|
||||
const auto height = ((con.screen_max[1] - con.screen_min[1]) - 32.0f) - 12.0f;
|
||||
|
||||
game::R_AddCmdDrawText("H1-Mod 1.4", 0x7FFFFFFF, console_font, x,
|
||||
game::R_AddCmdDrawText("H1-Mod 1.15", 0x7FFFFFFF, console_font, x,
|
||||
((height - 16.0f) + y) + console_font->pixelHeight, 1.0f, 1.0f, 0.0f, color_title, 0);
|
||||
|
||||
draw_output_scrollbar(x, y, width, height, output);
|
||||
@ -453,11 +470,19 @@ namespace game_console
|
||||
|
||||
bool console_char_event(const int local_client_num, const int key)
|
||||
{
|
||||
if (key == game::keyNum_t::K_GRAVE || key == game::keyNum_t::K_TILDE)
|
||||
if (key == game::keyNum_t::K_GRAVE ||
|
||||
key == game::keyNum_t::K_TILDE ||
|
||||
key == '|' ||
|
||||
key == '\\')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (key > 127)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (*game::keyCatchers & 1)
|
||||
{
|
||||
if (key == game::keyNum_t::K_TAB) // tab (auto complete)
|
||||
@ -555,7 +580,7 @@ namespace game_console
|
||||
{
|
||||
if (key == game::keyNum_t::K_F10)
|
||||
{
|
||||
if (!game::Com_InFrontEnd())
|
||||
if (!game::Com_InFrontend())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -570,10 +595,13 @@ namespace game_console
|
||||
return false;
|
||||
}
|
||||
|
||||
if (game::playerKeys[local_client_num].keys[game::keyNum_t::K_SHIFT].down)
|
||||
const auto shift_down = game::playerKeys[local_client_num].keys[game::keyNum_t::K_SHIFT].down;
|
||||
if (shift_down)
|
||||
{
|
||||
if (!(*game::keyCatchers & 1))
|
||||
{
|
||||
toggle_console();
|
||||
}
|
||||
|
||||
toggle_console_output();
|
||||
return false;
|
||||
@ -664,7 +692,7 @@ namespace game_console
|
||||
|
||||
if (key == game::keyNum_t::K_ENTER)
|
||||
{
|
||||
game::Cbuf_AddText(0, utils::string::va("%s \n", fixed_input.data()));
|
||||
game::Cbuf_AddText(0, 0, utils::string::va("%s \n", fixed_input.data()));
|
||||
|
||||
if (history_index != -1)
|
||||
{
|
||||
@ -695,7 +723,6 @@ namespace game_console
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
@ -705,20 +732,17 @@ namespace game_console
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//scheduler::loop(draw_console, scheduler::pipeline::renderer);
|
||||
}
|
||||
|
||||
void post_unpack() override
|
||||
{
|
||||
scheduler::loop(draw_console, scheduler::pipeline::renderer);
|
||||
|
||||
|
||||
if (game::environment::is_dedi())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
scheduler::loop(draw_console, scheduler::pipeline::renderer);
|
||||
|
||||
// initialize our structs
|
||||
con.cursor = 0;
|
||||
con.visible_line_count = 0;
|
||||
@ -759,7 +783,7 @@ namespace game_console
|
||||
dvars::con_outputBarColor = dvars::register_vec4("con_outputBarColor", 0.5f, 0.5f, 0.5f, 0.6f, 0.0f,
|
||||
1.0f, game::DVAR_FLAG_SAVED,
|
||||
"color of console output bar");
|
||||
dvars::con_outputSliderColor = dvars::register_vec4("con_outputSliderColor", 1.0f, 0.8f, 0.0f, 1.0f,
|
||||
dvars::con_outputSliderColor = dvars::register_vec4("con_outputSliderColor", 0.3f, 0.7f, 0.3f, 1.0f,
|
||||
0.0f, 1.0f,
|
||||
game::DVAR_FLAG_SAVED, "color of console output slider");
|
||||
dvars::con_outputWindowColor = dvars::register_vec4("con_outputWindowColor", 0.25f, 0.25f, 0.25f, 0.85f,
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "game_module.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
#include <game/game.hpp>
|
||||
|
||||
namespace game_module
|
||||
{
|
||||
@ -59,9 +60,9 @@ namespace game_module
|
||||
|
||||
DWORD __stdcall get_module_file_name_a(HMODULE hmodule, const LPSTR filename, const DWORD size)
|
||||
{
|
||||
if (!hmodule)
|
||||
if (!hmodule || utils::nt::library(hmodule) == get_game_module())
|
||||
{
|
||||
hmodule = get_game_module();
|
||||
hmodule = get_host_module();
|
||||
}
|
||||
|
||||
return file_name_a_hook.invoke<DWORD>(hmodule, filename, size);
|
||||
@ -69,9 +70,9 @@ namespace game_module
|
||||
|
||||
DWORD __stdcall get_module_file_name_w(HMODULE hmodule, const LPWSTR filename, const DWORD size)
|
||||
{
|
||||
if (!hmodule)
|
||||
if (!hmodule || utils::nt::library(hmodule) == get_game_module())
|
||||
{
|
||||
hmodule = get_game_module();
|
||||
hmodule = get_host_module();
|
||||
}
|
||||
|
||||
return file_name_w_hook.invoke<DWORD>(hmodule, filename, size);
|
||||
@ -90,7 +91,7 @@ namespace game_module
|
||||
|
||||
utils::nt::library get_game_module()
|
||||
{
|
||||
static utils::nt::library game{HMODULE(0x140000000)};
|
||||
static utils::nt::library game{HMODULE(game::base_address)};
|
||||
return game;
|
||||
}
|
||||
|
||||
@ -110,7 +111,11 @@ namespace game_module
|
||||
|
||||
void post_load() override
|
||||
{
|
||||
#ifdef INJECT_HOST_AS_LIB
|
||||
hook_module_resolving();
|
||||
#else
|
||||
assert(get_host_module() == get_game_module());
|
||||
#endif
|
||||
}
|
||||
};
|
||||
}
|
||||
|
350
src/client/component/gameplay.cpp
Normal file
350
src/client/component/gameplay.cpp
Normal file
@ -0,0 +1,350 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "dvars.hpp"
|
||||
|
||||
#include "game/game.hpp"
|
||||
#include "game/dvars.hpp"
|
||||
|
||||
#include <utils/nt.hpp>
|
||||
#include <utils/hook.hpp>
|
||||
#include <utils/flags.hpp>
|
||||
|
||||
namespace gameplay
|
||||
{
|
||||
namespace
|
||||
{
|
||||
utils::hook::detour pm_weapon_use_ammo_hook;
|
||||
utils::hook::detour pm_player_trace_hook;
|
||||
utils::hook::detour pm_crashland_hook;
|
||||
utils::hook::detour jump_apply_slowdown_hook;
|
||||
utils::hook::detour stuck_in_client_hook;
|
||||
utils::hook::detour cm_transformed_capsule_trace_hook;
|
||||
|
||||
utils::hook::detour client_end_frame_hook;
|
||||
utils::hook::detour g_damage_client_hook;
|
||||
utils::hook::detour g_damage_hook;
|
||||
|
||||
game::dvar_t* jump_slowDownEnable;
|
||||
game::dvar_t* jump_enableFallDamage;
|
||||
|
||||
void jump_apply_slowdown_stub(game::mp::playerState_s* ps)
|
||||
{
|
||||
if (jump_slowDownEnable->current.enabled)
|
||||
{
|
||||
jump_apply_slowdown_hook.invoke<void>(ps);
|
||||
}
|
||||
}
|
||||
|
||||
void stuck_in_client_stub(void* entity)
|
||||
{
|
||||
if (dvars::g_playerEjection->current.enabled)
|
||||
{
|
||||
stuck_in_client_hook.invoke<void>(entity);
|
||||
}
|
||||
}
|
||||
|
||||
void cm_transformed_capsule_trace_stub(game::trace_t* results, const float* start, const float* end,
|
||||
game::Bounds* bounds, game::Bounds* capsule, int contents, const float* origin, const float* angles)
|
||||
{
|
||||
if (dvars::g_playerCollision->current.enabled)
|
||||
{
|
||||
cm_transformed_capsule_trace_hook.invoke<void>(results, start, end,
|
||||
bounds, capsule, contents, origin, angles);
|
||||
}
|
||||
}
|
||||
|
||||
void pm_crashland_stub(game::mp::playerState_s* ps, void* pml)
|
||||
{
|
||||
if (jump_enableFallDamage->current.enabled)
|
||||
{
|
||||
pm_crashland_hook.invoke<void>(ps, pml);
|
||||
}
|
||||
}
|
||||
|
||||
void pm_weapon_use_ammo_stub(game::playerState_s* ps, game::Weapon weapon,
|
||||
bool is_alternate, int amount, game::PlayerHandIndex hand)
|
||||
{
|
||||
if (!dvars::player_sustainAmmo->current.enabled)
|
||||
{
|
||||
pm_weapon_use_ammo_hook.invoke<void>(ps, weapon, is_alternate, amount, hand);
|
||||
}
|
||||
}
|
||||
|
||||
void* pm_bouncing_stub_mp()
|
||||
{
|
||||
return utils::hook::assemble([](utils::hook::assembler& a)
|
||||
{
|
||||
const auto no_bounce = a.newLabel();
|
||||
const auto loc_2D395D = a.newLabel();
|
||||
|
||||
a.push(rax);
|
||||
|
||||
a.mov(rax, qword_ptr(reinterpret_cast<int64_t>(&dvars::pm_bouncing)));
|
||||
a.mov(al, byte_ptr(rax, 0x10));
|
||||
a.cmp(byte_ptr(rbp, -0x7D), al);
|
||||
|
||||
a.pop(rax);
|
||||
a.jz(no_bounce);
|
||||
a.jmp(0x2D39C0_b);
|
||||
|
||||
a.bind(no_bounce);
|
||||
a.cmp(dword_ptr(rsp, 0x44), 0);
|
||||
a.jnz(loc_2D395D);
|
||||
a.jmp(0x2D39B1_b);
|
||||
|
||||
a.bind(loc_2D395D);
|
||||
a.jmp(0x2D395D_b);
|
||||
});
|
||||
}
|
||||
|
||||
void* g_speed_stub()
|
||||
{
|
||||
return utils::hook::assemble([](utils::hook::assembler& a)
|
||||
{
|
||||
a.mov(rax, qword_ptr(reinterpret_cast<int64_t>(&dvars::g_speed)));
|
||||
a.mov(eax, dword_ptr(rax, 0x10));
|
||||
|
||||
// original code
|
||||
a.mov(dword_ptr(r14, 0x36), ax);
|
||||
a.movzx(eax, word_ptr(r14, 0x3A));
|
||||
|
||||
a.jmp(0x4006BC_b);
|
||||
});
|
||||
}
|
||||
|
||||
void* client_end_frame_stub()
|
||||
{
|
||||
return utils::hook::assemble([](utils::hook::assembler& a)
|
||||
{
|
||||
a.push(rax);
|
||||
|
||||
a.mov(rax, qword_ptr(reinterpret_cast<int64_t>(&dvars::g_gravity)));
|
||||
a.mov(eax, dword_ptr(rax, 0x10));
|
||||
a.mov(word_ptr(rbx, 0x34), ax);
|
||||
|
||||
a.pop(rax);
|
||||
|
||||
// Game code hook skipped
|
||||
a.mov(eax, dword_ptr(rbx, 0x495C));
|
||||
a.mov(rdi, rcx);
|
||||
|
||||
a.jmp(0x3FF822_b);
|
||||
});
|
||||
}
|
||||
|
||||
void pm_player_trace_stub(game::mp::pmove_t* pm, game::trace_t* trace, const float* f3,
|
||||
const float* f4, const game::Bounds* bounds, int a6, int a7)
|
||||
{
|
||||
pm_player_trace_hook.invoke<void>(pm, trace, f3, f4, bounds, a6, a7);
|
||||
|
||||
// By setting startsolid to false we allow the player to clip through solid objects above their head
|
||||
if (dvars::g_enableElevators->current.enabled)
|
||||
{
|
||||
trace->startsolid = false;
|
||||
}
|
||||
}
|
||||
|
||||
void pm_trace_stub(utils::hook::assembler& a)
|
||||
{
|
||||
const auto stand = a.newLabel();
|
||||
const auto allsolid = a.newLabel();
|
||||
|
||||
a.call(rsi); // Game code
|
||||
|
||||
a.push(rax);
|
||||
|
||||
a.mov(rax, qword_ptr(reinterpret_cast<int64_t>(&dvars::g_enableElevators)));
|
||||
a.mov(al, byte_ptr(rax, 0x10));
|
||||
a.cmp(al, 1);
|
||||
|
||||
a.pop(rax);
|
||||
|
||||
a.jz(stand); // Always stand up
|
||||
|
||||
a.cmp(byte_ptr(rsp, 0x89), 0); // Game code trace[0].allsolid == false
|
||||
a.jnz(allsolid);
|
||||
|
||||
a.bind(stand);
|
||||
a.and_(dword_ptr(r15, 0x54), 0xFFFFFFFD);
|
||||
a.jmp(0x2C9F9D_b);
|
||||
|
||||
a.bind(allsolid);
|
||||
a.jmp(0x2C9F9F_b);
|
||||
};
|
||||
|
||||
void client_end_frame_stub2(game::mp::gentity_s* entity)
|
||||
{
|
||||
client_end_frame_hook.invoke<void>(entity);
|
||||
|
||||
if ((entity->client->flags & 1)) // noclip
|
||||
{
|
||||
entity->client->pm_type = 2;
|
||||
}
|
||||
else if ((entity->client->flags & 2)) // ufo
|
||||
{
|
||||
entity->client->pm_type = 3;
|
||||
}
|
||||
}
|
||||
|
||||
void g_damage_client_stub(game::mp::gentity_s* targ, const game::mp::gentity_s* inflictor, game::mp::gentity_s* attacker,
|
||||
const float* dir, const float* point, int damage, int dflags, int mod,
|
||||
const unsigned int weapon, bool is_alternate, unsigned int hit_loc, int time_offset)
|
||||
{
|
||||
if ((targ->client->flags & 1) || (targ->client->flags & 2)) // noclip, ufo
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
g_damage_client_hook.invoke<void>(targ, inflictor, attacker, dir, point, damage, dflags, mod,
|
||||
weapon, is_alternate, hit_loc, time_offset);
|
||||
}
|
||||
|
||||
void g_damage_stub(game::mp::gentity_s* targ, const game::mp::gentity_s* inflictor, game::mp::gentity_s* attacker,
|
||||
const float* dir, const float* point, int damage, int dflags, int mod,
|
||||
const unsigned int weapon, bool is_alternate, unsigned int hit_loc,
|
||||
unsigned int model_index, unsigned int part_name, int time_offset, int a15)
|
||||
{
|
||||
if (targ->flags & 1) // godmode
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (targ->flags & 2) // demigod
|
||||
{
|
||||
damage = 1;
|
||||
}
|
||||
|
||||
g_damage_hook.invoke<void>(targ, inflictor, attacker, dir, point, damage, dflags, mod, weapon,
|
||||
is_alternate, hit_loc, model_index, part_name, time_offset, a15);
|
||||
}
|
||||
|
||||
void* jump_push_off_ladder()
|
||||
{
|
||||
return utils::hook::assemble([](utils::hook::assembler& a)
|
||||
{
|
||||
a.push(rax);
|
||||
|
||||
a.mov(rax, qword_ptr(reinterpret_cast<int64_t>(&dvars::jump_ladderPushVel)));
|
||||
a.mulss(xmm7, dword_ptr(rax, 0x10));
|
||||
a.mulss(xmm6, dword_ptr(rax, 0x10));
|
||||
|
||||
a.pop(rax);
|
||||
|
||||
a.jmp(0x2BD71C_b);
|
||||
});
|
||||
}
|
||||
|
||||
void jump_start_stub(game::pmove_t* pm, game::pml_t* pml, float /*height*/)
|
||||
{
|
||||
utils::hook::invoke<void>(0x2BD800_b, pm, pml, dvars::jump_height->current.value);
|
||||
}
|
||||
|
||||
void pm_project_velocity_stub(const float* vel_in, const float* normal, float* vel_out)
|
||||
{
|
||||
const auto length_squared_2d = vel_in[0] * vel_in[0] + vel_in[1] * vel_in[1];
|
||||
|
||||
if (std::fabsf(normal[2]) < 0.001f || length_squared_2d == 0.0)
|
||||
{
|
||||
vel_out[0] = vel_in[0];
|
||||
vel_out[1] = vel_in[1];
|
||||
vel_out[2] = vel_in[2];
|
||||
return;
|
||||
}
|
||||
|
||||
auto new_z = vel_in[0] * normal[0] + vel_in[1] * normal[1];
|
||||
new_z = -new_z / normal[2];
|
||||
|
||||
const auto length_scale = std::sqrtf((vel_in[2] * vel_in[2] + length_squared_2d)
|
||||
/ (new_z * new_z + length_squared_2d));
|
||||
|
||||
if (dvars::pm_bouncingAllAngles->current.enabled
|
||||
|| (length_scale < 1.f || new_z < 0.f || vel_in[2] > 0.f))
|
||||
{
|
||||
vel_out[0] = vel_in[0] * length_scale;
|
||||
vel_out[1] = vel_in[1] * length_scale;
|
||||
vel_out[2] = new_z * length_scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
if (game::environment::is_sp())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
dvars::player_sustainAmmo = dvars::register_bool("player_sustainAmmo", false,
|
||||
game::DVAR_FLAG_REPLICATED, "Firing weapon will not decrease clip ammo");
|
||||
pm_weapon_use_ammo_hook.create(0x2DF830_b, &pm_weapon_use_ammo_stub);
|
||||
|
||||
utils::hook::nop(0x4006AD_b, 15);
|
||||
utils::hook::jump(0x4006AD_b, g_speed_stub(), true);
|
||||
dvars::g_speed = dvars::register_int("g_speed", 190, 0, 1000,
|
||||
game::DVAR_FLAG_REPLICATED, "changes the speed of the player");
|
||||
|
||||
dvars::pm_bouncing = dvars::register_bool("pm_bouncing", false,
|
||||
game::DVAR_FLAG_REPLICATED, "Enable bouncing");
|
||||
utils::hook::jump(0x2D39A4_b, pm_bouncing_stub_mp(), true);
|
||||
|
||||
dvars::pm_bouncingAllAngles = dvars::register_bool("pm_bouncingAllAngles", false,
|
||||
game::DvarFlags::DVAR_FLAG_REPLICATED, "Enable bouncing from all angles");
|
||||
utils::hook::call(0x2D3A74_b, pm_project_velocity_stub);
|
||||
|
||||
dvars::g_gravity = dvars::register_int("g_gravity", 800, 0, 1000, game::DVAR_FLAG_REPLICATED,
|
||||
"Game gravity in inches per second squared");
|
||||
utils::hook::jump(0x3FF812_b, client_end_frame_stub(), true);
|
||||
utils::hook::nop(0x3FF808_b, 1);
|
||||
|
||||
// Influence PM_JitterPoint code flow so the trace->startsolid checks are 'ignored'
|
||||
pm_player_trace_hook.create(0x2D14C0_b, &pm_player_trace_stub);
|
||||
// If g_enableElevators is 1 the 'ducked' flag will always be removed from the player state
|
||||
utils::hook::jump(0x2C9F90_b, utils::hook::assemble(pm_trace_stub), true);
|
||||
dvars::g_enableElevators = dvars::register_bool("g_enableElevators", false, game::DVAR_FLAG_REPLICATED, "Enables Elevators");
|
||||
|
||||
auto* timescale = dvars::register_float("timescale", 1.0f, 0.1f, 50.0f, game::DVAR_FLAG_REPLICATED, "Changes Timescale of the game");
|
||||
utils::hook::inject(0x15B204_b, ×cale->current.value); // Com_GetTimeScale
|
||||
utils::hook::inject(0x17D243_b, ×cale->current.value); // Com_Restart
|
||||
utils::hook::inject(0x17E609_b, ×cale->current.value); // Com_SetSlowMotion
|
||||
utils::hook::inject(0x17E626_b, ×cale->current.value); // Com_SetSlowMotion
|
||||
utils::hook::inject(0x17E69C_b, ×cale->current.value);// Com_SetSlowMotion
|
||||
utils::hook::inject(0x17EAD0_b, ×cale->current.value); // Com_TimeScaleMsec
|
||||
utils::hook::inject(0x17EFE2_b, ×cale->current.value); // Com_UpdateSlowMotion
|
||||
utils::hook::inject(0x17F00C_b, ×cale->current.value); //Com_UpdateSlowMotion
|
||||
|
||||
dvars::jump_ladderPushVel = dvars::register_float("jump_ladderPushVel", 128.0f,
|
||||
0.0f, 1024.0f, game::DVAR_FLAG_REPLICATED, "The velocity of a jump off of a ladder");
|
||||
utils::hook::jump(0x2BD70C_b, jump_push_off_ladder(), true);
|
||||
utils::hook::nop(0x2BD718_b, 4); // Nop skipped opcodes
|
||||
|
||||
dvars::jump_height = dvars::register_float("jump_height", 39.0f,
|
||||
0.0f, 1000.0f, game::DVAR_FLAG_REPLICATED, "The maximum height of a player\'s jump");
|
||||
utils::hook::call(0x2BD22D_b, jump_start_stub);
|
||||
|
||||
jump_apply_slowdown_hook.create(0x2BD0B0_b, jump_apply_slowdown_stub);
|
||||
jump_slowDownEnable = dvars::register_bool("jump_slowDownEnable", true, game::DVAR_FLAG_REPLICATED, "Slow player movement after jumping");
|
||||
|
||||
pm_crashland_hook.create(0x2CB070_b, pm_crashland_stub);
|
||||
jump_enableFallDamage = dvars::register_bool("jump_enableFallDamage", true, game::DVAR_FLAG_REPLICATED, "Enable fall damage");
|
||||
|
||||
dvars::g_playerEjection = dvars::register_bool("g_playerEjection", true, game::DVAR_FLAG_REPLICATED,
|
||||
"Flag whether player ejection is on or off");
|
||||
stuck_in_client_hook.create(0x4035F0_b, stuck_in_client_stub);
|
||||
|
||||
dvars::g_playerCollision = dvars::register_bool("g_playerCollision", true, game::DVAR_FLAG_REPLICATED,
|
||||
"Flag whether player collision is on or off");
|
||||
cm_transformed_capsule_trace_hook.create(0x4D63C0_b, cm_transformed_capsule_trace_stub);
|
||||
|
||||
// Make noclip work
|
||||
client_end_frame_hook.create(0x3FF7D0_b, client_end_frame_stub2);
|
||||
g_damage_client_hook.create(0x414F10_b, g_damage_client_stub);
|
||||
g_damage_hook.create(0x414A10_b, g_damage_stub);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(gameplay::component)
|
128
src/client/component/images.cpp
Normal file
128
src/client/component/images.cpp
Normal file
@ -0,0 +1,128 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "images.hpp"
|
||||
#include "console.hpp"
|
||||
#include "filesystem.hpp"
|
||||
|
||||
#include "game/game.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
#include <utils/string.hpp>
|
||||
#include <utils/image.hpp>
|
||||
#include <utils/io.hpp>
|
||||
#include <utils/concurrency.hpp>
|
||||
|
||||
namespace images
|
||||
{
|
||||
namespace
|
||||
{
|
||||
utils::hook::detour load_texture_hook;
|
||||
utils::hook::detour setup_texture_hook;
|
||||
utils::concurrency::container<std::unordered_map<std::string, std::string>> overriden_textures;
|
||||
|
||||
std::optional<std::string> load_image(game::GfxImage* image)
|
||||
{
|
||||
std::string data{};
|
||||
overriden_textures.access([&](const std::unordered_map<std::string, std::string>& textures)
|
||||
{
|
||||
if (const auto i = textures.find(image->name); i != textures.end())
|
||||
{
|
||||
data = i->second;
|
||||
}
|
||||
});
|
||||
|
||||
if (data.empty() && !filesystem::read_file(utils::string::va("images/%s.png", image->name), &data))
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
return {std::move(data)};
|
||||
}
|
||||
|
||||
std::optional<utils::image> load_raw_image_from_file(game::GfxImage* image)
|
||||
{
|
||||
const auto image_file = load_image(image);
|
||||
if (!image_file)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
return utils::image(*image_file);
|
||||
}
|
||||
|
||||
bool load_custom_texture(game::GfxImage* image)
|
||||
{
|
||||
auto raw_image = load_raw_image_from_file(image);
|
||||
if (!raw_image)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
image->imageFormat = 0x1000003;
|
||||
image->resourceSize = -1;
|
||||
|
||||
D3D11_SUBRESOURCE_DATA data{};
|
||||
data.SysMemPitch = raw_image->get_width() * 4;
|
||||
data.SysMemSlicePitch = data.SysMemPitch * raw_image->get_height();
|
||||
data.pSysMem = raw_image->get_buffer();
|
||||
|
||||
game::Image_Setup(image, raw_image->get_width(), raw_image->get_height(), image->depth, image->numElements,
|
||||
image->imageFormat, DXGI_FORMAT_R8G8B8A8_UNORM, image->name, &data);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void load_texture_stub(game::GfxImage* image, void* a2, int* a3)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (load_custom_texture(image))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
console::error("Failed to load image %s: %s\n", image->name, e.what());
|
||||
}
|
||||
|
||||
load_texture_hook.invoke<void>(image, a2, a3);
|
||||
}
|
||||
|
||||
int setup_texture_stub(game::GfxImage* image, void* a2, void* a3)
|
||||
{
|
||||
if (image->resourceSize == -1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return setup_texture_hook.invoke<bool>(image, a2, a3);
|
||||
}
|
||||
}
|
||||
|
||||
void override_texture(std::string name, std::string data)
|
||||
{
|
||||
overriden_textures.access([&](std::unordered_map<std::string, std::string>& textures)
|
||||
{
|
||||
textures[std::move(name)] = std::move(data);
|
||||
});
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
if (game::environment::is_dedi())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
setup_texture_hook.create(SELECT_VALUE(0x55F870_b, 0x6829C0_b), setup_texture_stub);
|
||||
load_texture_hook.create(SELECT_VALUE(0x83300_b, 0xA4AA0_b), load_texture_stub);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(images::component)
|
6
src/client/component/images.hpp
Normal file
6
src/client/component/images.hpp
Normal file
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
namespace images
|
||||
{
|
||||
void override_texture(std::string name, std::string data);
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
#include "game/game.hpp"
|
||||
|
||||
#include "game_console.hpp"
|
||||
#include "game/ui_scripting/execution.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
|
||||
@ -16,6 +17,15 @@ namespace input
|
||||
|
||||
void cl_char_event_stub(const int local_client_num, const int key)
|
||||
{
|
||||
if (game::environment::is_sp() && ui_scripting::lui_running())
|
||||
{
|
||||
ui_scripting::notify("keypress",
|
||||
{
|
||||
{"keynum", key},
|
||||
{"key", game::Key_KeynumToString(key, 0, 1)},
|
||||
});
|
||||
}
|
||||
|
||||
if (!game_console::console_char_event(local_client_num, key))
|
||||
{
|
||||
return;
|
||||
@ -26,6 +36,15 @@ namespace input
|
||||
|
||||
void cl_key_event_stub(const int local_client_num, const int key, const int down)
|
||||
{
|
||||
if (game::environment::is_sp() && ui_scripting::lui_running())
|
||||
{
|
||||
ui_scripting::notify(down ? "keydown" : "keyup",
|
||||
{
|
||||
{"keynum", key},
|
||||
{"key", game::Key_KeynumToString(key, 0, 1)},
|
||||
});
|
||||
}
|
||||
|
||||
if (!game_console::console_key_event(local_client_num, key, down))
|
||||
{
|
||||
return;
|
||||
@ -45,8 +64,8 @@ namespace input
|
||||
return;
|
||||
}
|
||||
|
||||
cl_char_event_hook.create(SELECT_VALUE(0x1401871A0, 0x14024E810), cl_char_event_stub); // H1(1.4)
|
||||
cl_key_event_hook.create(SELECT_VALUE(0x1401874D0, 0x14024EA60), cl_key_event_stub); // H1(1.4)
|
||||
cl_char_event_hook.create(SELECT_VALUE(0x1AB8F0_b, 0x12C8F0_b), cl_char_event_stub);
|
||||
cl_key_event_hook.create(SELECT_VALUE(0x1ABC20_b, 0x135A70_b), cl_key_event_stub);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -44,9 +44,9 @@ namespace localized_strings
|
||||
void post_unpack() override
|
||||
{
|
||||
// Change some localized strings
|
||||
seh_string_ed_get_string_hook.create(SELECT_VALUE(0x1403924A0, 0x1404BB2A0), &seh_string_ed_get_string);
|
||||
seh_string_ed_get_string_hook.create(SELECT_VALUE(0x3E6CE0_b, 0x585DA0_b), &seh_string_ed_get_string);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(localized_strings::component)
|
||||
REGISTER_COMPONENT(localized_strings::component)
|
298
src/client/component/logfile.cpp
Normal file
298
src/client/component/logfile.cpp
Normal file
@ -0,0 +1,298 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
#include "scheduler.hpp"
|
||||
|
||||
#include "logfile.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
|
||||
namespace logfile
|
||||
{
|
||||
std::unordered_map<const char*, sol::protected_function> vm_execute_hooks;
|
||||
|
||||
namespace
|
||||
{
|
||||
utils::hook::detour scr_player_killed_hook;
|
||||
utils::hook::detour scr_player_damage_hook;
|
||||
|
||||
utils::hook::detour client_command_hook;
|
||||
utils::hook::detour g_shutdown_game_hook;
|
||||
|
||||
std::vector<sol::protected_function> player_killed_callbacks;
|
||||
std::vector<sol::protected_function> player_damage_callbacks;
|
||||
|
||||
utils::hook::detour vm_execute_hook;
|
||||
char empty_function[2] = {0x32, 0x34}; // CHECK_CLEAR_PARAMS, END
|
||||
bool hook_enabled = true;
|
||||
|
||||
sol::lua_value convert_entity(lua_State* state, const game::mp::gentity_s* ent)
|
||||
{
|
||||
if (!ent)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
const scripting::entity player{game::Scr_GetEntityId(ent->s.entityNum, 0)};
|
||||
return scripting::lua::convert(state, player);
|
||||
}
|
||||
|
||||
std::string get_weapon_name(unsigned int weapon, bool isAlternate)
|
||||
{
|
||||
char output[1024] = {0};
|
||||
game::BG_GetWeaponNameComplete(weapon, isAlternate, output, 1024);
|
||||
return output;
|
||||
}
|
||||
|
||||
sol::lua_value convert_vector(lua_State* state, const float* vec)
|
||||
{
|
||||
if (!vec)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
const auto vec_ = scripting::vector(vec);
|
||||
return scripting::lua::convert(state, vec_);
|
||||
}
|
||||
|
||||
std::string convert_mod(const int meansOfDeath)
|
||||
{
|
||||
const auto value = reinterpret_cast<game::scr_string_t**>(0x10B5290_b)[meansOfDeath];
|
||||
const auto string = game::SL_ConvertToString(*value);
|
||||
return string;
|
||||
}
|
||||
|
||||
void scr_player_killed_stub(game::mp::gentity_s* self, const game::mp::gentity_s* inflictor,
|
||||
game::mp::gentity_s* attacker, int damage, const int meansOfDeath, const unsigned int weapon,
|
||||
const bool isAlternate, const float* vDir, const unsigned int hitLoc, int psTimeOffset, int deathAnimDuration)
|
||||
{
|
||||
{
|
||||
const std::string hitloc = reinterpret_cast<const char**>(0x10B5370_b)[hitLoc];
|
||||
const auto mod_ = convert_mod(meansOfDeath);
|
||||
|
||||
const auto weapon_ = get_weapon_name(weapon, isAlternate);
|
||||
|
||||
for (const auto& callback : player_killed_callbacks)
|
||||
{
|
||||
const auto state = callback.lua_state();
|
||||
|
||||
const auto self_ = convert_entity(state, self);
|
||||
const auto inflictor_ = convert_entity(state, inflictor);
|
||||
const auto attacker_ = convert_entity(state, attacker);
|
||||
|
||||
const auto dir = convert_vector(state, vDir);
|
||||
|
||||
const auto result = callback(self_, inflictor_, attacker_, damage,
|
||||
mod_, weapon_, dir, hitloc, psTimeOffset, deathAnimDuration);
|
||||
|
||||
scripting::lua::handle_error(result);
|
||||
|
||||
if (result.valid() && result.get_type() == sol::type::number)
|
||||
{
|
||||
damage = result.get<int>();
|
||||
}
|
||||
}
|
||||
|
||||
if (damage == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
scr_player_killed_hook.invoke<void>(self, inflictor, attacker, damage, meansOfDeath,
|
||||
weapon, isAlternate, vDir, hitLoc, psTimeOffset, deathAnimDuration);
|
||||
}
|
||||
|
||||
void scr_player_damage_stub(game::mp::gentity_s* self, const game::mp::gentity_s* inflictor,
|
||||
game::mp::gentity_s* attacker, int damage, int dflags, const int meansOfDeath,
|
||||
const unsigned int weapon, const bool isAlternate, const float* vPoint,
|
||||
const float* vDir, const unsigned int hitLoc, const int timeOffset)
|
||||
{
|
||||
{
|
||||
const std::string hitloc = reinterpret_cast<const char**>(0x10B5370_b)[hitLoc];
|
||||
const auto mod_ = convert_mod(meansOfDeath);
|
||||
|
||||
const auto weapon_ = get_weapon_name(weapon, isAlternate);
|
||||
|
||||
for (const auto& callback : player_damage_callbacks)
|
||||
{
|
||||
const auto state = callback.lua_state();
|
||||
|
||||
const auto self_ = convert_entity(state, self);
|
||||
const auto inflictor_ = convert_entity(state, inflictor);
|
||||
const auto attacker_ = convert_entity(state, attacker);
|
||||
|
||||
const auto point = convert_vector(state, vPoint);
|
||||
const auto dir = convert_vector(state, vDir);
|
||||
|
||||
const auto result = callback(self_, inflictor_, attacker_,
|
||||
damage, dflags, mod_, weapon_, point, dir, hitloc);
|
||||
|
||||
scripting::lua::handle_error(result);
|
||||
|
||||
if (result.valid() && result.get_type() == sol::type::number)
|
||||
{
|
||||
damage = result.get<int>();
|
||||
}
|
||||
}
|
||||
|
||||
if (damage == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
scr_player_damage_hook.invoke<void>(self, inflictor, attacker, damage, dflags,
|
||||
meansOfDeath, weapon, isAlternate, vPoint, vDir, hitLoc, timeOffset);
|
||||
}
|
||||
|
||||
unsigned int local_id_to_entity(unsigned int local_id)
|
||||
{
|
||||
const auto variable = game::scr_VarGlob->objectVariableValue[local_id];
|
||||
return variable.u.f.next;
|
||||
}
|
||||
|
||||
bool execute_vm_hook(const char* pos)
|
||||
{
|
||||
if (vm_execute_hooks.find(pos) == vm_execute_hooks.end())
|
||||
{
|
||||
hook_enabled = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!hook_enabled && pos > reinterpret_cast<char*>(vm_execute_hooks.size()))
|
||||
{
|
||||
hook_enabled = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto& hook = vm_execute_hooks[pos];
|
||||
const auto state = hook.lua_state();
|
||||
|
||||
const scripting::entity self = local_id_to_entity(game::scr_VmPub->function_frame->fs.localId);
|
||||
|
||||
std::vector<sol::lua_value> args;
|
||||
|
||||
const auto top = game::scr_function_stack->top;
|
||||
|
||||
for (auto* value = top; value->type != game::SCRIPT_END; --value)
|
||||
{
|
||||
args.push_back(scripting::lua::convert(state, *value));
|
||||
}
|
||||
|
||||
const auto result = hook(self, sol::as_args(args));
|
||||
scripting::lua::handle_error(result);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void vm_execute_stub(utils::hook::assembler& a)
|
||||
{
|
||||
const auto replace = a.newLabel();
|
||||
const auto end = a.newLabel();
|
||||
|
||||
a.pushad64();
|
||||
|
||||
a.mov(rcx, r14);
|
||||
a.call_aligned(execute_vm_hook);
|
||||
|
||||
a.cmp(al, 0);
|
||||
a.jne(replace);
|
||||
|
||||
a.popad64();
|
||||
a.jmp(end);
|
||||
|
||||
a.bind(end);
|
||||
|
||||
a.movzx(r15d, byte_ptr(r14));
|
||||
a.inc(r14);
|
||||
a.mov(dword_ptr(rbp, 0xA4), r15d);
|
||||
|
||||
a.jmp(SELECT_VALUE(0x3CA153_b, 0x5111B3_b));
|
||||
|
||||
a.bind(replace);
|
||||
|
||||
a.popad64();
|
||||
a.mov(r14, reinterpret_cast<char*>(empty_function));
|
||||
a.jmp(end);
|
||||
}
|
||||
}
|
||||
|
||||
void add_player_damage_callback(const sol::protected_function& callback)
|
||||
{
|
||||
player_damage_callbacks.push_back(callback);
|
||||
}
|
||||
|
||||
void add_player_killed_callback(const sol::protected_function& callback)
|
||||
{
|
||||
player_killed_callbacks.push_back(callback);
|
||||
}
|
||||
|
||||
void clear_callbacks()
|
||||
{
|
||||
player_damage_callbacks.clear();
|
||||
player_killed_callbacks.clear();
|
||||
vm_execute_hooks.clear();
|
||||
}
|
||||
|
||||
void enable_vm_execute_hook()
|
||||
{
|
||||
hook_enabled = true;
|
||||
}
|
||||
|
||||
void disable_vm_execute_hook()
|
||||
{
|
||||
hook_enabled = false;
|
||||
}
|
||||
|
||||
bool client_command_stub(const int client_num)
|
||||
{
|
||||
auto self = &game::mp::g_entities[client_num];
|
||||
char cmd[1024] = {0};
|
||||
|
||||
game::SV_Cmd_ArgvBuffer(0, cmd, 1024);
|
||||
|
||||
if (cmd == "say"s || cmd == "say_team"s)
|
||||
{
|
||||
auto hidden = false;
|
||||
std::string message(game::ConcatArgs(1));
|
||||
|
||||
hidden = message[1] == '/';
|
||||
message.erase(0, hidden ? 2 : 1);
|
||||
|
||||
scheduler::once([cmd, message, self, hidden]()
|
||||
{
|
||||
const scripting::entity level{*game::levelEntityId};
|
||||
const scripting::entity player{game::Scr_GetEntityId(self->s.entityNum, 0)};
|
||||
|
||||
scripting::notify(level, cmd, {player, message, hidden});
|
||||
scripting::notify(player, cmd, {message, hidden});
|
||||
}, scheduler::pipeline::server);
|
||||
|
||||
if (hidden)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
utils::hook::jump(SELECT_VALUE(0x3CA145_b, 0x5111A5_b), utils::hook::assemble(vm_execute_stub), true);
|
||||
|
||||
if (game::environment::is_sp())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
scr_player_damage_hook.create(0x1CE780_b, scr_player_damage_stub);
|
||||
scr_player_killed_hook.create(0x1CEA60_b, scr_player_killed_stub);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(logfile::component)
|
20
src/client/component/logfile.hpp
Normal file
20
src/client/component/logfile.hpp
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "game/scripting/entity.hpp"
|
||||
#include "game/scripting/execution.hpp"
|
||||
#include "game/scripting/lua/value_conversion.hpp"
|
||||
#include "game/scripting/lua/error.hpp"
|
||||
|
||||
namespace logfile
|
||||
{
|
||||
extern std::unordered_map<const char*, sol::protected_function> vm_execute_hooks;
|
||||
|
||||
void add_player_damage_callback(const sol::protected_function& callback);
|
||||
void add_player_killed_callback(const sol::protected_function& callback);
|
||||
void clear_callbacks();
|
||||
|
||||
void enable_vm_execute_hook();
|
||||
void disable_vm_execute_hook();
|
||||
|
||||
bool client_command_stub(const int client_num);
|
||||
}
|
133
src/client/component/logger.cpp
Normal file
133
src/client/component/logger.cpp
Normal file
@ -0,0 +1,133 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "party.hpp"
|
||||
#include "console.hpp"
|
||||
|
||||
#include "game/game.hpp"
|
||||
#include "game/dvars.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
|
||||
namespace logger
|
||||
{
|
||||
namespace
|
||||
{
|
||||
utils::hook::detour com_error_hook;
|
||||
|
||||
void print_error(const char* msg, ...)
|
||||
{
|
||||
char buffer[2048];
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, msg);
|
||||
|
||||
vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, msg, ap);
|
||||
|
||||
va_end(ap);
|
||||
|
||||
console::error(buffer);
|
||||
}
|
||||
|
||||
void print_com_error(int, const char* msg, ...)
|
||||
{
|
||||
char buffer[2048];
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, msg);
|
||||
|
||||
vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, msg, ap);
|
||||
|
||||
va_end(ap);
|
||||
|
||||
console::error(buffer);
|
||||
}
|
||||
|
||||
void com_error_stub(const int error, const char* msg, ...)
|
||||
{
|
||||
char buffer[2048];
|
||||
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, msg);
|
||||
|
||||
vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, msg, ap);
|
||||
|
||||
va_end(ap);
|
||||
|
||||
console::error("Error: %s\n", buffer);
|
||||
}
|
||||
|
||||
party::clear_sv_motd(); // clear sv_motd on error if it exists
|
||||
|
||||
com_error_hook.invoke<void>(error, "%s", buffer);
|
||||
}
|
||||
|
||||
void print_warning(const char* msg, ...)
|
||||
{
|
||||
char buffer[2048];
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, msg);
|
||||
|
||||
vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, msg, ap);
|
||||
|
||||
va_end(ap);
|
||||
|
||||
console::warn(buffer);
|
||||
}
|
||||
|
||||
void print(const char* msg, ...)
|
||||
{
|
||||
char buffer[2048];
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, msg);
|
||||
|
||||
vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, msg, ap);
|
||||
|
||||
va_end(ap);
|
||||
|
||||
console::info(buffer);
|
||||
}
|
||||
|
||||
void print_dev(const char* msg, ...)
|
||||
{
|
||||
static auto* enabled = dvars::register_bool("logger_dev", false, game::DVAR_FLAG_SAVED, "Print dev stuff");
|
||||
if (!enabled->current.enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
char buffer[2048];
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, msg);
|
||||
|
||||
vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, msg, ap);
|
||||
|
||||
va_end(ap);
|
||||
|
||||
console::info(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
if (!game::environment::is_dedi())
|
||||
{
|
||||
// lua stuff
|
||||
utils::hook::jump(SELECT_VALUE(0x106010_b, 0x27CBB0_b), print_dev); // debug
|
||||
utils::hook::jump(SELECT_VALUE(0x107680_b, 0x27E210_b), print_error); // error
|
||||
utils::hook::jump(SELECT_VALUE(0x0E6E30_b, 0x1F6140_b), printf); // print
|
||||
}
|
||||
|
||||
com_error_hook.create(game::Com_Error, com_error_stub);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(logger::component)
|
@ -15,19 +15,6 @@ namespace lui
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
if (!game::environment::is_mp())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't show create cod account popup
|
||||
//utils::hook::set<uint32_t>(0x14017C957, 0); // H1(1.4)
|
||||
|
||||
//#ifdef _DEBUG
|
||||
// Enable development menus (causes issues in sp)
|
||||
//utils::hook::set<uint32_t>(SELECT_VALUE(0x1400B4ABC, 0x1401AB779), 1);
|
||||
//#endif
|
||||
|
||||
command::add("lui_open", [](const command::params& params)
|
||||
{
|
||||
if (params.size() <= 1)
|
||||
|
@ -9,9 +9,10 @@
|
||||
|
||||
namespace map_rotation
|
||||
{
|
||||
DWORD previousPriority;
|
||||
namespace
|
||||
{
|
||||
DWORD previous_priority{};
|
||||
|
||||
void set_dvar(const std::string& dvar, const std::string& value)
|
||||
{
|
||||
command::execute(utils::string::va("%s \"%s\"", dvar.data(), value.data()), true);
|
||||
@ -84,10 +85,10 @@ namespace map_rotation
|
||||
scheduler::on_game_initialized([]()
|
||||
{
|
||||
//printf("=======================setting OLD priority=======================\n");
|
||||
SetPriorityClass(GetCurrentProcess(), previousPriority);
|
||||
SetPriorityClass(GetCurrentProcess(), previous_priority);
|
||||
}, scheduler::pipeline::main, 1s);
|
||||
|
||||
previousPriority = GetPriorityClass(GetCurrentProcess());
|
||||
previous_priority = GetPriorityClass(GetCurrentProcess());
|
||||
//printf("=======================setting NEW priority=======================\n");
|
||||
SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
|
||||
}
|
||||
@ -147,7 +148,6 @@ namespace map_rotation
|
||||
return scheduler::cond_end;
|
||||
}, scheduler::pipeline::main, 1s);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
@ -162,17 +162,17 @@ namespace map_rotation
|
||||
|
||||
scheduler::once([]()
|
||||
{
|
||||
dvars::register_string("sv_mapRotation", "", game::DVAR_FLAG_NONE, true);
|
||||
dvars::register_string("sv_mapRotationCurrent", "", game::DVAR_FLAG_NONE, true);
|
||||
dvars::register_string("sv_autoPriority", "", game::DVAR_FLAG_NONE, true);
|
||||
dvars::register_string("sv_mapRotation", "", game::DVAR_FLAG_NONE, "");
|
||||
dvars::register_string("sv_mapRotationCurrent", "", game::DVAR_FLAG_NONE, "");
|
||||
dvars::register_string("sv_autoPriority", "", game::DVAR_FLAG_NONE, "Lowers the process priority during map changes to not cause lags on other servers.");
|
||||
}, scheduler::pipeline::main);
|
||||
|
||||
command::add("map_rotate", &perform_map_rotation);
|
||||
|
||||
// Hook GScr_ExitLevel
|
||||
utils::hook::jump(0x140376630, &trigger_map_rotation); // not sure if working
|
||||
utils::hook::jump(0xE2670_b, &trigger_map_rotation, true); // not sure if working
|
||||
|
||||
previousPriority = GetPriorityClass(GetCurrentProcess());
|
||||
previous_priority = GetPriorityClass(GetCurrentProcess());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
212
src/client/component/materials.cpp
Normal file
212
src/client/component/materials.cpp
Normal file
@ -0,0 +1,212 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "materials.hpp"
|
||||
#include "console.hpp"
|
||||
#include "filesystem.hpp"
|
||||
|
||||
#include "game/game.hpp"
|
||||
#include "game/dvars.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
#include <utils/memory.hpp>
|
||||
#include <utils/io.hpp>
|
||||
#include <utils/string.hpp>
|
||||
#include <utils/image.hpp>
|
||||
#include <utils/concurrency.hpp>
|
||||
|
||||
namespace materials
|
||||
{
|
||||
namespace
|
||||
{
|
||||
utils::hook::detour db_material_streaming_fail_hook;
|
||||
utils::hook::detour material_register_handle_hook;
|
||||
utils::hook::detour db_get_material_index_hook;
|
||||
|
||||
struct material_data_t
|
||||
{
|
||||
std::unordered_map<std::string, game::Material*> materials;
|
||||
std::unordered_map<std::string, std::string> images;
|
||||
};
|
||||
|
||||
char constant_table[0x20] = {};
|
||||
|
||||
utils::concurrency::container<material_data_t> material_data;
|
||||
|
||||
game::GfxImage* setup_image(game::GfxImage* image, const utils::image& raw_image)
|
||||
{
|
||||
image->imageFormat = 0x1000003;
|
||||
image->resourceSize = -1;
|
||||
|
||||
D3D11_SUBRESOURCE_DATA data{};
|
||||
data.SysMemPitch = raw_image.get_width() * 4;
|
||||
data.SysMemSlicePitch = data.SysMemPitch * raw_image.get_height();
|
||||
data.pSysMem = raw_image.get_buffer();
|
||||
|
||||
game::Image_Setup(image, raw_image.get_width(), raw_image.get_height(), image->depth, image->numElements,
|
||||
image->imageFormat, DXGI_FORMAT_R8G8B8A8_UNORM, image->name, &data);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
game::Material* create_material(const std::string& name, const std::string& data)
|
||||
{
|
||||
const auto white = material_register_handle_hook.invoke<game::Material*>("white");
|
||||
const auto material = utils::memory::get_allocator()->allocate<game::Material>();
|
||||
const auto texture_table = utils::memory::get_allocator()->allocate<game::MaterialTextureDef>();
|
||||
const auto image = utils::memory::get_allocator()->allocate<game::GfxImage>();
|
||||
|
||||
std::memcpy(material, white, sizeof(game::Material));
|
||||
std::memcpy(texture_table, white->textureTable, sizeof(game::MaterialTextureDef));
|
||||
std::memcpy(image, white->textureTable->u.image, sizeof(game::GfxImage));
|
||||
|
||||
material->constantTable = &constant_table;
|
||||
material->name = utils::memory::get_allocator()->duplicate_string(name);
|
||||
image->name = material->name;
|
||||
|
||||
material->textureTable = texture_table;
|
||||
material->textureTable->u.image = setup_image(image, data);
|
||||
|
||||
return material;
|
||||
}
|
||||
|
||||
void free_material(game::Material* material)
|
||||
{
|
||||
material->textureTable->u.image->textures.___u0.map->Release();
|
||||
material->textureTable->u.image->textures.shaderView->Release();
|
||||
utils::memory::get_allocator()->free(material->textureTable->u.image);
|
||||
utils::memory::get_allocator()->free(material->textureTable);
|
||||
utils::memory::get_allocator()->free(material->name);
|
||||
utils::memory::get_allocator()->free(material);
|
||||
}
|
||||
|
||||
game::Material* load_material(const std::string& name)
|
||||
{
|
||||
return material_data.access<game::Material*>([&](material_data_t& data_) -> game::Material*
|
||||
{
|
||||
if (const auto i = data_.materials.find(name); i != data_.materials.end())
|
||||
{
|
||||
return i->second;
|
||||
}
|
||||
|
||||
std::string data{};
|
||||
if (const auto i = data_.images.find(name); i != data_.images.end())
|
||||
{
|
||||
data = i->second;
|
||||
}
|
||||
|
||||
if (data.empty() && !filesystem::read_file(utils::string::va("materials/%s.png", name.data()), &data))
|
||||
{
|
||||
data_.materials[name] = nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const auto material = create_material(name, data);
|
||||
data_.materials[name] = material;
|
||||
|
||||
return material;
|
||||
});
|
||||
}
|
||||
|
||||
game::Material* try_load_material(const std::string& name)
|
||||
{
|
||||
if (name == "white")
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return load_material(name);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
console::error("Failed to load material %s: %s\n", name.data(), e.what());
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
game::Material* material_register_handle_stub(const char* name)
|
||||
{
|
||||
auto result = try_load_material(name);
|
||||
if (result == nullptr)
|
||||
{
|
||||
result = material_register_handle_hook.invoke<game::Material*>(name);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int db_material_streaming_fail_stub(game::Material* material)
|
||||
{
|
||||
if (material->constantTable == &constant_table)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return db_material_streaming_fail_hook.invoke<int>(material);
|
||||
}
|
||||
|
||||
unsigned int db_get_material_index_stub(game::Material* material)
|
||||
{
|
||||
if (material->constantTable == &constant_table)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return db_get_material_index_hook.invoke<unsigned int>(material);
|
||||
}
|
||||
}
|
||||
|
||||
void add(const std::string& name, const std::string& data)
|
||||
{
|
||||
material_data.access([&](material_data_t& data_)
|
||||
{
|
||||
data_.images[name] = data;
|
||||
});
|
||||
}
|
||||
|
||||
bool exists(const std::string& name)
|
||||
{
|
||||
return material_data.access<bool>([&](material_data_t& data_)
|
||||
{
|
||||
return data_.images.find(name) != data_.images.end();
|
||||
});
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
material_data.access([&](material_data_t& data_)
|
||||
{
|
||||
for (auto& material : data_.materials)
|
||||
{
|
||||
if (material.second == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
free_material(material.second);
|
||||
}
|
||||
|
||||
data_.materials.clear();
|
||||
});
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
if (game::environment::is_dedi())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
material_register_handle_hook.create(game::Material_RegisterHandle, material_register_handle_stub);
|
||||
db_material_streaming_fail_hook.create(SELECT_VALUE(0x1FB400_b, 0x3A1600_b), db_material_streaming_fail_stub);
|
||||
db_get_material_index_hook.create(SELECT_VALUE(0x1F1D80_b, 0x396000_b), db_get_material_index_stub);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(materials::component)
|
8
src/client/component/materials.hpp
Normal file
8
src/client/component/materials.hpp
Normal file
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
namespace materials
|
||||
{
|
||||
void add(const std::string& name, const std::string& data);
|
||||
bool exists(const std::string& name);
|
||||
void clear();
|
||||
}
|
119
src/client/component/mods.cpp
Normal file
119
src/client/component/mods.cpp
Normal file
@ -0,0 +1,119 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "game/game.hpp"
|
||||
#include "game/dvars.hpp"
|
||||
|
||||
#include "command.hpp"
|
||||
#include "console.hpp"
|
||||
#include "scheduler.hpp"
|
||||
#include "filesystem.hpp"
|
||||
#include "materials.hpp"
|
||||
#include "fonts.hpp"
|
||||
#include "mods.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
#include <utils/io.hpp>
|
||||
|
||||
namespace mods
|
||||
{
|
||||
std::string mod_path{};
|
||||
|
||||
namespace
|
||||
{
|
||||
utils::hook::detour db_release_xassets_hook;
|
||||
bool release_assets = false;
|
||||
|
||||
void db_release_xassets_stub()
|
||||
{
|
||||
if (release_assets)
|
||||
{
|
||||
materials::clear();
|
||||
fonts::clear();
|
||||
}
|
||||
|
||||
db_release_xassets_hook.invoke<void>();
|
||||
}
|
||||
|
||||
void restart()
|
||||
{
|
||||
scheduler::once([]()
|
||||
{
|
||||
release_assets = true;
|
||||
game::Com_Shutdown("");
|
||||
release_assets = false;
|
||||
}, scheduler::pipeline::main);
|
||||
}
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
if (!game::environment::is_sp())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!utils::io::directory_exists("mods"))
|
||||
{
|
||||
utils::io::create_directory("mods");
|
||||
}
|
||||
|
||||
db_release_xassets_hook.create(SELECT_VALUE(0x1F4DB0_b, 0x399740_b), db_release_xassets_stub);
|
||||
|
||||
command::add("loadmod", [](const command::params& params)
|
||||
{
|
||||
if (params.size() < 2)
|
||||
{
|
||||
console::info("Usage: loadmod mods/<modname>");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!game::Com_InFrontend())
|
||||
{
|
||||
console::info("Cannot load mod while in-game!\n");
|
||||
game::CG_GameMessage(0, "^1Cannot unload mod while in-game!");
|
||||
return;
|
||||
}
|
||||
|
||||
const auto path = params.get(1);
|
||||
if (!utils::io::directory_exists(path))
|
||||
{
|
||||
console::info("Mod %s not found!\n", path);
|
||||
return;
|
||||
}
|
||||
|
||||
console::info("Loading mod %s\n", path);
|
||||
filesystem::get_search_paths().erase(mod_path);
|
||||
filesystem::get_search_paths().insert(path);
|
||||
mod_path = path;
|
||||
restart();
|
||||
});
|
||||
|
||||
command::add("unloadmod", [](const command::params& params)
|
||||
{
|
||||
if (mod_path.empty())
|
||||
{
|
||||
console::info("No mod loaded\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!game::Com_InFrontend())
|
||||
{
|
||||
console::info("Cannot unload mod while in-game!\n");
|
||||
game::CG_GameMessage(0, "^1Cannot unload mod while in-game!");
|
||||
return;
|
||||
}
|
||||
|
||||
console::info("Unloading mod %s\n", mod_path.data());
|
||||
filesystem::get_search_paths().erase(mod_path);
|
||||
mod_path.clear();
|
||||
restart();
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(mods::component)
|
6
src/client/component/mods.hpp
Normal file
6
src/client/component/mods.hpp
Normal file
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
namespace mods
|
||||
{
|
||||
extern std::string mod_path;
|
||||
}
|
180
src/client/component/movement.cpp
Normal file
180
src/client/component/movement.cpp
Normal file
@ -0,0 +1,180 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
#include "game/game.hpp"
|
||||
#include "game/dvars.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
#include <utils/vector.hpp>
|
||||
|
||||
// https://github.com/xoxor4d/iw3xo-dev/blob/develop/src/components/modules/movement.cpp :)
|
||||
|
||||
namespace movement
|
||||
{
|
||||
namespace
|
||||
{
|
||||
utils::hook::detour pm_airmove_hook;
|
||||
|
||||
game::dvar_t* pm_cs_airAccelerate;
|
||||
game::dvar_t* pm_cs_airSpeedCap;
|
||||
game::dvar_t* pm_cs_strafing;
|
||||
|
||||
void pm_air_accelerate(game::vec3_t wishdir, float wishspeed, game::mp::playerState_s* ps, game::mp::pml_t* pml)
|
||||
{
|
||||
float wishspd = wishspeed, accelspeed, currentspeed, addspeed;
|
||||
|
||||
auto accel = pm_cs_airAccelerate->current.value;
|
||||
auto airspeedcap = pm_cs_airSpeedCap->current.value;
|
||||
|
||||
if (wishspd > airspeedcap)
|
||||
{
|
||||
wishspd = airspeedcap;
|
||||
}
|
||||
|
||||
currentspeed = utils::vector::product(ps->velocity, wishdir);
|
||||
addspeed = wishspd - currentspeed;
|
||||
|
||||
if (addspeed > 0)
|
||||
{
|
||||
accelspeed = pml->frametime * accel * wishspeed * 1.0f;
|
||||
|
||||
if (accelspeed > addspeed)
|
||||
{
|
||||
accelspeed = addspeed;
|
||||
}
|
||||
|
||||
for (auto i = 0; i < 3; i++)
|
||||
{
|
||||
ps->velocity[i] += wishdir[i] * accelspeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pm_clip_velocity(game::vec3_t in, game::vec3_t normal, game::vec3_t out, float overbounce)
|
||||
{
|
||||
float backoff, change, angle, adjust;
|
||||
|
||||
angle = normal[2];
|
||||
backoff = utils::vector::product(in, normal) * overbounce;
|
||||
|
||||
for (auto i = 0; i < 3; i++)
|
||||
{
|
||||
change = normal[i] * backoff;
|
||||
out[i] = in[i] - change;
|
||||
}
|
||||
|
||||
adjust = utils::vector::product(out, normal);
|
||||
|
||||
if (adjust < 0)
|
||||
{
|
||||
game::vec3_t reduce{};
|
||||
|
||||
utils::vector::scale(normal, adjust, reduce);
|
||||
utils::vector::subtract(out, reduce, out);
|
||||
}
|
||||
}
|
||||
|
||||
void pm_try_playermove(game::mp::pmove_t* pm, game::mp::pml_t* pml)
|
||||
{
|
||||
const auto surf_slope = 0.7f;
|
||||
const auto ps = pm->ps;
|
||||
|
||||
game::vec3_t end{};
|
||||
game::trace_t trace{};
|
||||
|
||||
if (utils::vector::length(ps->velocity) == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
utils::vector::ma(ps->origin, pml->frametime, ps->velocity, end);
|
||||
utils::hook::invoke<void>(0x2D14C0_b, pm, &trace, ps->origin, end,
|
||||
&pm->bounds, ps->clientNum, pm->tracemask); // PM_playerTrace
|
||||
|
||||
if (trace.fraction == 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (trace.normal[2] > surf_slope)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pm_clip_velocity(ps->velocity, trace.normal, ps->velocity, 1.0f);
|
||||
}
|
||||
|
||||
void pm_airmove_stub(game::mp::pmove_t* pm, game::mp::pml_t* pml)
|
||||
{
|
||||
if (!pm_cs_strafing->current.enabled)
|
||||
{
|
||||
return pm_airmove_hook.invoke<void>(pm, pml);
|
||||
}
|
||||
|
||||
const auto ps = pm->ps;
|
||||
|
||||
ps->sprintButtonUpRequired = 1;
|
||||
|
||||
float fmove{}, smove{}, wishspeed{};
|
||||
game::vec3_t wishvel{}, wishdir{};
|
||||
|
||||
fmove = pm->cmd.forwardmove;
|
||||
smove = pm->cmd.rightmove;
|
||||
|
||||
pml->forward[2] = 0.0f;
|
||||
pml->right[2] = 0.0f;
|
||||
|
||||
utils::vector::normalize(pml->forward);
|
||||
utils::vector::normalize(pml->right);
|
||||
|
||||
for (auto i = 0; i < 2; i++)
|
||||
{
|
||||
wishvel[i] = pml->forward[i] * fmove + pml->right[i] * smove;
|
||||
}
|
||||
|
||||
wishvel[2] = 0;
|
||||
|
||||
utils::vector::copy(wishvel, wishdir);
|
||||
wishspeed = utils::vector::normalize(wishdir);
|
||||
|
||||
if (wishspeed != 0 && (wishspeed > 320.0f))
|
||||
{
|
||||
utils::vector::scale(wishvel, 320.0f / wishspeed, wishvel);
|
||||
wishspeed = 320.0f;
|
||||
}
|
||||
|
||||
pm_air_accelerate(wishdir, wishspeed, ps, pml);
|
||||
|
||||
utils::hook::invoke<void>(0x2D3380_b, pm, pml, 1, 1); // PM_StepSlideMove
|
||||
|
||||
pm_try_playermove(pm, pml);
|
||||
}
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
if (game::environment::is_sp())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pm_airmove_hook.create(0x2C93B0_b, pm_airmove_stub);
|
||||
|
||||
pm_cs_airAccelerate = dvars::register_float("pm_cs_airAccelerate", 100.0f, 1.0f, 500.0f,
|
||||
game::DvarFlags::DVAR_FLAG_REPLICATED,
|
||||
"Defines player acceleration mid-air");
|
||||
|
||||
pm_cs_airSpeedCap = dvars::register_float("pm_cs_airSpeedCap", 30.0f, 1.0f, 500.0f,
|
||||
game::DvarFlags::DVAR_FLAG_REPLICATED,
|
||||
"Maximum speed mid-air");
|
||||
|
||||
pm_cs_strafing = dvars::register_bool("pm_cs_strafing", false,
|
||||
game::DvarFlags::DVAR_FLAG_REPLICATED,
|
||||
"Enable CS like strafing");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(movement::component)
|
@ -27,15 +27,8 @@ namespace network
|
||||
const auto cmd_string = utils::string::to_lower(command);
|
||||
auto& callbacks = get_callbacks();
|
||||
const auto handler = callbacks.find(cmd_string);
|
||||
|
||||
if (handler == callbacks.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto offset = cmd_string.size() + 5;
|
||||
|
||||
if (message->cursize <= offset)
|
||||
if (message->cursize < offset || handler == callbacks.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -67,25 +60,25 @@ namespace network
|
||||
// Command handled
|
||||
a.popad64();
|
||||
a.mov(al, 1);
|
||||
a.jmp(0x140252AF8); // H1MP64(1.4)
|
||||
a.jmp(0x12FCAA_b);
|
||||
|
||||
a.bind(return_unhandled);
|
||||
a.popad64();
|
||||
a.jmp(0x14025234C); // H1MP64(1.4)
|
||||
a.jmp(0x12F3AC_b);
|
||||
}
|
||||
|
||||
int net_compare_base_address(const game::netadr_s* a1, const game::netadr_s* a2)
|
||||
int net_compare_base_address(const game::netadr_s* a, const game::netadr_s* b)
|
||||
{
|
||||
if (a1->type == a2->type)
|
||||
if (a->type == b->type)
|
||||
{
|
||||
switch (a1->type)
|
||||
switch (a->type)
|
||||
{
|
||||
case game::netadrtype_t::NA_BOT:
|
||||
case game::netadrtype_t::NA_LOOPBACK:
|
||||
return a1->port == a2->port;
|
||||
return a->port == b->port;
|
||||
|
||||
case game::netadrtype_t::NA_IP:
|
||||
return !memcmp(a1->ip, a2->ip, 4);
|
||||
return !memcmp(a->ip, b->ip, 4);
|
||||
case game::netadrtype_t::NA_BROADCAST:
|
||||
return true;
|
||||
default:
|
||||
@ -96,9 +89,9 @@ namespace network
|
||||
return false;
|
||||
}
|
||||
|
||||
int net_compare_address(const game::netadr_s* a1, const game::netadr_s* a2)
|
||||
int net_compare_address(const game::netadr_s* a, const game::netadr_s* b)
|
||||
{
|
||||
return net_compare_base_address(a1, a2) && a1->port == a2->port;
|
||||
return net_compare_base_address(a, b) && a->port == b->port;
|
||||
}
|
||||
|
||||
void reconnect_migratated_client(void*, game::netadr_s* from, const int, const int, const char*,
|
||||
@ -117,17 +110,17 @@ namespace network
|
||||
if (net_interface && net_interface != "localhost"s)
|
||||
{
|
||||
// Sys_StringToSockaddr
|
||||
utils::hook::invoke<void>(0x1404F6580, net_interface, &address);
|
||||
utils::hook::invoke<void>(0x59E810_b, net_interface, &address);
|
||||
}
|
||||
|
||||
address.sin_family = AF_INET;
|
||||
address.sin_port = ntohs(static_cast<short>(port));
|
||||
|
||||
const auto sock = ::socket(AF_INET, SOCK_DGRAM, protocol);
|
||||
const auto sock = socket(AF_INET, SOCK_DGRAM, protocol);
|
||||
|
||||
u_long arg = 1;
|
||||
ioctlsocket(sock, FIONBIO, &arg);
|
||||
char optval[4] = { 1 };
|
||||
char optval[4] = {1};
|
||||
setsockopt(sock, 0xFFFF, 32, optval, 4);
|
||||
|
||||
if (bind(sock, reinterpret_cast<sockaddr*>(&address), sizeof(address)) != -1)
|
||||
@ -145,10 +138,10 @@ namespace network
|
||||
get_callbacks()[utils::string::to_lower(command)] = callback;
|
||||
}
|
||||
|
||||
int dw_send_to_stub(const int size, const char* src, game::netadr_s* a3)
|
||||
int dw_send_to_stub(const int size, const char* src, game::netadr_s* to)
|
||||
{
|
||||
sockaddr s = {};
|
||||
game::NetadrToSockadr(a3, &s);
|
||||
game::NetadrToSockadr(to, &s);
|
||||
return sendto(*game::query_socket, src, size, 0, &s, 16) >= 0;
|
||||
}
|
||||
|
||||
@ -216,7 +209,7 @@ namespace network
|
||||
const char* description)
|
||||
{
|
||||
game::dvar_t* dvar;
|
||||
dvar = dvars::register_int("net_port", 27016, 0, 0xFFFFu, game::DVAR_FLAG_LATCHED);
|
||||
dvar = dvars::register_int("net_port", 27016, 0, 0xFFFFu, game::DVAR_FLAG_LATCHED, "Network port");
|
||||
|
||||
// read net_port from command line
|
||||
command::read_startup_variable("net_port");
|
||||
@ -236,53 +229,47 @@ namespace network
|
||||
}
|
||||
|
||||
// redirect dw_sendto to raw socket
|
||||
//utils::hook::jump(0x1404D850A, reinterpret_cast<void*>(0x1404D849A));
|
||||
utils::hook::call(0x140513467, dw_send_to_stub); // H1MP64(1.4)
|
||||
utils::hook::jump(game::Sys_SendPacket, dw_send_to_stub); // H1MP64(1.4)
|
||||
utils::hook::jump(0x5EEC90_b, dw_send_to_stub);
|
||||
utils::hook::jump(game::Sys_SendPacket, dw_send_to_stub);
|
||||
|
||||
// intercept command handling
|
||||
utils::hook::jump(0x140252327, utils::hook::assemble(handle_command_stub), true); // H1MP64(1.4)
|
||||
utils::hook::jump(0x12F387_b, utils::hook::assemble(handle_command_stub), true);
|
||||
|
||||
// handle xuid without secure connection
|
||||
utils::hook::nop(0x140486AAF, 6); // H1MP64(1.4)
|
||||
utils::hook::nop(0x554222_b, 6);
|
||||
|
||||
utils::hook::jump(0x140424F20, net_compare_address); // H1MP64(1.4)
|
||||
utils::hook::jump(0x140424F70, net_compare_base_address); // H1MP64(1.4)
|
||||
utils::hook::jump(0x4F1800_b, net_compare_address);
|
||||
utils::hook::jump(0x4F1850_b, net_compare_base_address);
|
||||
|
||||
// don't establish secure conenction
|
||||
utils::hook::set<uint8_t>(0x14027EA4D, 0xEB); // H1MP64(1.4)
|
||||
utils::hook::set<uint8_t>(0x14027EB1E, 0xEB); // H1MP64(1.4)
|
||||
utils::hook::set<uint8_t>(0x14027EF8D, 0xEB); // H1MP64(1.4)
|
||||
utils::hook::set<uint8_t>(0x14025081F, 0xEB); // H1MP64(1.4)
|
||||
utils::hook::set<uint8_t>(0x358C8D_b, 0xEB);
|
||||
utils::hook::set<uint8_t>(0x358D5E_b, 0xEB);
|
||||
utils::hook::set<uint8_t>(0x3591CD_b, 0xEB);
|
||||
utils::hook::set<uint8_t>(0x12CD0F_b, 0xEB);
|
||||
|
||||
// ignore unregistered connection
|
||||
utils::hook::jump(0x140480F46, 0x140480EE5); // H1MP64(1.4)
|
||||
utils::hook::set<uint8_t>(0x140480F3B, 0xEB); // H1MP64(1.4)
|
||||
utils::hook::jump(0x54E2D1_b, 0x54E270_b, true);
|
||||
utils::hook::set<uint8_t>(0x54E2C6_b, 0xEB);
|
||||
|
||||
// disable xuid verification
|
||||
utils::hook::set<uint8_t>(0x14005B62D, 0xEB); // H1MP64(1.4)
|
||||
utils::hook::set<uint8_t>(0x14005B649, 0xEB); // H1MP64(1.4)
|
||||
utils::hook::set<uint8_t>(0x728BF_b, 0xEB);
|
||||
|
||||
// disable xuid verification
|
||||
utils::hook::nop(0x14048382C, 2);
|
||||
utils::hook::set<uint8_t>(0x140483889, 0xEB); // H1MP64(1.4)
|
||||
utils::hook::nop(0x5509D9_b, 2);
|
||||
utils::hook::set<uint8_t>(0x550A36_b, 0xEB);
|
||||
|
||||
// ignore configstring mismatch
|
||||
utils::hook::set<uint8_t>(0x1402591C9, 0xEB); // H1MP64(1.4)
|
||||
utils::hook::set<uint8_t>(0x341261_b, 0xEB);
|
||||
|
||||
// ignore dw handle in SV_PacketEvent
|
||||
utils::hook::set<uint8_t>(0x1404898E2, 0xEB);
|
||||
utils::hook::call(0x1404898D6, &net_compare_address); // H1MP64(1.4)
|
||||
utils::hook::set<uint8_t>(0x1CBC22_b, 0xEB);
|
||||
|
||||
// ignore dw handle in SV_FindClientByAddress
|
||||
utils::hook::set<uint8_t>(0x140488EFD, 0xEB);
|
||||
utils::hook::call(0x140488EF1, &net_compare_address); // H1MP64(1.4)
|
||||
utils::hook::set<uint8_t>(0x1CB24D_b, 0xEB);
|
||||
|
||||
// ignore dw handle in SV_DirectConnect
|
||||
utils::hook::set<uint8_t>(0x140480C58, 0xEB);
|
||||
utils::hook::set<uint8_t>(0x140480E6F, 0xEB);
|
||||
utils::hook::call(0x140480C4B, &net_compare_address);
|
||||
utils::hook::call(0x140480E62, &net_compare_address);
|
||||
utils::hook::set<uint8_t>(0x54DFE8_b, 0xEB);
|
||||
utils::hook::set<uint8_t>(0x54E1FD_b, 0xEB);
|
||||
|
||||
// increase cl_maxpackets
|
||||
dvars::override::register_int("cl_maxpackets", 1000, 1, 1000, game::DVAR_FLAG_SAVED);
|
||||
@ -291,32 +278,31 @@ namespace network
|
||||
dvars::override::register_int("sv_remote_client_snapshot_msec", 33, 33, 100, game::DVAR_FLAG_NONE);
|
||||
|
||||
// ignore impure client
|
||||
utils::hook::jump(0x140481B58, reinterpret_cast<void*>(0x140481BEE)); // H1MP64(1.4)
|
||||
utils::hook::jump(0x54EDD3_b, 0x54EE69_b);
|
||||
|
||||
// don't send checksum
|
||||
utils::hook::set<uint8_t>(0x140513433, 0); // H1MP64(1.4) mov: r8d, edi ; LEN
|
||||
utils::hook::set<uint8_t>(0x14051345A, 0); // H1MP64(1.4)
|
||||
utils::hook::set<uint8_t>(0x59E628_b, 0);
|
||||
|
||||
// don't read checksum
|
||||
utils::hook::set(0x1404F6620, 0xC301B0); // H1MP64(1.4)
|
||||
utils::hook::set(0x59E8B0_b, 0xC301B0);
|
||||
|
||||
// don't try to reconnect client
|
||||
utils::hook::call(0x140480DFF, reconnect_migratated_client); // H1MP64(1.4)
|
||||
utils::hook::nop(0x140480DDB, 4); // H1MP64(1.4) this crashes when reconnecting for some reason
|
||||
utils::hook::jump(0x54D220_b, reconnect_migratated_client);
|
||||
utils::hook::nop(0x54E168_b, 4); // this crashes when reconnecting for some reason
|
||||
|
||||
// allow server owner to modify net_port before the socket bind
|
||||
utils::hook::call(0x140512BE5, register_netport_stub); // H1MP64(1.4)
|
||||
utils::hook::call(0x140512D20, register_netport_stub); // H1MP64(1.4)
|
||||
utils::hook::call(0x5BD032_b, register_netport_stub);
|
||||
utils::hook::call(0x5BD3F0_b, register_netport_stub);
|
||||
|
||||
// increase allowed packet size
|
||||
const auto max_packet_size = 0x20000;
|
||||
utils::hook::set<int>(0x1404255F1, max_packet_size); // H1MP64(1.4)
|
||||
utils::hook::set<int>(0x140425630, max_packet_size); // H1MP64(1.4)
|
||||
utils::hook::set<int>(0x140425522, max_packet_size); // H1MP64(1.4)
|
||||
utils::hook::set<int>(0x140425545, max_packet_size); // H1MP64(1.4)
|
||||
utils::hook::set<int>(0x4F1ED1_b, max_packet_size);
|
||||
utils::hook::set<int>(0x4F1F10_b, max_packet_size);
|
||||
utils::hook::set<int>(0x4F1E02_b, max_packet_size);
|
||||
utils::hook::set<int>(0x4F1E25_b, max_packet_size);
|
||||
|
||||
// ignore built in "print" oob command and add in our own
|
||||
utils::hook::set<uint8_t>(0x14025280E, 0xEB); // H1MP64(1.4)
|
||||
utils::hook::set<uint8_t>(0x12F817_b, 0xEB);
|
||||
on("print", [](const game::netadr_s&, const std::string_view& data)
|
||||
{
|
||||
const std::string message{data};
|
||||
@ -325,7 +311,7 @@ namespace network
|
||||
|
||||
// Use our own socket since the game's socket doesn't work with non localhost addresses
|
||||
// why? no idea
|
||||
utils::hook::jump(0x140512B40, create_socket);
|
||||
utils::hook::jump(0x5BD210_b, create_socket);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -71,11 +71,11 @@ namespace party
|
||||
perform_game_initialization();
|
||||
|
||||
// exit from virtuallobby
|
||||
utils::hook::invoke<void>(0x140256D40, 1);
|
||||
utils::hook::invoke<void>(0x13C9C0_b, 1);
|
||||
|
||||
// CL_ConnectFromParty
|
||||
char session_info[0x100] = {};
|
||||
utils::hook::invoke<void>(0x140251560, 0, session_info, &target, mapname.data(), gametype.data());
|
||||
utils::hook::invoke<void>(0x12DFF0_b, 0, session_info, &target, mapname.data(), gametype.data());
|
||||
}
|
||||
|
||||
std::string get_dvar_string(const std::string& dvar)
|
||||
@ -111,55 +111,51 @@ namespace party
|
||||
return false;
|
||||
}
|
||||
|
||||
void didyouknow_stub(const char* dvar_name, const char* string)
|
||||
const char* get_didyouknow_stub(void* table, int row, int column)
|
||||
{
|
||||
if (!party::sv_motd.empty())
|
||||
if (party::sv_motd.empty())
|
||||
{
|
||||
string = party::sv_motd.data();
|
||||
return utils::hook::invoke<const char*>(0x5A0AC0_b, table, row, column);
|
||||
}
|
||||
|
||||
// This function either does Dvar_SetString or Dvar_RegisterString for the given dvar
|
||||
reinterpret_cast<void(*)(const char*, const char*)>(0x1404FB210)(dvar_name, string);
|
||||
return utils::string::va("%s", party::sv_motd.data());
|
||||
}
|
||||
|
||||
void disconnect_stub()
|
||||
void disconnect()
|
||||
{
|
||||
if (!game::VirtualLobby_Loaded())
|
||||
{
|
||||
if (game::CL_IsCgameInitialized())
|
||||
{
|
||||
// CL_ForwardCommandToServer
|
||||
reinterpret_cast<void (*)(int, const char*)>(0x140253480)(0, "disconnect");
|
||||
// CL_AddReliableCommand
|
||||
utils::hook::invoke<void>(0x12B810_b, 0, "disconnect");
|
||||
// CL_WritePacket
|
||||
reinterpret_cast<void (*)(int)>(0x14024DB10)(0);
|
||||
utils::hook::invoke<void>(0x13D490_b, 0);
|
||||
}
|
||||
// CL_Disconnect
|
||||
reinterpret_cast<void (*)(int)>(0x140252060)(0);
|
||||
utils::hook::invoke<void>(0x12F080_b, 0);
|
||||
}
|
||||
}
|
||||
|
||||
utils::hook::detour cldisconnect_hook;
|
||||
utils::hook::detour cl_disconnect_hook;
|
||||
|
||||
void cl_disconnect_stub(int a1)
|
||||
void cl_disconnect_stub(int showMainMenu) // possibly bool
|
||||
{
|
||||
party::sv_motd.clear();
|
||||
cldisconnect_hook.invoke<void>(a1);
|
||||
party::clear_sv_motd();
|
||||
cl_disconnect_hook.invoke<void>(showMainMenu);
|
||||
}
|
||||
|
||||
const auto drop_reason_stub = utils::hook::assemble([](utils::hook::assembler& a)
|
||||
{
|
||||
a.mov(rdx, rdi);
|
||||
a.mov(ecx, 2);
|
||||
a.jmp(0x140251F78);
|
||||
});
|
||||
|
||||
void menu_error(const std::string& error)
|
||||
{
|
||||
utils::hook::invoke<void>(0x1400DACC0, error.data(), "MENU_NOTICE");
|
||||
utils::hook::set(0x142C1DA98, 1);
|
||||
utils::hook::invoke<void>(0x17D770_b, error.data(), "MENU_NOTICE");
|
||||
utils::hook::set(0x2ED2F78_b, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void clear_sv_motd()
|
||||
{
|
||||
party::sv_motd.clear();
|
||||
}
|
||||
|
||||
int get_client_num_by_name(const std::string& name)
|
||||
{
|
||||
for (auto i = 0; !name.empty() && i < *game::mp::svs_numclients; ++i)
|
||||
@ -187,9 +183,15 @@ namespace party
|
||||
int get_client_count()
|
||||
{
|
||||
auto count = 0;
|
||||
const auto* svs_clients = *game::mp::svs_clients;
|
||||
if (svs_clients == nullptr)
|
||||
{
|
||||
return count;
|
||||
}
|
||||
|
||||
for (auto i = 0; i < *game::mp::svs_numclients; ++i)
|
||||
{
|
||||
if (game::mp::svs_clients[i].header.state >= 1)
|
||||
if (svs_clients[i].header.state >= 1)
|
||||
{
|
||||
++count;
|
||||
}
|
||||
@ -201,9 +203,15 @@ namespace party
|
||||
int get_bot_count()
|
||||
{
|
||||
auto count = 0;
|
||||
const auto* svs_clients = *game::mp::svs_clients;
|
||||
if (svs_clients == nullptr)
|
||||
{
|
||||
return count;
|
||||
}
|
||||
|
||||
for (auto i = 0; i < *game::mp::svs_numclients; ++i)
|
||||
{
|
||||
if (game::mp::svs_clients[i].header.state >= 1 &&
|
||||
if (svs_clients[i].header.state >= 1 &&
|
||||
game::SV_BotIsBot(i))
|
||||
{
|
||||
++count;
|
||||
@ -229,6 +237,16 @@ namespace party
|
||||
network::send(target, "getInfo", connect_state.challenge);
|
||||
}
|
||||
|
||||
game::netadr_s get_state_host()
|
||||
{
|
||||
return connect_state.host;
|
||||
}
|
||||
|
||||
std::string get_state_challenge()
|
||||
{
|
||||
return connect_state.challenge;
|
||||
}
|
||||
|
||||
void start_map(const std::string& mapname)
|
||||
{
|
||||
if (game::Live_SyncOnlineDataFlags(0) > 32)
|
||||
@ -267,7 +285,6 @@ namespace party
|
||||
}
|
||||
|
||||
console::info("Starting map: %s\n", mapname.data());
|
||||
|
||||
auto* gametype = game::Dvar_FindVar("g_gametype");
|
||||
if (gametype && gametype->current.string)
|
||||
{
|
||||
@ -302,21 +319,28 @@ namespace party
|
||||
return;
|
||||
}
|
||||
|
||||
// hook disconnect command function
|
||||
utils::hook::jump(0x1402521C7, disconnect_stub);
|
||||
|
||||
// detour CL_Disconnect to clear motd
|
||||
cldisconnect_hook.create(0x140252060, cl_disconnect_stub);
|
||||
cl_disconnect_hook.create(0x12F080_b, cl_disconnect_stub);
|
||||
|
||||
if (game::environment::is_mp())
|
||||
{
|
||||
// show custom drop reason
|
||||
utils::hook::nop(0x140251EFB, 13);
|
||||
utils::hook::jump(0x140251EFB, drop_reason_stub, true);
|
||||
utils::hook::nop(0x12EF4E_b, 13);
|
||||
utils::hook::jump(0x12EF4E_b, utils::hook::assemble([](utils::hook::assembler& a)
|
||||
{
|
||||
a.mov(rdx, rsi);
|
||||
a.mov(ecx, 2);
|
||||
a.jmp(0x12EF27_b);
|
||||
}), true);
|
||||
|
||||
command::add("disconnect", disconnect);
|
||||
}
|
||||
|
||||
// enable custom kick reason in GScr_KickPlayer
|
||||
utils::hook::set<uint8_t>(0x140376A1D, 0xEB);
|
||||
utils::hook::set<uint8_t>(0xE423D_b, 0xEB);
|
||||
|
||||
// allow custom didyouknow based on sv_motd
|
||||
utils::hook::call(0x1A8A3A_b, get_didyouknow_stub);
|
||||
|
||||
command::add("map", [](const command::params& argument)
|
||||
{
|
||||
@ -334,10 +358,12 @@ namespace party
|
||||
{
|
||||
return;
|
||||
}
|
||||
*reinterpret_cast<int*>(0x14A3A91D0) = 1; // sv_map_restart
|
||||
*reinterpret_cast<int*>(0x14A3A91D4) = 1; // sv_loadScripts
|
||||
*reinterpret_cast<int*>(0x14A3A91D8) = 0; // sv_migrate
|
||||
reinterpret_cast<void(*)()>(0x14047E7F0)(); // SV_CheckLoadGame
|
||||
|
||||
*reinterpret_cast<int*>(0xB7B8E60_b) = 1; // sv_map_restart
|
||||
*reinterpret_cast<int*>(0xB7B8E64_b) = 1; // sv_loadScripts
|
||||
*reinterpret_cast<int*>(0xB7B8E68_b) = 0; // sv_migrate
|
||||
|
||||
utils::hook::invoke<void>(0x54BD50_b); // SV_CheckLoadGame
|
||||
});
|
||||
|
||||
command::add("fast_restart", []()
|
||||
@ -530,8 +556,6 @@ namespace party
|
||||
printf("%s\n", message.data());
|
||||
});
|
||||
|
||||
utils::hook::call(0x1404C6E8D, didyouknow_stub); // allow custom didyouknow based on sv_motd
|
||||
|
||||
network::on("getInfo", [](const game::netadr_s& target, const std::string_view& data)
|
||||
{
|
||||
utils::info_string info{};
|
||||
|
@ -8,6 +8,9 @@ namespace party
|
||||
void connect(const game::netadr_s& target);
|
||||
void start_map(const std::string& mapname);
|
||||
|
||||
void clear_sv_motd();
|
||||
game::netadr_s get_state_host();
|
||||
std::string get_state_challenge();
|
||||
int server_client_count();
|
||||
|
||||
int get_client_num_by_name(const std::string& name);
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "console.hpp"
|
||||
#include "network.hpp"
|
||||
#include "scheduler.hpp"
|
||||
#include "filesystem.hpp"
|
||||
|
||||
#include "game/game.hpp"
|
||||
#include "game/dvars.hpp"
|
||||
@ -45,7 +46,7 @@ namespace patches
|
||||
return "Unknown Soldier";
|
||||
}
|
||||
|
||||
return std::string{ username, username_len - 1 };
|
||||
return std::string{username, username_len - 1};
|
||||
}
|
||||
|
||||
utils::hook::detour com_register_dvars_hook;
|
||||
@ -55,38 +56,42 @@ namespace patches
|
||||
if (game::environment::is_mp())
|
||||
{
|
||||
// Make name save
|
||||
dvars::register_string("name", get_login_username().data(), game::DVAR_FLAG_SAVED, true);
|
||||
|
||||
// Disable data validation error popup
|
||||
dvars::register_int("data_validation_allow_drop", 0, 0, 0, game::DVAR_FLAG_NONE, true);
|
||||
dvars::register_string("name", get_login_username().data(), game::DVAR_FLAG_SAVED, "Player name.");
|
||||
}
|
||||
|
||||
return com_register_dvars_hook.invoke<void>();
|
||||
}
|
||||
|
||||
int is_item_unlocked()
|
||||
{
|
||||
return 0; // 0 == yes
|
||||
}
|
||||
utils::hook::detour set_client_dvar_from_server_hook;
|
||||
|
||||
void set_client_dvar_from_server_stub(void* a1, void* a2, const char* dvar, const char* value)
|
||||
void set_client_dvar_from_server_stub(void* clientNum, void* cgameGlob, const char* dvar, const char* value)
|
||||
{
|
||||
if (dvar == "cg_fov"s)
|
||||
if (dvar == "cg_fov"s || dvar == "cg_fovMin"s)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// CG_SetClientDvarFromServer
|
||||
reinterpret_cast<void(*)(void*, void*, const char*, const char*)>(0x140236120)(a1, a2, dvar, value);
|
||||
set_client_dvar_from_server_hook.invoke<void>(0x11AA90_b, clientNum, cgameGlob, dvar, value);
|
||||
}
|
||||
|
||||
/*void aim_assist_add_to_target_list(void* a1, void* a2)
|
||||
const char* db_read_raw_file_stub(const char* filename, char* buf, const int size)
|
||||
{
|
||||
if (!dvars::aimassist_enabled->current.enabled)
|
||||
return;
|
||||
std::string file_name = filename;
|
||||
if (file_name.find(".cfg") == std::string::npos)
|
||||
{
|
||||
file_name.append(".cfg");
|
||||
}
|
||||
|
||||
game::AimAssist_AddToTargetList(a1, a2);
|
||||
}*/
|
||||
const auto file = filesystem::file(file_name);
|
||||
if (file.exists())
|
||||
{
|
||||
snprintf(buf, size, "%s\n", file.get_buffer().data());
|
||||
return buf;
|
||||
}
|
||||
|
||||
// DB_ReadRawFile
|
||||
return utils::hook::invoke<const char*>(SELECT_VALUE(0x1F4D00_b, 0x3994B0_b), filename, buf, size);
|
||||
}
|
||||
|
||||
void bsp_sys_error_stub(const char* error, const char* arg1)
|
||||
{
|
||||
@ -107,9 +112,15 @@ namespace patches
|
||||
utils::hook::detour cmd_lui_notify_server_hook;
|
||||
void cmd_lui_notify_server_stub(game::mp::gentity_s* ent)
|
||||
{
|
||||
const auto svs_clients = *game::mp::svs_clients;
|
||||
if (svs_clients == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
command::params_sv params{};
|
||||
const auto menu_id = atoi(params.get(1));
|
||||
const auto client = &game::mp::svs_clients[ent->s.entityNum];
|
||||
const auto client = &svs_clients[ent->s.entityNum];
|
||||
|
||||
// 22 => "end_game"
|
||||
if (menu_id == 22 && client->header.remoteAddress.type != game::NA_LOOPBACK)
|
||||
@ -131,15 +142,32 @@ namespace patches
|
||||
return;
|
||||
}
|
||||
|
||||
reinterpret_cast<void(*)(game::mp::client_t*, game::msg_t*)>(0x140481A00)(client, msg);
|
||||
utils::hook::invoke<void>(0x54EC50_b, client, msg);
|
||||
}
|
||||
|
||||
void aim_assist_add_to_target_list(void* a1, void* a2)
|
||||
void aim_assist_add_to_target_list(void* aaGlob, void* screenTarget)
|
||||
{
|
||||
if (!dvars::aimassist_enabled->current.enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
game::AimAssist_AddToTargetList(a1, a2);
|
||||
game::AimAssist_AddToTargetList(aaGlob, screenTarget);
|
||||
}
|
||||
|
||||
utils::hook::detour init_network_dvars_hook;
|
||||
void init_network_dvars_stub(game::dvar_t* dvar)
|
||||
{
|
||||
static const auto hash = game::generateHashValue("r_tonemapHighlightRange");
|
||||
if (dvar->hash == hash)
|
||||
{
|
||||
init_network_dvars_hook.invoke<void>(dvar);
|
||||
}
|
||||
}
|
||||
|
||||
int ui_draw_crosshair()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,15 +177,15 @@ namespace patches
|
||||
void post_unpack() override
|
||||
{
|
||||
// Register dvars
|
||||
com_register_dvars_hook.create(SELECT_VALUE(0x140351B80, 0x1400D9320), &com_register_dvars_stub); // H1(1.4)
|
||||
com_register_dvars_hook.create(SELECT_VALUE(0x385BE0_b, 0x15BB60_b), &com_register_dvars_stub);
|
||||
|
||||
// Unlock fps in main menu
|
||||
utils::hook::set<BYTE>(SELECT_VALUE(0x14018D47B, 0x14025B86B), 0xEB); // H1(1.4)
|
||||
utils::hook::set<BYTE>(SELECT_VALUE(0x1B1EAB_b, 0x34396B_b), 0xEB);
|
||||
|
||||
if (!game::environment::is_dedi())
|
||||
{
|
||||
// Fix mouse lag
|
||||
utils::hook::nop(SELECT_VALUE(0x1403E3C05, 0x1404DB1AF), 6);
|
||||
utils::hook::nop(SELECT_VALUE(0x4631F9_b, 0x5BFF89_b), 6);
|
||||
scheduler::loop([]()
|
||||
{
|
||||
SetThreadExecutionState(ES_DISPLAY_REQUIRED);
|
||||
@ -167,10 +195,14 @@ namespace patches
|
||||
// Make cg_fov and cg_fovscale saved dvars
|
||||
dvars::override::register_float("cg_fov", 65.f, 40.f, 200.f, game::DvarFlags::DVAR_FLAG_SAVED);
|
||||
dvars::override::register_float("cg_fovScale", 1.f, 0.1f, 2.f, game::DvarFlags::DVAR_FLAG_SAVED);
|
||||
|
||||
dvars::override::register_float("cg_fovMin", 1.f, 1.0f, 90.f, game::DvarFlags::DVAR_FLAG_SAVED);
|
||||
|
||||
// Allow kbam input when gamepad is enabled
|
||||
utils::hook::nop(SELECT_VALUE(0x14018797E, 0x14024EF60), 2);
|
||||
utils::hook::nop(SELECT_VALUE(0x1401856DC, 0x14024C6B0), 6);
|
||||
utils::hook::nop(SELECT_VALUE(0x1AC0CE_b, 0x135EFB_b), 2);
|
||||
utils::hook::nop(SELECT_VALUE(0x1A9DDC_b, 0x13388F_b), 6);
|
||||
|
||||
// Allow executing custom cfg files with the "exec" command
|
||||
utils::hook::call(SELECT_VALUE(0x376EB5_b, 0x156D41_b), db_read_raw_file_stub);
|
||||
|
||||
if (!game::environment::is_sp())
|
||||
{
|
||||
@ -180,65 +212,58 @@ namespace patches
|
||||
|
||||
static void patch_mp()
|
||||
{
|
||||
// Use name dvar
|
||||
utils::hook::jump(0x14050FF90, &live_get_local_client_name); // H1(1.4)
|
||||
utils::hook::jump(0x5BB9C0_b, &live_get_local_client_name);
|
||||
|
||||
// Disable data validation error popup
|
||||
dvars::override::register_int("data_validation_allow_drop", 0, 0, 0, game::DVAR_FLAG_NONE);
|
||||
|
||||
// Patch SV_KickClientNum
|
||||
sv_kick_client_num_hook.create(0x14047ED00, &sv_kick_client_num); // H1(1.4)
|
||||
sv_kick_client_num_hook.create(game::SV_KickClientNum, &sv_kick_client_num);
|
||||
|
||||
// block changing name in-game
|
||||
utils::hook::set<uint8_t>(0x14047FC90, 0xC3); // H1(1.4)
|
||||
|
||||
// patch "Couldn't find the bsp for this map." error to not be fatal in mp
|
||||
utils::hook::call(0x1402BA26B, bsp_sys_error_stub); // H1(1.4)
|
||||
utils::hook::set<uint8_t>(0x54CFF0_b, 0xC3);
|
||||
|
||||
// client side aim assist dvar
|
||||
dvars::aimassist_enabled = dvars::register_bool("aimassist_enabled", true,
|
||||
game::DvarFlags::DVAR_FLAG_SAVED,
|
||||
true);
|
||||
utils::hook::call(0x14009EE9E, aim_assist_add_to_target_list);
|
||||
"Enables aim assist for controllers");
|
||||
utils::hook::call(0xE857F_b, aim_assist_add_to_target_list);
|
||||
|
||||
// unlock all items
|
||||
utils::hook::jump(0x140413E60, is_item_unlocked); // LiveStorage_IsItemUnlockedFromTable_LocalClient H1(1.4)
|
||||
utils::hook::jump(0x140413860, is_item_unlocked); // LiveStorage_IsItemUnlockedFromTable H1(1.4)
|
||||
utils::hook::jump(0x140412B70, is_item_unlocked); // idk ( unlocks loot etc ) H1(1.4)
|
||||
// patch "Couldn't find the bsp for this map." error to not be fatal in mp
|
||||
utils::hook::call(0x39465B_b, bsp_sys_error_stub);
|
||||
|
||||
// isProfanity
|
||||
utils::hook::set(0x1402877D0, 0xC3C033); // MAY BE WRONG H1(1.4)
|
||||
|
||||
// disable emblems
|
||||
dvars::override::register_int("emblems_active", 0, 0, 0, game::DVAR_FLAG_NONE);
|
||||
utils::hook::set<uint8_t>(0x140479590, 0xC3); // don't register commands
|
||||
utils::hook::set(0x361AA0_b, 0xC3C033);
|
||||
|
||||
// disable elite_clan
|
||||
dvars::override::register_int("elite_clan_active", 0, 0, 0, game::DVAR_FLAG_NONE);
|
||||
utils::hook::set<uint8_t>(0x140585680, 0xC3); // don't register commands H1(1.4)
|
||||
utils::hook::set<uint8_t>(0x62D2F0_b, 0xC3); // don't register commands
|
||||
|
||||
// disable codPointStore
|
||||
dvars::override::register_int("codPointStore_enabled", 0, 0, 0, game::DVAR_FLAG_NONE);
|
||||
|
||||
// don't register every replicated dvar as a network dvar
|
||||
utils::hook::nop(0x14039E58E, 5); // dvar_foreach H1(1.4)
|
||||
// don't register every replicated dvar as a network dvar (only r_tonemapHighlightRange, fixes red dots)
|
||||
init_network_dvars_hook.create(0x4740C0_b, init_network_dvars_stub);
|
||||
|
||||
// patch "Server is different version" to show the server client version
|
||||
utils::hook::inject(0x140480952, VERSION); // H1(1.4)
|
||||
utils::hook::inject(0x54DCE5_b, VERSION);
|
||||
|
||||
// prevent servers overriding our fov
|
||||
utils::hook::call(0x14023279E, set_client_dvar_from_server_stub);
|
||||
utils::hook::nop(0x1400DAF69, 5);
|
||||
utils::hook::nop(0x140190C16, 5);
|
||||
utils::hook::set<uint8_t>(0x14021D22A, 0xEB);
|
||||
set_client_dvar_from_server_hook.create(0x11AA90_b, set_client_dvar_from_server_stub);
|
||||
utils::hook::nop(0x17DA96_b, 0x16);
|
||||
utils::hook::nop(0xE00BE_b, 0x17);
|
||||
utils::hook::set<uint8_t>(0x307F39_b, 0xEB);
|
||||
|
||||
// some [data validation] anti tamper thing that kills performance
|
||||
dvars::override::register_int("dvl", 0, 0, 0, game::DVAR_FLAG_READ);
|
||||
|
||||
// unlock safeArea_*
|
||||
utils::hook::jump(0x1402624F5, 0x140262503); // H1(1.4)
|
||||
utils::hook::jump(0x14026251C, 0x140262547); // H1(1.4)
|
||||
dvars::override::register_int("safeArea_adjusted_horizontal", 1, 0, 1, game::DVAR_FLAG_SAVED);
|
||||
dvars::override::register_int("safeArea_adjusted_vertical", 1, 0, 1, game::DVAR_FLAG_SAVED);
|
||||
dvars::override::register_int("safeArea_horizontal", 1, 0, 1, game::DVAR_FLAG_SAVED);
|
||||
dvars::override::register_int("safeArea_vertical", 1, 0, 1, game::DVAR_FLAG_SAVED);
|
||||
|
||||
// move chat position on the screen above menu splashes
|
||||
dvars::override::register_vec2("cg_hudChatPosition", 5, 170, 0, 640, game::DVAR_FLAG_SAVED);
|
||||
utils::hook::jump(0x347BC5_b, 0x347BD3_b);
|
||||
utils::hook::jump(0x347BEC_b, 0x347C17_b);
|
||||
dvars::override::register_float("safeArea_adjusted_horizontal", 1, 0, 1, game::DVAR_FLAG_SAVED);
|
||||
dvars::override::register_float("safeArea_adjusted_vertical", 1, 0, 1, game::DVAR_FLAG_SAVED);
|
||||
dvars::override::register_float("safeArea_horizontal", 1, 0, 1, game::DVAR_FLAG_SAVED);
|
||||
dvars::override::register_float("safeArea_vertical", 1, 0, 1, game::DVAR_FLAG_SAVED);
|
||||
|
||||
// allow servers to check for new packages more often
|
||||
dvars::override::register_int("sv_network_fps", 1000, 20, 1000, game::DVAR_FLAG_SAVED);
|
||||
@ -249,28 +274,34 @@ namespace patches
|
||||
dvars::override::register_int("cl_connectTimeout", 120, 120, 1800, game::DVAR_FLAG_NONE); // Seems unused
|
||||
dvars::override::register_int("sv_connectTimeout", 120, 120, 1800, game::DVAR_FLAG_NONE); // 60 - 0 - 1800
|
||||
|
||||
dvars::register_int("scr_game_spectatetype", 1, 0, 99, game::DVAR_FLAG_REPLICATED);
|
||||
dvars::register_int("scr_game_spectatetype", 1, 0, 99, game::DVAR_FLAG_REPLICATED, "");
|
||||
|
||||
dvars::override::register_int("com_maxfps", 0, 10, 1000, game::DVAR_FLAG_SAVED);
|
||||
dvars::override::register_bool("ui_drawCrosshair", true, game::DVAR_FLAG_WRITE);
|
||||
utils::hook::jump(0x1E6010_b, ui_draw_crosshair);
|
||||
|
||||
dvars::override::register_int("com_maxfps", 0, 0, 1000, game::DVAR_FLAG_SAVED);
|
||||
|
||||
// Prevent clients from ending the game as non host by sending 'end_game' lui notification
|
||||
// cmd_lui_notify_server_hook.create(0x140335A70, cmd_lui_notify_server_stub); // H1(1.4)
|
||||
cmd_lui_notify_server_hook.create(0x412D50_b, cmd_lui_notify_server_stub);
|
||||
|
||||
// Prevent clients from sending invalid reliableAcknowledge
|
||||
// utils::hook::call(0x1404899C6, sv_execute_client_message_stub); // H1(1.4)
|
||||
utils::hook::call(0x1CBD06_b, sv_execute_client_message_stub);
|
||||
|
||||
// "fix" for rare 'Out of memory error' error
|
||||
if (utils::flags::has_flag("memoryfix"))
|
||||
{
|
||||
utils::hook::jump(0x140578BE0, malloc);
|
||||
utils::hook::jump(0x140578B00, _aligned_malloc);
|
||||
utils::hook::jump(0x140578C40, free);
|
||||
utils::hook::jump(0x140578D30, realloc);
|
||||
utils::hook::jump(0x140578B60, _aligned_realloc);
|
||||
utils::hook::jump(0x6200C0_b, malloc);
|
||||
utils::hook::jump(0x61FFE0_b, _aligned_malloc);
|
||||
utils::hook::jump(0x620120_b, free);
|
||||
utils::hook::jump(0x620210_b, realloc);
|
||||
utils::hook::jump(0x620040_b, _aligned_realloc);
|
||||
}
|
||||
|
||||
// Change default hostname and make it replicated
|
||||
dvars::override::register_string("sv_hostname", "^2H1-Mod^7 Default Server", game::DVAR_FLAG_REPLICATED);
|
||||
|
||||
// Dont free server/client memory on asset loading (fixes crashing on map rotation)
|
||||
utils::hook::nop(0x132474_b, 5);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
45
src/client/component/ranked.cpp
Normal file
45
src/client/component/ranked.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "scheduler.hpp"
|
||||
#include "dvars.hpp"
|
||||
|
||||
#include "game/game.hpp"
|
||||
#include "game/dvars.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
#include <utils/flags.hpp>
|
||||
|
||||
namespace ranked
|
||||
{
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
if (game::environment::is_sp())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (game::environment::is_mp())
|
||||
{
|
||||
dvars::override::register_bool("xblive_privatematch", false, game::DVAR_FLAG_REPLICATED);
|
||||
}
|
||||
|
||||
if (game::environment::is_dedi())
|
||||
{
|
||||
dvars::override::register_bool("xblive_privatematch", false, game::DVAR_FLAG_REPLICATED | game::DVAR_FLAG_WRITE);
|
||||
dvars::register_bool("force_ranking", true, game::DVAR_FLAG_WRITE, ""); // Skip some check in _menus.gsc
|
||||
}
|
||||
|
||||
// Always run bots, even if xblive_privatematch is 0
|
||||
utils::hook::set(0x2C10B0_b, 0xC301B0); // BG_BotSystemEnabled
|
||||
utils::hook::set(0x2C0E60_b, 0xC301B0); // BG_AISystemEnabled
|
||||
utils::hook::set(0x2C1040_b, 0xC301B0); // BG_BotFastFileEnabled
|
||||
utils::hook::set(0x2C11B0_b, 0xC301B0); // BG_BotsUsingTeamDifficulty
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(ranked::component)
|
232
src/client/component/rcon.cpp
Normal file
232
src/client/component/rcon.cpp
Normal file
@ -0,0 +1,232 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "game/game.hpp"
|
||||
#include "game/dvars.hpp"
|
||||
|
||||
#include "command.hpp"
|
||||
#include "console.hpp"
|
||||
#include "network.hpp"
|
||||
#include "scheduler.hpp"
|
||||
#include "rcon.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
#include <utils/string.hpp>
|
||||
|
||||
namespace rcon
|
||||
{
|
||||
namespace
|
||||
{
|
||||
bool is_redirecting_ = false;
|
||||
bool has_redirected_ = false;
|
||||
game::netadr_s redirect_target_ = {};
|
||||
std::recursive_mutex redirect_lock;
|
||||
|
||||
void setup_redirect(const game::netadr_s& target)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> $(redirect_lock);
|
||||
|
||||
has_redirected_ = false;
|
||||
is_redirecting_ = true;
|
||||
redirect_target_ = target;
|
||||
}
|
||||
|
||||
void clear_redirect()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> $(redirect_lock);
|
||||
|
||||
has_redirected_ = false;
|
||||
is_redirecting_ = false;
|
||||
redirect_target_ = {};
|
||||
}
|
||||
|
||||
void send_rcon_command(const std::string& password, const std::string& data)
|
||||
{
|
||||
// If you are the server, don't bother with rcon and just execute the command
|
||||
if (game::Dvar_FindVar("sv_running")->current.enabled)
|
||||
{
|
||||
game::Cbuf_AddText(0, 0, data.data());
|
||||
return;
|
||||
}
|
||||
|
||||
if (password.empty())
|
||||
{
|
||||
console::info("You must login first to use RCON\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (*game::mp::connect_state != nullptr && *game::connectionState >= game::CA_CONNECTED)
|
||||
{
|
||||
const auto target = (*game::mp::connect_state)->address;
|
||||
const auto buffer = password + " " + data;
|
||||
network::send(target, "rcon", buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
console::warn("You need to be connected to a server!\n");
|
||||
}
|
||||
}
|
||||
|
||||
std::string build_status_buffer()
|
||||
{
|
||||
const auto sv_maxclients = game::Dvar_FindVar("sv_maxclients");
|
||||
const auto mapname = game::Dvar_FindVar("mapname");
|
||||
|
||||
std::string buffer{};
|
||||
buffer.append(utils::string::va("map: %s\n", mapname->current.string));
|
||||
buffer.append(
|
||||
"num score bot ping guid name address qport\n");
|
||||
buffer.append(
|
||||
"--- ----- --- ---- -------------------------------- ---------------- --------------------- -----\n");
|
||||
|
||||
const auto svs_clients = *game::mp::svs_clients;
|
||||
if (svs_clients == nullptr)
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
|
||||
for (int i = 0; i < sv_maxclients->current.integer; i++)
|
||||
{
|
||||
const auto client = &svs_clients[i];
|
||||
|
||||
char clean_name[32] = {0};
|
||||
strncpy_s(clean_name, client->name, sizeof(clean_name));
|
||||
game::I_CleanStr(clean_name);
|
||||
|
||||
if (client->header.state >= 1)
|
||||
{
|
||||
buffer.append(utils::string::va("%3i %5i %3s %s %32s %16s %21s %5i\n",
|
||||
i,
|
||||
game::G_GetClientScore(i),
|
||||
game::SV_BotIsBot(i) ? "Yes" : "No",
|
||||
(client->header.state == 2)
|
||||
? "CNCT"
|
||||
: (client->header.state == 1)
|
||||
? "ZMBI"
|
||||
: utils::string::va("%4i", game::SV_GetClientPing(i)),
|
||||
game::SV_GetGuid(i),
|
||||
clean_name,
|
||||
network::net_adr_to_string(client->header.remoteAddress),
|
||||
client->header.remoteAddress.port)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
||||
bool message_redirect(const std::string& message)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> $(redirect_lock);
|
||||
|
||||
if (is_redirecting_)
|
||||
{
|
||||
has_redirected_ = true;
|
||||
network::send(redirect_target_, "print", message, '\n');
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
if (game::environment::is_sp())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
scheduler::once([]()
|
||||
{
|
||||
dvars::register_string("rcon_password", "", game::DvarFlags::DVAR_FLAG_NONE,
|
||||
"The password for remote console");
|
||||
}, scheduler::pipeline::main);
|
||||
|
||||
command::add("status", []()
|
||||
{
|
||||
const auto sv_running = game::Dvar_FindVar("sv_running");
|
||||
if (game::VirtualLobby_Loaded() || !sv_running || !sv_running->current.enabled)
|
||||
{
|
||||
console::error("Server is not running\n");
|
||||
return;
|
||||
}
|
||||
|
||||
auto status_buffer = build_status_buffer();
|
||||
console::info(status_buffer.data());
|
||||
});
|
||||
|
||||
if (!game::environment::is_dedi())
|
||||
{
|
||||
command::add("rcon", [&](const command::params& params)
|
||||
{
|
||||
static std::string rcon_password{};
|
||||
|
||||
if (params.size() < 2) return;
|
||||
|
||||
const auto operation = params.get(1);
|
||||
if (operation == "login"s)
|
||||
{
|
||||
if (params.size() < 3) return;
|
||||
|
||||
rcon_password = params.get(2);
|
||||
}
|
||||
else if (operation == "logout"s)
|
||||
{
|
||||
rcon_password.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
send_rcon_command(rcon_password, params.join(1));
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
network::on("rcon", [](const game::netadr_s& addr, const std::string_view& data)
|
||||
{
|
||||
const auto message = std::string{data};
|
||||
const auto pos = message.find_first_of(" ");
|
||||
if (pos == std::string::npos)
|
||||
{
|
||||
network::send(addr, "print", "Invalid RCon request", '\n');
|
||||
console::info("Invalid RCon request from %s\n", network::net_adr_to_string(addr));
|
||||
return;
|
||||
}
|
||||
|
||||
const auto password = message.substr(0, pos);
|
||||
const auto command = message.substr(pos + 1);
|
||||
const auto rcon_password = game::Dvar_FindVar("rcon_password");
|
||||
if (command.empty() || !rcon_password || !rcon_password->current.string || !strlen(
|
||||
rcon_password->current.string))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
setup_redirect(addr);
|
||||
|
||||
if (password != rcon_password->current.string)
|
||||
{
|
||||
network::send(redirect_target_, "print", "Invalid rcon password", '\n');
|
||||
console::error("Invalid rcon password\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
command::execute(command, true);
|
||||
}
|
||||
|
||||
if (!has_redirected_)
|
||||
{
|
||||
network::send(redirect_target_, "print", "", '\n');
|
||||
}
|
||||
|
||||
clear_redirect();
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(rcon::component)
|
6
src/client/component/rcon.hpp
Normal file
6
src/client/component/rcon.hpp
Normal file
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
namespace rcon
|
||||
{
|
||||
bool message_redirect(const std::string& message);
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "game_module.hpp"
|
||||
|
||||
#include <utils/nt.hpp>
|
||||
#include <utils/string.hpp>
|
||||
#include "game_module.hpp"
|
||||
|
||||
namespace redirect
|
||||
{
|
||||
|
@ -1,5 +1,8 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "dvars.hpp"
|
||||
|
||||
#include "game/game.hpp"
|
||||
#include "game/dvars.hpp"
|
||||
|
||||
@ -12,15 +15,54 @@ namespace renderer
|
||||
utils::hook::detour r_init_draw_method_hook;
|
||||
utils::hook::detour r_update_front_end_dvar_options_hook;
|
||||
|
||||
utils::hook::detour db_load_xassets_hook;
|
||||
|
||||
game::dvar_t* r_red_dot_brightness_scale;
|
||||
game::dvar_t* r_use_custom_red_dot_brightness;
|
||||
float tonemap_highlight_range = 16.f;
|
||||
|
||||
std::unordered_map<std::string, float> tonemap_highlight_range_overrides =
|
||||
{
|
||||
// all these are 16 by default (except mp_bog & mp_cargoship which have it at 0) which makes red dots hard to see
|
||||
{"mp_convoy", 22.f},
|
||||
{"mp_backlot", 20.f},
|
||||
{"mp_bog", 12.f},
|
||||
{"mp_bloc", 30.f},
|
||||
{"mp_countdown", 20.f},
|
||||
{"mp_crash", 20.f},
|
||||
{"mp_creek", 20.f},
|
||||
{"mp_crossfire", 26.f},
|
||||
{"mp_citystreets", 30.f},
|
||||
{"mp_farm", 20.f},
|
||||
{"mp_overgrown", 22.f},
|
||||
{"mp_pipeline", 26.f},
|
||||
{"mp_shipment", 20.f},
|
||||
{"mp_showdown", 24.f},
|
||||
{"mp_strike", 24.f},
|
||||
{"mp_vacant", 20.f},
|
||||
{"mp_cargoship", 14.f},
|
||||
{"mp_crash_snow", 24.f},
|
||||
{"mp_bog_summer", 24.f},
|
||||
};
|
||||
|
||||
int get_fullbright_technique()
|
||||
{
|
||||
return game::TECHNIQUE_UNLIT;
|
||||
switch (dvars::r_fullbright->current.integer)
|
||||
{
|
||||
case 4:
|
||||
return 3;
|
||||
case 3:
|
||||
return 13;
|
||||
case 2:
|
||||
return 25;
|
||||
default:
|
||||
return game::TECHNIQUE_UNLIT;
|
||||
}
|
||||
}
|
||||
|
||||
void gfxdrawmethod()
|
||||
{
|
||||
game::gfxDrawMethod->drawScene = game::GFX_DRAW_SCENE_STANDARD;
|
||||
|
||||
game::gfxDrawMethod->baseTechType = dvars::r_fullbright->current.enabled ? get_fullbright_technique() : game::TECHNIQUE_LIT;
|
||||
game::gfxDrawMethod->emissiveTechType = dvars::r_fullbright->current.enabled ? get_fullbright_technique() : game::TECHNIQUE_EMISSIVE;
|
||||
game::gfxDrawMethod->forceTechType = dvars::r_fullbright->current.enabled ? get_fullbright_technique() : 242;
|
||||
@ -43,6 +85,57 @@ namespace renderer
|
||||
|
||||
return r_update_front_end_dvar_options_hook.invoke<bool>();
|
||||
}
|
||||
|
||||
void set_tonemap_highlight_range()
|
||||
{
|
||||
auto* mapname = game::Dvar_FindVar("mapname");
|
||||
if (mapname != nullptr && tonemap_highlight_range_overrides.find(mapname->current.string)
|
||||
!= tonemap_highlight_range_overrides.end())
|
||||
{
|
||||
tonemap_highlight_range = tonemap_highlight_range_overrides[mapname->current.string];
|
||||
}
|
||||
else
|
||||
{
|
||||
tonemap_highlight_range = 16.f;
|
||||
}
|
||||
}
|
||||
|
||||
void db_load_xassets_stub(void* a1, void* a2, void* a3)
|
||||
{
|
||||
set_tonemap_highlight_range();
|
||||
db_load_xassets_hook.invoke<void>(a1, a2, a3);
|
||||
}
|
||||
|
||||
int get_red_dot_brightness()
|
||||
{
|
||||
static auto* r_tonemap_highlight_range = game::Dvar_FindVar("r_tonemapHighlightRange");
|
||||
auto value = r_tonemap_highlight_range->current.value;
|
||||
if (r_use_custom_red_dot_brightness->current.enabled)
|
||||
{
|
||||
value = tonemap_highlight_range * r_red_dot_brightness_scale->current.value;
|
||||
}
|
||||
|
||||
return *reinterpret_cast<int*>(&value);
|
||||
}
|
||||
|
||||
void* get_tonemap_highlight_range_stub()
|
||||
{
|
||||
return utils::hook::assemble([](utils::hook::assembler& a)
|
||||
{
|
||||
a.push(r9);
|
||||
a.push(rax);
|
||||
a.pushad64();
|
||||
a.call_aligned(get_red_dot_brightness);
|
||||
a.mov(qword_ptr(rsp, 0x80), rax);
|
||||
a.popad64();
|
||||
a.pop(rax);
|
||||
a.pop(r9);
|
||||
|
||||
a.mov(dword_ptr(r9, 0x1E84), eax);
|
||||
|
||||
a.jmp(0x1C4136_b);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
@ -50,28 +143,35 @@ namespace renderer
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
if (game::environment::is_dedi() || !game::environment::is_mp())
|
||||
if (game::environment::is_dedi())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
dvars::r_fullbright = dvars::register_int("r_fullbright", 0, 0, 3, game::DVAR_FLAG_SAVED);
|
||||
dvars::r_fullbright = dvars::register_int("r_fullbright", 0, 0, 4, game::DVAR_FLAG_SAVED, "Toggles rendering without lighting");
|
||||
|
||||
r_init_draw_method_hook.create(SELECT_VALUE(0x1404BD140, 0x1405C46E0), &r_init_draw_method_stub);
|
||||
r_update_front_end_dvar_options_hook.create(SELECT_VALUE(0x1404F8870, 0x1405FF9E0), &r_update_front_end_dvar_options_stub);
|
||||
r_init_draw_method_hook.create(SELECT_VALUE(0x5467E0_b, 0x669580_b), &r_init_draw_method_stub);
|
||||
r_update_front_end_dvar_options_hook.create(SELECT_VALUE(0x583560_b, 0x6A78C0_b), &r_update_front_end_dvar_options_stub);
|
||||
|
||||
// use "saved" flags for "r_normalMap"
|
||||
utils::hook::set<uint8_t>(SELECT_VALUE(0x1404CF5CA, 0x1405D460E), game::DVAR_FLAG_SAVED);
|
||||
// use "saved" flags
|
||||
dvars::override::register_enum("r_normalMap", game::DVAR_FLAG_SAVED);
|
||||
dvars::override::register_enum("r_specularMap", game::DVAR_FLAG_SAVED);
|
||||
dvars::override::register_enum("r_specOccMap", game::DVAR_FLAG_SAVED);
|
||||
|
||||
// use "saved" flags for "r_specularMap"
|
||||
utils::hook::set<uint8_t>(SELECT_VALUE(0x1404CF5F5, 0x1405D4639), game::DVAR_FLAG_SAVED);
|
||||
if (game::environment::is_mp())
|
||||
{
|
||||
// Adjust red dot brightness
|
||||
utils::hook::jump(0x1C4125_b, get_tonemap_highlight_range_stub(), true);
|
||||
db_load_xassets_hook.create(0x397500_b, db_load_xassets_stub);
|
||||
|
||||
// use "saved" flags for "r_specOccMap"
|
||||
utils::hook::set<uint8_t>(SELECT_VALUE(0x1404CF620, 0x1405D4664), game::DVAR_FLAG_SAVED);
|
||||
r_red_dot_brightness_scale = dvars::register_float("r_redDotBrightnessScale",
|
||||
1.f, 0.1f, 5.f, game::DVAR_FLAG_SAVED, "Adjust red-dot reticle brightness");
|
||||
|
||||
r_use_custom_red_dot_brightness = dvars::register_bool("r_useCustomRedDotBrightness",
|
||||
true, game::DVAR_FLAG_SAVED, "Use custom red-dot brightness values");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
REGISTER_COMPONENT(renderer::component)
|
||||
#endif
|
@ -75,7 +75,8 @@ namespace scheduler
|
||||
{
|
||||
new_callbacks_.access([&](task_list& new_tasks)
|
||||
{
|
||||
tasks.insert(tasks.end(), std::move_iterator<task_list::iterator>(new_tasks.begin()), std::move_iterator<task_list::iterator>(new_tasks.end()));
|
||||
tasks.insert(tasks.end(), std::move_iterator<task_list::iterator>(new_tasks.begin()),
|
||||
std::move_iterator<task_list::iterator>(new_tasks.end()));
|
||||
new_tasks = {};
|
||||
});
|
||||
});
|
||||
@ -88,6 +89,7 @@ namespace scheduler
|
||||
utils::hook::detour r_end_frame_hook;
|
||||
utils::hook::detour g_run_frame_hook;
|
||||
utils::hook::detour main_frame_hook;
|
||||
utils::hook::detour hks_frame_hook;
|
||||
|
||||
void execute(const pipeline type)
|
||||
{
|
||||
@ -98,7 +100,6 @@ namespace scheduler
|
||||
void r_end_frame_stub()
|
||||
{
|
||||
execute(pipeline::renderer);
|
||||
r_end_frame_hook.invoke<void>();
|
||||
}
|
||||
|
||||
void server_frame_stub()
|
||||
@ -107,15 +108,29 @@ namespace scheduler
|
||||
execute(pipeline::server);
|
||||
}
|
||||
|
||||
void main_frame_stub()
|
||||
void* main_frame_stub()
|
||||
{
|
||||
main_frame_hook.invoke<void>();
|
||||
execute(pipeline::main);
|
||||
const auto _0 = gsl::finally([]()
|
||||
{
|
||||
execute(pipeline::main);
|
||||
});
|
||||
|
||||
return main_frame_hook.invoke<void*>();
|
||||
}
|
||||
|
||||
void hks_frame_stub()
|
||||
{
|
||||
const auto state = *game::hks::lua_state;
|
||||
if (state)
|
||||
{
|
||||
execute(pipeline::lui);
|
||||
}
|
||||
hks_frame_hook.invoke<bool>();
|
||||
}
|
||||
}
|
||||
|
||||
void schedule(const std::function<bool()>& callback, const pipeline type,
|
||||
const std::chrono::milliseconds delay)
|
||||
const std::chrono::milliseconds delay)
|
||||
{
|
||||
assert(type >= 0 && type < pipeline::count);
|
||||
|
||||
@ -128,7 +143,7 @@ namespace scheduler
|
||||
}
|
||||
|
||||
void loop(const std::function<void()>& callback, const pipeline type,
|
||||
const std::chrono::milliseconds delay)
|
||||
const std::chrono::milliseconds delay)
|
||||
{
|
||||
schedule([callback]()
|
||||
{
|
||||
@ -138,7 +153,7 @@ namespace scheduler
|
||||
}
|
||||
|
||||
void once(const std::function<void()>& callback, const pipeline type,
|
||||
const std::chrono::milliseconds delay)
|
||||
const std::chrono::milliseconds delay)
|
||||
{
|
||||
schedule([callback]()
|
||||
{
|
||||
@ -148,7 +163,7 @@ namespace scheduler
|
||||
}
|
||||
|
||||
void on_game_initialized(const std::function<void()>& callback, const pipeline type,
|
||||
const std::chrono::milliseconds delay)
|
||||
const std::chrono::milliseconds delay)
|
||||
{
|
||||
schedule([=]()
|
||||
{
|
||||
@ -180,9 +195,22 @@ namespace scheduler
|
||||
|
||||
void post_unpack() override
|
||||
{
|
||||
r_end_frame_hook.create(SELECT_VALUE(0x1404F7310, 0x1405FE470), scheduler::r_end_frame_stub);
|
||||
g_run_frame_hook.create(SELECT_VALUE(0x1402772D0, 0x14033A640), scheduler::server_frame_stub);
|
||||
main_frame_hook.create(SELECT_VALUE(0x1401CE8D0, 0x1400D8310), scheduler::main_frame_stub);
|
||||
utils::hook::jump(SELECT_VALUE(0x581FB0_b, 0x6A6300_b), utils::hook::assemble([](utils::hook::assembler& a)
|
||||
{
|
||||
a.pushad64();
|
||||
a.call_aligned(r_end_frame_stub);
|
||||
a.popad64();
|
||||
|
||||
a.sub(rsp, 0x28);
|
||||
a.call(SELECT_VALUE(0x581840_b, 0x6A5C20_b));
|
||||
a.mov(rax, SELECT_VALUE(0x1182A680_b, 0xEAB4308_b));
|
||||
a.mov(rax, qword_ptr(rax));
|
||||
a.jmp(SELECT_VALUE(0x581FC0_b, 0x6A6310_b));
|
||||
}), true);
|
||||
|
||||
g_run_frame_hook.create(SELECT_VALUE(0x2992E0_b, 0x417940_b), scheduler::server_frame_stub);
|
||||
main_frame_hook.create(SELECT_VALUE(0x1B1DF0_b, 0x3438B0_b), scheduler::main_frame_stub);
|
||||
hks_frame_hook.create(SELECT_VALUE(0x1028D0_b, 0x2792E0_b), scheduler::hks_frame_stub);
|
||||
}
|
||||
|
||||
void pre_destroy() override
|
||||
@ -196,4 +224,4 @@ namespace scheduler
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(scheduler::component)
|
||||
REGISTER_COMPONENT(scheduler::component)
|
@ -16,6 +16,9 @@ namespace scheduler
|
||||
// The game's main thread
|
||||
main,
|
||||
|
||||
// LUI context
|
||||
lui,
|
||||
|
||||
count,
|
||||
};
|
||||
|
||||
|
197
src/client/component/scripting.cpp
Normal file
197
src/client/component/scripting.cpp
Normal file
@ -0,0 +1,197 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "game/game.hpp"
|
||||
#include "game/dvars.hpp"
|
||||
|
||||
#include "game/scripting/entity.hpp"
|
||||
#include "game/scripting/functions.hpp"
|
||||
#include "game/scripting/event.hpp"
|
||||
#include "game/scripting/lua/engine.hpp"
|
||||
#include "game/scripting/execution.hpp"
|
||||
|
||||
#include "scheduler.hpp"
|
||||
#include "scripting.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
#include <utils/io.hpp>
|
||||
#include <utils/string.hpp>
|
||||
|
||||
namespace scripting
|
||||
{
|
||||
std::unordered_map<int, std::unordered_map<std::string, int>> fields_table;
|
||||
std::unordered_map<std::string, std::unordered_map<std::string, const char*>> script_function_table;
|
||||
utils::concurrency::container<shared_table_t> shared_table;
|
||||
|
||||
namespace
|
||||
{
|
||||
utils::hook::detour vm_notify_hook;
|
||||
utils::hook::detour vm_execute_hook;
|
||||
utils::hook::detour scr_load_level_hook;
|
||||
utils::hook::detour g_shutdown_game_hook;
|
||||
|
||||
utils::hook::detour scr_add_class_field_hook;
|
||||
|
||||
utils::hook::detour scr_set_thread_position_hook;
|
||||
utils::hook::detour process_script_hook;
|
||||
|
||||
utils::hook::detour sl_get_canonical_string_hook;
|
||||
|
||||
utils::hook::detour db_find_xasset_header_hook;
|
||||
|
||||
std::string current_file;
|
||||
unsigned int current_file_id{};
|
||||
|
||||
game::dvar_t* g_dump_scripts;
|
||||
|
||||
void vm_notify_stub(const unsigned int notify_list_owner_id, const game::scr_string_t string_value,
|
||||
game::VariableValue* top)
|
||||
{
|
||||
if (!game::VirtualLobby_Loaded())
|
||||
{
|
||||
const auto* string = game::SL_ConvertToString(string_value);
|
||||
if (string)
|
||||
{
|
||||
event e;
|
||||
e.name = string;
|
||||
e.entity = notify_list_owner_id;
|
||||
|
||||
for (auto* value = top; value->type != game::SCRIPT_END; --value)
|
||||
{
|
||||
e.arguments.emplace_back(*value);
|
||||
}
|
||||
|
||||
lua::engine::notify(e);
|
||||
}
|
||||
}
|
||||
|
||||
vm_notify_hook.invoke<void>(notify_list_owner_id, string_value, top);
|
||||
}
|
||||
|
||||
unsigned int vm_execute_stub()
|
||||
{
|
||||
if (!lua::engine::is_running())
|
||||
{
|
||||
lua::engine::start();
|
||||
}
|
||||
|
||||
return vm_execute_hook.invoke<unsigned int>();
|
||||
}
|
||||
|
||||
void scr_load_level_stub()
|
||||
{
|
||||
scr_load_level_hook.invoke<void>();
|
||||
if (!game::VirtualLobby_Loaded())
|
||||
{
|
||||
lua::engine::start();
|
||||
}
|
||||
}
|
||||
|
||||
void g_shutdown_game_stub(const int free_scripts)
|
||||
{
|
||||
if (free_scripts)
|
||||
{
|
||||
script_function_table.clear();
|
||||
}
|
||||
|
||||
scripting::notify(*game::levelEntityId, "shutdownGame_called", {1});
|
||||
lua::engine::stop();
|
||||
return g_shutdown_game_hook.invoke<void>(free_scripts);
|
||||
}
|
||||
|
||||
void scr_add_class_field_stub(unsigned int classnum, game::scr_string_t name, unsigned int canonical_string, unsigned int offset)
|
||||
{
|
||||
const auto name_str = game::SL_ConvertToString(name);
|
||||
|
||||
if (fields_table[classnum].find(name_str) == fields_table[classnum].end())
|
||||
{
|
||||
fields_table[classnum][name_str] = offset;
|
||||
}
|
||||
|
||||
scr_add_class_field_hook.invoke<void>(classnum, name, canonical_string, offset);
|
||||
}
|
||||
|
||||
void process_script_stub(const char* filename)
|
||||
{
|
||||
const auto file_id = atoi(filename);
|
||||
if (file_id)
|
||||
{
|
||||
current_file_id = file_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
current_file_id = 0;
|
||||
current_file = filename;
|
||||
}
|
||||
|
||||
process_script_hook.invoke<void>(filename);
|
||||
}
|
||||
|
||||
void add_function(const std::string& file, unsigned int id, const char* pos)
|
||||
{
|
||||
const auto function_names = scripting::find_token(id);
|
||||
for (const auto& name : function_names)
|
||||
{
|
||||
script_function_table[file][name] = pos;
|
||||
}
|
||||
}
|
||||
|
||||
void scr_set_thread_position_stub(unsigned int thread_name, const char* code_pos)
|
||||
{
|
||||
if (current_file_id)
|
||||
{
|
||||
const auto names = scripting::find_token(current_file_id);
|
||||
for (const auto& name : names)
|
||||
{
|
||||
add_function(name, thread_name, code_pos);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
add_function(current_file, thread_name, code_pos);
|
||||
}
|
||||
|
||||
scr_set_thread_position_hook.invoke<void>(thread_name, code_pos);
|
||||
}
|
||||
|
||||
unsigned int sl_get_canonical_string_stub(const char* str)
|
||||
{
|
||||
const auto result = sl_get_canonical_string_hook.invoke<unsigned int>(str);
|
||||
scripting::token_map[str] = result;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
vm_notify_hook.create(SELECT_VALUE(0x3CD500_b, 0x514560_b), vm_notify_stub);
|
||||
|
||||
scr_add_class_field_hook.create(SELECT_VALUE(0x3C3CE0_b, 0x50AE20_b), scr_add_class_field_stub);
|
||||
|
||||
scr_set_thread_position_hook.create(SELECT_VALUE(0x3BD890_b, 0x504870_b), scr_set_thread_position_stub);
|
||||
process_script_hook.create(SELECT_VALUE(0x3C7200_b, 0x50E340_b), process_script_stub);
|
||||
sl_get_canonical_string_hook.create(game::SL_GetCanonicalString, sl_get_canonical_string_stub);
|
||||
|
||||
if (!game::environment::is_sp())
|
||||
{
|
||||
scr_load_level_hook.create(0x450FC0_b, scr_load_level_stub);
|
||||
}
|
||||
else
|
||||
{
|
||||
vm_execute_hook.create(0x3CA080_b, vm_execute_stub);
|
||||
}
|
||||
|
||||
g_shutdown_game_hook.create(SELECT_VALUE(0x2A5130_b, 0x422F30_b), g_shutdown_game_stub);
|
||||
|
||||
scheduler::loop([]()
|
||||
{
|
||||
lua::engine::run_frame();
|
||||
}, scheduler::pipeline::server);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(scripting::component)
|
11
src/client/component/scripting.hpp
Normal file
11
src/client/component/scripting.hpp
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
#include <utils/concurrency.hpp>
|
||||
|
||||
namespace scripting
|
||||
{
|
||||
using shared_table_t = std::unordered_map<std::string, std::string>;
|
||||
|
||||
extern std::unordered_map<int, std::unordered_map<std::string, int>> fields_table;
|
||||
extern std::unordered_map<std::string, std::unordered_map<std::string, const char*>> script_function_table;
|
||||
extern utils::concurrency::container<shared_table_t> shared_table;
|
||||
}
|
37
src/client/component/security.cpp
Normal file
37
src/client/component/security.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "game/game.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
|
||||
namespace security
|
||||
{
|
||||
namespace
|
||||
{
|
||||
void set_cached_playerdata_stub(const int localclient, const int index1, const int index2)
|
||||
{
|
||||
if (index1 >= 0 && index1 < 18 && index2 >= 0 && index2 < 42)
|
||||
{
|
||||
utils::hook::invoke<void>(0x61A9D0_b, localclient, index1, index2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
if (game::environment::is_sp())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Patch vulnerability in PlayerCards_SetCachedPlayerData
|
||||
utils::hook::call(0xF4632_b, set_cached_playerdata_stub);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(security::component)
|
@ -1,23 +1,26 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "server_list.hpp"
|
||||
#include "localized_strings.hpp"
|
||||
#include "network.hpp"
|
||||
#include "scheduler.hpp"
|
||||
#include "party.hpp"
|
||||
#include "console.hpp"
|
||||
#include "command.hpp"
|
||||
|
||||
#include "game/game.hpp"
|
||||
#include "game/ui_scripting/execution.hpp"
|
||||
|
||||
#include <utils/cryptography.hpp>
|
||||
#include <utils/string.hpp>
|
||||
#include <utils/hook.hpp>
|
||||
|
||||
#include "console.hpp"
|
||||
|
||||
namespace server_list
|
||||
{
|
||||
namespace
|
||||
{
|
||||
const int server_limit = 18;
|
||||
const int server_limit = 100;
|
||||
|
||||
struct server_info
|
||||
{
|
||||
@ -106,19 +109,13 @@ namespace server_list
|
||||
int ui_feeder_count()
|
||||
{
|
||||
std::lock_guard<std::mutex> _(mutex);
|
||||
if (update_server_list)
|
||||
{
|
||||
update_server_list = false;
|
||||
return 0;
|
||||
}
|
||||
const auto count = static_cast<int>(servers.size());
|
||||
const auto index = get_page_base_index();
|
||||
const auto diff = count - index;
|
||||
return diff > server_limit ? server_limit : static_cast<int>(diff);
|
||||
}
|
||||
|
||||
const char* ui_feeder_item_text(int /*localClientNum*/, void* /*a2*/, void* /*a3*/, const int index,
|
||||
const int column)
|
||||
const char* ui_feeder_item_text(const int index, const int column)
|
||||
{
|
||||
std::lock_guard<std::mutex> _(mutex);
|
||||
|
||||
@ -150,6 +147,11 @@ namespace server_list
|
||||
return servers[i].game_type.empty() ? "" : utils::string::va("%s", servers[i].game_type.data());
|
||||
}
|
||||
|
||||
if (column == 4)
|
||||
{
|
||||
return servers[i].game_type.empty() ? "" : utils::string::va("%i", servers[i].ping);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
@ -252,34 +254,29 @@ namespace server_list
|
||||
return true;
|
||||
}
|
||||
|
||||
void resize_host_name(std::string& name)
|
||||
{
|
||||
name = utils::string::split(name, '\n').front();
|
||||
|
||||
game::Font_s* font = game::R_RegisterFont("fonts/default.otf", 18);
|
||||
auto text_size = game::UI_TextWidth(name.data(), 32, font, 1.0f);
|
||||
|
||||
while (text_size > 450)
|
||||
{
|
||||
text_size = game::UI_TextWidth(name.data(), 32, font, 1.0f);
|
||||
name.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
utils::hook::detour lui_open_menu_hook;
|
||||
|
||||
void lui_open_menu_stub(int controllerIndex, const char* menu, int a3, int a4, unsigned int a5)
|
||||
void lui_open_menu_stub(int controllerIndex, const char* menuName, int isPopup, int isModal, unsigned int isExclusive)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
console::info("[LUI] %s\n", menu);
|
||||
console::info("[LUI] %s\n", menuName);
|
||||
#endif
|
||||
|
||||
if (!strcmp(menu, "menu_systemlink_join"))
|
||||
if (!strcmp(menuName, "menu_systemlink_join"))
|
||||
{
|
||||
refresh_server_list();
|
||||
}
|
||||
|
||||
lui_open_menu_hook.invoke<void>(controllerIndex, menu, a3, a4, a5);
|
||||
lui_open_menu_hook.invoke<void>(controllerIndex, menuName, isPopup, isModal, isExclusive);
|
||||
}
|
||||
|
||||
void check_refresh()
|
||||
{
|
||||
if (update_server_list)
|
||||
{
|
||||
update_server_list = false;
|
||||
ui_scripting::notify("updateGameList", {});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -303,8 +300,7 @@ namespace server_list
|
||||
|
||||
bool get_master_server(game::netadr_s& address)
|
||||
{
|
||||
return game::NET_StringToAdr("135.148.53.121:20810", &address);
|
||||
// return game::NET_StringToAdr("master.xlabs.dev:20810", &address);
|
||||
return game::NET_StringToAdr("master.h1.gg:20810", &address);
|
||||
}
|
||||
|
||||
void handle_info_response(const game::netadr_s& address, const utils::info_string& info)
|
||||
@ -330,6 +326,11 @@ namespace server_list
|
||||
return;
|
||||
}
|
||||
|
||||
if (info.get("gamename") != "H1")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int start_time{};
|
||||
const auto now = game::Sys_Milliseconds();
|
||||
|
||||
@ -359,8 +360,6 @@ namespace server_list
|
||||
|
||||
server.in_game = 1;
|
||||
|
||||
resize_host_name(server.host_name);
|
||||
|
||||
insert_server(std::move(server));
|
||||
}
|
||||
|
||||
@ -372,20 +371,72 @@ namespace server_list
|
||||
if (!game::environment::is_mp()) return;
|
||||
|
||||
localized_strings::override("PLATFORM_SYSTEM_LINK_TITLE", "SERVER LIST");
|
||||
|
||||
|
||||
// hook LUI_OpenMenu to refresh server list for system link menu
|
||||
lui_open_menu_hook.create(game::LUI_OpenMenu, lui_open_menu_stub);
|
||||
|
||||
// replace UI_RunMenuScript call in LUI_CoD_LuaCall_RefreshServerList to our refresh_servers
|
||||
utils::hook::call(0x14018A0C9, &refresh_server_list);
|
||||
utils::hook::call(0x14018A5DE, &join_server);
|
||||
utils::hook::nop(0x14018A5FD, 5);
|
||||
utils::hook::jump(0x28E049_b, utils::hook::assemble([](utils::hook::assembler& a)
|
||||
{
|
||||
a.pushad64();
|
||||
a.call_aligned(refresh_server_list);
|
||||
a.popad64();
|
||||
|
||||
a.xor_(eax, eax);
|
||||
a.mov(rbx, qword_ptr(rsp, 0x38));
|
||||
a.add(rsp, 0x20);
|
||||
a.pop(rdi);
|
||||
a.ret();
|
||||
}), true);
|
||||
|
||||
utils::hook::jump(0x28E557_b, utils::hook::assemble([](utils::hook::assembler& a)
|
||||
{
|
||||
a.mov(r8d, edi);
|
||||
a.mov(ecx, eax);
|
||||
a.mov(ebx, eax);
|
||||
|
||||
a.pushad64();
|
||||
a.call_aligned(join_server);
|
||||
a.popad64();
|
||||
|
||||
a.jmp(0x28E563_b);
|
||||
}), true);
|
||||
|
||||
utils::hook::nop(0x28E57D_b, 5);
|
||||
|
||||
// do feeder stuff
|
||||
utils::hook::call(0x14018A199, &ui_feeder_count);
|
||||
utils::hook::call(0x14018A3B1, &ui_feeder_item_text);
|
||||
utils::hook::jump(0x28E117_b, utils::hook::assemble([](utils::hook::assembler& a)
|
||||
{
|
||||
a.mov(ecx, eax);
|
||||
|
||||
a.pushad64();
|
||||
a.call_aligned(ui_feeder_count);
|
||||
a.movd(xmm0, eax);
|
||||
a.popad64();
|
||||
|
||||
a.mov(rax, qword_ptr(rbx, 0x48));
|
||||
a.cvtdq2ps(xmm0, xmm0);
|
||||
a.jmp(0x28E12B_b);
|
||||
}), true);
|
||||
|
||||
utils::hook::jump(0x28E331_b, utils::hook::assemble([](utils::hook::assembler& a)
|
||||
{
|
||||
a.push(rax);
|
||||
a.pushad64();
|
||||
a.mov(rcx, r9); // index
|
||||
a.mov(rdx, qword_ptr(rsp, 0x88 + 0x20)); // column
|
||||
a.call_aligned(ui_feeder_item_text);
|
||||
a.mov(qword_ptr(rsp, 0x80), rax);
|
||||
a.popad64();
|
||||
a.pop(rax);
|
||||
|
||||
a.mov(rsi, qword_ptr(rsp, 0x90));
|
||||
a.mov(rdi, rax);
|
||||
a.jmp(0x28E341_b);
|
||||
}), true);
|
||||
|
||||
scheduler::loop(do_frame_work, scheduler::pipeline::main);
|
||||
scheduler::loop(check_refresh, scheduler::pipeline::lui, 10ms);
|
||||
|
||||
network::on("getServersResponse", [](const game::netadr_s& target, const std::string_view& data)
|
||||
{
|
||||
@ -434,4 +485,4 @@ namespace server_list
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(server_list::component)
|
||||
REGISTER_COMPONENT(server_list::component)
|
||||
|
@ -1,50 +0,0 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "scheduler.hpp"
|
||||
#include "dvars.hpp"
|
||||
|
||||
#include "game/game.hpp"
|
||||
#include "game/dvars.hpp"
|
||||
|
||||
#include <utils/nt.hpp>
|
||||
#include <utils/hook.hpp>
|
||||
#include <utils/flags.hpp>
|
||||
|
||||
namespace shaders
|
||||
{
|
||||
namespace
|
||||
{
|
||||
game::dvar_t* disable_shader_caching = nullptr;
|
||||
|
||||
bool shader_should_show_dialog_stub()
|
||||
{
|
||||
return !disable_shader_caching->current.enabled;
|
||||
}
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
if (!game::environment::is_mp())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const auto has_flag = utils::flags::has_flag("noshadercaching");
|
||||
|
||||
disable_shader_caching = dvars::register_bool("disable_shader_caching", has_flag, game::DVAR_FLAG_SAVED, true);
|
||||
if (has_flag)
|
||||
{
|
||||
dvars::override::set_bool("disable_shader_caching", 1);
|
||||
dvars::override::set_from_string("disable_shader_caching", "1");
|
||||
}
|
||||
|
||||
utils::hook::jump(0x14007E710, shader_should_show_dialog_stub);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(shaders::component)
|
@ -45,7 +45,7 @@ namespace slowmotion
|
||||
return;
|
||||
}
|
||||
|
||||
utils::hook::jump(0x140365480, scr_cmd_set_slow_motion); // H1(1.4)
|
||||
utils::hook::jump(0x43D2E0_b, scr_cmd_set_slow_motion);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -30,9 +30,9 @@ namespace splash
|
||||
void post_unpack() override
|
||||
{
|
||||
// Disable native splash screen
|
||||
utils::hook::nop(SELECT_VALUE(0x1403E192E, 0x1405123E2), 5); // H1(1.4)
|
||||
utils::hook::jump(SELECT_VALUE(0x1403E2E70, 0x140513AF0), destroy_stub); // H1(1.4)
|
||||
utils::hook::jump(SELECT_VALUE(0x1403E2EB0, 0x140513B30), destroy_stub); // H1(1.4)
|
||||
utils::hook::set<uint8_t>(SELECT_VALUE(0x462B90_b, 0x5BDF20_b), 0xC3);
|
||||
utils::hook::jump(SELECT_VALUE(0x462E40_b, 0x5BE1D0_b), destroy_stub, true);
|
||||
utils::hook::jump(SELECT_VALUE(0x462E80_b, 0x5BE210_b), destroy_stub, true);
|
||||
}
|
||||
|
||||
void pre_destroy() override
|
||||
|
84
src/client/component/stats.cpp
Normal file
84
src/client/component/stats.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "scheduler.hpp"
|
||||
#include "dvars.hpp"
|
||||
|
||||
#include "game/game.hpp"
|
||||
#include "game/dvars.hpp"
|
||||
|
||||
#include <utils/nt.hpp>
|
||||
#include <utils/hook.hpp>
|
||||
#include <utils/flags.hpp>
|
||||
|
||||
namespace stats
|
||||
{
|
||||
namespace
|
||||
{
|
||||
game::dvar_t* cg_unlock_all_items;
|
||||
game::dvar_t* cg_unlock_all_loot;
|
||||
|
||||
utils::hook::detour is_item_unlocked_hook;
|
||||
utils::hook::detour is_item_unlocked_hook2;
|
||||
|
||||
int is_item_unlocked_stub(int a1, void* a2, void* a3, void* a4, int a5, void* a6)
|
||||
{
|
||||
if (cg_unlock_all_items->current.enabled)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return is_item_unlocked_hook.invoke<int>(a1, a2, a3, a4, a5, a6);
|
||||
}
|
||||
|
||||
int is_item_unlocked()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int is_item_unlocked_stub2(void* a1, void* a2)
|
||||
{
|
||||
const auto state = is_item_unlocked_hook2.invoke<int>(a1, a2);
|
||||
if (state == 15 /*Not In Inventory*/ && cg_unlock_all_loot->current.enabled)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
if (game::environment::is_sp())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
utils::hook::jump(0x19E6E0_b, is_item_unlocked, true);
|
||||
|
||||
if (game::environment::is_dedi())
|
||||
{
|
||||
utils::hook::jump(0x19E070_b, is_item_unlocked, true);
|
||||
utils::hook::jump(0x19D390_b, is_item_unlocked, true);
|
||||
utils::hook::jump(0x19D140_b, is_item_unlocked, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
is_item_unlocked_hook.create(0x19E070_b, is_item_unlocked_stub);
|
||||
is_item_unlocked_hook2.create(0x19D140_b, is_item_unlocked_stub2);
|
||||
|
||||
cg_unlock_all_items = dvars::register_bool("cg_unlockall_items", false, game::DVAR_FLAG_SAVED,
|
||||
"Whether items should be locked based on the player's stats or always unlocked.");
|
||||
dvars::register_bool("cg_unlockall_classes", false, game::DVAR_FLAG_SAVED,
|
||||
"Whether classes should be locked based on the player's stats or always unlocked.");
|
||||
cg_unlock_all_loot = dvars::register_bool("cg_unlockall_loot", false, game::DVAR_FLAG_SAVED,
|
||||
"Whether loot should be locked based on the player's stats or always unlocked.");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(stats::component)
|
@ -42,7 +42,7 @@ namespace steam_proxy
|
||||
#ifndef DEV_BUILD
|
||||
try
|
||||
{
|
||||
this->start_mod("\xF0\x9F\x90\xA4" " H1-Mod: "s + (game::environment::is_sp() ? "Singleplayer" : "Multiplayer"), game::environment::is_sp() ? 393080 : 393100);
|
||||
this->start_mod("\xF0\x9F\x8E\xAE" " H1-Mod: "s + (game::environment::is_sp() ? "Singleplayer" : "Multiplayer"), game::environment::is_sp() ? 393080 : 393100);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
|
@ -51,25 +51,26 @@ namespace system_check
|
||||
{
|
||||
static std::unordered_map<std::string, std::string> mp_zone_hashes =
|
||||
{
|
||||
{"patch_common_mp.ff", "3F44B0CFB0B8E0FBD9687C2942204AB7F11E66E6E15C73B8B4A5EB5920115A31"},
|
||||
{"patch_common_mp.ff", "E45EF5F29D12A5A47F405F89FBBEE479C0A90D02141ABF852D481689514134A1"},
|
||||
};
|
||||
|
||||
static std::unordered_map<std::string, std::string> sp_zone_hashes =
|
||||
{
|
||||
// Steam doesn't necessarily deliver this file :(
|
||||
{"patch_common.ff", "BB0617DD94AF2F511571E7184BBEDE76E64D97E5D0DAFDB457F00717F035EBF0"},
|
||||
{"patch_common.ff", "1D32A9770F90ED022AA76F4859B4AB178E194A703383E61AC2CE83B1E828B18F"},
|
||||
};
|
||||
|
||||
|
||||
return verify_hashes(mp_zone_hashes) && (game::environment::is_dedi() || verify_hashes(sp_zone_hashes));
|
||||
}
|
||||
|
||||
// need to update these values
|
||||
void verify_binary_version()
|
||||
{
|
||||
const auto value = *reinterpret_cast<DWORD*>(0x140001337);
|
||||
if (value != 0xFFB8006D && value != 0xFFB80080)
|
||||
const auto value = *reinterpret_cast<DWORD*>(0x1337_b);
|
||||
if (value != 0x60202B6A && value != 0xBC0E9FE)
|
||||
{
|
||||
throw std::runtime_error("Unsupported Call of Duty: Modern Warfare Remastered version(1.4)");
|
||||
throw std::runtime_error("Unsupported Call of Duty: Modern Warfare Remastered version (1.15)");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -90,7 +91,7 @@ namespace system_check
|
||||
if (!is_valid())
|
||||
{
|
||||
MessageBoxA(nullptr, "Your game files are outdated or unsupported.\n"
|
||||
"Please get the latest officially supported Call of Duty: Modern Warfare Remastered 1.4 files, or you will get random crashes and issues.",
|
||||
"Please get the latest officially supported Call of Duty: Modern Warfare Remastered files, or you will get random crashes and issues.",
|
||||
"Invalid game files!", MB_ICONINFORMATION);
|
||||
}
|
||||
}
|
||||
|
549
src/client/component/ui_scripting.cpp
Normal file
549
src/client/component/ui_scripting.cpp
Normal file
@ -0,0 +1,549 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "game/game.hpp"
|
||||
#include "game/dvars.hpp"
|
||||
|
||||
#include "scheduler.hpp"
|
||||
#include "command.hpp"
|
||||
|
||||
#include "localized_strings.hpp"
|
||||
#include "console.hpp"
|
||||
#include "game_module.hpp"
|
||||
#include "fps.hpp"
|
||||
#include "server_list.hpp"
|
||||
#include "filesystem.hpp"
|
||||
#include "mods.hpp"
|
||||
#include "fastfiles.hpp"
|
||||
#include "scripting.hpp"
|
||||
#include "updater.hpp"
|
||||
|
||||
#include "game/ui_scripting/execution.hpp"
|
||||
#include "game/scripting/execution.hpp"
|
||||
|
||||
#include "ui_scripting.hpp"
|
||||
|
||||
#include <utils/string.hpp>
|
||||
#include <utils/hook.hpp>
|
||||
#include <utils/io.hpp>
|
||||
#include <utils/binary_resource.hpp>
|
||||
|
||||
namespace ui_scripting
|
||||
{
|
||||
namespace
|
||||
{
|
||||
std::unordered_map<game::hks::cclosure*, std::function<arguments(const function_arguments& args)>> converted_functions;
|
||||
|
||||
utils::hook::detour hks_start_hook;
|
||||
utils::hook::detour hks_shutdown_hook;
|
||||
utils::hook::detour hks_package_require_hook;
|
||||
|
||||
utils::hook::detour hks_load_hook;
|
||||
|
||||
const auto lui_common = utils::nt::load_resource(LUI_COMMON);
|
||||
const auto lui_updater = utils::nt::load_resource(LUI_UPDATER);
|
||||
const auto lua_json = utils::nt::load_resource(LUA_JSON);
|
||||
|
||||
struct script
|
||||
{
|
||||
std::string name;
|
||||
std::string root;
|
||||
};
|
||||
|
||||
struct globals_t
|
||||
{
|
||||
std::string in_require_script;
|
||||
std::vector<script> loaded_scripts;
|
||||
bool load_raw_script{};
|
||||
std::string raw_script_name{};
|
||||
};
|
||||
|
||||
globals_t globals{};
|
||||
|
||||
bool is_loaded_script(const std::string& name)
|
||||
{
|
||||
for (auto i = globals.loaded_scripts.begin(); i != globals.loaded_scripts.end(); ++i)
|
||||
{
|
||||
if (i->name == name)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string get_root_script(const std::string& name)
|
||||
{
|
||||
for (auto i = globals.loaded_scripts.begin(); i != globals.loaded_scripts.end(); ++i)
|
||||
{
|
||||
if (i->name == name)
|
||||
{
|
||||
return i->root;
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
table get_globals()
|
||||
{
|
||||
const auto state = *game::hks::lua_state;
|
||||
return state->globals.v.table;
|
||||
}
|
||||
|
||||
void print_error(const std::string& error)
|
||||
{
|
||||
console::error("************** LUI script execution error **************\n");
|
||||
console::error("%s\n", error.data());
|
||||
console::error("********************************************************\n");
|
||||
}
|
||||
|
||||
void print_loading_script(const std::string& name)
|
||||
{
|
||||
console::info("Loading LUI script '%s'\n", name.data());
|
||||
}
|
||||
|
||||
std::string get_current_script()
|
||||
{
|
||||
const auto state = *game::hks::lua_state;
|
||||
game::hks::lua_Debug info{};
|
||||
game::hks::hksi_lua_getstack(state, 1, &info);
|
||||
game::hks::hksi_lua_getinfo(state, "nSl", &info);
|
||||
return info.short_src;
|
||||
}
|
||||
|
||||
int load_buffer(const std::string& name, const std::string& data)
|
||||
{
|
||||
const auto state = *game::hks::lua_state;
|
||||
const auto sharing_mode = state->m_global->m_bytecodeSharingMode;
|
||||
state->m_global->m_bytecodeSharingMode = game::hks::HKS_BYTECODE_SHARING_ON;
|
||||
const auto _0 = gsl::finally([&]()
|
||||
{
|
||||
state->m_global->m_bytecodeSharingMode = sharing_mode;
|
||||
});
|
||||
|
||||
game::hks::HksCompilerSettings compiler_settings{};
|
||||
return game::hks::hksi_hksL_loadbuffer(state, &compiler_settings, data.data(), data.size(), name.data());
|
||||
}
|
||||
|
||||
void load_script(const std::string& name, const std::string& data)
|
||||
{
|
||||
globals.loaded_scripts.push_back({name, name});
|
||||
|
||||
const auto lua = get_globals();
|
||||
const auto load_results = lua["loadstring"](data, name);
|
||||
|
||||
if (load_results[0].is<function>())
|
||||
{
|
||||
const auto results = lua["pcall"](load_results);
|
||||
if (!results[0].as<bool>())
|
||||
{
|
||||
print_error(results[1].as<std::string>());
|
||||
}
|
||||
}
|
||||
else if (load_results[1].is<std::string>())
|
||||
{
|
||||
print_error(load_results[1].as<std::string>());
|
||||
}
|
||||
}
|
||||
|
||||
void load_scripts(const std::string& script_dir)
|
||||
{
|
||||
if (!utils::io::directory_exists(script_dir))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const auto scripts = utils::io::list_files(script_dir);
|
||||
|
||||
for (const auto& script : scripts)
|
||||
{
|
||||
std::string data{};
|
||||
if (std::filesystem::is_directory(script) && utils::io::read_file(script + "/__init__.lua", &data))
|
||||
{
|
||||
print_loading_script(script);
|
||||
load_script(script + "/__init__.lua", data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setup_functions()
|
||||
{
|
||||
const auto lua = get_globals();
|
||||
|
||||
lua["io"]["fileexists"] = utils::io::file_exists;
|
||||
lua["io"]["writefile"] = utils::io::write_file;
|
||||
lua["io"]["movefile"] = utils::io::move_file;
|
||||
lua["io"]["filesize"] = utils::io::file_size;
|
||||
lua["io"]["createdirectory"] = utils::io::create_directory;
|
||||
lua["io"]["directoryexists"] = utils::io::directory_exists;
|
||||
lua["io"]["directoryisempty"] = utils::io::directory_is_empty;
|
||||
lua["io"]["listfiles"] = utils::io::list_files;
|
||||
lua["io"]["removefile"] = utils::io::remove_file;
|
||||
lua["io"]["readfile"] = static_cast<std::string(*)(const std::string&)>(utils::io::read_file);
|
||||
|
||||
using game = table;
|
||||
auto game_type = game();
|
||||
lua["game"] = game_type;
|
||||
|
||||
game_type["getfps"] = [](const game&)
|
||||
{
|
||||
return fps::get_fps();
|
||||
};
|
||||
|
||||
if (::game::environment::is_mp())
|
||||
{
|
||||
game_type["getping"] = [](const game&)
|
||||
{
|
||||
if ((*::game::mp::client_state) == nullptr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (*::game::mp::client_state)->ping;
|
||||
};
|
||||
}
|
||||
|
||||
game_type["issingleplayer"] = [](const game&)
|
||||
{
|
||||
return ::game::environment::is_sp();
|
||||
};
|
||||
|
||||
game_type["ismultiplayer"] = [](const game&)
|
||||
{
|
||||
return ::game::environment::is_mp();
|
||||
};
|
||||
|
||||
game_type["addlocalizedstring"] = [](const game&, const std::string& string,
|
||||
const std::string& value)
|
||||
{
|
||||
localized_strings::override(string, value);
|
||||
};
|
||||
|
||||
game_type["sharedset"] = [](const game&, const std::string& key, const std::string& value)
|
||||
{
|
||||
scripting::shared_table.access([key, value](scripting::shared_table_t& table)
|
||||
{
|
||||
table[key] = value;
|
||||
});
|
||||
};
|
||||
|
||||
game_type["sharedget"] = [](const game&, const std::string& key)
|
||||
{
|
||||
std::string result;
|
||||
scripting::shared_table.access([key, &result](scripting::shared_table_t& table)
|
||||
{
|
||||
result = table[key];
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
game_type["sharedclear"] = [](const game&)
|
||||
{
|
||||
scripting::shared_table.access([](scripting::shared_table_t& table)
|
||||
{
|
||||
table.clear();
|
||||
});
|
||||
};
|
||||
|
||||
game_type["assetlist"] = [](const game&, const std::string& type_string)
|
||||
{
|
||||
auto table_ = table();
|
||||
auto index = 1;
|
||||
auto type_index = -1;
|
||||
|
||||
for (auto i = 0; i < ::game::XAssetType::ASSET_TYPE_COUNT; i++)
|
||||
{
|
||||
if (type_string == ::game::g_assetNames[i])
|
||||
{
|
||||
type_index = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (type_index == -1)
|
||||
{
|
||||
throw std::runtime_error("Asset type does not exist");
|
||||
}
|
||||
|
||||
const auto type = static_cast<::game::XAssetType>(type_index);
|
||||
fastfiles::enum_assets(type, [type, &table_, &index](const ::game::XAssetHeader header)
|
||||
{
|
||||
const auto asset = ::game::XAsset{type, header};
|
||||
const std::string asset_name = ::game::DB_GetXAssetName(&asset);
|
||||
table_[index++] = asset_name;
|
||||
}, true);
|
||||
|
||||
return table_;
|
||||
};
|
||||
|
||||
game_type["getweapondisplayname"] = [](const game&, const std::string& name)
|
||||
{
|
||||
const auto alternate = name.starts_with("alt_");
|
||||
const auto weapon = ::game::G_GetWeaponForName(name.data());
|
||||
|
||||
char buffer[0x400] = {0};
|
||||
::game::CG_GetWeaponDisplayName(weapon, alternate, buffer, 0x400);
|
||||
|
||||
return std::string(buffer);
|
||||
};
|
||||
|
||||
game_type["getloadedmod"] = [](const game&)
|
||||
{
|
||||
return mods::mod_path;
|
||||
};
|
||||
|
||||
if (::game::environment::is_sp())
|
||||
{
|
||||
using player = table;
|
||||
auto player_type = player();
|
||||
lua["player"] = player_type;
|
||||
|
||||
player_type["notify"] = [](const player&, const std::string& name, const variadic_args& va)
|
||||
{
|
||||
if (!::game::CL_IsCgameInitialized() || !::game::SV_Loaded())
|
||||
{
|
||||
throw std::runtime_error("Not in game");
|
||||
}
|
||||
|
||||
const auto to_string = get_globals()["tostring"];
|
||||
const auto arguments = get_return_values();
|
||||
std::vector<std::string> args{};
|
||||
for (const auto& value : va)
|
||||
{
|
||||
const auto value_str = to_string(value);
|
||||
|
||||
args.push_back(value_str[0].as<std::string>());
|
||||
}
|
||||
|
||||
::scheduler::once([name, args]()
|
||||
{
|
||||
try
|
||||
{
|
||||
std::vector<scripting::script_value> arguments{};
|
||||
|
||||
for (const auto& arg : args)
|
||||
{
|
||||
arguments.push_back(arg);
|
||||
}
|
||||
|
||||
const auto player = scripting::call("getentbynum", {0}).as<scripting::entity>();
|
||||
scripting::notify(player, name, arguments);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}, ::scheduler::pipeline::server);
|
||||
};
|
||||
}
|
||||
|
||||
auto updater_table = table();
|
||||
lua["updater"] = updater_table;
|
||||
|
||||
updater_table["relaunch"] = updater::relaunch;
|
||||
|
||||
updater_table["sethastriedupdate"] = updater::set_has_tried_update;
|
||||
updater_table["gethastriedupdate"] = updater::get_has_tried_update;
|
||||
updater_table["autoupdatesenabled"] = updater::auto_updates_enabled;
|
||||
|
||||
updater_table["startupdatecheck"] = updater::start_update_check;
|
||||
updater_table["isupdatecheckdone"] = updater::is_update_check_done;
|
||||
updater_table["getupdatecheckstatus"] = updater::get_update_check_status;
|
||||
updater_table["isupdateavailable"] = updater::is_update_available;
|
||||
|
||||
updater_table["startupdatedownload"] = updater::start_update_download;
|
||||
updater_table["isupdatedownloaddone"] = updater::is_update_download_done;
|
||||
updater_table["getupdatedownloadstatus"] = updater::get_update_download_status;
|
||||
updater_table["cancelupdate"] = updater::cancel_update;
|
||||
updater_table["isrestartrequired"] = updater::is_restart_required;
|
||||
|
||||
updater_table["getlasterror"] = updater::get_last_error;
|
||||
updater_table["getcurrentfile"] = updater::get_current_file;
|
||||
}
|
||||
|
||||
void start()
|
||||
{
|
||||
globals = {};
|
||||
|
||||
const auto lua = get_globals();
|
||||
lua["EnableGlobals"]();
|
||||
|
||||
setup_functions();
|
||||
|
||||
lua["print"] = function(reinterpret_cast<game::hks::lua_function>(SELECT_VALUE(0x93490_b, 0x209EB0_b)));
|
||||
lua["table"]["unpack"] = lua["unpack"];
|
||||
lua["luiglobals"] = lua;
|
||||
|
||||
load_script("lui_common", lui_common);
|
||||
load_script("lui_updater", lui_updater);
|
||||
load_script("lua_json", lua_json);
|
||||
|
||||
for (const auto& path : filesystem::get_search_paths())
|
||||
{
|
||||
load_scripts(path + "/ui_scripts/");
|
||||
if (game::environment::is_sp())
|
||||
{
|
||||
load_scripts(path + "/ui_scripts/sp/");
|
||||
}
|
||||
else
|
||||
{
|
||||
load_scripts(path + "/ui_scripts/mp/");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void try_start()
|
||||
{
|
||||
try
|
||||
{
|
||||
start();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
console::error("Failed to load LUI scripts: %s\n", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
void* hks_start_stub(char a1)
|
||||
{
|
||||
const auto _0 = gsl::finally(&try_start);
|
||||
return hks_start_hook.invoke<void*>(a1);
|
||||
}
|
||||
|
||||
void hks_shutdown_stub()
|
||||
{
|
||||
converted_functions.clear();
|
||||
globals = {};
|
||||
return hks_shutdown_hook.invoke<void>();
|
||||
}
|
||||
|
||||
void* hks_package_require_stub(game::hks::lua_State* state)
|
||||
{
|
||||
const auto script = get_current_script();
|
||||
const auto root = get_root_script(script);
|
||||
globals.in_require_script = root;
|
||||
return hks_package_require_hook.invoke<void*>(state);
|
||||
}
|
||||
|
||||
game::XAssetHeader db_find_xasset_header_stub(game::XAssetType type, const char* name, int allow_create_default)
|
||||
{
|
||||
if (!is_loaded_script(globals.in_require_script))
|
||||
{
|
||||
return game::DB_FindXAssetHeader(type, name, allow_create_default);
|
||||
}
|
||||
|
||||
const auto folder = globals.in_require_script.substr(0, globals.in_require_script.find_last_of("/\\"));
|
||||
const std::string name_ = name;
|
||||
const std::string target_script = folder + "/" + name_ + ".lua";
|
||||
|
||||
if (utils::io::file_exists(target_script))
|
||||
{
|
||||
globals.load_raw_script = true;
|
||||
globals.raw_script_name = target_script;
|
||||
return static_cast<game::XAssetHeader>(reinterpret_cast<game::LuaFile*>(1));
|
||||
}
|
||||
else if (name_.starts_with("ui/LUI/"))
|
||||
{
|
||||
return game::DB_FindXAssetHeader(type, name, allow_create_default);
|
||||
}
|
||||
|
||||
return static_cast<game::XAssetHeader>(nullptr);
|
||||
}
|
||||
|
||||
int hks_load_stub(game::hks::lua_State* state, void* compiler_options,
|
||||
void* reader, void* reader_data, const char* chunk_name)
|
||||
{
|
||||
if (globals.load_raw_script)
|
||||
{
|
||||
globals.load_raw_script = false;
|
||||
globals.loaded_scripts.push_back({globals.raw_script_name, globals.in_require_script});
|
||||
return load_buffer(globals.raw_script_name, utils::io::read_file(globals.raw_script_name));
|
||||
}
|
||||
else
|
||||
{
|
||||
return hks_load_hook.invoke<int>(state, compiler_options, reader,
|
||||
reader_data, chunk_name);
|
||||
}
|
||||
}
|
||||
|
||||
int main_handler(game::hks::lua_State* state)
|
||||
{
|
||||
const auto value = state->m_apistack.base[-1];
|
||||
if (value.t != game::hks::TCFUNCTION)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const auto closure = value.v.cClosure;
|
||||
if (converted_functions.find(closure) == converted_functions.end())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const auto& function = converted_functions[closure];
|
||||
|
||||
try
|
||||
{
|
||||
const auto args = get_return_values();
|
||||
const auto results = function(args);
|
||||
|
||||
for (const auto& result : results)
|
||||
{
|
||||
push_value(result);
|
||||
}
|
||||
|
||||
return static_cast<int>(results.size());
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
game::hks::hksi_luaL_error(state, e.what());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
game::hks::cclosure* convert_function(F f)
|
||||
{
|
||||
const auto state = *game::hks::lua_state;
|
||||
const auto closure = game::hks::cclosure_Create(state, main_handler, 0, 0, 0);
|
||||
converted_functions[closure] = wrap_function(f);
|
||||
return closure;
|
||||
}
|
||||
|
||||
bool lui_running()
|
||||
{
|
||||
return *game::hks::lua_state != nullptr;
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
|
||||
void post_unpack() override
|
||||
{
|
||||
if (game::environment::is_dedi())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
utils::hook::call(SELECT_VALUE(0xE7419_b, 0x25E809_b), db_find_xasset_header_stub);
|
||||
utils::hook::call(SELECT_VALUE(0xE72CB_b, 0x25E6BB_b), db_find_xasset_header_stub);
|
||||
|
||||
hks_load_hook.create(SELECT_VALUE(0xB46F0_b, 0x22C180_b), hks_load_stub);
|
||||
|
||||
hks_package_require_hook.create(SELECT_VALUE(0x90070_b, 0x214040_b), hks_package_require_stub);
|
||||
hks_start_hook.create(SELECT_VALUE(0x103C50_b, 0x27A790_b), hks_start_stub);
|
||||
hks_shutdown_hook.create(SELECT_VALUE(0xFB370_b, 0x2707C0_b), hks_shutdown_stub);
|
||||
|
||||
command::add("lui_restart", []()
|
||||
{
|
||||
utils::hook::invoke<void>(SELECT_VALUE(0x1052C0_b, 0x27BEC0_b));
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(ui_scripting::component)
|
49
src/client/component/ui_scripting.hpp
Normal file
49
src/client/component/ui_scripting.hpp
Normal file
@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
namespace ui_scripting
|
||||
{
|
||||
template <class... Args, std::size_t... I>
|
||||
auto wrap_function(const std::function<void(Args...)>& f, std::index_sequence<I...>)
|
||||
{
|
||||
return [f](const function_arguments& args)
|
||||
{
|
||||
f(args[I]...);
|
||||
return arguments{{}};
|
||||
};
|
||||
}
|
||||
|
||||
template <class... Args, std::size_t... I>
|
||||
auto wrap_function(const std::function<arguments(Args...)>& f, std::index_sequence<I...>)
|
||||
{
|
||||
return [f](const function_arguments& args)
|
||||
{
|
||||
return f(args[I]...);
|
||||
};
|
||||
}
|
||||
|
||||
template <typename R, class... Args, std::size_t... I>
|
||||
auto wrap_function(const std::function<R(Args...)>& f, std::index_sequence<I...>)
|
||||
{
|
||||
return [f](const function_arguments& args)
|
||||
{
|
||||
return arguments{f(args[I]...)};
|
||||
};
|
||||
}
|
||||
|
||||
template <typename R, class... Args>
|
||||
auto wrap_function(const std::function<R(Args...)>& f)
|
||||
{
|
||||
return wrap_function(f, std::index_sequence_for<Args...>{});
|
||||
}
|
||||
|
||||
template <class F>
|
||||
auto wrap_function(F f)
|
||||
{
|
||||
return wrap_function(std::function(f));
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
game::hks::cclosure* convert_function(F f);
|
||||
|
||||
bool lui_running();
|
||||
}
|
467
src/client/component/updater.cpp
Normal file
467
src/client/component/updater.cpp
Normal file
@ -0,0 +1,467 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "scheduler.hpp"
|
||||
#include "dvars.hpp"
|
||||
#include "updater.hpp"
|
||||
#include "game/ui_scripting/execution.hpp"
|
||||
|
||||
#include "version.h"
|
||||
|
||||
#include "game/game.hpp"
|
||||
#include "game/dvars.hpp"
|
||||
|
||||
#include <utils/nt.hpp>
|
||||
#include <utils/concurrency.hpp>
|
||||
#include <utils/http.hpp>
|
||||
#include <utils/cryptography.hpp>
|
||||
#include <utils/io.hpp>
|
||||
#include <utils/string.hpp>
|
||||
|
||||
#define MASTER "https://master.fed0001.xyz/h1-mod/"
|
||||
|
||||
#define FILES_PATH "files.json"
|
||||
#define FILES_PATH_DEV "files-dev.json"
|
||||
|
||||
#define DATA_PATH "data/"
|
||||
#define DATA_PATH_DEV "data-dev/"
|
||||
|
||||
#define ERR_UPDATE_CHECK_FAIL "Failed to check for updates"
|
||||
#define ERR_DOWNLOAD_FAIL "Failed to download file "
|
||||
#define ERR_WRITE_FAIL "Failed to write file "
|
||||
|
||||
#define BINARY_NAME "h1-mod.exe"
|
||||
|
||||
namespace updater
|
||||
{
|
||||
namespace
|
||||
{
|
||||
game::dvar_t* cl_auto_update;
|
||||
bool has_tried_update = false;
|
||||
|
||||
struct status
|
||||
{
|
||||
bool done;
|
||||
bool success;
|
||||
};
|
||||
|
||||
struct file_data
|
||||
{
|
||||
std::string name;
|
||||
std::string data;
|
||||
};
|
||||
|
||||
struct update_data_t
|
||||
{
|
||||
bool restart_required{};
|
||||
bool cancelled{};
|
||||
status check{};
|
||||
status download{};
|
||||
std::string error{};
|
||||
std::string current_file{};
|
||||
std::vector<std::string> required_files{};
|
||||
};
|
||||
|
||||
utils::concurrency::container<update_data_t> update_data;
|
||||
|
||||
std::string select(const std::string& main, const std::string& develop)
|
||||
{
|
||||
if (GIT_BRANCH == "develop"s)
|
||||
{
|
||||
return develop;
|
||||
}
|
||||
|
||||
return main;
|
||||
}
|
||||
|
||||
void notify(const std::string& name)
|
||||
{
|
||||
scheduler::once([=]()
|
||||
{
|
||||
ui_scripting::notify(name, {});
|
||||
}, scheduler::pipeline::lui);
|
||||
}
|
||||
|
||||
void set_update_check_status(bool done, bool success, const std::string& error = {})
|
||||
{
|
||||
update_data.access([done, success, error](update_data_t& data_)
|
||||
{
|
||||
data_.check.done = done;
|
||||
data_.check.success = success;
|
||||
data_.error = error;
|
||||
|
||||
notify("update_check_done");
|
||||
});
|
||||
}
|
||||
|
||||
void set_update_download_status(bool done, bool success, const std::string& error = {})
|
||||
{
|
||||
update_data.access([done, success, error](update_data_t& data_)
|
||||
{
|
||||
data_.download.done = done;
|
||||
data_.download.success = success;
|
||||
data_.error = error;
|
||||
notify("update_done");
|
||||
});
|
||||
}
|
||||
|
||||
bool check_file(const std::string& name, const std::string& sha)
|
||||
{
|
||||
std::string data;
|
||||
if (!utils::io::read_file(name, &data))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (utils::cryptography::sha1::compute(data, true) != sha)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string load_binary_name()
|
||||
{
|
||||
utils::nt::library self;
|
||||
return self.get_name();
|
||||
}
|
||||
|
||||
std::string get_binary_name()
|
||||
{
|
||||
static const auto name = load_binary_name();
|
||||
return name;
|
||||
}
|
||||
|
||||
std::string get_time_str()
|
||||
{
|
||||
return utils::string::va("%i", uint32_t(time(nullptr)));
|
||||
}
|
||||
|
||||
std::optional<std::string> download_file(const std::string& name)
|
||||
{
|
||||
return utils::http::get_data(MASTER + select(DATA_PATH, DATA_PATH_DEV) + name + "?" + get_time_str());
|
||||
}
|
||||
|
||||
bool is_update_cancelled()
|
||||
{
|
||||
return update_data.access<bool>([](update_data_t& data_)
|
||||
{
|
||||
return data_.cancelled;
|
||||
});
|
||||
}
|
||||
|
||||
bool write_file(const std::string& name, const std::string& data)
|
||||
{
|
||||
if (get_binary_name() == name &&
|
||||
utils::io::file_exists(name) &&
|
||||
!utils::io::move_file(name, name + ".old"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return utils::io::write_file(name, data);
|
||||
}
|
||||
|
||||
void delete_old_file()
|
||||
{
|
||||
utils::io::remove_file(get_binary_name() + ".old");
|
||||
}
|
||||
|
||||
void reset_data()
|
||||
{
|
||||
update_data.access([](update_data_t& data_)
|
||||
{
|
||||
data_ = {};
|
||||
});
|
||||
}
|
||||
|
||||
std::string get_mode_flag()
|
||||
{
|
||||
if (game::environment::is_mp())
|
||||
{
|
||||
return "-multiplayer";
|
||||
}
|
||||
|
||||
if (game::environment::is_sp())
|
||||
{
|
||||
return "-singleplayer";
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
// workaround
|
||||
void relaunch()
|
||||
{
|
||||
if (!utils::io::file_exists(BINARY_NAME))
|
||||
{
|
||||
utils::nt::terminate(0);
|
||||
return;
|
||||
}
|
||||
|
||||
STARTUPINFOA startup_info;
|
||||
PROCESS_INFORMATION process_info;
|
||||
|
||||
ZeroMemory(&startup_info, sizeof(startup_info));
|
||||
ZeroMemory(&process_info, sizeof(process_info));
|
||||
startup_info.cb = sizeof(startup_info);
|
||||
|
||||
char current_dir[MAX_PATH];
|
||||
GetCurrentDirectoryA(sizeof(current_dir), current_dir);
|
||||
|
||||
char buf[1024] = {0};
|
||||
const auto command_line = utils::string::va("%s %s", GetCommandLineA(), get_mode_flag().data());
|
||||
strcpy_s(buf, 1024, command_line);
|
||||
|
||||
CreateProcess(BINARY_NAME, buf, nullptr, nullptr, false, NULL, nullptr, current_dir,
|
||||
&startup_info, &process_info);
|
||||
|
||||
if (process_info.hThread && process_info.hThread != INVALID_HANDLE_VALUE) CloseHandle(process_info.hThread);
|
||||
if (process_info.hProcess && process_info.hProcess != INVALID_HANDLE_VALUE) CloseHandle(process_info.hProcess);
|
||||
|
||||
utils::nt::terminate(0);
|
||||
}
|
||||
|
||||
void set_has_tried_update(bool tried)
|
||||
{
|
||||
has_tried_update = tried;
|
||||
}
|
||||
|
||||
bool get_has_tried_update()
|
||||
{
|
||||
return has_tried_update;
|
||||
}
|
||||
|
||||
bool auto_updates_enabled()
|
||||
{
|
||||
return cl_auto_update->current.enabled;
|
||||
}
|
||||
|
||||
bool is_update_check_done()
|
||||
{
|
||||
return update_data.access<bool>([](update_data_t& data_)
|
||||
{
|
||||
return data_.check.done;
|
||||
});
|
||||
}
|
||||
|
||||
bool is_update_download_done()
|
||||
{
|
||||
return update_data.access<bool>([](update_data_t& data_)
|
||||
{
|
||||
return data_.download.done;
|
||||
});
|
||||
}
|
||||
|
||||
bool get_update_check_status()
|
||||
{
|
||||
return update_data.access<bool>([](update_data_t& data_)
|
||||
{
|
||||
return data_.check.success;
|
||||
});
|
||||
}
|
||||
|
||||
bool get_update_download_status()
|
||||
{
|
||||
return update_data.access<bool>([](update_data_t& data_)
|
||||
{
|
||||
return data_.download.success;
|
||||
});
|
||||
}
|
||||
|
||||
bool is_update_available()
|
||||
{
|
||||
return update_data.access<bool>([](update_data_t& data_)
|
||||
{
|
||||
return data_.required_files.size() > 0;
|
||||
});
|
||||
}
|
||||
|
||||
bool is_restart_required()
|
||||
{
|
||||
return update_data.access<bool>([](update_data_t& data_)
|
||||
{
|
||||
return data_.restart_required;
|
||||
});
|
||||
}
|
||||
|
||||
std::string get_last_error()
|
||||
{
|
||||
return update_data.access<std::string>([](update_data_t& data_)
|
||||
{
|
||||
return data_.error;
|
||||
});
|
||||
}
|
||||
|
||||
std::string get_current_file()
|
||||
{
|
||||
return update_data.access<std::string>([](update_data_t& data_)
|
||||
{
|
||||
return data_.current_file;
|
||||
});
|
||||
}
|
||||
|
||||
void cancel_update()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("[Updater] Cancelling update\n");
|
||||
#endif
|
||||
|
||||
return update_data.access([](update_data_t& data_)
|
||||
{
|
||||
data_.cancelled = true;
|
||||
});
|
||||
}
|
||||
|
||||
void start_update_check()
|
||||
{
|
||||
cancel_update();
|
||||
reset_data();
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("[Updater] starting update check\n");
|
||||
#endif
|
||||
|
||||
scheduler::once([]()
|
||||
{
|
||||
const auto files_data = utils::http::get_data(MASTER + select(FILES_PATH, FILES_PATH_DEV) + "?" + get_time_str());
|
||||
|
||||
if (is_update_cancelled())
|
||||
{
|
||||
reset_data();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!files_data.has_value())
|
||||
{
|
||||
set_update_check_status(true, false, ERR_UPDATE_CHECK_FAIL);
|
||||
return;
|
||||
}
|
||||
|
||||
rapidjson::Document j;
|
||||
j.Parse(files_data.value().data());
|
||||
|
||||
if (!j.IsArray())
|
||||
{
|
||||
set_update_check_status(true, false, ERR_UPDATE_CHECK_FAIL);
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<std::string> required_files;
|
||||
|
||||
const auto files = j.GetArray();
|
||||
for (const auto& file : files)
|
||||
{
|
||||
if (!file.IsArray() || file.Size() != 3 || !file[0].IsString() || !file[2].IsString())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto name = file[0].GetString();
|
||||
const auto sha = file[2].GetString();
|
||||
|
||||
if (!check_file(name, sha))
|
||||
{
|
||||
if (get_binary_name() == name)
|
||||
{
|
||||
update_data.access([](update_data_t& data_)
|
||||
{
|
||||
data_.restart_required = true;
|
||||
});
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("[Updater] need file %s\n", name);
|
||||
#endif
|
||||
|
||||
required_files.push_back(name);
|
||||
}
|
||||
}
|
||||
|
||||
update_data.access([&required_files](update_data_t& data_)
|
||||
{
|
||||
data_.check.done = true;
|
||||
data_.check.success = true;
|
||||
data_.required_files = required_files;
|
||||
});
|
||||
|
||||
notify("update_check_done");
|
||||
}, scheduler::pipeline::async);
|
||||
}
|
||||
|
||||
void start_update_download()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("[Updater] starting update download\n");
|
||||
#endif
|
||||
|
||||
if (!is_update_check_done() || !get_update_check_status() || is_update_cancelled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
scheduler::once([]()
|
||||
{
|
||||
const auto required_files = update_data.access<std::vector<std::string>>([](update_data_t& data_)
|
||||
{
|
||||
return data_.required_files;
|
||||
});
|
||||
|
||||
std::vector<file_data> downloads;
|
||||
|
||||
for (const auto& file : required_files)
|
||||
{
|
||||
update_data.access([file](update_data_t& data_)
|
||||
{
|
||||
data_.current_file = file;
|
||||
});
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("[Updater] downloading file %s\n", file.data());
|
||||
#endif
|
||||
|
||||
const auto data = download_file(file);
|
||||
|
||||
if (is_update_cancelled())
|
||||
{
|
||||
reset_data();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.has_value())
|
||||
{
|
||||
set_update_download_status(true, false, ERR_DOWNLOAD_FAIL + file);
|
||||
return;
|
||||
}
|
||||
|
||||
downloads.push_back({file, data.value()});
|
||||
}
|
||||
|
||||
for (const auto& download : downloads)
|
||||
{
|
||||
if (!write_file(download.name, download.data))
|
||||
{
|
||||
set_update_download_status(true, false, ERR_WRITE_FAIL + download.name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
set_update_download_status(true, true);
|
||||
}, scheduler::pipeline::async);
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
delete_old_file();
|
||||
cl_auto_update = dvars::register_bool("cg_auto_update", true, game::DVAR_FLAG_SAVED,
|
||||
"Automatically check for updates");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(updater::component)
|
26
src/client/component/updater.hpp
Normal file
26
src/client/component/updater.hpp
Normal file
@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
namespace updater
|
||||
{
|
||||
void relaunch();
|
||||
|
||||
void set_has_tried_update(bool tried);
|
||||
bool get_has_tried_update();
|
||||
bool auto_updates_enabled();
|
||||
|
||||
bool is_update_available();
|
||||
bool is_update_check_done();
|
||||
bool get_update_check_status();
|
||||
|
||||
bool is_update_download_done();
|
||||
bool get_update_download_status();
|
||||
|
||||
bool is_restart_required();
|
||||
|
||||
std::string get_last_error();
|
||||
std::string get_current_file();
|
||||
|
||||
void start_update_check();
|
||||
void start_update_download();
|
||||
void cancel_update();
|
||||
}
|
@ -35,7 +35,7 @@ namespace videos
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
playvid_hook.create(SELECT_VALUE(0x1404A9D00, 0x1405B0AF0), &playvid); // H1(1.4)
|
||||
playvid_hook.create(SELECT_VALUE(0x1404A9D00, 0x1405B0AF0), &playvid);
|
||||
|
||||
if (game::environment::is_mp())
|
||||
{
|
||||
@ -52,4 +52,4 @@ namespace videos
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(videos::component)
|
||||
//REGISTER_COMPONENT(videos::component)
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user