#include <windows.h>
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>

int main() {
    DWORD pid = 43084;
    HANDLE h = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
    if (!h) {
        std::cerr << "Cannot open process\n";
        return 1;
    }

    uintptr_t modBase = 0x7FF6AFC20000;
    uintptr_t textStart = modBase + 0x1000;
    size_t textSize = 0x2E85000;

    std::vector<uint8_t> code(textSize);
    SIZE_T bytesRead = 0;
    if (!ReadProcessMemory(h, (LPCVOID)textStart, code.data(), textSize, &bytesRead)) {
        std::cerr << "Cannot read .text\n";
        return 1;
    }

    std::cout << "Read " << bytesRead << " bytes of .text\n";

    struct Target {
        const char* name;
        uintptr_t addr;
    };

    Target targets[] = {
        {"Minimap_Visibility", 0x7ff6b2da9200},
        {"RenderVisibility", 0x7ff6b2da9218},
        {"revealed_bound", 0x7ff6b2da9250},
        {"use_revealed_bound", 0x7ff6b2da9290},
        {"visibility_walkable_revealed", 0x7ff6b2da92a8},
        {"visibility_fully_revealed", 0x7ff6b2da92c8},
        {"Minimap Visibility", 0x7ff6b2da92e8},
        {"FogOfWar", 0x7ff6b2dad670},
        {"Minimap Walkability", 0x7ff6b2da9768},
        {"Minimap", 0x7ff6b2da9568},
        {"Minimap_Poi", 0x7ff6b2da9440}
    };
    const size_t numTargets = sizeof(targets) / sizeof(targets[0]);

    for (size_t i = 0; i < code.size() - 8; ++i) {
        // Look for 48 8D ?? [disp32] or 4C 8D ?? [disp32] or other LEA/MOV
        if (code[i+1] == 0x8D || code[i+1] == 0x8B) {
            uint8_t modrm = code[i+2];
            if ((modrm & 0xC7) == 0x05) {
                int32_t disp = *(int32_t*)&code[i+3];
                uintptr_t nextInstr = textStart + i + 7;
                uintptr_t targetAddr = nextInstr + disp;

                for (size_t t = 0; t < numTargets; ++t) {
                    if (targetAddr == targets[t].addr) {
                        uintptr_t instrAddr = textStart + i;
                        std::cout << "MATCH: [" << targets[t].name << "] at 0x" << std::hex << instrAddr
                                  << " (RVA: +0x" << (instrAddr - modBase) << ")\n";
                    }
                }
            }
        }
    }

    CloseHandle(h);
    return 0;
}
