forked from igroglaz/a2mgr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_control.cpp
194 lines (160 loc) · 3.46 KB
/
resource_control.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include <windows.h>
#include <stdint.h>
#include "utils.h"
char aPatchC[] = "data\\patch\\";
char aDataC[] = "data\\";
char aLocale_res[] = "locale.res";
bool _stdcall TestMap(const char* file) // if this returns true, the file's path is unchanged for loading
{
std::string filename = TruncateSlashes(FixSlashes(ToLower(file)));
if ((filename.find("graphics/") == 0) ||
(filename.find("locale/") == 0) ||
(filename.find("main/") == 0) ||
(filename.find("movies/") == 0) ||
(filename.find("music/") == 0) ||
(filename.find("patch/") == 0) ||
(filename.find("scenario/") == 0) ||
(filename.find("sfx/") == 0) ||
(filename.find("speech/") == 0) ||
(filename.find("video/") == 0) ||
(filename.find("world/") == 0))
return false;
return true;
}
int __declspec(naked) RES_loadFile(int x)
/* èçìåíåííàÿ ïðîöåäóðà çàãðóçêè ðåñóðñîâ;
* ñíà÷àëà ïûòàåìñÿ çàãðóçèòü ôàéë èç patch11.res
* ïîòîì èç a25graph.res, åñëè îí ïîäãðóæåí,
* ïîñëå èç îðèãèíàëüíîãî ðåñóðñà */
// ZZYZX EDIT: a25graph.res íå èñïîëüçóåòñÿ.
{
__asm
{ // 004EBEDA
call sub_4EB99D
mov [ebp-0x814], eax
cmp eax, 0
jz loc_4EBF9B
mov edx, 0x004EBEEE
jmp edx
loc_4EBF9B:
mov edx, 0x004EBF9B
jmp edx
sub_4EB99D:
push ebp
mov ebp, esp
sub esp, 8
mov [ebp-4], ecx
push [ebp+8]
call TestMap
and eax, 0xFF
test eax, eax
jnz regular_load
push 0x200
mov edx, 0x0058CA80
call edx /// malloc
add esp, 4
mov [ebp-8], eax
push offset aPatchC
push [ebp-8]
mov edx, 0x0058CDF0
call edx // strcpy
add esp, 8
push dword ptr [ebp+8]
push dword ptr [ebp-8]
mov edx, 0x0058CE00 // strcat
call edx
add esp, 8
push dword ptr [ebp-8]
mov ecx, [ebp-4]
mov edx, 0x004EB99D
call edx
test eax, eax
jnz en
// concat with data
push offset aDataC
push [ebp-8]
mov edx, 0x0058CDF0
call edx // strcpy
add esp, 8
push dword ptr [ebp+8]
push dword ptr [ebp-8]
mov edx, 0x0058CE00 // strcat
call edx
add esp, 8
push dword ptr [ebp-8]
mov ecx, [ebp-4]
mov edx, 0x004EB99D
call edx
jmp en
regular_load:
push dword ptr [ebp+8]
mov ecx, [ebp-4]
mov edx, 0x004EB99D
call edx
jmp en_nofree
en:
mov [ebp-4], eax
push dword ptr [ebp-8]
mov edx, 0x0058CB50
call edx /// free
add esp, 4
mov eax, [ebp-4]
en_nofree:
mov esp, ebp
pop ebp
retn 4
loc_retzero:
mov eax, 0
mov esp, ebp
pop ebp
retn 4
}
}
void __declspec(naked) RES_loadException()
{ // 004EB723
__asm
{
mov edx, 0x004EB72E
jmp edx
}
}
void _stdcall CheckMusic()
{
// check if data/music directory exists
// if not, disable music
uint32_t dwAttrib = GetFileAttributes("data\\music");
bool exists = (dwAttrib != INVALID_FILE_ATTRIBUTES &&
(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
if (!exists)
*(uint32_t*)(0x0062C870) = 0; // disable music
}
void __declspec(naked) RES_loadDirectories()
{ // 004867E6
__asm
{
push offset aLocale_res
mov edx, 0x004EB741
call edx
add esp, 4
mov byte ptr [ebp-0x04], 4
push 0x005FD168 // offset aMusic_res; "music.res"
mov edx, 0x004EB741
call edx
add esp, 4
call CheckMusic
mov edx, 0x0048681A
jmp edx
}
}
void __declspec(naked) RES_noLoad()
{
__asm
{ // 4EB741
push ebp
mov ebp, esp
// do nothing
mov esp, ebp
pop ebp
retn
}
}