Skip to content

Commit

Permalink
fix: actor not dying after kill move
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbeBryssinck committed May 4, 2022
1 parent 3944b58 commit 489a1f8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
21 changes: 21 additions & 0 deletions Code/client/Games/References.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@ static TRotate* RealRotateZ = nullptr;
static TActorProcess* RealActorProcess = nullptr;
static TLockChange* RealLockChange = nullptr;

namespace GameplayFormulas
{

float CalculateRealDamage(Actor* apHittee, float aDamage) noexcept
{
using TGetDifficultyMultiplier = float(int32_t, int32_t, bool);
POINTER_SKYRIMSE(TGetDifficultyMultiplier, s_getDifficultyMultiplier, 26503);

bool isPlayer = apHittee == PlayerCharacter::Get();
float multiplier = s_getDifficultyMultiplier(PlayerCharacter::Get()->difficulty, ActorValueInfo::kHealth, isPlayer);

float realDamage = aDamage;

if (fabs(aDamage) <= 0.000099999997 || DifficultyMultiplier < 1.0)
realDamage = aDamage * multiplier;

return realDamage;
}

}

TESObjectREFR* TESObjectREFR::GetByHandle(uint32_t aHandle) noexcept
{
TESObjectREFR* pResult = nullptr;
Expand Down
7 changes: 7 additions & 0 deletions Code/client/Games/References.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
#include <Games/ActorExtension.h>
#include <PlayerCharacter.h>

namespace GameplayFormulas
{

float CalculateRealDamage(Actor* apHittee, float aDamage) noexcept;

}

struct ExActor : Actor, ActorExtension
{
};
Expand Down
36 changes: 15 additions & 21 deletions Code/client/Games/Skyrim/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,50 +571,44 @@ static TDamageActor* RealDamageActor = nullptr;

bool TP_MAKE_THISCALL(HookDamageActor, Actor, float aDamage, Actor* apHitter)
{
float oldHealth = apThis->GetActorValue(ActorValueInfo::kHealth);
float realDamage = GameplayFormulas::CalculateRealDamage(apThis, aDamage);

const auto pExHittee = apThis->GetExtension();
float currentHealth = apThis->GetActorValue(ActorValueInfo::kHealth);
bool wouldKill = (currentHealth - realDamage) <= 0.f;

const auto* pExHittee = apThis->GetExtension();
if (pExHittee->IsLocalPlayer())
{
bool result = ThisCall(RealDamageActor, apThis, aDamage, apHitter);
float newHealth = apThis->GetActorValue(ActorValueInfo::kHealth);
float damage = oldHealth - newHealth;
World::Get().GetRunner().Trigger(HealthChangeEvent(apThis->formID, -damage));
return result;
World::Get().GetRunner().Trigger(HealthChangeEvent(apThis->formID, -realDamage));
return ThisCall(RealDamageActor, apThis, aDamage, apHitter);
}
else if (pExHittee->IsRemotePlayer())
{
return false;
return wouldKill;
}

if (apHitter)
{
const auto pExHitter = apHitter->GetExtension();
const auto* pExHitter = apHitter->GetExtension();
if (pExHitter->IsLocalPlayer())
{
bool result = ThisCall(RealDamageActor, apThis, aDamage, apHitter);
float newHealth = apThis->GetActorValue(ActorValueInfo::kHealth);
float damage = oldHealth - newHealth;
World::Get().GetRunner().Trigger(HealthChangeEvent(apThis->formID, -damage));
return result;
World::Get().GetRunner().Trigger(HealthChangeEvent(apThis->formID, -realDamage));
return ThisCall(RealDamageActor, apThis, aDamage, apHitter);
}
if (pExHitter->IsRemotePlayer())
{
return false;
return wouldKill;
}
}

if (pExHittee->IsLocal())
{
bool result = ThisCall(RealDamageActor, apThis, aDamage, apHitter);
float newHealth = apThis->GetActorValue(ActorValueInfo::kHealth);
float damage = oldHealth - newHealth;
World::Get().GetRunner().Trigger(HealthChangeEvent(apThis->formID, -damage));
return result;
World::Get().GetRunner().Trigger(HealthChangeEvent(apThis->formID, -realDamage));
return ThisCall(RealDamageActor, apThis, aDamage, apHitter);
}
else
{
return false;
return wouldKill;
}
}

Expand Down

0 comments on commit 489a1f8

Please sign in to comment.