[MetaHook] Quake Bink function

If you want to play Bink video in game, maybe you need this code.

QBink.h

 1 #ifndef QBINK_H
 2 #define QBINK_H
 3 
 4 #include "bink.h"
 5 
 6 extern void PTR4* (RADEXPLINK *qBinkLogoAddress)(void);
 7 extern void (RADEXPLINK *qBinkSetError)(const char PTR4* err);
 8 extern char PTR4* (RADEXPLINK *qBinkGetError)(void);
 9 extern HBINK (RADEXPLINK *qBinkOpen)(const char PTR4* name,U32 flags);
10 extern void (RADEXPLINK *qBinkGetFrameBuffersInfo)( HBINK bink, BINKFRAMEBUFFERS * fbset );
11 extern void (RADEXPLINK *qBinkRegisterFrameBuffers)( HBINK bink, BINKFRAMEBUFFERS * fbset );
12 extern S32  (RADEXPLINK *qBinkDoFrame)(HBINK bnk);
13 extern void (RADEXPLINK *qBinkNextFrame)(HBINK bnk);
14 extern S32  (RADEXPLINK *qBinkWait)(HBINK bnk);
15 extern void (RADEXPLINK *qBinkClose)(HBINK bnk);
16 extern S32  (RADEXPLINK *qBinkPause)(HBINK bnk,S32 pause);
17 extern S32  (RADEXPLINK *qBinkCopyToBuffer)(HBINK bnk,void* dest,S32 destpitch,U32 destheight,U32 destx,U32 desty,U32 flags);
18 extern S32  (RADEXPLINK *qBinkCopyToBufferRect)(HBINK bnk,void* dest,S32 destpitch,U32 destheight,U32 destx,U32 desty,U32 srcx, U32 srcy, U32 srcw, U32 srch, U32 flags);
19 extern S32  (RADEXPLINK *qBinkGetRects)(HBINK bnk,U32 flags);
20 extern void (RADEXPLINK *qBinkGoto)(HBINK bnk,U32 frame,S32 flags);  // use 1 for the first frame
21 extern U32  (RADEXPLINK *qBinkGetKeyFrame)(HBINK bnk,U32 frame,S32 flags);
22 extern S32  (RADEXPLINK *qBinkSetVideoOnOff)(HBINK bnk,S32 onoff);
23 extern S32  (RADEXPLINK *qBinkSetSoundOnOff)(HBINK bnk,S32 onoff);
24 extern void (RADEXPLINK *qBinkFreeGlocalMemory)( void );
25 extern void (RADEXPLINK *qBinkSetVolume)(HBINK bnk, U32 trackid, S32 volume);
26 extern void (RADEXPLINK *qBinkSetPan)(HBINK bnk,U32 trackid, S32 pan);
27 extern void (RADEXPLINK *qBinkSetMixBins)(HBINK bnk,U32 trackid, U32 PTR4* mix_bins, U32 total);
28 extern void (RADEXPLINK *qBinkSetMixBinVolumes)(HBINK bnk,U32 trackid, U32 PTR4* vol_mix_bins, S32 PTR4* volumes, U32 total);
29 extern void (RADEXPLINK *qBinkService)(HBINK bink);
30 extern S32  (RADEXPLINK *qBinkShouldSkip)(HBINK bink);
31 extern void (RADEXPLINK *qBinkGetPalette)( void * out_pal );
32 extern S32  (RADEXPLINK *qBinkControlBackgroundIO)(HBINK bink,U32 control);
33 extern HBINKTRACK (RADEXPLINK *qBinkOpenTrack)(HBINK bnk,U32 trackindex);
34 extern void (RADEXPLINK *qBinkCloseTrack)(HBINKTRACK bnkt);
35 extern U32  (RADEXPLINK *qBinkGetTrackData)(HBINKTRACK bnkt,void PTR4* dest);
36 extern U32  (RADEXPLINK *qBinkGetTrackType)(HBINK bnk,U32 trackindex);
37 extern U32  (RADEXPLINK *qBinkGetTrackMaxSize)(HBINK bnk,U32 trackindex);
38 extern U32  (RADEXPLINK *qBinkGetTrackID)(HBINK bnk,U32 trackindex);
39 extern void (RADEXPLINK *qBinkGetSummary)(HBINK bnk,BINKSUMMARY PTR4* sum);
40 extern void (RADEXPLINK *qBinkGetRealtime)(HBINK bink,BINKREALTIME PTR4* run,U32 frames);
41 extern void (RADEXPLINK *qBinkSetSoundTrack)(U32 total_tracks, U32 PTR4* tracks);
42 extern void (RADEXPLINK *qBinkSetIO)(BINKIOOPEN io);
43 extern void (RADEXPLINK *qBinkSetFrameRate)(U32 forcerate,U32 forceratediv);
44 extern void (RADEXPLINK *qBinkSetSimulate)(U32 sim);
45 extern void (RADEXPLINK *qBinkSetIOSize)(U32 iosize);
46 extern S32  (RADEXPLINK *qBinkSetSoundSystem)(BINKSNDSYSOPEN open, U32 param);
47 extern void (RADEXPLINK *qBinkControlCPUFeatures)( S32 use, S32 dont_use );
48 extern BINKSNDOPEN (RADEXPLINK *qBinkOpenDirectSound)(U32 param); // don't call directly
49 extern BINKSNDOPEN (RADEXPLINK *qBinkOpenWaveOut)(U32 param); // don't call directly
50 extern BINKSNDOPEN (RADEXPLINK *qBinkOpenMiles)(U32 param); // don't call directly
51 extern S32 (RADEXPLINK *qBinkDX8SurfaceType)(void* lpD3Ds);
52 extern S32 (RADEXPLINK *qBinkDX9SurfaceType)(void* lpD3Ds);
53 extern HBINKBUFFER (RADEXPLINK *qBinkBufferOpen)( void* /*HWND*/ wnd, U32 width, U32 height, U32 bufferflags);
54 extern S32 (RADEXPLINK *qBinkBufferSetHWND)( HBINKBUFFER buf, void* /*HWND*/ newwnd);
55 extern S32 (RADEXPLINK *qBinkDDSurfaceType)(void PTR4* lpDDS);
56 extern S32 (RADEXPLINK *qBinkIsSoftwareCursor)(void PTR4* lpDDSP, void* /*HCURSOR*/ cur);
57 extern S32 (RADEXPLINK *qBinkCheckCursor)(void* /*HWND*/ wnd,S32 x,S32 y,S32 w,S32 h);
58 extern S32 (RADEXPLINK *qBinkBufferSetDirectDraw)(void PTR4* lpDirectDraw, void PTR4* lpPrimary);
59 extern void (RADEXPLINK *qBinkBufferClose)( HBINKBUFFER buf);
60 extern S32 (RADEXPLINK *qBinkBufferLock)( HBINKBUFFER buf);
61 extern S32 (RADEXPLINK *qBinkBufferUnlock)( HBINKBUFFER buf);
62 extern void (RADEXPLINK *qBinkBufferSetResolution)( S32 w, S32 h, S32 bits);
63 extern void (RADEXPLINK *qBinkBufferCheckWinPos)( HBINKBUFFER buf, S32 PTR4* NewWindowX, S32 PTR4* NewWindowY);
64 extern S32 (RADEXPLINK *qBinkBufferSetOffset)( HBINKBUFFER buf, S32 destx, S32 desty);
65 extern void (RADEXPLINK *qBinkBufferBlit)( HBINKBUFFER buf, BINKRECT PTR4* rects, U32 numrects );
66 extern S32 (RADEXPLINK *qBinkBufferSetScale)( HBINKBUFFER buf, U32 w, U32 h);
67 extern char PTR4* (RADEXPLINK *qBinkBufferGetDescription)( HBINKBUFFER buf);
68 extern char PTR4* (RADEXPLINK *qBinkBufferGetError)();
69 extern void (RADEXPLINK *qBinkRestoreCursor)(S32 checkcount);
70 extern S32 (RADEXPLINK *qBinkBufferClear)(HBINKBUFFER buf, U32 RGB);
71 extern void (RADEXPLINK *qBinkSetMemory)(BINKMEMALLOC a,BINKMEMFREE f);
72 
73 void QBink_Init(void);
74 void QBink_Shutdown(void);
75 
76 #endif

