CVideoHandler.cpp 4.3 KB

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