From b861f5cc560c60a1362d847efc06fb4c141a0975 Mon Sep 17 00:00:00 2001 From: JezuzLizard Date: Fri, 24 Mar 2023 20:21:50 -0700 Subject: [PATCH] Add more structs, and more script functions. --- src/game/game.cpp | 153 ++++++++++++++++++++++++++++++++++++++++++- src/game/game.hpp | 22 +++++++ src/game/structs.hpp | 47 +++++++++++++ src/game/symbols.hpp | 2 + 4 files changed, 221 insertions(+), 3 deletions(-) diff --git a/src/game/game.cpp b/src/game/game.cpp index 5b0a3aa..0b316b5 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -39,6 +39,19 @@ namespace game return answer; } + void Scr_AddInt(game::scriptInstance_t inst, int value) + { + static const auto call_addr = SELECT(0x0, 0x69A610); + + __asm + { + push value; + mov eax, inst; + call call_addr; + add esp, 4; + } + } + float Scr_GetFloat(game::scriptInstance_t inst, unsigned int arg_index) { static const auto call_addr = SELECT(0x0, 0x699E90); @@ -49,12 +62,25 @@ namespace game mov ecx, arg_index; mov eax, inst; call call_addr; - mov answer, eax; + movss answer, xmm0; } return answer; } + void Scr_AddFloat(game::scriptInstance_t inst, float value) + { + static const auto call_addr = SELECT(0x0, 0x69A670); + + __asm + { + push value; + mov eax, inst; + call call_addr; + add esp, 4; + } + } + char* Scr_GetString(game::scriptInstance_t inst, unsigned int arg_index) { static const auto call_addr = SELECT(0x0, 0x699F30); @@ -62,8 +88,8 @@ namespace game __asm { - mov ecx, arg_index; - mov eax, inst; + mov esi, inst; + mov eax, arg_index; call call_addr; mov answer, eax; } @@ -71,6 +97,114 @@ namespace game return answer; } + void Scr_AddString(game::scriptInstance_t inst, const char* string) + { + static const auto call_addr = SELECT(0x0, 0x69A7E0); + + __asm + { + push string; + mov eax, inst; + call call_addr; + add esp, 4; + } + } + + const char* Scr_GetIString(game::scriptInstance_t inst, unsigned int arg_index) + { + static const auto call_addr = SELECT(0x0, 0x69A1A0); //Scr_GetConstIString + + unsigned short id; + + __asm + { + mov eax, arg_index; + call call_addr; + mov id, eax; + } + + return SL_ConvertToString(inst, id); + } + + void Scr_AddIString(game::scriptInstance_t inst, const char* string) + { + static const auto call_addr = SELECT(0x0, 0x69A860); + + __asm + { + mov esi, string; + call call_addr; + } + } + + unsigned short Scr_GetConstString(game::scriptInstance_t inst, unsigned int arg_index) + { + static const auto call_addr = SELECT(0x0, 0x699F30); + + unsigned short answer; + + __asm + { + push arg_index; + mov eax, inst; + call call_addr; + mov answer, eax; + add esp, 4; + } + + return answer; + } + + void Scr_AddConstString(game::scriptInstance_t inst, unsigned short id) + { + static const auto call_addr = SELECT(0x0, 0x69A8D0); + + __asm + { + mov esi, id; + mov eax, inst; + call call_addr; + } + } + + void Scr_GetVector(game::scriptInstance_t inst, unsigned int arg_index, float* value) + { + static const auto call_addr = SELECT(0x0, 0x69A220); + + __asm + { + push arg_index; + mov ecx, value; + mov eax, inst; + call call_addr; + add esp, 4; + } + } + + void Scr_AddVector(game::scriptInstance_t inst, float* value) + { + static const auto call_addr = SELECT(0x0, 0x69A940); + + __asm + { + push value; + mov eax, inst; + call call_addr; + add esp, 4; + } + } + + void Scr_AddUndefined(game::scriptInstance_t inst) + { + static const auto call_addr = SELECT(0x0, 0x69A720); + + __asm + { + mov eax, inst; + call call_addr; + } + } + gentity_s* Scr_GetEntity(unsigned int arg_index) { static const auto call_addr = SELECT(0x0, 0x546E30); @@ -98,6 +232,12 @@ namespace game } } + int Scr_GetEntityId@(int entNum@, scriptInstance_t inst, classNum_e classnum, unsigned __int16 clientnum) + { + + } + + //Only supports getting the first argument as a path node pathnode_t* Scr_GetPathnode(scriptInstance_t inst) { static const auto call_addr = SELECT(0x0, 0x559E20); @@ -113,6 +253,13 @@ namespace game return answer; } + void Scr_AddPathnode(scriptInstance_t inst, pathnode_t* node) + { + int entnum = node - (*gameWorldCurrent)->path.nodes; + int entid = Scr_GetEntityId(entnum >> 7, SCRIPTINSTANCE_SERVER, CLASS_NUM_PATHNODE, 0); + Scr_AddEntityNum(SCRIPTINSTANCE_SERVER, entid); + } + void Scr_MakeArray(scriptInstance_t inst) { static const auto call_addr = SELECT(0x0, 0x69A9D0); diff --git a/src/game/game.hpp b/src/game/game.hpp index 2b3a933..5ee8651 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -28,6 +28,28 @@ namespace game dvar_s* Dvar_RegisterInt(const char* name, int value, int min, int max, DvarFlags flags, const char* desc); dvar_s* Dvar_RegisterString(const char* name, const char* value, DvarFlags flags, const char* desc); + int Scr_GetInt(game::scriptInstance_t inst, unsigned int arg_index); + void Scr_AddInt(game::scriptInstance_t inst, int value); + float Scr_GetFloat(game::scriptInstance_t inst, unsigned int arg_index); + void Scr_AddFloat(game::scriptInstance_t inst, float value); + char* Scr_GetString(game::scriptInstance_t inst, unsigned int arg_index); + void Scr_AddString(game::scriptInstance_t inst, const char* string); + const char* Scr_GetIString(game::scriptInstance_t inst, unsigned int arg_index); + void Scr_AddIString(game::scriptInstance_t inst, const char* string); + unsigned short Scr_GetConstString(game::scriptInstance_t inst, unsigned int arg_index); + void Scr_AddConstString(game::scriptInstance_t inst, unsigned short id); + void Scr_GetVector(game::scriptInstance_t inst, unsigned int arg_index, float* value); + void Scr_AddVector(game::scriptInstance_t inst, float* value); + void Scr_AddUndefined(game::scriptInstance_t inst); + gentity_s* Scr_GetEntity(unsigned int arg_index); + void Scr_AddEntity(game::scriptInstance_t inst, gentity_s* ent); + int Scr_GetEntityId(int entNum, scriptInstance_t inst, classNum_e classnum, unsigned __int16 clientnum); + pathnode_t* Scr_GetPathnode(scriptInstance_t inst); + void Scr_AddPathnode(scriptInstance_t inst, pathnode_t* node); + void Scr_MakeArray(scriptInstance_t inst); + void Scr_AddArrayStringIndexed(scriptInstance_t inst, unsigned short id); + const char* SL_ConvertToString(scriptInstance_t inst, unsigned short id); + template class symbol { diff --git a/src/game/structs.hpp b/src/game/structs.hpp index 1730e55..dfaeb25 100644 --- a/src/game/structs.hpp +++ b/src/game/structs.hpp @@ -1502,4 +1502,51 @@ namespace game unsigned __int8 negotiationLink; unsigned __int8 ubBadPlaceCount[4]; }; + + struct pathbasenode_t + { + float vOrigin[3]; + unsigned int type; + }; + + struct pathnode_tree_nodes_t + { + int nodeCount; + unsigned __int16* nodes; + }; + + + union __declspec(align(4)) pathnode_tree_info_t + { + pathnode_tree_t* child[2]; + pathnode_tree_nodes_t s[8]; + }; + + struct pathnode_tree_t + { + int axis; + float dist; + pathnode_tree_info_t u; + }; + + struct PathData + { + unsigned int nodeCount; + pathnode_t* nodes; + pathbasenode_t* basenodes; + unsigned int chainNodeCount; + unsigned __int16* chainNodeForNode; + unsigned __int16* nodeForChainNode; + int visBytes; + unsigned __int8* pathVis; + int nodeTreeCount; + pathnode_tree_t* nodeTree; + }; + + struct __declspec(align(4)) GameWorldSp + { + const char* name; + PathData path; + }; + } \ No newline at end of file diff --git a/src/game/symbols.hpp b/src/game/symbols.hpp index a3b6b42..3cdab08 100644 --- a/src/game/symbols.hpp +++ b/src/game/symbols.hpp @@ -17,6 +17,8 @@ namespace game WEAK symbol cmd_functions{ 0x0, 0x1F416F4 }; WEAK symbol cmd_args{ 0x0, 0x1F41670 }; + WEAK symbol gameWorldCurrent{0x0, 0x8E1D80 }; + namespace plutonium { }