From 0f8995fb32b127e204ce10b786ac18d20c8f3626 Mon Sep 17 00:00:00 2001 From: qaate47 Date: Thu, 30 May 2024 16:53:01 +0200 Subject: [PATCH] fix string formatting, replace --vm behavior and use decrypted jupb strings --- src/acts/tools/gsc.cpp | 10 +++++++--- src/acts/tools/gsc_opcodes.cpp | 10 +++++----- src/acts/tools/gsc_vm.hpp | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/acts/tools/gsc.cpp b/src/acts/tools/gsc.cpp index dc4c1a8..9ab5d98 100644 --- a/src/acts/tools/gsc.cpp +++ b/src/acts/tools/gsc.cpp @@ -244,7 +244,7 @@ void GscInfoOption::PrintHelp() { LOG_INFO("-a --asm : Produce ASM"); LOG_INFO("-t --type [t] : Set type, default PC, values: 'ps', 'xbox', 'pc'"); LOG_INFO("-o --output [d] : ASM/GSC output dir, default same.gscasm"); - LOG_INFO("-v --vm : Set vm, useless for Treyarch VM, values: mw23"); + LOG_INFO("-v --vm : Only decompile a particular vm"); LOG_INFO("-H --header : Write file header"); LOG_INFO("-m --hashmap [f] : Write hashmap in a file f"); { @@ -732,12 +732,12 @@ int GscInfoHandleData(byte* data, size_t size, const char* path, const GscInfoOp bool iw; uint64_t magicVal = *reinterpret_cast(data); - if ((magicVal & ~0x000000000000000F) == 0xA0D43534780) { + if ((magicVal & ~0xFF) == 0xa0d43534700) { // IW GSC file, use 0 revision vm = data[0]; iw = true; } - else if ((magicVal & ~0xFF0000000000000F) == 0xa0d43534780) { + else if ((magicVal & ~0xFF00000000000000) == 0xa0d43534780) { // Treyarch GSC file, use 7 revision vm = data[7]; iw = false; @@ -748,6 +748,10 @@ int GscInfoHandleData(byte* data, size_t size, const char* path, const GscInfoOp } hashutils::ReadDefaultFile(); + if (opt.m_vm && vm != opt.m_vm) { + LOG_INFO("Not the wanted vm: 0x{:x} != 0x{:x}", (int)vm, (int)opt.m_vm); + return tool::OK; + } VmInfo* vmInfo; if (!IsValidVm(vm, vmInfo)) { diff --git a/src/acts/tools/gsc_opcodes.cpp b/src/acts/tools/gsc_opcodes.cpp index c249254..a205029 100644 --- a/src/acts/tools/gsc_opcodes.cpp +++ b/src/acts/tools/gsc_opcodes.cpp @@ -128,8 +128,8 @@ namespace tool::gsc::opcode { out << "\\\""; break; default: - if (*str < 0x20) { - out << "\\" << std::oct << (int)(*str) << std::dec; + if (*str < 0x20 || *str >= 0x7F) { + out << "\\" << std::oct << (unsigned int)(*reinterpret_cast(str)) << std::dec; } else { out << *str; @@ -876,7 +876,7 @@ class OPCodeInfoGetNeg : public OPCodeInfo { context.PushASMCNode(new ASMContextNodeValue(negv, TYPE_VALUE, false, true, true)); } - out << std::dec << negv << std::endl; + out << std::dec << negv << " (0x" << std::hex << -negv << ")" << std::endl; return 0; } @@ -1088,7 +1088,7 @@ class OPCodeInfoGetNumber : public OPCodeInfo { if (context.m_runDecompiler) { context.PushASMCNode(new ASMContextNodeValue(intValue, m_valtype, false, true, true)); } - out << std::dec << intValue << std::endl; + out << std::dec << intValue << " (0x" << std::hex << intValue << ")" << std::endl; } bytecode += sizeof(Type); @@ -4954,7 +4954,7 @@ void tool::gsc::opcode::RegisterOpCodes() { RegisterOpCodeHandler(new OPCodeInfoSetGlobalObjectFieldVariable(OPCODE_IW_SetLevelFieldVariable, "SetLevelFieldVar", "level")); RegisterOpCodeHandler(new OPCodeInfoEvalGlobalObjectFieldVariable(OPCODE_IW_EvalAnimFieldVar, "EvalAnimFieldVar", "anim", true)); RegisterOpCodeHandler(new OPCodeInfoEvalGlobalObjectFieldVariable(OPCODE_IW_EvalAnimFieldVarRef, "EvalAnimFieldVarRef", "anim", false)); - RegisterOpCodeHandler(new OPCodeInfoSetGlobalObjectFieldVariable(OPCODE_IW_SetAnimFieldVar, "SetLevelFieldVar", "anim")); + RegisterOpCodeHandler(new OPCodeInfoSetGlobalObjectFieldVariable(OPCODE_IW_SetAnimFieldVar, "SetAnimFieldVar", "anim")); // let's say it's a "global" RegisterOpCodeHandler(new OPCodeInfoEvalGlobalObjectFieldVariable(OPCODE_IW_EvalSelfFieldVar, "EvalSelfFieldVar", "self", true)); RegisterOpCodeHandler(new OPCodeInfoEvalGlobalObjectFieldVariable(OPCODE_IW_EvalSelfFieldVarRef, "EvalSelfFieldVarRef", "self", false)); diff --git a/src/acts/tools/gsc_vm.hpp b/src/acts/tools/gsc_vm.hpp index 38985a9..55b910b 100644 --- a/src/acts/tools/gsc_vm.hpp +++ b/src/acts/tools/gsc_vm.hpp @@ -1238,7 +1238,7 @@ class MW23BGSCOBJHandler : public GSCOBJHandler { return sizeof(GscObj23); } char* DecryptString(char* str) override { - return str; // iw + return str + 3; // iw } bool IsValidHeader(size_t size) override { return size >= sizeof(GscObj23) && *reinterpret_cast(file) == 0xa0d4353478b;