Skip to content

Commit

Permalink
Fix a really strange crashe and do some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
keyboardcrash32 committed Jul 16, 2024
1 parent a413ef1 commit b506f6d
Show file tree
Hide file tree
Showing 15 changed files with 351 additions and 344 deletions.
82 changes: 41 additions & 41 deletions src/CDiscordRPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,64 +37,64 @@ void handleDiscordSpectate(LPCSTR secret)

void handleDiscordJoinRequest(const DiscordUser* request)
{
Discord_Respond(request->userId, DISCORD_REPLY_IGNORE);
Discord_Respond(request->userId, DISCORD_REPLY_IGNORE);
}

void CDiscordRPC::updateDiscordPresence(DiscordRichPresence& discordPresence)
{
Discord_UpdatePresence(&discordPresence);
ZeroMemory(&discordPresence, sizeof(discordPresence));
Discord_UpdatePresence(&discordPresence);
ZeroMemory(&discordPresence, sizeof(discordPresence));

#ifdef DISCORD_DISABLE_IO_THREAD
Discord_UpdateConnection();
Discord_UpdateConnection();
#endif
Discord_RunCallbacks();
Discord_RunCallbacks();

printf("[Discord RPC] Updated the Discord presence\n");
printf("[Discord RPC] Updated the Discord presence\n");
}

void CDiscordRPC::Init()
{
ZeroMemory(&m_discordPresence, sizeof(m_discordPresence));
ZeroMemory(&m_handlers, sizeof(m_handlers));
ZeroMemory(&m_discordPresence, sizeof(m_discordPresence));
ZeroMemory(&m_handlers, sizeof(m_handlers));

m_handlers.ready = handleDiscordReady;
m_handlers.disconnected = handleDiscordDisconnected;
m_handlers.errored = handleDiscordError;
m_handlers.joinGame = handleDiscordJoin;
m_handlers.spectateGame = handleDiscordSpectate;
m_handlers.joinRequest = handleDiscordJoinRequest;
m_handlers.ready = handleDiscordReady;
m_handlers.disconnected = handleDiscordDisconnected;
m_handlers.errored = handleDiscordError;
m_handlers.joinGame = handleDiscordJoin;
m_handlers.spectateGame = handleDiscordSpectate;
m_handlers.joinRequest = handleDiscordJoinRequest;

Discord_Initialize(APPLICATION_ID, &m_handlers, 1, NULL);
printf("[Discord RPC] Discord RPC initialized!\n");
Discord_Initialize(APPLICATION_ID, &m_handlers, 1, NULL);
printf("[Discord RPC] Discord RPC initialized!\n");

updateDiscordPresence(m_discordPresence);
updateDiscordPresence(m_discordPresence);
}

void CDiscordRPC::SetGameState(GameStateEnum gameState)
{
std::string discordDetails;
switch (gameState)
{
case INMENU:
discordDetails = "In Menu";
break;

case INGAME: {
discordDetails = "In Game";

m_discordPresence.startTimestamp = time(0);
break;
}

default:
discordDetails = "Unknown state";
break;
}
m_discordPresence.largeImageKey = "main";
m_discordPresence.state = discordDetails.c_str();
printf("[Discord RPC] Changed the game state to %s\n", discordDetails.c_str());
updateDiscordPresence(m_discordPresence);
std::string discordDetails;
switch (gameState)
{
case INMENU:
discordDetails = "In Menu";
break;

case INGAME: {
discordDetails = "In Game";

m_discordPresence.startTimestamp = time(0);
break;
}

default:
discordDetails = "Unknown state";
break;
}
m_discordPresence.largeImageKey = "main";
m_discordPresence.state = discordDetails.c_str();
printf("[Discord RPC] Changed the game state to %s\n", discordDetails.c_str());
updateDiscordPresence(m_discordPresence);
}
2 changes: 1 addition & 1 deletion src/CDiscordRPC.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2024 keyboardcrash
Copyright (C) 2024 keyboardcrash
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
4 changes: 2 additions & 2 deletions src/CImguiMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

CImguiMenu::CImguiMenu(std::string menuName) : m_menuName(menuName)
{
printf("%s Imgui Menu created\n", m_menuName.c_str());
printf("%s Imgui Menu created\n", m_menuName.c_str());
}

