Skip to content

Commit

Permalink
WIP: disable input processing during open UI
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbeBryssinck committed May 25, 2022
1 parent 4513476 commit ce22b92
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 26 deletions.
25 changes: 25 additions & 0 deletions Code/client/Games/Skyrim/AI/Movement/PlayerControls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,29 @@ PlayerControls* PlayerControls::GetInstance()
return *(s_instance.Get());
}

void PlayerControls::SetEnabled(bool abFlag)
{
TP_THIS_FUNCTION(TSetEnabled, void, PlayerControls, bool);
POINTER_SKYRIMSE(TSetEnabled, setEnabled, 42345);
ThisCall(setEnabled, this, abFlag);
}

void PlayerControls::SetCamSwitch(bool aSet) noexcept
{
Data.remapMode = aSet;
}

BSInputEnableManager* BSInputEnableManager::Get()
{
POINTER_SKYRIMSE(BSInputEnableManager*, s_instance, 400863);
return *(s_instance.Get());
}

void BSInputEnableManager::EnableOtherEvent(int32_t aFlags, bool aEnable, bool aUnk2)
{
TP_THIS_FUNCTION(TSetEnabled, void, BSInputEnableManager, int32_t, bool, bool);
POINTER_SKYRIMSE(TSetEnabled, setEnabled, 68545);
ThisCall(setEnabled, this, aFlags, aEnable, aUnk2);
}

//static TiltedPhoques::Initializer s_Init([]() { TiltedPhoques::Put<uint8_t>(0x14072E490, 0xCC); });
47 changes: 33 additions & 14 deletions Code/client/Games/Skyrim/AI/Movement/PlayerControls.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

#include "Games/Primitives.h"

struct PlayerInputHandler
{
virtual ~PlayerInputHandler();

bool isEnabled;
};

struct PlayerControlsData
{
// members
Expand All @@ -27,13 +34,17 @@ struct PlayerControlsData

struct PlayerControls
{
PlayerControls* GetInstance();
static PlayerControls* GetInstance();

void SetBlockPlayerInput(bool abFlag)
{
bBlockPlayerInput = abFlag;
}

void SetEnabled(bool abFlag);

void SetCamSwitch(bool aSet) noexcept;

public:
char pad0[0x20];
PlayerControlsData Data;
Expand All @@ -49,23 +60,31 @@ struct PlayerControls
float unk100[20]; // 100
GameArray<void*> actionInterestedActor; // 150
char actorArrayLock[8]; // 168
void* pMovementHandler; // 170
void* pLookHandler; // 178
void* pSprintHandler; // 180
void* pReadyWeaponHandler; // 188
void* pAutoMoveHandler; // 190
void* pToggleRunHandler; // 198
void* pActivateHandler; // 1A0
void* pJumpHandler; // 1A8
void* shoutHandler; // 1B0
void* attackBlockHandler; // 1B8
void* runHandler; // 1C0
void* sneakHandler; // 1C8
void* togglePOVHandler; // 1D0
PlayerInputHandler* pMovementHandler; // 170
PlayerInputHandler* pLookHandler; // 178
PlayerInputHandler* pSprintHandler; // 180
PlayerInputHandler* pReadyWeaponHandler; // 188
PlayerInputHandler* pAutoMoveHandler; // 190
PlayerInputHandler* pToggleRunHandler; // 198
PlayerInputHandler* pActivateHandler; // 1A0
PlayerInputHandler* pJumpHandler; // 1A8
PlayerInputHandler* shoutHandler; // 1B0
PlayerInputHandler* attackBlockHandler; // 1B8
PlayerInputHandler* runHandler; // 1C0
PlayerInputHandler* sneakHandler; // 1C8
PlayerInputHandler* togglePOVHandler; // 1D0
bool bNotifyingHandlers; // 1D8
bool bBlockPlayerInput; // 1D9
std::uint16_t unk1DA; // 1DA
std::uint32_t unk1DC; // 1DC
};

static_assert(offsetof(PlayerControls, PlayerControls::bBlockPlayerInput) == 0x1D9);
static_assert(offsetof(PlayerControls, PlayerControls::Data) == 0x20);

struct BSInputEnableManager
{
static BSInputEnableManager* Get();

void EnableOtherEvent(int32_t aFlags, bool aEnable, bool aUnk2);
};
25 changes: 25 additions & 0 deletions Code/client/Games/Skyrim/Camera/PlayerCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ PlayerCamera* PlayerCamera::Get() noexcept
return *(s_instance.Get());
}

