A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
PixoVRFunctionLibrary.cpp
Go to the documentation of this file.
1// Copyright(c) Pixo Group. All Rights Reserved.
2
4#include "HeadMountedDisplayFunctionLibrary.h"
5#include "Kismet/GameplayStatics.h"
6#include "Misc/Paths.h"
7#include "HAL/PlatformFilemanager.h"
8#include "GenericPlatform/GenericPlatformFile.h"
9#include "Misc/CString.h"
10#include "Misc/FileHelper.h"
12#include "Misc/CString.h"
14#include "Kismet/GameplayStatics.h"
15#include "PixoCoreSettings.h"
16#if PLATFORM_ANDROID
17#include "Android/AndroidPlatformMisc.h"
18#endif
19
20#if WITH_EDITOR
21#include "Editor/EditorEngine.h"
22#endif
23
24DEFINE_LOG_CATEGORY(PixoVRFunctionLibrary);
25
26const FString CacheFileName = TEXT("Cache");
27
28bool ExportToCSV(FString ThePath, FString textbody, FString fileName, FString folderName, bool OverwriteFile);
29
31 const FTransform& ComponentRelativeTransform)
32{
33 if (Class != nullptr && Outer != nullptr)
34 {
35 USceneComponent* Component = NewObject<USceneComponent>(Outer, *Class);
36 if (Component != nullptr)
37 {
38 if (USceneComponent* ParentComp = Cast<USceneComponent>(Outer))
39 {
40 Component->SetupAttachment(ParentComp);
41 }
42
43 Component->RegisterComponent();
44 Component->SetRelativeTransform(ComponentRelativeTransform);
45
46 return Component;
47 }
48 return nullptr;
49 }
50
51 return nullptr;
52}
53
55{
56 return TEXT("\n");
57}
58
59bool UPixoVRFunctionLibrary::ExportToCSVToSpecifiedPath(FString FilePath, FString Textbody, FString FileName,
60 FString FolderName, bool OverwriteFile)
61{
62 FString ThePath = FilePath;
63 return ExportToCSV(ThePath, Textbody, FileName, FolderName, OverwriteFile);
64}
65
67{
68 FString deviceName = TEXT("None");
69
70#if PLATFORM_ANDROID
71 deviceName = FAndroidMisc::GetDeviceModel();
72#else
73 deviceName = UHeadMountedDisplayFunctionLibrary::GetHMDDeviceName().ToString();
74#endif
75
76 return deviceName; //Possible values: SteamVR, Vive Focus Plus, VIVE Focus 3, Quest, Pico Neo 2, Pico Neo 3
77}
78
80{
81 FString ValueReceived1;
82 GConfig->GetString(
83 TEXT("/Script/EngineSettings.GeneralProjectSettings"),
84// TEXT("VersionName"),
85// VersionName does not exist anymore, Use ProjectVersion key
86 TEXT("ProjectVersion"),
87 Version,
88 GGameIni
89 );
90}
91
93{
94 FString ValueReceived1;
95 bool bEnabled = false;
96 if (GConfig)
97 {
98 GConfig->GetBool(
99 TEXT("/Script/Pixo.TerminateValues"),
100 TEXT("bEnabled"),
101 bEnabled,
102 GEngineIni
103 );
104 GConfig->GetString(
105 TEXT("/Script/Pixo.TerminateValues"),
106 TEXT("MonthDayYear"),
107 MonthDayYear,
108 GEngineIni
109 );
110 }
111 return bEnabled;
112}
113
115{
116 FPixoLoginInfo Tmp = LoginInfo;
117
118 PIXOVR_BYTE Digest[SHA256_BLOCK_SIZE] = {0};
119 const ANSICHAR* password = TCHAR_TO_ANSI(*Password);
120 SHA256_CTX ctx;
121 sha256_init(&ctx);
122 sha256_update(&ctx, (const PIXOVR_BYTE*)password, static_cast<size_t>(TCString<ANSICHAR>::Strlen(password)));
123 sha256_final(&ctx, Digest);
124
125 TCHAR Buffer[2 * SHA256_BLOCK_SIZE + 1];
126 for (int i = 0; i < SHA256_BLOCK_SIZE; i++)
127 {
128 FCString::Sprintf(Buffer + 2 * i, TEXT("%02x"), Digest[i]);
129 }
130 FString Signature(Buffer);
131 Tmp.Password = Signature;
132 Tmp.Encrypted = true;
133
134 return Tmp;
135}
136
137
139{
140 UPixoVRLoginCache* LoginCache = Cast<UPixoVRLoginCache>(UGameplayStatics::LoadGameFromSlot(CacheFileName, 0));
141 if (LoginCache)
142 {
143 LoginInfo = LoginCache->LoginInfo;
144 return true;
145 }
146
147 return false;
148}
149
151{
152 UPixoVRLoginCache* SaveGame = NewObject<UPixoVRLoginCache>();
153 SaveGame->LoginInfo = LoginInfo;
154
155 bool Result = UGameplayStatics::SaveGameToSlot(SaveGame, CacheFileName, 0);
156 return Result;
157}
158
160{
161 UPixoVRLoginCache* LoginCache = Cast<UPixoVRLoginCache>(UGameplayStatics::LoadGameFromSlot(CacheFileName, 0));
162 if (LoginCache)
163 {
164 return (LoginInfo == LoginCache->LoginInfo);
165 }
166
167 return false;
168}
169
171{
172 bool Result = UGameplayStatics::DeleteGameInSlot(CacheFileName, 0);
173
174 return Result;
175}
176
178{
179 return UGameplayStatics::DoesSaveGameExist(CacheFileName, 0);
180}
181
182bool UPixoVRFunctionLibrary::ExportToCSVToProjectRootDirectory(FString Textbody, FString FileName, FString FolderName,
183 bool OverwriteFile)
184{
185 FString ThePath = FPaths::ConvertRelativePathToFull(FPaths::RootDir());
186 return ExportToCSV(ThePath, Textbody, FileName, FolderName, OverwriteFile);
187}
188
189bool ExportToCSV(FString ThePath, FString Textbody, FString FileName, FString FolderName, bool OverwriteFile)
190{
191 ThePath += TEXT("/") + FolderName;
192 FileName += TEXT(".csv");
193 IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
194
195 if (!PlatformFile.DirectoryExists(*ThePath))
196 {
197 PlatformFile.CreateDirectory(*ThePath);
198 }
199 FString AbsoluteFilePath = ThePath + TEXT("/") + FileName;
200
201 if (OverwriteFile)
202 {
203 FFileHelper::SaveStringToFile(Textbody, *AbsoluteFilePath);
204 return true;
205 }
206 FFileHelper::SaveStringToFile(Textbody, *AbsoluteFilePath, FFileHelper::EEncodingOptions::AutoDetect,
207 &IFileManager::Get(),
208 FILEWRITE_Append);
209 return true;
210
211 return false;
212}
213
215{
216 return GetDefault<UPixoCoreSettings>()->OfflineMode;
217}
218
220{
221 return GetDefault<UPixoCoreSettings>()->OfflineTime;
222}
223
225{
226 return GetDefault<UPixoCoreSettings>()->MapAfterLogin;
227}
228
230{
231 return GetDefault<UPixoCoreSettings>()->MapAfterIntro;
232}
233
235{
236 return GetDefault<UPixoCoreSettings>()->TestServerIP;
237}
238
240{
241 FInternationalization::Get().SetCurrentCulture(Culture);
242}
243
245{
246 if (Culture.Equals("en"))
247 return "English";
248 else if (Culture.Equals("de"))
249 return "Deutch";
250 else
251 return "Undefined Language";
252}
253
255{
256 bool UseSSL = false;
257 if (!FParse::Bool(FCommandLine::Get(), TEXT("-PIXOVR_LS_USE_SSL="), UseSSL))
258 {
259 if (GConfig && !GConfig->GetBool(TEXT("OnlineSubsystemPixoVR"), TEXT("UseSSL"), UseSSL, GEngineIni))
260 {
261 }
262 }
263
264 FString Protocol;
265 if (UseSSL)
266 {
267 Protocol = TEXT("https://");
268 }
269 else
270 {
271 Protocol = TEXT("http://");
272 }
273
274 FString IP = "127.0.0.1";
275 if (!FParse::Value(FCommandLine::Get(), TEXT("-PIXOVR_MS_IP="), IP))
276 {
277 if (GConfig && !GConfig->GetString(TEXT("OnlineSubsystemPixoVR"), TEXT("IP"), IP, GEngineIni))
278 {
279 }
280 }
281
282 int Port = 8000;
283 if (!FParse::Value(FCommandLine::Get(), TEXT("-PIXOVR_MS_PORT="), Port))
284 {
285 if (GConfig && !GConfig->GetInt(TEXT("OnlineSubsystemPixoVR"), TEXT("Port"), Port, GEngineIni))
286 {
287 }
288 }
289
290 FString MasterServiceURL = Protocol + IP + ":" + FString::FromInt(Port);
291
292 return MasterServiceURL;
293}
void sha256_final(SHA256_CTX *ctx, PIXOVR_BYTE hash[])
void sha256_update(SHA256_CTX *ctx, const PIXOVR_BYTE data[], size_t len)
void sha256_init(SHA256_CTX *ctx)
uint8 PIXOVR_BYTE
Definition PixoSHA256.h:20
#define SHA256_BLOCK_SIZE
Definition PixoSHA256.h:16
bool ExportToCSV(FString ThePath, FString textbody, FString fileName, FString folderName, bool OverwriteFile)
const FString CacheFileName
DEFINE_LOG_CATEGORY(PixoVRFunctionLibrary)
static float GetOfflineTime()
Retrieves the time in seconds for offline mode.
static bool DeleteAuthJSON()
Deletes the authentication cache file from the disk.
static FPixoLoginInfo EncryptLoginInfo(const FPixoLoginInfo &LoginInfo, const FString &Password)
Encrypts the login information using the specified password.
static bool CompareAuthJSON(const FPixoLoginInfo &LoginInfo)
Compares the credentials of the authentication.
static bool GetKillSwitchValues(FString &MonthDayYear)
Retrieves the kill switch values from the configuration file.
static bool ExportToCSVToSpecifiedPath(FString FilePath, FString Textbody, FString FileName, FString OptionalFolderName, bool OverwriteFile)
Exports the specified text as a CSV file to the specified file path.
static bool CheckAuthJSON()
Checks if the authentication cache file exists.
static bool LoadAuthFromJSON(FPixoLoginInfo &LoginInfo)
Loads the cached authentication from a JSON file and fills the necessary UMG fields.
static USceneComponent * AddSceneComponentByClass(UObject *Outer, TSubclassOf< USceneComponent > Class, const FTransform &ComponentRelativeTransform)
Adds a scene component based on the specified class to the given outer object.
static FName GetMapAfterIntro()
Retrieves the map name to load after the introduction.
static bool ExportToCSVToProjectRootDirectory(FString Textbody, FString FileName, FString OptionalFolderName, bool OverwriteFile)
Exports the specified text as a CSV file to the project root directory.
static bool SaveAuthToJSON(const FPixoLoginInfo &LoginInfo)
Caches the authentication fields from the UMG widget to a JSON file.
static FString GetMasterServiceIP()
Retrieves the IP address of the master service. Probably not used.
static FName GetMapAfterLogin()
Retrieves the map name to load after login.
static FString GetHMDFullDeviceName()
Retrieves the full device name of the HMD (Head-Mounted Display).
static void GetVersionName(FString &Version)
Retrieves the version name.
static FString GetTestServerIP()
Retrieves the IP address of the test server.
static bool GetIsOfflineModeEnabled()
Retrieves the flag indicating whether offline mode is enabled.
static void SetLocalizationCulture(FString Culture)
Sets the localization culture.
static FName GetFullCultureName(FString Culture)
Retrieves the full culture name based on the specified culture.
static FString NewLineCharacter()
Retrieves the newline character used in the current platform.
Cache class for storing login information. It allows to save password of user, so the next time user ...
FPixoLoginInfo LoginInfo
UPROPERTY(VisibleAnywhere, Category = "Pixo HTTP")
Structure representing login information.
bool Encrypted
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Pixo HTTP")
FString Password
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Pixo HTTP")