Skip to content

Commit

Permalink
decompile and compile event handlers, remove file namespace, add back…
Browse files Browse the repository at this point in the history
… GetTagHash in cer and use all hashes in acts debug decompiler
  • Loading branch information
ate47 committed Aug 10, 2024
1 parent 6bc50c9 commit 244a7de
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 12 deletions.
2 changes: 1 addition & 1 deletion grammar/gsc.g4
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,4 @@ IDENTIFIER: [a-z_A-Z] ([a-z_A-Z0-9])*;
STRUCT_IDENTIFIER: '#' [a-z_A-Z] ([a-z_A-Z0-9])*;
PATH: [a-z_A-Z0-9\\/]+ ('.gsc' | '.csc')?;
STRING: '"' (~["\\] | ('\\'.))* '"';
HASHSTRING: ('#' | '@' | 't' | '%') STRING;
HASHSTRING: ('#' | '@' | 't' | '%' | '&') STRING;
2 changes: 1 addition & 1 deletion src/acts/compiler/gscLexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void gsclexerLexerInitialize() {
205,103,207,104,209,105,1,0,13,2,0,9,9,32,32,1,0,49,57,1,0,48,57,2,0,
88,88,120,120,3,0,48,57,65,70,97,102,1,0,48,55,2,0,66,66,98,98,1,0,48,
49,3,0,65,90,95,95,97,122,4,0,48,57,65,90,95,95,97,122,5,0,47,57,65,90,
92,92,95,95,97,122,2,0,34,34,92,92,4,0,35,35,37,37,64,64,116,116,802,
92,92,95,95,97,122,2,0,34,34,92,92,4,0,35,35,37,38,64,64,116,116,802,
0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1,0,0,0,0,11,1,0,
0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,19,1,0,0,0,0,21,1,0,0,0,
0,23,1,0,0,0,0,25,1,0,0,0,0,27,1,0,0,0,0,29,1,0,0,0,0,31,1,0,0,0,0,33,
Expand Down
11 changes: 8 additions & 3 deletions src/acts/compiler/gsc_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ namespace acts::compiler {
class AscmNodeRaw : public AscmNode {
public:
std::vector<byte> data{};
size_t align;
uint32_t align;

AscmNodeRaw(size_t align = 1) : align(align) {
AscmNodeRaw(size_t align = 1) : align((uint32_t)align) {
nodetype = ASCMNT_RAW;
}

Expand Down Expand Up @@ -5082,7 +5082,7 @@ namespace acts::compiler {

obj.AddHash(txt);
obj.currentNamespace = obj.vmInfo->HashField(txt.data());
if (!obj.fileNameSpace) {
if (!obj.fileNameSpace && obj.gscHandler->HasFlag(tool::gsc::GscObjHandlerBuildFlags::GOHF_FILENAMESPACE)) {
obj.fileNameSpace = obj.vmInfo->HashFilePath(txt.data());
}

Expand All @@ -5094,6 +5094,11 @@ namespace acts::compiler {
return false; // bad
}

if (!obj.gscHandler->HasFlag(tool::gsc::GscObjHandlerBuildFlags::GOHF_FILENAMESPACE)) {
obj.info.PrintLineMessage(alogs::LVL_WARNING, nsp, "this vm doesn't support file namespace");
return true;
}

std::string txt = nsp->children[1]->getText();

// set the current file namespace to the one specified
Expand Down
22 changes: 21 additions & 1 deletion src/acts/tools/gsc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,9 +986,29 @@ int GscInfoHandleData(byte* data, size_t size, const char* path, GscDecompilerGl
hashutils::AddPrecomputed(hashField, str);
hashutils::AddPrecomputed(hashFilePath, str);
hashutils::AddPrecomputed(hashPath, str);

if (opt.m_header) {
PrintFormattedString(actsHeader << "// - #\"", str)
<< "\" (0x" << std::hex << hashField << "/0x" << hashFilePath << "/0x" << hashPath << ")\n";
<< "\" (0x" << std::hex << hashField << "/0x" << hashFilePath << "/0x" << hashPath;
}
// use all the known hashes for this VM
for (auto& [k, func] : vmInfo->hashesFunc) {
try {
int64_t hash = func.hashFunc(str);

if (hash) {
if (opt.m_header) {
actsHeader << "/" << k << '=' << std::hex << hash;
}
hashutils::AddPrecomputed(hash, str);
}
}
catch (std::exception&) {
// ignore
}
}
if (opt.m_header) {
actsHeader << ")\n";
}
}
LOG_TRACE("{} hash(es) added", dbg->strings_count);
Expand Down
1 change: 1 addition & 0 deletions src/acts/tools/gsc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace tool::gsc {
GOHF_SUPPORT_GET_API_SCRIPT = 0x1000,
GOHF_STRING_NAMES = 0x2000,
GOHF_NOTIFY_CRC_STRING = 0x4000,
GOHF_FILENAMESPACE = 0x8000,
};
static_assert(
((GOHF_FOREACH_TYPE_T8 | GOHF_FOREACH_TYPE_T9 | GOHF_FOREACH_TYPE_JUP | GOHF_FOREACH_TYPE_T7
Expand Down
3 changes: 2 additions & 1 deletion src/acts/tools/gsc_opcodes_load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,8 @@ namespace tool::gsc::opcode {
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, 't', OPCODE_T10_GetTargetHash, 8, [](const char* str) { return hashutils::Hash64(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); });
RegisterDevCall(VM_BO6, "assert", "assertmsg", "assertex", "println");
RegisterDatatype(VM_BO6, "builtinfunction", "builtinmethod", "function", "string", "istring", "struct", "int", "float", "vector");
#ifdef SP23_INCLUDES
Expand Down
12 changes: 8 additions & 4 deletions src/acts/tools/gsc_vm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ class T9GSCOBJHandler : public GSCOBJHandler {

class MW23GSCOBJHandler : public GSCOBJHandler {
public:
MW23GSCOBJHandler(byte* file, size_t fileSize) : GSCOBJHandler(file, fileSize, GOHF_ANIMTREE | GOHF_ANIMTREE_DOUBLE | GOHF_FOREACH_TYPE_JUP) {}
MW23GSCOBJHandler(byte* file, size_t fileSize) : GSCOBJHandler(file, fileSize, GOHF_ANIMTREE | GOHF_ANIMTREE_DOUBLE | GOHF_FOREACH_TYPE_JUP | GOHF_FILENAMESPACE) {}

void DumpHeader(std::ostream& asmout, const GscInfoOption& opt) override {
auto* data = Ptr<GscObj23>();
Expand Down Expand Up @@ -1389,7 +1389,7 @@ class MW23GSCOBJHandler : public GSCOBJHandler {

class MW23BGSCOBJHandler : public GSCOBJHandler {
public:
MW23BGSCOBJHandler(byte* file, size_t fileSize) : GSCOBJHandler(file, fileSize, GOHF_ANIMTREE | GOHF_ANIMTREE_DOUBLE | GOHF_FOREACH_TYPE_JUP | GOHF_NOTIFY_CRC_STRING) {}
MW23BGSCOBJHandler(byte* file, size_t fileSize) : GSCOBJHandler(file, fileSize, GOHF_ANIMTREE | GOHF_ANIMTREE_DOUBLE | GOHF_FOREACH_TYPE_JUP | GOHF_NOTIFY_CRC_STRING | GOHF_FILENAMESPACE) {}

void DumpHeader(std::ostream& asmout, const GscInfoOption& opt) override {
auto* data = Ptr<GscObj23>();
Expand Down Expand Up @@ -2328,7 +2328,7 @@ class T71BGSCOBJHandler : public GSCOBJHandler {

class T10GSCOBJHandler : public GSCOBJHandler {
public:
T10GSCOBJHandler(byte* file, size_t fileSize) : GSCOBJHandler(file, fileSize, GOHF_ANIMTREE | GOHF_ANIMTREE_DOUBLE | GOHF_FOREACH_TYPE_JUP | GOHF_NOTIFY_CRC_STRING | GOHF_SUPPORT_VAR_VA) {}
T10GSCOBJHandler(byte* file, size_t fileSize) : GSCOBJHandler(file, fileSize, GOHF_ANIMTREE | GOHF_ANIMTREE_DOUBLE | GOHF_FOREACH_TYPE_JUP | GOHF_NOTIFY_CRC_STRING | GOHF_SUPPORT_EV_HANDLER | GOHF_SUPPORT_VAR_VA) {}

void DumpHeader(std::ostream& asmout, const GscInfoOption& opt) override {
GscObj24* data = Ptr<GscObj24>();
Expand Down Expand Up @@ -2556,6 +2556,9 @@ class T10GSCOBJHandler : public GSCOBJHandler {
if (flags & 4) {
nflags |= T8GSCExportFlags::PRIVATE;
}
if (flags & 0x20) {
nflags |= T8GSCExportFlags::EVENT;
}
if (flags & 0x40) {
nflags |= T8GSCExportFlags::VE;
}
Expand All @@ -2570,6 +2573,7 @@ class T10GSCOBJHandler : public GSCOBJHandler {
if (flags & AUTOEXEC) nflags |= 1;
if (flags & LINKED) nflags |= 2;
if (flags & PRIVATE) nflags |= 4;
if (flags & EVENT) nflags |= 0x20;
if (flags & VE) nflags |= 0x40;

return nflags;
Expand Down Expand Up @@ -2659,7 +2663,7 @@ class T10GSCOBJHandler : public GSCOBJHandler {
auto& imp = *reinterpret_cast<tool::gsc::IW24GSCExport*>(data);
imp.name = item.name;
imp.name_space = item.name_space;
//imp.checksum = (uint32_t)item.checksum; // no checksum
imp.file_name_space = item.file_name_space;
imp.flags = item.flags;
imp.address = item.address;
imp.param_count = item.param_count;
Expand Down
6 changes: 5 additions & 1 deletion test/gsc-compiler/acts_cer.gsc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
#using scripts\core_common\callbacks_shared;

#namespace acts;
#file scripts\test\acts;
// #file scripts\test\acts; // not a feature anymore (good)

function event_handler[sprint_begin] on_sprint_begin(params) {

println("test " + &"ok" + t"ok2" + #"ok3" + @"ok4");
}

function autoexec test_ev() {
assert(dev::func_dev(2) === 2);
Expand Down

0 comments on commit 244a7de

Please sign in to comment.