2007-08-08 22:28:56 +03:00
|
|
|
#include "stdafx.h"
|
2007-08-17 20:42:21 +03:00
|
|
|
#include <iostream>
|
2007-08-08 22:28:56 +03:00
|
|
|
#include "CVideoHandler.h"
|
2007-08-17 20:42:21 +03:00
|
|
|
#include "SDL.h"
|
2007-08-08 22:28:56 +03:00
|
|
|
void DLLHandler::Instantiate(const char *filename)
|
|
|
|
{
|
|
|
|
dll = LoadLibraryA(filename);
|
|
|
|
}
|
|
|
|
const char *DLLHandler::GetLibExtension()
|
|
|
|
{
|
|
|
|
#ifdef WIN32
|
|
|
|
return "dll";
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
return "dylib";
|
|
|
|
#else
|
|
|
|
return "so";
|
|
|
|
#endif
|
|
|
|
}
|
2007-08-17 20:42:21 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void *DLLHandler::FindAddress234(const char *symbol)
|
2007-08-08 22:28:56 +03:00
|
|
|
{
|
2007-08-17 20:42:21 +03:00
|
|
|
if ((int)symbol == 0x00001758)
|
|
|
|
return NULL;
|
|
|
|
std::cout<<"co ja tu robie"<<std::endl;
|
2007-08-08 22:28:56 +03:00
|
|
|
return (void*) GetProcAddress(dll,symbol);
|
|
|
|
}
|
|
|
|
DLLHandler::~DLLHandler()
|
|
|
|
{
|
|
|
|
FreeLibrary(dll);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CBIKHandler::CBIKHandler()
|
|
|
|
{
|
|
|
|
ourLib.Instantiate("BINKW32.DLL");
|
|
|
|
newmode=-1;
|
2007-08-17 20:42:21 +03:00
|
|
|
waveOutOpen=0;
|
2007-08-08 22:28:56 +03:00
|
|
|
///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*=256;
|
|
|
|
}
|
|
|
|
iter+=bytCon;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-08-17 20:42:21 +03:00
|
|
|
void RaiseLastOSErrorAt(char * offset)
|
|
|
|
{
|
|
|
|
int * lastError = new int;
|
|
|
|
std::exception * error;
|
|
|
|
*lastError = GetLastError();
|
|
|
|
if (*lastError)
|
|
|
|
throw lastError;
|
|
|
|
|
2007-08-08 22:28:56 +03:00
|
|
|
|
2007-08-17 20:42:21 +03:00
|
|
|
}
|
|
|
|
//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
|
|
|
|
// }
|
|
|
|
//}
|
2007-08-08 22:28:56 +03:00
|
|
|
void CBIKHandler::open(std::string name)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-08-17 20:42:21 +03:00
|
|
|
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 ;
|
|
|
|
}
|
2007-08-08 22:28:56 +03:00
|
|
|
|
|
|
|
|
2007-08-17 20:42:21 +03:00
|
|
|
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");
|
|
|
|
}
|
2007-08-08 22:28:56 +03:00
|
|
|
}
|
2007-08-17 20:42:21 +03:00
|
|
|
//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;
|