fix this so the logs are clear only log the ecpecteed results and offsets #include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <tlhelp32.h>
#include <psapi.h>
#include <new>

// Function to log messages
void log_message(FILE* log_file, const wchar_t* format, ...) {
    va_list args;
    va_start(args, format);
    vfwprintf(log_file, format, args);
    fflush(log_file);
    va_end(args);
}

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

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

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

    do {
        if (_wcsicmp(pe32.szExeFile, process_name) == 0) {
            CloseHandle(hSnapshot);
            return pe32.th32ProcessID;
        }
    } while (Process32NextW(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 wchar_t* module_name) {
    MODULEENTRY32W me32;
    HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, pid);

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

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

    unsigned long long base_address = 0;

    do {
        if (_wcsicmp(me32.szModule, module_name) == 0) {
            base_address = (unsigned long long)me32.modBaseAddr;
            break;
        }
    } while (Module32NextW(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)) {
        printf("Failed to read DOS header. Error: %lu\n", GetLastError());
        return false;
    }

    IMAGE_NT_HEADERS64 nt_headers;
    if (!ReadProcessMemory(hProcess, (LPCVOID)(base_addr + dos_header.e_lfanew), &nt_headers, sizeof(nt_headers), NULL)) {
        printf("Failed to read NT headers. Error: %lu\n", GetLastError());
        return false;
    }

    unsigned long long section_offset = base_addr + dos_header.e_lfanew + sizeof(IMAGE_NT_HEADERS64);
    DWORD section_count = nt_headers.FileHeader.NumberOfSections;
    IMAGE_SECTION_HEADER* section_headers = new (std::nothrow) IMAGE_SECTION_HEADER[section_count];
    if (!section_headers) {
        printf("Failed to allocate memory for section headers\n");
        return false;
    }

    if (!ReadProcessMemory(hProcess, (LPCVOID)section_offset, section_headers, sizeof(IMAGE_SECTION_HEADER) * section_count, NULL)) {
        printf("Failed to read section headers. Error: %lu\n", GetLastError());
        delete[] section_headers;
        return false;
    }

    bool found = false;
    for (DWORD i = 0; i < section_count; i++) {
        if (strncmp((char*)section_headers[i].Name, section_name, IMAGE_SIZEOF_SHORT_NAME) == 0) {
            section_start = base_addr + section_headers[i].VirtualAddress;
            DWORD aligned_size = section_headers[i].Misc.VirtualSize;
            if (aligned_size % nt_headers.OptionalHeader.SectionAlignment != 0) {
                aligned_size = (aligned_size + nt_headers.OptionalHeader.SectionAlignment - 1) & ~(nt_headers.OptionalHeader.SectionAlignment - 1);
            }
            section_end = section_start + aligned_size;

            printf("Found section %s:\n", section_name);
            printf("  Virtual Address: 0x%llx\n", section_headers[i].VirtualAddress);
            printf("  Virtual Size: 0x%x\n", section_headers[i].Misc.VirtualSize);
            printf("  Raw Size: 0x%x\n", section_headers[i].SizeOfRawData);
            printf("  Characteristics: 0x%x\n", section_headers[i].Characteristics);
            printf("  Calculated Start: 0x%llx\n", section_start);
            printf("  Calculated End: 0x%llx\n", section_end);

            found = true;
            break;
        }
    }

    delete[] section_headers;
    return found;
}

unsigned long long find_string_in_section(HANDLE hProcess, unsigned long long section_start, unsigned long long section_end, const char* string_to_search) {
    SIZE_T string_length = strlen(string_to_search);
    unsigned long long addr = section_start;
    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) {
            printf("Memory allocation failed for buffer\n");
            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) {
                    unsigned long long string_addr = addr + i;
                    delete[] buffer;
                    return string_addr;
                }
            }
        }

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

    return 0;
}

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) {
            printf("Memory allocation failed for reference buffer\n");
            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 wchar_t* process_name = L"Fallout76.exe";
    const wchar_t* module_name = L"Fallout76.exe";

    const unsigned long long EXPECTED_RDATA_START = 0x143DC64E0;
    const unsigned long long EXPECTED_RDATA_END = 0x1457AF000;
    const unsigned long long EXPECTED_DATA_START = 0x1457AF000;
    const unsigned long long EXPECTED_DATA_END = 0x146FB0000;

    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 (_wfopen_s(&log_file, L"memscan.log", L"w") != 0) {
        wprintf(L"Could not open log file for writing\n");
        return 1;
    }

    DWORD pid = get_process_id_by_name(process_name);
    if (pid == 0) {
        fprintf(log_file, "Process not found\n");
        fclose(log_file);
        return 1;
    }
    fprintf(log_file, "Process ID: %lu\n", pid);

    HANDLE hProcess = OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, FALSE, pid);
    if (hProcess == NULL) {
        fprintf(log_file, "Failed to open process. Error: %lu\n", GetLastError());
        fclose(log_file);
        return 1;
    }

    unsigned long long base_addr = get_base_address(pid, module_name);
    if (base_addr == 0) {
        fprintf(log_file, "Failed to get base address\n");
        CloseHandle(hProcess);
        fclose(log_file);
        return 1;
    }
    fprintf(log_file, "Base address: 0x%llx\n", base_addr);

    unsigned long long rdata_start, rdata_end;
    unsigned long long data_start, data_end;

    if (!get_section_limits(hProcess, base_addr, ".rdata", rdata_start, rdata_end)) {
        fprintf(log_file, "Failed to get .rdata section limits\n");
        CloseHandle(hProcess);
        fclose(log_file);
        return 1;
    }

    if (!get_section_limits(hProcess, base_addr, ".data", data_start, data_end)) {
        fprintf(log_file, "Failed to get .data section limits\n");
        CloseHandle(hProcess);
        fclose(log_file);
        return 1;
    }

    fprintf(log_file, "\nSection Address Comparison:\n");
    fprintf(log_file, ".rdata section:\n");
    fprintf(log_file, "  Expected: 0x%llx - 0x%llx\n", EXPECTED_RDATA_START, EXPECTED_RDATA_END);
    fprintf(log_file, "  Found:    0x%llx - 0x%llx\n", rdata_start, rdata_end);

    fprintf(log_file, ".data section:\n");
    fprintf(log_file, "  Expected: 0x%llx - 0x%llx\n", EXPECTED_DATA_START, EXPECTED_DATA_END);
    fprintf(log_file, "  Found:    0x%llx - 0x%llx\n", data_start, data_end);

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

    for (const char* string_to_search : gameSettings) {
        fprintf(log_file, "Searching for: %s\n", string_to_search);

        unsigned long long string_addr = find_string_in_section(hProcess, rdata_start, rdata_end, string_to_search);

        if (string_addr != 0) {
            fprintf(log_file, "String found at: 0x%llx\n", string_addr);

            unsigned long long reference_addr = find_reference_in_data_section(hProcess, data_start, data_end, string_addr);

            if (reference_addr != 0) {
                unsigned long long offset = reference_addr - base_addr + 0x140000000;
                fprintf(log_file, "    \"%s\" => 0x%llx,\n", string_to_search, offset);
            }
            else {
                fprintf(log_file, "No reference found for string: %s\n", string_to_search);
            }
        }
        else {
            fprintf(log_file, "String not found: %s\n", string_to_search);
        }
    }

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

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