From d8e10441ecb5f52ce1b5b6c9804ac6db1f5ba73a Mon Sep 17 00:00:00 2001 From: ineed bots Date: Fri, 15 Sep 2023 17:41:24 -0600 Subject: [PATCH] Add pluto patches to compiler --- src/codsrc/clientscript/cscr_compiler.cpp | 61 ++++++++++++++++++++--- src/component/gsc.cpp | 12 +++++ src/component/gsc.hpp | 2 + src/component/signatures.cpp | 22 +++++--- src/component/signatures.hpp | 2 +- src/game/game.hpp | 4 +- src/game/symbols.hpp | 7 +++ 7 files changed, 94 insertions(+), 16 deletions(-) diff --git a/src/codsrc/clientscript/cscr_compiler.cpp b/src/codsrc/clientscript/cscr_compiler.cpp index 7c71ee0..4b557f1 100644 --- a/src/codsrc/clientscript/cscr_compiler.cpp +++ b/src/codsrc/clientscript/cscr_compiler.cpp @@ -1997,10 +1997,29 @@ LABEL_17: { if ( inst ) { - return game::CScr_GetFunction(pName, type); + // pluto + if (game::plutonium::cscr_get_function_hook != nullptr) + { + return game::plutonium::cscr_get_function_hook(pName, type); + } + // + else + { + return game::CScr_GetFunction(pName, type); + } + + } + + // pluto + if (game::plutonium::scr_get_function_hook != nullptr) + { + return game::plutonium::scr_get_function_hook(pName, type); + } + // + else + { + return game::Scr_GetFunction(pName, type); } - - return game::Scr_GetFunction(pName, type); } // Completed @@ -2114,10 +2133,28 @@ LABEL_17: { if ( inst ) { - return game::CScr_GetMethod(pName, type); + // pluto + if (game::plutonium::cscr_get_method_hook != nullptr) + { + return game::plutonium::cscr_get_method_hook(pName, type); + } + // + else + { + return game::CScr_GetMethod(pName, type); + } } - return game::Scr_GetMethod(type, pName); + // pluto + if (game::plutonium::scr_get_method_hook != nullptr) + { + return game::plutonium::scr_get_method_hook(pName, type); + } + // + else + { + return game::Scr_GetMethod(type, pName); + } } // Completed @@ -2345,8 +2382,10 @@ LABEL_17: pos = game::Scr_EvalVariable(inst, posId); if ( pos.type != game::VAR_UNDEFINED ) { - // crash BUG! need to check in developer (vanilla) - if ( pos.u.intValue ) + // pluto + auto* developer = game::Dvar_FindVar("developer"); + if ( pos.u.intValue && developer && developer->current.enabled ) + // { game::CompileError(inst, sourcePos, "function '%s' already defined in '%s'", game::SL_ConvertToString(name, inst), game::gScrParserPub[inst].sourceBufferLookup[game::Scr_GetSourceBuffer(inst, pos.u.codePosValue)].buf); } @@ -4980,6 +5019,14 @@ LABEL_17: game::gScrCompileGlob[inst].cumulOffset = 0; game::gScrCompileGlob[inst].maxOffset = 0; game::gScrCompileGlob[inst].maxCallOffset = 0; + + // pluto + if (game::plutonium::store_func_codepos != nullptr) + { + game::plutonium::store_func_codepos(inst, val.node[1].stringValue); + } + // + game::CompileTransferRefToString(val.node[1].stringValue, inst, 2u); game::EmitFormalParameterList(inst, val.node[2], sourcePos, block); game::EmitStatementList(inst, val.node[3], 1, endSourcePos.stringValue, block); diff --git a/src/component/gsc.cpp b/src/component/gsc.cpp index 3337890..6192a28 100644 --- a/src/component/gsc.cpp +++ b/src/component/gsc.cpp @@ -1,5 +1,6 @@ #include #include "loader/component_loader.hpp" +#include "gsc.hpp" #include "scheduler.hpp" @@ -107,6 +108,11 @@ namespace gsc { functions.insert_or_assign(name, function); } + + const std::unordered_map& get() + { + return functions; + } } namespace method @@ -115,6 +121,11 @@ namespace gsc { methods.insert_or_assign(name, method); } + + const std::unordered_map& get() + { + return methods; + } } class component final : public component_interface @@ -122,6 +133,7 @@ namespace gsc public: void post_unpack() override { + // for when we dont use the decomp // custom gsc methods if (game::plutonium::scr_get_method_stub != nullptr) { diff --git a/src/component/gsc.hpp b/src/component/gsc.hpp index 134b513..0851030 100644 --- a/src/component/gsc.hpp +++ b/src/component/gsc.hpp @@ -5,10 +5,12 @@ namespace gsc namespace function { void add(const std::string& name, const game::BuiltinFunction function); + const std::unordered_map& get(); } namespace method { void add(const std::string& name, const game::BuiltinMethod method); + const std::unordered_map& get(); } } \ No newline at end of file diff --git a/src/component/signatures.cpp b/src/component/signatures.cpp index 179e615..dd52ffb 100644 --- a/src/component/signatures.cpp +++ b/src/component/signatures.cpp @@ -139,15 +139,13 @@ namespace signatures std::string err_reason; - std::string get_err_reason() + const std::string& get_err_reason() { return err_reason; } - bool process_printf() + bool process_printf(std::unordered_map &cache_info) { - auto cache_info = get_cache_info_for_our_version(); - if (cache_info.contains("printf")) { game::plutonium::printf.set(std::atoi(cache_info.at("printf").c_str())); @@ -165,7 +163,6 @@ namespace signatures game::plutonium::printf.set(string_ref + 4 + 5 + offset); cache_info.insert_or_assign("printf", std::to_string(string_ref + 4 + 5 + offset)); - save_cache_info_for_our_version(cache_info); return true; } @@ -201,6 +198,12 @@ namespace signatures { size_t addr1; size_t addr2; + auto cache_info = get_cache_info_for_our_version(); + + if (!process_printf(cache_info)) + { + return false; + } SAFE_SET_PLUTO_SYMBOL_DOUBLE(load_custom_script_func, 0x689C80, 0x6); SAFE_SET_PLUTO_SYMBOL_DOUBLE(script_preprocess, 0x689BCF, 0x2); @@ -210,9 +213,16 @@ namespace signatures SAFE_SET_PLUTO_SYMBOL_DOUBLE(scr_execentthread_update_codepos_func, 0x699640, 0x7); SAFE_SET_PLUTO_SYMBOL_DOUBLE(scr_addexecthread_update_codepos_func, 0x699730, 0x7); SAFE_SET_PLUTO_SYMBOL_DOUBLE(at_codepose_va, 0x68B3A5, 0xA); + 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); + + save_cache_info_for_our_version(cache_info); return true; } @@ -221,6 +231,6 @@ namespace signatures { utils::cryptography::des::set_key("694201337"); - return handle_funcs() && process_printf(); + return handle_funcs(); } } diff --git a/src/component/signatures.hpp b/src/component/signatures.hpp index 0af1541..6bbee4b 100644 --- a/src/component/signatures.hpp +++ b/src/component/signatures.hpp @@ -2,6 +2,6 @@ namespace signatures { - std::string get_err_reason(); + const std::string& get_err_reason(); bool process(); } \ No newline at end of file diff --git a/src/game/game.hpp b/src/game/game.hpp index 2120000..623db96 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -22,7 +22,7 @@ #define RE_CSCR_ANIMTREE_USE_WRAPPERS -#define RE_CSCR_COMPILER_USE_WRAPPERS +//#define RE_CSCR_COMPILER_USE_WRAPPERS //#define RE_CSCR_MAIN_USE_WRAPPERS //#define RE_CSCR_MEMORYTREE_USE_WRAPPERS //#define RE_CSCR_PARSER_USE_WRAPPERS @@ -33,7 +33,7 @@ //#define RE_CSCR_VM_USE_WRAPPERS //#define RE_CSCR_YACC_USE_WRAPPERS -//#define DISABLE_RE_CSCR_YACC +//#define DISABLE_RE_CSCR_ANIMTREE //#define DISABLE_RE_CSCR_COMPILER //#define DISABLE_RE_CSCR_MAIN //#define DISABLE_RE_CSCR_MEMORYTREE diff --git a/src/game/symbols.hpp b/src/game/symbols.hpp index 23f5d68..1489c56 100644 --- a/src/game/symbols.hpp +++ b/src/game/symbols.hpp @@ -106,5 +106,12 @@ namespace game 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 }; + WEAK symbol cscr_get_function_hook{ 0x0, 0x0 }; + + WEAK symbol store_func_codepos{ 0x0, 0x0 }; } }