Pylon C++ implementation actually working now

This commit is contained in:
Alex 2021-12-28 22:07:02 +02:00
parent 00cd76f7b2
commit a3946bb5ce
9 changed files with 198 additions and 9 deletions

73
r5dev/IDevPalette.h Normal file
View File

@ -0,0 +1,73 @@
#pragma once
#include "core/stdafx.h"
#include <windows/id3dx.h>
#include <networksystem/r5net.h>
#include <gameui/IConsole.h>
#ifndef DEDICATED
class CDevPalette
{
public:
void Draw(bool* bDraw)
{
ImGui::SetNextWindowSize(ImVec2(1000, 600), ImGuiCond_FirstUseEver);
ImGui::SetWindowPos(ImVec2(-1000, 50), ImGuiCond_FirstUseEver);
if (!ImGui::Begin("Dev Palette", bDraw))
{
ImGui::End();
return;
}
if (ImGui::Button("Get Stats"))
{
auto response = g_pR5net->GetGlobalStats();
switch (response.status)
{
case R5Net::EResponseStatus::SUCCESS:
{
g_GameConsole->AddLog("SUCCESS: %d players, %d servers", response.noPlayers, response.noServers);
break;
}
default:
{
g_GameConsole->AddLog("ERROR: %s", response.error.c_str());
}
}
}
if (ImGui::Button("Send Fake Server Request"))
{
R5Net::UpdateGameServerMSRequest request{};
request.gameServer.name = "TestNameServer";
request.gameServer.playlist = "yoopp";
request.gameServer.gamePort = 8089;
auto response = g_pR5net->UpdateMyGameServer(request);
switch (response.status)
{
case R5Net::EResponseStatus::SUCCESS:
{
g_GameConsole->AddLog("SUCCESS: %s", response.gameServer.name.c_str());
break;
}
default:
{
g_GameConsole->AddLog("ERROR: %s", response.error.c_str());
}
}
}
if (*bDraw == NULL)
{
g_bShowBrowser = false;
}
ImGui::End();
}
};
void DrawDevPalette(bool* bDraw);
extern CDevPalette* g_DevPalette;
#endif

26
r5dev/IDevPallete.cpp Normal file
View File

@ -0,0 +1,26 @@
#include "core/stdafx.h"
#ifndef DEDICATED
#include "IDevPalette.h"
//#############################################################################
// ENTRYPOINT
//#############################################################################
CDevPalette* g_DevPalette = nullptr;
void DrawDevPalette(bool* bDraw)
{
static CDevPalette devPalette;
static bool AssignPtr = []()
{
g_DevPalette = &devPalette;
return true;
} ();
if (*bDraw) devPalette.Draw(bDraw);
}
///////////////////////////////////////////////////////////////////////////
#endif

View File

@ -7,3 +7,4 @@
#define IM_FMTARGS(FMT) __attribute__((format(printf, FMT, FMT+1)))
#define IM_FMTARGS(FMT) __attribute__((format(gnu_printf, FMT, FMT+1)))
#define IM_FMTARGS(FMT)
#define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, __VA_ARGS__) friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }

View File

