Skip to content

Commit

Permalink
wip t7 decompiler
Browse files Browse the repository at this point in the history
  • Loading branch information
ate47 committed May 20, 2024
1 parent 1fe31c6 commit 62390d0
Show file tree
Hide file tree
Showing 12 changed files with 576 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/acts/compiler/gsc_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4191,7 +4191,7 @@ namespace acts::compiler {
return tool::BASIC_ERROR;
}

std::shared_ptr<tool::gsc::GSCOBJHandler> handler {(*readerBuilder)(nullptr)};
std::shared_ptr<tool::gsc::GSCOBJHandler> handler {(*readerBuilder)(nullptr, 0)};

std::vector<std::filesystem::path> inputs{};

Expand Down
72 changes: 72 additions & 0 deletions src/acts/tools/bo3/dumpt7.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include <includes.hpp>
#include "pools.hpp"

namespace {
constexpr size_t xassetpools = 0x94073F0;

int t7poolscripts(Process& proc, int argc, const char* argv[]) {

const uintptr_t spt = proc[xassetpools] + sizeof(bo3::pool::T7XAssetPool) * bo3::pool::T7_ASSET_TYPE_SCRIPTPARSETREE;
auto [pool, ok] = proc.ReadMemoryObject<bo3::pool::T7XAssetPool>(spt);

if (!ok) {
LOG_ERROR("Can't read SPT pool: {}", spt);
return tool::BASIC_ERROR;
}

auto [entries, ok2] = proc.ReadMemoryArray<bo3::pool::T7ScriptParseTree>(pool->pool, pool->itemAllocCount);

if (!ok2) {
LOG_ERROR("Can't read SPT pool data");
return tool::BASIC_ERROR;
}

std::filesystem::path outDir;
if (argc == 2) {
outDir = "scriptparsetree_t7";
}
else {
outDir = argv[2];
}

std::filesystem::create_directories(outDir);
size_t added{};

for (size_t i = 0; i < pool->itemAllocCount; i++) {
bo3::pool::T7ScriptParseTree& entry{ entries[i] };

if (!proc.ReadMemory<char>(entry.name)) {
continue;
}

const char* name{ proc.ReadStringTmp(entry.name) };

auto [buffer, okb] = proc.ReadMemoryArray<byte>(entry.script, entry.scriptSize);

if (!okb) {
LOG_ERROR("Can't read script {}", name);
continue;
}

std::filesystem::path outFile{ outDir / utils::va("%sc", name)}; // add c to do gscc/cscc
bool isNew{ !std::filesystem::exists(outFile) };
if (isNew) {
std::filesystem::create_directories(outFile.parent_path());
added++;
}
if (!utils::WriteFile(outFile, &buffer[0], entry.scriptSize)) {
LOG_ERROR("Error when dumping {} bytes into {}", entry.scriptSize, outFile.string());
continue;
}
LOG_INFO("Dump into {} ({}){}", outFile.string(), entry.scriptSize, isNew ? " (new)" : "");
}

LOG_INFO("Done, {} file(s) added", added);

return tool::OK;
}



ADD_TOOL("wpst7", "bo3", " [output=scriptparsetree_t7]", "dump pooled scripts (bo3)", L"BlackOps3.exe", t7poolscripts);
}
133 changes: 133 additions & 0 deletions src/acts/tools/bo3/pools.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#pragma once

