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,17 +355,15 @@ void Actor::StopCombat() noexcept
352355 s_pStopCombat (this );
353356}
354357
355- void Actor::RemoveSpell (MagicItem* apSpell) noexcept
358+ bool Actor::RemoveSpell (MagicItem* apSpell) noexcept
356359{
357- TP_THIS_FUNCTION (TRemoveSpell, void , Actor, MagicItem*);
358- POINTER_SKYRIMSE (TRemoveSpell, removeSpell, 38717 );
359360 if (!apSpell)
360361 {
361- spdlog::error (" Actor::RemoveSpell : apSpell is null" );
362- return ;
362+ spdlog::error (__FUNCTION__ " : apSpell is null" );
363+ return FALSE ;
363364 }
364- // spdlog::info("Removing spell : {} from actor: {}", apSpell->formID, formID);
365- TiltedPhoques::ThisCall (removeSpell , this , apSpell);
365+ // spdlog::info(__FUNCTION__ ": removing : {} from actor: {}", apSpell->formID, formID);
366+ return TiltedPhoques::ThisCall (RealRemoveSpell , this , apSpell);
366367}
367368
368369bool Actor::HasPerk (uint32_t aPerkFormId) const noexcept
@@ -382,6 +383,23 @@ uint8_t Actor::GetPerkRank(uint32_t aPerkFormId) const noexcept
382383 return TiltedPhoques::ThisCall (getPerkRank, this , pPerk);
383384}
384385
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+ // Log spell info
392+ // spdlog::info("Removing spell {}, ID: {} from local player", apSpell->GetName() , apSpell->formID);
393+ RemoveSpellEvent removalEvent;
394+
395+ removalEvent.TargetId = apThis->formID ;
396+ removalEvent.SpellId = apSpell->formID ;
397+ World::Get ().GetRunner ().Trigger (removalEvent);
398+ }
399+
400+ return result;
401+ }
402+
385403Actor* TP_MAKE_THISCALL (HookCharacterConstructor, Actor)
386404{
387405 TP_EMPTY_HOOK_PLACEHOLDER;
@@ -1246,6 +1264,7 @@ static TiltedPhoques::Initializer s_actorHooks(
12461264 {
12471265 POINTER_SKYRIMSE (TActorProcess, s_actorProcess, 37356 );
12481266 POINTER_SKYRIMSE (TSetPosition, s_setPosition, 19790 );
1267+ POINTER_SKYRIMSE (TRemoveSpell, s_removeSpell, 38717 );
12491268 POINTER_SKYRIMSE (TCharacterConstructor, s_characterCtor, 40245 );
12501269 POINTER_SKYRIMSE (TCharacterConstructor2, s_characterCtor2, 40246 );
12511270 POINTER_SKYRIMSE (TCharacterDestructor, s_characterDtor, 37175 );
@@ -1268,6 +1287,7 @@ static TiltedPhoques::Initializer s_actorHooks(
12681287
12691288 RealActorProcess = s_actorProcess.Get ();
12701289 RealSetPosition = s_setPosition.Get ();
1290+ RealRemoveSpell = s_removeSpell.Get ();
12711291 FUNC_GetActorLocation = s_GetActorLocation.Get ();
12721292 RealCharacterConstructor = s_characterCtor.Get ();
12731293 RealCharacterConstructor2 = s_characterCtor2.Get ();
@@ -1289,6 +1309,7 @@ static TiltedPhoques::Initializer s_actorHooks(
12891309
12901310 TP_HOOK (&RealActorProcess, HookActorProcess);
12911311 TP_HOOK (&RealSetPosition, HookSetPosition);
1312+ TP_HOOK (&RealRemoveSpell, HookRemoveSpell);
12921313 TP_HOOK (&RealCharacterConstructor, HookCharacterConstructor);
12931314 TP_HOOK (&RealCharacterConstructor2, HookCharacterConstructor2);
12941315 TP_HOOK (&RealForceState, HookForceState);
0 commit comments