Skip to content

Commit

Permalink
Make Synclogger caller address relative (prototype, to be fixed later)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaserli committed Jun 10, 2024
1 parent c801eb9 commit a1a99ab
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
4 changes: 2 additions & 2 deletions docs/New-or-Enhanced-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ Trajectory.Bombard.Height=0.0 ; double
- `ShrapnelWeapon` can now be triggered against ground & buildings via `Shrapnel.AffectsGround` and `Shrapnel.AffectsBuildings`.
- Setting `Shrapnel.UseWeaponTargeting` now allows weapon target filtering to be enabled for `ShrapnelWeapon`. Target's `LegalTarget` setting, Warhead `Verses` against `Armor` as well as `ShrapnelWeapon` [weapon targeting filters](#weapon-targeting-filter) & [AttachEffect filters](#attached-effects) will be checked.
- Do note that this overrides the normal check of only allowing shrapnels to hit non-allied objects. Use `CanTargetHouses=enemies` to manually enable this behaviour again.

In `rulesmd.ini`:
```ini
[SOMEPROJECTILE] ; Projectile
Expand Down Expand Up @@ -1167,7 +1167,7 @@ In `rulesmd.ini`:
```ini
[SOMETECHNO]
Convert.HumanToComputer = ; TechnoType
Convert.ComputerToHuman = ; TechnoType
Convert.ComputerToHuman = ; TechnoType
```

## Terrain
Expand Down
2 changes: 1 addition & 1 deletion docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ ShowPlacementPreview=yes ; boolean
RealTimeTimers=false ; boolean
RealTimeTimers.Adaptive=false ; boolean
ShowHarvesterCounter=true ; boolean
ShowPowerDelta=true ; boolean
ShowPowerDelta=true ; boolean
ShowWeedsCounter=true ; boolean
ToolTipDescriptions=true ; boolean
ToolTipBlur=false ; boolean
Expand Down
39 changes: 26 additions & 13 deletions src/Misc/SyncLogging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <Utilities/Debug.h>
#include <Utilities/Macro.h>
#include <Utilities/GeneralUtils.h>
#include <Utilities/AresHelper.h>

bool SyncLogger::HooksDisabled = false;
int SyncLogger::AnimCreations_HighestX = 0;
Expand Down Expand Up @@ -287,10 +288,22 @@ DEFINE_HOOK(0x64CD11, ExecuteDoList_WriteDesyncLog, 0x8)

// RNG call logging

DWORD __forceinline GetCallerAddress(REGISTERS* R)
{
GET_STACK(DWORD, caller, 0x0);
// B for Bobos
if (caller > AresHelper::PhobosBaseAddress && caller < (AresHelper::PhobosBaseAddress + 0x100000))
caller = caller - AresHelper::PhobosBaseAddress + 0xB0000000;
// A for Ares
else if (caller > AresHelper::AresBaseAddress && caller < (AresHelper::AresBaseAddress + 0x100000))
caller = caller - AresHelper::AresBaseAddress + 0xA0000000;
return caller;
}

DEFINE_HOOK(0x65C7D0, Random2Class_Random_SyncLog, 0x6)
{
GET(Randomizer*, pThis, ECX);
GET_STACK(unsigned int, callerAddress, 0x0);
DWORD callerAddress = GetCallerAddress(R);

SyncLogger::AddRNGCallSyncLogEvent(pThis, 1, callerAddress);

Expand All @@ -300,7 +313,7 @@ DEFINE_HOOK(0x65C7D0, Random2Class_Random_SyncLog, 0x6)
DEFINE_HOOK(0x65C88A, Random2Class_RandomRanged_SyncLog, 0x6)
{
GET(Randomizer*, pThis, EDX);
GET_STACK(unsigned int, callerAddress, 0x0);
DWORD callerAddress = GetCallerAddress(R);
GET_STACK(int, min, 0x4);
GET_STACK(int, max, 0x8);

Expand All @@ -314,7 +327,7 @@ DEFINE_HOOK(0x65C88A, Random2Class_RandomRanged_SyncLog, 0x6)
DEFINE_HOOK(0x4C9300, FacingClass_Set_SyncLog, 0x5)
{
GET_STACK(DirStruct*, facing, 0x4);
GET_STACK(unsigned int, callerAddress, 0x0);
DWORD callerAddress = GetCallerAddress(R);

SyncLogger::AddFacingChangeSyncLogEvent(facing->Raw, callerAddress);

Expand All @@ -327,7 +340,7 @@ DEFINE_HOOK(0x51B1F0, InfantryClass_AssignTarget_SyncLog, 0x5)
{
GET(InfantryClass*, pThis, ECX);
GET_STACK(AbstractClass*, pTarget, 0x4);
GET_STACK(unsigned int, callerAddress, 0x0);
DWORD callerAddress = GetCallerAddress(R);

SyncLogger::AddTargetChangeSyncLogEvent(pThis, pTarget, callerAddress);

Expand All @@ -338,7 +351,7 @@ DEFINE_HOOK(0x443B90, BuildingClass_AssignTarget_SyncLog, 0xB)
{
GET(BuildingClass*, pThis, ECX);
GET_STACK(AbstractClass*, pTarget, 0x4);
GET_STACK(unsigned int, callerAddress, 0x0);
DWORD callerAddress = GetCallerAddress(R);

SyncLogger::AddTargetChangeSyncLogEvent(pThis, pTarget, callerAddress);

Expand All @@ -349,7 +362,7 @@ DEFINE_HOOK(0x6FCDB0, TechnoClass_AssignTarget_SyncLog, 0x5)
{
GET(TechnoClass*, pThis, ECX);
GET_STACK(AbstractClass*, pTarget, 0x4);
GET_STACK(unsigned int, callerAddress, 0x0);
DWORD callerAddress = GetCallerAddress(R);

auto const RTTI = pThis->WhatAmI();

Expand All @@ -365,7 +378,7 @@ DEFINE_HOOK(0x41AA80, AircraftClass_AssignDestination_SyncLog, 0x7)
{
GET(AircraftClass*, pThis, ECX);
GET_STACK(AbstractClass*, pDest, 0x4);
GET_STACK(unsigned int, callerAddress, 0x0);
DWORD callerAddress = GetCallerAddress(R);

SyncLogger::AddDestinationChangeSyncLogEvent(pThis, pDest, callerAddress);

Expand All @@ -376,7 +389,7 @@ DEFINE_HOOK(0x455D50, BuildingClass_AssignDestination_SyncLog, 0xA)
{
GET(BuildingClass*, pThis, ECX);
GET_STACK(AbstractClass*, pDest, 0x4);
GET_STACK(unsigned int, callerAddress, 0x0);
DWORD callerAddress = GetCallerAddress(R);

SyncLogger::AddDestinationChangeSyncLogEvent(pThis, pDest, callerAddress);

Expand All @@ -387,7 +400,7 @@ DEFINE_HOOK(0x51AA40, InfantryClass_AssignDestination_SyncLog, 0x5)
{
GET(InfantryClass*, pThis, ECX);
GET_STACK(AbstractClass*, pDest, 0x4);
GET_STACK(unsigned int, callerAddress, 0x0);
DWORD callerAddress = GetCallerAddress(R);

SyncLogger::AddDestinationChangeSyncLogEvent(pThis, pDest, callerAddress);

Expand All @@ -398,7 +411,7 @@ DEFINE_HOOK(0x741970, UnitClass_AssignDestination_SyncLog, 0x6)
{
GET(UnitClass*, pThis, ECX);
GET_STACK(AbstractClass*, pDest, 0x4);
GET_STACK(unsigned int, callerAddress, 0x0);
DWORD callerAddress = GetCallerAddress(R);

SyncLogger::AddDestinationChangeSyncLogEvent(pThis, pDest, callerAddress);

Expand All @@ -411,7 +424,7 @@ DEFINE_HOOK(0x41BB30, AircraftClass_OverrideMission_SyncLog, 0x6)
{
GET(AircraftClass*, pThis, ECX);
GET_STACK(int, mission, 0x4);
GET_STACK(unsigned int, callerAddress, 0x0);
DWORD callerAddress = GetCallerAddress(R);

SyncLogger::AddMissionOverrideSyncLogEvent(pThis, mission, callerAddress);

Expand All @@ -422,7 +435,7 @@ DEFINE_HOOK(0x4D8F40, FootClass_OverrideMission_SyncLog, 0x5)
{
GET(FootClass*, pThis, ECX);
GET_STACK(int, mission, 0x4);
GET_STACK(unsigned int, callerAddress, 0x0);
DWORD callerAddress = GetCallerAddress(R);

SyncLogger::AddMissionOverrideSyncLogEvent(pThis, mission, callerAddress);

Expand All @@ -433,7 +446,7 @@ DEFINE_HOOK(0x7013A0, TechnoClass_OverrideMission_SyncLog, 0x5)
{
GET(TechnoClass*, pThis, ECX);
GET_STACK(int, mission, 0x4);
GET_STACK(unsigned int, callerAddress, 0x0);
DWORD callerAddress = GetCallerAddress(R);

if (pThis->WhatAmI() == AbstractType::Building)
SyncLogger::AddMissionOverrideSyncLogEvent(pThis, mission, callerAddress);
Expand Down

0 comments on commit a1a99ab

Please sign in to comment.