diff --git a/.gitmodules b/.gitmodules index 959bf20..5bdf456 100644 --- a/.gitmodules +++ b/.gitmodules @@ -14,3 +14,6 @@ [submodule "deps/zlib"] path = deps/zlib url = https://github.com/madler/zlib.git +[submodule "deps/plutonium-sdk"] + path = deps/plutonium-sdk + url = https://github.com/plutoniummod/plutonium-sdk.git diff --git a/deps/premake/plutonium-sdk.lua b/deps/premake/plutonium-sdk.lua new file mode 100644 index 0000000..22d8ab7 --- /dev/null +++ b/deps/premake/plutonium-sdk.lua @@ -0,0 +1,18 @@ +plutonium_sdk = { + source = path.join(dependencies.basePath, "plutonium-sdk"), +} + +function plutonium_sdk.import() + plutonium_sdk.includes() +end + +function plutonium_sdk.includes() + includedirs { + plutonium_sdk.source, + } +end + +function plutonium_sdk.project() +end + +table.insert(dependencies, plutonium_sdk) diff --git a/src/component/gsc.cpp b/src/component/gsc.cpp index 92d2173..048853d 100644 --- a/src/component/gsc.cpp +++ b/src/component/gsc.cpp @@ -270,6 +270,11 @@ namespace gsc { void add(const std::string& name, const script_method& func) { + if (true) + { + return; + } + auto index = 0u; auto& ctx = (*game::plutonium::gsc_ctx); diff --git a/src/component/io.cpp b/src/component/io.cpp index 35ba2e2..66e3f0d 100644 --- a/src/component/io.cpp +++ b/src/component/io.cpp @@ -179,4 +179,4 @@ namespace io }; } -REGISTER_COMPONENT(io::component) +//REGISTER_COMPONENT(io::component) diff --git a/src/component/json.cpp b/src/component/json.cpp index b3c632c..5b5fc84 100644 --- a/src/component/json.cpp +++ b/src/component/json.cpp @@ -194,4 +194,4 @@ namespace json }; } -REGISTER_COMPONENT(json::component) +//REGISTER_COMPONENT(json::component) diff --git a/src/component/notifies.cpp b/src/component/notifies.cpp index a5a5d22..cdc6f73 100644 --- a/src/component/notifies.cpp +++ b/src/component/notifies.cpp @@ -71,4 +71,4 @@ namespace notifies }; } -REGISTER_COMPONENT(notifies::component) +//REGISTER_COMPONENT(notifies::component) diff --git a/src/component/scheduler.cpp b/src/component/scheduler.cpp index 9bad71d..3a31878 100644 --- a/src/component/scheduler.cpp +++ b/src/component/scheduler.cpp @@ -144,4 +144,4 @@ namespace scheduler }; } -REGISTER_COMPONENT(scheduler::component) +//REGISTER_COMPONENT(scheduler::component) diff --git a/src/component/scripting.cpp b/src/component/scripting.cpp index 322bc8e..7b375b7 100644 --- a/src/component/scripting.cpp +++ b/src/component/scripting.cpp @@ -136,4 +136,4 @@ namespace scripting }; } -REGISTER_COMPONENT(scripting::component) +//REGISTER_COMPONENT(scripting::component) diff --git a/src/component/signatures.cpp b/src/component/signatures.cpp index 0e962fa..edc6292 100644 --- a/src/component/signatures.cpp +++ b/src/component/signatures.cpp @@ -34,7 +34,7 @@ namespace signatures std::string mask(string.size(), 'x'); const auto base = reinterpret_cast(GetModuleHandle("plutonium-bootstrapper-win32.exe")); utils::hook::signature signature(base, get_image_size() - base); - + OutputDebugString(utils::string::va("%p %p\n", base, get_image_size())); auto found = false; signature.add({ string, @@ -70,37 +70,23 @@ namespace signatures bool process_gsc_ctx() { + OutputDebugString("HELLOOO"); + const auto string_ref = find_string_ref("in call to builtin %s \"%s\""); if (!string_ref) { return false; } - - const auto gsc_ctx_ptr = *reinterpret_cast(string_ref - 0xAD); + + const auto gsc_ctx_ptr = *reinterpret_cast(string_ref + 215); OutputDebugString(utils::string::va("gsc_ctx_ptr: %p\n", gsc_ctx_ptr)); game::plutonium::gsc_ctx.set(gsc_ctx_ptr); return true; } - bool process_printf() - { - const auto string_ref = find_string_ref("A critical exception occured!\n"); - if (!string_ref) - { - return false; - } - - const auto offset = *reinterpret_cast(string_ref + 5); - const auto printf_ptr = string_ref + 4 + 5 + offset; - OutputDebugString(utils::string::va("printf_ptr: %p\n", printf_ptr)); - game::plutonium::printf.set(printf_ptr); - - return true; - } - bool process() { load_function_tables(); - return process_printf() && process_gsc_ctx(); + return process_gsc_ctx(); } } diff --git a/src/component/string.cpp b/src/component/string.cpp index e6becb2..27fbaf9 100644 --- a/src/component/string.cpp +++ b/src/component/string.cpp @@ -43,4 +43,4 @@ namespace string }; } -REGISTER_COMPONENT(string::component) +//REGISTER_COMPONENT(string::component) diff --git a/src/component/userinfo.cpp b/src/component/userinfo.cpp index ca69326..66c1936 100644 --- a/src/component/userinfo.cpp +++ b/src/component/userinfo.cpp @@ -193,4 +193,4 @@ namespace userinfo }; } -REGISTER_COMPONENT(userinfo::component) +//REGISTER_COMPONENT(userinfo::component) diff --git a/src/dllmain.cpp b/src/dllmain.cpp index 6c79e7c..d853866 100644 --- a/src/dllmain.cpp +++ b/src/dllmain.cpp @@ -1,28 +1,23 @@ #include #include "loader/component_loader.hpp" -#include "component/signatures.hpp" +#include "plugin.hpp" + +PLUTONIUM_API plutonium::sdk::plugin* PLUTONIUM_CALLBACK on_initialize() +{ + return plugin::get(); +} BOOL APIENTRY DllMain(HMODULE /*hModule*/, DWORD ul_reason_for_call, LPVOID /*lpReserved*/) { if (ul_reason_for_call == DLL_PROCESS_ATTACH) { - if (!signatures::process()) - { - MessageBoxA(NULL, - "This version of iw5-gsc-utils is outdated.\n" \ - "Download the latest dll from here: https://github.com/fedddddd/iw5-gsc-utils/releases", - "ERROR", MB_ICONERROR); - return FALSE; - } + } - if (game::plutonium::printf.get() != nullptr) - { - utils::hook::jump(reinterpret_cast(&printf), game::plutonium::printf); - } - - component_loader::post_unpack(); + if (ul_reason_for_call == DLL_PROCESS_DETACH) + { + component_loader::pre_destroy(); } return TRUE; diff --git a/src/game/scripting/array.cpp b/src/game/scripting/array.cpp index 5781e4f..f6993e1 100644 --- a/src/game/scripting/array.cpp +++ b/src/game/scripting/array.cpp @@ -212,8 +212,6 @@ namespace scripting { return this->get(key.as()); } - - return {}; } script_value array::get(const std::string& key) const diff --git a/src/game/symbols.hpp b/src/game/symbols.hpp index ae52441..8d8ddd7 100644 --- a/src/game/symbols.hpp +++ b/src/game/symbols.hpp @@ -87,7 +87,6 @@ namespace game namespace plutonium { WEAK symbol> gsc_ctx{0}; - WEAK symbol printf{0}; WEAK symbol function_table{0}; WEAK symbol method_table{0}; } diff --git a/src/plugin.cpp b/src/plugin.cpp new file mode 100644 index 0000000..b45fb1a --- /dev/null +++ b/src/plugin.cpp @@ -0,0 +1,84 @@ +#include +#include "loader/component_loader.hpp" + +#include "plugin.hpp" + +#include "component/signatures.hpp" + +#include +#include + +namespace plugin +{ + namespace + { + void printf_stub(const char* fmt, ...) + { + char buffer[0x2000] = {}; + + va_list ap; + va_start(ap, fmt); + + vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, fmt, ap); + + va_end(ap); + + get()->get_interface()->logging()->info(buffer); + } + } + + std::uint32_t plugin::plugin_version() + { + return 1; + } + + const char* plugin::plugin_name() + { + return "iw5-gsc-utils"; + } + + bool plugin::is_game_supported([[maybe_unused]] plutonium::sdk::game game) + { + return game == plutonium::sdk::game::iw5; + } + + void plugin::on_startup(plutonium::sdk::iinterface* interface_ptr, plutonium::sdk::game game) + { + this->interface_ = interface_ptr; + this->game_ = game; + utils::hook::jump(reinterpret_cast(&printf), printf_stub); + + if (!signatures::process()) + { + MessageBoxA(NULL, + "This version of iw5-gsc-utils is outdated.\n" \ + "Download the latest dll from here: https://github.com/alicealys/iw5-gsc-utils/releases", + "ERROR", MB_ICONERROR); + } + else + { + component_loader::post_unpack(); + } + } + + void plugin::on_shutdown() + { + component_loader::pre_destroy(); + } + + plutonium::sdk::iinterface* plugin::get_interface() + { + return this->interface_; + } + + plutonium::sdk::game plugin::get_game() + { + return this->game_; + } + + plugin* get() + { + static plugin instance; + return &instance; + } +} diff --git a/src/plugin.hpp b/src/plugin.hpp new file mode 100644 index 0000000..3d18d09 --- /dev/null +++ b/src/plugin.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include + +namespace plugin +{ + class plugin : public plutonium::sdk::plugin + { + public: + ~plugin() = default; + + std::uint32_t plugin_version() override; + const char* plugin_name() override; + + bool is_game_supported([[maybe_unused]] plutonium::sdk::game game) override; + + void on_startup(plutonium::sdk::iinterface* interface_ptr, plutonium::sdk::game game) override; + void on_shutdown() override; + + plutonium::sdk::iinterface* get_interface(); + plutonium::sdk::game get_game(); + + private: + plutonium::sdk::iinterface* interface_{}; + plutonium::sdk::game game_{}; + + }; + + plugin* get(); +}