Merge pull request #26 from SamZahreddine/v3

Added wxWidgets
This commit is contained in:
Anonymous275 2022-08-04 10:08:56 +03:00 committed by GitHub
commit 48bcb8f4a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 290 additions and 63 deletions

View File

@ -20,6 +20,8 @@ endif(WIN32)
set(wxUSE_STL ON) set(wxUSE_STL ON)
set(BUILD_EXAMPLES OFF) set(BUILD_EXAMPLES OFF)
set(wxBUILD_SHARED OFF) set(wxBUILD_SHARED OFF)
set(wxUSE_HTML ON)
set(wxUSE_STREAMS ON)
set(wxBUILD_MSVC_MULTIPROC ON) set(wxBUILD_MSVC_MULTIPROC ON)
set(wxBUILD_USE_STATIC_RUNTIME ON) set(wxBUILD_USE_STATIC_RUNTIME ON)
@ -31,7 +33,7 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
add_executable(${PROJECT_NAME} add_executable(${PROJECT_NAME} WIN32
src/main.cpp include/easyloggingpp/src/easylogging++.cc src/main.cpp include/easyloggingpp/src/easylogging++.cc
src/Launcher.cpp include/Launcher.h include/Memory/Hook.h src/Launcher.cpp include/Launcher.h include/Memory/Hook.h
src/Memory/Definitions.cpp include/Memory/Definitions.h src/Memory/Definitions.cpp include/Memory/Definitions.h
@ -55,7 +57,7 @@ if (WIN32)
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug") if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
target_link_libraries(${PROJECT_NAME} PRIVATE discord-rpc) target_link_libraries(${PROJECT_NAME} PRIVATE discord-rpc)
endif() endif()
target_link_libraries(${PROJECT_NAME} PRIVATE wx::net wx::core wx::base) target_link_libraries(${PROJECT_NAME} PRIVATE wx::net wx::html wx::webview wx::core wx::base)
target_link_libraries(${PROJECT_NAME} PRIVATE target_link_libraries(${PROJECT_NAME} PRIVATE
ZLIB::ZLIB OpenSSL::SSL OpenSSL::Crypto ws2_32 ZLIB::ZLIB OpenSSL::SSL OpenSSL::Crypto ws2_32
Dbghelp comsuppw minhook::minhook nlohmann_json nlohmann_json::nlohmann_json) Dbghelp comsuppw minhook::minhook nlohmann_json nlohmann_json::nlohmann_json)

View File

@ -29,9 +29,7 @@ uint32_t Memory::GetBeamNGPID(const std::set<uint32_t>& BL) {
} while (Process32Next(Snapshot, &pe32)); } while (Process32Next(Snapshot, &pe32));
} }
if (Snapshot != INVALID_HANDLE_VALUE) { if (Snapshot != INVALID_HANDLE_VALUE) { CloseHandle(Snapshot); }
CloseHandle(Snapshot);
}
if (GetLastError() != 0) return 0; if (GetLastError() != 0) return 0;
return pe32.th32ProcessID; return pe32.th32ProcessID;
@ -58,9 +56,7 @@ uint64_t Memory::FindPattern(const char* module, const char* Pattern[]) {
found &= found &=
Pattern[1][j] == '?' || Pattern[0][j] == *(char*)(base + i + j); Pattern[1][j] == '?' || Pattern[0][j] == *(char*)(base + i + j);
} }
if (found) { if (found) { return base + i; }
return base + i;
}
} }
return 0; return 0;
} }

View File

