CVideoHandler.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #include "../stdafx.h"
  2. #include <iostream>
  3. #include "CVideoHandler.h"
  4. #include "SDL.h"
  5. void DLLHandler::Instantiate(const char *filename)
  6. {
  7. dll = LoadLibraryA(filename);
  8. }
  9. const char *DLLHandler::GetLibExtension()
  10. {
  11. #ifdef WIN32
  12. return "dll";
  13. #elif defined(__APPLE__)
  14. return "dylib";
  15. #else
  16. return "so";
  17. #endif
  18. }
  19. void *DLLHandler::FindAddress234(const char *symbol)
  20. {
  21. if ((int)symbol == 0x00001758)
  22. return NULL;
  23. std::cout<<"co ja tu robie"<<std::endl;
  24. return (void*) GetProcAddress(dll,symbol);
  25. }
  26. DLLHandler::~DLLHandler()
  27. {
  28. FreeLibrary(dll);
  29. }
  30. CBIKHandler::CBIKHandler()
  31. {
  32. ourLib.Instantiate("BINKW32.DLL");
  33. newmode=-1;
  34. waveOutOpen=0;
  35. ///waveOutOpen = ourLib.FindAddress("_BinkOpenWaveOut@4");
  36. }
  37. int readNormalNr2 (unsigned char* bufor, int &iter, int bytCon)
  38. {
  39. int ret=0;
  40. int amp=1;
  41. for (int i=iter; i<iter+bytCon; i++)
  42. {
  43. ret+=bufor[i]*amp;
  44. amp<<=8;
  45. }
  46. iter+=bytCon;
  47. return ret;
  48. }
  49. void RaiseLastOSErrorAt(char * offset)
  50. {
  51. int * lastError = new int;
  52. std::exception * error;
  53. *lastError = GetLastError();
  54. if (*lastError)
  55. throw lastError;
  56. }
  57. //var
  58. // LastError: Integer;
  59. // Error: EOSError;
  60. //begin
  61. // LastError := GetLastError;
  62. // if LastError <> 0 then
  63. // Error := EOSError.CreateResFmt(@SOSError, [LastError,
  64. // SysErrorMessage(LastError)])
  65. // else
  66. // Error := EOSError.CreateRes(@SUnkOSError);
  67. // Error.ErrorCode := LastError;
  68. // raise Error at Offset;
  69. //end;
  70. //void RSRaiseLastOSError()
  71. //{
  72. // __asm
  73. // {
  74. // mov eax, [esp]
  75. // sub eax, 5
  76. // jmp RaiseLastOSErrorAt
  77. // }
  78. //}
  79. //int RSWin32Check(int CheckForZero)
  80. //{
  81. // __asm
  82. // {
  83. // test eax, eax
  84. // jz RSRaiseLastOSError
  85. // }
  86. //}
  87. void CBIKHandler::open(std::string name)
  88. {
  89. hBinkFile = CreateFile
  90. (
  91. L"CSECRET.BIK", // file name
  92. GENERIC_READ, // access mode
  93. FILE_SHARE_READ, // share mode
  94. NULL, // Security Descriptor
  95. OPEN_EXISTING, // how to create
  96. FILE_ATTRIBUTE_NORMAL,//FILE_FLAG_SEQUENTIAL_SCAN, // file attributes
  97. 0 // handle to template file
  98. );
  99. //RSWin32Check(hBinkFile!=INVALID_HANDLE_VALUE);
  100. if(hBinkFile == INVALID_HANDLE_VALUE)
  101. {
  102. printf("failed to open \"%s\"\n", name.c_str());
  103. return ;
  104. }
  105. try
  106. {
  107. BinkGetError = ourLib.FindAddress234("_BinkGetError@0");
  108. BinkOpen = ourLib.FindAddress234("_BinkOpen@8");
  109. if (!waveOutOpen)
  110. {
  111. BinkSetSoundSystem = ourLib.FindAddress234("_BinkSetSoundSystem@8");
  112. ((void(*)(void*,void*))BinkSetSoundSystem)(waveOutOpen,NULL);
  113. }
  114. std::cout<<"punkt kulminacyjny... "<<std::flush;
  115. hBink = ((HBINK(*)(HANDLE)) BinkOpen)(hBinkFile);
  116. width = hBink->width;
  117. height = hBink->height;
  118. BITMAP gg;
  119. gg.bmWidth=width;
  120. gg.bmHeight=height;
  121. gg.bmBitsPixel=24;
  122. gg.bmPlanes=1;
  123. gg.bmWidthBytes=3*width;
  124. gg.bmBits = new unsigned char[width*height*(gg.bmBitsPixel/8)];
  125. //HBITMAP bitmapa = CreateBitmap(width, height,1,24,NULL);
  126. std::cout<<"przeszlo!"<<std::endl;
  127. }
  128. catch(...)
  129. {
  130. printf("cos nie tak");
  131. }
  132. }
  133. //void CBIKHandler::close()
  134. //{
  135. // void *binkClose;
  136. // binkClose = ourLib.FindAddress234("_BinkClose@4");
  137. // (( void(*)() ) binkClose )();
  138. //
  139. //}
  140. //void CBIKHandler::preparePic()
  141. //procedure TRSBinkPlayer.PreparePic(b: TBitmap);
  142. //var j:int; Pal:array[0..256] of int;
  143. //begin
  144. // inherited;
  145. // case RSGetPixelFormat(b) of
  146. // pf24bit, pf32bit, pf15bit, pf16bit:;
  147. //
  148. // pf8bit:
  149. // begin
  150. // if @BinkGetPalette=nil then
  151. // @BinkGetPalette:=GetProcAddress(FLib, '_BinkGetPalette@4');
  152. // if @BinkGetPalette<>nil then
  153. // begin
  154. // with PLogPalette(@Pal)^ do
  155. // begin
  156. // palVersion:=$300;
  157. // palNumEntries:=BinkGetPalette(@palPalEntry);
  158. // for j:=0 to palNumEntries-1 do
  159. // int(palPalEntry[j]):=RSSwapColor(int(palPalEntry[j]));
  160. // end;
  161. // b.Palette:=CreatePalette(PLogPalette(@Pal)^);
  162. // end else
  163. // b.PixelFormat:=pf24bit;
  164. // end;
  165. //
  166. // else
  167. // b.PixelFormat:=pf24bit;
  168. // end
  169. //
  170. //end;