This commit is contained in:
alice
2025-12-03 05:45:25 +01:00
parent 54226a0e56
commit 8d4fa65e3b
16 changed files with 163 additions and 45 deletions

3
.gitmodules vendored
View File

@@ -14,3 +14,6 @@
[submodule "deps/zlib"] [submodule "deps/zlib"]
path = deps/zlib path = deps/zlib
url = https://github.com/madler/zlib.git url = https://github.com/madler/zlib.git
[submodule "deps/plutonium-sdk"]
path = deps/plutonium-sdk
url = https://github.com/plutoniummod/plutonium-sdk.git

18
deps/premake/plutonium-sdk.lua vendored Normal file
View File

@@ -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)

View File

@@ -270,6 +270,11 @@ namespace gsc
{ {
void add(const std::string& name, const script_method& func) void add(const std::string& name, const script_method& func)
{ {
if (true)
{
return;
}
auto index = 0u; auto index = 0u;
auto& ctx = (*game::plutonium::gsc_ctx); auto& ctx = (*game::plutonium::gsc_ctx);

View File

@@ -179,4 +179,4 @@ namespace io
}; };
} }
REGISTER_COMPONENT(io::component) //REGISTER_COMPONENT(io::component)

View File

@@ -194,4 +194,4 @@ namespace json
}; };
} }
REGISTER_COMPONENT(json::component) //REGISTER_COMPONENT(json::component)

View File

@@ -71,4 +71,4 @@ namespace notifies
}; };
} }
REGISTER_COMPONENT(notifies::component) //REGISTER_COMPONENT(notifies::component)

View File

@@ -144,4 +144,4 @@ namespace scheduler
}; };
} }
REGISTER_COMPONENT(scheduler::component) //REGISTER_COMPONENT(scheduler::component)

View File

@@ -136,4 +136,4 @@ namespace scripting
}; };
} }
REGISTER_COMPONENT(scripting::component) //REGISTER_COMPONENT(scripting::component)

View File

@@ -34,7 +34,7 @@ namespace signatures
std::string mask(string.size(), 'x'); std::string mask(string.size(), 'x');
const auto base = reinterpret_cast<size_t>(GetModuleHandle("plutonium-bootstrapper-win32.exe")); const auto base = reinterpret_cast<size_t>(GetModuleHandle("plutonium-bootstrapper-win32.exe"));
utils::hook::signature signature(base, get_image_size() - base); utils::hook::signature signature(base, get_image_size() - base);
OutputDebugString(utils::string::va("%p %p\n", base, get_image_size()));
auto found = false; auto found = false;
signature.add({ signature.add({
string, string,
@@ -70,37 +70,23 @@ namespace signatures
bool process_gsc_ctx() bool process_gsc_ctx()
{ {
OutputDebugString("HELLOOO");
const auto string_ref = find_string_ref("in call to builtin %s \"%s\""); const auto string_ref = find_string_ref("in call to builtin %s \"%s\"");
if (!string_ref) if (!string_ref)
{ {
return false; return false;
} }
const auto gsc_ctx_ptr = *reinterpret_cast<size_t*>(string_ref - 0xAD); const auto gsc_ctx_ptr = *reinterpret_cast<size_t*>(string_ref + 215);
OutputDebugString(utils::string::va("gsc_ctx_ptr: %p\n", gsc_ctx_ptr)); OutputDebugString(utils::string::va("gsc_ctx_ptr: %p\n", gsc_ctx_ptr));
game::plutonium::gsc_ctx.set(gsc_ctx_ptr); game::plutonium::gsc_ctx.set(gsc_ctx_ptr);
return true; 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<size_t*>(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() bool process()
{ {
load_function_tables(); load_function_tables();
return process_printf() && process_gsc_ctx(); return process_gsc_ctx();
} }
} }

View File

@@ -43,4 +43,4 @@ namespace string
}; };
} }
REGISTER_COMPONENT(string::component) //REGISTER_COMPONENT(string::component)

View File

@@ -193,4 +193,4 @@ namespace userinfo
}; };
} }
REGISTER_COMPONENT(userinfo::component) //REGISTER_COMPONENT(userinfo::component)

View File

@@ -1,28 +1,23 @@
#include <stdinc.hpp> #include <stdinc.hpp>
#include "loader/component_loader.hpp" #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*/) BOOL APIENTRY DllMain(HMODULE /*hModule*/, DWORD ul_reason_for_call, LPVOID /*lpReserved*/)
{ {
if (ul_reason_for_call == DLL_PROCESS_ATTACH) 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) if (ul_reason_for_call == DLL_PROCESS_DETACH)
{ {
utils::hook::jump(reinterpret_cast<uintptr_t>(&printf), game::plutonium::printf); component_loader::pre_destroy();
}
component_loader::post_unpack();
} }
return TRUE; return TRUE;

View File

@@ -212,8 +212,6 @@ namespace scripting
{ {
return this->get(key.as<std::string>()); return this->get(key.as<std::string>());
} }
return {};
} }
script_value array::get(const std::string& key) const script_value array::get(const std::string& key) const

View File

@@ -87,7 +87,6 @@ namespace game
namespace plutonium namespace plutonium
{ {
WEAK symbol<std::unique_ptr<xsk::gsc::iw5_pc::context>> gsc_ctx{0}; WEAK symbol<std::unique_ptr<xsk::gsc::iw5_pc::context>> gsc_ctx{0};
WEAK symbol<int(const char* fmt, ...)> printf{0};
WEAK symbol<void*> function_table{0}; WEAK symbol<void*> function_table{0};
WEAK symbol<void*> method_table{0}; WEAK symbol<void*> method_table{0};
} }

84
src/plugin.cpp Normal file
View File

@@ -0,0 +1,84 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "plugin.hpp"
#include "component/signatures.hpp"
#include <utils/hook.hpp>
#include <utils/string.hpp>
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<uintptr_t>(&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;
}
}

30
src/plugin.hpp Normal file
View File

@@ -0,0 +1,30 @@
#pragma once
#include <plutonium_sdk.hpp>
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();
}