this program needs alot of adjutments as it dont do as it should offsets found i nthis otta point to the string in ida when searched i think but it dont #include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <tlhelp32.h>
#include <string>
#include <ctime>
#include <psapi.h>

// Function to log messages
void log_message(FILE* log_file, const char* format, ...) {
    va_list args;
    va_start(args, format);
    vprintf(format, args);
    if (log_file != NULL) {
        vfprintf(log_file, format, args);
        fflush(log_file);
    }
    va_end(args);
}

// Function to get process ID by name
DWORD get_process_id_by_name(const char* process_name) {
    PROCESSENTRY32 pe32;
    HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

    if (hSnapshot == INVALID_HANDLE_VALUE) {
        return 0;
    }

    pe32.dwSize = sizeof(PROCESSENTRY32);
    if (!Process32First(hSnapshot, &pe32)) {
        CloseHandle(hSnapshot);
        return 0;
    }

    do {
        char exeFile[MAX_PATH];
        int result = WideCharToMultiByte(CP_ACP, 0, pe32.szExeFile, -1, exeFile, MAX_PATH, NULL, NULL);
        if (result == 0) {
            CloseHandle(hSnapshot);
            return 0;
        }

        if (_stricmp(exeFile, process_name) == 0) {
            CloseHandle(hSnapshot);
            return pe32.th32ProcessID;
        }
    } while (Process32Next(hSnapshot, &pe32));

    CloseHandle(hSnapshot);
    return 0;
}

// Function to get the base address of a module in a given process
unsigned long long get_base_address(DWORD pid, const char* module_name) {
    MODULEENTRY32 me32;
    HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, pid);

    if (hSnapshot == INVALID_HANDLE_VALUE) {
        return 0;
    }

    me32.dwSize = sizeof(MODULEENTRY32);
    if (!Module32First(hSnapshot, &me32)) {
        CloseHandle(hSnapshot);
        return 0;
    }

    unsigned long long base_address = 0;

    do {
        char modName[MAX_PATH];
        if (WideCharToMultiByte(CP_ACP, 0, me32.szModule, -1, modName, MAX_PATH, NULL, NULL) != 0 &&
            _stricmp(modName, module_name) == 0) {
            base_address = (unsigned long long)me32.modBaseAddr;
            break;
        }
    } while (Module32Next(hSnapshot, &me32));

    CloseHandle(hSnapshot);
    return base_address;
}

// Function to get the start and end addresses of a section
bool get_section_limits(HANDLE hProcess, unsigned long long base_addr, const char* section_name, unsigned long long& section_start, unsigned long long& section_end) {
    IMAGE_DOS_HEADER dos_header;
    if (!ReadProcessMemory(hProcess, (LPCVOID)base_addr, &dos_header, sizeof(dos_header), NULL)) {
        return false;
    }

    if (dos_header.e_magic != IMAGE_DOS_SIGNATURE) {
        return false;
    }

    IMAGE_NT_HEADERS nt_headers;
    if (!ReadProcessMemory(hProcess, (LPCVOID)(base_addr + dos_header.e_lfanew), &nt_headers, sizeof(nt_headers), NULL)) {
        return false;
    }

    if (nt_headers.Signature != IMAGE_NT_SIGNATURE) {
        return false;
    }

    IMAGE_SECTION_HEADER* section_headers = new IMAGE_SECTION_HEADER[nt_headers.FileHeader.NumberOfSections];
    if (!ReadProcessMemory(hProcess, (LPCVOID)((unsigned long long)(base_addr + dos_header.e_lfanew) + sizeof(nt_headers)), section_headers, sizeof(IMAGE_SECTION_HEADER) * nt_headers.FileHeader.NumberOfSections, NULL)) {
        delete[] section_headers;
        return false;
    }

    for (int i = 0; i < nt_headers.FileHeader.NumberOfSections; ++i) {
        if (strncmp((char*)section_headers[i].Name, section_name, IMAGE_SIZEOF_SHORT_NAME) == 0) {
            section_start = base_addr + section_headers[i].VirtualAddress;
            section_end = section_start + section_headers[i].Misc.VirtualSize;
            delete[] section_headers;
            return true;
        }
    }

    delete[] section_headers;
    return false;
}

// Function to find a string in a section
unsigned long long find_string_in_section(HANDLE hProcess, unsigned long long section_start, unsigned long long section_end, const char* string_to_search) {
    unsigned long long string_addr = 0;
    unsigned long long addr = section_start;
    SIZE_T string_length = strlen(string_to_search);

    while (addr < section_end) {
        MEMORY_BASIC_INFORMATION mbi;
        if (!VirtualQueryEx(hProcess, (LPCVOID)addr, &mbi, sizeof(mbi))) {
            break;
        }

        char* buffer = new (std::nothrow) char[mbi.RegionSize];
        if (!buffer) {
            break;
        }

        SIZE_T bytesRead;
        if (ReadProcessMemory(hProcess, (LPCVOID)addr, buffer, mbi.RegionSize, &bytesRead) && bytesRead > 0) {
            for (SIZE_T i = 0; i < bytesRead - string_length; i++) {
                if (memcmp(buffer + i, string_to_search, string_length) == 0) {
                    string_addr = addr + i;
                    delete[] buffer;
                    return string_addr;
                }
            }
        }

        delete[] buffer;
        addr += mbi.RegionSize;
    }

    return 0;
}

