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 <metahook.h> 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, "[email protected]"); 79 qBinkSetError = (void (RADEXPLINK *)(const char PTR4*))GetProcAddress(hBink, "[email protected]"); 80 qBinkGetError = (char PTR4* (RADEXPLINK *)(void))GetProcAddress(hBink, "[email protected]"); 81 qBinkOpen = (HBINK (RADEXPLINK *)(const char PTR4*,U32))GetProcAddress(hBink, "[email protected]"); 82 qBinkGetFrameBuffersInfo = (void (RADEXPLINK *)( HBINK, BINKFRAMEBUFFERS *))GetProcAddress(hBink, "[email protected]"); 83 qBinkRegisterFrameBuffers = (void (RADEXPLINK *)( HBINK, BINKFRAMEBUFFERS *))GetProcAddress(hBink, "[email protected]"); 84 qBinkDoFrame = (S32 (RADEXPLINK *)(HBINK))GetProcAddress(hBink, "[email protected]"); 85 qBinkNextFrame = (void (RADEXPLINK *)(HBINK))GetProcAddress(hBink, "[email protected]"); 86 qBinkWait = (S32 (RADEXPLINK *)(HBINK))GetProcAddress(hBink, "[email protected]"); 87 qBinkClose = (void (RADEXPLINK *)(HBINK))GetProcAddress(hBink, "[email protected]"); 88 qBinkPause = (S32 (RADEXPLINK *)(HBINK,S32))GetProcAddress(hBink, "[email protected]"); 89 qBinkCopyToBuffer = (S32 (RADEXPLINK *)(HBINK,void*,S32,U32,U32,U32,U32))GetProcAddress(hBink, "[email protected]"); 90 qBinkCopyToBufferRect = (S32 (RADEXPLINK *)(HBINK,void*,S32,U32,U32,U32,U32, U32, U32, U32, U32))GetProcAddress(hBink, "[email protected]"); 91 qBinkGetRects = (S32 (RADEXPLINK *)(HBINK,U32))GetProcAddress(hBink, "[email protected]"); 92 qBinkGoto = (void (RADEXPLINK *)(HBINK,U32,S32))GetProcAddress(hBink, "[email protected]"); // use 1 for the first frame 93 qBinkGetKeyFrame = (U32 (RADEXPLINK *)(HBINK,U32,S32))GetProcAddress(hBink, "[email protected]"); 94 qBinkSetVideoOnOff = (S32 (RADEXPLINK *)(HBINK,S32))GetProcAddress(hBink, "[email protected]"); 95 qBinkSetSoundOnOff = (S32 (RADEXPLINK *)(HBINK,S32))GetProcAddress(hBink, "[email protected]"); 96 qBinkSetVolume = (void (RADEXPLINK *)(HBINK, U32, S32))GetProcAddress(hBink, "[email protected]"); 97 qBinkSetPan = (void (RADEXPLINK *)(HBINK,U32, S32))GetProcAddress(hBink, "[email protected]"); 98 qBinkSetMixBins = (void (RADEXPLINK *)(HBINK,U32, U32 PTR4*, U32))GetProcAddress(hBink, "[email protected]"); 99 qBinkSetMixBinVolumes = (void (RADEXPLINK *)(HBINK,U32, U32 PTR4*, S32 PTR4*, U32))GetProcAddress(hBink, "[email protected]"); 100 qBinkService = (void (RADEXPLINK *)(HBINK))GetProcAddress(hBink, "[email protected]"); 101 qBinkShouldSkip = (S32 (RADEXPLINK *)(HBINK))GetProcAddress(hBink, "[email protected]"); 102 qBinkGetPalette = (void (RADEXPLINK *)( void * ))GetProcAddress(hBink, "[email protected]"); 103 qBinkControlBackgroundIO = (S32 (RADEXPLINK *)(HBINK,U32))GetProcAddress(hBink, "[email protected]"); 104 qBinkOpenTrack = (HBINKTRACK (RADEXPLINK *)(HBINK,U32))GetProcAddress(hBink, "[email protected]"); 105 qBinkCloseTrack = (void (RADEXPLINK *)(HBINKTRACK))GetProcAddress(hBink, "[email protected]"); 106 qBinkGetTrackData = (U32 (RADEXPLINK *)(HBINKTRACK,void PTR4*))GetProcAddress(hBink, "[email protected]"); 107 qBinkGetTrackType = (U32 (RADEXPLINK *)(HBINK,U32))GetProcAddress(hBink, "[email protected]"); 108 qBinkGetTrackMaxSize = (U32 (RADEXPLINK *)(HBINK,U32))GetProcAddress(hBink, "[email protected]"); 109 qBinkGetTrackID = (U32 (RADEXPLINK *)(HBINK,U32))GetProcAddress(hBink, "[email protected]"); 110 qBinkGetSummary = (void (RADEXPLINK *)(HBINK,BINKSUMMARY PTR4*))GetProcAddress(hBink, "[email protected]"); 111 qBinkGetRealtime = (void (RADEXPLINK *)(HBINK,BINKREALTIME PTR4*,U32))GetProcAddress(hBink, "[email protected]"); 112 qBinkSetSoundTrack = (void (RADEXPLINK *)(U32, U32 PTR4*))GetProcAddress(hBink, "[email protected]"); 113 qBinkSetIO = (void (RADEXPLINK *)(BINKIOOPEN))GetProcAddress(hBink, "[email protected]"); 114 qBinkSetFrameRate = (void (RADEXPLINK *)(U32,U32))GetProcAddress(hBink, "[email protected]"); 115 qBinkSetSimulate = (void (RADEXPLINK *)(U32))GetProcAddress(hBink, "[email protected]"); 116 qBinkSetIOSize = (void (RADEXPLINK *)(U32))GetProcAddress(hBink, "[email protected]"); 117 qBinkSetSoundSystem = (S32 (RADEXPLINK *)(BINKSNDSYSOPEN, U32))GetProcAddress(hBink, "[email protected]"); 118 qBinkOpenDirectSound = (BINKSNDOPEN (RADEXPLINK *)(U32))GetProcAddress(hBink, "[email protected]"); // don‘t call directly 119 qBinkOpenWaveOut = (BINKSNDOPEN (RADEXPLINK *)(U32))GetProcAddress(hBink, "[email protected]"); // don‘t call directly 120 qBinkOpenMiles = (BINKSNDOPEN (RADEXPLINK *)(U32))GetProcAddress(hBink, "[email protected]"); // don‘t call directly 121 qBinkDX8SurfaceType = (S32 (RADEXPLINK *)(void*))GetProcAddress(hBink, "[email protected]"); 122 qBinkDX9SurfaceType = (S32 (RADEXPLINK *)(void*))GetProcAddress(hBink, "[email protected]"); 123 qBinkBufferOpen = (HBINKBUFFER (RADEXPLINK *)( void* /*HWND*/, U32, U32, U32))GetProcAddress(hBink, "[email protected]"); 124 qBinkBufferSetHWND = (S32 (RADEXPLINK *)( HBINKBUFFER, void* /*HWND*/))GetProcAddress(hBink, "[email protected]"); 125 qBinkDDSurfaceType = (S32 (RADEXPLINK *)(void PTR4*))GetProcAddress(hBink, "[email protected]"); 126 qBinkIsSoftwareCursor = (S32 (RADEXPLINK *)(void PTR4*, void* /*HCURSOR*/))GetProcAddress(hBink, "[email protected]"); 127 qBinkCheckCursor = (S32 (RADEXPLINK *)(void* /*HWND*/,S32,S32,S32,S32))GetProcAddress(hBink, "[email protected]"); 128 qBinkBufferSetDirectDraw = (S32 (RADEXPLINK *)(void PTR4*, void PTR4*))GetProcAddress(hBink, "[email protected]"); 129 qBinkBufferClose = (void (RADEXPLINK *)( HBINKBUFFER))GetProcAddress(hBink, "[email protected]"); 130 qBinkBufferLock = (S32 (RADEXPLINK *)( HBINKBUFFER))GetProcAddress(hBink, "[email protected]"); 131 qBinkBufferUnlock = (S32 (RADEXPLINK *)( HBINKBUFFER))GetProcAddress(hBink, "[email protected]"); 132 qBinkBufferSetResolution = (void (RADEXPLINK *)( S32, S32, S32))GetProcAddress(hBink, "[email protected]"); 133 qBinkBufferCheckWinPos = (void (RADEXPLINK *)( HBINKBUFFER, S32 PTR4*, S32 PTR4*))GetProcAddress(hBink, "[email protected]"); 134 qBinkBufferSetOffset = (S32 (RADEXPLINK *)( HBINKBUFFER, S32, S32))GetProcAddress(hBink, "[email protected]"); 135 qBinkBufferBlit = (void (RADEXPLINK *)( HBINKBUFFER, BINKRECT PTR4*, U32 ))GetProcAddress(hBink, "[email protected]"); 136 qBinkBufferSetScale = (S32 (RADEXPLINK *)( HBINKBUFFER, U32, U32))GetProcAddress(hBink, "[email protected]"); 137 qBinkBufferGetDescription = (char PTR4* (RADEXPLINK *)( HBINKBUFFER))GetProcAddress(hBink, "[email protected]"); 138 qBinkBufferGetError = (char PTR4* (RADEXPLINK *)())GetProcAddress(hBink, "[email protected]"); 139 qBinkRestoreCursor = (void (RADEXPLINK *)(S32))GetProcAddress(hBink, "[email protected]"); 140 qBinkBufferClear = (S32 (RADEXPLINK *)(HBINKBUFFER, U32))GetProcAddress(hBink, "[email protected]"); 141 qBinkSetMemory = (void (RADEXPLINK *)(BINKMEMALLOC,BINKMEMFREE))GetProcAddress(hBink, "[email protected]"); 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 <metahook.h> 2 3 #include "qbink.h" 4 #include "surface.h" 5 #include "qgl.h" 6 7 #include <math.h> 8 #include <vector.h> 9 10 #include "cbink.h" 11 12 CBink::CBink() 13 { 14 m_iTexID = 0; 15 m_hBink = NULL; 16 m_pszName = NULL; 17 m_iWidth = 0; 18 m_iHeight = 0; 19 m_pBuffer = NULL; 20 m_bPlay = false; 21 m_flStartTime = 0.0f; 22 m_iCurFrame = 0; 23 m_iLastFrame = 0; 24 } 25 26 CBink::~CBink() 27 { 28 Free(); 29 } 30 31 BOOL CBink::Load(char *pszFileName) 32 { 33 if (IsValid()) 34 return FALSE; 35 36 BINKSNDSYSOPEN pSoundSystem = (BINKSNDSYSOPEN)qBinkOpenWaveOut; 37 qBinkSetSoundSystem(pSoundSystem, NULL); 38 39 m_hBink = qBinkOpen(pszFileName, NULL); 40 41 if (!m_hBink) 42 return FALSE; 43 44 if (!m_pszName) 45 m_pszName = (char *)malloc(strlen(pszFileName) * sizeof(char) + 1); 46 47 strcpy(m_pszName, pszFileName); 48 49 if (!m_iTexID) 50 m_iTexID = g_pSurface->CreateNewTextureID(); 51 52 m_iWidth = m_hBink->Width; 53 m_iHeight = m_hBink->Height; 54 55 DWORD dwBufferSize = m_iWidth * m_iHeight * 3; 56 57 m_pBuffer = (BYTE *)malloc(dwBufferSize); 58 m_bPlay = false; 59 m_flStartTime = 0.0f; 60 m_iCurFrame = 0; 61 m_iLastFrame = 0; 62 63 qglBindTexture(GL_TEXTURE_2D, m_iTexID); 64 qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 65 qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 66 67 memset(m_pBuffer, 0, dwBufferSize); 68 qglTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_iWidth, m_iHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, m_pBuffer); 69 70 qBinkGoto(m_hBink, 1, 0); 71 72 return TRUE; 73 } 74 75 void CBink::SetPos(Vector vec1, Vector vec2, Vector vec3, Vector vec4) 76 { 77 if (!IsValid()) 78 return; 79 80 m_vecRect[0] = vec1; 81 m_vecRect[1] = vec2; 82 m_vecRect[2] = vec3; 83 m_vecRect[3] = vec4; 84 } 85 86 void CBink::Draw(void) 87 { 88 if (!IsValid()) 89 return; 90 91 if (!m_bPlay) 92 return; 93 94 float flCurTime = gEngfuncs.GetClientTime(); 95 96 if (m_iLastFrame < m_iCurFrame) 97 { 98 int iSub = m_iCurFrame - m_iLastFrame; 99 100 for (int i = 0; i < iSub; ++i) 101 { 102 qBinkDoFrame(m_hBink); 103 qBinkNextFrame(m_hBink); 104 } 105 106 qBinkCopyToBuffer(m_hBink, m_pBuffer, m_iWidth * 3, m_iHeight, 0, 0, BINKSURFACE24R); 107 108 qglBindTexture(GL_TEXTURE_2D, m_iTexID); 109 qglTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_iWidth, m_iHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, m_pBuffer); 110 111 m_iLastFrame = m_iCurFrame; 112 } 113 114 if (m_iCurFrame > 0) 115 { 116 qglEnable(GL_TEXTURE_2D); 117 qglDisable(GL_CULL_FACE); 118 119 qglEnable(GL_BLEND); 120 qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 121 122 qglBindTexture(GL_TEXTURE_2D, m_iTexID); 123 qglColor4f(1.0f, 1.0f, 1.0f, 1.0f); 124 125 qglBegin(GL_QUADS); 126 qglTexCoord2f(0.0f, 0.0f); 127 qglVertex3f(m_vecRect[0].x, m_vecRect[0].y, m_vecRect[0].z); 128 qglTexCoord2f(1.0f, 0.0f); 129 qglVertex3f(m_vecRect[1].x, m_vecRect[1].y, m_vecRect[1].z); 130 qglTexCoord2f(1.0f, 1.0f); 131 qglVertex3f(m_vecRect[2].x, m_vecRect[2].y, m_vecRect[2].z); 132 qglTexCoord2f(0.0f, 1.0f); 133 qglVertex3f(m_vecRect[3].x, m_vecRect[3].y, m_vecRect[3].z); 134 qglEnd(); 135 136 qglEnable(GL_CULL_FACE); 137 } 138 139 float flPlayTime, flSubTime, flRot; 140 int iDoFrame; 141 142 flPlayTime = m_hBink->Frames * ((float)m_hBink->FrameRateDiv / (float)m_hBink->FrameRate); 143 flSubTime = flCurTime - m_flStartTime; 144 flRot = flSubTime / flPlayTime; 145 146 iDoFrame = (int)((float)m_hBink->Frames * flRot); 147 148 m_iCurFrame = iDoFrame; 149 150 if (m_iCurFrame > (int)m_hBink->Frames) 151 Stop(); 152 } 153 154 bool CBink::IsValid(void) 155 { 156 return m_pBuffer != NULL; 157 } 158 159 char *CBink::GetName(void) 160 { 161 return m_pszName; 162 } 163 164 void CBink::Play(void) 165 { 166 if (!IsValid()) 167 return; 168 169 m_bPlay = true; 170 m_flStartTime = gEngfuncs.GetClientTime(); 171 m_iCurFrame = 0; 172 m_iLastFrame = 0; 173 } 174 175 void CBink::Pause(void) 176 { 177 if (!IsValid()) 178 return; 179 } 180 181 void CBink::Stop(void) 182 { 183 if (!IsValid()) 184 return; 185 186 m_bPlay = false; 187 } 188 189 void CBink::Free(void) 190 { 191 if (!IsValid()) 192 return; 193 194 Stop(); 195 196 if (m_hBink) 197 qBinkClose(m_hBink); 198 199 if (m_pszName) 200 free(m_pszName); 201 202 if (m_pBuffer) 203 free(m_pBuffer); 204 205 m_hBink = NULL; 206 m_pszName = NULL; 207 m_iWidth = 0; 208 m_iHeight = 0; 209 m_pBuffer = NULL; 210 }
时间: 2024-10-27 12:15:27