add gsc dumping in scriptfile form
This commit is contained in:
parent
33088bec37
commit
e45da37766
@ -10,6 +10,8 @@ namespace
|
|||||||
{
|
{
|
||||||
utils::hook::detour db_find_x_asset_header_hook;
|
utils::hook::detour db_find_x_asset_header_hook;
|
||||||
|
|
||||||
|
const game::native::dvar_t* g_dump_scripts;
|
||||||
|
|
||||||
__declspec(naked) void db_load_stub_client(game::native::XZoneInfo*, unsigned int, int)
|
__declspec(naked) void db_load_stub_client(game::native::XZoneInfo*, unsigned int, int)
|
||||||
{
|
{
|
||||||
__asm
|
__asm
|
||||||
@ -24,12 +26,38 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dump_gsc_script(const std::string& name, game::native::XAssetHeader header)
|
||||||
|
{
|
||||||
|
if (g_dump_scripts->current.enabled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string buffer;
|
||||||
|
buffer.append(header.scriptfile->name, std::strlen(header.scriptfile->name) + 1);
|
||||||
|
buffer.append(reinterpret_cast<char*>(&header.scriptfile->compressedLen), sizeof(int));
|
||||||
|
buffer.append(reinterpret_cast<char*>(&header.scriptfile->len), sizeof(int));
|
||||||
|
buffer.append(reinterpret_cast<char*>(&header.scriptfile->bytecodeLen), sizeof(int));
|
||||||
|
buffer.append(header.scriptfile->buffer, header.scriptfile->compressedLen);
|
||||||
|
buffer.append(reinterpret_cast<char*>(header.scriptfile->bytecode), header.scriptfile->bytecodeLen);
|
||||||
|
|
||||||
|
const auto out_name = std::format("gsc_dump/{}.gscbin", name);
|
||||||
|
utils::io::write_file(out_name, buffer);
|
||||||
|
|
||||||
|
console::info("Dumped %s\n", out_name.data());
|
||||||
|
}
|
||||||
|
|
||||||
game::native::XAssetHeader db_find_x_asset_header_stub(game::native::XAssetType type, const char* name, int allow_create_default)
|
game::native::XAssetHeader db_find_x_asset_header_stub(game::native::XAssetType type, const char* name, int allow_create_default)
|
||||||
{
|
{
|
||||||
const auto start = game::native::Sys_Milliseconds();
|
const auto start = game::native::Sys_Milliseconds();
|
||||||
const auto result = db_find_x_asset_header_hook.invoke<game::native::XAssetHeader>(type, name, allow_create_default);
|
const auto result = db_find_x_asset_header_hook.invoke<game::native::XAssetHeader>(type, name, allow_create_default);
|
||||||
const auto diff = game::native::Sys_Milliseconds() - start;
|
const auto diff = game::native::Sys_Milliseconds() - start;
|
||||||
|
|
||||||
|
if (type == game::native::ASSET_TYPE_SCRIPTFILE)
|
||||||
|
{
|
||||||
|
dump_gsc_script(name, result);
|
||||||
|
}
|
||||||
|
|
||||||
if (diff > 100)
|
if (diff > 100)
|
||||||
{
|
{
|
||||||
console::print(
|
console::print(
|
||||||
@ -55,6 +83,8 @@ public:
|
|||||||
utils::hook(game::native::DB_LoadXAssets, db_load_stub, HOOK_JUMP).install()->quick();
|
utils::hook(game::native::DB_LoadXAssets, db_load_stub, HOOK_JUMP).install()->quick();
|
||||||
|
|
||||||
db_find_x_asset_header_hook.create(game::native::DB_FindXAssetHeader, &db_find_x_asset_header_stub);
|
db_find_x_asset_header_hook.create(game::native::DB_FindXAssetHeader, &db_find_x_asset_header_stub);
|
||||||
|
|
||||||
|
g_dump_scripts = game::Dvar_RegisterBool("g_dumpScripts", false, game::native::DVAR_NONE, "Dump GSC scripts to binary format");
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user