From 82fca1bfbcaf0264717ee3ea608134a9fa6f7997 Mon Sep 17 00:00:00 2001 From: GenZmeY Date: Sun, 13 Jun 2021 03:02:17 +0300 Subject: [PATCH] WIP --- ScoreboardExt/Build.uci | 2 +- ScoreboardExt/Classes/ScoreboardExtMut.uc | 15 +-- ScoreboardExt/Classes/ScoreboardExtRepInfo.uc | 96 +++++++++++++++---- ScoreboardExt/Classes/SystemPlayerRank.uc | 6 +- ScoreboardExt/Logger.uci | 2 +- 5 files changed, 91 insertions(+), 30 deletions(-) diff --git a/ScoreboardExt/Build.uci b/ScoreboardExt/Build.uci index 5eb784a..5e0bb32 100644 --- a/ScoreboardExt/Build.uci +++ b/ScoreboardExt/Build.uci @@ -1,2 +1,2 @@ `define bEnableCallstack true -`define CurrentVersion 1 \ No newline at end of file +`define bEnableDebug true \ No newline at end of file diff --git a/ScoreboardExt/Classes/ScoreboardExtMut.uc b/ScoreboardExt/Classes/ScoreboardExtMut.uc index 464b5df..21fecc4 100644 --- a/ScoreboardExt/Classes/ScoreboardExtMut.uc +++ b/ScoreboardExt/Classes/ScoreboardExtMut.uc @@ -5,6 +5,8 @@ class ScoreboardExtMut extends KFMutator `include(Build.uci) `include(Logger.uci) +const CurrentVersion = 1; + var config int ConfigVersion; var private OnlineSubsystem Steamworks; @@ -119,23 +121,23 @@ private function InitConfig() class'SteamGroupRankRelations'.static.StaticSaveConfig(); case 2147483647: - `info("Config updated to version"@`CurrentVersion); + `info("Config updated to version"@CurrentVersion); break; - case `CurrentVersion: + case CurrentVersion: `info("Config is up-to-date"); break; default: `warning("The config version is higher than the current version (are you using an old mutator?)"); - `warning("Config version is"@ConfigVersion@"but current version is"@`CurrentVersion); - `warning("The config version will be changed to "@`CurrentVersion); + `warning("Config version is"@ConfigVersion@"but current version is"@CurrentVersion); + `warning("The config version will be changed to "@CurrentVersion); break; } - if (ConfigVersion != `CurrentVersion) + if (ConfigVersion != CurrentVersion) { - ConfigVersion = `CurrentVersion; + ConfigVersion = CurrentVersion; SaveConfig(); } } @@ -200,7 +202,6 @@ private function AddPlayer(Controller C) RepClientNew.RepInfo.Settings = Settings; RepClientNew.RepInfo.RankRelation.UID = KFPC.PlayerReplicationInfo.UniqueId; RepClientNew.RepInfo.RankRelation.RankID = UIDRankRelationsPlayers.Find('UID', RepClientNew.RepInfo.RankRelation.UID); - UIDRankRelationsActive.AddItem(RepClientNew.RepInfo.RankRelation); RepClients.AddItem(RepClientNew); diff --git a/ScoreboardExt/Classes/ScoreboardExtRepInfo.uc b/ScoreboardExt/Classes/ScoreboardExtRepInfo.uc index b7a6b79..83046af 100644 --- a/ScoreboardExt/Classes/ScoreboardExtRepInfo.uc +++ b/ScoreboardExt/Classes/ScoreboardExtRepInfo.uc @@ -12,6 +12,7 @@ var private OnlineSubsystemSteamworks SW; // Fitst time replication var public array SteamGroupRelations; +var private array RankRelations; var public array CustomRanks; var public SCESettings Settings; var public UIDRankRelation RankRelation; // Current player rank relation @@ -26,48 +27,95 @@ simulated event PostBeginPlay() if (bDeleteMe) return; - if (Role < ROLE_Authority) + if (Role < ROLE_Authority || WorldInfo.NetMode == NM_StandAlone) { - ClientInit(); + GetScoreboard(); + GetOnlineSubsystem(); } } -private reliable client function ClientInit() +private reliable client function GetScoreboard() { `callstack(); if (SC == None) SC = ScoreboardExtHUD(GetALocalPlayerController().myHUD).Scoreboard; + if (SC == None) + SetTimer(0.1f, false, nameof(GetScoreboard)); + else + ClearTimer(nameof(GetScoreboard)); +} + +private reliable client function GetOnlineSubsystem() +{ + `callstack(); + if (SW == None) SW = OnlineSubsystemSteamworks(class'GameEngine'.static.GetOnlineSubsystem()); - if (SC == None || SW == None) - SetTimer(0.1f, false, nameof(ClientInit)); + if (SW == None) + SetTimer(0.1f, false, nameof(GetOnlineSubsystem)); else - ClearTimer(nameof(ClientInit)); + ClearTimer(nameof(GetOnlineSubsystem)); } public function StartFirstTimeReplication() { `callstack(); + ClientApplySettings(); SetTimer(0.01f, true, nameof(ReplicateCustomRanks)); SetTimer(0.01f, true, nameof(ReplicateSteamGroupRelations)); } -private reliable client function ClientSetSettings(SCESettings Set) +private reliable client function ClientApplySettings() { `callstack(); - SC.Settings = Set; + if (SC == None) + { + SetTimer(0.1f, false, nameof(ClientApplySettings)); + return; + } + + ClearTimer(nameof(ClientApplySettings)); + SC.Settings = Settings; +} + +private reliable client function ClientApplyCustomRanks() +{ + `callstack(); + + if (SC == None) + { + SetTimer(0.1f, false, nameof(ClientApplyCustomRanks)); + return; + } + + ClearTimer(nameof(ClientApplyCustomRanks)); + SC.CustomRanks = CustomRanks; +} + +private reliable client function ClientApplyRankRelations() +{ + `callstack(); + + if (SC == None) + { + SetTimer(0.1f, false, nameof(ClientApplyRankRelations)); + return; + } + + ClearTimer(nameof(ClientApplyRankRelations)); + SC.RankRelations = RankRelations; } private function ReplicateCustomRanks() { `callstack(); - if (CustomRanksRepProgress < CustomRanks.Length) + if (WorldInfo.NetMode != NM_StandAlone && CustomRanksRepProgress < CustomRanks.Length) { ClientAddCustomRank(CustomRanks[CustomRanksRepProgress]); ++CustomRanksRepProgress; @@ -75,6 +123,7 @@ private function ReplicateCustomRanks() else { ClearTimer(nameof(ReplicateCustomRanks)); + ClientApplyCustomRanks(); } } @@ -89,7 +138,7 @@ private function ReplicateSteamGroupRelations() { `callstack(); - if (SteamGroupsRepProgress < SteamGroupRelations.Length) + if (WorldInfo.NetMode != NM_StandAlone && SteamGroupsRepProgress < SteamGroupRelations.Length) { ClientAddSteamGroupRelation(SteamGroupRelations[SteamGroupsRepProgress]); ++SteamGroupsRepProgress; @@ -114,11 +163,11 @@ private reliable client function FindMyRankInSteamGroups() local UIDRankRelation SteamGroupRel; `callstack(); - + foreach SteamGroupRelations(SteamGroupRel) if (SW.CheckPlayerGroup(SteamGroupRel.UID)) RankRelation.RankID = SteamGroupRel.RankID; - + if (RankRelation.RankID != INDEX_NONE) ServerApplyRank(RankRelation.RankID); } @@ -142,7 +191,8 @@ private reliable client function ClientAddRankRelation(UIDRankRelation Rel) { `callstack(); - SC.RankRelations.AddItem(Rel); + RankRelations.AddItem(Rel); + ClientApplyRankRelations(); } public function RemoveRankRelation(UIDRankRelation Rel) @@ -152,11 +202,12 @@ public function RemoveRankRelation(UIDRankRelation Rel) ClientRemoveRankRelation(Rel); } -private unreliable client function ClientRemoveRankRelation(UIDRankRelation Rel) +private reliable client function ClientRemoveRankRelation(UIDRankRelation Rel) { `callstack(); - SC.RankRelations.RemoveItem(Rel); + RankRelations.RemoveItem(Rel); + ClientApplyRankRelations(); } public function UpdateRankRelation(UIDRankRelation Rel) @@ -172,14 +223,23 @@ private reliable client function ClientUpdateRankRelation(UIDRankRelation Rel) `callstack(); - Index = SC.RankRelations.Find('UID', Rel.UID); + Index = RankRelations.Find('UID', Rel.UID); if (Index != INDEX_NONE) - SC.RankRelations[Index] = Rel; + RankRelations[Index] = Rel; + + ClientApplyRankRelations(); } defaultproperties -{ +{ + bAlwaysRelevant = false; + bOnlyRelevantToOwner = true; + Role = ROLE_Authority; + RemoteRole = ROLE_SimulatedProxy; + // This is needed, otherwise the client-to-server RPC fails + bSkipActorPropertyReplication = false; + CustomRanksRepProgress = 0; SteamGroupsRepProgress = 0; } \ No newline at end of file diff --git a/ScoreboardExt/Classes/SystemPlayerRank.uc b/ScoreboardExt/Classes/SystemPlayerRank.uc index 74d62c9..0ff1b45 100644 --- a/ScoreboardExt/Classes/SystemPlayerRank.uc +++ b/ScoreboardExt/Classes/SystemPlayerRank.uc @@ -13,7 +13,7 @@ public static function SCESettingsPlayer DefaultSettings() { local SCESettingsPlayer Settings; - `callstack_static("abc"); + `callstack_static("DefaultSettings"); return Settings; } @@ -22,7 +22,7 @@ public static function SCESettingsPlayer Settings() { local SCESettingsPlayer Settings; - `callstack_static("abc"); + `callstack_static("Settings"); Settings.Rank = default.Rank; Settings.TextColor = default.TextColor; @@ -33,7 +33,7 @@ public static function SCESettingsPlayer Settings() public static function WriteSettings(SCESettingsPlayer Settings) { - `callstack_static("abc"); + `callstack_static("WriteSettings"); default.Rank = Settings.Rank; default.TextColor = Settings.TextColor; diff --git a/ScoreboardExt/Logger.uci b/ScoreboardExt/Logger.uci index acaa3b4..714c862 100644 --- a/ScoreboardExt/Logger.uci +++ b/ScoreboardExt/Logger.uci @@ -4,6 +4,6 @@ `define warning(text) `scelog("[WARNING]"@`text, true) `define error(text) `scelog("[ERROR]"@`text, true) -`define debug(text, cond) `scelog("[DEBUG]"@`text, true) +`define debug(text) `scelog("[DEBUG]"@`text, `bEnableDebug) `define callstack() `scelog("[CALLSTACK]"@`Location@"ROLE="$ROLE, `bEnableCallstack) `define callstack_static(text) `scelog("[CALLSTACK]"@`text, `bEnableCallstack) \ No newline at end of file