namespace bo3::pool {

struct T7XAssetPool {
uintptr_t pool; // void*
unsigned int itemSize;
int itemCount;
bool isSingleton;
int itemAllocCount;
uintptr_t freeHead; // AssetLink*
};
static_assert(sizeof(T7XAssetPool) == 0x20);

struct T7ScriptParseTree {
uintptr_t name; // const char*
int64_t scriptSize;
uintptr_t script; // T7GSC_OBJ*
};
static_assert(sizeof(T7ScriptParseTree) == 0x18);

enum T7XAssetType {
T7_ASSET_TYPE_PHYSPRESET = 0,
T7_ASSET_TYPE_PHYSCONSTRAINTS = 1,
T7_ASSET_TYPE_DESTRUCTIBLEDEF = 2,
T7_ASSET_TYPE_XANIM = 3,
T7_ASSET_TYPE_XMODEL = 4,
T7_ASSET_TYPE_XMODELMESH = 5,
T7_ASSET_TYPE_MATERIAL = 6,
T7_ASSET_TYPE_COMPUTESHADERSET = 7,
T7_ASSET_TYPE_TECHSET = 8,
T7_ASSET_TYPE_IMAGE = 9,
T7_ASSET_TYPE_SOUND = 10,
T7_ASSET_TYPE_SOUND_PATCH = 11,
T7_ASSET_TYPE_COL_MAP = 12,
T7_ASSET_TYPE_COM_MAP = 13,
T7_ASSET_TYPE_GAME_MAP = 14,
T7_ASSET_TYPE_MAP_ENTS = 15,
T7_ASSET_TYPE_GFX_MAP = 16,
T7_ASSET_TYPE_LIGHTDEF = 17,
T7_ASSET_TYPE_LENSFLAREDEF = 18,
T7_ASSET_TYPE_UI_MAP = 19,
T7_ASSET_TYPE_FONT = 20,
T7_ASSET_TYPE_FONTICON = 21,
T7_ASSET_TYPE_LOCALIZE = 22,
T7_ASSET_TYPE_WEAPON = 23,
T7_ASSET_TYPE_WEAPONDEF = 24,
T7_ASSET_TYPE_WEAPONVARIANT = 25,
T7_ASSET_TYPE_WEAPONFULL = 26,
T7_ASSET_TYPE_CGMEDIATABLE = 27,
T7_ASSET_TYPE_PLAYERSOUNDSTABLE = 28,
T7_ASSET_TYPE_PLAYERFXTABLE = 29,
T7_ASSET_TYPE_SHAREDWEAPONSOUNDS = 30,
T7_ASSET_TYPE_ATTACHMENT = 31,
T7_ASSET_TYPE_ATTACHMENTUNIQUE = 32,
T7_ASSET_TYPE_WEAPONCAMO = 33,
T7_ASSET_TYPE_CUSTOMIZATIONTABLE = 34,
T7_ASSET_TYPE_CUSTOMIZATIONTABLE_FEIMAGES = 35,
T7_ASSET_TYPE_CUSTOMIZATIONTABLECOLOR = 36,
T7_ASSET_TYPE_SNDDRIVERGLOBALS = 37,
T7_ASSET_TYPE_FX = 38,
T7_ASSET_TYPE_TAGFX = 39,
T7_ASSET_TYPE_KLF = 40,
T7_ASSET_TYPE_IMPACTSFXTABLE = 41,
T7_ASSET_TYPE_IMPACTSOUNDSTABLE = 42,
T7_ASSET_TYPE_PLAYER_CHARACTER = 43,
T7_ASSET_TYPE_AITYPE = 44,
T7_ASSET_TYPE_CHARACTER = 45,
T7_ASSET_TYPE_XMODELALIAS = 46,
T7_ASSET_TYPE_RAWFILE = 47,
T7_ASSET_TYPE_STRINGTABLE = 48,
T7_ASSET_TYPE_STRUCTUREDTABLE = 49,
T7_ASSET_TYPE_LEADERBOARDDEF = 50,
T7_ASSET_TYPE_DDL = 51,
T7_ASSET_TYPE_GLASSES = 52,
T7_ASSET_TYPE_TEXTURELIST = 53,
T7_ASSET_TYPE_SCRIPTPARSETREE = 54,
T7_ASSET_TYPE_KEYVALUEPAIRS = 55,
T7_ASSET_TYPE_VEHICLE = 56,
T7_ASSET_TYPE_ADDON_MAP_ENTS = 57,
T7_ASSET_TYPE_TRACER = 58,
T7_ASSET_TYPE_SLUG = 59,
T7_ASSET_TYPE_SURFACEFXTABLE = 60,
T7_ASSET_TYPE_SURFACESOUNDDEF = 61,
T7_ASSET_TYPE_FOOTSTEPTABLE = 62,
T7_ASSET_TYPE_ENTITYFXIMPACTS = 63,
T7_ASSET_TYPE_ENTITYSOUNDIMPACTS = 64,
T7_ASSET_TYPE_ZBARRIER = 65,
T7_ASSET_TYPE_VEHICLEFXDEF = 66,
T7_ASSET_TYPE_VEHICLESOUNDDEF = 67,
T7_ASSET_TYPE_TYPEINFO = 68,
T7_ASSET_TYPE_SCRIPTBUNDLE = 69,
T7_ASSET_TYPE_SCRIPTBUNDLELIST = 70,
T7_ASSET_TYPE_RUMBLE = 71,
T7_ASSET_TYPE_BULLETPENETRATION = 72,
T7_ASSET_TYPE_LOCDMGTABLE = 73,
T7_ASSET_TYPE_AIMTABLE = 74,
T7_ASSET_TYPE_ANIMSELECTORTABLE = 75,
T7_ASSET_TYPE_ANIMMAPPINGTABLE = 76,
T7_ASSET_TYPE_ANIMSTATEMACHINE = 77,
T7_ASSET_TYPE_BEHAVIORTREE = 78,
T7_ASSET_TYPE_BEHAVIORSTATEMACHINE = 79,
T7_ASSET_TYPE_TTF = 80,
T7_ASSET_TYPE_SANIM = 81,
T7_ASSET_TYPE_LIGHTDESCRIPTION = 82,
T7_ASSET_TYPE_SHELLSHOCK = 83,
T7_ASSET_TYPE_XCAM = 84,
T7_ASSET_TYPE_BGCACHE = 85,
T7_ASSET_TYPE_TEXTURECOMBO = 86,
T7_ASSET_TYPE_FLAMETABLE = 87,
T7_ASSET_TYPE_BITFIELD = 88,
T7_ASSET_TYPE_ATTACHMENTCOSMETICVARIANT = 89,
T7_ASSET_TYPE_MAPTABLE = 90,
T7_ASSET_TYPE_MAPTABLELOADINGIMAGES = 91,
T7_ASSET_TYPE_MEDAL = 92,
T7_ASSET_TYPE_MEDALTABLE = 93,
T7_ASSET_TYPE_OBJECTIVE = 94,
T7_ASSET_TYPE_OBJECTIVELIST = 95,
T7_ASSET_TYPE_UMBRA_TOME = 96,
T7_ASSET_TYPE_NAVMESH = 97,
T7_ASSET_TYPE_NAVVOLUME = 98,
T7_ASSET_TYPE_BINARYHTML = 99,
T7_ASSET_TYPE_LASER = 100,
T7_ASSET_TYPE_BEAM = 101,
T7_ASSET_TYPE_STREAMERHINT = 102,
T7_ASSET_TYPE_STRING = 103,
T7_ASSET_TYPE_ASSETLIST = 104,
T7_ASSET_TYPE_REPORT = 105,
T7_ASSET_TYPE_DEPEND = 106,
};


}
Loading

0 comments on commit 62390d0

Please sign in to comment.