// Function to find a reference to a string in the data section
unsigned long long find_reference_in_data_section(HANDLE hProcess, unsigned long long section_start, unsigned long long section_end, unsigned long long string_addr) {
    unsigned long long addr = section_start;

    while (addr < section_end) {
        MEMORY_BASIC_INFORMATION mbi;
        if (!VirtualQueryEx(hProcess, (LPCVOID)addr, &mbi, sizeof(mbi))) {
            break;
        }

        unsigned long long* buffer = new (std::nothrow) unsigned long long[mbi.RegionSize / sizeof(unsigned long long)];
        if (!buffer) {
            break;
        }

        SIZE_T bytesRead;
        if (ReadProcessMemory(hProcess, (LPCVOID)addr, buffer, mbi.RegionSize, &bytesRead) && bytesRead > 0) {
            for (SIZE_T i = 0; i < (bytesRead / sizeof(unsigned long long)); i++) {
                if (buffer[i] == string_addr) {
                    unsigned long long reference_addr = addr + i * sizeof(unsigned long long);
                    delete[] buffer;
                    return reference_addr;
                }
            }
        }

        delete[] buffer;
        addr += mbi.RegionSize;
    }

    return 0;
}

// Main function
int main() {
    const char* process_name = "notepadexe";
    const char* module_name = "notepad.exe";
    const char* gameSettings[] = {
        "fVATSMaxChance",
        "fVATSChancePerceptionMultiplier",
        "fVATSMaxEngageDistance",
        "fVATSChanceRaycastVisibilityMininmum",
        "fVATSPingCost",
        "fVATSCriticalChargeBase",
        "fVATSCriticalChargeBonusMult",
        "fVATSCriticalChargeLimit",
        "fVATSCriticalChargeMult",
        "fPlayerAutoReloadDelaySec",
        "bDisablePlayerCollision",
        "fAVDCarryWeightBase",
        "fAbsolutePlayerInventoryWeightLimit",
        "fInvisibilityMaxRefraction",
        "fInvisibilityMinRefraction",
        "fJetpackThrustInitial",
        "fJetpackThrustSustained",
        "fJetpackTimeToSustained",
        "bJetpackInitialThrustOnlyOnTakeoff",
        "fAimStabilityCrouchedScopeMult",
        "fPropModScaleWeapDurability",
        "fLockpickSkillSweetSpotBase",
        "fSweetSpotEasy",
        "fSweetSpotAverage",
        "fSweetSpotHard",
        "fSweetSpotVeryHard",
        "iHackingMinWords",
        "iHackingMaxWords",
        "fCombatMusicNearCombatInnerRadius",
        "fCombatMusicNearCombatOuterRadius",
        "fCombatMusicPlayerTargetedThreatRatio",
        "pkKeywords",
        "fAttackActionPointCost",
        "fspeed",
        "fweight",
        "iDurability",
        "ihealth",
        "bHoldInputToPower",
        "fMinPowerPerShot",
        "poAmmo",
        "paAimModel",
        "ppOverrideProjectile",
        "uNumProjectiles",
        "vaActorValues",
        "ihealth"
    };

    FILE* log_file;
    if (fopen_s(&log_file, "memscan.log", "w") != 0) {
        printf("Could not open log file for writing\n");
        return 1;
    }

    DWORD pid = get_process_id_by_name(process_name);
    if (pid == 0) {
        printf("Could not find process\n");
        fclose(log_file);
        return 1;
    }

    unsigned long long base_addr = get_base_address(pid, module_name);
    if (base_addr == 0) {
        printf("Could not find base address\n");
        fclose(log_file);
        return 1;
    }

    HANDLE hProcess = OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, FALSE, pid);
    if (hProcess == NULL) {
        printf("Could not open process\n");
        fclose(log_file);
        return 1;
    }

    unsigned long long rdata_section_start, rdata_section_end;
    if (!get_section_limits(hProcess, base_addr, ".rdata", rdata_section_start, rdata_section_end)) {
        printf("Could not find .rdata section\n");
        CloseHandle(hProcess);
        fclose(log_file);
        return 1;
    }

    unsigned long long data_section_start, data_section_end;
    if (!get_section_limits(hProcess, base_addr, ".data", data_section_start, data_section_end)) {
        printf("Could not find .data section\n");
        CloseHandle(hProcess);
        fclose(log_file);
        return 1;
    }

    fprintf(log_file, "$gameSettings = [\n");

    for (const char* string_to_search : gameSettings) {
        unsigned long long string_addr = find_string_in_section(hProcess, rdata_section_start, rdata_section_end, string_to_search);
        if (string_addr == 0) {
            printf("String not found: %s\n", string_to_search);
            continue;
        }

        unsigned long long reference_addr = find_reference_in_data_section(hProcess, data_section_start, data_section_end, string_addr);
        if (reference_addr == 0) {
            printf("Reference not found for string: %s\n", string_to_search);
            continue;
        }

        // Adjust by 0x10 as originally intended
        unsigned long long function_pointer = reference_addr - 0x10;
        unsigned long long offset = function_pointer - base_addr;
        fprintf(log_file, "    \"%s\" => 0x%llx,\n", string_to_search, offset);
    }

    fprintf(log_file, "];\n");

    CloseHandle(hProcess);
    fclose(log_file);
    return 0;
}