Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: spell damage #681

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Code/client/Events/AddTargetEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ struct AddTargetEvent
AddTargetEvent() = default;

uint32_t TargetID{};
uint32_t CasterID{};
uint32_t SpellID{};
uint32_t EffectID{};
float Magnitude{};
Expand Down
4 changes: 3 additions & 1 deletion Code/client/Games/Skyrim/Effects/ActiveEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ struct ActiveEffect

static ActiveEffect* Instantiate(Actor* apCaster, MagicItem* apSpell, EffectItem* apEffect);

uint8_t pad8[0x38];
uint8_t pad8[0x34 - 0x8];
uint32_t hCaster;
NiNode* pSourceNode;
MagicItem* pSpell;
void* pEffect;
MagicTarget* pTarget;
Expand Down
1 change: 1 addition & 0 deletions Code/client/Games/Skyrim/Magic/MagicTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ bool TP_MAKE_THISCALL(HookAddTarget, MagicTarget, MagicTarget::AddTargetData& ar

AddTargetEvent addTargetEvent{};
addTargetEvent.TargetID = pTargetActor->formID;
addTargetEvent.CasterID = arData.pCaster ? arData.pCaster->formID : 0;
addTargetEvent.SpellID = arData.pSpell->formID;
addTargetEvent.EffectID = arData.pEffectItem->pEffectSetting->formID;
addTargetEvent.Magnitude = arData.fMagnitude;
Expand Down
6 changes: 5 additions & 1 deletion Code/client/Games/Skyrim/Projectiles/Projectile.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ struct Projectile : TESObjectREFR
bool bForceConeOfFire; // unsure // usually false
};

uint8_t unk98[0xF0];
uint8_t unkA0[0x120 - sizeof(TESObjectREFR)];
void* pActorCause;
uint32_t hShooter;
uint8_t unk[0x190 - 0x12C];
float fPower;
float fSpeedMult;
float fRange;
Expand All @@ -60,3 +63,4 @@ struct Projectile : TESObjectREFR
};

static_assert(sizeof(Projectile::LaunchData) == 0xA8);
static_assert(offsetof(Projectile, fPower) == 0x190);
16 changes: 16 additions & 0 deletions Code/client/Services/Generic/MagicService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,20 @@ void MagicService::OnAddTargetEvent(const AddTargetEvent& acEvent) noexcept
}

request.TargetId = serverIdRes.value();

const auto casterIt = std::find_if(std::begin(view), std::end(view), [id = acEvent.CasterID, view](auto entity) { return view.get<FormIdComponent>(entity).Id == id; });

if (casterIt == std::end(view))
{
spdlog::warn("Form id not found for magic add target, form id: {:X}", acEvent.CasterID);
m_queuedEffects[acEvent.TargetID] = request;
return;
}

serverIdRes = Utils::GetServerId(*casterIt);
if (serverIdRes.has_value())
request.CasterId = serverIdRes.value();

request.IsDualCasting = acEvent.IsDualCasting;
request.ApplyHealPerkBonus = acEvent.ApplyHealPerkBonus;
request.ApplyStaminaPerkBonus = acEvent.ApplyStaminaPerkBonus;
Expand Down Expand Up @@ -411,6 +425,8 @@ void MagicService::OnNotifyAddTarget(const NotifyAddTarget& acMessage) noexcept
if (pEffect->IsSlowEffect())
pActor = PlayerCharacter::Get();

data.pCaster = Utils::GetByServerId<Actor>(acMessage.CasterId);

pActor->magicTarget.AddTarget(data, acMessage.ApplyHealPerkBonus, acMessage.ApplyStaminaPerkBonus);

