Skip to content

Commit d59be3f

Browse files
authored
Update Resman.cpp with a production server code
1 parent e9d7a28 commit d59be3f

1 file changed

Lines changed: 50 additions & 154 deletions

File tree

CIL/Resman.cpp

Lines changed: 50 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -12,182 +12,78 @@ enum RESMAN_PARAM {
1212
RC_AUTO_REPARSE_MASK = 0x30,
1313
};
1414

15-
struct CWvsApp
16-
{
17-
/*Nothing for now*/
18-
};
19-
20-
struct Ztl_bstr_t
21-
{
22-
struct DATA
23-
{
24-
wchar_t *m_wstr;
25-
char *m_str;
26-
unsigned int m_RefCount;
27-
};
28-
29-
Ztl_bstr_t::DATA* m_Data;
30-
};
31-
32-
struct _com_ptr_t {
33-
void *m_pInterface;
34-
};
35-
36-
// Data Type
37-
typedef void(__fastcall* CWvsApp__InitializeResMan_t)(CWvsApp* ecx, void* edx);
38-
typedef void(__cdecl* PcCreateObject_IWzResMan_t)(void *, void *);
39-
typedef HRESULT(__fastcall* IWzResMan__SetResManParam_t)(void *, void *, int a, int b, int c);
40-
typedef void(__cdecl* PcCreateObject_IWzNameSpace_t)(void *, void *);
41-
typedef HRESULT(__cdecl* PcSetRootNameSpace_t)(void *);
42-
typedef HRESULT(__fastcall* IWZNameSpace__Mount_t)(void *, void *, Ztl_bstr_t, void *, int a);
43-
typedef void(__cdecl* PcCreateObject_IWzFileSystem_t)(void *, void *);
44-
typedef void(__cdecl* ztl_bstr_constructor_t)(void *, void *, const char *);
45-
typedef HRESULT(__fastcall* IWzFileSystem__Init_t)(void *, void *, Ztl_bstr_t);
46-
typedef void*(__fastcall* _com_IWzFileSystem_ptr_t)(void *, void *);
47-
typedef void*(__fastcall* _com_IWzResMan_arrow_t)(void *, void *);
48-
typedef void*(__fastcall* _com_IWzNameSpace_arrow_t)(void *, void *);
49-
typedef void*(__fastcall* _com_IWzFileSystem_arrow_t)(void *, void *);
50-
typedef void*(__fastcall* _com_IWzNameSpace_deref_t)(void *, void *);
51-
typedef void*(__fastcall* _com_IWzPackage_deref_t)(void *, void *);
52-
53-
// DWORD
54-
DWORD g_rm = 0x00000000;
55-
DWORD g_root = 0x00000000;
56-
57-
// ResMan
58-
auto PcCreateObject_IWzResMan = reinterpret_cast<PcCreateObject_IWzResMan_t>(0x00000000);
59-
auto IWzResMan__SetResManParam = reinterpret_cast<IWzResMan__SetResManParam_t>(0x00000000);
60-
61-
// NameSpace
62-
auto PcCreateObject_IWzNameSpace = reinterpret_cast<PcCreateObject_IWzNameSpace_t>(0x00000000);
63-
auto PcSetRootNameSpace = reinterpret_cast<PcSetRootNameSpace_t>(0x00000000);
64-
auto IWZNameSpace__Mount = reinterpret_cast<IWZNameSpace__Mount_t>(0x00000000);
65-
66-
// FileSystem
67-
auto PcCreateObject_IWzFileSystem = reinterpret_cast<PcCreateObject_IWzFileSystem_t>(0x00000000);
68-
auto ztl_bstr_constructor = reinterpret_cast<ztl_bstr_constructor_t>(0x00000000);
69-
auto IWzFileSystem__Init = reinterpret_cast<IWzFileSystem__Init_t>(0x00000000);
70-
71-
// Pointers
72-
auto _com_IWzFileSystem_ptr = reinterpret_cast<_com_IWzFileSystem_ptr_t>(0x00000000);
73-
auto _com_IWzResMan_arrow = reinterpret_cast<_com_IWzResMan_arrow_t>(0x00000000);
74-
auto _com_IWzNameSpace_arrow = reinterpret_cast<_com_IWzNameSpace_arrow_t>(0x00000000);
75-
auto _com_IWzFileSystem_arrow = reinterpret_cast<_com_IWzFileSystem_arrow_t>(0x00000000);
76-
auto _com_IWzNameSpace_deref = reinterpret_cast<_com_IWzNameSpace_deref_t>(0x00000000);
77-
auto _com_IWzPackage_deref = reinterpret_cast<_com_IWzPackage_deref_t>(0x00000000);
78-
79-
// Hard Coded Functions
80-
void* __cdecl get_rm()
81-
{
82-
return *((void**)g_rm);
83-
}
84-
85-
void* __cdecl get_root()
86-
{
87-
return *((void**)g_root);
88-
}
89-
90-
void __cdecl CWvsApp__Dir_upDir(char *sDir)
91-
{
92-
size_t v1 = strlen(sDir);
93-
94-
if (v1 > 0 && sDir[v1 - 1] == '/')
95-
sDir[v1 - 1] = 0;
96-
97-
size_t v2 = strlen(sDir) - 1;
98-
99-
if (v2 > 0)
100-
{
101-
while (sDir[v2] != '/')
102-
{
103-
if (--v2 <= 0)
104-
return;
105-
}
106-
107-
sDir[v2] = 0;
108-
}
109-
}
110-
111-
void __cdecl CWvsApp__Dir_BackSlashToSlash(char *sDir)
112-
{
113-
size_t v1 = strlen(sDir);
114-
115-
for (int i = 0; i < v1; ++i)
116-
{
117-
if (sDir[i] == '\\')
118-
sDir[i] = '/';
119-
}
120-
}
121-
15+
typedef void(__fastcall* CWvsApp__InitializeResMan_t)(void*);
16+
17+
// Function Address
18+
auto CWvsApp__InitializeResMan = reinterpret_cast<CWvsApp__InitializeResMan_t>(0x000000);
19+
auto PcCreateObject_IWzResMan = (void(__cdecl*)(void*, void*, void*))0x000000;
20+
auto PcCreateObject_IWzNameSpace = (void(__cdecl*)(void*, void*, void*))0x000000;
21+
auto PcCreateObject_IWzFileSystem = (void(__cdecl*)(void*, void*, void*))0x000000;
22+
auto CWvsApp__Dir_BackSlashToSlash = (void(__cdecl*)(void*))0x000000;
23+
auto CWvsApp__Dir_upDir = (void(__cdecl*)(void*))0x000000;
24+
auto bstr_constructor = (void(__fastcall*)(void*, void*, void*))0x000000;
25+
auto IWzFileSystem__Init = (void*(__fastcall*)(void*, void*, void*))0x000000;
26+
auto IWZNameSpace__Mount = (void*(__fastcall*)(void*, void*, void*, void*, void*))0x000000;
27+
28+
// DWORD Address
29+
auto g_rm = (void**)0x000000;
30+
auto g_root = (void**)0x000000;
31+
auto pNameSpace = (int*)0x000000;
32+
33+
#pragma optimize("", off)
12234
BOOL Hook_InitializeResMan(BOOL bEnable) {
12335

124-
// Init
125-
static auto CWvsApp__InitializeResMan = reinterpret_cast<CWvsApp__InitializeResMan_t>(0x00000000);
36+
CWvsApp__InitializeResMan_t Hook = [](void*) {
12637

127-
CWvsApp__InitializeResMan_t Hook = [](CWvsApp* ecx, void* edx) -> void {
38+
// Generic
39+
void* pFileSystem = nullptr;
40+
void* pUnkOuter = 0;
41+
void* nPriority = 0;
42+
void* sPath;
43+
void* base = "./Data";
12844

129-
auto g_rm = get_rm();
45+
// Resman
46+
PcCreateObject_IWzResMan(L"ResMan", g_rm, pUnkOuter);
13047

131-
// Create Resource Manager Instance.
132-
PcCreateObject_IWzResMan((void*)L"ResMan", g_rm);
48+
void* pIWzResMan_Instance = *g_rm;
49+
auto IWzResMan__SetResManParam = *(void(__cdecl**)(void*, int, int, int))((*(int*)pIWzResMan_Instance) + 20);
50+
IWzResMan__SetResManParam(pIWzResMan_Instance, RC_AUTO_REPARSE | RC_AUTO_SERIALIZE, -1, -1);
13351

134-
void* pIWzResMan_Instance = _com_IWzResMan_arrow(g_rm, nullptr);
135-
IWzResMan__SetResManParam(pIWzResMan_Instance, nullptr, RC_AUTO_REPARSE | RC_AUTO_SERIALIZE, -1, -1);
52+
// NameSpace
53+
PcCreateObject_IWzNameSpace(L"NameSpace", g_root, pUnkOuter);
13654

137-
// Create NameSpace Instance.
138-
auto g_root = get_root();
139-
PcCreateObject_IWzNameSpace((void*)L"NameSpace", g_root);
55+
void* pIWzNameSpace_Instance = g_root;
56+
auto PcSetRootNameSpace = (void(__cdecl*)(void*, int))*pNameSpace;
57+
PcSetRootNameSpace(pIWzNameSpace_Instance, 1);
14058

141-
void* pIWzNameSpace_Instance = _com_IWzNameSpace_deref(g_root, nullptr);
142-
PcSetRootNameSpace(pIWzNameSpace_Instance); // PcSetRootNameSpace(*((void**)g_root))
59+
// Game FileSystem
60+
PcCreateObject_IWzFileSystem(L"NameSpace#FileSystem", &pFileSystem, pUnkOuter);
14361

144-
// Initialize FileSystem
145-
int pIWzFileSystem;
146-
void* com_iwfsp = _com_IWzFileSystem_ptr(&pIWzFileSystem, nullptr);
147-
PcCreateObject_IWzFileSystem((void*)L"NameSpace#FileSystem", com_iwfsp);
14862
char sStartPath[MAX_PATH];
14963
GetModuleFileNameA(NULL, sStartPath, MAX_PATH);
15064
CWvsApp__Dir_BackSlashToSlash(sStartPath);
15165
CWvsApp__Dir_upDir(sStartPath);
15266

153-
printf("Path: %s\n", sStartPath);
154-
155-
Ztl_bstr_t* p_bstr_data = new Ztl_bstr_t();
156-
ztl_bstr_constructor(p_bstr_data, nullptr, sStartPath);
67+
bstr_constructor(&sPath, nullptr, sStartPath);
15768

158-
void* pIWzFileSystem_Idek = _com_IWzFileSystem_arrow(&pIWzFileSystem, nullptr);
159-
auto iahefauf = IWzFileSystem__Init(pIWzFileSystem_Idek, nullptr, *p_bstr_data);
69+
auto a = IWzFileSystem__Init(pFileSystem, nullptr, sPath);
16070

161-
// Mount time OwO
162-
// bms does some checks, but who cares about that
163-
void* ppRoot = _com_IWzNameSpace_arrow(g_root, nullptr); // *((void**)g_root)
164-
Ztl_bstr_t* p_bstr_path = new Ztl_bstr_t();
165-
void* p_down;
71+
bstr_constructor(&sPath, nullptr, "/");
16672

167-
ztl_bstr_constructor(p_bstr_path, nullptr, (const char*)"/");
168-
p_down = _com_IWzPackage_deref(&pIWzFileSystem, nullptr);
73+
auto b = IWZNameSpace__Mount(*g_root, nullptr, sPath, pFileSystem, nPriority);
16974

170-
auto ajefgeaf = IWZNameSpace__Mount(ppRoot, nullptr, *p_bstr_path, p_down, 0);
75+
// Data FileSystem
76+
PcCreateObject_IWzFileSystem(L"NameSpace#FileSystem", &pFileSystem, pUnkOuter);
17177

172-
// Create FileSystem Instance
173-
int pDataFileSystem;
174-
void* com_iwdsp = _com_IWzFileSystem_ptr(&pDataFileSystem, nullptr);
175-
PcCreateObject_IWzFileSystem((void*)L"NameSpace#FileSystem", com_iwdsp);
78+
bstr_constructor(&sPath, nullptr, base);
17679

177-
Ztl_bstr_t* pDataStr = new Ztl_bstr_t();
178-
ztl_bstr_constructor(pDataStr, nullptr, "./Data");
80+
auto c = IWzFileSystem__Init(pFileSystem, nullptr, sPath);
17981

180-
void* pDataArrow = _com_IWzFileSystem_arrow(&pDataFileSystem, nullptr);
181-
auto fsinitret = IWzFileSystem__Init(pDataArrow, nullptr, *pDataStr);
182-
183-
p_down = _com_IWzPackage_deref(&pDataFileSystem, nullptr);
184-
p_bstr_path = new Ztl_bstr_t();
185-
ztl_bstr_constructor(p_bstr_path, nullptr, (const char*)"/");
186-
ppRoot = _com_IWzNameSpace_arrow(get_root(), nullptr); // *((void**)g_root)
187-
auto ejhafaf = IWZNameSpace__Mount(ppRoot, nullptr, *p_bstr_path, p_down, 0);
82+
bstr_constructor(&sPath, nullptr, "/");
18883

84+
auto d = IWZNameSpace__Mount(*g_root, nullptr, sPath, pFileSystem, nPriority);
18985
};
19086

191-
19287
return SetHook(bEnable, reinterpret_cast<void**>(&CWvsApp__InitializeResMan), Hook);
193-
}
88+
}
89+
#pragma optimize("", on)

0 commit comments

Comments
 (0)