From 9f3983409059c87ff0def6f9527f289e93cd252b Mon Sep 17 00:00:00 2001 From: Edo Date: Mon, 2 Jan 2023 17:04:34 +0000 Subject: [PATCH] [General]: Clean structs (#692) --- src/Components/Modules/ClientCommand.cpp | 8 +- src/Components/Modules/Command.cpp | 6 +- src/Components/Modules/Command.hpp | 6 +- src/Components/Modules/Debug.cpp | 6 +- src/Components/Modules/GSC/Script.cpp | 2 +- src/Components/Modules/Maps.cpp | 2 +- src/Components/Modules/Maps.hpp | 2 +- src/Game/FileSystem.cpp | 2 +- src/Game/FileSystem.hpp | 2 +- src/Game/Functions.cpp | 2 +- src/Game/Functions.hpp | 6 +- src/Game/Structs.hpp | 187 +++++++++++++---------- 12 files changed, 125 insertions(+), 106 deletions(-) diff --git a/src/Components/Modules/ClientCommand.cpp b/src/Components/Modules/ClientCommand.cpp index 5de247e1..3b8bc3fb 100644 --- a/src/Components/Modules/ClientCommand.cpp +++ b/src/Components/Modules/ClientCommand.cpp @@ -66,12 +66,12 @@ namespace Components if (!CheatsOk(ent)) return; - ent->client->flags ^= Game::PLAYER_FLAG_NOCLIP; + ent->client->flags ^= Game::PF_NOCLIP; const auto entNum = ent->s.number; Logger::Debug("Noclip toggled for entity {}", entNum); - Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, VA("%c \"%s\"", 0x65, (ent->client->flags & Game::PLAYER_FLAG_NOCLIP) ? "GAME_NOCLIPON" : "GAME_NOCLIPOFF")); + Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, VA("%c \"%s\"", 0x65, (ent->client->flags & Game::PF_NOCLIP) ? "GAME_NOCLIPON" : "GAME_NOCLIPOFF")); }); Add("ufo", [](Game::gentity_s* ent, [[maybe_unused]] const Command::ServerParams* params) @@ -79,12 +79,12 @@ namespace Components if (!CheatsOk(ent)) return; - ent->client->flags ^= Game::PLAYER_FLAG_UFO; + ent->client->flags ^= Game::PF_UFO; const auto entNum = ent->s.number; Logger::Debug("UFO toggled for entity {}", entNum); - Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, VA("%c \"%s\"", 0x65, (ent->client->flags & Game::PLAYER_FLAG_UFO) ? "GAME_UFOON" : "GAME_UFOOFF")); + Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, VA("%c \"%s\"", 0x65, (ent->client->flags & Game::PF_UFO) ? "GAME_UFOON" : "GAME_UFOOFF")); }); Add("god", [](Game::gentity_s* ent, [[maybe_unused]] const Command::ServerParams* params) diff --git a/src/Components/Modules/Command.cpp b/src/Components/Modules/Command.cpp index 9afca701..773a108e 100644 --- a/src/Components/Modules/Command.cpp +++ b/src/Components/Modules/Command.cpp @@ -130,7 +130,7 @@ namespace Components } } - Game::cmd_function_t* Command::Find(const std::string& command) + Game::cmd_function_s* Command::Find(const std::string& command) { auto* cmdFunction = *Game::cmd_functions; @@ -147,9 +147,9 @@ namespace Components return nullptr; } - Game::cmd_function_t* Command::Allocate() + Game::cmd_function_s* Command::Allocate() { - return Utils::Memory::GetAllocator()->allocate(); + return Utils::Memory::GetAllocator()->allocate(); } void Command::MainCallback() diff --git a/src/Components/Modules/Command.hpp b/src/Components/Modules/Command.hpp index 9ed9889c..e51d69f7 100644 --- a/src/Components/Modules/Command.hpp +++ b/src/Components/Modules/Command.hpp @@ -5,7 +5,7 @@ namespace Components class Command : public Component { public: - static_assert(sizeof(Game::cmd_function_t) == 0x18); + static_assert(sizeof(Game::cmd_function_s) == 0x18); class Params { @@ -49,7 +49,7 @@ namespace Components Command() = default; - static Game::cmd_function_t* Allocate(); + static Game::cmd_function_s* Allocate(); static void Add(const char* name, const std::function& callback); static void Add(const char* name, const std::function& callback); @@ -57,7 +57,7 @@ namespace Components static void AddSV(const char* name, const std::function& callback); static void Execute(std::string command, bool sync = true); - static Game::cmd_function_t* Find(const std::string& command); + static Game::cmd_function_s* Find(const std::string& command); private: static std::unordered_map> FunctionMap; diff --git a/src/Components/Modules/Debug.cpp b/src/Components/Modules/Debug.cpp index 9e742f22..31f9e550 100644 --- a/src/Components/Modules/Debug.cpp +++ b/src/Components/Modules/Debug.cpp @@ -269,9 +269,9 @@ namespace Components void Debug::Com_Bug_f(Command::Params* params) { - char newFileName[0x105]{}; - char to_ospath[MAX_PATH]{}; - char from_ospath[MAX_PATH]{}; + char newFileName[MAX_PATH]{}; + char to_ospath[MAX_OSPATH]{}; + char from_ospath[MAX_OSPATH]{}; const char* bug; if (!*Game::logfile) diff --git a/src/Components/Modules/GSC/Script.cpp b/src/Components/Modules/GSC/Script.cpp index e662ccf6..c3b5570a 100644 --- a/src/Components/Modules/GSC/Script.cpp +++ b/src/Components/Modules/GSC/Script.cpp @@ -630,7 +630,7 @@ namespace Components { const auto* ent = Scr_GetPlayerEntity(entref); - Game::Scr_AddBool((ent->client->flags & Game::PLAYER_FLAG_FROZEN) != 0); + Game::Scr_AddBool((ent->client->flags & Game::PF_FROZEN) != 0); }); } diff --git a/src/Components/Modules/Maps.cpp b/src/Components/Modules/Maps.cpp index a19e0361..74739a29 100644 --- a/src/Components/Modules/Maps.cpp +++ b/src/Components/Modules/Maps.cpp @@ -79,7 +79,7 @@ namespace Components this->wasFreed = true; // Unchain our searchpath - for (Game::searchpath_t** pathPtr = Game::fs_searchpaths; *pathPtr; pathPtr = &(*pathPtr)->next) + for (auto** pathPtr = Game::fs_searchpaths; *pathPtr; pathPtr = &(*pathPtr)->next) { if (*pathPtr == &this->searchPath) { diff --git a/src/Components/Modules/Maps.hpp b/src/Components/Modules/Maps.hpp index 915f6069..b5a6ef2a 100644 --- a/src/Components/Modules/Maps.hpp +++ b/src/Components/Modules/Maps.hpp @@ -43,7 +43,7 @@ namespace Components bool wasFreed; unsigned int hash; std::string mapname; - Game::searchpath_t searchPath; + Game::searchpath_s searchPath; }; Maps(); diff --git a/src/Game/FileSystem.cpp b/src/Game/FileSystem.cpp index eb51f368..4486f405 100644 --- a/src/Game/FileSystem.cpp +++ b/src/Game/FileSystem.cpp @@ -29,7 +29,7 @@ namespace Game FS_Delete_t FS_Delete = FS_Delete_t(0x48A5B0); FS_BuildOSPath_t FS_BuildOSPath = FS_BuildOSPath_t(0x4702C0); - searchpath_t** fs_searchpaths = reinterpret_cast(0x63D96E0); + searchpath_s** fs_searchpaths = reinterpret_cast(0x63D96E0); int FS_FOpenFileReadCurrentThread(const char* filename, int* file) { diff --git a/src/Game/FileSystem.hpp b/src/Game/FileSystem.hpp index a89f887f..41a0029e 100644 --- a/src/Game/FileSystem.hpp +++ b/src/Game/FileSystem.hpp @@ -80,7 +80,7 @@ namespace Game typedef void(*FS_BuildOSPath_t)(const char* base, const char* game, const char* qpath, char* ospath); extern FS_BuildOSPath_t FS_BuildOSPath; - extern searchpath_t** fs_searchpaths; + extern searchpath_s** fs_searchpaths; extern int FS_FOpenFileReadCurrentThread(const char* filename, int* file); diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index ed6f44c8..aff6d1af 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -267,7 +267,7 @@ namespace Game CmdArgs* cmd_args = reinterpret_cast(0x1AAC5D0); CmdArgs* sv_cmd_args = reinterpret_cast(0x1ACF8A0); - cmd_function_t** cmd_functions = reinterpret_cast(0x1AAC658); + cmd_function_s** cmd_functions = reinterpret_cast(0x1AAC658); source_t** sourceFiles = reinterpret_cast(0x7C4A98); diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 45ed25bf..8e9a9d66 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -51,10 +51,10 @@ namespace Game typedef void(*CG_SetupWeaponDef_t)(int localClientNum, unsigned int weapIndex); extern CG_SetupWeaponDef_t CG_SetupWeaponDef; - typedef void(*Cmd_AddCommand_t)(const char* cmdName, void(*function), cmd_function_t* allocedCmd, int isKey); + typedef void(*Cmd_AddCommand_t)(const char* cmdName, void(*function), cmd_function_s* allocedCmd, int isKey); extern Cmd_AddCommand_t Cmd_AddCommand; - typedef void(*Cmd_AddServerCommand_t)(const char* name, void(*callback), cmd_function_t* data); + typedef void(*Cmd_AddServerCommand_t)(const char* name, void(*callback), cmd_function_s* data); extern Cmd_AddServerCommand_t Cmd_AddServerCommand; typedef void(*Cmd_ExecuteSingleCommand_t)(int localClientNum, int controllerIndex, const char* cmd); @@ -610,7 +610,7 @@ namespace Game extern CmdArgs* cmd_args; extern CmdArgs* sv_cmd_args; - extern cmd_function_t** cmd_functions; + extern cmd_function_s** cmd_functions; extern float* cgameFOVSensitivityScale; diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index f27366c1..e39fbdbc 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -4,6 +4,9 @@ #define NUM_CUSTOM_CLASSES 15 #define FX_ELEM_FIELD_COUNT 90 +#define MAX_QPATH 64 +#define MAX_OSPATH 256 + // This allows us to compile our structures in IDA, for easier reversing :3 #ifndef __cplusplus #define IDA @@ -614,7 +617,7 @@ namespace Game CLASS_NUM_COUNT = 0x6, }; - typedef enum + enum hitLocation_t { HITLOC_NONE, HITLOC_HELMET, @@ -637,7 +640,7 @@ namespace Game HITLOC_GUN, HITLOC_SHIELD, HITLOC_NUM - } hitLocation_t; + }; enum svscmd_type { @@ -664,7 +667,7 @@ namespace Game static_assert(sizeof(CmdArgs) == 0x84); - typedef struct cmd_function_s + struct cmd_function_s { cmd_function_s* next; const char* name; @@ -672,7 +675,7 @@ namespace Game const char* autoCompleteExt; void(__cdecl* function)(); int flags; - } cmd_function_t; + }; #pragma pack(push, 4) struct kbutton_t @@ -2096,7 +2099,7 @@ namespace Game int extrapolatedSnapshot; int newSnapshots; int serverId; - char mapname[64]; + char mapname[MAX_QPATH]; int parseEntitiesIndex; int parseClientsIndex; int mouseDx[2]; @@ -5810,9 +5813,9 @@ namespace Game struct iwd_t { - char iwdFilename[256]; - char iwdBasename[256]; - char iwdGamename[256]; + char iwdFilename[MAX_OSPATH]; + char iwdBasename[MAX_OSPATH]; + char iwdGamename[MAX_OSPATH]; char* handle; int checksum; int pure_checksum; @@ -5851,12 +5854,13 @@ namespace Game char name[256]; }; - typedef struct { - char path[256]; // c:\quake3 - char gamedir[256]; // baseq3 - } directory_t; + struct directory_t + { + char path[MAX_OSPATH]; + char gamedir[MAX_OSPATH]; + }; - typedef struct searchpath_s + struct searchpath_s { searchpath_s* next; iwd_t* iwd; @@ -5865,7 +5869,7 @@ namespace Game int ignore; int ignorePureCheck; int language; - } searchpath_t; + }; struct SafeArea { @@ -5891,9 +5895,35 @@ namespace Game typedef char mapname_t[40]; + struct TraceExtents + { + float midPoint[3]; + float halfDelta[3]; + float halfDeltaAbs[3]; + float invDeltaAbs[3]; + float start[3]; + float end[3]; + }; + + struct TraceCheckCount + { + int global; + int* partitions; + }; + + struct TraceThreadInfo + { + TraceCheckCount checkcount; + }; + + struct CM_WorldTraceCallbacks + { + bool(*isGlassSolid)(unsigned int); + }; + struct traceWork_t { - /*TraceExtents*/int extents; + TraceExtents extents; float delta[3]; float deltaLen; float deltaLenSq; @@ -5908,8 +5938,8 @@ namespace Game float offset[3]; float radiusOffset[3]; float boundingRadius; - /*TraceThreadInfo*/ int threadInfo; - /*CM_WorldTraceCallbacks*/ void* callbacks; + TraceThreadInfo threadInfo; + CM_WorldTraceCallbacks* callbacks; }; struct gameState_t @@ -6583,7 +6613,7 @@ namespace Game struct FxEditorEffectDef { - char name[64]; + char name[MAX_QPATH]; int elemCount; FxEditorElemDef elems[32]; }; @@ -6720,29 +6750,29 @@ namespace Game DB_ZONE_DEV = 0x40 }; - enum playerFlag + enum { - PLAYER_FLAG_NOCLIP = 1 << 0, - PLAYER_FLAG_UFO = 1 << 1, - PLAYER_FLAG_FROZEN = 1 << 2, + PF_NOCLIP = 1 << 0, + PF_UFO = 1 << 1, + PF_FROZEN = 1 << 2, }; - typedef enum + enum sessionState_t { SESS_STATE_PLAYING = 0x0, SESS_STATE_DEAD = 0x1, SESS_STATE_SPECTATOR = 0x2, SESS_STATE_INTERMISSION = 0x3 - } sessionState_t; + }; - typedef enum + enum clientConnected_t { CON_DISCONNECTED = 0x0, CON_CONNECTING = 0x1, CON_CONNECTED = 0x2 - } clientConnected_t; + }; - typedef enum + enum visionSetMode_t { VISIONSET_NORMAL, VISIONSET_NIGHT, @@ -6750,7 +6780,7 @@ namespace Game VISIONSET_THERMAL, VISIONSET_PAIN, VISIONSETCOUNT - } visionSetMode_t; + }; enum hintType_t { @@ -6959,8 +6989,8 @@ namespace Game const char* name; int ofs; fieldtype_t type; - void(__cdecl* setter)(gentity_s*, int); - void(__cdecl* getter)(gentity_s*, int); + void(*setter)(gentity_s*, int); + void(*getter)(gentity_s*, int); }; struct client_fields_s @@ -6968,12 +6998,12 @@ namespace Game const char* name; int ofs; fieldtype_t type; - void(__cdecl* setter)(gclient_s*, const client_fields_s*); - void(__cdecl* getter)(gclient_s*, const client_fields_s*); + void(*setter)(gclient_s*, const client_fields_s*); + void(*getter)(gclient_s*, const client_fields_s*); }; - typedef void(__cdecl* ScriptCallbackEnt)(gentity_s*, int); - typedef void(__cdecl* ScriptCallbackClient)(gclient_s*, const client_fields_s*); + typedef void(*ScriptCallbackEnt)(gentity_s*, int); + typedef void(*ScriptCallbackClient)(gclient_s*, const client_fields_s*); struct lockonFireParms { @@ -7098,7 +7128,7 @@ namespace Game char serverCommands[128][1024]; bool isServerRestarting; int lastClientArchiveIndex; - char demoName[64]; + char demoName[MAX_QPATH]; int demorecording; int demoplaying; int isTimeDemo; @@ -7177,56 +7207,56 @@ namespace Game typedef struct script_s { - char filename[64]; //file name of the script - char* buffer; //buffer containing the script - char* script_p; //current pointer in the script - char* end_p; //pointer to the end of the script - char* lastscript_p; //script pointer before reading token - char* whitespace_p; //begin of the white space - char* endwhitespace_p; //end of the white space - int length; //length of the script in bytes - int line; //current line in script - int lastline; //line before reading token - int tokenavailable; //set by UnreadLastToken - int flags; //several script flags - punctuation_t* punctuations; //the punctuations used in the script + char filename[64]; //file name of the script + char* buffer; //buffer containing the script + char* script_p; //current pointer in the script + char* end_p; //pointer to the end of the script + char* lastscript_p; //script pointer before reading token + char* whitespace_p; //begin of the white space + char* endwhitespace_p; //end of the white space + int length; //length of the script in bytes + int line; //current line in script + int lastline; //line before reading token + int tokenavailable; //set by UnreadLastToken + int flags; //several script flags + punctuation_t* punctuations; //the punctuations used in the script punctuation_t** punctuationtable; - token_t token; //available token - struct script_s* next; //next script in a chain + token_t token; //available token + script_s* next; //next script in a chain } script_t; typedef struct define_s { - char* name; //define name - int flags; //define flags - int builtin; // > 0 if builtin define - int numparms; //number of define parameters - token_t* parms; //define parameters - token_t* tokens; //macro tokens (possibly containing parm tokens) - struct define_s* next; //next defined macro in a list - struct define_s* hashnext; //next define in the hash chain + char* name; //define name + int flags; //define flags + int builtin; // > 0 if builtin define + int numparms; //number of define parameters + token_t* parms; //define parameters + token_t* tokens; //macro tokens (possibly containing parm tokens) + define_s* next; //next defined macro in a list + define_s* hashnext; //next define in the hash chain } define_t; typedef struct indent_s { - int type; //indent type - int skip; //true if skipping current indent - script_t* script; //script the indent was in - struct indent_s* next; //next indent on the indent stack + int type; //indent type + int skip; //true if skipping current indent + script_t* script; //script the indent was in + indent_s* next; //next indent on the indent stack } indent_t; typedef struct source_s { - char filename[64]; //file name of the script - char includepath[64]; //path to include files - punctuation_t* punctuations; //punctuations to use - script_t* scriptstack; //stack with scripts of the source - token_t* tokens; //tokens to read first - define_t* defines; //list with macro definitions - define_t** definehash; //hash chain with defines - indent_t* indentstack; //stack with indents - int skip; // > 0 if skipping conditional code - token_t token; //last read token + char filename[MAX_QPATH]; //file name of the script + char includepath[MAX_QPATH]; //path to include files + punctuation_t* punctuations; //punctuations to use + script_t* scriptstack; //stack with scripts of the source + token_t* tokens; //tokens to read first + define_t* defines; //list with macro definitions + define_t** definehash; //hash chain with defines + indent_t* indentstack; //stack with indents + int skip; // > 0 if skipping conditional code + token_t token; //last read token } source_t; typedef struct pc_token_s @@ -8958,7 +8988,7 @@ namespace Game struct animation_s { - char name[64]; + char name[MAX_QPATH]; int initialLerp; float moveSpeed; int duration; @@ -10387,17 +10417,6 @@ namespace Game int index; }; - struct TraceCheckCount - { - int global; - int* partitions; - }; - - struct TraceThreadInfo - { - TraceCheckCount checkcount; - }; - struct ProfileAtom { unsigned int value[1];