summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/control/Script.cpp267
-rw-r--r--src/control/Script.h8
-rw-r--r--src/render/Shadows.cpp1
-rw-r--r--src/render/Shadows.h1
4 files changed, 270 insertions, 7 deletions
diff --git a/src/control/Script.cpp b/src/control/Script.cpp
index b8add76a..ba34c3e1 100644
--- a/src/control/Script.cpp
+++ b/src/control/Script.cpp
@@ -11212,11 +11212,264 @@ void CTheScripts::RenderTheScriptDebugLines()
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)0);
}
-WRAPPER void CTheScripts::SaveAllScripts(uint8*, uint32*) { EAXJMP(0x4535E0); }
-WRAPPER void CTheScripts::LoadAllScripts(uint8*, uint32) { EAXJMP(0x453B30); }
-WRAPPER void CTheScripts::ClearSpaceForMissionEntity(const CVector&, CEntity*) { EAXJMP(0x454060); }
-WRAPPER void CTheScripts::HighlightImportantArea(uint32, float, float, float, float, float) { EAXJMP(0x454320); }
-WRAPPER void CTheScripts::HighlightImportantAngledArea(uint32, float, float, float, float, float, float, float, float, float) { EAXJMP(0x454430); }
+#define SCRIPT_DATA_SIZE sizeof(CTheScripts::OnAMissionFlag) + sizeof(CTheScripts::BaseBriefIdForContact) + sizeof(CTheScripts::OnAMissionForContactFlag) +\
+ sizeof(CTheScripts::CollectiveArray) + 4 * sizeof(uint32) * MAX_NUM_BUILDING_SWAPS + 2 * sizeof(uint32) * MAX_NUM_INVISIBILITY_SETTINGS + 5 * sizeof(uint32)
+
+void CTheScripts::SaveAllScripts(uint8* buf, uint32* size)
+{
+INITSAVEBUF
+ uint32 varSpace = GetSizeOfVariableSpace();
+ uint32 runningScripts = 0;
+ for (CRunningScript* pScript = pActiveScripts; pScript; pScript = pScript->GetNext())
+ runningScripts++;
+ *size = sizeof(CRunningScript) * runningScripts + varSpace + SCRIPT_DATA_SIZE + SAVE_HEADER_SIZE + 3 * sizeof(uint32);
+ WriteSaveHeader(buf, 'S', 'C', 'R', '\0', *size - SAVE_HEADER_SIZE);
+ WriteSaveBuf(buf, varSpace);
+ for (uint32 i = 0; i < varSpace; i++)
+ WriteSaveBuf(buf, ScriptSpace[i]);
+ static_assert(SCRIPT_DATA_SIZE == 968, "CTheScripts::SaveAllScripts");
+ uint32 script_data_size = SCRIPT_DATA_SIZE;
+ WriteSaveBuf(buf, script_data_size);
+ WriteSaveBuf(buf, OnAMissionFlag);
+ for (uint32 i = 0; i < MAX_NUM_CONTACTS; i++) {
+ WriteSaveBuf(buf, OnAMissionForContactFlag[i]);
+ WriteSaveBuf(buf, BaseBriefIdForContact[i]);
+ }
+ for (uint32 i = 0; i < MAX_NUM_COLLECTIVES; i++)
+ WriteSaveBuf(buf, CollectiveArray[i]);
+ WriteSaveBuf(buf, NextFreeCollectiveIndex);
+ for (uint32 i = 0; i < MAX_NUM_BUILDING_SWAPS; i++) {
+ CBuilding* pBuilding = BuildingSwapArray[i].m_pBuilding;
+ uint32 type, handle;
+ if (!pBuilding) {
+ type = 0;
+ handle = 0;
+ } else if (pBuilding->GetIsATreadable()) {
+ type = 1;
+ handle = CPools::GetTreadablePool()->GetJustIndex((CTreadable*)pBuilding) + 1;
+ } else {
+ type = 2;
+ handle = CPools::GetBuildingPool()->GetJustIndex(pBuilding) + 1;
+ }
+ WriteSaveBuf(buf, type);
+ WriteSaveBuf(buf, handle);
+ WriteSaveBuf(buf, BuildingSwapArray[i].m_nNewModel);
+ WriteSaveBuf(buf, BuildingSwapArray[i].m_nOldModel);
+ }
+ for (uint32 i = 0; i < MAX_NUM_INVISIBILITY_SETTINGS; i++) {
+ CEntity* pEntity = InvisibilitySettingArray[i];
+ uint32 type, handle;
+ if (!pEntity) {
+ type = 0;
+ handle = 0;
+ } else {
+ switch (pEntity->m_type) {
+ case ENTITY_TYPE_BUILDING:
+ if (((CBuilding*)pEntity)->GetIsATreadable()) {
+ type = 1;
+ handle = CPools::GetTreadablePool()->GetJustIndex((CTreadable*)pEntity) + 1;
+ } else {
+ type = 2;
+ handle = CPools::GetBuildingPool()->GetJustIndex((CBuilding*)pEntity) + 1;
+ }
+ break;
+ case ENTITY_TYPE_OBJECT:
+ type = 3;
+ handle = CPools::GetObjectPool()->GetJustIndex((CObject*)pEntity) + 1;
+ break;
+ case ENTITY_TYPE_DUMMY:
+ type = 4;
+ handle = CPools::GetDummyPool()->GetJustIndex((CDummy*)pEntity) + 1;
+ }
+ }
+ WriteSaveBuf(buf, type);
+ WriteSaveBuf(buf, handle);
+ }
+ WriteSaveBuf(buf, bUsingAMultiScriptFile);
+ WriteSaveBuf(buf, (uint8)0);
+ WriteSaveBuf(buf, (uint16)0);
+ WriteSaveBuf(buf, MainScriptSize);
+ WriteSaveBuf(buf, LargestMissionScriptSize);
+ WriteSaveBuf(buf, NumberOfMissionScripts);
+ WriteSaveBuf(buf, (uint16)0);
+ WriteSaveBuf(buf, runningScripts);
+ for (CRunningScript* pScript = pActiveScripts; pScript; pScript = pScript->GetNext())
+ WriteSaveBuf(buf, *pScript);
+VALIDATESAVEBUF(*size)
+}
+
+void CTheScripts::LoadAllScripts(uint8* buf, uint32 size)
+{
+ Init();
+INITSAVEBUF
+ CheckSaveHeader(buf, 'S', 'C', 'R', '\0', size - SAVE_HEADER_SIZE);
+ uint32 varSpace = ReadSaveBuf<uint32>(buf);
+ for (uint32 i = 0; i < varSpace; i++)
+ ScriptSpace[i] = ReadSaveBuf<uint8>(buf);
+ assert(ReadSaveBuf<uint32>(buf) == SCRIPT_DATA_SIZE);
+ OnAMissionFlag = ReadSaveBuf<uint32>(buf);
+ for (uint32 i = 0; i < MAX_NUM_CONTACTS; i++) {
+ OnAMissionForContactFlag[i] = ReadSaveBuf<uint32>(buf);
+ BaseBriefIdForContact[i] = ReadSaveBuf<uint32>(buf);
+ }
+ for (uint32 i = 0; i < MAX_NUM_COLLECTIVES; i++)
+ CollectiveArray[i] = ReadSaveBuf<tCollectiveData>(buf);
+ NextFreeCollectiveIndex = ReadSaveBuf<uint32>(buf);
+ for (uint32 i = 0; i < MAX_NUM_BUILDING_SWAPS; i++) {
+ uint32 type = ReadSaveBuf<uint32>(buf);
+ uint32 handle = ReadSaveBuf<uint32>(buf);
+ switch (type) {
+ case 0:
+ BuildingSwapArray[i].m_pBuilding = nil;
+ break;
+ case 1:
+ BuildingSwapArray[i].m_pBuilding = CPools::GetTreadablePool()->GetSlot(handle - 1);
+ break;
+ case 2:
+ BuildingSwapArray[i].m_pBuilding = CPools::GetBuildingPool()->GetSlot(handle - 1);
+ break;
+ default:
+ assert(false);
+ }
+ BuildingSwapArray[i].m_nNewModel = ReadSaveBuf<uint32>(buf);
+ BuildingSwapArray[i].m_nOldModel = ReadSaveBuf<uint32>(buf);
+ if (BuildingSwapArray[i].m_pBuilding)
+ BuildingSwapArray[i].m_pBuilding->ReplaceWithNewModel(BuildingSwapArray[i].m_nNewModel);
+ }
+ for (uint32 i = 0; i < MAX_NUM_INVISIBILITY_SETTINGS; i++) {
+ uint32 type = ReadSaveBuf<uint32>(buf);
+ uint32 handle = ReadSaveBuf<uint32>(buf);
+ switch (type) {
+ case 0:
+ InvisibilitySettingArray[i] = nil;
+ break;
+ case 1:
+ InvisibilitySettingArray[i] = CPools::GetTreadablePool()->GetSlot(handle - 1);
+ break;
+ case 2:
+ InvisibilitySettingArray[i] = CPools::GetBuildingPool()->GetSlot(handle - 1);
+ break;
+ case 3:
+ InvisibilitySettingArray[i] = CPools::GetObjectPool()->GetSlot(handle - 1);
+ break;
+ case 4:
+ InvisibilitySettingArray[i] = CPools::GetDummyPool()->GetSlot(handle - 1);
+ default:
+ assert(false);
+ }
+ if (InvisibilitySettingArray[i])
+ InvisibilitySettingArray[i]->bIsVisible = false;
+ }
+ assert(ReadSaveBuf<bool>(buf) == bUsingAMultiScriptFile);
+ ReadSaveBuf<uint8>(buf);
+ ReadSaveBuf<uint16>(buf);
+ assert(ReadSaveBuf<uint32>(buf) == MainScriptSize);
+ assert(ReadSaveBuf<uint32>(buf) == LargestMissionScriptSize);
+ assert(ReadSaveBuf<uint16>(buf) == NumberOfMissionScripts);
+ ReadSaveBuf<uint16>(buf);
+ uint32 runningScripts = ReadSaveBuf<uint32>(buf);
+ for (uint32 i = 0; i < runningScripts; i++)
+ StartNewScript(0)->BuildFromSaved(ReadSaveBuf<CRunningScript>(buf));
+VALIDATESAVEBUF(size)
+}
+
+#undef SCRIPT_DATA_SIZE
+
+void CTheScripts::ClearSpaceForMissionEntity(const CVector& pos, CEntity* pEntity)
+{
+ static CColPoint aTempColPoints[32];
+ int16 entities = 0;
+ CEntity* aEntities[16];
+ CWorld::FindObjectsKindaColliding(pos, pEntity->GetBoundRadius(), false, &entities, 16, aEntities, false, true, true, false, false);
+ if (entities <= 0)
+ return;
+ for (uint16 i = 0; i < entities; i++) {
+ if (aEntities[i] != pEntity && aEntities[i]->IsPed() && ((CPed*)aEntities[i])->bInVehicle)
+ aEntities[i] = nil;
+ }
+ for (uint16 i = 0; i < entities; i++) {
+ if (aEntities[i] == pEntity || !aEntities[i])
+ continue;
+ CEntity* pFound = aEntities[i];
+ int cols;
+ if (CModelInfo::GetModelInfo(pEntity->GetModelIndex())->GetColModel()->numLines <= 0)
+ cols = CCollision::ProcessColModels(pEntity->GetMatrix(), *CModelInfo::GetModelInfo(pEntity->GetModelIndex())->GetColModel(),
+ pFound->GetMatrix(), *CModelInfo::GetModelInfo(pFound->GetModelIndex())->GetColModel(), aTempColPoints, nil, nil);
+ else {
+ float lines[4];
+ lines[0] = lines[1] = lines[2] = lines[3] = 1.0f;
+ CColPoint tmp;
+ cols = CCollision::ProcessColModels(pEntity->GetMatrix(), *CModelInfo::GetModelInfo(pEntity->GetModelIndex())->GetColModel(),
+ pFound->GetMatrix(), *CModelInfo::GetModelInfo(pFound->GetModelIndex())->GetColModel(), aTempColPoints, &tmp, lines);
+ }
+ if (cols <= 0)
+ continue;
+ switch (pFound->m_type) {
+ case ENTITY_TYPE_VEHICLE:
+ {
+ printf("Will try to delete a vehicle where a mission entity should be\n");
+ CVehicle* pVehicle = (CVehicle*)pFound;
+ if (pVehicle->bIsLocked || !pVehicle->CanBeDeleted())
+ break;
+ if (pVehicle->pDriver) {
+ CPopulation::RemovePed(pVehicle->pDriver);
+ pVehicle->pDriver = nil;
+ }
+ for (int i = 0; i < pVehicle->m_nNumMaxPassengers; i++) {
+ if (pVehicle->pPassengers[i]) {
+ CPopulation::RemovePed(pVehicle->pPassengers[i]);
+ pVehicle->pPassengers[i] = 0;
+ pVehicle->m_nNumPassengers--;
+ }
+ }
+ CCarCtrl::RemoveFromInterestingVehicleList(pVehicle);
+ CWorld::Remove(pVehicle);
+ delete pVehicle;
+ break;
+ }
+ case ENTITY_TYPE_PED:
+ {
+ CPed* pPed = (CPed*)pFound;
+ if (pPed->IsPlayer() || !pPed->CanBeDeleted())
+ break;
+ CPopulation::RemovePed(pPed);
+ printf("Deleted a ped where a mission entity should be\n");
+ break;
+ }
+ }
+ }
+}
+
+void CTheScripts::HighlightImportantArea(uint32 id, float X1, float Y1, float X2, float Y2, float Z)
+{
+ float infX, infY, supX, supY;
+ if (X1 < X2) {
+ infX = X1;
+ supX = X2;
+ } else {
+ infX = X2;
+ supX = X1;
+ }
+ if (Y1 < Y2) {
+ infY = Y1;
+ supY = Y2;
+ }
+ else {
+ infY = Y2;
+ supY = Y1;
+ }
+ CVector center;
+ center.x = (infX + supX) / 2;
+ center.y = (infY + supY) / 2;
+ center.z = (Z <= 100.0f) ? CWorld::FindGroundZForCoord(center.x, center.y) : Z;
+ CShadows::RenderIndicatorShadow(id, 2, gpGoalTex, &center, supX - center.x, 0.0f, 0.0f, center.y - supY, 0);
+}
+
+WRAPPER void CTheScripts::HighlightImportantAngledArea(uint32 id, float, float, float, float, float, float, float, float, float)
+{
+ EAXJMP(0x454430);
+}
+
WRAPPER bool CTheScripts::IsPedStopped(CPed*) { EAXJMP(0x454670); }
WRAPPER bool CTheScripts::IsPlayerStopped(CPlayerInfo*) { EAXJMP(0x4546C0); }
@@ -11241,7 +11494,7 @@ InjectHook(0x44FD10, &CTheScripts::UndoBuildingSwaps, PATCH_JUMP);
InjectHook(0x44FD60, &CTheScripts::UndoEntityVisibilitySettings, 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(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 59054be3..b6844b6c 100644
--- a/src/control/Script.h
+++ b/src/control/Script.h
@@ -414,6 +414,14 @@ class CRunningScript
public:
void SetIP(uint32 ip) { m_nIp = ip; }
CRunningScript* GetNext() const { return next; }
+ void BuildFromSaved(const CRunningScript& pSaved)
+ {
+ CRunningScript* n = next;
+ CRunningScript* p = prev;
+ *this = pSaved;
+ next = n;
+ prev = p;
+ }
void UpdateTimers(float timeStep) {
m_anLocalVariables[NUM_LOCAL_VARS] += timeStep;
m_anLocalVariables[NUM_LOCAL_VARS + 1] += timeStep;
diff --git a/src/render/Shadows.cpp b/src/render/Shadows.cpp
index 1d100d4d..e14b0453 100644
--- a/src/render/Shadows.cpp
+++ b/src/render/Shadows.cpp
@@ -40,6 +40,7 @@ RwTexture *&gpGoalMarkerTex = *(RwTexture **)0x94142C;
RwTexture *&gpWalkDontTex = *(RwTexture **)0x95CB4C;
RwTexture *&gpCrackedGlassTex = *(RwTexture **)0x95CB94;
RwTexture *&gpPostShadowTex = *(RwTexture **)0x8F59D4;
+RwTexture *&gpGoalTex = *(RwTexture**)0x94142C;
#if 1
int16 CShadows::ShadowsStoredToBeRendered;
diff --git a/src/render/Shadows.h b/src/render/Shadows.h
index c12327b1..41404612 100644
--- a/src/render/Shadows.h
+++ b/src/render/Shadows.h
@@ -178,3 +178,4 @@ public:
extern RwTexture *&gpBloodPoolTex;
extern RwTexture *&gpShadowExplosionTex;
extern RwTexture *&gpShadowHeadLightsTex;
+extern RwTexture *&gpGoalTex;