Skip to content

Commit

Permalink
feat: equip sync works for real now
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbeBryssinck committed Nov 14, 2021
1 parent 6f69da9 commit c8e324f
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 21 deletions.
8 changes: 7 additions & 1 deletion Code/client/Games/Fallout4/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <Games/References.h>
#include <PlayerCharacter.h>
#include <Games/Fallout4/EquipManager.h>
#include <Forms/BGSObjectInstance.h>

#include <Services/PapyrusService.h>
#include <World.h>
Expand Down Expand Up @@ -158,7 +159,12 @@ void Actor::SetInventory(const Inventory& acInventory) noexcept
uint32_t mainHandWeaponId = modSystem.GetGameId(acInventory.RightHandWeapon);

if (mainHandWeaponId)
pEquipManager->Equip(this, TESForm::GetById(mainHandWeaponId), 0, 1, nullptr, false, true, false, false);
{
TESForm* pWeapon = TESForm::GetById(mainHandWeaponId);
BGSObjectInstance object(pWeapon, nullptr);
const BGSEquipSlot* pSlot = GetEquipSlot(0);
pEquipManager->EquipObject(this, object, 0, 1, pSlot, false, true, false, true, false);
}
}

void Actor::SetActorValues(const ActorValues& acActorValues) noexcept
Expand Down
50 changes: 32 additions & 18 deletions Code/client/Games/Fallout4/EquipManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <EquipManager.h>
#include <Games/References.h>
#include <Games/Overrides.h>
#include <Forms/BGSObjectInstance.h>

#include <Events/EquipmentChangeEvent.h>

Expand Down Expand Up @@ -37,26 +38,36 @@ EquipManager* EquipManager::Get() noexcept
return *s_singleton.Get();
}

void* EquipManager::Equip(Actor* apActor, TESForm* apItem, uint32_t aUnk1, uint32_t aCount, void* aSlot, bool aUnk2, bool aPreventEquip, bool aUnk3, bool aUnk4)
TP_THIS_FUNCTION(TEquipObject, bool, EquipManager, Actor* apActor, BGSObjectInstance& arObject, uint32_t auiStackID, uint32_t auiNumber, const BGSEquipSlot* apSlot, bool abQueueEquip, bool abForceEquip, bool abPlaySounds, bool abApplyNow, bool abLocked);
//TEquipObject* RealEquipObject = nullptr;

bool EquipManager::EquipObject(Actor* apActor, BGSObjectInstance& arObject, uint32_t auiStackID, uint32_t auiNumber, const BGSEquipSlot* apSlot, bool abQueueEquip, bool abForceEquip, bool abPlaySounds, bool abApplyNow, bool abLocked)
{
TP_THIS_FUNCTION(TEquipInternal, void*, EquipManager, Actor* apActor, TESForm* apItem, uint32_t aUnk1, uint32_t aCount, void* aSlot, bool aUnk2, bool aPreventEquip, bool aUnk3, bool aUnk4);
POINTER_FALLOUT4(TEquipInternal, s_equipFunc, 0x140E1BCC0 - 0x140000000);
POINTER_FALLOUT4(TEquipObject, equipObject, 0x140E1BCD0 - 0x140000000);

ScopedEquipOverride equipOverride;

const auto result = ThisCall(s_equipFunc, this, apActor, apItem, aUnk1, aCount, aSlot, aUnk2, aPreventEquip, aUnk3, aUnk4);
const auto result = ThisCall(equipObject, this, apActor, arObject, auiStackID, auiNumber, apSlot, abQueueEquip, abForceEquip, abPlaySounds, abApplyNow, abLocked);

return result;
}

void* EquipManager::UnEquip(Actor* apActor, TESForm* apItem, int aCount, void* aSlot, int aUnk1, bool aPreventEquip, bool aUnk2, bool aUnk3, bool aUnk4, void* aUnk5)
/*
bool TP_MAKE_THISCALL(EquipObjectHook, EquipManager, Actor* apActor, BGSObjectInstance& arObject, uint32_t auiStackID, uint32_t auiNumber, const BGSEquipSlot* apSlot, bool abQueueEquip, bool abForceEquip, bool abPlaySounds, bool abApplyNow, bool abLocked)
{
return ThisCall(RealEquipObject, apThis, apActor, arObject, auiStackID, auiNumber, apSlot, abQueueEquip,
abForceEquip, abPlaySounds, abApplyNow, abLocked);
}
*/

bool EquipManager::UnequipObject(Actor* apActor, BGSObjectInstance& arObject, uint32_t auiNumber, const BGSEquipSlot* apSlot, uint32_t auiStackID, bool abQueueEquip, bool abForceEquip, bool abPlaySounds, bool abApplyNow, const BGSEquipSlot* apSlotBeingReplaced)
{
TP_THIS_FUNCTION(TUnEquipInternal, void*, EquipManager, Actor* apActor, TESForm* apItem, int aCount, void* aSlot, int aUnk1, bool aPreventEquip, bool aUnk2, bool aUnk3, bool aUnk4, void* aUnk5);
POINTER_FALLOUT4(TUnEquipInternal, s_unequipFunc, 0x140E1C0A0 - 0x140000000);
TP_THIS_FUNCTION(TUnequipObject, bool, EquipManager, Actor* apActor, BGSObjectInstance& arObject, uint32_t auiNumber, const BGSEquipSlot* apSlot, uint32_t auiStackID, bool abQueueEquip, bool abForceEquip, bool abPlaySounds, bool abApplyNow, const BGSEquipSlot* apSlotBeingReplaced);
POINTER_FALLOUT4(TUnequipObject, unequipObject, 0x140E1C0B0 - 0x140000000);

ScopedEquipOverride equipOverride;

const auto result = ThisCall(s_unequipFunc, this, apActor, apItem, aCount, aSlot, aUnk1, aPreventEquip, aUnk2, aUnk3, aUnk4, aUnk5);
const auto result = ThisCall(unequipObject, this, apActor, arObject, auiNumber, apSlot, auiStackID, abQueueEquip, abForceEquip, abPlaySounds, abApplyNow, apSlotBeingReplaced);

return result;
}
Expand Down Expand Up @@ -105,13 +116,16 @@ void* TP_MAKE_THISCALL(UnEquipHook, EquipManager, Actor* apActor, TESForm* apIte
}

static TiltedPhoques::Initializer s_equipmentHooks([]()
{
POINTER_FALLOUT4(TEquip, s_equipFunc, 0x140E1EB40 - 0x140000000);
POINTER_FALLOUT4(TUnEquip, s_unequipFunc, 0x140E20390 - 0x140000000);

RealUnEquip = s_unequipFunc.Get();
RealEquip = s_equipFunc.Get();

TP_HOOK(&RealUnEquip, UnEquipHook);
TP_HOOK(&RealEquip, EquipHook);
});
{
POINTER_FALLOUT4(TEquip, s_equipFunc, 0x140E1EB50 - 0x140000000);
POINTER_FALLOUT4(TUnEquip, s_unequipFunc, 0x140E203A0 - 0x140000000);
//POINTER_FALLOUT4(TEquipObject, equipObject, 0x140E1BCD0 - 0x140000000);

RealUnEquip = s_unequipFunc.Get();
RealEquip = s_equipFunc.Get();
//RealEquipObject = equipObject.Get();

TP_HOOK(&RealUnEquip, UnEquipHook);
TP_HOOK(&RealEquip, EquipHook);
//TP_HOOK(&RealEquipObject, EquipObjectHook);
});
6 changes: 4 additions & 2 deletions Code/client/Games/Fallout4/EquipManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
struct TESForm;
struct BSExtraDataList;
struct Actor;
struct BGSObjectInstance;
struct BGSEquipSlot;

struct EquipManager
{
static EquipManager* Get() noexcept;

void* Equip(Actor* apActor, TESForm* apItem, uint32_t aUnk1, uint32_t aCount, void* aSlot, bool aUnk2, bool aPreventEquip, bool aUnk3, bool aUnk4);
void* UnEquip(Actor* apActor, TESForm* apItem, int aCount, void* aSlot, int aUnk1, bool aPreventEquip, bool aUnk2, bool aUnk3, bool aUnk4, void* aUnk5);
bool EquipObject(Actor* apActor, BGSObjectInstance& arObject, uint32_t auiStackID, uint32_t auiNumber, const BGSEquipSlot* apSlot, bool abQueueEquip, bool abForceEquip, bool abPlaySounds, bool abApplyNow, bool abLocked);
bool UnequipObject(Actor* apActor, BGSObjectInstance& arObject, uint32_t auiNumber, const BGSEquipSlot* apSlot, uint32_t auiStackID, bool abQueueEquip, bool abForceEquip, bool abPlaySounds, bool abApplyNow, const BGSEquipSlot* apSlotBeingReplaced);
};
10 changes: 10 additions & 0 deletions Code/client/Games/Fallout4/Forms/BGSObjectInstance.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "BGSObjectInstance.h"

BGSObjectInstance::BGSObjectInstance(TESForm* apObject, TBO_InstanceData* apInstanceData)
{
TP_THIS_FUNCTION(TBGSObjectInstance, void, BGSObjectInstance, TESForm* apObject, TBO_InstanceData* apInstanceData);

POINTER_FALLOUT4(TBGSObjectInstance, bgsObjectInstance, 0x1402F7B50 - 0x140000000);

ThisCall(bgsObjectInstance, this, apObject, apInstanceData);
}
14 changes: 14 additions & 0 deletions Code/client/Games/Fallout4/Forms/BGSObjectInstance.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

struct TESForm;
struct TBO_InstanceData;

class BGSObjectInstance
{
public:
BGSObjectInstance(TESForm* apObject, TBO_InstanceData* apInstanceData);

TESForm* pObject;
void* spInstanceData; // BSTSmartPointer<TBO_InstanceData,BSTSmartPointerIntrusiveRefCount> spInstanceData;
};

9 changes: 9 additions & 0 deletions Code/client/Games/Fallout4/TESObjectREFR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ ActorValueInfo* TESObjectREFR::GetActorValueInfo(uint32_t aId) noexcept
return actorValueInfoArray[aId];
}

const BGSEquipSlot* TESObjectREFR::GetEquipSlot(uint32_t aEquipIndex) const noexcept
{
TP_THIS_FUNCTION(TGetEquipSlot, const BGSEquipSlot*, const TESObjectREFR, uint32_t);

POINTER_FALLOUT4(TGetEquipSlot, getEquipSlot, 0x1403FE4F0 - 0x140000000);

return ThisCall(getEquipSlot, this, aEquipIndex);
}

void TESObjectREFR::Activate(TESObjectREFR* apActivator, TESBoundObject* apObjectToGet, int32_t aCount, bool aDefaultProcessing, bool aFromScript, bool aIsLooping) noexcept
{
return ThisCall(RealActivate, this, apActivator, apObjectToGet, aCount, aDefaultProcessing, aFromScript, aIsLooping);
Expand Down
2 changes: 2 additions & 0 deletions Code/client/Games/Fallout4/TESObjectREFR.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct BSFaceGenNiNode;
struct TESObjectCELL;
struct AnimationVariables;
struct TESBoundObject;
struct BGSEquipSlot;

struct TESObjectREFR : TESForm
{
Expand Down Expand Up @@ -149,6 +150,7 @@ struct TESObjectREFR : TESForm
BSExtraDataList* GetExtraDataList() noexcept;
ActorValueInfo* GetActorValueInfo(uint32_t aId) noexcept;
Lock* GetLock() noexcept;
const BGSEquipSlot* GetEquipSlot(uint32_t uiIndex) const noexcept;

void SaveAnimationVariables(AnimationVariables& aWriter) const noexcept;
void SaveInventory(BGSSaveFormBuffer* apBuffer) const noexcept;
Expand Down

0 comments on commit c8e324f

Please sign in to comment.