95 lines
No EOL
2.4 KiB
C++
95 lines
No EOL
2.4 KiB
C++
#include "pch.h"
|
|
#include "Dependencies/nexus/Nexus.h"
|
|
#include <Windows.h>
|
|
|
|
AddonAPI* g_api = nullptr;
|
|
|
|
struct {
|
|
bool enabled = false;
|
|
} g_state;
|
|
|
|
void HandleKeybind(const char* identifier, bool isRelease) {
|
|
if (!isRelease && g_state.enabled) {
|
|
POINT currentPos;
|
|
GetCursorPos(¤tPos);
|
|
|
|
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
|
|
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
|
|
int centerX = screenWidth / 2;
|
|
int centerY = screenHeight / 2;
|
|
|
|
if (currentPos.x != centerX || currentPos.y != centerY) {
|
|
BlockInput(TRUE);
|
|
SetCursorPos(centerX, centerY);
|
|
Sleep(1);
|
|
BlockInput(FALSE);
|
|
}
|
|
|
|
if (g_api) {
|
|
g_api->GameBinds.InvokeAsync(EGameBinds_CameraActionMode, 50);
|
|
}
|
|
}
|
|
}
|
|
|
|
void Load(AddonAPI* api) {
|
|
g_api = api;
|
|
g_state.enabled = true;
|
|
|
|
if (g_api) {
|
|
g_api->Log(ELogLevel_INFO, "CursorAnchor", "Loading addon...");
|
|
|
|
Keybind kb;
|
|
kb.Key = 0;
|
|
kb.Alt = false;
|
|
kb.Ctrl = false;
|
|
kb.Shift = false;
|
|
|
|
g_api->InputBinds.RegisterWithStruct("CursorAnchor.Center", HandleKeybind, kb);
|
|
|
|
g_api->Log(ELogLevel_INFO, "CursorAnchor", "Addon loaded successfully");
|
|
}
|
|
}
|
|
|
|
void Unload() {
|
|
if (g_api) {
|
|
g_api->InputBinds.Deregister("CursorAnchor.Center");
|
|
g_api->Log(ELogLevel_INFO, "CursorAnchor", "Addon unloaded successfully");
|
|
g_api = nullptr;
|
|
}
|
|
g_state.enabled = false;
|
|
}
|
|
|
|
extern "C" __declspec(dllexport) AddonDefinition* GetAddonDef() {
|
|
static AddonDefinition def;
|
|
def.Signature = -424242;
|
|
def.APIVersion = NEXUS_API_VERSION;
|
|
def.Name = "CursorAnchor";
|
|
def.Version.Major = 1;
|
|
def.Version.Minor = 0;
|
|
def.Version.Build = 0;
|
|
def.Version.Revision = 0;
|
|
def.Author = "Azrub";
|
|
def.Description = "Centers cursor when toggling action camera";
|
|
def.Load = Load;
|
|
def.Unload = Unload;
|
|
def.Flags = EAddonFlags_None;
|
|
def.Provider = EUpdateProvider_Direct;
|
|
def.UpdateLink = "https://git.azrub.dev/azrub/CursorAnchor/releases/download/latest/CursorAnchor.dll";
|
|
return &def;
|
|
}
|
|
|
|
BOOL APIENTRY DllMain(HMODULE hModule,
|
|
DWORD ul_reason_for_call,
|
|
LPVOID lpReserved
|
|
)
|
|
{
|
|
switch (ul_reason_for_call)
|
|
{
|
|
case DLL_PROCESS_ATTACH:
|
|
case DLL_THREAD_ATTACH:
|
|
case DLL_THREAD_DETACH:
|
|
case DLL_PROCESS_DETACH:
|
|
break;
|
|
}
|
|
return TRUE;
|
|
} |