Skip to content

Commit

Permalink
feat: Smarter input handling for skyrim.
Browse files Browse the repository at this point in the history
  • Loading branch information
Force67 committed Dec 28, 2021
1 parent f9491fe commit 68e188b
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 12 deletions.
20 changes: 16 additions & 4 deletions Code/client/Games/Skyrim/BSGraphics/BSGraphicsRenderer.cpp
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@

#include "Systems/RenderSystemD3D11.h"
#include "Services/InputService.h"

#include "World.h"

#include "BSGraphics/BSGraphicsRenderer.h"

namespace BSGraphics
{
static RenderSystemD3D11* g_sRs = nullptr;
static WNDPROC RealWndProc = nullptr;

void (*Renderer_Init)(Renderer*, BSGraphics::RendererInitOSData*, const BSGraphics::ApplicationWindowProperties*,
BSGraphics::RendererInitReturn*) = nullptr;

// WNDPROC seems to be part of the renderer
LRESULT CALLBACK Hook_WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (InputService::WndProc(hwnd, uMsg, wParam, lParam) != 0)
return 0;

return RealWndProc(hwnd, uMsg, wParam, lParam);
}

void Hook_Renderer_Init(Renderer* self, BSGraphics::RendererInitOSData* aOSData,
const BSGraphics::ApplicationWindowProperties* aFBData, BSGraphics::RendererInitReturn* aOut)
{
// Append our window name.
aOSData->pClassName = "ST Anniversary | " BUILD_BRANCH "@" BUILD_COMMIT;

WNDPROC gameProc = aOSData->pWndProc;
RealWndProc = aOSData->pWndProc;
aOSData->pWndProc = Hook_WndProc;

Renderer_Init(self, aOSData, aFBData, aOut);

auto& rs = World::Get().ctx<RenderSystemD3D11>();
g_sRs = &rs;
g_sRs = &World::Get().ctx<RenderSystemD3D11>();
// This how the game does it too
rs.OnDeviceCreation(self->Data.RenderWindowA[0].pSwapChain);
g_sRs->OnDeviceCreation(self->Data.RenderWindowA[0].pSwapChain);
}

void (*StopTimer)(int) = nullptr;
Expand Down
13 changes: 13 additions & 0 deletions Code/client/Games/Skyrim/Interface/MenuControls.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

#include "Interface/MenuControls.h"

void MenuControls::SetToggle(bool b)
{
canBeOpened = b;
}

MenuControls* MenuControls::GetInstance()
{
POINTER_SKYRIMSE(MenuControls*, s_instance, 0x142F9AB08 - 0x140000000);
return *(s_instance.Get());
}
18 changes: 18 additions & 0 deletions Code/client/Games/Skyrim/Interface/MenuControls.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

class MenuControls
{
public:
static MenuControls* GetInstance();

void SetToggle(bool);

private:
char pad_0000[128]; // 0x0000
bool isProcessing; // 0x0080
bool isBeastForm; // 0x0081
bool isRemapMode; // 0x0082
bool canBeOpened; // 0x0083
char pad_0084[12]; // 0x0084
}; // Size: 0x0090
static_assert(sizeof(MenuControls) == 0x90);
14 changes: 9 additions & 5 deletions Code/client/Services/Generic/InputService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@
#include <Services/DiscordService.h>
#include <World.h>

#include "Games/Skyrim/Interface/MenuControls.h"

static OverlayService* s_pOverlay = nullptr;

void ForceKillAllInput()
{
MenuControls::GetInstance()->SetToggle(false);

}

uint32_t GetCefModifiers(uint16_t aVirtualKey)
{
uint32_t modifiers = EVENTFLAG_NONE;
Expand Down Expand Up @@ -278,7 +286,7 @@ void ProcessMouseWheel(uint16_t aX, uint16_t aY, int16_t aZ)
}
}

static LRESULT CALLBACK InputServiceWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK InputService::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
const auto pApp = s_pOverlay->GetOverlayApp();
if (!pApp)
Expand Down Expand Up @@ -392,14 +400,10 @@ static LRESULT CALLBACK InputServiceWndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
InputService::InputService(OverlayService& aOverlay) noexcept
{
s_pOverlay = &aOverlay;

TiltedPhoques::WindowsHook::Get().SetCallback(InputServiceWndProc);
}

InputService::~InputService() noexcept
{
TiltedPhoques::WindowsHook::Get().SetCallback(nullptr);

s_pOverlay = nullptr;
}

2 changes: 2 additions & 0 deletions Code/client/Services/InputService.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ struct InputService
InputService(OverlayService& aOverlay) noexcept;
~InputService() noexcept;

static LRESULT WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

TP_NOCOPYMOVE(InputService);
};
1 change: 0 additions & 1 deletion Code/client/TiltedOnlineApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ void TiltedOnlineApp::InstallHooks2()
TiltedPhoques::Initializer::RunAll();

TiltedPhoques::DInputHook::Install();
TiltedPhoques::WindowsHook::Install();
}

void TiltedOnlineApp::UninstallHooks()
Expand Down
3 changes: 1 addition & 2 deletions Code/immersive_launcher/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ int main(int argc, char** argv)
return -1;
}
PreloadSystemDlls();
CoreStubsInit();

CoreStubsInit();
ComScope cs;
TP_UNUSED(cs);

Expand Down

0 comments on commit 68e188b

Please sign in to comment.