-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: serializing custom enchantments
- Loading branch information
1 parent
57ed4f1
commit 0bc2e1b
Showing
8 changed files
with
145 additions
and
15 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,12 @@ | ||
#pragma once | ||
|
||
#include "TESForm.h" | ||
|
||
struct BGSListForm : TESForm | ||
{ | ||
GameArray<TESForm*> ArrayOfForms{}; | ||
GameArray<uint32_t>* pScriptAddedTempFormA{}; | ||
uint32_t iScriptAddedFormCount{}; | ||
}; | ||
|
||
static_assert(sizeof(BGSListForm) == 0x48); |
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,6 +1,61 @@ | ||
#include "EnchantmentItem.h" | ||
|
||
#include <Systems/ModSystem.h> | ||
#include <Magic/EffectItem.h> | ||
#include <World.h> | ||
|
||
EnchantmentItem* EnchantmentItem::Create(const Container::EnchantmentData& aData) noexcept | ||
{ | ||
TP_THIS_FUNCTION(TCreateNewEnchantment, EnchantmentItem*, GameArray<EffectItem*>, bool abIsWeapon); | ||
POINTER_SKYRIMSE(TCreateNewEnchantment, createNewEnchantment, 0x1405C1290 - 0x140000000); | ||
|
||
ModSystem& modSystem = World::Get().GetModSystem(); | ||
|
||
GameArray<EffectItem*> effects{}; | ||
for (Container::EffectItem effect : aData.Effects) | ||
{ | ||
EffectItem* pEffectItem = new EffectItem; | ||
pEffectItem->data.fMagnitude = effect.Magnitude; | ||
pEffectItem->data.iArea = effect.Area; | ||
pEffectItem->data.iDuration = effect.Duration; | ||
pEffectItem->fRawCost = effect.RawCost; | ||
pEffectItem->pEffectSetting = | ||
RTTI_CAST(TESForm::GetById(modSystem.GetGameId(effect.EffectId)), TESForm, EffectSetting); | ||
if (!pEffectItem->pEffectSetting) | ||
spdlog::error("Effect setting not found: {:X}:{:X}", effect.EffectId.ModId, effect.EffectId.BaseId); | ||
} | ||
|
||
EnchantmentItem* pItem = ThisCall(createNewEnchantment, &effects, aData.IsWeapon); | ||
|
||
for (EffectItem* pEffectItem : effects) | ||
delete pEffectItem; | ||
|
||
return pItem; | ||
} | ||
|
||
void EnchantmentItem::Init(const Container::EnchantmentData& aData) | ||
{ | ||
/* | ||
iCostOverride = aData.CostOverride; | ||
iFlags = aData.Flags; | ||
eCastingType = static_cast<MagicSystem::CastingType>(aData.CastingType); | ||
iChargeOverride = aData.ChargeOverride; | ||
eDelivery = static_cast<MagicSystem::Delivery>(aData.Delivery); | ||
eSpellType = static_cast<MagicSystem::SpellType>(aData.SpellType); | ||
fChargeTime = aData.ChargeTime; | ||
ModSystem& modSystem = World::Get().GetModSystem(); | ||
TP_ASSERT(aData.BaseEnchantmentId.ModId != 0xFFFFFFFF, "Base enchantment is a temporary!"); | ||
uint32_t baseEnchantId = modSystem.GetGameId(aData.BaseEnchantmentId); | ||
pBaseEnchantment = RTTI_CAST(TESForm::GetById(baseEnchantId), TESForm, EnchantmentItem); | ||
if (!pBaseEnchantment) | ||
spdlog::error("{}: base enchantment not found.", __FUNCTION__); | ||
TP_ASSERT(aData.WornRestrictionsId.ModId != 0xFFFFFFFF, "Worn restrictions is a temporary!"); | ||
uint32_t restrictionsId = modSystem.GetGameId(aData.WornRestrictionsId); | ||
pWornRestrictions = RTTI_CAST(TESForm::GetById(restrictionsId), TESForm, BGSListForm); | ||
if (!pWornRestrictions) | ||
spdlog::error("{}: worn restrictions not found.", __FUNCTION__); | ||
*/ | ||
} |
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,19 +1,27 @@ | ||
#pragma once | ||
|
||
#include "TESForm.h" | ||
#include "MagicItem.h" | ||
|
||
#include <Structs/Container.h> | ||
#include <Games/Magic/MagicSystem.h> | ||
#include "BGSListForm.h" | ||
|
||
struct EnchantmentItem : TESForm | ||
struct EnchantmentItem : MagicItem | ||
{ | ||
static EnchantmentItem* Create(const Container::EnchantmentData& aData) noexcept; | ||
|
||
void Init(const Container::EnchantmentData& aData); | ||
|
||
int32_t iCostOverride; | ||
int32_t iFlags; | ||
MagicSystem::CastingType eCastingType; | ||
int32_t iChargeOverride; | ||
MagicSystem::Delivery eDelivery; | ||
MagicSystem::SpellType eSpellType; | ||
float fChargeTime; | ||
EnchantmentItem* pBaseEnchantment; | ||
void* pWornRestrictions; | ||
// TODO: use BGSListForm::SaveGame() and BGSListForm::LoadGame()? | ||
BGSListForm* pWornRestrictions; | ||
}; | ||
|
||
static_assert(sizeof(EnchantmentItem) == 0xC0); |
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