Skip to content

Commit 94ee4e6

Browse files
Joesnowyote
Joe
authored andcommitted
[Unreal] Fix for Shipping Builds (#112)
* Changes to allow plugin to work in Shipping Builds * Add files via upload SourceTree is case-insensitive on Windows, fixin * Remove duplicated directory * Platform whitelist, mac support, compilation fix. * Finalization steps * Mac fix * Tabs/Spaces consistency. * Updated build.py #89 * .gitignore (headers) * Renamed folder to lowercase * Removed duplicates * Revert to lowercase
1 parent bd294d5 commit 94ee4e6

File tree

14 files changed

+229
-173
lines changed

14 files changed

+229
-173
lines changed

build.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,18 @@ def unreal(ctx):
101101

102102
click.echo('--- Copying libs and header into unreal example')
103103

104-
UNREAL_PROJECT_PATH = os.path.join(SCRIPT_PATH, 'examples', 'unrealstatus', 'plugins', 'discordrpc')
104+
UNREAL_PROJECT_PATH = os.path.join(SCRIPT_PATH, 'examples', 'unrealstatus', 'Plugins', 'discordrpc')
105105
BUILD_BASE_PATH = os.path.join(SCRIPT_PATH, 'builds', 'win64-dynamic', 'src', 'Release')
106106

107-
UNREAL_DLL_PATH = os.path.join(UNREAL_PROJECT_PATH, 'Binaries', 'ThirdParty', 'discordrpcLibrary', 'Win64')
107+
UNREAL_DLL_PATH = os.path.join(UNREAL_PROJECT_PATH, 'Source', 'ThirdParty', 'DiscordRpcLibrary', 'Win64')
108108
mkdir_p(UNREAL_DLL_PATH)
109109
shutil.copy(os.path.join(BUILD_BASE_PATH, 'discord-rpc.dll'), UNREAL_DLL_PATH)
110110

111-
UNREAL_INCLUDE_PATH = os.path.join(UNREAL_PROJECT_PATH, 'Source', 'ThirdParty', 'discordrpcLibrary', 'Include')
111+
UNREAL_INCLUDE_PATH = os.path.join(UNREAL_PROJECT_PATH, 'Source', 'ThirdParty', 'DiscordRpcLibrary', 'Include')
112112
mkdir_p(UNREAL_INCLUDE_PATH)
113113
shutil.copy(os.path.join(SCRIPT_PATH, 'include', 'discord-rpc.h'), UNREAL_INCLUDE_PATH)
114114

115-
UNREAL_LIB_PATH = os.path.join(UNREAL_PROJECT_PATH, 'Source', 'ThirdParty', 'discordrpcLibrary', 'x64', 'Release')
115+
UNREAL_LIB_PATH = os.path.join(UNREAL_PROJECT_PATH, 'Source', 'ThirdParty', 'DiscordRpcLibrary', 'Win64')
116116
mkdir_p(UNREAL_LIB_PATH)
117117
shutil.copy(os.path.join(BUILD_BASE_PATH, 'discord-rpc.lib'), UNREAL_LIB_PATH)
118118

examples/unrealstatus/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,6 @@ Intermediate/
7373

7474
# Cache files for the editor to use
7575
DerivedDataCache/
76+
77+
# Library headers must be copied automatically by the build script (build.py unreal)
78+
Plugins/DiscordRpc/Source/ThirdParty/DiscordRpcLibrary/Include

examples/unrealstatus/Plugins/discordrpc/discordrpc.uplugin renamed to examples/unrealstatus/Plugins/discordrpc/DiscordRpc.uplugin

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@
1515
"Installed": false,
1616
"Modules": [
1717
{
18-
"Name": "discordrpc",
19-
"Type": "Developer",
20-
"LoadingPhase": "Default"
18+
"Name": "DiscordRpc",
19+
"Type": "Runtime",
20+
"LoadingPhase": "PreDefault",
21+
"WhitelistPlatforms" :
22+
[
23+
"Win64",
24+
"Linux",
25+
"Mac"
26+
]
2127
}
2228
]
2329
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
2+
3+
using UnrealBuildTool;
4+
using System.IO;
5+
6+
public class DiscordRpc : ModuleRules
7+
{
8+
#if WITH_FORWARDED_MODULE_RULES_CTOR
9+
public DiscordRpc(ReadOnlyTargetRules Target) : base(Target)
10+
#else
11+
public DiscordRpc(TargetInfo Target)
12+
#endif
13+
{
14+
Definitions.Add("DISCORD_DYNAMIC_LIB=1");
15+
16+
PublicIncludePaths.AddRange(
17+
new string[] {
18+
"DiscordRpc/Public"
19+
}
20+
);
21+
22+
PrivateIncludePaths.AddRange(
23+
new string[] {
24+
"DiscordRpc/Private"
25+
}
26+
);
27+
28+
PublicDependencyModuleNames.AddRange(
29+
new string[]
30+
{
31+
"Core",
32+
"DiscordRpcLibrary"
33+
}
34+
);
35+
36+
PrivateDependencyModuleNames.AddRange(
37+
new string[]
38+
{
39+
"CoreUObject",
40+
"Engine",
41+
"Slate",
42+
"SlateCore",
43+
"Projects"
44+
}
45+
);
46+
47+
DynamicallyLoadedModuleNames.AddRange(
48+
new string[]
49+
{
50+
// ... add any modules that your module loads dynamically here ...
51+
}
52+
);
53+
54+
string BaseDirectory = Path.GetFullPath(Path.Combine(ModuleDirectory, "..", "..", "Source", "ThirdParty", "DiscordRpcLibrary"));
55+
PublicIncludePaths.Add(Path.Combine(BaseDirectory, "Include"));
56+
}
57+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
2+
3+
#include "DiscordRpcPrivatePCH.h"
4+
#include "IPluginManager.h"
5+
#include "ModuleManager.h"
6+
7+
#define LOCTEXT_NAMESPACE "FDiscordRpcModule"
8+
9+
void FDiscordRpcModule::StartupModule()
10+
{
11+
#if !PLATFORM_LINUX
12+
#if defined(DISCORD_DYNAMIC_LIB)
13+
// Get the base directory of this plugin
14+
FString BaseDir = IPluginManager::Get().FindPlugin("DiscordRpc")->GetBaseDir();
15+
const FString SDKDir = FPaths::Combine(*BaseDir, TEXT("Source"), TEXT("ThirdParty"), TEXT("DiscordRpcLibrary"));
16+
#if PLATFORM_WINDOWS
17+
const FString LibName = TEXT("discord-rpc");
18+
const FString LibDir = FPaths::Combine(*SDKDir, TEXT("Win64"));
19+
if (!LoadDependency(LibDir, LibName, DiscordRpcLibraryHandle)) {
20+
FMessageDialog::Open(EAppMsgType::Ok, LOCTEXT(LOCTEXT_NAMESPACE, "Failed to load DiscordRpc plugin. Plug-in will not be functional."));
21+
FreeDependency(DiscordRpcLibraryHandle);
22+
}
23+
#elif PLATFORM_MAC
24+
const FString LibName = TEXT("libdiscord-rpc");
25+
const FString LibDir = FPaths::Combine(*SDKDir, TEXT("Mac"));
26+
if (!LoadDependency(LibDir, LibName, DiscordRpcLibraryHandle)) {
27+
FMessageDialog::Open(EAppMsgType::Ok, LOCTEXT(LOCTEXT_NAMESPACE, "Failed to load DiscordRpc plugin. Plug-in will not be functional."));
28+
FreeDependency(DiscordRpcLibraryHandle);
29+
}
30+
#endif
31+
#endif
32+
#endif
33+
}
34+
35+
void FDiscordRpcModule::ShutdownModule()
36+
{
37+
// Free the dll handle
38+
#if !PLATFORM_LINUX
39+
#if defined(DISCORD_DYNAMIC_LIB)
40+
FreeDependency(DiscordRpcLibraryHandle);
41+
#endif
42+
#endif
43+
}
44+
45+
bool FDiscordRpcModule::LoadDependency(const FString& Dir, const FString& Name, void*& Handle)
46+
{
47+
FString Lib = Name + TEXT(".") + FPlatformProcess::GetModuleExtension();
48+
FString Path = Dir.IsEmpty() ? *Lib : FPaths::Combine(*Dir, *Lib);
49+
50+
Handle = FPlatformProcess::GetDllHandle(*Path);
51+
52+
if (Handle == nullptr)
53+
{
54+
return false;
55+
}
56+
57+
return true;
58+
}
59+
60+
void FDiscordRpcModule::FreeDependency(void*& Handle)
61+
{
62+
if (Handle != nullptr)
63+
{
64+
FPlatformProcess::FreeDllHandle(Handle);
65+
Handle = nullptr;
66+
}
67+
}
68+
69+
#undef LOCTEXT_NAMESPACE
70+
71+
IMPLEMENT_MODULE(FDiscordRpcModule, DiscordRpc)

examples/unrealstatus/Plugins/discordrpc/Source/discordrpc/Private/DiscordRpcBlueprint.cpp renamed to examples/unrealstatus/Plugins/discordrpc/Source/DiscordRpc/Private/DiscordRpcBlueprint.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
2-
1+
#include "DiscordRpcPrivatePCH.h"
32
#include "DiscordRpcBlueprint.h"
4-
53
#include "discord-rpc.h"
64

75
DEFINE_LOG_CATEGORY(Discord)
@@ -68,8 +66,8 @@ static void JoinRequestHandler(const DiscordJoinRequest* request)
6866
}
6967

7068
void UDiscordRpc::Initialize(const FString& applicationId,
71-
bool autoRegister,
72-
const FString& optionalSteamId)
69+
bool autoRegister,
70+
const FString& optionalSteamId)
7371
{
7472
self = this;
7573
IsConnected = false;
@@ -89,7 +87,7 @@ void UDiscordRpc::Initialize(const FString& applicationId,
8987
auto appId = StringCast<ANSICHAR>(*applicationId);
9088
auto steamId = StringCast<ANSICHAR>(*optionalSteamId);
9189
Discord_Initialize(
92-
(const char*)appId.Get(), &handlers, autoRegister, (const char*)steamId.Get());
90+
(const char*)appId.Get(), &handlers, autoRegister, (const char*)steamId.Get());
9391
}
9492

