From 3c3e1c46dfcf8190b6b2e137191d83906fdc4fe0 Mon Sep 17 00:00:00 2001 From: rexx <67599507+r-ex@users.noreply.github.com> Date: Thu, 22 Dec 2022 21:44:38 +0000 Subject: [PATCH] Add pak_listtypes command --- r5dev/public/utility/utility.cpp | 12 ++++++++++++ r5dev/public/utility/utility.h | 2 ++ r5dev/tier1/cmd.cpp | 1 + r5dev/vstdlib/callback.cpp | 28 ++++++++++++++++++++++++++++ r5dev/vstdlib/callback.h | 1 + 5 files changed, 44 insertions(+) diff --git a/r5dev/public/utility/utility.cpp b/r5dev/public/utility/utility.cpp index 318245c4..2c2bad8e 100644 --- a/r5dev/public/utility/utility.cpp +++ b/r5dev/public/utility/utility.cpp @@ -847,6 +847,18 @@ pair, string> StringToMaskedBytes(const string& svInput, bool bN return make_pair(vBytes, svMask); }; +/////////////////////////////////////////////////////////////////////////////// +// For converting a 32-bit integer into a 4-char ascii string +string FourCCToString(int n) +{ + stringstream ss; + ss << (char)((n & 0x000000ff) >> 0); + ss << (char)((n & 0x0000ff00) >> 8); + ss << (char)((n & 0x00ff0000) >> 16); + ss << (char)((n & 0xff000000) >> 24); + return ss.str(); +}; + /////////////////////////////////////////////////////////////////////////////// // For converting a string pattern with wildcards to an array of bytes. vector PatternToBytes(const string& svInput) diff --git a/r5dev/public/utility/utility.h b/r5dev/public/utility/utility.h index bc45e67d..ea8a6de3 100644 --- a/r5dev/public/utility/utility.h +++ b/r5dev/public/utility/utility.h @@ -57,6 +57,8 @@ string& StringLTrim(string& svInput, const char* pszToTrim, bool bTrimBefore = f string& StringRTrim(string& svInput, const char* pszToTrim, bool bTrimAfter = false); string& StringTrim(string& svInput, const char* pszToTrim, bool bTrimAll = false); +string FourCCToString(int n); + ///////////////////////////////////////////////////////////////////////////// // Bytes vector StringToBytes(const string& svInput, bool bNullTerminator); diff --git a/r5dev/tier1/cmd.cpp b/r5dev/tier1/cmd.cpp index 56590488..7248a24f 100644 --- a/r5dev/tier1/cmd.cpp +++ b/r5dev/tier1/cmd.cpp @@ -378,6 +378,7 @@ void ConCommand::Init(void) ConCommand::Create("pak_requestunload", "Requests unload for specified RPAK file or ID.", FCVAR_DEVELOPMENTONLY, Pak_RequestUnload_f, nullptr); ConCommand::Create("pak_swap", "Requests swap for specified RPAK file or ID", FCVAR_DEVELOPMENTONLY, Pak_Swap_f, nullptr); ConCommand::Create("pak_listpaks", "Display a list of the loaded Pak files.", FCVAR_RELEASE, Pak_ListPaks_f, nullptr); + ConCommand::Create("pak_listtypes", "Display a list of the registered asset types.", FCVAR_RELEASE, Pak_ListTypes_f, nullptr); //------------------------------------------------------------------------- // NETCHANNEL | ConCommand::Create("net_setkey", "Sets user specified base64 net key.", FCVAR_RELEASE, NET_SetKey_f, nullptr); diff --git a/r5dev/vstdlib/callback.cpp b/r5dev/vstdlib/callback.cpp index c1298d82..d77c3b8b 100644 --- a/r5dev/vstdlib/callback.cpp +++ b/r5dev/vstdlib/callback.cpp @@ -275,6 +275,34 @@ void Pak_ListPaks_f(const CCommand& args) DevMsg(eDLL_T::RTECH, "|------|----------------------------------------------------|--------------------------------------|-------------|\n"); } +/* +===================== +Pak_ListTypes_f +===================== +*/ +void Pak_ListTypes_f(const CCommand& args) +{ + DevMsg(eDLL_T::RTECH, "| ext | description | version | header size | native size |\n"); + DevMsg(eDLL_T::RTECH, "|------|---------------------------|---------|-------------|-------------|\n"); + + uint32_t nRegistered = 0; + + for (int8_t i = 0; i < 64; ++i) + { + RPakAssetBinding_t* type = &g_pUnknownPakStruct->m_nAssetBindings[i]; + + if (!type->m_szDescription) + continue; + + // todo: make status into a string from an array/vector + DevMsg(eDLL_T::RTECH, "| %-4s | %-25s | %7i | %11i | %11i |\n", FourCCToString(type->m_nExtension).c_str(), type->m_szDescription, type->m_iVersion, type->m_iSubHeaderSize, type->m_iNativeClassSize); + nRegistered++; + } + DevMsg(eDLL_T::RTECH, "|------|---------------------------|---------|-------------|-------------|\n"); + DevMsg(eDLL_T::RTECH, "| %18i registered types. |\n", nRegistered); + DevMsg(eDLL_T::RTECH, "|------|---------------------------|---------|-------------|-------------|\n"); +} + /* ===================== Pak_RequestUnload_f diff --git a/r5dev/vstdlib/callback.h b/r5dev/vstdlib/callback.h index 5c00506c..715b42b6 100644 --- a/r5dev/vstdlib/callback.h +++ b/r5dev/vstdlib/callback.h @@ -27,6 +27,7 @@ void Host_Changelevel_f(const CCommand& args); void Detour_HotSwap_f(const CCommand& args); #endif // !CLIENT_DLL void Pak_ListPaks_f(const CCommand& args); +void Pak_ListTypes_f(const CCommand& args); void Pak_RequestUnload_f(const CCommand& args); void Pak_RequestLoad_f(const CCommand& args); void Pak_Swap_f(const CCommand& args);