Skip to content

Commit

Permalink
fix: invisibility
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbeBryssinck committed May 24, 2022
1 parent d711783 commit b1b233f
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Code/client/Games/Skyrim/Actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct Actor : TESObjectREFR
virtual void sub_C0();
virtual void sub_C1();
virtual void sub_C2();
virtual void sub_C3();
virtual void SetRefraction(bool aEnable, float aRefraction);
virtual void sub_C4();
virtual void sub_C5();
virtual void sub_C6();
Expand Down Expand Up @@ -99,7 +99,7 @@ struct Actor : TESObjectREFR
virtual void sub_DD();
virtual void sub_DE();
virtual void PutCreatedPackage(struct TESPackage*, bool = false, bool = true, bool = true); // 14069BBF0
virtual void sub_E0();
virtual void UpdateAlpha();
virtual void sub_E1();
virtual void sub_E2();
virtual void sub_E3();
Expand Down
32 changes: 32 additions & 0 deletions Code/client/Games/Skyrim/Effects/InvisibilityEffect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "InvisibilityEffect.h"

#include <Games/ActorExtension.h>
#include <Forms/ActorValueInfo.h>

TP_THIS_FUNCTION(TFinish, void, InvisibilityEffect);
static TFinish* RealFinish = nullptr;

// This needs to be done because the actor value does not update in time
void TP_MAKE_THISCALL(HookFinish, InvisibilityEffect)
{
if (apThis && apThis->pTarget)
{
if (Actor* pActor = apThis->pTarget->GetTargetAsActor())
{
if (pActor->GetExtension()->IsRemote())
pActor->SetActorValue(ActorValueInfo::kInvisibility, 0.f);
}
}

ThisCall(RealFinish, apThis);
}

static TiltedPhoques::Initializer s_invisibilityEffectsHooks([]()
{
POINTER_SKYRIMSE(TFinish, s_finish, 34370);

RealFinish = s_finish.Get();

TP_HOOK(&RealFinish, HookFinish);
});

7 changes: 7 additions & 0 deletions Code/client/Games/Skyrim/Effects/InvisibilityEffect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include "ValueModifierEffect.h"

struct InvisibilityEffect : ValueModifierEffect
{
};
13 changes: 8 additions & 5 deletions Code/client/Games/Skyrim/Magic/MagicTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ bool MagicTarget::AddTargetData::ShouldSync()
!pSpell->IsWardSpell();
}

Actor* MagicTarget::GetTargetAsActor()
{
TP_THIS_FUNCTION(TGetTargetAsActor, Actor*, MagicTarget);
POINTER_SKYRIMSE(TGetTargetAsActor, getTargetAsActor, 34529);
return ThisCall(getTargetAsActor, this);
}

// If you want a detailed flowchart of what's happening here, ask cosi
bool TP_MAKE_THISCALL(HookAddTarget, MagicTarget, MagicTarget::AddTargetData& arData)
{
spdlog::info("HookAddTarget");

// TODO: this can be fixed by properly implementing multiple inheritance
Actor* pTargetActor = (Actor*)((uint8_t*)apThis - 0x98);
Actor* pTargetActor = apThis->GetTargetAsActor();
ActorExtension* pTargetActorEx = pTargetActor->GetExtension();

if (!pTargetActorEx)
Expand All @@ -56,7 +60,6 @@ bool TP_MAKE_THISCALL(HookAddTarget, MagicTarget, MagicTarget::AddTargetData& ar
if (arData.pEffectItem->IsVampireLordEffect())
pTargetActorEx->GraphDescriptorHash = AnimationGraphDescriptor_VampireLordBehavior::m_key;

// TODO(cosideci): maybe call MagicTarget::AddTarget()?
if (ScopedSpellCastOverride::IsOverriden())
return ThisCall(RealAddTarget, apThis, arData);

Expand Down
2 changes: 2 additions & 0 deletions Code/client/Games/Skyrim/Magic/MagicTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ struct MagicTarget

virtual ~MagicTarget();

Actor* GetTargetAsActor();

bool AddTarget(AddTargetData& arData) noexcept;
// this function actually adds the effect
bool CheckAddEffect(AddTargetData& arData) noexcept;
Expand Down
13 changes: 8 additions & 5 deletions Code/client/Services/Debug/Views/FormDebugView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

void DebugService::DrawFormDebugView()
{
static TESObjectREFR* pRefr = nullptr;
static Actor* pRefr = nullptr;
static TESForm* pFetchForm = nullptr;

ImGui::Begin("Form");
Expand All @@ -27,7 +27,7 @@ void DebugService::DrawFormDebugView()
{
pFetchForm = TESForm::GetById(m_formId);
if (pFetchForm)
pRefr = Cast<TESObjectREFR>(pFetchForm);
pRefr = Cast<Actor>(pFetchForm);
}
}

Expand All @@ -39,12 +39,13 @@ void DebugService::DrawFormDebugView()

if (pRefr)
{
/*
char name[256];
sprintf_s(name, std::size(name), "%s (%x)", pRefr->baseForm->GetName(), pRefr->formID);
ImGui::InputText("Name", name, std::size(name), ImGuiInputTextFlags_ReadOnly);
*/

/*
for (ActiveEffect* pEffect : *pActor->currentProcess->middleProcess->ActiveEffects)
for (ActiveEffect* pEffect : *pRefr->currentProcess->middleProcess->ActiveEffects)
{
if (!pEffect)
continue;
Expand All @@ -56,8 +57,10 @@ void DebugService::DrawFormDebugView()
ImGui::InputFloat("Duration", &pEffect->fDuration, 0, 0, "%.1f", ImGuiInputTextFlags_ReadOnly);
ImGui::InputFloat("Magnitude", &pEffect->fMagnitude, 0, 0, "%.1f", ImGuiInputTextFlags_ReadOnly);
ImGui::InputInt("Flags", (int*)&pEffect->uiFlags, 0, 0, ImGuiInputTextFlags_ReadOnly);

if (ImGui::Button("Elapse time"))
m_world.GetRunner().Queue([pEffect]() { pEffect->fElapsedSeconds = pEffect->fDuration - 3.f; });
}
*/
}

ImGui::End();
Expand Down

0 comments on commit b1b233f

Please sign in to comment.