Skip to content

Commit

Permalink
gsc vm 11 and gsc opcode translation
Browse files Browse the repository at this point in the history
  • Loading branch information
ate47 committed Feb 24, 2025
1 parent efd5396 commit 9753fbc
Show file tree
Hide file tree
Showing 10 changed files with 317 additions and 108 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ See the wiki to know how to use the features
| Black Ops 6 (T10) | 0B | Dc & Ex | Ex | - | [ate47/bo6-source](https://github.com/ate47/bo6-source) |
| Black Ops 6 (T10) | 0C | Dc & Ex | Ex | - | [ate47/bo6-source](https://github.com/ate47/bo6-source) |
| Black Ops 6 (T10) | 10 | Dc & Ex | Ex | - | [ate47/bo6-source](https://github.com/ate47/bo6-source) |
| Black Ops 6 (T10) | 11 | Dc & Ex | Ex | - | [ate47/bo6-source](https://github.com/ate47/bo6-source) |

- \* : Some source repositories might not be public yet.
- **Dc**: With pre-decode, see the [Using encrypted scripts in the wiki](https://github.com/ate47/atian-cod-tools/wiki/GSC-Decompiler#using-encrypted-scripts).
Expand Down
47 changes: 30 additions & 17 deletions src/acts/tools/gsc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <utils/decrypt.hpp>
#include <BS_thread_pool.hpp>
#include "tools/gsc.hpp"
#include "tools/gsc_decompiler.hpp"
#include "tools/gsc_vm.hpp"
#include "tools/gsc_opcode_nodes.hpp"
#include "tools/cw/cw.hpp"
Expand Down Expand Up @@ -1042,15 +1043,15 @@ const char* GetFLocName(GSCExportReader& reader, GSCOBJHandler& handler, uint32_
return utils::va("unk:%lx", floc);
}

int GscInfoHandleData(byte* data, size_t size, std::filesystem::path fsPath, GscDecompilerGlobalContext& gdctx) {
int tool::gsc::DecompileGsc(byte* data, size_t size, std::filesystem::path fsPath, GscDecompilerGlobalContext& gdctx) {
std::string pathStr{ fsPath.string() };
const char* path{ pathStr.data() };
actslib::profiler::Profiler profiler{ "f" };
actslib::profiler::ProfiledSection ps{ profiler, path };

const GscInfoOption& opt = gdctx.opt;

T8GSCOBJContext ctx{ opt };
T8GSCOBJContext ctx{ gdctx };
ctx.m_formatter = opt.m_formatter;
auto& gsicInfo = ctx.m_gsicInfo;

Expand Down Expand Up @@ -1171,11 +1172,13 @@ int GscInfoHandleData(byte* data, size_t size, std::filesystem::path fsPath, Gsc
core::async::opt_lock_guard lg{ gdctx.asyncMtx };
std::filesystem::create_directories(file.parent_path());
}
asmout.open(file);
if (!gdctx.noDump) {
asmout.open(file);

if (!asmout) {
LOG_ERROR("Can't open path output file {}", file.string());
return tool::BASIC_ERROR;
if (!asmout) {
LOG_ERROR("Can't open path output file {}", file.string());
return tool::BASIC_ERROR;
}
}
LOG_INFO("Decompiling into '{}'...", file.string());
}
Expand Down Expand Up @@ -1565,13 +1568,18 @@ int GscInfoHandleData(byte* data, size_t size, std::filesystem::path fsPath, Gsc
core::async::opt_lock_guard lg{ gdctx.asyncMtx };
std::filesystem::create_directories(file.parent_path());
}
asmout.open(file);
if (!gdctx.noDump) {
asmout.open(file);

if (!asmout) {
LOG_ERROR("Can't open output file {} ({})", asmfnamebuff, hashutils::ExtractTmpScript(scriptfile->GetName()));
return tool::BASIC_ERROR;
if (!asmout) {
LOG_ERROR("Can't open output file {} ({})", asmfnamebuff, hashutils::ExtractTmpScript(scriptfile->GetName()));
return tool::BASIC_ERROR;
}
LOG_INFO("Decompiling into '{}'{}...", asmfnamebuff, (gsicInfo.isGsic ? " (GSIC)" : ""));
}
else {
LOG_INFO("Decompiling '{}'{}...", hashutils::ExtractTmpScript(scriptfile->GetName()), (gsicInfo.isGsic ? " (GSIC)" : ""));
}
LOG_INFO("Decompiling into '{}'{}...", asmfnamebuff, (gsicInfo.isGsic ? " (GSIC)" : ""));
}

if (opt.m_copyright && *opt.m_copyright) {
Expand Down Expand Up @@ -2803,7 +2811,7 @@ int dumpdataset(Process& proc, int argc, const char* argv[]) {
return 0;
}

tool::gsc::T8GSCOBJContext::T8GSCOBJContext(const GscInfoOption& opt) : opt(opt) {}
tool::gsc::T8GSCOBJContext::T8GSCOBJContext(GscDecompilerGlobalContext& gdctx) : opt(gdctx.opt), gdctx(gdctx) {}

tool::gsc::T8GSCOBJContext::~T8GSCOBJContext() {
for (char* string : m_allocatedStrings) {
Expand Down Expand Up @@ -2880,7 +2888,8 @@ char* tool::gsc::T8GSCOBJContext::CloneString(const char* str) {
}

int tool::gsc::DumpAsm(GSCExportReader& exp, std::ostream& out, GSCOBJHandler& gscFile, T8GSCOBJContext& objctx, ASMContext& ctx) {
uint32_t baseloc = exp.GetAddress();
uint32_t baseloc{ exp.GetAddress() };
uint64_t filename{ ctx.m_gscReader.GetName() };
// main reading loop
while (ctx.FindNextLocation()) {
while (true) {
Expand Down Expand Up @@ -2951,7 +2960,7 @@ int tool::gsc::DumpAsm(GSCExportReader& exp, std::ostream& out, GSCOBJHandler& g
else {
opCode = (uint16_t)ctx.Read<byte>(base);
}

const auto* handler = ctx.LookupOpCode(opCode);

if (ctx.m_opt.m_func_floc) {
Expand Down Expand Up @@ -2984,7 +2993,11 @@ int tool::gsc::DumpAsm(GSCExportReader& exp, std::ostream& out, GSCOBJHandler& g
<< std::right << " " << std::flush;

// dump rosetta data
RosettaAddOpCode((uint32_t)(reinterpret_cast<uint64_t>(base) - reinterpret_cast<uint64_t>(gscFile.Ptr())), handler->m_id);
uint32_t opcodeRloc{ (uint32_t)(reinterpret_cast<uint64_t>(base) - reinterpret_cast<uint64_t>(gscFile.Ptr())) };
if (ctx.m_objctx.gdctx.opcodesLocs) {
(*ctx.m_objctx.gdctx.opcodesLocs)[filename].insert(opcodeRloc);
}
RosettaAddOpCode(opcodeRloc, handler->m_id);

// pass the opcode

Expand Down Expand Up @@ -3702,7 +3715,7 @@ int tool::gsc::gscinfo(Process& proc, int argc, const char* argv[]) {
continue;
}
try {
auto lret = GscInfoHandleData((byte*)bufferAlign, size, pathRel, gdctx);
auto lret = DecompileGsc((byte*)bufferAlign, size, pathRel, gdctx);
if (lret != tool::OK) {
ret = lret;
}
Expand Down Expand Up @@ -3742,7 +3755,7 @@ int tool::gsc::gscinfo(Process& proc, int argc, const char* argv[]) {
lret = tool::BASIC_ERROR;
}
else {
lret = GscInfoHandleData((byte*)bufferAlign, size, pathRel, gdctx);
lret = DecompileGsc((byte*)bufferAlign, size, pathRel, gdctx);
}

if (lret != tool::OK) {
Expand Down
5 changes: 4 additions & 1 deletion src/acts/tools/gsc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,11 +776,13 @@ namespace tool::gsc {
struct GscDecompilerGlobalContext {
std::mutex* asyncMtx{};
GscInfoOption opt{};
bool noDump{};
uint64_t warningOpt{};
std::unordered_map<uint64_t, tool::gsc::gdb::ACTS_GSC_GDB*> debugObjects{};
size_t decompiledFiles{};
size_t hardErrors{};
std::unordered_map<uint64_t, std::unordered_map<uint64_t, std::unordered_set<NameLocated, NameLocatedHash, NameLocatedEquals>>> vtables{};
std::unordered_map<uint64_t, std::unordered_set<uint32_t>>* opcodesLocs{};

~GscDecompilerGlobalContext() {
for (auto& [n, d] : debugObjects) {
Expand Down Expand Up @@ -811,7 +813,8 @@ namespace tool::gsc {
tool::gsc::gdb::ACTS_GSC_GDB* gdbctx{};
const tool::gsc::formatter::FormatterInfo* m_formatter{};
const GscInfoOption& opt;
T8GSCOBJContext(const GscInfoOption& opt);
GscDecompilerGlobalContext& gdctx;
T8GSCOBJContext(GscDecompilerGlobalContext& gdctx);
~T8GSCOBJContext();

/*
Expand Down
6 changes: 6 additions & 0 deletions src/acts/tools/gsc_decompiler.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once
#include <tools/gsc.hpp>

namespace tool::gsc {
int DecompileGsc(byte* data, size_t size, std::filesystem::path fsPath, GscDecompilerGlobalContext& gdctx);
}
Loading

0 comments on commit 9753fbc

Please sign in to comment.