Skip to content

Instantly share code, notes, and snippets.

@y785
Created August 20, 2019 13:06
Show Gist options
  • Save y785/3f13026d33b5a7f0edab0bd60f4eed36 to your computer and use it in GitHub Desktop.
Save y785/3f13026d33b5a7f0edab0bd60f4eed36 to your computer and use it in GitHub Desktop.
v92 initresman hook for .img loading instead of .wz, addies not included -- just look in InitializeResMan for them
enum RESMAN_PARAM {
RC_AUTO_SERIALIZE = 0x1,
RC_AUTO_SERIALIZE_NO_CACHE = 0x2,
RC_NO_AUTO_SERIALIZE = 0x4,
RC_DEFAULT_AUTO_SERIALIZE = 0x0,
RC_AUTO_SERIALIZE_MASK = 0x7,
RC_AUTO_REPARSE = 0x10,
RC_NO_AUTO_REPARSE = 0x20,
RC_DEFAULT_AUTO_REPARSE = 0x0,
RC_AUTO_REPARSE_MASK = 0x30,
};
BOOL maple::custom::Hook_InitializeResMan(BOOL bEnable) {
maple::methods::CWvsApp__InitializeResMan_t Hook = [](void* ecx, void* edx, void* cwvsapp) -> void* {
auto g_rm = maple::methods::get_rm();
// Create Resource Manager Instance.
maple::methods::PcCreateObject_IWzResMan((void*)L"ResMan", g_rm);
void* pIWzResMan_Instance = maple::methods::_com_IWzResMan_arrow(g_rm, nullptr);
maple::methods::IWzResMan__SetResManParam(pIWzResMan_Instance, nullptr, RC_AUTO_REPARSE | RC_AUTO_SERIALIZE, -1, -1);
// Create NameSpace Instance.
auto g_root = maple::methods::get_root();
maple::methods::PcCreateObject_IWzNameSpace((void*)L"NameSpace", g_root);
void* pIWzNameSpace_Instance = maple::methods::_com_IWzNameSpace_deref(g_root, nullptr);
maple::methods::PcSetRootNameSpace(pIWzNameSpace_Instance); // maple::methods::PcSetRootNameSpace(*((void**)g_root));
// Create FileSystem Instance
int pIWzFileSystem;
void* com_iwfsp = maple::methods::_com_IWzFileSystem_ptr(&pIWzFileSystem, nullptr);
maple::methods::PcCreateObject_IWzFileSystem((void*)L"NameSpace#FileSystem", com_iwfsp);
// Initialize FileSystem
char sStartPath[MAX_PATH];
GetModuleFileNameA(NULL, sStartPath, MAX_PATH);
maple::methods::CWvsApp__Dir_BackSlashToSlash(sStartPath);
maple::methods::CWvsApp__Dir_upDir(sStartPath);
DEBUG("Path: %s", sStartPath);
maple::types::Ztl_bstr_t* p_bstr_data = new maple::types::Ztl_bstr_t();
maple::methods::ztl_bstr_constructor(p_bstr_data, nullptr, sStartPath);
void* pIWzFileSystem_Idek = maple::methods::_com_IWzFileSystem_arrow(&pIWzFileSystem, nullptr);
auto iahefauf = maple::methods::IWzFileSystem__Init(pIWzFileSystem_Idek, nullptr, *p_bstr_data);
// Mount time OwO
// bms does some checks, but who cares about that
void* ppRoot = maple::methods::_com_IWzNameSpace_arrow(g_root, nullptr); // *((void**)g_root)
maple::types::Ztl_bstr_t* p_bstr_path = new maple::types::Ztl_bstr_t();
void* p_down;
maple::methods::ztl_bstr_constructor(p_bstr_path, nullptr, (const char*)"/");
p_down = maple::methods::_com_IWzPackage_deref(&pIWzFileSystem, nullptr);
auto ajefgeaf = maple::methods::IWZNameSpace__Mount(ppRoot, nullptr, *p_bstr_path, p_down, 0);
// Create FileSystem Instance
int pDataFileSystem;
void* com_iwdsp = maple::methods::_com_IWzFileSystem_ptr(&pDataFileSystem, nullptr);
maple::methods::PcCreateObject_IWzFileSystem((void*)L"NameSpace#FileSystem", com_iwdsp);
maple::types::Ztl_bstr_t* pDataStr = new maple::types::Ztl_bstr_t();
maple::methods::ztl_bstr_constructor(pDataStr, nullptr, "./Data");
void* pDataArrow = maple::methods::_com_IWzFileSystem_arrow(&pDataFileSystem, nullptr);
auto fsinitret = maple::methods::IWzFileSystem__Init(pDataArrow, nullptr, *pDataStr);
p_down = maple::methods::_com_IWzPackage_deref(&pDataFileSystem, nullptr);
p_bstr_path = new maple::types::Ztl_bstr_t();
maple::methods::ztl_bstr_constructor(p_bstr_path, nullptr, (const char*)"/");
ppRoot = maple::methods::_com_IWzNameSpace_arrow(maple::methods::get_root(), nullptr); // *((void**)g_root)
auto ejhafaf = maple::methods::IWZNameSpace__Mount(ppRoot, nullptr, *p_bstr_path, p_down, 0);
return (void*)0;
};
return Asm::Detour(reinterpret_cast<void**>(&maple::methods::CWvsApp__InitializeResMan), Hook, bEnable);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment