'I'm having a problem trying to make a WorldToScreen function work to a GTAV Cheat, and honestly i dont have any idea on how to solve it

Exception thrown at 0x0000000000000000 in gtavcheat.exe: 0xC0000005: Access violation executing location 0x0000000000000000.

The error is at "if (World2Screen(WorldPos, &ScrPos->x, &ScrPos->y))"


class game
{
public:
    typedef BOOLEAN(__fastcall* WorldToScreen_t)(Vector3 WorldPos, float* x, float* y);
    static WorldToScreen_t World2Screen;

    static void InitNativeFunctions()
    {
        World2Screen = (WorldToScreen_t)(GetModuleHandleA("FiveM_b2372_GTAProcess.exe") +0x56F83BFB);
    }

    static BOOLEAN W2S(const Vector3& WorldPos, Vector3* ScrPos)
    {
        float x, y;
        if (World2Screen(WorldPos, &ScrPos->x, &ScrPos->y))
        {
            ScrPos->x *= ScreenX;
            ScrPos->y *= ScreenY;

            return TRUE;
        }
        return FALSE;
    }
};


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source