@ -78,7 +78,8 @@ namespace R5Net {
SUCCESS,
FORBIDDEN,
NOT_FOUND,
MS_ERROR
MS_ERROR,
UNKNOWN
};
@ -108,7 +109,9 @@ namespace R5Net {
struct UpdateGameServerMSResponse : DefaultMSResponse
{
NetGameServer gameServer;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(UpdateGameServerMSResponse, gameServer)
};
struct GetIsUserBannedMSResponse : DefaultMSResponse

View File

@ -5,25 +5,97 @@
namespace R5Net
{
#define R5NET_GET_ENDPOINT(FuncName, Route, ResponseStructType) ResponseStructType FuncName() {\
#define R5NET_GET_ENDPOINT(FuncName, Route, ResponseStructType)\
ResponseStructType FuncName() {\
ResponseStructType result{};\
httplib::Result response = HttpClient.Get(Route);\
if(response == nullptr) return result;\
switch(response->status)\
{\
case 403:\
{\
result.status = EResponseStatus::FORBIDDEN;\
break;\
}\
case 404:\
{\
result.status = EResponseStatus::NOT_FOUND;\
break;\
}\
case 500:\
{\
result.status = EResponseStatus::MS_ERROR;\
break;\
}\
case 200:\
{\
result.status = EResponseStatus::SUCCESS;\
break;\
}\
default: \
{\
result.status = EResponseStatus::UNKNOWN;\
break;\
}\
}\
nlohmann::json response_body = nlohmann::json::parse(response->body);\
nlohmann::to_json(response_body, result);\
from_json(response_body, result);\
return result;\
}\
\
void FuncName##_Async(std::function<void(ResponseStructType)> Callback) {\
std::thread t([&]() {\
Callback(FuncName());\
});\
t.detach();\
}\
#define R5NET_POST_ENDPOINT(FuncName, Route, RequestStructType, ResponseStructType) ResponseStructType FuncName(RequestStructType& request) {\
#define R5NET_POST_ENDPOINT(FuncName, Route, RequestStructType, ResponseStructType)\
ResponseStructType FuncName(const RequestStructType& request) {\
ResponseStructType result{};\
nlohmann::json request_body;\
nlohmann::to_json(request_body, request);\
to_json(request_body, request);\
httplib::Result response = HttpClient.Post(Route, request_body.dump(), "application/json");\
if (response == nullptr) return result;\
switch(response->status)\
{\
case 403:\
{\
result.status = EResponseStatus::FORBIDDEN;\
break;\
}\
case 404:\
{\
result.status = EResponseStatus::NOT_FOUND;\
break;\
}\
case 500:\
{\
result.status = EResponseStatus::MS_ERROR;\
break;\
}\
case 200:\
{\
result.status = EResponseStatus::SUCCESS;\
break;\
}\
default: \
{\
result.status = EResponseStatus::UNKNOWN;\
break;\
}\
}\
nlohmann::json response_body = nlohmann::json::parse(response->body);\
nlohmann::to_json(response_body, result);\
from_json(response_body, result);\
return result;\
}
}\
\
void FuncName##_Async(const RequestStructType& request, std::function<void(ResponseStructType)> Callback) {\
std::thread t([&]() {\
Callback(FuncName(request));\
});\
t.detach();\
}\
class Client
@ -41,8 +113,8 @@ namespace R5Net
R5NET_GET_ENDPOINT(GetGameServersList, "/api/game_servers/list", GetGameServersListMSResponse)
R5NET_POST_ENDPOINT(UpdateMyGameServer, "/api/game_servers/update", UpdateGameServerMSRequest, UpdateGameServerMSResponse)
R5NET_POST_ENDPOINT(GetClientIsBanned, "/api/ban_system/is_user_banned", GetIsUserBannedMSRequest, GetIsUserBannedMSResponse)
R5NET_POST_ENDPOINT(GetPrivateGameServerInfo, "/api/game_servers/game_server_private_info", GetPrivateGameServerInfoMSRequest, GetPrivateGameServerInfoMSResponse)
R5NET_POST_ENDPOINT(GetClientIsBanned, "/api/ban_system/is_user_banned", GetIsUserBannedMSRequest, GetIsUserBannedMSResponse)

View File

@ -2483,7 +2483,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
#define NLOHMANN_JSON_PASTE64(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE63(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63)
#define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1;
#define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1);
#define NLOHMANN_JSON_FROM(v1) try { nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1); } catch(...) {}
/*!
@brief macro

View File

@ -40,6 +40,7 @@
<ClCompile Include="engine\sys_dll2.cpp" />
<ClCompile Include="engine\sys_utils.cpp" />
<ClCompile Include="gameui\IConsole.cpp" />
<ClCompile Include="IDevPallete.cpp" />
<ClCompile Include="inputsystem\inputsystem.cpp" />
<ClCompile Include="launcher\IApplication.cpp" />
<ClCompile Include="mathlib\adler32.cpp" />
@ -131,6 +132,7 @@
<ClInclude Include="engine\sys_dll2.h" />
<ClInclude Include="engine\sys_utils.h" />
<ClInclude Include="gameui\IConsole.h" />
<ClInclude Include="IDevPalette.h" />
<ClInclude Include="inputsystem\ButtonCode.h" />
<ClInclude Include="inputsystem\inputsystem.h" />
<ClInclude Include="launcher\IApplication.h" />

View File

@ -300,6 +300,9 @@
<ClCompile Include="engine\host_cmd.cpp">
<Filter>sdk\engine</Filter>
</ClCompile>
<ClCompile Include="IDevPallete.cpp">
<Filter>sdk\gameui</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="client\cdll_engine_int.h">
@ -833,6 +836,9 @@
<ClInclude Include="networksystem\net_structs.h">
<Filter>sdk\networksystem</Filter>
</ClInclude>
<ClInclude Include="IDevPalette.h">
<Filter>sdk\gameui</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="r5dev.def" />

View File

@ -9,6 +9,7 @@
#include "engine/sys_utils.h"
#include "inputsystem/inputsystem.h"
#include "public/include/stb_image.h"
#include <IDevPalette.h>
/**********************************************************************************
-----------------------------------------------------------------------------------
@ -279,6 +280,11 @@ void DrawImGui()
g_pInputSystem->EnableInput(false); // Disable input to game when console is drawn.
DrawConsole(&bShowConsole);
}
if (g_bShowBrowser)
{
g_pInputSystem->EnableInput(false);
DrawDevPalette(&bShowBrowser);
}
if (!g_bShowConsole && !g_bShowBrowser)
{
g_pInputSystem->EnableInput(true); // Enable input to game when both are not drawn.