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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
/*
QDPlugin.h
The central hive of the MPQDraft plugin system.
In addition to the standard MPQ "adding" functionality of MPQDraft,
MPQDraft also supports a powerful plugin system to acommodate addition
methods of patching. These plugins are specially constructed DLLs which
1) Export the GetMPQDraftPlugin function, and 2) Impliment the
IMPQDraftPlugin interface. Up to 8 plugins may be loaded in one patching
session (although 8 is a rather arbitrary number, and may be changed in
later versions, if there is reason to do so).
- PLUGIN MODULES -
MPQDraft supports the creation of completely self-contained SEMPQs. But,
this ability creates a palette of problems all its own. All of a plugin's
data files have to be packed into the SEMPQ. This means that a special
mechanism is needed, to marshall the data files from the plugin to the
SEMPQ, and back to the plugin; this is the plugin module system. Each data
file of the plugin is referred to as a "module", and identified by
a pair of DWORDs: a plugin ID, and a module ID. The plugin ID is the
globally unique ID of the plugin; the module ID is the plugin-specific ID
of the module.
[FURTHER TEXT TO BE ADDED HERE]
- SETUP SIDE -
There are two halves to each plugin: a setup side and a patching side. The
setup side is when the plugin gets loaded in MPQDraft, and displayed in
the plugin list, in either the patching wizard or SEMPQ wizard.
Specifically, MPQDraft loads all plugins when the plugins page in the
wizard first gets activated. The plugins will remain loaded until the
wizard is closed. If a patch is performed, the plugins will remain loaded
until the patch is completed. This allows plugins to get the opportunity
to delete any temporary files that were created for the patch.
Order and timing of calls to setup-side plugin functions:
When the plugins wizard page is first activated, and MPQDraft is building
its plugin database:
1. The plugin gets loaded with LoadLibrary.
2. The plugin's GetMPQDraftPlugin function gets called to obtain the
plugin's IMPQDraftPlugin interface.
3. IMPQDraftPlugin::Identify gets called.
4. IMPQDraftPlugin::GetPluginName gets called.
Each time the plugins page is switched to, MPQDraft determines which
plugins to display in the plugin list:
- IMPQDraftPlugin::CanPatchExecutable gets called for the currently
selected executable. If the plugin can patch the executable, it will
appear in the plugin list if it can't, then it won't appear. NOTE: this
step does not occur when selecting plugins for use in an SEMPQ. In this
case, ALL plugins will be available to select.
If the "Configure" button is clicked while a plugin is selected:
- IMPQDraftPlugin::Configure is called, with the HWND to the wizard in
use. This allows the plugin to create a modal dialog with various plugin
settings.
If the "Finish" button is clicked to initiate a patch:
1. IMPQDraftPlugin::ReadyForPatch is called to discern whether the plugin
is properly configured, and ready to perform the patch.
2. IMPQDraftPlugin::GetModules is called to obtain the number of plugin
modules the plugin will require.
3. IMPQDraftPlugin::GetModule is called again to get the plugin's modules.
Either after the patch is completed or the wizard is cancelled:
- FreeLibrary is called to unload the plugin. The plugin is responsible
for cleaning up any data files it created temporarily.
NOTE: Plugins will not be loaded in setup-side when an SEMPQ is executed.
- PATCHING SIDE -
The patching side is when a plugin gets loaded by the MPQDraft patching
kernel. The plugin will be loaded inside the patchee (the process being
patched) BEFORE any patchee code gets executed, but after any DLLs the
patchee uses are loaded and initialized (DllMain is called). This means
that plugins will be able to modify initialized data in the patchee, but
not uninitialized data. If the latter is necessary, a thread can be
spawned by the plugin to wait until the data has been initialized.
Order and timing of calls to patching-side plugin functions:
After MPQDraft performs its own initializations, it will load each
selected plugin (this is done before any MPQs are loaded):
1. LoadLibrary gets called to load the plugin inside the patch target.
2. GetMPQDraftPlugin gets called to obtain an IMPQDraftPlugin interface.
3. IMPQDraftPlugin::InitializePlugin gets called with a pointer to the
MPQDraft server interface, to allow the plugin to locate its data files.
When the patchee is closing down, and MPQDraft is terminating:
1. IMPQDraftPlugin::TerminatePlugin gets called to remove any patches the
plugin performed.
2. The plugin is unloaded with FreeLibrary.
*/
// The maximum length of a plugin module's filename. INCLUDES final NULL.
// The maximum length of a plugin's name. INCLUDES final NULL.
/*
MPQDRAFTPLUGINMODULE
Structure used by IMPQDraftPlugin::GetModules to notify MPQDraft of any
files (called plugin modules) that are to be loaded. Read description of
that function for more information.
*/
;
/*
IMPQDraftServer
Serves as a portal back to MPQDraft, allowing the plugin to
not only be executed by MPQDraft, but also it communicate with MPQDraft.
A plugin will be given an IMPQDraftServer pointer when MPQDraft calls
IMPQDraftPlugin::InitializePlugin.
*/
;
/*
IMPQDraftPlugin
The primary gateway between the MPQDraft patching kernel and the plugin.
This interface must be fully implimented by every MPQDraft plugin (or at
least until it is superseded by IMPQDraftPlugin2, in a much later version
of MPQDraft). MPQDraft will obtain this interface when it calls
GetMPQDraftPlugin. It will then store the interface in its plugin
database, and use it in all subsequent calls to the plugin.
NOTE: The specifications for this interface are based on the recommended
responses. In some places it may be legal to slightly depart from the
recommended specs (i.e. functions may fail instead of asserting).
*/
;
/*
GetMPQDraftPlugin
Exported by name from the plugin DLL. Called by MPQDraft to obtain the
IMPQDraftPlugin interface of the plugin.
Returns TRUE on success, and FALSE on failure.
Parameters:
lppMPQDraftPlugin [out] - A pointer to a pointer that will hold the
IMPQDraftPlugin. The plugin must set this to point to the plugin's
IMPQDraftPlugin interface.
Behavior:
- GetMPQDraftPlugin will only be called once, so it isn't necessary
to instantiate an IMPQDraftPlugin for each call. A single global
IMPQDraftPlugin is sufficient.
*/
BOOL WINAPI ;
// #ifndef QDPLUGIN_H