| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- #include "../stdafx.h"
- #include <iostream>
- #include "CVideoHandler.h"
- #include "SDL.h"
- void DLLHandler::Instantiate(const char *filename)
- {
- #ifdef WIN32
- dll = LoadLibraryA(filename);
- #else
- dll = dlopen(filename,RTLD_LOCAL | RTLD_LAZY);
- #endif
- }
- const char *DLLHandler::GetLibExtension()
- {
- #ifdef WIN32
- return "dll";
- #elif defined(__APPLE__)
- return "dylib";
- #else
- return "so";
- #endif
- }
- void *DLLHandler::FindAddress234(const char *symbol)
- {
- #ifdef WIN32
- if ((int)symbol == 0x00001758)
- return NULL;
- std::cout<<"co ja tu robie"<<std::endl;
- return (void*) GetProcAddress(dll,symbol);
- #else
- return (void *)dlsym(dll, symbol);
- #endif
- }
- DLLHandler::~DLLHandler()
- {
- #ifdef WIN32
- FreeLibrary(dll);
- #else
- dlclose(dll);
- #endif
- }
- CBIKHandler::CBIKHandler()
- {
- ourLib.Instantiate("BINKW32.DLL");
- newmode=-1;
- waveOutOpen=0;
- ///waveOutOpen = ourLib.FindAddress("_BinkOpenWaveOut@4");
- }
- int readNormalNr2 (unsigned char* bufor, int &iter, int bytCon)
- {
- int ret=0;
- int amp=1;
- for (int i=iter; i<iter+bytCon; i++)
- {
- ret+=bufor[i]*amp;
- amp<<=8;
- }
- iter+=bytCon;
- return ret;
- }
- void RaiseLastOSErrorAt(char * offset)
- {
- #ifdef WIN32
- int * lastError = new int;
- std::exception * error;
- *lastError = GetLastError();
- if (*lastError)
- throw lastError;
- #else
- throw new std::exception();
- #endif
- }
- //var
- // LastError: Integer;
- // Error: EOSError;
- //begin
- // LastError := GetLastError;
- // if LastError <> 0 then
- // Error := EOSError.CreateResFmt(@SOSError, [LastError,
- // SysErrorMessage(LastError)])
- // else
- // Error := EOSError.CreateRes(@SUnkOSError);
- // Error.ErrorCode := LastError;
- // raise Error at Offset;
- //end;
- //void RSRaiseLastOSError()
- //{
- // __asm
- // {
- // mov eax, [esp]
- // sub eax, 5
- // jmp RaiseLastOSErrorAt
- // }
- //}
- //int RSWin32Check(int CheckForZero)
- //{
- // __asm
- // {
- // test eax, eax
- // jz RSRaiseLastOSError
- // }
- //}
- void CBIKHandler::open(std::string name)
- {
- #ifdef WIN32
- hBinkFile = CreateFile
- (
- L"CSECRET.BIK", // file name
- GENERIC_READ, // access mode
- FILE_SHARE_READ, // share mode
- NULL, // Security Descriptor
- OPEN_EXISTING, // how to create
- FILE_ATTRIBUTE_NORMAL,//FILE_FLAG_SEQUENTIAL_SCAN, // file attributes
- 0 // handle to template file
- );
- //RSWin32Check(hBinkFile!=INVALID_HANDLE_VALUE);
- if(hBinkFile == INVALID_HANDLE_VALUE)
- {
- printf("failed to open \"%s\"\n", name.c_str());
- return ;
- }
- try
- {
- BinkGetError = ourLib.FindAddress234("_BinkGetError@0");
- BinkOpen = ourLib.FindAddress234("_BinkOpen@8");
- if (!waveOutOpen)
- {
- BinkSetSoundSystem = ourLib.FindAddress234("_BinkSetSoundSystem@8");
- ((void(*)(void*,void*))BinkSetSoundSystem)(waveOutOpen,NULL);
- }
- std::cout<<"punkt kulminacyjny... "<<std::flush;
- hBink = ((HBINK(*)(HANDLE)) BinkOpen)(hBinkFile);
- width = hBink->width;
- height = hBink->height;
- BITMAP gg;
- gg.bmWidth=width;
- gg.bmHeight=height;
- gg.bmBitsPixel=24;
- gg.bmPlanes=1;
- gg.bmWidthBytes=3*width;
- gg.bmBits = new unsigned char[width*height*(gg.bmBitsPixel/8)];
- //HBITMAP bitmapa = CreateBitmap(width, height,1,24,NULL);
- std::cout<<"przeszlo!"<<std::endl;
- }
- catch(...)
- {
- printf("cos nie tak");
- }
- #endif
- }
- //void CBIKHandler::close()
- //{
- // void *binkClose;
- // binkClose = ourLib.FindAddress234("_BinkClose@4");
- // (( void(*)() ) binkClose )();
- //
- //}
- //void CBIKHandler::preparePic()
- //procedure TRSBinkPlayer.PreparePic(b: TBitmap);
- //var j:int; Pal:array[0..256] of int;
- //begin
- // inherited;
- // case RSGetPixelFormat(b) of
- // pf24bit, pf32bit, pf15bit, pf16bit:;
- //
- // pf8bit:
- // begin
- // if @BinkGetPalette=nil then
- // @BinkGetPalette:=GetProcAddress(FLib, '_BinkGetPalette@4');
- // if @BinkGetPalette<>nil then
- // begin
- // with PLogPalette(@Pal)^ do
- // begin
- // palVersion:=$300;
- // palNumEntries:=BinkGetPalette(@palPalEntry);
- // for j:=0 to palNumEntries-1 do
- // int(palPalEntry[j]):=RSSwapColor(int(palPalEntry[j]));
- // end;
- // b.Palette:=CreatePalette(PLogPalette(@Pal)^);
- // end else
- // b.PixelFormat:=pf24bit;
- // end;
- //
- // else
- // b.PixelFormat:=pf24bit;
- // end
- //
- //end;
|