QBink.cpp

  1 #include 
  2 
  3 #include "bink.h"
  4 
  5 static HMODULE hBink = NULL;
  6 
  7 void PTR4* (RADEXPLINK *qBinkLogoAddress)(void) = 0;
  8 void (RADEXPLINK *qBinkSetError)(const char PTR4* err) = 0;
  9 char PTR4* (RADEXPLINK *qBinkGetError)(void) = 0;
 10 HBINK (RADEXPLINK *qBinkOpen)(const char PTR4* name,U32 flags) = 0;
 11 void (RADEXPLINK *qBinkGetFrameBuffersInfo)( HBINK bink, BINKFRAMEBUFFERS * fbset ) = 0;
 12 void (RADEXPLINK *qBinkRegisterFrameBuffers)( HBINK bink, BINKFRAMEBUFFERS * fbset ) = 0;
 13 S32  (RADEXPLINK *qBinkDoFrame)(HBINK bnk) = 0;
 14 void (RADEXPLINK *qBinkNextFrame)(HBINK bnk) = 0;
 15 S32  (RADEXPLINK *qBinkWait)(HBINK bnk) = 0;
 16 void (RADEXPLINK *qBinkClose)(HBINK bnk) = 0;
 17 S32  (RADEXPLINK *qBinkPause)(HBINK bnk,S32 pause) = 0;
 18 S32  (RADEXPLINK *qBinkCopyToBuffer)(HBINK bnk,void* dest,S32 destpitch,U32 destheight,U32 destx,U32 desty,U32 flags) = 0;
 19 S32  (RADEXPLINK *qBinkCopyToBufferRect)(HBINK bnk,void* dest,S32 destpitch,U32 destheight,U32 destx,U32 desty,U32 srcx, U32 srcy, U32 srcw, U32 srch, U32 flags) = 0;
 20 S32  (RADEXPLINK *qBinkGetRects)(HBINK bnk,U32 flags) = 0;
 21 void (RADEXPLINK *qBinkGoto)(HBINK bnk,U32 frame,S32 flags) = 0;  // use 1 for the first frame
 22 U32  (RADEXPLINK *qBinkGetKeyFrame)(HBINK bnk,U32 frame,S32 flags) = 0;
 23 S32  (RADEXPLINK *qBinkSetVideoOnOff)(HBINK bnk,S32 onoff) = 0;
 24 S32  (RADEXPLINK *qBinkSetSoundOnOff)(HBINK bnk,S32 onoff) = 0;
 25 void (RADEXPLINK *qBinkSetVolume)(HBINK bnk, U32 trackid, S32 volume) = 0;
 26 void (RADEXPLINK *qBinkSetPan)(HBINK bnk,U32 trackid, S32 pan) = 0;
 27 void (RADEXPLINK *qBinkSetMixBins)(HBINK bnk,U32 trackid, U32 PTR4* mix_bins, U32 total) = 0;
 28 void (RADEXPLINK *qBinkSetMixBinVolumes)(HBINK bnk,U32 trackid, U32 PTR4* vol_mix_bins, S32 PTR4* volumes, U32 total) = 0;
 29 void (RADEXPLINK *qBinkService)(HBINK bink) = 0;
 30 S32  (RADEXPLINK *qBinkShouldSkip)(HBINK bink) = 0;
 31 void (RADEXPLINK *qBinkGetPalette)( void * out_pal ) = 0;
 32 S32  (RADEXPLINK *qBinkControlBackgroundIO)(HBINK bink,U32 control) = 0;
 33 HBINKTRACK (RADEXPLINK *qBinkOpenTrack)(HBINK bnk,U32 trackindex) = 0;
 34 void (RADEXPLINK *qBinkCloseTrack)(HBINKTRACK bnkt) = 0;
 35 U32  (RADEXPLINK *qBinkGetTrackData)(HBINKTRACK bnkt,void PTR4* dest) = 0;
 36 U32  (RADEXPLINK *qBinkGetTrackType)(HBINK bnk,U32 trackindex) = 0;
 37 U32  (RADEXPLINK *qBinkGetTrackMaxSize)(HBINK bnk,U32 trackindex) = 0;
 38 U32  (RADEXPLINK *qBinkGetTrackID)(HBINK bnk,U32 trackindex) = 0;
 39 void (RADEXPLINK *qBinkGetSummary)(HBINK bnk,BINKSUMMARY PTR4* sum) = 0;
 40 void (RADEXPLINK *qBinkGetRealtime)(HBINK bink,BINKREALTIME PTR4* run,U32 frames) = 0;
 41 void (RADEXPLINK *qBinkSetSoundTrack)(U32 total_tracks, U32 PTR4* tracks) = 0;
 42 void (RADEXPLINK *qBinkSetIO)(BINKIOOPEN io) = 0;
 43 void (RADEXPLINK *qBinkSetFrameRate)(U32 forcerate,U32 forceratediv) = 0;
 44 void (RADEXPLINK *qBinkSetSimulate)(U32 sim) = 0;
 45 void (RADEXPLINK *qBinkSetIOSize)(U32 iosize) = 0;
 46 S32  (RADEXPLINK *qBinkSetSoundSystem)(BINKSNDSYSOPEN open, U32 param) = 0;
 47 BINKSNDOPEN (RADEXPLINK *qBinkOpenDirectSound)(U32 param) = 0; // don't call directly
 48 BINKSNDOPEN (RADEXPLINK *qBinkOpenWaveOut)(U32 param) = 0; // don't call directly
 49 BINKSNDOPEN (RADEXPLINK *qBinkOpenMiles)(U32 param) = 0; // don't call directly
 50 S32 (RADEXPLINK *qBinkDX8SurfaceType)(void* lpD3Ds) = 0;
 51 S32 (RADEXPLINK *qBinkDX9SurfaceType)(void* lpD3Ds) = 0;
 52 HBINKBUFFER (RADEXPLINK *qBinkBufferOpen)( void* /*HWND*/ wnd, U32 width, U32 height, U32 bufferflags) = 0;
 53 S32 (RADEXPLINK *qBinkBufferSetHWND)( HBINKBUFFER buf, void* /*HWND*/ newwnd) = 0;
 54 S32 (RADEXPLINK *qBinkDDSurfaceType)(void PTR4* lpDDS) = 0;
 55 S32 (RADEXPLINK *qBinkIsSoftwareCursor)(void PTR4* lpDDSP, void* /*HCURSOR*/ cur) = 0;
 56 S32 (RADEXPLINK *qBinkCheckCursor)(void* /*HWND*/ wnd,S32 x,S32 y,S32 w,S32 h) = 0;
 57 S32 (RADEXPLINK *qBinkBufferSetDirectDraw)(void PTR4* lpDirectDraw, void PTR4* lpPrimary) = 0;
 58 void (RADEXPLINK *qBinkBufferClose)( HBINKBUFFER buf) = 0;
 59 S32 (RADEXPLINK *qBinkBufferLock)( HBINKBUFFER buf) = 0;
 60 S32 (RADEXPLINK *qBinkBufferUnlock)( HBINKBUFFER buf) = 0;
 61 void (RADEXPLINK *qBinkBufferSetResolution)( S32 w, S32 h, S32 bits) = 0;
 62 void (RADEXPLINK *qBinkBufferCheckWinPos)( HBINKBUFFER buf, S32 PTR4* NewWindowX, S32 PTR4* NewWindowY) = 0;
 63 S32 (RADEXPLINK *qBinkBufferSetOffset)( HBINKBUFFER buf, S32 destx, S32 desty) = 0;
 64 void (RADEXPLINK *qBinkBufferBlit)( HBINKBUFFER buf, BINKRECT PTR4* rects, U32 numrects ) = 0;
 65 S32 (RADEXPLINK *qBinkBufferSetScale)( HBINKBUFFER buf, U32 w, U32 h) = 0;
 66 char PTR4* (RADEXPLINK *qBinkBufferGetDescription)( HBINKBUFFER buf) = 0;
 67 char PTR4* (RADEXPLINK *qBinkBufferGetError)() = 0;
 68 void (RADEXPLINK *qBinkRestoreCursor)(S32 checkcount) = 0;
 69 S32 (RADEXPLINK *qBinkBufferClear)(HBINKBUFFER buf, U32 RGB) = 0;
 70 void (RADEXPLINK *qBinkSetMemory)(BINKMEMALLOC a,BINKMEMFREE f) = 0;
 71 
 72 void QBink_Init(void)
 73 {
 74     hBink = LoadLibrary("binkw32.dll");
 75 
 76     if (hBink)
 77     {
 78         qBinkLogoAddress = (void PTR4* (RADEXPLINK *)(void))GetProcAddress(hBink, "_BinkLogoAddress@0");
 79         qBinkSetError = (void (RADEXPLINK *)(const char PTR4*))GetProcAddress(hBink, "_BinkSetError@4");
 80         qBinkGetError = (char PTR4* (RADEXPLINK *)(void))GetProcAddress(hBink, "_BinkGetError@0");
 81         qBinkOpen = (HBINK (RADEXPLINK *)(const char PTR4*,U32))GetProcAddress(hBink, "_BinkOpen@8");
 82         qBinkGetFrameBuffersInfo = (void (RADEXPLINK *)( HBINK, BINKFRAMEBUFFERS *))GetProcAddress(hBink, "_BinkGetFrameBuffersInfo@8");
 83         qBinkRegisterFrameBuffers = (void (RADEXPLINK *)( HBINK, BINKFRAMEBUFFERS *))GetProcAddress(hBink, "_BinkRegisterFrameBuffers@8");
 84         qBinkDoFrame = (S32  (RADEXPLINK *)(HBINK))GetProcAddress(hBink, "_BinkDoFrame@4");
 85         qBinkNextFrame = (void (RADEXPLINK *)(HBINK))GetProcAddress(hBink, "_BinkNextFrame@4");
 86         qBinkWait = (S32  (RADEXPLINK *)(HBINK))GetProcAddress(hBink, "_BinkWait@4");
 87         qBinkClose = (void (RADEXPLINK *)(HBINK))GetProcAddress(hBink, "_BinkClose@4");
 88         qBinkPause = (S32  (RADEXPLINK *)(HBINK,S32))GetProcAddress(hBink, "_BinkPause@8");
 89         qBinkCopyToBuffer = (S32  (RADEXPLINK *)(HBINK,void*,S32,U32,U32,U32,U32))GetProcAddress(hBink, "_BinkCopyToBuffer@28");
 90         qBinkCopyToBufferRect = (S32  (RADEXPLINK *)(HBINK,void*,S32,U32,U32,U32,U32, U32, U32, U32, U32))GetProcAddress(hBink, "_BinkCopyToBufferRect@44");
 91         qBinkGetRects = (S32  (RADEXPLINK *)(HBINK,U32))GetProcAddress(hBink, "_BinkGetRects@8");
 92         qBinkGoto = (void (RADEXPLINK *)(HBINK,U32,S32))GetProcAddress(hBink, "_BinkGoto@12");  // use 1 for the first frame
 93         qBinkGetKeyFrame = (U32  (RADEXPLINK *)(HBINK,U32,S32))GetProcAddress(hBink, "_BinkGetKeyFrame@12");
 94         qBinkSetVideoOnOff = (S32  (RADEXPLINK *)(HBINK,S32))GetProcAddress(hBink, "_BinkSetVideoOnOff@8");
 95         qBinkSetSoundOnOff = (S32  (RADEXPLINK *)(HBINK,S32))GetProcAddress(hBink, "_BinkSetSoundOnOff@8");
 96         qBinkSetVolume = (void (RADEXPLINK *)(HBINK, U32, S32))GetProcAddress(hBink, "_BinkSetVolume@12");
 97         qBinkSetPan = (void (RADEXPLINK *)(HBINK,U32, S32))GetProcAddress(hBink, "_BinkSetPan@12");
 98         qBinkSetMixBins = (void (RADEXPLINK *)(HBINK,U32, U32 PTR4*, U32))GetProcAddress(hBink, "_BinkSetMixBins@16");
 99         qBinkSetMixBinVolumes = (void (RADEXPLINK *)(HBINK,U32, U32 PTR4*, S32 PTR4*, U32))GetProcAddress(hBink, "_BinkSetMixBinVolumes@20");
100         qBinkService = (void (RADEXPLINK *)(HBINK))GetProcAddress(hBink, "_BinkService@4");
101         qBinkShouldSkip = (S32  (RADEXPLINK *)(HBINK))GetProcAddress(hBink, "_BinkShouldSkip@4");
102         qBinkGetPalette = (void (RADEXPLINK *)( void * ))GetProcAddress(hBink, "_BinkGetPalette@4");
103         qBinkControlBackgroundIO = (S32  (RADEXPLINK *)(HBINK,U32))GetProcAddress(hBink, "_BinkControlBackgroundIO@8");
104         qBinkOpenTrack = (HBINKTRACK (RADEXPLINK *)(HBINK,U32))GetProcAddress(hBink, "_BinkOpenTrack@8");
105         qBinkCloseTrack = (void (RADEXPLINK *)(HBINKTRACK))GetProcAddress(hBink, "_BinkCloseTrack@4");
106         qBinkGetTrackData = (U32  (RADEXPLINK *)(HBINKTRACK,void PTR4*))GetProcAddress(hBink, "_BinkGetTrackData@8");
107         qBinkGetTrackType = (U32  (RADEXPLINK *)(HBINK,U32))GetProcAddress(hBink, "_BinkGetTrackType@8");
108         qBinkGetTrackMaxSize = (U32  (RADEXPLINK *)(HBINK,U32))GetProcAddress(hBink, "_BinkGetTrackMaxSize@8");
109         qBinkGetTrackID = (U32  (RADEXPLINK *)(HBINK,U32))GetProcAddress(hBink, "_BinkGetTrackID@8");
110         qBinkGetSummary = (void (RADEXPLINK *)(HBINK,BINKSUMMARY PTR4*))GetProcAddress(hBink, "_BinkGetSummary@8");
111         qBinkGetRealtime = (void (RADEXPLINK *)(HBINK,BINKREALTIME PTR4*,U32))GetProcAddress(hBink, "_BinkGetRealtime@12");
112         qBinkSetSoundTrack = (void (RADEXPLINK *)(U32, U32 PTR4*))GetProcAddress(hBink, "_BinkSetSoundTrack@8");
113         qBinkSetIO = (void (RADEXPLINK *)(BINKIOOPEN))GetProcAddress(hBink, "_BinkSetIO@4");
114         qBinkSetFrameRate = (void (RADEXPLINK *)(U32,U32))GetProcAddress(hBink, "_BinkSetFrameRate@8");
115         qBinkSetSimulate = (void (RADEXPLINK *)(U32))GetProcAddress(hBink, "_BinkSetSimulate@4");
116         qBinkSetIOSize = (void (RADEXPLINK *)(U32))GetProcAddress(hBink, "_BinkSetIOSize@4");
117         qBinkSetSoundSystem = (S32  (RADEXPLINK *)(BINKSNDSYSOPEN, U32))GetProcAddress(hBink, "_BinkSetSoundSystem@8");
118         qBinkOpenDirectSound = (BINKSNDOPEN (RADEXPLINK *)(U32))GetProcAddress(hBink, "_BinkOpenDirectSound@4"); // don't call directly
119         qBinkOpenWaveOut = (BINKSNDOPEN (RADEXPLINK *)(U32))GetProcAddress(hBink, "_BinkOpenWaveOut@4"); // don't call directly
120         qBinkOpenMiles = (BINKSNDOPEN (RADEXPLINK *)(U32))GetProcAddress(hBink, "_BinkOpenMiles@4"); // don't call directly
121         qBinkDX8SurfaceType = (S32 (RADEXPLINK *)(void*))GetProcAddress(hBink, "_BinkDX8SurfaceType@4");
122         qBinkDX9SurfaceType = (S32 (RADEXPLINK *)(void*))GetProcAddress(hBink, "_BinkDX9SurfaceType@4");
123         qBinkBufferOpen = (HBINKBUFFER (RADEXPLINK *)( void* /*HWND*/, U32, U32, U32))GetProcAddress(hBink, "_BinkBufferOpen@16");
124         qBinkBufferSetHWND = (S32 (RADEXPLINK *)( HBINKBUFFER, void* /*HWND*/))GetProcAddress(hBink, "_BinkBufferSetHWND@8");
125         qBinkDDSurfaceType = (S32 (RADEXPLINK *)(void PTR4*))GetProcAddress(hBink, "_BinkDDSurfaceType@4");
126         qBinkIsSoftwareCursor = (S32 (RADEXPLINK *)(void PTR4*, void* /*HCURSOR*/))GetProcAddress(hBink, "_BinkIsSoftwareCursor@8");
127         qBinkCheckCursor = (S32 (RADEXPLINK *)(void* /*HWND*/,S32,S32,S32,S32))GetProcAddress(hBink, "_BinkCheckCursor@20");
128         qBinkBufferSetDirectDraw = (S32 (RADEXPLINK *)(void PTR4*, void PTR4*))GetProcAddress(hBink, "_BinkBufferSetDirectDraw@8");
129         qBinkBufferClose = (void (RADEXPLINK *)( HBINKBUFFER))GetProcAddress(hBink, "_BinkBufferClose@4");
130         qBinkBufferLock = (S32 (RADEXPLINK *)( HBINKBUFFER))GetProcAddress(hBink, "_BinkBufferLock@4");
131         qBinkBufferUnlock = (S32 (RADEXPLINK *)( HBINKBUFFER))GetProcAddress(hBink, "_BinkBufferUnlock@4");
132         qBinkBufferSetResolution = (void (RADEXPLINK *)( S32, S32, S32))GetProcAddress(hBink, "_BinkBufferSetResolution@12");
133         qBinkBufferCheckWinPos = (void (RADEXPLINK *)( HBINKBUFFER, S32 PTR4*, S32 PTR4*))GetProcAddress(hBink, "_BinkBufferCheckWinPos@12");
134         qBinkBufferSetOffset = (S32 (RADEXPLINK *)( HBINKBUFFER, S32, S32))GetProcAddress(hBink, "_BinkBufferSetOffset@12");
135         qBinkBufferBlit = (void (RADEXPLINK *)( HBINKBUFFER, BINKRECT PTR4*, U32 ))GetProcAddress(hBink, "_BinkBufferBlit@12");
136         qBinkBufferSetScale = (S32 (RADEXPLINK *)( HBINKBUFFER, U32, U32))GetProcAddress(hBink, "_BinkBufferSetScale@12");
137         qBinkBufferGetDescription = (char PTR4* (RADEXPLINK *)( HBINKBUFFER))GetProcAddress(hBink, "_BinkBufferGetDescription@4");
138         qBinkBufferGetError = (char PTR4* (RADEXPLINK *)())GetProcAddress(hBink, "_BinkBufferGetError@0");
139         qBinkRestoreCursor = (void (RADEXPLINK *)(S32))GetProcAddress(hBink, "_BinkRestoreCursor@4");
140         qBinkBufferClear = (S32 (RADEXPLINK *)(HBINKBUFFER, U32))GetProcAddress(hBink, "_BinkBufferClear@8");
141         qBinkSetMemory = (void (RADEXPLINK *)(BINKMEMALLOC,BINKMEMFREE))GetProcAddress(hBink, "_BinkSetMemory@8");
142     }
143 }
144 
145 void QBink_Shutdown(void)
146 {
147     if (hBink)
148         FreeLibrary(hBink);
149 }

