Skip to content

Commit

Permalink
fix scr hash, give better names to hashutils functions, pad using 0 v…
Browse files Browse the repository at this point in the history
…m names, enable anim in cer
  • Loading branch information
ate47 committed Aug 11, 2024
1 parent 169d7c6 commit 5b317c8
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 35 deletions.
20 changes: 12 additions & 8 deletions src/acts/hashutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,18 @@ void hashutils::WriteExtracted(const char* file) {

for (const auto& v : g_extracted) {
auto e = g_hashMap.find(v);
assert(e != g_hashMap.end());
out << std::hex << v << "," << e->second << "\n";
if (e != g_hashMap.end()) {
out << std::hex << v << "," << e->second << "\n";
}
else {
out << std::hex << v << ",hash_" << v << "\n";
}
}

out.close();
// clear and unset extract
SaveExtracted(false);
LOG_TRACE("End write extracted");
LOG_TRACE("End write extracted into {}", file);
}

int hashutils::LoadMap(const char* file, bool ignoreCol, bool iw) {
Expand Down Expand Up @@ -249,8 +253,8 @@ int hashutils::LoadMap(const char* file, bool ignoreCol, bool iw) {
bool hashutils::Add(const char* str, bool ignoreCol, bool iw) {
g_hashMap.emplace(hashutils::Hash64(str), str);
if (iw) {
g_hashMap.emplace(hashutils::HashIW(str), str);
g_hashMap.emplace(hashutils::HashIW2(str), str);
g_hashMap.emplace(hashutils::HashIWRes(str), str);
g_hashMap.emplace(hashutils::HashJupScr(str), str);
g_hashMap.emplace(hashutils::Hash64(str, 0x811C9DC5, 0x1000193) & 0xFFFFFFFF, str);
uint64_t sv = hashutils::HashIWDVar(str) & 0x7FFFFFFFFFFFFFFF;
uint64_t sf = hashutils::HashT10Scr(str) & 0x7FFFFFFFFFFFFFFF;
Expand Down Expand Up @@ -303,6 +307,9 @@ bool hashutils::Extract(const char* type, uint64_t hash, char* out, size_t outSi
}
return true;
}
if (g_saveExtracted) {
g_extracted.emplace(hash);
}
const auto res = g_hashMap.find(hash & 0x7FFFFFFFFFFFFFFF);
if (res == g_hashMap.end()) {
snprintf(out, outSize, heavyHashes ? "%s_%016llX" : "%s_%llx", type, hash);
Expand All @@ -314,9 +321,6 @@ bool hashutils::Extract(const char* type, uint64_t hash, char* out, size_t outSi
else {
snprintf(out, outSize, "%s", res->second.c_str());
}
if (g_saveExtracted) {
g_extracted.emplace(hash);
}
return true;
}

Expand Down
6 changes: 2 additions & 4 deletions src/acts/hashutils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,10 @@ namespace hashutils {

constexpr uint32_t Hash32(const char* str) { return hash::Hash32(str); }
constexpr uint64_t Hash64(const char* str, uint64_t start = 0xcbf29ce484222325LL, uint64_t iv = 0x100000001b3) { return hash::Hash64(str, start, iv); }
constexpr uint64_t HashIW(const char* str, uint64_t start = 0x47F5817A5EF961BA) { return hash::Hash64(str, start); }
constexpr uint64_t HashIW2(const char* str, uint64_t start = 0x79D6530B0BB9B5D1) { return hash::Hash64(str, start, 0x10000000233); }
constexpr uint64_t HashIWRes(const char* str, uint64_t start = 0x47F5817A5EF961BA) { return hash::Hash64(str, start); }
constexpr uint64_t HashIWTag(const char* str, uint64_t start = 0x811C9DC5) { return hash::Hash64(str, start, 0x1000193) & 0xFFFFFFFF; }
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, uint64_t start = 0x47F5817A5EF961BA) { return hash::Hash64A(str, start); }
constexpr uint64_t HashAIW2(const char* str, uint64_t start = 0x79D6530B0BB9B5D1) { return hash::Hash64A(str, start, 0x10000000233); }
constexpr uint64_t HashJupScr(const char* str, uint64_t start = 0x79D6530B0BB9B5D1) { return hash::Hash64A(str, start, 0x10000000233); }
constexpr uint32_t HashT7(const char* str) { return (uint32_t)(hash::Hash64A(str, 0x4B9ACE2F, 0x1000193) & 0xFFFFFFFF) * 0x1000193; }
constexpr uint64_t HashIWDVar(const char* str, uint64_t start = 0) { return !start ? HashSecure("q6n-+7=tyytg94_*", 0xD86A3B09566EBAAC, str, 0x10000000233) : hash::Hash64A(str, start, 0x10000000233); }
constexpr uint64_t HashT10Scr(const char* str, uint64_t start = 0) { return !start ? HashSecure("zt@f3yp(d[kkd=_@", 0x1C2F2E3C8A257D07, str, 0x10000000233) : hash::Hash64A(str, start, 0x10000000233); }
Expand Down
4 changes: 2 additions & 2 deletions src/acts/tools/compatibility/scobalula_wnigen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ namespace {
utils::WriteString(rawdata, line.c_str());
}
if (useIW) {
utils::WriteValue(rawdata, hashutils::HashIW(line.c_str()));
utils::WriteValue(rawdata, hashutils::HashIWRes(line.c_str()));
utils::WriteString(rawdata, line.c_str());
utils::WriteValue(rawdata, hashutils::HashIW2(line.c_str()));
utils::WriteValue(rawdata, hashutils::HashJupScr(line.c_str()));
utils::WriteString(rawdata, line.c_str());
utils::WriteValue(rawdata, hashutils::Hash64(line.c_str(), 0x811C9DC5, 0x1000193) & 0xFFFFFFFF);
utils::WriteString(rawdata, line.c_str());
Expand Down
6 changes: 3 additions & 3 deletions src/acts/tools/gsc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ int GscInfoHandleData(byte* data, size_t size, const char* path, GscDecompilerGl

const char* outDir;
if (opt.m_splitByVm) {
outDir = utils::va("%s/vm-%x", opt.m_outputDir, vmInfo->vm);
outDir = utils::va("%s/vm-%02x", opt.m_outputDir, vmInfo->vm);
}
else {
outDir = opt.m_outputDir;
Expand Down Expand Up @@ -1486,7 +1486,7 @@ int GscInfoHandleData(byte* data, size_t size, const char* path, GscDecompilerGl
asmout << "\n";
}
}
if (vm <= VM_T7 && scriptfile->GetAnimTreeDoubleOffset()) {
if (vmInfo->HasFlag(VmFlags::VMF_ANIMTREE_T7) && scriptfile->GetAnimTreeDoubleOffset()) {
uintptr_t animt_location = reinterpret_cast<uintptr_t>(scriptfile->file) + scriptfile->GetAnimTreeDoubleOffset();
auto anims_count = (int)scriptfile->GetAnimTreeDoubleCount();
for (size_t i = 0; i < anims_count; i++) {
Expand Down Expand Up @@ -1966,7 +1966,7 @@ int GscInfoHandleData(byte* data, size_t size, const char* path, GscDecompilerGl

const char* outDir;
if (opt.m_splitByVm) {
outDir = utils::va("%s/vm-%x", opt.m_dbgOutputDir, vmInfo->vm);
outDir = utils::va("%s/vm-%02x", opt.m_dbgOutputDir, vmInfo->vm);
}
else {
outDir = opt.m_dbgOutputDir;
Expand Down
12 changes: 6 additions & 6 deletions src/acts/tools/gsc_opcodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ uint64_t VmInfo::HashField(const char* value) const {

uint64_t VmInfo::HashPath(const char* value) const {
if (HasFlag(VmFlags::VMF_HASH_CER) || HasFlag(VmFlags::VMF_HASH_IW)) {
return hashutils::HashIW(value);
return hashutils::HashIWRes(value);
}
return hash::Hash64Pattern(value);
}
Expand Down Expand Up @@ -4154,7 +4154,7 @@ class OPCodeInfoIWSwitch : public OPCodeInfo {
int64_t integer;
uint32_t str;
uint64_t hash;
int32_t unkb; // i32
uint32_t unkb; // i32
};

CaseValue val = *(CaseValue*)basecase;
Expand Down Expand Up @@ -4214,7 +4214,7 @@ class OPCodeInfoIWSwitch : public OPCodeInfo {
case 5: // unkb
out << "t\"" << hashutils::ExtractTmp("hash", val.unkb) << "\"" << "(0x" << std::hex << val.unkb << ")" << std::flush;
if (node) {
node->m_cases.push_back({ new ASMContextNodeHash(val.unkb, false, "?"), caseRLoc });
node->m_cases.push_back({ new ASMContextNodeHash(val.unkb, false, "t"), caseRLoc });
}
break;
case 6: // unk9
Expand Down Expand Up @@ -5244,7 +5244,7 @@ namespace tool::gsc::opcode {
RegisterOpCodeHandler(new OPCodeInfoGetHash(OPCODE_IW_GetDVarHash, "GetDVarHash", "@"));
RegisterOpCodeHandler(new OPCodeInfoGetHash(OPCODE_IW_GetResourceHash, "GetResourceHash", "%"));
RegisterOpCodeHandler(new OPCodeInfoGetHash(OPCODE_IW_GetTagHash, "GetTagHash", "t", false));
RegisterOpCodeHandler(new OPCodeInfoGetHash(OPCODE_T10_GetTargetHash, "GetTargetHash", "&"));
RegisterOpCodeHandler(new OPCodeInfoGetHash(OPCODE_T10_GetScrHash, "GetScrHash", "&"));

RegisterOpCodeHandler(new OPCodeInfoIWSwitch());
RegisterOpCodeHandler(new OPCodeInfoIWEndSwitch());
Expand Down Expand Up @@ -6294,8 +6294,8 @@ int ASMContextNodeBlock::ComputeForEachBlocks(ASMContext& ctx) {
var_23ea8daa is the key, it might not be used, idea: counting the ref?
e_clip is the value
*/
constexpr uint64_t getfirstarraykeyIWHash = hashutils::HashIW2("getfirstarraykey");
constexpr uint64_t getnextarraykeyIWHash = hashutils::HashIW2("getnextarraykey");
constexpr uint64_t getfirstarraykeyIWHash = hashutils::HashJupScr("getfirstarraykey");
constexpr uint64_t getnextarraykeyIWHash = hashutils::HashJupScr("getnextarraykey");
constexpr uint64_t getfirstarraykeyCerHash = 0x7e4a95b654d9324;
constexpr uint64_t getnextarraykeyCerHash = 0xbedcb09342b6223;

Expand Down
1 change: 1 addition & 0 deletions src/acts/tools/gsc_opcodes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace tool::gsc::opcode {
VMF_IW_CALLS = 0x800,
VMF_EXPORT_NOCHECKSUM = 0x1000,
VMF_HASH_CER = 0x2000,
VMF_ANIMTREE_T7= 0x4000,
};
enum VmOperatorFunctionData : uint64_t {
VPFD_NONE = 0,
Expand Down
14 changes: 7 additions & 7 deletions src/acts/tools/gsc_opcodes_load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ namespace tool::gsc::opcode {
RegisterVMOperatorFunction(VM_MW23, "istrue", "istrue(object) -> bool", OPCODE_IW_IsTrue, VPFD_RETURN_VALUE, 1, 1);
RegisterVMHashOPCode(VM_MW23, '#', OPCODE_GetHash, 8, [](const char* str) { return hash::Hash64(str); });
RegisterVMHashOPCode(VM_MW23, '@', OPCODE_IW_GetDVarHash, 8, [](const char* str) { return hashutils::HashIWDVar(str); });
RegisterVMHashOPCode(VM_MW23, '%', OPCODE_IW_GetResourceHash, 8, [](const char* str) { return hashutils::HashIW(str); });
RegisterVMHashOPCode(VM_MW23, '%', OPCODE_IW_GetResourceHash, 8, [](const char* str) { return hashutils::HashIWRes(str); });
RegisterVMHashOPCode(VM_MW23, 't', OPCODE_IW_GetTagHash, 4, [](const char* str) { return hashutils::HashIWTag(str); });
RegisterDevCall(VM_MW23, "assert", "assertmsg", "assertex", "println");
RegisterDatatype(VM_MW23, "builtinfunction", "builtinmethod", "function", "string", "istring", "struct", "int", "float", "vector");
Expand All @@ -919,7 +919,7 @@ namespace tool::gsc::opcode {
RegisterVMOperatorFunction(VM_MW23B, "istrue", "istrue(object) -> bool", OPCODE_IW_IsTrue, VPFD_RETURN_VALUE, 1, 1);
RegisterVMHashOPCode(VM_MW23B, '#', OPCODE_GetHash, 8, [](const char* str) { return hash::Hash64(str); });
RegisterVMHashOPCode(VM_MW23B, '@', OPCODE_IW_GetDVarHash, 8, [](const char* str) { return hashutils::HashIWDVar(str); });
RegisterVMHashOPCode(VM_MW23B, '%', OPCODE_IW_GetResourceHash, 8, [](const char* str) { return hashutils::HashIW(str); });
RegisterVMHashOPCode(VM_MW23B, '%', OPCODE_IW_GetResourceHash, 8, [](const char* str) { return hashutils::HashIWRes(str); });
RegisterVMHashOPCode(VM_MW23B, 't', OPCODE_IW_GetTagHash, 4, [](const char* str) { return hashutils::HashIWTag(str); });
RegisterDevCall(VM_MW23B, "assert", "assertmsg", "assertex", "println");
RegisterDatatype(VM_MW23B, "builtinfunction", "builtinmethod", "function", "string", "istring", "struct", "int", "float", "vector");
Expand All @@ -940,16 +940,16 @@ namespace tool::gsc::opcode {
RegisterVMOperatorFunction(VM_BO6, "flat_args", "flat_args(array, count) -> bool", OPCODE_T10_FlatArgs, VPFD_RETURN_VALUE, 2, 2);
RegisterVMHashOPCode(VM_BO6, '#', OPCODE_GetHash, 8, [](const char* str) { return hash::Hash64(str); });
RegisterVMHashOPCode(VM_BO6, '@', OPCODE_IW_GetDVarHash, 8, [](const char* str) { return hashutils::HashIWDVar(str); });
RegisterVMHashOPCode(VM_BO6, '%', OPCODE_IW_GetResourceHash, 8, [](const char* str) { return hashutils::HashIW(str); });
RegisterVMHashOPCode(VM_BO6, '%', OPCODE_IW_GetResourceHash, 8, [](const char* str) { return hashutils::HashIWRes(str); });
RegisterVMHashOPCode(VM_BO6, 't', OPCODE_IW_GetTagHash, 4, [](const char* str) { return hashutils::HashIWTag(str); });
RegisterVMHashOPCode(VM_BO6, '&', OPCODE_T10_GetTargetHash, 8, [](const char* str) { return hashutils::Hash64(str); });
RegisterVMHashOPCode(VM_BO6, '&', OPCODE_T10_GetScrHash, 8, [](const char* str) { return hashutils::HashT10Scr(str); });
RegisterDevCall(VM_BO6, "assert", "assertmsg", "assertex", "println");
RegisterDatatype(VM_BO6, "builtinfunction", "builtinmethod", "function", "string", "istring", "struct", "int", "float", "vector");
#ifdef SP23_INCLUDES
sp23::opcodes::RegisterMW23OpCodes();
#endif

RegisterVM(VM_T7, "Call of Duty: Black ops 3", "t7", "bo3", VmFlags::VMF_CLIENT_VM | VmFlags::VMF_NO_FILE_NAMESPACE | VmFlags::VMF_OPCODE_U16 | VmFlags::VMF_ALIGN);
RegisterVM(VM_T7, "Call of Duty: Black ops 3", "t7", "bo3", VmFlags::VMF_CLIENT_VM | VmFlags::VMF_NO_FILE_NAMESPACE | VmFlags::VMF_OPCODE_U16 | VmFlags::VMF_ALIGN | VmFlags::VMF_ANIMTREE_T7);
RegisterVMPlatform(VM_T7, PLATFORM_PC);
RegisterVMGlobalVariable(VM_T7, "level", OPCODE_IW_GetLevel);
RegisterVMGlobalVariable(VM_T7, "game", OPCODE_IW_GetGame);
Expand Down Expand Up @@ -1133,7 +1133,7 @@ namespace tool::gsc::opcode {
// 243:12d0000 -> {0x243, 0x249, 0x25a, 0x2dc, 0x32a, 0x33b, 0x372, 0x38e, 0x54b, 0x552, 0x555, 0x5a0, 0x5b2, 0x5c0, 0x65a, 0x685, 0x79a, 0x7ee, 0x813, 0x95a, 0x969, 0x9b1, 0xa21, 0xb3c, 0xb51, 0xc0e, 0xc6a, 0xd0e, 0xdb6, 0xdc5, 0xf3f, 0xf5a, 0xfda, 0xfe5, 0x101d, 0x1277, 0x133f, 0x13b0, 0x1481, 0x14ab, 0x15cd, 0x1610, 0x1689, 0x17f6, 0x1896, 0x1953, 0x19fa, 0x1aa5, 0x1ab6, 0x1ad4, 0x1b06, 0x1b74, 0x1c58, 0x1cfb, 0x1d34, 0x1de5, 0x1e2e, 0x1f13, 0x1f46, 0x1fba, 0x1ff4}


RegisterVM(VM_T71B, "Call of Duty: Black ops 3 (1B)", "t7_1b", "bo3_1b", VmFlags::VMF_CLIENT_VM | VmFlags::VMF_NO_FILE_NAMESPACE | VmFlags::VMF_ALIGN); // | VmFlags::VMF_CALL_NO_PARAMS
RegisterVM(VM_T71B, "Call of Duty: Black ops 3 (1B)", "t7_1b", "bo3_1b", VmFlags::VMF_CLIENT_VM | VmFlags::VMF_NO_FILE_NAMESPACE | VmFlags::VMF_ALIGN | VmFlags::VMF_ANIMTREE_T7); // | VmFlags::VMF_CALL_NO_PARAMS
RegisterVMPlatform(VM_T71B, PLATFORM_PC);
RegisterVMGlobalVariable(VM_T71B, "level", OPCODE_IW_GetLevel);
RegisterVMGlobalVariable(VM_T71B, "game", OPCODE_IW_GetGame);
Expand Down Expand Up @@ -1725,7 +1725,7 @@ namespace tool::gsc::opcode {
RegisterOpCode(OPCODE_DEV_Consume9Push, "DevConsume9Push");
RegisterOpCode(OPCODE_JumpOnDefined, "JumpOnDefined");
RegisterOpCode(OPCODE_JumpOnDefinedExpr, "JumpOnDefinedExpr");
RegisterOpCode(OPCODE_T10_GetTargetHash, "GetTargetHash");
RegisterOpCode(OPCODE_T10_GetScrHash, "GetScrHash");
RegisterOpCode(OPCODE_T10_FlatArgs, "FlatArgs");
RegisterOpCode(OPCODE_T10_GreaterThanOrSuperEqualTo, "GreaterThanOrSuperEqualTo");
RegisterOpCode(OPCODE_T10_LowerThanOrSuperEqualTo, "LowerThanOrSuperEqualTo");
Expand Down
2 changes: 1 addition & 1 deletion src/acts/tools/gsc_opcodes_load.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ namespace tool::gsc::opcode {

OPCODE_JumpOnDefined,
OPCODE_JumpOnDefinedExpr,
OPCODE_T10_GetTargetHash,
OPCODE_T10_GetScrHash,
OPCODE_T10_FlatArgs,
OPCODE_T10_GreaterThanOrSuperEqualTo,
OPCODE_T10_LowerThanOrSuperEqualTo,
Expand Down
4 changes: 2 additions & 2 deletions src/acts/tools/gsc_vm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2453,13 +2453,13 @@ class T10GSCOBJHandler : public GSCOBJHandler {
return Ptr<GscObj24>()->animtree_use_count;
};
uint32_t GetAnimTreeSingleOffset() override {
return 0;// Ptr<GscObj24>()->animtree_use_offset;
return Ptr<GscObj24>()->animtree_use_offset;
};
uint16_t GetAnimTreeDoubleCount() override {
return Ptr<GscObj24>()->animtree_count;
};
uint32_t GetAnimTreeDoubleOffset() override {
return 0;// Ptr<GscObj24>()->animtree_offset;
return Ptr<GscObj24>()->animtree_offset;
};
uint16_t GetDevStringsCount() override {
return Ptr<GscObj24>()->devblock_string_count;
Expand Down
4 changes: 2 additions & 2 deletions src/acts/tools/hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ namespace {

std::wstring hash64Val = DefaultVal(hash::Hash64(info.hash.c_str()));
std::wstring hash32Val = DefaultVal(hash::Hash32(info.hash.c_str()));
std::wstring hash64IW2Val = DefaultVal(hashutils::HashAIW(info.hash.c_str()));
std::wstring hash64IW3Val = DefaultVal(hashutils::HashAIW2(info.hash.c_str()));
std::wstring hash64IW2Val = DefaultVal(hashutils::HashIWRes(info.hash.c_str()));
std::wstring hash64IW3Val = DefaultVal(hashutils::HashJupScr(info.hash.c_str()));
std::wstring hash32IW4Val = DefaultVal(hashutils::Hash64(info.hash.c_str(), 0x811C9DC5, 0x1000193) & 0xFFFFFFFF);
std::wstring hashT7Val = DefaultVal(hashutils::HashT7(info.hash.c_str()));
std::wstring hash64IWDvar = DefaultVal(hashutils::HashIWDVar(info.hash.c_str()));
Expand Down
40 changes: 40 additions & 0 deletions src/acts/tools/hashes/searcher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <includes.hpp>


namespace {

int hashsearcher(Process& proc, int argc, const char* argv[]) {
if (argc < 4) {
return tool::BAD_USAGE;
}

std::unordered_set<uint64_t> hashes{};

{
std::ifstream input{ argv[2] };
if (!input) {
LOG_ERROR("Can't open {}", argv[2]);
return tool::BASIC_ERROR;
}
utils::CloseEnd ci{ [&input] { input.close(); } };

std::string line{};

while (input && std::getline(input, line, '\n')) {
if (line.empty()) continue;
try {
hashes.insert(std::strtoull(line.c_str(), nullptr, 16));
}
catch (std::exception&) {}
}
}
LOG_INFO("Loaded {} hash(es)", hashes.size());



return tool::OK;
}

ADD_TOOL("hashsearcher", "hash", " [file] [output]", "search in hash file", nullptr, hashsearcher);

}

0 comments on commit 5b317c8

Please sign in to comment.