I am currently making a executable in C++ that is using Scripthook natives (plugin for GTA5) to draw text on the screen. My program code should be fine. However whenever I build my program and start it, im getting the error mentioned in my title. I have tried changing the program compatibility which did absolutely nothing. Aswell as rebuilding it multiple times. I kind of stopped after that since I didn't know what else I could try, google didn't help me either.
Aswell as if I try to debug my program in VS Comm 2019, I get the following error:
0xC0000005: Access violation executing location 0x0000000000000000.
So this is my code right now: (Im a beginner, so the code is probably a bit messy in a experienced developers eyes.)
main.cpp
#include <string>
#include <iostream>
#include "script.h"
#include "natives.h"
#include "TlHelp32.h"
#include "tchar.h"
using namespace std;
void draw_text(char* text, float x, float y, float scale) {
UI::SET_TEXT_FONT(0);
UI::SET_TEXT_SCALE(scale, scale);
UI::SET_TEXT_COLOUR(255, 255, 255, 245);
UI::SET_TEXT_WRAP(0.0, 1.0);
UI::SET_TEXT_CENTRE(0);
UI::SET_TEXT_DROPSHADOW(2, 2, 0, 0, 0);
UI::SET_TEXT_EDGE(1, 0, 0, 0, 205);
UI::_SET_TEXT_ENTRY("Test draw");
UI::_ADD_TEXT_COMPONENT_STRING(text);
UI::_DRAW_TEXT(y, x);
}
DWORD FindProcessId(const std::wstring& processName)
{
PROCESSENTRY32 processInfo;
processInfo.dwSize = sizeof(processInfo);
HANDLE processesSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (processesSnapshot == INVALID_HANDLE_VALUE) {
return 0;
}
Process32First(processesSnapshot, &processInfo);
if (!processName.compare(processInfo.szExeFile))
{
CloseHandle(processesSnapshot);
return processInfo.th32ProcessID;
}
while (Process32Next(processesSnapshot, &processInfo))
{
if (!processName.compare(processInfo.szExeFile))
{
CloseHandle(processesSnapshot);
return processInfo.th32ProcessID;
}
}
CloseHandle(processesSnapshot);
return 0;
}
int main() {
auto processId = FindProcessId(L"FiveM_GTAProcess.exe");
if (processId == NULL)
{
cout << "Can't find GTA Process" << endl;
}
else if (processId = FindProcessId(L"FiveM_GTAProcess.exe"))
{
cout << "Process found." << endl;
cin.get();
HANDLE hProcess;
hProcess = OpenProcess(PROCESS_ALL_ACCESS, NULL, processId);
while (hProcess == NULL)
{
CloseHandle(hProcess);
}
}
bool widescreen = GRAPHICS::GET_IS_WIDESCREEN();
Ped playerPed;
Vector3 position;
while (true) {
playerPed = PLAYER::PLAYER_PED_ID();
position = ENTITY::GET_ENTITY_COORDS(playerPed, 1);
widescreen = GRAPHICS::GET_IS_WIDESCREEN();
char coords[100];
sprintf_s(coords, "X: %.3f Y: %.3f Z: %.3f Angle: %.3f", position.x, position.y, position.z, ENTITY::GET_ENTITY_HEADING(playerPed));
widescreen ? draw_text(coords, 0.978, 0.205 - 0.03, 0.3) : draw_text(coords, 0.978, 0.205, 0.3);
WAIT(0);
}
}
void ScriptMain() {
main();
}
I'd really appreciate help.
Thanks!
User contributions licensed under CC BY-SA 3.0