From 232ce3bcaa5e94c32f8439a978068a01475410d5 Mon Sep 17 00:00:00 2001 From: ineed bots Date: Sat, 3 Aug 2024 14:20:06 -0600 Subject: [PATCH] use plugin gsc register --- src/codsrc/clientscript/cscr_compiler.cpp | 16 --- src/component/gsc.cpp | 153 +--------------------- src/component/gsc.hpp | 2 - src/component/signatures.cpp | 2 - src/game/symbols.hpp | 3 - 5 files changed, 2 insertions(+), 174 deletions(-) diff --git a/src/codsrc/clientscript/cscr_compiler.cpp b/src/codsrc/clientscript/cscr_compiler.cpp index 5d394cc..55d0486 100644 --- a/src/codsrc/clientscript/cscr_compiler.cpp +++ b/src/codsrc/clientscript/cscr_compiler.cpp @@ -2011,14 +2011,6 @@ LABEL_17: } - // our addition - auto f = gsc::function::get(pName, type); - if (f != nullptr) - { - return f; - } - // - // pluto if (game::plutonium::scr_get_function_hook != nullptr) { @@ -2154,14 +2146,6 @@ LABEL_17: } } - // our addition - auto f = gsc::method::get(pName, type); - if (f != nullptr) - { - return f; - } - // - // pluto if (game::plutonium::scr_get_method_hook != nullptr) { diff --git a/src/component/gsc.cpp b/src/component/gsc.cpp index 4421937..3b67bc1 100644 --- a/src/component/gsc.cpp +++ b/src/component/gsc.cpp @@ -2,124 +2,13 @@ #include "loader/component_loader.hpp" #include "gsc.hpp" -#include "scheduler.hpp" - -#include -#include -#include -#include - namespace gsc { - std::unordered_map functions; - std::unordered_map methods; - - utils::hook::detour scr_getmethod_hook; - void* scr_getfunction_stub_ret_loc; - - namespace - { - game::BuiltinFunction scr_getfunction_call(const char** pName, int* pType) - { - auto itr = functions.find(*pName); - - if (itr == functions.end()) - { - return nullptr; - } - - *pType = 0; - return itr->second; - } - - game::BuiltinFunction NAKED scr_getfunction_stub() - { - __asm - { - push eax; - pushad; - - lea eax, [esp + 0x24 + 0x2C - 0x1C]; - push eax; - push edx; - call scr_getfunction_call; - add esp, 8; - mov [esp + 0x20], eax; - - popad; - pop eax; - - test eax, eax; - jnz just_ret; - - // go do original code - push scr_getfunction_stub_ret_loc; - ret; - - just_ret: - add esp, 4; - push 0x682DC8; - ret; - } - } - - game::BuiltinMethod scr_getmethod_call(const char** pName, int* pType) - { - auto itr = methods.find(*pName); - - if (itr == methods.end()) - { - // call og - const auto og_addr = scr_getmethod_hook.get_original(); - game::BuiltinMethod answer; - - __asm - { - mov edi, pType; - mov esi, pName; - call og_addr; - mov answer, eax; - } - - return answer; - } - - *pType = 0; - return itr->second; - } - - game::BuiltinMethod NAKED scr_getmethod_stub() - { - __asm - { - push edi; - push esi; - call scr_getmethod_call; - add esp, 8; - - ret; - } - } - } - namespace function { void add(const std::string& name, const game::BuiltinFunction function) { - functions.insert_or_assign(name, function); - } - - game::BuiltinFunction get(const char** name, int* type) - { - auto got = functions.find(*name); - - if (got == functions.end()) - { - return nullptr; - } - - *type = 0; - return got->second; + plugin::get()->get_interface()->gsc()->register_function(name, function); } } @@ -127,46 +16,8 @@ namespace gsc { void add(const std::string& name, const game::BuiltinMethod method) { - methods.insert_or_assign(name, method); - } - - game::BuiltinMethod get(const char** name, int* type) - { - auto got = methods.find(*name); - - if (got == methods.end()) - { - return nullptr; - } - - *type = 0; - return got->second; + plugin::get()->get_interface()->gsc()->register_method(name, (plutonium::sdk::v1::interfaces::gsc::method_callback)method); } } - - class component final : public component_interface - { - public: - void post_unpack() override - { - // for when we dont use the decomp - // custom gsc methods - if (game::plutonium::scr_get_method_stub != nullptr) - { - scr_getmethod_hook.create(game::plutonium::scr_get_method_stub.get(), scr_getmethod_stub); - } - - // custom gsc funcs - if (game::plutonium::scr_get_function_stub != nullptr) - { - scr_getfunction_stub_ret_loc = game::plutonium::scr_get_function_stub.get(); - utils::hook::jump(SELECT(0x0, 0x682D99), scr_getfunction_stub); - } - } - - private: - }; } -REGISTER_COMPONENT(gsc::component) - diff --git a/src/component/gsc.hpp b/src/component/gsc.hpp index 6034bee..134b513 100644 --- a/src/component/gsc.hpp +++ b/src/component/gsc.hpp @@ -5,12 +5,10 @@ namespace gsc namespace function { void add(const std::string& name, const game::BuiltinFunction function); - game::BuiltinFunction get(const char** name, int* type); } namespace method { void add(const std::string& name, const game::BuiltinMethod method); - game::BuiltinMethod get(const char** name, int* type); } } \ No newline at end of file diff --git a/src/component/signatures.cpp b/src/component/signatures.cpp index dd52ffb..0fc4bae 100644 --- a/src/component/signatures.cpp +++ b/src/component/signatures.cpp @@ -216,8 +216,6 @@ namespace signatures SAFE_SET_PLUTO_SYMBOL_DOUBLE(store_func_codepos, 0x688909, 0x3); SAFE_SET_PLUTO_SYMBOL(cscr_get_function_hook, 0x682DC0); - SAFE_SET_PLUTO_SYMBOL(scr_get_function_stub, 0x682D99); - SAFE_SET_PLUTO_SYMBOL(scr_get_method_stub, 0x683043); SAFE_SET_PLUTO_SYMBOL(cscr_get_method_hook, 0x68305C); SAFE_SET_PLUTO_SYMBOL_DOUBLE(scr_get_method_hook, 0x683043, 0x4); SAFE_SET_PLUTO_SYMBOL_DOUBLE(scr_get_function_hook, 0x682D99, 0x8); diff --git a/src/game/symbols.hpp b/src/game/symbols.hpp index c25d338..262a8ac 100644 --- a/src/game/symbols.hpp +++ b/src/game/symbols.hpp @@ -107,9 +107,6 @@ namespace game WEAK symbol at_codepose_va{ 0x0, 0x0 }; - WEAK symbol scr_get_method_stub{ 0x0, 0x0 }; - WEAK symbol scr_get_function_stub{ 0x0, 0x0 }; - WEAK symbol scr_get_method_hook{ 0x0, 0x0 }; WEAK symbol scr_get_function_hook{ 0x0, 0x0 }; WEAK symbol cscr_get_method_hook{ 0x0, 0x0 };