├── .github
└── workflows
│ └── CI.yml
├── .gitignore
├── .gitmodules
├── LICENSE
├── README.md
├── licenses
├── BXT_LICENSE
├── FUNCHOOK_LICENSE
├── HLSDK_LICENSE
└── SPTLIB_LICENSE
├── runsven.sh
├── src
├── .clang-format
├── CMakeLists.txt
├── CTimer.h
├── SvenBXT.cpp
├── SvenBXT.h
├── Utils.cpp
├── Utils.h
├── cl_dll
│ ├── cdll_int.cpp
│ ├── cdll_int.h
│ ├── hud.cpp
│ ├── hud.h
│ ├── hud_crosshair.cpp
│ ├── hud_crosshair.h
│ ├── hud_jumpspeed.cpp
│ ├── hud_jumpspeed.h
│ ├── hud_origin.cpp
│ ├── hud_origin.h
│ ├── hud_speedometer.cpp
│ ├── hud_speedometer.h
│ ├── hud_timer.cpp
│ ├── hud_timer.h
│ ├── hud_viewangles.cpp
│ ├── hud_viewangles.h
│ ├── opengl_utils.cpp
│ ├── opengl_utils.hpp
│ ├── parsemsg.cpp
│ ├── parsemsg.h
│ ├── tri.cpp
│ ├── tri.h
│ ├── view.cpp
│ └── view.h
├── cmake
│ ├── InputFilesList.cmake
│ ├── Linux32CrossCompile.cmake
│ ├── PlatformInfo.cmake
│ └── ToolchainLinuxGCC.cmake
├── dlls
│ ├── enginecallback.h
│ ├── server.cpp
│ └── server.h
├── engine
│ ├── gl_screen.cpp
│ ├── gl_screen.h
│ ├── server.h
│ └── sound.h
├── engine_patterns.hpp
├── external
│ ├── CMakeLists.txt
│ └── SPTLib
│ │ ├── MemUtils.h
│ │ ├── Utils.hpp
│ │ ├── patterns.hpp
│ │ └── patterns_macros.hpp
├── hlsdk_mini.hpp
├── iface.cpp
├── iface.hpp
├── metahook_emulation.cpp
├── metahook_emulation.hpp
├── svenmod_emulation.cpp
└── svenmod_emulation.hpp
└── svenbxt.cfg
/.github/workflows/CI.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on:
4 | push:
5 | paths-ignore:
6 | - .gitignore
7 | - README.md
8 | - svenbxt.cfg
9 | pull_request:
10 | paths-ignore:
11 | - .gitignore
12 | - README.md
13 | - svenbxt.cfg
14 | workflow_dispatch:
15 | schedule:
16 | - cron: '0 0 1 * *' # Monthly
17 |
18 | jobs:
19 | build:
20 | runs-on: ${{ matrix.os }}
21 |
22 | strategy:
23 | fail-fast: true
24 | matrix:
25 | os: [ubuntu-latest, windows-latest]
26 | build_type: [Release]
27 | c_compiler: [gcc, cl]
28 | include:
29 | - os: windows-latest
30 | c_compiler: cl
31 | cpp_compiler: cl
32 | artifact: "svenbxt_windows-cl"
33 | bin-path: "src/build/Release/SvenBXT.dll"
34 | toolchain-file: ""
35 | cmake-generator: "Visual Studio 17 2022"
36 | build-target: "-A Win32" # HACK
37 | - os: ubuntu-latest
38 | c_compiler: gcc
39 | cpp_compiler: g++
40 | artifact: "svenbxt_ubuntu-gcc"
41 | bin-path: "src/build/libSvenBXT.so"
42 | toolchain-file: "cmake/ToolchainLinuxGCC.cmake"
43 | cmake-generator: "Unix Makefiles"
44 | build-target: ""
45 | exclude:
46 | - os: windows-latest
47 | c_compiler: gcc
48 | - os: ubuntu-latest
49 | c_compiler: cl
50 |
51 | steps:
52 | - name: Checkout repository
53 | uses: actions/checkout@v4
54 |
55 | - name: Checkout submodules
56 | shell: bash
57 | run: git submodule update --init --recursive
58 |
59 | - name: Set reusable strings
60 | id: strings
61 | shell: bash
62 | run: |
63 | echo "build-output-dir=${{ github.workspace }}/src/build" >> "$GITHUB_OUTPUT"
64 | echo "src-dir=${{ github.workspace }}/src" >> "$GITHUB_OUTPUT"
65 |
66 | - name: Add msbuild to PATH
67 | if: runner.os == 'Windows'
68 | uses: microsoft/setup-msbuild@v2
69 |
70 | - name: Install Ubuntu packages
71 | if: runner.os == 'Linux'
72 | run: |
73 | sudo dpkg --add-architecture i386
74 | sudo apt update || true
75 | sudo apt install -y build-essential libc6:i386 g++-multilib mesa-common-dev libgl-dev:i386 libgl1-mesa-dev
76 |
77 | - name: Configure CMake
78 | run: >
79 | cmake -G "${{ matrix.cmake-generator }}"
80 | ${{ matrix.build-target }}
81 | -B ${{ steps.strings.outputs.build-output-dir }}
82 | -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
83 | -DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
84 | -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
85 | -DCMAKE_TOOLCHAIN_FILE=${{ matrix.toolchain-file }}
86 | -DFUNCHOOK_BUILD_TESTS=OFF
87 | -S ${{ steps.strings.outputs.src-dir }}
88 |
89 | - name: Build Linux version
90 | if: runner.os == 'Linux'
91 | run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
92 |
93 | - name: Build Windows version
94 | if: runner.os == 'Windows'
95 | run: msbuild /m /p:OutputPath=${{ steps.strings.outputs.build-output-dir }} /p:Configuration=${{ matrix.build_type }} ${{ steps.strings.outputs.build-output-dir }}/SvenBXT.sln
96 |
97 | - name: Prepare artifacts
98 | run: mkdir -p bin && mv ${{ matrix.bin-path }} bin/
99 |
100 | - name: Upload artifacts
101 | uses: actions/upload-artifact@v4
102 | with:
103 | path: ./bin
104 | name: ${{ matrix.artifact }}
105 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | .vs/
3 | _build/
4 | _build_WIN32/
5 | build/
6 | src/.idea/
7 | src/.vs/
8 | src/_build/
9 | src/_build_WIN32/
10 | src/build/
11 |
12 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "src/external/funchook"]
2 | path = src/external/funchook
3 | url = https://github.com/kubo/funchook.git
4 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 ScriptedSnark
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SvenBXT
2 |
3 | SvenBXT is a complete remake of [BunnymodXT](https://github.com/YaLTeR/BunnymodXT), designed specifically for Sven Co-op 5.25.
4 |
You can legally use this tool for [Sven Co-op runs](https://www.speedrun.com/sven_coop).
5 |
6 |
Download latest release: [CLICK](https://github.com/ScriptedSnark/SvenBXT/releases/latest)
7 | Download nightly build: [CLICK](https://nightly.link/ScriptedSnark/SvenBXT/workflows/CI/new)
8 |
9 | ## Installation / Usage
10 |
11 | ### Windows
12 | SvenBXT can be installed as a [MetaHook](https://github.com/hzqst/MetaHookSv)/[SvenMod](https://github.com/sw1ft747/svenmod) plugin.
13 | Also can be injected by any injector (even deprecated one from `rebased` branch).
14 |
15 | #### MetaHook
16 | 1. Move `SvenBXT.dll` to `svencoop/metahook/plugins`
17 | 2. Write `SvenBXT.dll` in `svencoop/metahook/configs/plugins.lst`
18 |
19 | #### SvenMod
20 | 1. Move `SvenBXT.dll` to `svenmod/plugins`
21 | 2. Open `svenmod/plugins.txt` and write `"SvenBXT" "1"` inside plugins tab
22 |
23 | ```
24 | // SvenMod
25 | // List of plugins to load
26 |
27 | "Plugins"
28 | {
29 | "SvenBXT" "1"
30 |
31 | "Settings"
32 | {
33 | "LoadDelay" "0.5" // in seconds
34 | }
35 | }
36 | ```
37 |
38 | You can find additional info about that [here](https://github.com/sw1ft747/svenmod#adding-plugins).
39 |
40 | ### Linux
41 | You can use the `runsven.sh` script. Correct the paths at the top of the script if necessary.
42 |
43 | ## Credits
44 | **Thanks to [YaLTeR](https://github.com/YaLTeR) for [BunnymodXT](https://github.com/YaLTeR/BunnymodXT)!**
45 |
46 | Thanks to [autisoid](https://github.com/autisoid) for SvenMod/MetaHook emulators.
--------------------------------------------------------------------------------
/licenses/BXT_LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014-2020 Ivan Molodetskikh
4 | Copyright (c) 2015-2018 Chong Jiang Wei
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 |
--------------------------------------------------------------------------------
/licenses/FUNCHOOK_LICENSE:
--------------------------------------------------------------------------------
1 | Funchook is distributed under the terms of the GNU General Public
2 | License version 2 or later with the following clarification and
3 | special exception.
4 |
5 | Linking this library statically or dynamically with other modules is
6 | making a combined work based on this library. Thus, the terms and
7 | conditions of the GNU General Public License cover the whole
8 | combination.
9 |
10 | As a special exception, the copyright holders of this library give you
11 | permission to link this library with independent modules to produce an
12 | executable, regardless of the license terms of these independent
13 | modules, and to copy and distribute the resulting executable under
14 | terms of your choice, provided that you also meet, for each linked
15 | independent module, the terms and conditions of the license of that
16 | module. An independent module is a module which is not derived from or
17 | based on this library. If you modify this library, you must extend this
18 | exception to your version of the library.
19 |
20 | =====================================================================
21 |
22 | GNU GENERAL PUBLIC LICENSE
23 | Version 2, June 1991
24 |
25 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
26 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 | Everyone is permitted to copy and distribute verbatim copies
28 | of this license document, but changing it is not allowed.
29 |
30 | Preamble
31 |
32 | The licenses for most software are designed to take away your
33 | freedom to share and change it. By contrast, the GNU General Public
34 | License is intended to guarantee your freedom to share and change free
35 | software--to make sure the software is free for all its users. This
36 | General Public License applies to most of the Free Software
37 | Foundation's software and to any other program whose authors commit to
38 | using it. (Some other Free Software Foundation software is covered by
39 | the GNU Lesser General Public License instead.) You can apply it to
40 | your programs, too.
41 |
42 | When we speak of free software, we are referring to freedom, not
43 | price. Our General Public Licenses are designed to make sure that you
44 | have the freedom to distribute copies of free software (and charge for
45 | this service if you wish), that you receive source code or can get it
46 | if you want it, that you can change the software or use pieces of it
47 | in new free programs; and that you know you can do these things.
48 |
49 | To protect your rights, we need to make restrictions that forbid
50 | anyone to deny you these rights or to ask you to surrender the rights.
51 | These restrictions translate to certain responsibilities for you if you
52 | distribute copies of the software, or if you modify it.
53 |
54 | For example, if you distribute copies of such a program, whether
55 | gratis or for a fee, you must give the recipients all the rights that
56 | you have. You must make sure that they, too, receive or can get the
57 | source code. And you must show them these terms so they know their
58 | rights.
59 |
60 | We protect your rights with two steps: (1) copyright the software, and
61 | (2) offer you this license which gives you legal permission to copy,
62 | distribute and/or modify the software.
63 |
64 | Also, for each author's protection and ours, we want to make certain
65 | that everyone understands that there is no warranty for this free
66 | software. If the software is modified by someone else and passed on, we
67 | want its recipients to know that what they have is not the original, so
68 | that any problems introduced by others will not reflect on the original
69 | authors' reputations.
70 |
71 | Finally, any free program is threatened constantly by software
72 | patents. We wish to avoid the danger that redistributors of a free
73 | program will individually obtain patent licenses, in effect making the
74 | program proprietary. To prevent this, we have made it clear that any
75 | patent must be licensed for everyone's free use or not licensed at all.
76 |
77 | The precise terms and conditions for copying, distribution and
78 | modification follow.
79 |
80 | GNU GENERAL PUBLIC LICENSE
81 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
82 |
83 | 0. This License applies to any program or other work which contains
84 | a notice placed by the copyright holder saying it may be distributed
85 | under the terms of this General Public License. The "Program", below,
86 | refers to any such program or work, and a "work based on the Program"
87 | means either the Program or any derivative work under copyright law:
88 | that is to say, a work containing the Program or a portion of it,
89 | either verbatim or with modifications and/or translated into another
90 | language. (Hereinafter, translation is included without limitation in
91 | the term "modification".) Each licensee is addressed as "you".
92 |
93 | Activities other than copying, distribution and modification are not
94 | covered by this License; they are outside its scope. The act of
95 | running the Program is not restricted, and the output from the Program
96 | is covered only if its contents constitute a work based on the
97 | Program (independent of having been made by running the Program).
98 | Whether that is true depends on what the Program does.
99 |
100 | 1. You may copy and distribute verbatim copies of the Program's
101 | source code as you receive it, in any medium, provided that you
102 | conspicuously and appropriately publish on each copy an appropriate
103 | copyright notice and disclaimer of warranty; keep intact all the
104 | notices that refer to this License and to the absence of any warranty;
105 | and give any other recipients of the Program a copy of this License
106 | along with the Program.
107 |
108 | You may charge a fee for the physical act of transferring a copy, and
109 | you may at your option offer warranty protection in exchange for a fee.
110 |
111 | 2. You may modify your copy or copies of the Program or any portion
112 | of it, thus forming a work based on the Program, and copy and
113 | distribute such modifications or work under the terms of Section 1
114 | above, provided that you also meet all of these conditions:
115 |
116 | a) You must cause the modified files to carry prominent notices
117 | stating that you changed the files and the date of any change.
118 |
119 | b) You must cause any work that you distribute or publish, that in
120 | whole or in part contains or is derived from the Program or any
121 | part thereof, to be licensed as a whole at no charge to all third
122 | parties under the terms of this License.
123 |
124 | c) If the modified program normally reads commands interactively
125 | when run, you must cause it, when started running for such
126 | interactive use in the most ordinary way, to print or display an
127 | announcement including an appropriate copyright notice and a
128 | notice that there is no warranty (or else, saying that you provide
129 | a warranty) and that users may redistribute the program under
130 | these conditions, and telling the user how to view a copy of this
131 | License. (Exception: if the Program itself is interactive but
132 | does not normally print such an announcement, your work based on
133 | the Program is not required to print an announcement.)
134 |
135 | These requirements apply to the modified work as a whole. If
136 | identifiable sections of that work are not derived from the Program,
137 | and can be reasonably considered independent and separate works in
138 | themselves, then this License, and its terms, do not apply to those
139 | sections when you distribute them as separate works. But when you
140 | distribute the same sections as part of a whole which is a work based
141 | on the Program, the distribution of the whole must be on the terms of
142 | this License, whose permissions for other licensees extend to the
143 | entire whole, and thus to each and every part regardless of who wrote it.
144 |
145 | Thus, it is not the intent of this section to claim rights or contest
146 | your rights to work written entirely by you; rather, the intent is to
147 | exercise the right to control the distribution of derivative or
148 | collective works based on the Program.
149 |
150 | In addition, mere aggregation of another work not based on the Program
151 | with the Program (or with a work based on the Program) on a volume of
152 | a storage or distribution medium does not bring the other work under
153 | the scope of this License.
154 |
155 | 3. You may copy and distribute the Program (or a work based on it,
156 | under Section 2) in object code or executable form under the terms of
157 | Sections 1 and 2 above provided that you also do one of the following:
158 |
159 | a) Accompany it with the complete corresponding machine-readable
160 | source code, which must be distributed under the terms of Sections
161 | 1 and 2 above on a medium customarily used for software interchange; or,
162 |
163 | b) Accompany it with a written offer, valid for at least three
164 | years, to give any third party, for a charge no more than your
165 | cost of physically performing source distribution, a complete
166 | machine-readable copy of the corresponding source code, to be
167 | distributed under the terms of Sections 1 and 2 above on a medium
168 | customarily used for software interchange; or,
169 |
170 | c) Accompany it with the information you received as to the offer
171 | to distribute corresponding source code. (This alternative is
172 | allowed only for noncommercial distribution and only if you
173 | received the program in object code or executable form with such
174 | an offer, in accord with Subsection b above.)
175 |
176 | The source code for a work means the preferred form of the work for
177 | making modifications to it. For an executable work, complete source
178 | code means all the source code for all modules it contains, plus any
179 | associated interface definition files, plus the scripts used to
180 | control compilation and installation of the executable. However, as a
181 | special exception, the source code distributed need not include
182 | anything that is normally distributed (in either source or binary
183 | form) with the major components (compiler, kernel, and so on) of the
184 | operating system on which the executable runs, unless that component
185 | itself accompanies the executable.
186 |
187 | If distribution of executable or object code is made by offering
188 | access to copy from a designated place, then offering equivalent
189 | access to copy the source code from the same place counts as
190 | distribution of the source code, even though third parties are not
191 | compelled to copy the source along with the object code.
192 |
193 | 4. You may not copy, modify, sublicense, or distribute the Program
194 | except as expressly provided under this License. Any attempt
195 | otherwise to copy, modify, sublicense or distribute the Program is
196 | void, and will automatically terminate your rights under this License.
197 | However, parties who have received copies, or rights, from you under
198 | this License will not have their licenses terminated so long as such
199 | parties remain in full compliance.
200 |
201 | 5. You are not required to accept this License, since you have not
202 | signed it. However, nothing else grants you permission to modify or
203 | distribute the Program or its derivative works. These actions are
204 | prohibited by law if you do not accept this License. Therefore, by
205 | modifying or distributing the Program (or any work based on the
206 | Program), you indicate your acceptance of this License to do so, and
207 | all its terms and conditions for copying, distributing or modifying
208 | the Program or works based on it.
209 |
210 | 6. Each time you redistribute the Program (or any work based on the
211 | Program), the recipient automatically receives a license from the
212 | original licensor to copy, distribute or modify the Program subject to
213 | these terms and conditions. You may not impose any further
214 | restrictions on the recipients' exercise of the rights granted herein.
215 | You are not responsible for enforcing compliance by third parties to
216 | this License.
217 |
218 | 7. If, as a consequence of a court judgment or allegation of patent
219 | infringement or for any other reason (not limited to patent issues),
220 | conditions are imposed on you (whether by court order, agreement or
221 | otherwise) that contradict the conditions of this License, they do not
222 | excuse you from the conditions of this License. If you cannot
223 | distribute so as to satisfy simultaneously your obligations under this
224 | License and any other pertinent obligations, then as a consequence you
225 | may not distribute the Program at all. For example, if a patent
226 | license would not permit royalty-free redistribution of the Program by
227 | all those who receive copies directly or indirectly through you, then
228 | the only way you could satisfy both it and this License would be to
229 | refrain entirely from distribution of the Program.
230 |
231 | If any portion of this section is held invalid or unenforceable under
232 | any particular circumstance, the balance of the section is intended to
233 | apply and the section as a whole is intended to apply in other
234 | circumstances.
235 |
236 | It is not the purpose of this section to induce you to infringe any
237 | patents or other property right claims or to contest validity of any
238 | such claims; this section has the sole purpose of protecting the
239 | integrity of the free software distribution system, which is
240 | implemented by public license practices. Many people have made
241 | generous contributions to the wide range of software distributed
242 | through that system in reliance on consistent application of that
243 | system; it is up to the author/donor to decide if he or she is willing
244 | to distribute software through any other system and a licensee cannot
245 | impose that choice.
246 |
247 | This section is intended to make thoroughly clear what is believed to
248 | be a consequence of the rest of this License.
249 |
250 | 8. If the distribution and/or use of the Program is restricted in
251 | certain countries either by patents or by copyrighted interfaces, the
252 | original copyright holder who places the Program under this License
253 | may add an explicit geographical distribution limitation excluding
254 | those countries, so that distribution is permitted only in or among
255 | countries not thus excluded. In such case, this License incorporates
256 | the limitation as if written in the body of this License.
257 |
258 | 9. The Free Software Foundation may publish revised and/or new versions
259 | of the General Public License from time to time. Such new versions will
260 | be similar in spirit to the present version, but may differ in detail to
261 | address new problems or concerns.
262 |
263 | Each version is given a distinguishing version number. If the Program
264 | specifies a version number of this License which applies to it and "any
265 | later version", you have the option of following the terms and conditions
266 | either of that version or of any later version published by the Free
267 | Software Foundation. If the Program does not specify a version number of
268 | this License, you may choose any version ever published by the Free Software
269 | Foundation.
270 |
271 | 10. If you wish to incorporate parts of the Program into other free
272 | programs whose distribution conditions are different, write to the author
273 | to ask for permission. For software which is copyrighted by the Free
274 | Software Foundation, write to the Free Software Foundation; we sometimes
275 | make exceptions for this. Our decision will be guided by the two goals
276 | of preserving the free status of all derivatives of our free software and
277 | of promoting the sharing and reuse of software generally.
278 |
279 | NO WARRANTY
280 |
281 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
282 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
283 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
284 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
285 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
286 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
287 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
288 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
289 | REPAIR OR CORRECTION.
290 |
291 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
292 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
293 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
294 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
295 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
296 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
297 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
298 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
299 | POSSIBILITY OF SUCH DAMAGES.
300 |
301 | END OF TERMS AND CONDITIONS
302 |
303 | How to Apply These Terms to Your New Programs
304 |
305 | If you develop a new program, and you want it to be of the greatest
306 | possible use to the public, the best way to achieve this is to make it
307 | free software which everyone can redistribute and change under these terms.
308 |
309 | To do so, attach the following notices to the program. It is safest
310 | to attach them to the start of each source file to most effectively
311 | convey the exclusion of warranty; and each file should have at least
312 | the "copyright" line and a pointer to where the full notice is found.
313 |
314 |
315 | Copyright (C)
316 |
317 | This program is free software; you can redistribute it and/or modify
318 | it under the terms of the GNU General Public License as published by
319 | the Free Software Foundation; either version 2 of the License, or
320 | (at your option) any later version.
321 |
322 | This program is distributed in the hope that it will be useful,
323 | but WITHOUT ANY WARRANTY; without even the implied warranty of
324 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
325 | GNU General Public License for more details.
326 |
327 | You should have received a copy of the GNU General Public License along
328 | with this program; if not, write to the Free Software Foundation, Inc.,
329 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
330 |
331 | Also add information on how to contact you by electronic and paper mail.
332 |
333 | If the program is interactive, make it output a short notice like this
334 | when it starts in an interactive mode:
335 |
336 | Gnomovision version 69, Copyright (C) year name of author
337 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
338 | This is free software, and you are welcome to redistribute it
339 | under certain conditions; type `show c' for details.
340 |
341 | The hypothetical commands `show w' and `show c' should show the appropriate
342 | parts of the General Public License. Of course, the commands you use may
343 | be called something other than `show w' and `show c'; they could even be
344 | mouse-clicks or menu items--whatever suits your program.
345 |
346 | You should also get your employer (if you work as a programmer) or your
347 | school, if any, to sign a "copyright disclaimer" for the program, if
348 | necessary. Here is a sample; alter the names:
349 |
350 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
351 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
352 |
353 | , 1 April 1989
354 | Ty Coon, President of Vice
355 |
356 | This General Public License does not permit incorporating your program into
357 | proprietary programs. If your program is a subroutine library, you may
358 | consider it more useful to permit linking proprietary applications with the
359 | library. If this is what you want to do, use the GNU Lesser General
360 | Public License instead of this License.
361 |
--------------------------------------------------------------------------------
/licenses/HLSDK_LICENSE:
--------------------------------------------------------------------------------
1 | Half Life 1 SDK LICENSE
2 | ======================
3 |
4 | Half Life 1 SDK Copyright(c) Valve Corp.
5 |
6 | THIS DOCUMENT DESCRIBES A CONTRACT BETWEEN YOU AND VALVE CORPORATION ("Valve").
7 | PLEASE READ IT BEFORE DOWNLOADING OR USING THE HALF LIFE 1 SDK ("SDK"). BY
8 | DOWNLOADING AND/OR USING THE HALF LIFE 1 SDK YOU ACCEPT THIS LICENSE. IF YOU DO
9 | NOT AGREE TO THE TERMS OF THIS LICENSE PLEASE DON'T DOWNLOAD OR USE THE SDK.
10 |
11 | You may, free of charge, download and use the SDK to develop a modified Valve
12 | game running on the Half-Life 1 engine. You may distribute your modified Valve
13 | game in source and object code form, but only for free. Terms of use for Valve
14 | games are found in the Steam Subscriber Agreement located here:
15 | http://store.steampowered.com/subscriber_agreement/
16 |
17 | You may copy, modify, and distribute the SDK and any modifications you make to
18 | the SDK in source and object code form, but only for free. Any distribution of
19 | this SDK must include this LICENSE file.
20 |
21 | Any distribution of the SDK or a substantial portion of the SDK must include
22 | the above copyright notice and the following:
23 |
24 | DISCLAIMER OF WARRANTIES. THE HALF LIFE 1 SDK AND ANY OTHER MATERIAL
25 | DOWNLOADED BY LICENSEE IS PROVIDED "AS IS". VALVE AND ITS SUPPLIERS
26 | DISCLAIM ALL WARRANTIES WITH RESPECT TO THE SDK, EITHER EXPRESS OR IMPLIED,
27 | INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY,
28 | NON-INFRINGEMENT, TITLE AND FITNESS FOR A PARTICULAR PURPOSE.
29 |
30 | LIMITATION OF LIABILITY. IN NO EVENT SHALL VALVE OR ITS SUPPLIERS BE LIABLE
31 | FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER
32 | (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
33 | BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY
34 | LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE THE ENGINE AND/OR THE
35 | SDK, EVEN IF VALVE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
36 |
37 |
38 | If you would like to use the SDK for a commercial purpose, please contact Valve
39 | at sourceengine@valvesoftware.com.
40 |
--------------------------------------------------------------------------------
/licenses/SPTLIB_LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014-2017 Ivan Molodetskikh
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/runsven.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
3 |
4 | # If your Steam library is somewhere else, correct this path.
5 | export SVEN_ROOT="."
6 |
7 | # SvenBXT path (you can correct this path too)
8 | export SVENBXT="$SVEN_ROOT/libSvenBXT.so"
9 |
10 | # Check that the Sven Co-op folder exists.
11 | if [ ! -d "$SVEN_ROOT" ]; then
12 | echo "Sven Co-op folder does not exist at $SVEN_ROOT"
13 | exit 1
14 | fi
15 |
16 | # Check that SvenBXT exists.
17 | if [ ! -f "$SVENBXT" ]; then
18 | echo "SvenBXT does not exist at $SVENBXT"
19 | exit 1
20 | fi
21 |
22 | export LD_PRELOAD="$LD_PRELOAD:$SVENBXT"
23 |
24 | # Run Sven Co-op.
25 | export LD_LIBRARY_PATH="$SVEN_ROOT:$LD_LIBRARY_PATH"
26 | export SteamEnv=1
27 |
28 | cd "$SVEN_ROOT" || exit 1
29 | exec ./svencoop_linux -steam "$@"
--------------------------------------------------------------------------------
/src/.clang-format:
--------------------------------------------------------------------------------
1 | # Visual Studio generated .clang-format file
2 |
3 | # The style options in this file are a best effort attempt to replicate the
4 | # current IDE formatting configuration from Tools > Options.
5 |
6 | AccessModifierOffset: -4
7 | AlignAfterOpenBracket: DontAlign
8 | AllowShortBlocksOnASingleLine: true
9 | AllowShortCaseLabelsOnASingleLine: true
10 | AllowShortFunctionsOnASingleLine: All
11 | BasedOnStyle: LLVM
12 | BraceWrapping:
13 | BeforeLambdaBody: true
14 | AfterCaseLabel: true
15 | AfterClass: true
16 | AfterControlStatement: true
17 | AfterEnum: true
18 | AfterFunction: true
19 | AfterNamespace: true
20 | AfterStruct: true
21 | AfterUnion: true
22 | BeforeCatch: true
23 | BeforeElse: true
24 | IndentBraces: false
25 | SplitEmptyFunction: true
26 | SplitEmptyRecord: true
27 | BreakBeforeBraces: Custom
28 | ColumnLimit: 0
29 | Cpp11BracedListStyle: true
30 | FixNamespaceComments: false
31 | IndentCaseLabels: false
32 | IndentPPDirectives: None
33 | IndentWidth: 4
34 | MaxEmptyLinesToKeep: 10
35 | NamespaceIndentation: None
36 | PointerAlignment: Left
37 | SortIncludes: false
38 | SortUsingDeclarations: false
39 | SpaceAfterCStyleCast: false
40 | SpaceBeforeAssignmentOperators: true
41 | SpaceBeforeCaseColon: false
42 | SpaceBeforeCtorInitializerColon: false
43 | SpaceBeforeInheritanceColon: false
44 | SpaceBeforeParens: ControlStatements
45 | SpaceBeforeSquareBrackets: false
46 | SpaceInEmptyParentheses: false
47 | SpacesInCStyleCastParentheses: false
48 | SpacesInParentheses: false
49 | SpacesInSquareBrackets: false
50 | TabWidth: 4
51 | UseTab: true
--------------------------------------------------------------------------------
/src/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.22)
2 |
3 | # CMake modules
4 | list( APPEND CMAKE_MODULE_PATH
5 | "${CMAKE_CURRENT_LIST_DIR}/cmake"
6 | )
7 |
8 | project(SvenBXT LANGUAGES C CXX ASM)
9 |
10 | include(PlatformInfo)
11 | include(InputFilesList)
12 |
13 | include_directories(${CMAKE_SOURCE_DIR})
14 |
15 | if (COMPILER_MSVC)
16 | set(WINDOWS_FILES
17 | iface.cpp
18 | metahook_emulation.cpp
19 | svenmod_emulation.cpp)
20 | endif()
21 |
22 | set(CLIENT_FILES
23 | cl_dll/cdll_int.cpp
24 | cl_dll/cdll_int.h
25 | cl_dll/hud.cpp
26 | cl_dll/hud.h
27 | cl_dll/hud_crosshair.cpp
28 | cl_dll/hud_crosshair.h
29 | cl_dll/hud_jumpspeed.cpp
30 | cl_dll/hud_jumpspeed.h
31 | cl_dll/hud_origin.cpp
32 | cl_dll/hud_origin.h
33 | cl_dll/hud_speedometer.cpp
34 | cl_dll/hud_speedometer.h
35 | cl_dll/hud_timer.cpp
36 | cl_dll/hud_timer.h
37 | cl_dll/hud_viewangles.cpp
38 | cl_dll/hud_viewangles.h
39 | cl_dll/opengl_utils.cpp
40 | cl_dll/opengl_utils.hpp
41 | cl_dll/parsemsg.cpp
42 | cl_dll/parsemsg.h
43 | cl_dll/tri.cpp
44 | cl_dll/tri.h
45 | cl_dll/view.cpp
46 | cl_dll/view.h)
47 |
48 | set(SERVER_FILES
49 | dlls/server.cpp
50 | dlls/server.h)
51 |
52 | set(ENGINE_FILES
53 | engine/gl_screen.cpp
54 | engine/gl_screen.h)
55 |
56 | set(MAIN_FILES
57 | SvenBXT.cpp
58 | SvenBXT.h
59 | Utils.cpp
60 | Utils.h
61 | hlsdk_mini.hpp)
62 |
63 | source_group("cl_dll" FILES ${CLIENT_FILES})
64 | source_group("dlls" FILES ${SERVER_FILES})
65 | source_group("engine" FILES ${ENGINE_FILES})
66 | source_group("" FILES ${MAIN_FILES} ${WINDOWS_FILES})
67 |
68 | add_library(SvenBXT SHARED
69 | ${WINDOWS_FILES}
70 | ${CLIENT_FILES}
71 | ${SERVER_FILES}
72 | ${ENGINE_FILES}
73 | ${MAIN_FILES})
74 |
75 | add_subdirectory("external")
76 |
77 | # Preprocessor definitions
78 | set( COMMON_DEFINES "" ) # Preprocessor definitions for all targets
79 |
80 | # Add platform defines to common defines
81 | set( COMMON_DEFINES "${COMMON_DEFINES} ${PLATFORM_DEFINES}" )
82 |
83 | if( COMPILER_GNU )
84 |
85 | set( COMMON_DEFINES
86 | ${COMMON_DEFINES}
87 | _stricmp=strcasecmp
88 | _strnicmp=strncasecmp
89 | _snprintf=snprintf
90 | _alloca=alloca
91 | _vsnprintf=vsnprintf
92 | _snwprintf=swprintf
93 | )
94 |
95 | set(OPENGL_LIBRARY GL)
96 | elseif( COMPILER_MSVC )
97 |
98 | # Disable "unsafe" warnings
99 | set( COMMON_DEFINES
100 | ${COMMON_DEFINES}
101 | _CRT_SECURE_NO_WARNINGS
102 | _SCL_SECURE_NO_WARNINGS
103 | )
104 |
105 | set(OPENGL_LIBRARY opengl32)
106 | endif()
107 |
108 | if (COMPILER_GNU)
109 | set_target_properties(SvenBXT PROPERTIES
110 | C_VISIBILITY_PRESET hidden
111 | CXX_VISIBILITY_PRESET hidden
112 | COMPILE_FLAGS "${COMPILE_FLAGS} -fvisibility=hidden"
113 | LINKER_FLAGS "${LINKER_FLAGS} -fvisibility=hidden"
114 | )
115 | endif()
116 |
117 | target_compile_definitions( SvenBXT PUBLIC
118 | ${COMMON_DEFINES}
119 | )
120 |
121 | # Threads setup
122 | set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
123 | set(THREADS_PREFER_PTHREAD_FLAG TRUE)
124 |
125 | # Modules
126 | find_package(Threads REQUIRED)
127 | find_package(OpenGL REQUIRED)
128 |
129 | # Link with dependencies
130 | target_link_libraries(SvenBXT
131 | Threads::Threads
132 | funchook-static
133 | ${OPENGL_LIBRARY}
134 | )
--------------------------------------------------------------------------------
/src/CTimer.h:
--------------------------------------------------------------------------------
1 | #ifdef CTIMER_H_RECURSE_GUARD
2 | #error Recursive header files inclusion detected in CTimer.h
3 | #else //CTIMER_H_RECURSE_GUARD
4 |
5 | #define CTIMER_H_RECURSE_GUARD
6 |
7 | #ifndef CTIMER_H_GUARD
8 | #define CTIMER_H_GUARD
9 | #pragma once
10 |
11 | #ifdef __cplusplus
12 |
13 | class CTimer
14 | {
15 | public:
16 | CTimer()
17 | {
18 | Init();
19 | }
20 |
21 | void Init()
22 | {
23 | ResetTimer();
24 | }
25 |
26 | void StartTimer()
27 | {
28 | m_bStarted = true;
29 | if (!m_bRunning)
30 | {
31 | m_startTime = std::chrono::steady_clock::now();
32 | m_bRunning = true;
33 | }
34 | }
35 |
36 | void StopTimer()
37 | {
38 | if (m_bRunning)
39 | {
40 | auto now = std::chrono::steady_clock::now();
41 | m_elapsedTime += std::chrono::duration_cast(now - m_startTime).count();
42 | m_bRunning = false;
43 | }
44 | }
45 |
46 | void ResetTimer()
47 | {
48 | m_bRunning = false;
49 | m_elapsedTime = 0;
50 | }
51 |
52 | void SetTime(long long time)
53 | {
54 | m_elapsedTime = time;
55 | }
56 |
57 |
58 | void SyncTimer(long long serverTime, bool stop)
59 | {
60 | if (stop)
61 | {
62 | StopTimer();
63 | SetTime(serverTime);
64 | }
65 | else
66 | {
67 | if (m_bRunning)
68 | {
69 | auto now = std::chrono::steady_clock::now();
70 | long long currentElapsedTime = std::chrono::duration_cast(now - m_startTime).count() + m_elapsedTime;
71 | long long adjustment = serverTime - currentElapsedTime;
72 | m_startTime += std::chrono::milliseconds(adjustment);
73 | }
74 | else
75 | {
76 | SetTime(serverTime);
77 | StartTimer();
78 | }
79 | }
80 | }
81 |
82 | long long GetTime() const
83 | {
84 | if (m_bRunning)
85 | {
86 | auto now = std::chrono::steady_clock::now();
87 | return m_elapsedTime + std::chrono::duration_cast(now - m_startTime).count();
88 | }
89 | return m_elapsedTime;
90 | }
91 |
92 | int GetMilliseconds() const
93 | {
94 | return static_cast(fmod(GetTime(), 1000.0));
95 | }
96 |
97 | int GetSeconds() const
98 | {
99 | double seconds = GetTime() / 1000.0;
100 | return static_cast(fmod(seconds, 60.0));
101 | }
102 |
103 | int GetMinutes() const
104 | {
105 | double minutes = GetTime() / 60000.0;
106 | return static_cast(fmod(minutes, 60.0));
107 | }
108 |
109 | int GetHours() const
110 | {
111 | double hours = GetTime() / 3600000.0;
112 | return static_cast(fmod(hours, 24.0));
113 | }
114 |
115 | int GetDays() const
116 | {
117 | double days = GetTime() / 86400000.0;
118 | return static_cast(days);
119 | }
120 |
121 | bool IsStopped() const
122 | {
123 | return m_bRunning ? false : true;
124 | }
125 |
126 | private:
127 | std::chrono::time_point m_startTime;
128 | long long m_elapsedTime; // elapsed time in milliseconds
129 | bool m_bRunning, m_bStarted;
130 | };
131 |
132 | #else //!__cplusplus
133 | #error C++ compiler required to compile CTimer.h
134 | #endif //__cplusplus
135 |
136 | #endif //CTIMER_H_GUARD
137 |
138 | #undef CTIMER_H_RECURSE_GUARD
139 | #endif //CTIMER_H_RECURSE_GUARD
--------------------------------------------------------------------------------
/src/SvenBXT.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by scriptedsnark on 7/18/24.
3 | //
4 |
5 | #include "SvenBXT.h"
6 |
7 | #ifdef PLATFORM_WINDOWS
8 | Utils utils = Utils::Utils(NULL, NULL, NULL);
9 | Utils sv_utils = Utils::Utils(NULL, NULL, NULL);
10 | #endif
11 |
12 | funchook_t* g_lpFuncHook_Server;
13 | funchook_t* g_lpFuncHook_Engine;
14 | funchook_t* g_lpFuncHook_Client;
15 |
16 | dllhandle_t g_lpEngine;
17 | dllhandle_t g_lpServer;
18 | dllhandle_t g_lpClient;
19 |
20 | cl_enginefunc_t* g_lpEngfuncs;
21 | enginefuncs_t* g_engfuncs;
22 | globalvars_t* gpGlobals;
23 | server_t* sv;
24 |
25 | bool g_bHasLoaded = false;
26 |
27 | void SvenBXT_HookClient();
28 |
29 | void SvenBXT_FindEngineStuff()
30 | {
31 | TRACE("Finding engine stuff...\n");
32 |
33 | g_lpFuncHook_Engine = funchook_create();
34 |
35 | int status;
36 | #ifdef PLATFORM_LINUX
37 | g_lpEngfuncs = (cl_enginefunc_t*)Sys_GetProcAddress(g_lpEngine, "cl_enginefuncs");
38 |
39 | if (!g_lpEngfuncs)
40 | {
41 | Sys_Printf("[hw so] Failed to get \"cl_enginefuncs\".\n");
42 | return;
43 | }
44 | else
45 | {
46 | Sys_Printf("[hw so] Found cl_enginefuncs at %p.\n", g_lpEngfuncs);
47 | SvenBXT_HookClient();
48 | }
49 |
50 | // TODO: use GET_VARIABLE define
51 | enginefuncs_t** p_engfuncs = (enginefuncs_t**)Sys_GetProcAddress(g_lpEngine, "g_pengfuncsExportedToDlls");
52 | g_engfuncs = (*p_engfuncs);
53 | gpGlobals = (globalvars_t*)Sys_GetProcAddress(g_lpEngine, "gGlobalVariables");
54 | sv = (server_t*)Sys_GetProcAddress(g_lpEngine, "sv");
55 |
56 | if (!gpGlobals)
57 | {
58 | Sys_Printf("[hw so] Failed to get \"gGlobalVariables\".\n");
59 | }
60 |
61 | if (!g_engfuncs)
62 | {
63 | Sys_Printf("[hw so] Failed to get \"g_engfuncsExportedToDlls\".\n[Engine] Sharing time to clients is not available.\n");
64 | }
65 |
66 | if (!sv)
67 | {
68 | Sys_Printf("[hw so] Failed to get \"sv\".\n");
69 | }
70 |
71 | GET_VARIABLE(Engine, ORIG_GL_Begin2D, _Z10GL_Begin2Dv);
72 | GET_VARIABLE(Engine, ORIG_GL_Finish2D, _Z11GL_Finish2Dv);
73 |
74 | GET_VARIABLE(Engine, ORIG_LoadThisDll, _Z11LoadThisDllPc);
75 | GET_VARIABLE(Engine, ORIG_SCR_BeginLoadingPlaque, _Z22SCR_BeginLoadingPlaquei);
76 | GET_VARIABLE(Engine, ORIG_SCR_EndLoadingPlaque, _Z20SCR_EndLoadingPlaquev);
77 | GET_VARIABLE(Engine, ORIG_GL_EndRendering, _Z15GL_EndRenderingv);
78 | #else
79 | void* handle;
80 | static void* base;
81 | static size_t size;
82 |
83 | if (!MemUtils::GetModuleInfo(L"hw.dll", &handle, &base, &size))
84 | {
85 | Sys_Printf("Failed to get module info from engine.\n");
86 | return;
87 | }
88 |
89 | utils = Utils::Utils(handle, base, size);
90 |
91 | void* ClientDLL_Init;
92 | auto fClientDLL_Init = utils.FindAsync(
93 | ClientDLL_Init,
94 | patterns::engine::ClientDLL_Init,
95 | [&](auto pattern)
96 | {
97 | switch (pattern - patterns::engine::ClientDLL_Init.cbegin())
98 | {
99 | default:
100 | case 0: // Sven-5.25
101 | Sys_Printf("Searching cl_enginefuncs in Sven-5.25 pattern...\n");
102 | g_lpEngfuncs = *reinterpret_cast(reinterpret_cast(ClientDLL_Init) + 332);
103 |
104 | if (g_lpEngfuncs)
105 | {
106 | Sys_Printf("[Engine] Found cl_enginefuncs at 0x%p.\n", g_lpEngfuncs);
107 | SvenBXT_HookClient();
108 | }
109 | break;
110 | case 1: // Sven-5.26-rc1
111 | Sys_Printf("Searching cl_enginefuncs in Sven-5.26-rc1 pattern...\n");
112 | g_lpEngfuncs = *reinterpret_cast(reinterpret_cast(ClientDLL_Init) + 354);
113 |
114 | if (g_lpEngfuncs)
115 | {
116 | Sys_Printf("[Engine] Found cl_enginefuncs at 0x%p.\n", g_lpEngfuncs);
117 | SvenBXT_HookClient();
118 | }
119 | break;
120 | }
121 | });
122 |
123 | void* LoadThisDll;
124 | auto fLoadThisDll = utils.FindAsync(
125 | LoadThisDll,
126 | patterns::engine::LoadThisDll,
127 | [&](auto pattern)
128 | {
129 | switch (pattern - patterns::engine::LoadThisDll.cbegin())
130 | {
131 | default:
132 | case 0: // Sven-5.25
133 | Sys_Printf("Searching g_engfuncs in Sven-5.25 pattern...\n");
134 | enginefuncs_t** p_engfuncs = *reinterpret_cast(reinterpret_cast(LoadThisDll) + 109);
135 | g_engfuncs = (*p_engfuncs);
136 | gpGlobals = *reinterpret_cast(reinterpret_cast(LoadThisDll) + 67);
137 |
138 | if (g_engfuncs)
139 | Sys_Printf("[Engine] Found g_engfuncs at 0x%p.\n", g_engfuncs);
140 |
141 | if (gpGlobals)
142 | Sys_Printf("[Engine] Found gpGlobals at 0x%p.\n", gpGlobals);
143 | break;
144 | }
145 | });
146 |
147 | void* Host_ClearMemory;
148 | auto fHost_ClearMemory = utils.FindAsync(
149 | Host_ClearMemory,
150 | patterns::engine::Host_ClearMemory,
151 | [&](auto pattern)
152 | {
153 | switch (pattern - patterns::engine::Host_ClearMemory.cbegin())
154 | {
155 | default:
156 | case 0: // Sven-5.25
157 | Sys_Printf("Searching sv in Sven-5.25 pattern...\n");
158 | sv = *reinterpret_cast(reinterpret_cast(Host_ClearMemory) + 0x98);
159 | if (sv)
160 | {
161 | Sys_Printf("[Engine] Found sv at 0x%p.\n", sv);
162 | }
163 | break;
164 | }
165 | });
166 |
167 | SPTEngineFind(GL_Begin2D);
168 | SPTEngineFind(GL_Finish2D);
169 |
170 | SPTEngineFind(LoadThisDll);
171 | SPTEngineFind(SCR_BeginLoadingPlaque);
172 | SPTEngineFind(SCR_EndLoadingPlaque);
173 | SPTEngineFind(GL_EndRendering);
174 | #endif
175 |
176 | CreateHook(Engine, LoadThisDll);
177 | CreateHook(Engine, SCR_BeginLoadingPlaque);
178 | CreateHook(Engine, SCR_EndLoadingPlaque);
179 | CreateHook(Engine, GL_EndRendering);
180 |
181 | funchook_install(g_lpFuncHook_Engine, 0);
182 | }
183 |
184 | void SvenBXT_HookClient()
185 | {
186 | TRACE("Hooking client...\n");
187 | #ifdef PLATFORM_WINDOWS
188 | g_lpClient = Sys_GetModuleHandle("client");
189 | #else
190 | g_lpClient = Sys_GetModuleHandle("svencoop/cl_dlls/client.so");
191 | #endif
192 |
193 | if (!g_lpClient)
194 | {
195 | Sys_Printf("Failed to get client module handle.\n");
196 | return;
197 | }
198 |
199 | g_lpFuncHook_Client = funchook_create();
200 |
201 | CL_Initialize();
202 |
203 | funchook_install(g_lpFuncHook_Client, 0);
204 | }
205 |
206 | void SvenBXT_HookEngine()
207 | {
208 | g_lpEngine = Sys_GetModuleHandle("hw" DLL_FORMAT);
209 |
210 | if (!g_lpEngine)
211 | {
212 | Sys_Printf("Failed to get engine module handle.\n");
213 | return;
214 | }
215 |
216 | SvenBXT_FindEngineStuff();
217 | }
218 |
219 | void SvenBXT_UnhookClient()
220 | {
221 | if (g_lpFuncHook_Client)
222 | {
223 | funchook_uninstall(g_lpFuncHook_Client, 0);
224 | funchook_destroy(g_lpFuncHook_Client);
225 | }
226 | }
227 |
228 | void SvenBXT_UnhookEngine()
229 | {
230 | if (g_lpFuncHook_Engine)
231 | {
232 | funchook_uninstall(g_lpFuncHook_Engine, 0);
233 | funchook_destroy(g_lpFuncHook_Engine);
234 | }
235 | }
236 |
237 | //-----------------------------------------------------------------------------
238 | // Purpose: hook in right time a.k.a I don't wanna hook LoadLibraryA/dlopen
239 | //-----------------------------------------------------------------------------
240 | void WaitUntilClientLoads()
241 | {
242 | lbl_waitFor:
243 | #ifdef PLATFORM_WINDOWS
244 | g_lpClient = Sys_GetModuleHandle("client");
245 | #else
246 | g_lpClient = Sys_GetModuleHandle("svencoop/cl_dlls/client" DLL_FORMAT);
247 | #endif
248 |
249 | if (g_lpClient)
250 | {
251 | SvenBXT_HookEngine();
252 | g_bHasLoaded = true;
253 | }
254 | else
255 | goto lbl_waitFor;
256 | }
257 |
258 | void SvenBXT_Main()
259 | {
260 | if (g_bHasLoaded)
261 | {
262 | Sys_Printf("Loader/injector or whatever else tried to initialize SvenBXT again!");
263 | return;
264 | }
265 |
266 | // too lazy to do this using fopen
267 | std::ofstream ofs;
268 | ofs.open("svenbxt.log", std::ofstream::out | std::ofstream::trunc);
269 | ofs.close();
270 |
271 | TRACE("Initializing SvenBXT...\n");
272 |
273 | std::thread t(WaitUntilClientLoads);
274 | t.detach();
275 | }
276 |
277 | void SvenBXT_Shutdown()
278 | {
279 | TRACE("Shutting down...\n");
280 |
281 | SvenBXT_UnhookEngine();
282 | SvenBXT_UnhookClient();
283 |
284 | g_bHasLoaded = false;
285 | }
286 |
287 | #ifdef WIN32
288 | BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
289 | {
290 | switch (fdwReason)
291 | {
292 | case DLL_PROCESS_ATTACH:
293 | #ifdef _DEBUG
294 | AllocConsole();
295 | FILE *in, *out;
296 | freopen_s(&in, "conin$", "r", stdin);
297 | freopen_s(&out, "conout$", "w+", stdout);
298 | #endif
299 | CreateThread(NULL, NULL, reinterpret_cast(SvenBXT_Main), NULL, NULL, NULL);
300 | break;
301 |
302 | case DLL_PROCESS_DETACH:
303 | SvenBXT_Shutdown();
304 | break;
305 | }
306 |
307 | return TRUE;
308 | }
309 | #else
310 | static __attribute__((constructor)) void Construct()
311 | {
312 | SvenBXT_Main();
313 | }
314 |
315 | static __attribute__((destructor)) void Destruct()
316 | {
317 | SvenBXT_Shutdown();
318 | }
319 | #endif
320 |
--------------------------------------------------------------------------------
/src/SvenBXT.h:
--------------------------------------------------------------------------------
1 | #ifdef SVENBXT_H_RECURSE_GUARD
2 | #error Recursive header files inclusion detected in SvenBXT.h
3 | #else // SVENBXT_H_RECURSE_GUARD
4 |
5 | #define SVENBXT_H_RECURSE_GUARD
6 |
7 | #ifndef SVENBXT_H_GUARD
8 | #define SVENBXT_H_GUARD
9 | #pragma once
10 |
11 | #ifdef __cplusplus
12 |
13 | // GLOBAL DEFINE
14 | #define SVENBXT_VERSION __DATE__ // maybe something else? :thinking:
15 | #define SVENBXT_GITHUB_URL "https://github.com/ScriptedSnark/SvenBXT"
16 |
17 | // WINDOWS
18 | #ifdef PLATFORM_WINDOWS
19 | #include
20 | #include
21 | #else
22 | #include
23 | #include
24 | #include
25 | #endif
26 |
27 | // STL
28 | #include
29 | #include
30 | #include