Skip to content

Commit

Permalink
feat(magic): AddTargetEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbeBryssinck committed Nov 6, 2021
1 parent e60ef88 commit e4f0393
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 7 deletions.
11 changes: 11 additions & 0 deletions Code/client/Events/AddTargetEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

struct AddTargetEvent
{
AddTargetEvent(uint32_t aTargetID, uint32_t aSpellID)
: TargetID(aTargetID), SpellID(aSpellID)
{}

uint32_t TargetID;
uint32_t SpellID;
};
4 changes: 2 additions & 2 deletions Code/client/Games/Skyrim/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ bool TP_MAKE_THISCALL(HookDamageActor, Actor, float aDamage, Actor* apHitter)
{
if (faction.Id.BaseId == 0x00000DB1 && pExHittee->IsRemote())
{
return 0;
return false;
}
else if (faction.Id.BaseId == 0x00000DB1 && pExHittee->IsLocal())
{
Expand All @@ -492,7 +492,7 @@ bool TP_MAKE_THISCALL(HookDamageActor, Actor, float aDamage, Actor* apHitter)
return ThisCall(RealDamageActor, apThis, aDamage, apHitter);
}

return 0;
return false;
}

TP_THIS_FUNCTION(TApplyActorEffect, void, ActiveEffect, Actor* apTarget, float aEffectValue, unsigned int unk1);
Expand Down
1 change: 1 addition & 0 deletions Code/client/Games/Skyrim/Actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ struct Actor : TESObjectREFR

//void Save_Reversed(uint32_t aChangeFlags, Buffer::Writer& aWriter);
};
constexpr size_t t = offsetof(Actor, magicTarget);

static_assert(offsetof(Actor, processManager) == 0xF0);
static_assert(offsetof(Actor, flags1) == 0xE0);
Expand Down
3 changes: 1 addition & 2 deletions Code/client/Games/Skyrim/Forms/MagicItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@


#include <Forms/TESBoundObject.h>
#include <Forms/EffectSetting.h>
#include <Components/BGSKeywordForm.h>
#include <Components/TESFullName.h>

struct EffectSetting;

struct MagicItem : TESBoundObject
{
TESFullName fullName;
Expand Down
24 changes: 24 additions & 0 deletions Code/client/Games/Skyrim/Misc/MagicTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

#include <Actor.h>
#include <Games/ActorExtension.h>
#include <World.h>
#include <Games/ActorExtension.h>

#include <Events/AddTargetEvent.h>

TP_THIS_FUNCTION(TAddTarget, bool, MagicTarget, MagicTarget::AddTargetData& arData);
TP_THIS_FUNCTION(TCheckAddEffect, bool, MagicTarget::AddTargetData, void* arArgs, float afResistance);
Expand All @@ -19,8 +23,27 @@ bool MagicTarget::AddTarget(AddTargetData& arData) noexcept
return result;
}

// TODO: don't send continuous, value modifying effects like burning from flames concentration spell
// can't cancel all ValueModifierEffects though
bool TP_MAKE_THISCALL(HookAddTarget, MagicTarget, MagicTarget::AddTargetData& arData)
{
// TODO: barf
Actor* pTargetActor = (Actor*)((char*)apThis - 0x98);
ActorExtension* pTargetActorEx = pTargetActor->GetExtension();

auto factions = pTargetActor->GetFactions();
for (const auto& faction : factions.NpcFactions)
{
if (faction.Id.BaseId == 0x00000DB1)
{
if (pTargetActorEx->IsRemote())
return false;

World::Get().GetRunner().Trigger(AddTargetEvent(pTargetActor->formID, arData.pSpell->formID));
return ThisCall(RealAddTarget, apThis, arData);
}
}

if (arData.pCaster)
{
if (auto pExtension = arData.pCaster->GetExtension())
Expand All @@ -30,6 +53,7 @@ bool TP_MAKE_THISCALL(HookAddTarget, MagicTarget, MagicTarget::AddTargetData& ar
}
}

World::Get().GetRunner().Trigger(AddTargetEvent(pTargetActor->formID, arData.pSpell->formID));
return ThisCall(RealAddTarget, apThis, arData);
}

Expand Down
2 changes: 1 addition & 1 deletion Code/client/Games/Skyrim/Misc/MagicTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#include <Misc/MagicSystem.h>

struct EffectSetting;
struct Actor;
struct MagicItem;
struct EffectSetting;
struct TESBoundObject;

struct MagicTarget
Expand Down
8 changes: 6 additions & 2 deletions Code/client/Services/Generic/TestService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,18 +670,22 @@ void TestService::OnDraw() noexcept
{
MagicTarget::AddTargetData data{};

data.pCaster = PlayerCharacter::Get();
//data.pCaster = PlayerCharacter::Get();
data.pSpell = pEffectSpell;
data.pEffectSetting = effect;
data.pSource = nullptr;
/*
data.ExplosionLocation.x = -11891.820f;
data.ExplosionLocation.y = -56157.960f;
data.ExplosionLocation.z = 665.110f;
*/
data.fMagnitude = 0.0f;
data.fUnkFloat1 = 1.0f;
data.eCastingSource = MagicSystem::CastingSource::RIGHT_HAND;
data.eCastingSource = MagicSystem::CastingSource::CASTING_SOURCE_COUNT;
/*
data.bAreaTarget = true;
data.bDualCast = false;
*/

pFetchActor->magicTarget.AddTarget(data);
}
Expand Down

0 comments on commit e4f0393

Please sign in to comment.