bool PlayerCamera::IsFirstPerson() noexcept
{
TP_THIS_FUNCTION(TIsFirstPerson, void, PlayerCamera, void*, void*, double*);
POINTER_SKYRIMSE(TIsFirstPerson, isFirstPerson, 21600);

double firstPerson = 0.0;
ThisCall(isFirstPerson, this, nullptr, nullptr, &firstPerson);

return firstPerson == 1.0;
}

bool PlayerCamera::WorldPtToScreenPt3(const NiPoint3& in, NiPoint3& out, float zeroTolerance /* = 1e-5f */)
{
auto* pCam = GetNiCamera();
Expand All @@ -19,3 +30,17 @@ bool PlayerCamera::WorldPtToScreenPt3(const NiPoint3& in, NiPoint3& out, float z

return false;
}

void PlayerCamera::ForceFirstPerson() noexcept
{
TP_THIS_FUNCTION(TForceFirstPerson, void, PlayerCamera);
POINTER_SKYRIMSE(TForceFirstPerson, forceFirstPerson, 50790);
ThisCall(forceFirstPerson, this);
}

void PlayerCamera::ForceThirdPerson() noexcept
{
TP_THIS_FUNCTION(TForceThirdPerson, void, PlayerCamera);
POINTER_SKYRIMSE(TForceThirdPerson, forceThirdPerson, 50796);
ThisCall(forceThirdPerson, this);
}
7 changes: 5 additions & 2 deletions Code/client/Games/Skyrim/Camera/PlayerCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

struct PlayerCamera : public TESCamera
{
virtual ~PlayerCamera() = default;

static PlayerCamera* Get() noexcept;

bool IsFirstPerson() noexcept;

bool WorldPtToScreenPt3(const NiPoint3& in, NiPoint3& out, float zeroTolerance = 1e-5f);

void ForceFirstPerson() noexcept;
void ForceThirdPerson() noexcept;

float rotZ;
float rotX;
NiPoint3 pos;
Expand Down
6 changes: 3 additions & 3 deletions Code/client/Games/Skyrim/Camera/TESCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ struct TESCameraState;

struct TESCamera
{
virtual ~TESCamera() = default;
virtual ~TESCamera() {};

virtual void SetNode(NiNode* node) = 0;
virtual void Update() = 0;
virtual void SetNode(NiNode* node) {};
virtual void Update() {};

NiCamera* GetNiCamera();

Expand Down
28 changes: 21 additions & 7 deletions Code/client/Services/Debug/DebugService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <Games/TES.h>

#include <AI/AIProcess.h>
#include <AI/Movement/PlayerControls.h>

#include <Messages/RequestRespawn.h>

Expand All @@ -46,6 +47,7 @@

#include <Games/Misc/SubtitleManager.h>
#include <Games/Overrides.h>
#include <Camera/PlayerCamera.h>

#if TP_SKYRIM64
#include <EquipManager.h>
Expand Down Expand Up @@ -164,16 +166,28 @@ void DebugService::OnUpdate(const UpdateEvent& acUpdateEvent) noexcept
if (!s_f8Pressed)
{
s_f8Pressed = true;
if (m_actors.empty())
PlaceActorInWorld();

#if 0
static bool s_enabled = true;
static bool s_firstPerson = false;

auto* pCamera = PlayerCamera::Get();
auto* pPlayerControls = PlayerControls::GetInstance();

if (s_enabled)
{
s_firstPerson = pCamera->IsFirstPerson();
pCamera->ForceFirstPerson();
}
else
{
ScopedSpellCastOverride _;
auto pActor = m_actors[0];
pActor->GenerateMagicCasters();
pActor->casters[0]->CastSpellImmediate(Cast<MagicItem>(TESForm::GetById(0x27EB6)),
false, nullptr, 1.f, false, 0.f);
s_firstPerson ? pCamera->ForceFirstPerson() : pCamera->ForceThirdPerson();
}

pPlayerControls->SetCamSwitch(s_enabled);

s_enabled = !s_enabled;
#endif
}
}
else
Expand Down

0 comments on commit ce22b92

Please sign in to comment.