2019-05-31 17:02:26 +00:00
|
|
|
#include "common.h"
|
|
|
|
#include "patcher.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "rwcore.h"
|
|
|
|
|
|
|
|
#include "skeleton.h"
|
|
|
|
#include "platform.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static RwBool DefaultVideoMode = TRUE;
|
|
|
|
|
|
|
|
//RsGlobalType RsGlobal;
|
|
|
|
RsGlobalType &RsGlobal = *(RsGlobalType*)0x8F4360;
|
|
|
|
|
|
|
|
RwUInt32
|
|
|
|
RsTimer(void)
|
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
return psTimer();
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
RsCameraShowRaster(RwCamera * camera)
|
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
psCameraShowRaster(camera);
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
return;
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
RwBool
|
|
|
|
RsCameraBeginUpdate(RwCamera * camera)
|
|
|
|
{
|
|
|
|
return psCameraBeginUpdate(camera);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
RwBool
|
|
|
|
RsRegisterImageLoader(void)
|
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
return TRUE;
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
static RwBool
|
|
|
|
RsSetDebug(void)
|
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
return TRUE;
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
RsMouseSetPos(RwV2d * pos)
|
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
psMouseSetPos(pos);
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
return;
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
RwBool
|
|
|
|
RsSelectDevice(void)
|
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
return psSelectDevice();
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
RwBool
|
|
|
|
RsInputDeviceAttach(RsInputDeviceType inputDevice,
|
2019-06-02 03:00:38 +00:00
|
|
|
RsInputEventHandler inputEventHandler)
|
2019-05-31 17:02:26 +00:00
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
switch (inputDevice)
|
|
|
|
{
|
|
|
|
case rsKEYBOARD:
|
|
|
|
{
|
|
|
|
RsGlobal.keyboard.inputEventHandler = inputEventHandler;
|
|
|
|
RsGlobal.keyboard.used = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case rsMOUSE:
|
|
|
|
{
|
|
|
|
RsGlobal.mouse.inputEventHandler = inputEventHandler;
|
|
|
|
RsGlobal.mouse.used = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case rsPAD:
|
|
|
|
{
|
|
|
|
RsGlobal.pad.inputEventHandler = inputEventHandler;
|
|
|
|
RsGlobal.pad.used = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
static RwBool
|
|
|
|
rsCommandLine(RwChar *arg)
|
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
RsEventHandler(rsFILELOAD, arg);
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
return TRUE;
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
static RwBool
|
|
|
|
rsPreInitCommandLine(RwChar *arg)
|
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
if( !strcmp(arg, RWSTRING("-vms")) )
|
|
|
|
{
|
|
|
|
DefaultVideoMode = FALSE;
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
return FALSE;
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
RsEventStatus
|
|
|
|
RsKeyboardEventHandler(RsEvent event, void *param)
|
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
if (RsGlobal.keyboard.used)
|
|
|
|
{
|
|
|
|
return RsGlobal.keyboard.inputEventHandler(event, param);
|
|
|
|
}
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
return rsEVENTNOTPROCESSED;
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
RsEventStatus
|
|
|
|
RsPadEventHandler(RsEvent event, void *param)
|
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
if (RsGlobal.pad.used)
|
|
|
|
{
|
|
|
|
return RsGlobal.pad.inputEventHandler(event, param);
|
|
|
|
}
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
return rsEVENTNOTPROCESSED;
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
RsEventStatus
|
|
|
|
RsEventHandler(RsEvent event, void *param)
|
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
RsEventStatus result;
|
|
|
|
RsEventStatus es;
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
/*
|
|
|
|
* Give the application an opportunity to override any events...
|
|
|
|
*/
|
|
|
|
es = AppEventHandler(event, param);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We never allow the app to replace the quit behaviour,
|
|
|
|
* only to intercept...
|
|
|
|
*/
|
|
|
|
if (event == rsQUITAPP)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Set the flag which causes the event loop to exit...
|
|
|
|
*/
|
|
|
|
RsGlobal.quit = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (es == rsEVENTNOTPROCESSED)
|
|
|
|
{
|
|
|
|
switch (event)
|
|
|
|
{
|
|
|
|
case rsSELECTDEVICE:
|
|
|
|
result =
|
|
|
|
(RsSelectDevice()? rsEVENTPROCESSED : rsEVENTERROR);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case rsCOMMANDLINE:
|
|
|
|
result = (rsCommandLine((RwChar *) param) ?
|
|
|
|
rsEVENTPROCESSED : rsEVENTERROR);
|
|
|
|
break;
|
|
|
|
case rsPREINITCOMMANDLINE:
|
|
|
|
result = (rsPreInitCommandLine((RwChar *) param) ?
|
|
|
|
rsEVENTPROCESSED : rsEVENTERROR);
|
|
|
|
break;
|
|
|
|
case rsINITDEBUG:
|
|
|
|
result =
|
|
|
|
(RsSetDebug()? rsEVENTPROCESSED : rsEVENTERROR);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case rsREGISTERIMAGELOADER:
|
|
|
|
result = (RsRegisterImageLoader()?
|
|
|
|
rsEVENTPROCESSED : rsEVENTERROR);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case rsRWTERMINATE:
|
|
|
|
RsRwTerminate();
|
|
|
|
result = (rsEVENTPROCESSED);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case rsRWINITIALISE:
|
|
|
|
result = (RsRwInitialise(param) ?
|
|
|
|
rsEVENTPROCESSED : rsEVENTERROR);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case rsTERMINATE:
|
|
|
|
RsTerminate();
|
|
|
|
result = (rsEVENTPROCESSED);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case rsINITIALISE:
|
|
|
|
result =
|
|
|
|
(RsInitialise()? rsEVENTPROCESSED : rsEVENTERROR);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
result = (es);
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = (es);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
RsRwTerminate(void)
|
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
/* Close RenderWare */
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
RwEngineStop();
|
|
|
|
RwEngineClose();
|
|
|
|
RwEngineTerm();
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
return;
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
RwBool
|
|
|
|
RsRwInitialise(void *displayID)
|
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
RwEngineOpenParams openParams;
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
/*
|
|
|
|
* Start RenderWare...
|
|
|
|
*/
|
2019-05-31 17:02:26 +00:00
|
|
|
|
|
|
|
if (!RwEngineInit(psGetMemoryFunctions(), 0, rsRESOURCESDEFAULTARENASIZE))
|
2019-06-02 03:00:38 +00:00
|
|
|
{
|
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Install any platform specific file systems...
|
|
|
|
*/
|
|
|
|
psInstallFileSystem();
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
/*
|
|
|
|
* Initialize debug message handling...
|
|
|
|
*/
|
|
|
|
RsEventHandler(rsINITDEBUG, NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach all plugins...
|
|
|
|
*/
|
|
|
|
if (RsEventHandler(rsPLUGINATTACH, NULL) == rsEVENTERROR)
|
|
|
|
{
|
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach input devices...
|
|
|
|
*/
|
|
|
|
if (RsEventHandler(rsINPUTDEVICEATTACH, NULL) == rsEVENTERROR)
|
|
|
|
{
|
|
|
|
return (FALSE);
|
|
|
|
}
|
2019-05-31 17:02:26 +00:00
|
|
|
|
|
|
|
openParams.displayID = displayID;
|
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
if (!RwEngineOpen(&openParams))
|
|
|
|
{
|
|
|
|
RwEngineTerm();
|
|
|
|
return (FALSE);
|
|
|
|
}
|
2019-05-31 17:02:26 +00:00
|
|
|
|
|
|
|
if (RsEventHandler(rsSELECTDEVICE, displayID) == rsEVENTERROR)
|
2019-06-02 03:00:38 +00:00
|
|
|
{
|
|
|
|
RwEngineClose();
|
|
|
|
RwEngineTerm();
|
|
|
|
return (FALSE);
|
|
|
|
}
|
2019-05-31 17:02:26 +00:00
|
|
|
|
|
|
|
if (!RwEngineStart())
|
2019-06-02 03:00:38 +00:00
|
|
|
{
|
|
|
|
RwEngineClose();
|
|
|
|
RwEngineTerm();
|
|
|
|
return (FALSE);
|
|
|
|
}
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
/*
|
|
|
|
* Register loaders for an image with a particular file extension...
|
|
|
|
*/
|
|
|
|
RsEventHandler(rsREGISTERIMAGELOADER, NULL);
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
psNativeTextureSupport();
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
RwTextureSetMipmapping(FALSE);
|
2019-05-31 17:02:26 +00:00
|
|
|
RwTextureSetAutoMipmapping(FALSE);
|
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
return TRUE;
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
RsTerminate(void)
|
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
psTerminate();
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
return;
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
RwBool
|
|
|
|
RsInitialise(void)
|
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
/*
|
|
|
|
* Initialize Platform independent data...
|
|
|
|
*/
|
|
|
|
RwBool result;
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
RsGlobal.appName = RWSTRING("GTA3");
|
|
|
|
RsGlobal.maximumWidth = DEFAULT_SCREEN_WIDTH;
|
2019-05-31 17:02:26 +00:00
|
|
|
RsGlobal.maximumHeight = DEFAULT_SCREEN_HEIGHT;
|
|
|
|
RsGlobal.width = DEFAULT_SCREEN_WIDTH;
|
2019-06-02 03:00:38 +00:00
|
|
|
RsGlobal.height = DEFAULT_SCREEN_HEIGHT;
|
2019-05-31 17:02:26 +00:00
|
|
|
|
|
|
|
RsGlobal.maxFPS = 30;
|
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
RsGlobal.quit = FALSE;
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
/* setup the keyboard */
|
|
|
|
RsGlobal.keyboard.inputDeviceType = rsKEYBOARD;
|
|
|
|
RsGlobal.keyboard.inputEventHandler = 0;
|
|
|
|
RsGlobal.keyboard.used = FALSE;
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
/* setup the mouse */
|
|
|
|
RsGlobal.mouse.inputDeviceType = rsMOUSE;
|
|
|
|
RsGlobal.mouse.inputEventHandler = 0;
|
|
|
|
RsGlobal.mouse.used = FALSE;
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
/* setup the pad */
|
|
|
|
RsGlobal.pad.inputDeviceType = rsPAD;
|
|
|
|
RsGlobal.pad.inputEventHandler = 0;
|
|
|
|
RsGlobal.pad.used = FALSE;
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
result = psInitialise();
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
return result;
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
STARTPATCHES
|
|
|
|
InjectHook(0x584890, RsTimer, PATCH_JUMP);
|
|
|
|
InjectHook(0x5848A0, RsCameraShowRaster, PATCH_JUMP);
|
|
|
|
InjectHook(0x5848B0, RsCameraBeginUpdate, PATCH_JUMP);
|
|
|
|
InjectHook(0x5848C0, RsRegisterImageLoader, PATCH_JUMP);
|
|
|
|
InjectHook(0x5848D0, RsSetDebug, PATCH_JUMP);
|
|
|
|
InjectHook(0x5848E0, RsMouseSetPos, PATCH_JUMP);
|
|
|
|
InjectHook(0x5848F0, RsSelectDevice, PATCH_JUMP);
|
|
|
|
InjectHook(0x584900, RsInputDeviceAttach, PATCH_JUMP);
|
|
|
|
InjectHook(0x584960, rsCommandLine, PATCH_JUMP);
|
|
|
|
InjectHook(0x584980, rsPreInitCommandLine, PATCH_JUMP);
|
|
|
|
InjectHook(0x5849C0, RsKeyboardEventHandler, PATCH_JUMP);
|
|
|
|
InjectHook(0x5849F0, RsPadEventHandler, PATCH_JUMP);
|
|
|
|
InjectHook(0x584A20, RsEventHandler, PATCH_JUMP);
|
|
|
|
InjectHook(0x584B30, RsRwTerminate, PATCH_JUMP);
|
|
|
|
InjectHook(0x584B40, RsRwInitialise, PATCH_JUMP);
|
|
|
|
InjectHook(0x584C30, RsTerminate, PATCH_JUMP);
|
|
|
|
InjectHook(0x584C40, RsInitialise, PATCH_JUMP);
|
|
|
|
ENDPATCHES
|