-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: reverse engineered fallout 4 magic classes
- Loading branch information
1 parent
bf77eae
commit b05b415
Showing
27 changed files
with
257 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
|
||
#include "MagicCaster.h" | ||
|
||
struct ActorMagicCaster : MagicCaster | ||
{ | ||
uint8_t pad48[0xB8]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
|
||
struct EffectSetting; | ||
|
||
struct EffectItemData | ||
{ | ||
float fMagnitude; | ||
int32_t iArea; | ||
int32_t iDuration; | ||
}; | ||
|
||
struct EffectItem | ||
{ | ||
EffectItemData data; | ||
EffectSetting* pEffectSetting; | ||
float fRawCost; | ||
void* Conditions; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
#include <Forms/TESForm.h> | ||
#include <Games/Magic/MagicSystem.h> | ||
|
||
struct EffectSetting : TESForm | ||
{ | ||
uint8_t pad20[0xD0 - 0x20]; | ||
EffectArchetypes::ArchetypeID eArchetype; | ||
uint8_t padD4[0x1B0 - 0xD4]; | ||
}; | ||
|
||
static_assert(sizeof(EffectSetting) == 0x1B0); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
struct MagicCaster | ||
{ | ||
virtual ~MagicCaster(); | ||
|
||
enum State : int32_t | ||
{ | ||
DERIVED_ATTRIBUTE = 0x0, | ||
ATTRIBUTE = 0x1, | ||
SKILL = 0x2, | ||
AI_ATTRIBUTE = 0x3, | ||
RESISTANCE = 0x4, | ||
CONDITION = 0x5, | ||
CHARGE = 0x6, | ||
INT_VALUE = 0x7, | ||
VARIABLE = 0x8, | ||
RESOURCE = 0x9, | ||
TYPE_COUNT = 0xA, | ||
}; | ||
|
||
GameArray<uint32_t> hSounds; | ||
int32_t hDesiredTarget; | ||
MagicItem* pCurrentSpell; | ||
MagicCaster::State eState; | ||
float fCastingTimer; | ||
float fCurrentSpellCost; | ||
float fMagnitudeOverride; | ||
float fNextTargetUpdate; | ||
float fProjectileTimer; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
#include <Forms/TESBoundObject.h> | ||
#include <Components/TESFullName.h> | ||
#include <Components/BGSKeywordForm.h> | ||
|
||
struct EffectItem; | ||
struct EffectSetting; | ||
|
||
struct MagicItem : TESBoundObject, TESFullName, BGSKeywordForm | ||
{ | ||
GameArray<EffectItem*> listOfEffects; | ||
int32_t iHostileCount; | ||
EffectSetting* pAVEffectSetting; | ||
uint32_t uiPreloadCount; | ||
void* spPreloadedItem; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#include "MagicTarget.h" | ||
|
||
#include <Actor.h> | ||
#include <Games/ActorExtension.h> | ||
#include <World.h> | ||
#include <Games/ActorExtension.h> | ||
#include "EffectItem.h" | ||
#include "EffectSetting.h" | ||
#include "MagicItem.h" | ||
|
||
#include <Events/AddTargetEvent.h> | ||
|
||
TP_THIS_FUNCTION(TAddTarget, bool, MagicTarget, MagicTarget::AddTargetData& arData); | ||
TP_THIS_FUNCTION(TCheckAddEffectTargetData, bool, MagicTarget::AddTargetData, void* arArgs, float afResistance); | ||
|
||
static TAddTarget* RealAddTarget = nullptr; | ||
static TCheckAddEffectTargetData* RealCheckAddEffectTargetData = nullptr; | ||
|
||
static thread_local bool s_autoSucceedEffectCheck = false; | ||
|
||
bool MagicTarget::AddTarget(AddTargetData& arData) noexcept | ||
{ | ||
s_autoSucceedEffectCheck = true; | ||
bool result = ThisCall(RealAddTarget, this, arData); | ||
s_autoSucceedEffectCheck = false; | ||
return result; | ||
} | ||
|
||
bool TP_MAKE_THISCALL(HookAddTarget, MagicTarget, MagicTarget::AddTargetData& arData) | ||
{ | ||
// TODO: this can be fixed by properly implementing multiple inheritance | ||
Actor* pTargetActor = (Actor*)((char*)apThis - 0x98); | ||
ActorExtension* pTargetActorEx = pTargetActor->GetExtension(); | ||
|
||
if (!pTargetActorEx) | ||
return ThisCall(RealAddTarget, apThis, arData); | ||
|
||
if (pTargetActorEx->IsLocalPlayer()) | ||
{ | ||
bool result = ThisCall(RealAddTarget, apThis, arData); | ||
if (result && arData.pEffectItem->pEffectSetting->eArchetype != EffectArchetypes::ArchetypeID::SUMMON_CREATURE) | ||
World::Get().GetRunner().Trigger(AddTargetEvent(pTargetActor->formID, arData.pSpell->formID)); | ||
return result; | ||
} | ||
else if (pTargetActorEx->IsRemotePlayer()) | ||
{ | ||
return false; | ||
} | ||
|
||
if (arData.pCaster) | ||
{ | ||
ActorExtension* pCasterExtension = arData.pCaster->GetExtension(); | ||
if (pCasterExtension->IsLocalPlayer()) | ||
{ | ||
bool result = ThisCall(RealAddTarget, apThis, arData); | ||
if (result && arData.pEffectItem->pEffectSetting->eArchetype != EffectArchetypes::ArchetypeID::SUMMON_CREATURE) | ||
World::Get().GetRunner().Trigger(AddTargetEvent(pTargetActor->formID, arData.pSpell->formID)); | ||
return result; | ||
} | ||
else if (pCasterExtension->IsRemotePlayer()) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
if (pTargetActorEx->IsLocal()) | ||
{ | ||
bool result = ThisCall(RealAddTarget, apThis, arData); | ||
if (result && arData.pEffectItem->pEffectSetting->eArchetype != EffectArchetypes::ArchetypeID::SUMMON_CREATURE) | ||
World::Get().GetRunner().Trigger(AddTargetEvent(pTargetActor->formID, arData.pSpell->formID)); | ||
return result; | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
bool TP_MAKE_THISCALL(HookCheckAddEffectTargetData, MagicTarget::AddTargetData, void* arArgs, float afResistance) | ||
{ | ||
if (s_autoSucceedEffectCheck) | ||
return true; | ||
|
||
return ThisCall(RealCheckAddEffectTargetData, apThis, arArgs, afResistance); | ||
} | ||
|
||
static TiltedPhoques::Initializer s_magicTargetHooks([]() { | ||
POINTER_FALLOUT4(TAddTarget, addTarget, 0x140C6C5E0 - 0x140000000); | ||
POINTER_FALLOUT4(TCheckAddEffectTargetData, checkAddEffectTargetData, 0x140C6D4F0 - 0x140000000); | ||
|
||
RealAddTarget = addTarget.Get(); | ||
RealCheckAddEffectTargetData = checkAddEffectTargetData.Get(); | ||
|
||
TP_HOOK(&RealAddTarget, HookAddTarget); | ||
TP_HOOK(&RealCheckAddEffectTargetData, HookCheckAddEffectTargetData); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#pragma once | ||
|
||
#include <Effects/ActiveEffect.h> | ||
#include <Games/Magic/MagicSystem.h> | ||
|
||
struct Actor; | ||
struct EffectItem; | ||
struct MagicItem; | ||
struct TESBoundObject; | ||
|
||
struct MagicTarget | ||
{ | ||
struct IPostCreationModification; | ||
struct ResultsCollector; | ||
|
||
struct AddTargetData | ||
{ | ||
Actor* pCaster; | ||
MagicItem* pSpell; | ||
EffectItem* pEffectItem; | ||
TESBoundObject* pSource; | ||
MagicTarget::IPostCreationModification* pCallback; | ||
MagicTarget::ResultsCollector* pResultsCollector; | ||
NiPoint3 ExplosionLocation; | ||
float fMagnitude; | ||
MagicSystem::CastingSource eCastingSource; | ||
bool bAreaTarget; | ||
bool bDualCast; | ||
}; | ||
|
||
struct SpellDispelData | ||
{ | ||
const MagicItem* pSpell; | ||
int32_t hCaster; | ||
GamePtr<ActiveEffect> spActiveEffect; | ||
SpellDispelData* pNext; | ||
}; | ||
|
||
enum Flag : int32_t | ||
{ | ||
MTF_UPDATING = 0x1, | ||
MTF_INVISIBLE = 0x2, | ||
}; | ||
|
||
virtual ~MagicTarget(); | ||
|
||
bool AddTarget(AddTargetData& arData) noexcept; | ||
// this function actually adds the effect | ||
bool CheckAddEffect(AddTargetData& arData) noexcept; | ||
|
||
SpellDispelData* pPostUpdateDispelList; | ||
Flag ucFlags; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
Code/client/Games/Skyrim/Misc/EffectItem.h → Code/client/Games/Skyrim/Magic/EffectItem.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
#pragma once | ||
|
||
struct EffectSetting; | ||
|
||
struct EffectItemData | ||
{ | ||
float fMagnitude; | ||
|
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
Code/client/Games/Skyrim/Misc/MagicCaster.h → Code/client/Games/Skyrim/Magic/MagicCaster.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
Code/client/Games/Skyrim/Misc/MagicTarget.h → Code/client/Games/Skyrim/Magic/MagicTarget.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.