Merge pull request #7 from Fire-Head/master

updates/fixes
This commit is contained in:
Fire_Head 2019-06-03 17:08:24 +03:00 committed by GitHub
commit 8ec8c0c5db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 275 additions and 76 deletions

View File

@ -10,7 +10,7 @@
#include <stdint.h> #include <stdint.h>
#include <math.h> #include <math.h>
#include <assert.h> //#include <assert.h>
#include <new> #include <new>
#ifdef WITHD3D #ifdef WITHD3D
@ -125,7 +125,7 @@ inline float sq(float x) { return x*x; }
#define DEGTORAD(x) ((x) * PI / 180.0f) #define DEGTORAD(x) ((x) * PI / 180.0f)
#define RADTODEG(x) ((x) * 180.0f / PI) #define RADTODEG(x) ((x) * 180.0f / PI)
#if USE_PS2_RAND == TRUE #ifdef USE_PS2_RAND
#define MYRAND_MAX 65535 #define MYRAND_MAX 65535
#else #else
#define MYRAND_MAX 32767 #define MYRAND_MAX 32767
@ -134,8 +134,15 @@ inline float sq(float x) { return x*x; }
int myrand(void); int myrand(void);
void mysrand(unsigned int seed); void mysrand(unsigned int seed);
#define debug(f, ...) printf("[DBG]: " f "\n", __VA_ARGS__) void re3_debug(char *format, ...);
#define DEV(f, ...) printf("[DEV]: " f "", __VA_ARGS__) void re3_trace(const char *filename, unsigned int lineno, const char *func, char *format, ...);
void re3_assert(const char *expr, const char *filename, unsigned int lineno, const char *func);
#define debug(f, ...) re3_debug("[DBG]: " f, __VA_ARGS__)
#define DEV(f, ...) re3_debug("[DEV]: " f, __VA_ARGS__)
#define TRACE(f, ...) re3_trace(__FILE__, __LINE__, __FUNCTION__, f, __VA_ARGS__)
#define assert(_Expression) (void)( (!!(_Expression)) || (re3_assert(#_Expression, __FILE__, __LINE__, __FUNCTION__), 0) )
#define ASSERT assert #define ASSERT assert
#define _TODO(x) #define _TODO(x)

View File

@ -57,7 +57,10 @@ enum Config {
NUMPOINTLIGHTS = 32 NUMPOINTLIGHTS = 32
}; };
#define GTA3_1_1_PATCH FALSE #define GTA3_1_1_PATCH
#define USE_PS2_RAND FALSE #define USE_PS2_RAND
#define RANDOMSPLASH #define RANDOMSPLASH
#define CHATTYSPLASH #define CHATTYSPLASH
//#define FIX_BUGS
//#define NO_CDCHECK
#define NO_MOVIES

View File

@ -1,4 +1,5 @@
#include <direct.h> #include <direct.h>
#include <csignal>
#include <Windows.h> #include <Windows.h>
#include "common.h" #include "common.h"
#include "patcher.h" #include "patcher.h"
@ -20,7 +21,7 @@ WRAPPER void gtadelete(void *p) { EAXJMP(0x5A07E0); }
void *operator new(size_t sz) { return gtanew(sz); } void *operator new(size_t sz) { return gtanew(sz); }
void operator delete(void *ptr) noexcept { gtadelete(ptr); } void operator delete(void *ptr) noexcept { gtadelete(ptr); }
#if USE_PS2_RAND == TRUE #ifdef USE_PS2_RAND
unsigned __int64 myrand_seed = 1; unsigned __int64 myrand_seed = 1;
#else #else
unsigned long int myrand_seed = 1; unsigned long int myrand_seed = 1;
@ -29,7 +30,7 @@ unsigned long int myrand_seed = 1;
int int
myrand(void) myrand(void)
{ {
#if USE_PS2_RAND == TRUE #ifdef USE_PS2_RAND
// Use our own implementation of rand, stolen from PS2 // Use our own implementation of rand, stolen from PS2
myrand_seed = 0x5851F42D4C957F2D * myrand_seed + 1; myrand_seed = 0x5851F42D4C957F2D * myrand_seed + 1;
return ((myrand_seed >> 32) & 0x7FFFFFFF); return ((myrand_seed >> 32) & 0x7FFFFFFF);
@ -136,6 +137,79 @@ HeadlightsFix_DontLimit:
} }
} }
const int re3_buffsize = 1024;
static char re3_buff[re3_buffsize];
void re3_assert(const char *expr, const char *filename, unsigned int lineno, const char *func)
{
int nCode;
strcpy_s(re3_buff, re3_buffsize, "Assertion failed!" );
strcat_s(re3_buff, re3_buffsize, "\n" );
strcat_s(re3_buff, re3_buffsize, "File: ");
strcat_s(re3_buff, re3_buffsize, filename );
strcat_s(re3_buff, re3_buffsize, "\n" );
strcat_s(re3_buff, re3_buffsize, "Line: " );
_itoa_s( lineno, re3_buff + strlen(re3_buff), re3_buffsize - strlen(re3_buff), 10 );
strcat_s(re3_buff, re3_buffsize, "\n");
strcat_s(re3_buff, re3_buffsize, "Function: ");
strcat_s(re3_buff, re3_buffsize, func );
strcat_s(re3_buff, re3_buffsize, "\n" );
strcat_s(re3_buff, re3_buffsize, "Expression: ");
strcat_s(re3_buff, re3_buffsize, expr);
strcat_s(re3_buff, re3_buffsize, "\n");
strcat_s(re3_buff, re3_buffsize, "\n" );
strcat_s(re3_buff, re3_buffsize, "(Press Retry to debug the application)");
nCode = ::MessageBoxA(NULL, re3_buff, "RE3 Assertion Failed!",
MB_ABORTRETRYIGNORE|MB_ICONHAND|MB_SETFOREGROUND|MB_TASKMODAL);
if (nCode == IDABORT)
{
raise(SIGABRT);
_exit(3);
}
if (nCode == IDRETRY)
{
__debugbreak();
return;
}
if (nCode == IDIGNORE)
return;
abort();
}
void re3_debug(char *format, ...)
{
va_list va;
va_start(va, format);
vsprintf_s(re3_buff, re3_buffsize, format, va);
va_end(va);
printf("%s\n", re3_buff);
}
void re3_trace(const char *filename, unsigned int lineno, const char *func, char *format, ...)
{
char buff[re3_buffsize *2];
va_list va;
va_start(va, format);
vsprintf_s(re3_buff, re3_buffsize, format, va);
va_end(va);
sprintf_s(buff, re3_buffsize * 2, "[%s.%s:%d]: %s", filename, func, lineno, re3_buff);
OutputDebugStringA(buff);
}
void void
patch() patch()

View File

@ -587,7 +587,7 @@ void CParticle::Shutdown()
for ( Int32 i = 0; i < MAX_SMOKE_FILES; i++ ) for ( Int32 i = 0; i < MAX_SMOKE_FILES; i++ )
{ {
RwTextureDestroy(gpSmokeTex[i]); RwTextureDestroy(gpSmokeTex[i]);
#if GTA3_1_1_PATCH == TRUE #ifdef GTA3_1_1_PATCH
gpSmokeTex[i] = NULL; gpSmokeTex[i] = NULL;
#endif #endif
} }
@ -595,7 +595,7 @@ void CParticle::Shutdown()
for ( Int32 i = 0; i < MAX_SMOKE2_FILES; i++ ) for ( Int32 i = 0; i < MAX_SMOKE2_FILES; i++ )
{ {
RwTextureDestroy(gpSmoke2Tex[i]); RwTextureDestroy(gpSmoke2Tex[i]);
#if GTA3_1_1_PATCH == TRUE #ifdef GTA3_1_1_PATCH
gpSmoke2Tex[i] = NULL; gpSmoke2Tex[i] = NULL;
#endif #endif
} }
@ -603,7 +603,7 @@ void CParticle::Shutdown()
for ( Int32 i = 0; i < MAX_RUBBER_FILES; i++ ) for ( Int32 i = 0; i < MAX_RUBBER_FILES; i++ )
{ {
RwTextureDestroy(gpRubberTex[i]); RwTextureDestroy(gpRubberTex[i]);
#if GTA3_1_1_PATCH == TRUE #ifdef GTA3_1_1_PATCH
gpRubberTex[i] = NULL; gpRubberTex[i] = NULL;
#endif #endif
} }
@ -611,7 +611,7 @@ void CParticle::Shutdown()
for ( Int32 i = 0; i < MAX_RAINSPLASH_FILES; i++ ) for ( Int32 i = 0; i < MAX_RAINSPLASH_FILES; i++ )
{ {
RwTextureDestroy(gpRainSplashTex[i]); RwTextureDestroy(gpRainSplashTex[i]);
#if GTA3_1_1_PATCH == TRUE #ifdef GTA3_1_1_PATCH
gpRainSplashTex[i] = NULL; gpRainSplashTex[i] = NULL;
#endif #endif
} }
@ -619,7 +619,7 @@ void CParticle::Shutdown()
for ( Int32 i = 0; i < MAX_WATERSPRAY_FILES; i++ ) for ( Int32 i = 0; i < MAX_WATERSPRAY_FILES; i++ )
{ {
RwTextureDestroy(gpWatersprayTex[i]); RwTextureDestroy(gpWatersprayTex[i]);
#if GTA3_1_1_PATCH == TRUE #ifdef GTA3_1_1_PATCH
gpWatersprayTex[i] = NULL; gpWatersprayTex[i] = NULL;
#endif #endif
} }
@ -627,7 +627,7 @@ void CParticle::Shutdown()
for ( Int32 i = 0; i < MAX_EXPLOSIONMEDIUM_FILES; i++ ) for ( Int32 i = 0; i < MAX_EXPLOSIONMEDIUM_FILES; i++ )
{ {
RwTextureDestroy(gpExplosionMediumTex[i]); RwTextureDestroy(gpExplosionMediumTex[i]);
#if GTA3_1_1_PATCH == TRUE #ifdef GTA3_1_1_PATCH
gpExplosionMediumTex[i] = NULL; gpExplosionMediumTex[i] = NULL;
#endif #endif
} }
@ -635,7 +635,7 @@ void CParticle::Shutdown()
for ( Int32 i = 0; i < MAX_GUNFLASH_FILES; i++ ) for ( Int32 i = 0; i < MAX_GUNFLASH_FILES; i++ )
{ {
RwTextureDestroy(gpGunFlashTex[i]); RwTextureDestroy(gpGunFlashTex[i]);
#if GTA3_1_1_PATCH == TRUE #ifdef GTA3_1_1_PATCH
gpGunFlashTex[i] = NULL; gpGunFlashTex[i] = NULL;
#endif #endif
} }
@ -643,7 +643,7 @@ void CParticle::Shutdown()
for ( Int32 i = 0; i < MAX_RAINDROP_FILES; i++ ) for ( Int32 i = 0; i < MAX_RAINDROP_FILES; i++ )
{ {
RwTextureDestroy(gpRainDropTex[i]); RwTextureDestroy(gpRainDropTex[i]);
#if GTA3_1_1_PATCH == TRUE #ifdef GTA3_1_1_PATCH
gpRainDropTex[i] = NULL; gpRainDropTex[i] = NULL;
#endif #endif
} }
@ -651,7 +651,7 @@ void CParticle::Shutdown()
for ( Int32 i = 0; i < MAX_RAINSPLASHUP_FILES; i++ ) for ( Int32 i = 0; i < MAX_RAINSPLASHUP_FILES; i++ )
{ {
RwTextureDestroy(gpRainSplashupTex[i]); RwTextureDestroy(gpRainSplashupTex[i]);
#if GTA3_1_1_PATCH == TRUE #ifdef GTA3_1_1_PATCH
gpRainSplashupTex[i] = NULL; gpRainSplashupTex[i] = NULL;
#endif #endif
} }
@ -659,7 +659,7 @@ void CParticle::Shutdown()
for ( Int32 i = 0; i < MAX_BIRDFRONT_FILES; i++ ) for ( Int32 i = 0; i < MAX_BIRDFRONT_FILES; i++ )
{ {
RwTextureDestroy(gpBirdfrontTex[i]); RwTextureDestroy(gpBirdfrontTex[i]);
#if GTA3_1_1_PATCH == TRUE #ifdef GTA3_1_1_PATCH
gpBirdfrontTex[i] = NULL; gpBirdfrontTex[i] = NULL;
#endif #endif
} }
@ -667,7 +667,7 @@ void CParticle::Shutdown()
for ( Int32 i = 0; i < MAX_CARDEBRIS_FILES; i++ ) for ( Int32 i = 0; i < MAX_CARDEBRIS_FILES; i++ )
{ {
RwTextureDestroy(gpCarDebrisTex[i]); RwTextureDestroy(gpCarDebrisTex[i]);
#if GTA3_1_1_PATCH == TRUE #ifdef GTA3_1_1_PATCH
gpCarDebrisTex[i] = NULL; gpCarDebrisTex[i] = NULL;
#endif #endif
} }
@ -675,78 +675,78 @@ void CParticle::Shutdown()
for ( Int32 i = 0; i < MAX_CARSPLASH_FILES; i++ ) for ( Int32 i = 0; i < MAX_CARSPLASH_FILES; i++ )
{ {
RwTextureDestroy(gpCarSplashTex[i]); RwTextureDestroy(gpCarSplashTex[i]);
#if GTA3_1_1_PATCH == TRUE #ifdef GTA3_1_1_PATCH
gpCarSplashTex[i] = NULL; gpCarSplashTex[i] = NULL;
#endif #endif
} }
RwTextureDestroy(gpFlame1Tex); RwTextureDestroy(gpFlame1Tex);
#if GTA3_1_1_PATCH == TRUE #ifdef GTA3_1_1_PATCH
gpFlame1Tex = NULL; gpFlame1Tex = NULL;
#endif #endif
RwTextureDestroy(gpFlame5Tex); RwTextureDestroy(gpFlame5Tex);
#if GTA3_1_1_PATCH == TRUE #ifdef GTA3_1_1_PATCH
gpFlame5Tex = NULL; gpFlame5Tex = NULL;
#endif #endif
RwTextureDestroy(gpRainDropSmallTex); RwTextureDestroy(gpRainDropSmallTex);
#if GTA3_1_1_PATCH == TRUE #ifdef GTA3_1_1_PATCH
gpRainDropSmallTex = NULL; gpRainDropSmallTex = NULL;
#endif #endif
RwTextureDestroy(gpBloodTex); RwTextureDestroy(gpBloodTex);
#if GTA3_1_1_PATCH == TRUE #ifdef GTA3_1_1_PATCH
gpBloodTex = NULL; gpBloodTex = NULL;
#endif #endif
RwTextureDestroy(gpLeafTex); RwTextureDestroy(gpLeafTex);
#if GTA3_1_1_PATCH == TRUE #ifdef GTA3_1_1_PATCH
gpLeafTex = NULL; gpLeafTex = NULL;
#endif #endif
RwTextureDestroy(gpCloudTex1); RwTextureDestroy(gpCloudTex1);
#if GTA3_1_1_PATCH == TRUE #ifdef GTA3_1_1_PATCH
gpCloudTex1 = NULL; gpCloudTex1 = NULL;
#endif #endif
RwTextureDestroy(gpCloudTex4); RwTextureDestroy(gpCloudTex4);
#if GTA3_1_1_PATCH == TRUE #ifdef GTA3_1_1_PATCH
gpCloudTex4 = NULL; gpCloudTex4 = NULL;
#endif #endif
RwTextureDestroy(gpBloodSmallTex); RwTextureDestroy(gpBloodSmallTex);
#if GTA3_1_1_PATCH == TRUE #ifdef GTA3_1_1_PATCH
gpBloodSmallTex = NULL; gpBloodSmallTex = NULL;
#endif #endif
RwTextureDestroy(gpGungeTex); RwTextureDestroy(gpGungeTex);
#if GTA3_1_1_PATCH == TRUE #ifdef GTA3_1_1_PATCH
gpGungeTex = NULL; gpGungeTex = NULL;
#endif #endif
RwTextureDestroy(gpCollisionSmokeTex); RwTextureDestroy(gpCollisionSmokeTex);
#if GTA3_1_1_PATCH == TRUE #ifdef GTA3_1_1_PATCH
gpCollisionSmokeTex = NULL; gpCollisionSmokeTex = NULL;
#endif #endif
RwTextureDestroy(gpBulletHitTex); RwTextureDestroy(gpBulletHitTex);
#if GTA3_1_1_PATCH == TRUE #ifdef GTA3_1_1_PATCH
gpBulletHitTex = NULL; gpBulletHitTex = NULL;
#endif #endif
RwTextureDestroy(gpGunShellTex); RwTextureDestroy(gpGunShellTex);
#if GTA3_1_1_PATCH == TRUE #ifdef GTA3_1_1_PATCH
gpGunShellTex = NULL; gpGunShellTex = NULL;
#endif #endif
RwTextureDestroy(gpWakeOldTex); RwTextureDestroy(gpWakeOldTex);
#if GTA3_1_1_PATCH == TRUE #ifdef GTA3_1_1_PATCH
gpWakeOldTex = NULL; gpWakeOldTex = NULL;
#endif #endif
RwTextureDestroy(gpPointlightTex); RwTextureDestroy(gpPointlightTex);
#if GTA3_1_1_PATCH == TRUE #ifdef GTA3_1_1_PATCH
gpPointlightTex = NULL; gpPointlightTex = NULL;
#endif #endif