spdlog::debug("Applied remote magic effect");
Expand Down
2 changes: 2 additions & 0 deletions Code/encoding/Messages/AddTargetRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
void AddTargetRequest::SerializeRaw(TiltedPhoques::Buffer::Writer& aWriter) const noexcept
{
Serialization::WriteVarInt(aWriter, TargetId);
Serialization::WriteVarInt(aWriter, CasterId);
SpellId.Serialize(aWriter);
EffectId.Serialize(aWriter);
Serialization::WriteFloat(aWriter, Magnitude);
Expand All @@ -16,6 +17,7 @@ void AddTargetRequest::DeserializeRaw(TiltedPhoques::Buffer::Reader& aReader) no
ClientMessage::DeserializeRaw(aReader);

TargetId = Serialization::ReadVarInt(aReader) & 0xFFFFFFFF;
CasterId = Serialization::ReadVarInt(aReader) & 0xFFFFFFFF;
SpellId.Deserialize(aReader);
EffectId.Deserialize(aReader);
Magnitude = Serialization::ReadFloat(aReader);
Expand Down
3 changes: 2 additions & 1 deletion Code/encoding/Messages/AddTargetRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ struct AddTargetRequest final : ClientMessage

bool operator==(const AddTargetRequest& acRhs) const noexcept
{
return GetOpcode() == acRhs.GetOpcode() && TargetId == acRhs.TargetId && SpellId == acRhs.SpellId &&
return GetOpcode() == acRhs.GetOpcode() && TargetId == acRhs.TargetId && CasterId == acRhs.CasterId && SpellId == acRhs.SpellId &&
EffectId == acRhs.EffectId && Magnitude == acRhs.Magnitude && IsDualCasting == acRhs.IsDualCasting &&
ApplyHealPerkBonus == acRhs.ApplyHealPerkBonus && ApplyStaminaPerkBonus == acRhs.ApplyStaminaPerkBonus;
}

uint32_t TargetId{};
uint32_t CasterId{};
GameId SpellId{};
GameId EffectId{};
float Magnitude{};
Expand Down
2 changes: 2 additions & 0 deletions Code/encoding/Messages/NotifyAddTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
void NotifyAddTarget::SerializeRaw(TiltedPhoques::Buffer::Writer& aWriter) const noexcept
{
Serialization::WriteVarInt(aWriter, TargetId);
Serialization::WriteVarInt(aWriter, CasterId);
SpellId.Serialize(aWriter);
EffectId.Serialize(aWriter);
Serialization::WriteFloat(aWriter, Magnitude);
Expand All @@ -16,6 +17,7 @@ void NotifyAddTarget::DeserializeRaw(TiltedPhoques::Buffer::Reader& aReader) noe
ServerMessage::DeserializeRaw(aReader);

TargetId = Serialization::ReadVarInt(aReader) & 0xFFFFFFFF;
CasterId = Serialization::ReadVarInt(aReader) & 0xFFFFFFFF;
SpellId.Deserialize(aReader);
EffectId.Deserialize(aReader);
Magnitude = Serialization::ReadFloat(aReader);
Expand Down
3 changes: 2 additions & 1 deletion Code/encoding/Messages/NotifyAddTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ struct NotifyAddTarget final : ServerMessage

bool operator==(const NotifyAddTarget& acRhs) const noexcept
{
return GetOpcode() == acRhs.GetOpcode() && TargetId == acRhs.TargetId && SpellId == acRhs.SpellId &&
return GetOpcode() == acRhs.GetOpcode() && TargetId == acRhs.TargetId && CasterId == acRhs.CasterId && SpellId == acRhs.SpellId &&
EffectId == acRhs.EffectId && Magnitude == acRhs.Magnitude && IsDualCasting == acRhs.IsDualCasting &&
ApplyHealPerkBonus == acRhs.ApplyHealPerkBonus && ApplyStaminaPerkBonus == acRhs.ApplyStaminaPerkBonus;
}

uint32_t TargetId{};
uint32_t CasterId{};
GameId SpellId{};
GameId EffectId{};
float Magnitude{};
Expand Down
1 change: 1 addition & 0 deletions Code/server/Services/MagicService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ void MagicService::OnAddTargetRequest(const PacketEvent<AddTargetRequest>& acMes

NotifyAddTarget notify;
notify.TargetId = message.TargetId;
notify.CasterId = message.CasterId;
notify.SpellId = message.SpellId;
notify.EffectId = message.EffectId;
notify.Magnitude = message.Magnitude;
Expand Down
Loading