diff --git a/src/codsrc/clientscript/cscr_main.cpp b/src/codsrc/clientscript/cscr_main.cpp index 8524fff..21e5f2b 100644 --- a/src/codsrc/clientscript/cscr_main.cpp +++ b/src/codsrc/clientscript/cscr_main.cpp @@ -304,7 +304,6 @@ namespace codsrc { game::plutonium::script_preprocess(sourceBuffer, inst, &parseData); // the pluto hook will call ScriptParse, so we dont have to } - // else { diff --git a/src/codsrc/clientscript/cscr_parser.cpp b/src/codsrc/clientscript/cscr_parser.cpp index 792dca8..8d25d55 100644 --- a/src/codsrc/clientscript/cscr_parser.cpp +++ b/src/codsrc/clientscript/cscr_parser.cpp @@ -723,19 +723,20 @@ namespace codsrc { if (game::Scr_IsInOpcodeMemory(scriptInstance, codepos - 1)) { - // pluto const char* s; + + // pluto if (game::plutonium::at_codepose_va != nullptr) { s = game::plutonium::at_codepose_va(scriptInstance, codepos - game::gScrVarPub[scriptInstance].programBuffer); } + // else { s = game::va("@ %d\n", codepos - game::gScrVarPub[scriptInstance].programBuffer); } game::Com_PrintMessage(channel, s, 0); - // return; } } diff --git a/src/component/scheduler.cpp b/src/component/scheduler.cpp index fba20a8..40f5e42 100644 --- a/src/component/scheduler.cpp +++ b/src/component/scheduler.cpp @@ -4,8 +4,8 @@ namespace scheduler { - void on_scr_execute(const std::function& callback) + void on_scr_execute(void(*callback)()) { - plugin::get()->get_interface()->callbacks()->on_scripts_execute((plutonium::sdk::v1::interfaces::callbacks::on_scripts_execute_callback)&callback); + plugin::get()->get_interface()->callbacks()->on_scripts_execute(callback); } } diff --git a/src/component/scheduler.hpp b/src/component/scheduler.hpp index 1e72957..2274291 100644 --- a/src/component/scheduler.hpp +++ b/src/component/scheduler.hpp @@ -2,5 +2,5 @@ namespace scheduler { - void on_scr_execute(const std::function& callback); + void on_scr_execute(void(*callback)()); } diff --git a/src/component/signatures.cpp b/src/component/signatures.cpp index 0fc4bae..f0069a1 100644 --- a/src/component/signatures.cpp +++ b/src/component/signatures.cpp @@ -9,174 +9,32 @@ namespace signatures { - std::string read_sigs_file() - { - return utils::compression::zlib::decompress(utils::cryptography::des::decrypt(utils::io::read_file("t4sp-server-plugin/sigs"))); - } - - bool write_sigs_file(const std::string& f) - { - return utils::io::write_file("t4sp-server-plugin/sigs", utils::cryptography::des::encrypt(utils::compression::zlib::compress(f))); - } - - const char* get_current_version() - { - return *reinterpret_cast(0x4FF72D + 4); - } - - std::unordered_map get_cache_info_for_our_version() - { - std::unordered_map answer; - - auto* version = get_current_version(); - - nlohmann::json cache_json = nlohmann::json::parse(read_sigs_file(), nullptr, false, true); - if (!cache_json.is_discarded() && cache_json.is_object()) - { - for (const auto& [key, value] : cache_json.items()) - { - if (key != version) - { - continue; - } - - if (!value.is_object()) - { - continue; - } - - answer = value.get>(); - break; - } - } - - return answer; - } - - bool save_cache_info_for_our_version(const std::unordered_map& cache_info) - { - auto* version = get_current_version(); - - nlohmann::json cache_json = nlohmann::json::parse(read_sigs_file(), nullptr, false, true); - if (cache_json.is_discarded() || !cache_json.is_object()) - { - cache_json = nlohmann::json::parse("{}", nullptr, false, true); - - if (cache_json.is_discarded() || !cache_json.is_object()) - { - return false; // can't happen? - } - } - - cache_json[version] = cache_info; - return write_sigs_file(cache_json.dump()); - } - - size_t load_image_size() + bool addr_is_in_image_space_of_pluto(size_t wheree) { MODULEINFO info{}; GetModuleInformation(GetCurrentProcess(), GetModuleHandle("plutonium-bootstrapper-win32.exe"), &info, sizeof(MODULEINFO)); - return info.SizeOfImage; - } - size_t get_image_size() - { - static const auto image_size = load_image_size(); - return image_size; - } + static const auto image_base = reinterpret_cast(GetModuleHandle("plutonium-bootstrapper-win32.exe")); - size_t load_iamge_base() - { - return reinterpret_cast(GetModuleHandle("plutonium-bootstrapper-win32.exe")); - } - - size_t get_image_base() - { - static const auto image_base = load_iamge_base(); - return image_base; - } - - bool addr_is_in_image_space(size_t wheree) - { - static const auto image_base = load_iamge_base(); - - return wheree >= image_base && wheree < image_base + get_image_size(); - } - - size_t find_string_ptr(const std::string& string) - { - const char* string_ptr = nullptr; - std::string mask(string.size(), 'x'); - const auto base = get_image_base(); - utils::hook::signature signature(base, get_image_size() - base); - - signature.add({ - string, - mask, - [&](char* address) - { - string_ptr = address; - } - }); - - signature.process(); - return reinterpret_cast(string_ptr); - } - - size_t find_string_ref(const std::string& string) - { - char bytes[4] = {0}; - const auto string_ptr = find_string_ptr(string); - if (!string_ptr) - { - return 0; - } - - std::memcpy(bytes, &string_ptr, sizeof(bytes)); - return find_string_ptr({bytes, 4}); + return wheree >= image_base && wheree < image_base + info.SizeOfImage; } std::string err_reason; - const std::string& get_err_reason() { return err_reason; } - bool process_printf(std::unordered_map &cache_info) - { - if (cache_info.contains("printf")) - { - game::plutonium::printf.set(std::atoi(cache_info.at("printf").c_str())); - return true; - } - - const auto string_ref = find_string_ref("A critical exception occured!\n"); - if (!string_ref) - { - err_reason = "printf"; - return false; - } - - const auto offset = *reinterpret_cast(string_ref + 5); - game::plutonium::printf.set(string_ref + 4 + 5 + offset); - - cache_info.insert_or_assign("printf", std::to_string(string_ref + 4 + 5 + offset)); - - return true; - } - - #define SAFE_SET_PLUTO_SYMBOL_DOUBLE(name, addr, off) \ addr2 = reinterpret_cast(utils::hook::get_displacement_addr(addr)); \ - if (!addr_is_in_image_space(addr2)) \ + if (!addr_is_in_image_space_of_pluto(addr2)) \ { \ err_reason = #name " 1"; \ return false; \ } \ addr1 = reinterpret_cast(utils::hook::get_displacement_addr(addr2 + off)); \ - if (!addr_is_in_image_space(addr1)) \ + if (!addr_is_in_image_space_of_pluto(addr1)) \ { \ err_reason = #name " 2"; \ return false; \ @@ -186,7 +44,7 @@ namespace signatures #define SAFE_SET_PLUTO_SYMBOL(name, addr) \ addr1 = reinterpret_cast(utils::hook::get_displacement_addr(addr)); \ - if (!addr_is_in_image_space(addr1)) \ + if (!addr_is_in_image_space_of_pluto(addr1)) \ { \ err_reason = #name; \ return false; \ @@ -198,12 +56,6 @@ 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); @@ -220,15 +72,11 @@ namespace signatures 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; } bool process() { - utils::cryptography::des::set_key("694201337"); - return handle_funcs(); } } diff --git a/src/game/symbols.hpp b/src/game/symbols.hpp index 262a8ac..5a7aed8 100644 --- a/src/game/symbols.hpp +++ b/src/game/symbols.hpp @@ -96,8 +96,6 @@ namespace game namespace plutonium { - WEAK symbol printf{0x0, 0x0}; - WEAK symbol load_custom_script_func{0x0, 0x0}; WEAK symbol script_preprocess{0x0, 0x0}; WEAK symbol vm_execute_update_codepos{0x0, 0x0}; diff --git a/src/plugin.cpp b/src/plugin.cpp index 16aa4d9..f3394b9 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -43,11 +43,6 @@ namespace plugin return; } - if (game::plutonium::printf.get() != nullptr) - { - utils::hook::jump(reinterpret_cast(&printf), game::plutonium::printf); - } - component_loader::post_unpack(); }