summaryrefslogtreecommitdiffstats
path: root/src/core/re3.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/re3.cpp')
-rw-r--r--src/core/re3.cpp90
1 files changed, 83 insertions, 7 deletions
diff --git a/src/core/re3.cpp b/src/core/re3.cpp
index 6f0a4682..137a890c 100644
--- a/src/core/re3.cpp
+++ b/src/core/re3.cpp
@@ -20,12 +20,64 @@
#include "debugmenu_public.h"
#include "Particle.h"
#include "Console.h"
+#include "Debug.h"
+#include <algorithm>
#include <vector>
#include <list>
std::vector<int32> usedAddresses;
+static DWORD protect[2];
+static uint32 protect_address;
+static uint32 protect_size;
+
+void
+Protect_internal(uint32 address, uint32 size)
+{
+ protect_address = address;
+ protect_size = size;
+ VirtualProtect((void*)address, size, PAGE_EXECUTE_READWRITE, &protect[0]);
+}
+
+void
+Unprotect_internal(void)
+{
+ VirtualProtect((void*)protect_address, protect_size, protect[0], &protect[1]);
+}
+
+void
+InjectHook_internal(uint32 address, uint32 hook, int type)
+{
+ if(std::any_of(usedAddresses.begin(), usedAddresses.end(),
+ [address](uint32 value) { return (int32)value == address; })) {
+ debug("Used address %#06x twice when injecting hook\n", address);
+ }
+
+ usedAddresses.push_back((int32)address);
+
+
+ switch(type){
+ case PATCH_JUMP:
+ VirtualProtect((void*)address, 5, PAGE_EXECUTE_READWRITE, &protect[0]);
+ *(uint8*)address = 0xE9;
+ break;
+ case PATCH_CALL:
+ VirtualProtect((void*)address, 5, PAGE_EXECUTE_READWRITE, &protect[0]);
+ *(uint8*)address = 0xE8;
+ break;
+ default:
+ VirtualProtect((void*)((uint32)address + 1), 4, PAGE_EXECUTE_READWRITE, &protect[0]);
+ break;
+ }
+
+ *(ptrdiff_t*)(address + 1) = hook - address - 5;
+ if(type == PATCH_NOTHING)
+ VirtualProtect((void*)(address + 1), 4, protect[0], &protect[1]);
+ else
+ VirtualProtect((void*)address, 5, protect[0], &protect[1]);
+}
+
void **rwengine = *(void***)0x5A10E1;
DebugMenuAPI gDebugMenuAPI;
@@ -114,13 +166,16 @@ SpawnCar(int id)
CStreaming::LoadAllRequestedModels(false);
if(CStreaming::HasModelLoaded(id)){
playerpos = FindPlayerCoors();
- int node = ThePaths.FindNodeClosestToCoors(playerpos, 0, 100.0f, false, false);
- if(node < 0)
- return;
+ int node;
+ if(!CModelInfo::IsBoatModel(id)){
+ node = ThePaths.FindNodeClosestToCoors(playerpos, 0, 100.0f, false, false);
+ if(node < 0)
+ return;
+ }
CVehicle *v;
if(CModelInfo::IsBoatModel(id))
- return;
+ v = new CBoat(id, RANDOM_VEHICLE);
else
v = new CAutomobile(id, RANDOM_VEHICLE);
@@ -130,7 +185,11 @@ SpawnCar(int id)
if(carCol2)
DebugMenuEntrySetAddress(carCol2, &v->m_currentColour2);
- v->GetPosition() = ThePaths.m_pathNodes[node].pos;
+ if(CModelInfo::IsBoatModel(id))
+ v->GetPosition() = TheCamera.GetPosition() + TheCamera.GetForward()*15.0f;
+ else
+ v->GetPosition() = ThePaths.m_pathNodes[node].pos;
+
v->GetPosition().z += 4.0f;
v->SetOrientation(0.0f, 0.0f, 3.49f);
v->m_status = STATUS_ABANDONED;
@@ -197,6 +256,12 @@ PlaceOnRoad(void)
((CAutomobile*)veh)->PlaceOnRoadProperly();
}
+static void
+ResetCamStatics(void)
+{
+ TheCamera.Cams[TheCamera.ActiveCam].ResetStatics = true;
+}
+
static const char *carnames[] = {
"landstal", "idaho", "stinger", "linerun", "peren", "sentinel", "patriot", "firetruk", "trash", "stretch", "manana", "infernus", "blista", "pony",
"mule", "cheetah", "ambulan", "fbicar", "moonbeam", "esperant", "taxi", "kuruma", "bobcat", "mrwhoop", "bfinject", "corpse", "police", "enforcer",
@@ -358,7 +423,17 @@ DebugMenuPopulate(void)
DebugMenuAddCmd("Debug", "Start Credits", CCredits::Start);
DebugMenuAddCmd("Debug", "Stop Credits", CCredits::Stop);
-
+
+ extern bool PrintDebugCode;
+ extern int16 &DebugCamMode;
+ DebugMenuAddVarBool8("Cam", "Print Debug Code", (int8*)&PrintDebugCode, nil);
+ DebugMenuAddVar("Cam", "Cam Mode", &DebugCamMode, nil, 1, 0, CCam::MODE_EDITOR, nil);
+ DebugMenuAddCmd("Cam", "Normal", []() { DebugCamMode = 0; });
+ DebugMenuAddCmd("Cam", "Follow Ped With Bind", []() { DebugCamMode = CCam::MODE_FOLLOW_PED_WITH_BIND; });
+ DebugMenuAddCmd("Cam", "Reaction", []() { DebugCamMode = CCam::MODE_REACTION; });
+ DebugMenuAddCmd("Cam", "Chris", []() { DebugCamMode = CCam::MODE_CHRIS; });
+ DebugMenuAddCmd("Cam", "Reset Statics", ResetCamStatics);
+
CTweakVars::AddDBG("Debug");
}
}
@@ -433,7 +508,8 @@ void re3_debug(const char *format, ...)
vsprintf_s(re3_buff, re3_buffsize, format, va);
va_end(va);
- printf("%s", re3_buff);
+// printf("%s", re3_buff);
+ CDebug::DebugAddText(re3_buff);
}
void re3_trace(const char *filename, unsigned int lineno, const char *func, const char *format, ...)