Skip to content

Commit 8093e86

Browse files
authored
Destroyed unit leaves sensors fix (#1541)
see [issue 1536](#1536) Corrected two parameters in the RemoveSensorsAt function thx to [tyuah8](https://github.com/tyuah8)
1 parent 36aadec commit 8093e86

File tree

7 files changed

+117
-40
lines changed

7 files changed

+117
-40
lines changed

CREDITS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,9 @@ This page lists all the individual contributions to the project by their author.
410410
- Bunkerable checks dehardcode
411411
- Prevent the units with locomotors that cause problems from entering the tank bunker
412412
- No turret unit turn to the target
413-
- **tyuah8** - Drive/Jumpjet/Ship/Teleport locomotor did not power on when it is un-piggybacked bugfix
413+
- **tyuah8**
414+
- Drive/Jumpjet/Ship/Teleport locomotor did not power on when it is un-piggybacked bugfix
415+
- Destroyed unit leaves sensors bugfix
414416
- **Aephiex** - initial fix for Ares academy not working on the initial payloads of vehicles built from a war factory
415417
- **Multfinite** - Allow to toggle main exception handler via command line argument `-ExceptionHandler=boolean`
416418
- **Ares developers**

docs/Fixed-or-Improved-Logics.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ This page describes all ingame logics that are fixed or improved in Phobos witho
187187
- Fix the bug that parasite will vanish if it missed its target when its previous cell is occupied.
188188
- Prevent the units with locomotors that cause problems from entering the tank bunker.
189189
- Fix an issue where a unit will leave an impassable invisible barrier in its original position when it is teleported by ChronoSphere onto an uncrushable unit and self destruct.
190+
- Fix the bug that destroyed unit may leaves sensors.
190191

191192
## Fixes / interactions with other extensions
192193

docs/Whats-New.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ Vanilla fixes:
591591
- Fix an issue where a unit will leave an impassable invisible barrier in its original position when it is teleported by ChronoSphere onto an uncrushable unit and self destruct (by NetsuNegi)
592592
- Fix the bug that parasite will vanish if it missed its target when its previous cell is occupied (by 航味麻酱)
593593
- Aircraft will now behave as expected according to it's `MovementZone` and `SpeedType` when moving onto different surfaces. In particular, this fixes erratic behavior when vanilla aircraft is ordered to move onto water surface and instead the movement order changes to a shore nearby (by CrimRecya)
594+
- Fix the bug that destroyed unit may leaves sensors (by tyuah8)
594595
595596
Phobos fixes:
596597
- Fixed a few errors of calling for superweapon launch by `LaunchSW` or building infiltration (by Trsdy)

src/Ext/Techno/Body.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ void TechnoExt::ExtData::Serialize(T& Stm)
560560
.Process(this->LastWarpInDelay)
561561
.Process(this->IsBeingChronoSphered)
562562
.Process(this->KeepTargetOnMove)
563+
.Process(this->LastSensorsMapCoords)
563564
;
564565
}
565566

src/Ext/Techno/Body.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class TechnoExt
6060
int LastWarpInDelay; // Last-warp in delay for this unit, used by HasCarryoverWarpInDelay.
6161
bool IsBeingChronoSphered; // Set to true on units currently being ChronoSphered, does not apply to Ares-ChronoSphere'd buildings or Chrono reinforcements.
6262
bool KeepTargetOnMove;
63+
CellStruct LastSensorsMapCoords;
6364

6465
ExtData(TechnoClass* OwnerObject) : Extension<TechnoClass>(OwnerObject)
6566
, TypeExtData { nullptr }
@@ -96,6 +97,7 @@ class TechnoExt
9697
, LastWarpInDelay { 0 }
9798
, IsBeingChronoSphered { false }
9899
, KeepTargetOnMove { false }
100+
, LastSensorsMapCoords { CellStruct::Empty }
99101
{ }
100102

101103
void OnEarlyUpdate();

src/Ext/Unit/Hooks.Jumpjet.cpp

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <Utilities/Macro.h>
44
#include <Ext/TechnoType/Body.h>
55
#include <Ext/WeaponType/Body.h>
6+
#include <Ext/Techno/Body.h>
67

78
// Misc jumpjet facing, turning, drawing fix -- Author: Trsdy
89
// Jumpjets stuck at FireError::FACING because Jumpjet has its own facing just for JumpjetTurnRate
@@ -136,28 +137,6 @@ DEFINE_HOOK(0x736BA3, UnitClass_UpdateRotation_TurretFacing_Jumpjet, 0x6)
136137
return 0;
137138
}
138139

