diff --git a/Source/VAPlugin/Private/VAPlugin.cpp b/Source/VAPlugin/Private/VAPlugin.cpp index 7d8d456d1e4f4134ad857520f3a37b2cdf0aa94c..b9aae9e72f89fff0429303fb2c345b885f93ba9c 100644 --- a/Source/VAPlugin/Private/VAPlugin.cpp +++ b/Source/VAPlugin/Private/VAPlugin.cpp @@ -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) diff --git a/Source/VAPlugin/Private/VAPlugin.h b/Source/VAPlugin/Private/VAPlugin.h index d4874d279772cba27745b138d443a2fc9364993f..c19c1517fa51b4bd673709ec1bf685c3ffa46f8b 100644 --- a/Source/VAPlugin/Private/VAPlugin.h +++ b/Source/VAPlugin/Private/VAPlugin.h @@ -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