Skip to content

Commit

Permalink
feat: PlayerCamera RE (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
powerof3 authored Sep 14, 2023
1 parent 16adc0b commit 66c8581
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 0 deletions.
19 changes: 19 additions & 0 deletions CommonLibSF/include/RE/B/BSInputEventReceiver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

namespace RE
{
class InputEvent;

class BSInputEventReceiver
{
public:
virtual ~BSInputEventReceiver() = default; // 00

// add
virtual void PerformInputProcessing(const InputEvent* a_queueHead) = 0; // 01

// members
std::uint32_t currInputTimeCount; // 08
};
static_assert(sizeof(BSInputEventReceiver) == 0x10);
}
86 changes: 86 additions & 0 deletions CommonLibSF/include/RE/P/PlayerCamera.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#pragma once

#include "RE/B/BSInputEventReceiver.h"
#include "RE/B/BSTEvent.h"
#include "RE/T/TESCamera.h"

namespace RE
{
class BSWorldOriginShiftEvent;
class OtherEventEnabledEvent;
class UserEventEnabledEvent;
struct IdleInputEvent;

namespace Spaceship
{
struct TakeOffEvent;
struct DockEvent;
struct LandedSetEvent;
}

struct CameraStates
{
enum CameraState : std::uint32_t
{
kFirstPerson = 0,
kAutoVanity,
kVATS,
kIronSights,
kPCTransition,
kTween,
kUnk06,
kFlightCamera,
kShipFarTravel,
kShipAction,
kShipTargeting,
kShipCombatOrbit,
kFreeWalk,
kFreeAdvanced,
kFreeFly,
kFreeTethered,
kDialogue,
kWorkshopIsometric,
kPhotoMode,
kThirdPerson,
kFurniture,
kHorse,
kBleedout
};
};
using CameraState = CameraStates::CameraState;

class PlayerCamera :
public TESCamera, // 00
public BSInputEventReceiver, // 48
public BSTEventSink<IdleInputEvent>, // 58
public BSTEventSink<UserEventEnabledEvent>, // 60
public BSTEventSink<OtherEventEnabledEvent>, // 68
public BSTEventSink<Spaceship::TakeOffEvent>, // 70
public BSTEventSink<Spaceship::DockEvent>, // 78
public BSTEventSink<Spaceship::LandedSetEvent>, // 80
public BSTEventSink<BSWorldOriginShiftEvent> // 88
{
public:
SF_RTTI_VTABLE(PlayerCamera);

~PlayerCamera() override; // 00

// override (TESCamera)
void SetCameraRoot(NiNode* a_root) override; // 01
void SetEnabled(bool a_enabled) override; // 02
void Unk_04() override; // 04

static PlayerCamera* GetSingleton();

void ForceFirstPerson();
void ForceThirdPerson();
bool IsInFirstPerson() const;
bool IsInThirdPerson() const;
void SetCameraState(CameraState a_cameraState);

// More...

private:
bool QCameraEquals(CameraState a_cameraState) const;
};
}
36 changes: 36 additions & 0 deletions CommonLibSF/include/RE/T/TESCamera.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

namespace RE
{
class NiNode;

class TESCamera
{
public:
SF_RTTI(TESCamera);

virtual ~TESCamera(); // 00

// add
virtual void SetCameraRoot(NiNode* a_cameraRoot); // 01
virtual void SetEnabled(bool a_enabled); // 02
virtual void Update(); // 03
virtual void Unk_04(); // 04

// members
void* cameraRoot; // 08 - NiPointer<NiNode>
void* currentState; // 10 - BSTSmartPointer<TESCameraState>
std::uint64_t unk18; // 18
bool enabled; // 20
float unk24; // 24
float unk28; // 28
float unk2C; // 2C
float unk30; // 30
float unk34; // 34
float unk38; // 38
float unk3C; // 3C
float unk40; // 40
std::uint32_t pad44; // 44
};
static_assert(sizeof(TESCamera) == 0x48);
}
48 changes: 48 additions & 0 deletions CommonLibSF/src/RE/P/PlayerCamera.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "RE/P/PlayerCamera.h"

namespace RE
{
PlayerCamera* PlayerCamera::GetSingleton()
{
REL::Relocation<PlayerCamera**> singleton{ REL::Offset(0x058F1978) };
return *singleton;
}

void PlayerCamera::ForceFirstPerson()
{
using func_t = decltype(&PlayerCamera::ForceFirstPerson);
REL::Relocation<func_t> func{ REL::Offset(0x0286A798) };
return func(this);
}

void PlayerCamera::ForceThirdPerson()
{
using func_t = decltype(&PlayerCamera::ForceThirdPerson);
REL::Relocation<func_t> func{ REL::Offset(0x0286A850) };
return func(this);
}

bool PlayerCamera::IsInFirstPerson() const
{
return QCameraEquals(CameraState::kFirstPerson);
}

bool PlayerCamera::IsInThirdPerson() const
{
return QCameraEquals(CameraState::kThirdPerson);
}

void PlayerCamera::SetCameraState(CameraState a_cameraState)
{
using func_t = decltype(&PlayerCamera::SetCameraState);
REL::Relocation<func_t> func{ REL::Offset(0x0286BCBC) };
return func(this, a_cameraState);
}

bool PlayerCamera::QCameraEquals(CameraState a_cameraState) const
{
using func_t = decltype(&PlayerCamera::QCameraEquals);
REL::Relocation<func_t> func{ REL::Offset(0x0286BDC8) };
return func(this, a_cameraState);
}
}
5 changes: 5 additions & 0 deletions CommonLibSF/src/RE/T/TESCamera.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "RE/T/TESCamera.h"
namespace RE
{
}

0 comments on commit 66c8581

Please sign in to comment.