Skip to content
Snippets Groups Projects
Commit 16aebf1d authored by cos-erm's avatar cos-erm
Browse files

Raw to unique pointer - allows for newer and older dll versions

parent 8c62fb42
No related branches found
No related tags found
No related merge requests found
......@@ -59,8 +59,8 @@ bool FVAPlugin::bUseVA = true;
bool FVAPlugin::bDebugMode = true;
// Interface Classes to Server
IVANetClient* FVAPlugin::VANetClient;
IVAInterface* FVAPlugin::VAServer;
std::unique_ptr<IVANetClient> FVAPlugin::VANetClient;
std::unique_ptr<IVAInterface> FVAPlugin::VAServer;
// Link to the current receiver actor
AVAReceiverActor* FVAPlugin::ReceiverActor = nullptr;
......@@ -293,7 +293,16 @@ bool FVAPlugin::ConnectServer(const FString HostF, const int Port)
FVAUtils::LogStuff("[FVAPlugin::ConnectServer()]: Connecting to VAServer. Be sure to have it switched on", false);
try
{
VANetClient = IVANetClient::Create();
VANetClient = []() {
if constexpr (std::is_same_v<decltype(IVANetClient::Create()),std::unique_ptr<IVANetClient>>) {
// New dll (>= 2025) with unique pointer
return IVANetClient::Create();
}
else {
// Old dll with raw pointer -> convert to unique pointer
return std::unique_ptr<IVANetClient>{IVANetClient::Create()};
}
}();
const std::string HostS(TCHAR_TO_UTF8(*HostF));
VANetClient->Initialize(HostS, Port);
......@@ -304,7 +313,22 @@ bool FVAPlugin::ConnectServer(const FString HostF, const int Port)
return false;
}
VAServer = VANetClient->GetCoreInstance();
VAServer = []() -> std::unique_ptr<IVAInterface> {
using IVANetInstance = decltype(std::declval<IVANetClient>());
if constexpr (std::is_same_v<
decltype(std::declval<IVANetInstance>().GetCoreInstance()),
std::unique_ptr<IVAInterface>
>) {
// New dll (>= 2025)
return std::move(VANetClient->GetCoreInstance());
}
else {
// Old dll
return std::unique_ptr<IVAInterface>{VANetClient->GetCoreInstance()};
}
}();
VAServer->Reset();
}
catch (CVAException& e)
......
......@@ -179,8 +179,8 @@ protected:
static bool bDebugMode; // bool if is in Debug Mode
// Interface Classes to Server
static IVANetClient* VANetClient; // VA Net Client
static IVAInterface* VAServer; // VA Server Interface
static std::unique_ptr<IVANetClient> VANetClient; // VA Net Client
static std::unique_ptr<IVAInterface> VAServer; // VA Server Interface
// Link to the current receiver actor
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment