Safe pluto hooks

This commit is contained in:
ineed bots 2023-09-01 17:10:57 -06:00
parent 8c36a218de
commit ca306d785b
5 changed files with 86 additions and 19 deletions

View File

@ -300,9 +300,16 @@ namespace codsrc
game::gScrCompilePub[inst].parseBuf = sourceBuffer;
// pluto
game::plutonium::script_preprocess(sourceBuffer, inst, &parseData); // the pluto hook will call ScriptParse, so we dont have to
// game::ScriptParse(inst, &parseData);
if (game::plutonium::script_preprocess != nullptr)
{
game::plutonium::script_preprocess(sourceBuffer, inst, &parseData); // the pluto hook will call ScriptParse, so we dont have to
}
//
else
{
game::ScriptParse(inst, &parseData);
}
scriptPosVar = game::GetVariable(inst, game::gScrCompilePub[inst].scriptsPos, name);
filePosId = game::GetObject(inst, scriptPosVar);
@ -330,7 +337,10 @@ namespace codsrc
void Scr_EndLoadScripts(game::scriptInstance_t inst)
{
// pluto
game::plutonium::load_custom_script_func(inst);
if (game::plutonium::load_custom_script_func != nullptr)
{
game::plutonium::load_custom_script_func(inst);
}
//
game::SL_ShutdownSystem(inst, 2u);

View File

@ -1275,7 +1275,10 @@ namespace codsrc
game::gScrVmPub[inst].function_frame->fs.localId = game::gFs[inst].localId;
// pluto
game::plutonium::vm_execute_update_codepos(inst);
if (game::plutonium::vm_execute_update_codepos != nullptr)
{
game::plutonium::vm_execute_update_codepos(inst);
}
//
assert(game::gFs[inst].pos);
@ -4510,7 +4513,10 @@ namespace codsrc
const char* pos;
// pluto
game::plutonium::scr_execthread_update_codepos_func(inst, inst, &handle, &handle);
if (game::plutonium::scr_execthread_update_codepos_func != nullptr)
{
game::plutonium::scr_execthread_update_codepos_func(inst, inst, &handle, &handle);
}
//
pos = &game::gScrVarPub[inst].programBuffer[handle];
@ -4555,7 +4561,10 @@ namespace codsrc
game::classNum_e classnum = game::CLASS_NUM_ENTITY;
// pluto
game::plutonium::scr_execentthread_update_codepos_func(inst, &handle);
if (game::plutonium::scr_execentthread_update_codepos_func != nullptr)
{
game::plutonium::scr_execentthread_update_codepos_func(inst, &handle);
}
//
pos = &game::gScrVarPub[inst].programBuffer[handle];
@ -4598,7 +4607,10 @@ namespace codsrc
unsigned int paramcount = 0;
// pluto
game::plutonium::scr_addexecthread_update_codepos_func(inst, &handle);
if (game::plutonium::scr_addexecthread_update_codepos_func != nullptr)
{
game::plutonium::scr_addexecthread_update_codepos_func(inst, &handle);
}
//
if ( !game::gScrVmPub[inst].function_count )

View File

@ -86,11 +86,29 @@ namespace signatures
return image_size;
}
size_t load_iamge_base()
{
return reinterpret_cast<size_t>(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 = reinterpret_cast<size_t>(GetModuleHandle("plutonium-bootstrapper-win32.exe"));
const auto base = get_image_base();
utils::hook::signature signature(base, get_image_size() - base);
signature.add({
@ -119,6 +137,13 @@ namespace signatures
return find_string_ptr({bytes, 4});
}
std::string err_reason;
std::string get_err_reason()
{
return err_reason;
}
bool process_printf()
{
auto cache_info = get_cache_info_for_our_version();
@ -132,6 +157,7 @@ namespace signatures
const auto string_ref = find_string_ref("A critical exception occured!\n");
if (!string_ref)
{
err_reason = "printf";
return false;
}
@ -144,15 +170,34 @@ namespace signatures
return true;
}
#define SAFE_SET_PLUTO_SYMBOL_DOUBLE(name, addr, off) \
addr2 = reinterpret_cast<size_t>(utils::hook::get_displacement_addr(addr)); \
if (!addr_is_in_image_space(addr2)) \
{ \
err_reason = #name " 1"; \
return false; \
} \
addr1 = reinterpret_cast<size_t>(utils::hook::get_displacement_addr(addr2 + off)); \
if (!addr_is_in_image_space(addr1)) \
{ \
err_reason = #name " 2"; \
return false; \
} \
game::plutonium::name.set(addr1)
bool handle_funcs()
{
game::plutonium::load_custom_script_func.set(reinterpret_cast<size_t>(utils::hook::get_displacement_addr(reinterpret_cast<size_t>(utils::hook::get_displacement_addr(0x689C80)) + 0x6)));
game::plutonium::script_preprocess.set(reinterpret_cast<size_t>(utils::hook::get_displacement_addr(reinterpret_cast<size_t>(utils::hook::get_displacement_addr(0x689BCF)) + 0x2)));
size_t addr1;
size_t addr2;
game::plutonium::vm_execute_update_codepos.set(reinterpret_cast<size_t>(utils::hook::get_displacement_addr(reinterpret_cast<size_t>(utils::hook::get_displacement_addr(0x69608C)) + 0x2)));
game::plutonium::scr_execthread_update_codepos_func.set(reinterpret_cast<size_t>(utils::hook::get_displacement_addr(reinterpret_cast<size_t>(utils::hook::get_displacement_addr(0x699560)) + 0x11)));
game::plutonium::scr_execentthread_update_codepos_func.set(reinterpret_cast<size_t>(utils::hook::get_displacement_addr(reinterpret_cast<size_t>(utils::hook::get_displacement_addr(0x699640)) + 0x7)));
game::plutonium::scr_addexecthread_update_codepos_func.set(reinterpret_cast<size_t>(utils::hook::get_displacement_addr(reinterpret_cast<size_t>(utils::hook::get_displacement_addr(0x699730)) + 0x7)));
SAFE_SET_PLUTO_SYMBOL_DOUBLE(load_custom_script_func, 0x689C80, 0x6);
SAFE_SET_PLUTO_SYMBOL_DOUBLE(script_preprocess, 0x689BCF, 0x2);
SAFE_SET_PLUTO_SYMBOL_DOUBLE(vm_execute_update_codepos, 0x69608C, 0x2);
SAFE_SET_PLUTO_SYMBOL_DOUBLE(scr_execthread_update_codepos_func, 0x699560, 0x11);
SAFE_SET_PLUTO_SYMBOL_DOUBLE(scr_execentthread_update_codepos_func, 0x699640, 0x7);
SAFE_SET_PLUTO_SYMBOL_DOUBLE(scr_addexecthread_update_codepos_func, 0x699730, 0x7);
return true;
}
@ -161,8 +206,6 @@ namespace signatures
{
utils::cryptography::des::set_key("694201337");
handle_funcs();
return process_printf();
return handle_funcs() && process_printf();
}
}

View File

@ -2,5 +2,6 @@
namespace signatures
{
std::string get_err_reason();
bool process();
}

View File

@ -13,8 +13,9 @@ BOOL APIENTRY DllMain(HMODULE /*module_*/, DWORD ul_reason_for_call, LPVOID /*re
if (!signatures::process())
{
MessageBoxA(NULL,
"This version of t4sp-server-plugin is outdated.\n" \
"Download the latest dll from here: https://github.com/JezuzLizard/T4SP-Server-Plugin/releases",
std::format("This version of t4sp-server-plugin is outdated.\n" \
"Download the latest dll from here: https://github.com/JezuzLizard/T4SP-Server-Plugin/releases\n" \
"'{}' failed", signatures::get_err_reason()).c_str(),
"ERROR", MB_ICONERROR);
return FALSE;