View File

@ -3,6 +3,7 @@
#define DIRECTINPUT_VERSION 0x0800 #define DIRECTINPUT_VERSION 0x0800
#define WM_GRAPHNOTIFY WM_USER+13 #define WM_GRAPHNOTIFY WM_USER+13
#include <winerror.h>
#include <windows.h> #include <windows.h>
#include <mmsystem.h> #include <mmsystem.h>
#include <shellapi.h> #include <shellapi.h>
@ -17,12 +18,14 @@
#pragma warning( push ) #pragma warning( push )
#pragma warning( disable : 4005) #pragma warning( disable : 4005)
#include <d3d8.h>
#include <ddraw.h> #include <ddraw.h>
#include <dinput.h> #include <dinput.h>
#include <DShow.h> #include <DShow.h>
//#include <dmusici.h>
#pragma warning( pop ) #pragma warning( pop )
#pragma comment( lib, "d3d8.lib" )
#pragma comment( lib, "ddraw.lib" )
#pragma comment( lib, "Winmm.lib" ) #pragma comment( lib, "Winmm.lib" )
#pragma comment( lib, "dxguid.lib" ) #pragma comment( lib, "dxguid.lib" )
#pragma comment( lib, "strmiids.lib" ) #pragma comment( lib, "strmiids.lib" )
@ -40,15 +43,24 @@
#define MAX_SUBSYSTEMS (16) #define MAX_SUBSYSTEMS (16)
static RwBool ForegroundApp = TRUE; //static RwBool ForegroundApp = TRUE;
static RwBool RwInitialised = FALSE; static RwBool &ForegroundApp = *(RwBool*)0x060F000;
//static RwBool RwInitialised = FALSE;
static RwBool &RwInitialised = *(RwBool*)0x885B88;
static RwSubSystemInfo GsubSysInfo[MAX_SUBSYSTEMS]; static RwSubSystemInfo GsubSysInfo[MAX_SUBSYSTEMS];
static RwInt32 GnumSubSystems = 0; static RwInt32 GnumSubSystems = 0;
static RwInt32 GcurSel = 0, GcurSelVM = 0; static RwInt32 GcurSel = 0, GcurSelVM = 0;
static RwBool startupDeactivate; //static RwBool startupDeactivate;
static RwBool useDefault; static RwBool &startupDeactivate = *(RwBool*)0x8E2878;
static RwBool defaultFullscreenRes = TRUE;
//static RwBool useDefault;
static RwBool &useDefault = *(RwBool*)0x6510D4;
//static RwBool defaultFullscreenRes = TRUE;
static RwBool &defaultFullscreenRes = *(RwBool*)0x60EFFC;
/* Class name for the MS Window's window class. */ /* Class name for the MS Window's window class. */
@ -84,9 +96,7 @@ static psGlobalType &PsGlobal = *(psGlobalType*)0x72CF60;
#define SAFE_RELEASE(x) { if (x) x->Release(); x = NULL; } #define SAFE_RELEASE(x) { if (x) x->Release(); x = NULL; }
#define JIF(x) if (FAILED(hr=(x))) \ #define JIF(x) if (FAILED(hr=(x))) \
{debug(TEXT("FAILED(hr=0x%x) in ") TEXT(#x) TEXT("\n"), hr); return hr;} {debug(TEXT("FAILED(hr=0x%x) in ") TEXT(#x) TEXT("\n"), hr); return;}
#include "common.h" #include "common.h"
#include "patcher.h" #include "patcher.h"
@ -124,10 +134,6 @@ DWORD &_dwOperatingSystemVersion = *(DWORD*)0x70F290;
RwUInt32 &gGameState = *(RwUInt32*)0x8F5838; RwUInt32 &gGameState = *(RwUInt32*)0x8F5838;
//
WRAPPER RwUInt32 GetBestRefreshRate(RwUInt32 width, RwUInt32 height, RwUInt32 depth) { EAXJMP(0x581CB0); }
WRAPPER HRESULT _GetVideoMemInfo(DWORD *total, DWORD *avaible) { EAXJMP(0x580F30); }
WRAPPER BOOL _InputTranslateKey(RsKeyCodes *rs, DWORD flag, UINT key) { EAXJMP(0x583A20); } WRAPPER BOOL _InputTranslateKey(RsKeyCodes *rs, DWORD flag, UINT key) { EAXJMP(0x583A20); }
WRAPPER void _InputTranslateShiftKeyUpDown(RsKeyCodes *rs) { EAXJMP(0x583DC0); } WRAPPER void _InputTranslateShiftKeyUpDown(RsKeyCodes *rs) { EAXJMP(0x583DC0); }
WRAPPER HRESULT _InputInitialise() { EAXJMP(0x5830D0); } WRAPPER HRESULT _InputInitialise() { EAXJMP(0x5830D0); }
@ -143,7 +149,7 @@ CSprite2d *LoadSplash(const char *name);
void InitialiseLanguage(); void InitialiseLanguage();
RwBool _psSetVideoMode(RwInt32 subSystem, RwInt32 videoMode); RwBool _psSetVideoMode(RwInt32 subSystem, RwInt32 videoMode);
HRESULT CenterVideo(void); void CenterVideo(void);
void CloseClip(void); void CloseClip(void);
/**/ /**/
@ -368,8 +374,25 @@ InitInstance(HANDLE instance)
(HWND)NULL, (HMENU)NULL, (HINSTANCE)instance, NULL); (HWND)NULL, (HMENU)NULL, (HINSTANCE)instance, NULL);
} }
_TODO("") void _GetVideoMemInfo(LPDWORD total, LPDWORD avaible)
//_GetVideoMemInfo 0x580F30 {
HRESULT hr;
LPDIRECTDRAW7 pDD7;
hr = DirectDrawCreateEx(NULL, (VOID**)&pDD7, IID_IDirectDraw7, NULL);
if ( FAILED(hr) )
return;
DDSCAPS2 caps;
ZeroMemory(&caps, sizeof(DDSCAPS2));
caps.dwCaps = DDSCAPS_VIDEOMEMORY;
pDD7->GetAvailableVidMem(&caps, total, avaible);
pDD7->Release();
}
/* /*
***************************************************************************** *****************************************************************************
@ -597,6 +620,7 @@ psInitialise(void)
FrontEndMenuManager.LoadSettings(); FrontEndMenuManager.LoadSettings();
gGameState = GS_START_UP; gGameState = GS_START_UP;
TRACE("gGameState = GS_START_UP");
_psPrintCpuInfo(); _psPrintCpuInfo();
@ -809,55 +833,63 @@ void _psSelectScreenVM(RwInt32 videoMode)
/* /*
***************************************************************************** *****************************************************************************
*/ */
HRESULT WaitForState(FILTER_STATE State) void WaitForState(FILTER_STATE State)
{ {
HRESULT hr; HRESULT hr;
ASSERT(pMC != NULL);
// Make sure we have switched to the required state // Make sure we have switched to the required state
LONG lfs; LONG lfs;
do do
{ {
hr = pMC->GetState(10, &lfs); hr = pMC->GetState(10, &lfs);
} while (State != lfs); } while (State != lfs);
return hr;
} }
/* /*
***************************************************************************** *****************************************************************************
*/ */
HRESULT HandleGraphEvent(void) void HandleGraphEvent(void)
{ {
LONG evCode, evParam1, evParam2; LONG evCode, evParam1, evParam2;
HRESULT hr=S_OK; HRESULT hr=S_OK;
ASSERT(pME != NULL);
// Process all queued events // Process all queued events
while(SUCCEEDED(pME->GetEvent(&evCode, (LONG_PTR *) &evParam1, while (SUCCEEDED(pME->GetEvent(&evCode, (LONG_PTR *)&evParam1,
(LONG_PTR *) &evParam2, 0))) (LONG_PTR *)&evParam2, 0)))
{ {
// Free memory associated with callback, since we're not using it // Free memory associated with callback, since we're not using it
hr = pME->FreeEventParams(evCode, evParam1, evParam2); hr = pME->FreeEventParams(evCode, evParam1, evParam2);
// If this is the end of the clip, reset to beginning // If this is the end of the clip, reset to beginning
if(EC_COMPLETE == evCode) if (EC_COMPLETE == evCode)
{ {
switch ( gGameState ) switch (gGameState)
{ {
case GS_LOGO_MPEG: case GS_LOGO_MPEG:
{
gGameState = GS_INIT_INTRO_MPEG; gGameState = GS_INIT_INTRO_MPEG;
TRACE("gGameState = GS_INIT_INTRO_MPEG");
break; break;
}
case GS_INTRO_MPEG: case GS_INTRO_MPEG:
{
gGameState = GS_INIT_ONCE; gGameState = GS_INIT_ONCE;
TRACE("gGameState = GS_INIT_ONCE");
break; break;
}
default: default:
{
break; break;
}
} }
pME->SetNotifyWindow((OAHWND)NULL, 0, 0); pME->SetNotifyWindow((OAHWND)NULL, 0, 0);
} }
} }
return hr;
} }
/* /*
@ -1066,6 +1098,8 @@ MainWndProc(HWND window, UINT message, WPARAM wParam, LPARAM lParam)
case GS_LOGO_MPEG: case GS_LOGO_MPEG:
case GS_INTRO_MPEG: case GS_INTRO_MPEG:
{ {
ASSERT(pMC != NULL);
LONG state; LONG state;
pMC->GetState(10, &state); pMC->GetState(10, &state);
@ -1209,9 +1243,52 @@ RwBool IsForegroundApp()
return !!ForegroundApp; return !!ForegroundApp;
} }
_TODO("") UINT GetBestRefreshRate(UINT width, UINT height, UINT depth)
//GetBestRefreshRate(uint,uint,uint) 00581CB0 {
LPDIRECT3D8 d3d = Direct3DCreate8(D3D_SDK_VERSION);
ASSERT(d3d != NULL);
INT refreshRate = -1;
D3DFORMAT format;
if ( depth == 32 )
format = D3DFMT_X8R8G8B8;
else if ( depth == 24 )
format = D3DFMT_R8G8B8;
else
format = D3DFMT_R5G6B5;
UINT modeCount = d3d->GetAdapterModeCount(GcurSel);
for ( UINT i = 0; i < modeCount; i++ )
{
D3DDISPLAYMODE mode;
d3d->EnumAdapterModes(GcurSel, i, &mode);
if ( mode.Width == width && mode.Height == height && mode.Format == format )
{
if ( mode.RefreshRate == 0 )
return 0;
#pragma warning( push )
#pragma warning( disable : 4018)
if ( mode.RefreshRate < refreshRate && mode.RefreshRate >= 60 )
refreshRate = mode.RefreshRate;
#pragma warning( pop )
}
}
#ifdef FIX_BUGS
d3d->Release();
#endif
if ( refreshRate == -1 )
return -1;
return refreshRate;
}
/* /*
***************************************************************************** *****************************************************************************
@ -1298,12 +1375,12 @@ psSelectDevice()
{ {
debug("%dx%dx%d", vm.width, vm.height, vm.depth); debug("%dx%dx%d", vm.width, vm.height, vm.depth);
RwUInt32 refresh = GetBestRefreshRate(vm.width, vm.height, vm.depth); UINT refresh = GetBestRefreshRate(vm.width, vm.height, vm.depth);
if ( refresh != (RwUInt32)-1 ) if ( refresh != (UINT)-1 )
{ {
debug("refresh %d", refresh); debug("refresh %d", refresh);
RwD3D8EngineSetRefreshRate(refresh); RwD3D8EngineSetRefreshRate((RwUInt32)refresh);
} }
} }
@ -1553,11 +1630,13 @@ void InitialiseLanguage()
/* /*
***************************************************************************** *****************************************************************************
*/ */
HRESULT CenterVideo(void) void CenterVideo(void)
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
RECT rect; RECT rect;
ASSERT(pVW != NULL);
GetClientRect(PSGLOBAL(window), &rect); GetClientRect(PSGLOBAL(window), &rect);
JIF(pVW->SetWindowPosition(rect.left, rect.top, rect.right, rect.bottom)); JIF(pVW->SetWindowPosition(rect.left, rect.top, rect.right, rect.bottom));
@ -1565,14 +1644,12 @@ HRESULT CenterVideo(void)
JIF(pVW->put_MessageDrain((OAHWND) PSGLOBAL(window))); JIF(pVW->put_MessageDrain((OAHWND) PSGLOBAL(window)));
SetFocus(PSGLOBAL(window)); SetFocus(PSGLOBAL(window));
return hr;
} }
/* /*
***************************************************************************** *****************************************************************************
*/ */
HRESULT PlayMovieInWindow(int cmdShow, LPTSTR szFile) void PlayMovieInWindow(int cmdShow, LPTSTR szFile)
{ {
WCHAR wFileName[256]; WCHAR wFileName[256];
HRESULT hr; HRESULT hr;
@ -1617,10 +1694,13 @@ HRESULT PlayMovieInWindow(int cmdShow, LPTSTR szFile)
SetFocus(PSGLOBAL(window)); SetFocus(PSGLOBAL(window));
} }
ASSERT(pGB != NULL);
ASSERT(pVW != NULL);
ASSERT(pME != NULL);
ASSERT(pMC != NULL);
if(FAILED(hr)) if(FAILED(hr))
CloseClip(); CloseClip();
return hr;
} }
/* /*
@ -1826,6 +1906,17 @@ _WinMain(HINSTANCE instance,
SetErrorMode(SEM_FAILCRITICALERRORS); SetErrorMode(SEM_FAILCRITICALERRORS);
#ifdef NO_MOVIES
gGameState = GS_INIT_FRONTEND;
TRACE("gGameState = GS_INIT_FRONTEND");
LoadingScreen(NULL, NULL, "loadsc0");
if ( !CGame::InitialiseOnceAfterRW() )
RsGlobal.quit = TRUE;
#endif
while ( TRUE ) while ( TRUE )
{ {
RwInitialised = TRUE; RwInitialised = TRUE;
@ -1866,6 +1957,7 @@ _WinMain(HINSTANCE instance,
case GS_START_UP: case GS_START_UP:
{ {
gGameState = GS_INIT_LOGO_MPEG; gGameState = GS_INIT_LOGO_MPEG;
TRACE("gGameState = GS_INIT_LOGO_MPEG");
break; break;
} }
@ -1874,13 +1966,15 @@ _WinMain(HINSTANCE instance,
if ( !startupDeactivate ) if ( !startupDeactivate )
PlayMovieInWindow(cmdShow, "movies\\Logo.mpg"); PlayMovieInWindow(cmdShow, "movies\\Logo.mpg");
gGameState = GS_LOGO_MPEG; gGameState = GS_LOGO_MPEG;
TRACE("gGameState = GS_LOGO_MPEG;");
break; break;
} }
case GS_LOGO_MPEG: case GS_LOGO_MPEG:
{ {
CPad::UpdatePads(); CPad::UpdatePads();
if ( startupDeactivate || ControlsManager.GetJoyButtonJustDown() )
if ( startupDeactivate || ControlsManager.GetJoyButtonJustDown() != 0 )
++gGameState; ++gGameState;
else if ( CPad::GetPad(0)->GetLeftMouseJustDown() ) else if ( CPad::GetPad(0)->GetLeftMouseJustDown() )
++gGameState; ++gGameState;
@ -1892,6 +1986,8 @@ _WinMain(HINSTANCE instance,
++gGameState; ++gGameState;
else if ( CPad::GetPad(0)->GetTabJustDown() ) else if ( CPad::GetPad(0)->GetTabJustDown() )
++gGameState; ++gGameState;
break;
} }
case GS_INIT_INTRO_MPEG: case GS_INIT_INTRO_MPEG:
@ -1906,13 +2002,15 @@ _WinMain(HINSTANCE instance,
PlayMovieInWindow(cmdShow, "movies\\GTAtitles.mpg"); PlayMovieInWindow(cmdShow, "movies\\GTAtitles.mpg");
gGameState = GS_INTRO_MPEG; gGameState = GS_INTRO_MPEG;
TRACE("gGameState = GS_INTRO_MPEG;");
break; break;
} }
case GS_INTRO_MPEG: case GS_INTRO_MPEG:
{ {
CPad::UpdatePads(); CPad::UpdatePads();
if ( startupDeactivate || ControlsManager.GetJoyButtonJustDown() )
if ( startupDeactivate || ControlsManager.GetJoyButtonJustDown() != 0 )
++gGameState; ++gGameState;
else if ( CPad::GetPad(0)->GetLeftMouseJustDown() ) else if ( CPad::GetPad(0)->GetLeftMouseJustDown() )
++gGameState; ++gGameState;
@ -1924,6 +2022,8 @@ _WinMain(HINSTANCE instance,
++gGameState; ++gGameState;
else if ( CPad::GetPad(0)->GetTabJustDown() ) else if ( CPad::GetPad(0)->GetTabJustDown() )
++gGameState; ++gGameState;
break;
} }
case GS_INIT_ONCE: case GS_INIT_ONCE:
@ -1937,6 +2037,7 @@ _WinMain(HINSTANCE instance,
RsGlobal.quit = TRUE; RsGlobal.quit = TRUE;
gGameState = GS_INIT_FRONTEND; gGameState = GS_INIT_FRONTEND;
TRACE("gGameState = GS_INIT_FRONTEND;");
break; break;
} }
@ -1950,12 +2051,13 @@ _WinMain(HINSTANCE instance,
if ( defaultFullscreenRes ) if ( defaultFullscreenRes )
{ {
defaultFullscreenRes = 0; defaultFullscreenRes = FALSE;
FrontEndMenuManager.m_nPrefsVideoMode = GcurSelVM; FrontEndMenuManager.m_nPrefsVideoMode = GcurSelVM;
FrontEndMenuManager.m_nDisplayVideoMode = GcurSelVM; FrontEndMenuManager.m_nDisplayVideoMode = GcurSelVM;
} }
gGameState = GS_FRONTEND; gGameState = GS_FRONTEND;
TRACE("gGameState = GS_FRONTEND;");
break; break;
} }
@ -1967,13 +2069,17 @@ _WinMain(HINSTANCE instance,
RsEventHandler(rsFRONTENDIDLE, NULL); RsEventHandler(rsFRONTENDIDLE, NULL);
if ( !FrontEndMenuManager.m_bMenuActive || FrontEndMenuManager.m_bLoadingSavedGame ) if ( !FrontEndMenuManager.m_bMenuActive || FrontEndMenuManager.m_bLoadingSavedGame )
{
gGameState = GS_INIT_PLAYING_GAME; gGameState = GS_INIT_PLAYING_GAME;
TRACE("gGameState = GS_INIT_PLAYING_GAME;");
}
if ( FrontEndMenuManager.m_bLoadingSavedGame ) if ( FrontEndMenuManager.m_bLoadingSavedGame )
{ {
InitialiseGame(); InitialiseGame();
FrontEndMenuManager.m_bGameNotLoaded = false; FrontEndMenuManager.m_bGameNotLoaded = false;
gGameState = GS_PLAYING_GAME; gGameState = GS_PLAYING_GAME;
TRACE("gGameState = GS_PLAYING_GAME;");
} }
break; break;
} }
@ -1983,6 +2089,7 @@ _WinMain(HINSTANCE instance,
InitialiseGame(); InitialiseGame();
FrontEndMenuManager.m_bGameNotLoaded = false; FrontEndMenuManager.m_bGameNotLoaded = false;
gGameState = GS_PLAYING_GAME; gGameState = GS_PLAYING_GAME;
TRACE("gGameState = GS_PLAYING_GAME;");
break; break;
} }
@ -2044,9 +2151,15 @@ _WinMain(HINSTANCE instance,
CTimer::Stop(); CTimer::Stop();
if ( FrontEndMenuManager.m_bFirstTime == true ) if ( FrontEndMenuManager.m_bFirstTime == true )
{
gGameState = GS_INIT_FRONTEND; gGameState = GS_INIT_FRONTEND;
TRACE("gGameState = GS_INIT_FRONTEND;");
}
else else
{
gGameState = GS_INIT_PLAYING_GAME; gGameState = GS_INIT_PLAYING_GAME;
TRACE("gGameState = GS_INIT_PLAYING_GAME;");
}
} }
FrontEndMenuManager.m_bFirstTime = false; FrontEndMenuManager.m_bFirstTime = false;
@ -2126,6 +2239,7 @@ STARTPATCHES
InjectHook(0x580E30, psNativeTextureSupport, PATCH_JUMP); InjectHook(0x580E30, psNativeTextureSupport, PATCH_JUMP);
InjectHook(0x580E40, InitApplication, PATCH_JUMP); InjectHook(0x580E40, InitApplication, PATCH_JUMP);
InjectHook(0x580EB0, InitInstance, PATCH_JUMP); InjectHook(0x580EB0, InitInstance, PATCH_JUMP);
InjectHook(0x580F30, _GetVideoMemInfo, PATCH_JUMP);
InjectHook(0x580FA0, GetDXVersion, PATCH_JUMP); InjectHook(0x580FA0, GetDXVersion, PATCH_JUMP);
InjectHook(0x5810C0, _psGetCpuVendr, PATCH_JUMP); InjectHook(0x5810C0, _psGetCpuVendr, PATCH_JUMP);
InjectHook(0x5810E0, _psGetCpuFeatures, PATCH_JUMP); InjectHook(0x5810E0, _psGetCpuFeatures, PATCH_JUMP);
@ -2141,6 +2255,7 @@ STARTPATCHES
InjectHook(0x5816E0, HandleGraphEvent, PATCH_JUMP); InjectHook(0x5816E0, HandleGraphEvent, PATCH_JUMP);
InjectHook(0x581790, MainWndProc, PATCH_JUMP); InjectHook(0x581790, MainWndProc, PATCH_JUMP);
InjectHook(0x581C90, IsForegroundApp, PATCH_JUMP); InjectHook(0x581C90, IsForegroundApp, PATCH_JUMP);
InjectHook(0x581CB0, GetBestRefreshRate, PATCH_JUMP);
InjectHook(0x581D80, psSelectDevice, PATCH_JUMP); InjectHook(0x581D80, psSelectDevice, PATCH_JUMP);
InjectHook(0x581F90, _psSetVideoMode, PATCH_JUMP); InjectHook(0x581F90, _psSetVideoMode, PATCH_JUMP);
InjectHook(0x582030, CommandLineToArgv, PATCH_JUMP); InjectHook(0x582030, CommandLineToArgv, PATCH_JUMP);