1 | #include "bink-proxy.h"
|
---|
2 |
|
---|
3 | #include <windows.h>
|
---|
4 | #include "Daodan_Utility.h"
|
---|
5 |
|
---|
6 |
|
---|
7 | static HMODULE realbink = 0;
|
---|
8 |
|
---|
9 | typedef void (__stdcall *BINKBUFFERBLIT) (void* buf, void* rects, uint32_t numrects);
|
---|
10 | typedef void (__stdcall *BINKBUFFERCLOSE) (void* buf);
|
---|
11 | typedef int32_t (__stdcall *BINKBUFFERLOCK) (void* buf);
|
---|
12 | typedef void* (__stdcall *BINKBUFFEROPEN) (void* wnd, uint32_t width, uint32_t height, uint32_t bufferflags);
|
---|
13 | typedef int32_t (__stdcall *BINKBUFFERSETOFFSET) (void* buf, int32_t destx, int32_t desty);
|
---|
14 | typedef int32_t (__stdcall *BINKBUFFERUNLOCK) (void* buf);
|
---|
15 | typedef void (__stdcall *BINKCLOSE) (void* bnk);
|
---|
16 | typedef int32_t (__stdcall *BINKCOPYTOBUFFER) (void* bnk, void* dest, int32_t destpitch, uint32_t destheight, uint32_t destx, uint32_t desty, uint32_t flags);
|
---|
17 | typedef int32_t (__stdcall *BINKDOFRAME) (void* bnk);
|
---|
18 | typedef int32_t (__stdcall *BINKGETRECTS) (void* bnk, uint32_t flags);
|
---|
19 | typedef void (__stdcall *BINKNEXTFRAME) (void* bnk);
|
---|
20 | typedef void* (__stdcall *BINKOPEN) (const char* name, uint32_t flags);
|
---|
21 | typedef void* (__stdcall *BINKOPENDIRECTSOUND) (uint32_t param);
|
---|
22 | typedef void (__stdcall *BINKSERVICE) (void* bink);
|
---|
23 | typedef void (__stdcall *BINKSETIOSIZE) (uint32_t iosize);
|
---|
24 | typedef int32_t (__stdcall *BINKSETSOUNDONOFF) (void* bnk, int32_t onoff);
|
---|
25 | typedef int32_t (__stdcall *BINKSETSOUNDSYSTEM) (void* open, uint32_t param);
|
---|
26 | typedef void (__stdcall *BINKSETVOLUME) (void* bnk, int32_t volume);
|
---|
27 | typedef int32_t (__stdcall *BINKWAIT) (void* bnk);
|
---|
28 |
|
---|
29 | static BINKBUFFERBLIT BinkBufferBlit = 0;
|
---|
30 | static BINKBUFFERCLOSE BinkBufferClose = 0;
|
---|
31 | static BINKBUFFERLOCK BinkBufferLock = 0;
|
---|
32 | static BINKBUFFEROPEN BinkBufferOpen = 0;
|
---|
33 | static BINKBUFFERSETOFFSET BinkBufferSetOffset = 0;
|
---|
34 | static BINKBUFFERUNLOCK BinkBufferUnlock = 0;
|
---|
35 | static BINKCLOSE BinkClose = 0;
|
---|
36 | static BINKCOPYTOBUFFER BinkCopyToBuffer = 0;
|
---|
37 | static BINKDOFRAME BinkDoFrame = 0;
|
---|
38 | static BINKGETRECTS BinkGetRects = 0;
|
---|
39 | static BINKNEXTFRAME BinkNextFrame = 0;
|
---|
40 | static BINKOPEN BinkOpen = 0;
|
---|
41 | static BINKOPENDIRECTSOUND BinkOpenDirectSound = 0;
|
---|
42 | static BINKSERVICE BinkService = 0;
|
---|
43 | static BINKSETIOSIZE BinkSetIOSize = 0;
|
---|
44 | static BINKSETSOUNDONOFF BinkSetSoundOnOff = 0;
|
---|
45 | static BINKSETSOUNDSYSTEM BinkSetSoundSystem = 0;
|
---|
46 | static BINKSETVOLUME BinkSetVolume = 0;
|
---|
47 | static BINKWAIT BinkWait = 0;
|
---|
48 |
|
---|
49 |
|
---|
50 | void __stdcall BinkProxyInit()
|
---|
51 | {
|
---|
52 | if (GetFileAttributes("realbink.dll") != INVALID_FILE_ATTRIBUTES)
|
---|
53 | {
|
---|
54 | DWORD err;
|
---|
55 |
|
---|
56 | DDrStartupMessage("Daodan: Loading real Bink DLL");
|
---|
57 | realbink = LoadLibrary("realbink.dll");
|
---|
58 | err = GetLastError();
|
---|
59 | if(realbink)
|
---|
60 | {
|
---|
61 |
|
---|
62 | BinkBufferBlit = (BINKBUFFERBLIT)GetProcAddress(realbink, "_BinkBufferBlit@12");
|
---|
63 | if(!BinkBufferBlit)
|
---|
64 | {
|
---|
65 | DDrStartupMessage("Daodan: Retrieving function address from real Bink DLL failed for: BinkBufferBlit");
|
---|
66 | goto exit_err;
|
---|
67 | }
|
---|
68 | BinkBufferClose = (BINKBUFFERCLOSE)GetProcAddress(realbink, "_BinkBufferClose@4");
|
---|
69 | if(!BinkBufferClose)
|
---|
70 | {
|
---|
71 | DDrStartupMessage("Daodan: Retrieving function address from real Bink DLL failed for: BinkBufferClose");
|
---|
72 | goto exit_err;
|
---|
73 | }
|
---|
74 | BinkBufferLock = (BINKBUFFERLOCK)GetProcAddress(realbink, "_BinkBufferLock@4");
|
---|
75 | if(!BinkBufferLock)
|
---|
76 | {
|
---|
77 | DDrStartupMessage("Daodan: Retrieving function address from real Bink DLL failed for: BinkBufferLock");
|
---|
78 | goto exit_err;
|
---|
79 | }
|
---|
80 | BinkBufferOpen = (BINKBUFFEROPEN)GetProcAddress(realbink, "_BinkBufferOpen@16");
|
---|
81 | if(!BinkBufferOpen)
|
---|
82 | {
|
---|
83 | DDrStartupMessage("Daodan: Retrieving function address from real Bink DLL failed for: BinkBufferOpen");
|
---|
84 | goto exit_err;
|
---|
85 | }
|
---|
86 | BinkBufferSetOffset = (BINKBUFFERSETOFFSET)GetProcAddress(realbink, "_BinkBufferSetOffset@12");
|
---|
87 | if(!BinkBufferSetOffset)
|
---|
88 | {
|
---|
89 | DDrStartupMessage("Daodan: Retrieving function address from real Bink DLL failed for: BinkBufferSetOffset");
|
---|
90 | goto exit_err;
|
---|
91 | }
|
---|
92 | BinkBufferUnlock = (BINKBUFFERUNLOCK)GetProcAddress(realbink, "_BinkBufferUnlock@4");
|
---|
93 | if(!BinkBufferUnlock)
|
---|
94 | {
|
---|
95 | DDrStartupMessage("Daodan: Retrieving function address from real Bink DLL failed for: BinkBufferUnlock");
|
---|
96 | goto exit_err;
|
---|
97 | }
|
---|
98 | BinkClose = (BINKCLOSE)GetProcAddress(realbink, "_BinkClose@4");
|
---|
99 | if(!BinkClose)
|
---|
100 | {
|
---|
101 | DDrStartupMessage("Daodan: Retrieving function address from real Bink DLL failed for: BinkClose");
|
---|
102 | goto exit_err;
|
---|
103 | }
|
---|
104 | BinkCopyToBuffer = (BINKCOPYTOBUFFER)GetProcAddress(realbink, "_BinkCopyToBuffer@28");
|
---|
105 | if(!BinkCopyToBuffer)
|
---|
106 | {
|
---|
107 | DDrStartupMessage("Daodan: Retrieving function address from real Bink DLL failed for: BinkCopyToBuffer");
|
---|
108 | goto exit_err;
|
---|
109 | }
|
---|
110 | BinkDoFrame = (BINKDOFRAME)GetProcAddress(realbink, "_BinkDoFrame@4");
|
---|
111 | if(!BinkDoFrame)
|
---|
112 | {
|
---|
113 | DDrStartupMessage("Daodan: Retrieving function address from real Bink DLL failed for: BinkDoFrame");
|
---|
114 | goto exit_err;
|
---|
115 | }
|
---|
116 | BinkGetRects = (BINKGETRECTS)GetProcAddress(realbink, "_BinkGetRects@8");
|
---|
117 | if(!BinkGetRects)
|
---|
118 | {
|
---|
119 | DDrStartupMessage("Daodan: Retrieving function address from real Bink DLL failed for: BinkGetRects");
|
---|
120 | goto exit_err;
|
---|
121 | }
|
---|
122 | BinkNextFrame = (BINKNEXTFRAME)GetProcAddress(realbink, "_BinkNextFrame@4");
|
---|
123 | if(!BinkNextFrame)
|
---|
124 | {
|
---|
125 | DDrStartupMessage("Daodan: Retrieving function address from real Bink DLL failed for: BinkNextFrame");
|
---|
126 | goto exit_err;
|
---|
127 | }
|
---|
128 | BinkOpen = (BINKOPEN)GetProcAddress(realbink, "_BinkOpen@8");
|
---|
129 | if(!BinkOpen)
|
---|
130 | {
|
---|
131 | DDrStartupMessage("Daodan: Retrieving function address from real Bink DLL failed for: BinkOpen");
|
---|
132 | goto exit_err;
|
---|
133 | }
|
---|
134 | BinkOpenDirectSound = (BINKOPENDIRECTSOUND)GetProcAddress(realbink, "_BinkOpenDirectSound@4");
|
---|
135 | if(!BinkOpenDirectSound)
|
---|
136 | {
|
---|
137 | DDrStartupMessage("Daodan: Retrieving function address from real Bink DLL failed for: BinkOpenDirectSound");
|
---|
138 | goto exit_err;
|
---|
139 | }
|
---|
140 | BinkService = (BINKSERVICE)GetProcAddress(realbink, "_BinkService@4");
|
---|
141 | if(!BinkService)
|
---|
142 | {
|
---|
143 | DDrStartupMessage("Daodan: Retrieving function address from real Bink DLL failed for: BinkService");
|
---|
144 | goto exit_err;
|
---|
145 | }
|
---|
146 | BinkSetIOSize = (BINKSETIOSIZE)GetProcAddress(realbink, "_BinkSetIOSize@4");
|
---|
147 | if(!BinkSetIOSize)
|
---|
148 | {
|
---|
149 | DDrStartupMessage("Daodan: Retrieving function address from real Bink DLL failed for: BinkSetIOSize");
|
---|
150 | goto exit_err;
|
---|
151 | }
|
---|
152 | BinkSetSoundOnOff = (BINKSETSOUNDONOFF)GetProcAddress(realbink, "_BinkSetSoundOnOff@8");
|
---|
153 | if(!BinkSetSoundOnOff)
|
---|
154 | {
|
---|
155 | DDrStartupMessage("Daodan: Retrieving function address from real Bink DLL failed for: BinkSetSoundOnOff");
|
---|
156 | goto exit_err;
|
---|
157 | }
|
---|
158 | BinkSetSoundSystem = (BINKSETSOUNDSYSTEM)GetProcAddress(realbink, "_BinkSetSoundSystem@8");
|
---|
159 | if(!BinkSetSoundSystem)
|
---|
160 | {
|
---|
161 | DDrStartupMessage("Daodan: Retrieving function address from real Bink DLL failed for: BinkSetSoundSystem");
|
---|
162 | goto exit_err;
|
---|
163 | }
|
---|
164 | BinkSetVolume = (BINKSETVOLUME)GetProcAddress(realbink, "_BinkSetVolume@8");
|
---|
165 | if(!BinkSetVolume)
|
---|
166 | {
|
---|
167 | DDrStartupMessage("Daodan: Retrieving function address from real Bink DLL failed for: BinkSetVolume");
|
---|
168 | goto exit_err;
|
---|
169 | }
|
---|
170 | BinkWait = (BINKWAIT)GetProcAddress(realbink, "_BinkWait@4");
|
---|
171 | if(!BinkWait)
|
---|
172 | {
|
---|
173 | DDrStartupMessage("Daodan: Retrieving function address from real Bink DLL failed for: BinkWait");
|
---|
174 | goto exit_err;
|
---|
175 | }
|
---|
176 |
|
---|
177 | } else {
|
---|
178 | char msg[100];
|
---|
179 | FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, msg, 100, NULL);
|
---|
180 | DDrStartupMessage("Daodan: Loading real Bink DLL failed with error %i: %s", err, msg);
|
---|
181 | }
|
---|
182 | }
|
---|
183 |
|
---|
184 | return;
|
---|
185 |
|
---|
186 | exit_err:
|
---|
187 | realbink = 0;
|
---|
188 | return;
|
---|
189 | }
|
---|
190 |
|
---|
191 |
|
---|
192 |
|
---|
193 |
|
---|
194 | void __stdcall _BinkBufferBlit(void* buf, void* rects, uint32_t numrects)
|
---|
195 | {
|
---|
196 | if (realbink)
|
---|
197 | BinkBufferBlit(buf, rects, numrects);
|
---|
198 | }
|
---|
199 |
|
---|
200 | void __stdcall _BinkBufferClose(void* buf)
|
---|
201 | {
|
---|
202 | if (realbink)
|
---|
203 | BinkBufferClose(buf);
|
---|
204 | }
|
---|
205 |
|
---|
206 | int32_t __stdcall _BinkBufferLock(void* buf)
|
---|
207 | {
|
---|
208 | if (realbink)
|
---|
209 | return BinkBufferLock(buf);
|
---|
210 | return 0;
|
---|
211 | }
|
---|
212 |
|
---|
213 | void* __stdcall _BinkBufferOpen(void* wnd, uint32_t width, uint32_t height, uint32_t bufferflags)
|
---|
214 | {
|
---|
215 | if (realbink)
|
---|
216 | return BinkBufferOpen(wnd, width, height, bufferflags);
|
---|
217 | return 0;
|
---|
218 | }
|
---|
219 |
|
---|
220 | int32_t __stdcall _BinkBufferSetOffset(void* buf, int32_t destx, int32_t desty)
|
---|
221 | {
|
---|
222 | if (realbink)
|
---|
223 | return BinkBufferSetOffset(buf, destx, desty);
|
---|
224 | return 0;
|
---|
225 | }
|
---|
226 |
|
---|
227 | int32_t __stdcall _BinkBufferUnlock(void* buf)
|
---|
228 | {
|
---|
229 | if (realbink)
|
---|
230 | return BinkBufferUnlock(buf);
|
---|
231 | return 0;
|
---|
232 | }
|
---|
233 |
|
---|
234 | void __stdcall _BinkClose(void* bnk)
|
---|
235 | {
|
---|
236 | if (realbink)
|
---|
237 | BinkClose(bnk);
|
---|
238 | }
|
---|
239 |
|
---|
240 | int32_t __stdcall _BinkCopyToBuffer(void* bnk, void* dest, int32_t destpitch, uint32_t destheight, uint32_t destx, uint32_t desty, uint32_t flags)
|
---|
241 | {
|
---|
242 | if (realbink)
|
---|
243 | return BinkCopyToBuffer(bnk, dest, destpitch, destheight, destx, desty, flags);
|
---|
244 | return 0;
|
---|
245 | }
|
---|
246 |
|
---|
247 | int32_t __stdcall _BinkDoFrame(void* bnk)
|
---|
248 | {
|
---|
249 | if (realbink)
|
---|
250 | return BinkDoFrame(bnk);
|
---|
251 | return 0;
|
---|
252 | }
|
---|
253 |
|
---|
254 | int32_t __stdcall _BinkGetRects(void* bnk, uint32_t flags)
|
---|
255 | {
|
---|
256 | if (realbink)
|
---|
257 | return BinkGetRects(bnk, flags);
|
---|
258 | return 0;
|
---|
259 | }
|
---|
260 |
|
---|
261 | void __stdcall _BinkNextFrame(void* bnk)
|
---|
262 | {
|
---|
263 | if (realbink)
|
---|
264 | BinkNextFrame(bnk);
|
---|
265 | }
|
---|
266 |
|
---|
267 | void* __stdcall _BinkOpen(const char* name, uint32_t flags)
|
---|
268 | {
|
---|
269 | if (realbink)
|
---|
270 | return BinkOpen(name, flags);
|
---|
271 | return 0;
|
---|
272 | }
|
---|
273 |
|
---|
274 | void* __stdcall _BinkOpenDirectSound(uint32_t param)
|
---|
275 | {
|
---|
276 | if (realbink)
|
---|
277 | return BinkOpenDirectSound(param);
|
---|
278 | return 0;
|
---|
279 | }
|
---|
280 |
|
---|
281 | void __stdcall _BinkService(void* bink)
|
---|
282 | {
|
---|
283 | if (realbink)
|
---|
284 | BinkService(bink);
|
---|
285 | }
|
---|
286 |
|
---|
287 | void __stdcall _BinkSetIOSize(uint32_t iosize)
|
---|
288 | {
|
---|
289 | if (realbink)
|
---|
290 | BinkSetIOSize(iosize);
|
---|
291 | }
|
---|
292 |
|
---|
293 | int32_t __stdcall _BinkSetSoundOnOff(void* bnk, int32_t onoff)
|
---|
294 | {
|
---|
295 | if (realbink)
|
---|
296 | return BinkSetSoundOnOff(bnk, onoff);
|
---|
297 | return 0;
|
---|
298 | }
|
---|
299 |
|
---|
300 | int32_t __stdcall _BinkSetSoundSystem(void* open, uint32_t param)
|
---|
301 | {
|
---|
302 | if (realbink)
|
---|
303 | return BinkSetSoundSystem(open, param);
|
---|
304 | return 0;
|
---|
305 | }
|
---|
306 |
|
---|
307 | void __stdcall _BinkSetVolume(void* bnk, int32_t volume)
|
---|
308 | {
|
---|
309 | if (realbink)
|
---|
310 | BinkSetVolume(bnk, volume);
|
---|
311 | }
|
---|
312 |
|
---|
313 | int32_t __stdcall _BinkWait(void* bnk)
|
---|
314 | {
|
---|
315 | if (realbink)
|
---|
316 | return BinkWait(bnk);
|
---|
317 | return 0;
|
---|
318 | }
|
---|
319 |
|
---|
320 |
|
---|