@ -3,84 +3,313 @@
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info. /// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
/// ///
#define _CRT_SECURE_NO_WARNINGS
#include <wx/wxprec.h> #include <wx/wxprec.h>
#include <set>
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include <wx/animate.h> #include <wx/dc.h>
#include <wx/mstream.h> #include <wx/dcbuffer.h>
#include <wx/fs_inet.h>
#include <wx/graphics.h>
#include <wx/hyperlink.h>
#include <wx/sizer.h>
#include <wx/statline.h>
#include <wx/webview.h>
#include <wx/wx.h> #include <wx/wx.h>
#include "gifs.h" #include <wx/wxhtml.h.>
#include "Launcher.h"
#include "Logger.h"
#endif #endif
/////////// Inherit App class ///////////
class MyApp : public wxApp { class MyApp : public wxApp {
public: public:
virtual bool OnInit(); bool OnInit() override;
}; };
class MyFrame : public wxFrame {
/////////// MainFrame class ///////////
class MyMainFrame : public wxFrame {
public: public:
MyFrame(); MyMainFrame();
private: private:
void OnHello(wxCommandEvent& event); // Here you put the frame functions:
void OnExit(wxCommandEvent& event); bool DarkMode = wxSystemSettings::GetAppearance().IsDark();
void OnAbout(wxCommandEvent& event); void OnClickAccount(wxCommandEvent& event);
static wxSize FixedSize; void OnClickSettings(wxCommandEvent& event);
}; void OnClickLaunch(wxCommandEvent& event);
enum { ID_Hello = 1 }; void OnClickLogo(wxCommandEvent& event);
wxSize MyFrame::FixedSize(370, 400); wxDECLARE_EVENT_TABLE();
};
/////////// AccountFrame class ///////////
class MyAccountFrame : public wxFrame {
public:
MyAccountFrame();
private:
// Here you put the frame functions:
bool DarkMode = wxSystemSettings::GetAppearance().IsDark();
};
/////////// SettingsFrame class ///////////
class MySettingsFrame : public wxFrame {
public:
MySettingsFrame();
private:
// Here you put the frame functions:
bool DarkMode = wxSystemSettings::GetAppearance().IsDark();
};
enum { ID_Hello = 1 };
/////////// Event Table ///////////
wxBEGIN_EVENT_TABLE(MyMainFrame, wxFrame)
EVT_BUTTON(39, MyMainFrame::OnClickAccount)
EVT_BUTTON(40, MyMainFrame::OnClickSettings)
EVT_BUTTON(41, MyMainFrame::OnClickLaunch)
EVT_BUTTON(42, MyMainFrame::OnClickLogo)
wxEND_EVENT_TABLE()
/////////// OnInit function to show frame ///////////
bool MyApp::OnInit() { bool MyApp::OnInit() {
auto* frame = new MyFrame(); auto* MainFrame = new MyMainFrame();
frame->Show(true); MainFrame->SetIcon(wxIcon("BeamMP.png",wxBITMAP_TYPE_PNG));
// Set MainFrame properties:
MainFrame->SetSize(1000, 650);
MainFrame->Center();
if (wxSystemSettings::GetAppearance().IsDark()) {
MainFrame->SetBackgroundColour(wxColour(40, 40, 40));
MainFrame->SetForegroundColour(wxColour(255, 255, 255));
}
else {
MainFrame->SetBackgroundColour(wxColour("white"));
MainFrame->SetForegroundColour(wxColour("white"));
}
wxFileSystem::AddHandler(new wxInternetFSHandler);
MainFrame->Show(true);
return true; return true;
} }
MyFrame::MyFrame() : /////////// MainFrame Function ///////////
wxFrame(nullptr, wxID_ANY, "BeamMP V3.0", wxDefaultPosition, FixedSize) { MyMainFrame::MyMainFrame() :
// SetMaxSize(FixedSize); wxFrame(nullptr, wxID_ANY, "BeamMP Launcher V3", wxDefaultPosition,wxDefaultSize,
// SetMinSize(FixedSize); wxMINIMIZE_BOX | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX) {
Center();
// 27 35 35 /////////// News ///////////
wxWebView::New() ->Create(this, wxID_ANY, "https://beammp.com", wxPoint(10, 70), wxSize(950, 400));
auto* txtNews = new wxStaticText(this, wxID_ANY, wxT("News"), wxPoint(10, 40));
wxColour Colour(27, 35, 35, 1); auto* HorizontalLine1 = new wxStaticLine(this, wxID_ANY, wxPoint(10, 60), wxSize(950, 1));
SetBackgroundColour(Colour); auto* HorizontalLine2 = new wxStaticLine(this, wxID_ANY, wxPoint(10, 480), wxSize(950, 1));
auto* menuFile = new wxMenu; /////////// PNG Handler to load the files ///////////
menuFile->Append(ID_Hello, "&Hello...\tCtrl-H", auto *handler = new wxPNGHandler;
"Help string shown in status bar for this menu item"); wxImage::AddHandler(handler);
menuFile->AppendSeparator();
menuFile->Append(wxID_EXIT);
auto* menuHelp = new wxMenu;
menuHelp->Append(wxID_ABOUT);
auto* menuBar = new wxMenuBar;
menuBar->SetOwnBackgroundColour(Colour); /////////// Hyperlinks ///////////
menuBar->Append(menuFile, "&File"); auto* HyperForum = new wxHyperlinkCtrl(this, wxID_ANY, wxT("Forum"), wxT("https://forum.beammp.com"), wxPoint(10, 10));
menuBar->Append(menuHelp, "&Help"); auto* txtSeparator1 = new wxStaticText(this, wxID_ANY, wxT("|"), wxPoint(55, 10));
// SetMenuBar(menuBar);
auto* m_ani = new wxAnimationCtrl(this, wxID_ANY);
wxMemoryInputStream stream(gif::Logo, sizeof(gif::Logo));
if (m_ani->Load(stream)) m_ani->Play();
Bind(wxEVT_MENU, &MyFrame::OnHello, this, ID_Hello); auto* HyperDiscord = new wxHyperlinkCtrl(this, wxID_ANY, wxT("Discord"), wxT("https://discord.gg/beammp"), wxPoint(70, 10));
Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT); auto* txtSeparator2 = new wxStaticText(this, wxID_ANY, wxT("|"), wxPoint(120, 10));
Bind(wxEVT_MENU, &MyFrame::OnExit, this, wxID_EXIT);
}
void MyFrame::OnExit(wxCommandEvent& event) { auto* HyperGithub = new wxHyperlinkCtrl(this, wxID_ANY, wxT("GitHub"), wxT("https://github.com/BeamMP"), wxPoint(130, 10));
Close(true); auto* txtSeparator3 = new wxStaticText(this, wxID_ANY, wxT("|"), wxPoint(180, 10));
}
void MyFrame::OnAbout(wxCommandEvent& event) {
wxMessageBox("This is a wxWidgets Hello World example", "About Hello World", auto* HyperWiki = new wxHyperlinkCtrl(this, wxID_ANY, wxT("Wiki"), wxT("https://wiki.beammp.com"), wxPoint(195, 10));
wxOK | wxICON_INFORMATION); auto* txtSeparator4 = new wxStaticText(this, wxID_ANY, wxT("|"), wxPoint(230, 10));
}
void MyFrame::OnHello(wxCommandEvent& event) { auto* HyperPatreon = new wxHyperlinkCtrl(this, wxID_ANY, wxT("Patreon"), wxT("https://www.patreon.com/BeamMP"), wxPoint(240, 10));
wxLogMessage("Hello world from wxWidgets!");
/////////// Update ///////////
auto* txtUpdate = new wxStaticText(this, wxID_ANY, wxT("Updating BeamMP "), wxPoint(10, 490));
auto* UpdateBar = new wxGauge(this, wxID_ANY, 100, wxPoint(10, 520), wxSize(127, -1));
UpdateBar->SetValue(0);
while (UpdateBar->GetValue() <76) {
txtUpdate->SetLabel(wxT("Updating BeamMP: " + std::to_string(UpdateBar->GetValue()) + "%"));
UpdateBar->SetValue(UpdateBar->GetValue() + 1);
}
/////////// Information ///////////
auto* txtGameVersion = new wxStaticText(this, wxID_ANY, wxT("Game Version: NA"), wxPoint(160, 490));
auto* txtPlayers = new wxStaticText(this, wxID_ANY, wxT("Currently Playing: NA"), wxPoint(300, 490));
auto* txtPatreon = new wxStaticText(this, wxID_ANY, wxT("Patreons:"), wxPoint(570, 490));
auto* txtPatreonList = new wxStaticText(this, wxID_ANY, wxT("yesn't"), wxPoint(570, 510));
auto* txtModVersion = new wxStaticText(this, wxID_ANY, wxT("Mod Version: NA"), wxPoint(160, 520));
auto* txtServers = new wxStaticText(this, wxID_ANY, wxT("Available Servers: NA"), wxPoint(300, 520));
auto* txtStatus = new wxStaticText(this, wxID_ANY, wxT("Status: NA"), wxPoint(880, 520));
auto* HorizontalLine3 = new wxStaticLine(this, wxID_ANY, wxPoint(10, 550), wxSize(950, 1));
/////////// Account ///////////
auto* bitmap = new wxBitmapButton(this, 39, wxBitmapBundle(wxImage("default.png", wxBITMAP_TYPE_PNG).Scale(45,45, wxIMAGE_QUALITY_HIGH)), wxPoint(20, 560), wxSize(45,45));
/////////// Buttons ///////////
auto btnSettings = new wxButton(this, 40, wxT("Settings"), wxPoint(730,570), wxSize(110, 25));
auto btnLaunch = new wxButton(this, 41, wxT("Launch"), wxPoint(850,570), wxSize(110, 25));
/////////// UI Colors ///////////
if (DarkMode) {
//Text Separators:
txtSeparator1->SetForegroundColour("white");
txtSeparator2->SetForegroundColour("white");
txtSeparator3->SetForegroundColour("white");
txtSeparator4->SetForegroundColour("white");
//Texts:
txtNews->SetForegroundColour("white");
txtUpdate->SetForegroundColour("white");
txtGameVersion->SetForegroundColour("white");
txtPlayers->SetForegroundColour("white");
txtModVersion->SetForegroundColour("white");
txtServers->SetForegroundColour("white");
txtPatreon->SetForegroundColour("white");
txtPatreonList->SetForegroundColour("white");
txtStatus->SetForegroundColour("white");
//Line Separators:
HorizontalLine1->SetForegroundColour("white");
HorizontalLine2->SetForegroundColour("white");
HorizontalLine3->SetForegroundColour("white");
//Logo:
auto* logo = new wxBitmapButton(this, 42, wxBitmapBundle(wxImage("BeamMPwhite.png", wxBITMAP_TYPE_PNG).Scale(100,100, wxIMAGE_QUALITY_HIGH)), wxPoint(850, -15), wxSize(100,100), wxBORDER_NONE);
logo->SetBackgroundColour(wxColour(40, 40, 40));
}
else {
//Logo:
auto* logo = new wxBitmapButton(this, 42, wxBitmapBundle(wxImage("BeamMP.png", wxBITMAP_TYPE_PNG).Scale(100,100, wxIMAGE_QUALITY_HIGH)), wxPoint(850, -15), wxSize(100,100), wxBORDER_NONE);
logo->SetBackgroundColour("white");
}
} }
int main(int argc, char* argv[]) { /////////// Account Frame Content ///////////
MyAccountFrame::MyAccountFrame() : wxFrame(nullptr, wxID_ANY, "Account Manager", wxDefaultPosition,wxDefaultSize,
wxMINIMIZE_BOX | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX) {
auto *handler = new wxPNGHandler;
wxImage::AddHandler(handler);
wxStaticBitmap *image;
image = new wxStaticBitmap( this, wxID_ANY, wxBitmapBundle(wxImage("default.png", wxBITMAP_TYPE_PNG).Scale(120,120, wxIMAGE_QUALITY_HIGH)), wxPoint(180,20), wxSize(120, 120));
auto* txtName = new wxStaticText(this, wxID_ANY, wxT("Name: NA"), wxPoint(210, 200));
auto btnLogout = new wxButton(this, wxID_ANY, wxT("Logout"), wxPoint(185,550), wxSize(110, 25));
/////////// UI Colors ///////////
if (DarkMode) {
//Text:
txtName->SetForegroundColour("white");
}
}
/////////// Settings Frame Content ///////////
MySettingsFrame::MySettingsFrame() :
wxFrame(nullptr, wxID_ANY, "Settings", wxDefaultPosition,wxDefaultSize,
wxMINIMIZE_BOX | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX) {
auto* txtName = new wxStaticText(this, wxID_ANY, wxT("settings1"), wxPoint(200, 200));
auto* txtName2 = new wxStaticText(this, wxID_ANY, wxT("settings12"), wxPoint(200, 200));
/////////// UI Colors ///////////
if (DarkMode) {
//Text:
txtName->SetForegroundColour("white");
txtName2->SetForegroundColour("white");
}
}
/////////// OnClickAccount Event ///////////
void MyMainFrame::OnClickAccount(wxCommandEvent& event WXUNUSED(event)) {
auto* AccountFrame = new MyAccountFrame();
AccountFrame->SetSize(500, 650);
AccountFrame->Center();
if (wxSystemSettings::GetAppearance().IsDark()) {
AccountFrame->SetBackgroundColour(wxColour(40, 40, 40));
AccountFrame->SetForegroundColour(wxColour(255, 255, 255));
}
else {
AccountFrame->SetBackgroundColour(wxColour("white"));
AccountFrame->SetForegroundColour(wxColour("white"));
}
AccountFrame->Show(true);
}
/////////// OnClickSettings Event ///////////
void MyMainFrame::OnClickSettings(wxCommandEvent& event WXUNUSED(event)) {
auto* SettingsFrame = new MySettingsFrame();
SettingsFrame->SetSize(500, 650);
SettingsFrame->Center();
if (wxSystemSettings::GetAppearance().IsDark()) {
SettingsFrame->SetBackgroundColour(wxColour(40, 40, 40));
SettingsFrame->SetForegroundColour(wxColour(255, 255, 255));
}
else {
SettingsFrame->SetBackgroundColour(wxColour("white"));
SettingsFrame->SetForegroundColour(wxColour("white"));
}
SettingsFrame->Show(true);
}
/////////// OnClickLogoEvent ///////////
void MyMainFrame::OnClickLogo(wxCommandEvent& event WXUNUSED(event)) {
wxLaunchDefaultApplication("https://beammp.com");
}
/////////// OnClickLaunch Event ///////////
void MyMainFrame::OnClickLaunch(wxCommandEvent& event WXUNUSED(event)) {
/*
try {
Launcher launcher(argc, argv);
launcher.RunDiscordRPC();
launcher.LoadConfig(); // check if json (issue)
launcher.CheckKey();
launcher.QueryRegistry();
// UI call
// launcher.SetupMOD();
launcher.LaunchGame();
launcher.WaitForGame();
LOG(INFO) << "Launcher shutting down";
} catch (const ShutdownException& e) {
LOG(INFO) << "Launcher shutting down with reason: " << e.what();
} catch (const std::exception& e) {
LOG(FATAL) << e.what();
}
std::this_thread::sleep_for(std::chrono::seconds(2));
Launcher::setExit(true);
*/
}
/////////// MAIN FUNCTION ///////////
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
wxDisableAsserts();
wxLog::SetLogLevel(wxLOG_Info);
new MyApp(); new MyApp();
return wxEntry(argc, argv); return wxEntry(hInstance, hPrevInstance, lpCmdLine, nShowCmd);
} }