#pragma once
#include <Windows.h>
#include <stdint.h>
#include <string>
#include <atomic>

class DriverInterfaceV3 {
public:
    DriverInterfaceV3();
    ~DriverInterfaceV3();

    bool Initialize();
    void Cleanup();

    DWORD GetProcessId(const wchar_t* processName);
    uintptr_t GetModuleBase(DWORD pid, const wchar_t* moduleName);

    bool ReadMemory(DWORD pid, uintptr_t address, void* buffer, size_t size);
    bool WriteMemory(DWORD pid, uintptr_t address, void* buffer, size_t size);

    void SetCurrentPid(DWORD pid);
    uintptr_t GetProcessCr3(DWORD pid);
    void SetCr3(uintptr_t cr3);
    
    // 缓存相关的字段
    uintptr_t GetCachedCr3() const { return currentCr3; }
    void UpdateCr3();

    void TestRandomMouseMoveLoop(std::atomic<bool>& running);

    // Mouse functions required by aimbot/triggerbot
    bool InjectMouseClick(int key = VK_LBUTTON);
    void InjectMouseMove(float x, float y);

    // Some drivers use these for mouse movement, if not supported by HK, we stub them
    void SetMouseSignature(int x, int y);
    bool MoveMouse(float x, float y);

    // HK Specific methods if needed
    void ProtectProcess(DWORD pid);
    void KillProcess(DWORD pid);

private:
    HANDLE hDriver = INVALID_HANDLE_VALUE;
    DWORD currentPid = 0;
    uintptr_t currentCr3 = 0;
    float mouseXRemainder = 0.0f;
    float mouseYRemainder = 0.0f;
};
