diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 00000000..fb3ee9ff
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+*.html linguist-detectable=false
\ No newline at end of file
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644
index 00000000..c8d876a7
--- /dev/null
+++ b/.github/workflows/build.yml
@@ -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 }}
diff --git a/.gitmodules b/.gitmodules
index 7230acd8..e92c76fd 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -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
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 00000000..f288702d
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ 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.
+
+
+ Copyright (C)
+
+ 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 .
+
+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:
+
+ Copyright (C)
+ 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
+.
+
+ 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
+.
diff --git a/README.md b/README.md
index b459ea06..46739214 100644
--- a/README.md
+++ b/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
-
+
-Proof of concept for an Modern Warfare Remastered client.
-[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.
## 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.
diff --git a/assets/github/banner.png b/assets/github/banner.png
new file mode 100644
index 00000000..ec35f0f6
Binary files /dev/null and b/assets/github/banner.png differ
diff --git a/data/.gitkeep b/data/.gitkeep
new file mode 100644
index 00000000..e69de29b
diff --git a/data/ui_scripts/discord/__init__.lua b/data/ui_scripts/discord/__init__.lua
new file mode 100644
index 00000000..bb6e5075
--- /dev/null
+++ b/data/ui_scripts/discord/__init__.lua
@@ -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)
diff --git a/data/ui_scripts/extra_gamemodes/__init__.lua b/data/ui_scripts/extra_gamemodes/__init__.lua
new file mode 100644
index 00000000..6bdadc82
--- /dev/null
+++ b/data/ui_scripts/extra_gamemodes/__init__.lua
@@ -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
+ }
+ }
+}
diff --git a/data/ui_scripts/hud_info/__init__.lua b/data/ui_scripts/hud_info/__init__.lua
new file mode 100644
index 00000000..1194a4f6
--- /dev/null
+++ b/data/ui_scripts/hud_info/__init__.lua
@@ -0,0 +1,6 @@
+if (game:issingleplayer()) then
+ return
+end
+
+require("settings")
+require("hud")
diff --git a/data/ui_scripts/hud_info/hud.lua b/data/ui_scripts/hud_info/hud.lua
new file mode 100644
index 00000000..fe2e4a5a
--- /dev/null
+++ b/data/ui_scripts/hud_info/hud.lua
@@ -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)
diff --git a/data/ui_scripts/hud_info/settings.lua b/data/ui_scripts/hud_info/settings.lua
new file mode 100644
index 00000000..ed654422
--- /dev/null
+++ b/data/ui_scripts/hud_info/settings.lua
@@ -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
diff --git a/data/ui_scripts/mods/__init__.lua b/data/ui_scripts/mods/__init__.lua
new file mode 100644
index 00000000..1ca1f8d2
--- /dev/null
+++ b/data/ui_scripts/mods/__init__.lua
@@ -0,0 +1,3 @@
+if (game:issingleplayer()) then
+ require("loading")
+end
diff --git a/data/ui_scripts/mods/loading.lua b/data/ui_scripts/mods/loading.lua
new file mode 100644
index 00000000..9600d8a5
--- /dev/null
+++ b/data/ui_scripts/mods/loading.lua
@@ -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)
diff --git a/data/ui_scripts/patches/__init__.lua b/data/ui_scripts/patches/__init__.lua
new file mode 100644
index 00000000..693a249b
--- /dev/null
+++ b/data/ui_scripts/patches/__init__.lua
@@ -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
diff --git a/data/ui_scripts/server_list/__init__.lua b/data/ui_scripts/server_list/__init__.lua
new file mode 100644
index 00000000..94df0df8
--- /dev/null
+++ b/data/ui_scripts/server_list/__init__.lua
@@ -0,0 +1,6 @@
+if (not LUI.mp_menus) then
+ return
+end
+
+require("lobby")
+require("serverlist")
diff --git a/data/ui_scripts/server_list/lobby.lua b/data/ui_scripts/server_list/lobby.lua
new file mode 100644
index 00000000..93e01a90
--- /dev/null
+++ b/data/ui_scripts/server_list/lobby.lua
@@ -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
diff --git a/data/ui_scripts/server_list/serverlist.lua b/data/ui_scripts/server_list/serverlist.lua
new file mode 100644
index 00000000..568670ed
--- /dev/null
+++ b/data/ui_scripts/server_list/serverlist.lua
@@ -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
diff --git a/data/ui_scripts/stats/__init__.lua b/data/ui_scripts/stats/__init__.lua
new file mode 100644
index 00000000..306c7ae0
--- /dev/null
+++ b/data/ui_scripts/stats/__init__.lua
@@ -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
diff --git a/deps/GSL b/deps/GSL
index 4377f6e6..d9fc52e2 160000
--- a/deps/GSL
+++ b/deps/GSL
@@ -1 +1 @@
-Subproject commit 4377f6e603c64a86c934f1546aa9db482f2e1a4e
+Subproject commit d9fc52e20e32fcc804502480a781120b210afd41
diff --git a/deps/asmjit b/deps/asmjit
index 6efd4d56..06d0bade 160000
--- a/deps/asmjit
+++ b/deps/asmjit
@@ -1 +1 @@
-Subproject commit 6efd4d563dee6832224295fa3bbf1647964246c4
+Subproject commit 06d0badec53710a4f572cf5642881ce570c5d274
diff --git a/deps/libtomcrypt b/deps/libtomcrypt
index 673f5ce2..06a81aeb 160000
--- a/deps/libtomcrypt
+++ b/deps/libtomcrypt
@@ -1 +1 @@
-Subproject commit 673f5ce29015a9bba3c96792920a10601b5b0718
+Subproject commit 06a81aeb227424182125363f7554fad5146d6d2a
diff --git a/deps/libtommath b/deps/libtommath
index 04e9d1e7..4b473685 160000
--- a/deps/libtommath
+++ b/deps/libtommath
@@ -1 +1 @@
-Subproject commit 04e9d1e7a0493910b2eb5e757d623870692ada04
+Subproject commit 4b47368501321c795d5b54d87a5bab35a21a7940
diff --git a/deps/lua b/deps/lua
index 8426d9b4..d61b0c60 160000
--- a/deps/lua
+++ b/deps/lua
@@ -1 +1 @@
-Subproject commit 8426d9b4d4df1da3c5b2d759e509ae1c50a86667
+Subproject commit d61b0c60287c38008d312ddd11724a15b1737f7b
diff --git a/deps/rapidjson b/deps/rapidjson
index e4bde977..232389d4 160000
--- a/deps/rapidjson
+++ b/deps/rapidjson
@@ -1 +1 @@
-Subproject commit e4bde977440d4a00f820b6586899e48a972d2493
+Subproject commit 232389d4f1012dddec4ef84861face2d2ba85709
diff --git a/deps/sol2 b/deps/sol2
index 50b62c93..2198d937 160000
--- a/deps/sol2
+++ b/deps/sol2
@@ -1 +1 @@
-Subproject commit 50b62c9346750b7c2c406c9e4c546f96b0bf021d
+Subproject commit 2198d9374d260f168d53b6248e49068a6307227d
diff --git a/deps/zlib b/deps/zlib
index 2014a993..ec3df002 160000
--- a/deps/zlib
+++ b/deps/zlib
@@ -1 +1 @@
-Subproject commit 2014a993addbc8f1b9785d97f55fd189792c2f78
+Subproject commit ec3df00224d4b396e2ac6586ab5d25f673caa4c2
diff --git a/premake5.lua b/premake5.lua
index 16043516..7bb114b7 100644
--- a/premake5.lua
+++ b/premake5.lua
@@ -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"
diff --git a/src/client/component/arxan.cpp b/src/client/component/arxan.cpp
new file mode 100644
index 00000000..3f77095f
--- /dev/null
+++ b/src/client/component/arxan.cpp
@@ -0,0 +1,145 @@
+#include
+#include "loader/component_loader.hpp"
+#include "scheduler.hpp"
+#include "game/game.hpp"
+
+#include
+
+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(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(info)->Reserved3 = PVOID(DWORD64(explorer_pid));
+ }
+ else if (info_class == 30) // ProcessDebugObjectHandle
+ {
+ *static_cast(info) = nullptr;
+
+ return 0xC0000353;
+ }
+ else if (info_class == 7) // ProcessDebugPort
+ {
+ *static_cast(info) = nullptr;
+ }
+ else if (info_class == 31)
+ {
+ *static_cast(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(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(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("NtClose"), nt_close_stub);
+ nt_query_information_process_hook.create(ntdll.get_proc("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)
\ No newline at end of file
diff --git a/src/client/component/auth.cpp b/src/client/component/auth.cpp
index 5ea40d9c..21ede068 100644
--- a/src/client/component/auth.cpp
+++ b/src/client/component/auth.cpp
@@ -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", []()
diff --git a/src/client/component/binding.cpp b/src/client/component/binding.cpp
index e40b7f42..5ef5bf66 100644
--- a/src/client/component/binding.cpp
+++ b/src/client/component/binding.cpp
@@ -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 get_custom_binding_for_key(int key)
+ {
+ key -= get_num_keys();
+
+ if (static_cast(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(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(local_client_num, key, down, time);
}
+
+ const char* cmd_get_binding_for_key_stub(unsigned int key)
+ {
+ if (key >= static_cast(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);
+ }
}
};
}
diff --git a/src/client/component/bots.cpp b/src/client/component/bots.cpp
index e9a25628..896f00a7 100644
--- a/src/client/component/bots.cpp
+++ b/src/client/component/bots.cpp
@@ -7,6 +7,7 @@
#include "party.hpp"
#include "game/game.hpp"
+#include "game/scripting/execution.hpp"
#include
#include
@@ -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(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)
\ No newline at end of file
+REGISTER_COMPONENT(bots::component)
diff --git a/src/client/component/branding.cpp b/src/client/component/branding.cpp
index 2f74693b..cbbcb0eb 100644
--- a/src/client/component/branding.cpp
+++ b/src/client/component/branding.cpp
@@ -27,14 +27,33 @@ namespace branding
const auto* const build_num = ui_get_formatted_build_number_hook.invoke();
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(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(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(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)
\ No newline at end of file
diff --git a/src/client/component/bullet.cpp b/src/client/component/bullet.cpp
new file mode 100644
index 00000000..72f6f4ff
--- /dev/null
+++ b/src/client/component/bullet.cpp
@@ -0,0 +1,46 @@
+#include
+#include "loader/component_loader.hpp"
+
+#include "game/game.hpp"
+#include "game/dvars.hpp"
+
+#include
+
+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(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::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)
diff --git a/src/client/component/chat.cpp b/src/client/component/chat.cpp
new file mode 100644
index 00000000..e78550b7
--- /dev/null
+++ b/src/client/component/chat.cpp
@@ -0,0 +1,52 @@
+#include
+#include "loader/component_loader.hpp"
+
+#include "localized_strings.hpp"
+#include "dvars.hpp"
+
+#include "game/game.hpp"
+#include "game/dvars.hpp"
+
+#include
+
+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(0x2E6F588_b));
+ utils::hook::inject(0x18A980_b, reinterpret_cast(0x2E6F588_b));
+ utils::hook::call(0x33EDEC_b, ui_get_font_handle_stub);
+
+ // set text style to 0 (non-blurry)
+ utils::hook::set(0x18A9F2_b, 0);
+ utils::hook::set(0x0F7151_b, 0);
+ utils::hook::set(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)
diff --git a/src/client/component/colors.cpp b/src/client/component/colors.cpp
index 66abb6b1..56bfa93c 100644
--- a/src/client/component/colors.cpp
+++ b/src/client/component/colors.cpp
@@ -96,8 +96,7 @@ namespace colors
const size_t unk, const size_t unk2)
{
// CL_GetClientName (CL_GetClientNameAndClantag?)
- const auto result = reinterpret_cast(0x14025BAA0)( // H1 (1.4)
- local_client_num, index, buf, size, unk, unk2);
+ const auto result = utils::hook::invoke(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(SELECT_VALUE(0x14F142FF8, 0x14FE70634)); // H1(1.4)
+ *color = *reinterpret_cast(SELECT_VALUE(0xF79D288_b, 0xEA749B4_b));
}
else if (index == '9')
{
- *color = *reinterpret_cast(SELECT_VALUE(0x14F142FFC, 0x14FE70638)); // H1(1.4)
+ *color = *reinterpret_cast(SELECT_VALUE(0xF79D28C_b, 0xEA749B8_b));
}
else if (index == ':')
{
@@ -122,7 +121,7 @@ namespace colors
}
else if (index == ';')
{
- *color = *reinterpret_cast(SELECT_VALUE(0x14F143004, 0x14FE70640)); // H1(1.4)
+ *color = *reinterpret_cast(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
diff --git a/src/client/component/command.cpp b/src/client/component/command.cpp
index 01f7b241..6b4febb2 100644
--- a/src/client/component/command.cpp
+++ b/src/client/component/command.cpp
@@ -1,22 +1,29 @@
#include
#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
#include
#include
-#include "utils/io.hpp"
-#include
+#include
namespace command
{
namespace
{
utils::hook::detour client_command_hook;
+ utils::hook::detour parse_commandline_hook;
std::unordered_map> handlers;
std::unordered_map> 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(client_num, a2);
+ client_command_hook.invoke(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(0x142623FB4); //H1(1.4)
- auto* com_console_lines = reinterpret_cast(0x142623FC0); //H1(1.4)
+ auto& com_num_console_lines = *reinterpret_cast(0x35634B8_b);
+ auto* com_console_lines = reinterpret_cast(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(0x1400D8210)(); // mwr: test
+ parse_commandline_hook.invoke();
}
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(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& 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(client_num), 0});
+ auto ps = game::SV_GetPlayerstateForClientNum(client_num);
+
+ if (arg == "ammo")
+ {
+ const auto weapon = player.call("getcurrentweapon").as();
+ player.call("givemaxammo", {weapon});
+ }
+ else if (arg == "allammo")
+ {
+ const auto weapons = player.call("getweaponslistall").as();
+ 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();
+ 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(client_num), 0});
+ const auto weapon = player.call("getcurrentweapon");
+ player.call("dropitem", {weapon});
+ }
+ catch (...)
+ {
+ }
+ }
+
+ void cmd_take_weapon(int client_num, const std::vector& 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(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(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(0x142623FB4); //H1(1.4)
- auto* com_console_lines = reinterpret_cast(0x142623FC0); //H1(1.4)
+ auto& com_num_console_lines = *reinterpret_cast(0x35634B8_b);
+ auto* com_console_lines = reinterpret_cast(0x35634C0_b);
for (int i = 0; i < com_num_console_lines; i++)
{
@@ -185,6 +409,16 @@ namespace command
return result;
}
+ std::vector params::get_all() const
+ {
+ std::vector 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 params_sv::get_all() const
+ {
+ std::vector 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());
@@ -230,8 +474,6 @@ namespace command
void add(const char* name, const std::function& 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& callback)
{
add(name, [callback](const params&)
- {
- callback();
- });
+ {
+ callback();
+ });
}
void add_sv(const char* name, std::function 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(1) = 0;
});
- /*add("consoleList", [](const params& params)
- {
- const std::string input = params.get(1);
-
- std::vector 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);
+ });
}
};
}
diff --git a/src/client/component/command.hpp b/src/client/component/command.hpp
index bd70d0c6..06228c9d 100644
--- a/src/client/component/command.hpp
+++ b/src/client/component/command.hpp
@@ -10,6 +10,7 @@ namespace command
int size() const;
const char* get(int index) const;
std::string join(int index) const;
+ std::vector 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 get_all() const;
const char* operator[](const int index) const
{
diff --git a/src/client/component/console.cpp b/src/client/component/console.cpp
index 174beaf8..2fd35434 100644
--- a/src/client/component/console.cpp
+++ b/src/client/component/console.cpp
@@ -1,14 +1,18 @@
#include
#include "console.hpp"
#include "loader/component_loader.hpp"
+
#include "game/game.hpp"
+
#include "command.hpp"
+#include "rcon.hpp"
+#include "version.hpp"
#include
-#include
-#include
#include
+#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;
- utils::concurrency::container 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 history{};
+ } con{};
+
+ void set_cursor_pos(int x)
+ {
+ CONSOLE_SCREEN_BUFFER_INFO info{};
+ GetConsoleScreenBufferInfo(OUTPUT_HANDLE, &info);
+ info.dwCursorPosition.X = static_cast(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
+ int invoke_printf(const char* fmt, Args&&... args)
+ {
+ return printf_hook.invoke(fmt, std::forward(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(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(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(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(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(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 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((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(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)
diff --git a/src/client/component/console.hpp b/src/client/component/console.hpp
index 302951a8..4101a3a6 100644
--- a/src/client/component/console.hpp
+++ b/src/client/component/console.hpp
@@ -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)...);
}
+ template
+ void debug(const char* fmt, Args&&... args)
+ {
+#ifdef DEBUG
+ print(con_type_debug, fmt, std::forward(args)...);
+#endif
+ }
+
template
void warn(const char* fmt, Args&&... args)
{
diff --git a/src/client/component/dedicated.cpp b/src/client/component/dedicated.cpp
index dd9f920f..46843e64 100644
--- a/src/client/component/dedicated.cpp
+++ b/src/client/component/dedicated.cpp
@@ -26,7 +26,7 @@ namespace dedicated
initialized = true;
// R_LoadGraphicsAssets
- reinterpret_cast(0x1405DF4B0)();
+ utils::hook::invoke(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(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(0x1400DC1D0, 0xC3); // don't save config file
- utils::hook::set(0x140274710, 0xC3); // disable self-registration
- utils::hook::set(0x140515890, 0xC3); // init sound system (1)
- utils::hook::set(0x1406574F0, 0xC3); // init sound system (2)
- utils::hook::set(0x140620D10, 0xC3); // render thread
- utils::hook::set(0x14025B850, 0xC3); // called from Com_Frame, seems to do renderer stuff
- utils::hook::set(0x1402507B0, 0xC3); // CL_CheckForResend, which tries to connect to the local server constantly
- utils::hook::set(0x1405D5178, 0x00); // r_loadForRenderer default to 0
- utils::hook::set(0x14050C2D0, 0xC3); // recommended settings check - TODO: Check hook
- utils::hook::set(0x140514C00, 0xC3); // some mixer-related function called on shutdown
- utils::hook::set(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(0x17F470_b, 0xC3); // don't save config file
+ utils::hook::set(0x351AA0_b, 0xC3); // disable self-registration
+ utils::hook::set(0x5BF4E0_b, 0xC3); // init sound system (1)
+ utils::hook::set(0x701820_b, 0xC3); // init sound system (2)
+ utils::hook::set(0x701850_b, 0xC3); // init sound system (3)
+ utils::hook::set(0x6C9B10_b, 0xC3); // render thread
+ utils::hook::set(0x343950_b, 0xC3); // called from Com_Frame, seems to do renderer stuff
+ utils::hook::set(0x12CCA0_b, 0xC3); // CL_CheckForResend, which tries to connect to the local server constantly
+ utils::hook::set(0x67ADCE_b, 0x00); // r_loadForRenderer default to 0
+ utils::hook::set(0x5B7AF0_b, 0xC3); // recommended settings check
+ utils::hook::set(0x5BE850_b, 0xC3); // some mixer-related function called on shutdown
+ utils::hook::set(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(0x140091840, 0xC3); // something to do with blendShapeVertsView
- utils::hook::nop(0x140659A0D, 8); // sound thing
+ utils::hook::set(0xAA290_b, 0xC3); // something to do with blendShapeVertsView
+ utils::hook::nop(0x70465D_b, 8); // sound thing
// (COULD NOT FIND IN H1)
- // utils::hook::set(0x1404D6960, 0xC3); // cpu detection stuff?
- utils::hook::set(0x1405E97F0, 0xC3); // gfx stuff during fastfile loading
- utils::hook::set(0x1405E9700, 0xC3); // ^
- utils::hook::set(0x1405E9790, 0xC3); // ^
- utils::hook::set(0x1402C1180, 0xC3); // ^
- utils::hook::set(0x1405E9750, 0xC3); // ^
- utils::hook::set(0x1405AD5B0, 0xC3); // directx stuff
- utils::hook::set(0x1405DB150, 0xC3); // ^
- utils::hook::set(0x140625220, 0xC3); // ^ - mutex
- utils::hook::set(0x1405DB650, 0xC3); // ^
+ utils::hook::set(0x1D8A20_b, 0xC3); // cpu detection stuff?
+ utils::hook::set(0x690F30_b, 0xC3); // gfx stuff during fastfile loading
+ utils::hook::set(0x690E00_b, 0xC3); // ^
+ utils::hook::set(0x690ED0_b, 0xC3); // ^
+ utils::hook::set(0x39B980_b, 0xC3); // ^
+ utils::hook::set(0x690E50_b, 0xC3); // ^
+ utils::hook::set(0x651BA0_b, 0xC3); // directx stuff
+ utils::hook::set(0x681950_b, 0xC3); // ^
+ utils::hook::set(0x6CE390_b, 0xC3); // ^ - mutex
+ utils::hook::set(0x681ED0_b, 0xC3); // ^
- utils::hook::set(0x14008B5F0, 0xC3); // rendering stuff
- utils::hook::set(0x1405DB8B0, 0xC3); // ^
- utils::hook::set(0x1405DB9C0, 0xC3); // ^
- utils::hook::set(0x1405DC050, 0xC3); // ^
- utils::hook::set(0x1405DCBA0, 0xC3); // ^
- utils::hook::set(0x1405DD240, 0xC3); // ^
+ utils::hook::set(0x0A3CD0_b, 0xC3); // rendering stuff
+ utils::hook::set(0x682150_b, 0xC3); // ^
+ utils::hook::set(0x682260_b, 0xC3); // ^
+ utils::hook::set(0x6829C0_b, 0xC3); // ^
+ utils::hook::set(0x6834A0_b, 0xC3); // ^
+ utils::hook::set(0x683B40_b, 0xC3); // ^
// shaders
- utils::hook::set(0x1400916A0, 0xC3); // ^
- utils::hook::set(0x140091610, 0xC3); // ^
- utils::hook::set(0x14061ACC0, 0xC3); // ^ - mutex
+ utils::hook::set(0x0AA090_b, 0xC3); // ^
+ utils::hook::set(0x0A9FE0_b, 0xC3); // ^
+ utils::hook::set(0x6C38D0_b, 0xC3); // ^ - mutex
- utils::hook::set(0x140516080, 0xC3); // idk
- utils::hook::set(0x1405AE5F0, 0xC3); // ^
+ utils::hook::set(0x5BFD10_b, 0xC3); // idk
+ utils::hook::set(0x652E10_b, 0xC3); // ^
- utils::hook::set(0x1405E0B30, 0xC3); // R_Shutdown
- utils::hook::set(0x1405AE400, 0xC3); // shutdown stuff
- utils::hook::set(0x1405E0C00, 0xC3); // ^
- utils::hook::set(0x1405DFE50, 0xC3); // ^
+ utils::hook::set(0x687D20_b, 0xC3); // R_Shutdown
+ utils::hook::set(0x652BA0_b, 0xC3); // shutdown stuff
+ utils::hook::set(0x687DF0_b, 0xC3); // ^
+ utils::hook::set(0x686DE0_b, 0xC3); // ^
// utils::hook::set(0x1404B67E0, 0xC3); // sound crashes (H1 - questionable, function looks way different)
- utils::hook::set(0x14048B660, 0xC3); // disable host migration
+ utils::hook::set(0x556250_b, 0xC3); // disable host migration
- utils::hook::set(0x14042B2E0, 0xC3); // render synchronization lock
- utils::hook::set(0x14042B210, 0xC3); // render synchronization unlock
+ utils::hook::set(0x4F7C10_b, 0xC3); // render synchronization lock
+ utils::hook::set(0x4F7B40_b, 0xC3); // render synchronization unlock
- utils::hook::set(0x140176D2D, 0xEB); // LUI: Unable to start the LUI system due to errors in main.lua
+ utils::hook::set(0x27AA9D_b, 0xEB); // LUI: Unable to start the LUI system due to errors in main.lua
+ utils::hook::set(0x27AAC5_b, 0xEB); // LUI: Unable to start the LUI system due to errors in depot.lua
+ utils::hook::set(0x27AADC_b, 0xEB); // ^
- utils::hook::nop(0x140506ECE, 5); // Disable sound pak file loading
- utils::hook::nop(0x140506ED6, 2); // ^
- utils::hook::set(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(0x3A0BA0_b, 0xC3); // Disable image pak file loading
// Reduce min required memory
- utils::hook::set(0x14050C717, 0x80000000);
+ utils::hook::set(0x5B7F37_b, 0x80000000);
- utils::hook::set(0x1402BF7F0, 0xC3); // some loop
- utils::hook::set(0x14007E150, 0xC3); // related to shader caching / techsets / fastfiles
+ utils::hook::set(0x399E10_b, 0xC3); // some loop
+ utils::hook::set(0x1D48B0_b, 0xC3); // related to shader caching / techsets / fastfilesc
+ utils::hook::set(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);
}
};
}
diff --git a/src/client/component/dedicated_info.cpp b/src/client/component/dedicated_info.cpp
index 55973193..fa5c9a34 100644
--- a/src/client/component/dedicated_info.cpp
+++ b/src/client/component/dedicated_info.cpp
@@ -1,5 +1,4 @@
#include
-#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(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);
}
};
diff --git a/src/client/component/demonware.cpp b/src/client/component/demonware.cpp
index 4cb3362c..1a3ea084 100644
--- a/src/client/component/demonware.cpp
+++ b/src/client/component/demonware.cpp
@@ -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(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(0x1405FCA00, 0xC3); // bdAuthSteam H1(1.4)
- utils::hook::set(0x140333A00, 0xC3); // dwNet H1(1.4)
+ utils::hook::set(0x68DDA0_b, 0xC3); // bdAuthSteam
+ utils::hook::set(0x366600_b, 0xC3); // dwNet
return;
}
- utils::hook::set(0x140715039, 0x0); // CURLOPT_SSL_VERIFYPEER H1MP64(1.4)
- utils::hook::set(0x140715025, 0xAF); // CURLOPT_SSL_VERIFYHOST H1MP64(1.4)
- utils::hook::set(0x14095433C, 0x0); // HTTPS -> HTTP [MWR OK][S1X: 0x14088D0E8]
+ utils::hook::set(0x7C0AD9_b, 0x0); // CURLOPT_SSL_VERIFYPEER
+ utils::hook::set(0x7C0AC5_b, 0xAF); // CURLOPT_SSL_VERIFYHOST
+ utils::hook::set(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(0x8D0298_b),
+ "http://prod.umbrella.demonware.net/v1.0/", sizeof("http://prod.umbrella.demonware.net/v1.0/"));
+ std::memcpy(reinterpret_cast(0x8D05A8_b),
+ "http://prod.uno.demonware.net/v1.0/", sizeof("http://prod.uno.demonware.net/v1.0/"));
+ std::memcpy(reinterpret_cast(0x9EDB08_b), "http://%s:%d/auth/", sizeof("http://%s:%d/auth/"));
- utils::hook::set(0x14047F290, 0xC3); // SV_SendMatchData H1MP64(1.4)
- utils::hook::set(0x140598990, 0xC3); // Live_CheckForFullDisconnect H1MP64(1.4)
+ // utils::hook::set(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(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
diff --git a/src/client/component/discord.cpp b/src/client/component/discord.cpp
index 5925a64a..e0693fa5 100644
--- a/src/client/component/discord.cpp
+++ b/src/client/component/discord.cpp
@@ -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
+#include
+#include
#include
+#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(server_net_info.ip[0]),
+ static_cast(server_net_info.ip[1]),
+ static_cast(server_net_info.ip[2]),
+ static_cast(server_net_info.ip[3]),
+ static_cast(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(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(
@@ -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)
\ No newline at end of file
+REGISTER_COMPONENT(discord::component)
diff --git a/src/client/component/discord.hpp b/src/client/component/discord.hpp
new file mode 100644
index 00000000..5399f952
--- /dev/null
+++ b/src/client/component/discord.hpp
@@ -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);
+}
diff --git a/src/client/component/dvar_cheats.cpp b/src/client/component/dvar_cheats.cpp
new file mode 100644
index 00000000..66c49e6c
--- /dev/null
+++ b/src/client/component/dvar_cheats.cpp
@@ -0,0 +1,147 @@
+#include
+#include "loader/component_loader.hpp"
+
+#include "console.hpp"
+#include "scheduler.hpp"
+
+#include "game/game.hpp"
+#include "game/dvars.hpp"
+
+#include
+#include
+
+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)
diff --git a/src/client/component/dvars.cpp b/src/client/component/dvars.cpp
index d9c77fdf..3b285f20 100644
--- a/src/client/component/dvars.cpp
+++ b/src/client/component/dvars.cpp
@@ -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 register_string_overrides;
static std::unordered_map register_vector2_overrides;
static std::unordered_map register_vector3_overrides;
+ static std::unordered_map register_enum_overrides;
static std::unordered_map set_bool_overrides;
static std::unordered_map 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(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(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(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