Skip to content

Commit

Permalink
Destroyed unit leaves sensors fix (#1541)
Browse files Browse the repository at this point in the history
see [issue
1536](#1536)
Corrected two parameters in the RemoveSensorsAt function
thx to [tyuah8](https://github.com/tyuah8)
  • Loading branch information
NetsuNegi authored Feb 26, 2025
1 parent 36aadec commit 8093e86
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 40 deletions.
4 changes: 3 additions & 1 deletion CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,9 @@ This page lists all the individual contributions to the project by their author.
- Bunkerable checks dehardcode
- Prevent the units with locomotors that cause problems from entering the tank bunker
- No turret unit turn to the target
- **tyuah8** - Drive/Jumpjet/Ship/Teleport locomotor did not power on when it is un-piggybacked bugfix
- **tyuah8**
- Drive/Jumpjet/Ship/Teleport locomotor did not power on when it is un-piggybacked bugfix
- Destroyed unit leaves sensors bugfix
- **Aephiex** - initial fix for Ares academy not working on the initial payloads of vehicles built from a war factory
- **Multfinite** - Allow to toggle main exception handler via command line argument `-ExceptionHandler=boolean`
- **Ares developers**
Expand Down
1 change: 1 addition & 0 deletions docs/Fixed-or-Improved-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ This page describes all ingame logics that are fixed or improved in Phobos witho
- Fix the bug that parasite will vanish if it missed its target when its previous cell is occupied.
- Prevent the units with locomotors that cause problems from entering the tank bunker.
- 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.
- Fix the bug that destroyed unit may leaves sensors.

## Fixes / interactions with other extensions

Expand Down
1 change: 1 addition & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ Vanilla fixes:
- 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)
- Fix the bug that parasite will vanish if it missed its target when its previous cell is occupied (by 航味麻酱)
- 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)
- Fix the bug that destroyed unit may leaves sensors (by tyuah8)
Phobos fixes:
- Fixed a few errors of calling for superweapon launch by `LaunchSW` or building infiltration (by Trsdy)
Expand Down
1 change: 1 addition & 0 deletions src/Ext/Techno/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ void TechnoExt::ExtData::Serialize(T& Stm)
.Process(this->LastWarpInDelay)
.Process(this->IsBeingChronoSphered)
.Process(this->KeepTargetOnMove)
.Process(this->LastSensorsMapCoords)
;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Ext/Techno/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class TechnoExt
int LastWarpInDelay; // Last-warp in delay for this unit, used by HasCarryoverWarpInDelay.
bool IsBeingChronoSphered; // Set to true on units currently being ChronoSphered, does not apply to Ares-ChronoSphere'd buildings or Chrono reinforcements.
bool KeepTargetOnMove;
CellStruct LastSensorsMapCoords;

ExtData(TechnoClass* OwnerObject) : Extension<TechnoClass>(OwnerObject)
, TypeExtData { nullptr }
Expand Down Expand Up @@ -96,6 +97,7 @@ class TechnoExt
, LastWarpInDelay { 0 }
, IsBeingChronoSphered { false }
, KeepTargetOnMove { false }
, LastSensorsMapCoords { CellStruct::Empty }
{ }

void OnEarlyUpdate();
Expand Down
57 changes: 18 additions & 39 deletions src/Ext/Unit/Hooks.Jumpjet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <Utilities/Macro.h>
#include <Ext/TechnoType/Body.h>
#include <Ext/WeaponType/Body.h>
#include <Ext/Techno/Body.h>

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

// Bugfix: Jumpjet detect cloaked objects beneath
DEFINE_HOOK(0x54C036, JumpjetLocomotionClass_State3_UpdateSensors, 0x7)
{
GET(FootClass* const, pLinkedTo, ECX);
GET(CellStruct const, currentCell, EAX);

// Copied from FootClass::UpdatePosition
if (pLinkedTo->GetTechnoType()->SensorsSight)
{
CellStruct const lastCell = pLinkedTo->LastFlightMapCoords;

if (lastCell != currentCell)
{
pLinkedTo->RemoveSensorsAt(lastCell);
pLinkedTo->AddSensorsAt(currentCell);
}
}
// Something more may be missing

return 0;
}

DEFINE_HOOK(0x54CB0E, JumpjetLocomotionClass_State5_CrashSpin, 0x7)
{
GET(JumpjetLocomotionClass*, pThis, EDI);
Expand Down Expand Up @@ -187,6 +166,23 @@ FireError __stdcall JumpjetLocomotionClass_Can_Fire(ILocomotion* pThis)

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

DEFINE_HOOK(0x54DAC4, JumpjetLocomotionClass_EndPiggyback_Blyat, 0x6)
{
GET(FootClass*, pLinkedTo, EAX);
auto const* pType = pLinkedTo->GetTechnoType();

pLinkedTo->PrimaryFacing.SetROT(pType->ROT);

if (pType->SensorsSight)
{
const auto pExt = TechnoExt::ExtMap.Find(pLinkedTo);
pLinkedTo->RemoveSensorsAt(pExt->LastSensorsMapCoords);
pLinkedTo->AddSensorsAt(CellStruct::Empty);
}

return 0;
}

// Fix initial facing when jumpjet locomotor is being attached
DEFINE_HOOK(0x54AE44, JumpjetLocomotionClass_LinkToObject_FixFacing, 0x7)
{
Expand All @@ -212,20 +208,3 @@ void __stdcall JumpjetLocomotionClass_Unlimbo(ILocomotion* pThis)
}

DEFINE_JUMP(VTABLE, 0x7ECDB8, GET_OFFSET(JumpjetLocomotionClass_Unlimbo))

DEFINE_HOOK(0x54DAC4, JumpjetLocomotionClass_EndPiggyback_Blyat, 0x6)
{
GET(FootClass*, pLinked, EAX);
auto const* pType = pLinked->GetTechnoType();

pLinked->PrimaryFacing.SetROT(pType->ROT);

if (pType->SensorsSight)
{
pLinked->RemoveSensorsAt(pLinked->LastFlightMapCoords);
pLinked->RemoveSensorsAt(pLinked->GetMapCoords());
pLinked->AddSensorsAt(pLinked->GetMapCoords());
}

return 0;
}
91 changes: 91 additions & 0 deletions src/Misc/Hooks.BugFixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1224,3 +1224,94 @@ size_t __fastcall HexStr2Int_replacement(const char* str)
}
DEFINE_JUMP(CALL, 0x6E8305, GET_OFFSET(HexStr2Int_replacement)); // TaskForce
DEFINE_JUMP(CALL, 0x6E5FA6, GET_OFFSET(HexStr2Int_replacement)); // TagType

#pragma region Sensors

DEFINE_HOOK(0x4DE839, FootClass_AddSensorsAt_Record, 0x6)
{
GET(FootClass*, pThis, ESI);
LEA_STACK(CellStruct*, cell, STACK_OFFSET(0x34, 0x4));
const auto pExt = TechnoExt::ExtMap.Find(pThis);
pExt->LastSensorsMapCoords = *cell;

return 0;
}

DEFINE_HOOK(0x4D8606, FootClass_UpdatePosition_Sensors, 0x6)
{
enum { SkipGameCode = 0x4D8627 };

GET(FootClass*, pThis, ESI);
const auto pExt = TechnoExt::ExtMap.Find(pThis);
const auto currentCell = pThis->GetMapCoords();

if (pExt->LastSensorsMapCoords != currentCell)
{
pThis->RemoveSensorsAt(pExt->LastSensorsMapCoords);
pThis->AddSensorsAt(currentCell);
}

return SkipGameCode;
}

DEFINE_HOOK(0x4DB36C, FootClass_Limbo_RemoveSensors, 0x5)
{
enum { SkipGameCode = 0x4DB37C };

GET(FootClass*, pThis, EDI);
const auto pExt = TechnoExt::ExtMap.Find(pThis);

pThis->RemoveSensorsAt(pExt->LastSensorsMapCoords);

return SkipGameCode;
}

DEFINE_HOOK(0x4DBEE7, FootClass_SetOwningHouse_RemoveSensors, 0x6)
{
enum { SkipGameCode = 0x4DBF01 };

GET(FootClass*, pThis, ESI);
const auto pExt = TechnoExt::ExtMap.Find(pThis);

pThis->RemoveSensorsAt(pExt->LastSensorsMapCoords);

return SkipGameCode;
}

// Bugfix: Jumpjet detect cloaked objects beneath
DEFINE_HOOK(0x54C036, JumpjetLocomotionClass_State3_UpdateSensors, 0x7)
{
GET(FootClass* const, pLinkedTo, ECX);
GET(CellStruct const, currentCell, EAX);

// Copied from FootClass::UpdatePosition
if (pLinkedTo->GetTechnoType()->SensorsSight)
{
const auto pExt = TechnoExt::ExtMap.Find(pLinkedTo);
CellStruct const lastCell = pExt->LastSensorsMapCoords;

if (lastCell != currentCell)
{
pLinkedTo->RemoveSensorsAt(lastCell);
pLinkedTo->AddSensorsAt(currentCell);
}
}
// Something more may be missing

return 0;
}

DEFINE_HOOK(0x54D06F, JumpjetLocomotionClass_ProcessCrashing_RemoveSensors, 0x5)
{
GET(FootClass*, pLinkedTo, EAX);

if (pLinkedTo->GetTechnoType()->SensorsSight)
{
const auto pExt = TechnoExt::ExtMap.Find(pLinkedTo);
pLinkedTo->RemoveSensorsAt(pExt->LastSensorsMapCoords);
}

return 0;
}

#pragma endregion

0 comments on commit 8093e86

Please sign in to comment.