source: Daodan/src/bink-proxy.c@ 1178

Last change on this file since 1178 was 994, checked in by alloc, 11 years ago

Daodan:

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