Skip to content

Commit

Permalink
wip t7 decompiler opcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
ate47 committed May 20, 2024
1 parent 62390d0 commit d81fbfe
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/acts/hashutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ bool hashutils::Add(const char* str, bool ignoreCol, bool iw) {
}

if (cand32) {
g_hashMap.emplace(hashutils::HashT7(str), str);

auto h = hashutils::Hash32(str);
if (!ignoreCol) {
auto find = g_hashMap.find(h);
Expand Down
2 changes: 2 additions & 0 deletions src/acts/hashutils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ namespace hashutils {
constexpr uint64_t Hash64A(const char* str, uint64_t start = 0xcbf29ce484222325LL, uint64_t iv = 0x100000001b3) { return hash::Hash64A(str, start, iv); }
constexpr uint64_t HashAIW(const char* str) { return hash::Hash64A(str, 0x47F5817A5EF961BA); }
constexpr uint64_t HashAIW2(const char* str) { return hash::Hash64A(str, 0x79D6530B0BB9B5D1, 0x10000000233); }
constexpr uint32_t HashT7(const char* str) { return (uint32_t)(hash::Hash64A(str, 0x4B9ACE2F, 0x1000193) & 0xFFFFFFFF) * 0x1000193; }

/*
* Compute the hash32 on a string (canon id), but allow pattern like "function_123456"
* @param str String to compute
Expand Down
32 changes: 32 additions & 0 deletions src/acts/tools/bo3/pools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,37 @@ namespace bo3::pool {
T7_ASSET_TYPE_DEPEND = 106,
};

enum T7ScrVarType : uint32_t {
T7_TYPE_UNDEFINED = 0,
T7_TYPE_POINTER = 1,
T7_TYPE_STRING = 2,
T7_TYPE_LOCALIZED_STRING = 3,
T7_TYPE_VECTOR = 4,
T7_TYPE_HASH = 5,
T7_TYPE_FLOAT = 6,
T7_TYPE_INT = 7,
T7_TYPE_UINT64 = 8,
T7_TYPE_UINTPTR_T = 9,
T7_TYPE_ENTITY_OFFSET = 10,
T7_TYPE_CODEPOS = 11,
T7_TYPE_PRECODEPOS = 12,
T7_TYPE_API_FUNCTION = 13,
T7_TYPE_FUNCTION = 14,
T7_TYPE_STACK = 15,
T7_TYPE_ANIMATION = 16,
T7_TYPE_THREAD = 17,
T7_TYPE_NOTIFY_THREAD = 18,
T7_TYPE_TIME_THREAD = 19,
T7_TYPE_CHILD_THREAD = 20,
T7_TYPE_CLASS = 21,
T7_TYPE_STRUCT = 22,
T7_TYPE_REMOVED_ENTITY = 23,
T7_TYPE_ENTITY = 24,
T7_TYPE_ARRAY = 25,
T7_TYPE_REMOVED_THREAD = 26,
T7_TYPE_FREE = 27,
T7_TYPE_THREAD_LIST = 28,
T7_TYPE_ENT_LIST = 29,
};

}
8 changes: 4 additions & 4 deletions src/acts/tools/gsc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1738,7 +1738,7 @@ int tool::gsc::DumpAsm(GSCExportReader& exp, std::ostream& out, GSCOBJHandler& g

uint16_t opCode;

if (objctx.m_vmInfo->flags & VmFlags::VMF_OPCODE_SHORT) {
if (objctx.m_vmInfo->HasFlag(VmFlags::VMF_OPCODE_SHORT)) {
opCode = *(uint16_t*)base;
}
else {
Expand All @@ -1750,9 +1750,9 @@ int tool::gsc::DumpAsm(GSCExportReader& exp, std::ostream& out, GSCOBJHandler& g

out << "." << std::hex << std::setfill('0') << std::setw(sizeof(int32_t) << 1) << loc.rloc << ": " << std::flush;

if (opCode & ~0xFFF) {
out << std::hex << "FAILURE, FIND errec: " << handler->m_name << "(" << opCode << ")" << "\n";
opCode &= 0xFFF;
if (opCode > objctx.m_vmInfo->maxOpCode) {
out << std::hex << "FAILURE, FIND errec: " << handler->m_name << "(0x" << opCode << " > 0x" << objctx.m_vmInfo->maxOpCode << ")" << "\n";
opCode &= objctx.m_vmInfo->maxOpCode;
ctx.m_disableDecompiler = true;
break;
}
Expand Down
17 changes: 15 additions & 2 deletions src/acts/tools/gsc_opcodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4517,6 +4517,16 @@ void tool::gsc::opcode::RegisterVMGlobalVariable(byte vm, const char* name, OPCo
gv.getOpCode = getOpCode;
}

void tool::gsc::opcode::SetMaxOpCode(byte vm, uint16_t maxOpCode) {
auto ref = g_opcodeMap.find(vm);

if (ref == g_opcodeMap.end()) {
LOG_ERROR("Set max opcode to bad vm: VM_{:x}", (int)vm);
return;
}

ref->second.maxOpCode = maxOpCode;
}
void tool::gsc::opcode::RegisterVMPlatform(byte vm, Platform plt) {
auto ref = g_opcodeMap.find(vm);

Expand Down Expand Up @@ -4727,6 +4737,8 @@ void tool::gsc::opcode::RegisterOpCodes() {
RegisterOpCodeHandler(new OPCodeInfoGetNumber<uint16_t>(OPCODE_GetUnsignedShort, "GetUnsignedShort"));
RegisterOpCodeHandler(new OPCodeInfoGetNumber<FLOAT, FLOAT>(OPCODE_GetFloat, "GetFloat", TYPE_FLOAT));
RegisterOpCodeHandler(new OPCodeInfoGetNumber<uintptr_t, uintptr_t>(OPCODE_GetUIntPtr, "GetUIntPtr"));
RegisterOpCodeHandler(new OPCodeInfoGetNumber<int8_t>(OPCODE_GetSignedByte, "GetSignedByte"));
RegisterOpCodeHandler(new OPCodeInfoGetNumber<int16_t>(OPCODE_GetShort, "GetShort"));
RegisterOpCodeHandler(new OPCodeInfoVector());
RegisterOpCodeHandler(new OPCodeInfoVectorConstant());
RegisterOpCodeHandler(new OPCodeInfoGetVector());
Expand Down Expand Up @@ -4848,7 +4860,8 @@ void tool::gsc::opcode::RegisterOpCodes() {
RegisterOpCodeHandler(new OPCodeInfoSingle(OPCODE_IW_WaitTillMatch, "WaitTillMatch", "waittillmatch", true, 2, 2));
RegisterOpCodeHandler(new OPCodeInfoIWNotify(OPCODE_IW_Notify, "Notify"));


// T7
RegisterOpCodeHandler(new OPCodeInfoGetHash(OPCODE_GetHash32, "GetHash", "#", false));

// T8compiler custom opcode
RegisterOpCodeHandler(new OPCodeInfoT8CGetLazyFunction());
Expand Down Expand Up @@ -4888,7 +4901,7 @@ const OPCodeInfo* tool::gsc::opcode::LookupOpCode(byte vm, Platform platform, ui
return g_unknownOpcode;
}

auto ref = info->opcodemap.find(opcode & 0xFFF);
auto ref = info->opcodemap.find(opcode);

if (ref == info->opcodemap.end()) {
return g_unknownOpcode;
Expand Down
2 changes: 2 additions & 0 deletions src/acts/tools/gsc_opcodes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace tool::gsc::opcode {
const char* codeName;
uint64_t flags;
byte platforms{};
uint16_t maxOpCode{ 0xFFF };
std::unordered_map<char, VmHashFunc> hashesFunc{};
std::unordered_set<uint64_t> devCallsNames{};
std::unordered_map<uint16_t, std::unordered_map<Platform, OPCode>> opcodemap{};
Expand Down Expand Up @@ -123,6 +124,7 @@ namespace tool::gsc::opcode {
void RegisterVMPlatform(byte vm, Platform plt);
void RegisterVMHashOPCode(byte vm, char type, OPCode opCode, int size, std::function<uint64_t(const char*)> hashFunc);
void RegisterOpCode(byte vm, Platform platform, OPCode enumValue, uint16_t op);
void SetMaxOpCode(byte vm, uint16_t maxOpCode);
void RegisterDevCall(byte vm, const char* devCall);
void RegisterOpCodes();

Expand Down
Loading

0 comments on commit d81fbfe

Please sign in to comment.