9593
void UDiscordRpc::Shutdown()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include "Core.h"
2+
#include "DiscordRpc.h"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
2+
3+
#pragma once
4+
5+
#include "ModuleManager.h"
6+
7+
class FDiscordRpcModule : public IModuleInterface {
8+
public:
9+
/** IModuleInterface implementation */
10+
virtual void StartupModule() override;
11+
virtual void ShutdownModule() override;
12+
13+
private:
14+
/** Handle to the test dll we will load */
15+
void* DiscordRpcLibraryHandle;
16+
17+
/** StartupModule is covered with defines, these functions are the place to put breakpoints */
18+
static bool LoadDependency(const FString& Dir, const FString& Name, void*& Handle);
19+
static void FreeDependency(void*& Handle);
20+
};

examples/unrealstatus/Plugins/discordrpc/Source/discordrpc/Public/DiscordRpcBlueprint.h renamed to examples/unrealstatus/Plugins/discordrpc/Source/DiscordRpc/Public/DiscordRpcBlueprint.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
#pragma once
42

53
#include "CoreMinimal.h"
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Fill out your copyright notice in the Description page of Project Settings.
2+
3+
using System.IO;
4+
using UnrealBuildTool;
5+
6+
public class DiscordRpcLibrary : ModuleRules
7+
{
8+
#if WITH_FORWARDED_MODULE_RULES_CTOR
9+
public DiscordRpcLibrary(ReadOnlyTargetRules Target) : base(Target)
10+
#else
11+
public DiscordRpcLibrary(TargetInfo Target)
12+
#endif
13+
{
14+
Type = ModuleType.External;
15+
Definitions.Add("DISCORD_DYNAMIC_LIB=1");
16+
17+
string BaseDirectory = Path.GetFullPath(Path.Combine(ModuleDirectory, "..", "..", "ThirdParty", "DiscordRpcLibrary"));
18+
19+
if (Target.Platform == UnrealTargetPlatform.Win64)
20+
{
21+
string lib = Path.Combine(BaseDirectory, "Win64");
22+
23+
// Include headers
24+
PublicIncludePaths.Add(Path.Combine(BaseDirectory, "Include"));
25+
26+
// Add the import library
27+
PublicLibraryPaths.Add(lib);
28+
PublicAdditionalLibraries.Add(Path.Combine(lib, "discord-rpc.lib"));
29+
30+
// Dynamic
31+
RuntimeDependencies.Add(new RuntimeDependency(Path.Combine(lib, "discord-rpc.dll")));
32+
PublicDelayLoadDLLs.Add("discord-rpc.dll");
33+
}
34+
else if (Target.Platform == UnrealTargetPlatform.Linux)
35+
{
36+
string lib = Path.Combine(BaseDirectory, "Linux", "x86_64-unknown-linux-gnu");
37+
38+
// Include headers
39+
PublicIncludePaths.Add(Path.Combine(BaseDirectory, "Include"));
40+
41+
// Add the import library
42+
PublicLibraryPaths.Add(lib);
43+
PublicAdditionalLibraries.Add(Path.Combine(lib, "libdiscord-rpc.so"));
44+
RuntimeDependencies.Add(new RuntimeDependency(Path.Combine(lib, "libdiscord-rpc.so")));
45+
}
46+
else if (Target.Platform == UnrealTargetPlatform.Mac)
47+
{
48+
string lib = Path.Combine(BaseDirectory, "Mac");
49+
50+
// Include headers
51+
PublicIncludePaths.Add(Path.Combine(BaseDirectory, "Include"));
52+
53+
// Add the import library
54+
PublicLibraryPaths.Add(lib);
55+
PublicAdditionalLibraries.Add(Path.Combine(lib, "libdiscord-rpc.dylib"));
56+
RuntimeDependencies.Add(new RuntimeDependency(Path.Combine(lib, "libdiscord-rpc.dylib")));
57+
}
58+
}
59+
}

examples/unrealstatus/Plugins/discordrpc/Source/ThirdParty/discordrpcLibrary/discordrpcLibrary.Build.cs

Lines changed: 0 additions & 27 deletions
This file was deleted.

examples/unrealstatus/Plugins/discordrpc/Source/discordrpc/Private/discordrpc.cpp

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)