mirror of
https://github.com/JezuzLizard/T4SP-Server-Plugin.git
synced 2025-04-19 13:12:53 +00:00
cleanup
This commit is contained in:
parent
83ffa1c324
commit
3e9fcc5fda
@ -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
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,8 @@
|
||||
|
||||
namespace scheduler
|
||||
{
|
||||
void on_scr_execute(const std::function<void()>& 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);
|
||||
}
|
||||
}
|
||||
|
@ -2,5 +2,5 @@
|
||||
|
||||
namespace scheduler
|
||||
{
|
||||
void on_scr_execute(const std::function<void()>& callback);
|
||||
void on_scr_execute(void(*callback)());
|
||||
}
|
||||
|
@ -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<const char**>(0x4FF72D + 4);
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, std::string> get_cache_info_for_our_version()
|
||||
{
|
||||
std::unordered_map<std::string, std::string> 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<std::unordered_map<std::string, std::string>>();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return answer;
|
||||
}
|
||||
|
||||
bool save_cache_info_for_our_version(const std::unordered_map<std::string, std::string>& 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<size_t>(GetModuleHandle("plutonium-bootstrapper-win32.exe"));
|
||||
|
||||
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 = 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<size_t>(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<std::string, std::string> &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<size_t*>(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<size_t>(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<size_t>(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<size_t>(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();
|
||||
}
|
||||
}
|
||||
|
@ -96,8 +96,6 @@ namespace game
|
||||
|
||||
namespace plutonium
|
||||
{
|
||||
WEAK symbol<int(const char* fmt, ...)> printf{0x0, 0x0};
|
||||
|
||||
WEAK symbol<void(scriptInstance_t)> load_custom_script_func{0x0, 0x0};
|
||||
WEAK symbol<void(char*, game::scriptInstance_t, sval_u*)> script_preprocess{0x0, 0x0};
|
||||
WEAK symbol<void(game::scriptInstance_t)> vm_execute_update_codepos{0x0, 0x0};
|
||||
|
@ -43,11 +43,6 @@ namespace plugin
|
||||
return;
|
||||
}
|
||||
|
||||
if (game::plutonium::printf.get() != nullptr)
|
||||
{
|
||||
utils::hook::jump(reinterpret_cast<uintptr_t>(&printf), game::plutonium::printf);
|
||||
}
|
||||
|
||||
component_loader::post_unpack();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user