From 4e261f788a857c15177fe28ca97e391fc4d0b59e Mon Sep 17 00:00:00 2001 From: IcePixelx <41352111+PixieCore@users.noreply.github.com> Date: Sat, 14 Aug 2021 01:56:05 +0200 Subject: [PATCH] Went over pr and added GetExportedFunction to address.h --- r5dev/r5dev.vcxproj | 16 ++- r5dev/src/CCompanion.cpp | 160 ++++++++++++------------- r5dev/src/hooks/hooks.cpp | 24 ++-- r5dev/src/id3dx.cpp | 62 ++++------ r5net/include/{ => r5}/r5net.h | 5 - r5net/include/{ => r5}/serverlisting.h | 2 - r5net/r5net.vcxproj | 10 +- r5net/r5net.vcxproj.filters | 6 +- r5net/src/netpch.cpp | 1 - r5net/src/r5net.cpp | 16 ++- r5net/src/serverlisting.cpp | 2 +- shared/include/address.h | 48 +++++++- 12 files changed, 189 insertions(+), 163 deletions(-) rename r5net/include/{ => r5}/r5net.h (99%) rename r5net/include/{ => r5}/serverlisting.h (86%) diff --git a/r5dev/r5dev.vcxproj b/r5dev/r5dev.vcxproj index 1df19480..005037e8 100644 --- a/r5dev/r5dev.vcxproj +++ b/r5dev/r5dev.vcxproj @@ -82,7 +82,7 @@ true - $(SolutionDir)r5net\include;$(SolutionDir)external\minhook\include;$(SolutionDir)external\imgui\include;$(SolutionDir)external\spdlog\include;$(SolutionDir)shared\include;$(SolutionDir)r5dev\include;$(IncludePath) + $(SolutionDir)r5net\include\r5;$(SolutionDir)external\minhook\include;$(SolutionDir)external\imgui\include;$(SolutionDir)external\spdlog\include;$(SolutionDir)shared\include;$(SolutionDir)r5dev\include;$(IncludePath) $(SolutionDir)external\minhook\lib\$(Configuration);$(SolutionDir)r5net\lib\$(Configuration);$(LibraryPath) $(SolutionDir)bin\$(Configuration)\ r5detours @@ -90,7 +90,7 @@ false - $(SolutionDir)r5net\include;$(SolutionDir)external\minhook\include;$(SolutionDir)external\imgui\include;$(SolutionDir)external\spdlog\include;$(SolutionDir)shared\include;$(SolutionDir)r5dev\include;$(IncludePath) + $(SolutionDir)r5net\include\r5;$(SolutionDir)external\minhook\include;$(SolutionDir)external\imgui\include;$(SolutionDir)external\spdlog\include;$(SolutionDir)shared\include;$(SolutionDir)r5dev\include;$(IncludePath) $(SolutionDir)external\minhook\lib\$(Configuration);$(SolutionDir)r5net\lib\$(Configuration);$(LibraryPath) $(SolutionDir)bin\$(Configuration)\ $(SolutionDir)build\$(ProjectName)\$(Configuration)\ @@ -157,7 +157,11 @@ if not EXIST $(SolutionDir)external\minhook\lib\$(Configuration)\Minhook.x64.lib ( "$(DevEnvDir)devenv" "$(SolutionDir)apex.sln" /Rebuild $(Configuration) /project "$(SolutionDir)external\minhook\libMinHook.vcxproj" -) +); + +if not EXIST $(SolutionDir)r5net\lib\$(Configuration)\r5net.lib ( +"$(DevEnvDir)devenv" "$(SolutionDir)apex.sln" /Rebuild $(Configuration) /project "$(SolutionDir)r5net\r5net.vcxproj" +); @@ -194,7 +198,11 @@ if not EXIST $(SolutionDir)external\minhook\lib\$(Configuration)\Minhook.x64.lib ( "$(DevEnvDir)devenv" "$(SolutionDir)apex.sln" /Rebuild $(Configuration) /project "$(SolutionDir)external\minhook\libMinHook.vcxproj" -) +); + +if not EXIST $(SolutionDir)r5net\lib\$(Configuration)\r5net.lib ( +"$(DevEnvDir)devenv" "$(SolutionDir)apex.sln" /Rebuild $(Configuration) /project "$(SolutionDir)r5net\r5net.vcxproj" +); diff --git a/r5dev/src/CCompanion.cpp b/r5dev/src/CCompanion.cpp index a354d245..fc579cc0 100644 --- a/r5dev/src/CCompanion.cpp +++ b/r5dev/src/CCompanion.cpp @@ -190,39 +190,39 @@ void CCompanion::ServerBrowserSection() } ImGui::EndTable(); } - ImGui::EndChild(); + ImGui::EndChild(); - ImGui::Separator(); + ImGui::Separator(); - ImGui::InputTextWithHint("##ServerBrowser_ServerConnString", "Enter IP address or \"localhost\"", ServerConnStringBuffer, IM_ARRAYSIZE(ServerConnStringBuffer)); + ImGui::InputTextWithHint("##ServerBrowser_ServerConnString", "Enter IP address or \"localhost\"", ServerConnStringBuffer, IM_ARRAYSIZE(ServerConnStringBuffer)); - ImGui::SameLine(); + ImGui::SameLine(); - if (ImGui::Button("Connect##ServerBrowser_ConnectByIp", ImVec2(ImGui::GetWindowContentRegionWidth() * (1.f / 3.f / 2.f), 19))) - { - //const char* replace = ""; // For history pos soon - std::stringstream cmd; - cmd << "connect " << ServerConnStringBuffer; - ConnectToServer(ServerConnStringBuffer); - //strcpy_s(ServerConnStringBuffer, sizeof(replace), replace); // For history pos soon - } + if (ImGui::Button("Connect##ServerBrowser_ConnectByIp", ImVec2(ImGui::GetWindowContentRegionWidth() * (1.f / 3.f / 2.f), 19))) + { + //const char* replace = ""; // For history pos soon + std::stringstream cmd; + cmd << "connect " << ServerConnStringBuffer; + ConnectToServer(ServerConnStringBuffer); + //strcpy_s(ServerConnStringBuffer, sizeof(replace), replace); // For history pos soon + } - ImGui::SameLine(); + ImGui::SameLine(); - if (ImGui::Button("Private Servers##ServerBrowser_PrivateServersButton", ImVec2(ImGui::GetWindowContentRegionWidth() * (1.f / 3.f / 2.f), 19))) - { - ImGui::OpenPopup("Connect to Private Server##PrivateServersConnectModal"); - } + if (ImGui::Button("Private Servers##ServerBrowser_PrivateServersButton", ImVec2(ImGui::GetWindowContentRegionWidth() * (1.f / 3.f / 2.f), 19))) + { + ImGui::OpenPopup("Connect to Private Server##PrivateServersConnectModal"); + } - bool modalOpen = true; - if (ImGui::BeginPopupModal("Connect to Private Server##PrivateServersConnectModal", &modalOpen)) - { - // I *WILL* move this in a separate class + bool modalOpen = true; + if (ImGui::BeginPopupModal("Connect to Private Server##PrivateServersConnectModal", &modalOpen)) + { + // I *WILL* move this in a separate class - ImGui::SetWindowSize(ImVec2(400.f, 200.f), ImGuiCond_Always); + ImGui::SetWindowSize(ImVec2(400.f, 200.f), ImGuiCond_Always); - /* When removing this and adding the resource instead. Please initialize the texture in the CCompanion class constructor. - Pixie*/ - static unsigned char lockedserver[] = { + /* When removing this and adding the resource instead. Please initialize the texture in the CCompanion class constructor. - Pixie*/ + static unsigned char lockedserver[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -271,69 +271,67 @@ void CCompanion::ServerBrowserSection() 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }; + // ^^^^ + // this definitely wont reach the final commit lmao + // Nope it will for now -Pixie + if (!ApexLockIcon) + { + bool ret = LoadTextureFromByteArray(lockedserver, ApexLockIconWidth, ApexLockIconHeight, &ApexLockIcon); // Load texture from byte array. + } - }; - // ^^^^ - // this definitely wont reach the final commit lmao - // Nope it will for now -Pixie - if (!ApexLockIcon) - { - bool ret = LoadTextureFromByteArray(lockedserver, ApexLockIconWidth, ApexLockIconHeight, &ApexLockIcon); // Load texture from byte array. - } - - ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.00f, 0.00f, 0.00f, 0.00f)); // Override the style color for child bg. - ImGui::BeginChild("##PrivateServersConnectModal_IconParent", ImVec2(ApexLockIconWidth, ApexLockIconHeight)); - { - ImGui::Image(ApexLockIcon, ImVec2(ApexLockIconWidth, ApexLockIconHeight)); // Display texture. - } - ImGui::EndChild(); - ImGui::PopStyleColor(); // Pop the override for the child bg. - - ImGui::SameLine(); - - ImGui::Text("Enter the following details to continue"); - - ImGui::PushItemWidth(ImGui::GetWindowContentRegionWidth()); // Override item width. - ImGui::InputTextWithHint("##PrivateServersConnectModal_TokenInput", "Token", &PrivateServerToken); - ImGui::InputTextWithHint("##PrivateServersConnectModal_PasswordInput", "Password", &PrivateServerPassword, ImGuiInputTextFlags_Password); - ImGui::PopItemWidth(); // Pop item width. - - ImGui::Dummy(ImVec2(ImGui::GetWindowContentRegionWidth(), 19.f)); // Place a dummy, basically making space inserting a blank element. - - ImGui::TextColored(PrivateServerMessageColor, PrivateServerRequestMessage.c_str()); - - ImGui::Separator(); - - if (ImGui::Button("Connect##PrivateServersConnectModal_ConnectButton", ImVec2(ImGui::GetWindowContentRegionWidth() / 2.f, 19))) - { - PrivateServerRequestMessage = ""; - ServerListing server; - bool result = r5net.GetServerByToken(server, PrivateServerRequestMessage, PrivateServerToken, PrivateServerPassword); // Send token connect request. - if (!server.name.empty()) - { - ConnectToServer(server.ip, server.port); // Connect to the server - PrivateServerRequestMessage = "Found Server: " + server.name; - PrivateServerMessageColor = ImVec4(0.00f, 1.00f, 0.00f, 1.00f); - ImGui::CloseCurrentPopup(); - } - else - { - PrivateServerRequestMessage = "Error: " + PrivateServerRequestMessage; - PrivateServerMessageColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); - } - - } - - ImGui::SameLine(); - - if (ImGui::Button("Close##PrivateServersConnectModal_CloseButton", ImVec2(ImGui::GetWindowContentRegionWidth() / 2.f, 19))) + ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.00f, 0.00f, 0.00f, 0.00f)); // Override the style color for child bg. + ImGui::BeginChild("##PrivateServersConnectModal_IconParent", ImVec2(ApexLockIconWidth, ApexLockIconHeight)); + { + ImGui::Image(ApexLockIcon, ImVec2(ApexLockIconWidth, ApexLockIconHeight)); // Display texture. + } + ImGui::EndChild(); + ImGui::PopStyleColor(); // Pop the override for the child bg. + + ImGui::SameLine(); + + ImGui::Text("Enter the following details to continue"); + + ImGui::PushItemWidth(ImGui::GetWindowContentRegionWidth()); // Override item width. + ImGui::InputTextWithHint("##PrivateServersConnectModal_TokenInput", "Token", &PrivateServerToken); + ImGui::InputTextWithHint("##PrivateServersConnectModal_PasswordInput", "Password", &PrivateServerPassword, ImGuiInputTextFlags_Password); + ImGui::PopItemWidth(); // Pop item width. + + ImGui::Dummy(ImVec2(ImGui::GetWindowContentRegionWidth(), 19.f)); // Place a dummy, basically making space inserting a blank element. + + ImGui::TextColored(PrivateServerMessageColor, PrivateServerRequestMessage.c_str()); + + ImGui::Separator(); + + if (ImGui::Button("Connect##PrivateServersConnectModal_ConnectButton", ImVec2(ImGui::GetWindowContentRegionWidth() / 2.f, 19))) + { + PrivateServerRequestMessage = ""; + ServerListing server; + bool result = r5net.GetServerByToken(server, PrivateServerRequestMessage, PrivateServerToken, PrivateServerPassword); // Send token connect request. + if (!server.name.empty()) { + ConnectToServer(server.ip, server.port); // Connect to the server + PrivateServerRequestMessage = "Found Server: " + server.name; + PrivateServerMessageColor = ImVec4(0.00f, 1.00f, 0.00f, 1.00f); ImGui::CloseCurrentPopup(); } - - ImGui::EndPopup(); + else + { + PrivateServerRequestMessage = "Error: " + PrivateServerRequestMessage; + PrivateServerMessageColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); + } } + + ImGui::SameLine(); + + if (ImGui::Button("Close##PrivateServersConnectModal_CloseButton", ImVec2(ImGui::GetWindowContentRegionWidth() / 2.f, 19))) + { + ImGui::CloseCurrentPopup(); + } + + ImGui::EndPopup(); } +} void CCompanion::HostServerSection() { diff --git a/r5dev/src/hooks/hooks.cpp b/r5dev/src/hooks/hooks.cpp index 3793c8a8..ad0c1801 100644 --- a/r5dev/src/hooks/hooks.cpp +++ b/r5dev/src/hooks/hooks.cpp @@ -47,14 +47,12 @@ void Hooks::InstallHooks() /////////////////////////////////////////////////////////////////////////////// // Hook WinAPI - HMODULE user32dll = GetModuleHandleA("user32.dll"); - - if (user32dll) + if (Module user32dll = Module("user32.dll"); user32dll.GetModuleBase()) // Is user32.dll valid? { - void* SetCursorPosPtr = GetProcAddress(user32dll, "SetCursorPos"); - void* ClipCursorPtr = GetProcAddress(user32dll, "ClipCursor"); - void* GetCursorPosPtr = GetProcAddress(user32dll, "GetCursorPos"); - void* ShowCursorPtr = GetProcAddress(user32dll, "ShowCursor"); + void* SetCursorPosPtr = user32dll.GetExportedFunction("SetCursorPos"); + void* ClipCursorPtr = user32dll.GetExportedFunction("ClipCursor"); + void* GetCursorPosPtr = user32dll.GetExportedFunction("GetCursorPos"); + void* ShowCursorPtr = user32dll.GetExportedFunction("ShowCursor"); MH_CreateHook(SetCursorPosPtr, &Hooks::SetCursorPos, reinterpret_cast(&originalSetCursorPos)); MH_CreateHook(ClipCursorPtr, &Hooks::ClipCursor, reinterpret_cast(&originalClipCursor)); @@ -124,14 +122,12 @@ void Hooks::RemoveHooks() /////////////////////////////////////////////////////////////////////////////// // Unhook WinAPI - HMODULE user32dll = GetModuleHandleA("user32.dll"); - - if (user32dll) + if (Module user32dll = Module("user32.dll"); user32dll.GetModuleBase()) // Is user32.dll valid? { - void* SetCursorPosPtr = GetProcAddress(user32dll, "SetCursorPos"); - void* ClipCursorPtr = GetProcAddress(user32dll, "ClipCursor"); - void* GetCursorPosPtr = GetProcAddress(user32dll, "GetCursorPos"); - void* ShowCursorPtr = GetProcAddress(user32dll, "ShowCursor"); + void* SetCursorPosPtr = user32dll.GetExportedFunction("SetCursorPos"); + void* ClipCursorPtr = user32dll.GetExportedFunction("ClipCursor"); + void* GetCursorPosPtr = user32dll.GetExportedFunction("GetCursorPos"); + void* ShowCursorPtr = user32dll.GetExportedFunction("ShowCursor"); MH_RemoveHook(SetCursorPosPtr); MH_RemoveHook(ClipCursorPtr); diff --git a/r5dev/src/id3dx.cpp b/r5dev/src/id3dx.cpp index c830c2d5..31962ca3 100644 --- a/r5dev/src/id3dx.cpp +++ b/r5dev/src/id3dx.cpp @@ -9,7 +9,6 @@ #include "CCompanion.h" #include "CGameConsole.h" - #pragma comment(lib, "d3d11.lib") /*--------------------------------------------------------------------------------- @@ -29,7 +28,6 @@ extern BOOL g_bShowConsole = false; extern BOOL g_bShowBrowser = false; static BOOL g_bInitMenu = false; static BOOL g_bInitialized = false; -static BOOL g_bPresentHooked = false; /////////////////////////////////////////////////////////////////////////////////// static WNDPROC g_oWndProc = NULL; @@ -227,18 +225,12 @@ void GetPresent() pDeviceVTable = (DWORD_PTR*)pDevice; pDeviceVTable = (DWORD_PTR*)pDeviceVTable[0]; - int pIDX = (int)DXGISwapChainVTbl::Present; - int rIDX = (int)DXGISwapChainVTbl::ResizeBuffers; - - g_fnIDXGISwapChainPresent = (IDXGISwapChainPresent)(DWORD_PTR)pSwapChainVtable[pIDX]; - g_oResizeBuffers = (IDXGIResizeBuffers)(DWORD_PTR)pSwapChainVtable[rIDX]; + g_fnIDXGISwapChainPresent = (IDXGISwapChainPresent)(DWORD_PTR)pSwapChainVtable[(int)DXGISwapChainVTbl::Present]; + g_oResizeBuffers = (IDXGIResizeBuffers)(DWORD_PTR)pSwapChainVtable[(int)DXGISwapChainVTbl::ResizeBuffers]; pSwapChain->Release(); pContext->Release(); pDevice->Release(); - - /////////////////////////////////////////////////////////////////////////////// - g_bPresentHooked = true; } //################################################################################# @@ -316,7 +308,7 @@ void CreateRenderTarget(IDXGISwapChain* pSwapChain) void DestroyRenderTarget() { - if (nullptr != g_pRenderTargetView) + if (g_pRenderTargetView) { g_pRenderTargetView->Release(); g_pRenderTargetView = nullptr; @@ -348,7 +340,6 @@ HRESULT __stdcall GetResizeBuffers(IDXGISwapChain* pSwapChain, UINT nBufferCount g_bShowConsole = false; g_bShowBrowser = false; g_bInitialized = false; - g_bPresentHooked = false; /////////////////////////////////////////////////////////////////////////////// @@ -448,19 +439,6 @@ bool LoadTextureFromByteArray(unsigned char* image_data, const int& image_width, void InstallDXHooks() { - HMODULE user32dll = GetModuleHandleA("user32.dll"); - - if (user32dll) - { - IPostMessageA PostMessageA = (IPostMessageA)GetProcAddress(user32dll, "PostMessageA"); - IPostMessageW PostMessageW = (IPostMessageW)GetProcAddress(user32dll, "PostMessageW"); - } - - /////////////////////////////////////////////////////////////////////////////// - // Hook PostMessage - MH_CreateHook(PostMessageA, &HPostMessageA, reinterpret_cast(&g_oPostMessageA)); - MH_CreateHook(PostMessageW, &HPostMessageW, reinterpret_cast(&g_oPostMessageW)); - /////////////////////////////////////////////////////////////////////////////// // Hook SwapChain MH_CreateHook(g_fnIDXGISwapChainPresent, &Present, reinterpret_cast(&originalPresent)); @@ -468,26 +446,36 @@ void InstallDXHooks() /////////////////////////////////////////////////////////////////////////////// // Enable hooks - MH_EnableHook(PostMessageA); - MH_EnableHook(PostMessageW); MH_EnableHook(g_fnIDXGISwapChainPresent); MH_EnableHook(g_oResizeBuffers); + + if (Module user32dll = Module("user32.dll"); user32dll.GetModuleBase()) // Is user32.dll valid? + { + IPostMessageA PostMessageA = user32dll.GetExportedFunction("PostMessageA").RCast(); + IPostMessageW PostMessageW = user32dll.GetExportedFunction("PostMessageW").RCast(); + + /////////////////////////////////////////////////////////////////////////////// + // Hook PostMessage + MH_CreateHook(PostMessageA, &HPostMessageA, reinterpret_cast(&g_oPostMessageA)); + MH_CreateHook(PostMessageW, &HPostMessageW, reinterpret_cast(&g_oPostMessageW)); + + MH_EnableHook(PostMessageA); + MH_EnableHook(PostMessageW); + } } void RemoveDXHooks() { - HMODULE user32dll = GetModuleHandleA("user32.dll"); - - if (user32dll) - { - IPostMessageA PostMessageA = (IPostMessageA)GetProcAddress(user32dll, "PostMessageA"); - IPostMessageW PostMessageW = (IPostMessageW)GetProcAddress(user32dll, "PostMessageW"); - } - /////////////////////////////////////////////////////////////////////////////// // Unhook PostMessage - MH_RemoveHook(PostMessageA); - MH_RemoveHook(PostMessageW); + if (Module user32dll = Module("user32.dll"); user32dll.GetModuleBase()) // Is user32.dll valid? + { + IPostMessageA PostMessageA = user32dll.GetExportedFunction("PostMessageA").RCast(); + IPostMessageW PostMessageW = user32dll.GetExportedFunction("PostMessageW").RCast(); + + MH_RemoveHook(PostMessageA); + MH_RemoveHook(PostMessageW); + } /////////////////////////////////////////////////////////////////////////////// // Unhook SwapChain diff --git a/r5net/include/r5net.h b/r5net/include/r5/r5net.h similarity index 99% rename from r5net/include/r5net.h rename to r5net/include/r5/r5net.h index fba7f02e..dadf9124 100644 --- a/r5net/include/r5net.h +++ b/r5net/include/r5/r5net.h @@ -4,7 +4,6 @@ namespace R5Net { - struct Config { std::string MOTD; @@ -19,14 +18,10 @@ namespace R5Net Client(std::string serverString) : m_HttpClient(serverString.c_str()) { m_HttpClient.set_connection_timeout(10); - } - std::vector GetServersList(); - bool PostServerHost(std::string& outMessage, std::string& outToken, const ServerListing& serverListing); - bool GetServerByToken(ServerListing& outServer, std::string& outError, const std::string& token, const std::string& password = ""); }; } \ No newline at end of file diff --git a/r5net/include/serverlisting.h b/r5net/include/r5/serverlisting.h similarity index 86% rename from r5net/include/serverlisting.h rename to r5net/include/r5/serverlisting.h index 92cd0a30..4209c19a 100644 --- a/r5net/include/serverlisting.h +++ b/r5net/include/r5/serverlisting.h @@ -1,7 +1,5 @@ #pragma once -#include "netpch.h" - struct ServerListing { std::string name; diff --git a/r5net/r5net.vcxproj b/r5net/r5net.vcxproj index 081afc9e..577d5ed0 100644 --- a/r5net/r5net.vcxproj +++ b/r5net/r5net.vcxproj @@ -20,7 +20,7 @@ - + @@ -91,14 +91,14 @@ true - $(ProjectDir)lib\$(Configuration) - $(SolutionDir)build\$(ProjectName)\$(Configuration) + $(ProjectDir)lib\$(Configuration)\ + $(SolutionDir)build\$(ProjectName)\$(Configuration)\ $(SolutionDir)shared\include;$(ProjectDir)include;$(IncludePath) false - $(ProjectDir)lib\$(Configuration) - $(SolutionDir)build\$(ProjectName)\$(Configuration) + $(ProjectDir)lib\$(Configuration)\ + $(SolutionDir)build\$(ProjectName)\$(Configuration)\ $(SolutionDir)shared\include;$(ProjectDir)include;$(IncludePath) diff --git a/r5net/r5net.vcxproj.filters b/r5net/r5net.vcxproj.filters index f76f868a..f50c168f 100644 --- a/r5net/r5net.vcxproj.filters +++ b/r5net/r5net.vcxproj.filters @@ -9,15 +9,15 @@ - - include - include include + + include + diff --git a/r5net/src/netpch.cpp b/r5net/src/netpch.cpp index 783231ed..0c622c94 100644 --- a/r5net/src/netpch.cpp +++ b/r5net/src/netpch.cpp @@ -1,3 +1,2 @@ #pragma once - #include "netpch.h" \ No newline at end of file diff --git a/r5net/src/r5net.cpp b/r5net/src/r5net.cpp index 28d2fca3..c7d3d916 100644 --- a/r5net/src/r5net.cpp +++ b/r5net/src/r5net.cpp @@ -2,14 +2,11 @@ // #include "netpch.h" -#include "r5net.h" +#include "r5\r5net.h" - -using namespace R5Net; - -std::vector Client::GetServersList() +std::vector R5Net::Client::GetServersList() { - std::vector list; + std::vector list{ }; auto res = m_HttpClient.Get("/servers"); @@ -23,11 +20,10 @@ std::vector Client::GetServersList() ); } } - return list; } -bool Client::PostServerHost(std::string& outMessage, std::string& outToken, const ServerListing& serverListing) +bool R5Net::Client::PostServerHost(std::string& outMessage, std::string& outToken, const ServerListing& serverListing) { nlohmann::json reqBody = nlohmann::json::object(); reqBody["name"] = serverListing.name; @@ -48,7 +44,7 @@ bool Client::PostServerHost(std::string& outMessage, std::string& outToken, cons if (resBody["token"].is_string()) outToken = resBody["token"].get(); else - outToken = ""; + outToken = ""; return true; } else @@ -94,5 +90,7 @@ bool R5Net::Client::GetServerByToken(ServerListing& outServer, std::string& outE outServer = ServerListing{}; return false; } + + return false; } diff --git a/r5net/src/serverlisting.cpp b/r5net/src/serverlisting.cpp index fecac08a..1f5f5a71 100644 --- a/r5net/src/serverlisting.cpp +++ b/r5net/src/serverlisting.cpp @@ -1,3 +1,3 @@ #include "netpch.h" -#include "serverlisting.h" +#include "r5\serverlisting.h" diff --git a/shared/include/address.h b/shared/include/address.h index f7d92531..9a9d88b6 100644 --- a/shared/include/address.h +++ b/shared/include/address.h @@ -343,7 +343,7 @@ public: { for (ModuleSections& currentSection : moduleSections) { - printf(" [+Module: %s+]%s, %p\n", moduleName.c_str(), currentSection.sectionName.c_str(), currentSection.sectionStartAddress); + printf(" [+Module: %s+]%s, %p\n", moduleName.c_str(), currentSection.sectionName.c_str(), reinterpret_cast(currentSection.sectionStartAddress)); } } @@ -436,6 +436,52 @@ public: return MemoryAddress(latestOccurence); } + + MemoryAddress GetExportedFunction(const std::string functionName) + { + if (!dosHeader || dosHeader->e_magic != IMAGE_DOS_SIGNATURE) // Is dosHeader valid? + return MemoryAddress(); + + if (!ntHeaders || ntHeaders->Signature != IMAGE_NT_SIGNATURE) // Is ntHeader valid? + return MemoryAddress(); + + // Get the location of IMAGE_EXPORT_DIRECTORY for this module by adding the IMAGE_DIRECTORY_ENTRY_EXPORT relative virtual address onto our module base address. + IMAGE_EXPORT_DIRECTORY* ImageExportDirectory = reinterpret_cast(moduleBase + ntHeaders->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress); + if (!ImageExportDirectory) + return MemoryAddress(); + + // Are there any exported functions? + if (!ImageExportDirectory->NumberOfFunctions) + return MemoryAddress(); + + // Get the location of the functions via adding the relative virtual address from the struct into our module base address. + DWORD* AddressOfFunctionsPtr = reinterpret_cast(moduleBase + ImageExportDirectory->AddressOfFunctions); + if (!AddressOfFunctionsPtr) + return MemoryAddress(); + + // Get the names of the functions via adding the relative virtual address from the struct into our module base address. + DWORD* AddressOfNamePtr = reinterpret_cast(moduleBase + ImageExportDirectory->AddressOfNames); + if (!AddressOfNamePtr) + return MemoryAddress(); + + // Get the ordinals of the functions via adding the relative virtual address from the struct into our module base address. + DWORD* AddressOfOrdinalsPtr = reinterpret_cast(moduleBase + ImageExportDirectory->AddressOfNameOrdinals); + if (!AddressOfOrdinalsPtr) + return MemoryAddress(); + + for (std::size_t i = 0; i < ImageExportDirectory->NumberOfFunctions; i++) // Iterate through all the functions. + { + // Get virtual relative address of the function name. Then add module base address to get the actual location. + std::string ExportFunctionName = reinterpret_cast(reinterpret_cast(moduleBase + AddressOfNamePtr[i])); + + if (ExportFunctionName.compare(functionName) == 0) // Is this our wanted exported function? + { + // Get the function ordinal. Then grab the relative virtual address of our wanted function. Then add module base address so we get the actual location. + return MemoryAddress(moduleBase + AddressOfFunctionsPtr[reinterpret_cast(AddressOfOrdinalsPtr)[i]]); // Return as MemoryAddress class. + } + } + return MemoryAddress(); + } MemoryAddress FindAddressForString(const std::string string, bool nullTerminator) {