Successfully compiled and working on Win32 + tested on steam deck
This commit is contained in:
parent
47008fcefe
commit
e5cca6b23f
19 changed files with 311 additions and 186 deletions
|
@ -10,7 +10,7 @@
|
||||||
"DocsURL": "https://github.com/Jordonbc/HarmonyLink",
|
"DocsURL": "https://github.com/Jordonbc/HarmonyLink",
|
||||||
"MarketplaceURL": "com.epicgames.launcher://ue/marketplace/product/92fd511971274d1f955abb7197485041",
|
"MarketplaceURL": "com.epicgames.launcher://ue/marketplace/product/92fd511971274d1f955abb7197485041",
|
||||||
"SupportURL": "",
|
"SupportURL": "",
|
||||||
"CanContainContent": true,
|
"CanContainContent": false,
|
||||||
"IsBetaVersion": false,
|
"IsBetaVersion": false,
|
||||||
"IsExperimentalVersion": false,
|
"IsExperimentalVersion": false,
|
||||||
"Installed": false,
|
"Installed": false,
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
{
|
{
|
||||||
"Name": "HarmonyLink",
|
"Name": "HarmonyLink",
|
||||||
"Type": "Runtime",
|
"Type": "Runtime",
|
||||||
"LoadingPhase": "Default",
|
"LoadingPhase": "PreDefault",
|
||||||
"WhitelistPlatforms": ["Win64", "Linux"]
|
"WhitelistPlatforms": ["Win64", "Linux"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -9,7 +9,7 @@ public class HarmonyLink : ModuleRules
|
||||||
{
|
{
|
||||||
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
|
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
|
||||||
|
|
||||||
IWYUSupport = IWYUSupport.Full;
|
//IWYUSupport = IWYUSupport.Full;
|
||||||
|
|
||||||
PublicIncludePaths.AddRange(
|
PublicIncludePaths.AddRange(
|
||||||
new string[] {
|
new string[] {
|
||||||
|
@ -31,6 +31,8 @@ public class HarmonyLink : ModuleRules
|
||||||
"Core",
|
"Core",
|
||||||
"CoreUObject",
|
"CoreUObject",
|
||||||
"Engine",
|
"Engine",
|
||||||
|
|
||||||
|
"HarmonyLinkLib",
|
||||||
// ... add other public dependencies that you statically link with here ...
|
// ... add other public dependencies that you statically link with here ...
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -40,7 +42,6 @@ public class HarmonyLink : ModuleRules
|
||||||
new string[]
|
new string[]
|
||||||
{
|
{
|
||||||
// ... add private dependencies that you statically link with here ...
|
// ... add private dependencies that you statically link with here ...
|
||||||
"HarmonyLinkLib",
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,21 @@
|
||||||
// Copyright (C) 2024 Jordon Brooks
|
// Copyright (C) 2024 Jordon Brooks
|
||||||
|
|
||||||
#include "HarmonyLinkLibrary.h"
|
#include "HarmonyLinkLibrary.h"
|
||||||
|
#include "HarmonyLink.h"
|
||||||
|
|
||||||
#include "HarmonyLinkLib.h"
|
#include "HarmonyLinkLib.h"
|
||||||
|
|
||||||
|
UHarmonyLinkLibrary::UHarmonyLinkLibrary()
|
||||||
|
{
|
||||||
|
if (!HarmonyLinkLib::HL_Init())
|
||||||
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, Fatal, TEXT("Failed to initialise HarmonyLinkLib!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
UE_LOG(LogHarmonyLink, Log, TEXT("HarmonyLinkLib Initialised!"));
|
||||||
|
}
|
||||||
|
|
||||||
bool UHarmonyLinkLibrary::IsWine()
|
bool UHarmonyLinkLibrary::IsWine()
|
||||||
{
|
{
|
||||||
return HarmonyLinkLib::get_is_wine();
|
return HarmonyLinkLib::get_is_wine();
|
||||||
|
@ -16,7 +28,7 @@ bool UHarmonyLinkLibrary::IsLinux()
|
||||||
|
|
||||||
bool UHarmonyLinkLibrary::IsSteamDeck()
|
bool UHarmonyLinkLibrary::IsSteamDeck()
|
||||||
{
|
{
|
||||||
return GetDeviceInfo().Device == EDeviceEnum::STEAM_DECK;
|
return GetDeviceInfo().Device == EDevice::STEAM_DECK;
|
||||||
}
|
}
|
||||||
|
|
||||||
FCPUInfo UHarmonyLinkLibrary::GetCPUInfo()
|
FCPUInfo UHarmonyLinkLibrary::GetCPUInfo()
|
||||||
|
|
|
@ -6,10 +6,23 @@
|
||||||
#include "HarmonyLink.h"
|
#include "HarmonyLink.h"
|
||||||
#include "HarmonyLinkLibrary.h"
|
#include "HarmonyLinkLibrary.h"
|
||||||
#include "GameFramework/GameUserSettings.h"
|
#include "GameFramework/GameUserSettings.h"
|
||||||
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
|
||||||
UHarmonyLinkGraphics* UHarmonyLinkGraphics::_INSTANCE = nullptr;
|
UHarmonyLinkGraphics* UHarmonyLinkGraphics::_INSTANCE = nullptr;
|
||||||
int32 UHarmonyLinkGraphics::_TickRate = 1;
|
int32 UHarmonyLinkGraphics::_TickRate = 1;
|
||||||
FTimerHandle UHarmonyLinkGraphics::_TickTimerHandle = FTimerHandle();
|
FTimerHandle UHarmonyLinkGraphics::_TickTimerHandle = FTimerHandle();
|
||||||
|
TSharedPtr<FConfigFile> UHarmonyLinkGraphics::_ConfigFile = nullptr;
|
||||||
|
bool UHarmonyLinkGraphics::_bAutomaticSwitch = false;
|
||||||
|
int32 UHarmonyLinkGraphics::_LastBatteryPercentage = 0;
|
||||||
|
EProfile UHarmonyLinkGraphics::_ActiveProfile = EProfile::NONE;
|
||||||
|
TMap<EProfile, FSettingsProfile> UHarmonyLinkGraphics::_Profiles = TMap<EProfile, FSettingsProfile>();
|
||||||
|
|
||||||
|
TMap<EProfile, FName> UHarmonyLinkGraphics::_ProfileNames =
|
||||||
|
{
|
||||||
|
{EProfile::BATTERY, "Battery"},
|
||||||
|
{EProfile::CHARGING, "Charging"},
|
||||||
|
{EProfile::DOCKED, "Docked"},
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Default graphics settings for different power states in HarmonyLink.
|
* @brief Default graphics settings for different power states in HarmonyLink.
|
||||||
|
@ -25,115 +38,125 @@ FTimerHandle UHarmonyLinkGraphics::_TickTimerHandle = FTimerHandle();
|
||||||
*/
|
*/
|
||||||
TMap<FName, TMap<FName, FHLConfigValue>> UHarmonyLinkGraphics::_DefaultSettings = {
|
TMap<FName, TMap<FName, FHLConfigValue>> UHarmonyLinkGraphics::_DefaultSettings = {
|
||||||
{ "Battery", {
|
{ "Battery", {
|
||||||
{ TEXT("r.ReflectionMethod"), FHLConfigValue(0) },
|
// { TEXT("r.ReflectionMethod"), FHLConfigValue(0) },
|
||||||
{ TEXT("r.DynamicGlobalIlluminationMethod"), FHLConfigValue(2) },
|
// { TEXT("r.DynamicGlobalIlluminationMethod"), FHLConfigValue(2) },
|
||||||
{ TEXT("r.Shadow.Virtual.Enable"), FHLConfigValue(0) },
|
// { TEXT("r.Shadow.Virtual.Enable"), FHLConfigValue(0) },
|
||||||
{ TEXT("r.ScreenPercentage"), FHLConfigValue(50) },
|
// { TEXT("r.ScreenPercentage"), FHLConfigValue(50) },
|
||||||
}},
|
}},
|
||||||
{ "Charging", {
|
{ "Charging", {
|
||||||
{ TEXT("r.ReflectionMethod"), FHLConfigValue(2) },
|
// { TEXT("r.ReflectionMethod"), FHLConfigValue(2) },
|
||||||
{ TEXT("r.DynamicGlobalIlluminationMethod"), FHLConfigValue(2) },
|
// { TEXT("r.DynamicGlobalIlluminationMethod"), FHLConfigValue(2) },
|
||||||
{ TEXT("r.Shadow.Virtual.Enable"), FHLConfigValue(1) },
|
// { TEXT("r.Shadow.Virtual.Enable"), FHLConfigValue(1) },
|
||||||
{ TEXT("r.ScreenPercentage"), FHLConfigValue(100) },
|
// { TEXT("r.ScreenPercentage"), FHLConfigValue(100) },
|
||||||
}},
|
}},
|
||||||
{ "Docked", {
|
{ "Docked", {
|
||||||
{ TEXT("r.ReflectionMethod"), FHLConfigValue(2) },
|
// { TEXT("r.ReflectionMethod"), FHLConfigValue(2) },
|
||||||
{ TEXT("r.DynamicGlobalIlluminationMethod"), FHLConfigValue(2) },
|
// { TEXT("r.DynamicGlobalIlluminationMethod"), FHLConfigValue(2) },
|
||||||
{ TEXT("r.Shadow.Virtual.Enable"), FHLConfigValue(1) },
|
// { TEXT("r.Shadow.Virtual.Enable"), FHLConfigValue(1) },
|
||||||
{ TEXT("r.ScreenPercentage"), FHLConfigValue(100) },
|
// { TEXT("r.ScreenPercentage"), FHLConfigValue(100) },
|
||||||
}}
|
}}
|
||||||
};
|
};
|
||||||
|
|
||||||
UHarmonyLinkGraphics::UHarmonyLinkGraphics()
|
UHarmonyLinkGraphics::UHarmonyLinkGraphics()
|
||||||
{
|
{
|
||||||
UE_LOG(LogHarmonyLink, Warning, TEXT("HarmonyLinkGraphics initialized."));
|
UE_LOG(LogHarmonyLink, Warning, TEXT("HarmonyLinkGraphics initialized."));
|
||||||
|
if (_INSTANCE != this)
|
||||||
|
{
|
||||||
|
if (_INSTANCE)
|
||||||
|
{
|
||||||
|
DestroySettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
_INSTANCE = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
AddToRoot();
|
||||||
|
|
||||||
FWorldDelegates::OnPostWorldInitialization.AddUObject(this, &UHarmonyLinkGraphics::OnPostWorldInitialization);
|
FWorldDelegates::OnPostWorldInitialization.AddUObject(this, &UHarmonyLinkGraphics::OnPostWorldInitialization);
|
||||||
FWorldDelegates::OnPreWorldFinishDestroy.AddUObject(this, &UHarmonyLinkGraphics::OnWorldEnd);
|
FWorldDelegates::OnPreWorldFinishDestroy.AddUObject(this, &UHarmonyLinkGraphics::OnWorldEnd);
|
||||||
|
|
||||||
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
UHarmonyLinkGraphics::~UHarmonyLinkGraphics()
|
UHarmonyLinkGraphics::~UHarmonyLinkGraphics()
|
||||||
{
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, Verbose, TEXT("~UHarmonyLinkGraphics called."));
|
||||||
FWorldDelegates::OnPostWorldInitialization.RemoveAll(this);
|
FWorldDelegates::OnPostWorldInitialization.RemoveAll(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UHarmonyLinkGraphics::LoadConfig(const bool bForceReload)
|
void UHarmonyLinkGraphics::LoadConfig(const bool bForceReload)
|
||||||
{
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, Verbose, TEXT("LoadConfig called."));
|
||||||
QUICK_SCOPE_CYCLE_COUNTER(HarmonyLinkGraphics_LoadSettings);
|
QUICK_SCOPE_CYCLE_COUNTER(HarmonyLinkGraphics_LoadSettings);
|
||||||
|
|
||||||
// Load the settings into the map
|
// Load the settings into the map
|
||||||
if (!LoadSettingsFromConfig(false))
|
GetConfig();
|
||||||
{
|
|
||||||
if (!LoadSettingsFromConfig(true))
|
|
||||||
{
|
|
||||||
CreateDefaultConfigFile();
|
|
||||||
// Retry 2nd time
|
|
||||||
LoadSettingsFromConfig(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DebugPrintProfiles();
|
DebugPrintProfiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UHarmonyLinkGraphics::LoadSettingsFromConfig(const bool bLoadDefaults)
|
bool UHarmonyLinkGraphics::LoadSettingsFromConfig(FConfigFile* ConfigFile) const
|
||||||
{
|
{
|
||||||
// Load the configuration from the INI file
|
UE_LOG(LogHarmonyLink, Verbose, TEXT("LoadSettingsFromConfig called."));
|
||||||
FConfigFile ConfigFile;
|
//const FString Filename = "HarmonyLink"; //GetConfigDirectoryFile(bLoadDefaults);
|
||||||
|
|
||||||
|
// Load each profile section
|
||||||
|
bool bLoaded = true;
|
||||||
|
|
||||||
const FString Filename = GetConfigDirectoryFile(bLoadDefaults);
|
// Load the _bAutomaticSwitch variable
|
||||||
|
const FString SectionName = TEXT("HarmonyLink");
|
||||||
|
const FString KeyName = TEXT("AutomaticProfileSwitch");
|
||||||
|
|
||||||
if (!GConfig)
|
if (!ConfigFile->GetBool(*SectionName, *KeyName, _bAutomaticSwitch))
|
||||||
{
|
{
|
||||||
UE_LOG(LogHarmonyLink, Error, TEXT("Failed to access GConfig!"));
|
UE_LOG(LogHarmonyLink, Error, TEXT("Failed to load bAutomaticSwitch from config"));
|
||||||
return false;
|
bLoaded = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, Log, TEXT("Loaded bAutomaticSwitch: %s"), _bAutomaticSwitch ? TEXT("true") : TEXT("false"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GConfig->LoadLocalIniFile(ConfigFile, *Filename, false, nullptr, false))
|
for (const TPair<EProfile, FName>& Profile : _ProfileNames)
|
||||||
{
|
{
|
||||||
// Load each profile section
|
if (!LoadSection(ConfigFile, Profile))
|
||||||
bool bLoaded = true;
|
|
||||||
|
|
||||||
// Load the _bAutomaticSwitch variable
|
|
||||||
const FString SectionName = TEXT("HarmonyLink");
|
|
||||||
const FString KeyName = TEXT("AutomaticProfileSwitch");
|
|
||||||
|
|
||||||
if (!GConfig->GetBool(*SectionName, *KeyName, _bAutomaticSwitch, Filename))
|
|
||||||
{
|
{
|
||||||
UE_LOG(LogHarmonyLink, Error, TEXT("Failed to load bAutomaticSwitch from config"));
|
UE_LOG(LogHarmonyLink, Error, TEXT("Failed to load section: '%s'"), *Profile.Value.ToString());
|
||||||
bLoaded = false;
|
bLoaded = false;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
UE_LOG(LogHarmonyLink, Log, TEXT("Loaded bAutomaticSwitch: %s"), _bAutomaticSwitch ? TEXT("true") : TEXT("false"));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const TPair<EProfile, FName>& Profile : _ProfileNames)
|
|
||||||
{
|
|
||||||
if (!LoadSection(ConfigFile, Profile))
|
|
||||||
{
|
|
||||||
UE_LOG(LogHarmonyLink, Error, TEXT("Failed to load section: '%s'"), *Profile.Value.ToString());
|
|
||||||
bLoaded = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if all profiles and settings were loaded successfully
|
|
||||||
if (bLoaded)
|
|
||||||
{
|
|
||||||
UE_LOG(LogHarmonyLink, Log, TEXT("Successfully loaded config file: %s"), *Filename);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UE_LOG(LogHarmonyLink, Error, TEXT("Failed to load config file: %s"), *Filename);
|
// Check if all profiles and settings were loaded successfully
|
||||||
|
if (bLoaded)
|
||||||
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, Log, TEXT("Successfully loaded config."));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
UE_LOG(LogHarmonyLink, Error, TEXT("Failed to load config file."));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UHarmonyLinkGraphics::LoadSection(const FConfigFile& ConfigFile, const TPair<EProfile, FName> Profile)
|
bool UHarmonyLinkGraphics::LoadSection(FConfigFile* ConfigFile, const TPair<EProfile, FName> Profile)
|
||||||
{
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, Verbose, TEXT("LoadSection called."));
|
||||||
|
if (!ensureMsgf(ConfigFile, TEXT("ConfigFile is nullptr!"))) return false;
|
||||||
|
|
||||||
const FName& SectionName = Profile.Value;
|
const FName& SectionName = Profile.Value;
|
||||||
const EProfile ProfileKey = Profile.Key;
|
const EProfile ProfileKey = Profile.Key;
|
||||||
|
|
||||||
if (const FConfigSection* Section = ConfigFile.FindSection(*SectionName.ToString()))
|
const FConfigSection* Section = nullptr;
|
||||||
|
|
||||||
|
|
||||||
|
#if (ENGINE_MAJOR_VERSION >= 5)
|
||||||
|
Section = ConfigFile->FindSection(*SectionName.ToString())
|
||||||
|
#elif (ENGINE_MAJOR_VERSION == 4) && (ENGINE_MINOR_VERSION >= 27)
|
||||||
|
Section = ConfigFile->FindOrAddSection(*SectionName.ToString());
|
||||||
|
#else
|
||||||
|
#error "Unsupported Unreal Engine version"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (Section)
|
||||||
{
|
{
|
||||||
FSettingsProfile& SettingsProfile = _Profiles.FindOrAdd(ProfileKey);
|
FSettingsProfile& SettingsProfile = _Profiles.FindOrAdd(ProfileKey);
|
||||||
SettingsProfile.SectionName = SectionName;
|
SettingsProfile.SectionName = SectionName;
|
||||||
|
@ -180,11 +203,13 @@ bool UHarmonyLinkGraphics::LoadSection(const FConfigFile& ConfigFile, const TPai
|
||||||
|
|
||||||
void UHarmonyLinkGraphics::SaveConfig() const
|
void UHarmonyLinkGraphics::SaveConfig() const
|
||||||
{
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, Verbose, TEXT("SaveConfig called."));
|
||||||
Intermal_SaveConfig(false);
|
Intermal_SaveConfig(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UHarmonyLinkGraphics::SetSetting(const EProfile Profile, const FName Setting, const FHLConfigValue Value)
|
void UHarmonyLinkGraphics::SetSetting(const EProfile Profile, const FName Setting, const FHLConfigValue Value)
|
||||||
{
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, Verbose, TEXT("SetSetting called."));
|
||||||
// Ignore if HarmonyLinkSettings is disabled
|
// Ignore if HarmonyLinkSettings is disabled
|
||||||
if (Profile == EProfile::NONE)
|
if (Profile == EProfile::NONE)
|
||||||
{
|
{
|
||||||
|
@ -214,7 +239,7 @@ void UHarmonyLinkGraphics::SetSetting(const EProfile Profile, const FName Settin
|
||||||
TypeString = TEXT("float");
|
TypeString = TEXT("float");
|
||||||
break;
|
break;
|
||||||
case EConfigValueType::Bool:
|
case EConfigValueType::Bool:
|
||||||
ValueString = Value.GetValue<bool>() ? TEXT("true") : TEXT("false");
|
ValueString = Value.GetValue<bool>() ? TEXT("True") : TEXT("False");
|
||||||
TypeString = TEXT("bool");
|
TypeString = TEXT("bool");
|
||||||
break;
|
break;
|
||||||
case EConfigValueType::String:
|
case EConfigValueType::String:
|
||||||
|
@ -240,6 +265,7 @@ void UHarmonyLinkGraphics::SetSetting(const EProfile Profile, const FName Settin
|
||||||
|
|
||||||
UHarmonyLinkGraphics* UHarmonyLinkGraphics::GetSettings()
|
UHarmonyLinkGraphics* UHarmonyLinkGraphics::GetSettings()
|
||||||
{
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, VeryVerbose, TEXT("GetSettings called."));
|
||||||
// Check if we already initialised
|
// Check if we already initialised
|
||||||
if (_INSTANCE)
|
if (_INSTANCE)
|
||||||
{
|
{
|
||||||
|
@ -248,14 +274,13 @@ UHarmonyLinkGraphics* UHarmonyLinkGraphics::GetSettings()
|
||||||
|
|
||||||
// Proceed to create a new singleton instance
|
// Proceed to create a new singleton instance
|
||||||
_INSTANCE = NewObject<UHarmonyLinkGraphics>();
|
_INSTANCE = NewObject<UHarmonyLinkGraphics>();
|
||||||
_INSTANCE->AddToRoot();
|
|
||||||
_INSTANCE->Init();
|
|
||||||
|
|
||||||
return _INSTANCE;
|
return _INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
FSettingsProfile UHarmonyLinkGraphics::GetSettingProfile(const EProfile Profile)
|
FSettingsProfile UHarmonyLinkGraphics::GetSettingProfile(const EProfile Profile)
|
||||||
{
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, Verbose, TEXT("GetSettingProfile called."));
|
||||||
// Ignore if HarmonyLinkSettings is disabled
|
// Ignore if HarmonyLinkSettings is disabled
|
||||||
if (Profile == EProfile::NONE)
|
if (Profile == EProfile::NONE)
|
||||||
{
|
{
|
||||||
|
@ -285,35 +310,48 @@ FSettingsProfile UHarmonyLinkGraphics::GetSettingProfile(const EProfile Profile)
|
||||||
|
|
||||||
EProfile UHarmonyLinkGraphics::GetActiveProfile() const
|
EProfile UHarmonyLinkGraphics::GetActiveProfile() const
|
||||||
{
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, Verbose, TEXT("GetActiveProfile called."));
|
||||||
return _ActiveProfile;
|
return _ActiveProfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UHarmonyLinkGraphics::SetAutomaticSwitching(const bool bAutomaticSwitch)
|
void UHarmonyLinkGraphics::SetAutomaticSwitching(const bool bAutomaticSwitch)
|
||||||
{
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, Verbose, TEXT("SetAutomaticSwitching called."));
|
||||||
_bAutomaticSwitch = bAutomaticSwitch;
|
_bAutomaticSwitch = bAutomaticSwitch;
|
||||||
OnAutomaticSwitchChanged.Broadcast(_bAutomaticSwitch);
|
OnAutomaticSwitchChanged.Broadcast(_bAutomaticSwitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UHarmonyLinkGraphics::GetAutomaticSwitching() const
|
bool UHarmonyLinkGraphics::GetAutomaticSwitching() const
|
||||||
{
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, Verbose, TEXT("GetAutomaticSwitching called."));
|
||||||
return _bAutomaticSwitch;
|
return _bAutomaticSwitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UHarmonyLinkGraphics::DestroySettings()
|
void UHarmonyLinkGraphics::DestroySettings()
|
||||||
{
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, Log, TEXT("DestroySettings called."));
|
||||||
if (_INSTANCE)
|
if (_INSTANCE)
|
||||||
{
|
{
|
||||||
UE_LOG(LogHarmonyLink, Log, TEXT("Destroying UHarmonyLinkGraphics."))
|
UE_LOG(LogHarmonyLink, Log, TEXT("Destroying UHarmonyLinkGraphics."))
|
||||||
FWorldDelegates::OnPostWorldInitialization.RemoveAll(_INSTANCE);
|
FWorldDelegates::OnPostWorldInitialization.RemoveAll(_INSTANCE);
|
||||||
FWorldDelegates::OnPreWorldFinishDestroy.RemoveAll(_INSTANCE);
|
FWorldDelegates::OnPreWorldFinishDestroy.RemoveAll(_INSTANCE);
|
||||||
_INSTANCE->RemoveFromRoot();
|
_INSTANCE->RemoveFromRoot();
|
||||||
_INSTANCE->MarkAsGarbage();
|
|
||||||
|
#if (ENGINE_MAJOR_VERSION >= 5)
|
||||||
|
_INSTANCE->MarkAsGarbage(); // For UE 5.0 and above
|
||||||
|
#elif (ENGINE_MAJOR_VERSION == 4) && (ENGINE_MINOR_VERSION >= 27)
|
||||||
|
_INSTANCE->MarkPendingKill(); // For UE 4.27 and above
|
||||||
|
#else
|
||||||
|
#error "Unsupported Unreal Engine version"
|
||||||
|
#endif
|
||||||
|
|
||||||
_INSTANCE = nullptr;
|
_INSTANCE = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UHarmonyLinkGraphics::Init()
|
void UHarmonyLinkGraphics::Init()
|
||||||
{
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, Log, TEXT("Init called."));
|
||||||
LoadConfig();
|
LoadConfig();
|
||||||
|
|
||||||
const FBattery BatteryStatus = UHarmonyLinkLibrary::GetBatteryStatus();
|
const FBattery BatteryStatus = UHarmonyLinkLibrary::GetBatteryStatus();
|
||||||
|
@ -326,8 +364,9 @@ void UHarmonyLinkGraphics::Init()
|
||||||
|
|
||||||
void UHarmonyLinkGraphics::Intermal_SaveConfig(const bool bDefaultConfig) const
|
void UHarmonyLinkGraphics::Intermal_SaveConfig(const bool bDefaultConfig) const
|
||||||
{
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, Log, TEXT("Intermal_SaveConfig called."));
|
||||||
QUICK_SCOPE_CYCLE_COUNTER(HarmonyLinkGraphics_SaveConfig);
|
QUICK_SCOPE_CYCLE_COUNTER(HarmonyLinkGraphics_SaveConfig);
|
||||||
|
|
||||||
const FString Filename = GetConfigDirectoryFile(bDefaultConfig);
|
const FString Filename = GetConfigDirectoryFile(bDefaultConfig);
|
||||||
const FString SectionName = TEXT("HarmonyLink");
|
const FString SectionName = TEXT("HarmonyLink");
|
||||||
const FString KeyName = TEXT("AutomaticProfileSwitch");
|
const FString KeyName = TEXT("AutomaticProfileSwitch");
|
||||||
|
@ -343,57 +382,52 @@ void UHarmonyLinkGraphics::Intermal_SaveConfig(const bool bDefaultConfig) const
|
||||||
}
|
}
|
||||||
|
|
||||||
UE_LOG(LogHarmonyLink, Log, TEXT("Flushing file: '%s'"), *Filename);
|
UE_LOG(LogHarmonyLink, Log, TEXT("Flushing file: '%s'"), *Filename);
|
||||||
|
GetConfig()->Dirty = true;
|
||||||
|
// You'd think that Write would actually write something but for some
|
||||||
|
// reason even if it outputs a success the file doesn't actually get created.
|
||||||
|
// For this reason, Flush seems to work for now.
|
||||||
|
//GetConfig()->Write(Filename);
|
||||||
GConfig->Flush(true, Filename);
|
GConfig->Flush(true, Filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UHarmonyLinkGraphics::Tick()
|
void UHarmonyLinkGraphics::Tick()
|
||||||
{
|
{
|
||||||
Async(EAsyncExecution::Thread, [this]()
|
UE_LOG(LogHarmonyLink, VeryVerbose, TEXT("Tick called."));
|
||||||
|
const FBattery BatteryStatus = UHarmonyLinkLibrary::GetBatteryStatus();
|
||||||
|
|
||||||
|
if (BatteryStatus.BatteryPercent != _LastBatteryPercentage)
|
||||||
{
|
{
|
||||||
const FBattery BatteryStatus = UHarmonyLinkLibrary::GetBatteryStatus();
|
// Ensure thread-safe broadcasting
|
||||||
|
OnBatteryLevelChanged.Broadcast(BatteryStatus.BatteryPercent);
|
||||||
|
}
|
||||||
|
|
||||||
if (BatteryStatus.BatteryPercent != _LastBatteryPercentage)
|
if (!_bAutomaticSwitch)
|
||||||
{
|
{
|
||||||
// Ensure thread-safe broadcasting
|
return;
|
||||||
Async(EAsyncExecution::TaskGraphMainThread, [this, BatteryStatus]()
|
}
|
||||||
{
|
|
||||||
OnBatteryLevelChanged.Broadcast(BatteryStatus.BatteryPercent);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_bAutomaticSwitch)
|
if (BatteryStatus.HasBattery)
|
||||||
|
{
|
||||||
|
if (BatteryStatus.IsACConnected)
|
||||||
{
|
{
|
||||||
return;
|
if (_ActiveProfile != EProfile::CHARGING)
|
||||||
}
|
|
||||||
|
|
||||||
if (BatteryStatus.HasBattery)
|
|
||||||
{
|
|
||||||
if (BatteryStatus.IsACConnected)
|
|
||||||
{
|
{
|
||||||
if (_ActiveProfile != EProfile::CHARGING)
|
ApplyProfileInternal(EProfile::CHARGING);
|
||||||
{
|
|
||||||
Async(EAsyncExecution::TaskGraphMainThread, [this]()
|
|
||||||
{
|
|
||||||
ApplyProfileInternal(EProfile::CHARGING);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (_ActiveProfile != EProfile::BATTERY)
|
|
||||||
{
|
|
||||||
Async(EAsyncExecution::TaskGraphMainThread, [this]()
|
|
||||||
{
|
|
||||||
ApplyProfileInternal(EProfile::BATTERY);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
else
|
||||||
|
{
|
||||||
|
if (_ActiveProfile != EProfile::BATTERY)
|
||||||
|
{
|
||||||
|
ApplyProfileInternal(EProfile::BATTERY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UHarmonyLinkGraphics::CreateDefaultConfigFile()
|
void UHarmonyLinkGraphics::CreateDefaultConfigFile() const
|
||||||
{
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, Log, TEXT("CreateDefaultConfigFile called."));
|
||||||
UE_LOG(LogHarmonyLink, Log, TEXT("Creating default config file."));
|
UE_LOG(LogHarmonyLink, Log, TEXT("Creating default config file."));
|
||||||
|
|
||||||
LoadDefaults();
|
LoadDefaults();
|
||||||
|
@ -404,13 +438,17 @@ void UHarmonyLinkGraphics::CreateDefaultConfigFile()
|
||||||
|
|
||||||
FString UHarmonyLinkGraphics::GetConfigDirectoryFile(const bool bDefaultFolder)
|
FString UHarmonyLinkGraphics::GetConfigDirectoryFile(const bool bDefaultFolder)
|
||||||
{
|
{
|
||||||
FString ConfigFileName = bDefaultFolder? "DefaultHarmonyLink.ini" : "HarmonyLink.ini"; // Replace with your actual config file name
|
UE_LOG(LogHarmonyLink, Log, TEXT("GetConfigDirectoryFile called."));
|
||||||
|
FString ConfigFileName = bDefaultFolder ? TEXT("DefaultHarmonyLink.ini") : TEXT("HarmonyLink.ini");
|
||||||
|
|
||||||
return FPaths::Combine(bDefaultFolder ? FPaths::ProjectConfigDir() : FPaths::GeneratedConfigDir(), ConfigFileName);
|
FString ConfigDirectory = bDefaultFolder ? FPaths::ProjectConfigDir() : FPaths::Combine(FPaths::GeneratedConfigDir(), UGameplayStatics::GetPlatformName());
|
||||||
|
|
||||||
|
return FPaths::Combine(ConfigDirectory, ConfigFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UHarmonyLinkGraphics::SaveSection(const FSettingsProfile& SettingsProfile, const bool bDefaultConfig, const bool bFlush)
|
void UHarmonyLinkGraphics::SaveSection(const FSettingsProfile& SettingsProfile, const bool bDefaultConfig, const bool bFlush) const
|
||||||
{
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, Log, TEXT("SaveSection called."));
|
||||||
if (GConfig)
|
if (GConfig)
|
||||||
{
|
{
|
||||||
const FString Filename = GetConfigDirectoryFile(bDefaultConfig);
|
const FString Filename = GetConfigDirectoryFile(bDefaultConfig);
|
||||||
|
@ -430,7 +468,7 @@ void UHarmonyLinkGraphics::SaveSection(const FSettingsProfile& SettingsProfile,
|
||||||
TypeString = TEXT("float");
|
TypeString = TEXT("float");
|
||||||
break;
|
break;
|
||||||
case EConfigValueType::Bool:
|
case EConfigValueType::Bool:
|
||||||
ValueString = Setting.Value.GetValue<bool>() ? TEXT("true") : TEXT("false");
|
ValueString = Setting.Value.GetValue<bool>() ? TEXT("True") : TEXT("False");
|
||||||
TypeString = TEXT("bool");
|
TypeString = TEXT("bool");
|
||||||
break;
|
break;
|
||||||
case EConfigValueType::String:
|
case EConfigValueType::String:
|
||||||
|
@ -452,9 +490,9 @@ void UHarmonyLinkGraphics::SaveSection(const FSettingsProfile& SettingsProfile,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UHarmonyLinkGraphics::LoadDefaults()
|
void UHarmonyLinkGraphics::LoadDefaults() const
|
||||||
{
|
{
|
||||||
UE_LOG(LogHarmonyLink, Log, TEXT("LoadDefaults started."));
|
UE_LOG(LogHarmonyLink, Log, TEXT("LoadDefaults called."));
|
||||||
|
|
||||||
_Profiles.Reset();
|
_Profiles.Reset();
|
||||||
|
|
||||||
|
@ -475,6 +513,7 @@ void UHarmonyLinkGraphics::LoadDefaults()
|
||||||
|
|
||||||
bool UHarmonyLinkGraphics::ApplyProfileInternal(const EProfile Profile)
|
bool UHarmonyLinkGraphics::ApplyProfileInternal(const EProfile Profile)
|
||||||
{
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, Log, TEXT("ApplyProfileInternal called."));
|
||||||
// If the profile is None, revert to the original user game settings
|
// If the profile is None, revert to the original user game settings
|
||||||
if (Profile == EProfile::NONE)
|
if (Profile == EProfile::NONE)
|
||||||
{
|
{
|
||||||
|
@ -536,6 +575,7 @@ bool UHarmonyLinkGraphics::ApplyProfileInternal(const EProfile Profile)
|
||||||
|
|
||||||
void UHarmonyLinkGraphics::OnPostWorldInitialization(UWorld* World, UWorld::InitializationValues IVS)
|
void UHarmonyLinkGraphics::OnPostWorldInitialization(UWorld* World, UWorld::InitializationValues IVS)
|
||||||
{
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, Log, TEXT("OnPostWorldInitialization called."));
|
||||||
if (!World || !World->IsValidLowLevel())
|
if (!World || !World->IsValidLowLevel())
|
||||||
{
|
{
|
||||||
UE_LOG(LogHarmonyLink, Error, TEXT("Failed to Hook into World Initialisation!"))
|
UE_LOG(LogHarmonyLink, Error, TEXT("Failed to Hook into World Initialisation!"))
|
||||||
|
@ -544,7 +584,7 @@ void UHarmonyLinkGraphics::OnPostWorldInitialization(UWorld* World, UWorld::Init
|
||||||
|
|
||||||
if (World->IsGameWorld())
|
if (World->IsGameWorld())
|
||||||
{
|
{
|
||||||
if (_INSTANCE)
|
if (IsValid(_INSTANCE))
|
||||||
{
|
{
|
||||||
FTimerManager* TimerManager = &World->GetTimerManager();
|
FTimerManager* TimerManager = &World->GetTimerManager();
|
||||||
if (!TimerManager)
|
if (!TimerManager)
|
||||||
|
@ -553,11 +593,12 @@ void UHarmonyLinkGraphics::OnPostWorldInitialization(UWorld* World, UWorld::Init
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!TimerManager->TimerExists(_INSTANCE->_TickTimerHandle) || !TimerManager->IsTimerActive(_INSTANCE->_TickTimerHandle))
|
if (!TimerManager->TimerExists(_TickTimerHandle) || !TimerManager->IsTimerActive(_TickTimerHandle))
|
||||||
{
|
{
|
||||||
World->GetTimerManager().SetTimer(_INSTANCE->_TickTimerHandle, [&, TimerManager]
|
|
||||||
|
World->GetTimerManager().SetTimer(_TickTimerHandle, [TimerManager]
|
||||||
{
|
{
|
||||||
if (!this)
|
if (!_INSTANCE)
|
||||||
{
|
{
|
||||||
UE_LOG(LogHarmonyLink, Error, TEXT("'This' is destroyed, Clearing timer."))
|
UE_LOG(LogHarmonyLink, Error, TEXT("'This' is destroyed, Clearing timer."))
|
||||||
if (TimerManager)
|
if (TimerManager)
|
||||||
|
@ -566,16 +607,29 @@ void UHarmonyLinkGraphics::OnPostWorldInitialization(UWorld* World, UWorld::Init
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Tick();
|
_INSTANCE->Tick();
|
||||||
}, _TickRate, true);
|
}, _TickRate, true);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, Error, TEXT("Error: Timer already exists."));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, Error, TEXT("'This' is nullptr!"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//UE_LOG(LogHarmonyLink, Error, TEXT("Failed to bring up tick!"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UHarmonyLinkGraphics::OnWorldEnd(UWorld* World)
|
void UHarmonyLinkGraphics::OnWorldEnd(UWorld* World)
|
||||||
{
|
{
|
||||||
if (!World || !World->IsValidLowLevel())
|
UE_LOG(LogHarmonyLink, Log, TEXT("OnWorldEnd(UWorld* World) called."));
|
||||||
|
if (!World)
|
||||||
{
|
{
|
||||||
UE_LOG(LogHarmonyLink, Error, TEXT("World Already destroyed"))
|
UE_LOG(LogHarmonyLink, Error, TEXT("World Already destroyed"))
|
||||||
return;
|
return;
|
||||||
|
@ -592,6 +646,7 @@ void UHarmonyLinkGraphics::OnWorldEnd(UWorld* World)
|
||||||
|
|
||||||
bool UHarmonyLinkGraphics::ApplyProfile(const EProfile Profile, const bool bDisableAutomaticSwitch)
|
bool UHarmonyLinkGraphics::ApplyProfile(const EProfile Profile, const bool bDisableAutomaticSwitch)
|
||||||
{
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, Log, TEXT("Applying Profile."));
|
||||||
// Manual profile change, turn off automatic switching
|
// Manual profile change, turn off automatic switching
|
||||||
if (bDisableAutomaticSwitch)
|
if (bDisableAutomaticSwitch)
|
||||||
{
|
{
|
||||||
|
@ -603,6 +658,7 @@ bool UHarmonyLinkGraphics::ApplyProfile(const EProfile Profile, const bool bDisa
|
||||||
|
|
||||||
void UHarmonyLinkGraphics::ApplySetting(const TPair<FName, FHLConfigValue>& Setting)
|
void UHarmonyLinkGraphics::ApplySetting(const TPair<FName, FHLConfigValue>& Setting)
|
||||||
{
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, Log, TEXT("Applying settings."));
|
||||||
// Apply the setting based on the key (CVar)
|
// Apply the setting based on the key (CVar)
|
||||||
IConsoleManager& ConsoleManager = IConsoleManager::Get();
|
IConsoleManager& ConsoleManager = IConsoleManager::Get();
|
||||||
IConsoleVariable* CVar = ConsoleManager.FindConsoleVariable(*Setting.Key.ToString());
|
IConsoleVariable* CVar = ConsoleManager.FindConsoleVariable(*Setting.Key.ToString());
|
||||||
|
@ -646,6 +702,45 @@ void UHarmonyLinkGraphics::DebugPrintProfiles() const
|
||||||
UE_LOG(LogHarmonyLink, Log, TEXT("DebugPrintProfiles completed."));
|
UE_LOG(LogHarmonyLink, Log, TEXT("DebugPrintProfiles completed."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FConfigFile* UHarmonyLinkGraphics::GetConfig() const
|
||||||
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, Verbose, TEXT("GetConfig Called."));
|
||||||
|
if (_ConfigFile)
|
||||||
|
{
|
||||||
|
return _ConfigFile.Get();
|
||||||
|
}
|
||||||
|
|
||||||
|
FConfigFile* ConfigFile = GConfig->Find(GetConfigDirectoryFile(false), false);
|
||||||
|
|
||||||
|
if (!ConfigFile)
|
||||||
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, Warning, TEXT("Config file not found, attempting to read DefaultHarmonyLink.ini."));
|
||||||
|
// Look in ProjectFolder->Config->DefaultHarmonyLink.ini
|
||||||
|
ConfigFile = GConfig->Find(GetConfigDirectoryFile(true), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if (!ConfigFile)
|
||||||
|
{
|
||||||
|
CreateDefaultConfigFile();
|
||||||
|
ConfigFile = GConfig->Find(GetConfigDirectoryFile(true), true);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
if (ConfigFile)
|
||||||
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, Verbose, TEXT("Setting up config."));
|
||||||
|
ConfigFile->Name = "HarmonyLink";
|
||||||
|
LoadSettingsFromConfig(ConfigFile);
|
||||||
|
_ConfigFile = MakeShareable(ConfigFile);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, Error, TEXT("Failed to make config variable!"))
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _ConfigFile.Get();
|
||||||
|
}
|
||||||
|
|
||||||
void UHarmonyLinkGraphics::PrintDebugSection(FSettingsProfile& SettingsProfile)
|
void UHarmonyLinkGraphics::PrintDebugSection(FSettingsProfile& SettingsProfile)
|
||||||
{
|
{
|
||||||
UE_LOG(LogHarmonyLink, Warning, TEXT("[%s]"), *SettingsProfile.SectionName.ToString());
|
UE_LOG(LogHarmonyLink, Warning, TEXT("[%s]"), *SettingsProfile.SectionName.ToString());
|
||||||
|
@ -681,6 +776,7 @@ void UHarmonyLinkGraphics::PrintDebugSection(FSettingsProfile& SettingsProfile)
|
||||||
|
|
||||||
void UHarmonyLinkGraphics::ResetInstance()
|
void UHarmonyLinkGraphics::ResetInstance()
|
||||||
{
|
{
|
||||||
|
UE_LOG(LogHarmonyLink, Log, TEXT("Resetting instance."));
|
||||||
_INSTANCE->DestroySettings();
|
_INSTANCE->DestroySettings();
|
||||||
GetSettings();
|
GetSettings();
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,20 +19,20 @@ FDevice::FDevice(HarmonyLinkLib::FDevice* oldDevice)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EDeviceEnum FDevice::Convert(HarmonyLinkLib::EDevice Device)
|
EDevice FDevice::Convert(HarmonyLinkLib::EDevice Device)
|
||||||
{
|
{
|
||||||
switch (Device)
|
switch (Device)
|
||||||
{
|
{
|
||||||
case HarmonyLinkLib::EDevice::DESKTOP:
|
case HarmonyLinkLib::EDevice::DESKTOP:
|
||||||
return EDeviceEnum::DESKTOP;
|
return EDevice::DESKTOP;
|
||||||
case HarmonyLinkLib::EDevice::LAPTOP:
|
case HarmonyLinkLib::EDevice::LAPTOP:
|
||||||
return EDeviceEnum::LAPTOP;
|
return EDevice::LAPTOP;
|
||||||
case HarmonyLinkLib::EDevice::HANDHELD:
|
case HarmonyLinkLib::EDevice::HANDHELD:
|
||||||
return EDeviceEnum::HANDHELD;
|
return EDevice::HANDHELD;
|
||||||
case HarmonyLinkLib::EDevice::STEAM_DECK:
|
case HarmonyLinkLib::EDevice::STEAM_DECK:
|
||||||
return EDeviceEnum::STEAM_DECK;
|
return EDevice::STEAM_DECK;
|
||||||
default:
|
default:
|
||||||
return EDeviceEnum::DESKTOP;
|
return EDevice::DESKTOP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
* Enum representing different operating system platforms.
|
* Enum representing different operating system platforms.
|
||||||
*/
|
*/
|
||||||
UENUM(BlueprintType)
|
UENUM(BlueprintType)
|
||||||
enum class EDeviceEnum : uint8
|
enum class EDevice : uint8
|
||||||
{
|
{
|
||||||
DESKTOP UMETA(DisplayName = "Desktop"),
|
DESKTOP UMETA(DisplayName = "Desktop"),
|
||||||
LAPTOP UMETA(DisplayName = "Laptop"),
|
LAPTOP UMETA(DisplayName = "Laptop"),
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
UENUM(BlueprintType)
|
UENUM(BlueprintType)
|
||||||
enum class EProfile : uint8
|
enum class EProfile : uint8
|
||||||
{
|
{
|
||||||
NONE UMETA(DisplayName = "NONE"),
|
NONE = 0 UMETA(DisplayName = "NONE"),
|
||||||
BATTERY UMETA(DisplayName = "BATTERY"),
|
BATTERY UMETA(DisplayName = "BATTERY"),
|
||||||
CHARGING UMETA(DisplayName = "CHARGING"),
|
CHARGING UMETA(DisplayName = "CHARGING"),
|
||||||
DOCKED UMETA(DisplayName = "DOCKED"),
|
DOCKED UMETA(DisplayName = "DOCKED"),
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#include "Modules/ModuleManager.h"
|
#include "Modules/ModuleManager.h"
|
||||||
|
|
||||||
DECLARE_LOG_CATEGORY_EXTERN(LogHarmonyLink, Log, All);
|
DECLARE_LOG_CATEGORY_EXTERN(LogHarmonyLink, All, All);
|
||||||
|
|
||||||
class FHarmonyLinkModule : public IModuleInterface
|
class FHarmonyLinkModule : public IModuleInterface
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,31 +21,33 @@ class HARMONYLINK_API UHarmonyLinkLibrary : public UBlueprintFunctionLibrary
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
UHarmonyLinkLibrary();
|
||||||
|
|
||||||
// Checks if the game is running under Wine.
|
// Checks if the game is running under Wine.
|
||||||
UFUNCTION(BlueprintCallable, Category="HarmonyLink")
|
UFUNCTION(BlueprintCallable, BlueprintPure, Category="HarmonyLink")
|
||||||
static bool IsWine();
|
static bool IsWine();
|
||||||
|
|
||||||
// Checks if the operating system is Linux.
|
// Checks if the operating system is Linux.
|
||||||
UFUNCTION(BlueprintCallable, Category="HarmonyLink")
|
UFUNCTION(BlueprintCallable, BlueprintPure, Category="HarmonyLink")
|
||||||
static bool IsLinux();
|
static bool IsLinux();
|
||||||
|
|
||||||
// Checks if the game is running on a Steam Deck.
|
// Checks if the game is running on a Steam Deck.
|
||||||
UFUNCTION(BlueprintCallable, Category="HarmonyLink")
|
UFUNCTION(BlueprintCallable, BlueprintPure, Category="HarmonyLink")
|
||||||
static bool IsSteamDeck();
|
static bool IsSteamDeck();
|
||||||
|
|
||||||
// Retrieves information about the CPU of the current device.
|
// Retrieves information about the CPU of the current device.
|
||||||
UFUNCTION(BlueprintCallable, Category="HarmonyLink")
|
UFUNCTION(BlueprintCallable, BlueprintPure, Category="HarmonyLink")
|
||||||
static FCPUInfo GetCPUInfo();
|
static FCPUInfo GetCPUInfo();
|
||||||
|
|
||||||
// Retrieves information about the current device.
|
// Retrieves information about the current device.
|
||||||
UFUNCTION(BlueprintCallable, Category="HarmonyLink")
|
UFUNCTION(BlueprintCallable, BlueprintPure, Category="HarmonyLink")
|
||||||
static FDevice GetDeviceInfo();
|
static FDevice GetDeviceInfo();
|
||||||
|
|
||||||
// Retrieves information about the operating system of the current device.
|
// Retrieves information about the operating system of the current device.
|
||||||
UFUNCTION(BlueprintCallable, Category="HarmonyLink")
|
UFUNCTION(BlueprintCallable, BlueprintPure, Category="HarmonyLink")
|
||||||
static FOSVerInfo GetOSInfo();
|
static FOSVerInfo GetOSInfo();
|
||||||
|
|
||||||
// Retrieves the current battery status of the device.
|
// Retrieves the current battery status of the device.
|
||||||
UFUNCTION(BlueprintCallable, Category="HarmonyLink")
|
UFUNCTION(BlueprintCallable, BlueprintPure, Category="HarmonyLink")
|
||||||
static FBattery GetBatteryStatus();
|
static FBattery GetBatteryStatus();
|
||||||
};
|
};
|
||||||
|
|
|
@ -120,7 +120,7 @@ public:
|
||||||
* - Calls the `Init` function on the new instance to perform any necessary initialization.
|
* - Calls the `Init` function on the new instance to perform any necessary initialization.
|
||||||
* - Returns the singleton instance.
|
* - Returns the singleton instance.
|
||||||
*/
|
*/
|
||||||
UFUNCTION(BlueprintCallable, Category="HarmonyLink Settings")
|
UFUNCTION(BlueprintCallable, BlueprintPure, Category="HarmonyLink Settings")
|
||||||
static UHarmonyLinkGraphics* GetSettings();
|
static UHarmonyLinkGraphics* GetSettings();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -141,7 +141,7 @@ public:
|
||||||
*
|
*
|
||||||
* @note Uses UE_LOG for logging errors.
|
* @note Uses UE_LOG for logging errors.
|
||||||
*/
|
*/
|
||||||
UFUNCTION(BlueprintCallable, BlueprintPure, Category="HarmonyLink Settings")
|
UFUNCTION(BlueprintCallable, BlueprintPure, BlueprintPure, Category="HarmonyLink Settings")
|
||||||
FSettingsProfile GetSettingProfile(const EProfile Profile);
|
FSettingsProfile GetSettingProfile(const EProfile Profile);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -245,7 +245,7 @@ private:
|
||||||
*
|
*
|
||||||
* @note Uses UE_LOG for logging the creation process.
|
* @note Uses UE_LOG for logging the creation process.
|
||||||
*/
|
*/
|
||||||
void CreateDefaultConfigFile();
|
void CreateDefaultConfigFile() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Retrieves the path to the configuration file.
|
* @brief Retrieves the path to the configuration file.
|
||||||
|
@ -278,7 +278,7 @@ private:
|
||||||
*
|
*
|
||||||
* @note Uses UE_LOG for logging errors and success messages.
|
* @note Uses UE_LOG for logging errors and success messages.
|
||||||
*/
|
*/
|
||||||
bool LoadSettingsFromConfig(const bool bLoadDefaults);
|
bool LoadSettingsFromConfig(FConfigFile* ConfigFile) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Loads a specific section from the configuration file into a settings profile.
|
* @brief Loads a specific section from the configuration file into a settings profile.
|
||||||
|
@ -298,7 +298,7 @@ private:
|
||||||
*
|
*
|
||||||
* @note The function handles settings of types int, float, bool, and string.
|
* @note The function handles settings of types int, float, bool, and string.
|
||||||
*/
|
*/
|
||||||
bool LoadSection(const FConfigFile& ConfigFile, const TPair<EProfile, FName> Profile);
|
static bool LoadSection(FConfigFile* ConfigFile, const TPair<EProfile, FName> Profile);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -322,7 +322,7 @@ private:
|
||||||
*
|
*
|
||||||
* @note Uses UE_LOG for logging the save and flush operations.
|
* @note Uses UE_LOG for logging the save and flush operations.
|
||||||
*/
|
*/
|
||||||
static void SaveSection(const FSettingsProfile& SettingsProfile, const bool bDefaultConfig, const bool bFlush = false);
|
void SaveSection(const FSettingsProfile& SettingsProfile, const bool bDefaultConfig, const bool bFlush = false) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Loads the default settings into the profiles.
|
* @brief Loads the default settings into the profiles.
|
||||||
|
@ -340,7 +340,7 @@ private:
|
||||||
*
|
*
|
||||||
* @note Uses UE_LOG for logging the start of the default settings loading process.
|
* @note Uses UE_LOG for logging the start of the default settings loading process.
|
||||||
*/
|
*/
|
||||||
void LoadDefaults();
|
void LoadDefaults() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Applies the specified graphics profile internally.
|
* @brief Applies the specified graphics profile internally.
|
||||||
|
@ -451,6 +451,8 @@ private:
|
||||||
*/
|
*/
|
||||||
void DebugPrintProfiles() const;
|
void DebugPrintProfiles() const;
|
||||||
|
|
||||||
|
FConfigFile* GetConfig() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Prints debug information for a specific settings profile.
|
* @brief Prints debug information for a specific settings profile.
|
||||||
*
|
*
|
||||||
|
@ -468,10 +470,10 @@ private:
|
||||||
static void PrintDebugSection(FSettingsProfile& SettingsProfile);
|
static void PrintDebugSection(FSettingsProfile& SettingsProfile);
|
||||||
|
|
||||||
// Indicates whether automatic profile switching is enabled.
|
// Indicates whether automatic profile switching is enabled.
|
||||||
bool _bAutomaticSwitch = false;
|
static bool _bAutomaticSwitch;
|
||||||
|
|
||||||
// Stores the last recorded battery percentage.
|
// Stores the last recorded battery percentage.
|
||||||
int32 _LastBatteryPercentage = 0;
|
static int32 _LastBatteryPercentage;
|
||||||
|
|
||||||
// The rate at which to query HarmonyLinkLib for hardware info.
|
// The rate at which to query HarmonyLinkLib for hardware info.
|
||||||
static int32 _TickRate;
|
static int32 _TickRate;
|
||||||
|
@ -480,17 +482,15 @@ private:
|
||||||
static FTimerHandle _TickTimerHandle;
|
static FTimerHandle _TickTimerHandle;
|
||||||
|
|
||||||
// The currently active profile.
|
// The currently active profile.
|
||||||
EProfile _ActiveProfile = EProfile::NONE;
|
static EProfile _ActiveProfile;
|
||||||
|
|
||||||
// Maps profile enums to their corresponding names.
|
// Maps profile enums to their corresponding names.
|
||||||
TMap<EProfile, FName> _ProfileNames = {
|
static TMap<EProfile, FName> _ProfileNames;
|
||||||
{EProfile::BATTERY, "Battery"},
|
|
||||||
{EProfile::CHARGING, "Charging"},
|
|
||||||
{EProfile::DOCKED, "Docked"},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Stores the settings profiles.
|
// Stores the settings profiles.
|
||||||
TMap<EProfile, FSettingsProfile> _Profiles;
|
static TMap<EProfile, FSettingsProfile> _Profiles;
|
||||||
|
|
||||||
|
static TSharedPtr<FConfigFile> _ConfigFile;
|
||||||
|
|
||||||
// The default settings for profiles.
|
// The default settings for profiles.
|
||||||
static TMap<FName, TMap<FName, FHLConfigValue>> _DefaultSettings;
|
static TMap<FName, TMap<FName, FHLConfigValue>> _DefaultSettings;
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
// Copyright (C) 2024 Jordon Brooks
|
// Copyright (C) 2024 Jordon Brooks
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <HarmonyLinkLib.h>
|
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
|
|
||||||
|
#include "Structs/FBattery.h"
|
||||||
|
|
||||||
#include "Battery.generated.h"
|
#include "Battery.generated.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <HarmonyLinkLib.h>
|
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
|
|
||||||
|
#include "Structs/FCPUInfo.h"
|
||||||
|
|
||||||
#include "CPUInfo.generated.h"
|
#include "CPUInfo.generated.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "Enums/DeviceEnum.h"
|
#include "Enums/DeviceEnum.h"
|
||||||
#include "Enums/Platform.h"
|
#include "Enums/Platform.h"
|
||||||
#include <Structs/FDevice.h>
|
|
||||||
|
#include "Structs/FDevice.h"
|
||||||
|
|
||||||
#include "Device.generated.h"
|
#include "Device.generated.h"
|
||||||
|
|
||||||
|
@ -25,7 +26,7 @@ struct FDevice
|
||||||
|
|
||||||
// The type of the device.
|
// The type of the device.
|
||||||
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="HarmonyLink")
|
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="HarmonyLink")
|
||||||
EDeviceEnum Device = EDeviceEnum::DESKTOP;
|
EDevice Device = EDevice::DESKTOP;
|
||||||
|
|
||||||
// Constructor that initializes the struct with information from an external source.
|
// Constructor that initializes the struct with information from an external source.
|
||||||
// @param oldDevice Pointer to an external FDevice structure to copy data from.
|
// @param oldDevice Pointer to an external FDevice structure to copy data from.
|
||||||
|
@ -35,7 +36,7 @@ private:
|
||||||
// Converts an external device enum to the internal EDeviceEnum type.
|
// Converts an external device enum to the internal EDeviceEnum type.
|
||||||
// @param Device External device enum to convert.
|
// @param Device External device enum to convert.
|
||||||
// @returns Converted EDeviceEnum value.
|
// @returns Converted EDeviceEnum value.
|
||||||
static EDeviceEnum Convert(HarmonyLinkLib::EDevice Device);
|
static EDevice Convert(HarmonyLinkLib::EDevice Device);
|
||||||
|
|
||||||
// Converts an external platform enum to the internal EPlatform type.
|
// Converts an external platform enum to the internal EPlatform type.
|
||||||
// @param Platform External platform enum to convert.
|
// @param Platform External platform enum to convert.
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include <HarmonyLinkLib.h>
|
|
||||||
|
#include "Structs/FOSVerInfo.h"
|
||||||
|
|
||||||
#include "OSVerInfo.generated.h"
|
#include "OSVerInfo.generated.h"
|
||||||
|
|
||||||
|
|
|
@ -8,39 +8,46 @@ public class HarmonyLinkLib : ModuleRules
|
||||||
{
|
{
|
||||||
public HarmonyLinkLib(ReadOnlyTargetRules Target) : base(Target)
|
public HarmonyLinkLib(ReadOnlyTargetRules Target) : base(Target)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Building HarmonyLinkLib");
|
//Console.WriteLine("Building HarmonyLinkLib");
|
||||||
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
|
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
|
||||||
|
|
||||||
Type = ModuleType.External;
|
Type = ModuleType.External;
|
||||||
|
|
||||||
// Add the standard library
|
// Add the standard library
|
||||||
bUseRTTI = true;
|
//bUseRTTI = true;
|
||||||
bEnableExceptions = true;
|
//bEnableExceptions = true;
|
||||||
|
|
||||||
// Optionally, if you need C++17 features
|
// Optionally, if you need C++17 features
|
||||||
CppStandard = CppStandardVersion.Cpp17;
|
//CppStandard = CppStandardVersion.Cpp17;
|
||||||
|
|
||||||
string includePath = Path.Combine(ModuleDirectory, "include");
|
string includePath = Path.Combine(ModuleDirectory, "include");
|
||||||
Console.WriteLine("Include Path: " + includePath);
|
//Console.WriteLine("Include Path: " + includePath);
|
||||||
PublicIncludePaths.Add(includePath);
|
PublicIncludePaths.Add(includePath);
|
||||||
|
|
||||||
PublicDefinitions.Add("HARMONYLINKLIB_STATIC=1");
|
|
||||||
|
|
||||||
string platformString = Target.Platform.ToString();
|
string platformString = Target.Platform.ToString();
|
||||||
if (Target.Platform == UnrealTargetPlatform.Win64)
|
if (Target.Platform == UnrealTargetPlatform.Win64)
|
||||||
{
|
{
|
||||||
|
PublicDefinitions.Add("HARMONYLINKLIB_STATIC=1");
|
||||||
PublicDefinitions.Add("BUILD_WINDOWS=1");
|
PublicDefinitions.Add("BUILD_WINDOWS=1");
|
||||||
string dllPath = Path.Combine(ModuleDirectory, "lib", platformString, "HarmonyLinkLibStatic.lib");
|
string libpath = Path.Combine(ModuleDirectory, "lib", platformString, "HarmonyLinkLibStatic.lib");
|
||||||
Console.WriteLine("DLL Path: " + dllPath);
|
|
||||||
PublicAdditionalLibraries.Add(dllPath);
|
PublicAdditionalLibraries.Add(libpath);
|
||||||
//RuntimeDependencies.Add(dllPath);
|
|
||||||
|
//string dllPath = Path.Combine(ModuleDirectory, "bin", platformString, "HarmonyLinkLibShared.dll");
|
||||||
|
//string dllTargetPath = "$(TargetOutputDir)/HarmonyLinkLibShared.dll";
|
||||||
|
|
||||||
|
//Console.WriteLine("DLL Path: " + dllPath);
|
||||||
|
//RuntimeDependencies.Add(dllTargetPath, dllPath);
|
||||||
|
|
||||||
|
//PublicDelayLoadDLLs.Add("HarmonyLinkLibShared.dll");
|
||||||
}
|
}
|
||||||
else if (Target.Platform == UnrealTargetPlatform.Linux)
|
else if (Target.Platform == UnrealTargetPlatform.Linux)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Building Linux");
|
PublicDefinitions.Add("HARMONYLINKLIB_SHARED=1");
|
||||||
|
//Console.WriteLine("Building Linux");
|
||||||
PublicDefinitions.Add("BUILD_LINUX=1");
|
PublicDefinitions.Add("BUILD_LINUX=1");
|
||||||
string libPath = Path.Combine(ModuleDirectory, "bin", platformString, "libHarmonyLinkLibShared.so");
|
string libPath = Path.Combine(ModuleDirectory, "bin", platformString, "libHarmonyLinkLibShared.so");
|
||||||
Console.WriteLine("Library Path: " + libPath);
|
//Console.WriteLine("Library Path: " + libPath);
|
||||||
PublicAdditionalLibraries.Add(libPath);
|
PublicAdditionalLibraries.Add(libPath);
|
||||||
|
|
||||||
// Add the C++ standard library explicitly
|
// Add the C++ standard library explicitly
|
||||||
|
@ -51,9 +58,10 @@ public class HarmonyLinkLib : ModuleRules
|
||||||
// I shall include this if anyone wishes to provide Mac binaries of HarmonyLink but these are not included by default as I don't own one.
|
// I shall include this if anyone wishes to provide Mac binaries of HarmonyLink but these are not included by default as I don't own one.
|
||||||
else if (Target.Platform == UnrealTargetPlatform.Mac)
|
else if (Target.Platform == UnrealTargetPlatform.Mac)
|
||||||
{
|
{
|
||||||
|
PublicDefinitions.Add("HARMONYLINKLIB_SHARED=1");
|
||||||
PublicDefinitions.Add("BUILD_MACOS=1");
|
PublicDefinitions.Add("BUILD_MACOS=1");
|
||||||
string dynlibPath = Path.Combine(ModuleDirectory, "lib", platformString, "libHarmonyLinkLibStatic.a");
|
string dynlibPath = Path.Combine(ModuleDirectory, "lib", platformString, "libHarmonyLinkLibStatic.a");
|
||||||
Console.WriteLine("Dynamic Library Path: " + dynlibPath);
|
//Console.WriteLine("Dynamic Library Path: " + dynlibPath);
|
||||||
RuntimeDependencies.Add(dynlibPath);
|
RuntimeDependencies.Add(dynlibPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
BIN
Source/ThirdParty/HarmonyLinkLib/bin/Win64/HarmonyLinkLibShared.dll
(Stored with Git LFS)
vendored
BIN
Source/ThirdParty/HarmonyLinkLib/bin/Win64/HarmonyLinkLibShared.dll
(Stored with Git LFS)
vendored
Binary file not shown.
|
@ -44,17 +44,19 @@ class IPlatformUtilities;
|
||||||
|
|
||||||
namespace HarmonyLinkLib
|
namespace HarmonyLinkLib
|
||||||
{
|
{
|
||||||
extern "C" HARMONYLINKLIB_API bool get_is_wine();
|
HARMONYLINKLIB_API bool HL_Init();
|
||||||
|
|
||||||
extern "C" HARMONYLINKLIB_API bool get_is_linux();
|
HARMONYLINKLIB_API bool get_is_wine();
|
||||||
|
|
||||||
extern "C" HARMONYLINKLIB_API bool get_is_docked();
|
HARMONYLINKLIB_API bool get_is_linux();
|
||||||
|
|
||||||
extern "C" HARMONYLINKLIB_API FCPUInfo* get_cpu_info();
|
HARMONYLINKLIB_API bool get_is_docked();
|
||||||
|
|
||||||
extern "C" HARMONYLINKLIB_API FDevice* get_device_info();
|
HARMONYLINKLIB_API FCPUInfo* get_cpu_info();
|
||||||
|
|
||||||
extern "C" HARMONYLINKLIB_API FOSVerInfo* get_os_version();
|
HARMONYLINKLIB_API FDevice* get_device_info();
|
||||||
|
|
||||||
|
HARMONYLINKLIB_API FOSVerInfo* get_os_version();
|
||||||
|
|
||||||
extern "C" HARMONYLINKLIB_API FBattery* get_battery_status();
|
HARMONYLINKLIB_API FBattery* get_battery_status();
|
||||||
}
|
}
|
||||||
|
|
BIN
Source/ThirdParty/HarmonyLinkLib/lib/Linux/libHarmonyLinkLibStatic.a
(Stored with Git LFS)
vendored
BIN
Source/ThirdParty/HarmonyLinkLib/lib/Linux/libHarmonyLinkLibStatic.a
(Stored with Git LFS)
vendored
Binary file not shown.
BIN
Source/ThirdParty/HarmonyLinkLib/lib/Win64/HarmonyLinkLibStatic.lib
(Stored with Git LFS)
vendored
BIN
Source/ThirdParty/HarmonyLinkLib/lib/Win64/HarmonyLinkLibStatic.lib
(Stored with Git LFS)
vendored
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue