├── CMakeLists.txt
├── LICENSE
├── README.md
├── include
├── cstrike
│ ├── Classes
│ │ ├── CBaseHandle.h
│ │ ├── CGlobalVarsBase.h
│ │ ├── CInput.h
│ │ ├── CShowPixelsParams.h
│ │ ├── CUserCmd.h
│ │ ├── ClientClass.h
│ │ ├── IClientEntity.h
│ │ ├── IClientNetworkable.h
│ │ ├── IClientRenderable.h
│ │ ├── IClientThinkable.h
│ │ ├── IClientUnknown.h
│ │ ├── ICollideable.h
│ │ ├── IHandleEntity.h
│ │ └── RecvTable.h
│ ├── Definitions
│ │ ├── Buttons.h
│ │ ├── Const.h
│ │ ├── Flags.h
│ │ └── Input.h
│ ├── Interfaces
│ │ ├── IBaseClientDLL.h
│ │ ├── IClientEntityList.h
│ │ ├── ICvar.h
│ │ ├── IEngineVGui.h
│ │ ├── IGameEventManager2.h
│ │ ├── IInputInternal.h
│ │ ├── IInputSystem.h
│ │ ├── ILauncherMgr.h
│ │ ├── IMaterialSystem.h
│ │ ├── IPanel.h
│ │ ├── ISurface.h
│ │ ├── IVDebugOverlay.h
│ │ ├── IVEngineClient.h
│ │ ├── IVModelInfo.h
│ │ └── IVModelRender.h
│ ├── Structures
│ │ ├── Color.h
│ │ ├── Matrix.h
│ │ ├── PlayerInfo.h
│ │ └── Vector.h
│ ├── Utilities
│ │ ├── CRC32.h
│ │ └── Virtuals.h
│ └── cstrike.h
├── imgui
│ ├── imconfig.h
│ ├── imgui.cpp
│ ├── imgui.h
│ ├── imgui_draw.cpp
│ ├── imgui_impl_sdl.cpp
│ ├── imgui_impl_sdl.h
│ ├── imgui_internal.h
│ ├── stb_rect_pack.h
│ ├── stb_textedit.h
│ └── stb_truetype.h
└── vmthook
│ └── vmthook.h
└── src
├── Basehook.cpp
├── Basehook.h
├── Events
└── TestListener.h
├── GUI
├── Components.cpp
├── GUI.cpp
└── GUI.h
├── Game
└── Entity.h
├── Hooks
├── CreateMove.cpp
├── DrawModelExecute.cpp
├── FrameStageNotify.cpp
├── Hooks.h
├── Paint.cpp
├── PumpWindowsMessageLoop.cpp
├── SetKeyCodeState.cpp
├── SetMouseCodeState.cpp
└── ShowPixels.cpp
└── Utilities
├── FindPattern.h
├── Interfaces.h
├── Linker.cpp
├── Linker.h
└── NetVars.h
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 2.8)
2 | project(cstrike-basehook)
3 |
4 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++14 -m32 -Wall -Wextra -Wpedantic")
5 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++ -m32")
6 |
7 | include_directories("include")
8 |
9 | file(GLOB_RECURSE SOURCE_FILES src/*.cpp include/*.cpp)
10 |
11 | add_library(cstrike-basehook SHARED ${SOURCE_FILES})
12 |
13 | target_link_libraries(cstrike-basehook SDL2 GL)
14 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # cstrike-basehook-linux
2 |
3 | Internal project base for Counter-Strike: Source on Linux. Includes full OpenGL ImGui rendering and input handling, a minimal Source SDK implementation, virtual hooking class and various other features for quick prototyping.
4 |
5 | ### Features
6 | * Retrieves interfaces directly from the *s_pInterfaceRegs* linked list.
7 | * ImGui drawing and input handling via *ILauncherMgr* virtual hooks.
8 | * Engine drawing with *ISurface* functions via *IEngineVGui::Paint* hook.
9 | * *IBaseClientDLL::CreateMove* hook with *CUserCmd* checksum validation.
10 | * *CInput* and *CGlobalVars* pointers retrieved from IBaseClientDLL virtuals.
11 | * Can easily be unloaded, modified and reloaded without restarting the game.
12 | * Includes an example game event listener in a self-contained class.
13 |
14 | ### Requirements
15 |
16 | You will need **cmake**, a relatively up-to-date C++ compiler and 32-bit **SDL2** headers.
17 |
18 | If you are on a 64-bit system you may need to enable 32-bit repositories.
19 |
20 | ```
21 | pacman -S cmake base-devel lib32-sdl2 gcc-multilib
22 | ```
23 |
24 | ### Usage
25 |
26 | After you have cloned or extracted an archive of the repository you can use `cmake .` to create a Makefile and `make` to build the shared library. When finished, load the output file into the game while it is running. Using [gdb](https://aixxe.net/2016/09/shared-library-injection) is recommended.
27 |
28 | Press INSERT to toggle the configuration window.
29 |
30 | ### Credits
31 |
32 | Special thanks to [luk1337](https://github.com/luk1337) for the ImGui SDL2 input fix.
--------------------------------------------------------------------------------
/include/cstrike/Classes/CBaseHandle.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | class CBaseHandle {
4 | public:
5 | inline bool IsValid() const {
6 | return m_Index != INVALID_EHANDLE_INDEX;
7 | }
8 |
9 | inline int GetEntryIndex() const {
10 | return m_Index & ENT_ENTRY_MASK;
11 | }
12 |
13 | unsigned long m_Index;
14 | };
--------------------------------------------------------------------------------
/include/cstrike/Classes/CGlobalVarsBase.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | class CSaveRestoreData;
4 |
5 | class CGlobalVarsBase {
6 | public:
7 | float realtime;
8 | int framecount;
9 | float absoluteframetime;
10 | float curtime;
11 | float frametime;
12 | int maxClients;
13 | int tickcount;
14 | float interval_per_tick;
15 | float interpolation_amount;
16 | int simTicksThisFrame;
17 | int network_protocol;
18 | CSaveRestoreData* pSaveData;
19 | private:
20 | bool m_bClient;
21 | int nTimestampNetworkingBase;
22 | int nTimestampRandomizeWindow;
23 | };
24 |
25 | extern CGlobalVarsBase* globalvars;
--------------------------------------------------------------------------------
/include/cstrike/Classes/CInput.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #define MAX_SPLITSCREEN_PLAYERS 1
4 |
5 | enum MouseParams: int {
6 | MOUSE_ACCEL_THRESHHOLD1 = 0,
7 | MOUSE_ACCEL_THRESHHOLD2,
8 | MOUSE_SPEED_FACTOR,
9 | NUM_MOUSE_PARAMS
10 | };
11 |
12 | enum JoystickAxis_t {
13 | JOY_AXIS_X = 0,
14 | JOY_AXIS_Y,
15 | JOY_AXIS_Z,
16 | JOY_AXIS_R,
17 | JOY_AXIS_U,
18 | JOY_AXIS_V,
19 | MAX_JOYSTICK_AXES,
20 | };
21 |
22 | typedef struct {
23 | unsigned int AxisFlags;
24 | unsigned int AxisMap;
25 | unsigned int ControlMap;
26 | } joy_axis_t;
27 |
28 | struct Split_t {
29 | int m_nDown[2];
30 | int m_nState;
31 | };
32 |
33 | struct kbutton_t {
34 | Split_t m_PerUser[MAX_SPLITSCREEN_PLAYERS];
35 | };
36 |
37 | class CKeyboardKey {
38 | public:
39 | char m_szName[32];
40 | kbutton_t* m_pKey;
41 | CKeyboardKey* m_pNext;
42 | };
43 |
44 | class CUserCmd;
45 | class CVerifiedUserCmd;
46 |
47 | class CInput {
48 | private:
49 | virtual ~CInput(void) {};
50 | public:
51 | bool m_fMouseInitialized;
52 | bool m_fMouseActive;
53 | bool m_fJoystickAdvancedInit;
54 | bool m_fHadJoysticks;
55 |
56 | float m_flAccumulatedMouseXMovement;
57 | float m_flAccumulatedMouseYMovement;
58 | float m_flPreviousMouseXPosition;
59 | float m_flPreviousMouseYPosition;
60 | float m_flRemainingJoystickSampleTime;
61 | float m_flKeyboardSampleTime;
62 |
63 | bool m_fRestoreSPI;
64 | int m_rgOrigMouseParms[NUM_MOUSE_PARAMS];
65 | int m_rgNewMouseParms[NUM_MOUSE_PARAMS];
66 | bool m_rgCheckMouseParam[NUM_MOUSE_PARAMS];
67 | bool m_fMouseParmsValid;
68 |
69 | joy_axis_t m_rgAxes[MAX_JOYSTICK_AXES];
70 | CKeyboardKey* m_pKeys;
71 |
72 | bool m_fCameraInterceptingMouse;
73 | bool m_fCameraInThirdPerson;
74 | bool m_fCameraMovingWithMouse;
75 |
76 | bool m_fCameraDistanceMove;
77 |
78 | int m_nCameraOldX;
79 | int m_nCameraOldY;
80 | int m_nCameraX;
81 | int m_nCameraY;
82 |
83 | bool m_CameraIsOrthographic;
84 |
85 | QAngle m_angPreviousViewAngles;
86 |
87 | float m_flLastForwardMove;
88 |
89 | float m_flPreviousJoystickForward;
90 | float m_flPreviousJoystickSide;
91 | float m_flPreviousJoystickPitch;
92 | float m_flPreviousJoystickYaw;
93 |
94 | CUserCmd* m_pCommands;
95 | CVerifiedUserCmd* m_pVerifiedCommands;
96 |
97 | inline CUserCmd* GetUserCmd(int sequence) {
98 | return &this->m_pCommands[sequence % MULTIPLAYER_BACKUP];
99 | }
100 |
101 | inline CVerifiedUserCmd* GetVerifiedUserCmd(int sequence) {
102 | return &this->m_pVerifiedCommands[sequence % MULTIPLAYER_BACKUP];
103 | }
104 |
105 | inline void VerifyUserCmd(CUserCmd* cmd, int sequence) {
106 | CVerifiedUserCmd* cmd_verified = this->GetVerifiedUserCmd(sequence);
107 |
108 | cmd_verified->m_cmd = *cmd;
109 | cmd_verified->m_crc = cmd->GetChecksum();
110 | }
111 | };
112 |
113 | extern CInput* input;
--------------------------------------------------------------------------------
/include/cstrike/Classes/CShowPixelsParams.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | class CShowPixelsParams {
4 | public:
5 | unsigned int m_srcTexName;
6 | int m_width;
7 | int m_height;
8 | bool m_vsyncEnable;
9 | bool m_fsEnable;
10 | bool m_useBlit;
11 | bool m_noBlit;
12 | bool m_onlySyncView;
13 | };
--------------------------------------------------------------------------------
/include/cstrike/Classes/CUserCmd.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | class CUserCmd {
4 | virtual ~CUserCmd() {};
5 |
6 | public:
7 | int command_number;
8 | int tick_count;
9 | QAngle viewangles;
10 | float forwardmove;
11 | float sidemove;
12 | float upmove;
13 | int buttons;
14 | unsigned char impulse;
15 | int weaponselect;
16 | int weaponsubtype;
17 | int random_seed;
18 | short mousedx;
19 | short mousedy;
20 | bool hasbeenpredicted;
21 |
22 | inline CRC32_t GetChecksum() {
23 | CRC32_t crc;
24 |
25 | CRC32_Init(&crc);
26 |
27 | CRC32_ProcessBuffer(&crc, &this->command_number, sizeof(this->command_number));
28 | CRC32_ProcessBuffer(&crc, &this->tick_count, sizeof(this->tick_count));
29 | CRC32_ProcessBuffer(&crc, &this->viewangles, sizeof(this->viewangles));
30 | CRC32_ProcessBuffer(&crc, &this->forwardmove, sizeof(this->forwardmove));
31 | CRC32_ProcessBuffer(&crc, &this->sidemove, sizeof(this->sidemove));
32 | CRC32_ProcessBuffer(&crc, &this->upmove, sizeof(this->upmove));
33 | CRC32_ProcessBuffer(&crc, &this->buttons, sizeof(this->buttons));
34 | CRC32_ProcessBuffer(&crc, &this->impulse, sizeof(this->impulse));
35 | CRC32_ProcessBuffer(&crc, &this->weaponselect, sizeof(this->weaponselect));
36 | CRC32_ProcessBuffer(&crc, &this->weaponsubtype, sizeof(this->weaponsubtype));
37 | CRC32_ProcessBuffer(&crc, &this->random_seed, sizeof(this->random_seed));
38 | CRC32_ProcessBuffer(&crc, &this->mousedx, sizeof(this->mousedx));
39 | CRC32_ProcessBuffer(&crc, &this->mousedy, sizeof(this->mousedy));
40 |
41 | CRC32_Final(&crc);
42 |
43 | return crc;
44 | }
45 | };
46 |
47 | class CVerifiedUserCmd {
48 | public:
49 | CUserCmd m_cmd;
50 | CRC32_t m_crc;
51 | };
--------------------------------------------------------------------------------
/include/cstrike/Classes/ClientClass.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | class IClientNetworkable;
4 | class RecvTable;
5 |
6 | typedef IClientNetworkable* (*CreateClientClassFn) (int, int);
7 | typedef IClientNetworkable* (*CreateEventFn) (void);
8 |
9 | class ClientClass {
10 | public:
11 | CreateClientClassFn m_pCreateFn;
12 | CreateEventFn m_pCreateEventFn;
13 |
14 | char* m_pNetworkName;
15 |
16 | RecvTable* m_pRecvTable;
17 | ClientClass* m_pNext;
18 |
19 | int m_nClassID;
20 | };
21 |
--------------------------------------------------------------------------------
/include/cstrike/Classes/IClientEntity.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | class IClientEntity: public IClientUnknown, public IClientRenderable, public IClientNetworkable, public IClientThinkable {
4 | public:
5 | virtual void Release(void) = 0;
6 | virtual const Vector& GetAbsOrigin(void) const = 0;
7 | virtual const QAngle& GetAbsAngles(void) const = 0;
8 | };
--------------------------------------------------------------------------------
/include/cstrike/Classes/IClientNetworkable.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | enum ShouldTransmitState_t: int {
4 | SHOULDTRANSMIT_START = 0,
5 | SHOULDTRANSMIT_END
6 | };
7 |
8 | enum DataUpdateType_t: int {
9 | DATA_UPDATE_CREATED = 0,
10 | DATA_UPDATE_DATATABLE_CHANGED
11 | };
12 |
13 | class IClientNetworkable {
14 | public:
15 | virtual IClientUnknown* GetIClientUnknown() = 0;
16 | virtual void Release() = 0;
17 | virtual ClientClass* GetClientClass() = 0;
18 | virtual void NotifyShouldTransmit(ShouldTransmitState_t state) = 0;
19 | virtual void OnPreDataChanged(DataUpdateType_t type) = 0;
20 | virtual void OnDataChanged(DataUpdateType_t type) = 0;
21 | virtual void PreDataUpdate(DataUpdateType_t type) = 0;
22 | virtual void PostDataUpdate(DataUpdateType_t type) = 0;
23 | virtual bool IsDormant(void) = 0;
24 | virtual int GetIndex(void) const = 0;
25 | };
--------------------------------------------------------------------------------
/include/cstrike/Classes/IClientRenderable.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | class model_t;
4 |
5 | class IClientRenderable {
6 | public:
7 | virtual IClientUnknown* GetIClientUnknown() = 0;
8 | virtual Vector const& GetRenderOrigin(void) = 0;
9 | virtual QAngle const& GetRenderAngles(void) = 0;
10 |
11 | const model_t* GetModel() {
12 | return GetVirtualFunction(this, 9)(this);
13 | }
14 |
15 | bool SetupBones(matrix3x4_t* bonematrix, int maxbones, int mask, float curtime = 0) {
16 | return GetVirtualFunction(this, 16)(this, bonematrix, maxbones, mask, curtime);
17 | }
18 | };
--------------------------------------------------------------------------------
/include/cstrike/Classes/IClientThinkable.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | class IClientThinkable {
4 | public:
5 | virtual IClientUnknown* GetIClientUnknown() = 0;
6 | };
--------------------------------------------------------------------------------
/include/cstrike/Classes/IClientUnknown.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | class ICollideable;
4 | class IClientRenderable;
5 | class IClientEntity;
6 | class C_BaseEntity;
7 | class IClientThinkable;
8 |
9 | class IClientUnknown: public IHandleEntity {
10 | public:
11 | virtual ICollideable* GetCollideable() = 0;
12 | virtual IClientNetworkable* GetClientNetworkable() = 0;
13 | virtual IClientRenderable* GetClientRenderable() = 0;
14 | virtual IClientEntity* GetIClientEntity() = 0;
15 | virtual C_BaseEntity* GetBaseEntity() = 0;
16 | virtual IClientThinkable* GetClientThinkable() = 0;
17 | };
--------------------------------------------------------------------------------
/include/cstrike/Classes/ICollideable.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | class ICollideable {
4 | public:
5 | virtual IHandleEntity* GetEntityHandle() = 0;
6 | virtual const Vector& OBBMinsPreScaled() const = 0;
7 | virtual const Vector& OBBMaxsPreScaled() const = 0;
8 | virtual const Vector& OBBMins() const = 0;
9 | virtual const Vector& OBBMaxs() const = 0;
10 | };
--------------------------------------------------------------------------------
/include/cstrike/Classes/IHandleEntity.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | class IHandleEntity {
4 | public:
5 | virtual ~IHandleEntity() {};
6 | virtual void SetRefEHandle(const CBaseHandle& Handle) = 0;
7 | virtual const CBaseHandle& GetRefEHandle() const = 0;
8 | };
--------------------------------------------------------------------------------
/include/cstrike/Classes/RecvTable.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | class RecvTable;
4 | struct CRecvProxyData;
5 |
6 | typedef void (*RecvVarProxyFn) (const CRecvProxyData*, void*, void*);
7 |
8 | enum SendPropType: int {
9 | DPT_Int = 0,
10 | DPT_Float,
11 | DPT_Vector,
12 | DPT_VectorXY,
13 | DPT_String,
14 | DPT_Array,
15 | DPT_DataTable,
16 | DPT_Int64,
17 | DPT_NUMSendPropTypes
18 | };
19 |
20 | class RecvProp {
21 | public:
22 | char* m_pVarName;
23 | SendPropType m_RecvType;
24 | int m_Flags;
25 | int m_StringBufferSize;
26 | bool m_bInsideArray;
27 | const void* m_pExtraData;
28 | RecvProp* m_pArrayProp;
29 | void* m_ArrayLengthProxy;
30 | void* m_ProxyFn;
31 | void* m_DataTableProxyFn;
32 | RecvTable* m_pDataTable;
33 | int m_Offset;
34 | int m_ElementStride;
35 | int m_nElements;
36 | const char* m_pParentArrayPropName;
37 | };
38 |
39 | class RecvTable {
40 | public:
41 | RecvProp* m_pProps;
42 | int m_nProps;
43 | void* m_pDecoder;
44 | char* m_pNetTableName;
45 | bool m_bInitialized;
46 | bool m_bInMainList;
47 | };
48 |
49 | struct DVariant {
50 | union {
51 | float m_Float;
52 | long m_Int;
53 | char* m_pString;
54 | void* m_pData;
55 | float m_Vector[3];
56 | int64_t m_Int64;
57 | };
58 |
59 | int m_Type;
60 | };
61 |
62 | struct CRecvProxyData {
63 | const RecvProp* m_pRecvProp;
64 | DVariant m_Value;
65 | int m_iElement;
66 | int m_ObjectID;
67 | };
--------------------------------------------------------------------------------
/include/cstrike/Definitions/Buttons.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #define IN_ATTACK (1 << 0)
4 | #define IN_JUMP (1 << 1)
5 | #define IN_DUCK (1 << 2)
6 | #define IN_FORWARD (1 << 3)
7 | #define IN_BACK (1 << 4)
8 | #define IN_USE (1 << 5)
9 | #define IN_CANCEL (1 << 6)
10 | #define IN_LEFT (1 << 7)
11 | #define IN_RIGHT (1 << 8)
12 | #define IN_MOVELEFT (1 << 9)
13 | #define IN_MOVERIGHT (1 << 10)
14 | #define IN_ATTACK2 (1 << 11)
15 | #define IN_RUN (1 << 12)
16 | #define IN_RELOAD (1 << 13)
17 | #define IN_ALT1 (1 << 14)
18 | #define IN_ALT2 (1 << 15)
19 | #define IN_SCORE (1 << 16)
20 | #define IN_SPEED (1 << 17)
21 | #define IN_WALK (1 << 18)
22 | #define IN_ZOOM (1 << 19)
23 | #define IN_WEAPON1 (1 << 20)
24 | #define IN_WEAPON2 (1 << 21)
25 | #define IN_BULLRUSH (1 << 22)
26 | #define IN_GRENADE1 (1 << 23)
27 | #define IN_GRENADE2 (1 << 24)
28 | #define IN_ATTACK3 (1 << 25)
--------------------------------------------------------------------------------
/include/cstrike/Definitions/Const.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #define MULTIPLAYER_BACKUP 90
4 |
5 | #define SIGNED_GUID_LEN 32
6 |
7 | #define MAX_PLAYER_NAME_LENGTH 32
8 | #define MAX_CUSTOM_FILES 4
9 |
10 | #define LIFE_ALIVE 0
11 | #define LIFE_DYING 1
12 | #define LIFE_DEAD 2
13 | #define LIFE_RESPAWNABLE 3
14 | #define LIFE_DISCARDBODY 4
15 |
16 | #define MAX_EDICT_BITS 11
17 | #define NUM_ENT_ENTRY_BITS (MAX_EDICT_BITS + 1)
18 | #define NUM_ENT_ENTRIES (1 << NUM_ENT_ENTRY_BITS)
19 | #define ENT_ENTRY_MASK (NUM_ENT_ENTRIES - 1)
20 | #define INVALID_EHANDLE_INDEX 0xFFFFFFFF
21 |
22 | #define NUM_SERIAL_NUM_BITS (32 - NUM_ENT_ENTRY_BITS)
--------------------------------------------------------------------------------
/include/cstrike/Definitions/Flags.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #define FL_ONGROUND (1 << 0)
4 | #define FL_DUCKING (1 << 1)
5 | #define FL_WATERJUMP (1 << 3)
6 | #define FL_ONTRAIN (1 << 4)
7 | #define FL_INRAIN (1 << 5)
8 | #define FL_FROZEN (1 << 6)
9 | #define FL_ATCONTROLS (1 << 7)
10 | #define FL_CLIENT (1 << 8)
11 | #define FL_FAKECLIENT (1 << 9)
12 | #define FL_INWATER (1 << 10)
13 | #define FL_FLY (1 << 11)
14 | #define FL_SWIM (1 << 12)
15 | #define FL_CONVEYOR (1 << 13)
16 | #define FL_NPC (1 << 14)
17 | #define FL_GODMODE (1 << 15)
18 | #define FL_NOTARGET (1 << 16)
19 | #define FL_AIMTARGET (1 << 17)
20 | #define FL_PARTIALGROUND (1 << 18)
21 | #define FL_STATICPROP (1 << 19)
22 | #define FL_GRAPHED (1 << 20)
23 | #define FL_GRENADE (1 << 21)
24 | #define FL_STEPMOVEMENT (1 << 22)
25 | #define FL_DONTTOUCH (1 << 23)
26 | #define FL_BASEVELOCITY (1 << 24)
27 | #define FL_WORLDBRUSH (1 << 25)
28 | #define FL_OBJECT (1 << 26)
29 | #define FL_KILLME (1 << 27)
30 | #define FL_ONFIRE (1 << 28)
31 | #define FL_DISSOLVING (1 << 29)
32 | #define FL_TRANSRAGDOLL (1 << 30)
33 | #define FL_UNBLOCKABLE_BY_PLAYER (1 << 31)
--------------------------------------------------------------------------------
/include/cstrike/Definitions/Input.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | enum ButtonCode_t {
4 | BUTTON_CODE_INVALID = -1,
5 | BUTTON_CODE_NONE = 0,
6 | KEY_FIRST = 0,
7 | KEY_NONE = KEY_FIRST,
8 | KEY_0,
9 | KEY_1,
10 | KEY_2,
11 | KEY_3,
12 | KEY_4,
13 | KEY_5,
14 | KEY_6,
15 | KEY_7,
16 | KEY_8,
17 | KEY_9,
18 | KEY_A,
19 | KEY_B,
20 | KEY_C,
21 | KEY_D,
22 | KEY_E,
23 | KEY_F,
24 | KEY_G,
25 | KEY_H,
26 | KEY_I,
27 | KEY_J,
28 | KEY_K,
29 | KEY_L,
30 | KEY_M,
31 | KEY_N,
32 | KEY_O,
33 | KEY_P,
34 | KEY_Q,
35 | KEY_R,
36 | KEY_S,
37 | KEY_T,
38 | KEY_U,
39 | KEY_V,
40 | KEY_W,
41 | KEY_X,
42 | KEY_Y,
43 | KEY_Z,
44 | KEY_PAD_0,
45 | KEY_PAD_1,
46 | KEY_PAD_2,
47 | KEY_PAD_3,
48 | KEY_PAD_4,
49 | KEY_PAD_5,
50 | KEY_PAD_6,
51 | KEY_PAD_7,
52 | KEY_PAD_8,
53 | KEY_PAD_9,
54 | KEY_PAD_DIVIDE,
55 | KEY_PAD_MULTIPLY,
56 | KEY_PAD_MINUS,
57 | KEY_PAD_PLUS,
58 | KEY_PAD_ENTER,
59 | KEY_PAD_DECIMAL,
60 | KEY_LBRACKET,
61 | KEY_RBRACKET,
62 | KEY_SEMICOLON,
63 | KEY_APOSTROPHE,
64 | KEY_BACKQUOTE,
65 | KEY_COMMA,
66 | KEY_PERIOD,
67 | KEY_SLASH,
68 | KEY_BACKSLASH,
69 | KEY_MINUS,
70 | KEY_EQUAL,
71 | KEY_ENTER,
72 | KEY_SPACE,
73 | KEY_BACKSPACE,
74 | KEY_TAB,
75 | KEY_CAPSLOCK,
76 | KEY_NUMLOCK,
77 | KEY_ESCAPE,
78 | KEY_SCROLLLOCK,
79 | KEY_INSERT,
80 | KEY_DELETE,
81 | KEY_HOME,
82 | KEY_END,
83 | KEY_PAGEUP,
84 | KEY_PAGEDOWN,
85 | KEY_BREAK,
86 | KEY_LSHIFT,
87 | KEY_RSHIFT,
88 | KEY_LALT,
89 | KEY_RALT,
90 | KEY_LCONTROL,
91 | KEY_RCONTROL,
92 | KEY_LWIN,
93 | KEY_RWIN,
94 | KEY_APP,
95 | KEY_UP,
96 | KEY_LEFT,
97 | KEY_DOWN,
98 | KEY_RIGHT,
99 | KEY_F1,
100 | KEY_F2,
101 | KEY_F3,
102 | KEY_F4,
103 | KEY_F5,
104 | KEY_F6,
105 | KEY_F7,
106 | KEY_F8,
107 | KEY_F9,
108 | KEY_F10,
109 | KEY_F11,
110 | KEY_F12,
111 | KEY_CAPSLOCKTOGGLE,
112 | KEY_NUMLOCKTOGGLE,
113 | KEY_SCROLLLOCKTOGGLE,
114 | KEY_LAST = KEY_SCROLLLOCKTOGGLE,
115 | KEY_COUNT = KEY_LAST - KEY_FIRST + 1,
116 | MOUSE_FIRST = KEY_LAST + 1,
117 | MOUSE_LEFT = MOUSE_FIRST,
118 | MOUSE_RIGHT,
119 | MOUSE_MIDDLE,
120 | MOUSE_4,
121 | MOUSE_5,
122 | MOUSE_WHEEL_UP,
123 | MOUSE_WHEEL_DOWN,
124 | MOUSE_LAST = MOUSE_WHEEL_DOWN,
125 | MOUSE_COUNT = MOUSE_LAST - MOUSE_FIRST + 1
126 | };
--------------------------------------------------------------------------------
/include/cstrike/Interfaces/IBaseClientDLL.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | class ClientClass;
4 |
5 | enum ClientFrameStage_t: int {
6 | FRAME_UNDEFINED = -1,
7 | FRAME_START,
8 | FRAME_NET_UPDATE_START,
9 | FRAME_NET_UPDATE_POSTDATAUPDATE_START,
10 | FRAME_NET_UPDATE_POSTDATAUPDATE_END,
11 | FRAME_NET_UPDATE_END,
12 | FRAME_RENDER_START,
13 | FRAME_RENDER_END
14 | };
15 |
16 | class IBaseClientDLL {
17 | public:
18 | ClientClass* GetAllClasses() {
19 | return GetVirtualFunction(this, 8)(this);
20 | }
21 |
22 | void CreateMove(int sequence, float frametime, bool active) {
23 | return GetVirtualFunction(this, 21)(this, sequence, frametime, active);
24 | }
25 |
26 | void FrameStageNotify(ClientFrameStage_t stage) {
27 | return GetVirtualFunction(this, 35)(this, stage);
28 | }
29 | };
30 |
31 | extern IBaseClientDLL* clientdll;
--------------------------------------------------------------------------------
/include/cstrike/Interfaces/IClientEntityList.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | class CBaseHandle;
4 | class IClientEntity;
5 | class IClientNetworkable;
6 | class IClientUnknown;
7 |
8 | class IClientEntityList {
9 | public:
10 | virtual IClientNetworkable* GetClientNetworkable(int entindex) = 0;
11 | virtual IClientNetworkable* GetClientNetworkableFromHandle(CBaseHandle handle) = 0;
12 | virtual IClientUnknown* GetClientUnknownFromHandle(CBaseHandle handle) = 0;
13 | virtual IClientEntity* GetClientEntity(int entindex) = 0;
14 | virtual IClientEntity* GetClientEntityFromHandle(CBaseHandle handle) = 0;
15 | virtual int NumberOfEntities(bool include_non_networkable) = 0;
16 | virtual int GetHighestEntityIndex(void) = 0;
17 | virtual void SetMaxEntities(int max_entities) = 0;
18 | virtual int GetMaxEntities() = 0;
19 | };
20 |
21 | extern IClientEntityList* entitylist;
--------------------------------------------------------------------------------
/include/cstrike/Interfaces/ICvar.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | class ICvar {
4 | public:
5 | template void ConsoleColorPrintf(const Color& MsgColor, const char* Format, Values... Parameters) {
6 | return GetVirtualFunction(this, 23)(this, MsgColor, Format, Parameters...);
7 | }
8 |
9 | template void ConsoleDPrintf(const char* Format, Values... Parameters) {
10 | return GetVirtualFunction(this, 24)(this, Format, Parameters...);
11 | }
12 | };
13 |
14 | extern ICvar* cvar;
--------------------------------------------------------------------------------
/include/cstrike/Interfaces/IEngineVGui.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | enum VGuiPanel_t {
4 | PANEL_ROOT = 0,
5 | PANEL_GAMEUIDLL,
6 | PANEL_CLIENTDLL,
7 | PANEL_TOOLS,
8 | PANEL_INGAMESCREENS,
9 | PANEL_GAMEDLL,
10 | PANEL_CLIENTDLL_TOOLS
11 | };
12 |
13 | enum PaintMode_t {
14 | PAINT_UIPANELS = (1 << 0),
15 | PAINT_INGAMEPANELS = (1 << 1),
16 | PAINT_CURSOR = (1 << 2)
17 | };
18 |
19 | class IEngineVGui {
20 | public:
21 | virtual ~IEngineVGui(void) {};
22 | virtual VPANEL GetPanel(VGuiPanel_t type) = 0;
23 | virtual bool IsGameUIVisible() = 0;
24 | };
25 |
26 | extern IEngineVGui* enginevgui;
--------------------------------------------------------------------------------
/include/cstrike/Interfaces/IGameEventManager2.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #define EVENT_DEBUG_ID_INIT 42
4 | #define EVENT_DEBUG_ID_SHUTDOWN 13
5 |
6 | class bf_read;
7 | class bf_write;
8 |
9 | class IGameEvent {
10 | public:
11 | virtual ~IGameEvent() {};
12 | virtual const char* GetName() const = 0;
13 | virtual bool IsReliable() const = 0;
14 | virtual bool IsLocal() const = 0;
15 | virtual bool IsEmpty(const char* key = 0) = 0;
16 | virtual bool GetBool(const char* key = 0, bool default_value = false) = 0;
17 | virtual int GetInt(const char* key = 0, int default_value = 0) = 0;
18 | virtual float GetFloat(const char* key = 0, float default_value = 0.0f) = 0;
19 | virtual const char* GetString(const char* key = 0, const char* default_value = "") = 0;
20 | virtual void SetBool(const char* key, bool value) = 0;
21 | virtual void SetInt(const char* key, int value) = 0;
22 | virtual void SetFloat(const char* key, float value) = 0;
23 | virtual void SetString(const char* key, const char* value) = 0;
24 | };
25 |
26 | class IGameEventListener2 {
27 | public:
28 | virtual ~IGameEventListener2() {};
29 | virtual void FireGameEvent(IGameEvent* event) = 0;
30 | virtual int GetEventDebugID(void) = 0;
31 | };
32 |
33 | class IGameEventManager2 {
34 | public:
35 | virtual ~IGameEventManager2() {};
36 | virtual int LoadEventsFromFile(const char* filename) = 0;
37 | virtual void Reset() = 0;
38 | virtual bool AddListener(IGameEventListener2* listener, const char* name, bool serverside) = 0;
39 | virtual bool FindListener(IGameEventListener2* listener, const char* name) = 0;
40 | virtual void RemoveListener(IGameEventListener2* listener) = 0;
41 | virtual IGameEvent* CreateEvent(const char* name, bool force = false) = 0;
42 | virtual bool FireEvent(IGameEvent* event, bool dont_broadcast = false) = 0;
43 | virtual bool FireEventClientSide(IGameEvent* event) = 0;
44 | virtual IGameEvent* DuplicateEvent(IGameEvent* event) = 0;
45 | virtual void FreeEvent(IGameEvent* event) = 0;
46 | virtual bool SerializeEvent(IGameEvent* event, bf_write* buf) = 0;
47 | virtual IGameEvent* UnserializeEvent(bf_read* buf) = 0;
48 | };
49 |
50 | extern IGameEventManager2* gameevents;
--------------------------------------------------------------------------------
/include/cstrike/Interfaces/IInputInternal.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | typedef ButtonCode_t KeyCode;
4 | typedef ButtonCode_t MouseCode;
5 |
6 | enum MouseCodeState_t {
7 | BUTTON_RELEASED = 0,
8 | BUTTON_PRESSED,
9 | BUTTON_DOUBLECLICKED
10 | };
11 |
12 | class IInputInternal {
13 | public:
14 | void SetKeyCodeState(KeyCode code, bool down) {
15 | GetVirtualFunction(this, 83)(this, code, down);
16 | }
17 |
18 | void SetMouseCodeState(MouseCode code, MouseCodeState_t state) {
19 | GetVirtualFunction(this, 84)(this, code, state);
20 | }
21 | };
22 |
23 | extern IInputInternal* inputinternal;
--------------------------------------------------------------------------------
/include/cstrike/Interfaces/IInputSystem.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | enum ButtonCode_t;
4 |
5 | class IInputSystem {
6 | public:
7 | bool IsButtonDown(ButtonCode_t button) {
8 | return GetVirtualFunction(this, 11)(this, button);
9 | }
10 | };
11 |
12 | extern IInputSystem* inputsystem;
--------------------------------------------------------------------------------
/include/cstrike/Interfaces/ILauncherMgr.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | class CShowPixelsParams;
4 |
5 | typedef void* PseudoGLContextPtr;
6 |
7 | class ILauncherMgr {
8 | public:
9 | void PumpWindowsMessageLoop() {
10 | return GetVirtualFunction(this, 15)(this);
11 | }
12 |
13 | PseudoGLContextPtr GetMainContext() {
14 | return GetVirtualFunction(this, 22)(this);
15 | }
16 |
17 | PseudoGLContextPtr CreateExtraContext() {
18 | return GetVirtualFunction(this, 24)(this);
19 | }
20 |
21 | void DeleteContext(PseudoGLContextPtr context) {
22 | return GetVirtualFunction(this, 27)(this, context);
23 | }
24 |
25 | bool MakeContextCurrent(PseudoGLContextPtr context) {
26 | return GetVirtualFunction(this, 26)(this, context);
27 | }
28 |
29 | void PumpWindowsMessageLoop(CShowPixelsParams* params) {
30 | return GetVirtualFunction(this, 29)(this, params);
31 | }
32 |
33 | void* GetWindowRef() {
34 | return GetVirtualFunction(this, 32)(this);
35 | }
36 | };
37 |
38 | extern ILauncherMgr* launchermgr;
--------------------------------------------------------------------------------
/include/cstrike/Interfaces/IMaterialSystem.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #define TEXTURE_GROUP_LIGHTMAP "Lightmaps"
4 | #define TEXTURE_GROUP_WORLD "World textures"
5 | #define TEXTURE_GROUP_MODEL "Model textures"
6 | #define TEXTURE_GROUP_VGUI "VGUI textures"
7 | #define TEXTURE_GROUP_PARTICLE "Particle textures"
8 | #define TEXTURE_GROUP_DECAL "Decal textures"
9 | #define TEXTURE_GROUP_SKYBOX "SkyBox textures"
10 | #define TEXTURE_GROUP_CLIENT_EFFECTS "ClientEffect textures"
11 | #define TEXTURE_GROUP_OTHER "Other textures"
12 | #define TEXTURE_GROUP_PRECACHED "Precached"
13 | #define TEXTURE_GROUP_CUBE_MAP "CubeMap textures"
14 | #define TEXTURE_GROUP_RENDER_TARGET "RenderTargets"
15 | #define TEXTURE_GROUP_RUNTIME_COMPOSITE "Runtime Composite"
16 | #define TEXTURE_GROUP_UNACCOUNTED "Unaccounted textures"
17 | #define TEXTURE_GROUP_STATIC_VERTEX_BUFFER "Static Vertex"
18 | #define TEXTURE_GROUP_STATIC_INDEX_BUFFER "Static Indices"
19 | #define TEXTURE_GROUP_STATIC_VERTEX_BUFFER_DISP "Displacement Verts"
20 | #define TEXTURE_GROUP_STATIC_VERTEX_BUFFER_COLOR "Lighting Verts"
21 | #define TEXTURE_GROUP_STATIC_VERTEX_BUFFER_WORLD "World Verts"
22 | #define TEXTURE_GROUP_STATIC_VERTEX_BUFFER_MODELS "Model Verts"
23 | #define TEXTURE_GROUP_STATIC_VERTEX_BUFFER_OTHER "Other Verts"
24 | #define TEXTURE_GROUP_DYNAMIC_INDEX_BUFFER "Dynamic Indices"
25 | #define TEXTURE_GROUP_DYNAMIC_VERTEX_BUFFER "Dynamic Verts"
26 | #define TEXTURE_GROUP_DEPTH_BUFFER "DepthBuffer"
27 | #define TEXTURE_GROUP_VIEW_MODEL "ViewModel"
28 | #define TEXTURE_GROUP_PIXEL_SHADERS "Pixel Shaders"
29 | #define TEXTURE_GROUP_VERTEX_SHADERS "Vertex Shaders"
30 | #define TEXTURE_GROUP_RENDER_TARGET_SURFACE "RenderTarget Surfaces"
31 | #define TEXTURE_GROUP_MORPH_TARGETS "Morph Targets"
32 |
33 | enum MaterialVarFlags_t {
34 | MATERIAL_VAR_DEBUG = (1 << 0),
35 | MATERIAL_VAR_NO_DEBUG_OVERRIDE = (1 << 1),
36 | MATERIAL_VAR_NO_DRAW = (1 << 2),
37 | MATERIAL_VAR_USE_IN_FILLRATE_MODE = (1 << 3),
38 | MATERIAL_VAR_VERTEXCOLOR = (1 << 4),
39 | MATERIAL_VAR_VERTEXALPHA = (1 << 5),
40 | MATERIAL_VAR_SELFILLUM = (1 << 6),
41 | MATERIAL_VAR_ADDITIVE = (1 << 7),
42 | MATERIAL_VAR_ALPHATEST = (1 << 8),
43 | MATERIAL_VAR_MULTIPASS = (1 << 9),
44 | MATERIAL_VAR_ZNEARER = (1 << 10),
45 | MATERIAL_VAR_MODEL = (1 << 11),
46 | MATERIAL_VAR_FLAT = (1 << 12),
47 | MATERIAL_VAR_NOCULL = (1 << 13),
48 | MATERIAL_VAR_NOFOG = (1 << 14),
49 | MATERIAL_VAR_IGNOREZ = (1 << 15),
50 | MATERIAL_VAR_DECAL = (1 << 16),
51 | MATERIAL_VAR_ENVMAPSPHERE = (1 << 17),
52 | MATERIAL_VAR_NOALPHAMOD = (1 << 18),
53 | MATERIAL_VAR_ENVMAPCAMERASPACE = (1 << 19),
54 | MATERIAL_VAR_BASEALPHAENVMAPMASK = (1 << 20),
55 | MATERIAL_VAR_TRANSLUCENT = (1 << 21),
56 | MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK = (1 << 22),
57 | MATERIAL_VAR_NEEDS_SOFTWARE_SKINNING = (1 << 23),
58 | MATERIAL_VAR_OPAQUETEXTURE = (1 << 24),
59 | MATERIAL_VAR_ENVMAPMODE = (1 << 25),
60 | MATERIAL_VAR_SUPPRESS_DECALS = (1 << 26),
61 | MATERIAL_VAR_HALFLAMBERT = (1 << 27),
62 | MATERIAL_VAR_WIREFRAME = (1 << 28),
63 | MATERIAL_VAR_ALLOWALPHATOCOVERAGE = (1 << 29),
64 | MATERIAL_VAR_IGNORE_ALPHA_MODULATION = (1 << 30)
65 | };
66 |
67 | typedef unsigned short MaterialHandle_t;
68 |
69 | class KeyValues;
70 |
71 | class IMaterial {
72 | public:
73 | const char* GetName() {
74 | return GetVirtualFunction(this, 0)(this);
75 | }
76 |
77 | const char* GetTextureGroupName() {
78 | return GetVirtualFunction(this, 1)(this);
79 | }
80 |
81 | void IncrementReferenceCount() {
82 | return GetVirtualFunction(this, 12)(this);
83 | }
84 |
85 | void DecrementReferenceCount() {
86 | return GetVirtualFunction(this, 13)(this);
87 | }
88 |
89 | void AlphaModulate(float alpha) {
90 | return GetVirtualFunction(this, 27)(this, alpha);
91 | }
92 |
93 | void ColorModulate(float red, float green, float blue) {
94 | return GetVirtualFunction(this, 28)(this, red, green, blue);
95 | }
96 |
97 | void SetMaterialVarFlag(MaterialVarFlags_t flags, bool state) {
98 | return GetVirtualFunction(this, 29)(this, flags, state);
99 | }
100 |
101 | bool GetMaterialVarFlag(MaterialVarFlags_t flags) {
102 | return GetVirtualFunction(this, 30)(this, flags);
103 | }
104 |
105 | bool IsErrorMaterial() {
106 | return GetVirtualFunction(this, 42)(this);
107 | }
108 | };
109 |
110 | class IMaterialSystem {
111 | public:
112 | IMaterial* CreateMaterial(const char* name, KeyValues* keyvalues) {
113 | return GetVirtualFunction(this, 70)(this, name, keyvalues);
114 | }
115 |
116 | IMaterial* FindMaterial(char const* name, const char* group, bool complain = true, const char* complain_prefix = NULL) {
117 | return GetVirtualFunction(this, 71)(this, name, group, complain, complain_prefix);
118 | }
119 |
120 | bool IsMaterialLoaded(char const* name) {
121 | return GetVirtualFunction(this, 72)(this, name);
122 | }
123 |
124 | MaterialHandle_t FirstMaterial() {
125 | return GetVirtualFunction(this, 73)(this);
126 | }
127 |
128 | MaterialHandle_t NextMaterial(MaterialHandle_t material) {
129 | return GetVirtualFunction(this, 74)(this, material);
130 | }
131 |
132 | MaterialHandle_t InvalidMaterial() {
133 | return GetVirtualFunction(this, 75)(this);
134 | }
135 |
136 | IMaterial* GetMaterial(MaterialHandle_t material) {
137 | return GetVirtualFunction(this, 76)(this, material);
138 | }
139 | };
140 |
141 | extern IMaterialSystem* matsystem;
--------------------------------------------------------------------------------
/include/cstrike/Interfaces/IPanel.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | typedef unsigned long VPANEL;
4 |
5 | class IPanel {
6 | public:
7 | const char* GetName(VPANEL vpanel) {
8 | return GetVirtualFunction(this, 37)(this, vpanel);
9 | }
10 |
11 | void PaintTraverse(VPANEL vpanel, bool force_repaint, bool allow_force) {
12 | GetVirtualFunction(this, 42)(this, vpanel, force_repaint, allow_force);
13 | }
14 | };
15 |
16 | extern IPanel* panel;
--------------------------------------------------------------------------------
/include/cstrike/Interfaces/ISurface.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | typedef unsigned long HFont;
4 |
5 | enum class FontFeature: int {
6 | FONT_FEATURE_ANTIALIASED_FONTS = 1,
7 | FONT_FEATURE_DROPSHADOW_FONTS = 2,
8 | FONT_FEATURE_OUTLINE_FONTS = 6
9 | };
10 |
11 | enum FontDrawType_t: int {
12 | FONT_DRAW_DEFAULT = 0,
13 | FONT_DRAW_NONADDITIVE,
14 | FONT_DRAW_ADDITIVE,
15 | FONT_DRAW_TYPE_COUNT = 2
16 | };
17 |
18 | enum FontFlags: int {
19 | FONTFLAG_NONE = 0,
20 | FONTFLAG_ITALIC = 0x1,
21 | FONTFLAG_UNDERLINE = 0x2,
22 | FONTFLAG_STRIKEOUT = 0x4,
23 | FONTFLAG_SYMBOL = 0x8,
24 | FONTFLAG_ANTIALIAS = 0x10,
25 | FONTFLAG_GAUSSIANBLUR = 0x20,
26 | FONTFLAG_ROTARY = 0x40,
27 | FONTFLAG_DROPSHADOW = 0x80,
28 | FONTFLAG_ADDITIVE = 0x100,
29 | FONTFLAG_OUTLINE = 0x200,
30 | FONTFLAG_CUSTOM = 0x400,
31 | FONTFLAG_BITMAP = 0x800
32 | };
33 |
34 | class ISurface {
35 | public:
36 | void DrawSetColor(int r, int g, int b, int a) {
37 | GetVirtualFunction(this, 10)(this, r, g, b, a);
38 | }
39 |
40 | void DrawSetColor(Color color) {
41 | GetVirtualFunction(this, 11)(this, color);
42 | }
43 |
44 | void DrawFilledRect(int x0, int y0, int x1, int y1) {
45 | GetVirtualFunction(this, 12)(this, x0, y0, x1, y1);
46 | }
47 |
48 | void DrawOutlinedRect(int x0, int y0, int x1, int y1) {
49 | GetVirtualFunction(this, 14)(this, x0, y0, x1, y1);
50 | }
51 |
52 | void DrawLine(int x0, int y0, int x1, int y1) {
53 | GetVirtualFunction(this, 15)(this, x0, y0, x1, y1);
54 | }
55 |
56 | void DrawSetTextFont(HFont font) {
57 | GetVirtualFunction(this, 17)(this, font);
58 | }
59 |
60 | void DrawSetTextColor(int r, int g, int b, int a) {
61 | GetVirtualFunction(this, 18)(this, r, g, b, a);
62 | }
63 |
64 | void DrawSetTextColor(Color color) {
65 | GetVirtualFunction(this, 19)(this, color);
66 | }
67 |
68 | void DrawSetTextPos(int x, int y) {
69 | GetVirtualFunction(this, 20)(this, x, y);
70 | }
71 |
72 | void DrawPrintText(const wchar_t* text, int length, FontDrawType_t type = FONT_DRAW_DEFAULT) {
73 | return GetVirtualFunction(this, 22)(this, text, length, type);
74 | }
75 |
76 | HFont CreateFont() {
77 | return GetVirtualFunction(this, 66)(this);
78 | }
79 |
80 | void SetFontGlyphSet(HFont& font, const char* name, int tall, int weight, int blur, int scanlines, FontFlags flags = FONTFLAG_NONE) {
81 | GetVirtualFunction(this, 67)(this, font, name, tall, weight, blur, scanlines, flags, 0, 0);
82 | }
83 |
84 | void GetTextSize(HFont font, const wchar_t* text, int& wide, int& tall) {
85 | GetVirtualFunction(this, 75)(this, font, text, wide, tall);
86 | }
87 |
88 | void GetCursorPos(int& x, int& y) {
89 | return GetVirtualFunction(this, 96)(this, x, y);
90 | }
91 |
92 | void DrawOutlinedCircle(int x, int y, int radius, int segments) {
93 | return GetVirtualFunction(this, 99)(this, x, y, radius, segments);
94 | }
95 | };
96 |
97 | extern ISurface* matsurface;
--------------------------------------------------------------------------------
/include/cstrike/Interfaces/IVDebugOverlay.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | class IVDebugOverlay {
4 | public:
5 | bool ScreenPosition(const Vector& world, Vector& screen) {
6 | return GetVirtualFunction(this, 9)(this, world, screen) == 0;
7 | }
8 | };
9 |
10 | extern IVDebugOverlay* debugoverlay;
--------------------------------------------------------------------------------
/include/cstrike/Interfaces/IVEngineClient.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | class IVEngineClient {
4 | public:
5 | void GetScreenSize(int& width, int& height) {
6 | return GetVirtualFunction(this, 5)(this, width, height);
7 | }
8 |
9 | bool GetPlayerInfo(int index, player_info_t* infoptr) {
10 | return GetVirtualFunction(this, 8)(this, index, infoptr);
11 | }
12 |
13 | int GetPlayerForUserID(int userid) {
14 | return GetVirtualFunction(this, 9)(this, userid);
15 | }
16 |
17 | bool Con_IsVisible() {
18 | return GetVirtualFunction(this, 11)(this);
19 | }
20 |
21 | int GetLocalPlayer() {
22 | return GetVirtualFunction(this, 12)(this);
23 | }
24 |
25 | float Time() {
26 | return GetVirtualFunction(this, 14)(this);
27 | }
28 |
29 | float GetLastTimeStamp() {
30 | return GetVirtualFunction(this, 15)(this);
31 | }
32 |
33 | void GetViewAngles(QAngle& angles) {
34 | return GetVirtualFunction(this, 19)(this, angles);
35 | }
36 |
37 | void SetViewAngles(QAngle& angles) {
38 | return GetVirtualFunction(this, 20)(this, angles);
39 | }
40 |
41 | int GetMaxClients() {
42 | return GetVirtualFunction(this, 21)(this);
43 | }
44 |
45 | bool IsInGame() {
46 | return GetVirtualFunction(this, 26)(this);
47 | }
48 |
49 | bool IsConnected() {
50 | return GetVirtualFunction(this, 27)(this);
51 | }
52 |
53 | const char* GetGameDirectory() {
54 | return GetVirtualFunction(this, 35)(this);
55 | }
56 |
57 | const char* GetLevelName() {
58 | return GetVirtualFunction(this, 51)(this);
59 | }
60 |
61 | void ClientCmd_Unrestricted(const char* command) {
62 | return GetVirtualFunction(this, 106)(this, command);
63 | }
64 | };
65 |
66 | extern IVEngineClient* engine;
--------------------------------------------------------------------------------
/include/cstrike/Interfaces/IVModelInfo.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #define MAXSTUDIOBONES 128
4 |
5 | #define BONE_USED_MASK 0x7FF00
6 | #define BONE_USED_BY_ANYTHING 0x7FF00
7 | #define BONE_USED_BY_HITBOX 0x100
8 | #define BONE_USED_BY_ATTACHMENT 0x200
9 | #define BONE_USED_BY_VERTEX_MASK 0x3FC00
10 | #define BONE_USED_BY_VERTEX_LOD0 0x400
11 | #define BONE_USED_BY_VERTEX_LOD1 0x800
12 | #define BONE_USED_BY_VERTEX_LOD2 0x1000
13 | #define BONE_USED_BY_VERTEX_LOD3 0x2000
14 | #define BONE_USED_BY_VERTEX_LOD4 0x4000
15 | #define BONE_USED_BY_VERTEX_LOD5 0x8000
16 | #define BONE_USED_BY_VERTEX_LOD6 0x10000
17 | #define BONE_USED_BY_VERTEX_LOD7 0x20000
18 | #define BONE_USED_BY_BONE_MERGE 0x40000
19 |
20 | struct mstudiobbox_t {
21 | public:
22 | inline const char* GetName() {
23 | if (szhitboxnameindex == 0)
24 | return nullptr;
25 |
26 | return ((const char*)this) + szhitboxnameindex;
27 | }
28 |
29 | int bone;
30 | int group;
31 | Vector bbmin;
32 | Vector bbmax;
33 | int szhitboxnameindex;
34 | int unused[8];
35 | };
36 |
37 | struct mstudiohitboxset_t {
38 | public:
39 | inline const char* GetName() {
40 | return ((const char*)this) + sznameindex;
41 | }
42 |
43 | inline mstudiobbox_t* GetHitbox(int i) const {
44 | return (mstudiobbox_t*)(((unsigned char*)this) + hitboxindex) + i;
45 | };
46 |
47 | int sznameindex;
48 | int numhitboxes;
49 | int hitboxindex;
50 | };
51 |
52 | class studiohdr_t {
53 | public:
54 | inline const mstudiohitboxset_t* GetHitboxSet(int i) {
55 | if (i > numhitboxsets)
56 | return nullptr;
57 |
58 | return (const mstudiohitboxset_t*)((unsigned char*)this + hitboxsetindex) + i;
59 | }
60 |
61 | int id;
62 | int version;
63 | long checksum;
64 | char szName[64];
65 | int length;
66 | Vector vecEyePos;
67 | Vector vecIllumPos;
68 | Vector vecHullMin;
69 | Vector vecHullMax;
70 | Vector vecBBMin;
71 | Vector vecBBMax;
72 | int flags;
73 | int numBones;
74 | int indexBones;
75 | int numbonecontrollers;
76 | int bonecontrollerindex;
77 | int numhitboxsets;
78 | int hitboxsetindex;
79 | int numlocalanim;
80 | int localanimindex;
81 | int numlocalseq;
82 | int localseqindex;
83 | int activitylistversion;
84 | int eventsindexed;
85 | int numtextures;
86 | int textureindex;
87 | };
88 |
89 | class model_t;
90 |
91 | class IVModelInfoClient {
92 | public:
93 | const char* GetModelName(const model_t* model) {
94 | return GetVirtualFunction(this, 4)(this, model);
95 | }
96 |
97 | studiohdr_t* GetStudioModel(const model_t* model) {
98 | return GetVirtualFunction(this, 29)(this, model);
99 | }
100 | };
101 |
102 | extern IVModelInfoClient* modelinfo;
--------------------------------------------------------------------------------
/include/cstrike/Interfaces/IVModelRender.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | typedef unsigned short ModelInstanceHandle_t;
4 |
5 | class model_t;
6 | class studiohdr_t;
7 | class studiohwdata_t;
8 | class IClientRenderable;
9 | class matrix3x4_t;
10 | class StudioDecalHandle_t;
11 | class IMaterial;
12 |
13 | struct DrawModelState_t {
14 | studiohdr_t* m_pStudioHdr;
15 | studiohwdata_t* m_pStudioHWData;
16 | IClientRenderable* m_pRenderable;
17 | const matrix3x4_t* m_pModelToWorld;
18 | StudioDecalHandle_t* m_decals;
19 | int m_drawFlags;
20 | int m_lod;
21 | };
22 |
23 | struct ModelRenderInfo_t {
24 | Vector origin;
25 | QAngle angles;
26 | IClientRenderable* pRenderable;
27 | const model_t* pModel;
28 | const matrix3x4_t* pModelToWorld;
29 | const matrix3x4_t* pLightingOffset;
30 | const Vector* pLightingOrigin;
31 | int flags;
32 | int entity_index;
33 | int skin;
34 | int body;
35 | int hitboxset;
36 | ModelInstanceHandle_t instance;
37 | };
38 |
39 | enum OverrideType_t: int {
40 | OVERRIDE_NORMAL = 0,
41 | OVERRIDE_BUILD_SHADOWS,
42 | OVERRIDE_DEPTH_WRITE,
43 | OVERRIDE_SSAO_DEPTH_WRITE,
44 | };
45 |
46 | class IVModelRender {
47 | public:
48 | void ForcedMaterialOverride(IMaterial* material, OverrideType_t override_type = OVERRIDE_NORMAL) {
49 | GetVirtualFunction(this, 1)(this, material, override_type);
50 | }
51 |
52 | void DrawModelExecute(DrawModelState_t const& state, ModelRenderInfo_t const& info, matrix3x4_t* bone) {
53 | GetVirtualFunction(this, 19)(this, state, info, bone);
54 | }
55 | };
56 |
57 | extern IVModelRender* modelrender;
--------------------------------------------------------------------------------
/include/cstrike/Structures/Color.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | struct Color {
4 | Color(int r, int g, int b, int a = 255) {
5 | value[0] = static_cast(r);
6 | value[1] = static_cast(g);
7 | value[2] = static_cast(b);
8 | value[3] = static_cast(a);
9 | }
10 |
11 | unsigned char value[4];
12 | };
--------------------------------------------------------------------------------
/include/cstrike/Structures/Matrix.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | typedef float VMatrix[4][4];
4 |
5 | class matrix3x4_t {
6 | public:
7 | matrix3x4_t() {};
8 | matrix3x4_t(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23) {
9 | m_flMatVal[0][0] = m00; m_flMatVal[0][1] = m01; m_flMatVal[0][2] = m02; m_flMatVal[0][3] = m03;
10 | m_flMatVal[1][0] = m10; m_flMatVal[1][1] = m11; m_flMatVal[1][2] = m12; m_flMatVal[1][3] = m13;
11 | m_flMatVal[2][0] = m20; m_flMatVal[2][1] = m21; m_flMatVal[2][2] = m22; m_flMatVal[2][3] = m23;
12 | };
13 |
14 | float* operator[](int i) {
15 | return m_flMatVal[i];
16 | }
17 |
18 | const float* operator[](int i) const {
19 | return m_flMatVal[i];
20 | }
21 |
22 | float m_flMatVal[3][4];
23 | };
--------------------------------------------------------------------------------
/include/cstrike/Structures/PlayerInfo.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | typedef struct player_info_s {
4 | char name[MAX_PLAYER_NAME_LENGTH];
5 | int userID;
6 | char guid[SIGNED_GUID_LEN + 1];
7 | uint32_t friendsID;
8 | char friendsName[MAX_PLAYER_NAME_LENGTH];
9 | bool fakeplayer;
10 | bool ishltv;
11 | CRC32_t customFiles[MAX_CUSTOM_FILES];
12 | unsigned char filesDownloaded;
13 | } player_info_t;
--------------------------------------------------------------------------------
/include/cstrike/Structures/Vector.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | struct Vector {
4 | float X = 0.f;
5 | float Y = 0.f;
6 | float Z = 0.f;
7 |
8 | Vector(float X = 0, float Y = 0, float Z = 0) {
9 | this->X = X;
10 | this->Y = Y;
11 | this->Z = Z;
12 | }
13 |
14 | Vector operator + (const Vector& input) {
15 | return Vector(this->X + input.X, this->Y + input.Y, this->Z + input.Z);
16 | }
17 |
18 | Vector operator - (const Vector& input) {
19 | return Vector(this->X - input.X, this->Y - input.Y, this->Z - input.Z);
20 | }
21 |
22 | Vector operator * (const Vector& input) {
23 | return Vector(this->X * input.X, this->Y * input.Y, this->Z * input.Z);
24 | }
25 |
26 | Vector operator / (const Vector& input) {
27 | return Vector(this->X / input.X, this->Y / input.Y, this->Z / input.Z);
28 | }
29 | };
30 |
31 | typedef Vector QAngle;
--------------------------------------------------------------------------------
/include/cstrike/Utilities/CRC32.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #define CRC32_INIT_VALUE 0xFFFFFFFFUL
4 | #define CRC32_XOR_VALUE 0xFFFFFFFFUL
5 |
6 | typedef unsigned int CRC32_t;
7 |
8 | typedef void (*CRC32_ProcessBufferFn) (CRC32_t*, const void*, int);
9 |
10 | extern CRC32_ProcessBufferFn CRC32_ProcessBuffer;
11 |
12 | static void CRC32_Init(CRC32_t* crc) {
13 | *crc = CRC32_INIT_VALUE;
14 | }
15 |
16 | static void CRC32_Final(CRC32_t* crc) {
17 | *crc ^= CRC32_XOR_VALUE;
18 | }
--------------------------------------------------------------------------------
/include/cstrike/Utilities/Virtuals.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | inline void**& GetVirtualTable(void* baseclass) {
4 | return *reinterpret_cast(baseclass);
5 | }
6 |
7 | template inline Fn GetVirtualFunction(void* baseclass, size_t index) {
8 | return reinterpret_cast(GetVirtualTable(baseclass)[index]);
9 | }
--------------------------------------------------------------------------------
/include/cstrike/cstrike.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "Definitions/Flags.h"
4 | #include "Definitions/Input.h"
5 | #include "Definitions/Buttons.h"
6 | #include "Definitions/Const.h"
7 |
8 | #include "Utilities/Virtuals.h"
9 | #include "Utilities/CRC32.h"
10 |
11 | #include "Structures/Color.h"
12 | #include "Structures/Matrix.h"
13 | #include "Structures/Vector.h"
14 | #include "Structures/PlayerInfo.h"
15 |
16 | #include "Classes/CShowPixelsParams.h"
17 | #include "Classes/CUserCmd.h"
18 | #include "Classes/CInput.h"
19 | #include "Classes/CBaseHandle.h"
20 | #include "Classes/CGlobalVarsBase.h"
21 | #include "Classes/ClientClass.h"
22 | #include "Classes/IHandleEntity.h"
23 | #include "Classes/IClientUnknown.h"
24 | #include "Classes/IClientRenderable.h"
25 | #include "Classes/IClientNetworkable.h"
26 | #include "Classes/IClientThinkable.h"
27 | #include "Classes/ICollideable.h"
28 | #include "Classes/IClientEntity.h"
29 | #include "Classes/RecvTable.h"
30 |
31 | #include "Interfaces/ICvar.h"
32 | #include "Interfaces/IPanel.h"
33 | #include "Interfaces/ISurface.h"
34 | #include "Interfaces/IEngineVGui.h"
35 | #include "Interfaces/IVModelInfo.h"
36 | #include "Interfaces/ILauncherMgr.h"
37 | #include "Interfaces/IInputSystem.h"
38 | #include "Interfaces/IInputInternal.h"
39 | #include "Interfaces/IVEngineClient.h"
40 | #include "Interfaces/IVModelRender.h"
41 | #include "Interfaces/IVDebugOverlay.h"
42 | #include "Interfaces/IBaseClientDLL.h"
43 | #include "Interfaces/IMaterialSystem.h"
44 | #include "Interfaces/IClientEntityList.h"
45 | #include "Interfaces/IGameEventManager2.h"
--------------------------------------------------------------------------------
/include/imgui/imconfig.h:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------------
2 | // USER IMPLEMENTATION
3 | // This file contains compile-time options for ImGui.
4 | // Other options (memory allocation overrides, callbacks, etc.) can be set at runtime via the ImGuiIO structure - ImGui::GetIO().
5 | //-----------------------------------------------------------------------------
6 |
7 | #pragma once
8 |
9 | //---- Define assertion handler. Defaults to calling assert().
10 | //#define IM_ASSERT(_EXPR) MyAssert(_EXPR)
11 |
12 | //---- Define attributes of all API symbols declarations, e.g. for DLL under Windows.
13 | //#define IMGUI_API __declspec( dllexport )
14 | //#define IMGUI_API __declspec( dllimport )
15 |
16 | //---- Include imgui_user.h at the end of imgui.h
17 | //#define IMGUI_INCLUDE_IMGUI_USER_H
18 |
19 | //---- Don't implement default handlers for Windows (so as not to link with OpenClipboard() and others Win32 functions)
20 | //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS
21 | //#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCS
22 |
23 | //---- Don't implement help and test window functionality (ShowUserGuide()/ShowStyleEditor()/ShowTestWindow() methods will be empty)
24 | //#define IMGUI_DISABLE_TEST_WINDOWS
25 |
26 | //---- Don't define obsolete functions names
27 | //#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
28 |
29 | //---- Pack colors to BGRA instead of RGBA (remove need to post process vertex buffer in back ends)
30 | //#define IMGUI_USE_BGRA_PACKED_COLOR
31 |
32 | //---- Implement STB libraries in a namespace to avoid conflicts
33 | //#define IMGUI_STB_NAMESPACE ImGuiStb
34 |
35 | //---- Define constructor and implicit cast operators to convert back<>forth from your math types and ImVec2/ImVec4.
36 | /*
37 | #define IM_VEC2_CLASS_EXTRA \
38 | ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \
39 | operator MyVec2() const { return MyVec2(x,y); }
40 |
41 | #define IM_VEC4_CLASS_EXTRA \
42 | ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \
43 | operator MyVec4() const { return MyVec4(x,y,z,w); }
44 | */
45 |
46 | //---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files.
47 | //---- e.g. create variants of the ImGui::Value() helper for your low-level math types, or your own widgets/helpers.
48 | /*
49 | namespace ImGui
50 | {
51 | void Value(const char* prefix, const MyMatrix44& v, const char* float_format = NULL);
52 | }
53 | */
54 |
55 |
--------------------------------------------------------------------------------
/include/imgui/imgui_impl_sdl.cpp:
--------------------------------------------------------------------------------
1 | #include "imgui.h"
2 | #include "imgui_impl_sdl.h"
3 |
4 | static double g_Time = 0.0f;
5 | static bool g_MousePressed[3] = {false, false, false};
6 | static float g_MouseWheel = 0.0f;
7 | static GLuint g_FontTexture = 0;
8 |
9 | void ImGui_ImplSdl_RenderDrawLists(ImDrawData* draw_data) {
10 | ImGuiIO& io = ImGui::GetIO();
11 |
12 | int fb_width = (int)(io.DisplaySize.x * io.DisplayFramebufferScale.x);
13 | int fb_height = (int)(io.DisplaySize.y * io.DisplayFramebufferScale.y);
14 |
15 | if (fb_width == 0 || fb_height == 0)
16 | return;
17 |
18 | draw_data->ScaleClipRects(io.DisplayFramebufferScale);
19 |
20 | GLint last_texture;
21 | glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
22 |
23 | GLint last_viewport[4];
24 | glGetIntegerv(GL_VIEWPORT, last_viewport);
25 |
26 | GLint last_scissor_box[4];
27 | glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box);
28 |
29 | glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT);
30 | glEnable(GL_BLEND);
31 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
32 | glDisable(GL_CULL_FACE);
33 | glDisable(GL_DEPTH_TEST);
34 | glEnable(GL_SCISSOR_TEST);
35 | glEnableClientState(GL_VERTEX_ARRAY);
36 | glEnableClientState(GL_TEXTURE_COORD_ARRAY);
37 | glEnableClientState(GL_COLOR_ARRAY);
38 | glEnable(GL_TEXTURE_2D);
39 |
40 | glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height);
41 | glMatrixMode(GL_PROJECTION);
42 | glPushMatrix();
43 | glLoadIdentity();
44 | glOrtho(0.0f, io.DisplaySize.x, io.DisplaySize.y, 0.0f, -1.0f, +1.0f);
45 | glMatrixMode(GL_MODELVIEW);
46 | glPushMatrix();
47 | glLoadIdentity();
48 |
49 | #define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT))
50 | for (int n = 0; n < draw_data->CmdListsCount; n++) {
51 | const ImDrawList* cmd_list = draw_data->CmdLists[n];
52 | const ImDrawVert* vtx_buffer = cmd_list->VtxBuffer.Data;
53 | const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data;
54 | glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + OFFSETOF(ImDrawVert, pos)));
55 | glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + OFFSETOF(ImDrawVert, uv)));
56 | glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + OFFSETOF(ImDrawVert, col)));
57 |
58 | for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) {
59 | const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
60 | if (pcmd->UserCallback) {
61 | pcmd->UserCallback(cmd_list, pcmd);
62 | } else {
63 | glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId);
64 | glScissor((int)pcmd->ClipRect.x, (int)(fb_height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y));
65 | glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer);
66 | }
67 | idx_buffer += pcmd->ElemCount;
68 | }
69 | }
70 | #undef OFFSETOF
71 |
72 | glDisableClientState(GL_COLOR_ARRAY);
73 | glDisableClientState(GL_TEXTURE_COORD_ARRAY);
74 | glDisableClientState(GL_VERTEX_ARRAY);
75 | glBindTexture(GL_TEXTURE_2D, (GLuint)last_texture);
76 | glMatrixMode(GL_MODELVIEW);
77 | glPopMatrix();
78 | glMatrixMode(GL_PROJECTION);
79 | glPopMatrix();
80 | glPopAttrib();
81 | glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]);
82 | glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3]);
83 | }
84 |
85 | static const char* ImGui_ImplSdl_GetClipboardText(void*) {
86 | return SDL_GetClipboardText();
87 | }
88 |
89 | static void ImGui_ImplSdl_SetClipboardText(void*, const char* text) {
90 | SDL_SetClipboardText(text);
91 | }
92 |
93 | bool ImGui_ImplSdl_ProcessEvent(SDL_Event* event) {
94 | ImGuiIO& io = ImGui::GetIO();
95 |
96 | switch (event->type) {
97 | case SDL_MOUSEWHEEL:
98 | {
99 | if (!io.WantCaptureMouse)
100 | return false;
101 |
102 | if (event->wheel.y > 0)
103 | g_MouseWheel = 1;
104 | if (event->wheel.y < 0)
105 | g_MouseWheel = -1;
106 | return true;
107 | }
108 | case SDL_MOUSEBUTTONDOWN:
109 | {
110 | if (!io.WantCaptureMouse)
111 | return false;
112 |
113 | if (event->button.button == SDL_BUTTON_LEFT) g_MousePressed[0] = true;
114 | if (event->button.button == SDL_BUTTON_RIGHT) g_MousePressed[1] = true;
115 | if (event->button.button == SDL_BUTTON_MIDDLE) g_MousePressed[2] = true;
116 | return true;
117 | }
118 | case SDL_TEXTINPUT:
119 | {
120 | if (!io.WantCaptureKeyboard)
121 | return false;
122 |
123 | io.AddInputCharactersUTF8(event->text.text);
124 | return true;
125 | }
126 | case SDL_KEYDOWN:
127 | case SDL_KEYUP:
128 | {
129 | if (!io.WantCaptureKeyboard)
130 | return false;
131 |
132 | int key = event->key.keysym.sym & ~SDLK_SCANCODE_MASK;
133 | io.KeysDown[key] = (event->type == SDL_KEYDOWN);
134 | io.KeyShift = ((SDL_GetModState() & KMOD_SHIFT) != 0);
135 | io.KeyCtrl = ((SDL_GetModState() & KMOD_CTRL) != 0);
136 | io.KeyAlt = ((SDL_GetModState() & KMOD_ALT) != 0);
137 | io.KeySuper = ((SDL_GetModState() & KMOD_GUI) != 0);
138 | return true;
139 | }
140 | }
141 |
142 | return false;
143 | }
144 |
145 | bool ImGui_ImplSdl_CreateDeviceObjects() {
146 | ImGuiIO& io = ImGui::GetIO();
147 |
148 | unsigned char* pixels;
149 | int width, height;
150 | io.Fonts->GetTexDataAsAlpha8(&pixels, &width, &height);
151 |
152 | GLint last_texture;
153 | glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
154 | glGenTextures(1, &g_FontTexture);
155 | glBindTexture(GL_TEXTURE_2D, g_FontTexture);
156 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
157 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
158 | glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
159 | glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels);
160 |
161 | io.Fonts->TexID = (void *)(intptr_t)g_FontTexture;
162 |
163 | glBindTexture(GL_TEXTURE_2D, last_texture);
164 |
165 | return true;
166 | }
167 |
168 | void ImGui_ImplSdl_InvalidateDeviceObjects() {
169 | if (g_FontTexture) {
170 | glDeleteTextures(1, &g_FontTexture);
171 | ImGui::GetIO().Fonts->TexID = 0;
172 | g_FontTexture = 0;
173 | }
174 | }
175 |
176 | bool ImGui_ImplSdl_Init(SDL_Window* window) {
177 | ImGuiIO& io = ImGui::GetIO();
178 | io.KeyMap[ImGuiKey_Tab] = SDLK_TAB;
179 | io.KeyMap[ImGuiKey_LeftArrow] = SDL_SCANCODE_LEFT;
180 | io.KeyMap[ImGuiKey_RightArrow] = SDL_SCANCODE_RIGHT;
181 | io.KeyMap[ImGuiKey_UpArrow] = SDL_SCANCODE_UP;
182 | io.KeyMap[ImGuiKey_DownArrow] = SDL_SCANCODE_DOWN;
183 | io.KeyMap[ImGuiKey_PageUp] = SDL_SCANCODE_PAGEUP;
184 | io.KeyMap[ImGuiKey_PageDown] = SDL_SCANCODE_PAGEDOWN;
185 | io.KeyMap[ImGuiKey_Home] = SDL_SCANCODE_HOME;
186 | io.KeyMap[ImGuiKey_End] = SDL_SCANCODE_END;
187 | io.KeyMap[ImGuiKey_Delete] = SDLK_DELETE;
188 | io.KeyMap[ImGuiKey_Backspace] = SDLK_BACKSPACE;
189 | io.KeyMap[ImGuiKey_Enter] = SDLK_RETURN;
190 | io.KeyMap[ImGuiKey_Escape] = SDLK_ESCAPE;
191 | io.KeyMap[ImGuiKey_A] = SDLK_a;
192 | io.KeyMap[ImGuiKey_C] = SDLK_c;
193 | io.KeyMap[ImGuiKey_V] = SDLK_v;
194 | io.KeyMap[ImGuiKey_X] = SDLK_x;
195 | io.KeyMap[ImGuiKey_Y] = SDLK_y;
196 | io.KeyMap[ImGuiKey_Z] = SDLK_z;
197 |
198 | io.RenderDrawListsFn = ImGui_ImplSdl_RenderDrawLists;
199 | io.SetClipboardTextFn = ImGui_ImplSdl_SetClipboardText;
200 | io.GetClipboardTextFn = ImGui_ImplSdl_GetClipboardText;
201 | io.ClipboardUserData = NULL;
202 |
203 | (void)window;
204 |
205 | return true;
206 | }
207 |
208 | void ImGui_ImplSdl_Shutdown() {
209 | ImGui_ImplSdl_InvalidateDeviceObjects();
210 | ImGui::Shutdown();
211 | }
212 |
213 | void ImGui_ImplSdl_NewFrame(SDL_Window *window) {
214 | if (!g_FontTexture)
215 | ImGui_ImplSdl_CreateDeviceObjects();
216 |
217 | ImGuiIO& io = ImGui::GetIO();
218 |
219 | int w, h, display_w, display_h;
220 |
221 | SDL_GetWindowSize(window, &w, &h);
222 | SDL_GL_GetDrawableSize(window, &display_w, &display_h);
223 |
224 | io.DisplaySize = ImVec2((float)w, (float)h);
225 | io.DisplayFramebufferScale = ImVec2(w > 0 ? ((float)display_w / w) : 0, h > 0 ? ((float)display_h / h) : 0);
226 |
227 | Uint32 time = SDL_GetTicks();
228 | double current_time = time / 1000.0;
229 | io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f / 60.0f);
230 | g_Time = current_time;
231 |
232 | if (io.WantCaptureMouse)
233 | {
234 | int mx, my;
235 | Uint32 mouseMask = SDL_GetMouseState(&mx, &my);
236 |
237 | if (SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_FOCUS)
238 | io.MousePos = ImVec2((float)mx, (float)my);
239 | else
240 | io.MousePos = ImVec2(-1, -1);
241 |
242 | io.MouseDown[0] = g_MousePressed[0] || (mouseMask & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0;
243 | io.MouseDown[1] = g_MousePressed[1] || (mouseMask & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0;
244 | io.MouseDown[2] = g_MousePressed[2] || (mouseMask & SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0;
245 | g_MousePressed[0] = g_MousePressed[1] = g_MousePressed[2] = false;
246 |
247 | io.MouseWheel = g_MouseWheel;
248 | g_MouseWheel = 0.0f;
249 |
250 | SDL_ShowCursor(io.MouseDrawCursor ? 0: 1);
251 | }
252 |
253 | ImGui::NewFrame();
254 | }
--------------------------------------------------------------------------------
/include/imgui/imgui_impl_sdl.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 |
6 | struct SDL_Window;
7 | typedef union SDL_Event SDL_Event;
8 |
9 | IMGUI_API bool ImGui_ImplSdl_Init(SDL_Window* window);
10 | IMGUI_API void ImGui_ImplSdl_Shutdown();
11 | IMGUI_API void ImGui_ImplSdl_NewFrame(SDL_Window* window);
12 | IMGUI_API bool ImGui_ImplSdl_ProcessEvent(SDL_Event* event);
13 |
14 | IMGUI_API void ImGui_ImplSdl_InvalidateDeviceObjects();
15 | IMGUI_API bool ImGui_ImplSdl_CreateDeviceObjects();
--------------------------------------------------------------------------------
/include/imgui/imgui_internal.h:
--------------------------------------------------------------------------------
1 | // dear imgui, v1.50 WIP
2 | // (internals)
3 |
4 | // You may use this file to debug, understand or extend ImGui features but we don't provide any guarantee of forward compatibility!
5 | // Implement maths operators for ImVec2 (disabled by default to not collide with using IM_VEC2_CLASS_EXTRA along with your own math types+operators)
6 | // #define IMGUI_DEFINE_MATH_OPERATORS
7 |
8 | #pragma once
9 |
10 | #ifndef IMGUI_VERSION
11 | #error Must include imgui.h before imgui_internal.h
12 | #endif
13 |
14 | #include // FILE*
15 | #include // sqrtf, fabsf, fmodf, powf, floorf, ceilf, cosf, sinf
16 |
17 | #ifdef _MSC_VER
18 | #pragma warning (push)
19 | #pragma warning (disable: 4251) // class 'xxx' needs to have dll-interface to be used by clients of struct 'xxx' // when IMGUI_API is set to__declspec(dllexport)
20 | #endif
21 |
22 | #ifdef __clang__
23 | #pragma clang diagnostic push
24 | #pragma clang diagnostic ignored "-Wunused-function" // for stb_textedit.h
25 | #pragma clang diagnostic ignored "-Wmissing-prototypes" // for stb_textedit.h
26 | #pragma clang diagnostic ignored "-Wold-style-cast"
27 | #endif
28 |
29 | //-----------------------------------------------------------------------------
30 | // Forward Declarations
31 | //-----------------------------------------------------------------------------
32 |
33 | struct ImRect;
34 | struct ImGuiColMod;
35 | struct ImGuiStyleMod;
36 | struct ImGuiGroupData;
37 | struct ImGuiSimpleColumns;
38 | struct ImGuiDrawContext;
39 | struct ImGuiTextEditState;
40 | struct ImGuiIniData;
41 | struct ImGuiMouseCursorData;
42 | struct ImGuiPopupRef;
43 | struct ImGuiWindow;
44 |
45 | typedef int ImGuiLayoutType; // enum ImGuiLayoutType_
46 | typedef int ImGuiButtonFlags; // enum ImGuiButtonFlags_
47 | typedef int ImGuiTreeNodeFlags; // enum ImGuiTreeNodeFlags_
48 | typedef int ImGuiSliderFlags; // enum ImGuiSliderFlags_
49 |
50 | //-------------------------------------------------------------------------
51 | // STB libraries
52 | //-------------------------------------------------------------------------
53 |
54 | namespace ImGuiStb
55 | {
56 |
57 | #undef STB_TEXTEDIT_STRING
58 | #undef STB_TEXTEDIT_CHARTYPE
59 | #define STB_TEXTEDIT_STRING ImGuiTextEditState
60 | #define STB_TEXTEDIT_CHARTYPE ImWchar
61 | #define STB_TEXTEDIT_GETWIDTH_NEWLINE -1.0f
62 | #include "stb_textedit.h"
63 |
64 | } // namespace ImGuiStb
65 |
66 | //-----------------------------------------------------------------------------
67 | // Context
68 | //-----------------------------------------------------------------------------
69 |
70 | #ifndef GImGui
71 | extern IMGUI_API ImGuiContext* GImGui; // Current implicit ImGui context pointer
72 | #endif
73 |
74 | //-----------------------------------------------------------------------------
75 | // Helpers
76 | //-----------------------------------------------------------------------------
77 |
78 | #define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR)/sizeof(*_ARR)))
79 | #define IM_PI 3.14159265358979323846f
80 | #define IM_OFFSETOF(_TYPE,_ELM) ((size_t)&(((_TYPE*)0)->_ELM))
81 |
82 | // Helpers: UTF-8 <> wchar
83 | IMGUI_API int ImTextStrToUtf8(char* buf, int buf_size, const ImWchar* in_text, const ImWchar* in_text_end); // return output UTF-8 bytes count
84 | IMGUI_API int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end); // return input UTF-8 bytes count
85 | IMGUI_API int ImTextStrFromUtf8(ImWchar* buf, int buf_size, const char* in_text, const char* in_text_end, const char** in_remaining = NULL); // return input UTF-8 bytes count
86 | IMGUI_API int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end); // return number of UTF-8 code-points (NOT bytes count)
87 | IMGUI_API int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_end); // return number of bytes to express string as UTF-8 code-points
88 |
89 | // Helpers: Misc
90 | IMGUI_API ImU32 ImHash(const void* data, int data_size, ImU32 seed = 0); // Pass data_size==0 for zero-terminated strings
91 | IMGUI_API void* ImLoadFileToMemory(const char* filename, const char* file_open_mode, int* out_file_size = NULL, int padding_bytes = 0);
92 | IMGUI_API FILE* ImOpenFile(const char* filename, const char* file_open_mode);
93 | IMGUI_API bool ImIsPointInTriangle(const ImVec2& p, const ImVec2& a, const ImVec2& b, const ImVec2& c);
94 | static inline bool ImCharIsSpace(int c) { return c == ' ' || c == '\t' || c == 0x3000; }
95 | static inline int ImUpperPowerOfTwo(int v) { v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++; return v; }
96 |
97 | // Helpers: String
98 | IMGUI_API int ImStricmp(const char* str1, const char* str2);
99 | IMGUI_API int ImStrnicmp(const char* str1, const char* str2, int count);
100 | IMGUI_API char* ImStrdup(const char* str);
101 | IMGUI_API int ImStrlenW(const ImWchar* str);
102 | IMGUI_API const ImWchar*ImStrbolW(const ImWchar* buf_mid_line, const ImWchar* buf_begin); // Find beginning-of-line
103 | IMGUI_API const char* ImStristr(const char* haystack, const char* haystack_end, const char* needle, const char* needle_end);
104 | IMGUI_API int ImFormatString(char* buf, int buf_size, const char* fmt, ...) IM_PRINTFARGS(3);
105 | IMGUI_API int ImFormatStringV(char* buf, int buf_size, const char* fmt, va_list args);
106 |
107 | // Helpers: Math
108 | // We are keeping those not leaking to the user by default, in the case the user has implicit cast operators between ImVec2 and its own types (when IM_VEC2_CLASS_EXTRA is defined)
109 | #ifdef IMGUI_DEFINE_MATH_OPERATORS
110 | static inline ImVec2 operator*(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x*rhs, lhs.y*rhs); }
111 | static inline ImVec2 operator/(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x/rhs, lhs.y/rhs); }
112 | static inline ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x+rhs.x, lhs.y+rhs.y); }
113 | static inline ImVec2 operator-(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x-rhs.x, lhs.y-rhs.y); }
114 | static inline ImVec2 operator*(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x*rhs.x, lhs.y*rhs.y); }
115 | static inline ImVec2 operator/(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x/rhs.x, lhs.y/rhs.y); }
116 | static inline ImVec2& operator+=(ImVec2& lhs, const ImVec2& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; }
117 | static inline ImVec2& operator-=(ImVec2& lhs, const ImVec2& rhs) { lhs.x -= rhs.x; lhs.y -= rhs.y; return lhs; }
118 | static inline ImVec2& operator*=(ImVec2& lhs, const float rhs) { lhs.x *= rhs; lhs.y *= rhs; return lhs; }
119 | static inline ImVec2& operator/=(ImVec2& lhs, const float rhs) { lhs.x /= rhs; lhs.y /= rhs; return lhs; }
120 | static inline ImVec4 operator-(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x-rhs.x, lhs.y-rhs.y, lhs.z-rhs.z, lhs.w-rhs.w); }
121 | #endif
122 |
123 | static inline int ImMin(int lhs, int rhs) { return lhs < rhs ? lhs : rhs; }
124 | static inline int ImMax(int lhs, int rhs) { return lhs >= rhs ? lhs : rhs; }
125 | static inline float ImMin(float lhs, float rhs) { return lhs < rhs ? lhs : rhs; }
126 | static inline float ImMax(float lhs, float rhs) { return lhs >= rhs ? lhs : rhs; }
127 | static inline ImVec2 ImMin(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(ImMin(lhs.x,rhs.x), ImMin(lhs.y,rhs.y)); }
128 | static inline ImVec2 ImMax(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(ImMax(lhs.x,rhs.x), ImMax(lhs.y,rhs.y)); }
129 | static inline int ImClamp(int v, int mn, int mx) { return (v < mn) ? mn : (v > mx) ? mx : v; }
130 | static inline float ImClamp(float v, float mn, float mx) { return (v < mn) ? mn : (v > mx) ? mx : v; }
131 | static inline ImVec2 ImClamp(const ImVec2& f, const ImVec2& mn, ImVec2 mx) { return ImVec2(ImClamp(f.x,mn.x,mx.x), ImClamp(f.y,mn.y,mx.y)); }
132 | static inline float ImSaturate(float f) { return (f < 0.0f) ? 0.0f : (f > 1.0f) ? 1.0f : f; }
133 | static inline float ImLerp(float a, float b, float t) { return a + (b - a) * t; }
134 | static inline ImVec2 ImLerp(const ImVec2& a, const ImVec2& b, const ImVec2& t) { return ImVec2(a.x + (b.x - a.x) * t.x, a.y + (b.y - a.y) * t.y); }
135 | static inline float ImLengthSqr(const ImVec2& lhs) { return lhs.x*lhs.x + lhs.y*lhs.y; }
136 | static inline float ImLengthSqr(const ImVec4& lhs) { return lhs.x*lhs.x + lhs.y*lhs.y + lhs.z*lhs.z + lhs.w*lhs.w; }
137 | static inline float ImInvLength(const ImVec2& lhs, float fail_value) { float d = lhs.x*lhs.x + lhs.y*lhs.y; if (d > 0.0f) return 1.0f / sqrtf(d); return fail_value; }
138 | static inline float ImFloor(float f) { return (float)(int)f; }
139 | static inline ImVec2 ImFloor(ImVec2 v) { return ImVec2((float)(int)v.x, (float)(int)v.y); }
140 |
141 | // We call C++ constructor on own allocated memory via the placement "new(ptr) Type()" syntax.
142 | // Defining a custom placement new() with a dummy parameter allows us to bypass including which on some platforms complains when user has disabled exceptions.
143 | #ifdef IMGUI_DEFINE_PLACEMENT_NEW
144 | struct ImPlacementNewDummy {};
145 | inline void* operator new(size_t, ImPlacementNewDummy, void* ptr) { return ptr; }
146 | inline void operator delete(void*, ImPlacementNewDummy, void*) {}
147 | #define IM_PLACEMENT_NEW(_PTR) new(ImPlacementNewDummy(), _PTR)
148 | #endif
149 |
150 | //-----------------------------------------------------------------------------
151 | // Types
152 | //-----------------------------------------------------------------------------
153 |
154 | enum ImGuiButtonFlags_
155 | {
156 | ImGuiButtonFlags_Repeat = 1 << 0, // hold to repeat
157 | ImGuiButtonFlags_PressedOnClickRelease = 1 << 1, // (default) return pressed on click+release on same item (default if no PressedOn** flag is set)
158 | ImGuiButtonFlags_PressedOnClick = 1 << 2, // return pressed on click (default requires click+release)
159 | ImGuiButtonFlags_PressedOnRelease = 1 << 3, // return pressed on release (default requires click+release)
160 | ImGuiButtonFlags_PressedOnDoubleClick = 1 << 4, // return pressed on double-click (default requires click+release)
161 | ImGuiButtonFlags_FlattenChilds = 1 << 5, // allow interaction even if a child window is overlapping
162 | ImGuiButtonFlags_DontClosePopups = 1 << 6, // disable automatically closing parent popup on press
163 | ImGuiButtonFlags_Disabled = 1 << 7, // disable interaction
164 | ImGuiButtonFlags_AlignTextBaseLine = 1 << 8, // vertically align button to match text baseline - ButtonEx() only
165 | ImGuiButtonFlags_NoKeyModifiers = 1 << 9, // disable interaction if a key modifier is held
166 | ImGuiButtonFlags_AllowOverlapMode = 1 << 10 // require previous frame HoveredId to either match id or be null before being usable
167 | };
168 |
169 | enum ImGuiSliderFlags_
170 | {
171 | ImGuiSliderFlags_Vertical = 1 << 0
172 | };
173 |
174 | enum ImGuiSelectableFlagsPrivate_
175 | {
176 | // NB: need to be in sync with last value of ImGuiSelectableFlags_
177 | ImGuiSelectableFlags_Menu = 1 << 3,
178 | ImGuiSelectableFlags_MenuItem = 1 << 4,
179 | ImGuiSelectableFlags_Disabled = 1 << 5,
180 | ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 6
181 | };
182 |
183 | // FIXME: this is in development, not exposed/functional as a generic feature yet.
184 | enum ImGuiLayoutType_
185 | {
186 | ImGuiLayoutType_Vertical,
187 | ImGuiLayoutType_Horizontal
188 | };
189 |
190 | enum ImGuiPlotType
191 | {
192 | ImGuiPlotType_Lines,
193 | ImGuiPlotType_Histogram
194 | };
195 |
196 | enum ImGuiDataType
197 | {
198 | ImGuiDataType_Int,
199 | ImGuiDataType_Float,
200 | ImGuiDataType_Float2,
201 | };
202 |
203 | enum ImGuiCorner
204 | {
205 | ImGuiCorner_TopLeft = 1 << 0, // 1
206 | ImGuiCorner_TopRight = 1 << 1, // 2
207 | ImGuiCorner_BottomRight = 1 << 2, // 4
208 | ImGuiCorner_BottomLeft = 1 << 3, // 8
209 | ImGuiCorner_All = 0x0F
210 | };
211 |
212 | // 2D axis aligned bounding-box
213 | // NB: we can't rely on ImVec2 math operators being available here
214 | struct IMGUI_API ImRect
215 | {
216 | ImVec2 Min; // Upper-left
217 | ImVec2 Max; // Lower-right
218 |
219 | ImRect() : Min(FLT_MAX,FLT_MAX), Max(-FLT_MAX,-FLT_MAX) {}
220 | ImRect(const ImVec2& min, const ImVec2& max) : Min(min), Max(max) {}
221 | ImRect(const ImVec4& v) : Min(v.x, v.y), Max(v.z, v.w) {}
222 | ImRect(float x1, float y1, float x2, float y2) : Min(x1, y1), Max(x2, y2) {}
223 |
224 | ImVec2 GetCenter() const { return ImVec2((Min.x+Max.x)*0.5f, (Min.y+Max.y)*0.5f); }
225 | ImVec2 GetSize() const { return ImVec2(Max.x-Min.x, Max.y-Min.y); }
226 | float GetWidth() const { return Max.x-Min.x; }
227 | float GetHeight() const { return Max.y-Min.y; }
228 | ImVec2 GetTL() const { return Min; } // Top-left
229 | ImVec2 GetTR() const { return ImVec2(Max.x, Min.y); } // Top-right
230 | ImVec2 GetBL() const { return ImVec2(Min.x, Max.y); } // Bottom-left
231 | ImVec2 GetBR() const { return Max; } // Bottom-right
232 | bool Contains(const ImVec2& p) const { return p.x >= Min.x && p.y >= Min.y && p.x < Max.x && p.y < Max.y; }
233 | bool Contains(const ImRect& r) const { return r.Min.x >= Min.x && r.Min.y >= Min.y && r.Max.x < Max.x && r.Max.y < Max.y; }
234 | bool Overlaps(const ImRect& r) const { return r.Min.y < Max.y && r.Max.y > Min.y && r.Min.x < Max.x && r.Max.x > Min.x; }
235 | void Add(const ImVec2& rhs) { if (Min.x > rhs.x) Min.x = rhs.x; if (Min.y > rhs.y) Min.y = rhs.y; if (Max.x < rhs.x) Max.x = rhs.x; if (Max.y < rhs.y) Max.y = rhs.y; }
236 | void Add(const ImRect& rhs) { if (Min.x > rhs.Min.x) Min.x = rhs.Min.x; if (Min.y > rhs.Min.y) Min.y = rhs.Min.y; if (Max.x < rhs.Max.x) Max.x = rhs.Max.x; if (Max.y < rhs.Max.y) Max.y = rhs.Max.y; }
237 | void Expand(const float amount) { Min.x -= amount; Min.y -= amount; Max.x += amount; Max.y += amount; }
238 | void Expand(const ImVec2& amount) { Min.x -= amount.x; Min.y -= amount.y; Max.x += amount.x; Max.y += amount.y; }
239 | void Reduce(const ImVec2& amount) { Min.x += amount.x; Min.y += amount.y; Max.x -= amount.x; Max.y -= amount.y; }
240 | void Clip(const ImRect& clip) { if (Min.x < clip.Min.x) Min.x = clip.Min.x; if (Min.y < clip.Min.y) Min.y = clip.Min.y; if (Max.x > clip.Max.x) Max.x = clip.Max.x; if (Max.y > clip.Max.y) Max.y = clip.Max.y; }
241 | void Floor() { Min.x = (float)(int)Min.x; Min.y = (float)(int)Min.y; Max.x = (float)(int)Max.x; Max.y = (float)(int)Max.y; }
242 | ImVec2 GetClosestPoint(ImVec2 p, bool on_edge) const
243 | {
244 | if (!on_edge && Contains(p))
245 | return p;
246 | if (p.x > Max.x) p.x = Max.x;
247 | else if (p.x < Min.x) p.x = Min.x;
248 | if (p.y > Max.y) p.y = Max.y;
249 | else if (p.y < Min.y) p.y = Min.y;
250 | return p;
251 | }
252 | };
253 |
254 | // Stacked color modifier, backup of modified data so we can restore it
255 | struct ImGuiColMod
256 | {
257 | ImGuiCol Col;
258 | ImVec4 BackupValue;
259 | };
260 |
261 | // Stacked style modifier, backup of modified data so we can restore it. Data type inferred from the variable.
262 | struct ImGuiStyleMod
263 | {
264 | ImGuiStyleVar VarIdx;
265 | union { int BackupInt[2]; float BackupFloat[2]; };
266 | ImGuiStyleMod(ImGuiStyleVar idx, int v) { VarIdx = idx; BackupInt[0] = v; }
267 | ImGuiStyleMod(ImGuiStyleVar idx, float v) { VarIdx = idx; BackupFloat[0] = v; }
268 | ImGuiStyleMod(ImGuiStyleVar idx, ImVec2 v) { VarIdx = idx; BackupFloat[0] = v.x; BackupFloat[1] = v.y; }
269 | };
270 |
271 | // Stacked data for BeginGroup()/EndGroup()
272 | struct ImGuiGroupData
273 | {
274 | ImVec2 BackupCursorPos;
275 | ImVec2 BackupCursorMaxPos;
276 | float BackupIndentX;
277 | float BackupGroupOffsetX;
278 | float BackupCurrentLineHeight;
279 | float BackupCurrentLineTextBaseOffset;
280 | float BackupLogLinePosY;
281 | bool BackupActiveIdIsAlive;
282 | bool AdvanceCursor;
283 | };
284 |
285 | // Per column data for Columns()
286 | struct ImGuiColumnData
287 | {
288 | float OffsetNorm; // Column start offset, normalized 0.0 (far left) -> 1.0 (far right)
289 | //float IndentX;
290 | };
291 |
292 | // Simple column measurement currently used for MenuItem() only. This is very short-sighted/throw-away code and NOT a generic helper.
293 | struct IMGUI_API ImGuiSimpleColumns
294 | {
295 | int Count;
296 | float Spacing;
297 | float Width, NextWidth;
298 | float Pos[8], NextWidths[8];
299 |
300 | ImGuiSimpleColumns();
301 | void Update(int count, float spacing, bool clear);
302 | float DeclColumns(float w0, float w1, float w2);
303 | float CalcExtraSpace(float avail_w);
304 | };
305 |
306 | // Internal state of the currently focused/edited text input box
307 | struct IMGUI_API ImGuiTextEditState
308 | {
309 | ImGuiID Id; // widget id owning the text state
310 | ImVector Text; // edit buffer, we need to persist but can't guarantee the persistence of the user-provided buffer. so we copy into own buffer.
311 | ImVector InitialText; // backup of end-user buffer at the time of focus (in UTF-8, unaltered)
312 | ImVector TempTextBuffer;
313 | int CurLenA, CurLenW; // we need to maintain our buffer length in both UTF-8 and wchar format.
314 | int BufSizeA; // end-user buffer size
315 | float ScrollX;
316 | ImGuiStb::STB_TexteditState StbState;
317 | float CursorAnim;
318 | bool CursorFollow;
319 | bool SelectedAllMouseLock;
320 |
321 | ImGuiTextEditState() { memset(this, 0, sizeof(*this)); }
322 | void CursorAnimReset() { CursorAnim = -0.30f; } // After a user-input the cursor stays on for a while without blinking
323 | void CursorClamp() { StbState.cursor = ImMin(StbState.cursor, CurLenW); StbState.select_start = ImMin(StbState.select_start, CurLenW); StbState.select_end = ImMin(StbState.select_end, CurLenW); }
324 | bool HasSelection() const { return StbState.select_start != StbState.select_end; }
325 | void ClearSelection() { StbState.select_start = StbState.select_end = StbState.cursor; }
326 | void SelectAll() { StbState.select_start = 0; StbState.select_end = CurLenW; StbState.cursor = StbState.select_end; StbState.has_preferred_x = false; }
327 | void OnKeyPressed(int key);
328 | };
329 |
330 | // Data saved in imgui.ini file
331 | struct ImGuiIniData
332 | {
333 | char* Name;
334 | ImGuiID Id;
335 | ImVec2 Pos;
336 | ImVec2 Size;
337 | bool Collapsed;
338 | };
339 |
340 | // Mouse cursor data (used when io.MouseDrawCursor is set)
341 | struct ImGuiMouseCursorData
342 | {
343 | ImGuiMouseCursor Type;
344 | ImVec2 HotOffset;
345 | ImVec2 Size;
346 | ImVec2 TexUvMin[2];
347 | ImVec2 TexUvMax[2];
348 | };
349 |
350 | // Storage for current popup stack
351 | struct ImGuiPopupRef
352 | {
353 | ImGuiID PopupId; // Set on OpenPopup()
354 | ImGuiWindow* Window; // Resolved on BeginPopup() - may stay unresolved if user never calls OpenPopup()
355 | ImGuiWindow* ParentWindow; // Set on OpenPopup()
356 | ImGuiID ParentMenuSet; // Set on OpenPopup()
357 | ImVec2 MousePosOnOpen; // Copy of mouse position at the time of opening popup
358 |
359 | ImGuiPopupRef(ImGuiID id, ImGuiWindow* parent_window, ImGuiID parent_menu_set, const ImVec2& mouse_pos) { PopupId = id; Window = NULL; ParentWindow = parent_window; ParentMenuSet = parent_menu_set; MousePosOnOpen = mouse_pos; }
360 | };
361 |
362 | // Main state for ImGui
363 | struct ImGuiContext
364 | {
365 | bool Initialized;
366 | ImGuiIO IO;
367 | ImGuiStyle Style;
368 | ImFont* Font; // (Shortcut) == FontStack.empty() ? IO.Font : FontStack.back()
369 | float FontSize; // (Shortcut) == FontBaseSize * g.CurrentWindow->FontWindowScale == window->FontSize()
370 | float FontBaseSize; // (Shortcut) == IO.FontGlobalScale * Font->Scale * Font->FontSize. Size of characters.
371 | ImVec2 FontTexUvWhitePixel; // (Shortcut) == Font->TexUvWhitePixel
372 |
373 | float Time;
374 | int FrameCount;
375 | int FrameCountEnded;
376 | int FrameCountRendered;
377 | ImVector Windows;
378 | ImVector WindowsSortBuffer;
379 | ImGuiWindow* CurrentWindow; // Being drawn into
380 | ImVector CurrentWindowStack;
381 | ImGuiWindow* FocusedWindow; // Will catch keyboard inputs
382 | ImGuiWindow* HoveredWindow; // Will catch mouse inputs
383 | ImGuiWindow* HoveredRootWindow; // Will catch mouse inputs (for focus/move only)
384 | ImGuiID HoveredId; // Hovered widget
385 | bool HoveredIdAllowOverlap;
386 | ImGuiID HoveredIdPreviousFrame;
387 | ImGuiID ActiveId; // Active widget
388 | ImGuiID ActiveIdPreviousFrame;
389 | bool ActiveIdIsAlive;
390 | bool ActiveIdIsJustActivated; // Set at the time of activation for one frame
391 | bool ActiveIdAllowOverlap; // Set only by active widget
392 | ImVec2 ActiveIdClickOffset; // Clicked offset from upper-left corner, if applicable (currently only set by ButtonBehavior)
393 | ImGuiWindow* ActiveIdWindow;
394 | ImGuiWindow* MovedWindow; // Track the child window we clicked on to move a window.
395 | ImGuiID MovedWindowMoveId; // == MovedWindow->RootWindow->MoveId
396 | ImVector Settings; // .ini Settings
397 | float SettingsDirtyTimer; // Save .ini Settings on disk when time reaches zero
398 | ImVector ColorModifiers; // Stack for PushStyleColor()/PopStyleColor()
399 | ImVector StyleModifiers; // Stack for PushStyleVar()/PopStyleVar()
400 | ImVector FontStack; // Stack for PushFont()/PopFont()
401 | ImVector OpenPopupStack; // Which popups are open (persistent)
402 | ImVector CurrentPopupStack; // Which level of BeginPopup() we are in (reset every frame)
403 |
404 | // Storage for SetNexWindow** and SetNextTreeNode*** functions
405 | ImVec2 SetNextWindowPosVal;
406 | ImVec2 SetNextWindowSizeVal;
407 | ImVec2 SetNextWindowContentSizeVal;
408 | bool SetNextWindowCollapsedVal;
409 | ImGuiSetCond SetNextWindowPosCond;
410 | ImGuiSetCond SetNextWindowSizeCond;
411 | ImGuiSetCond SetNextWindowContentSizeCond;
412 | ImGuiSetCond SetNextWindowCollapsedCond;
413 | ImRect SetNextWindowSizeConstraintRect; // Valid if 'SetNextWindowSizeConstraint' is true
414 | ImGuiSizeConstraintCallback SetNextWindowSizeConstraintCallback;
415 | void* SetNextWindowSizeConstraintCallbackUserData;
416 | bool SetNextWindowSizeConstraint;
417 | bool SetNextWindowFocus;
418 | bool SetNextTreeNodeOpenVal;
419 | ImGuiSetCond SetNextTreeNodeOpenCond;
420 |
421 | // Render
422 | ImDrawData RenderDrawData; // Main ImDrawData instance to pass render information to the user
423 | ImVector RenderDrawLists[3];
424 | float ModalWindowDarkeningRatio;
425 | ImDrawList OverlayDrawList; // Optional software render of mouse cursors, if io.MouseDrawCursor is set + a few debug overlays
426 | ImGuiMouseCursor MouseCursor;
427 | ImGuiMouseCursorData MouseCursorData[ImGuiMouseCursor_Count_];
428 |
429 | // Widget state
430 | ImGuiTextEditState InputTextState;
431 | ImFont InputTextPasswordFont;
432 | ImGuiID ScalarAsInputTextId; // Temporary text input when CTRL+clicking on a slider, etc.
433 | ImGuiStorage ColorEditModeStorage; // Store user selection of color edit mode
434 | float DragCurrentValue; // Currently dragged value, always float, not rounded by end-user precision settings
435 | ImVec2 DragLastMouseDelta;
436 | float DragSpeedDefaultRatio; // If speed == 0.0f, uses (max-min) * DragSpeedDefaultRatio
437 | float DragSpeedScaleSlow;
438 | float DragSpeedScaleFast;
439 | ImVec2 ScrollbarClickDeltaToGrabCenter; // Distance between mouse and center of grab box, normalized in parent space. Use storage?
440 | char Tooltip[1024];
441 | char* PrivateClipboard; // If no custom clipboard handler is defined
442 | ImVec2 OsImePosRequest, OsImePosSet; // Cursor position request & last passed to the OS Input Method Editor
443 |
444 | // Logging
445 | bool LogEnabled;
446 | FILE* LogFile; // If != NULL log to stdout/ file
447 | ImGuiTextBuffer* LogClipboard; // Else log to clipboard. This is pointer so our GImGui static constructor doesn't call heap allocators.
448 | int LogStartDepth;
449 | int LogAutoExpandMaxDepth;
450 |
451 | // Misc
452 | float FramerateSecPerFrame[120]; // calculate estimate of framerate for user
453 | int FramerateSecPerFrameIdx;
454 | float FramerateSecPerFrameAccum;
455 | int CaptureMouseNextFrame; // explicit capture via CaptureInputs() sets those flags
456 | int CaptureKeyboardNextFrame;
457 | char TempBuffer[1024*3+1]; // temporary text buffer
458 |
459 | ImGuiContext()
460 | {
461 | Initialized = false;
462 | Font = NULL;
463 | FontSize = FontBaseSize = 0.0f;
464 | FontTexUvWhitePixel = ImVec2(0.0f, 0.0f);
465 |
466 | Time = 0.0f;
467 | FrameCount = 0;
468 | FrameCountEnded = FrameCountRendered = -1;
469 | CurrentWindow = NULL;
470 | FocusedWindow = NULL;
471 | HoveredWindow = NULL;
472 | HoveredRootWindow = NULL;
473 | HoveredId = 0;
474 | HoveredIdAllowOverlap = false;
475 | HoveredIdPreviousFrame = 0;
476 | ActiveId = 0;
477 | ActiveIdPreviousFrame = 0;
478 | ActiveIdIsAlive = false;
479 | ActiveIdIsJustActivated = false;
480 | ActiveIdAllowOverlap = false;
481 | ActiveIdClickOffset = ImVec2(-1,-1);
482 | ActiveIdWindow = NULL;
483 | MovedWindow = NULL;
484 | MovedWindowMoveId = 0;
485 | SettingsDirtyTimer = 0.0f;
486 |
487 | SetNextWindowPosVal = ImVec2(0.0f, 0.0f);
488 | SetNextWindowSizeVal = ImVec2(0.0f, 0.0f);
489 | SetNextWindowCollapsedVal = false;
490 | SetNextWindowPosCond = 0;
491 | SetNextWindowSizeCond = 0;
492 | SetNextWindowContentSizeCond = 0;
493 | SetNextWindowCollapsedCond = 0;
494 | SetNextWindowSizeConstraintRect = ImRect();
495 | SetNextWindowSizeConstraintCallback = NULL;
496 | SetNextWindowSizeConstraintCallbackUserData = NULL;
497 | SetNextWindowSizeConstraint = false;
498 | SetNextWindowFocus = false;
499 | SetNextTreeNodeOpenVal = false;
500 | SetNextTreeNodeOpenCond = 0;
501 |
502 | ScalarAsInputTextId = 0;
503 | DragCurrentValue = 0.0f;
504 | DragLastMouseDelta = ImVec2(0.0f, 0.0f);
505 | DragSpeedDefaultRatio = 1.0f / 100.0f;
506 | DragSpeedScaleSlow = 0.01f;
507 | DragSpeedScaleFast = 10.0f;
508 | ScrollbarClickDeltaToGrabCenter = ImVec2(0.0f, 0.0f);
509 | memset(Tooltip, 0, sizeof(Tooltip));
510 | PrivateClipboard = NULL;
511 | OsImePosRequest = OsImePosSet = ImVec2(-1.0f, -1.0f);
512 |
513 | ModalWindowDarkeningRatio = 0.0f;
514 | OverlayDrawList._OwnerName = "##Overlay"; // Give it a name for debugging
515 | MouseCursor = ImGuiMouseCursor_Arrow;
516 | memset(MouseCursorData, 0, sizeof(MouseCursorData));
517 |
518 | LogEnabled = false;
519 | LogFile = NULL;
520 | LogClipboard = NULL;
521 | LogStartDepth = 0;
522 | LogAutoExpandMaxDepth = 2;
523 |
524 | memset(FramerateSecPerFrame, 0, sizeof(FramerateSecPerFrame));
525 | FramerateSecPerFrameIdx = 0;
526 | FramerateSecPerFrameAccum = 0.0f;
527 | CaptureMouseNextFrame = CaptureKeyboardNextFrame = -1;
528 | memset(TempBuffer, 0, sizeof(TempBuffer));
529 | }
530 | };
531 |
532 | // Transient per-window data, reset at the beginning of the frame
533 | // FIXME: That's theory, in practice the delimitation between ImGuiWindow and ImGuiDrawContext is quite tenuous and could be reconsidered.
534 | struct IMGUI_API ImGuiDrawContext
535 | {
536 | ImVec2 CursorPos;
537 | ImVec2 CursorPosPrevLine;
538 | ImVec2 CursorStartPos;
539 | ImVec2 CursorMaxPos; // Implicitly calculate the size of our contents, always extending. Saved into window->SizeContents at the end of the frame
540 | float CurrentLineHeight;
541 | float CurrentLineTextBaseOffset;
542 | float PrevLineHeight;
543 | float PrevLineTextBaseOffset;
544 | float LogLinePosY;
545 | int TreeDepth;
546 | ImGuiID LastItemId;
547 | ImRect LastItemRect;
548 | bool LastItemHoveredAndUsable; // Item rectangle is hovered, and its window is currently interactable with (not blocked by a popup preventing access to the window)
549 | bool LastItemHoveredRect; // Item rectangle is hovered, but its window may or not be currently interactable with (might be blocked by a popup preventing access to the window)
550 | bool MenuBarAppending;
551 | float MenuBarOffsetX;
552 | ImVector ChildWindows;
553 | ImGuiStorage* StateStorage;
554 | ImGuiLayoutType LayoutType;
555 |
556 | // We store the current settings outside of the vectors to increase memory locality (reduce cache misses). The vectors are rarely modified. Also it allows us to not heap allocate for short-lived windows which are not using those settings.
557 | float ItemWidth; // == ItemWidthStack.back(). 0.0: default, >0.0: width in pixels, <0.0: align xx pixels to the right of window
558 | float TextWrapPos; // == TextWrapPosStack.back() [empty == -1.0f]
559 | bool AllowKeyboardFocus; // == AllowKeyboardFocusStack.back() [empty == true]
560 | bool ButtonRepeat; // == ButtonRepeatStack.back() [empty == false]
561 | ImVector ItemWidthStack;
562 | ImVector TextWrapPosStack;
563 | ImVector AllowKeyboardFocusStack;
564 | ImVector ButtonRepeatStack;
565 | ImVectorGroupStack;
566 | ImGuiColorEditMode ColorEditMode;
567 | int StackSizesBackup[6]; // Store size of various stacks for asserting
568 |
569 | float IndentX; // Indentation / start position from left of window (increased by TreePush/TreePop, etc.)
570 | float GroupOffsetX;
571 | float ColumnsOffsetX; // Offset to the current column (if ColumnsCurrent > 0). FIXME: This and the above should be a stack to allow use cases like Tree->Column->Tree. Need revamp columns API.
572 | int ColumnsCurrent;
573 | int ColumnsCount;
574 | float ColumnsMinX;
575 | float ColumnsMaxX;
576 | float ColumnsStartPosY;
577 | float ColumnsCellMinY;
578 | float ColumnsCellMaxY;
579 | bool ColumnsShowBorders;
580 | ImGuiID ColumnsSetId;
581 | ImVector ColumnsData;
582 |
583 | ImGuiDrawContext()
584 | {
585 | CursorPos = CursorPosPrevLine = CursorStartPos = CursorMaxPos = ImVec2(0.0f, 0.0f);
586 | CurrentLineHeight = PrevLineHeight = 0.0f;
587 | CurrentLineTextBaseOffset = PrevLineTextBaseOffset = 0.0f;
588 | LogLinePosY = -1.0f;
589 | TreeDepth = 0;
590 | LastItemId = 0;
591 | LastItemRect = ImRect(0.0f,0.0f,0.0f,0.0f);
592 | LastItemHoveredAndUsable = LastItemHoveredRect = false;
593 | MenuBarAppending = false;
594 | MenuBarOffsetX = 0.0f;
595 | StateStorage = NULL;
596 | LayoutType = ImGuiLayoutType_Vertical;
597 | ItemWidth = 0.0f;
598 | ButtonRepeat = false;
599 | AllowKeyboardFocus = true;
600 | TextWrapPos = -1.0f;
601 | ColorEditMode = ImGuiColorEditMode_RGB;
602 | memset(StackSizesBackup, 0, sizeof(StackSizesBackup));
603 |
604 | IndentX = 0.0f;
605 | GroupOffsetX = 0.0f;
606 | ColumnsOffsetX = 0.0f;
607 | ColumnsCurrent = 0;
608 | ColumnsCount = 1;
609 | ColumnsMinX = ColumnsMaxX = 0.0f;
610 | ColumnsStartPosY = 0.0f;
611 | ColumnsCellMinY = ColumnsCellMaxY = 0.0f;
612 | ColumnsShowBorders = true;
613 | ColumnsSetId = 0;
614 | }
615 | };
616 |
617 | // Windows data
618 | struct IMGUI_API ImGuiWindow
619 | {
620 | char* Name;
621 | ImGuiID ID; // == ImHash(Name)
622 | ImGuiWindowFlags Flags; // See enum ImGuiWindowFlags_
623 | int IndexWithinParent; // Order within immediate parent window, if we are a child window. Otherwise 0.
624 | ImVec2 PosFloat;
625 | ImVec2 Pos; // Position rounded-up to nearest pixel
626 | ImVec2 Size; // Current size (==SizeFull or collapsed title bar size)
627 | ImVec2 SizeFull; // Size when non collapsed
628 | ImVec2 SizeContents; // Size of contents (== extents reach of the drawing cursor) from previous frame
629 | ImVec2 SizeContentsExplicit; // Size of contents explicitly set by the user via SetNextWindowContentSize()
630 | ImRect ContentsRegionRect; // Maximum visible content position in window coordinates. ~~ (SizeContentsExplicit ? SizeContentsExplicit : Size - ScrollbarSizes) - CursorStartPos, per axis
631 | ImVec2 WindowPadding; // Window padding at the time of begin. We need to lock it, in particular manipulation of the ShowBorder would have an effect
632 | ImGuiID MoveId; // == window->GetID("#MOVE")
633 | ImVec2 Scroll;
634 | ImVec2 ScrollTarget; // target scroll position. stored as cursor position with scrolling canceled out, so the highest point is always 0.0f. (FLT_MAX for no change)
635 | ImVec2 ScrollTargetCenterRatio; // 0.0f = scroll so that target position is at top, 0.5f = scroll so that target position is centered
636 | bool ScrollbarX, ScrollbarY;
637 | ImVec2 ScrollbarSizes;
638 | float BorderSize;
639 | bool Active; // Set to true on Begin()
640 | bool WasActive;
641 | bool Accessed; // Set to true when any widget access the current window
642 | bool Collapsed; // Set when collapsing window to become only title-bar
643 | bool SkipItems; // == Visible && !Collapsed
644 | int BeginCount; // Number of Begin() during the current frame (generally 0 or 1, 1+ if appending via multiple Begin/End pairs)
645 | ImGuiID PopupId; // ID in the popup stack when this window is used as a popup/menu (because we use generic Name/ID for recycling)
646 | int AutoFitFramesX, AutoFitFramesY;
647 | bool AutoFitOnlyGrows;
648 | int AutoPosLastDirection;
649 | int HiddenFrames;
650 | int SetWindowPosAllowFlags; // bit ImGuiSetCond_*** specify if SetWindowPos() call will succeed with this particular flag.
651 | int SetWindowSizeAllowFlags; // bit ImGuiSetCond_*** specify if SetWindowSize() call will succeed with this particular flag.
652 | int SetWindowCollapsedAllowFlags; // bit ImGuiSetCond_*** specify if SetWindowCollapsed() call will succeed with this particular flag.
653 | bool SetWindowPosCenterWanted;
654 |
655 | ImGuiDrawContext DC; // Temporary per-window data, reset at the beginning of the frame
656 | ImVector IDStack; // ID stack. ID are hashes seeded with the value at the top of the stack
657 | ImRect ClipRect; // = DrawList->clip_rect_stack.back(). Scissoring / clipping rectangle. x1, y1, x2, y2.
658 | ImRect WindowRectClipped; // = WindowRect just after setup in Begin(). == window->Rect() for root window.
659 | int LastFrameActive;
660 | float ItemWidthDefault;
661 | ImGuiSimpleColumns MenuColumns; // Simplified columns storage for menu items
662 | ImGuiStorage StateStorage;
663 | float FontWindowScale; // Scale multiplier per-window
664 | ImDrawList* DrawList;
665 | ImGuiWindow* RootWindow; // If we are a child window, this is pointing to the first non-child parent window. Else point to ourself.
666 | ImGuiWindow* RootNonPopupWindow; // If we are a child window, this is pointing to the first non-child non-popup parent window. Else point to ourself.
667 | ImGuiWindow* ParentWindow; // If we are a child window, this is pointing to our parent window. Else point to NULL.
668 |
669 | // Navigation / Focus
670 | int FocusIdxAllCounter; // Start at -1 and increase as assigned via FocusItemRegister()
671 | int FocusIdxTabCounter; // (same, but only count widgets which you can Tab through)
672 | int FocusIdxAllRequestCurrent; // Item being requested for focus
673 | int FocusIdxTabRequestCurrent; // Tab-able item being requested for focus
674 | int FocusIdxAllRequestNext; // Item being requested for focus, for next update (relies on layout to be stable between the frame pressing TAB and the next frame)
675 | int FocusIdxTabRequestNext; // "
676 |
677 | public:
678 | ImGuiWindow(const char* name);
679 | ~ImGuiWindow();
680 |
681 | ImGuiID GetID(const char* str, const char* str_end = NULL);
682 | ImGuiID GetID(const void* ptr);
683 | ImGuiID GetIDNoKeepAlive(const char* str, const char* str_end = NULL);
684 |
685 | ImRect Rect() const { return ImRect(Pos.x, Pos.y, Pos.x+Size.x, Pos.y+Size.y); }
686 | float CalcFontSize() const { return GImGui->FontBaseSize * FontWindowScale; }
687 | float TitleBarHeight() const { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0.0f : CalcFontSize() + GImGui->Style.FramePadding.y * 2.0f; }
688 | ImRect TitleBarRect() const { return ImRect(Pos, ImVec2(Pos.x + SizeFull.x, Pos.y + TitleBarHeight())); }
689 | float MenuBarHeight() const { return (Flags & ImGuiWindowFlags_MenuBar) ? CalcFontSize() + GImGui->Style.FramePadding.y * 2.0f : 0.0f; }
690 | ImRect MenuBarRect() const { float y1 = Pos.y + TitleBarHeight(); return ImRect(Pos.x, y1, Pos.x + SizeFull.x, y1 + MenuBarHeight()); }
691 | };
692 |
693 | //-----------------------------------------------------------------------------
694 | // Internal API
695 | // No guarantee of forward compatibility here.
696 | //-----------------------------------------------------------------------------
697 |
698 | namespace ImGui
699 | {
700 | // We should always have a CurrentWindow in the stack (there is an implicit "Debug" window)
701 | // If this ever crash because g.CurrentWindow is NULL it means that either
702 | // - ImGui::NewFrame() has never been called, which is illegal.
703 | // - You are calling ImGui functions after ImGui::Render() and before the next ImGui::NewFrame(), which is also illegal.
704 | inline ImGuiWindow* GetCurrentWindowRead() { ImGuiContext& g = *GImGui; return g.CurrentWindow; }
705 | inline ImGuiWindow* GetCurrentWindow() { ImGuiContext& g = *GImGui; g.CurrentWindow->Accessed = true; return g.CurrentWindow; }
706 | IMGUI_API ImGuiWindow* GetParentWindow();
707 | IMGUI_API ImGuiWindow* FindWindowByName(const char* name);
708 | IMGUI_API void FocusWindow(ImGuiWindow* window);
709 |
710 | IMGUI_API void EndFrame(); // Ends the ImGui frame. Automatically called by Render()! you most likely don't need to ever call that yourself directly. If you don't need to render you can call EndFrame() but you'll have wasted CPU already. If you don't need to render, don't create any windows instead!
711 |
712 | IMGUI_API void SetActiveID(ImGuiID id, ImGuiWindow* window);
713 | IMGUI_API void SetHoveredID(ImGuiID id);
714 | IMGUI_API void KeepAliveID(ImGuiID id);
715 |
716 | IMGUI_API void ItemSize(const ImVec2& size, float text_offset_y = 0.0f);
717 | IMGUI_API void ItemSize(const ImRect& bb, float text_offset_y = 0.0f);
718 | IMGUI_API bool ItemAdd(const ImRect& bb, const ImGuiID* id);
719 | IMGUI_API bool IsClippedEx(const ImRect& bb, const ImGuiID* id, bool clip_even_when_logged);
720 | IMGUI_API bool IsHovered(const ImRect& bb, ImGuiID id, bool flatten_childs = false);
721 | IMGUI_API bool FocusableItemRegister(ImGuiWindow* window, bool is_active, bool tab_stop = true); // Return true if focus is requested
722 | IMGUI_API void FocusableItemUnregister(ImGuiWindow* window);
723 | IMGUI_API ImVec2 CalcItemSize(ImVec2 size, float default_x, float default_y);
724 | IMGUI_API float CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x);
725 |
726 | IMGUI_API void OpenPopupEx(const char* str_id, bool reopen_existing);
727 |
728 | // NB: All position are in absolute pixels coordinates (not window coordinates)
729 | // FIXME: All those functions are a mess and needs to be refactored into something decent. AVOID USING OUTSIDE OF IMGUI.CPP! NOT FOR PUBLIC CONSUMPTION.
730 | // We need: a sort of symbol library, preferably baked into font atlas when possible + decent text rendering helpers.
731 | IMGUI_API void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, bool hide_text_after_hash = true);
732 | IMGUI_API void RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end, float wrap_width);
733 | IMGUI_API void RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_end, const ImVec2* text_size_if_known, const ImVec2& align = ImVec2(0,0), const ImRect* clip_rect = NULL);
734 | IMGUI_API void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f);
735 | IMGUI_API void RenderCollapseTriangle(ImVec2 pos, bool is_open, float scale = 1.0f);
736 | IMGUI_API void RenderBullet(ImVec2 pos);
737 | IMGUI_API void RenderCheckMark(ImVec2 pos, ImU32 col);
738 | IMGUI_API const char* FindRenderedTextEnd(const char* text, const char* text_end = NULL); // Find the optional ## from which we stop displaying text.
739 |
740 | IMGUI_API bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, ImGuiButtonFlags flags = 0);
741 | IMGUI_API bool ButtonEx(const char* label, const ImVec2& size_arg = ImVec2(0,0), ImGuiButtonFlags flags = 0);
742 | IMGUI_API bool CloseButton(ImGuiID id, const ImVec2& pos, float radius);
743 |
744 | IMGUI_API bool SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_min, float v_max, float power, int decimal_precision, ImGuiSliderFlags flags = 0);
745 | IMGUI_API bool SliderFloatN(const char* label, float* v, int components, float v_min, float v_max, const char* display_format, float power);
746 | IMGUI_API bool SliderIntN(const char* label, int* v, int components, int v_min, int v_max, const char* display_format);
747 |
748 | IMGUI_API bool DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_speed, float v_min, float v_max, int decimal_precision, float power);
749 | IMGUI_API bool DragFloatN(const char* label, float* v, int components, float v_speed, float v_min, float v_max, const char* display_format, float power);
750 | IMGUI_API bool DragIntN(const char* label, int* v, int components, float v_speed, int v_min, int v_max, const char* display_format);
751 |
752 | IMGUI_API bool InputTextEx(const char* label, char* buf, int buf_size, const ImVec2& size_arg, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback = NULL, void* user_data = NULL);
753 | IMGUI_API bool InputFloatN(const char* label, float* v, int components, int decimal_precision, ImGuiInputTextFlags extra_flags);
754 | IMGUI_API bool InputIntN(const char* label, int* v, int components, ImGuiInputTextFlags extra_flags);
755 | IMGUI_API bool InputScalarEx(const char* label, ImGuiDataType data_type, void* data_ptr, void* step_ptr, void* step_fast_ptr, const char* scalar_format, ImGuiInputTextFlags extra_flags);
756 | IMGUI_API bool InputScalarAsWidgetReplacement(const ImRect& aabb, const char* label, ImGuiDataType data_type, void* data_ptr, ImGuiID id, int decimal_precision);
757 |
758 | IMGUI_API bool TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* label, const char* label_end = NULL);
759 | IMGUI_API bool TreeNodeBehaviorIsOpen(ImGuiID id, ImGuiTreeNodeFlags flags = 0); // Consume previous SetNextTreeNodeOpened() data, if any. May return true when logging
760 | IMGUI_API void TreePushRawID(ImGuiID id);
761 |
762 | IMGUI_API void PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size);
763 |
764 | IMGUI_API int ParseFormatPrecision(const char* fmt, int default_value);
765 | IMGUI_API float RoundScalar(float value, int decimal_precision);
766 |
767 | } // namespace ImGui
768 |
769 | #ifdef __clang__
770 | #pragma clang diagnostic pop
771 | #endif
772 |
773 | #ifdef _MSC_VER
774 | #pragma warning (pop)
775 | #endif
776 |
--------------------------------------------------------------------------------
/include/imgui/stb_rect_pack.h:
--------------------------------------------------------------------------------
1 | // stb_rect_pack.h - v0.10 - public domain - rectangle packing
2 | // Sean Barrett 2014
3 | //
4 | // Useful for e.g. packing rectangular textures into an atlas.
5 | // Does not do rotation.
6 | //
7 | // Not necessarily the awesomest packing method, but better than
8 | // the totally naive one in stb_truetype (which is primarily what
9 | // this is meant to replace).
10 | //
11 | // Has only had a few tests run, may have issues.
12 | //
13 | // More docs to come.
14 | //
15 | // No memory allocations; uses qsort() and assert() from stdlib.
16 | // Can override those by defining STBRP_SORT and STBRP_ASSERT.
17 | //
18 | // This library currently uses the Skyline Bottom-Left algorithm.
19 | //
20 | // Please note: better rectangle packers are welcome! Please
21 | // implement them to the same API, but with a different init
22 | // function.
23 | //
24 | // Credits
25 | //
26 | // Library
27 | // Sean Barrett
28 | // Minor features
29 | // Martins Mozeiko
30 | // Bugfixes / warning fixes
31 | // Jeremy Jaussaud
32 | //
33 | // Version history:
34 | //
35 | // 0.10 (2016-10-25) remove cast-away-const to avoid warnings
36 | // 0.09 (2016-08-27) fix compiler warnings
37 | // 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0)
38 | // 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0)
39 | // 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort
40 | // 0.05: added STBRP_ASSERT to allow replacing assert
41 | // 0.04: fixed minor bug in STBRP_LARGE_RECTS support
42 | // 0.01: initial release
43 | //
44 | // LICENSE
45 | //
46 | // This software is dual-licensed to the public domain and under the following
47 | // license: you are granted a perpetual, irrevocable license to copy, modify,
48 | // publish, and distribute this file as you see fit.
49 |
50 | //////////////////////////////////////////////////////////////////////////////
51 | //
52 | // INCLUDE SECTION
53 | //
54 |
55 | #ifndef STB_INCLUDE_STB_RECT_PACK_H
56 | #define STB_INCLUDE_STB_RECT_PACK_H
57 |
58 | #define STB_RECT_PACK_VERSION 1
59 |
60 | #ifdef STBRP_STATIC
61 | #define STBRP_DEF static
62 | #else
63 | #define STBRP_DEF extern
64 | #endif
65 |
66 | #ifdef __cplusplus
67 | extern "C" {
68 | #endif
69 |
70 | typedef struct stbrp_context stbrp_context;
71 | typedef struct stbrp_node stbrp_node;
72 | typedef struct stbrp_rect stbrp_rect;
73 |
74 | #ifdef STBRP_LARGE_RECTS
75 | typedef int stbrp_coord;
76 | #else
77 | typedef unsigned short stbrp_coord;
78 | #endif
79 |
80 | STBRP_DEF void stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
81 | // Assign packed locations to rectangles. The rectangles are of type
82 | // 'stbrp_rect' defined below, stored in the array 'rects', and there
83 | // are 'num_rects' many of them.
84 | //
85 | // Rectangles which are successfully packed have the 'was_packed' flag
86 | // set to a non-zero value and 'x' and 'y' store the minimum location
87 | // on each axis (i.e. bottom-left in cartesian coordinates, top-left
88 | // if you imagine y increasing downwards). Rectangles which do not fit
89 | // have the 'was_packed' flag set to 0.
90 | //
91 | // You should not try to access the 'rects' array from another thread
92 | // while this function is running, as the function temporarily reorders
93 | // the array while it executes.
94 | //
95 | // To pack into another rectangle, you need to call stbrp_init_target
96 | // again. To continue packing into the same rectangle, you can call
97 | // this function again. Calling this multiple times with multiple rect
98 | // arrays will probably produce worse packing results than calling it
99 | // a single time with the full rectangle array, but the option is
100 | // available.
101 |
102 | struct stbrp_rect
103 | {
104 | // reserved for your use:
105 | int id;
106 |
107 | // input:
108 | stbrp_coord w, h;
109 |
110 | // output:
111 | stbrp_coord x, y;
112 | int was_packed; // non-zero if valid packing
113 |
114 | }; // 16 bytes, nominally
115 |
116 |
117 | STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes);
118 | // Initialize a rectangle packer to:
119 | // pack a rectangle that is 'width' by 'height' in dimensions
120 | // using temporary storage provided by the array 'nodes', which is 'num_nodes' long
121 | //
122 | // You must call this function every time you start packing into a new target.
123 | //
124 | // There is no "shutdown" function. The 'nodes' memory must stay valid for
125 | // the following stbrp_pack_rects() call (or calls), but can be freed after
126 | // the call (or calls) finish.
127 | //
128 | // Note: to guarantee best results, either:
129 | // 1. make sure 'num_nodes' >= 'width'
130 | // or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1'
131 | //
132 | // If you don't do either of the above things, widths will be quantized to multiples
133 | // of small integers to guarantee the algorithm doesn't run out of temporary storage.
134 | //
135 | // If you do #2, then the non-quantized algorithm will be used, but the algorithm
136 | // may run out of temporary storage and be unable to pack some rectangles.
137 |
138 | STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem);
139 | // Optionally call this function after init but before doing any packing to
140 | // change the handling of the out-of-temp-memory scenario, described above.
141 | // If you call init again, this will be reset to the default (false).
142 |
143 |
144 | STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic);
145 | // Optionally select which packing heuristic the library should use. Different
146 | // heuristics will produce better/worse results for different data sets.
147 | // If you call init again, this will be reset to the default.
148 |
149 | enum
150 | {
151 | STBRP_HEURISTIC_Skyline_default=0,
152 | STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default,
153 | STBRP_HEURISTIC_Skyline_BF_sortHeight
154 | };
155 |
156 |
157 | //////////////////////////////////////////////////////////////////////////////
158 | //
159 | // the details of the following structures don't matter to you, but they must
160 | // be visible so you can handle the memory allocations for them
161 |
162 | struct stbrp_node
163 | {
164 | stbrp_coord x,y;
165 | stbrp_node *next;
166 | };
167 |
168 | struct stbrp_context
169 | {
170 | int width;
171 | int height;
172 | int align;
173 | int init_mode;
174 | int heuristic;
175 | int num_nodes;
176 | stbrp_node *active_head;
177 | stbrp_node *free_head;
178 | stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2'
179 | };
180 |
181 | #ifdef __cplusplus
182 | }
183 | #endif
184 |
185 | #endif
186 |
187 | //////////////////////////////////////////////////////////////////////////////
188 | //
189 | // IMPLEMENTATION SECTION
190 | //
191 |
192 | #ifdef STB_RECT_PACK_IMPLEMENTATION
193 | #ifndef STBRP_SORT
194 | #include
195 | #define STBRP_SORT qsort
196 | #endif
197 |
198 | #ifndef STBRP_ASSERT
199 | #include
200 | #define STBRP_ASSERT assert
201 | #endif
202 |
203 | #ifdef _MSC_VER
204 | #define STBRP__NOTUSED(v) (void)(v)
205 | #else
206 | #define STBRP__NOTUSED(v) (void)sizeof(v)
207 | #endif
208 |
209 | enum
210 | {
211 | STBRP__INIT_skyline = 1
212 | };
213 |
214 | STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
215 | {
216 | switch (context->init_mode) {
217 | case STBRP__INIT_skyline:
218 | STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight);
219 | context->heuristic = heuristic;
220 | break;
221 | default:
222 | STBRP_ASSERT(0);
223 | }
224 | }
225 |
226 | STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem)
227 | {
228 | if (allow_out_of_mem)
229 | // if it's ok to run out of memory, then don't bother aligning them;
230 | // this gives better packing, but may fail due to OOM (even though
231 | // the rectangles easily fit). @TODO a smarter approach would be to only
232 | // quantize once we've hit OOM, then we could get rid of this parameter.
233 | context->align = 1;
234 | else {
235 | // if it's not ok to run out of memory, then quantize the widths
236 | // so that num_nodes is always enough nodes.
237 | //
238 | // I.e. num_nodes * align >= width
239 | // align >= width / num_nodes
240 | // align = ceil(width/num_nodes)
241 |
242 | context->align = (context->width + context->num_nodes-1) / context->num_nodes;
243 | }
244 | }
245 |
246 | STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
247 | {
248 | int i;
249 | #ifndef STBRP_LARGE_RECTS
250 | STBRP_ASSERT(width <= 0xffff && height <= 0xffff);
251 | #endif
252 |
253 | for (i=0; i < num_nodes-1; ++i)
254 | nodes[i].next = &nodes[i+1];
255 | nodes[i].next = NULL;
256 | context->init_mode = STBRP__INIT_skyline;
257 | context->heuristic = STBRP_HEURISTIC_Skyline_default;
258 | context->free_head = &nodes[0];
259 | context->active_head = &context->extra[0];
260 | context->width = width;
261 | context->height = height;
262 | context->num_nodes = num_nodes;
263 | stbrp_setup_allow_out_of_mem(context, 0);
264 |
265 | // node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly)
266 | context->extra[0].x = 0;
267 | context->extra[0].y = 0;
268 | context->extra[0].next = &context->extra[1];
269 | context->extra[1].x = (stbrp_coord) width;
270 | #ifdef STBRP_LARGE_RECTS
271 | context->extra[1].y = (1<<30);
272 | #else
273 | context->extra[1].y = 65535;
274 | #endif
275 | context->extra[1].next = NULL;
276 | }
277 |
278 | // find minimum y position if it starts at x1
279 | static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste)
280 | {
281 | stbrp_node *node = first;
282 | int x1 = x0 + width;
283 | int min_y, visited_width, waste_area;
284 |
285 | STBRP__NOTUSED(c);
286 |
287 | STBRP_ASSERT(first->x <= x0);
288 |
289 | #if 0
290 | // skip in case we're past the node
291 | while (node->next->x <= x0)
292 | ++node;
293 | #else
294 | STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency
295 | #endif
296 |
297 | STBRP_ASSERT(node->x <= x0);
298 |
299 | min_y = 0;
300 | waste_area = 0;
301 | visited_width = 0;
302 | while (node->x < x1) {
303 | if (node->y > min_y) {
304 | // raise min_y higher.
305 | // we've accounted for all waste up to min_y,
306 | // but we'll now add more waste for everything we've visted
307 | waste_area += visited_width * (node->y - min_y);
308 | min_y = node->y;
309 | // the first time through, visited_width might be reduced
310 | if (node->x < x0)
311 | visited_width += node->next->x - x0;
312 | else
313 | visited_width += node->next->x - node->x;
314 | } else {
315 | // add waste area
316 | int under_width = node->next->x - node->x;
317 | if (under_width + visited_width > width)
318 | under_width = width - visited_width;
319 | waste_area += under_width * (min_y - node->y);
320 | visited_width += under_width;
321 | }
322 | node = node->next;
323 | }
324 |
325 | *pwaste = waste_area;
326 | return min_y;
327 | }
328 |
329 | typedef struct
330 | {
331 | int x,y;
332 | stbrp_node **prev_link;
333 | } stbrp__findresult;
334 |
335 | static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height)
336 | {
337 | int best_waste = (1<<30), best_x, best_y = (1 << 30);
338 | stbrp__findresult fr;
339 | stbrp_node **prev, *node, *tail, **best = NULL;
340 |
341 | // align to multiple of c->align
342 | width = (width + c->align - 1);
343 | width -= width % c->align;
344 | STBRP_ASSERT(width % c->align == 0);
345 |
346 | node = c->active_head;
347 | prev = &c->active_head;
348 | while (node->x + width <= c->width) {
349 | int y,waste;
350 | y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste);
351 | if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL
352 | // bottom left
353 | if (y < best_y) {
354 | best_y = y;
355 | best = prev;
356 | }
357 | } else {
358 | // best-fit
359 | if (y + height <= c->height) {
360 | // can only use it if it first vertically
361 | if (y < best_y || (y == best_y && waste < best_waste)) {
362 | best_y = y;
363 | best_waste = waste;
364 | best = prev;
365 | }
366 | }
367 | }
368 | prev = &node->next;
369 | node = node->next;
370 | }
371 |
372 | best_x = (best == NULL) ? 0 : (*best)->x;
373 |
374 | // if doing best-fit (BF), we also have to try aligning right edge to each node position
375 | //
376 | // e.g, if fitting
377 | //
378 | // ____________________
379 | // |____________________|
380 | //
381 | // into
382 | //
383 | // | |
384 | // | ____________|
385 | // |____________|
386 | //
387 | // then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned
388 | //
389 | // This makes BF take about 2x the time
390 |
391 | if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) {
392 | tail = c->active_head;
393 | node = c->active_head;
394 | prev = &c->active_head;
395 | // find first node that's admissible
396 | while (tail->x < width)
397 | tail = tail->next;
398 | while (tail) {
399 | int xpos = tail->x - width;
400 | int y,waste;
401 | STBRP_ASSERT(xpos >= 0);
402 | // find the left position that matches this
403 | while (node->next->x <= xpos) {
404 | prev = &node->next;
405 | node = node->next;
406 | }
407 | STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);
408 | y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
409 | if (y + height < c->height) {
410 | if (y <= best_y) {
411 | if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
412 | best_x = xpos;
413 | STBRP_ASSERT(y <= best_y);
414 | best_y = y;
415 | best_waste = waste;
416 | best = prev;
417 | }
418 | }
419 | }
420 | tail = tail->next;
421 | }
422 | }
423 |
424 | fr.prev_link = best;
425 | fr.x = best_x;
426 | fr.y = best_y;
427 | return fr;
428 | }
429 |
430 | static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height)
431 | {
432 | // find best position according to heuristic
433 | stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height);
434 | stbrp_node *node, *cur;
435 |
436 | // bail if:
437 | // 1. it failed
438 | // 2. the best node doesn't fit (we don't always check this)
439 | // 3. we're out of memory
440 | if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) {
441 | res.prev_link = NULL;
442 | return res;
443 | }
444 |
445 | // on success, create new node
446 | node = context->free_head;
447 | node->x = (stbrp_coord) res.x;
448 | node->y = (stbrp_coord) (res.y + height);
449 |
450 | context->free_head = node->next;
451 |
452 | // insert the new node into the right starting point, and
453 | // let 'cur' point to the remaining nodes needing to be
454 | // stiched back in
455 |
456 | cur = *res.prev_link;
457 | if (cur->x < res.x) {
458 | // preserve the existing one, so start testing with the next one
459 | stbrp_node *next = cur->next;
460 | cur->next = node;
461 | cur = next;
462 | } else {
463 | *res.prev_link = node;
464 | }
465 |
466 | // from here, traverse cur and free the nodes, until we get to one
467 | // that shouldn't be freed
468 | while (cur->next && cur->next->x <= res.x + width) {
469 | stbrp_node *next = cur->next;
470 | // move the current node to the free list
471 | cur->next = context->free_head;
472 | context->free_head = cur;
473 | cur = next;
474 | }
475 |
476 | // stitch the list back in
477 | node->next = cur;
478 |
479 | if (cur->x < res.x + width)
480 | cur->x = (stbrp_coord) (res.x + width);
481 |
482 | #ifdef _DEBUG
483 | cur = context->active_head;
484 | while (cur->x < context->width) {
485 | STBRP_ASSERT(cur->x < cur->next->x);
486 | cur = cur->next;
487 | }
488 | STBRP_ASSERT(cur->next == NULL);
489 |
490 | {
491 | stbrp_node *L1 = NULL, *L2 = NULL;
492 | int count=0;
493 | cur = context->active_head;
494 | while (cur) {
495 | L1 = cur;
496 | cur = cur->next;
497 | ++count;
498 | }
499 | cur = context->free_head;
500 | while (cur) {
501 | L2 = cur;
502 | cur = cur->next;
503 | ++count;
504 | }
505 | STBRP_ASSERT(count == context->num_nodes+2);
506 | }
507 | #endif
508 |
509 | return res;
510 | }
511 |
512 | static int rect_height_compare(const void *a, const void *b)
513 | {
514 | const stbrp_rect *p = (const stbrp_rect *) a;
515 | const stbrp_rect *q = (const stbrp_rect *) b;
516 | if (p->h > q->h)
517 | return -1;
518 | if (p->h < q->h)
519 | return 1;
520 | return (p->w > q->w) ? -1 : (p->w < q->w);
521 | }
522 |
523 | static int rect_width_compare(const void *a, const void *b)
524 | {
525 | const stbrp_rect *p = (const stbrp_rect *) a;
526 | const stbrp_rect *q = (const stbrp_rect *) b;
527 | if (p->w > q->w)
528 | return -1;
529 | if (p->w < q->w)
530 | return 1;
531 | return (p->h > q->h) ? -1 : (p->h < q->h);
532 | }
533 |
534 | static int rect_original_order(const void *a, const void *b)
535 | {
536 | const stbrp_rect *p = (const stbrp_rect *) a;
537 | const stbrp_rect *q = (const stbrp_rect *) b;
538 | return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
539 | }
540 |
541 | #ifdef STBRP_LARGE_RECTS
542 | #define STBRP__MAXVAL 0xffffffff
543 | #else
544 | #define STBRP__MAXVAL 0xffff
545 | #endif
546 |
547 | STBRP_DEF void stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
548 | {
549 | int i;
550 |
551 | // we use the 'was_packed' field internally to allow sorting/unsorting
552 | for (i=0; i < num_rects; ++i) {
553 | rects[i].was_packed = i;
554 | #ifndef STBRP_LARGE_RECTS
555 | STBRP_ASSERT(rects[i].w <= 0xffff && rects[i].h <= 0xffff);
556 | #endif
557 | }
558 |
559 | // sort according to heuristic
560 | STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare);
561 |
562 | for (i=0; i < num_rects; ++i) {
563 | if (rects[i].w == 0 || rects[i].h == 0) {
564 | rects[i].x = rects[i].y = 0; // empty rect needs no space
565 | } else {
566 | stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
567 | if (fr.prev_link) {
568 | rects[i].x = (stbrp_coord) fr.x;
569 | rects[i].y = (stbrp_coord) fr.y;
570 | } else {
571 | rects[i].x = rects[i].y = STBRP__MAXVAL;
572 | }
573 | }
574 | }
575 |
576 | // unsort
577 | STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order);
578 |
579 | // set was_packed flags
580 | for (i=0; i < num_rects; ++i)
581 | rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL);
582 | }
583 | #endif
584 |
--------------------------------------------------------------------------------
/include/vmthook/vmthook.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | class VMTHook {
9 | private:
10 | std::uintptr_t** baseclass = nullptr;
11 | std::unique_ptr current_vft = nullptr;
12 | std::uintptr_t* original_vft = nullptr;
13 | std::size_t total_functions = 0;
14 | public:
15 | VMTHook(void) = default;
16 |
17 | VMTHook(void* baseclass) {
18 | this->baseclass = static_cast(baseclass);
19 |
20 | while (static_cast(*this->baseclass)[this->total_functions])
21 | ++this->total_functions;
22 |
23 | const std::size_t table_size = this->total_functions * sizeof(std::uintptr_t);
24 |
25 | this->original_vft = *this->baseclass;
26 | this->current_vft = std::make_unique(this->total_functions);
27 |
28 | std::memcpy(this->current_vft.get(), this->original_vft, table_size);
29 |
30 | *this->baseclass = this->current_vft.get();
31 | };
32 |
33 | ~VMTHook() {
34 | *this->baseclass = this->original_vft;
35 | };
36 |
37 | inline void* GetOriginalFunction(std::size_t function_index) {
38 | return reinterpret_cast(this->original_vft[function_index]);
39 | }
40 |
41 | template inline const Function GetOriginalFunction(std::size_t function_index) {
42 | return reinterpret_cast(this->original_vft[function_index]);
43 | }
44 |
45 | inline bool HookFunction(void* new_function, const std::size_t function_index) {
46 | if (function_index > this->total_functions)
47 | return false;
48 |
49 | this->current_vft[function_index] = reinterpret_cast(new_function);
50 |
51 | return true;
52 | }
53 |
54 | inline bool UnhookFunction(const std::size_t function_index) {
55 | if (function_index > this->total_functions)
56 | return false;
57 |
58 | this->current_vft[function_index] = this->original_vft[function_index];
59 |
60 | return true;
61 | }
62 |
63 | inline std::size_t GetTotalFunctions() {
64 | return this->total_functions;
65 | }
66 | };
--------------------------------------------------------------------------------
/src/Basehook.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | cstrike-basehook-linux -- Internal base for Counter-Strike: Source.
4 | Copyright (C) 2017, aixxe. (www.aixxe.net)
5 |
6 | This program is free software; you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation; either version 2 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with cstrike-basehook-linux. If not, see .
18 |
19 | */
20 |
21 | #include "Basehook.h"
22 |
23 | #include "Hooks/Hooks.h"
24 | #include "Events/TestListener.h"
25 | #include "Utilities/FindPattern.h"
26 |
27 | ICvar* cvar = nullptr;
28 | IPanel* panel = nullptr;
29 | ISurface* matsurface = nullptr;
30 | IEngineVGui* enginevgui = nullptr;
31 | IVModelInfoClient* modelinfo = nullptr;
32 | ILauncherMgr* launchermgr = nullptr;
33 | IInputSystem* inputsystem = nullptr;
34 | IInputInternal* inputinternal = nullptr;
35 | IVEngineClient* engine = nullptr;
36 | IVModelRender* modelrender = nullptr;
37 | IVDebugOverlay* debugoverlay = nullptr;
38 | IBaseClientDLL* clientdll = nullptr;
39 | IMaterialSystem* matsystem = nullptr;
40 | IClientEntityList* entitylist = nullptr;
41 | IGameEventManager2* gameevents = nullptr;
42 |
43 | CInput* input = nullptr;
44 | CGlobalVarsBase* globalvars = nullptr;
45 |
46 | CRC32_ProcessBufferFn CRC32_ProcessBuffer = NULL;
47 |
48 | StartDrawing_t StartDrawing = NULL;
49 | FinishDrawing_t FinishDrawing = NULL;
50 |
51 | std::unique_ptr sdl_hook;
52 | std::unique_ptr clientdll_hook;
53 | std::unique_ptr enginevgui_hook;
54 | std::unique_ptr modelrender_hook;
55 | std::unique_ptr inputinternal_hook;
56 |
57 | std::unique_ptr testevent;
58 |
59 | extern "C" void __attribute__((constructor)) css_basehook_open() {
60 | // Get class pointers from game libraries using partial interface versions.
61 | cvar = GetInterface("bin/libvstdlib.so", "VEngineCvar0");
62 | panel = GetInterface("bin/vgui2.so", "VGUI_Panel0");
63 | matsurface = GetInterface("bin/vguimatsurface.so", "VGUI_Surface0");
64 | enginevgui = GetInterface("bin/engine.so", "VEngineVGui0");
65 | modelinfo = GetInterface("bin/engine.so", "VModelInfoClient0");
66 | inputsystem = GetInterface("bin/inputsystem.so", "InputSystemVersion0");
67 | inputinternal = GetInterface("bin/vgui2.so", "VGUI_InputInternal0");
68 | engine = GetInterface("bin/engine.so", "VEngineClient0");
69 | modelrender = GetInterface("bin/engine.so", "VEngineModel0");
70 | debugoverlay = GetInterface("bin/engine.so", "VDebugOverlay0");
71 | clientdll = GetInterface("cstrike/bin/client.so", "VClient0");
72 | matsystem = GetInterface("bin/materialsystem.so", "VMaterialSystem0");
73 | entitylist = GetInterface("cstrike/bin/client.so", "VClientEntityList0");
74 | gameevents = GetInterface("bin/engine.so", "GAMEEVENTSMANAGER002");
75 |
76 | // Scan for the 'CRC32_ProcessBuffer' function. (overkill, but why not?)
77 | CRC32_ProcessBuffer = reinterpret_cast(
78 | FindPattern("cstrike/bin/client.so", "\x55\x89\xE5\x57\x56\x53\x83\xEC\x08\x8B\x4D\x10", "xxxxxxxxxxxx")
79 | );
80 |
81 | // Hook 'FrameStageNotify' and 'CreateMove' from IBaseClientDLL.
82 | clientdll_hook = std::make_unique(clientdll);
83 | clientdll_hook->HookFunction(reinterpret_cast(Hooks::CreateMove), 21);
84 | clientdll_hook->HookFunction(reinterpret_cast(Hooks::FrameStageNotify), 35);
85 |
86 | // Scan for 'StartDrawing' and 'FinishDrawing' from CMatSystemSurface.
87 | StartDrawing = reinterpret_cast(
88 | FindPattern("bin/vguimatsurface.so", "\x55\x89\xE5\x53\x83\xEC\x74\x80\x3D\x00\x00\x00\x00\x00", "xxxxxxxxx????x")
89 | );
90 |
91 | FinishDrawing = reinterpret_cast(
92 | FindPattern("bin/vguimatsurface.so", "\x55\x89\xE5\x53\x83\xEC\x24\xC7\x04\x00\x00\x00\x00\x00\xE8\x00\x00\x00\x00\xA1", "xxxxxxxxx????xx????x")
93 | );
94 |
95 | // Hook 'Paint' from IEngineVGui.
96 | enginevgui_hook = std::make_unique(enginevgui);
97 | enginevgui_hook->HookFunction(reinterpret_cast(Hooks::Paint), 14);
98 |
99 | // Hook 'DrawModelExecute' from IVModelRender.
100 | modelrender_hook = std::make_unique(modelrender);
101 | modelrender_hook->HookFunction(reinterpret_cast(Hooks::DrawModelExecute), 19);
102 |
103 | // Hook 'PumpWindowsMessageLoop' and 'ShowPixels' from ILauncherMgr.
104 | launchermgr = **reinterpret_cast(
105 | FindPattern("bin/launcher.so", "\x24\x8B\x1D\x00\x00\x00\x00", "xxx????") + 3
106 | );
107 |
108 | sdl_hook = std::make_unique(launchermgr);
109 | sdl_hook->HookFunction(reinterpret_cast(Hooks::PumpWindowsMessageLoop), 15);
110 | sdl_hook->HookFunction(reinterpret_cast(Hooks::ShowPixels), 29);
111 |
112 | // Hook 'SetKeyCodeState' and 'SetMouseCodeState' from IInputInternal.
113 | inputinternal_hook = std::make_unique(inputinternal);
114 | inputinternal_hook->HookFunction(reinterpret_cast(Hooks::SetKeyCodeState), 83);
115 | inputinternal_hook->HookFunction(reinterpret_cast(Hooks::SetMouseCodeState), 84);
116 |
117 | // Get a pointer to CInput from 'IN_ActivateMouse' in IBaseClientDLL.
118 | input = **reinterpret_cast(
119 | clientdll_hook->GetOriginalFunction(14) + 1
120 | );
121 |
122 | // Get a pointer to CGlobalVarsBase from 'HUDUpdate' in IBaseClientDLL.
123 | globalvars = **reinterpret_cast(
124 | clientdll_hook->GetOriginalFunction(11) + 8
125 | );
126 |
127 | // Register an event listener.
128 | testevent = std::make_unique("player_footstep");
129 | }
130 |
131 | extern "C" void __attribute__((destructor)) css_basehook_close() {
132 | cvar->ConsoleColorPrintf(Color(255, 150, 150), "Unloaded from game successfully.\n");
133 | }
--------------------------------------------------------------------------------
/src/Basehook.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 |
6 | #include
7 | #include
8 |
9 | #include "Utilities/Linker.h"
10 | #include "Utilities/Interfaces.h"
11 | #include "Utilities/NetVars.h"
12 |
13 | #include "Game/Entity.h"
--------------------------------------------------------------------------------
/src/Events/TestListener.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | class TestEventListener: public IGameEventListener2 {
4 | public:
5 | TestEventListener(const char* name) {
6 | // Register self as an event listener.
7 | gameevents->AddListener(this, name, false);
8 | };
9 |
10 | ~TestEventListener() {
11 | // Unregister when destructor is called.
12 | gameevents->RemoveListener(this);
13 | }
14 |
15 | void FireGameEvent(IGameEvent* event) {
16 | // Print text to console when event is fired.
17 | cvar->ConsoleColorPrintf(Color(150, 255, 150), "Event fired: %s\n", event->GetName());
18 | }
19 |
20 | int GetEventDebugID() override {
21 | return EVENT_DEBUG_ID_INIT;
22 | };
23 | };
--------------------------------------------------------------------------------
/src/GUI/Components.cpp:
--------------------------------------------------------------------------------
1 | #include "GUI.h"
2 |
3 | void GUI::DrawFramerateCounter() {
4 | ImGui::SetNextWindowPos(ImVec2(10, 10));
5 | ImGui::Begin("FPS", nullptr, ImVec2(0, 0), 0.3f, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize);
6 | ImGui::Text("FPS: %.2f", ImGui::GetIO().Framerate);
7 | ImGui::End();
8 | }
9 |
10 | void GUI::DrawConfigurationWindow() {
11 | ImGui::Begin("Settings", nullptr);
12 | ImGui::PushItemWidth(-1);
13 |
14 | ImGui::Checkbox("Auto-bunnyhop", &GUI::BunnyHop::Enabled);
15 | ImGui::Spacing();
16 |
17 | ImGui::Checkbox("No sky", &GUI::NoSky::Enabled);
18 | ImGui::ColorEdit3("##No sky color", GUI::NoSky::Color);
19 | ImGui::Spacing();
20 |
21 | ImGui::Checkbox("ASUS walls", &GUI::ASUS::Enabled);
22 | ImGui::ColorEdit4("##ASUS walls color", GUI::ASUS::Color, true);
23 | ImGui::Spacing();
24 |
25 | ImGui::PopItemWidth();
26 | ImGui::End();
27 | }
28 |
--------------------------------------------------------------------------------
/src/GUI/GUI.cpp:
--------------------------------------------------------------------------------
1 | #include "GUI.h"
2 |
3 | bool GUI::IsVisible = false;
4 |
5 | void GUI::Render() {
6 | // Draw various global components.
7 | GUI::DrawFramerateCounter();
8 |
9 | // Draw the actual configuration window.
10 | if (GUI::IsVisible)
11 | GUI::DrawConfigurationWindow();
12 | }
--------------------------------------------------------------------------------
/src/GUI/GUI.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 |
6 | namespace GUI {
7 | extern bool IsVisible;
8 |
9 | namespace BunnyHop {
10 | extern bool Enabled;
11 | }
12 |
13 | namespace NoSky {
14 | extern bool Enabled;
15 | extern float Color[3];
16 | }
17 |
18 | namespace ASUS {
19 | extern bool Enabled;
20 | extern float Color[4];
21 | }
22 |
23 | void DrawFramerateCounter();
24 | void DrawConfigurationWindow();
25 |
26 | void Render();
27 | }
--------------------------------------------------------------------------------
/src/Game/Entity.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | class C_BaseEntity: public IClientEntity {
4 | };
5 |
6 | class C_BasePlayer: public C_BaseEntity {
7 | public:
8 | int GetFlags() {
9 | return *reinterpret_cast(uintptr_t(this) + NetVars::GetOffset("CBasePlayer", "m_fFlags"));
10 | }
11 | };
--------------------------------------------------------------------------------
/src/Hooks/CreateMove.cpp:
--------------------------------------------------------------------------------
1 | #include "Hooks.h"
2 |
3 | typedef void (*CreateMove_t) (IBaseClientDLL*, int, float, bool);
4 |
5 | bool GUI::BunnyHop::Enabled = true;
6 |
7 | void Hooks::CreateMove(IBaseClientDLL* thisptr, int sequence, float frametime, bool active) {
8 | // Get the original function and store it statically.
9 | static CreateMove_t oCreateMove = clientdll_hook->GetOriginalFunction(21);
10 |
11 | // Call original 'IBaseClientDLL::CreateMove'.
12 | oCreateMove(thisptr, sequence, frametime, active);
13 |
14 | // Get the current user command.
15 | CUserCmd* cmd = input->GetUserCmd(sequence);
16 |
17 | // Get the LocalPlayer entity.
18 | C_BasePlayer* localplayer = static_cast(entitylist->GetClientEntity(engine->GetLocalPlayer()));
19 |
20 | // No need to validate if we stop here since we haven't changed anything yet.
21 | if (!localplayer)
22 | return;
23 |
24 | // Auto-bunnyhop when jump key is held. (releases the IN_JUMP button when on ground)
25 | if (GUI::BunnyHop::Enabled && cmd->buttons & IN_JUMP && !(localplayer->GetFlags() & FL_ONGROUND))
26 | cmd->buttons &= ~IN_JUMP;
27 |
28 | // Re-calculate the command checksum after making changes.
29 | input->VerifyUserCmd(cmd, sequence);
30 | }
--------------------------------------------------------------------------------
/src/Hooks/DrawModelExecute.cpp:
--------------------------------------------------------------------------------
1 | #include "Hooks.h"
2 |
3 | typedef void (*DrawModelExecute_t) (IVModelRender*, DrawModelState_t const&, ModelRenderInfo_t const&, matrix3x4_t*);
4 |
5 | void Hooks::DrawModelExecute(IVModelRender* thisptr, DrawModelState_t const& drawmodelstate, ModelRenderInfo_t const& modelrenderinfo, matrix3x4_t* bonetoworld) {
6 | // Get the original function and store it statically.
7 | static DrawModelExecute_t oDrawModelExecute = modelrender_hook->GetOriginalFunction(19);
8 |
9 | // Call original 'IVModelRender::DrawModelExecute'.
10 | oDrawModelExecute(thisptr, drawmodelstate, modelrenderinfo, bonetoworld);
11 | }
--------------------------------------------------------------------------------
/src/Hooks/FrameStageNotify.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include "Hooks.h"
4 |
5 | typedef void (*FrameStageNotify_t) (IBaseClientDLL*, ClientFrameStage_t);
6 |
7 | bool GUI::NoSky::Enabled = true;
8 | float GUI::NoSky::Color[3] = {0, 0, 0.275};
9 |
10 | bool GUI::ASUS::Enabled = true;
11 | float GUI::ASUS::Color[4] = {1, 1, 1, 0.75};
12 |
13 | std::unordered_map material_colors;
14 |
15 | void Hooks::FrameStageNotify(IBaseClientDLL* thisptr, ClientFrameStage_t stage) {
16 | // Get the original function and store it statically.
17 | static FrameStageNotify_t oFrameStageNotify = clientdll_hook->GetOriginalFunction(35);
18 |
19 | // Restore skybox & world materials to original state when disconnected.
20 | if (!engine->IsConnected() && material_colors.size() > 0) {
21 | for (const auto& it: material_colors) {
22 | IMaterial* material = matsystem->GetMaterial(it.first);
23 |
24 | material->ColorModulate(1, 1, 1);
25 | material->AlphaModulate(1);
26 | }
27 |
28 | material_colors.clear();
29 | }
30 |
31 | if (stage == ClientFrameStage_t::FRAME_NET_UPDATE_POSTDATAUPDATE_END) {
32 | for (MaterialHandle_t i = matsystem->FirstMaterial(); i != matsystem->InvalidMaterial(); i = matsystem->NextMaterial(i)) {
33 | // Get the material from the current handle.
34 | IMaterial* material = matsystem->GetMaterial(i);
35 |
36 | // Check for 'SkyBox textures' group.
37 | if (!strcmp(material->GetTextureGroupName(), TEXTURE_GROUP_SKYBOX)) {
38 | if (material_colors.find(i) == material_colors.end())
39 | material_colors.emplace(i, ImColor());
40 |
41 | ImColor color = ImColor(1.0f, 1.0f, 1.0f);
42 |
43 | if (GUI::NoSky::Enabled)
44 | color = ImColor(GUI::NoSky::Color[0], GUI::NoSky::Color[1], GUI::NoSky::Color[2]);
45 |
46 | if (material_colors.at(i) != color) {
47 | material->ColorModulate(color.Value.x, color.Value.y, color.Value.z);
48 |
49 | material_colors.at(i) = color;
50 | }
51 |
52 | continue;
53 | }
54 |
55 | // Check for 'World textures' group.
56 | if (!strcmp(material->GetTextureGroupName(), TEXTURE_GROUP_WORLD)) {
57 | if (material_colors.find(i) == material_colors.end())
58 | material_colors.emplace(i, ImColor());
59 |
60 | ImColor color = ImColor(1.0f, 1.0f, 1.0f);
61 |
62 | if (GUI::ASUS::Enabled)
63 | color = ImColor(GUI::ASUS::Color[0], GUI::ASUS::Color[1], GUI::ASUS::Color[2], GUI::ASUS::Color[3]);
64 |
65 | if (material_colors.at(i) != color) {
66 | material->ColorModulate(color.Value.x, color.Value.y, color.Value.z);
67 | material->AlphaModulate(color.Value.w);
68 |
69 | material_colors.at(i) = color;
70 | }
71 | }
72 | }
73 | }
74 |
75 | // Call original 'IBaseClientDLL::FrameStageNotify'.
76 | oFrameStageNotify(thisptr, stage);
77 | }
--------------------------------------------------------------------------------
/src/Hooks/Hooks.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "../Basehook.h"
4 | #include "../GUI/GUI.h"
5 |
6 | // Extra functions neccessary for proper engine drawing.
7 | typedef void (*StartDrawing_t) (ISurface*);
8 | typedef void (*FinishDrawing_t) (ISurface*);
9 |
10 | namespace Hooks {
11 | // ILauncherMgr
12 | void PumpWindowsMessageLoop(ILauncherMgr*);
13 | void ShowPixels(ILauncherMgr*, CShowPixelsParams*);
14 |
15 | // IBaseClientDLL
16 | void CreateMove(IBaseClientDLL*, int, float, bool);
17 | void FrameStageNotify(IBaseClientDLL*, ClientFrameStage_t);
18 |
19 | // IEngineVGui
20 | void Paint(IEngineVGui*, PaintMode_t);
21 |
22 | // IVModelRender
23 | void DrawModelExecute(IVModelRender*, DrawModelState_t const&, ModelRenderInfo_t const&, matrix3x4_t*);
24 |
25 | // IInputInternal
26 | void SetKeyCodeState(IInputInternal*, KeyCode, bool);
27 | void SetMouseCodeState(IInputInternal*, MouseCode, MouseCodeState_t);
28 | }
29 |
30 | extern std::unique_ptr sdl_hook;
31 | extern std::unique_ptr clientdll_hook;
32 | extern std::unique_ptr enginevgui_hook;
33 | extern std::unique_ptr modelrender_hook;
34 | extern std::unique_ptr inputinternal_hook;
--------------------------------------------------------------------------------
/src/Hooks/Paint.cpp:
--------------------------------------------------------------------------------
1 | #include "Hooks.h"
2 |
3 | extern StartDrawing_t StartDrawing;
4 | extern FinishDrawing_t FinishDrawing;
5 |
6 | typedef void (*Paint_t) (IEngineVGui*, PaintMode_t);
7 |
8 | void Hooks::Paint(IEngineVGui* thisptr, PaintMode_t mode) {
9 | // Get the original function and store it statically.
10 | static Paint_t oPaint = enginevgui_hook->GetOriginalFunction(14);
11 |
12 | // Call original 'IEngineVGui::Paint'.
13 | oPaint(thisptr, mode);
14 |
15 | if (mode & PaintMode_t::PAINT_UIPANELS) {
16 | StartDrawing(matsurface);
17 |
18 | // Set watermark text.
19 | const wchar_t* watermark = L"cstrike-basehook-linux";
20 |
21 | // Set position of watermark text. (bottom-right)
22 | int width = 0, height = 0, wide = 0, tall = 0;
23 | engine->GetScreenSize(width, height);
24 | matsurface->GetTextSize(37, watermark, wide, tall);
25 |
26 | // Do stuff here then call FinishDrawing.
27 | matsurface->DrawSetTextColor(Color(150, 150, 255));
28 | matsurface->DrawSetTextPos((width - wide) - 15, (height - tall) - 15);
29 | matsurface->DrawSetTextFont(37);
30 | matsurface->DrawPrintText(L"cstrike-basehook-linux", 23);
31 |
32 | FinishDrawing(matsurface);
33 | }
34 | }
--------------------------------------------------------------------------------
/src/Hooks/PumpWindowsMessageLoop.cpp:
--------------------------------------------------------------------------------
1 | #include "Hooks.h"
2 |
3 | typedef void (*PumpWindowsMessageLoop_t) (ILauncherMgr*);
4 |
5 | void Hooks::PumpWindowsMessageLoop(ILauncherMgr* thisptr) {
6 | // Get the original function and store it statically.
7 | static PumpWindowsMessageLoop_t oPumpWindowsMessageLoop = sdl_hook->GetOriginalFunction(15);
8 |
9 | // Block game input while the GUI is visible.
10 | if (GUI::IsVisible)
11 | return;
12 |
13 | // Call original 'ILauncherMgr::PumpWindowsMessageLoop'.
14 | oPumpWindowsMessageLoop(thisptr);
15 | }
--------------------------------------------------------------------------------
/src/Hooks/SetKeyCodeState.cpp:
--------------------------------------------------------------------------------
1 | #include "Hooks.h"
2 |
3 | typedef void (*SetKeyCodeState_t) (IInputInternal*, KeyCode, bool);
4 |
5 | void Hooks::SetKeyCodeState(IInputInternal* thisptr, KeyCode code, bool down) {
6 | // Get the original function and store it statically.
7 | static SetKeyCodeState_t oSetKeyCodeState = inputinternal_hook->GetOriginalFunction(83);
8 |
9 | // Print to console every time a key is pressed or released.
10 | cvar->ConsoleColorPrintf(Color(150, 150, 255, 255), "IInputInternal::SetKeyCodeState - code: %i, down: %i\n", code, down);
11 |
12 | // Check if we should open the menu.
13 | if (code == KeyCode::KEY_INSERT && down == false)
14 | GUI::IsVisible = true;
15 |
16 | // Call original 'IInputInternal::SetKeyCodeState'.
17 | oSetKeyCodeState(thisptr, code, down);
18 | }
--------------------------------------------------------------------------------
/src/Hooks/SetMouseCodeState.cpp:
--------------------------------------------------------------------------------
1 | #include "Hooks.h"
2 |
3 | typedef void (*SetMouseCodeState_t) (IInputInternal*, MouseCode, MouseCodeState_t);
4 |
5 | void Hooks::SetMouseCodeState(IInputInternal* thisptr, MouseCode code, MouseCodeState_t state) {
6 | // Get the original function and store it statically.
7 | static SetMouseCodeState_t oSetMouseCodeState = inputinternal_hook->GetOriginalFunction(84);
8 |
9 | // Print to console every time a mouse button is clicked, double-clicked or released.
10 | cvar->ConsoleColorPrintf(Color(150, 150, 255, 255), "IInputInternal::SetMouseCodeState - code: %i, state: %i\n", code, state);
11 |
12 | // Call original 'IInputInternal::SetMouseCodeState'.
13 | oSetMouseCodeState(thisptr, code, state);
14 | }
--------------------------------------------------------------------------------
/src/Hooks/ShowPixels.cpp:
--------------------------------------------------------------------------------
1 | #include "Hooks.h"
2 | #include "../GUI/GUI.h"
3 |
4 | typedef void (*ShowPixels_t) (ILauncherMgr*, CShowPixelsParams*);
5 |
6 | void Hooks::ShowPixels(ILauncherMgr* thisptr, CShowPixelsParams* params) {
7 | // Get the original function and store it statically.
8 | static ShowPixels_t oShowPixels = sdl_hook->GetOriginalFunction(29);
9 |
10 | if (!params->m_noBlit)
11 | return oShowPixels(thisptr, params);
12 |
13 | // Also store the game window, original and user contexts statically.
14 | static SDL_Window* window = reinterpret_cast(launchermgr->GetWindowRef());
15 |
16 | static PseudoGLContextPtr original_context = launchermgr->GetMainContext();
17 | static PseudoGLContextPtr user_context = nullptr;
18 |
19 | // Set up our context on first execution.
20 | if (!user_context) {
21 | user_context = launchermgr->CreateExtraContext();
22 | ImGui_ImplSdl_Init(window);
23 | }
24 |
25 | // Switch to our context.
26 | launchermgr->MakeContextCurrent(user_context);
27 |
28 | // Start ImGui rendering.
29 | ImGui_ImplSdl_NewFrame(window);
30 |
31 | // Enable or disable the ImGui cursor depending on the GUI visibility.
32 | ImGui::GetIO().MouseDrawCursor = GUI::IsVisible;
33 | ImGui::GetIO().WantCaptureMouse = GUI::IsVisible;
34 | ImGui::GetIO().WantCaptureKeyboard = GUI::IsVisible;
35 |
36 | // Handle incoming input while the menu is active.
37 | if (GUI::IsVisible) {
38 | SDL_Event event = {};
39 |
40 | while (SDL_PollEvent(&event)) {
41 | if (event.key.keysym.sym == SDLK_INSERT && event.type == SDL_KEYDOWN)
42 | GUI::IsVisible = !GUI::IsVisible;
43 |
44 | ImGui_ImplSdl_ProcessEvent(&event);
45 | }
46 | }
47 |
48 | // Draw GUI components.
49 | GUI::Render();
50 |
51 | // Finish ImGui rendering.
52 | ImGui::Render();
53 |
54 | // Switch back to the game context.
55 | launchermgr->MakeContextCurrent(original_context);
56 |
57 | // Call original 'ILauncherMgr::ShowPixels'.
58 | oShowPixels(thisptr, params);
59 | }
--------------------------------------------------------------------------------
/src/Utilities/FindPattern.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | // Slightly modified version of P47R!CK & dom1n1k's pattern scanner.
4 | inline bool Compare(const uint8_t* data, const uint8_t* pattern, const char* mask) {
5 | for (; *mask; ++mask, ++data, ++pattern) {
6 | if (*mask == 'x' && *data != *pattern) {
7 | return false;
8 | }
9 | }
10 |
11 | return *mask == 0;
12 | }
13 |
14 | static uintptr_t FindPattern(const char* library, const char* pattern_string, const char* mask) {
15 | size_t address = 0, length = 0;
16 |
17 | if (!Linker::GetLibraryInformation(library, &address, &length))
18 | return 0;
19 |
20 | const uint8_t* pattern = reinterpret_cast(pattern_string);
21 |
22 | for (size_t i = 0; i < length; i++) {
23 | if (Compare(reinterpret_cast(address + i), pattern, mask)) {
24 | return address + i;
25 | }
26 | }
27 |
28 | return 0;
29 | }
--------------------------------------------------------------------------------
/src/Utilities/Interfaces.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 |
6 | typedef void* (*InstantiateInterfaceFn) ();
7 |
8 | class InterfaceReg {
9 | public:
10 | InstantiateInterfaceFn m_CreateFn;
11 | const char* m_pName;
12 | InterfaceReg* m_pNext;
13 | };
14 |
15 | inline const InterfaceReg* GetInterfaces(const char* library) {
16 | // Open a handle to the library.
17 | void* library_handle = dlopen(library, RTLD_NOLOAD | RTLD_NOW);
18 |
19 | // Check for an exported 's_pInterfaceRegs' symbol. (easy mode)
20 | void* interfaceregs_symbol = dlsym(library_handle, "s_pInterfaceRegs");
21 |
22 | if (interfaceregs_symbol) {
23 | // Close the handle to the library.
24 | dlclose(library_handle);
25 |
26 | // Return interface list.
27 | return *reinterpret_cast(interfaceregs_symbol);
28 | }
29 |
30 | // Get the address to the exported 'CreateInterface' symbol.
31 | void* createinterface_symbol = dlsym(library_handle, "CreateInterface");
32 |
33 | // Close the handle to the library.
34 | dlclose(library_handle);
35 |
36 | // Get the jump displacement to the 'CreateInterfaceInternal' function.
37 | uintptr_t jump_instruction = uintptr_t(createinterface_symbol) + 4;
38 | int32_t jump_displacement = *reinterpret_cast(jump_instruction + 1);
39 |
40 | // Calculate the absolute jump address relative to the next instruction.
41 | uintptr_t createinterfaceinternal_addr = (jump_instruction + 5) + jump_displacement;
42 |
43 | // Read the address to the 'InterfaceReg::s_pInterfaceRegs' linked list from 11 bytes in.
44 | uintptr_t interface_list = *reinterpret_cast(createinterfaceinternal_addr + 11);
45 |
46 | return *reinterpret_cast(interface_list);
47 | }
48 |
49 | template inline T* GetInterface(const char* library, const char* partial_version) {
50 | for (const InterfaceReg* current = GetInterfaces(library); current; current = current->m_pNext) {
51 | if (std::string(current->m_pName).find(partial_version) != std::string::npos) {
52 | return reinterpret_cast(current->m_CreateFn());
53 | }
54 | }
55 |
56 | return nullptr;
57 | }
--------------------------------------------------------------------------------
/src/Utilities/Linker.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include "Linker.h"
6 |
7 | struct dlinfo_t {
8 | // Full path to shared library on filesystem.
9 | const char* library = nullptr;
10 |
11 | // Absolute 'start address' in memory.
12 | uintptr_t address = 0;
13 |
14 | // Size in memory - accuracy is questionable.
15 | size_t size = 0;
16 | };
17 |
18 | std::vector libraries;
19 |
20 | bool Linker::GetLibraryInformation(const char* library, uintptr_t* address, size_t* size) {
21 | if (libraries.size() == 0) {
22 | dl_iterate_phdr([] (struct dl_phdr_info* info, size_t, void*) {
23 | dlinfo_t library_info = {};
24 |
25 | library_info.library = info->dlpi_name;
26 | library_info.address = info->dlpi_addr + info->dlpi_phdr[0].p_vaddr;
27 | library_info.size = info->dlpi_phdr[0].p_memsz;
28 |
29 | libraries.push_back(library_info);
30 |
31 | return 0;
32 | }, nullptr);
33 | }
34 |
35 | for (const dlinfo_t& current: libraries) {
36 | if (!strcasestr(current.library, library))
37 | continue;
38 |
39 | if (address)
40 | *address = current.address;
41 |
42 | if (size)
43 | *size = current.size;
44 |
45 | return true;
46 | }
47 |
48 | return false;
49 | }
--------------------------------------------------------------------------------
/src/Utilities/Linker.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | namespace Linker {
4 | // Iterate loaded shared libraries and optionally return base address and size.
5 | bool GetLibraryInformation(const char*, uintptr_t* = nullptr, size_t* = nullptr);
6 | }
--------------------------------------------------------------------------------
/src/Utilities/NetVars.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | typedef std::unordered_map PropertyCache;
6 | typedef std::unordered_map ClassCache;
7 |
8 | static ClassCache class_cache;
9 |
10 | class NetVars {
11 | private:
12 | static uintptr_t FindOffset(RecvTable* recv_table, const char* property_name, RecvProp** property_ptr = nullptr) {
13 | for (int i = 0; i < recv_table->m_nProps; i++) {
14 | RecvProp& recv_prop = recv_table->m_pProps[i];
15 |
16 | if (strcmp(recv_prop.m_pVarName, property_name) == 0) {
17 | if (property_ptr)
18 | *property_ptr = &recv_table->m_pProps[i];
19 |
20 | return recv_prop.m_Offset;
21 | }
22 |
23 | if (recv_prop.m_RecvType != SendPropType::DPT_DataTable) {
24 | continue;
25 | }
26 |
27 | if (uintptr_t offset = FindOffset(recv_prop.m_pDataTable, property_name)) {
28 | if (property_ptr)
29 | *property_ptr = &recv_table->m_pProps[i];
30 |
31 | return recv_prop.m_Offset + offset;
32 | }
33 | }
34 |
35 | return 0;
36 | }
37 | public:
38 | static uintptr_t GetOffset(const char* class_name, const char* property_name, RecvProp** property_ptr = nullptr) {
39 | ClassCache::iterator class_cache_itr = class_cache.find(class_name);
40 |
41 | if (class_cache_itr != class_cache.end()) {
42 | PropertyCache& property_cache = class_cache_itr->second;
43 | PropertyCache::iterator property_cache_itr = property_cache.find(property_name);
44 |
45 | if (property_cache_itr != property_cache.end()) {
46 | return property_cache_itr->second;
47 | }
48 | }
49 |
50 | for (ClientClass* class_ptr = clientdll->GetAllClasses(); class_ptr; class_ptr = class_ptr->m_pNext) {
51 | if (strcmp(class_ptr->m_pNetworkName, class_name) == 0) {
52 | uintptr_t result = FindOffset(class_ptr->m_pRecvTable, property_name, property_ptr);
53 | class_cache[class_name][property_name] = result;
54 |
55 | return result;
56 | }
57 | }
58 |
59 | return 0;
60 | }
61 | };
62 |
--------------------------------------------------------------------------------