Skip to content

Commit

Permalink
fix(): Don't crash & actually work, itd be great thank you
Browse files Browse the repository at this point in the history
  • Loading branch information
ATXLtheAxolotl committed Jan 7, 2024
1 parent 4c09904 commit 1db61a6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/FovManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ FovManager::FovManager() {
}

uintptr_t FovManager::getAddress() {
if(hProcess == nullptr) {
if(hProcess == 0) {
DWORD procId = GetProcessIdByName(L"Minecraft.Windows.exe");
hProcess = OpenProcess(PROCESS_ALL_ACCESS, NULL, procId);
}
Expand Down Expand Up @@ -44,13 +44,13 @@ void FovManager::tick() {

void FovManager::zoomIn() {
float fov = getFov();
if(fov <= 30) return setFov(30);
if(fov <= 30) return;

float rate = (initialFov - 30) / 20;
setFov(fov - rate);
}

bool zoomingOut;
bool zoomingOut = false;
void FovManager::zoomOut() {
float fov = getFov();
if(fov >= initialFov) { zoomingOut = false; return; };
Expand Down
4 changes: 2 additions & 2 deletions src/FovManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
class FovManager {
private:
__bfloat16 initialFov;
HANDLE hProcess;
bool zoom;
HANDLE hProcess = 0;
bool zoom = false;

uintptr_t getAddress();
public:
Expand Down
3 changes: 2 additions & 1 deletion src/MemoryUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "MemoryUtils.h"
#include "amethyst/Log.h"

uintptr_t FindDMAAddy(HANDLE hProc, uintptr_t ptr, std::vector<unsigned int> offsets) {
uintptr_t addr = ptr;
Expand All @@ -12,8 +13,8 @@ uintptr_t FindDMAAddy(HANDLE hProc, uintptr_t ptr, std::vector<unsigned int> off
}

DWORD GetProcessIdByName(const wchar_t* processName) {
DWORD processId = 0;
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
DWORD processId = 0;

if (snapshot != INVALID_HANDLE_VALUE) {
PROCESSENTRY32 processEntry;
Expand Down
9 changes: 4 additions & 5 deletions src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,24 @@
#define ModFunction extern "C" __declspec(dllexport)

static ClientInstance* gameClient = nullptr;
FovManager* fovManager = nullptr;
FovManager* fovManager = new FovManager();
HookManager hookManager;

ModFunction void RegisterInputs(InputManager* inputManager) { inputManager->RegisterInput("zoom", 0x43); }

ModFunction void Initialize(const char* gameVersion, InputManager* inputManager) {
MH_Initialize();

fovManager = new FovManager();
inputManager->AddButtonDownHandler("zoom", [](FocusImpact fi, IClientInstance ci) { fovManager->buttonDown(); });
inputManager->AddButtonUpHandler("zoom", [](FocusImpact fi, IClientInstance ci) { fovManager->buttonUp(); });
}

ModFunction void OnTickAfter() { if(gameClient != nullptr) fovManager->tick(); }
ModFunction void OnStartJoinGame(ClientInstance* instance) { gameClient = instance; }
ModFunction void OnTickAfter() { fovManager->tick(); }
ModFunction void Shutdown() {
fovManager->resetFov();
hookManager.Shutdown();
free(fovManager);

hookManager.Shutdown();
}

BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { return TRUE; }

0 comments on commit 1db61a6

Please sign in to comment.