<commit_before>#include "stdafx.h"
#include "GTA\CFileMgr.h"

struct Screen
{
    int32_t Width;
    int32_t Height;
    int32_t Width43;
    float fWidth;
    float fHeight;
    float fAspectRatio;
    float fHudScaleX;
    float fHudPosX;
} Screen;

union HudPos
{
    uint32_t dwPos;
    float fPos;
    HudPos(uint32_t pos) : dwPos(pos) {}
    HudPos(float pos) : fPos(pos) {}
};

class CDatEntry
{
public:
    int32_t dwPosX;
    int32_t dwPosY;
    float fOffsetX;
    float fOffsetY;

    CDatEntry(uint32_t posx, uint32_t posy, float fOffsetX, float fOffsetY)
        : dwPosX(posx), dwPosY(posy), fOffsetX(fOffsetX), fOffsetY(fOffsetY)
    {}
};

std::vector<CDatEntry> HudCoords;
void LoadDatFile()
{
    CIniReader iniReader("");
    char* DataFilePath = (char*)iniReader.GetIniPath().c_str();
    *strrchr(DataFilePath, '.') = '\0';
    strcat(DataFilePath, ".dat");

    if (FILE* hFile = CFileMgr::OpenFile(DataFilePath, "r"))
    {
        while (const char* pLine = CFileMgr::LoadLine(hFile))
        {
            if (pLine[0] && pLine[0] != '#')
            {
                int32_t PosX, PosY;
                float fOffsetX, fOffsetY;
                sscanf(pLine, "%*s %x %x %f %f %*f %*f", &PosX, &PosY, &fOffsetX, &fOffsetY);

                if (Screen.fAspectRatio < (16.0f / 9.0f))
                {
                    fOffsetX /= (((16.0f / 9.0f) / Screen.fAspectRatio) * 1.5f);
                }

                HudCoords.push_back(CDatEntry(PosX, PosY, fOffsetX, fOffsetY));
            }
        }
        CFileMgr::CloseFile(hFile);
    }
}