139-
// Bugfix: Jumpjet detect cloaked objects beneath
140-
DEFINE_HOOK(0x54C036, JumpjetLocomotionClass_State3_UpdateSensors, 0x7)
141-
{
142-
GET(FootClass* const, pLinkedTo, ECX);
143-
GET(CellStruct const, currentCell, EAX);
144-
145-
// Copied from FootClass::UpdatePosition
146-
if (pLinkedTo->GetTechnoType()->SensorsSight)
147-
{
148-
CellStruct const lastCell = pLinkedTo->LastFlightMapCoords;
149-
150-
if (lastCell != currentCell)
151-
{
152-
pLinkedTo->RemoveSensorsAt(lastCell);
153-
pLinkedTo->AddSensorsAt(currentCell);
154-
}
155-
}
156-
// Something more may be missing
157-
158-
return 0;
159-
}
160-
161140
DEFINE_HOOK(0x54CB0E, JumpjetLocomotionClass_State5_CrashSpin, 0x7)
162141
{
163142
GET(JumpjetLocomotionClass*, pThis, EDI);
@@ -187,6 +166,23 @@ FireError __stdcall JumpjetLocomotionClass_Can_Fire(ILocomotion* pThis)
187166

188167
DEFINE_JUMP(VTABLE, 0x7ECDF4, GET_OFFSET(JumpjetLocomotionClass_Can_Fire));
189168

169+
DEFINE_HOOK(0x54DAC4, JumpjetLocomotionClass_EndPiggyback_Blyat, 0x6)
170+
{
171+
GET(FootClass*, pLinkedTo, EAX);
172+
auto const* pType = pLinkedTo->GetTechnoType();
173+
174+
pLinkedTo->PrimaryFacing.SetROT(pType->ROT);
175+
176+
if (pType->SensorsSight)
177+
{
178+
const auto pExt = TechnoExt::ExtMap.Find(pLinkedTo);
179+
pLinkedTo->RemoveSensorsAt(pExt->LastSensorsMapCoords);
180+
pLinkedTo->AddSensorsAt(CellStruct::Empty);
181+
}
182+
183+
return 0;
184+
}
185+
190186
// Fix initial facing when jumpjet locomotor is being attached
191187
DEFINE_HOOK(0x54AE44, JumpjetLocomotionClass_LinkToObject_FixFacing, 0x7)
192188
{
@@ -212,20 +208,3 @@ void __stdcall JumpjetLocomotionClass_Unlimbo(ILocomotion* pThis)
212208
}
213209

214210
DEFINE_JUMP(VTABLE, 0x7ECDB8, GET_OFFSET(JumpjetLocomotionClass_Unlimbo))
215-
216-
DEFINE_HOOK(0x54DAC4, JumpjetLocomotionClass_EndPiggyback_Blyat, 0x6)
217-
{
218-
GET(FootClass*, pLinked, EAX);
219-
auto const* pType = pLinked->GetTechnoType();
220-
221-
pLinked->PrimaryFacing.SetROT(pType->ROT);
222-
223-
if (pType->SensorsSight)
224-
{
225-
pLinked->RemoveSensorsAt(pLinked->LastFlightMapCoords);
226-
pLinked->RemoveSensorsAt(pLinked->GetMapCoords());
227-
pLinked->AddSensorsAt(pLinked->GetMapCoords());
228-
}
229-
230-
return 0;
231-
}

src/Misc/Hooks.BugFixes.cpp

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,3 +1224,94 @@ size_t __fastcall HexStr2Int_replacement(const char* str)
12241224
}
12251225
DEFINE_JUMP(CALL, 0x6E8305, GET_OFFSET(HexStr2Int_replacement)); // TaskForce
12261226
DEFINE_JUMP(CALL, 0x6E5FA6, GET_OFFSET(HexStr2Int_replacement)); // TagType
1227+
1228+
#pragma region Sensors
1229+
1230+
DEFINE_HOOK(0x4DE839, FootClass_AddSensorsAt_Record, 0x6)
1231+
{
1232+
GET(FootClass*, pThis, ESI);
1233+
LEA_STACK(CellStruct*, cell, STACK_OFFSET(0x34, 0x4));
1234+
const auto pExt = TechnoExt::ExtMap.Find(pThis);
1235+
pExt->LastSensorsMapCoords = *cell;
1236+
1237+
return 0;
1238+
}
1239+
1240+
DEFINE_HOOK(0x4D8606, FootClass_UpdatePosition_Sensors, 0x6)
1241+
{
1242+
enum { SkipGameCode = 0x4D8627 };
1243+
1244+
GET(FootClass*, pThis, ESI);
1245+
const auto pExt = TechnoExt::ExtMap.Find(pThis);
1246+
const auto currentCell = pThis->GetMapCoords();
1247+
1248+
if (pExt->LastSensorsMapCoords != currentCell)
1249+
{
1250+
pThis->RemoveSensorsAt(pExt->LastSensorsMapCoords);
1251+
pThis->AddSensorsAt(currentCell);
1252+
}
1253+
1254+
return SkipGameCode;
1255+
}
1256+
1257+
DEFINE_HOOK(0x4DB36C, FootClass_Limbo_RemoveSensors, 0x5)
1258+
{
1259+
enum { SkipGameCode = 0x4DB37C };
1260+
1261+
GET(FootClass*, pThis, EDI);
1262+
const auto pExt = TechnoExt::ExtMap.Find(pThis);
1263+
1264+
pThis->RemoveSensorsAt(pExt->LastSensorsMapCoords);
1265+
1266+
return SkipGameCode;
1267+
}
1268+
1269+
DEFINE_HOOK(0x4DBEE7, FootClass_SetOwningHouse_RemoveSensors, 0x6)
1270+
{
1271+
enum { SkipGameCode = 0x4DBF01 };
1272+
1273+
GET(FootClass*, pThis, ESI);
1274+
const auto pExt = TechnoExt::ExtMap.Find(pThis);
1275+
1276+
pThis->RemoveSensorsAt(pExt->LastSensorsMapCoords);
1277+
1278+
return SkipGameCode;
1279+
}
1280+
1281+
// Bugfix: Jumpjet detect cloaked objects beneath
1282+
DEFINE_HOOK(0x54C036, JumpjetLocomotionClass_State3_UpdateSensors, 0x7)
1283+
{
1284+
GET(FootClass* const, pLinkedTo, ECX);
1285+
GET(CellStruct const, currentCell, EAX);
1286+
1287+
// Copied from FootClass::UpdatePosition
1288+
if (pLinkedTo->GetTechnoType()->SensorsSight)
1289+
{
1290+
const auto pExt = TechnoExt::ExtMap.Find(pLinkedTo);
1291+
CellStruct const lastCell = pExt->LastSensorsMapCoords;
1292+
1293+
if (lastCell != currentCell)
1294+
{
1295+
pLinkedTo->RemoveSensorsAt(lastCell);
1296+
pLinkedTo->AddSensorsAt(currentCell);
1297+
}
1298+
}
1299+
// Something more may be missing
1300+
1301+
return 0;
1302+
}
1303+
1304+
DEFINE_HOOK(0x54D06F, JumpjetLocomotionClass_ProcessCrashing_RemoveSensors, 0x5)
1305+
{
1306+
GET(FootClass*, pLinkedTo, EAX);
1307+
1308+
if (pLinkedTo->GetTechnoType()->SensorsSight)
1309+
{
1310+
const auto pExt = TechnoExt::ExtMap.Find(pLinkedTo);
1311+
pLinkedTo->RemoveSensorsAt(pExt->LastSensorsMapCoords);
1312+
}
1313+
1314+
return 0;
1315+
}
1316+
1317+
#pragma endregion

0 commit comments

Comments
 (0)