How to play a Bink video file? Look here.

CBink.h

 1 #ifndef CBINK_H
 2 #define CBINK_H
 3 
 4 #include "bink.h"
 5 
 6 class CBink
 7 {
 8 public:
 9     CBink();
10     ~CBink();
11 public:
12     BOOL Load(char *pszFileName);
13     void SetPos(Vector vec1, Vector vec2, Vector vec3, Vector vec4);
14     void Draw(void);
15     bool IsValid(void);
16     char *GetName(void);
17     void Play(void);
18     void Pause(void);
19     void Stop(void);
20     void Free(void);
21 private:
22     int m_iTexID;
23     HBINK m_hBink;
24     char *m_pszName;
25     int m_iWidth;
26     int m_iHeight;
27     BYTE *m_pBuffer;
28     Vector m_vecRect[4];
29     bool m_bPlay;
30     float m_flStartTime;
31     int m_iCurFrame;
32     int m_iLastFrame;
33 };
34 
35 #endif

CBink.cpp

  1 #include 
  2 
  3 #include "qbink.h"
  4 #include "surface.h"
  5 #include "qgl.h"
  6 
  7 #include "cbink.h"
  8 
  9 extern IFileSystem *g_pFileSystem;
 10 
 11 CBink::CBink()
 12 {
 13     m_iTexID = 0;
 14     m_hBink = NULL;
 15     m_pszName = NULL;
 16     m_iWidth = 0;
 17     m_iHeight = 0;
 18     m_pBuffer = NULL;
 19     m_bPlay = false;
 20     m_flStartTime = 0.0f;
 21     m_iCurFrame = 0;
 22     m_iLastFrame = 0;
 23 }
 24 
 25 CBink::~CBink()
 26 {
 27     Free();
 28 }
 29 
 30 BOOL CBink::Load(char *pszFileName)
 31 {
 32     if (IsValid())
 33         return FALSE;
 34 
 35     FileHandle_t pFile = g_pFileSystem->Open(pszFileName, "rb");
 36 
 37     if (!pFile)
 38         return FALSE;
 39 
 40     uint32 iFileLength;
 41     BYTE *pBuffer;
 42 
 43     g_pFileSystem->Seek(pFile, 0, FILESYSTEM_SEEK_TAIL);
 44     iFileLength = g_pFileSystem->Tell(pFile);
 45     g_pFileSystem->Seek(pFile, 0, FILESYSTEM_SEEK_HEAD);
 46 
 47     pBuffer = (BYTE *)malloc(iFileLength);
 48     g_pFileSystem->Read(pBuffer, iFileLength, pFile);
 49 
 50     g_pFileSystem->Close(pFile);
 51 
 52     m_hBink = qBinkOpen((char *)pBuffer, BINKFROMMEMORY);
 53     free(pBuffer);
 54 
 55     if (!m_hBink)
 56         return FALSE;
 57 
 58     if (!m_pszName)
 59         m_pszName = (char *)malloc(strlen(pszFileName) * sizeof(char) + 1);
 60 
 61     strcpy(m_pszName, pszFileName);
 62 
 63     if (!m_iTexID)
 64         m_iTexID = g_pSurface->CreateNewTextureID();
 65 
 66     m_iWidth = m_hBink->Width;
 67     m_iHeight = m_hBink->Height;
 68 
 69     DWORD dwBufferSize = m_iWidth * m_iHeight * 3;
 70 
 71     m_pBuffer = (BYTE *)malloc(dwBufferSize);
 72     m_bPlay = false;
 73     m_flStartTime = 0.0f;
 74     m_iCurFrame = 0;
 75     m_iLastFrame = 0;
 76 
 77     qglBindTexture(GL_TEXTURE_2D, m_iTexID);
 78     qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 79     qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 80 
 81     memset(m_pBuffer, 0, dwBufferSize);
 82     qglTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_iWidth, m_iHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, m_pBuffer);
 83 
 84     qBinkGoto(m_hBink, 1, 0);
 85 
 86     return TRUE;
 87 }
 88 
 89 void CBink::SetPos(Vector vec1, Vector vec2, Vector vec3, Vector vec4)
 90 {
 91     if (!IsValid())
 92         return;
 93 
 94     m_vecRect[0] = vec1;
 95     m_vecRect[1] = vec2;
 96     m_vecRect[2] = vec3;
 97     m_vecRect[3] = vec4;
 98 }
 99 