CImguiMenu::~CImguiMenu()
{
printf("%s Imgui Menu deleted\n", m_menuName.c_str());
printf("%s Imgui Menu deleted\n", m_menuName.c_str());
}

void CImguiMenu::Init()
Expand Down
2 changes: 1 addition & 1 deletion src/CImguiMenu.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2024 keyboardcrash
Copyright (C) 2024 keyboardcrash
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
57 changes: 27 additions & 30 deletions src/CImguiMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

CImguiMgr::CImguiMgr()
{
}

CImguiMgr::~CImguiMgr()
Expand All @@ -12,51 +12,48 @@ CImguiMgr::~CImguiMgr()

void CImguiMgr::Init(HWND hWnd)
{
IMGUI_CHECKVERSION();
ImGui::CreateContext();
IMGUI_CHECKVERSION();
ImGui::CreateContext();

ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange;
ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange;

ImGui_ImplOpenGL3_Init();
ImGui_ImplWin32_Init(hWnd);
ImGui_ImplOpenGL3_Init();
ImGui_ImplWin32_Init(hWnd);

ImGui::StyleColorsDark();
ImGui::StyleColorsDark();

mainMenu.Init();
mainMenu.Init();
}

void CImguiMgr::Draw()
{
ImGui_ImplWin32_NewFrame();
ImGui_ImplOpenGL3_NewFrame();
ImGui::NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui_ImplOpenGL3_NewFrame();
ImGui::NewFrame();

if (ImGui::IsKeyPressed(ImGuiKey_Home))
m_showMainMenu = !m_showMainMenu;
/*if (ImGui::IsKeyPressed(ImGuiKey_Insert))
showMainMenu = !showMainMenu;*/

if (m_showMainMenu)
mainMenu.Draw();
if (g_bShowMainMenu)
mainMenu.Draw();

ImGuiIO& io = ImGui::GetIO();
io.MouseDrawCursor = io.WantCaptureMouse;
ImGuiIO& io = ImGui::GetIO();
io.MouseDrawCursor = io.WantCaptureMouse;

/*glViewport(0, 0, (int)ImGui::GetIO().DisplaySize.x, (int)ImGui::GetIO().DisplaySize.y);
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());*/
m_drawCalled = true;
m_drawCalled = true;
}

void CImguiMgr::End()
{
if (m_drawCalled) // just to prevent annoying errors
{
ImGui::EndFrame();
if (m_drawCalled) // just to prevent annoying errors
{
ImGui::EndFrame();

glViewport(0, 0, (int)ImGui::GetIO().DisplaySize.x, (int)ImGui::GetIO().DisplaySize.y);
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glViewport(0, 0, (int)ImGui::GetIO().DisplaySize.x, (int)ImGui::GetIO().DisplaySize.y);
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

m_drawCalled = false;
}
m_drawCalled = false;
}
}
6 changes: 4 additions & 2 deletions src/CImguiMgr.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2024 keyboardcrash
Copyright (C) 2024 keyboardcrash
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -23,6 +23,8 @@
#include "ImGuiIncludes.h"
#include "CMainMenu.h"

extern bool g_bShowMainMenu;

class CImguiMgr
{
public:
Expand All @@ -35,10 +37,10 @@ class CImguiMgr
void End();

CMainMenu mainMenu;
bool showMainMenu = false;

private:
bool m_drawCalled = false;
bool m_showMainMenu = false;
};

#endif // CIMGUIMGR_H_INCLUDED
82 changes: 41 additions & 41 deletions src/CMainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,62 @@ CMainMenu::~CMainMenu()

