summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--src/control/AccidentManager.cpp59
-rw-r--r--src/control/CarAI.cpp2
-rw-r--r--src/control/CarCtrl.cpp2
-rw-r--r--src/core/Accident.cpp134
-rw-r--r--src/core/Accident.h (renamed from src/control/AccidentManager.h)7
-rw-r--r--src/core/Frontend.cpp2
-rw-r--r--src/core/Game.cpp2
-rw-r--r--src/core/Timer.cpp22
-rw-r--r--src/peds/EmergencyPed.cpp2
-rw-r--r--src/peds/PlayerPed.cpp8
-rw-r--r--src/peds/PlayerPed.h2
12 files changed, 160 insertions, 83 deletions
diff --git a/README.md b/README.md
index b8e7a6e4..b03c3ce2 100644
--- a/README.md
+++ b/README.md
@@ -39,7 +39,6 @@ to reverse at the time, calling the original functions is acceptable.
### Unreversed / incomplete classes (at least the ones we know)
```
CAudioManager, cDMAudio, cSampleManager and all audio - being worked on
-CAccidentManager
CBoat
CBrightLights
CBulletInfo
diff --git a/src/control/AccidentManager.cpp b/src/control/AccidentManager.cpp
deleted file mode 100644
index a42280b7..00000000
--- a/src/control/AccidentManager.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-#include "common.h"
-#include "patcher.h"
-#include "AccidentManager.h"
-
-#include "Ped.h"
-
-CAccidentManager& gAccidentManager = *(CAccidentManager*)0x87FD10;
-
-WRAPPER void CAccidentManager::Update(void) { EAXJMP(0x456710); }
-
-uint16
-CAccidentManager::CountActiveAccidents()
-{
- uint16 accidents = 0;
- for (int i = 0; i < NUM_ACCIDENTS; i++){
- if (m_aAccidents[i].m_pVictim)
- accidents++;
- }
- return accidents;
-}
-
-CAccident*
-CAccidentManager::FindNearestAccident(CVector vecPos, float* pDistance)
-{
- for (int i = 0; i < MAX_MEDICS_TO_ATTEND_ACCIDENT; i++){
- int accidentId = -1;
- float minDistance = 999999;
- for (int j = 0; j < NUM_ACCIDENTS; j++){
- CPed* pVictim = m_aAccidents[j].m_pVictim;
- if (!pVictim)
- continue;
- if (pVictim->CharCreatedBy == MISSION_CHAR)
- continue;
- if (pVictim->m_fHealth != 0.0f)
- continue;
- if (m_aAccidents[j].m_nMedicsPerformingCPR != i)
- continue;
- float distance = (pVictim->GetPosition() - vecPos).Magnitude2D();
- if (distance / 2 > pVictim->GetPosition().z - vecPos.z && distance < minDistance){
- minDistance = distance;
- accidentId = j;
- }
- }
- *pDistance = minDistance;
- if (accidentId != -1)
- return &m_aAccidents[accidentId];
- }
- return nil;
-}
-
-bool
-CAccidentManager::UnattendedAccidents(void)
-{
- for (int i = 0; i < NUM_ACCIDENTS; i++) {
- if (m_aAccidents[i].m_pVictim && m_aAccidents[i].m_nMedicsAttending == 0)
- return true;
- }
- return false;
-} \ No newline at end of file
diff --git a/src/control/CarAI.cpp b/src/control/CarAI.cpp
index b4dd8777..6032c51f 100644
--- a/src/control/CarAI.cpp
+++ b/src/control/CarAI.cpp
@@ -2,7 +2,7 @@
#include "patcher.h"
#include "CarAI.h"
-#include "AccidentManager.h"
+#include "Accident.h"
#include "AutoPilot.h"
#include "CarCtrl.h"
#include "General.h"
diff --git a/src/control/CarCtrl.cpp b/src/control/CarCtrl.cpp
index 80cb8211..cd657815 100644
--- a/src/control/CarCtrl.cpp
+++ b/src/control/CarCtrl.cpp
@@ -2,7 +2,7 @@
#include "patcher.h"
#include "CarCtrl.h"
-#include "AccidentManager.h"
+#include "Accident.h"
#include "Automobile.h"
#include "Camera.h"
#include "CarAI.h"
diff --git a/src/core/Accident.cpp b/src/core/Accident.cpp
new file mode 100644
index 00000000..d8313ddc
--- /dev/null
+++ b/src/core/Accident.cpp
@@ -0,0 +1,134 @@
+#include "common.h"
+#include "patcher.h"
+#include "Accident.h"
+
+#include "Ped.h"
+#include "Pools.h"
+#include "World.h"
+
+CAccidentManager& gAccidentManager = *(CAccidentManager*)0x87FD10;
+
+CAccident*
+CAccidentManager::GetNextFreeAccident()
+{
+ for (int i = 0; i < NUM_ACCIDENTS; i++) {
+ if (m_aAccidents[i].m_pVictim == nil)
+ return &m_aAccidents[i];
+ }
+
+ return nil;
+}
+
+void
+CAccidentManager::ReportAccident(CPed *ped)
+{
+ if (!ped->IsPlayer() && ped->CharCreatedBy != MISSION_CHAR && !ped->bRenderScorched && !ped->bBodyPartJustCameOff && ped->bAllowMedicsToReviveMe && !ped->bIsInWater) {
+ for (int i = 0; i < NUM_ACCIDENTS; i++) {
+ if (m_aAccidents[i].m_pVictim != nil && m_aAccidents[i].m_pVictim == ped)
+ return;
+ }
+
+ if (ped->m_pCurrentPhysSurface == nil) {
+ CVector point = ped->GetPosition();
+ point.z -= 2.0f;
+
+ CColPoint colPoint;
+ CEntity *pEntity;
+
+ if (!CWorld::ProcessVerticalLine(point, -100.0f, colPoint, pEntity, true, false, false, false, false, false, nil)) {
+ CAccident *accident = GetNextFreeAccident();
+ if (accident != nil) {
+ accident->m_pVictim = ped;
+ ped->RegisterReference((CEntity**)&accident->m_pVictim);
+ accident->m_nMedicsPerformingCPR = 0;
+ accident->m_nMedicsAttending = 0;
+ ped->m_lastAccident = accident;
+ WorkToDoForMedics();
+ }
+ }
+ }
+ }
+}
+
+void
+CAccidentManager::Update()
+{
+ int32 e;
+ if (CEventList::GetEvent(EVENT_INJURED_PED, &e)) {
+ CPed *ped = CPools::GetPed(gaEvent[e].entityRef);
+ if (ped) {
+ ReportAccident(ped);
+ CEventList::ClearEvent(e);
+ }
+ }
+}
+
+CAccident*
+CAccidentManager::FindNearestAccident(CVector vecPos, float *pDistance)
+{
+ for (int i = 0; i < MAX_MEDICS_TO_ATTEND_ACCIDENT; i++){
+ int accidentId = -1;
+ float minDistance = 999999;
+ for (int j = 0; j < NUM_ACCIDENTS; j++){
+ CPed* pVictim = m_aAccidents[j].m_pVictim;
+ if (!pVictim)
+ continue;
+ if (pVictim->CharCreatedBy == MISSION_CHAR)
+ continue;
+ if (pVictim->m_fHealth != 0.0f)
+ continue;
+ if (m_aAccidents[j].m_nMedicsPerformingCPR != i)
+ continue;
+ float distance = (pVictim->GetPosition() - vecPos).Magnitude2D();
+ if (distance / 2 > pVictim->GetPosition().z - vecPos.z && distance < minDistance){
+ minDistance = distance;
+ accidentId = j;
+ }
+ }
+ *pDistance = minDistance;
+ if (accidentId != -1)
+ return &m_aAccidents[accidentId];
+ }
+ return nil;
+}
+
+uint16
+CAccidentManager::CountActiveAccidents()
+{
+ uint16 accidents = 0;
+ for (int i = 0; i < NUM_ACCIDENTS; i++) {
+ if (m_aAccidents[i].m_pVictim)
+ accidents++;
+ }
+ return accidents;
+}
+
+bool
+CAccidentManager::WorkToDoForMedics()
+{
+ for (int i = 0; i < NUM_ACCIDENTS; i++) {
+ if (m_aAccidents[i].m_pVictim != nil && m_aAccidents[i].m_nMedicsAttending < MAX_MEDICS_TO_ATTEND_ACCIDENT)
+ return true;
+ }
+ return false;
+}
+
+bool
+CAccidentManager::UnattendedAccidents()
+{
+ for (int i = 0; i < NUM_ACCIDENTS; i++) {
+ if (m_aAccidents[i].m_pVictim != nil && m_aAccidents[i].m_nMedicsAttending == 0)
+ return true;
+ }
+ return false;
+}
+
+STARTPATCHES
+ InjectHook(0x4565A0, &CAccidentManager::GetNextFreeAccident, PATCH_JUMP);
+ InjectHook(0x4565D0, &CAccidentManager::ReportAccident, PATCH_JUMP);
+ InjectHook(0x456710, &CAccidentManager::Update, PATCH_JUMP);
+ InjectHook(0x456760, &CAccidentManager::FindNearestAccident, PATCH_JUMP);
+ InjectHook(0x456880, &CAccidentManager::CountActiveAccidents, PATCH_JUMP);
+ InjectHook(0x4568A0, &CAccidentManager::WorkToDoForMedics, PATCH_JUMP);
+ InjectHook(0x4568D0, &CAccidentManager::UnattendedAccidents, PATCH_JUMP);
+ENDPATCHES
diff --git a/src/control/AccidentManager.h b/src/core/Accident.h
index 6a3088e7..69889645 100644
--- a/src/control/AccidentManager.h
+++ b/src/core/Accident.h
@@ -20,10 +20,13 @@ class CAccidentManager
MAX_MEDICS_TO_ATTEND_ACCIDENT = 2
};
public:
+ CAccident *GetNextFreeAccident();
+ void ReportAccident(CPed *ped);
+ void Update();
+ CAccident *FindNearestAccident(CVector vecPos, float *pDistance);
uint16 CountActiveAccidents();
bool UnattendedAccidents();
- CAccident* FindNearestAccident(CVector, float*);
- void Update(void);
+ bool WorkToDoForMedics();
};
extern CAccidentManager& gAccidentManager; \ No newline at end of file
diff --git a/src/core/Frontend.cpp b/src/core/Frontend.cpp
index 24cdad8e..38f6aff8 100644
--- a/src/core/Frontend.cpp
+++ b/src/core/Frontend.cpp
@@ -812,7 +812,7 @@ void CMenuManager::Draw()
textToPrint[MENUCOLUMN_RIGHT] = TheText.Get(m_PrefsDMA ? "FEM_ON" : "FEM_OFF");
break;
case MENUACTION_MOUSESTEER:
- textToPrint[MENUCOLUMN_RIGHT] = TheText.Get(m_bDisableMouseSteering ? "FEM_ON" : "FEM_OFF");
+ textToPrint[MENUCOLUMN_RIGHT] = TheText.Get(m_bDisableMouseSteering ? "FEM_OFF" : "FEM_ON");
break;
}
diff --git a/src/core/Game.cpp b/src/core/Game.cpp
index b2bac8dd..08751cf9 100644
--- a/src/core/Game.cpp
+++ b/src/core/Game.cpp
@@ -2,7 +2,7 @@
#include "patcher.h"
#include "Game.h"
#include "main.h"
-#include "AccidentManager.h"
+#include "Accident.h"
#include "Antennas.h"
#include "Bridge.h"
#include "Camera.h"
diff --git a/src/core/Timer.cpp b/src/core/Timer.cpp
index 543f582b..8695f64b 100644
--- a/src/core/Timer.cpp
+++ b/src/core/Timer.cpp
@@ -75,7 +75,7 @@ void CTimer::Shutdown(void)
;
}
-#if 1
+#if 0
WRAPPER void CTimer::Update(void) { EAXJMP(0x4ACF70); }
#else
void CTimer::Update(void)
@@ -87,22 +87,22 @@ void CTimer::Update(void)
LARGE_INTEGER pc;
QueryPerformanceCounter(&pc);
- int32 updInCycles = (pc.LowPart - _oldPerfCounter.LowPart) & 0x7FFFFFFF;
+ int32 updInCycles = (pc.LowPart - _oldPerfCounter.LowPart); // & 0x7FFFFFFF; pointless
_oldPerfCounter = pc;
- double updInCyclesScaled = (double)updInCycles * ms_fTimeScale;
+ float updInCyclesScaled = updInCycles * ms_fTimeScale;
double upd = updInCyclesScaled / (double)_nCyclesPerMS;
- m_snTimeInMillisecondsPauseMode = (Int64)(m_snTimeInMillisecondsPauseMode + upd);
+ m_snTimeInMillisecondsPauseMode = m_snTimeInMillisecondsPauseMode + upd;
if ( GetIsPaused() )
ms_fTimeStep = 0.0f;
else
{
- m_snTimeInMilliseconds = (Int64)(m_snTimeInMilliseconds + upd);
- m_snTimeInMillisecondsNonClipped = (Int64)(m_snTimeInMillisecondsNonClipped + upd);
+ m_snTimeInMilliseconds = m_snTimeInMilliseconds + upd;
+ m_snTimeInMillisecondsNonClipped = m_snTimeInMillisecondsNonClipped + upd;
ms_fTimeStep = updInCyclesScaled / (double)_nCyclesPerMS / 20.0;
}
}
@@ -116,14 +116,14 @@ void CTimer::Update(void)
oldPcTimer = timer;
- m_snTimeInMillisecondsPauseMode = (Int64)(m_snTimeInMillisecondsPauseMode + upd);
+ m_snTimeInMillisecondsPauseMode = m_snTimeInMillisecondsPauseMode + upd;
if ( GetIsPaused() )
ms_fTimeStep = 0.0f;
else
{
- m_snTimeInMilliseconds = (Int64)(m_snTimeInMilliseconds + upd);
- m_snTimeInMillisecondsNonClipped = (Int64)(m_snTimeInMillisecondsNonClipped + upd);
+ m_snTimeInMilliseconds = m_snTimeInMilliseconds + upd;
+ m_snTimeInMillisecondsNonClipped = m_snTimeInMillisecondsNonClipped + upd;
ms_fTimeStep = upd / 1000.0f * 50.0f;
}
}
@@ -192,7 +192,7 @@ uint32 CTimer::GetCurrentTimeInCycles(void)
{
LARGE_INTEGER pc;
QueryPerformanceCounter(&pc);
- return (pc.LowPart - _oldPerfCounter.LowPart) & 0x7FFFFFFF;
+ return (pc.LowPart - _oldPerfCounter.LowPart); // & 0x7FFFFFFF; pointless
}
else
return RsTimer() - oldPcTimer;
@@ -218,7 +218,7 @@ void CTimer::EndUserPause(void)
m_UserPause = false;
}
-#if 0
+#if 1
STARTPATCHES
InjectHook(0x4ACE60, CTimer::Initialise, PATCH_JUMP);
InjectHook(0x4ACF60, CTimer::Shutdown, PATCH_JUMP);
diff --git a/src/peds/EmergencyPed.cpp b/src/peds/EmergencyPed.cpp
index 16468270..cdcbf084 100644
--- a/src/peds/EmergencyPed.cpp
+++ b/src/peds/EmergencyPed.cpp
@@ -6,7 +6,7 @@
#include "Fire.h"
#include "General.h"
#include "CarCtrl.h"
-#include "AccidentManager.h"
+#include "Accident.h"
CEmergencyPed::CEmergencyPed(uint32 type) : CPed(type)
{
diff --git a/src/peds/PlayerPed.cpp b/src/peds/PlayerPed.cpp
index df234bfb..8892fc2a 100644
--- a/src/peds/PlayerPed.cpp
+++ b/src/peds/PlayerPed.cpp
@@ -573,8 +573,6 @@ CPlayerPed::ProcessWeaponSwitch(CPad *padUsed)
if (CDarkel::FrenzyOnGoing())
goto switchDetectDone;
- // The fact that m_nSelectedWepSlot is int8 makes below loops circular loop.
-
if (padUsed->CycleWeaponRightJustDown() && !m_pPointGunAt) {
if (TheCamera.PlayerWeaponMode.Mode != CCam::MODE_M16_1STPERSON
@@ -596,12 +594,14 @@ CPlayerPed::ProcessWeaponSwitch(CPad *padUsed)
&& TheCamera.PlayerWeaponMode.Mode != CCam::MODE_SNIPER
&& TheCamera.PlayerWeaponMode.Mode != CCam::MODE_ROCKETLAUNCHER) {
- for (m_nSelectedWepSlot = m_currentWeapon - 1; m_nSelectedWepSlot >= 0; --m_nSelectedWepSlot) {
+ for (m_nSelectedWepSlot = m_currentWeapon - 1; ; --m_nSelectedWepSlot) {
+ if (m_nSelectedWepSlot < WEAPONTYPE_UNARMED)
+ m_nSelectedWepSlot = WEAPONTYPE_DETONATOR;
+
if (HasWeapon(m_nSelectedWepSlot) && GetWeapon(m_nSelectedWepSlot).HasWeaponAmmoToBeUsed()) {
goto switchDetectDone;
}
}
- m_nSelectedWepSlot = WEAPONTYPE_DETONATOR;
}
} else if (CWeaponInfo::GetWeaponInfo((eWeaponType)m_currentWeapon)->m_eWeaponFire != WEAPON_FIRE_MELEE) {
if (GetWeapon(m_currentWeapon).m_nAmmoTotal <= 0) {
diff --git a/src/peds/PlayerPed.h b/src/peds/PlayerPed.h
index 5725a8ee..81d996be 100644
--- a/src/peds/PlayerPed.h
+++ b/src/peds/PlayerPed.h
@@ -13,7 +13,7 @@ public:
float m_fCurrentStamina;
float m_fMaxStamina;
float m_fStaminaProgress;
- uint8 m_nSelectedWepSlot; // eWeaponType
+ int8 m_nSelectedWepSlot; // eWeaponType
bool m_bSpeedTimerFlag;
bool m_bShouldEvade;
int8 field_1367;