(gsc): Improve decomp code a tiny bit

This commit is contained in:
FutureRave 2022-10-05 18:29:36 +01:00
parent 3694c02184
commit 0ad6b83f59
No known key found for this signature in database
GPG Key ID: 22F9079C86CFAB31

View File

@ -528,28 +528,27 @@ namespace gsc
return std::to_string(id); return std::to_string(id);
} }
std::vector<std::uint8_t> decompile_scriptfile(const std::string& name) std::vector<std::uint8_t> decompile_scriptfile(const std::string& name, const std::string& real_name)
{ {
const auto scriptfile = game::DB_FindXAssetHeader(game::ASSET_TYPE_SCRIPTFILE, name.data(), false).scriptfile; const auto* scriptfile = game::DB_FindXAssetHeader(game::ASSET_TYPE_SCRIPTFILE, name.data(), false).scriptfile;
if (scriptfile == nullptr) if (scriptfile == nullptr)
{ {
throw std::runtime_error(std::format("couldn't load scriptfile {}", name)); throw std::runtime_error(std::format("couldn't load scriptfile '{}'", real_name));
} }
console::info("Decompiling scriptfile %s\n", name.data()); console::info("Decompiling scriptfile '%s'\n", real_name.data());
std::vector<std::uint8_t> stack{scriptfile->buffer, scriptfile->buffer + scriptfile->len}; std::vector<std::uint8_t> stack{scriptfile->buffer, scriptfile->buffer + scriptfile->len};
std::vector<std::uint8_t> bytecode{scriptfile->bytecode, scriptfile->bytecode + scriptfile->bytecodeLen}; std::vector<std::uint8_t> bytecode{scriptfile->bytecode, scriptfile->bytecode + scriptfile->bytecodeLen};
auto decompressed_stack = xsk::utils::zlib::decompress(stack, static_cast<int>(stack.size())); auto decompressed_stack = xsk::utils::zlib::decompress(stack, static_cast<std::uint32_t>(stack.size()));
disassembler->disassemble(name, bytecode, decompressed_stack); disassembler->disassemble(name, bytecode, decompressed_stack);
auto output = disassembler->output(); auto output = disassembler->output();
decompiler->decompile(name, output); decompiler->decompile(name, output);
const auto data = decompiler->output();
return std::vector<std::uint8_t>{data.begin(), data.end()}; return decompiler->output();
} }
} }
@ -589,11 +588,11 @@ namespace gsc
const auto name = get_script_file_name(include_name); const auto name = get_script_file_name(include_name);
if (game::DB_XAssetExists(game::ASSET_TYPE_SCRIPTFILE, name.data())) if (game::DB_XAssetExists(game::ASSET_TYPE_SCRIPTFILE, name.data()))
{ {
return decompile_scriptfile(name); return decompile_scriptfile(name, real_name);
} }
else else
{ {
throw std::runtime_error(std::format("could not load gsc file '{}'", real_name)); throw std::runtime_error(std::format("couldn't load gsc file '{}'", real_name));
} }
} }