Re3/src/core/Game.cpp

360 lines
9.9 KiB
C++
Raw Normal View History

2019-05-15 10:52:37 -04:00
#include "common.h"
#include "patcher.h"
#include "Game.h"
2019-07-31 11:54:18 -04:00
#include "main.h"
2020-01-11 07:50:11 -05:00
#include "Accident.h"
2019-10-18 18:23:40 -04:00
#include "Antennas.h"
#include "Bridge.h"
#include "Camera.h"
#include "CarCtrl.h"
#include "CarGen.h"
2019-07-24 12:55:43 -04:00
#include "CdStream.h"
2019-10-18 18:23:40 -04:00
#include "Clock.h"
#include "Clouds.h"
#include "Collision.h"
2020-03-22 10:23:40 -04:00
#include "Console.h"
2019-10-18 18:23:40 -04:00
#include "Coronas.h"
#include "Cranes.h"
2020-03-22 10:23:40 -04:00
#include "Credits.h"
2019-10-18 18:23:40 -04:00
#include "CutsceneMgr.h"
#include "Darkel.h"
2020-03-22 10:23:40 -04:00
#include "Debug.h"
2019-10-18 18:23:40 -04:00
#include "EventList.h"
#include "FileLoader.h"
2019-07-24 12:55:43 -04:00
#include "FileMgr.h"
2019-10-18 18:23:40 -04:00
#include "Fire.h"
#include "Fluff.h"
#include "Font.h"
#include "Frontend.h"
#include "GameLogic.h"
#include "Garages.h"
#include "Glass.h"
#include "Heli.h"
2020-03-22 10:23:40 -04:00
#include "IniFile.h"
#include "Messages.h"
2019-10-18 18:23:40 -04:00
#include "Pad.h"
#include "Particle.h"
#include "Phones.h"
#include "Pickups.h"
#include "Plane.h"
#include "Population.h"
#include "Record.h"
#include "Renderer.h"
#include "Replay.h"
2020-03-22 10:23:40 -04:00
#include "Restart.h"
2019-10-18 18:23:40 -04:00
#include "RoadBlocks.h"
2020-03-22 10:23:40 -04:00
#include "PedRoutes.h"
2019-10-18 18:23:40 -04:00
#include "Rubbish.h"
2020-03-22 10:23:40 -04:00
#include "RwHelper.h"
2019-10-18 18:23:40 -04:00
#include "SceneEdit.h"
#include "Script.h"
#include "Shadows.h"
#include "Skidmarks.h"
#include "SpecialFX.h"
#include "Sprite2d.h"
2020-03-22 10:23:40 -04:00
#include "Stats.h"
2019-10-18 18:23:40 -04:00
#include "Streaming.h"
#include "TimeCycle.h"
#include "TrafficLights.h"
#include "Train.h"
2019-10-21 09:47:08 -04:00
#include "TxdStore.h"
2019-10-18 18:23:40 -04:00
#include "User.h"
#include "WaterCannon.h"
2020-03-22 10:23:40 -04:00
#include "WaterLevel.h"
2019-10-18 18:23:40 -04:00
#include "Weapon.h"
2020-03-22 10:23:40 -04:00
#include "WeaponEffects.h"
2019-10-18 18:23:40 -04:00
#include "Weather.h"
#include "World.h"
#include "ZoneCull.h"
#include "Zones.h"
2019-05-15 10:52:37 -04:00
2019-06-28 13:23:28 -04:00
eLevelName &CGame::currLevel = *(eLevelName*)0x941514;
2019-05-31 05:44:43 -04:00
bool &CGame::bDemoMode = *(bool*)0x5F4DD0;
bool &CGame::nastyGame = *(bool*)0x5F4DD4;
bool &CGame::frenchGame = *(bool*)0x95CDCB;
bool &CGame::germanGame = *(bool*)0x95CD1E;
bool &CGame::noProstitutes = *(bool*)0x95CDCF;
2019-06-12 20:35:26 -04:00
bool &CGame::playingIntro = *(bool*)0x95CDC2;
2019-06-17 04:30:02 -04:00
char *CGame::aDatFile = (char*)0x773A48;
2019-05-31 05:44:43 -04:00
2019-07-24 12:55:43 -04:00
bool
CGame::InitialiseOnceBeforeRW(void)
{
CFileMgr::Initialise();
CdStreamInit(MAX_CDCHANNELS);
ValidateVersion();
return true;
}
2020-03-22 10:23:40 -04:00
int &gameTxdSlot = *(int*)0x628D88;
bool CGame::Initialise(const char* datFile)
{
ResetLoadingScreenBar();
strcpy(aDatFile, datFile);
CPools::Initialise();
CIniFile::LoadIniFile();
currLevel = LEVEL_INDUSTRIAL;
LoadingScreen("Loading the Game", "Loading generic textures", GetRandomSplashScreen());
gameTxdSlot = CTxdStore::AddTxdSlot("generic");
CTxdStore::Create(gameTxdSlot);
CTxdStore::AddRef(gameTxdSlot);
LoadingScreen("Loading the Game", "Loading particles", nil);
int particleTxdSlot = CTxdStore::AddTxdSlot("particle");
CTxdStore::LoadTxd(particleTxdSlot, "MODELS/PARTICLE.TXD");
CTxdStore::AddRef(particleTxdSlot);
CTxdStore::SetCurrentTxd(gameTxdSlot);
LoadingScreen("Loading the Game", "Setup game variables", nil);
CGameLogic::InitAtStartOfGame();
CReferences::Init();
TheCamera.Init();
TheCamera.SetRwCamera(Scene.camera);
CDebug::DebugInitTextBuffer();
ThePaths.Init();
ThePaths.AllocatePathFindInfoMem(4500);
CWeather::Init();
CCullZones::Init();
CCollision::Init();
CTheZones::Init();
CUserDisplay::Init();
CMessages::Init();
CMessages::ClearAllMessagesDisplayedByGame();
CRecordDataForGame::Init();
CRestart::Initialise();
CWorld::Initialise();
CParticle::Initialise();
CAnimManager::Initialise();
CCutsceneMgr::Initialise();
CCarCtrl::Init();
InitModelIndices();
CModelInfo::Initialise();
CPickups::Init();
CTheCarGenerators::Init();
CdStreamAddImage("MODELS\\GTA3.IMG");
CFileLoader::LoadLevel("DATA\\DEFAULT.DAT");
CFileLoader::LoadLevel(datFile);
CWorld::AddParticles();
CVehicleModelInfo::LoadVehicleColours();
CVehicleModelInfo::LoadEnvironmentMaps();
CTheZones::PostZoneCreation();
LoadingScreen("Loading the Game", "Setup paths", GetRandomSplashScreen());
ThePaths.PreparePathData();
for (int i = 0; i < NUMPLAYERS; i++)
CWorld::Players[i].Clear();
CWorld::Players[0].LoadPlayerSkin();
TestModelIndices();
LoadingScreen("Loading the Game", "Setup water", nil);
CWaterLevel::Initialise("DATA\\WATER.DAT");
TheConsole.Init();
CDraw::SetFOV(120.0f);
CDraw::ms_fLODDistance = 500.0f;
LoadingScreen("Loading the Game", "Setup streaming", nil);
int txdHandle = CFileMgr::OpenFile("MODELS\\TXD.IMG", "r");
if (txdHandle)
CFileMgr::CloseFile(txdHandle);
if (!CheckVideoCardCaps() && txdHandle) {
CdStreamAddImage("MODELS\\TXD.IMG");
CStreaming::Init();
} else {
CStreaming::Init();
if (ConvertTextures()) {
CStreaming::Shutdown();
CdStreamAddImage("MODELS\\TXD.IMG");
CStreaming::Init();
}
}
CStreaming::LoadInitialVehicles();
CStreaming::LoadInitialPeds();
CStreaming::RequestBigBuildings(LEVEL_NONE);
CStreaming::LoadAllRequestedModels(false);
printf("Streaming uses %dK of its memory", CStreaming::ms_memoryUsed / 1024);
LoadingScreen("Loading the Game", "Load animations", GetRandomSplashScreen());
CAnimManager::LoadAnimFiles();
CPed::Initialise();
CRouteNode::Initialise();
CEventList::Initialise();
LoadingScreen("Loading the Game", "Find big buildings", nil);
CRenderer::Init();
LoadingScreen("Loading the Game", "Setup game variables", nil);
CRadar::Initialise();
CRadar::LoadTextures();
CWeapon::InitialiseWeapons();
LoadingScreen("Loading the Game", "Setup traffic lights", nil);
CTrafficLights::ScanForLightsOnMap();
CRoadBlocks::Init();
LoadingScreen("Loading the Game", "Setup game variables", nil);
CPopulation::Initialise();
CWorld::PlayerInFocus = 0;
CCoronas::Init();
CShadows::Init();
CWeaponEffects::Init();
CSkidmarks::Init();
CAntennas::Init();
CGlass::Init();
gPhoneInfo.Initialise();
CSceneEdit::Init();
LoadingScreen("Loading the Game", "Load scripts", nil);
CTheScripts::Init();
CGangs::Initialize();
LoadingScreen("Loading the Game", "Setup game variables", nil);
CClock::Initialise(1000);
CHeli::InitHelis();
CCranes::InitCranes();
CMovingThings::Init();
CDarkel::Init();
CStats::Init();
CPacManPickups::Init();
CRubbish::Init();
CClouds::Init();
CSpecialFX::Init();
CWaterCannons::Init();
CBridge::Init();
CGarages::Init();
LoadingScreen("Loading the Game", "Position dynamic objects", nil);
CWorld::RepositionCertainDynamicObjects();
LoadingScreen("Loading the Game", "Initialise vehicle paths", nil);
CCullZones::ResolveVisibilities();
CTrain::InitTrains();
CPlane::InitPlanes();
CCredits::Init();
CRecordDataForChase::Init();
CReplay::Init();
LoadingScreen("Loading the Game", "Start script", nil);
CTheScripts::StartTestScript();
CTheScripts::Process();
TheCamera.Process();
LoadingScreen("Loading the Game", "Load scene", nil);
CModelInfo::RemoveColModelsFromOtherLevels(CGame::currLevel);
CCollision::ms_collisionInMemory = CGame::currLevel;
for (int i = 0; i < MAX_PADS; i++)
CPad::GetPad(i)->Clear(true);
return true;
}
2019-10-18 18:23:40 -04:00
#if 0
2019-05-31 05:44:43 -04:00
WRAPPER void CGame::Process(void) { EAXJMP(0x48C850); }
2019-10-18 18:23:40 -04:00
#else
2019-10-24 19:25:11 -04:00
extern void (*DebugMenuProcess)(void);
2019-10-18 18:23:40 -04:00
void CGame::Process(void)
{
CPad::UpdatePads();
TheCamera.SetMotionBlurAlpha(0);
2019-10-19 07:12:18 -04:00
if (TheCamera.m_BlurType == MBLUR_NONE || TheCamera.m_BlurType == MBLUR_SNIPER || TheCamera.m_BlurType == MBLUR_NORMAL)
2019-10-19 07:20:51 -04:00
TheCamera.SetMotionBlur(0, 0, 0, 0, MBLUR_NONE);
2019-10-24 19:25:11 -04:00
DebugMenuProcess();
2019-10-18 18:23:40 -04:00
CCutsceneMgr::Update();
2019-10-19 07:12:18 -04:00
if (!CCutsceneMgr::IsCutsceneProcessing() && !CTimer::GetIsCodePaused())
2019-10-18 18:23:40 -04:00
FrontEndMenuManager.Process();
CStreaming::Update();
if (!CTimer::GetIsPaused())
{
CTheZones::Update();
CSprite2d::SetRecipNearClip();
CSprite2d::InitPerFrame();
CFont::InitPerFrame();
CRecordDataForGame::SaveOrRetrieveDataForThisFrame();
CRecordDataForChase::SaveOrRetrieveDataForThisFrame();
CPad::DoCheats();
CClock::Update();
CWeather::Update();
CTheScripts::Process();
CCollision::Update();
CTrain::UpdateTrains();
CPlane::UpdatePlanes();
CHeli::UpdateHelis();
CDarkel::Update();
CSkidmarks::Update();
CAntennas::Update();
CGlass::Update();
CSceneEdit::Update();
CEventList::Update();
CParticle::Update();
gFireManager.Update();
CPopulation::Update();
CWeapon::UpdateWeapons();
if (!CCutsceneMgr::IsRunning())
CTheCarGenerators::Process();
if (!CReplay::IsPlayingBack())
CCranes::UpdateCranes();
CClouds::Update();
CMovingThings::Update();
CWaterCannons::Update();
CUserDisplay::Process();
CReplay::Update();
CWorld::Process();
gAccidentManager.Update();
CPacManPickups::Update();
CPickups::Update();
CGarages::Update();
CRubbish::Update();
CSpecialFX::Update();
CTimeCycle::Update();
if (CReplay::ShouldStandardCameraBeProcessed())
TheCamera.Process();
CCullZones::Update();
if (!CReplay::IsPlayingBack())
CGameLogic::Update();
CBridge::Update();
CCoronas::DoSunAndMoon();
CCoronas::Update();
CShadows::UpdateStaticShadows();
CShadows::UpdatePermanentShadows();
gPhoneInfo.Update();
if (!CReplay::IsPlayingBack())
{
CCarCtrl::GenerateRandomCars();
CRoadBlocks::GenerateRoadBlocks();
CCarCtrl::RemoveDistantCars();
}
}
}
#endif
2019-07-24 12:55:43 -04:00
2019-10-18 18:23:40 -04:00
void CGame::ReloadIPLs(void)
{
CTimer::Stop();
CWorld::RemoveStaticObjects();
ThePaths.Init();
CCullZones::Init();
CFileLoader::ReloadPaths("GTA3.IDE");
CFileLoader::LoadScene("INDUST.IPL");
CFileLoader::LoadScene("COMMER.IPL");
CFileLoader::LoadScene("SUBURBAN.IPL");
CFileLoader::LoadScene("CULL.IPL");
ThePaths.PreparePathData();
CTrafficLights::ScanForLightsOnMap();
CRoadBlocks::Init();
CCranes::InitCranes();
CGarages::Init();
CWorld::RepositionCertainDynamicObjects();
CCullZones::ResolveVisibilities();
CRenderer::SortBIGBuildings();
CTimer::Update();
}
2019-07-24 12:55:43 -04:00
2019-10-21 09:47:08 -04:00
#if 0
WRAPPER void CGame::FinalShutdown(void) { EAXJMP(0x48BEC0); }
#else
void
CGame::FinalShutdown(void)
{
CTxdStore::Shutdown();
CPedStats::Shutdown();
CdStreamShutdown();
}
#endif
2019-06-16 18:16:38 -04:00
WRAPPER bool CGame::InitialiseRenderWare(void) { EAXJMP(0x48BBA0); }
2019-05-31 13:02:26 -04:00
WRAPPER void CGame::ShutdownRenderWare(void) { EAXJMP(0x48BCB0); }
WRAPPER void CGame::ShutDown(void) { EAXJMP(0x48C3A0); }
WRAPPER void CGame::ShutDownForRestart(void) { EAXJMP(0x48C6B0); }
WRAPPER void CGame::InitialiseWhenRestarting(void) { EAXJMP(0x48C740); }
2019-06-16 18:16:38 -04:00
WRAPPER bool CGame::InitialiseOnceAfterRW(void) { EAXJMP(0x48BD50); }
2019-10-18 18:23:40 -04:00
STARTPATCHES
2019-10-21 09:47:08 -04:00
InjectHook(0x48C850, CGame::Process, PATCH_JUMP);
InjectHook(0x48BEC0, CGame::FinalShutdown, PATCH_JUMP);
2019-10-18 18:23:40 -04:00
ENDPATCHES