From e0b9522e34630825f126b7f06fd5d84c0fabb18f Mon Sep 17 00:00:00 2001 From: ineedbots Date: Tue, 29 Jun 2021 11:55:00 -0600 Subject: [PATCH] Added custom gsc calls --- src/Components/Modules/Script.cpp | 43 ++++++++++++++++++++++++++++--- src/Components/Modules/Script.hpp | 9 +++++-- src/Game/Game.hpp | 4 +-- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/Components/Modules/Script.cpp b/src/Components/Modules/Script.cpp index 7527ece..0ab73be 100644 --- a/src/Components/Modules/Script.cpp +++ b/src/Components/Modules/Script.cpp @@ -3,14 +3,47 @@ namespace Components { - Game::xmethod_t* Script::Player_GetMethod_Hook(const char** name) + std::unordered_map Script::CustomScrFunctions; + std::unordered_map Script::CustomScrMethods; + + void Script::AddFunction(const char* name, Game::xfunction_t func, int type) { - return Game::Player_GetMethod(name); + Game::scr_function_t toAdd; + toAdd.call = func; + toAdd.name = name; + toAdd.developer = type; + + CustomScrFunctions.insert_or_assign(name, toAdd); } - Game::xfunction_t* Script::Scr_GetFunction_Hook(const char** name, int* isDev) + void Script::AddMethod(const char* name, Game::xmethod_t func, int type) { - return Game::Scr_GetFunction(name, isDev); + Game::scr_method_t toAdd; + toAdd.call = func; + toAdd.name = name; + toAdd.developer = type; + + CustomScrMethods.insert_or_assign(name, toAdd); + } + + Game::xmethod_t Script::Player_GetMethod_Hook(const char** name) + { + auto got = CustomScrMethods.find(*name); + + if (got == CustomScrMethods.end()) + return Game::Player_GetMethod(name); + + return got->second.call; + } + + Game::xfunction_t Script::Scr_GetFunction_Hook(const char** name, int* isDev) + { + auto got = CustomScrFunctions.find(*name); + + if (got == CustomScrFunctions.end()) + return Game::Scr_GetFunction(name, isDev); + + return got->second.call; } Script::Script() @@ -21,5 +54,7 @@ namespace Components Script::~Script() { + CustomScrFunctions.clear(); + CustomScrMethods.clear(); } } diff --git a/src/Components/Modules/Script.hpp b/src/Components/Modules/Script.hpp index 4b35023..c82a90b 100644 --- a/src/Components/Modules/Script.hpp +++ b/src/Components/Modules/Script.hpp @@ -5,10 +5,15 @@ namespace Components class Script : public Component { public: + static void AddFunction(const char*, Game::xfunction_t, int = 0); + static void AddMethod(const char*, Game::xmethod_t, int = 0); Script(); ~Script(); private: - static Game::xmethod_t* Player_GetMethod_Hook(const char**); - static Game::xfunction_t* Scr_GetFunction_Hook(const char**, int*); + static std::unordered_map CustomScrFunctions; + static std::unordered_map CustomScrMethods; + + static Game::xmethod_t Player_GetMethod_Hook(const char**); + static Game::xfunction_t Scr_GetFunction_Hook(const char**, int*); }; } diff --git a/src/Game/Game.hpp b/src/Game/Game.hpp index 92909b3..dbe3107 100644 --- a/src/Game/Game.hpp +++ b/src/Game/Game.hpp @@ -33,10 +33,10 @@ namespace Game extern bgs_s** bgs_ptr; - typedef Game::xmethod_t* (Player_GetMethod_t)(const char**); + typedef Game::xmethod_t (Player_GetMethod_t)(const char**); extern Player_GetMethod_t* Player_GetMethod; - typedef Game::xfunction_t* (Scr_GetFunction_t)(const char**, int*); + typedef Game::xfunction_t (Scr_GetFunction_t)(const char**, int*); extern Scr_GetFunction_t* Scr_GetFunction; extern void G_SelectWeaponIndex(int, int);