DWORD WINAPI Init(LPVOID bDelay)
{
    auto pattern = hook::pattern("68 20 03 00 00 BE 58 02 00 00");

    if (pattern.empty() && !bDelay)
    {
        CreateThread(0, 0, (LPTHREAD_START_ROUTINE)&Init, (LPVOID)true, 0, NULL);
        return 0;
    }

    if (bDelay)
        while (pattern.clear().count_hint(1).empty()) { Sleep(0); };

    CIniReader iniReader("");
    Screen.Width = iniReader.ReadInteger("MAIN", "ResX", 0);
    Screen.Height = iniReader.ReadInteger("MAIN", "ResY", 0);
    bool bFixHUD = iniReader.ReadInteger("MAIN", "FixHUD", 1) != 0;
    bool bFixFOV = iniReader.ReadInteger("MAIN", "FixFOV", 1) != 0;
    bool bXbox360Scaling = iniReader.ReadInteger("MAIN", "Xbox360Scaling", 1) != 0;
    bool bHudWidescreenMode = iniReader.ReadInteger("MAIN", "HudWidescreenMode", 1) != 0;
    bool bFMVWidescreenMode = iniReader.ReadInteger("MAIN", "FMVWidescreenMode", 1) != 0;
    static auto szCustomUserFilesDirectoryInGameDir = iniReader.ReadString("MISC", "CustomUserFilesDirectoryInGameDir", "0");
    static int nImproveGamepadSupport = iniReader.ReadInteger("MISC", "ImproveGamepadSupport", 0);
    static float fLeftStickDeadzone = iniReader.ReadFloat("MISC", "LeftStickDeadzone", 10.0f);
    bool bCustomUsrDir = false;
    if (strncmp(szCustomUserFilesDirectoryInGameDir, "0", 1) != 0)
        bCustomUsrDir = true;

    if (!Screen.Width || !Screen.Height)
        std::tie(Screen.Width, Screen.Height) = GetDesktopRes();

    Screen.fWidth = static_cast<float>(Screen.Width);
    Screen.fHeight = static_cast<float>(Screen.Height);
    Screen.fAspectRatio = (Screen.fWidth / Screen.fHeight);
    Screen.fHudScaleX = (1.0f / Screen.fWidth * (Screen.fHeight / 480.0f)) * 2.0f;
    Screen.fHudPosX = 640.0f / (640.0f * Screen.fHudScaleX);

    //menu
    uint32_t* dword_408A25 = hook::pattern("68 20 03 00 00 BE 58 02 00 00").count(1).get(0).get<uint32_t>(1);
    injector::WriteMemory(dword_408A25, Screen.Width, true);
    uint32_t dword_408A2A = (uint32_t)dword_408A25 + 5;
    injector::WriteMemory(dword_408A2A, Screen.Height, true);

    uint32_t* dword_4494C5 = hook::pattern("68 20 03 00 00 BE 58 02 00 00").count(1).get(0).get<uint32_t>(1);
    injector::WriteMemory(dword_4494C5, Screen.Width, true);
    uint32_t dword_4494CA = (uint32_t)dword_4494C5 + 5;
    injector::WriteMemory(dword_4494CA, Screen.Height, true);

    //game
    uint32_t* dword_408783 = hook::pattern("B8 20 03 00 00 BE 58 02 00 00 77 75").count(1).get(0).get<uint32_t>(1);
    injector::WriteMemory(dword_408783, Screen.Width, true);
    uint32_t dword_408788 = (uint32_t)dword_408783 + 5;
    injector::WriteMemory(dword_408788, Screen.Height, true);

    injector::MakeNOP(dword_408788 + 4, 9, true);

    uint32_t* dword_408796 = hook::pattern("B8 80 02 00 00 BE E0 01 00 00 50").count(1).get(0).get<uint32_t>(1);
    injector::WriteMemory(dword_408796, Screen.Width, true);
    uint32_t dword_40879B = (uint32_t)dword_408796 + 5;
    injector::WriteMemory(dword_40879B, Screen.Height, true);
    uint32_t* dword_4087AF = hook::pattern("B8 20 03 00 00 BE 58 02 00 00 50").count(1).get(0).get<uint32_t>(1);
    injector::WriteMemory(dword_4087AF, Screen.Width, true);
    uint32_t dword_4087B4 = (uint32_t)dword_4087AF + 5;
    injector::WriteMemory(dword_4087B4, Screen.Height, true);
    uint32_t* dword_4087C8 = hook::pattern("B8 00 04 00 00 BE 00 03 00 00 50").count(1).get(0).get<uint32_t>(1);
    injector::WriteMemory(dword_4087C8, Screen.Width, true);
    uint32_t dword_4087CD = (uint32_t)dword_4087C8 + 5;
    injector::WriteMemory(dword_4087CD, Screen.Height, true);
    uint32_t* dword_4087E1 = hook::pattern("B8 00 05 00 00 BE C0 03 00 00 50").count(1).get(0).get<uint32_t>(1);
    injector::WriteMemory(dword_4087E1, Screen.Width, true);
    uint32_t dword_4087E6 = (uint32_t)dword_4087E1 + 5;
    injector::WriteMemory(dword_4087E6, Screen.Height, true);

    //uint32_t* dword_4087FA = hook::pattern("BE 00 04 00 00 B8 00 05 00 00 50").count(1).get(0).get<uint32_t>(1);
    //injector::WriteMemory(dword_4087FA, Screen.Width, true);
    //uint32_t dword_4087FF = (uint32_t)dword_4087E1 + 5;
    //injector::WriteMemory(dword_4087FF, ResY, true);

    //__mbclen to strlen, "---" bug
    pattern = hook::pattern("E8 ? ? ? ? 83 C4 04 85 C0 76 21 8D 43 60");
    if (pattern.size() > 0)
    {
        auto dword_4148EA = pattern.get_first(0);
        injector::MakeCALL(dword_4148EA, strlen, true);
    }


    //HUD
    if (bFixHUD)
    {
        uint32_t* dword_6CC914 = *hook::pattern("D8 0D ? ? ? ? 57 0F B6 B8 81 00 00 00 D8 ? ? ? ? ?").count(1).get(0).get<uint32_t*>(2);
        injector::WriteMemory<float>(dword_6CC914, Screen.fHudScaleX, true);

        //fHudScaleY = *(float*)0x6CCBA4;
        //CPatch::SetFloat(0x79AC14, fHudScaleY);

        for (size_t i = 0; i < 4; i++)
        {
            auto pattern = hook::pattern("C7 ? ? ? ? 00 00 00 00 A0 43 C7 ? ? ? ? 00 00 00 00 70 43");
            if (pattern.size() > 0)
            {
                uint32_t* dword_4F20A3 = pattern.get(0).get<uint32_t>(7);
                injector::WriteMemory<float>(dword_4F20A3, Screen.fHudPosX, true);
            }
            else
            {
                pattern = hook::pattern("C7 ? ? ? 00 00 A0 43 C7 ? ? ? ? 00 00 00 00 70 43");
                if (pattern.size() > 0)
                {
                    uint32_t* dword_4F2287 = pattern.get(0).get<uint32_t>(4);
                    injector::WriteMemory<float>(dword_4F2287, Screen.fHudPosX, true);
                }
            }
        }

        uint32_t* dword_4F1E2D = hook::pattern("C7 ? ? ? 00 00 A0 43 C7 ? ? ? 00 00 70 43").count(1).get(0).get<uint32_t>(4);
        injector::WriteMemory<float>(dword_4F1E2D, Screen.fHudPosX, true);
        uint32_t* dword_4F26E5 = hook::pattern("C7 ? ? ? 00 00 A0 43 C7 ? ? ? 00 00 70 43").count(1).get(0).get<uint32_t>(4);
        injector::WriteMemory<float>(dword_4F26E5, Screen.fHudPosX, true);

        uint32_t* dword_6CC910 = *hook::pattern("D8 1D ? ? ? ? DF E0 F6 C4 41 75 0F D9 45 FC").count(1).get(0).get<uint32_t*>(2);
        injector::WriteMemory<float>(dword_6CC910, Screen.fHudPosX, true);

        auto pattern = hook::pattern("C7 44 24 ? 00 00 DC 43 C7 44 24 ? 00 00 70 41");
        if (pattern.size() > 0)
        {
            injector::WriteMemory<float>(pattern.get_first(20), (Screen.fHudPosX - 320.0f) + 200.0f, true);
            injector::WriteMemory<float>(pattern.get_first(42), (Screen.fHudPosX - 320.0f) + 200.0f, true);
            injector::WriteMemory<float>(pattern.get_first(4),  (Screen.fHudPosX - 320.0f) + 440.0f, true);
            injector::WriteMemory<float>(pattern.get_first(64), (Screen.fHudPosX - 320.0f) + 440.0f, true);
        }
    }

    if (bFixFOV)
    {
        static float hor3DScale = 1.0f / (Screen.fAspectRatio / (4.0f / 3.0f));
        static float ver3DScale = 0.75f;
        static float mirrorScale = 0.45f;
        static float f1234 = 1.25f;
        static float f06 = 0.6f;
        static float f1 = 1.0f; // horizontal for vehicle reflection
        static float flt1 = 0.0f;
        static float flt2 = 0.0f;
        static float flt3 = 0.0f;<commit_msg>nfsu update -fixes #179<commit_after>#include "stdafx.h"
#include "GTA\CFileMgr.h"

struct Screen
{
    int32_t Width;
    int32_t Height;
    int32_t Width43;
    float fWidth;
    float fHeight;
    float fAspectRatio;
    float fHudScaleX;
    float fHudPosX;
} Screen;

union HudPos
{
    uint32_t dwPos;
    float fPos;
    HudPos(uint32_t pos) : dwPos(pos) {}
    HudPos(float pos) : fPos(pos) {}
};

class CDatEntry
{
public:
    int32_t dwPosX;
    int32_t dwPosY;
    float fOffsetX;
    float fOffsetY;

    CDatEntry(uint32_t posx, uint32_t posy, float fOffsetX, float fOffsetY)
        : dwPosX(posx), dwPosY(posy), fOffsetX(fOffsetX), fOffsetY(fOffsetY)
    {}
};

std::vector<CDatEntry> HudCoords;
void LoadDatFile()
{
    CIniReader iniReader("");
    char* DataFilePath = (char*)iniReader.GetIniPath().c_str();
    *strrchr(DataFilePath, '.') = '\0';
    strcat(DataFilePath, ".dat");

    if (FILE* hFile = CFileMgr::OpenFile(DataFilePath, "r"))
    {
        while (const char* pLine = CFileMgr::LoadLine(hFile))
        {
            if (pLine[0] && pLine[0] != '#')
            {
                int32_t PosX, PosY;
                float fOffsetX, fOffsetY;
                sscanf(pLine, "%*s %x %x %f %f %*f %*f", &PosX, &PosY, &fOffsetX, &fOffsetY);

                if (Screen.fAspectRatio < (16.0f / 9.0f))
                {
                    fOffsetX /= (((16.0f / 9.0f) / Screen.fAspectRatio) * 1.5f);
                }

                HudCoords.push_back(CDatEntry(PosX, PosY, fOffsetX, fOffsetY));
            }
        }
        CFileMgr::CloseFile(hFile);
    }
}

DWORD WINAPI Init(LPVOID bDelay)
{
    auto pattern = hook::pattern("68 20 03 00 00 BE 58 02 00 00");

    if (pattern.empty() && !bDelay)
    {
        CreateThread(0, 0, (LPTHREAD_START_ROUTINE)&Init, (LPVOID)true, 0, NULL);
        return 0;
    }

    if (bDelay)
        while (pattern.clear().count_hint(1).empty()) { Sleep(0); };

    CIniReader iniReader("");
    Screen.Width = iniReader.ReadInteger("MAIN", "ResX", 0);
    Screen.Height = iniReader.ReadInteger("MAIN", "ResY", 0);
    bool bFixHUD = iniReader.ReadInteger("MAIN", "FixHUD", 1) != 0;
    bool bFixFOV = iniReader.ReadInteger("MAIN", "FixFOV", 1) != 0;
    bool bXbox360Scaling = iniReader.ReadInteger("MAIN", "Xbox360Scaling", 1) != 0;
    bool bHudWidescreenMode = iniReader.ReadInteger("MAIN", "HudWidescreenMode", 1) != 0;
    bool bFMVWidescreenMode = iniReader.ReadInteger("MAIN", "FMVWidescreenMode", 1) != 0;
    static auto szCustomUserFilesDirectoryInGameDir = iniReader.ReadString("MISC", "CustomUserFilesDirectoryInGameDir", "0");
    static int nImproveGamepadSupport = iniReader.ReadInteger("MISC", "ImproveGamepadSupport", 0);
    static float fLeftStickDeadzone = iniReader.ReadFloat("MISC", "LeftStickDeadzone", 10.0f);
    bool bCustomUsrDir = false;
    if (strncmp(szCustomUserFilesDirectoryInGameDir, "0", 1) != 0)
        bCustomUsrDir = true;

    if (!Screen.Width || !Screen.Height)
        std::tie(Screen.Width, Screen.Height) = GetDesktopRes();

    Screen.fWidth = static_cast<float>(Screen.Width);
    Screen.fHeight = static_cast<float>(Screen.Height);
    Screen.fAspectRatio = (Screen.fWidth / Screen.fHeight);
    Screen.fHudScaleX = (1.0f / Screen.fWidth * (Screen.fHeight / 480.0f)) * 2.0f;
    Screen.fHudPosX = 640.0f / (640.0f * Screen.fHudScaleX);

    //menu
    uint32_t* dword_408A25 = hook::pattern("68 20 03 00 00 BE 58 02 00 00").count(1).get(0).get<uint32_t>(1);
    injector::WriteMemory(dword_408A25, Screen.Width, true);
    uint32_t dword_408A2A = (uint32_t)dword_408A25 + 5;
    injector::WriteMemory(dword_408A2A, Screen.Height, true);

    uint32_t* dword_4494C5 = hook::pattern("68 20 03 00 00 BE 58 02 00 00").count(1).get(0).get<uint32_t>(1);
    injector::WriteMemory(dword_4494C5, Screen.Width, true);
    uint32_t dword_4494CA = (uint32_t)dword_4494C5 + 5;
    injector::WriteMemory(dword_4494CA, Screen.Height, true);

    //game
    uint32_t* dword_408783 = hook::pattern("B8 20 03 00 00 BE 58 02 00 00 77 75").count(1).get(0).get<uint32_t>(1);
    injector::WriteMemory(dword_408783, Screen.Width, true);
    uint32_t dword_408788 = (uint32_t)dword_408783 + 5;
    injector::WriteMemory(dword_408788, Screen.Height, true);

    injector::MakeNOP(dword_408788 + 4, 9, true);

    uint32_t* dword_408796 = hook::pattern("B8 80 02 00 00 BE E0 01 00 00 50").count(1).get(0).get<uint32_t>(1);
    injector::WriteMemory(dword_408796, Screen.Width, true);
    uint32_t dword_40879B = (uint32_t)dword_408796 + 5;
    injector::WriteMemory(dword_40879B, Screen.Height, true);
    uint32_t* dword_4087AF = hook::pattern("B8 20 03 00 00 BE 58 02 00 00 50").count(1).get(0).get<uint32_t>(1);
    injector::WriteMemory(dword_4087AF, Screen.Width, true);
    uint32_t dword_4087B4 = (uint32_t)dword_4087AF + 5;
    injector::WriteMemory(dword_4087B4, Screen.Height, true);
    uint32_t* dword_4087C8 = hook::pattern("B8 00 04 00 00 BE 00 03 00 00 50").count(1).get(0).get<uint32_t>(1);
    injector::WriteMemory(dword_4087C8, Screen.Width, true);
    uint32_t dword_4087CD = (uint32_t)dword_4087C8 + 5;
    injector::WriteMemory(dword_4087CD, Screen.Height, true);
    uint32_t* dword_4087E1 = hook::pattern("B8 00 05 00 00 BE C0 03 00 00 50").count(1).get(0).get<uint32_t>(1);
    injector::WriteMemory(dword_4087E1, Screen.Width, true);
    uint32_t dword_4087E6 = (uint32_t)dword_4087E1 + 5;
    injector::WriteMemory(dword_4087E6, Screen.Height, true);

    //uint32_t* dword_4087FA = hook::pattern("BE 00 04 00 00 B8 00 05 00 00 50").count(1).get(0).get<uint32_t>(1);
    //injector::WriteMemory(dword_4087FA, Screen.Width, true);
    //uint32_t dword_4087FF = (uint32_t)dword_4087E1 + 5;
    //injector::WriteMemory(dword_4087FF, ResY, true);

    //__mbclen to strlen, "---" bug
    pattern = hook::pattern("E8 ? ? ? ? 83 C4 04 85 C0 76 21 8D 43 60");
    if (pattern.size() > 0)
    {
        auto dword_4148EA = pattern.get_first(0);
        injector::MakeCALL(dword_4148EA, strlen, true);
    }


    //HUD
    if (bFixHUD)
    {
        uint32_t* dword_6CC914 = *hook::pattern("D8 0D ? ? ? ? 57 0F B6 B8 81 00 00 00 D8 ? ? ? ? ?").count(1).get(0).get<uint32_t*>(2);
        injector::WriteMemory<float>(dword_6CC914, Screen.fHudScaleX, true);

        //fHudScaleY = *(float*)0x6CCBA4;
        //CPatch::SetFloat(0x79AC14, fHudScaleY);

        for (size_t i = 0; i < 4; i++)
        {
            auto pattern = hook::pattern("C7 ? ? ? ? 00 00 00 00 A0 43 C7 ? ? ? ? 00 00 00 00 70 43");
            if (pattern.size() > 0)
            {
                uint32_t* dword_4F20A3 = pattern.get(0).get<uint32_t>(7);
                injector::WriteMemory<float>(dword_4F20A3, Screen.fHudPosX, true);
            }
            else
            {
                pattern = hook::pattern("C7 ? ? ? 00 00 A0 43 C7 ? ? ? ? 00 00 00 00 70 43");
                if (pattern.size() > 0)
                {
                    uint32_t* dword_4F2287 = pattern.get(0).get<uint32_t>(4);
                    injector::WriteMemory<float>(dword_4F2287, Screen.fHudPosX, true);
                }
            }
        }

        uint32_t* dword_4F1E2D = hook::pattern("C7 ? ? ? 00 00 A0 43 C7 ? ? ? 00 00 70 43").count(1).get(0).get<uint32_t>(4);
        injector::WriteMemory<float>(dword_4F1E2D, Screen.fHudPosX, true);
        uint32_t* dword_4F26E5 = hook::pattern("C7 ? ? ? 00 00 A0 43 C7 ? ? ? 00 00 70 43").count(1).get(0).get<uint32_t>(4);
        injector::WriteMemory<float>(dword_4F26E5, Screen.fHudPosX, true);

        uint32_t* dword_6CC910 = *hook::pattern("D8 1D ? ? ? ? DF E0 F6 C4 41 75 0F D9 45 FC").count(1).get(0).get<uint32_t*>(2);
        injector::WriteMemory<float>(dword_6CC910, Screen.fHudPosX, true);

        auto pattern = hook::pattern("C7 44 24 ? 00 00 DC 43 C7 44 24 ? 00 00 70 41");
        if (pattern.size() > 0)
        {
            injector::WriteMemory<float>(pattern.get_first(20), (Screen.fHudPosX - 320.0f) + 200.0f, true);
            injector::WriteMemory<float>(pattern.get_first(42), (Screen.fHudPosX - 320.0f) + 200.0f, true);
            injector::WriteMemory<float>(pattern.get_first(4),  (Screen.fHudPosX - 320.0f) + 440.0f, true);
            injector::WriteMemory<float>(pattern.get_first(64), (Screen.fHudPosX - 320.0f) + 440.0f, true);
        }

        pattern = hook::pattern("8D 72 04 83 C0 60 E8 ? ? ? ? 5F 5E C3"); //menu (#179)
        if (pattern.size() > 0)
            injector::MakeNOP(pattern.get_first(), 11, true);
    }

    if (bFixFOV)
    {
        static float hor3DScale = 1.0f / (Screen.fAspectRatio / (4.0f / 3.0f));
        static float ver3DScale = 0.75f;
        static float mirrorScale = 0.45f;
        static float f1234 = 1.25f;
        static float f06 = 0.6f;
        static float f1 = 1.0f; // horizontal for vehicle reflection
        static float flt1 = 0.0f;
        static float flt2 = 0.0f;
        static float flt3 = 0.0f;
{'fraction_non_alphanumeric': 0.1472569778633301, 'fraction_numerical': 0.10207778972994395, 'mean_word_length': 2.957875868250056, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 66, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2394591', 'n_tokens_mistral': 7957, 'n_tokens_neox': 6732, 'n_words': 1347}