diff options
author | Sergeanur <s.anureev@yandex.ua> | 2020-04-26 21:03:15 +0200 |
---|---|---|
committer | Sergeanur <s.anureev@yandex.ua> | 2020-04-26 21:03:15 +0200 |
commit | f0890b11122291a22d6a65f349281cf1aed49bd0 (patch) | |
tree | 3b418b522c5fd097abac916693e59808ea4f5b4f /src/control | |
parent | More japanese (diff) | |
parent | Remove little hack (diff) | |
download | re3-f0890b11122291a22d6a65f349281cf1aed49bd0.tar re3-f0890b11122291a22d6a65f349281cf1aed49bd0.tar.gz re3-f0890b11122291a22d6a65f349281cf1aed49bd0.tar.bz2 re3-f0890b11122291a22d6a65f349281cf1aed49bd0.tar.lz re3-f0890b11122291a22d6a65f349281cf1aed49bd0.tar.xz re3-f0890b11122291a22d6a65f349281cf1aed49bd0.tar.zst re3-f0890b11122291a22d6a65f349281cf1aed49bd0.zip |
Diffstat (limited to 'src/control')
33 files changed, 2131 insertions, 924 deletions
diff --git a/src/control/AutoPilot.cpp b/src/control/AutoPilot.cpp index b5bca21d..69511bc8 100644 --- a/src/control/AutoPilot.cpp +++ b/src/control/AutoPilot.cpp @@ -1,5 +1,5 @@ #include "common.h" -#include "patcher.h" + #include "AutoPilot.h" #include "CarCtrl.h" @@ -8,7 +8,7 @@ void CAutoPilot::ModifySpeed(float speed) { - m_fMaxTrafficSpeed = max(0.01f, speed); + m_fMaxTrafficSpeed = Max(0.01f, speed); float positionBetweenNodes = (float)(CTimer::GetTimeInMilliseconds() - m_nTimeEnteredCurve) / m_nTimeToSpendOnCurrentCurve; CCarPathLink* pCurrentLink = &ThePaths.m_carPathLinks[m_nCurrentPathNodeInfo]; CCarPathLink* pNextLink = &ThePaths.m_carPathLinks[m_nNextPathNodeInfo]; @@ -35,7 +35,7 @@ void CAutoPilot::ModifySpeed(float speed) m_nTimeEnteredCurve = CTimer::GetTimeInMilliseconds() - (uint32)(positionBetweenNodes * m_nTimeToSpendOnCurrentCurve); #else - m_nTimeEnteredCurve = CTimer::GetTimeInMilliseconds() - positionBetweenNodes * m_nSpeedScaleFactor; + m_nTimeEnteredCurve = CTimer::GetTimeInMilliseconds() - positionBetweenNodes * m_nTimeToSpendOnCurrentCurve; #endif } diff --git a/src/control/Bridge.cpp b/src/control/Bridge.cpp index 6a577449..8514ef9e 100644 --- a/src/control/Bridge.cpp +++ b/src/control/Bridge.cpp @@ -1,25 +1,25 @@ #include "common.h" -#include "patcher.h" + #include "Bridge.h" #include "Pools.h" #include "ModelIndices.h" #include "PathFind.h" #include "Stats.h" -CEntity*& CBridge::pLiftRoad = *(CEntity**)0x8E2C8C; -CEntity*& CBridge::pLiftPart = *(CEntity**)0x8E2C94; -CEntity*& CBridge::pWeight = *(CEntity**)0x8E28BC; +CEntity *CBridge::pLiftRoad; +CEntity *CBridge::pLiftPart; +CEntity *CBridge::pWeight; -int& CBridge::State = *(int*)0x8F2A1C; -int& CBridge::OldState = *(int*)0x8F2A20; +int CBridge::State; +int CBridge::OldState; -float& CBridge::DefaultZLiftPart = *(float*)0x941430; -float& CBridge::DefaultZLiftRoad = *(float*)0x941438; -float& CBridge::DefaultZLiftWeight = *(float*)0x8F1A44; +float CBridge::DefaultZLiftPart; +float CBridge::DefaultZLiftRoad; +float CBridge::DefaultZLiftWeight; -float& CBridge::OldLift = *(float*)0x8F6254; +float CBridge::OldLift; -uint32& CBridge::TimeOfBridgeBecomingOperational = *(uint32*)0x8F2BC0; +uint32 CBridge::TimeOfBridgeBecomingOperational; void CBridge::Init() { @@ -144,11 +144,3 @@ bool CBridge::ThisIsABridgeObjectMovingUp(int index) return State == STATE_LIFT_PART_ABOUT_TO_MOVE_UP || State == STATE_LIFT_PART_MOVING_UP; } - -STARTPATCHES - InjectHook(0x413A30, &CBridge::Init, PATCH_JUMP); - InjectHook(0x413AC0, &CBridge::Update, PATCH_JUMP); - InjectHook(0x413D10, &CBridge::ShouldLightsBeFlashing, PATCH_JUMP); - InjectHook(0x413D20, &CBridge::FindBridgeEntities, PATCH_JUMP); - InjectHook(0x413DE0, &CBridge::ThisIsABridgeObjectMovingUp, PATCH_JUMP); -ENDPATCHES diff --git a/src/control/Bridge.h b/src/control/Bridge.h index 63f41578..c5702629 100644 --- a/src/control/Bridge.h +++ b/src/control/Bridge.h @@ -14,11 +14,11 @@ enum bridgeStates { class CBridge { public: - static CEntity *&pLiftRoad, *&pLiftPart, *&pWeight; - static int &State, &OldState; - static float &DefaultZLiftPart, &DefaultZLiftRoad, &DefaultZLiftWeight; - static float &OldLift; - static uint32 &TimeOfBridgeBecomingOperational; + static CEntity *pLiftRoad, *pLiftPart, *pWeight; + static int State, OldState; + static float DefaultZLiftPart, DefaultZLiftRoad, DefaultZLiftWeight; + static float OldLift; + static uint32 TimeOfBridgeBecomingOperational; static void Init(); static void Update(); diff --git a/src/control/CarAI.cpp b/src/control/CarAI.cpp index e47e3d5e..a8e77fc2 100644 --- a/src/control/CarAI.cpp +++ b/src/control/CarAI.cpp @@ -1,5 +1,5 @@ #include "common.h" -#include "patcher.h" + #include "CarAI.h" #include "Accident.h" @@ -33,7 +33,6 @@ float CCarAI::FindSwitchDistanceFar(CVehicle* pVehicle) void CCarAI::UpdateCarAI(CVehicle* pVehicle) { - //((void(*)(CVehicle*))(0x413E50))(pVehicle); //return; if (pVehicle->bIsLawEnforcer){ if (pVehicle->AutoPilot.m_nCarMission == MISSION_BLOCKCAR_FARAWAY || @@ -375,7 +374,7 @@ void CCarAI::UpdateCarAI(CVehicle* pVehicle) pVehicle->AutoPilot.m_nTimeTempAction = CTimer::GetTimeInMilliseconds() + 750; pVehicle->AutoPilot.m_nAntiReverseTimer = CTimer::GetTimeInMilliseconds(); if (pVehicle->VehicleCreatedBy == RANDOM_VEHICLE) - pVehicle->AutoPilot.m_nDrivingStyle = max(DRIVINGSTYLE_AVOID_CARS, pVehicle->AutoPilot.m_nDrivingStyle); + pVehicle->AutoPilot.m_nDrivingStyle = Max(DRIVINGSTYLE_AVOID_CARS, pVehicle->AutoPilot.m_nDrivingStyle); pVehicle->PlayCarHorn(); } } @@ -511,7 +510,7 @@ void CCarAI::TellCarToRamOtherCar(CVehicle* pVehicle, CVehicle* pTarget) pTarget->RegisterReference((CEntity**)&pVehicle->AutoPilot.m_pTargetCar); pVehicle->AutoPilot.m_nCarMission = MISSION_RAMCAR_FARAWAY; pVehicle->bEngineOn = true; - pVehicle->AutoPilot.m_nCruiseSpeed = max(6, pVehicle->AutoPilot.m_nCruiseSpeed); + pVehicle->AutoPilot.m_nCruiseSpeed = Max(6, pVehicle->AutoPilot.m_nCruiseSpeed); } void CCarAI::TellCarToBlockOtherCar(CVehicle* pVehicle, CVehicle* pTarget) @@ -520,7 +519,7 @@ void CCarAI::TellCarToBlockOtherCar(CVehicle* pVehicle, CVehicle* pTarget) pTarget->RegisterReference((CEntity**)&pVehicle->AutoPilot.m_pTargetCar); pVehicle->AutoPilot.m_nCarMission = MISSION_BLOCKCAR_FARAWAY; pVehicle->bEngineOn = true; - pVehicle->AutoPilot.m_nCruiseSpeed = max(6, pVehicle->AutoPilot.m_nCruiseSpeed); + pVehicle->AutoPilot.m_nCruiseSpeed = Max(6, pVehicle->AutoPilot.m_nCruiseSpeed); } eCarMission CCarAI::FindPoliceCarMissionForWantedLevel() { @@ -637,6 +636,3 @@ void CCarAI::MakeWayForCarWithSiren(CVehicle *pVehicle) } } } - -STARTPATCHES -ENDPATCHES diff --git a/src/control/CarCtrl.cpp b/src/control/CarCtrl.cpp index 264f1f3f..ae38b68f 100644 --- a/src/control/CarCtrl.cpp +++ b/src/control/CarCtrl.cpp @@ -1,5 +1,5 @@ #include "common.h" -#include "patcher.h" + #include "CarCtrl.h" #include "Accident.h" @@ -67,25 +67,25 @@ #define MIN_ANGLE_TO_APPLY_HANDBRAKE 0.7f #define MIN_SPEED_TO_APPLY_HANDBRAKE 0.3f -int &CCarCtrl::NumLawEnforcerCars = *(int*)0x8F1B38; -int &CCarCtrl::NumAmbulancesOnDuty = *(int*)0x885BB0; -int &CCarCtrl::NumFiretrucksOnDuty = *(int*)0x9411F0; -bool &CCarCtrl::bCarsGeneratedAroundCamera = *(bool*)0x95CD8A; -float& CCarCtrl::CarDensityMultiplier = *(float*)0x5EC8B4; -int32 &CCarCtrl::NumMissionCars = *(int32*)0x8F1B54; -int32 &CCarCtrl::NumRandomCars = *(int32*)0x943118; -int32 &CCarCtrl::NumParkedCars = *(int32*)0x8F29E0; -int32 &CCarCtrl::NumPermanentCars = *(int32*)0x8F29F0; -int8 &CCarCtrl::CountDownToCarsAtStart = *(int8*)0x95CD63; -int32 &CCarCtrl::MaxNumberOfCarsInUse = *(int32*)0x5EC8B8; -uint32 &CCarCtrl::LastTimeLawEnforcerCreated = *(uint32*)0x8F5FF0; -uint32 &CCarCtrl::LastTimeFireTruckCreated = *(uint32*)0x880F5C; -uint32 &CCarCtrl::LastTimeAmbulanceCreated = *(uint32*)0x941450; -int32 (&CCarCtrl::TotalNumOfCarsOfRating)[TOTAL_CUSTOM_CLASSES] = *(int32(*)[TOTAL_CUSTOM_CLASSES])*(uintptr*)0x8F1A60; -int32 (&CCarCtrl::NextCarOfRating)[TOTAL_CUSTOM_CLASSES] = *(int32(*)[TOTAL_CUSTOM_CLASSES])*(uintptr*)0x9412AC; -int32 (&CCarCtrl::CarArrays)[TOTAL_CUSTOM_CLASSES][MAX_CAR_MODELS_IN_ARRAY] = *(int32(*)[TOTAL_CUSTOM_CLASSES][MAX_CAR_MODELS_IN_ARRAY])*(uintptr*)0x6EB860; -CVehicle* (&apCarsToKeep)[MAX_CARS_TO_KEEP] = *(CVehicle*(*)[MAX_CARS_TO_KEEP])*(uintptr*)0x70D830; -uint32 (&aCarsToKeepTime)[MAX_CARS_TO_KEEP] = *(uint32(*)[MAX_CARS_TO_KEEP])*(uintptr*)0x87F9A8; +int CCarCtrl::NumLawEnforcerCars; +int CCarCtrl::NumAmbulancesOnDuty; +int CCarCtrl::NumFiretrucksOnDuty; +bool CCarCtrl::bCarsGeneratedAroundCamera; +float CCarCtrl::CarDensityMultiplier = 1.0f; +int32 CCarCtrl::NumMissionCars; +int32 CCarCtrl::NumRandomCars; +int32 CCarCtrl::NumParkedCars; +int32 CCarCtrl::NumPermanentCars; +int8 CCarCtrl::CountDownToCarsAtStart; +int32 CCarCtrl::MaxNumberOfCarsInUse = 12; +uint32 CCarCtrl::LastTimeLawEnforcerCreated; +uint32 CCarCtrl::LastTimeFireTruckCreated; +uint32 CCarCtrl::LastTimeAmbulanceCreated; +int32 CCarCtrl::TotalNumOfCarsOfRating[TOTAL_CUSTOM_CLASSES]; +int32 CCarCtrl::NextCarOfRating[TOTAL_CUSTOM_CLASSES]; +int32 CCarCtrl::CarArrays[TOTAL_CUSTOM_CLASSES][MAX_CAR_MODELS_IN_ARRAY]; +CVehicle* apCarsToKeep[MAX_CARS_TO_KEEP]; +uint32 aCarsToKeepTime[MAX_CARS_TO_KEEP]; void CCarCtrl::GenerateRandomCars() @@ -362,7 +362,7 @@ CCarCtrl::GenerateOneRandomCar() if (distanceBetweenNodes / 2 < carLength) positionBetweenNodes = 0.5f; else - positionBetweenNodes = min(1.0f - carLength / distanceBetweenNodes, max(carLength / distanceBetweenNodes, positionBetweenNodes)); + positionBetweenNodes = Min(1.0f - carLength / distanceBetweenNodes, Max(carLength / distanceBetweenNodes, positionBetweenNodes)); pCar->AutoPilot.m_nNextDirection = (curNodeId >= nextNodeId) ? 1 : -1; if (pCurNode->numLinks == 1){ /* Do not create vehicle if there is nowhere to go. */ @@ -426,7 +426,7 @@ CCarCtrl::GenerateOneRandomCar() (uint32)((0.5f + positionBetweenNodes) * pCar->AutoPilot.m_nTimeToSpendOnCurrentCurve); #else pCar->AutoPilot.m_nTimeEnteredCurve = CTimer::GetTimeInMilliseconds() - - (0.5f + positionBetweenNodes) * pCar->AutoPilot.m_nSpeedScaleFactor; + (0.5f + positionBetweenNodes) * pCar->AutoPilot.m_nTimeToSpendOnCurrentCurve; #endif CVector directionCurrentLink(directionCurrentLinkX, directionCurrentLinkY, 0.0f); CVector directionNextLink(directionNextLinkX, directionNextLinkY, 0.0f); @@ -804,10 +804,10 @@ CCarCtrl::FindMaximumSpeedForThisCarInTraffic(CVehicle* pVehicle) float right = pVehicle->GetPosition().x + DISTANCE_TO_SCAN_FOR_DANGER; float top = pVehicle->GetPosition().y - DISTANCE_TO_SCAN_FOR_DANGER; float bottom = pVehicle->GetPosition().y + DISTANCE_TO_SCAN_FOR_DANGER; - int xstart = max(0, CWorld::GetSectorIndexX(left)); - int xend = min(NUMSECTORS_X - 1, CWorld::GetSectorIndexX(right)); - int ystart = max(0, CWorld::GetSectorIndexY(top)); - int yend = min(NUMSECTORS_Y - 1, CWorld::GetSectorIndexY(bottom)); + int xstart = Max(0, CWorld::GetSectorIndexX(left)); + int xend = Min(NUMSECTORS_X - 1, CWorld::GetSectorIndexX(right)); + int ystart = Max(0, CWorld::GetSectorIndexY(top)); + int yend = Min(NUMSECTORS_Y - 1, CWorld::GetSectorIndexY(bottom)); assert(xstart <= xend); assert(ystart <= yend); @@ -838,10 +838,10 @@ CCarCtrl::ScanForPedDanger(CVehicle* pVehicle) float right = pVehicle->GetPosition().x + DISTANCE_TO_SCAN_FOR_DANGER; float top = pVehicle->GetPosition().y - DISTANCE_TO_SCAN_FOR_DANGER; float bottom = pVehicle->GetPosition().y + DISTANCE_TO_SCAN_FOR_DANGER; - int xstart = max(0, CWorld::GetSectorIndexX(left)); - int xend = min(NUMSECTORS_X - 1, CWorld::GetSectorIndexX(right)); - int ystart = max(0, CWorld::GetSectorIndexY(top)); - int yend = min(NUMSECTORS_Y - 1, CWorld::GetSectorIndexY(bottom)); + int xstart = Max(0, CWorld::GetSectorIndexX(left)); + int xend = Min(NUMSECTORS_X - 1, CWorld::GetSectorIndexX(right)); + int ystart = Max(0, CWorld::GetSectorIndexY(top)); + int yend = Min(NUMSECTORS_Y - 1, CWorld::GetSectorIndexY(bottom)); assert(xstart <= xend); assert(ystart <= yend); @@ -873,12 +873,12 @@ CCarCtrl::SlowCarOnRailsDownForTrafficAndLights(CVehicle* pVehicle) float curSpeed = pVehicle->AutoPilot.m_fMaxTrafficSpeed; if (maxSpeed >= curSpeed){ if (maxSpeed > curSpeed) - pVehicle->AutoPilot.ModifySpeed(min(maxSpeed, curSpeed + 0.05f * CTimer::GetTimeStep())); + pVehicle->AutoPilot.ModifySpeed(Min(maxSpeed, curSpeed + 0.05f * CTimer::GetTimeStep())); }else if (curSpeed != 0.0f) { if (curSpeed < 0.1f) pVehicle->AutoPilot.ModifySpeed(0.0f); else - pVehicle->AutoPilot.ModifySpeed(max(maxSpeed, curSpeed - 0.5f * CTimer::GetTimeStep())); + pVehicle->AutoPilot.ModifySpeed(Max(maxSpeed, curSpeed - 0.5f * CTimer::GetTimeStep())); } } @@ -979,7 +979,7 @@ void CCarCtrl::SlowCarDownForPedsSectorList(CPtrList& lst, CVehicle* pVehicle, f if (distanceUntilHit < 10.0f){ if (pVehicle->AutoPilot.m_nDrivingStyle == DRIVINGSTYLE_STOP_FOR_CARS || pVehicle->AutoPilot.m_nDrivingStyle == DRIVINGSTYLE_SLOW_DOWN_FOR_CARS){ - *pSpeed = min(*pSpeed, ABS(distanceUntilHit - 1.0f) * 0.1f * curSpeed); + *pSpeed = Min(*pSpeed, ABS(distanceUntilHit - 1.0f) * 0.1f * curSpeed); pVehicle->AutoPilot.m_bSlowedDownBecauseOfPeds = true; if (distanceUntilHit < 2.0f){ pVehicle->AutoPilot.m_nTempAction = TEMPACT_WAIT; @@ -1028,11 +1028,11 @@ void CCarCtrl::SlowCarDownForOtherCar(CEntity* pOtherEntity, CVehicle* pVehicle, float projectionY = speedOtherY - forwardA.y * curSpeed; float proximityA = TestCollisionBetween2MovingRects(pOtherVehicle, pVehicle, projectionX, projectionY, &forwardA, &forwardB, 0); float proximityB = TestCollisionBetween2MovingRects(pVehicle, pOtherVehicle, -projectionX, -projectionY, &forwardB, &forwardA, 1); - float minProximity = min(proximityA, proximityB); + float minProximity = Min(proximityA, proximityB); if (minProximity >= 0.0f && minProximity < 1.0f){ - minProximity = max(0.0f, (minProximity - 0.2f) * 1.25f); + minProximity = Max(0.0f, (minProximity - 0.2f) * 1.25f); pVehicle->AutoPilot.m_bSlowedDownBecauseOfCars = true; - *pSpeed = min(*pSpeed, minProximity * curSpeed); + *pSpeed = Min(*pSpeed, minProximity * curSpeed); } if (minProximity >= 0.0f && minProximity < 0.5f && pOtherEntity->IsVehicle() && CTimer::GetTimeInMilliseconds() - pVehicle->AutoPilot.m_nTimeToStartMission > 15000 && @@ -1041,7 +1041,7 @@ void CCarCtrl::SlowCarDownForOtherCar(CEntity* pOtherEntity, CVehicle* pVehicle, if (pOtherEntity != FindPlayerVehicle() && DotProduct2D(pVehicle->GetForward(), pOtherVehicle->GetForward()) < 0.5f && pVehicle < pOtherVehicle){ /* that comparasion though... */ - *pSpeed = max(curSpeed / 5, *pSpeed); + *pSpeed = Max(curSpeed / 5, *pSpeed); if (pVehicle->m_status == STATUS_SIMPLE){ pVehicle->m_status = STATUS_PHYSICS; SwitchVehicleToRealPhysics(pVehicle); @@ -1097,7 +1097,7 @@ float CCarCtrl::TestCollisionBetween2MovingRects(CVehicle* pVehicleA, CVehicle* float proximityWidth = -(widthDistance - widthB) / widthProjection; if (proximityWidth < 1.0f){ baseWidthProximity = proximityWidth; - fullWidthProximity = min(1.0f, proximityWidth - fullWidthB / widthProjection); + fullWidthProximity = Min(1.0f, proximityWidth - fullWidthB / widthProjection); }else{ baseWidthProximity = 1.0f; } @@ -1110,7 +1110,7 @@ float CCarCtrl::TestCollisionBetween2MovingRects(CVehicle* pVehicleA, CVehicle* float proximityWidth = -(widthDistance + widthB) / widthProjection; if (proximityWidth < 1.0f) { baseWidthProximity = proximityWidth; - fullWidthProximity = min(1.0f, proximityWidth + fullWidthB / widthProjection); + fullWidthProximity = Min(1.0f, proximityWidth + fullWidthB / widthProjection); } else { baseWidthProximity = 1.0f; @@ -1135,7 +1135,7 @@ float CCarCtrl::TestCollisionBetween2MovingRects(CVehicle* pVehicleA, CVehicle* float proximityLength = -(lenDistance - lenB) / lenProjection; if (proximityLength < 1.0f) { baseLengthProximity = proximityLength; - fullLengthProximity = min(1.0f, proximityLength - fullLenB / lenProjection); + fullLengthProximity = Min(1.0f, proximityLength - fullLenB / lenProjection); } else { baseLengthProximity = 1.0f; @@ -1151,7 +1151,7 @@ float CCarCtrl::TestCollisionBetween2MovingRects(CVehicle* pVehicleA, CVehicle* float proximityLength = -(lenDistance + backLenB) / lenProjection; if (proximityLength < 1.0f) { baseLengthProximity = proximityLength; - fullLengthProximity = min(1.0f, proximityLength + fullLenB / lenProjection); + fullLengthProximity = Min(1.0f, proximityLength + fullLenB / lenProjection); } else { baseLengthProximity = 1.0f; @@ -1168,24 +1168,24 @@ float CCarCtrl::TestCollisionBetween2MovingRects(CVehicle* pVehicleA, CVehicle* else if (lenProjection < 0.0f) { fullLengthProximity = -(backLenB + lenDistance) / lenProjection; } - float baseProximity = max(baseWidthProximity, baseLengthProximity); + float baseProximity = Max(baseWidthProximity, baseLengthProximity); if (baseProximity < fullWidthProximity && baseProximity < fullLengthProximity) - proximity = min(proximity, baseProximity); + proximity = Min(proximity, baseProximity); } return proximity; } float CCarCtrl::FindAngleToWeaveThroughTraffic(CVehicle* pVehicle, CPhysical* pTarget, float angleToTarget, float angleForward) { - float distanceToTest = min(2.0f, pVehicle->GetMoveSpeed().Magnitude2D() * 2.5f + 1.0f) * 12.0f; + float distanceToTest = Min(2.0f, pVehicle->GetMoveSpeed().Magnitude2D() * 2.5f + 1.0f) * 12.0f; float left = pVehicle->GetPosition().x - distanceToTest; float right = pVehicle->GetPosition().x + distanceToTest; float top = pVehicle->GetPosition().y - distanceToTest; float bottom = pVehicle->GetPosition().y + distanceToTest; - int xstart = max(0, CWorld::GetSectorIndexX(left)); - int xend = min(NUMSECTORS_X - 1, CWorld::GetSectorIndexX(right)); - int ystart = max(0, CWorld::GetSectorIndexY(top)); - int yend = min(NUMSECTORS_Y - 1, CWorld::GetSectorIndexY(bottom)); + int xstart = Max(0, CWorld::GetSectorIndexX(left)); + int xend = Min(NUMSECTORS_X - 1, CWorld::GetSectorIndexX(right)); + int ystart = Max(0, CWorld::GetSectorIndexY(top)); + int yend = Min(NUMSECTORS_Y - 1, CWorld::GetSectorIndexY(bottom)); assert(xstart <= xend); assert(ystart <= yend); @@ -1566,8 +1566,8 @@ void CCarCtrl::PickNextNodeRandomly(CVehicle* pVehicle) pVehicle->AutoPilot.m_nNextLane -= 1; } } - pVehicle->AutoPilot.m_nNextLane = min(lanesOnNextNode - 1, pVehicle->AutoPilot.m_nNextLane); - pVehicle->AutoPilot.m_nNextLane = max(0, pVehicle->AutoPilot.m_nNextLane); + pVehicle->AutoPilot.m_nNextLane = Min(lanesOnNextNode - 1, pVehicle->AutoPilot.m_nNextLane); + pVehicle->AutoPilot.m_nNextLane = Max(0, pVehicle->AutoPilot.m_nNextLane); }else{ pVehicle->AutoPilot.m_nNextLane = pVehicle->AutoPilot.m_nCurrentLane; } @@ -1595,7 +1595,7 @@ void CCarCtrl::PickNextNodeRandomly(CVehicle* pVehicle) if (pVehicle->AutoPilot.m_nTimeToSpendOnCurrentCurve < 10) /* Oh hey there Obbe */ printf("fout\n"); - pVehicle->AutoPilot.m_nTimeToSpendOnCurrentCurve = max(10, pVehicle->AutoPilot.m_nTimeToSpendOnCurrentCurve); + pVehicle->AutoPilot.m_nTimeToSpendOnCurrentCurve = Max(10, pVehicle->AutoPilot.m_nTimeToSpendOnCurrentCurve); } uint8 CCarCtrl::FindPathDirection(int32 prevNode, int32 curNode, int32 nextNode) @@ -1746,8 +1746,8 @@ void CCarCtrl::PickNextNodeToChaseCar(CVehicle* pVehicle, float targetX, float t pVehicle->AutoPilot.m_nNextLane -= 1; } } - pVehicle->AutoPilot.m_nNextLane = min(lanesOnNextNode - 1, pVehicle->AutoPilot.m_nNextLane); - pVehicle->AutoPilot.m_nNextLane = max(0, pVehicle->AutoPilot.m_nNextLane); + pVehicle->AutoPilot.m_nNextLane = Min(lanesOnNextNode - 1, pVehicle->AutoPilot.m_nNextLane); + pVehicle->AutoPilot.m_nNextLane = Max(0, pVehicle->AutoPilot.m_nNextLane); } else { pVehicle->AutoPilot.m_nNextLane = pVehicle->AutoPilot.m_nCurrentLane; @@ -1773,7 +1773,7 @@ void CCarCtrl::PickNextNodeToChaseCar(CVehicle* pVehicle, float targetX, float t directionCurrentLinkX, directionCurrentLinkY, directionNextLinkX, directionNextLinkY ) * (1000.0f / pVehicle->AutoPilot.m_fMaxTrafficSpeed); - pVehicle->AutoPilot.m_nTimeToSpendOnCurrentCurve = max(10, pVehicle->AutoPilot.m_nTimeToSpendOnCurrentCurve); + pVehicle->AutoPilot.m_nTimeToSpendOnCurrentCurve = Max(10, pVehicle->AutoPilot.m_nTimeToSpendOnCurrentCurve); } bool CCarCtrl::PickNextNodeToFollowPath(CVehicle* pVehicle) @@ -1826,8 +1826,8 @@ bool CCarCtrl::PickNextNodeToFollowPath(CVehicle* pVehicle) else pVehicle->AutoPilot.m_nNextLane -= 1; } - pVehicle->AutoPilot.m_nNextLane = min(lanesOnNextNode - 1, pVehicle->AutoPilot.m_nNextLane); - pVehicle->AutoPilot.m_nNextLane = max(0, pVehicle->AutoPilot.m_nNextLane); + pVehicle->AutoPilot.m_nNextLane = Min(lanesOnNextNode - 1, pVehicle->AutoPilot.m_nNextLane); + pVehicle->AutoPilot.m_nNextLane = Max(0, pVehicle->AutoPilot.m_nNextLane); } else { pVehicle->AutoPilot.m_nNextLane = pVehicle->AutoPilot.m_nCurrentLane; @@ -1853,7 +1853,7 @@ bool CCarCtrl::PickNextNodeToFollowPath(CVehicle* pVehicle) directionCurrentLinkX, directionCurrentLinkY, directionNextLinkX, directionNextLinkY ) * (1000.0f / pVehicle->AutoPilot.m_fMaxTrafficSpeed); - pVehicle->AutoPilot.m_nTimeToSpendOnCurrentCurve = max(10, pVehicle->AutoPilot.m_nTimeToSpendOnCurrentCurve); + pVehicle->AutoPilot.m_nTimeToSpendOnCurrentCurve = Max(10, pVehicle->AutoPilot.m_nTimeToSpendOnCurrentCurve); return false; } @@ -1965,7 +1965,7 @@ float CCarCtrl::FindSpeedMultiplier(float angleChange, float minAngle, float max { float angle = Abs(LimitRadianAngle(angleChange)); float n = angle - minAngle; - n = max(0.0f, n); + n = Max(0.0f, n); float d = maxAngle - minAngle; float mult = 1.0f - n / d * (1.0f - coef); if (n > d) @@ -2252,9 +2252,9 @@ void CCarCtrl::SteerAICarWithPhysicsFollowPath(CVehicle* pVehicle, float* pSwerv angleCurrentLink = FindAngleToWeaveThroughTraffic(pVehicle, nil, angleCurrentLink, angleForward); float steerAngle = LimitRadianAngle(angleCurrentLink - angleForward); float maxAngle = FindMaxSteerAngle(pVehicle); - steerAngle = min(maxAngle, max(-maxAngle, steerAngle)); + steerAngle = Min(maxAngle, Max(-maxAngle, steerAngle)); if (pVehicle->GetMoveSpeed().Magnitude() > MIN_SPEED_TO_START_LIMITING_STEER) - steerAngle = min(MAX_ANGLE_TO_STEER_AT_HIGH_SPEED, max(-MAX_ANGLE_TO_STEER_AT_HIGH_SPEED, steerAngle)); + steerAngle = Min(MAX_ANGLE_TO_STEER_AT_HIGH_SPEED, Max(-MAX_ANGLE_TO_STEER_AT_HIGH_SPEED, steerAngle)); float currentForwardSpeed = DotProduct(pVehicle->GetMoveSpeed(), pVehicle->GetForward()) * GAME_SPEED_TO_CARAI_SPEED; float speedStyleMultiplier; switch (pVehicle->AutoPilot.m_nDrivingStyle) { @@ -2298,21 +2298,21 @@ void CCarCtrl::SteerAICarWithPhysicsFollowPath(CVehicle* pVehicle, float* pSwerv speedNodesMultiplier = 1.0f - (1.0f - scalarDistanceToNextNode / DISTANCE_TO_NEXT_NODE_TO_CONSIDER_SLOWING_DOWN) * (1.0f - tmpWideMultiplier); - float speedMultiplier = min(speedStyleMultiplier, min(speedAngleMultiplier, speedNodesMultiplier)); + float speedMultiplier = Min(speedStyleMultiplier, Min(speedAngleMultiplier, speedNodesMultiplier)); float speed = pVehicle->AutoPilot.m_nCruiseSpeed * speedMultiplier; float speedDifference = speed - currentForwardSpeed; if (speed < 0.05f && speedDifference < 0.03f){ *pBrake = 1.0f; *pAccel = 0.0f; }else if (speedDifference <= 0.0f){ - *pBrake = min(0.5f, -speedDifference * 0.05f); + *pBrake = Min(0.5f, -speedDifference * 0.05f); *pAccel = 0.0f; }else if (currentForwardSpeed < 2.0f){ *pBrake = 0.0f; - *pAccel = min(1.0f, speedDifference * 0.25f); + *pAccel = Min(1.0f, speedDifference * 0.25f); }else{ *pBrake = 0.0f; - *pAccel = min(1.0f, speedDifference * 0.125f); + *pAccel = Min(1.0f, speedDifference * 0.125f); } *pSwerve = steerAngle; *pHandbrake = false; @@ -2332,7 +2332,7 @@ void CCarCtrl::SteerAICarWithPhysicsHeadingForTarget(CVehicle* pVehicle, CPhysic if (ABS(steerAngle) > MIN_ANGLE_TO_APPLY_HANDBRAKE) *pHandbrake = true; float maxAngle = FindMaxSteerAngle(pVehicle); - steerAngle = min(maxAngle, max(-maxAngle, steerAngle)); + steerAngle = Min(maxAngle, Max(-maxAngle, steerAngle)); float speedMultiplier = FindSpeedMultiplier(angleToTarget - angleForward, MIN_ANGLE_FOR_SPEED_LIMITING, MAX_ANGLE_FOR_SPEED_LIMITING, MIN_LOWERING_SPEED_COEFFICIENT); float speedTarget = pVehicle->AutoPilot.m_nCruiseSpeed * speedMultiplier; @@ -2340,9 +2340,9 @@ void CCarCtrl::SteerAICarWithPhysicsHeadingForTarget(CVehicle* pVehicle, CPhysic float speedDiff = speedTarget - currentSpeed; if (speedDiff <= 0.0f){ *pAccel = 0.0f; - *pBrake = min(0.5f, -speedDiff * 0.05f); + *pBrake = Min(0.5f, -speedDiff * 0.05f); }else if (currentSpeed < 25.0f){ - *pAccel = min(1.0f, speedDiff * 0.1f); + *pAccel = Min(1.0f, speedDiff * 0.1f); *pBrake = 0.0f; }else{ *pAccel = 1.0f; @@ -2414,7 +2414,7 @@ void CCarCtrl::SteerAIBoatWithPhysicsHeadingForTarget(CBoat* pBoat, float target float angleToTarget = CGeneral::GetATanOfXY(distanceToTarget.x, distanceToTarget.y); float angleForward = CGeneral::GetATanOfXY(forward.x, forward.y); float angleDiff = LimitRadianAngle(angleToTarget - angleForward); - angleDiff = min(DEFAULT_MAX_STEER_ANGLE, max(-DEFAULT_MAX_STEER_ANGLE, angleDiff)); + angleDiff = Min(DEFAULT_MAX_STEER_ANGLE, Max(-DEFAULT_MAX_STEER_ANGLE, angleDiff)); float currentSpeed = pBoat->GetMoveSpeed().Magnitude2D(); // +0.0f for some reason float speedDiff = pBoat->AutoPilot.m_nCruiseSpeed - currentSpeed * 60.0f; if (speedDiff > 0.0f){ @@ -2736,20 +2736,3 @@ bool CCarCtrl::MapCouldMoveInThisArea(float x, float y) return x > -342.0f && x < -219.0f && y > -677.0f && y < -580.0f; } - -STARTPATCHES -InjectHook(0x416580, &CCarCtrl::GenerateRandomCars, PATCH_JUMP); -InjectHook(0x417EC0, &CCarCtrl::ChooseModel, PATCH_JUMP); -InjectHook(0x418320, &CCarCtrl::RemoveDistantCars, PATCH_JUMP); -InjectHook(0x418430, &CCarCtrl::PossiblyRemoveVehicle, PATCH_JUMP); -InjectHook(0x41D280, &CCarCtrl::Init, PATCH_JUMP); -InjectHook(0x41D3B0, &CCarCtrl::ReInit, PATCH_JUMP); -InjectHook(0x41E250, &CCarCtrl::SteerAIBoatWithPhysics, PATCH_JUMP); -InjectHook(0x41F6E0, &CCarCtrl::RegisterVehicleOfInterest, PATCH_JUMP); -InjectHook(0x41F780, &CCarCtrl::IsThisVehicleInteresting, PATCH_JUMP); -InjectHook(0x41F7A0, &CCarCtrl::RemoveFromInterestingVehicleList, PATCH_JUMP); -InjectHook(0x41F7D0, &CCarCtrl::ClearInterestingVehicleList, PATCH_JUMP); -InjectHook(0x41F7F0, &CCarCtrl::SwitchVehicleToRealPhysics, PATCH_JUMP); -InjectHook(0x41F820, &CCarCtrl::JoinCarWithRoadSystem, PATCH_JUMP); -InjectHook(0x41FA00, &CCarCtrl::JoinCarWithRoadSystemGotoCoors, PATCH_JUMP); -ENDPATCHES diff --git a/src/control/CarCtrl.h b/src/control/CarCtrl.h index 925552b5..44ef9ab6 100644 --- a/src/control/CarCtrl.h +++ b/src/control/CarCtrl.h @@ -120,23 +120,23 @@ public: return angle; } - static int32 &NumLawEnforcerCars; - static int32 &NumAmbulancesOnDuty; - static int32 &NumFiretrucksOnDuty; - static int32 &NumRandomCars; - static int32 &NumMissionCars; - static int32 &NumParkedCars; - static int32 &NumPermanentCars; - static bool &bCarsGeneratedAroundCamera; - static float &CarDensityMultiplier; - static int8 &CountDownToCarsAtStart; - static int32 &MaxNumberOfCarsInUse; - static uint32 &LastTimeLawEnforcerCreated; - static uint32 &LastTimeFireTruckCreated; - static uint32 &LastTimeAmbulanceCreated; - static int32 (&TotalNumOfCarsOfRating)[TOTAL_CUSTOM_CLASSES]; - static int32 (&NextCarOfRating)[TOTAL_CUSTOM_CLASSES]; - static int32 (&CarArrays)[TOTAL_CUSTOM_CLASSES][MAX_CAR_MODELS_IN_ARRAY]; + static int32 NumLawEnforcerCars; + static int32 NumAmbulancesOnDuty; + static int32 NumFiretrucksOnDuty; + static int32 NumRandomCars; + static int32 NumMissionCars; + static int32 NumParkedCars; + static int32 NumPermanentCars; + static bool bCarsGeneratedAroundCamera; + static float CarDensityMultiplier; + static int8 CountDownToCarsAtStart; + static int32 MaxNumberOfCarsInUse; + static uint32 LastTimeLawEnforcerCreated; + static uint32 LastTimeFireTruckCreated; + static uint32 LastTimeAmbulanceCreated; + static int32 TotalNumOfCarsOfRating[TOTAL_CUSTOM_CLASSES]; + static int32 NextCarOfRating[TOTAL_CUSTOM_CLASSES]; + static int32 CarArrays[TOTAL_CUSTOM_CLASSES][MAX_CAR_MODELS_IN_ARRAY]; }; -extern CVehicle* (&apCarsToKeep)[MAX_CARS_TO_KEEP];
\ No newline at end of file +extern CVehicle* apCarsToKeep[MAX_CARS_TO_KEEP];
\ No newline at end of file diff --git a/src/control/Curves.cpp b/src/control/Curves.cpp index 5c6ef06d..623ab040 100644 --- a/src/control/Curves.cpp +++ b/src/control/Curves.cpp @@ -1,5 +1,5 @@ #include "common.h" -#include "patcher.h" + #include "Curves.h" float CCurves::CalcSpeedScaleFactor(CVector* pPoint1, CVector* pPoint2, float dir1X, float dir1Y, float dir2X, float dir2Y) diff --git a/src/control/Darkel.cpp b/src/control/Darkel.cpp index b4d15abf..cfd58340 100644 --- a/src/control/Darkel.cpp +++ b/src/control/Darkel.cpp @@ -1,5 +1,5 @@ #include "common.h" -#include "patcher.h" + #include "main.h" #include "Darkel.h" #include "PlayerPed.h" @@ -17,29 +17,29 @@ #define FRENZY_ANY_PED -1 #define FRENZY_ANY_CAR -2 -int32 &CDarkel::TimeLimit = *(int32*)0x885BAC; -int32 &CDarkel::PreviousTime = *(int32*)0x885B00; -int32 &CDarkel::TimeOfFrenzyStart = *(int32*)0x9430D8; -int32 &CDarkel::WeaponType = *(int32*)0x9430F0; -int32 &CDarkel::AmmoInterruptedWeapon = *(int32*)0x8E29C8; -int32 &CDarkel::KillsNeeded = *(int32*)0x8F1AB8; -int8 &CDarkel::InterruptedWeapon = *(int8*)0x95CD60; +int32 CDarkel::TimeLimit; +int32 CDarkel::PreviousTime; +int32 CDarkel::TimeOfFrenzyStart; +int32 CDarkel::WeaponType; +int32 CDarkel::AmmoInterruptedWeapon; +int32 CDarkel::KillsNeeded; +int8 CDarkel::InterruptedWeapon; /* * bStandardSoundAndMessages is a completely beta thing, * makes game handle sounds & messages instead of SCM (just like in GTA2) * but it's never been used in the game. Has unused sliding text when frenzy completed etc. */ -int8 &CDarkel::bStandardSoundAndMessages = *(int8*)0x95CDB6; -int8 &CDarkel::bNeedHeadShot = *(int8*)0x95CDCA; -int8 &CDarkel::bProperKillFrenzy = *(int8*)0x95CD98; -uint16 &CDarkel::Status = *(uint16*)0x95CCB4; -uint16 (&CDarkel::RegisteredKills)[NUM_DEFAULT_MODELS] = *(uint16(*)[NUM_DEFAULT_MODELS]) * (uintptr*)0x6EDBE0; -int32 &CDarkel::ModelToKill = *(int32*)0x8F2C78; -int32 &CDarkel::ModelToKill2 = *(int32*)0x885B40; -int32 &CDarkel::ModelToKill3 = *(int32*)0x885B3C; -int32 &CDarkel::ModelToKill4 = *(int32*)0x885B34; -wchar *CDarkel::pStartMessage = (wchar*)0x8F2C08; +int8 CDarkel::bStandardSoundAndMessages; +int8 CDarkel::bNeedHeadShot; +int8 CDarkel::bProperKillFrenzy; +uint16 CDarkel::Status; +uint16 CDarkel::RegisteredKills[NUM_DEFAULT_MODELS]; +int32 CDarkel::ModelToKill; +int32 CDarkel::ModelToKill2; +int32 CDarkel::ModelToKill3; +int32 CDarkel::ModelToKill4; +wchar *CDarkel::pStartMessage; uint8 CDarkel::CalcFade(uint32 time, uint32 start, uint32 end) @@ -262,10 +262,10 @@ CDarkel::StartFrenzy(eWeaponType weaponType, int32 time, uint16 kill, int32 mode pStartMessage = text; if (text == TheText.Get("PAGE_00")) { - CDarkel::bProperKillFrenzy = 1; - CDarkel::pStartMessage = 0; + CDarkel::bProperKillFrenzy = true; + CDarkel::pStartMessage = nil; } else - bProperKillFrenzy = 0; + bProperKillFrenzy = false; bStandardSoundAndMessages = standardSound; bNeedHeadShot = needHeadShot; @@ -284,7 +284,7 @@ CDarkel::StartFrenzy(eWeaponType weaponType, int32 time, uint16 kill, int32 mode if (FindPlayerVehicle()) { player->m_currentWeapon = player->m_nSelectedWepSlot; - player->GetWeapon()->m_nAmmoInClip = min(player->GetWeapon()->m_nAmmoTotal, CWeaponInfo::GetWeaponInfo(player->GetWeapon()->m_eWeaponType)->m_nAmountofAmmunition); + player->GetWeapon()->m_nAmmoInClip = Min(player->GetWeapon()->m_nAmmoTotal, CWeaponInfo::GetWeaponInfo(player->GetWeapon()->m_eWeaponType)->m_nAmountofAmmunition); player->ClearWeaponTarget(); } } @@ -371,19 +371,3 @@ CDarkel::Update() DMAudio.PlayFrontEndSound(SOUND_RAMPAGE_PASSED, 0); } } - -STARTPATCHES - InjectHook(0x421380, CDarkel::CalcFade, PATCH_JUMP); - InjectHook(0x420650, CDarkel::Init, PATCH_JUMP); - InjectHook(0x420660, CDarkel::Update, PATCH_JUMP); - InjectHook(0x420E60, CDarkel::FrenzyOnGoing, PATCH_JUMP); - InjectHook(0x420E50, CDarkel::ReadStatus, PATCH_JUMP); - InjectHook(0x420E70, CDarkel::ResetOnPlayerDeath, PATCH_JUMP); - InjectHook(0x4210E0, CDarkel::StartFrenzy, PATCH_JUMP); - InjectHook(0x421370, CDarkel::QueryModelsKilledByPlayer, PATCH_JUMP); - InjectHook(0x421060, CDarkel::RegisterKillNotByPlayer, PATCH_JUMP); - InjectHook(0x421310, CDarkel::ResetModelsKilledByPlayer, PATCH_JUMP); - InjectHook(0x420920, CDarkel::DrawMessages, PATCH_JUMP); - InjectHook(0x421070, CDarkel::RegisterCarBlownUpByPlayer, PATCH_JUMP); - InjectHook(0x420F60, CDarkel::RegisterKillByPlayer, PATCH_JUMP); -ENDPATCHES
\ No newline at end of file diff --git a/src/control/Darkel.h b/src/control/Darkel.h index 12ce4451..14529c63 100644 --- a/src/control/Darkel.h +++ b/src/control/Darkel.h @@ -1,9 +1,10 @@ #pragma once + #include "ModelIndices.h" +#include "WeaponType.h" class CVehicle; class CPed; -enum eWeaponType; enum { @@ -16,22 +17,22 @@ enum class CDarkel { private: - static int32 &TimeLimit; - static int32 &PreviousTime; - static int32 &TimeOfFrenzyStart; - static int32 &WeaponType; - static int32 &AmmoInterruptedWeapon; - static int32 &KillsNeeded; - static int8 &InterruptedWeapon; - static int8 &bStandardSoundAndMessages; - static int8 &bNeedHeadShot; - static int8 &bProperKillFrenzy; - static uint16 &Status; - static uint16 (&RegisteredKills)[NUM_DEFAULT_MODELS]; - static int32 &ModelToKill; - static int32 &ModelToKill2; - static int32 &ModelToKill3; - static int32 &ModelToKill4; + static int32 TimeLimit; + static int32 PreviousTime; + static int32 TimeOfFrenzyStart; + static int32 WeaponType; + static int32 AmmoInterruptedWeapon; + static int32 KillsNeeded; + static int8 InterruptedWeapon; + static int8 bStandardSoundAndMessages; + static int8 bNeedHeadShot; + static int8 bProperKillFrenzy; + static uint16 Status; + static uint16 RegisteredKills[NUM_DEFAULT_MODELS]; + static int32 ModelToKill; + static int32 ModelToKill2; + static int32 ModelToKill3; + static int32 ModelToKill4; static wchar *pStartMessage; public: diff --git a/src/control/GameLogic.cpp b/src/control/GameLogic.cpp index 8e0ea02d..f8c8fa69 100644 --- a/src/control/GameLogic.cpp +++ b/src/control/GameLogic.cpp @@ -1,5 +1,5 @@ #include "common.h" -#include "patcher.h" + #include "GameLogic.h" #include "Clock.h" #include "Stats.h" @@ -20,7 +20,7 @@ #include "Script.h" #include "Garages.h" -uint8 CGameLogic::ActivePlayers; // 0x95CD5E +uint8 CGameLogic::ActivePlayers; void CGameLogic::InitAtStartOfGame() @@ -93,7 +93,7 @@ CGameLogic::Update() if (pPlayerInfo.m_bGetOutOfHospitalFree) { pPlayerInfo.m_bGetOutOfHospitalFree = false; } else { - pPlayerInfo.m_nMoney = max(0, pPlayerInfo.m_nMoney - 1000); + pPlayerInfo.m_nMoney = Max(0, pPlayerInfo.m_nMoney - 1000); pPlayerInfo.m_pPed->ClearWeapons(); } @@ -163,7 +163,7 @@ CGameLogic::Update() if (pPlayerInfo.m_bGetOutOfJailFree) { pPlayerInfo.m_bGetOutOfJailFree = false; } else { - pPlayerInfo.m_nMoney = max(0, pPlayerInfo.m_nMoney - takeMoney); + pPlayerInfo.m_nMoney = Max(0, pPlayerInfo.m_nMoney - takeMoney); pPlayerInfo.m_pPed->ClearWeapons(); } @@ -284,11 +284,3 @@ CGameLogic::RestorePlayerStuffDuringResurrection(CPlayerPed *pPlayerPed, CVector CWorld::Remove(pPlayerPed); CWorld::Add(pPlayerPed); } - -STARTPATCHES - InjectHook(0x4213F0, &CGameLogic::InitAtStartOfGame, PATCH_JUMP); - InjectHook(0x421C00, &CGameLogic::PassTime, PATCH_JUMP); - InjectHook(0x421A20, &CGameLogic::SortOutStreamingAndMemory, PATCH_JUMP); - InjectHook(0x421400, &CGameLogic::Update, PATCH_JUMP); - InjectHook(0x421A60, &CGameLogic::RestorePlayerStuffDuringResurrection, PATCH_JUMP); -ENDPATCHES
\ No newline at end of file diff --git a/src/control/Garages.cpp b/src/control/Garages.cpp index e4b2aee3..53527503 100644 --- a/src/control/Garages.cpp +++ b/src/control/Garages.cpp @@ -1,5 +1,5 @@ #include "common.h" -#include "patcher.h" + #include "Garages.h" #include "main.h" @@ -111,27 +111,27 @@ const int32 gaCarsToCollectInCraigsGarages[TOTAL_COLLECTCARS_GARAGES][TOTAL_COLL { MI_LANDSTAL, MI_LANDSTAL, MI_LANDSTAL, MI_LANDSTAL, MI_LANDSTAL, MI_LANDSTAL, MI_LANDSTAL, MI_LANDSTAL, MI_LANDSTAL, MI_LANDSTAL, MI_LANDSTAL, MI_CHEETAH, MI_TAXI, MI_ESPERANT, MI_SENTINEL, MI_IDAHO } }; -int32& CGarages::BankVansCollected = *(int32*)0x8F1B34; -bool& CGarages::BombsAreFree = *(bool*)0x95CD7A; -bool& CGarages::RespraysAreFree = *(bool*)0x95CD1D; -int32& CGarages::CarsCollected = *(int32*)0x880E18; -int32(&CGarages::CarTypesCollected)[TOTAL_COLLECTCARS_GARAGES] = *(int32(*)[TOTAL_COLLECTCARS_GARAGES]) * (uintptr*)0x8E286C; -int32& CGarages::CrushedCarId = *(int32*)0x943060; -uint32& CGarages::LastTimeHelpMessage = *(uint32*)0x8F1B58; -int32& CGarages::MessageNumberInString = *(int32*)0x885BA8; -char(&CGarages::MessageIDString)[MESSAGE_LENGTH] = *(char(*)[MESSAGE_LENGTH]) * (uintptr*)0x878358; -int32& CGarages::MessageNumberInString2 = *(int32*)0x8E2C14; -uint32& CGarages::MessageStartTime = *(uint32*)0x8F2530; -uint32& CGarages::MessageEndTime = *(uint32*)0x8F597C; -uint32& CGarages::NumGarages = *(uint32*)0x8F29F4; -bool& CGarages::PlayerInGarage = *(bool*)0x95CD83; -int32& CGarages::PoliceCarsCollected = *(int32*)0x941444; -CStoredCar(&CGarages::aCarsInSafeHouse1)[NUM_GARAGE_STORED_CARS] = *(CStoredCar(*)[NUM_GARAGE_STORED_CARS]) * (uintptr*)0x6FA210; -CStoredCar(&CGarages::aCarsInSafeHouse2)[NUM_GARAGE_STORED_CARS] = *(CStoredCar(*)[NUM_GARAGE_STORED_CARS]) * (uintptr*)0x6FA300; -CStoredCar(&CGarages::aCarsInSafeHouse3)[NUM_GARAGE_STORED_CARS] = *(CStoredCar(*)[NUM_GARAGE_STORED_CARS]) * (uintptr*)0x6FA3F0; -int32& CGarages::AudioEntity = *(int32*)0x5ECEA8; -CGarage(&CGarages::aGarages)[NUM_GARAGES] = *(CGarage(*)[NUM_GARAGES]) * (uintptr*)0x72BCD0; -bool& CGarages::bCamShouldBeOutisde = *(bool*)0x95CDB2; +int32 CGarages::BankVansCollected; +bool CGarages::BombsAreFree; +bool CGarages::RespraysAreFree; +int32 CGarages::CarsCollected; +int32 CGarages::CarTypesCollected[TOTAL_COLLECTCARS_GARAGES]; +int32 CGarages::CrushedCarId; +uint32 CGarages::LastTimeHelpMessage; +int32 CGarages::MessageNumberInString; +char CGarages::MessageIDString[MESSAGE_LENGTH]; +int32 CGarages::MessageNumberInString2; +uint32 CGarages::MessageStartTime; +uint32 CGarages::MessageEndTime; +uint32 CGarages::NumGarages; +bool CGarages::PlayerInGarage; +int32 CGarages::PoliceCarsCollected; +CStoredCar CGarages::aCarsInSafeHouse1[NUM_GARAGE_STORED_CARS]; +CStoredCar CGarages::aCarsInSafeHouse2[NUM_GARAGE_STORED_CARS]; +CStoredCar CGarages::aCarsInSafeHouse3[NUM_GARAGE_STORED_CARS]; +int32 CGarages::AudioEntity = AEHANDLE_NONE; +CGarage CGarages::aGarages[NUM_GARAGES]; +bool CGarages::bCamShouldBeOutisde; void CGarages::Init(void) { @@ -206,12 +206,12 @@ int16 CGarages::AddOne(float X1, float Y1, float Z1, float X2, float Y2, float Z return NumGarages++; } CGarage* pGarage = &aGarages[NumGarages]; - pGarage->m_fX1 = min(X1, X2); - pGarage->m_fX2 = max(X1, X2); - pGarage->m_fY1 = min(Y1, Y2); - pGarage->m_fY2 = max(Y1, Y2); - pGarage->m_fZ1 = min(Z1, Z2); - pGarage->m_fZ2 = max(Z1, Z2); + pGarage->m_fX1 = Min(X1, X2); + pGarage->m_fX2 = Max(X1, X2); + pGarage->m_fY1 = Min(Y1, Y2); + pGarage->m_fY2 = Max(Y1, Y2); + pGarage->m_fZ1 = Min(Z1, Z2); + pGarage->m_fZ2 = Max(Z1, Z2); pGarage->m_pDoor1 = nil; pGarage->m_pDoor2 = nil; pGarage->m_fDoor1Z = Z1; @@ -307,13 +307,13 @@ void CGarage::Update() CGarages::bCamShouldBeOutisde = true; } if (pVehicle) { - if (IsEntityEntirelyOutside(pVehicle, 0.0f)) + if (!IsEntityEntirelyOutside(pVehicle, 0.0f)) TheCamera.pToGarageWeAreInForHackAvoidFirstPerson = this; if (pVehicle->GetModelIndex() == MI_MRWHOOP) { if (pVehicle->IsWithinArea( m_fX1 - DISTANCE_FOR_MRWHOOP_HACK, - m_fX2 + DISTANCE_FOR_MRWHOOP_HACK, - m_fY1 - DISTANCE_FOR_MRWHOOP_HACK, + m_fY1 + DISTANCE_FOR_MRWHOOP_HACK, + m_fX2 - DISTANCE_FOR_MRWHOOP_HACK, m_fY2 + DISTANCE_FOR_MRWHOOP_HACK)) { TheCamera.pToGarageWeAreIn = this; CGarages::bCamShouldBeOutisde = true; @@ -361,7 +361,7 @@ void CGarage::Update() } break; case GS_CLOSING: - m_fDoorPos = max(0.0f, m_fDoorPos - (m_bRotatedDoor ? ROTATED_DOOR_CLOSE_SPEED : DEFAULT_DOOR_CLOSE_SPEED) * CTimer::GetTimeStep()); + m_fDoorPos = Max(0.0f, m_fDoorPos - (m_bRotatedDoor ? ROTATED_DOOR_CLOSE_SPEED : DEFAULT_DOOR_CLOSE_SPEED) * CTimer::GetTimeStep()); if (m_fDoorPos == 0.0f) { m_eGarageState = GS_FULLYCLOSED; m_nTimeToStartAction = CTimer::GetTimeInMilliseconds() + TIME_TO_RESPRAY; @@ -440,7 +440,7 @@ void CGarage::Update() } if (bTakeMoney) { if (!CGarages::RespraysAreFree) - CWorld::Players[CWorld::PlayerInFocus].m_nMoney = max(0, CWorld::Players[CWorld::PlayerInFocus].m_nMoney - RESPRAY_PRICE); + CWorld::Players[CWorld::PlayerInFocus].m_nMoney = Max(0, CWorld::Players[CWorld::PlayerInFocus].m_nMoney - RESPRAY_PRICE); CGarages::TriggerMessage("GA_2", -1, 4000, -1); // New engine and paint job. The cops won't recognize you! } else if (bChangedColour) { @@ -458,7 +458,7 @@ void CGarage::Update() m_fY2 + DISTANCE_TO_CALL_OFF_CHASE); break; case GS_OPENING: - m_fDoorPos = min(m_fDoorHeight, m_fDoorPos + (m_bRotatedDoor ? ROTATED_DOOR_OPEN_SPEED : DEFAULT_DOOR_OPEN_SPEED) * CTimer::GetTimeStep()); + m_fDoorPos = Min(m_fDoorHeight, m_fDoorPos + (m_bRotatedDoor ? ROTATED_DOOR_OPEN_SPEED : DEFAULT_DOOR_OPEN_SPEED) * CTimer::GetTimeStep()); if (m_fDoorPos == m_fDoorHeight) { m_eGarageState = GS_OPENEDCONTAINSCAR; DMAudio.PlayOneShot(CGarages::AudioEntity, SOUND_GARAGE_DOOR_OPENED, 1.0f); @@ -503,7 +503,7 @@ void CGarage::Update() } break; case GS_CLOSING: - m_fDoorPos = max(0.0f, m_fDoorPos - (m_bRotatedDoor ? ROTATED_DOOR_CLOSE_SPEED : DEFAULT_DOOR_CLOSE_SPEED) * CTimer::GetTimeStep()); + m_fDoorPos = Max(0.0f, m_fDoorPos - (m_bRotatedDoor ? ROTATED_DOOR_CLOSE_SPEED : DEFAULT_DOOR_CLOSE_SPEED) * CTimer::GetTimeStep()); if (m_fDoorPos == 0.0f) { m_eGarageState = GS_FULLYCLOSED; m_nTimeToStartAction = CTimer::GetTimeInMilliseconds() + TIME_TO_SETUP_BOMB; @@ -520,7 +520,7 @@ void CGarage::Update() } m_eGarageState = GS_OPENING; if (!CGarages::BombsAreFree) - CWorld::Players[CWorld::PlayerInFocus].m_nMoney = max(0, CWorld::Players[CWorld::PlayerInFocus].m_nMoney - BOMB_PRICE); + CWorld::Players[CWorld::PlayerInFocus].m_nMoney = Max(0, CWorld::Players[CWorld::PlayerInFocus].m_nMoney - BOMB_PRICE); if (FindPlayerVehicle() && FindPlayerVehicle()->IsCar()) { ((CAutomobile*)(FindPlayerVehicle()))->m_bombType = CGarages::GetBombTypeForGarageType(m_eGarageType); ((CAutomobile*)(FindPlayerVehicle()))->m_pBombRigger = FindPlayerPed(); @@ -562,7 +562,7 @@ void CGarage::Update() } break; case GS_OPENING: - m_fDoorPos = min(m_fDoorHeight, m_fDoorPos + (m_bRotatedDoor ? ROTATED_DOOR_OPEN_SPEED : DEFAULT_DOOR_OPEN_SPEED) * CTimer::GetTimeStep()); + m_fDoorPos = Min(m_fDoorHeight, m_fDoorPos + (m_bRotatedDoor ? ROTATED_DOOR_OPEN_SPEED : DEFAULT_DOOR_OPEN_SPEED) * CTimer::GetTimeStep()); if (m_fDoorPos == m_fDoorHeight) { m_eGarageState = GS_OPENEDCONTAINSCAR; DMAudio.PlayOneShot(CGarages::AudioEntity, SOUND_GARAGE_DOOR_OPENED, 1.0f); @@ -597,7 +597,7 @@ void CGarage::Update() } break; case GS_CLOSING: - m_fDoorPos = max(0.0f, m_fDoorPos - (m_bRotatedDoor ? ROTATED_DOOR_CLOSE_SPEED : DEFAULT_DOOR_CLOSE_SPEED) * CTimer::GetTimeStep()); + m_fDoorPos = Max(0.0f, m_fDoorPos - (m_bRotatedDoor ? ROTATED_DOOR_CLOSE_SPEED : DEFAULT_DOOR_CLOSE_SPEED) * CTimer::GetTimeStep()); if (m_fDoorPos == 0.0f) { DMAudio.PlayOneShot(CGarages::AudioEntity, SOUND_GARAGE_DOOR_CLOSED, 1.0f); if (m_bClosingWithoutTargetCar) @@ -626,7 +626,7 @@ void CGarage::Update() } break; case GS_OPENING: - m_fDoorPos = min(m_fDoorHeight, m_fDoorPos + (m_bRotatedDoor ? ROTATED_DOOR_OPEN_SPEED : DEFAULT_DOOR_OPEN_SPEED) * CTimer::GetTimeStep()); + m_fDoorPos = Min(m_fDoorHeight, m_fDoorPos + (m_bRotatedDoor ? ROTATED_DOOR_OPEN_SPEED : DEFAULT_DOOR_OPEN_SPEED) * CTimer::GetTimeStep()); if (m_fDoorPos == m_fDoorHeight) { m_eGarageState = GS_OPENED; DMAudio.PlayOneShot(CGarages::AudioEntity, SOUND_GARAGE_DOOR_OPENED, 1.0f); @@ -663,7 +663,7 @@ void CGarage::Update() } break; case GS_CLOSING: - m_fDoorPos = max(0.0f, m_fDoorPos - (m_bRotatedDoor ? ROTATED_DOOR_CLOSE_SPEED : DEFAULT_DOOR_CLOSE_SPEED) * CTimer::GetTimeStep()); + m_fDoorPos = Max(0.0f, m_fDoorPos - (m_bRotatedDoor ? ROTATED_DOOR_CLOSE_SPEED : DEFAULT_DOOR_CLOSE_SPEED) * CTimer::GetTimeStep()); if (m_fDoorPos == 0.0f) { m_eGarageState = GS_FULLYCLOSED; DMAudio.PlayOneShot(CGarages::AudioEntity, SOUND_GARAGE_DOOR_CLOSED, 1.0f); @@ -710,7 +710,7 @@ void CGarage::Update() m_pTarget = FindPlayerVehicle(); m_pTarget->RegisterReference((CEntity**)&m_pTarget); } - m_fDoorPos = min(m_fDoorHeight, m_fDoorPos + (m_bRotatedDoor ? ROTATED_DOOR_OPEN_SPEED : DEFAULT_DOOR_OPEN_SPEED) * CTimer::GetTimeStep()); + m_fDoorPos = Min(m_fDoorHeight, m_fDoorPos + (m_bRotatedDoor ? ROTATED_DOOR_OPEN_SPEED : DEFAULT_DOOR_OPEN_SPEED) * CTimer::GetTimeStep()); if (m_fDoorPos == m_fDoorHeight) { m_eGarageState = GS_OPENED; DMAudio.PlayOneShot(CGarages::AudioEntity, SOUND_GARAGE_DOOR_OPENED, 1.0f); @@ -759,7 +759,7 @@ void CGarage::Update() } break; case GS_CLOSING: - m_fDoorPos = max(0.0f, m_fDoorPos - (m_bRotatedDoor ? ROTATED_DOOR_CLOSE_SPEED : DEFAULT_DOOR_CLOSE_SPEED) * CTimer::GetTimeStep()); + m_fDoorPos = Max(0.0f, m_fDoorPos - (m_bRotatedDoor ? ROTATED_DOOR_CLOSE_SPEED : DEFAULT_DOOR_CLOSE_SPEED) * CTimer::GetTimeStep()); if (m_fDoorPos == 0.0f) { m_eGarageState = GS_FULLYCLOSED; DMAudio.PlayOneShot(CGarages::AudioEntity, SOUND_GARAGE_DOOR_CLOSED, 1.0f); @@ -799,7 +799,7 @@ void CGarage::Update() m_pTarget = FindPlayerVehicle(); m_pTarget->RegisterReference((CEntity**)&m_pTarget); } - m_fDoorPos = min(m_fDoorHeight, m_fDoorPos + (m_bRotatedDoor ? ROTATED_DOOR_OPEN_SPEED : DEFAULT_DOOR_OPEN_SPEED) * CTimer::GetTimeStep()); + m_fDoorPos = Min(m_fDoorHeight, m_fDoorPos + (m_bRotatedDoor ? ROTATED_DOOR_OPEN_SPEED : DEFAULT_DOOR_OPEN_SPEED) * CTimer::GetTimeStep()); if (m_fDoorPos == m_fDoorHeight) { m_eGarageState = GS_OPENED; DMAudio.PlayOneShot(CGarages::AudioEntity, SOUND_GARAGE_DOOR_OPENED, 1.0f); @@ -820,7 +820,7 @@ void CGarage::Update() m_eGarageState = GS_CLOSING; break; case GS_CLOSING: - m_fDoorPos = max(0.0f, m_fDoorPos - (m_bRotatedDoor ? ROTATED_DOOR_CLOSE_SPEED : DEFAULT_DOOR_CLOSE_SPEED) * CTimer::GetTimeStep()); + m_fDoorPos = Max(0.0f, m_fDoorPos - (m_bRotatedDoor ? ROTATED_DOOR_CLOSE_SPEED : DEFAULT_DOOR_CLOSE_SPEED) * CTimer::GetTimeStep()); if (m_fDoorPos == 0.0f) { m_eGarageState = GS_FULLYCLOSED; DMAudio.PlayOneShot(CGarages::AudioEntity, SOUND_GARAGE_DOOR_CLOSED, 1.0f); @@ -831,7 +831,7 @@ void CGarage::Update() case GS_FULLYCLOSED: break; case GS_OPENING: - m_fDoorPos = min(m_fDoorHeight, m_fDoorPos + (m_bRotatedDoor ? ROTATED_DOOR_OPEN_SPEED : DEFAULT_DOOR_OPEN_SPEED) * CTimer::GetTimeStep()); + m_fDoorPos = Min(m_fDoorHeight, m_fDoorPos + (m_bRotatedDoor ? ROTATED_DOOR_OPEN_SPEED : DEFAULT_DOOR_OPEN_SPEED) * CTimer::GetTimeStep()); if (m_fDoorPos == m_fDoorHeight) { m_eGarageState = GS_OPENED; DMAudio.PlayOneShot(CGarages::AudioEntity, SOUND_GARAGE_DOOR_OPENED, 1.0f); @@ -865,7 +865,7 @@ void CGarage::Update() } case GS_CLOSING: if (m_pTarget) { - m_fDoorPos = max(0.0f, m_fDoorPos - CRUSHER_CRANE_SPEED * CTimer::GetTimeStep()); + m_fDoorPos = Max(0.0f, m_fDoorPos - CRUSHER_CRANE_SPEED * CTimer::GetTimeStep()); if (m_fDoorPos < TWOPI / 5) { m_pTarget->bUsesCollision = false; m_pTarget->bAffectedByGravity = false; @@ -876,7 +876,7 @@ void CGarage::Update() } if (m_fDoorPos == 0.0f) { CGarages::CrushedCarId = CPools::GetVehiclePool()->GetIndex(m_pTarget); - float reward = min(CRUSHER_MAX_REWARD, CRUSHER_MIN_REWARD + m_pTarget->pHandling->nMonetaryValue * m_pTarget->m_fHealth * CRUSHER_REWARD_COEFFICIENT); + float reward = Min(CRUSHER_MAX_REWARD, CRUSHER_MIN_REWARD + m_pTarget->pHandling->nMonetaryValue * m_pTarget->m_fHealth * CRUSHER_REWARD_COEFFICIENT); CWorld::Players[CWorld::PlayerInFocus].m_nMoney += reward; DestroyVehicleAndDriverAndPassengers(m_pTarget); ++CStats::CarsCrushed; @@ -900,7 +900,7 @@ void CGarage::Update() } break; case GS_OPENING: - m_fDoorPos = min(HALFPI, m_fDoorPos + CTimer::GetTimeStep() * CRUSHER_CRANE_SPEED); + m_fDoorPos = Min(HALFPI, m_fDoorPos + CTimer::GetTimeStep() * CRUSHER_CRANE_SPEED); if (m_fDoorPos == HALFPI) { m_eGarageState = GS_OPENED; DMAudio.PlayOneShot(CGarages::AudioEntity, SOUND_GARAGE_DOOR_OPENED, 1.0f); @@ -933,7 +933,7 @@ void CGarage::Update() } break; case GS_CLOSING: - m_fDoorPos = max(0.0f, m_fDoorPos - (m_bRotatedDoor ? ROTATED_DOOR_CLOSE_SPEED : DEFAULT_DOOR_CLOSE_SPEED) * CTimer::GetTimeStep()); + m_fDoorPos = Max(0.0f, m_fDoorPos - (m_bRotatedDoor ? ROTATED_DOOR_CLOSE_SPEED : DEFAULT_DOOR_CLOSE_SPEED) * CTimer::GetTimeStep()); if (m_fDoorPos == 0.0f) { DMAudio.PlayOneShot(CGarages::AudioEntity, SOUND_GARAGE_DOOR_CLOSED, 1.0f); if (m_bClosingWithoutTargetCar) @@ -961,7 +961,7 @@ void CGarage::Update() m_eGarageState = GS_OPENING; break; case GS_OPENING: - m_fDoorPos = min(m_fDoorHeight, m_fDoorPos + (m_bRotatedDoor ? ROTATED_DOOR_OPEN_SPEED : DEFAULT_DOOR_OPEN_SPEED) * CTimer::GetTimeStep()); + m_fDoorPos = Min(m_fDoorHeight, m_fDoorPos + (m_bRotatedDoor ? ROTATED_DOOR_OPEN_SPEED : DEFAULT_DOOR_OPEN_SPEED) * CTimer::GetTimeStep()); if (m_fDoorPos == m_fDoorHeight) { m_eGarageState = GS_OPENED; DMAudio.PlayOneShot(CGarages::AudioEntity, SOUND_GARAGE_DOOR_OPENED, 1.0f); @@ -981,7 +981,7 @@ void CGarage::Update() case GARAGE_FOR_SCRIPT_TO_OPEN: switch (m_eGarageState) { case GS_OPENING: - m_fDoorPos = min(m_fDoorHeight, m_fDoorPos + (m_bRotatedDoor ? ROTATED_DOOR_OPEN_SPEED : DEFAULT_DOOR_OPEN_SPEED) * CTimer::GetTimeStep()); + m_fDoorPos = Min(m_fDoorHeight, m_fDoorPos + (m_bRotatedDoor ? ROTATED_DOOR_OPEN_SPEED : DEFAULT_DOOR_OPEN_SPEED) * CTimer::GetTimeStep()); if (m_fDoorPos == m_fDoorHeight) { m_eGarageState = GS_OPENED; DMAudio.PlayOneShot(CGarages::AudioEntity, SOUND_GARAGE_DOOR_OPENED, 1.0f); @@ -1001,7 +1001,7 @@ void CGarage::Update() case GARAGE_FOR_SCRIPT_TO_OPEN_AND_CLOSE: switch (m_eGarageState) { case GS_CLOSING: - m_fDoorPos = max(0.0f, m_fDoorPos - (m_bRotatedDoor ? ROTATED_DOOR_CLOSE_SPEED : DEFAULT_DOOR_CLOSE_SPEED) * CTimer::GetTimeStep()); + m_fDoorPos = Max(0.0f, m_fDoorPos - (m_bRotatedDoor ? ROTATED_DOOR_CLOSE_SPEED : DEFAULT_DOOR_CLOSE_SPEED) * CTimer::GetTimeStep()); if (m_fDoorPos == 0.0f) { m_eGarageState = GS_FULLYCLOSED; DMAudio.PlayOneShot(CGarages::AudioEntity, SOUND_GARAGE_DOOR_CLOSED, 1.0f); @@ -1009,7 +1009,7 @@ void CGarage::Update() UpdateDoorsHeight(); break; case GS_OPENING: - m_fDoorPos = min(m_fDoorHeight, m_fDoorPos + (m_bRotatedDoor ? ROTATED_DOOR_OPEN_SPEED : DEFAULT_DOOR_OPEN_SPEED) * CTimer::GetTimeStep()); + m_fDoorPos = Min(m_fDoorHeight, m_fDoorPos + (m_bRotatedDoor ? ROTATED_DOOR_OPEN_SPEED : DEFAULT_DOOR_OPEN_SPEED) * CTimer::GetTimeStep()); if (m_fDoorPos == m_fDoorHeight) { m_eGarageState = GS_OPENED; DMAudio.PlayOneShot(CGarages::AudioEntity, SOUND_GARAGE_DOOR_OPENED, 1.0f); @@ -1050,7 +1050,7 @@ void CGarage::Update() break; } case GS_CLOSING: - m_fDoorPos = max(0.0f, m_fDoorPos - HIDEOUT_DOOR_SPEED_COEFFICIENT * (m_bRotatedDoor ? ROTATED_DOOR_CLOSE_SPEED : DEFAULT_DOOR_CLOSE_SPEED) * CTimer::GetTimeStep()); + m_fDoorPos = Max(0.0f, m_fDoorPos - HIDEOUT_DOOR_SPEED_COEFFICIENT * (m_bRotatedDoor ? ROTATED_DOOR_CLOSE_SPEED : DEFAULT_DOOR_CLOSE_SPEED) * CTimer::GetTimeStep()); if (!IsPlayerOutsideGarage()) m_eGarageState = GS_OPENING; else if (m_fDoorPos == 0.0f) { @@ -1082,7 +1082,7 @@ void CGarage::Update() #ifdef FIX_BUGS bool bCreatedAllCars = false; #else - bool bCraetedAllCars; + bool bCreatedAllCars; #endif switch (m_eGarageType) { case GARAGE_HIDEOUT_ONE: bCreatedAllCars = RestoreCarsForThisHideout(CGarages::aCarsInSafeHouse1); break; @@ -1096,7 +1096,7 @@ void CGarage::Update() break; } case GS_OPENING: - m_fDoorPos = min(m_fDoorHeight, m_fDoorPos + HIDEOUT_DOOR_SPEED_COEFFICIENT * (m_bRotatedDoor ? ROTATED_DOOR_OPEN_SPEED : DEFAULT_DOOR_OPEN_SPEED) * CTimer::GetTimeStep()); + m_fDoorPos = Min(m_fDoorHeight, m_fDoorPos + HIDEOUT_DOOR_SPEED_COEFFICIENT * (m_bRotatedDoor ? ROTATED_DOOR_OPEN_SPEED : DEFAULT_DOOR_OPEN_SPEED) * CTimer::GetTimeStep()); if (m_fDoorPos == m_fDoorHeight) { m_eGarageState = GS_OPENED; DMAudio.PlayOneShot(CGarages::AudioEntity, SOUND_GARAGE_DOOR_OPENED, 1.0f); @@ -1121,7 +1121,7 @@ void CGarage::Update() } break; case GS_CLOSING: - m_fDoorPos = max(0.0f, m_fDoorPos - (m_bRotatedDoor ? ROTATED_DOOR_CLOSE_SPEED : DEFAULT_DOOR_CLOSE_SPEED) * CTimer::GetTimeStep()); + m_fDoorPos = Max(0.0f, m_fDoorPos - (m_bRotatedDoor ? ROTATED_DOOR_CLOSE_SPEED : DEFAULT_DOOR_CLOSE_SPEED) * CTimer::GetTimeStep()); if (m_fDoorPos == 0.0f) { m_eGarageState = GS_FULLYCLOSED; DMAudio.PlayOneShot(CGarages::AudioEntity, SOUND_GARAGE_DOOR_CLOSED, 1.0f); @@ -1137,7 +1137,7 @@ void CGarage::Update() m_eGarageState = GS_OPENING; break; case GS_OPENING: - m_fDoorPos = min(m_fDoorHeight, m_fDoorPos + (m_bRotatedDoor ? ROTATED_DOOR_OPEN_SPEED : DEFAULT_DOOR_OPEN_SPEED) * CTimer::GetTimeStep()); + m_fDoorPos = Min(m_fDoorHeight, m_fDoorPos + (m_bRotatedDoor ? ROTATED_DOOR_OPEN_SPEED : DEFAULT_DOOR_OPEN_SPEED) * CTimer::GetTimeStep()); if (m_fDoorPos == m_fDoorHeight) { m_eGarageState = GS_OPENED; DMAudio.PlayOneShot(CGarages::AudioEntity, SOUND_GARAGE_DOOR_OPENED, 1.0f); @@ -1695,17 +1695,17 @@ float CGarage::CalcSmallestDistToGarageDoorSquared(float X, float Y) dist1 = SQR(m_fDoor1X - X) + SQR(m_fDoor1Y - Y); if (m_pDoor2) dist2 = SQR(m_fDoor2X - X) + SQR(m_fDoor2Y - Y); - return min(dist1, dist2); + return Min(dist1, dist2); } void CGarage::FindDoorsEntities() { m_pDoor1 = nil; m_pDoor2 = nil; - int xstart = max(0, CWorld::GetSectorIndexX(m_fX1)); - int xend = min(NUMSECTORS_X - 1, CWorld::GetSectorIndexX(m_fX2)); - int ystart = max(0, CWorld::GetSectorIndexY(m_fY1)); - int yend = min(NUMSECTORS_Y - 1, CWorld::GetSectorIndexY(m_fY2)); + int xstart = Max(0, CWorld::GetSectorIndexX(m_fX1)); + int xend = Min(NUMSECTORS_X - 1, CWorld::GetSectorIndexX(m_fX2)); + int ystart = Max(0, CWorld::GetSectorIndexY(m_fY1)); + int yend = Min(NUMSECTORS_Y - 1, CWorld::GetSectorIndexY(m_fY2)); assert(xstart <= xend); assert(ystart <= yend); @@ -1891,7 +1891,7 @@ void CGarage::StoreAndRemoveCarsForThisHideout(CStoredCar* aCars, int32 nMax) pVehicle->GetPosition().y > m_fY1 && pVehicle->GetPosition().y < m_fY2 && pVehicle->GetPosition().z > m_fZ1 && pVehicle->GetPosition().z < m_fZ2) { if (pVehicle->VehicleCreatedBy != MISSION_VEHICLE) { - if (index < max(NUM_GARAGE_STORED_CARS, nMax) && !EntityHasASphereWayOutsideGarage(pVehicle, 1.0f)) + if (index < Max(NUM_GARAGE_STORED_CARS, nMax) && !EntityHasASphereWayOutsideGarage(pVehicle, 1.0f)) aCars[index++].StoreCar(pVehicle); CWorld::Players[CWorld::PlayerInFocus].CancelPlayerEnteringCars(pVehicle); CWorld::Remove(pVehicle); @@ -2256,7 +2256,7 @@ void CGarages::Save(uint8 * buf, uint32 * size) #endif } -CStoredCar::CStoredCar(const CStoredCar & other) +const CStoredCar &CStoredCar::operator=(const CStoredCar & other) { m_nModelIndex = other.m_nModelIndex; m_vecPos = other.m_vecPos; @@ -2272,6 +2272,7 @@ CStoredCar::CStoredCar(const CStoredCar & other) m_nVariationA = other.m_nVariationA; m_nVariationB = other.m_nVariationB; m_nCarBombType = other.m_nCarBombType; + return *this; } void CGarages::Load(uint8* buf, uint32 size) @@ -2313,6 +2314,10 @@ void CGarages::Load(uint8* buf, uint32 size) #ifdef FIX_GARAGE_SIZE VALIDATESAVEBUF(size); #endif + + MessageEndTime = 0; + bCamShouldBeOutisde = false; + MessageStartTime = 0; } bool @@ -2352,10 +2357,3 @@ CGarages::IsModelIndexADoor(uint32 id) id == MI_CRUSHERBODY || id == MI_CRUSHERLID; } - - -STARTPATCHES - InjectHook(0x427AB0, CGarages::IsPointInAGarageCameraZone, PATCH_JUMP); // CCamera::CamControl - InjectHook(0x427BC0, CGarages::CameraShouldBeOutside, PATCH_JUMP); // CCamera::CamControl - InjectHook(0x428940, CGarages::Load, PATCH_JUMP); // GenericLoad -ENDPATCHES diff --git a/src/control/Garages.h b/src/control/Garages.h index 26e7a89a..65193b32 100644 --- a/src/control/Garages.h +++ b/src/control/Garages.h @@ -70,7 +70,7 @@ public: void Init() { m_nModelIndex = 0; } void Clear() { m_nModelIndex = 0; } bool HasCar() { return m_nModelIndex != 0; } - CStoredCar(const CStoredCar& other); + const CStoredCar &operator=(const CStoredCar& other); void StoreCar(CVehicle*); CVehicle* RestoreCar(); }; @@ -179,27 +179,27 @@ class CGarages enum { MESSAGE_LENGTH = 8 }; - static int32 &BankVansCollected; - static bool &BombsAreFree; - static bool &RespraysAreFree; - static int32 &CarsCollected; - static int32 (&CarTypesCollected)[TOTAL_COLLECTCARS_GARAGES]; - static int32 &CrushedCarId; - static uint32 &LastTimeHelpMessage; - static int32 &MessageNumberInString; - static char(&MessageIDString)[MESSAGE_LENGTH]; - static int32 &MessageNumberInString2; - static uint32 &MessageStartTime; - static uint32 &MessageEndTime; - static uint32 &NumGarages; - static bool &PlayerInGarage; - static int32 &PoliceCarsCollected; - static CGarage(&aGarages)[NUM_GARAGES]; - static CStoredCar(&aCarsInSafeHouse1)[NUM_GARAGE_STORED_CARS]; - static CStoredCar(&aCarsInSafeHouse2)[NUM_GARAGE_STORED_CARS]; - static CStoredCar(&aCarsInSafeHouse3)[NUM_GARAGE_STORED_CARS]; - static int32 &AudioEntity; - static bool &bCamShouldBeOutisde; + static int32 BankVansCollected; + static bool BombsAreFree; + static bool RespraysAreFree; + static int32 CarsCollected; + static int32 CarTypesCollected[TOTAL_COLLECTCARS_GARAGES]; + static int32 CrushedCarId; + static uint32 LastTimeHelpMessage; + static int32 MessageNumberInString; + static char MessageIDString[MESSAGE_LENGTH]; + static int32 MessageNumberInString2; + static uint32 MessageStartTime; + static uint32 MessageEndTime; + static uint32 NumGarages; + static bool PlayerInGarage; + static int32 PoliceCarsCollected; + static CGarage aGarages[NUM_GARAGES]; + static CStoredCar aCarsInSafeHouse1[NUM_GARAGE_STORED_CARS]; + static CStoredCar aCarsInSafeHouse2[NUM_GARAGE_STORED_CARS]; + static CStoredCar aCarsInSafeHouse3[NUM_GARAGE_STORED_CARS]; + static int32 AudioEntity; + static bool bCamShouldBeOutisde; public: static void Init(void); diff --git a/src/control/OnscreenTimer.cpp b/src/control/OnscreenTimer.cpp index 5406522c..d128efeb 100644 --- a/src/control/OnscreenTimer.cpp +++ b/src/control/OnscreenTimer.cpp @@ -1,5 +1,5 @@ #include "common.h" -#include "patcher.h" + #include "DMAudio.h" #include "Hud.h" @@ -153,18 +153,3 @@ void COnscreenTimerEntry::ProcessForDisplayCounter() { uint32 counter = *CTheScripts::GetPointerToScriptVariable(m_nCounterOffset); sprintf(m_bCounterBuffer, "%d", counter); } - -STARTPATCHES - InjectHook(0x429160, &COnscreenTimerEntry::Process, PATCH_JUMP); - InjectHook(0x429110, &COnscreenTimerEntry::ProcessForDisplay, PATCH_JUMP); - InjectHook(0x429080, &COnscreenTimerEntry::ProcessForDisplayClock, PATCH_JUMP); - InjectHook(0x4290F0, &COnscreenTimerEntry::ProcessForDisplayCounter, PATCH_JUMP); - - InjectHook(0x429220, &COnscreenTimer::Init, PATCH_JUMP); - InjectHook(0x429320, &COnscreenTimer::Process, PATCH_JUMP); - InjectHook(0x4292E0, &COnscreenTimer::ProcessForDisplay, PATCH_JUMP); - InjectHook(0x429450, &COnscreenTimer::ClearCounter, PATCH_JUMP); - InjectHook(0x429410, &COnscreenTimer::ClearClock, PATCH_JUMP); - InjectHook(0x4293B0, &COnscreenTimer::AddCounter, PATCH_JUMP); - InjectHook(0x429350, &COnscreenTimer::AddClock, PATCH_JUMP); -ENDPATCHES
\ No newline at end of file diff --git a/src/control/PathFind.cpp b/src/control/PathFind.cpp index 61cd3d4e..44062b38 100644 --- a/src/control/PathFind.cpp +++ b/src/control/PathFind.cpp @@ -1,5 +1,5 @@ #include "common.h" -#include "patcher.h" + #include "General.h" #include "FileMgr.h" // only needed for empty function #include "Camera.h" @@ -12,21 +12,213 @@ bool gbShowPedPaths; bool gbShowCarPaths; bool gbShowCarPathsLinks; -CPathFind &ThePaths = *(CPathFind*)0x8F6754; - -WRAPPER bool CPedPath::CalcPedRoute(uint8, CVector, CVector, CVector*, int16*, int16) { EAXJMP(0x42E680); } +CPathFind ThePaths; #define MAX_DIST INT16_MAX-1 +#define MIN_PED_ROUTE_DISTANCE 23.8f // object flags: // 1 UseInRoadBlock // 2 east/west road(?) -CPathInfoForObject *&InfoForTileCars = *(CPathInfoForObject**)0x8F1A8C; -CPathInfoForObject *&InfoForTilePeds = *(CPathInfoForObject**)0x8F1AE4; +CPathInfoForObject *InfoForTileCars; +CPathInfoForObject *InfoForTilePeds; // unused -CTempDetachedNode *&DetachedNodesCars = *(CTempDetachedNode**)0x8E2824; -CTempDetachedNode *&DetachedNodesPeds = *(CTempDetachedNode**)0x8E28A0; +CTempDetachedNode *DetachedNodesCars; +CTempDetachedNode *DetachedNodesPeds; + +bool +CPedPath::CalcPedRoute(int8 pathType, CVector position, CVector destination, CVector *pointPoses, int16 *pointsFound, int16 maxPoints) +{ + *pointsFound = 0; + CVector vecDistance = destination - position; + if (Abs(vecDistance.x) > MIN_PED_ROUTE_DISTANCE || Abs(vecDistance.y) > MIN_PED_ROUTE_DISTANCE || Abs(vecDistance.z) > MIN_PED_ROUTE_DISTANCE) + return false; + CVector vecPos = (position + destination) * 0.5f; + CVector vecSectorStartPos (vecPos.x - 14.0f, vecPos.y - 14.0f, vecPos.z); + CVector2D vecSectorEndPos (vecPos.x + 28.0f, vecPos.x + 28.0f); + const int16 nodeStartX = (position.x - vecSectorStartPos.x) / 0.7f; + const int16 nodeStartY = (position.y - vecSectorStartPos.y) / 0.7f; + const int16 nodeEndX = (destination.x - vecSectorStartPos.x) / 0.7f; + const int16 nodeEndY = (destination.y - vecSectorStartPos.y) / 0.7f; + if (nodeStartX == nodeEndX && nodeStartY == nodeEndY) + return false; + CPedPathNode pathNodes[40][40]; + CPedPathNode pathNodesList[416]; + for (int32 x = 0; x < 40; x++) { + for (int32 y = 0; y < 40; y++) { + pathNodes[x][y].bBlockade = false; + pathNodes[x][y].id = INT16_MAX; + pathNodes[x][y].nodeIdX = x; + pathNodes[x][y].nodeIdY = y; + } + } + CWorld::AdvanceCurrentScanCode(); + if (pathType != ROUTE_NO_BLOCKADE) { + const int32 nStartX = Max(CWorld::GetSectorIndexX(vecSectorStartPos.x), 0); + const int32 nStartY = Max(CWorld::GetSectorIndexY(vecSectorStartPos.y), 0); + const int32 nEndX = Min(CWorld::GetSectorIndexX(vecSectorEndPos.x), NUMSECTORS_X - 1); + const int32 nEndY = Min(CWorld::GetSectorIndexY(vecSectorEndPos.y), NUMSECTORS_Y - 1); + for (int32 y = nStartY; y <= nEndY; y++) { + for (int32 x = nStartX; x <= nEndX; x++) { + CSector *pSector = CWorld::GetSector(x, y); + AddBlockadeSectorList(pSector->m_lists[ENTITYLIST_VEHICLES], pathNodes, &vecSectorStartPos); + AddBlockadeSectorList(pSector->m_lists[ENTITYLIST_VEHICLES_OVERLAP], pathNodes, &vecSectorStartPos); + AddBlockadeSectorList(pSector->m_lists[ENTITYLIST_OBJECTS], pathNodes, &vecSectorStartPos); + AddBlockadeSectorList(pSector->m_lists[ENTITYLIST_OBJECTS_OVERLAP], pathNodes, &vecSectorStartPos); + } + } + } + for (int32 i = 0; i < 416; i++) { + pathNodesList[i].prev = nil; + pathNodesList[i].next = nil; + } + CPedPathNode *pStartPathNode = &pathNodes[nodeStartX][nodeStartY]; + CPedPathNode *pEndPathNode = &pathNodes[nodeEndX][nodeEndY]; + pEndPathNode->bBlockade = false; + pEndPathNode->id = 0; + pEndPathNode->prev = nil; + pEndPathNode->next = pathNodesList; + pathNodesList[0].prev = pEndPathNode; + int32 pathNodeIndex = 0; + CPedPathNode *pPreviousNode = nil; + for (; pathNodeIndex < 414; pathNodeIndex++) + { + pPreviousNode = pathNodesList[pathNodeIndex].prev; + while (pPreviousNode && pPreviousNode != pStartPathNode) { + const uint8 nodeIdX = pPreviousNode->nodeIdX; + const uint8 nodeIdY = pPreviousNode->nodeIdY; + if (nodeIdX > 0) { + AddNodeToPathList(&pathNodes[nodeIdX - 1][nodeIdY], pathNodeIndex + 5, pathNodesList); + if (nodeIdY > 0) + AddNodeToPathList(&pathNodes[nodeIdX - 1][nodeIdY - 1], pathNodeIndex + 7, pathNodesList); + if (nodeIdY < 39) + AddNodeToPathList(&pathNodes[nodeIdX - 1][nodeIdY + 1], pathNodeIndex + 7, pathNodesList); + } + if (nodeIdX < 39) { + AddNodeToPathList(&pathNodes[nodeIdX + 1][nodeIdY], pathNodeIndex + 5, pathNodesList); + if (nodeIdY > 0) + AddNodeToPathList(&pathNodes[nodeIdX + 1][nodeIdY - 1], pathNodeIndex + 7, pathNodesList); + if (nodeIdY < 39) + AddNodeToPathList(&pathNodes[nodeIdX + 1][nodeIdY + 1], pathNodeIndex + 7, pathNodesList); + } + if (nodeIdY > 0) + AddNodeToPathList(&pathNodes[nodeIdX][nodeIdY - 1], pathNodeIndex + 5, pathNodesList); + if (nodeIdY < 39) + AddNodeToPathList(&pathNodes[nodeIdX][nodeIdY + 1], pathNodeIndex + 5, pathNodesList); + pPreviousNode = pPreviousNode->prev; + if (!pPreviousNode) + break; + } + + if (pPreviousNode && pPreviousNode == pStartPathNode) + break; + } + if (pathNodeIndex == 414) + return false; + CPedPathNode *pPathNode = pStartPathNode; + for (*pointsFound = 0; pPathNode != pEndPathNode && *pointsFound < maxPoints; ++ *pointsFound) { + const uint8 nodeIdX = pPathNode->nodeIdX; + const uint8 nodeIdY = pPathNode->nodeIdY; + if (nodeIdX > 0 && pathNodes[nodeIdX - 1][nodeIdY].id + 5 == pPathNode->id) + pPathNode = &pathNodes[nodeIdX - 1][nodeIdY]; + else if (nodeIdX > 39 && pathNodes[nodeIdX + 1][nodeIdY].id + 5 == pPathNode->id) + pPathNode = &pathNodes[nodeIdX + 1][nodeIdY]; + else if (nodeIdY > 0 && pathNodes[nodeIdX][nodeIdY - 1].id + 5 == pPathNode->id) + pPathNode = &pathNodes[nodeIdX][nodeIdY - 1]; + else if (nodeIdY > 39 && pathNodes[nodeIdX][nodeIdY + 1].id + 5 == pPathNode->id) + pPathNode = &pathNodes[nodeIdX][nodeIdY + 1]; + else if (nodeIdX > 0 && nodeIdY > 0 && pathNodes[nodeIdX - 1][nodeIdY - 1].id + 7 == pPathNode->id) + pPathNode = &pathNodes[nodeIdX - 1][nodeIdY - 1]; + else if (nodeIdX > 0 && nodeIdY < 39 && pathNodes[nodeIdX - 1][nodeIdY + 1].id + 7 == pPathNode->id) + pPathNode = &pathNodes[nodeIdX - 1][nodeIdY + 1]; + else if (nodeIdX < 39 && nodeIdY > 0 && pathNodes[nodeIdX + 1][nodeIdY - 1].id + 7 == pPathNode->id) + pPathNode = &pathNodes[nodeIdX + 1][nodeIdY - 1]; + else if (nodeIdX < 39 && nodeIdY < 39 && pathNodes[nodeIdX + 1][nodeIdY + 1].id + 7 == pPathNode->id) + pPathNode = &pathNodes[nodeIdX + 1][nodeIdY + 1]; + pointPoses[*pointsFound] = vecSectorStartPos; + pointPoses[*pointsFound].x += pPathNode->nodeIdX * 0.7f; + pointPoses[*pointsFound].y += pPathNode->nodeIdY * 0.7f; + } + return true; +} + + +void +CPedPath::AddNodeToPathList(CPedPathNode *pNodeToAdd, int16 id, CPedPathNode *pNodeList) +{ + if (!pNodeToAdd->bBlockade && id < pNodeToAdd->id) { + if (pNodeToAdd->id != INT16_MAX) + RemoveNodeFromList(pNodeToAdd); + AddNodeToList(pNodeToAdd, id, pNodeList); + } +} + +void +CPedPath::RemoveNodeFromList(CPedPathNode *pNode) +{ + pNode->next->prev = pNode->prev; + if (pNode->prev) + pNode->prev->next = pNode->next; +} + +void +CPedPath::AddNodeToList(CPedPathNode *pNode, int16 index, CPedPathNode *pList) +{ + pNode->prev = pList[index].prev; + pNode->next = &pList[index]; + if (pList[index].prev) + pList[index].prev->next = pNode; + pList[index].prev = pNode; + pNode->id = index; +} + +void +CPedPath::AddBlockadeSectorList(CPtrList& list, CPedPathNode(*pathNodes)[40], CVector *pPosition) +{ + CPtrNode* listNode = list.first; + while (listNode) { + CEntity* pEntity = (CEntity*)listNode->item; + if (pEntity->m_scanCode != CWorld::GetCurrentScanCode() && pEntity->bUsesCollision) { + pEntity->m_scanCode = CWorld::GetCurrentScanCode(); + AddBlockade(pEntity, pathNodes, pPosition); + } + listNode = listNode->next; + } +} + +void +CPedPath::AddBlockade(CEntity *pEntity, CPedPathNode(*pathNodes)[40], CVector *pPosition) +{ + const CColBox& boundingBox = pEntity->GetColModel()->boundingBox; + const float fBoundMaxY = boundingBox.max.y + 0.3f; + const float fBoundMinY = boundingBox.min.y - 0.3f; + const float fBoundMaxX = boundingBox.max.x + 0.3f; + const float fDistanceX = pPosition->x - pEntity->m_matrix.GetPosition().x; + const float fDistanceY = pPosition->y - pEntity->m_matrix.GetPosition().y; + const float fBoundRadius = pEntity->GetBoundRadius(); + CVector vecBoundCentre; + pEntity->GetBoundCentre(vecBoundCentre); + if (vecBoundCentre.x + fBoundRadius >= pPosition->x && + vecBoundCentre.y + fBoundRadius >= pPosition->y && + vecBoundCentre.x - fBoundRadius <= pPosition->x + 28.0f && + vecBoundCentre.y - fBoundRadius <= pPosition->y + 28.0f) { + for (int16 x = 0; x < 40; x++) { + const float pointX = x * 0.7f + fDistanceX; + for (int16 y = 0; y < 40; y++) { + if (!pathNodes[x][y].bBlockade) { + const float pointY = y * 0.7f + fDistanceY; + CVector2D point(pointX, pointY); + if (fBoundMaxX > Abs(DotProduct2D(point, pEntity->m_matrix.GetRight()))) { + float fDotProduct = DotProduct2D(point, pEntity->m_matrix.GetForward()); + if (fBoundMaxY > fDotProduct && fBoundMinY < fDotProduct) + pathNodes[x][y].bBlockade = true; + } + } + } + } + } +} void CPathFind::Init(void) @@ -205,8 +397,8 @@ CPathFind::PreparePathData(void) numExtern++; if(InfoForTileCars[k].numLeftLanes + InfoForTileCars[k].numRightLanes > numLanes) numLanes = InfoForTileCars[k].numLeftLanes + InfoForTileCars[k].numRightLanes; - maxX = max(maxX, Abs(InfoForTileCars[k].x)); - maxY = max(maxY, Abs(InfoForTileCars[k].y)); + maxX = Max(maxX, Abs(InfoForTileCars[k].x)); + maxY = Max(maxY, Abs(InfoForTileCars[k].y)); }else if(InfoForTileCars[k].type == NodeTypeIntern) numIntern++; } @@ -390,7 +582,7 @@ CPathFind::PreparePathDataForType(uint8 type, CTempNode *tempnodes, CPathInfoFor if(Abs(dx) < nearestDist){ dy = tempnodes[k].pos.y - CoorsXFormed.y; if(Abs(dy) < nearestDist){ - nearestDist = max(Abs(dx), Abs(dy)); + nearestDist = Max(Abs(dx), Abs(dy)); nearestId = k; } } @@ -499,13 +691,13 @@ CPathFind::PreparePathDataForType(uint8 type, CTempNode *tempnodes, CPathInfoFor // Find i inside path segment iseg = 0; - for(j = max(oldNumPathNodes, i-12); j < i; j++) + for(j = Max(oldNumPathNodes, i-12); j < i; j++) if(m_pathNodes[j].objectIndex == m_pathNodes[i].objectIndex) iseg++; istart = 12*m_mapObjects[m_pathNodes[i].objectIndex]->m_modelIndex; // Add links to other internal nodes - for(j = max(oldNumPathNodes, i-12); j < min(m_numPathNodes, i+12); j++){ + for(j = Max(oldNumPathNodes, i-12); j < Min(m_numPathNodes, i+12); j++){ if(m_pathNodes[i].objectIndex != m_pathNodes[j].objectIndex || i == j) continue; // N.B.: in every path segment, the externals have to be at the end @@ -1274,8 +1466,11 @@ CPathFind::DoPathSearch(uint8 type, CVector start, int32 startNodeId, CVector ta targetNode = FindNodeClosestToCoors(target, type, distLimit); else targetNode = forcedTargetNode; - if(targetNode < 0) - goto fail; + if(targetNode < 0) { + *pNumNodes = 0; + if(pDist) *pDist = 100000.0f; + return; + } // Find start int numPathsToTry; @@ -1294,19 +1489,28 @@ CPathFind::DoPathSearch(uint8 type, CVector start, int32 startNodeId, CVector ta numPathsToTry = 1; startObj = m_mapObjects[m_pathNodes[startNodeId].objectIndex]; } - if(numPathsToTry == 0) - goto fail; + if(numPathsToTry == 0) { + *pNumNodes = 0; + if(pDist) *pDist = 100000.0f; + return; + } if(startNodeId < 0){ // why only check node 0? - if(m_pathNodes[startObj->m_nodeIndices[type][0]].group != m_pathNodes[targetNode].group) - goto fail; + if(m_pathNodes[startObj->m_nodeIndices[type][0]].group != + m_pathNodes[targetNode].group) { + *pNumNodes = 0; + if(pDist) *pDist = 100000.0f; + return; + } }else{ - if(m_pathNodes[startNodeId].group != m_pathNodes[targetNode].group) - goto fail; + if(m_pathNodes[startNodeId].group != m_pathNodes[targetNode].group) { + *pNumNodes = 0; + if(pDist) *pDist = 100000.0f; + return; + } } - for(i = 0; i < 512; i++) m_searchNodes[i].next = nil; AddNodeToList(&m_pathNodes[targetNode], 0); @@ -1384,11 +1588,6 @@ CPathFind::DoPathSearch(uint8 type, CVector start, int32 startNodeId, CVector ta for(i = 0; i < numNodesToBeCleared; i++) apNodesToBeCleared[i]->distance = MAX_DIST; return; - -fail: - *pNumNodes = 0; - if(pDist) - *pDist = 100000.0f; } static CPathNode *pNodeList[32]; @@ -1574,41 +1773,3 @@ CPathFind::DisplayPathData(void) } } } - -STARTPATCHES - InjectHook(0x4294A0, &CPathFind::Init, PATCH_JUMP); - InjectHook(0x42D580, &CPathFind::AllocatePathFindInfoMem, PATCH_JUMP); - InjectHook(0x429540, &CPathFind::RegisterMapObject, PATCH_JUMP); - InjectHook(0x42D7E0, &CPathFind::StoreNodeInfoPed, PATCH_JUMP); - InjectHook(0x42D690, &CPathFind::StoreNodeInfoCar, PATCH_JUMP); - InjectHook(0x429610, &CPathFind::PreparePathData, PATCH_JUMP); - InjectHook(0x42B810, &CPathFind::CountFloodFillGroups, PATCH_JUMP); - InjectHook(0x429C20, &CPathFind::PreparePathDataForType, PATCH_JUMP); - - InjectHook(0x42C990, &CPathFind::CalcRoadDensity, PATCH_JUMP); - InjectHook(0x42E1B0, &CPathFind::TestForPedTrafficLight, PATCH_JUMP); - InjectHook(0x42E340, &CPathFind::TestCrossesRoad, PATCH_JUMP); - InjectHook(0x42CBE0, &CPathFind::AddNodeToList, PATCH_JUMP); - InjectHook(0x42CBB0, &CPathFind::RemoveNodeFromList, PATCH_JUMP); - InjectHook(0x42B790, &CPathFind::RemoveBadStartNode, PATCH_JUMP); - InjectHook(0x42E3B0, &CPathFind::SetLinksBridgeLights, PATCH_JUMP); - InjectHook(0x42DED0, &CPathFind::SwitchOffNodeAndNeighbours, PATCH_JUMP); - InjectHook(0x42D960, &CPathFind::SwitchRoadsOffInArea, PATCH_JUMP); - InjectHook(0x42DA50, &CPathFind::SwitchPedRoadsOffInArea, PATCH_JUMP); - InjectHook(0x42DB50, &CPathFind::SwitchRoadsInAngledArea, PATCH_JUMP); - InjectHook(0x42E140, &CPathFind::MarkRoadsBetweenLevelsNodeAndNeighbours, PATCH_JUMP); - InjectHook(0x42DF50, &CPathFind::MarkRoadsBetweenLevelsInArea, PATCH_JUMP); - InjectHook(0x42E040, &CPathFind::PedMarkRoadsBetweenLevelsInArea, PATCH_JUMP); - InjectHook(0x42CC30, &CPathFind::FindNodeClosestToCoors, PATCH_JUMP); - InjectHook(0x42CDC0, &CPathFind::FindNodeClosestToCoorsFavourDirection, PATCH_JUMP); - InjectHook(0x42CFC0, &CPathFind::FindNodeOrientationForCarPlacement, PATCH_JUMP); - InjectHook(0x42D060, &CPathFind::FindNodeOrientationForCarPlacementFacingDestination, PATCH_JUMP); - InjectHook(0x42BF10, &CPathFind::NewGenerateCarCreationCoors, PATCH_JUMP); - InjectHook(0x42C1E0, &CPathFind::GeneratePedCreationCoors, PATCH_JUMP); - InjectHook(0x42D2A0, &CPathFind::FindRoadObjectClosestToCoors, PATCH_JUMP); - InjectHook(0x42B9F0, &CPathFind::FindNextNodeWandering, PATCH_JUMP); - InjectHook(0x42B040, &CPathFind::DoPathSearch, PATCH_JUMP); - InjectHook(0x42C8C0, &CPathFind::TestCoorsCloseness, PATCH_JUMP); - InjectHook(0x42E450, &CPathFind::Save, PATCH_JUMP); - InjectHook(0x42E550, &CPathFind::Load, PATCH_JUMP); -ENDPATCHES diff --git a/src/control/PathFind.h b/src/control/PathFind.h index 81467cdf..64c12d5b 100644 --- a/src/control/PathFind.h +++ b/src/control/PathFind.h @@ -3,11 +3,7 @@ #include "Treadable.h" class CVehicle; - -class CPedPath { -public: - static bool CalcPedRoute(uint8, CVector, CVector, CVector*, int16*, int16); -}; +class CPtrList; enum { @@ -30,6 +26,33 @@ enum SWITCH_ON = 1, }; +enum +{ + ROUTE_ADD_BLOCKADE = 0, + ROUTE_NO_BLOCKADE = 1 +}; + +struct CPedPathNode +{ + bool bBlockade; + uint8 nodeIdX; + uint8 nodeIdY; + int16 id; + CPedPathNode* prev; + CPedPathNode* next; +}; +static_assert(sizeof(CPedPathNode) == 0x10, "CPedPathNode: error"); + +class CPedPath { +public: + static bool CalcPedRoute(int8 pathType, CVector position, CVector destination, CVector *pointPoses, int16 *pointsFound, int16 maxPoints); + static void AddNodeToPathList(CPedPathNode *pNodeToAdd, int16 id, CPedPathNode *pNodeList); + static void RemoveNodeFromList(CPedPathNode *pNode); + static void AddNodeToList(CPedPathNode *pNode, int16 index, CPedPathNode *pList); + static void AddBlockade(CEntity *pEntity, CPedPathNode(*pathNodes)[40], CVector *pPosition); + static void AddBlockadeSectorList(CPtrList& list, CPedPathNode(*pathNodes)[40], CVector *pPosition); +}; + struct CPathNode { CVector pos; @@ -115,8 +138,8 @@ struct CPathInfoForObject int8 numRightLanes; uint8 crossing : 1; }; -extern CPathInfoForObject *&InfoForTileCars; -extern CPathInfoForObject *&InfoForTilePeds; +extern CPathInfoForObject *InfoForTileCars; +extern CPathInfoForObject *InfoForTilePeds; struct CTempNode { @@ -211,7 +234,7 @@ public: }; static_assert(sizeof(CPathFind) == 0x49bf4, "CPathFind: error"); -extern CPathFind &ThePaths; +extern CPathFind ThePaths; extern bool gbShowPedPaths; extern bool gbShowCarPaths; diff --git a/src/control/Phones.cpp b/src/control/Phones.cpp index 276f02b9..15e9f9f1 100644 --- a/src/control/Phones.cpp +++ b/src/control/Phones.cpp @@ -1,5 +1,5 @@ #include "common.h" -#include "patcher.h" + #include "Phones.h" #include "Pools.h" #include "ModelIndices.h" @@ -12,14 +12,17 @@ #include "AudioScriptObject.h" #include "RpAnimBlend.h" #include "AnimBlendAssociation.h" +#ifdef FIX_BUGS +#include "Replay.h" +#endif -CPhoneInfo &gPhoneInfo = *(CPhoneInfo*)0x732A20; +CPhoneInfo gPhoneInfo; -bool &CPhoneInfo::bDisplayingPhoneMessage = *(bool*)0x6283AC; // is phone picked up -uint32 &CPhoneInfo::PhoneEnableControlsTimer = *(uint32*)0x6283A8; -CPhone *&CPhoneInfo::pPhoneDisplayingMessages = *(CPhone**)0x6283B0; -bool &CPhoneInfo::bPickingUpPhone = *(bool*)0x6283B4; -CPed *&CPhoneInfo::pCallBackPed = *(CPed**)0x6283B8; // ped who picking up the phone (reset after pickup cb) +bool CPhoneInfo::bDisplayingPhoneMessage; // is phone picked up +uint32 CPhoneInfo::PhoneEnableControlsTimer; +CPhone *CPhoneInfo::pPhoneDisplayingMessages; +bool CPhoneInfo::bPickingUpPhone; +CPed *CPhoneInfo::pCallBackPed; // ped who picking up the phone (reset after pickup cb) /* Entering phonebooth cutscene, showing messages and triggering these things @@ -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) { @@ -377,20 +384,3 @@ PhonePickUpCB(CAnimBlendAssociation *assoc, void *arg) CPhoneInfo::pCallBackPed = nil; } - -STARTPATCHES - InjectHook(0x42F720, &CPhoneInfo::FindNearestFreePhone, PATCH_JUMP); - InjectHook(0x42FD50, &CPhoneInfo::PhoneAtThisPosition, PATCH_JUMP); - InjectHook(0x42FFF0, &CPhoneInfo::HasMessageBeenDisplayed, PATCH_JUMP); - InjectHook(0x430030, &CPhoneInfo::IsMessageBeingDisplayed, PATCH_JUMP); - InjectHook(0x430120, &CPhoneInfo::Load, PATCH_JUMP); - InjectHook(0x42FF90, &CPhoneInfo::SetPhoneMessage_JustOnce, PATCH_JUMP); - InjectHook(0x42FF30, &CPhoneInfo::SetPhoneMessage_Repeatedly, PATCH_JUMP); - InjectHook(0x430060, &CPhoneInfo::Save, PATCH_JUMP); - InjectHook(0x42F710, &CPhoneInfo::Shutdown, PATCH_JUMP); - InjectHook(0x42F640, &CPhoneInfo::Initialise, PATCH_JUMP); - InjectHook(0x42FDB0, &CPhoneInfo::GrabPhone, PATCH_JUMP); - InjectHook(0x42F7A0, &CPhoneInfo::Update, PATCH_JUMP); - InjectHook(0x42F570, &PhonePutDownCB, PATCH_JUMP); - InjectHook(0x42F470, &PhonePickUpCB, PATCH_JUMP); -ENDPATCHES
\ No newline at end of file diff --git a/src/control/Phones.h b/src/control/Phones.h index e7e3c9a7..7fbf403f 100644 --- a/src/control/Phones.h +++ b/src/control/Phones.h @@ -36,11 +36,11 @@ static_assert(sizeof(CPhone) == 0x34, "CPhone: error"); class CPhoneInfo { public: - static bool &bDisplayingPhoneMessage; - static uint32 &PhoneEnableControlsTimer; - static CPhone *&pPhoneDisplayingMessages; - static bool &bPickingUpPhone; - static CPed *&pCallBackPed; + static bool bDisplayingPhoneMessage; + static uint32 PhoneEnableControlsTimer; + static CPhone *pPhoneDisplayingMessages; + static bool bPickingUpPhone; + static CPed *pCallBackPed; int32 m_nMax; int32 m_nScriptPhonesMax; @@ -63,7 +63,7 @@ public: void Update(void); }; -extern CPhoneInfo &gPhoneInfo; +extern CPhoneInfo gPhoneInfo; void PhonePutDownCB(CAnimBlendAssociation *assoc, void *arg); void PhonePickUpCB(CAnimBlendAssociation *assoc, void *arg); diff --git a/src/control/Pickups.cpp b/src/control/Pickups.cpp index eb561670..d5db4ad8 100644 --- a/src/control/Pickups.cpp +++ b/src/control/Pickups.cpp @@ -1,5 +1,5 @@ #include "common.h" -#include "patcher.h" + #include "main.h" #include "Camera.h" @@ -31,16 +31,16 @@ #include "WaterLevel.h" #include "World.h" -CPickup(&CPickups::aPickUps)[NUMPICKUPS] = *(CPickup(*)[NUMPICKUPS])*(uintptr*)0x878C98; -int16 CPickups::NumMessages;// = *(int16*)0x95CC98; -int32 CPickups::aPickUpsCollected[NUMCOLLECTEDPICKUPS];// = *(int32(*)[NUMCOLLECTEDPICKUPS])*(uintptr*)0x87C538; -int16 CPickups::CollectedPickUpIndex;// = *(int16*)0x95CC8A; +CPickup CPickups::aPickUps[NUMPICKUPS]; +int16 CPickups::NumMessages; +int32 CPickups::aPickUpsCollected[NUMCOLLECTEDPICKUPS]; +int16 CPickups::CollectedPickUpIndex; // unused -bool &CPickups::bPickUpcamActivated = *(bool*)0x95CD71; -CVehicle *&CPickups::pPlayerVehicle = *(CVehicle**)0x8F29E8; -CVector &CPickups::StaticCamCoors = *(CVector*)0x9404C8; -uint32 &CPickups::StaticCamStartTime = *(uint32*)0x8E289C; +bool CPickups::bPickUpcamActivated; +CVehicle *CPickups::pPlayerVehicle; +CVector CPickups::StaticCamCoors; +uint32 CPickups::StaticCamStartTime; tPickupMessage CPickups::aMessages[NUMPICKUPMESSAGES]; @@ -99,7 +99,7 @@ CPickup::GiveUsAPickUpObject(int32 handle) switch (m_eType) { case PICKUP_IN_SHOP: - object->m_obj_flag2 = true; + object->bPickupObjWithMessage = true; object->bOutOfStock = false; break; case PICKUP_ON_STREET: @@ -113,11 +113,11 @@ CPickup::GiveUsAPickUpObject(int32 handle) case PICKUP_NAUTICAL_MINE_ARMED: case PICKUP_FLOATINGPACKAGE: case PICKUP_ON_STREET_SLOW: - object->m_obj_flag2 = false; + object->bPickupObjWithMessage = false; object->bOutOfStock = false; break; case PICKUP_IN_SHOP_OUT_OF_STOCK: - object->m_obj_flag2 = false; + object->bPickupObjWithMessage = false; object->bOutOfStock = true; object->bRenderScorched = true; break; @@ -491,7 +491,7 @@ CPickups::GenerateNewOne(CVector pos, uint32 modelIndex, uint8 type, uint32 quan int32 slot = 0; if (type == PICKUP_FLOATINGPACKAGE || type == PICKUP_NAUTICAL_MINE_INACTIVE) { - for (slot = NUMPICKUPS; slot >= 0; slot--) { + for (slot = NUMPICKUPS-1; slot >= 0; slot--) { if (aPickUps[slot].m_eType == PICKUP_NONE) { bFreeFound = true; break; @@ -623,6 +623,34 @@ CPickups::Update() if (CReplay::IsPlayingBack()) return; #endif +#ifdef CAMERA_PICKUP + if ( bPickUpcamActivated ) // taken from PS2 + { + float dist = (FindPlayerCoors() - StaticCamCoors).Magnitude2D(); + float mult; + if ( dist < 10.0f ) + mult = 1.0f - (dist / 10.0f ); + else + mult = 0.0f; + + CVector pos = StaticCamCoors; + pos.z += (pPlayerVehicle->GetColModel()->boundingBox.GetSize().z + 2.0f) * mult; + + if ( (CTimer::GetTimeInMilliseconds() - StaticCamStartTime) > 750 ) + { + TheCamera.SetCamPositionForFixedMode(pos, CVector(0.0f, 0.0f, 0.0f)); + TheCamera.TakeControl(FindPlayerVehicle(), CCam::MODE_FIXED, JUMP_CUT, CAMCONTROL_SCRIPT); + } + + if ( FindPlayerVehicle() != pPlayerVehicle + || (FindPlayerCoors() - StaticCamCoors).Magnitude() > 40.0f + || ((CTimer::GetTimeInMilliseconds() - StaticCamStartTime) > 60000) ) + { + TheCamera.RestoreWithJumpCut(); + bPickUpcamActivated = false; + } + } +#endif #define PICKUPS_FRAME_SPAN (6) #ifdef FIX_BUGS for (uint32 i = NUMGENERALPICKUPS * (CTimer::GetFrameCounter() % PICKUPS_FRAME_SPAN) / PICKUPS_FRAME_SPAN; i < NUMGENERALPICKUPS * (CTimer::GetFrameCounter() % PICKUPS_FRAME_SPAN + 1) / PICKUPS_FRAME_SPAN; i++) { @@ -690,7 +718,7 @@ CPickups::DoPickUpEffects(CEntity *entity) size, 65.0f, CCoronas::TYPE_RING, CCoronas::FLARE_NONE, CCoronas::REFLECTION_OFF, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f); CObject *object = (CObject*)entity; - if (object->m_obj_flag2 || object->bOutOfStock || object->m_nBonusValue) { + if (object->bPickupObjWithMessage || object->bOutOfStock || object->m_nBonusValue) { float dist = (TheCamera.GetPosition() - pos).Magnitude(); const float MAXDIST = 12.0f; @@ -1406,47 +1434,3 @@ CPacManPickups::ResetPowerPillsCarriedByPlayer() FindPlayerVehicle()->m_fForceMultiplier = 1.0f; } } - -STARTPATCHES - InjectHook(0x430220, CPickups::Init, PATCH_JUMP); - InjectHook(0x4303D0, CPickups::Update, PATCH_JUMP); - InjectHook(0x432440, CPickups::RenderPickUpText, PATCH_JUMP); - InjectHook(0x431C30, CPickups::DoCollectableEffects, PATCH_JUMP); - InjectHook(0x431F40, CPickups::DoMoneyEffects, PATCH_JUMP); - InjectHook(0x4321C0, CPickups::DoMineEffects, PATCH_JUMP); - InjectHook(0x431520, CPickups::DoPickUpEffects, PATCH_JUMP); - InjectHook(0x4304B0, CPickups::GenerateNewOne, PATCH_JUMP); - InjectHook(0x430660, CPickups::GenerateNewOne_WeaponType, PATCH_JUMP); - InjectHook(0x4307A0, CPickups::RemovePickUp, PATCH_JUMP); - InjectHook(0x430800, CPickups::RemoveAllFloatingPickups, PATCH_JUMP); - InjectHook(0x433D60, CPickups::AddToCollectedPickupsArray, PATCH_JUMP); - InjectHook(0x430770, CPickups::IsPickUpPickedUp, PATCH_JUMP); - InjectHook(0x430690, CPickups::ModelForWeapon, PATCH_JUMP); - InjectHook(0x4306F0, CPickups::WeaponForModel, PATCH_JUMP); - InjectHook(0x431510, CPickups::FindColourIndexForWeaponMI, PATCH_JUMP);/**/ - InjectHook(0x433DF0, CPickups::GetActualPickupIndex, PATCH_JUMP); - InjectHook(0x433DB0, CPickups::GetNewUniquePickupIndex, PATCH_JUMP); - InjectHook(0x433B60, CPickups::PassTime, PATCH_JUMP); - InjectHook(0x4339F0, CPickups::GivePlayerGoodiesWithPickUpMI, PATCH_JUMP); - InjectHook(0x433F60, CPickups::Load, PATCH_JUMP); - InjectHook(0x433E40, CPickups::Save, PATCH_JUMP); - InjectHook(0x433BA0, &CPickup::GiveUsAPickUpObject, PATCH_JUMP); - InjectHook(0x430860, &CPickup::Update, PATCH_JUMP); - InjectHook(0x4331B0, &CPacManPickup::Update, PATCH_JUMP); - InjectHook(0x432760, CPacManPickups::Init, PATCH_JUMP); - InjectHook(0x432800, CPacManPickups::Update, PATCH_JUMP); - InjectHook(0x432AE0, CPacManPickups::GeneratePMPickUps, PATCH_JUMP); - InjectHook(0x432D50, CPacManPickups::GeneratePMPickUpsForRace, PATCH_JUMP); - InjectHook(0x432F20, CPacManPickups::GenerateOnePMPickUp, PATCH_JUMP); - InjectHook(0x432F60, CPacManPickups::Render, PATCH_JUMP); - InjectHook(0x433150, CPacManPickups::ClearPMPickUps, PATCH_JUMP); - InjectHook(0x433340, CPacManPickups::StartPacManRace, PATCH_JUMP); - InjectHook(0x433360, CPacManPickups::StartPacManRecord, PATCH_JUMP); - InjectHook(0x4333A0, CPacManPickups::QueryPowerPillsEatenInRace, PATCH_JUMP); - InjectHook(0x4333B0, CPacManPickups::ResetPowerPillsEatenInRace, PATCH_JUMP); - InjectHook(0x4333C0, CPacManPickups::CleanUpPacManStuff, PATCH_JUMP); - InjectHook(0x4333D0, CPacManPickups::StartPacManScramble, PATCH_JUMP); - InjectHook(0x4333F0, CPacManPickups::QueryPowerPillsCarriedByPlayer, PATCH_JUMP); - InjectHook(0x433410, CPacManPickups::ResetPowerPillsCarriedByPlayer, PATCH_JUMP); - -ENDPATCHES diff --git a/src/control/Pickups.h b/src/control/Pickups.h index b5b4f396..11da5f54 100644 --- a/src/control/Pickups.h +++ b/src/control/Pickups.h @@ -89,13 +89,13 @@ public: static void Load(uint8 *buf, uint32 size); static void Save(uint8 *buf, uint32 *size); - static CPickup(&aPickUps)[NUMPICKUPS]; + static CPickup aPickUps[NUMPICKUPS]; // unused - static bool &bPickUpcamActivated; - static CVehicle *&pPlayerVehicle; - static CVector &StaticCamCoors; - static uint32 &StaticCamStartTime; + static bool bPickUpcamActivated; + static CVehicle *pPlayerVehicle; + static CVector StaticCamCoors; + static uint32 StaticCamStartTime; }; extern uint16 AmmoForWeapon[20]; diff --git a/src/control/Record.cpp b/src/control/Record.cpp index ca4128e3..b9e8f8da 100644 --- a/src/control/Record.cpp +++ b/src/control/Record.cpp @@ -1,5 +1,5 @@ #include "common.h" -#include "patcher.h" + #include "Record.h" #include "FileMgr.h" @@ -10,11 +10,11 @@ #include "VehicleModelInfo.h" #include "World.h" -uint16 &CRecordDataForGame::RecordingState = *(uint16*)0x95CC24; -uint8*& CRecordDataForGame::pDataBuffer = *(uint8**)0x8F1B70; -uint8*& CRecordDataForGame::pDataBufferPointer = *(uint8**)0x8F1AB0; -int& CRecordDataForGame::FId = *(int*)0x885BA4; -tGameBuffer& CRecordDataForGame::pDataBufferForFrame = *(tGameBuffer*)0x72CED0; +uint16 CRecordDataForGame::RecordingState; +uint8* CRecordDataForGame::pDataBuffer; +uint8* CRecordDataForGame::pDataBufferPointer; +int CRecordDataForGame::FId; +tGameBuffer CRecordDataForGame::pDataBufferForFrame; #define MEMORY_FOR_GAME_RECORD (150000) @@ -176,15 +176,15 @@ uint16 CRecordDataForGame::CalcGameChecksum(void) return checksum ^ checksum >> 16; } -uint8& CRecordDataForChase::Status = *(uint8*)0x95CDCE; -int& CRecordDataForChase::PositionChanges = *(int*)0x8F59C8; -uint8& CRecordDataForChase::CurrentCar = *(uint8*)0x95CDC9; -CAutomobile* (&CRecordDataForChase::pChaseCars)[NUM_CHASE_CARS] = *(CAutomobile * (*)[NUM_CHASE_CARS])*(uintptr*)0x6F46A8; -uint32& CRecordDataForChase::AnimStartTime = *(uint32*)0x8F1AEC; -float& CRecordDataForChase::AnimTime = *(float*)0x880F88; -CCarStateEachFrame* (&CRecordDataForChase::pBaseMemForCar)[NUM_CHASE_CARS] = *(CCarStateEachFrame * (*)[NUM_CHASE_CARS])*(uintptr*)0x70EA18; -float& CRecordDataForChase::TimeMultiplier = *(float*)0x8E2A94; -int& CRecordDataForChase::FId2 = *(int*)0x8E2C18; +uint8 CRecordDataForChase::Status; +int CRecordDataForChase::PositionChanges; +uint8 CRecordDataForChase::CurrentCar; +CAutomobile* CRecordDataForChase::pChaseCars[NUM_CHASE_CARS]; +uint32 CRecordDataForChase::AnimStartTime; +float CRecordDataForChase::AnimTime; +CCarStateEachFrame* CRecordDataForChase::pBaseMemForCar[NUM_CHASE_CARS]; +float CRecordDataForChase::TimeMultiplier; +int CRecordDataForChase::FId2; #define CHASE_SCENE_LENGTH_IN_SECONDS (80) #define CHASE_SCENE_FRAMES_PER_SECOND (15) // skipping every second frame @@ -296,7 +296,7 @@ void CRecordDataForChase::SaveOrRetrieveCarPositions(void) case STATE_PLAYBACK: { TimeMultiplier += CTimer::GetTimeStepNonClippedInSeconds(); - float EndOfFrameTime = CHASE_SCENE_FRAMES_PER_SECOND * min(CHASE_SCENE_LENGTH_IN_SECONDS, TimeMultiplier); + float EndOfFrameTime = CHASE_SCENE_FRAMES_PER_SECOND * Min(CHASE_SCENE_LENGTH_IN_SECONDS, TimeMultiplier); for (int i = 0; i < NUM_CHASE_CARS; i++) { if (!pBaseMemForCar[i]) continue; @@ -371,7 +371,7 @@ void CRecordDataForChase::RestoreInfoForCar(CAutomobile* pCar, CCarStateEachFram else pCar->GetModelInfo()->ChooseVehicleColour(pCar->m_currentColour1, pCar->m_currentColour2); } - pCar->m_fHealth = min(pCar->m_fHealth, 500.0f); + pCar->m_fHealth = Min(pCar->m_fHealth, 500.0f); if (stop) { pCar->m_fGasPedal = 0.0f; pCar->m_fBrakePedal = 0.0f; diff --git a/src/control/Record.h b/src/control/Record.h index 4abeb68a..7af733ba 100644 --- a/src/control/Record.h +++ b/src/control/Record.h @@ -23,7 +23,7 @@ public: CVector pos; }; -extern char* gString; +extern char gString[256];; class CRecordDataForChase { @@ -37,15 +37,15 @@ class CRecordDataForChase STATE_PLAYBACK = 3, STATE_PLAYBACK_BEFORE_RECORDING = 4 }; - static uint8 &Status; - static int &PositionChanges; - static uint8 &CurrentCar; - static CAutomobile*(&pChaseCars)[NUM_CHASE_CARS]; - static float &AnimTime; - static uint32 &AnimStartTime; - static CCarStateEachFrame* (&pBaseMemForCar)[NUM_CHASE_CARS]; - static float &TimeMultiplier; - static int &FId2; + static uint8 Status; + static int PositionChanges; + static uint8 CurrentCar; + static CAutomobile*pChaseCars[NUM_CHASE_CARS]; + static float AnimTime; + static uint32 AnimStartTime; + static CCarStateEachFrame* pBaseMemForCar[NUM_CHASE_CARS]; + static float TimeMultiplier; + static int FId2; public: static bool IsRecording(void) { return Status == STATE_RECORD; } @@ -86,11 +86,11 @@ class CRecordDataForGame STATE_RECORD = 1, STATE_PLAYBACK = 2, }; - static uint16& RecordingState; - static uint8* &pDataBuffer; - static uint8* &pDataBufferPointer; - static int &FId; - static tGameBuffer &pDataBufferForFrame; + static uint16 RecordingState; + static uint8* pDataBuffer; + static uint8* pDataBufferPointer; + static int FId; + static tGameBuffer pDataBufferForFrame; public: static bool IsRecording() { return RecordingState == STATE_RECORD; } diff --git a/src/control/Remote.cpp b/src/control/Remote.cpp index f7d12702..9c749bd9 100644 --- a/src/control/Remote.cpp +++ b/src/control/Remote.cpp @@ -1,5 +1,5 @@ #include "common.h" -#include "patcher.h" + #include "Automobile.h" #include "CarCtrl.h" #include "Camera.h" @@ -49,8 +49,3 @@ CRemote::TakeRemoteControlledCarFromPlayer(void) CWorld::Players[CWorld::PlayerInFocus].m_bInRemoteMode = true; CWorld::Players[CWorld::PlayerInFocus].m_pRemoteVehicle->bRemoveFromWorld = true; } - -STARTPATCHES - InjectHook(0x435C30, &CRemote::GivePlayerRemoteControlledCar, PATCH_JUMP); - InjectHook(0x435DA0, &CRemote::TakeRemoteControlledCarFromPlayer, PATCH_JUMP); -ENDPATCHES
\ No newline at end of file diff --git a/src/control/Replay.cpp b/src/control/Replay.cpp index 0da32dd2..d37e98cf 100644 --- a/src/control/Replay.cpp +++ b/src/control/Replay.cpp @@ -1,5 +1,5 @@ #include "common.h" -#include "patcher.h" + #include "AnimBlendAssociation.h" #include "Boat.h" #include "SpecialFX.h" @@ -39,71 +39,73 @@ #include "Camera.h" #include "Radar.h" -uint8 &CReplay::Mode = *(uint8*)0x95CD5B; -CAddressInReplayBuffer &CReplay::Record = *(CAddressInReplayBuffer*)0x942F7C; -CAddressInReplayBuffer &CReplay::Playback = *(CAddressInReplayBuffer*)0x8F5F48; -uint8 *&CReplay::pBuf0 = *(uint8**)0x8E2C64; -CAutomobile *&CReplay::pBuf1 = *(CAutomobile**)0x8E2C68; -uint8 *&CReplay::pBuf2 = *(uint8**)0x8E2C6C; -CPlayerPed *&CReplay::pBuf3 = *(CPlayerPed**)0x8E2C70; -uint8 *&CReplay::pBuf4 = *(uint8**)0x8E2C74; -CCutsceneHead *&CReplay::pBuf5 = *(CCutsceneHead**)0x8E2C78; -uint8 *&CReplay::pBuf6 = *(uint8**)0x8E2C80; -CPtrNode *&CReplay::pBuf7 = *(CPtrNode**)0x8E2C84; -uint8 *&CReplay::pBuf8 = *(uint8**)0x8E2C54; -CEntryInfoNode *&CReplay::pBuf9 = *(CEntryInfoNode**)0x8E2C58; -uint8 *&CReplay::pBuf10 = *(uint8**)0x8F2C28; -CDummyPed *&CReplay::pBuf11 = *(CDummyPed**)0x8F2C2C; -uint8 *&CReplay::pRadarBlips = *(uint8**)0x8F29F8; -uint8 *&CReplay::pStoredCam = *(uint8**)0x8F2C34; -uint8 *&CReplay::pWorld1 = *(uint8**)0x8E29C4; -CReference *&CReplay::pEmptyReferences = *(CReference**)0x8F256C; -CStoredDetailedAnimationState *&CReplay::pPedAnims = *(CStoredDetailedAnimationState**)0x8F6260; -uint8 *&CReplay::pPickups = *(uint8**)0x8F1A48; -uint8 *&CReplay::pReferences = *(uint8**)0x880FAC; -uint8(&CReplay::BufferStatus)[NUM_REPLAYBUFFERS] = *(uint8(*)[NUM_REPLAYBUFFERS])*(uintptr*)0x8804D8; -uint8(&CReplay::Buffers)[NUM_REPLAYBUFFERS][REPLAYBUFFERSIZE] = *(uint8(*)[NUM_REPLAYBUFFERS][REPLAYBUFFERSIZE])*(uintptr*)0x779958; -bool &CReplay::bPlayingBackFromFile = *(bool*)0x95CD58; -bool &CReplay::bReplayEnabled = *(bool*)0x617CAC; -uint32 &CReplay::SlowMotion = *(uint32*)0x9414D4; -uint32 &CReplay::FramesActiveLookAroundCam = *(uint32*)0x880F84; -bool &CReplay::bDoLoadSceneWhenDone = *(bool*)0x95CD76; -CPtrList &CReplay::WorldPtrList = *(CPtrList*)0x880F90; -CPtrList &CReplay::BigBuildingPtrList = *(CPtrList*)0x941284; -CWanted &CReplay::PlayerWanted = *(CWanted*)0x8F6278; -CPlayerInfo &CReplay::PlayerInfo = *(CPlayerInfo*)0x8F5840; -uint32 &CReplay::Time1 = *(uint32*)0x8F29DC; -uint32 &CReplay::Time2 = *(uint32*)0x8F29D0; -uint32 &CReplay::Time3 = *(uint32*)0x8F29D4; -uint32 &CReplay::Time4 = *(uint32*)0x8F29C8; -uint32 &CReplay::Frame = *(uint32*)0x8F2554; -uint8 &CReplay::ClockHours = *(uint8*)0x95CDC5; -uint8 &CReplay::ClockMinutes = *(uint8*)0x95CDA2; -uint16 &CReplay::OldWeatherType = *(uint16*)0x95CCEA; -uint16 &CReplay::NewWeatherType = *(uint16*)0x95CC6E; -float &CReplay::WeatherInterpolationValue = *(float*)0x8F1A28; -float &CReplay::TimeStepNonClipped = *(float*)0x8F5FF4; -float &CReplay::TimeStep = *(float*)0x8F2C24; -float &CReplay::TimeScale = *(float*)0x880E20; -float &CReplay::CameraFixedX = *(float*)0x943054; -float &CReplay::CameraFixedY = *(float*)0x943058; -float &CReplay::CameraFixedZ = *(float*)0x94305C; -int32 &CReplay::OldRadioStation = *(int32*)0x94151C; -int8 &CReplay::CameraMode = *(int8*)0x95CD5F; -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; -float &CReplay::fDistanceLookAroundCam = *(float*)0x885B44; -float &CReplay::fBetaAngleLookAroundCam = *(float*)0x94072C; -float &CReplay::fAlphaAngleLookAroundCam = *(float*)0x8F2A0C; +uint8 CReplay::Mode; +CAddressInReplayBuffer CReplay::Record; +CAddressInReplayBuffer CReplay::Playback; +uint8 *CReplay::pBuf0; +CAutomobile *CReplay::pBuf1; +uint8 *CReplay::pBuf2; +CPlayerPed *CReplay::pBuf3; +uint8 *CReplay::pBuf4; +CCutsceneHead *CReplay::pBuf5; +uint8 *CReplay::pBuf6; +CPtrNode *CReplay::pBuf7; +uint8 *CReplay::pBuf8; +CEntryInfoNode *CReplay::pBuf9; +uint8 *CReplay::pBuf10; +CDummyPed *CReplay::pBuf11; +uint8 *CReplay::pRadarBlips; +uint8 *CReplay::pStoredCam; +uint8 *CReplay::pWorld1; +CReference *CReplay::pEmptyReferences; +CStoredDetailedAnimationState *CReplay::pPedAnims; +uint8 *CReplay::pPickups; +uint8 *CReplay::pReferences; +uint8 CReplay::BufferStatus[NUM_REPLAYBUFFERS]; +uint8 CReplay::Buffers[NUM_REPLAYBUFFERS][REPLAYBUFFERSIZE]; +bool CReplay::bPlayingBackFromFile; +bool CReplay::bReplayEnabled = true; +uint32 CReplay::SlowMotion; +uint32 CReplay::FramesActiveLookAroundCam; +bool CReplay::bDoLoadSceneWhenDone; +CPtrNode* CReplay::WorldPtrList; +CPtrNode* CReplay::BigBuildingPtrList; +CWanted CReplay::PlayerWanted; +CPlayerInfo CReplay::PlayerInfo; +uint32 CReplay::Time1; +uint32 CReplay::Time2; +uint32 CReplay::Time3; +uint32 CReplay::Time4; +uint32 CReplay::Frame; +uint8 CReplay::ClockHours; +uint8 CReplay::ClockMinutes; +uint16 CReplay::OldWeatherType; +uint16 CReplay::NewWeatherType; +float CReplay::WeatherInterpolationValue; +float CReplay::TimeStepNonClipped; +float CReplay::TimeStep; +float CReplay::TimeScale; +float CReplay::CameraFixedX; +float CReplay::CameraFixedY; +float CReplay::CameraFixedZ; +int32 CReplay::OldRadioStation; +int8 CReplay::CameraMode; +bool CReplay::bAllowLookAroundCam; +float CReplay::LoadSceneX; +float CReplay::LoadSceneY; +float CReplay::LoadSceneZ; +float CReplay::CameraFocusX; +float CReplay::CameraFocusY; +float CReplay::CameraFocusZ; +bool CReplay::bPlayerInRCBuggy; +float CReplay::fDistanceLookAroundCam; +float CReplay::fBetaAngleLookAroundCam; +float CReplay::fAlphaAngleLookAroundCam; +#ifdef FIX_BUGS +int CReplay::nHandleOfPlayerPed[NUMPLAYERS]; +#endif -static void(*(&CBArray)[30])(CAnimBlendAssociation*, void*) = *(void(*(*)[30])(CAnimBlendAssociation*, void*))*(uintptr*)0x61052C; -static void(*CBArray_RE3[])(CAnimBlendAssociation*, void*) = +static void(*CBArray[])(CAnimBlendAssociation*, void*) = { nil, &CPed::PedGetupCB, &CPed::PedStaggerCB, &CPed::PedEvadeCB, &CPed::FinishDieAnimCB, &CPed::FinishedWaitCB, &CPed::FinishLaunchCB, &CPed::FinishHitHeadCB, &CPed::PedAnimGetInCB, &CPed::PedAnimDoorOpenCB, @@ -119,16 +121,13 @@ 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; } static void(*FindCBFunction(uint8 id))(CAnimBlendAssociation*, void*) { - return CBArray_RE3[id]; + return CBArray[id]; } static void ApplyPanelDamageToCar(uint32 panels, CAutomobile* vehicle, bool flying) @@ -279,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; @@ -682,9 +681,9 @@ void CReplay::StoreCarUpdate(CVehicle *vehicle, int id) vp->health = vehicle->m_fHealth / 4.0f; /* Not anticipated that health can be > 1000. */ vp->acceleration = vehicle->m_fGasPedal * 100.0f; vp->panels = vehicle->IsCar() ? ((CAutomobile*)vehicle)->Damage.m_panelStatus : 0; - vp->velocityX = 8000.0f * max(-4.0f, min(4.0f, vehicle->GetMoveSpeed().x)); /* 8000!? */ - vp->velocityY = 8000.0f * max(-4.0f, min(4.0f, vehicle->GetMoveSpeed().y)); - vp->velocityZ = 8000.0f * max(-4.0f, min(4.0f, vehicle->GetMoveSpeed().z)); + vp->velocityX = 8000.0f * Max(-4.0f, Min(4.0f, vehicle->GetMoveSpeed().x)); /* 8000!? */ + vp->velocityY = 8000.0f * Max(-4.0f, Min(4.0f, vehicle->GetMoveSpeed().y)); + vp->velocityZ = 8000.0f * Max(-4.0f, Min(4.0f, vehicle->GetMoveSpeed().z)); vp->mi = vehicle->GetModelIndex(); vp->primary_color = vehicle->m_currentColour1; vp->secondary_color = vehicle->m_currentColour2; @@ -1087,7 +1086,7 @@ void CReplay::TriggerPlayback(uint8 cam_mode, float cam_x, float cam_y, float ca Playback.m_bSlot = first; Playback.m_nOffset = 0; Playback.m_pBase = Buffers[first]; - CObject::DeleteAllTempObjectInArea(CVector(0.0f, 0.0f, 0.0f), 1000000.0f); + CObject::DeleteAllTempObjectsInArea(CVector(0.0f, 0.0f, 0.0f), 1000000.0f); StoreStuffInMem(); EmptyPedsAndVehiclePools(); SlowMotion = 1; @@ -1112,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); @@ -1120,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)]; @@ -1166,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; @@ -1182,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(); @@ -1215,7 +1226,7 @@ void CReplay::RestoreStuffFromMem(void) vehicle->SetModelIndex(mi); if (mi == MI_DODO){ CAutomobile* dodo = (CAutomobile*)vehicle; - RpAtomicSetFlags(GetFirstObject(dodo->m_aCarNodes[CAR_WHEEL_LF]), 0); + RpAtomicSetFlags((RpAtomic*)GetFirstObject(dodo->m_aCarNodes[CAR_WHEEL_LF]), 0); CMatrix tmp1; tmp1.Attach(RwFrameGetMatrix(dodo->m_aCarNodes[CAR_WHEEL_RF]), false); CMatrix tmp2(RwFrameGetMatrix(dodo->m_aCarNodes[CAR_WHEEL_LF]), false); @@ -1243,7 +1254,7 @@ void CReplay::RestoreStuffFromMem(void) vehicle->GetMatrix().Detach(); if (vehicle->m_rwObject){ if (RwObjectGetType(vehicle->m_rwObject) == rpATOMIC){ - RwFrame* frame = RpAtomicGetFrame(vehicle->m_rwObject); + RwFrame* frame = RpAtomicGetFrame((RpAtomic*)vehicle->m_rwObject); RpAtomicDestroy((RpAtomic*)vehicle->m_rwObject); RwFrameDestroy(frame); } @@ -1254,7 +1265,7 @@ void CReplay::RestoreStuffFromMem(void) int model_id = info->m_wheelId; if (model_id != -1){ if ((vehicle->m_rwObject = CModelInfo::GetModelInfo(model_id)->CreateInstance())){ - vehicle->GetMatrix().AttachRW(&((RwFrame*)vehicle->m_rwObject->parent)->modelling, false); + vehicle->GetMatrix().AttachRW(RwFrameGetMatrix(RpClumpGetFrame((RpClump*)vehicle->m_rwObject)), false); } } } @@ -1274,7 +1285,7 @@ void CReplay::RestoreStuffFromMem(void) object->SetModelIndex(mi); object->GetMatrix().m_attachment = nil; if (RwObjectGetType(object->m_rwObject) == rpATOMIC) - object->GetMatrix().AttachRW(RwFrameGetMatrix(RpAtomicGetFrame(object->m_rwObject)), false); + object->GetMatrix().AttachRW(RwFrameGetMatrix(RpAtomicGetFrame((RpAtomic*)object->m_rwObject)), false); } i = CPools::GetDummyPool()->GetSize(); while (--i >= 0) { @@ -1289,7 +1300,7 @@ void CReplay::RestoreStuffFromMem(void) dummy->SetModelIndex(mi); dummy->GetMatrix().m_attachment = nil; if (RwObjectGetType(dummy->m_rwObject) == rpATOMIC) - dummy->GetMatrix().AttachRW(RwFrameGetMatrix(RpAtomicGetFrame(dummy->m_rwObject)), false); + dummy->GetMatrix().AttachRW(RwFrameGetMatrix(RpAtomicGetFrame((RpAtomic*)dummy->m_rwObject)), false); } CTimer::SetTimeInMilliseconds(Time1); CTimer::SetTimeInMillisecondsNonClipped(Time2); @@ -1397,8 +1408,8 @@ void CReplay::SaveReplayToHD(void) for (first = (current + 1) % NUM_REPLAYBUFFERS; ; first = (first + 1) % NUM_REPLAYBUFFERS) 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])); + for(int i = first; ; i = (i + 1) % NUM_REPLAYBUFFERS){ + CFileMgr::Write(fw, (char*)Buffers[i], sizeof(Buffers[i])); if (BufferStatus[i] == REPLAYBUFFER_RECORD) break; } @@ -1501,9 +1512,9 @@ void CReplay::ProcessLookAroundCam(void) --FramesActiveLookAroundCam; fBetaAngleLookAroundCam += x_moved; if (CPad::NewMouseControllerState.LMB && CPad::NewMouseControllerState.RMB) - fDistanceLookAroundCam = max(3.0f, min(15.0f, fDistanceLookAroundCam + 2.0f * y_moved)); + fDistanceLookAroundCam = Max(3.0f, Min(15.0f, fDistanceLookAroundCam + 2.0f * y_moved)); else - fAlphaAngleLookAroundCam = max(0.1f, min(1.5f, fAlphaAngleLookAroundCam + y_moved)); + fAlphaAngleLookAroundCam = Max(0.1f, Min(1.5f, fAlphaAngleLookAroundCam + y_moved)); CVector camera_pt( fDistanceLookAroundCam * Sin(fBetaAngleLookAroundCam) * Cos(fAlphaAngleLookAroundCam), fDistanceLookAroundCam * Cos(fBetaAngleLookAroundCam) * Cos(fAlphaAngleLookAroundCam), @@ -1574,16 +1585,3 @@ void CReplay::Display() if (Mode == MODE_PLAYBACK) CFont::PrintString(SCREEN_SCALE_X(63.5f), SCREEN_SCALE_Y(30.0f), TheText.Get("REPLAY")); } - -STARTPATCHES -InjectHook(0x592FE0, &CReplay::Init, PATCH_JUMP); -InjectHook(0x593150, &CReplay::DisableReplays, PATCH_JUMP); -InjectHook(0x593160, &CReplay::EnableReplays, PATCH_JUMP); -InjectHook(0x593170, &CReplay::Update, PATCH_JUMP); -InjectHook(0x595B20, &CReplay::FinishPlayback, PATCH_JUMP); -InjectHook(0x595BD0, &CReplay::EmptyReplayBuffer, PATCH_JUMP); -InjectHook(0x595EE0, &CReplay::Display, PATCH_JUMP); -InjectHook(0x596030, &CReplay::TriggerPlayback, PATCH_JUMP); -InjectHook(0x597560, &CReplay::StreamAllNecessaryCarsAndPeds, PATCH_JUMP); -InjectHook(0x597680, &CReplay::ShouldStandardCameraBeProcessed, PATCH_JUMP); -ENDPATCHES diff --git a/src/control/Replay.h b/src/control/Replay.h index 56de52a3..bf70a28a 100644 --- a/src/control/Replay.h +++ b/src/control/Replay.h @@ -192,7 +192,7 @@ class CReplay int8 velocityX; int8 velocityY; int8 velocityZ; - union{ + union { int8 car_gun; int8 wheel_state; }; @@ -205,68 +205,71 @@ class CReplay static_assert(sizeof(tVehicleUpdatePacket) == 48, "tVehicleUpdatePacket: error"); private: - static uint8 &Mode; - static CAddressInReplayBuffer &Record; - static CAddressInReplayBuffer &Playback; - static uint8 *&pBuf0; - static CAutomobile *&pBuf1; - static uint8 *&pBuf2; - static CPlayerPed *&pBuf3; - static uint8 *&pBuf4; - static CCutsceneHead *&pBuf5; - static uint8 *&pBuf6; - static CPtrNode *&pBuf7; - static uint8 *&pBuf8; - static CEntryInfoNode *&pBuf9; - static uint8 *&pBuf10; - static CDummyPed *&pBuf11; - static uint8 *&pRadarBlips; - static uint8 *&pStoredCam; - static uint8 *&pWorld1; - static CReference *&pEmptyReferences; - static CStoredDetailedAnimationState *&pPedAnims; - static uint8 *&pPickups; - static uint8 *&pReferences; - static uint8 (&BufferStatus)[NUM_REPLAYBUFFERS]; - static uint8 (&Buffers)[NUM_REPLAYBUFFERS][REPLAYBUFFERSIZE]; - static bool &bPlayingBackFromFile; - static bool &bReplayEnabled; - static uint32 &SlowMotion; - static uint32 &FramesActiveLookAroundCam; - static bool &bDoLoadSceneWhenDone; - static CPtrList &WorldPtrList; - static CPtrList &BigBuildingPtrList; - static CWanted &PlayerWanted; - static CPlayerInfo &PlayerInfo; - static uint32 &Time1; - static uint32 &Time2; - static uint32 &Time3; - static uint32 &Time4; - static uint32 &Frame; - static uint8 &ClockHours; - static uint8 &ClockMinutes; - static uint16 &OldWeatherType; - static uint16 &NewWeatherType; - static float &WeatherInterpolationValue; - static float &TimeStepNonClipped; - static float &TimeStep; - static float &TimeScale; - static float &CameraFixedX; - static float &CameraFixedY; - static float &CameraFixedZ; - static int32 &OldRadioStation; - static int8 &CameraMode; - static bool &bAllowLookAroundCam; - static float &LoadSceneX; - static float &LoadSceneY; - static float &LoadSceneZ; - static float &CameraFocusX; - static float &CameraFocusY; - static float &CameraFocusZ; - static bool &bPlayerInRCBuggy; - static float &fDistanceLookAroundCam; - static float &fAlphaAngleLookAroundCam; - static float &fBetaAngleLookAroundCam; + static uint8 Mode; + static CAddressInReplayBuffer Record; + static CAddressInReplayBuffer Playback; + static uint8* pBuf0; + static CAutomobile* pBuf1; + static uint8* pBuf2; + static CPlayerPed* pBuf3; + static uint8* pBuf4; + static CCutsceneHead* pBuf5; + static uint8* pBuf6; + static CPtrNode* pBuf7; + static uint8* pBuf8; + static CEntryInfoNode* pBuf9; + static uint8* pBuf10; + static CDummyPed* pBuf11; + static uint8* pRadarBlips; + static uint8* pStoredCam; + static uint8* pWorld1; + static CReference* pEmptyReferences; + static CStoredDetailedAnimationState* pPedAnims; + static uint8* pPickups; + static uint8* pReferences; + static uint8 BufferStatus[NUM_REPLAYBUFFERS]; + static uint8 Buffers[NUM_REPLAYBUFFERS][REPLAYBUFFERSIZE]; + static bool bPlayingBackFromFile; + static bool bReplayEnabled; + static uint32 SlowMotion; + static uint32 FramesActiveLookAroundCam; + static bool bDoLoadSceneWhenDone; + static CPtrNode* WorldPtrList; + static CPtrNode* BigBuildingPtrList; + static CWanted PlayerWanted; + static CPlayerInfo PlayerInfo; + static uint32 Time1; + static uint32 Time2; + static uint32 Time3; + static uint32 Time4; + static uint32 Frame; + static uint8 ClockHours; + static uint8 ClockMinutes; + static uint16 OldWeatherType; + static uint16 NewWeatherType; + static float WeatherInterpolationValue; + static float TimeStepNonClipped; + static float TimeStep; + static float TimeScale; + static float CameraFixedX; + static float CameraFixedY; + static float CameraFixedZ; + static int32 OldRadioStation; + static int8 CameraMode; + static bool bAllowLookAroundCam; + static float LoadSceneX; + static float LoadSceneY; + static float LoadSceneZ; + static float CameraFocusX; + static float CameraFocusY; + static float CameraFocusZ; + static bool bPlayerInRCBuggy; + static float fDistanceLookAroundCam; + static float fAlphaAngleLookAroundCam; + static float fBetaAngleLookAroundCam; +#ifdef FIX_BUGS + static int nHandleOfPlayerPed[NUMPLAYERS]; +#endif public: static void Init(void); diff --git a/src/control/Restart.cpp b/src/control/Restart.cpp index 788a054a..2a31f8f1 100644 --- a/src/control/Restart.cpp +++ b/src/control/Restart.cpp @@ -1,25 +1,25 @@ #include "common.h" -#include "patcher.h" + #include "Restart.h" #include "Zones.h" #include "PathFind.h" -uint8 &CRestart::OverrideHospitalLevel = *(uint8*)0x95CD4C; -uint8 &CRestart::OverridePoliceStationLevel = *(uint8*)0x95CD50; -bool &CRestart::bFadeInAfterNextArrest = *(bool*)0x95CD69; -bool &CRestart::bFadeInAfterNextDeath = *(bool*)0x95CD9D; +uint8 CRestart::OverrideHospitalLevel; +uint8 CRestart::OverridePoliceStationLevel; +bool CRestart::bFadeInAfterNextArrest; +bool CRestart::bFadeInAfterNextDeath; -bool &CRestart::bOverrideRestart = *(bool*)0x95CD5D; -CVector &CRestart::OverridePosition = *(CVector*)0x8E2C00; -float &CRestart::OverrideHeading = *(float*)0x8F2A18; +bool CRestart::bOverrideRestart; +CVector CRestart::OverridePosition; +float CRestart::OverrideHeading; -CVector(&CRestart::HospitalRestartPoints)[NUM_RESTART_POINTS] = *(CVector(*)[NUM_RESTART_POINTS])*(uintptr*)0x87F9B0; -float(&CRestart::HospitalRestartHeadings)[NUM_RESTART_POINTS] = *(float(*)[NUM_RESTART_POINTS])*(uintptr*)0x6F1D40; -uint16 &CRestart::NumberOfHospitalRestarts = *(uint16*)0x95CC46; +CVector CRestart::HospitalRestartPoints[NUM_RESTART_POINTS]; +float CRestart::HospitalRestartHeadings[NUM_RESTART_POINTS]; +uint16 CRestart::NumberOfHospitalRestarts; -CVector(&CRestart::PoliceRestartPoints)[NUM_RESTART_POINTS] = *(CVector(*)[NUM_RESTART_POINTS])*(uintptr*)0x846228; -float(&CRestart::PoliceRestartHeadings)[NUM_RESTART_POINTS] = *(float(*)[NUM_RESTART_POINTS])*(uintptr*)0x6F1D20; -uint16 &CRestart::NumberOfPoliceRestarts = *(uint16*)0x95CC44; +CVector CRestart::PoliceRestartPoints[NUM_RESTART_POINTS]; +float CRestart::PoliceRestartHeadings[NUM_RESTART_POINTS]; +uint16 CRestart::NumberOfPoliceRestarts; void CRestart::Initialise() @@ -247,16 +247,3 @@ INITSAVEBUF WriteSaveBuf(buf, OverridePoliceStationLevel); VALIDATESAVEBUF(*size); } - - -STARTPATCHES - InjectHook(0x435E20, &CRestart::Initialise, PATCH_JUMP); - InjectHook(0x436100, &CRestart::AddHospitalRestartPoint, PATCH_JUMP); - InjectHook(0x436150, &CRestart::AddPoliceRestartPoint, PATCH_JUMP); - InjectHook(0x4366C0, &CRestart::OverrideNextRestart, PATCH_JUMP); - InjectHook(0x4366F0, &CRestart::CancelOverrideRestart, PATCH_JUMP); - InjectHook(0x4361A0, &CRestart::FindClosestHospitalRestartPoint, PATCH_JUMP); - InjectHook(0x436450, &CRestart::FindClosestPoliceRestartPoint, PATCH_JUMP); - InjectHook(0x436B20, &CRestart::LoadAllRestartPoints, PATCH_JUMP); - InjectHook(0x436700, &CRestart::SaveAllRestartPoints, PATCH_JUMP); -ENDPATCHES
\ No newline at end of file diff --git a/src/control/Restart.h b/src/control/Restart.h index fb7806db..5d84c723 100644 --- a/src/control/Restart.h +++ b/src/control/Restart.h @@ -17,20 +17,20 @@ public: static void LoadAllRestartPoints(uint8 *buf, uint32 size); static void SaveAllRestartPoints(uint8 *buf, uint32 *size); - static uint8 &OverrideHospitalLevel; - static uint8 &OverridePoliceStationLevel; - static bool &bFadeInAfterNextArrest; - static bool &bFadeInAfterNextDeath; - - static bool &bOverrideRestart; - static CVector &OverridePosition; - static float &OverrideHeading; - - static CVector(&HospitalRestartPoints)[NUM_RESTART_POINTS]; - static float (&HospitalRestartHeadings)[NUM_RESTART_POINTS]; - static uint16 &NumberOfHospitalRestarts; - - static CVector (&PoliceRestartPoints)[NUM_RESTART_POINTS]; - static float (&PoliceRestartHeadings)[NUM_RESTART_POINTS]; - static uint16 &NumberOfPoliceRestarts; + static uint8 OverrideHospitalLevel; + static uint8 OverridePoliceStationLevel; + static bool bFadeInAfterNextArrest; + static bool bFadeInAfterNextDeath; + + static bool bOverrideRestart; + static CVector OverridePosition; + static float OverrideHeading; + + static CVector HospitalRestartPoints[NUM_RESTART_POINTS]; + static float HospitalRestartHeadings[NUM_RESTART_POINTS]; + static uint16 NumberOfHospitalRestarts; + + static CVector PoliceRestartPoints[NUM_RESTART_POINTS]; + static float PoliceRestartHeadings[NUM_RESTART_POINTS]; + static uint16 NumberOfPoliceRestarts; }; diff --git a/src/control/RoadBlocks.cpp b/src/control/RoadBlocks.cpp index 9548bc0a..7fb0c211 100644 --- a/src/control/RoadBlocks.cpp +++ b/src/control/RoadBlocks.cpp @@ -1,5 +1,5 @@ #include "common.h" -#include "patcher.h" + #include "RoadBlocks.h" #include "PathFind.h" #include "ModelIndices.h" @@ -15,9 +15,9 @@ #include "CarCtrl.h" #include "General.h" -int16 &CRoadBlocks::NumRoadBlocks = *(int16*)0x95CC34; -int16 (&CRoadBlocks::RoadBlockObjects)[NUMROADBLOCKS] = *(int16(*)[NUMROADBLOCKS]) * (uintptr*)0x72B3A8; -bool (&CRoadBlocks::InOrOut)[NUMROADBLOCKS] = *(bool(*)[NUMROADBLOCKS]) * (uintptr*)0x733810; +int16 CRoadBlocks::NumRoadBlocks; +int16 CRoadBlocks::RoadBlockObjects[NUMROADBLOCKS]; +bool CRoadBlocks::InOrOut[NUMROADBLOCKS]; void CRoadBlocks::Init(void) @@ -195,9 +195,3 @@ CRoadBlocks::GenerateRoadBlocks(void) } } } - -STARTPATCHES - InjectHook(0x436F50, &CRoadBlocks::Init, PATCH_JUMP); - InjectHook(0x4376A0, &CRoadBlocks::GenerateRoadBlockCopsForCar, PATCH_JUMP); - InjectHook(0x436FA0, &CRoadBlocks::GenerateRoadBlocks, PATCH_JUMP); -ENDPATCHES
\ No newline at end of file diff --git a/src/control/RoadBlocks.h b/src/control/RoadBlocks.h index 16e3a362..0f0c1882 100644 --- a/src/control/RoadBlocks.h +++ b/src/control/RoadBlocks.h @@ -6,9 +6,9 @@ class CVehicle; class CRoadBlocks { public: - static int16 (&NumRoadBlocks); - static int16 (&RoadBlockObjects)[NUMROADBLOCKS]; - static bool (&InOrOut)[NUMROADBLOCKS]; + static int16 NumRoadBlocks; + static int16 RoadBlockObjects[NUMROADBLOCKS]; + static bool InOrOut[NUMROADBLOCKS]; static void Init(void); static void GenerateRoadBlockCopsForCar(CVehicle* pVehicle, int32 roadBlockType, int16 roadBlockNode); diff --git a/src/control/SceneEdit.cpp b/src/control/SceneEdit.cpp index 3e55d431..7f914a76 100644 --- a/src/control/SceneEdit.cpp +++ b/src/control/SceneEdit.cpp @@ -1,12 +1,1097 @@ #include "common.h" -#include "patcher.h" + #include "SceneEdit.h" -bool &CSceneEdit::m_bEditOn = *(bool*)0x95CD77; -int32 &CSceneEdit::m_bCameraFollowActor = *(int*)0x940590; -bool &CSceneEdit::m_bRecording = *(bool*)0x95CD1F; -CVector &CSceneEdit::m_vecCurrentPosition = *(CVector*)0x943064; -CVector &CSceneEdit::m_vecCamHeading = *(CVector*)0x942F8C; +#include "Automobile.h" +#include "Camera.h" +#include "CarCtrl.h" +#include "CivilianPed.h" +#include "FileMgr.h" +#include "Font.h" +#include "ModelIndices.h" +#include "ModelInfo.h" +#include "Pad.h" +#include "Ped.h" +#include "Population.h" +#include "Text.h" +#include "Timecycle.h" +#include "Streaming.h" +#include "Vehicle.h" +#include "WeaponInfo.h" +#include "World.h" + +bool CSceneEdit::m_bEditOn; +int32 CSceneEdit::m_bCameraFollowActor; +bool CSceneEdit::m_bRecording; +CVector CSceneEdit::m_vecCurrentPosition; +CVector CSceneEdit::m_vecCamHeading; +CVector CSceneEdit::m_vecGotoPosition; +int32 CSceneEdit::m_nVehicle; +int32 CSceneEdit::m_nVehicle2; +int32 CSceneEdit::m_nActor; +int32 CSceneEdit::m_nActor2; +int32 CSceneEdit::m_nVehiclemodelId; +int32 CSceneEdit::m_nPedmodelId; +int16 CSceneEdit::m_nCurrentMovieCommand; +int16 CSceneEdit::m_nNumActors; +int16 CSceneEdit::m_nNumMovieCommands; +int16 CSceneEdit::m_nCurrentCommand; +int16 CSceneEdit::m_nCurrentVehicle; +int16 CSceneEdit::m_nCurrentActor; +int16 CSceneEdit::m_nWeaponType; +bool CSceneEdit::m_bCommandActive; +bool CSceneEdit::m_bActorSelected; +bool CSceneEdit::m_bActor2Selected; +bool CSceneEdit::m_bVehicleSelected; +int16 CSceneEdit::m_nNumVehicles; +CPed* CSceneEdit::pActors[NUM_ACTORS_IN_MOVIE]; +CVehicle* CSceneEdit::pVehicles[NUM_VEHICLES_IN_MOVIE]; +bool CSceneEdit::m_bDrawGotoArrow; +CMovieCommand CSceneEdit::Movie[NUM_COMMANDS_IN_MOVIE]; + +#define SHADOW_OFFSET (2.0f) +#define ACTION_MESSAGE_X_RIGHT (60.0f) +#define ACTION_MESSAGE_Y (8.0f) +#define SELECTED_MESSAGE_X_RIGHT (60.0f) +#define SELECTED_MESSAGE_Y (248.0f) +#define COMMAND_NAME_X_RIGHT (60.0f) +#define COMMAND_NAME_Y (38.0f) +#define COMMAND_NAME_HEIGHT (16.0f) + +#define NUM_COMMANDS_TO_DRAW (9) + +static const char* pCommandStrings[] = { + "do-nothing", "New Actor", "Move Actor", "Select Actor", "Delete Actor", + "New Vehicle", "Move Vehicle", "Select Vehicle", "Delete Vehicle", "Give Weapon", + "Goto", "Goto (wait)", "Get In Car", "Get Out Car", "Kill", + "Flee", "Wait", "Position Camera", "Set Camera Target", "Select Camera Mode", + "Save Movie", "Load Movie", "Play Movie", "END" +}; + +static_assert(ARRAY_SIZE(pCommandStrings) == CSceneEdit::MOVIE_TOTAL_COMMANDS, "Scene edit: not all commands have names"); + +static int32 NextValidModelId(int32 mi, int32 step) +{ + int32 result = -1; + int32 i = mi; + while (result == -1) { + i += step; + if (i < 0 || i > 5500) { + step = -step; + continue; + } + CBaseModelInfo* pInfo = CModelInfo::GetModelInfo(i); + CVehicleModelInfo* pVehicleInfo = (CVehicleModelInfo*)pInfo; + if (!pInfo) + continue; + if (pInfo->m_type == MITYPE_PED +#ifdef FIX_BUGS + && !(i >= MI_SPECIAL01 && i <= MI_SPECIAL04) +#endif + || + pInfo->m_type == MITYPE_VEHICLE && +#ifdef FIX_BUGS + (pVehicleInfo->m_vehicleType == VEHICLE_TYPE_CAR || pVehicleInfo->m_vehicleType == VEHICLE_TYPE_BOAT)) +#else // && and || priority failure it seems, also crashes on special models + pVehicleInfo->m_vehicleType == VEHICLE_TYPE_CAR || pVehicleInfo->m_vehicleType == VEHICLE_TYPE_BOAT) +#endif + result = i; + } + return result; +} + +void CSceneEdit::LoadMovie(void) +{ + ReInitialise(); + CFileMgr::SetDir("DATA"); + int fid = CFileMgr::OpenFile("movie.dat", "r"); +#ifdef FIX_BUGS + if (fid >= 0) +#endif + { + CFileMgr::Read(fid, (char*)&Movie, sizeof(Movie)); + CFileMgr::Read(fid, (char*)&m_nNumMovieCommands, sizeof(m_nNumMovieCommands)); + CFileMgr::CloseFile(fid); + } + CFileMgr::SetDir(""); + m_bCommandActive = false; +} + +void CSceneEdit::SaveMovie(void) +{ + CFileMgr::SetDir("DATA"); + int fid = CFileMgr::OpenFileForWriting("movie.dat"); + if (fid >= 0) { + CFileMgr::Write(fid, (char*)&Movie, sizeof(Movie)); + CFileMgr::Write(fid, (char*)&m_nNumMovieCommands, sizeof(m_nNumMovieCommands)); + CFileMgr::CloseFile(fid); + } + CFileMgr::SetDir(""); + m_bCommandActive = false; +} + +void CSceneEdit::Initialise(void) +{ + m_nActor = -1; + m_nActor2 = -1; + m_nVehicle = -1; + m_nVehicle2 = -1; + m_nCurrentCommand = MOVIE_NEW_ACTOR; + m_nVehiclemodelId = MI_INFERNUS; + m_nPedmodelId = MI_MALE01; + m_nNumVehicles = 0; + m_nNumActors = 0; + m_nNumMovieCommands = 0; + m_bCommandActive = false; + m_bRecording = true; + m_bEditOn = false; + for (int i = 0; i < NUM_ACTORS_IN_MOVIE; i++) + pActors[i] = nil; + for (int i = 0; i < NUM_VEHICLES_IN_MOVIE; i++) + pVehicles[i] = nil; + m_vecCamHeading = TheCamera.Cams[TheCamera.ActiveCam].Front; + m_vecGotoPosition = CVector(0.0f, 0.0f, 0.0f); + m_bCameraFollowActor = false; + TheCamera.Cams[TheCamera.ActiveCam].ResetStatics = true; + m_bDrawGotoArrow = false; +} + +void CSceneEdit::InitPlayback(void) +{ + m_nVehiclemodelId = MI_INFERNUS; + m_nPedmodelId = MI_MALE01; + m_bCommandActive = false; + m_nNumActors = 0; + m_nNumVehicles = 0; + m_nActor = -1; + m_nActor2 = -1; + m_nVehicle = -1; + m_nVehicle2 = -1; + TheCamera.Cams[TheCamera.ActiveCam].ResetStatics = true; + m_vecCamHeading = TheCamera.Cams[TheCamera.ActiveCam].Front; + for (int i = 0; i < NUM_ACTORS_IN_MOVIE; i++) { + if (pActors[i]) { + CPopulation::RemovePed(pActors[i]); + pActors[i] = nil; + } + } + m_nCurrentActor = 0; + for (int i = 0; i < NUM_VEHICLES_IN_MOVIE; i++) { + if (pVehicles[i]) { + CWorld::Remove(pVehicles[i]); + delete pVehicles[i]; + pVehicles[i] = nil; + } + } + m_nCurrentVehicle = 0; + m_vecGotoPosition = CVector(0.0f, 0.0f, 0.0f); + m_nCurrentMovieCommand = MOVIE_DO_NOTHING; + m_bDrawGotoArrow = false; +} + +void CSceneEdit::ReInitialise(void) +{ + m_nVehiclemodelId = MI_INFERNUS; + m_nPedmodelId = MI_MALE01; + m_nCurrentCommand = MOVIE_NEW_ACTOR; + m_bEditOn = true; + m_bRecording = true; + m_bCommandActive = false; +#ifdef FIX_BUGS + m_bCameraFollowActor = false; + TheCamera.Cams[TheCamera.ActiveCam].ResetStatics = true; // not enough... +#endif + m_nActor = -1; + m_nActor2 = -1; + m_nVehicle = -1; + m_nVehicle2 = -1; + m_nNumMovieCommands = 0; + m_nCurrentMovieCommand = MOVIE_DO_NOTHING; + m_nNumActors = 0; + m_nNumVehicles = 0; + for (int i = 0; i < NUM_ACTORS_IN_MOVIE; i++) { + if (pActors[i]) { + CPopulation::RemovePed(pActors[i]); + pActors[i] = nil; + } + } + for (int i = 0; i < NUM_VEHICLES_IN_MOVIE; i++) { + if (pVehicles[i]) { + CWorld::Remove(pVehicles[i]); + delete pVehicles[i]; + pVehicles[i] = nil; + } + } + for (int i = 0; i < NUM_COMMANDS_IN_MOVIE; i++) { + Movie[i].m_nCommandId = MOVIE_DO_NOTHING; + Movie[i].m_vecPosition = CVector(0.0f, 0.0f, 0.0f); + Movie[i].m_vecCamera = CVector(0.0f, 0.0f, 0.0f); + Movie[i].m_nActorId = -1; + Movie[i].m_nActor2Id = -1; + Movie[i].m_nVehicleId = -1; + Movie[i].m_nModelIndex = 0; + } + m_vecGotoPosition = CVector(0.0f, 0.0f, 0.0f); + m_bDrawGotoArrow = false; +} + +void CSceneEdit::Update(void) +{ + if (!m_bEditOn) + return; + if (m_bRecording) + ProcessCommand(); + else { + if (m_bCameraFollowActor && m_nActor != -1) { + if (pActors[m_nActor]->bInVehicle) + TheCamera.TakeControl(pActors[m_nActor]->m_pMyVehicle, CCam::MODE_BEHINDCAR, JUMP_CUT, CAMCONTROL_SCRIPT); + else + TheCamera.TakeControl(pActors[m_nActor], CCam::MODE_FOLLOWPED, JUMP_CUT, CAMCONTROL_SCRIPT); + } + PlayBack(); + } +} + +void CSceneEdit::Draw(void) +{ + char str[200]; + wchar wstr[200]; + if (TheCamera.m_WideScreenOn) + return; +#ifndef FIX_BUGS + CFont::SetPropOff(); +#endif + CFont::SetBackgroundOff(); + CFont::SetScale(SCREEN_SCALE_X(0.8f), SCREEN_SCALE_Y(1.35f)); + CFont::SetCentreOn(); + CFont::SetRightJustifyOn(); + CFont::SetRightJustifyWrap(0.0f); + CFont::SetBackGroundOnlyTextOff(); +#ifdef FIX_BUGS + CFont::SetFontStyle(FONT_BANK); + CFont::SetPropOn(); + CFont::SetDropColor(CRGBA(0, 0, 0, 255)); + CFont::SetDropShadowPosition(1); +#else + CFont::SetFontStyle(FONT_HEADING); + CFont::SetPropOff(); +#endif + sprintf(str, "Action"); + AsciiToUnicode(str, wstr); + CFont::SetColor(CRGBA(0, 0, 0, 0)); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(ACTION_MESSAGE_X_RIGHT - SHADOW_OFFSET), SCREEN_SCALE_Y(ACTION_MESSAGE_Y + SHADOW_OFFSET), wstr); + CFont::SetColor(CRGBA(193, 164, 120, 255)); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(ACTION_MESSAGE_X_RIGHT), SCREEN_SCALE_Y(ACTION_MESSAGE_Y), wstr); + sprintf(str, "Selected"); + AsciiToUnicode(str, wstr); + CFont::SetColor(CRGBA(0, 0, 0, 0)); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(SELECTED_MESSAGE_X_RIGHT - SHADOW_OFFSET), SCREEN_SCALE_Y(SELECTED_MESSAGE_Y + SHADOW_OFFSET), wstr); + CFont::SetColor(CRGBA(193, 164, 120, 255)); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(SELECTED_MESSAGE_X_RIGHT), SCREEN_SCALE_Y(SELECTED_MESSAGE_Y), wstr); + CFont::SetCentreOff(); + CFont::SetScale(SCREEN_SCALE_X(0.7f), SCREEN_SCALE_Y(0.7f)); +#ifdef FIX_BUGS + CFont::SetFontStyle(FONT_BANK); +#else + CFont::SetFontStyle(FONT_HEADING); +#endif + CFont::SetColor(CRGBA(0, 0, 0, 0)); + for (int i = 0; i < NUM_COMMANDS_TO_DRAW; i++) { + int16 nCommandDrawn = m_nCurrentCommand + i - NUM_COMMANDS_TO_DRAW / 2; + if (nCommandDrawn >= MOVIE_TOTAL_COMMANDS) + nCommandDrawn -= (MOVIE_TOTAL_COMMANDS - 1); + if (nCommandDrawn <= MOVIE_DO_NOTHING) + nCommandDrawn += (MOVIE_TOTAL_COMMANDS - 1); + sprintf(str, pCommandStrings[nCommandDrawn]); + AsciiToUnicode(str, wstr); + CFont::SetColor(CRGBA(0, 0, 0, 0)); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(COMMAND_NAME_X_RIGHT - SHADOW_OFFSET), SCREEN_SCALE_Y(COMMAND_NAME_Y + SHADOW_OFFSET + i * COMMAND_NAME_HEIGHT), wstr); + if (nCommandDrawn == m_nCurrentCommand) + CFont::SetColor(CRGBA(156, 91, 40, 255)); + else + CFont::SetColor(CRGBA(193, 164, 120, 255)); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(COMMAND_NAME_X_RIGHT), SCREEN_SCALE_Y(COMMAND_NAME_Y + i * COMMAND_NAME_HEIGHT), wstr); + } +} + +void CSceneEdit::ProcessCommand(void) +{ + if (!m_bCommandActive) { + ClearForNewCommand(); + if (CPad::GetPad(1)->GetDPadUpJustDown()) { + if (--m_nCurrentCommand == MOVIE_DO_NOTHING) + m_nCurrentCommand = MOVIE_END; + } + if (CPad::GetPad(1)->GetDPadDownJustDown()) { + if (++m_nCurrentCommand == MOVIE_TOTAL_COMMANDS) + m_nCurrentCommand = MOVIE_NEW_ACTOR; + } + if (CPad::GetPad(1)->GetTriangleJustDown()) { + if (m_nCurrentCommand != MOVIE_DO_NOTHING) + m_bCommandActive = true; + } + return; + } + switch (m_nCurrentCommand) { + case MOVIE_DO_NOTHING: + m_bCommandActive = false; + break; + case MOVIE_NEW_ACTOR: + if (m_nActor == -1) { + if (m_nNumActors == NUM_ACTORS_IN_MOVIE) + break; + if (!CStreaming::HasModelLoaded(m_nPedmodelId)) { + CStreaming::RequestModel(m_nPedmodelId, 0); +#ifdef FIX_BUGS + CStreaming::LoadAllRequestedModels(false); // otherwise gets stuck :( +#endif + break; + } + CPed* pPed = new CCivilianPed(PEDTYPE_SPECIAL, m_nPedmodelId); + pPed->CharCreatedBy = MISSION_CHAR; + pPed->GetPosition() = m_vecCurrentPosition; + pPed->SetOrientation(0.0f, 0.0f, 0.0f); + CWorld::Add(pPed); + pPed->bUsesCollision = false; + pPed->bAffectedByGravity = false; + for (int i = 0; i < NUM_ACTORS_IN_MOVIE; i++) { + if (pActors[i] == nil) { + m_nActor = i; + pActors[i] = pPed; + break; + } + } + } + else { + pActors[m_nActor]->GetPosition() = m_vecCurrentPosition; + pActors[m_nActor]->SetOrientation(0.0f, 0.0f, 0.0f); + int32 mi = m_nPedmodelId; + if (CPad::GetPad(1)->GetLeftShoulder1JustDown()) + mi = NextValidModelId(m_nPedmodelId, -1); + else if (CPad::GetPad(1)->GetRightShoulder1JustDown()) + mi = NextValidModelId(m_nPedmodelId, 1); + if (mi == m_nPedmodelId) { + if (CPad::GetPad(1)->GetTriangleJustDown()) { + pActors[m_nActor]->bUsesCollision = true; + pActors[m_nActor]->bAffectedByGravity = true; + ++m_nNumActors; + Movie[m_nNumMovieCommands].m_nCommandId = MOVIE_NEW_ACTOR; + Movie[m_nNumMovieCommands].m_vecPosition = m_vecCurrentPosition; + Movie[m_nNumMovieCommands].m_nModelIndex = m_nPedmodelId; + Movie[m_nNumMovieCommands++].m_nActorId = m_nActor; + m_nActor = -1; + m_bCommandActive = false; + } + if (CPad::GetPad(1)->GetCircleJustDown()) { + CWorld::Remove(pActors[m_nActor]); + delete pActors[m_nActor]; + pActors[m_nActor] = nil; + m_nActor = -1; + m_bCommandActive = false; + } + } + else { + m_nPedmodelId = mi; + if (pActors[m_nActor]) { + CWorld::Remove(pActors[m_nActor]); + delete pActors[m_nActor]; + } + pActors[m_nActor] = nil; + m_nActor = -1; + } + } + break; + case MOVIE_MOVE_ACTOR: + SelectActor(); + if (m_bCommandActive) + break; + pActors[m_nActor]->GetPosition() = m_vecCurrentPosition; + if (CPad::GetPad(1)->GetTriangleJustDown()) { + m_bCommandActive = false; +#ifndef FIX_BUGS // why? it crashes, also makes no sense + pActors[m_nActor] = nil; +#endif + SelectActor(); + } + break; + case MOVIE_SELECT_ACTOR: + SelectActor(); + break; + case MOVIE_DELETE_ACTOR: + SelectActor(); + if (m_bActorSelected) { + CPopulation::RemovePed(pActors[m_nActor]); + m_nCurrentActor = 0; + --m_nNumActors; +#ifdef FIX_BUGS + pActors[m_nActor] = nil; + m_nActor = -1; +#else + m_nActor = -1; + pActors[m_nActor] = nil; +#endif + SelectActor(); + m_bCommandActive = false; + } + else if (CPad::GetPad(1)->GetCircleJustDown()) { + m_nActor = -1; + m_bCommandActive = false; + } + break; + case MOVIE_NEW_VEHICLE: + if (m_nVehicle == -1) { + if (m_nNumVehicles == NUM_VEHICLES_IN_MOVIE) + break; + if (!CStreaming::HasModelLoaded(m_nVehiclemodelId)) { + CStreaming::RequestModel(m_nVehiclemodelId, 0); +#ifdef FIX_BUGS + CStreaming::LoadAllRequestedModels(false); // otherwise gets stuck :( +#endif + break; + } + CVehicle* pVehicle = new CAutomobile(m_nVehiclemodelId, MISSION_VEHICLE); + pVehicle->m_status = STATUS_PHYSICS; + pVehicle->GetPosition() = m_vecCurrentPosition; + pVehicle->SetOrientation(0.0f, 0.0f, 0.0f); + CWorld::Add(pVehicle); + pVehicle->bUsesCollision = false; + pVehicle->bAffectedByGravity = false; + for (int i = 0; i < NUM_VEHICLES_IN_MOVIE; i++) { + if (pVehicles[i] == nil) { + m_nVehicle = i; + pVehicles[i] = pVehicle; + break; + } + } + } + else { + pVehicles[m_nVehicle]->GetPosition() = m_vecCurrentPosition; + pVehicles[m_nVehicle]->SetOrientation(0.0f, 0.0f, 0.0f); + int32 mi = m_nVehiclemodelId; + if (CPad::GetPad(1)->GetLeftShoulder1JustDown()) + mi = NextValidModelId(m_nVehiclemodelId, -1); + else if (CPad::GetPad(1)->GetRightShoulder1JustDown()) + mi = NextValidModelId(m_nVehiclemodelId, 1); + if (mi == m_nVehiclemodelId) { + if (CPad::GetPad(1)->GetTriangleJustDown()) { + pVehicles[m_nVehicle]->bUsesCollision = true; + pVehicles[m_nVehicle]->bAffectedByGravity = true; + ++m_nNumVehicles; + Movie[m_nNumMovieCommands].m_nCommandId = MOVIE_NEW_VEHICLE; + Movie[m_nNumMovieCommands].m_vecPosition = m_vecCurrentPosition; + Movie[m_nNumMovieCommands].m_nModelIndex = m_nVehiclemodelId; + Movie[m_nNumMovieCommands++].m_nVehicleId = m_nVehicle; + m_nVehicle = -1; + m_bCommandActive = false; + } + if (CPad::GetPad(1)->GetCircleJustDown()) { + CWorld::Remove(pVehicles[m_nVehicle]); + delete pVehicles[m_nVehicle]; + pVehicles[m_nVehicle] = nil; + m_nVehicle = -1; + m_bCommandActive = false; + } + } + else { + m_nVehiclemodelId = mi; + if (pVehicles[m_nVehicle]) { + CWorld::Remove(pVehicles[m_nVehicle]); + delete pVehicles[m_nVehicle]; + } + pVehicles[m_nVehicle] = nil; + m_nVehicle = -1; + } + } + break; + case MOVIE_MOVE_VEHICLE: + SelectVehicle(); + if (m_bCommandActive) + break; + pVehicles[m_nVehicle]->GetPosition() = m_vecCurrentPosition; + if (CPad::GetPad(1)->GetTriangleJustDown()) { + m_bCommandActive = false; +#ifndef FIX_BUGS // again, why? works wrong + pVehicles[m_nVehicle] = nil; +#endif + m_nVehicle = -1; + } + break; + case MOVIE_SELECT_VEHICLE: + SelectVehicle(); + break; + case MOVIE_DELETE_VEHICLE: + SelectVehicle(); + if (m_bVehicleSelected) { + CWorld::Remove(pVehicles[m_nVehicle]); + delete pVehicles[m_nVehicle]; + m_nCurrentVehicle = 0; + --m_nNumVehicles; + pVehicles[m_nVehicle] = nil; + m_nVehicle = -1; + SelectVehicle(); + m_bCommandActive = false; + } + else if (CPad::GetPad(1)->GetCircleJustDown()) { + pVehicles[m_nVehicle] = nil; + m_nVehicle = -1; + m_bCommandActive = false; + } + break; + case MOVIE_GIVE_WEAPON: + if (m_bActorSelected) { + if (SelectWeapon()) { + m_bCommandActive = false; + Movie[m_nNumMovieCommands].m_nCommandId = MOVIE_GIVE_WEAPON; + Movie[m_nNumMovieCommands].m_nActorId = m_nActor; + Movie[m_nNumMovieCommands++].m_nModelIndex = m_nWeaponType; + } + } + else { + SelectActor(); + m_bCommandActive = true; + } + break; + case MOVIE_GOTO: + case MOVIE_GOTO_WAIT: + if (!m_bActorSelected) { + m_bDrawGotoArrow = true; + SelectActor(); + if (m_nActor == -1) + m_bCommandActive = true; + } + else { + m_vecGotoPosition = m_vecCurrentPosition; + if (CPad::GetPad(1)->GetTriangleJustDown()) { + if (pActors[m_nActor]->bInVehicle) { + if (CCarCtrl::JoinCarWithRoadSystemGotoCoors(pActors[m_nActor]->m_pMyVehicle, m_vecGotoPosition, false)) + pActors[m_nActor]->m_pMyVehicle->AutoPilot.m_nCarMission = MISSION_GOTOCOORDS_STRAIGHT; + else + pActors[m_nActor]->m_pMyVehicle->AutoPilot.m_nCarMission = MISSION_GOTOCOORDS; + pActors[m_nActor]->m_pMyVehicle->m_status = STATUS_PHYSICS; + pActors[m_nActor]->m_pMyVehicle->bEngineOn = true; + pActors[m_nActor]->m_pMyVehicle->AutoPilot.m_nCruiseSpeed = Max(16, pActors[m_nActor]->m_pMyVehicle->AutoPilot.m_nCruiseSpeed); + pActors[m_nActor]->m_pMyVehicle->AutoPilot.m_nAntiReverseTimer = CTimer::GetTimeInMilliseconds(); + TheCamera.TakeControl(pActors[m_nActor]->m_pMyVehicle, CCam::MODE_BEHINDCAR, JUMP_CUT, CAMCONTROL_SCRIPT); + } + else { + pActors[m_nActor]->SetObjective(OBJECTIVE_GOTO_AREA_ON_FOOT, m_vecGotoPosition); + TheCamera.TakeControl(pActors[m_nActor], CCam::MODE_FOLLOWPED, JUMP_CUT, CAMCONTROL_SCRIPT); + } + m_bDrawGotoArrow = false; + Movie[m_nNumMovieCommands].m_nCommandId = MOVIE_GOTO; + Movie[m_nNumMovieCommands].m_nActorId = m_nActor; + Movie[m_nNumMovieCommands++].m_vecPosition = m_vecGotoPosition; + } + if (!m_bDrawGotoArrow) { + if (pActors[m_nActor]->bInVehicle && pActors[m_nActor]->m_pMyVehicle->AutoPilot.m_nCarMission == MISSION_NONE || + !pActors[m_nActor]->bInVehicle && pActors[m_nActor]->m_objective == OBJECTIVE_NONE) { + if (pActors[m_nActor]) // if there is something that requires this check the least, it's this one + m_vecCamHeading = TheCamera.Cams[TheCamera.ActiveCam].CamTargetEntity->GetPosition() - TheCamera.Cams[TheCamera.ActiveCam].Source; + m_bCommandActive = false; + TheCamera.Cams[TheCamera.ActiveCam].Mode = CCam::MODE_FIGHT_CAM_RUNABOUT; + m_vecCurrentPosition = pActors[m_nActor]->GetPosition(); + pActors[m_nActor]->SetObjective(OBJECTIVE_NONE); + if (pActors[m_nActor]->bInVehicle) + pActors[m_nActor]->m_pMyVehicle->AutoPilot.m_nCarMission = MISSION_NONE; + } + } + if (CPad::GetPad(1)->GetCircleJustDown()) { + pActors[m_nActor] = nil; + m_nActor = -1; + m_bCommandActive = false; + } + } + break; + case MOVIE_GET_IN_CAR: + if (m_bActorSelected) + SelectVehicle(); + else { + SelectActor(); + if (m_nActor != -1) + m_bCommandActive = true; + } + if (m_bVehicleSelected) { + pActors[m_nActor]->SetObjective(OBJECTIVE_ENTER_CAR_AS_DRIVER, pVehicles[m_nVehicle]); + Movie[m_nNumMovieCommands].m_nCommandId = MOVIE_GET_IN_CAR; + Movie[m_nNumMovieCommands].m_nActorId = m_nActor; + Movie[m_nNumMovieCommands++].m_nVehicleId = m_nVehicle; + m_nVehicle = -1; + m_bCommandActive = false; + } + if (CPad::GetPad(1)->GetCircleJustDown()) { + pVehicles[m_nVehicle] = nil; + m_nVehicle = -1; + pActors[m_nActor] = nil; + m_nActor = -1; + m_bCommandActive = false; + } + break; + case MOVIE_GET_OUT_CAR: + SelectActor(); + if (m_bActorSelected) { + if (pActors[m_nActor]->bInVehicle) { + pActors[m_nActor]->SetObjective(OBJECTIVE_LEAVE_VEHICLE); + Movie[m_nNumMovieCommands].m_nCommandId = MOVIE_GET_OUT_CAR; + Movie[m_nNumMovieCommands++].m_nActorId = m_nActor; + } + m_nActor = -1; + m_bCommandActive = false; + } + if (CPad::GetPad(1)->GetCircleJustDown()) { + pVehicles[m_nVehicle] = nil; + m_nVehicle = -1; + pActors[m_nActor] = nil; + m_nActor = -1; + m_bCommandActive = false; + } + break; + case MOVIE_KILL: + if (!m_bActorSelected) { + SelectActor(); + m_bCommandActive = true; + } + else if (!m_bActor2Selected) { + SelectActor2(); + if (m_bActorSelected && m_bActor2Selected && m_nActor != -1 && m_nActor2 != -1 && m_nActor != m_nActor2) { + pActors[m_nActor]->SetObjective(OBJECTIVE_KILL_CHAR_ON_FOOT, pActors[m_nActor2]); + Movie[m_nNumMovieCommands].m_nCommandId = MOVIE_KILL; + Movie[m_nNumMovieCommands].m_nActorId = m_nActor; + Movie[m_nNumMovieCommands++].m_nActor2Id = m_nActor2; + m_bCommandActive = false; + } + } + if (CPad::GetPad(1)->GetCircleJustDown()) { + pActors[m_nActor] = nil; + m_nActor = -1; + pActors[m_nActor2] = nil; + m_nActor2 = -1; + m_bCommandActive = false; + } + break; + case MOVIE_FLEE: + if (!m_bActorSelected) { + SelectActor(); + m_bCommandActive = true; + } + else if (!m_bActor2Selected) { + SelectActor2(); + if (m_bActorSelected && m_bActor2Selected && m_nActor != -1 && m_nActor2 != -1 && m_nActor != m_nActor2) { + pActors[m_nActor]->SetObjective(OBJECTIVE_FLEE_CHAR_ON_FOOT_ALWAYS, pActors[m_nActor2]); + Movie[m_nNumMovieCommands].m_nCommandId = MOVIE_FLEE; + Movie[m_nNumMovieCommands].m_nActorId = m_nActor; + Movie[m_nNumMovieCommands++].m_nActor2Id = m_nActor2; + m_bCommandActive = false; + } + } + if (CPad::GetPad(1)->GetCircleJustDown()) { + pActors[m_nActor] = nil; + m_nActor = -1; + pActors[m_nActor2] = nil; + m_nActor2 = -1; + m_bCommandActive = false; + } + break; + case MOVIE_WAIT: + SelectActor(); + if (m_bActorSelected) { + pActors[m_nActor]->SetObjective(OBJECTIVE_IDLE); + Movie[m_nNumMovieCommands].m_nCommandId = MOVIE_WAIT; + Movie[m_nNumMovieCommands++].m_nActorId = m_nActor; + } + if (CPad::GetPad(1)->GetCircleJustDown()) { + pActors[m_nActor] = nil; + m_nActor = -1; + m_bCommandActive = false; + } + break; + case MOVIE_POSITION_CAMERA: + if (CPad::GetPad(1)->GetTriangleJustDown()) { + Movie[m_nNumMovieCommands].m_nCommandId = MOVIE_POSITION_CAMERA; + Movie[m_nNumMovieCommands].m_vecPosition = TheCamera.Cams[TheCamera.ActiveCam].Source; + Movie[m_nNumMovieCommands++].m_vecCamera = m_vecCamHeading; + m_bCommandActive = false; + } + if (CPad::GetPad(1)->GetCircleJustDown()) { + m_bCommandActive = false; + } + break; + case MOVIE_SET_CAMERA_TARGET: + if (!m_bActorSelected) { + SelectActor(); + m_bCommandActive = true; + } + else { + TheCamera.Cams[TheCamera.ActiveCam].CamTargetEntity = pActors[m_nActor]; + if (CPad::GetPad(1)->GetTriangleJustDown()) { + Movie[m_nNumMovieCommands].m_nCommandId = MOVIE_SET_CAMERA_TARGET; + Movie[m_nNumMovieCommands++].m_nActorId = m_nActor; + m_bCommandActive = false; + } + } + break; + case MOVIE_SELECT_CAMERA_MODE: + m_bCommandActive = false; + break; + case MOVIE_SAVE_MOVIE: + SaveMovie(); + break; + case MOVIE_LOAD_MOVIE: + LoadMovie(); + break; + case MOVIE_PLAY_MOVIE: + InitPlayback(); + LoadMovie(); + m_bRecording = false; + break; + case MOVIE_END: + m_bRecording = false; + break; + default: + assert(0); + } +} + +void CSceneEdit::PlayBack(void) +{ + m_nCurrentCommand = Movie[m_nCurrentMovieCommand].m_nCommandId; + if (m_nCurrentMovieCommand >= m_nNumMovieCommands) { + if (CPad::GetPad(1)->GetTriangleJustDown()) { + m_nCurrentCommand = MOVIE_DO_NOTHING; + m_bRecording = true; + ReInitialise(); + } + return; + } + switch (m_nCurrentCommand) { + case MOVIE_DO_NOTHING: + case MOVIE_MOVE_ACTOR: + case MOVIE_SELECT_ACTOR: + case MOVIE_DELETE_ACTOR: + case MOVIE_MOVE_VEHICLE: + case MOVIE_SELECT_VEHICLE: + case MOVIE_DELETE_VEHICLE: + break; + case MOVIE_NEW_ACTOR: + { + m_nPedmodelId = Movie[m_nCurrentMovieCommand].m_nModelIndex; + m_vecCurrentPosition = Movie[m_nCurrentMovieCommand].m_vecPosition; + if (!CStreaming::HasModelLoaded(m_nPedmodelId)) { + CStreaming::RequestModel(m_nPedmodelId, 0); +#ifdef FIX_BUGS + CStreaming::LoadAllRequestedModels(false); // otherwise gets stuck :( +#endif + break; + } + CPed* pPed = new CCivilianPed(PEDTYPE_SPECIAL, m_nPedmodelId); + pPed->CharCreatedBy = MISSION_CHAR; + CWorld::Add(pPed); + pPed->GetPosition() = m_vecCurrentPosition; + pPed->SetOrientation(0.0f, 0.0f, 0.0f); + for (int i = 0; i < NUM_ACTORS_IN_MOVIE; i++) { + if (pActors[i] == nil) { + m_nActor = i; + pActors[i] = pPed; + break; + } + } + m_nNumActors++; + m_nCurrentMovieCommand++; + break; + } + case MOVIE_NEW_VEHICLE: + { + m_nVehiclemodelId = Movie[m_nCurrentMovieCommand].m_nModelIndex; + m_vecCurrentPosition = Movie[m_nCurrentMovieCommand].m_vecPosition; + if (!CStreaming::HasModelLoaded(m_nVehiclemodelId)) { + CStreaming::RequestModel(m_nVehiclemodelId, 0); +#ifdef FIX_BUGS + CStreaming::LoadAllRequestedModels(false); // otherwise gets stuck :( +#endif + break; + } + CVehicle* pVehicle = new CAutomobile(m_nVehiclemodelId, MISSION_VEHICLE); + pVehicle->m_status = STATUS_PHYSICS; + pVehicle->GetPosition() = m_vecCurrentPosition; + pVehicle->SetOrientation(0.0f, 0.0f, 0.0f); + CWorld::Add(pVehicle); + for (int i = 0; i < NUM_VEHICLES_IN_MOVIE; i++) { + if (pVehicles[i] == nil) { + m_nVehicle = i; + pVehicles[i] = pVehicle; + break; + } + } + m_nNumVehicles++; + m_nCurrentMovieCommand++; + break; + } + case MOVIE_GIVE_WEAPON: + m_nActor = Movie[m_nCurrentMovieCommand].m_nActorId; + m_nWeaponType = Movie[m_nCurrentMovieCommand].m_nModelIndex; + pActors[m_nActor]->GiveWeapon((eWeaponType)m_nWeaponType, 1000); + pActors[m_nActor]->AddWeaponModel(CWeaponInfo::GetWeaponInfo(pActors[m_nActor]->GetWeapon()->m_eWeaponType)->m_nModelId); + pActors[m_nActor]->SetCurrentWeapon(m_nWeaponType); + m_nCurrentMovieCommand++; + break; + case MOVIE_GOTO: + case MOVIE_GOTO_WAIT: + m_nActor = Movie[m_nCurrentMovieCommand].m_nActorId; + m_vecGotoPosition = Movie[m_nCurrentMovieCommand].m_vecPosition; + if (pActors[m_nActor]->bInVehicle) { + if (pActors[m_nActor]->m_pMyVehicle->AutoPilot.m_nCarMission != MISSION_GOTOCOORDS && + pActors[m_nActor]->m_pMyVehicle->AutoPilot.m_nCarMission != MISSION_GOTOCOORDS_STRAIGHT) { + if ((pActors[m_nActor]->m_pMyVehicle->GetPosition() - m_vecGotoPosition).Magnitude() < 5.0f) { + if (CCarCtrl::JoinCarWithRoadSystemGotoCoors(pActors[m_nActor]->m_pMyVehicle, m_vecGotoPosition, false)) + pActors[m_nActor]->m_pMyVehicle->AutoPilot.m_nCarMission = MISSION_GOTOCOORDS_STRAIGHT; + else + pActors[m_nActor]->m_pMyVehicle->AutoPilot.m_nCarMission = MISSION_GOTOCOORDS; + pActors[m_nActor]->m_pMyVehicle->m_status = STATUS_PHYSICS; + pActors[m_nActor]->m_pMyVehicle->bEngineOn = true; + pActors[m_nActor]->m_pMyVehicle->AutoPilot.m_nCruiseSpeed = Max(16, pActors[m_nActor]->m_pMyVehicle->AutoPilot.m_nCruiseSpeed); + pActors[m_nActor]->m_pMyVehicle->AutoPilot.m_nAntiReverseTimer = CTimer::GetTimeInMilliseconds(); + if (m_nCurrentCommand != MOVIE_GOTO_WAIT) + ++m_nCurrentMovieCommand; + } + else + ++m_nCurrentMovieCommand; + } + } + else { + if (pActors[m_nActor]->m_objective != OBJECTIVE_GOTO_AREA_ON_FOOT) { + pActors[m_nActor]->SetObjective(OBJECTIVE_GOTO_AREA_ON_FOOT, m_vecGotoPosition); + ++m_nCurrentMovieCommand; + } + } + break; + case MOVIE_GET_IN_CAR: + m_nActor = Movie[m_nCurrentMovieCommand].m_nActorId; + if (!pActors[m_nActor]->bInVehicle){ + m_nVehicle = Movie[m_nCurrentMovieCommand].m_nVehicleId; + pActors[m_nActor]->SetObjective(OBJECTIVE_ENTER_CAR_AS_DRIVER, pVehicles[m_nVehicle]); + } + else + ++m_nCurrentMovieCommand; + break; + case MOVIE_GET_OUT_CAR: + m_nActor = Movie[m_nCurrentMovieCommand].m_nActorId; + if (pActors[m_nActor]->bInVehicle) + pActors[m_nActor]->SetObjective(OBJECTIVE_LEAVE_VEHICLE); + else + ++m_nCurrentMovieCommand; + break; + case MOVIE_KILL: + m_nActor = Movie[m_nCurrentMovieCommand].m_nActorId; + m_nActor2 = Movie[m_nCurrentMovieCommand].m_nActor2Id; + pActors[m_nActor]->SetObjective(OBJECTIVE_KILL_CHAR_ON_FOOT, pActors[m_nActor2]); + if (pActors[m_nActor2]->GetPedState() == PED_DEAD) + ++m_nCurrentMovieCommand; + break; + case MOVIE_FLEE: + m_nActor = Movie[m_nCurrentMovieCommand].m_nActorId; + m_nActor2 = Movie[m_nCurrentMovieCommand].m_nActor2Id; + pActors[m_nActor]->SetObjective(OBJECTIVE_FLEE_CHAR_ON_FOOT_ALWAYS, pActors[m_nActor2]); + ++m_nCurrentMovieCommand; + break; + case MOVIE_WAIT: + m_nActor = Movie[m_nCurrentMovieCommand].m_nActorId; + pActors[m_nActor]->SetObjective(OBJECTIVE_IDLE); + ++m_nCurrentMovieCommand; + break; + case MOVIE_POSITION_CAMERA: + TheCamera.Cams[TheCamera.ActiveCam].Source = Movie[m_nCurrentMovieCommand].m_vecPosition; + m_vecCamHeading = Movie[m_nCurrentMovieCommand].m_vecCamera; + TheCamera.Cams[TheCamera.ActiveCam].Front = m_vecCamHeading; + ++m_nCurrentMovieCommand; + break; + case MOVIE_SET_CAMERA_TARGET: + m_bCameraFollowActor = true; + TheCamera.Cams[TheCamera.ActiveCam].CamTargetEntity = pActors[Movie[m_nNumMovieCommands].m_nActorId]; + TheCamera.pTargetEntity = pActors[Movie[m_nNumMovieCommands].m_nActorId]; + TheCamera.m_bLookingAtPlayer = false; + ++m_nCurrentMovieCommand; + break; + case MOVIE_SELECT_CAMERA_MODE: + m_bCommandActive = false; // this is wrong + break; + } +} + +void CSceneEdit::ClearForNewCommand(void) +{ + m_nActor = -1; + m_nActor2 = -1; + m_nVehicle = -1; + m_bActorSelected = false; + m_bActor2Selected = false; + m_bVehicleSelected = false; + m_bDrawGotoArrow = false; +} +void CSceneEdit::SelectActor(void) +{ + m_bActorSelected = false; + if (m_nActor != -1) { + if (CPad::GetPad(1)->GetLeftShoulder1JustDown()) { + CPed* pPed; + do { + if (--m_nActor < 0) + m_nActor = NUM_ACTORS_IN_MOVIE - 1; + pPed = pActors[m_nActor]; + } while (pPed == nil); + TheCamera.Cams[TheCamera.ActiveCam].Source = pPed->GetPosition() - m_vecCamHeading; + } + else if (CPad::GetPad(1)->GetRightShoulder1JustDown()) { + CPed* pPed; + do { + if (++m_nActor == NUM_ACTORS_IN_MOVIE) + m_nActor = 0; + pPed = pActors[m_nActor]; + } while (pPed == nil); + TheCamera.Cams[TheCamera.ActiveCam].Source = pPed->GetPosition() - m_vecCamHeading; + } + m_vecCurrentPosition = pActors[m_nActor]->GetPosition(); + if (CPad::GetPad(1)->GetTriangleJustDown()) { + m_bActorSelected = true; + m_bCommandActive = false; + } + else if (CPad::GetPad(1)->GetCircleJustDown()) { + m_nActor = -1; + } + } + else if (m_nNumActors != 0) { + for (int i = 0; i < NUM_ACTORS_IN_MOVIE; i++) { + if (pActors[i] != nil) { + m_nActor = i; + break; + } + } + TheCamera.Cams[TheCamera.ActiveCam].Source = pActors[m_nActor]->GetPosition() - m_vecCamHeading; + if (m_nNumActors == 1) { + m_bActorSelected = true; + m_bCommandActive = false; + } + } + else { + m_bCommandActive = false; + } +} + +void CSceneEdit::SelectActor2(void) +{ + m_bActor2Selected = false; + if (m_nNumActors <= 1) { + m_bCommandActive = false; + return; + } + if (m_nActor2 != -1) { + if (CPad::GetPad(1)->GetLeftShoulder1JustDown()) { + CPed* pPed; + do { + if (--m_nActor2 < 0) + m_nActor2 = NUM_ACTORS_IN_MOVIE - 1; + pPed = pActors[m_nActor2]; + } while (pPed == nil || pPed == pActors[m_nActor]); + TheCamera.Cams[TheCamera.ActiveCam].Source = pPed->GetPosition() - m_vecCamHeading; + } + else if (CPad::GetPad(1)->GetRightShoulder1JustDown()) { + CPed* pPed; + do { + if (++m_nActor2 == NUM_ACTORS_IN_MOVIE) + m_nActor2 = 0; + pPed = pActors[m_nActor2]; + } while (pPed == nil || pPed == pActors[m_nActor]); + TheCamera.Cams[TheCamera.ActiveCam].Source = pPed->GetPosition() - m_vecCamHeading; + } + m_vecCurrentPosition = pActors[m_nActor2]->GetPosition(); + if (CPad::GetPad(1)->GetTriangleJustDown()) { + m_bActor2Selected = true; + m_bCommandActive = false; + } + else if (CPad::GetPad(1)->GetCircleJustDown()) { + m_nActor2 = -1; + } + } + else { + for (int i = 0; i < NUM_ACTORS_IN_MOVIE; i++) { + if (pActors[i] != nil && pActors[m_nActor] != pActors[i] ) { + m_nActor2 = i; + break; + } + } + TheCamera.Cams[TheCamera.ActiveCam].Source = pActors[m_nActor2]->GetPosition() - m_vecCamHeading; + } +} + +void CSceneEdit::SelectVehicle(void) +{ + m_bVehicleSelected = false; + if (m_nVehicle != -1) { + if (CPad::GetPad(1)->GetLeftShoulder1JustDown()) { + CVehicle* pVehicle; + do { + if (--m_nVehicle < 0) + m_nVehicle = NUM_VEHICLES_IN_MOVIE - 1; + pVehicle = pVehicles[m_nVehicle]; + } while (pVehicle == nil); + } + else if (CPad::GetPad(1)->GetRightShoulder1JustDown()) { + CVehicle* pVehicle; + do { + if (++m_nVehicle == NUM_VEHICLES_IN_MOVIE) + m_nVehicle = 0; + pVehicle = pVehicles[m_nVehicle]; + } while (pVehicle == nil); + } + m_vecCurrentPosition = pVehicles[m_nVehicle]->GetPosition(); + TheCamera.Cams[TheCamera.ActiveCam].Source = pVehicles[m_nVehicle]->GetPosition() - m_vecCamHeading; + if (CPad::GetPad(1)->GetTriangleJustDown()) { + m_bVehicleSelected = true; + m_bCommandActive = false; + } + else if (CPad::GetPad(1)->GetCircleJustDown()) { + m_nVehicle = -1; + } + } + else if (m_nNumVehicles != 0) { + for (int i = 0; i < NUM_ACTORS_IN_MOVIE; i++) { + if (pVehicles[i] != nil) { + m_nVehicle = i; + break; + } + } + } +} -WRAPPER void CSceneEdit::Update(void) { EAXJMP(0x585570); } -WRAPPER void CSceneEdit::Init(void) { EAXJMP(0x585170); } +bool CSceneEdit::SelectWeapon(void) +{ + if (m_nWeaponType == WEAPONTYPE_UNARMED) { + m_nWeaponType = WEAPONTYPE_COLT45; + return false; + } + if (CPad::GetPad(1)->GetLeftShoulder1JustDown()) { + if (++m_nWeaponType >= WEAPONTYPE_DETONATOR) + m_nWeaponType = WEAPONTYPE_BASEBALLBAT; + pActors[m_nActor]->ClearWeapons(); + pActors[m_nActor]->GiveWeapon((eWeaponType)m_nWeaponType, 1000); + pActors[m_nActor]->AddWeaponModel(CWeaponInfo::GetWeaponInfo(pActors[m_nActor]->GetWeapon()->m_eWeaponType)->m_nModelId); + pActors[m_nActor]->SetCurrentWeapon(m_nWeaponType); + } + else if (CPad::GetPad(1)->GetRightShoulder1JustDown()){ + if (--m_nWeaponType <= WEAPONTYPE_UNARMED) + m_nWeaponType = WEAPONTYPE_GRENADE; + pActors[m_nActor]->ClearWeapons(); + pActors[m_nActor]->GiveWeapon((eWeaponType)m_nWeaponType, 1000); + pActors[m_nActor]->AddWeaponModel(CWeaponInfo::GetWeaponInfo(pActors[m_nActor]->GetWeapon()->m_eWeaponType)->m_nModelId); + pActors[m_nActor]->SetCurrentWeapon(m_nWeaponType); + } + if (CPad::GetPad(1)->GetTriangleJustDown()) { + m_bCommandActive = false; + return true; + } + if (CPad::GetPad(1)->GetCircleJustDown()) { + pActors[m_nActor]->ClearWeapons(); + m_nWeaponType = WEAPONTYPE_UNARMED; + m_bCommandActive = false; + return false; + } + return false; +}
\ No newline at end of file diff --git a/src/control/SceneEdit.h b/src/control/SceneEdit.h index 0de72c19..6dcefa31 100644 --- a/src/control/SceneEdit.h +++ b/src/control/SceneEdit.h @@ -1,14 +1,95 @@ #pragma once +class CPed; +class CVehicle; + +struct CMovieCommand +{ + int32 m_nCommandId; + CVector m_vecPosition; + CVector m_vecCamera; + int16 m_nActorId; + int16 m_nActor2Id; + int16 m_nVehicleId; + int16 m_nModelIndex; +}; + class CSceneEdit { public: - static bool &m_bEditOn; - static int32 &m_bCameraFollowActor; - static bool &m_bRecording; - static CVector &m_vecCurrentPosition; - static CVector &m_vecCamHeading; + enum { + MOVIE_DO_NOTHING = 0, + MOVIE_NEW_ACTOR, + MOVIE_MOVE_ACTOR, + MOVIE_SELECT_ACTOR, + MOVIE_DELETE_ACTOR, + MOVIE_NEW_VEHICLE, + MOVIE_MOVE_VEHICLE, + MOVIE_SELECT_VEHICLE, + MOVIE_DELETE_VEHICLE, + MOVIE_GIVE_WEAPON, + MOVIE_GOTO, + MOVIE_GOTO_WAIT, + MOVIE_GET_IN_CAR, + MOVIE_GET_OUT_CAR, + MOVIE_KILL, + MOVIE_FLEE, + MOVIE_WAIT, + MOVIE_POSITION_CAMERA, + MOVIE_SET_CAMERA_TARGET, + MOVIE_SELECT_CAMERA_MODE, + MOVIE_SAVE_MOVIE, + MOVIE_LOAD_MOVIE, + MOVIE_PLAY_MOVIE, + MOVIE_END, + MOVIE_TOTAL_COMMANDS + }; + enum { + NUM_ACTORS_IN_MOVIE = 5, + NUM_VEHICLES_IN_MOVIE = 5, + NUM_COMMANDS_IN_MOVIE = 20 + }; + static int32 m_bCameraFollowActor; + static CVector m_vecCurrentPosition; + static CVector m_vecCamHeading; + static CVector m_vecGotoPosition; + static int32 m_nVehicle; + static int32 m_nVehicle2; + static int32 m_nActor; + static int32 m_nActor2; + static int32 m_nVehiclemodelId; + static int32 m_nPedmodelId; + static int16 m_nCurrentMovieCommand; + static int16 m_nCurrentCommand; + static int16 m_nCurrentVehicle; + static int16 m_nCurrentActor; + static bool m_bEditOn; + static bool m_bRecording; + static bool m_bCommandActive; + static bool m_bActorSelected; + static bool m_bActor2Selected; + static bool m_bVehicleSelected; + static int16 m_nNumActors; + static int16 m_nNumVehicles; + static int16 m_nNumMovieCommands; + static int16 m_nWeaponType; + static CPed* pActors[NUM_ACTORS_IN_MOVIE]; + static CVehicle* pVehicles[NUM_VEHICLES_IN_MOVIE]; + static bool m_bDrawGotoArrow; + static CMovieCommand Movie[NUM_COMMANDS_IN_MOVIE]; + static void LoadMovie(void); + static void SaveMovie(void); + static void Initialise(void); + static void InitPlayback(void); + static void ReInitialise(void); static void Update(void); - static void Init(void); + static void Draw(void); + static void ProcessCommand(void); + static void PlayBack(void); + static void ClearForNewCommand(void); + static void SelectActor(void); + static void SelectActor2(void); + static void SelectVehicle(void); + static bool SelectWeapon(void); }; diff --git a/src/control/Script.cpp b/src/control/Script.cpp index 1f085d32..7ab40847 100644 --- a/src/control/Script.cpp +++ b/src/control/Script.cpp @@ -1,10 +1,10 @@ #define WITHWINDOWS // for our script loading hack #include "common.h" -#include "patcher.h" #include "Script.h" #include "ScriptCommands.h" +#include "AnimBlendAssociation.h" #include "Boat.h" #include "BulletInfo.h" #include "Camera.h" @@ -18,11 +18,12 @@ #include "Cranes.h" #include "Credits.h" #include "CutsceneMgr.h" -#include "Darkel.h" #include "DMAudio.h" +#include "Darkel.h" #include "EmergencyPed.h" #include "Explosion.h" #include "FileMgr.h" +#include "Fire.h" #include "Frontend.h" #include "Gangs.h" #include "Garages.h" @@ -31,7 +32,6 @@ #include "Heli.h" #include "Hud.h" #include "Lines.h" -#include "main.h" #include "Messages.h" #include "ModelIndices.h" #include "Pad.h" @@ -48,13 +48,12 @@ #include "Population.h" #include "PowerPoints.h" #include "ProjectileInfo.h" +#include "Radar.h" #include "Record.h" #include "Remote.h" -#include "Restart.h" #include "Replay.h" +#include "Restart.h" #include "RpAnimBlend.h" -#include "AnimBlendAssociation.h" -#include "Fire.h" #include "Rubbish.h" #include "Shadows.h" #include "SpecialFX.h" @@ -67,7 +66,7 @@ #include "Weather.h" #include "World.h" #include "Zones.h" -#include "Radar.h" +#include "main.h" #define PICKUP_PLACEMENT_OFFSET 0.5f #define PED_FIND_Z_OFFSET 5.0f @@ -87,47 +86,47 @@ #define FEET_IN_METER 3.33f #endif -uint8 (&CTheScripts::ScriptSpace)[SIZE_SCRIPT_SPACE] = *(uint8(*)[SIZE_SCRIPT_SPACE])*(uintptr*)0x74B248; -CRunningScript(&CTheScripts::ScriptsArray)[MAX_NUM_SCRIPTS] = *(CRunningScript(*)[MAX_NUM_SCRIPTS])*(uintptr*)0x6F5C08; -int32(&CTheScripts::BaseBriefIdForContact)[MAX_NUM_CONTACTS] = *(int32(*)[MAX_NUM_CONTACTS])*(uintptr*)0x880200; -int32(&CTheScripts::OnAMissionForContactFlag)[MAX_NUM_CONTACTS] = *(int32(*)[MAX_NUM_CONTACTS])*(uintptr*)0x8622F0; -intro_text_line (&CTheScripts::IntroTextLines)[MAX_NUM_INTRO_TEXT_LINES] = *(intro_text_line (*)[MAX_NUM_INTRO_TEXT_LINES])*(uintptr*)0x70EA68; -intro_script_rectangle (&CTheScripts::IntroRectangles)[MAX_NUM_INTRO_RECTANGLES] = *(intro_script_rectangle (*)[MAX_NUM_INTRO_RECTANGLES])*(uintptr*)0x72D108; -CSprite2d (&CTheScripts::ScriptSprites)[MAX_NUM_SCRIPT_SRPITES] = *(CSprite2d(*)[MAX_NUM_SCRIPT_SRPITES])*(uintptr*)0x72B090; -script_sphere_struct(&CTheScripts::ScriptSphereArray)[MAX_NUM_SCRIPT_SPHERES] = *(script_sphere_struct(*)[MAX_NUM_SCRIPT_SPHERES])*(uintptr*)0x727D60; -tCollectiveData(&CTheScripts::CollectiveArray)[MAX_NUM_COLLECTIVES] = *(tCollectiveData(*)[MAX_NUM_COLLECTIVES])*(uintptr*)0x6FA008; -tUsedObject(&CTheScripts::UsedObjectArray)[MAX_NUM_USED_OBJECTS] = *(tUsedObject(*)[MAX_NUM_USED_OBJECTS])*(uintptr*)0x6E69C8; -int32(&CTheScripts::MultiScriptArray)[MAX_NUM_MISSION_SCRIPTS] = *(int32(*)[MAX_NUM_MISSION_SCRIPTS])*(uintptr*)0x6F0558; -tBuildingSwap(&CTheScripts::BuildingSwapArray)[MAX_NUM_BUILDING_SWAPS] = *(tBuildingSwap(*)[MAX_NUM_BUILDING_SWAPS])*(uintptr*)0x880E30; -CEntity*(&CTheScripts::InvisibilitySettingArray)[MAX_NUM_INVISIBILITY_SETTINGS] = *(CEntity*(*)[MAX_NUM_INVISIBILITY_SETTINGS])*(uintptr*)0x8620F0; -CStoredLine (&CTheScripts::aStoredLines)[MAX_NUM_STORED_LINES] = *(CStoredLine(*)[MAX_NUM_STORED_LINES])*(uintptr*)0x743018; -bool &CTheScripts::DbgFlag = *(bool*)0x95CD87; -uint32 &CTheScripts::OnAMissionFlag = *(uint32*)0x8F1B64; -int32 &CTheScripts::StoreVehicleIndex = *(int32*)0x8F5F3C; -bool &CTheScripts::StoreVehicleWasRandom = *(bool*)0x95CDBC; -CRunningScript *&CTheScripts::pIdleScripts = *(CRunningScript**)0x9430D4; -CRunningScript *&CTheScripts::pActiveScripts = *(CRunningScript**)0x8E2BF4; -uint32 &CTheScripts::NextFreeCollectiveIndex = *(uint32*)0x942F98; -int32 &CTheScripts::LastRandomPedId = *(int32*)0x8F251C; -uint16 &CTheScripts::NumberOfUsedObjects = *(uint16*)0x95CC72; -bool &CTheScripts::bAlreadyRunningAMissionScript = *(bool*)0x95CDB3; -bool &CTheScripts::bUsingAMultiScriptFile = *(bool*)0x95CD55; -uint16 &CTheScripts::NumberOfMissionScripts = *(uint16*)0x95CC9A; -uint32 &CTheScripts::LargestMissionScriptSize = *(uint32*)0x9414C8; -uint32 &CTheScripts::MainScriptSize = *(uint32*)0x9405A4; -uint8 &CTheScripts::FailCurrentMission = *(uint8*)0x95CD41; -uint8 &CTheScripts::CountdownToMakePlayerUnsafe = *(uint8*)0x95CD51; -uint8 &CTheScripts::DelayMakingPlayerUnsafeThisTime = *(uint8*)0x95CD88; -uint16 &CTheScripts::NumScriptDebugLines = *(uint16*)0x95CC42; -uint16 &CTheScripts::NumberOfIntroRectanglesThisFrame = *(uint16*)0x95CC88; -uint16 &CTheScripts::NumberOfIntroTextLinesThisFrame = *(uint16*)0x95CC32; -uint8 &CTheScripts::UseTextCommands = *(uint8*)0x95CD57; -CMissionCleanup (&CTheScripts::MissionCleanup) = *(CMissionCleanup*)0x8F2A24; -CUpsideDownCarCheck (&CTheScripts::UpsideDownCars) = *(CUpsideDownCarCheck*)0x6EE450; -CStuckCarCheck (&CTheScripts::StuckCars) = *(CStuckCarCheck*)0x87C588; -uint16 &CTheScripts::CommandsExecuted = *(uint16*)0x95CCA6; -uint16 &CTheScripts::ScriptsUpdated = *(uint16*)0x95CC5E; -int32(&ScriptParams)[32] = *(int32(*)[32])*(uintptr*)0x6ED460; +uint8 CTheScripts::ScriptSpace[SIZE_SCRIPT_SPACE]; +CRunningScript CTheScripts::ScriptsArray[MAX_NUM_SCRIPTS]; +int32 CTheScripts::BaseBriefIdForContact[MAX_NUM_CONTACTS]; +int32 CTheScripts::OnAMissionForContactFlag[MAX_NUM_CONTACTS]; +intro_text_line CTheScripts::IntroTextLines[MAX_NUM_INTRO_TEXT_LINES]; +intro_script_rectangle CTheScripts::IntroRectangles[MAX_NUM_INTRO_RECTANGLES]; +CSprite2d CTheScripts::ScriptSprites[MAX_NUM_SCRIPT_SRPITES]; +script_sphere_struct CTheScripts::ScriptSphereArray[MAX_NUM_SCRIPT_SPHERES]; +tCollectiveData CTheScripts::CollectiveArray[MAX_NUM_COLLECTIVES]; +tUsedObject CTheScripts::UsedObjectArray[MAX_NUM_USED_OBJECTS]; +int32 CTheScripts::MultiScriptArray[MAX_NUM_MISSION_SCRIPTS]; +tBuildingSwap CTheScripts::BuildingSwapArray[MAX_NUM_BUILDING_SWAPS]; +CEntity* CTheScripts::InvisibilitySettingArray[MAX_NUM_INVISIBILITY_SETTINGS]; +CStoredLine CTheScripts::aStoredLines[MAX_NUM_STORED_LINES]; +bool CTheScripts::DbgFlag; +uint32 CTheScripts::OnAMissionFlag; +int32 CTheScripts::StoreVehicleIndex; +bool CTheScripts::StoreVehicleWasRandom; +CRunningScript *CTheScripts::pIdleScripts; +CRunningScript *CTheScripts::pActiveScripts; +uint32 CTheScripts::NextFreeCollectiveIndex; +int32 CTheScripts::LastRandomPedId; +uint16 CTheScripts::NumberOfUsedObjects; +bool CTheScripts::bAlreadyRunningAMissionScript; +bool CTheScripts::bUsingAMultiScriptFile; +uint16 CTheScripts::NumberOfMissionScripts; +uint32 CTheScripts::LargestMissionScriptSize; +uint32 CTheScripts::MainScriptSize; +uint8 CTheScripts::FailCurrentMission; +uint8 CTheScripts::CountdownToMakePlayerUnsafe; +uint8 CTheScripts::DelayMakingPlayerUnsafeThisTime; +uint16 CTheScripts::NumScriptDebugLines; +uint16 CTheScripts::NumberOfIntroRectanglesThisFrame; +uint16 CTheScripts::NumberOfIntroTextLinesThisFrame; +uint8 CTheScripts::UseTextCommands; +CMissionCleanup CTheScripts::MissionCleanup; +CUpsideDownCarCheck CTheScripts::UpsideDownCars; +CStuckCarCheck CTheScripts::StuckCars; +uint16 CTheScripts::CommandsExecuted; +uint16 CTheScripts::ScriptsUpdated; +int32 ScriptParams[32]; CMissionCleanup::CMissionCleanup() { @@ -2010,7 +2009,7 @@ int8 CRunningScript::ProcessCommands100To199(int32 command) car->AutoPilot.m_nCarMission = MISSION_GOTOCOORDS; car->m_status = STATUS_PHYSICS; car->bEngineOn = true; - car->AutoPilot.m_nCruiseSpeed = max(car->AutoPilot.m_nCruiseSpeed, 6); + car->AutoPilot.m_nCruiseSpeed = Max(car->AutoPilot.m_nCruiseSpeed, 6); car->AutoPilot.m_nAntiReverseTimer = CTimer::GetTimeInMilliseconds(); return 0; } @@ -2022,7 +2021,7 @@ int8 CRunningScript::ProcessCommands100To199(int32 command) CCarCtrl::JoinCarWithRoadSystem(car); car->AutoPilot.m_nCarMission = MISSION_CRUISE; car->bEngineOn = true; - car->AutoPilot.m_nCruiseSpeed = max(car->AutoPilot.m_nCruiseSpeed, 6); + car->AutoPilot.m_nCruiseSpeed = Max(car->AutoPilot.m_nCruiseSpeed, 6); car->AutoPilot.m_nAntiReverseTimer = CTimer::GetTimeInMilliseconds(); return 0; } @@ -2106,7 +2105,7 @@ int8 CRunningScript::ProcessCommands100To199(int32 command) CollectParameters(&m_nIp, 2); CVehicle* car = CPools::GetVehiclePool()->GetAt(ScriptParams[0]); assert(car); - car->AutoPilot.m_nCruiseSpeed = min(*(float*)&ScriptParams[1], 60.0f * car->pHandling->Transmission.fUnkMaxVelocity); + car->AutoPilot.m_nCruiseSpeed = Min(*(float*)&ScriptParams[1], 60.0f * car->pHandling->Transmission.fUnkMaxVelocity); return 0; } case COMMAND_SET_CAR_DRIVING_STYLE: @@ -3645,7 +3644,7 @@ int8 CRunningScript::ProcessCommands400To499(int32 command) pos.x = (infX + supX) / 2; pos.y = (infY + supY) / 2; pos.z = CWorld::FindGroundZForCoord(pos.x, pos.y); - float radius = max(pos.x - infX, pos.y - infY); + float radius = Max(pos.x - infX, pos.y - infY); pPed->bScriptObjectiveCompleted = false; pPed->SetObjective(OBJECTIVE_GUARD_SPOT, pos, radius); return 0; @@ -4151,7 +4150,7 @@ int8 CRunningScript::ProcessCommands400To499(int32 command) pos.x = (infX + supX) / 2; pos.y = (infY + supY) / 2; pos.z = CWorld::FindGroundZForCoord(pos.x, pos.y); - float radius = max(pos.x - infX, pos.y - infY); + float radius = Max(pos.x - infX, pos.y - infY); pPed->bScriptObjectiveCompleted = false; pPed->SetObjective(OBJECTIVE_GOTO_AREA_ON_FOOT, pos, radius); return 0; @@ -4947,7 +4946,7 @@ int8 CRunningScript::ProcessCommands500To599(int32 command) pos.x = (infX + supX) / 2; pos.y = (infY + supY) / 2; pos.z = CWorld::FindGroundZForCoord(pos.x, pos.y); - float radius = max(pos.x - infX, pos.y - infY); + float radius = Max(pos.x - infX, pos.y - infY); pPed->bScriptObjectiveCompleted = false; pPed->SetObjective(OBJECTIVE_RUN_TO_AREA, pos, radius); return 0; @@ -5369,7 +5368,7 @@ int8 CRunningScript::ProcessCommands600To699(int32 command) pos.x = (infX + supX) / 2; pos.y = (infY + supY) / 2; pos.z = CWorld::FindGroundZForCoord(pos.x, pos.y); - float radius = max(pos.x - infX, pos.y - infY); + float radius = Max(pos.x - infX, pos.y - infY); pPed->bScriptObjectiveCompleted = false; pPed->SetObjective(OBJECTIVE_GOTO_AREA_ANY_MEANS, pos, radius); return 0; @@ -5606,7 +5605,7 @@ int8 CRunningScript::ProcessCommands700To799(int32 command) pVehicle->AutoPilot.m_nCarMission = MISSION_GOTOCOORDS_ACCURATE; pVehicle->m_status = STATUS_PHYSICS; pVehicle->bEngineOn = true; - pVehicle->AutoPilot.m_nCruiseSpeed = max(6, pVehicle->AutoPilot.m_nCruiseSpeed); + pVehicle->AutoPilot.m_nCruiseSpeed = Max(6, pVehicle->AutoPilot.m_nCruiseSpeed); pVehicle->AutoPilot.m_nAntiReverseTimer = CTimer::GetTimeInMilliseconds(); return 0; } @@ -5721,7 +5720,7 @@ int8 CRunningScript::ProcessCommands700To799(int32 command) pBoat->AutoPilot.m_nCarMission = MISSION_GOTOCOORDS_ASTHECROWSWIMS; pBoat->AutoPilot.m_vecDestinationCoors = pos; pBoat->m_status = STATUS_PHYSICS; - pBoat->AutoPilot.m_nCruiseSpeed = max(6, pBoat->AutoPilot.m_nCruiseSpeed); + pBoat->AutoPilot.m_nCruiseSpeed = Max(6, pBoat->AutoPilot.m_nCruiseSpeed); pBoat->AutoPilot.m_nAntiReverseTimer = CTimer::GetTimeInMilliseconds(); return 0; } @@ -6306,23 +6305,23 @@ int8 CRunningScript::ProcessCommands700To799(int32 command) return 0; case COMMAND_REGISTER_JUMP_DISTANCE: CollectParameters(&m_nIp, 1); - CStats::MaximumJumpDistance = max(CStats::MaximumJumpDistance, *(float*)&ScriptParams[0]); + CStats::MaximumJumpDistance = Max(CStats::MaximumJumpDistance, *(float*)&ScriptParams[0]); return 0; case COMMAND_REGISTER_JUMP_HEIGHT: CollectParameters(&m_nIp, 1); - CStats::MaximumJumpHeight = max(CStats::MaximumJumpHeight, *(float*)&ScriptParams[0]); + CStats::MaximumJumpHeight = Max(CStats::MaximumJumpHeight, *(float*)&ScriptParams[0]); return 0; case COMMAND_REGISTER_JUMP_FLIPS: CollectParameters(&m_nIp, 1); - CStats::MaximumJumpFlips = max(CStats::MaximumJumpFlips, ScriptParams[0]); + CStats::MaximumJumpFlips = Max(CStats::MaximumJumpFlips, ScriptParams[0]); return 0; case COMMAND_REGISTER_JUMP_SPINS: CollectParameters(&m_nIp, 1); - CStats::MaximumJumpSpins = max(CStats::MaximumJumpSpins, ScriptParams[0]); + CStats::MaximumJumpSpins = Max(CStats::MaximumJumpSpins, ScriptParams[0]); return 0; case COMMAND_REGISTER_JUMP_STUNT: CollectParameters(&m_nIp, 1); - CStats::BestStuntJump = max(CStats::BestStuntJump, ScriptParams[0]); + CStats::BestStuntJump = Max(CStats::BestStuntJump, ScriptParams[0]); return 0; case COMMAND_REGISTER_UNIQUE_JUMP_FOUND: ++CStats::NumberOfUniqueJumpsFound; @@ -6436,9 +6435,7 @@ int8 CRunningScript::ProcessCommands800To899(int32 command) pPed->FlagToDestroyWhenNextProcessed(); } else if (CGame::nastyGame && pPed->IsPedInControl()) { - RwMatrix tmp_rw; - CPedIK::GetWorldMatrix(pPed->m_pFrames[PED_HEAD]->frame, &tmp_rw); - pPed->ApplyHeadShot(WEAPONTYPE_SNIPERRIFLE, tmp_rw.pos, true); + pPed->ApplyHeadShot(WEAPONTYPE_SNIPERRIFLE, pPed->GetNodePosition(PED_HEAD), true); } else { pPed->SetDie(ANIM_KO_SHOT_FRONT1, 4.0f, 0.0f); @@ -6451,9 +6448,7 @@ int8 CRunningScript::ProcessCommands800To899(int32 command) CPed* pPed = CWorld::Players[ScriptParams[0]].m_pPed; assert(pPed); if (CGame::nastyGame) { - RwMatrix tmp_rw; - CPedIK::GetWorldMatrix(pPed->m_pFrames[PED_HEAD]->frame, &tmp_rw); - pPed->ApplyHeadShot(WEAPONTYPE_SNIPERRIFLE, tmp_rw.pos, true); + pPed->ApplyHeadShot(WEAPONTYPE_SNIPERRIFLE, pPed->GetNodePosition(PED_HEAD), true); } else { pPed->SetDie(ANIM_KO_SHOT_FRONT1, 4.0f, 0.0f); @@ -6855,10 +6850,10 @@ int8 CRunningScript::ProcessCommands800To899(int32 command) CVector cp4 = tmp_matrix * CVector(pColModel->boundingBox.min.x, pColModel->boundingBox.min.y, pColModel->boundingBox.max.z); int16 collisions; CWorld::FindObjectsIntersectingAngledCollisionBox(pColModel->boundingBox, tmp_matrix, pos, - min(cp1.x, min(cp2.x, min(cp3.x, cp4.x))), - min(cp1.y, min(cp2.y, min(cp3.y, cp4.y))), - max(cp1.x, max(cp2.x, max(cp3.x, cp4.x))), - max(cp1.y, max(cp2.y, max(cp3.y, cp4.y))), + Min(cp1.x, Min(cp2.x, Min(cp3.x, cp4.x))), + Min(cp1.y, Min(cp2.y, Min(cp3.y, cp4.y))), + Max(cp1.x, Max(cp2.x, Max(cp3.x, cp4.x))), + Max(cp1.y, Max(cp2.y, Max(cp3.y, cp4.y))), &collisions, 2, nil, false, true, true, false, false); if (collisions > 0) obstacleInPath = true; @@ -6909,11 +6904,11 @@ int8 CRunningScript::ProcessCommands800To899(int32 command) CVector cp3 = tmp_matrix * CVector(pColModel->boundingBox.min.x, pColModel->boundingBox.max.y, pColModel->boundingBox.min.z); CVector cp4 = tmp_matrix * CVector(pColModel->boundingBox.min.x, pColModel->boundingBox.min.y, pColModel->boundingBox.max.z); int16 collisions; - CWorld::FindObjectsIntersectingAngledCollisionBox(pColModel->boundingBox, tmp_matrix, pos, - min(cp1.x, min(cp2.x, min(cp3.x, cp4.x))), - min(cp1.y, min(cp2.y, min(cp3.y, cp4.y))), - max(cp1.x, max(cp2.x, max(cp3.x, cp4.x))), - max(cp1.y, max(cp2.y, max(cp3.y, cp4.y))), + CWorld::FindObjectsIntersectingAngledCollisionBox(pColModel->boundingBox, tmp_matrix, newPosition, + Min(cp1.x, Min(cp2.x, Min(cp3.x, cp4.x))), + Min(cp1.y, Min(cp2.y, Min(cp3.y, cp4.y))), + Max(cp1.x, Max(cp2.x, Max(cp3.x, cp4.x))), + Max(cp1.y, Max(cp2.y, Max(cp3.y, cp4.y))), &collisions, 2, nil, false, true, true, false, false); if (collisions > 0) obstacleInPath = true; @@ -7746,7 +7741,7 @@ int8 CRunningScript::ProcessCommands900To999(int32 command) CVector pos = *(CVector*)&ScriptParams[1]; if (pos.z <= MAP_Z_LOW_LIMIT) pos.z = CWorld::FindGroundZForCoord(pos.x, pos.y); - float size = max(0.0f, *(float*)&ScriptParams[7]); + float size = Max(0.0f, *(float*)&ScriptParams[7]); eParticleObjectType type = (eParticleObjectType)ScriptParams[0]; RwRGBA color; if (type == POBJECT_SMOKE_TRAIL){ @@ -8931,7 +8926,7 @@ int8 CRunningScript::ProcessCommands1000To1099(int32 command) CPed* pPed = CPools::GetPedPool()->GetAt(ScriptParams[0]); assert(pPed); if (ScriptParams[1]) - pPed->m_nZoneLevel = -1; + pPed->m_nZoneLevel = LEVEL_IGNORE; else pPed->m_nZoneLevel = CTheZones::GetLevelFromPosition(pPed->GetPosition()); return 0; @@ -9130,7 +9125,7 @@ int8 CRunningScript::ProcessCommands1100To1199(int32 command) CVehicle* pVehicle = CPools::GetVehiclePool()->GetAt(ScriptParams[0]); assert(pVehicle); if (ScriptParams[1]) - pVehicle->m_nZoneLevel = -1; + pVehicle->m_nZoneLevel = LEVEL_IGNORE; else pVehicle->m_nZoneLevel = CTheZones::GetLevelFromPosition(pVehicle->GetPosition()); return 0; @@ -9147,7 +9142,7 @@ int8 CRunningScript::ProcessCommands1100To1199(int32 command) } case COMMAND_SET_JAMES_CAR_ON_PATH_TO_PLAYER: { - CollectParameters(&m_nIp, 2); + CollectParameters(&m_nIp, 1); CVehicle* pVehicle = CPools::GetVehiclePool()->GetAt(ScriptParams[0]); assert(pVehicle); CCarCtrl::JoinCarWithRoadSystemGotoCoors(pVehicle, FindPlayerCoors(), false); @@ -10076,8 +10071,8 @@ void CRunningScript::LocatePlayerCarCommand(int32 command, uint32* pIp) case COMMAND_LOCATE_PLAYER_ON_FOOT_CAR_3D: result = !pPlayerInfo->m_pPed->bInVehicle; break; - case COMMAND_LOCATE_PLAYER_IN_CAR_CHAR_2D: - case COMMAND_LOCATE_PLAYER_IN_CAR_CHAR_3D: + case COMMAND_LOCATE_PLAYER_IN_CAR_CAR_2D: + case COMMAND_LOCATE_PLAYER_IN_CAR_CAR_3D: result = pPlayerInfo->m_pPed->bInVehicle; break; default: @@ -11359,7 +11354,7 @@ VALIDATESAVEBUF(size) void CTheScripts::ClearSpaceForMissionEntity(const CVector& pos, CEntity* pEntity) { - static CColPoint aTempColPoints[32]; + static CColPoint aTempColPoints[MAX_COLLISION_POINTS]; int16 entities = 0; CEntity* aEntities[16]; CWorld::FindObjectsKindaColliding(pos, pEntity->GetBoundRadius(), false, &entities, 16, aEntities, false, true, true, false, false); @@ -11456,22 +11451,22 @@ void CTheScripts::HighlightImportantAngledArea(uint32 id, float x1, float y1, fl supY = infY = Y; X = (x2 + x3) / 2; Y = (y2 + y3) / 2; - infX = min(infX, X); - supX = max(supX, X); - infY = min(infY, Y); - supY = max(supY, Y); + infX = Min(infX, X); + supX = Max(supX, X); + infY = Min(infY, Y); + supY = Max(supY, Y); X = (x3 + x4) / 2; Y = (y3 + y4) / 2; - infX = min(infX, X); - supX = max(supX, X); - infY = min(infY, Y); - supY = max(supY, Y); + infX = Min(infX, X); + supX = Max(supX, X); + infY = Min(infY, Y); + supY = Max(supY, Y); X = (x4 + x1) / 2; Y = (y4 + y1) / 2; - infX = min(infX, X); - supX = max(supX, X); - infY = min(infY, Y); - supY = max(supY, Y); + infX = Min(infX, X); + supX = Max(supX, X); + infY = Min(infY, Y); + supY = Max(supY, Y); CVector center; center.x = (infX + supX) / 2; center.y = (infY + supY) / 2; @@ -11626,17 +11621,3 @@ void CTheScripts::ReadMultiScriptFileOffsetsFromScript() MultiScriptArray[i] = Read4BytesFromScript(&ip); } } - -STARTPATCHES -InjectHook(0x438790, &CTheScripts::Init, PATCH_JUMP); -InjectHook(0x439040, &CTheScripts::Process, PATCH_JUMP); -InjectHook(0x439400, &CTheScripts::StartTestScript, PATCH_JUMP); -InjectHook(0x439410, &CTheScripts::IsPlayerOnAMission, PATCH_JUMP); -InjectHook(0x44FD10, &CTheScripts::UndoBuildingSwaps, PATCH_JUMP); -InjectHook(0x44FD60, &CTheScripts::UndoEntityInvisibilitySettings, PATCH_JUMP); -InjectHook(0x4534E0, &CTheScripts::ScriptDebugLine3D, PATCH_JUMP); -InjectHook(0x453550, &CTheScripts::RenderTheScriptDebugLines, PATCH_JUMP); -InjectHook(0x4535E0, &CTheScripts::SaveAllScripts, PATCH_JUMP); -InjectHook(0x453B30, &CTheScripts::LoadAllScripts, PATCH_JUMP); -InjectHook(0x454060, &CTheScripts::ClearSpaceForMissionEntity, PATCH_JUMP); -ENDPATCHES diff --git a/src/control/Script.h b/src/control/Script.h index 4338bd18..2eed29fe 100644 --- a/src/control/Script.h +++ b/src/control/Script.h @@ -240,46 +240,46 @@ enum { class CTheScripts { - static uint8(&ScriptSpace)[SIZE_SCRIPT_SPACE]; - static CRunningScript(&ScriptsArray)[MAX_NUM_SCRIPTS]; - static int32(&BaseBriefIdForContact)[MAX_NUM_CONTACTS]; - static int32(&OnAMissionForContactFlag)[MAX_NUM_CONTACTS]; - static intro_text_line(&IntroTextLines)[MAX_NUM_INTRO_TEXT_LINES]; - static intro_script_rectangle(&IntroRectangles)[MAX_NUM_INTRO_RECTANGLES]; - static CSprite2d(&ScriptSprites)[MAX_NUM_SCRIPT_SRPITES]; - static script_sphere_struct(&ScriptSphereArray)[MAX_NUM_SCRIPT_SPHERES]; - static tCollectiveData(&CollectiveArray)[MAX_NUM_COLLECTIVES]; - static tUsedObject(&UsedObjectArray)[MAX_NUM_USED_OBJECTS]; - static int32(&MultiScriptArray)[MAX_NUM_MISSION_SCRIPTS]; - static tBuildingSwap(&BuildingSwapArray)[MAX_NUM_BUILDING_SWAPS]; - static CEntity*(&InvisibilitySettingArray)[MAX_NUM_INVISIBILITY_SETTINGS]; - static CStoredLine(&aStoredLines)[MAX_NUM_STORED_LINES]; - static bool &DbgFlag; - static uint32 &OnAMissionFlag; - static CMissionCleanup &MissionCleanup; - static CStuckCarCheck &StuckCars; - static CUpsideDownCarCheck &UpsideDownCars; - static int32 &StoreVehicleIndex; - static bool &StoreVehicleWasRandom; - static CRunningScript *&pIdleScripts; - static CRunningScript *&pActiveScripts; - static uint32 &NextFreeCollectiveIndex; - static int32 &LastRandomPedId; - static uint16 &NumberOfUsedObjects; - static bool &bAlreadyRunningAMissionScript; - static bool &bUsingAMultiScriptFile; - static uint16 &NumberOfMissionScripts; - static uint32 &LargestMissionScriptSize; - static uint32 &MainScriptSize; - static uint8 &FailCurrentMission; - static uint8 &CountdownToMakePlayerUnsafe; - static uint8 &DelayMakingPlayerUnsafeThisTime; - static uint16 &NumScriptDebugLines; - static uint16 &NumberOfIntroRectanglesThisFrame; - static uint16 &NumberOfIntroTextLinesThisFrame; - static uint8 &UseTextCommands; - static uint16 &CommandsExecuted; - static uint16 &ScriptsUpdated; + static uint8 ScriptSpace[SIZE_SCRIPT_SPACE]; + static CRunningScript ScriptsArray[MAX_NUM_SCRIPTS]; + static int32 BaseBriefIdForContact[MAX_NUM_CONTACTS]; + static int32 OnAMissionForContactFlag[MAX_NUM_CONTACTS]; + static intro_text_line IntroTextLines[MAX_NUM_INTRO_TEXT_LINES]; + static intro_script_rectangle IntroRectangles[MAX_NUM_INTRO_RECTANGLES]; + static CSprite2d ScriptSprites[MAX_NUM_SCRIPT_SRPITES]; + static script_sphere_struct ScriptSphereArray[MAX_NUM_SCRIPT_SPHERES]; + static tCollectiveData CollectiveArray[MAX_NUM_COLLECTIVES]; + static tUsedObject UsedObjectArray[MAX_NUM_USED_OBJECTS]; + static int32 MultiScriptArray[MAX_NUM_MISSION_SCRIPTS]; + static tBuildingSwap BuildingSwapArray[MAX_NUM_BUILDING_SWAPS]; + static CEntity* InvisibilitySettingArray[MAX_NUM_INVISIBILITY_SETTINGS]; + static CStoredLine aStoredLines[MAX_NUM_STORED_LINES]; + static bool DbgFlag; + static uint32 OnAMissionFlag; + static CMissionCleanup MissionCleanup; + static CStuckCarCheck StuckCars; + static CUpsideDownCarCheck UpsideDownCars; + static int32 StoreVehicleIndex; + static bool StoreVehicleWasRandom; + static CRunningScript *pIdleScripts; + static CRunningScript *pActiveScripts; + static uint32 NextFreeCollectiveIndex; + static int32 LastRandomPedId; + static uint16 NumberOfUsedObjects; + static bool bAlreadyRunningAMissionScript; + static bool bUsingAMultiScriptFile; + static uint16 NumberOfMissionScripts; + static uint32 LargestMissionScriptSize; + static uint32 MainScriptSize; + static uint8 FailCurrentMission; + static uint8 CountdownToMakePlayerUnsafe; + static uint8 DelayMakingPlayerUnsafeThisTime; + static uint16 NumScriptDebugLines; + static uint16 NumberOfIntroRectanglesThisFrame; + static uint16 NumberOfIntroTextLinesThisFrame; + static uint8 UseTextCommands; + static uint16 CommandsExecuted; + static uint16 ScriptsUpdated; public: static void Init(); diff --git a/src/control/TrafficLights.cpp b/src/control/TrafficLights.cpp index ab9cd92d..c8d3f79f 100644 --- a/src/control/TrafficLights.cpp +++ b/src/control/TrafficLights.cpp @@ -1,19 +1,19 @@ #include "common.h" -#include "patcher.h" -#include "General.h" + #include "Camera.h" -#include "World.h" -#include "PathFind.h" -#include "Timer.h" #include "Clock.h" -#include "Weather.h" -#include "Timecycle.h" -#include "Pointlights.h" -#include "Shadows.h" #include "Coronas.h" +#include "General.h" +#include "PathFind.h" +#include "PointLights.h" +#include "Shadows.h" #include "SpecialFX.h" -#include "Vehicle.h" +#include "Timecycle.h" +#include "Timer.h" #include "TrafficLights.h" +#include "Vehicle.h" +#include "Weather.h" +#include "World.h" // TODO: figure out the meaning of this enum { SOME_FLAG = 0x80 }; @@ -39,10 +39,10 @@ CTrafficLights::DisplayActualLight(CEntity *ent) float zMax = mi->Get2dEffect(0)->pos.z; for(i = 1; i < 6; i++){ assert(mi->Get2dEffect(i)); - yMin = min(yMin, mi->Get2dEffect(i)->pos.y); - yMax = max(yMax, mi->Get2dEffect(i)->pos.y); - zMin = min(zMin, mi->Get2dEffect(i)->pos.z); - zMax = max(zMax, mi->Get2dEffect(i)->pos.z); + yMin = Min(yMin, mi->Get2dEffect(i)->pos.y); + yMax = Max(yMax, mi->Get2dEffect(i)->pos.y); + zMin = Min(zMin, mi->Get2dEffect(i)->pos.z); + zMax = Max(zMax, mi->Get2dEffect(i)->pos.z); } CVector pos1, pos2; @@ -327,9 +327,3 @@ CTrafficLights::LightForCars2(void) else return CAR_LIGHTS_RED; } - -STARTPATCHES - InjectHook(0x455760, &CTrafficLights::LightForCars1, PATCH_JUMP); - InjectHook(0x455790, &CTrafficLights::LightForCars2, PATCH_JUMP); - InjectHook(0x4557D0, &CTrafficLights::LightForPeds, PATCH_JUMP); -ENDPATCHES |