Merge pull request #474 from Nick007J/master

Bug fixes, mostly replay; added RegisterReference for player ped pointer
This commit is contained in:
erorcun 2020-04-19 16:56:39 +03:00 committed by GitHub
commit 0f07a323c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 200 additions and 96 deletions

View File

@ -12,6 +12,9 @@
#include "AudioScriptObject.h"
#include "RpAnimBlend.h"
#include "AnimBlendAssociation.h"
#ifdef FIX_BUGS
#include "Replay.h"
#endif
CPhoneInfo gPhoneInfo;
@ -45,6 +48,10 @@ isPhoneAvailable(int m_phoneId)
void
CPhoneInfo::Update(void)
{
#ifdef FIX_BUGS
if (CReplay::IsPlayingBack())
return;
#endif
CPlayerPed *player = FindPlayerPed();
CPlayerInfo *playerInfo = &CWorld::Players[CWorld::PlayerInFocus];
if (bDisplayingPhoneMessage && CTimer::GetTimeInMilliseconds() > PhoneEnableControlsTimer) {

View File

@ -68,8 +68,8 @@ bool CReplay::bReplayEnabled = true;
uint32 CReplay::SlowMotion;
uint32 CReplay::FramesActiveLookAroundCam;
bool CReplay::bDoLoadSceneWhenDone;
CPtrList CReplay::WorldPtrList;
CPtrList CReplay::BigBuildingPtrList;
CPtrNode* CReplay::WorldPtrList;
CPtrNode* CReplay::BigBuildingPtrList;
CWanted CReplay::PlayerWanted;
CPlayerInfo CReplay::PlayerInfo;
uint32 CReplay::Time1;
@ -101,6 +101,9 @@ bool CReplay::bPlayerInRCBuggy;
float CReplay::fDistanceLookAroundCam;
float CReplay::fBetaAngleLookAroundCam;
float CReplay::fAlphaAngleLookAroundCam;
#ifdef FIX_BUGS
int CReplay::nHandleOfPlayerPed[NUMPLAYERS];
#endif
static void(*CBArray[])(CAnimBlendAssociation*, void*) =
{
@ -275,7 +278,7 @@ void CReplay::RecordThisFrame(void)
continue;
memory_required += sizeof(tBulletTracePacket);
}
memory_required += sizeof(tEndOfFramePacket);
memory_required += sizeof(tEndOfFramePacket) + 1; // 1 for Record.m_pBase[Record.m_nOffset] = REPLAYPACKET_END;
if (Record.m_nOffset + memory_required > REPLAYBUFFERSIZE) {
Record.m_pBase[Record.m_nOffset] = REPLAYPACKET_END;
BufferStatus[Record.m_bSlot] = REPLAYBUFFER_PLAYBACK;
@ -1108,6 +1111,10 @@ void CReplay::TriggerPlayback(uint8 cam_mode, float cam_x, float cam_y, float ca
void CReplay::StoreStuffInMem(void)
{
#ifdef FIX_BUGS
for (int i = 0; i < NUMPLAYERS; i++)
nHandleOfPlayerPed[i] = CPools::GetPedPool()->GetIndex(CWorld::Players[i].m_pPed);
#endif
CPools::GetVehiclePool()->Store(pBuf0, pBuf1);
CPools::GetPedPool()->Store(pBuf2, pBuf3);
CPools::GetObjectPool()->Store(pBuf4, pBuf5);
@ -1116,8 +1123,8 @@ void CReplay::StoreStuffInMem(void)
CPools::GetDummyPool()->Store(pBuf10, pBuf11);
pWorld1 = new uint8[sizeof(CSector) * NUMSECTORS_X * NUMSECTORS_Y];
memcpy(pWorld1, CWorld::GetSector(0, 0), NUMSECTORS_X * NUMSECTORS_Y * sizeof(CSector));
WorldPtrList = CWorld::GetMovingEntityList();
BigBuildingPtrList = CWorld::GetBigBuildingList(LEVEL_NONE);
WorldPtrList = CWorld::GetMovingEntityList().first; // why
BigBuildingPtrList = CWorld::GetBigBuildingList(LEVEL_NONE).first;
pPickups = new uint8[sizeof(CPickup) * NUMPICKUPS];
memcpy(pPickups, CPickups::aPickUps, NUMPICKUPS * sizeof(CPickup));
pReferences = new uint8[(sizeof(CReference) * NUMREFERENCES)];
@ -1162,8 +1169,8 @@ void CReplay::RestoreStuffFromMem(void)
memcpy(CWorld::GetSector(0, 0), pWorld1, sizeof(CSector) * NUMSECTORS_X * NUMSECTORS_Y);
delete[] pWorld1;
pWorld1 = nil;
CWorld::GetMovingEntityList() = WorldPtrList;
CWorld::GetBigBuildingList(LEVEL_NONE) = BigBuildingPtrList;
CWorld::GetMovingEntityList().first = WorldPtrList;
CWorld::GetBigBuildingList(LEVEL_NONE).first = BigBuildingPtrList;
memcpy(CPickups::aPickUps, pPickups, sizeof(CPickup) * NUMPICKUPS);
delete[] pPickups;
pPickups = nil;
@ -1178,6 +1185,14 @@ void CReplay::RestoreStuffFromMem(void)
memcpy(CRadar::ms_RadarTrace, pRadarBlips, sizeof(sRadarTrace) * NUMRADARBLIPS);
delete[] pRadarBlips;
pRadarBlips = nil;
#ifdef FIX_BUGS
for (int i = 0; i < NUMPLAYERS; i++) {
CPlayerPed* pPlayerPed = (CPlayerPed*)CPools::GetPedPool()->GetAt(nHandleOfPlayerPed[i]);
assert(pPlayerPed);
CWorld::Players[i].m_pPed = pPlayerPed;
pPlayerPed->RegisterReference((CEntity**)&CWorld::Players[i].m_pPed);
}
#endif
FindPlayerPed()->m_pWanted = new CWanted(PlayerWanted);
CWorld::Players[0] = PlayerInfo;
int i = CPools::GetPedPool()->GetSize();
@ -1394,7 +1409,7 @@ void CReplay::SaveReplayToHD(void)
if (BufferStatus[first] == REPLAYBUFFER_RECORD || BufferStatus[first] == REPLAYBUFFER_PLAYBACK)
break;
for(int i = first; ; i = (i + 1) % NUM_REPLAYBUFFERS){
CFileMgr::Write(fw, (char*)Buffers[first], sizeof(Buffers[first]));
CFileMgr::Write(fw, (char*)Buffers[i], sizeof(Buffers[i]));
if (BufferStatus[i] == REPLAYBUFFER_RECORD)
break;
}

View File

@ -234,8 +234,8 @@ private:
static uint32 SlowMotion;
static uint32 FramesActiveLookAroundCam;
static bool bDoLoadSceneWhenDone;
static CPtrList WorldPtrList;
static CPtrList BigBuildingPtrList;
static CPtrNode* WorldPtrList;
static CPtrNode* BigBuildingPtrList;
static CWanted PlayerWanted;
static CPlayerInfo PlayerInfo;
static uint32 Time1;
@ -267,6 +267,9 @@ private:
static float fDistanceLookAroundCam;
static float fAlphaAngleLookAroundCam;
static float fBetaAngleLookAroundCam;
#ifdef FIX_BUGS
static int nHandleOfPlayerPed[NUMPLAYERS];
#endif
public:
static void Init(void);

View File

@ -2490,6 +2490,10 @@ CCamera::TryToStartNewCamMode(int obbeMode)
TakeControl(FindPlayerEntity(), CCam::MODE_CAM_ON_A_STRING, JUMP_CUT, CAMCONTROL_OBBE);
return true;
case OBBE_COPCAR:
#ifdef FIX_BUGS
if (CReplay::IsPlayingBack())
return false;
#endif
if(FindPlayerPed()->m_pWanted->m_nWantedLevel < 1)
return false;
if(FindPlayerVehicle() == nil)
@ -2514,6 +2518,10 @@ CCamera::TryToStartNewCamMode(int obbeMode)
}
return false;
case OBBE_COPCAR_WHEEL:
#ifdef FIX_BUGS
if (CReplay::IsPlayingBack())
return false;
#endif
if(FindPlayerPed()->m_pWanted->m_nWantedLevel < 1)
return false;
if(FindPlayerVehicle() == nil)

View File

@ -41,6 +41,10 @@ CPlayerInfo::SetPlayerSkin(char *skin)
CVector&
CPlayerInfo::GetPos()
{
#ifdef FIX_BUGS
if (!m_pPed)
return TheCamera.GetPosition();
#endif
if (m_pPed->InVehicle())
return m_pPed->m_pMyVehicle->GetPosition();
return m_pPed->GetPosition();
@ -342,6 +346,10 @@ CPlayerInfo::FindClosestCarSectorList(CPtrList& carList, CPed* ped, float unk1,
void
CPlayerInfo::Process(void)
{
#ifdef FIX_BUGS
if (CReplay::IsPlayingBack())
return;
#endif
// Unused taxi feature. Gives you a dollar for every second with a passenger. Can be toggled via 0x29A opcode.
bool startTaxiTimer = true;
if (m_bUnusedTaxiThing && m_pPed->bInVehicle) {

View File

@ -26,8 +26,17 @@ CReferences::RemoveReferencesToPlayer(void)
{
if(FindPlayerVehicle())
FindPlayerVehicle()->ResolveReferences();
#ifdef FIX_BUGS
if (FindPlayerPed()) {
CPlayerPed* pPlayerPed = FindPlayerPed();
FindPlayerPed()->ResolveReferences();
CWorld::Players[CWorld::PlayerInFocus].m_pPed = pPlayerPed;
pPlayerPed->RegisterReference((CEntity**)&CWorld::Players[CWorld::PlayerInFocus].m_pPed);
}
#else
if(FindPlayerPed())
FindPlayerPed()->ResolveReferences();
#endif
}
void

View File

@ -28,6 +28,9 @@
#include "CutsceneMgr.h"
#include "CdStream.h"
#include "Streaming.h"
#ifdef FIX_BUGS
#include "Replay.h"
#endif
#include "main.h"
bool CStreaming::ms_disableStreaming;
@ -280,7 +283,11 @@ CStreaming::Update(void)
!requestedSubway &&
!CGame::playingIntro &&
ms_numModelsRequested < 5 &&
!CRenderer::m_loadingPriority){
!CRenderer::m_loadingPriority
#ifdef FIX_BUGS
&& !CReplay::IsPlayingBack()
#endif
){
StreamVehiclesAndPeds();
StreamZoneModels(FindPlayerCoors());
}
@ -1248,7 +1255,11 @@ CStreaming::StreamVehiclesAndPeds(void)
static int modelQualityClass = 0;
if(CRecordDataForGame::IsRecording() ||
CRecordDataForGame::IsPlayingBack())
CRecordDataForGame::IsPlayingBack()
#ifdef FIX_BUGS
|| CReplay::IsPlayingBack()
#endif
)
return;
if(FindPlayerPed()->m_pWanted->AreSwatRequired()){

View File

@ -3,6 +3,7 @@
#include "Hud.h"
#include "PlayerPed.h"
#include "Replay.h"
#include "Text.h"
#include "User.h"
#include "Vehicle.h"
@ -115,6 +116,10 @@ CUserDisplay::Init()
void
CUserDisplay::Process()
{
#ifdef FIX_BUGS
if (CReplay::IsPlayingBack())
return;
#endif
PlaceName.Process();
OnscnTimer.Process();
Pager.Process();

View File

@ -1386,6 +1386,10 @@ FindPlayerEntity(void)
CVector
FindPlayerCoors(void)
{
#ifdef FIX_BUGS
if (CReplay::IsPlayingBack())
return TheCamera.GetPosition();
#endif
CPlayerPed *ped = FindPlayerPed();
if(ped->InVehicle())
return ped->m_pMyVehicle->GetPosition();
@ -1396,6 +1400,11 @@ FindPlayerCoors(void)
CVector &
FindPlayerSpeed(void)
{
#ifdef FIX_BUGS
static CVector vecTmpVector(0.0f, 0.0f, 0.0f);
if (CReplay::IsPlayingBack())
return vecTmpVector;
#endif
CPlayerPed *ped = FindPlayerPed();
if(ped->InVehicle())
return ped->m_pMyVehicle->m_vecMoveSpeed;
@ -1406,6 +1415,9 @@ FindPlayerSpeed(void)
CVector &
FindPlayerCentreOfWorld(int32 player)
{
#ifdef FIX_BUGS
if(CReplay::IsPlayingBack()) return TheCamera.GetPosition();
#endif
if(CCarCtrl::bCarsGeneratedAroundCamera) return TheCamera.GetPosition();
if(CWorld::Players[player].m_pRemoteVehicle) return CWorld::Players[player].m_pRemoteVehicle->GetPosition();
if(FindPlayerVehicle()) return FindPlayerVehicle()->GetPosition();
@ -1415,6 +1427,9 @@ FindPlayerCentreOfWorld(int32 player)
CVector &
FindPlayerCentreOfWorld_NoSniperShift(void)
{
#ifdef FIX_BUGS
if (CReplay::IsPlayingBack()) return TheCamera.GetPosition();
#endif
if(CCarCtrl::bCarsGeneratedAroundCamera) return TheCamera.GetPosition();
if(CWorld::Players[CWorld::PlayerInFocus].m_pRemoteVehicle)
return CWorld::Players[CWorld::PlayerInFocus].m_pRemoteVehicle->GetPosition();

View File

@ -135,6 +135,9 @@ CPlayerPed::SetupPlayerPed(int32 index)
{
CPlayerPed *player = new CPlayerPed();
CWorld::Players[index].m_pPed = player;
#ifdef FIX_BUGS
player->RegisterReference((CEntity**)&CWorld::Players[index].m_pPed);
#endif
player->SetOrientation(0.0f, 0.0f, 0.0f);

View File

@ -13,6 +13,9 @@
#include "Weather.h"
#include "ModelIndices.h"
#include "RenderBuffer.h"
#ifdef FIX_BUGS
#include "Replay.h"
#endif
#include "PointLights.h"
#include "SpecialFX.h"
#include "Shadows.h"
@ -1609,6 +1612,10 @@ CShadows::CalcPedShadowValues(CVector vecLightDir,
void
CShadows::RenderExtraPlayerShadows(void)
{
#ifdef FIX_BUGS
if (CReplay::IsPlayingBack())
return;
#endif
if ( CTimeCycle::GetLightShadowStrength() != 0 )
{
CVehicle *pCar = FindPlayerVehicle();

View File

@ -24,6 +24,9 @@
#include "Object.h"
#include "HandlingMgr.h"
#include "Heli.h"
#ifdef FIX_BUGS
#include "Replay.h"
#endif
enum
{
@ -462,7 +465,10 @@ CHeli::ProcessControl(void)
DMAudio.PlayOneShot(m_audioEntityId, SOUND_PED_HELI_PLAYER_FOUND, 0.0f);
m_nPoliceShoutTimer = CTimer::GetTimeInMilliseconds() + 4500 + (CGeneral::GetRandomNumber() & 0xFFF);
}
#ifdef FIX_BUGS
if (!CReplay::IsPlayingBack())
#endif
{
// Shoot
int shootTimeout;
if (m_heliType == HELI_TYPE_RANDOM) {
@ -477,7 +483,8 @@ CHeli::ProcessControl(void)
}
if (CCullZones::NoPolice())
shootTimeout /= 2;
}else
}
else
shootTimeout = 1500;
if (FindPlayerPed()->m_pWanted->IsIgnored())
@ -489,7 +496,8 @@ CHeli::ProcessControl(void)
if (CWorld::GetIsLineOfSightClear(GetPosition(), FindPlayerCoors(), true, false, false, false, false, false)) {
if (m_heliStatus == HELI_STATUS_HOVER2)
m_heliStatus = HELI_STATUS_HOVER;
}else{
}
else {
m_nShootTimer = CTimer::GetTimeInMilliseconds();
if (m_heliStatus == HELI_STATUS_HOVER)
m_heliStatus = HELI_STATUS_HOVER2;
@ -514,6 +522,7 @@ CHeli::ProcessControl(void)
}
}
}
}
// Drop Catalina's bombs
if(m_heliType == HELI_TYPE_CATALINA && m_pathState > 8 && (CTimer::GetTimeInMilliseconds()>>9) != (CTimer::GetPreviousTimeInMilliseconds()>>9)){
@ -825,7 +834,11 @@ CHeli::UpdateHelis(void)
int i, j;
// Spawn new police helis
int numHelisRequired = FindPlayerPed()->m_pWanted->NumOfHelisRequired();
int numHelisRequired =
#ifdef FIX_BUGS
CReplay::IsPlayingBack() ? 0 :
#endif
FindPlayerPed()->m_pWanted->NumOfHelisRequired();
if(CStreaming::HasModelLoaded(MI_CHOPPER) && CTimer::GetTimeInMilliseconds() > TestForNewRandomHelisTimer){
// Spawn a police heli
TestForNewRandomHelisTimer = CTimer::GetTimeInMilliseconds() + 15000;