Skip to content

Commit

Permalink
random things
Browse files Browse the repository at this point in the history
  • Loading branch information
ate47 committed Dec 13, 2023
1 parent d405a24 commit beb4870
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/bo4-dll/data/error_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ std::unordered_map<UINT64, LPCCH> error_handler::errors = {
{ 2855209542, "Cannot call IncrementClientField on a non-'counter' type clientfield." },
{ 4220857104, "Cannot call IncrementClientField on a 'counter' type clientfield on the frame it is spawned, since newEnts on the clientside will not process 'counter' type clientfields." },
{ 359760836, "G_Spawn: no free entities." },
{ 2082640650, "Stream_GetNextFileID: Too many open files (128)" }

// messages handled by detours
{ 2737681163, "assert fail (with message)" },
Expand Down
25 changes: 25 additions & 0 deletions src/bo4-dll/data/files_dump.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <dll_includes.hpp>


#ifdef DEBUG

void* __fastcall Lua_CoD_GetRawFile(const char* filename);
void* __fastcall R_RegisterFont(const char* filename);

static inject::DetourInfo<void*, const char*> dLua_CoD_GetRawFile{ "Lua_CoD_GetRawFile", 0x390FBB0, Lua_CoD_GetRawFile };
static inject::DetourInfo<void*, const char*> dR_RegisterFont{ "R_RegisterFont", 0x35B22A0, R_RegisterFont };

void* __fastcall Lua_CoD_GetRawFile(const char* filename) {
if (strncmp(filename, "x64:", 4)) {
LOG_DEBUG("LUA_FILE: %s", filename);
}

return dLua_CoD_GetRawFile(filename);
}
void* __fastcall R_RegisterFont(const char* filename) {
LOG_DEBUG("TTF: %s", filename);

return dR_RegisterFont(filename);
}

#endif
15 changes: 12 additions & 3 deletions src/cli/hashutils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ namespace hashutils {
*/
LPCH ExtractTmp(LPCCH type, UINT64 hash);
/*
* Call ExtractTmp for a script name and apply formatting
* Call ExtractTmp for a path name and apply formatting
* @param type Hash type
* @param hash Script hash
* @return script formatted value, same condition as ExtractTmp
*/
inline LPCH ExtractTmpScript(UINT64 hash) {
LPCH unhash = ExtractTmp("script", hash);
inline LPCH ExtractTmpPath(LPCCH type, UINT64 hash) {
LPCH unhash = ExtractTmp(type, hash);

// replace '/' -> '\' in script
for (LPCH script = unhash; *script; script++) {
Expand All @@ -71,6 +72,14 @@ namespace hashutils {

return unhash;
}
/*
* Call ExtractTmp for a script name and apply formatting
* @param hash Script hash
* @return script formatted value, same condition as ExtractTmp
*/
inline LPCH ExtractTmpScript(UINT64 hash) {
return ExtractTmpPath("script", hash);
}
/*
* Extract a pointer to a hash value
* @param hash Hashed value
Expand Down
50 changes: 50 additions & 0 deletions src/cli/tools/pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ struct RawString {
uintptr_t padding; // 0x10 0
uintptr_t stringvalue; // 0x18 const char*
};
struct LuaFile {
UINT64 name;
UINT64 pad08;
UINT32 size;
uintptr_t buffer;
};
struct DDLEntry {
UINT64 name; // 0x8
uintptr_t unk8; // 0x10
Expand Down Expand Up @@ -477,6 +483,50 @@ int pooltool(const Process& proc, int argc, const char* argv[]) {
std::cout << "Dump into " << file << "\n";
}
break;
case ASSET_TYPE_LUAFILE:
{
hashutils::ReadDefaultFile();

auto pool = std::make_unique<LuaFile[]>(entry.itemAllocCount);

sprintf_s(outputName, "%s/luapool", opt.m_output);

std::filesystem::path outDir{ outputName };

std::filesystem::create_directories(outDir);

if (!proc.ReadMemory(&pool[0], entry.pool, sizeof(pool[0]) * entry.itemAllocCount)) {
std::cerr << "Can't read pool data\n";
return tool::BASIC_ERROR;
}

for (size_t i = 0; i < entry.itemAllocCount; i++) {
const auto& p = pool[i];

auto name = hashutils::ExtractPtr(p.name);

std::filesystem::path outFile;
if (name) {
outFile = outDir / name;
std::filesystem::create_directories(outFile.parent_path());
}
else {
outFile = outDir / std::format("hashed/{:x}.lua", p.name);
}
{
auto buffer = std::make_unique<BYTE[]>(p.size);

if (!proc.ReadMemory(&buffer[0], p.buffer, p.size)) {
std::cerr << "Can't read buffer for " << outFile.string() << "\n";
continue;
}

utils::WriteFile(outFile, &buffer[0], p.size);
std::cout << "Dumped " << outFile.string() << "\n";
}
}
}
break;
case ASSET_TYPE_RAWFILE:
{

Expand Down

0 comments on commit beb4870

Please sign in to comment.