1717#include < Events/MountEvent.h>
1818#include < Events/DialogueEvent.h>
1919#include < Events/HitEvent.h>
20+ #include < Events/RemoveSpellEvent.h>
2021
2122#include < Games/TES.h>
2223#include < World.h>
@@ -103,6 +104,7 @@ void Actor::Save_Reversed(const uint32_t aChangeFlags, Buffer::Writer& aWriter)
103104
104105#endif
105106
107+ TP_THIS_FUNCTION (TRemoveSpell, bool , Actor, MagicItem*);
106108TP_THIS_FUNCTION (TCharacterConstructor, Actor*, Actor);
107109TP_THIS_FUNCTION (TCharacterConstructor2, Actor*, Actor, uint8_t aUnk);
108110TP_THIS_FUNCTION (TCharacterDestructor, Actor*, Actor);
@@ -119,6 +121,7 @@ TCharacterConstructor* RealCharacterConstructor;
119121TCharacterConstructor2* RealCharacterConstructor2;
120122TCharacterDestructor* RealCharacterDestructor;
121123
124+ static TRemoveSpell* RealRemoveSpell = nullptr ;
122125static TAddInventoryItem* RealAddInventoryItem = nullptr ;
123126static TPickUpObject* RealPickUpObject = nullptr ;
124127static TDropObject* RealDropObject = nullptr ;
@@ -352,6 +355,17 @@ void Actor::StopCombat() noexcept
352355 s_pStopCombat (this );
353356}
354357
358+ bool Actor::RemoveSpell (MagicItem* apSpell) noexcept
359+ {
360+ if (!apSpell)
361+ {
362+ spdlog::error (__FUNCTION__ " : apSpell is null" );
363+ return false ;
364+ }
365+ // spdlog::info(__FUNCTION__ ": removing: {} from actor: {}", apSpell->formID, formID);
366+ return TiltedPhoques::ThisCall (RealRemoveSpell, this , apSpell);
367+ }
368+
355369bool Actor::HasPerk (uint32_t aPerkFormId) const noexcept
356370{
357371 return GetPerkRank (aPerkFormId) != 0 ;
@@ -369,6 +383,22 @@ uint8_t Actor::GetPerkRank(uint32_t aPerkFormId) const noexcept
369383 return TiltedPhoques::ThisCall (getPerkRank, this , pPerk);
370384}
371385
386+ bool TP_MAKE_THISCALL (HookRemoveSpell, Actor, MagicItem* apSpell)
387+ {
388+ bool result = TiltedPhoques::ThisCall (RealRemoveSpell, apThis, apSpell);
389+ if (apThis->GetExtension ()->IsLocalPlayer () && result)
390+ {
391+ // spdlog::info(__FUNCTION__ ": spell: {}, ID: {} from local player", apSpell->GetName() , apSpell->formID);
392+ RemoveSpellEvent removalEvent;
393+
394+ removalEvent.TargetId = apThis->formID ;
395+ removalEvent.SpellId = apSpell->formID ;
396+ World::Get ().GetRunner ().Trigger (removalEvent);
397+ }
398+
399+ return result;
400+ }
401+
372402Actor* TP_MAKE_THISCALL (HookCharacterConstructor, Actor)
373403{
374404 TP_EMPTY_HOOK_PLACEHOLDER;
@@ -1233,6 +1263,7 @@ static TiltedPhoques::Initializer s_actorHooks(
12331263 {
12341264 POINTER_SKYRIMSE (TActorProcess, s_actorProcess, 37356 );
12351265 POINTER_SKYRIMSE (TSetPosition, s_setPosition, 19790 );
1266+ POINTER_SKYRIMSE (TRemoveSpell, s_removeSpell, 38717 );
12361267 POINTER_SKYRIMSE (TCharacterConstructor, s_characterCtor, 40245 );
12371268 POINTER_SKYRIMSE (TCharacterConstructor2, s_characterCtor2, 40246 );
12381269 POINTER_SKYRIMSE (TCharacterDestructor, s_characterDtor, 37175 );
@@ -1255,6 +1286,7 @@ static TiltedPhoques::Initializer s_actorHooks(
12551286
12561287 RealActorProcess = s_actorProcess.Get ();
12571288 RealSetPosition = s_setPosition.Get ();
1289+ RealRemoveSpell = s_removeSpell.Get ();
12581290 FUNC_GetActorLocation = s_GetActorLocation.Get ();
12591291 RealCharacterConstructor = s_characterCtor.Get ();
12601292 RealCharacterConstructor2 = s_characterCtor2.Get ();
@@ -1276,6 +1308,7 @@ static TiltedPhoques::Initializer s_actorHooks(
12761308
12771309 TP_HOOK (&RealActorProcess, HookActorProcess);
12781310 TP_HOOK (&RealSetPosition, HookSetPosition);
1311+ TP_HOOK (&RealRemoveSpell, HookRemoveSpell);
12791312 TP_HOOK (&RealCharacterConstructor, HookCharacterConstructor);
12801313 TP_HOOK (&RealCharacterConstructor2, HookCharacterConstructor2);
12811314 TP_HOOK (&RealForceState, HookForceState);
0 commit comments