char* GetGameBuildVersion()
{
DWORD verHandle = 0;
UINT size = 0;
LPBYTE lpBuffer = NULL;
DWORD verSize = GetFileVersionInfoSizeA("game.dll", &verHandle);
DWORD verHandle = 0;
UINT size = 0;
LPBYTE lpBuffer = NULL;
DWORD verSize = GetFileVersionInfoSizeA("game.dll", &verHandle);

if (verSize != NULL)
{
LPSTR verData = new char[verSize];
if (verSize != NULL)
{
LPSTR verData = new char[verSize];

if (GetFileVersionInfoA("game.dll", verHandle, verSize, verData))
{
if (VerQueryValueA(verData, "\\", (VOID FAR * FAR*) & lpBuffer, &size))
{
if (size)
{
VS_FIXEDFILEINFO* verInfo = (VS_FIXEDFILEINFO*)lpBuffer;
if (verInfo->dwSignature == 0xfeef04bd)
{
char buffer[1024];
sprintf(buffer, "%d.%d.%d.%d",
(verInfo->dwFileVersionMS >> 16) & 0xffff,
(verInfo->dwFileVersionMS >> 0) & 0xffff,
(verInfo->dwFileVersionLS >> 16) & 0xffff,
(verInfo->dwFileVersionLS >> 0) & 0xffff
);
if (GetFileVersionInfoA("game.dll", verHandle, verSize, verData))
{
if (VerQueryValueA(verData, "\\", (VOID FAR * FAR*) & lpBuffer, &size))
{
if (size)
{
VS_FIXEDFILEINFO* verInfo = (VS_FIXEDFILEINFO*)lpBuffer;
if (verInfo->dwSignature == 0xfeef04bd)
{
char buffer[1024];
sprintf(buffer, "%d.%d.%d.%d",
(verInfo->dwFileVersionMS >> 16) & 0xffff,
(verInfo->dwFileVersionMS >> 0) & 0xffff,
(verInfo->dwFileVersionLS >> 16) & 0xffff,
(verInfo->dwFileVersionLS >> 0) & 0xffff
);

return buffer;
}
}
}
}
delete[] verData;
}
return buffer;
}
}
}
}
delete[] verData;
}

return const_cast<char*>("Unknown");
return const_cast<char*>("Unknown");
}

void CMainMenu::Init()
{
m_gameBuildVersion = GetGameBuildVersion();
printf("Warcraft build version: %s\n", m_gameBuildVersion.c_str());
m_gameBuildVersion = GetGameBuildVersion();
printf("Warcraft build version: %s\n", m_gameBuildVersion.c_str());
}

void CMainMenu::Draw()
{
ImGui::PushStyleColor(ImGuiCol_TitleBgActive, ImVec4(0.0f, 0.0f, 0.0f, 1.0f));
ImGui::Begin("WarTool Main Menu");
ImGui::PushStyleColor(ImGuiCol_TitleBgActive, ImVec4(0.0f, 0.0f, 0.0f, 1.0f));
ImGui::Begin("WarTool Main Menu");

ImGui::Text("Warcraft build version: %s", m_gameBuildVersion.c_str());
ImGui::Text("Warcraft build version: %s", m_gameBuildVersion.c_str());

ImGui::Checkbox("Lock cursor in a window", &lockCursor);
ImGui::Checkbox("Widescreen Fix", &widescreenFix);
ImGui::SliderFloat("Custom FOV fix", &g_CustomFovFix, 0.1f, 5.0f);
ImGui::Checkbox("Lock cursor in a window", &lockCursor);
ImGui::Checkbox("Widescreen Fix", &widescreenFix);
ImGui::SliderFloat("Custom FOV fix", &g_CustomFovFix, 0.1f, 5.0f);

ImGui::Checkbox("Save screenshots in .png (NOT IMPLEMENTED)", &PNGScreenshots);
ImGui::Checkbox("Save screenshots in .png (NOT IMPLEMENTED)", &PNGScreenshots);

ImGui::End();
ImGui::End();
ImGui::PopStyleColor();
}
9 changes: 3 additions & 6 deletions src/CMainMenu.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2024 keyboardcrash
Copyright (C) 2024 keyboardcrash
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -33,11 +33,8 @@ class CMainMenu : public CImguiMenu
void Init() override;
void Draw() override;

bool lockCursor = false;
bool PNGScreenshots = false;
bool Fix8MBSize = false;
bool MemHackProtection = false;
bool showFPS = false;
bool lockCursor = false;
bool PNGScreenshots = false;
bool widescreenFix = false;

private:
Expand Down
2 changes: 1 addition & 1 deletion src/ImGuiIncludes.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2024 keyboardcrash
Copyright (C) 2024 keyboardcrash
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
Loading

0 comments on commit b506f6d

Please sign in to comment.