100 void CBink::Draw(void)
101 {
102     if (!IsValid())
103         return;
104 
105     if (!m_bPlay)
106         return;
107 
108     float flCurTime = gEngfuncs.GetClientTime();
109 
110     if (m_iLastFrame != m_iCurFrame)
111     {
112 #if 0
113         int iSub = m_iCurFrame - m_iLastFrame;
114 
115         for (int i = 0; i < iSub; ++i)
116         {
117             qBinkDoFrame(m_hBink);
118             qBinkNextFrame(m_hBink);
119         }
120 #else
121         qBinkGoto(m_hBink, m_iCurFrame, 0);
122         qBinkDoFrame(m_hBink);
123         qBinkNextFrame(m_hBink);
124 #endif
125 
126         qBinkCopyToBuffer(m_hBink, m_pBuffer, m_iWidth * 3, m_iHeight, 0, 0, BINKSURFACE24R);
127 
128         qglBindTexture(GL_TEXTURE_2D, m_iTexID);
129         qglTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_iWidth, m_iHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, m_pBuffer);
130 
131         m_iLastFrame = m_iCurFrame;
132     }
133 
134     if (m_iCurFrame > 0)
135     {
136         qglEnable(GL_TEXTURE_2D);
137         qglDisable(GL_CULL_FACE);
138 
139         qglEnable(GL_BLEND);
140         qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
141 
142         qglBindTexture(GL_TEXTURE_2D, m_iTexID);
143         qglColor4f(1.0f, 1.0f, 1.0f, 1.0f);
144 
145         qglBegin(GL_QUADS);
146         qglTexCoord2f(0.0f, 0.0f);
147         qglVertex3f(m_vecRect[0].x, m_vecRect[0].y, m_vecRect[0].z);
148         qglTexCoord2f(1.0f, 0.0f);
149         qglVertex3f(m_vecRect[1].x, m_vecRect[1].y, m_vecRect[1].z);
150         qglTexCoord2f(1.0f, 1.0f);
151         qglVertex3f(m_vecRect[2].x, m_vecRect[2].y, m_vecRect[2].z);
152         qglTexCoord2f(0.0f, 1.0f);
153         qglVertex3f(m_vecRect[3].x, m_vecRect[3].y, m_vecRect[3].z);
154         qglEnd();
155 
156         qglEnable(GL_CULL_FACE);
157     }
158 
159     float flPlayTime, flSubTime, flRot;
160     int iDoFrame;
161 
162     flPlayTime = m_hBink->Frames * ((float)m_hBink->FrameRateDiv / (float)m_hBink->FrameRate);
163     flSubTime = flCurTime - m_flStartTime;
164     flRot = flSubTime / flPlayTime;
165 
166     iDoFrame = (int)((float)m_hBink->Frames * flRot);
167 
168     m_iCurFrame = iDoFrame;
169 
170     if (m_iCurFrame > (int)m_hBink->Frames)
171         Stop();
172 }
173 
174 bool CBink::IsValid(void)
175 {
176     return m_pBuffer != NULL;
177 }
178 
179 char *CBink::GetName(void)
180 {
181     return m_pszName;
182 }
183 
184 void CBink::Play(void)
185 {
186     if (!IsValid())
187         return;
188 
189     m_bPlay = true;
190     m_flStartTime = gEngfuncs.GetClientTime();
191     m_iCurFrame = 0;
192     m_iLastFrame = 0;
193 }
194 
195 void CBink::Pause(void)
196 {
197     if (!IsValid())
198         return;
199 }
200 
201 void CBink::Stop(void)
202 {
203     if (!IsValid())
204         return;
205 
206     m_bPlay = false;
207 }
208 
209 void CBink::Free(void)
210 {
211     if (!IsValid())
212         return;
213 
214     Stop();
215 
216     if (m_hBink)
217         qBinkClose(m_hBink);
218 
219     if (m_pszName)
220         free(m_pszName);
221 
222     if (m_pBuffer)
223         free(m_pBuffer);
224 
225     m_hBink = NULL;
226     m_pszName = NULL;
227     m_iWidth = 0;
228     m_iHeight = 0;
229     m_pBuffer = NULL;
230 }

 

转载于:https://www.cnblogs.com/crsky/p/4702960.html

你可能感兴趣的:([MetaHook] Quake Bink function)