zxvnme / zgui

zxvnme's graphical user interface
MIT License
399 stars 53 forks source link

[BUG] Game crashing when injecting? #49

Closed joshcancode closed 5 years ago

joshcancode commented 5 years ago

For some reason, injecting the cheat I'm working on causes my game to immediately crash. Here is my code for the menu.

`Color ToZGUI(zgui::color c) { Color col = Color(c.r, c.g, c.b, c.a); return col; }

void line(int x, int y, int x2, int y2, zgui::color c) noexcept { g_pSurface->Line(x, y, x2, y2, ToZGUI(c)); }

void rect(int x, int y, int x2, int y2, zgui::color c) noexcept { g_pSurface->OutlinedRect(x, y, x2, y2, ToZGUI(c)); }

void filled_rect(int x, int y, int x2, int y2, zgui::color c) noexcept { g_pSurface->FilledRect(x, y, x2, y2, ToZGUI(c)); }

void text(int x, int y, zgui::color c, int font, bool center, const char text) noexcept { g_pSurface->DrawSetTextColor(ToZGUI(c)); g_pSurface->DrawSetTextPos(x, y); g_pSurface->DrawSetTextFont(font); const char _input = text; size_t length = strlen(_input); wchar_t text_wchar[30]; mbstowcs_s(&length, text_wchar, _input, length); g_pSurface->DrawPrintText(text_wchar, strlen(text)); }

void get_text_size(unsigned long font, const char text, int& wide, int& tall) noexcept { g_pSurface->GetTextSize(font, (wchar_t)text, wide, tall); }

float get_frametime() noexcept { return g_pGlobalVars->frametime; }

void Menu::Initialize() { zgui::functions.draw_line = line; zgui::functions.draw_rect = rect; zgui::functions.draw_filled_rect = filled_rect; zgui::functions.draw_text = text; zgui::functions.get_text_size = get_text_size; }

void Menu::Render() { const unsigned long _font = Globals::CourierNew;

static bool _pressed = true;

if (!_pressed && GetAsyncKeyState(VK_INSERT))
    _pressed = true;
else if (_pressed && !GetAsyncKeyState(VK_INSERT))
{
    _pressed = false;
    menuOpened = !menuOpened;
}

g_InputSystem->EnableInput(!menuOpened);

if (menuOpened)
{
    zgui::poll_input("Counter-Strike: Global Offensive");

    if (zgui::begin_window("zgui example window", { 500, 350 }, _font, zgui::zgui_window_flags_none))
    {
        zgui::text("sample checkbox #example");
        zgui::end_window();
    }
}

}`

Any ideas would be amazing.

zxvnme commented 5 years ago

Dont check if(menuOpened) before drawing. zgui has its own checks in zgui.cpp at the top of the file in global_config struct.

48cf commented 5 years ago

debug debug debug debug debug debug debug debug debug debug debug debug debug debug debug debug debug debug debug debug debug debug debug debug debug debug debug debug debug debug debug debug debug

48cf commented 5 years ago

Closing the issue as the OP is not providing any helpful information.