Skip to content

Commit a326289

Browse files
committed
Merge branch 'dev'
2 parents d7b63a4 + b2ad3ef commit a326289

File tree

4 files changed

+69
-14
lines changed

4 files changed

+69
-14
lines changed

CheckAppInstance.uplugin

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"FileVersion": 3,
3-
"Version": 4,
4-
"VersionName": "2.1.3",
3+
"Version": 5,
4+
"VersionName": "2.2.0",
55
"FriendlyName": "CheckAppInstance",
66
"Description": "This plugin makes it possible only one instance of your game can be run at the same time",
77
"Category": "Other",

README.md

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,37 @@
1-
# CheckAppInstance
2-
Plugin for UE4/5 project.
3-
This plugin makes it possible only one instance of your game can be run at the same time.
4-
This can be controlled with the launch argument
5-
-checkinst=<0/1|false/true> it's useful for testing multiplayer game on a single pc.
6-
Example: game.exe -checkinst=0
1+
# CheckAppInstance
2+
This plugin allows you to run only one instance of your game at the same time.
3+
You can enable/disable check instance from the launch argument to the game binary file
4+
`-checkinst=<0/1|false/true>`, this is useful for testing multiplayer game on a single pc.
5+
Example: `game -checkinst=0`
76

87
**C++/Blueprints functions:**
98
- CheckAnotherAppInstance(bool IsEnabled = true)
109

1110
ProjectSettings -> Maps&Modes -> Game Instance Class: BP_GameInstance
1211
<img src="Example.png"/>
1312

14-
# Install
15-
You can install manually by extracting archive (CheckAppInstance-X.X.X...zip) from
13+
# Install into Project
14+
You can install manually by extracting archive `CheckAppInstance-X.X.X-UE-X.X.zip` from
1615
[Releases](https://github.com/mrbindraw/CheckAppInstance/releases) to your project plugins folder
17-
or build example project (ExamplePrj-UEX.X-CheckAppInstance-X.X.X.zip).
16+
or build example project `ExamplePrj-UE-X.X-CheckAppInstance-X.X.X.zip`.
17+
18+
# Install into Unreal Engine
1819
You can install it from the marketplace [CheckAppInstance](https://www.fab.com/listings/c17f1eb9-dfd8-4f41-ba30-e6c6c43d7c98)
20+
21+
Manual:
22+
1. Download and extracting archive `CheckAppInstance-X.X.X-UE-X.X.zip` from [Releases](https://github.com/mrbindraw/ProjectVersionFromGit/releases) to any disk path, for example: `D:\Plugins`
23+
2. Than open any terminal (cmd, powershell) in `D:\Plugins` folder
24+
3. Launch `RunUAT` in the terminal with arguments, for example:
25+
26+
Windows:
27+
```
28+
D:\EpicGames\UE_5.4\Engine\Build\BatchFiles\RunUAT.bat BuildPlugin -Plugin=D:\Plugins\CheckAppInstance\CheckAppInstance.uplugin -Package=D:\Plugins\UE_5.4\CheckAppInstance -Rocket
29+
```
30+
Mac:
31+
```
32+
sh "/Users/Shared/Epic Games/UE_5.4/Engine/Build/BatchFiles/RunUAT.sh" BuildPlugin -Plugin="$PWD/CheckAppInstance/CheckAppInstance.uplugin" -Package="$PWD/5.4/CheckAppInstance" -Rocket
33+
```
34+
4. If you see the message `BUILD SUCCESSFUL` in the terminal after the build is complete,
35+
copy the `CheckAppInstance` folder from `D:\Plugins\UE_5.4` to `D:\EpicGames\UE_5.4\Engine\Plugins\Marketplace`
36+
> [!IMPORTANT]
37+
> **The engine path and folder names may differ on your system.**

Source/CheckAppInstance/Private/CheckAppInstanceBPLibrary.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "CheckAppInstanceBPLibrary.h"
44
#include "CheckAppInstance.h"
55

6+
DEFINE_LOG_CATEGORY(LogCheckAppInstanceBPLibrary)
7+
68
UCheckAppInstanceBPLibrary::UCheckAppInstanceBPLibrary(const FObjectInitializer& ObjectInitializer)
79
: Super(ObjectInitializer)
810
{
@@ -18,17 +20,41 @@ void UCheckAppInstanceBPLibrary::CheckAnotherAppInstance(bool bIsEnabled)
1820
bIsEnabled = ParseValue.ToBool();
1921
}
2022

21-
FCoreDelegates::OnAllModuleLoadingPhasesComplete.AddLambda([bIsEnabled]()
23+
if(!bIsEnabled)
24+
{
25+
return;
26+
}
27+
28+
FCoreDelegates::OnAllModuleLoadingPhasesComplete.AddLambda([]()
2229
{
2330
// Only one instance of the game can be initialized!
2431
const UGeneralProjectSettings& ProjectSettings = *GetDefault<UGeneralProjectSettings>();
2532
const FString LockFilePath = FPlatformProcess::UserTempDir() + ProjectSettings.ProjectID.ToString();
26-
if (!IFileManager::Get().CreateFileWriter(*LockFilePath, 0) && bIsEnabled)
33+
bool bIsAppInstLaunched = false;
34+
35+
#if PLATFORM_WINDOWS
36+
bIsAppInstLaunched = (IFileManager::Get().CreateFileWriter(*LockFilePath, 0) == nullptr ? true : false);
37+
#else
38+
int FileDescriptor = open(TCHAR_TO_UTF8(*LockFilePath), O_CREAT | O_RDWR, 0666); // 0644
39+
if(FileDescriptor >= 0)
40+
{
41+
int CodeFlock = flock(FileDescriptor, LOCK_EX | LOCK_NB);
42+
if (CodeFlock && errno == EWOULDBLOCK)
43+
{
44+
flock(FileDescriptor, LOCK_UN);
45+
close(FileDescriptor);
46+
47+
bIsAppInstLaunched = true;
48+
}
49+
}
50+
#endif
51+
UE_LOG(LogCheckAppInstanceBPLibrary, Log, TEXT("LockFilePath: %s, bIsAppInstLaunched: %s"), *LockFilePath, bIsAppInstLaunched ? TEXT("true") : TEXT("false"));
52+
if (bIsAppInstLaunched)
2753
{
2854
FPlatformApplicationMisc::RequestMinimize();
2955
FPlatformMisc::RequestExit(0);
3056
}
3157
});
32-
#endif
58+
#endif // !UE_EDITOR
3359
}
3460

Source/CheckAppInstance/Public/CheckAppInstanceBPLibrary.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,18 @@
88
#include "GeneralProjectSettings.h"
99
#include "Misc/CoreDelegates.h"
1010
#include "Misc/CommandLine.h"
11+
12+
#if PLATFORM_UNIX
13+
#include <unistd.h> // close
14+
#include <fcntl.h> // open
15+
#include <sys/file.h> // flock
16+
#include <errno.h>
17+
#endif
18+
1119
#include "CheckAppInstanceBPLibrary.generated.h"
1220

21+
DECLARE_LOG_CATEGORY_EXTERN(LogCheckAppInstanceBPLibrary, Log, All);
22+
1323
UCLASS()
1424
class UCheckAppInstanceBPLibrary : public UBlueprintFunctionLibrary
1525
{

0 commit comments

Comments
 (0)