diff options
Diffstat (limited to 'src/control/Replay.cpp')
-rw-r--r-- | src/control/Replay.cpp | 422 |
1 files changed, 389 insertions, 33 deletions
diff --git a/src/control/Replay.cpp b/src/control/Replay.cpp index e80d8746..4733f6f2 100644 --- a/src/control/Replay.cpp +++ b/src/control/Replay.cpp @@ -1,11 +1,14 @@ #include "common.h" #include "patcher.h" #include "AnimBlendAssociation.h" +#include "Boat.h" #include "BulletTraces.h" #include "CarCtrl.h" +#include "CivilianPed.h" #include "Clock.h" #include "DMAudio.h" #include "Draw.h" +#include "Heli.h" #include "math/Matrix.h" #include "ModelIndices.h" #include "ModelInfo.h" @@ -13,6 +16,7 @@ #include "Pad.h" #include "PhoneInfo.h" #include "Pickups.h" +#include "Plane.h" #include "Pools.h" #include "Population.h" #include "Replay.h" @@ -22,6 +26,7 @@ #include "render/Skidmarks.h" #include "Streaming.h" #include "Timer.h" +#include "Train.h" #include "Weather.h" #include "Zones.h" #include "Font.h" @@ -82,11 +87,13 @@ bool &CReplay::bAllowLookAroundCam = *(bool*)0x95CDCD; float &CReplay::LoadSceneX = *(float*)0x880F9C; float &CReplay::LoadSceneY = *(float*)0x880F98; float &CReplay::LoadSceneZ = *(float*)0x880F94; +float &CReplay::CameraFocusX = *(float*)0x942F5C; +float &CReplay::CameraFocusY = *(float*)0x942F74; +float &CReplay::CameraFocusZ = *(float*)0x942F58; +bool &CReplay::bPlayerInRCBuggy = *(bool*)0x95CDC3; -#if 1 static void(*(&CBArray)[30])(CAnimBlendAssociation*, void*) = *(void(*(*)[30])(CAnimBlendAssociation*, void*))*(uintptr*)0x61052C; -#else -static void(*CBArray[])(CAnimBlendAssociation*, void*) = +static void(*CBArray_RE3[])(CAnimBlendAssociation*, void*) = { nil, &CPed::PedGetupCB, &CPed::PedStaggerCB, &CPed::PedEvadeCB, &CPed::FinishDieAnimCB, &CPed::FinishedWaitCB, &CPed::FinishLaunchCB, &CPed::FinishHitHeadCB, &CPed::PedAnimGetInCB, &CPed::PedAnimDoorOpenCB, @@ -95,7 +102,6 @@ static void(*CBArray[])(CAnimBlendAssociation*, void*) = &CPed::FinishFightMoveCB, &PhonePutDownCB, &PhonePickUpCB, &CPed::PedAnimDoorCloseRollingCB, &CPed::FinishJumpCB, &CPed::PedLandCB, &FinishFuckUCB, &CPed::RestoreHeadingRateCB, &CPed::PedSetQuickDraggedOutCarPositionCB, &CPed::PedSetDraggedOutCarPositionCB }; -#endif #if 0 WRAPPER uint8 FindCBFunctionID(void(*f)(CAnimBlendAssociation*, void*)) { EAXJMP(0x584E70); } @@ -106,13 +112,17 @@ static uint8 FindCBFunctionID(void(*f)(CAnimBlendAssociation*, void*)) if (CBArray[i] == f) return i; } + for (int i = 0; i < sizeof(CBArray_RE3) / sizeof(*CBArray_RE3); i++) { + if (CBArray_RE3[i] == f) + return i; + } return 0; } #endif static void(*FindCBFunction(uint8 id))(CAnimBlendAssociation*, void*) { - return CBArray[id]; + return CBArray_RE3[id]; } WRAPPER static void ApplyPanelDamageToCar(uint32, CAutomobile*, bool) { EAXJMP(0x584EA0); } @@ -410,36 +420,37 @@ WRAPPER void CReplay::ProcessPedUpdate(CPed *ped, float interpolation, CAddressI void CReplay::ProcessPedUpdate(CPed *ped, float interpolation, CAddressInReplayBuffer *buffer) { tPedUpdatePacket *pp = (tPedUpdatePacket*)&buffer->m_pBase[buffer->m_nOffset]; - if (ped){ - ped->m_fRotationCur = pp->heading * M_PI / 128.0f; - ped->m_fRotationDest = pp->heading * M_PI / 128.0f; - CMatrix ped_matrix; - pp->matrix.DecompressIntoFullMatrix(ped_matrix); - ped->GetMatrix() = ped->GetMatrix() * CMatrix(1.0f - interpolation); - *ped->GetMatrix().GetPosition() *= (1.0f - interpolation); - ped->GetMatrix() += CMatrix(interpolation) * ped_matrix; - if (pp->vehicle_index) { - ped->m_pMyVehicle = CPools::GetVehiclePool()->GetSlot(pp->vehicle_index - 1); - ped->bInVehicle = pp->vehicle_index; - } - else { - ped->m_pMyVehicle = nil; - ped->bInVehicle = false; - } - if (pp->assoc_group_id != ped->m_animGroup) { - ped->m_animGroup = (AssocGroupId)pp->assoc_group_id; - if (ped == FindPlayerPed()) - ((CPlayerPed*)ped)->ReApplyMoveAnims(); - } - RetrievePedAnimation(ped, &pp->anim_state); - ped->RemoveWeaponModel(-1); - if (pp->weapon_model != (uint8)-1) - ped->AddWeaponModel(pp->weapon_model); - CWorld::Remove(ped); - CWorld::Add(ped); - }else{ + if (!ped){ debug("Replay:Ped wasn't there\n"); + buffer->m_nOffset += sizeof(tPedUpdatePacket); + return; + } + ped->m_fRotationCur = pp->heading * M_PI / 128.0f; + ped->m_fRotationDest = pp->heading * M_PI / 128.0f; + CMatrix ped_matrix; + pp->matrix.DecompressIntoFullMatrix(ped_matrix); + ped->GetMatrix() = ped->GetMatrix() * CMatrix(1.0f - interpolation); + *ped->GetMatrix().GetPosition() *= (1.0f - interpolation); + ped->GetMatrix() += CMatrix(interpolation) * ped_matrix; + if (pp->vehicle_index) { + ped->m_pMyVehicle = CPools::GetVehiclePool()->GetSlot(pp->vehicle_index - 1); + ped->bInVehicle = pp->vehicle_index; } + else { + ped->m_pMyVehicle = nil; + ped->bInVehicle = false; + } + if (pp->assoc_group_id != ped->m_animGroup) { + ped->m_animGroup = (AssocGroupId)pp->assoc_group_id; + if (ped == FindPlayerPed()) + ((CPlayerPed*)ped)->ReApplyMoveAnims(); + } + RetrievePedAnimation(ped, &pp->anim_state); + ped->RemoveWeaponModel(-1); + if (pp->weapon_model != (uint8)-1) + ped->AddWeaponModel(pp->weapon_model); + CWorld::Remove(ped); + CWorld::Add(ped); buffer->m_nOffset += sizeof(tPedUpdatePacket); } #endif @@ -533,7 +544,35 @@ void CReplay::RetrieveDetailedPedAnimation(CPed *ped, CStoredDetailedAnimationSt } } #endif + +#if 0 WRAPPER void CReplay::PlaybackThisFrame(void) { EAXJMP(0x5946B0); } +#else +void CReplay::PlaybackThisFrame(void) +{ + static int SlowMotionCounter = 0; + CAddressInReplayBuffer buf = Playback; + if (PlayBackThisFrameInterpolation(&buf, 1.0f, nil)){ + DMAudio.SetEffectsFadeVol(127); + DMAudio.SetMusicFadeVol(127); + return; + } + if (SlowMotionCounter){ + CAddressInReplayBuffer buf_sm = buf; + if (PlayBackThisFrameInterpolation(&buf_sm, SlowMotionCounter * 1.0f / SlowMotion, nil)){ + DMAudio.SetEffectsFadeVol(127); + DMAudio.SetMusicFadeVol(127); + return; + } + } + SlowMotionCounter = (SlowMotionCounter + 1) % SlowMotion; + if (SlowMotionCounter == 0) + Playback = buf; + ProcessLookAroundCam(); + DMAudio.SetEffectsFadeVol(0); + DMAudio.SetMusicFadeVol(0); +} +#endif #if 0 WRAPPER void CReplay::StoreCarUpdate(CVehicle *vehicle, int id) { EAXJMP(0x5947F0); } @@ -574,10 +613,325 @@ void CReplay::StoreCarUpdate(CVehicle *vehicle, int id) Record.m_nOffset += sizeof(tVehicleUpdatePacket); } #endif + +#if 0 WRAPPER void CReplay::ProcessCarUpdate(CVehicle *vehicle, float interpolation, CAddressInReplayBuffer *buffer) { EAXJMP(0x594D10); } +#else +void CReplay::ProcessCarUpdate(CVehicle *vehicle, float interpolation, CAddressInReplayBuffer *buffer) +{ + tVehicleUpdatePacket* vp = (tVehicleUpdatePacket*)&buffer->m_pBase[buffer->m_nOffset]; + if (!vehicle){ + debug("Replay:Car wasn't there"); + return; + } + CMatrix vehicle_matrix; + vp->matrix.DecompressIntoFullMatrix(vehicle_matrix); + vehicle->GetMatrix() = vehicle->GetMatrix() * CMatrix(1.0f - interpolation); + *vehicle->GetMatrix().GetPosition() *= (1.0f - interpolation); + vehicle->GetMatrix() += CMatrix(interpolation) * vehicle_matrix; + vehicle->m_vecTurnSpeed = CVector(0.0f, 0.0f, 0.0f); + vehicle->m_fHealth = 4 * vp->health; + vehicle->m_fGasPedal = vp->acceleration / 100.0f; + if (vehicle->IsCar()) + ApplyPanelDamageToCar(vp->panels, (CAutomobile*)vehicle, true); + vehicle->m_vecMoveSpeed = CVector(vp->velocityX / 8000.0f, vp->velocityY / 8000.0f, vp->velocityZ / 8000.0f); + if (vehicle->GetModelIndex() == MI_RHINO) { + ((CAutomobile*)vehicle)->m_fCarGunLR = vp->car_gun * M_PI / 128.0f; + vehicle->m_fSteerAngle = 0.0f; + }else{ + vehicle->m_fSteerAngle = vp->wheel_state / 50.0f; + } + if (vehicle->IsCar()) { + CAutomobile* car = (CAutomobile*)vehicle; + for (int i = 0; i < 4; i++) { + car->m_afWheelSuspDist[i] = vp->wheel_susp_dist[i] / 50.0f; + car->m_afWheelRotation[i] = vp->wheel_rotation[i] * M_PI / 128.0f; + } + car->m_aDoors[2].m_fAngle = car->m_aDoors[2].m_fPreviousAngle = vp->door_angles[0] * M_PI / 127.0f; + car->m_aDoors[3].m_fAngle = car->m_aDoors[3].m_fPreviousAngle = vp->door_angles[1] * M_PI / 127.0f; + if (vp->door_angles[0]) + car->m_DamageManager.m_bDoorStatus[2] = 2; + if (vp->door_angles[1]) + car->m_DamageManager.m_bDoorStatus[3] = 2; + if (vp->door_status & 1 && car->m_DamageManager.GetDoorStatus(CDamageManager::CAR_DOOR_BONNET) != 3){ + car->m_DamageManager.SetDoorStatus(CDamageManager::CAR_DOOR_BONNET, 3); + car->SetDoorDamage(17, CDamageManager::CAR_DOOR_BONNET, true); + } + if (vp->door_status & 2 && car->m_DamageManager.GetDoorStatus(CDamageManager::CAR_DOOR_BUMPER) != 3) { + car->m_DamageManager.SetDoorStatus(CDamageManager::CAR_DOOR_BUMPER, 3); + car->SetDoorDamage(18, CDamageManager::CAR_DOOR_BUMPER, true); + } + if (vp->door_status & 4 && car->m_DamageManager.GetDoorStatus(CDamageManager::CAR_DOOR_LF) != 3) { + car->m_DamageManager.SetDoorStatus(CDamageManager::CAR_DOOR_LF, 3); + car->SetDoorDamage(15, CDamageManager::CAR_DOOR_LF, true); + } + if (vp->door_status & 8 && car->m_DamageManager.GetDoorStatus(CDamageManager::CAR_DOOR_RF) != 3) { + car->m_DamageManager.SetDoorStatus(CDamageManager::CAR_DOOR_RF, 3); + car->SetDoorDamage(11, CDamageManager::CAR_DOOR_RF, true); + } + if (vp->door_status & 0x10 && car->m_DamageManager.GetDoorStatus(CDamageManager::CAR_DOOR_LR) != 3) { + car->m_DamageManager.SetDoorStatus(CDamageManager::CAR_DOOR_LR, 3); + car->SetDoorDamage(16, CDamageManager::CAR_DOOR_LR, true); + } + if (vp->door_status & 0x20 && car->m_DamageManager.GetDoorStatus(CDamageManager::CAR_DOOR_RR) != 3) { + car->m_DamageManager.SetDoorStatus(CDamageManager::CAR_DOOR_RR, 3); + car->SetDoorDamage(12, CDamageManager::CAR_DOOR_RR, true); + } + vehicle->m_veh_flagA10 = true; + if (vehicle->IsCar()) + ((CAutomobile*)vehicle)->m_nDriveWheelsOnGround = 4; + CWorld::Remove(vehicle); + CWorld::Add(vehicle); + if (vehicle->IsBoat()) + ((CBoat*)vehicle)->m_bIsAnchored = false; + } +} +#endif + +#if 0 WRAPPER bool CReplay::PlayBackThisFrameInterpolation(CAddressInReplayBuffer *buffer, float interpolation, uint32 *pTimer) { EAXJMP(0x595240); } +#else +bool CReplay::PlayBackThisFrameInterpolation(CAddressInReplayBuffer *buffer, float interpolation, uint32 *pTimer){ + /* Mistake. Not even sure what this is even doing here... + * PlayerWanted is a backup to restore at the end of replay. + * Setting current wanted pointer to it makes it useless. + * Causes picking up bribes in replays reducing wanted level bug. + * Obviously fact of picking them up is a bug on its own, + * but it doesn't cancel this one. + */ + FindPlayerPed()->m_pWanted = &PlayerWanted; + + CBulletTraces::Init(); + float split = 1.0f - interpolation; + int ped_min_index = 0; /* Optimization due to peds and vehicles placed in buffer sequentially. */ + int vehicle_min_index = 0; /* So next ped can't have pool index less than current. */ + for(;;){ + uint8* ptr = buffer->m_pBase; + uint32 offset = buffer->m_nOffset; + uint8 type = ptr[offset]; + if (type == REPLAYPACKET_ENDOFFRAME) + break; + switch (type) { + case REPLAYPACKET_END: + { + int slot = buffer->m_bSlot; + if (BufferStatus[slot] == REPLAYBUFFER_RECORD) { + FinishPlayback(); + return true; + } + buffer->m_bSlot = (slot + 1) % 8; + buffer->m_nOffset = 0; + buffer->m_pBase = Buffers[buffer->m_bSlot]; + ped_min_index = 0; + vehicle_min_index = 0; + break; + } + case REPLAYPACKET_VEHICLE: + { + tVehicleUpdatePacket* vp = (tVehicleUpdatePacket*)&ptr[offset]; + for (int i = vehicle_min_index; i < vp->index; i++) { + CVehicle* v = CPools::GetVehiclePool()->GetSlot(i); + if (!v) + continue; + /* Removing vehicles not present in this frame. */ + CWorld::Remove(v); + delete v; + } + vehicle_min_index = vp->index + 1; + CVehicle* v = CPools::GetVehiclePool()->GetSlot(vp->index); + CVehicle* new_v; + if (!v) { + int mi = vp->mi; + if (CStreaming::ms_aInfoForModel[mi].m_loadState != 1) { + CStreaming::RequestModel(mi, 0); + } + else { + if (mi == MI_DEADDODO || mi == MI_AIRTRAIN) { + new_v = new(vp->index << 8) CPlane(mi, 2); + } + else if (mi == MI_TRAIN) { + new_v = new(vp->index << 8) CTrain(mi, 2); + } + else if (mi == MI_CHOPPER || mi == MI_ESCAPE) { + new_v = new(vp->index << 8) CHeli(mi, 2); + } + else if (CModelInfo::IsBoatModel(mi)){ + new_v = new(vp->index << 8) CBoat(mi, 2); + } + else{ + new_v = new(vp->index << 8) CAutomobile(mi, 2); + } + new_v->m_status = STATUS_PLAYER_PLAYBACKFROMBUFFER; + vp->matrix.DecompressIntoFullMatrix(new_v->GetMatrix()); + new_v->m_currentColour1 = vp->primary_color; + new_v->m_currentColour2 = vp->secondary_color; + CWorld::Add(new_v); + } + } + ProcessCarUpdate(CPools::GetVehiclePool()->GetSlot(vp->index), interpolation, buffer); + buffer->m_nOffset += sizeof(tVehicleUpdatePacket); + break; + } + case REPLAYPACKET_PED_HEADER: + { + tPedHeaderPacket* ph = (tPedHeaderPacket*)&ptr[offset]; + if (!CPools::GetPedPool()->GetSlot(ph->index)) { + if (CStreaming::ms_aInfoForModel[ph->mi].m_loadState != 1) { + CStreaming::RequestModel(ph->mi, 0); + } + else { + CPed* new_p = new(ph->index << 8) CCivilianPed(ph->pedtype, ph->mi); + new_p->m_status = STATUS_PLAYER_PLAYBACKFROMBUFFER; + new_p->GetMatrix().SetUnity(); + CWorld::Add(new_p); + } + } + buffer->m_nOffset += sizeof(tPedHeaderPacket); + break; + } + case REPLAYPACKET_PED_UPDATE: + { + tPedUpdatePacket* pu = (tPedUpdatePacket*)&ptr[offset]; + for (int i = ped_min_index; i < pu->index; i++) { + CPed* p = CPools::GetPedPool()->GetSlot(i); + if (!p) + continue; + /* Removing peds not present in this frame. */ + CWorld::Remove(p); + delete p; + } + ped_min_index = pu->index + 1; + ProcessPedUpdate(CPools::GetPedPool()->GetSlot(pu->index), interpolation, buffer); + break; + } + case REPLAYPACKET_GENERAL: + { + tGeneralPacket* pg = (tGeneralPacket*)&ptr[offset]; + TheCamera.GetMatrix() = TheCamera.GetMatrix() * CMatrix(split); + *TheCamera.GetMatrix().GetPosition() *= split; + TheCamera.GetMatrix() += CMatrix(interpolation) * pg->camera_pos; + RwMatrix* pm = &RpAtomicGetFrame(&TheCamera.m_pRwCamera->object.object)->modelling; + pm->pos = *(RwV3d*)TheCamera.GetMatrix().GetPosition(); + pm->at = *(RwV3d*)TheCamera.GetMatrix().GetForward(); + pm->up = *(RwV3d*)TheCamera.GetMatrix().GetUp(); + pm->right = *(RwV3d*)TheCamera.GetMatrix().GetRight(); + CameraFocusX = split * CameraFocusX + interpolation * pg->player_pos.x; + CameraFocusY = split * CameraFocusY + interpolation * pg->player_pos.y; + CameraFocusZ = split * CameraFocusZ + interpolation * pg->player_pos.z; + bPlayerInRCBuggy = pg->in_rcvehicle; + buffer->m_nOffset += sizeof(tGeneralPacket); + break; + } + case REPLAYPACKET_CLOCK: + { + tClockPacket* pc = (tClockPacket*)&ptr[offset]; + CClock::SetGameClock(pc->hours, pc->minutes); + buffer->m_nOffset += sizeof(tClockPacket); + break; + } + case REPLAYPACKET_WEATHER: + { + tWeatherPacket* pw = (tWeatherPacket*)&ptr[offset]; + CWeather::OldWeatherType = pw->old_weather; + CWeather::NewWeatherType = pw->new_weather; + CWeather::InterpolationValue = pw->interpolation; + buffer->m_nOffset += sizeof(tWeatherPacket); + break; + } + case REPLAYPACKET_ENDOFFRAME: + { + /* Not supposed to be here. */ + buffer->m_nOffset++; + break; + } + case REPLAYPACKET_TIMER: + { + tTimerPacket* pt = (tTimerPacket*)&ptr[offset]; + if (pTimer) + *pTimer = pt->timer; + CTimer::SetTimeInMilliseconds(pt->timer); + buffer->m_nOffset += sizeof(tTimerPacket); + break; + } + case REPLAYPACKET_BULLET_TRACES: + { + tBulletTracePacket* pb = (tBulletTracePacket*)&ptr[offset]; + CBulletTraces::aTraces[pb->index].m_bInUse = true; + CBulletTraces::aTraces[pb->index].m_bFramesInUse = pb->frames; + CBulletTraces::aTraces[pb->index].m_bLifeTime = pb->lifetime; + CBulletTraces::aTraces[pb->index].m_vecInf = pb->inf; + CBulletTraces::aTraces[pb->index].m_vecSup = pb->sup; + buffer->m_nOffset += sizeof(tBulletTracePacket); + } + default: + break; + } + } + buffer->m_nOffset += 4; + for (int i = vehicle_min_index; i < CPools::GetVehiclePool()->GetSize(); i++) { + CVehicle* v = CPools::GetVehiclePool()->GetSlot(i); + if (!v) + continue; + /* Removing vehicles not present in this frame. */ + CWorld::Remove(v); + delete v; + } + for (int i = ped_min_index; i < CPools::GetPedPool()->GetSize(); i++) { + CPed* p = CPools::GetPedPool()->GetSlot(i); + if (!p) + continue; + /* Removing peds not present in this frame. */ + CWorld::Remove(p); + delete p; + } + ProcessReplayCamera(); + return false; +} +#endif +#if 0 WRAPPER void CReplay::FinishPlayback(void) { EAXJMP(0x595B20); } +#else +void CReplay::FinishPlayback(void) +{ + if (Mode != MODE_PLAYBACK) + return; + EmptyAllPools(); + RestoreStuffFromMem(); + Mode = MODE_RECORD; + if (bDoLoadSceneWhenDone){ + CVector v_ls(LoadSceneX, LoadSceneY, LoadSceneZ); + CGame::currLevel = CTheZones::GetLevelFromPosition(v_ls); + CCollision::SortOutCollisionAfterLoad(); + CStreaming::LoadScene(v_ls); + } + bDoLoadSceneWhenDone = false; + if (bPlayingBackFromFile){ + Init(); + MarkEverythingAsNew(); + } + DMAudio.SetEffectsFadeVol(127); + DMAudio.SetMusicFadeVol(127); +} +#endif + +#if 0 WRAPPER void CReplay::EmptyReplayBuffer(void) { EAXJMP(0x595BD0); } +#else +void CReplay::EmptyReplayBuffer(void) +{ + if (Mode == MODE_PLAYBACK) + return; + for (int i = 0; i < 8; i++){ + BufferStatus[i] = REPLAYBUFFER_UNUSED; + } + Record.m_bSlot = 0; + Record.m_pBase = Buffers[0]; + BufferStatus[0] = REPLAYBUFFER_RECORD; + Record.m_pBase[Record.m_nOffset] = 0; + MarkEverythingAsNew(); +} +#endif + WRAPPER void CReplay::ProcessReplayCamera(void) { EAXJMP(0x595C40); } #if 0 @@ -883,6 +1237,8 @@ InjectHook(0x593150, CReplay::DisableReplays, PATCH_JUMP); InjectHook(0x593160, CReplay::EnableReplays, PATCH_JUMP); InjectHook(0x593170, CReplay::Update, PATCH_JUMP); InjectHook(0x594050, CReplay::ProcessPedUpdate, PATCH_JUMP); +InjectHook(0x594D10, CReplay::ProcessCarUpdate, PATCH_JUMP); +InjectHook(0x593BB0, CReplay::StoreDetailedPedAnimation, PATCH_JUMP); InjectHook(0x5944B0, CReplay::RetrieveDetailedPedAnimation, PATCH_JUMP); //InjectHook(0x5966E0, CReplay::RestoreStuffFromMem, PATCH_JUMP); ENDPATCHES |