From b52e372ea9a73bf92bb75d8b18a2116d50060a48 Mon Sep 17 00:00:00 2001 From: Zetrith Date: Wed, 18 Oct 2023 19:46:26 +0200 Subject: [PATCH] Add ideo preset chooser for new factions Fix saving of policies (outfits etc) Remove spectator faction when converting to sp --- Source/Client/Comp/World/FactionWorldData.cs | 10 +++- .../Client/Comp/World/MultiplayerWorldComp.cs | 37 +++++++++++- Source/Client/Factions/FactionCreator.cs | 59 +++++++++++++++---- Source/Client/Factions/FactionSidebar.cs | 46 ++++++++++++--- Source/Client/Factions/MultifactionPatches.cs | 7 ++- .../Factions/Page_ChooseIdeo_Multifaction.cs | 49 +++++++++++++++ Source/Client/Factions/SidebarPatch.cs | 7 ++- Source/Client/Networking/HostUtil.cs | 16 +---- .../Networking/State/ClientPlayingState.cs | 3 + Source/Client/Patches/UniqueIds.cs | 30 ++++++++++ Source/Client/Saving/ConvertToSp.cs | 8 +++ Source/Client/UI/IngameDebug.cs | 19 ++---- Source/Client/UI/IngameUI.cs | 23 +++++++- Source/Client/UI/MainMenuPatches.cs | 3 +- 14 files changed, 260 insertions(+), 57 deletions(-) create mode 100644 Source/Client/Factions/Page_ChooseIdeo_Multifaction.cs diff --git a/Source/Client/Comp/World/FactionWorldData.cs b/Source/Client/Comp/World/FactionWorldData.cs index ac715ac7..5d2b9214 100644 --- a/Source/Client/Comp/World/FactionWorldData.cs +++ b/Source/Client/Comp/World/FactionWorldData.cs @@ -32,8 +32,16 @@ public void ExposeData() Scribe_Deep.Look(ref researchSpeed, "researchSpeed"); } - public void Tick() + public void ReassignIds() { + foreach (DrugPolicy p in drugPolicyDatabase.policies) + p.uniqueId = Find.UniqueIDsManager.GetNextThingID(); + + foreach (Outfit o in outfitDatabase.outfits) + o.uniqueId = Find.UniqueIDsManager.GetNextThingID(); + + foreach (FoodRestriction o in foodRestrictionDatabase.foodRestrictions) + o.id = Find.UniqueIDsManager.GetNextThingID(); } public static FactionWorldData New(int factionId) diff --git a/Source/Client/Comp/World/MultiplayerWorldComp.cs b/Source/Client/Comp/World/MultiplayerWorldComp.cs index 54a986d2..c2209daa 100644 --- a/Source/Client/Comp/World/MultiplayerWorldComp.cs +++ b/Source/Client/Comp/World/MultiplayerWorldComp.cs @@ -1,6 +1,7 @@ using RimWorld; using RimWorld.Planet; using System.Collections.Generic; +using System.Linq; using Verse; using Multiplayer.Client.Persistent; using Multiplayer.Client.Saving; @@ -36,16 +37,46 @@ public void ExposeData() Scribe_Collections.Look(ref trading, "tradingSessions", LookMode.Deep); if (Scribe.mode == LoadSaveMode.PostLoadInit) + if (trading.RemoveAll(t => t.trader == null || t.playerNegotiator == null) > 0) + Log.Message("Some trading sessions had null entries"); + + DoBackCompat(); + } + + private void DoBackCompat() + { + if (Scribe.mode != LoadSaveMode.PostLoadInit) + return; + + if (spectatorFaction == null) { - if (spectatorFaction == null) + void AddSpectatorFaction() { spectatorFaction = HostUtil.AddNewFaction("Spectator", FactionDefOf.PlayerColony); + + factionData[spectatorFaction.loadID] = FactionWorldData.New(spectatorFaction.loadID); + factionData[spectatorFaction.loadID].ReassignIds(); + foreach (var map in Find.Maps) MapSetup.InitNewFactionData(map, spectatorFaction); } - if (trading.RemoveAll(t => t.trader == null || t.playerNegotiator == null) > 0) - Log.Message("Some trading sessions had null entries"); + void RemoveOpponentFaction() + { + // Test faction left in by mistake in version 0.7 + var opponent = + Find.FactionManager.AllFactions.FirstOrDefault(f => f.Name == "Opponent" && f.IsPlayer); + + if (opponent is not null) + { + opponent.RemoveAllRelations(); + Find.FactionManager.allFactions.Remove(opponent); + Log.Warning("Multiplayer removed dummy Opponent faction"); + } + } + + AddSpectatorFaction(); + RemoveOpponentFaction(); } } diff --git a/Source/Client/Factions/FactionCreator.cs b/Source/Client/Factions/FactionCreator.cs index 48d70c2d..7b759ed3 100644 --- a/Source/Client/Factions/FactionCreator.cs +++ b/Source/Client/Factions/FactionCreator.cs @@ -24,7 +24,7 @@ public static void SendPawn(int sessionId, Pawn p) } [SyncMethod] - public static void CreateFaction(int sessionId, string factionName, int tile, string scenario, FactionRelationKind relation) + public static void CreateFaction(int sessionId, string factionName, int tile, string scenario, FactionRelationKind relation, ChooseIdeoInfo chooseIdeoInfo) { PrepareState(sessionId); @@ -32,8 +32,14 @@ public static void CreateFaction(int sessionId, string factionName, int tile, st LongEventHandler.QueueLongEvent(delegate { - int id = Find.UniqueIDsManager.GetNextFactionID(); - var newFaction = NewFaction(id, factionName, FactionDefOf.PlayerColony); + int newFactionID = Find.UniqueIDsManager.GetNextFactionID(); + + var newFaction = NewFaction( + newFactionID, + factionName, + FactionDefOf.PlayerColony, + chooseIdeoInfo + ); newFaction.hidden = true; @@ -44,6 +50,10 @@ public static void CreateFaction(int sessionId, string factionName, int tile, st } FactionContext.Push(newFaction); + + foreach (var pawn in StartingPawnUtility.StartingAndOptionalPawns) + pawn.ideo.SetIdeo(newFaction.ideos.PrimaryIdeo); + var newMap = GenerateNewMap(tile, scenario); FactionContext.Pop(); @@ -94,7 +104,7 @@ private static Map GenerateNewMap(int tile, string scenario) Find.WorldObjects.Add(mapParent); var prevScenario = Find.Scenario; - Current.Game.scenarioInt = ScenarioLister.AllScenarios().First(s => s.name == scenario); + Current.Game.scenarioInt = DefDatabase.AllDefs.First(s => s.defName == scenario).scenario; try { @@ -116,7 +126,7 @@ private static void InitNewGame() ResearchUtility.ApplyPlayerStartingResearch(); } - public static void SetInitialInitData() + public static void SetGameInitData() { Current.Game.InitData = new GameInitData { @@ -127,7 +137,7 @@ public static void SetInitialInitData() public static void PrepareState(int sessionId) { - SetInitialInitData(); + SetGameInitData(); if (pawnStore.TryGetValue(sessionId, out var pawns)) { @@ -140,24 +150,34 @@ public static void PrepareState(int sessionId) } } - private static Faction NewFaction(int id, string name, FactionDef def) + private static Faction NewFaction(int id, string name, FactionDef def, ChooseIdeoInfo chooseIdeoInfo) { Faction faction = Find.FactionManager.AllFactions.FirstOrDefault(f => f.loadID == id); if (faction == null) { - faction = new Faction() { loadID = id, def = def }; - + faction = new Faction { loadID = id, def = def }; faction.ideos = new FactionIdeosTracker(faction); - faction.ideos.ChooseOrGenerateIdeo(new IdeoGenerationParms()); + + if (!ModsConfig.IdeologyActive || Find.IdeoManager.classicMode) + { + faction.ideos.SetPrimary(Faction.OfPlayer.ideos.PrimaryIdeo); + } + else + { + var newIdeo = GenerateIdeo(chooseIdeoInfo); + faction.ideos.SetPrimary(newIdeo); + Find.IdeoManager.Add(newIdeo); + } foreach (Faction other in Find.FactionManager.AllFactionsListForReading) faction.TryMakeInitialRelationsWith(other); Find.FactionManager.Add(faction); - Multiplayer.WorldComp.factionData[faction.loadID] = - FactionWorldData.New(faction.loadID); + var newWorldFactionData = FactionWorldData.New(faction.loadID); + Multiplayer.WorldComp.factionData[faction.loadID] = newWorldFactionData; + newWorldFactionData.ReassignIds(); } faction.Name = name; @@ -165,4 +185,19 @@ private static Faction NewFaction(int id, string name, FactionDef def) return faction; } + + private static Ideo GenerateIdeo(ChooseIdeoInfo chooseIdeoInfo) + { + List list = chooseIdeoInfo.SelectedIdeo.memes.ToList(); + + if (chooseIdeoInfo.SelectedStructure != null) + list.Add(chooseIdeoInfo.SelectedStructure); + else if (DefDatabase.AllDefsListForReading.Where(m => m.category == MemeCategory.Structure && IdeoUtility.IsMemeAllowedFor(m, Find.Scenario.playerFaction.factionDef)).TryRandomElement(out var result)) + list.Add(result); + + Ideo ideo = IdeoGenerator.GenerateIdeo(new IdeoGenerationParms(Find.FactionManager.OfPlayer.def, forceNoExpansionIdeo: false, null, null, list, chooseIdeoInfo.SelectedIdeo.classicPlus, forceNoWeaponPreference: true)); + new Page_ChooseIdeoPreset { selectedStyles = chooseIdeoInfo.SelectedStyles }.ApplySelectedStylesToIdeo(ideo); + + return ideo; + } } diff --git a/Source/Client/Factions/FactionSidebar.cs b/Source/Client/Factions/FactionSidebar.cs index 233e195c..60b68ba3 100644 --- a/Source/Client/Factions/FactionSidebar.cs +++ b/Source/Client/Factions/FactionSidebar.cs @@ -1,5 +1,7 @@ -using System.Linq; +using System.Collections.Generic; +using System.Linq; using System.Text; +using Multiplayer.Client.Experimental; using Multiplayer.Client.Factions; using Multiplayer.Client.Util; using Multiplayer.Common; @@ -66,10 +68,28 @@ private static void DrawFactionCreator() { PreparePawns(); - Find.WindowStack.Add(new Page_ConfigureStartingPawns + var pages = new List(); + Page_ChooseIdeo_Multifaction chooseIdeoPage = null; + + if (ModsConfig.IdeologyActive && !Find.IdeoManager.classicMode) + pages.Add(chooseIdeoPage = new Page_ChooseIdeo_Multifaction()); + + pages.Add(new Page_ConfigureStartingPawns { - nextAct = DoCreateFaction + nextAct = () => + { + DoCreateFaction( + new ChooseIdeoInfo( + chooseIdeoPage?.pageChooseIdeo.selectedIdeo, + chooseIdeoPage?.pageChooseIdeo.selectedStructure, + chooseIdeoPage?.pageChooseIdeo.selectedStyles + ) + ); + } }); + + var page = PageUtility.StitchedPages(pages); + Find.WindowStack.Add(page); } } } @@ -81,7 +101,7 @@ private static void PreparePawns() try { - FactionCreator.SetInitialInitData(); + FactionCreator.SetGameInitData(); // Create starting pawns new ScenPart_ConfigPage_ConfigureStartingPawns { pawnCount = Current.Game.InitData.startingPawnCount } @@ -93,7 +113,7 @@ private static void PreparePawns() } } - private static void DoCreateFaction() + private static void DoCreateFaction(ChooseIdeoInfo chooseIdeoInfo) { int sessionId = Multiplayer.session.playerId; var prevState = Current.programStateInt; @@ -107,8 +127,14 @@ private static void DoCreateFaction() p ); - FactionCreator.CreateFaction(sessionId, factionName, Find.WorldInterface.SelectedTile, - scenario, hostility); + FactionCreator.CreateFaction( + sessionId, + factionName, + Find.WorldInterface.SelectedTile, + scenario, + hostility, + chooseIdeoInfo + ); } finally { @@ -172,3 +198,9 @@ public static bool Button(string text, float width, float height = 35f) return Widgets.ButtonText(Layouter.Rect(width, height), text); } } + +public record ChooseIdeoInfo( + IdeoPresetDef SelectedIdeo, + MemeDef SelectedStructure, + List SelectedStyles +) : ISyncSimple; diff --git a/Source/Client/Factions/MultifactionPatches.cs b/Source/Client/Factions/MultifactionPatches.cs index a720d66b..33db739b 100644 --- a/Source/Client/Factions/MultifactionPatches.cs +++ b/Source/Client/Factions/MultifactionPatches.cs @@ -29,11 +29,14 @@ static IEnumerable Postfix(IEnumerable gizmos, Pawn __instance) foreach (var gizmo in gizmos) yield return gizmo; - if (__instance.Faction is { IsPlayer: true } && __instance.Faction != Faction.OfPlayer) + if (Multiplayer.Client == null || Multiplayer.RealPlayerFaction == Multiplayer.WorldComp.spectatorFaction) + yield break; + + if (__instance.Faction is { IsPlayer: true } &&__instance.Faction != Faction.OfPlayer) { var otherFaction = __instance.Faction; - yield return new Command_Action() + yield return new Command_Action { defaultLabel = "Change faction relation", icon = MultiplayerStatic.ChangeRelationIcon, diff --git a/Source/Client/Factions/Page_ChooseIdeo_Multifaction.cs b/Source/Client/Factions/Page_ChooseIdeo_Multifaction.cs new file mode 100644 index 00000000..aebfea52 --- /dev/null +++ b/Source/Client/Factions/Page_ChooseIdeo_Multifaction.cs @@ -0,0 +1,49 @@ +using System.Linq; +using RimWorld; +using UnityEngine; +using Verse; + +namespace Multiplayer.Client.Factions; + +public class Page_ChooseIdeo_Multifaction : Page +{ + public override string PageTitle => "ChooseYourIdeoligion".Translate(); + + public Page_ChooseIdeoPreset pageChooseIdeo = new(); + + public override void DoWindowContents(Rect inRect) + { + DrawPageTitle(inRect); + float totalHeight = 0f; + Rect mainRect = GetMainRect(inRect); + TaggedString descText = "ChooseYourIdeoligionDesc".Translate(); + float descHeight = Text.CalcHeight(descText, mainRect.width); + Rect descRect = mainRect; + descRect.yMin += totalHeight; + Widgets.Label(descRect, descText); + totalHeight += descHeight + 10f; + + pageChooseIdeo.DrawStructureAndStyleSelection(inRect); + + Rect outRect = mainRect; + outRect.width = 954f; + outRect.yMin += totalHeight; + float num3 = (InitialSize.x - 937f) / 2f; + + Widgets.BeginScrollView( + viewRect: new Rect(0f - num3, 0f, 921f, pageChooseIdeo.totalCategoryListHeight + 100f), + outRect: outRect, + scrollPosition: ref pageChooseIdeo.leftScrollPosition); + + totalHeight = 0f; + pageChooseIdeo.lastCategoryGroupLabel = ""; + foreach (IdeoPresetCategoryDef item in DefDatabase.AllDefsListForReading.Where(c => c != IdeoPresetCategoryDefOf.Classic && c != IdeoPresetCategoryDefOf.Custom && c != IdeoPresetCategoryDefOf.Fluid)) + { + pageChooseIdeo.DrawCategory(item, ref totalHeight); + } + pageChooseIdeo.totalCategoryListHeight = totalHeight; + Widgets.EndScrollView(); + + DoBottomButtons(inRect); + } +} diff --git a/Source/Client/Factions/SidebarPatch.cs b/Source/Client/Factions/SidebarPatch.cs index ff2e48f7..c551a36f 100644 --- a/Source/Client/Factions/SidebarPatch.cs +++ b/Source/Client/Factions/SidebarPatch.cs @@ -10,15 +10,16 @@ static class UIRootPrefix { static void Postfix() { - // if (Multiplayer.Client != null && Multiplayer.RealPlayerFaction != null && Find.FactionManager != null) - // Find.FactionManager.ofPlayer = Multiplayer.RealPlayerFaction; + if (Multiplayer.Client != null && Multiplayer.RealPlayerFaction != null && Find.FactionManager != null) + Find.FactionManager.ofPlayer = Multiplayer.RealPlayerFaction; Layouter.BeginFrame(); if (Multiplayer.Client != null && Multiplayer.RealPlayerFaction == Multiplayer.WorldComp.spectatorFaction && !TickPatch.Simulating && - Find.WindowStack.WindowOfType() == null + !Multiplayer.IsReplay && + Find.WindowStack.WindowOfType() == null ) Find.WindowStack.ImmediateWindow( "MpWindowFaction".GetHashCode(), diff --git a/Source/Client/Networking/HostUtil.cs b/Source/Client/Networking/HostUtil.cs index 308b6287..917688af 100644 --- a/Source/Client/Networking/HostUtil.cs +++ b/Source/Client/Networking/HostUtil.cs @@ -138,20 +138,11 @@ private static void SetupGameFromSingleplayer() spectator.hidden = true; spectator.SetRelation(new FactionRelation(Faction.OfPlayer, FactionRelationKind.Neutral)); + worldComp.factionData[spectator.loadID] = FactionWorldData.New(spectator.loadID); worldComp.spectatorFaction = spectator; - // todo is this needed? - // foreach (FactionWorldData data in worldComp.factionData.Values) - // { - // foreach (DrugPolicy p in data.drugPolicyDatabase.policies) - // p.uniqueId = Multiplayer.GlobalIdBlock.NextId(); - // - // foreach (Outfit o in data.outfitDatabase.outfits) - // o.uniqueId = Multiplayer.GlobalIdBlock.NextId(); - // - // foreach (FoodRestriction o in data.foodRestrictionDatabase.foodRestrictions) - // o.id = Multiplayer.GlobalIdBlock.NextId(); - // } + foreach (FactionWorldData data in worldComp.factionData.Values) + data.ReassignIds(); foreach (Map map in Find.Maps) { @@ -177,7 +168,6 @@ public static Faction AddNewFaction(string name, FactionDef def) faction.def = def; Find.FactionManager.Add(faction); - Multiplayer.WorldComp.factionData[faction.loadID] = FactionWorldData.New(faction.loadID); return faction; } diff --git a/Source/Client/Networking/State/ClientPlayingState.cs b/Source/Client/Networking/State/ClientPlayingState.cs index e10f6e27..b1e031fc 100644 --- a/Source/Client/Networking/State/ClientPlayingState.cs +++ b/Source/Client/Networking/State/ClientPlayingState.cs @@ -263,7 +263,10 @@ public void HandleSetFaction(ByteReader data) Session.GetPlayerInfo(player).factionId = factionId; if (Session.playerId == player) + { Multiplayer.game.ChangeRealPlayerFaction(factionId); + Session.myFactionId = factionId; + } } } diff --git a/Source/Client/Patches/UniqueIds.cs b/Source/Client/Patches/UniqueIds.cs index d8055a3e..6c52c939 100644 --- a/Source/Client/Patches/UniqueIds.cs +++ b/Source/Client/Patches/UniqueIds.cs @@ -43,6 +43,36 @@ static IEnumerable TargetMethods() static bool Prefix() => Scribe.mode != LoadSaveMode.LoadingVars; } + [HarmonyPatch(typeof(OutfitDatabase), nameof(OutfitDatabase.MakeNewOutfit))] + static class OutfitUniqueIdPatch + { + static void Postfix(Outfit __result) + { + if (Multiplayer.Ticking || Multiplayer.ExecutingCmds) + __result.uniqueId = Find.UniqueIDsManager.GetNextThingID(); + } + } + + [HarmonyPatch(typeof(DrugPolicyDatabase), nameof(DrugPolicyDatabase.MakeNewDrugPolicy))] + static class DrugPolicyUniqueIdPatch + { + static void Postfix(DrugPolicy __result) + { + if (Multiplayer.Ticking || Multiplayer.ExecutingCmds) + __result.uniqueId = Find.UniqueIDsManager.GetNextThingID(); + } + } + + [HarmonyPatch(typeof(FoodRestrictionDatabase), nameof(FoodRestrictionDatabase.MakeNewFoodRestriction))] + static class FoodRestrictionUniqueIdPatch + { + static void Postfix(FoodRestriction __result) + { + if (Multiplayer.Ticking || Multiplayer.ExecutingCmds) + __result.id = Find.UniqueIDsManager.GetNextThingID(); + } + } + [HarmonyPatch] static class MessagesMarker { diff --git a/Source/Client/Saving/ConvertToSp.cs b/Source/Client/Saving/ConvertToSp.cs index 63e8ff6b..76bebe9c 100644 --- a/Source/Client/Saving/ConvertToSp.cs +++ b/Source/Client/Saving/ConvertToSp.cs @@ -25,6 +25,14 @@ private static void SaveReplay() private static void PrepareSingleplayer() { Find.GameInfo.permadeathMode = false; + + // Remove spectator faction + var spectator = Multiplayer.WorldComp.spectatorFaction; + if (spectator != null) + { + spectator.RemoveAllRelations(); + Find.FactionManager.allFactions.Remove(spectator); + } } private static void PrepareLoading() diff --git a/Source/Client/UI/IngameDebug.cs b/Source/Client/UI/IngameDebug.cs index 7454be25..fa8f3a5c 100644 --- a/Source/Client/UI/IngameDebug.cs +++ b/Source/Client/UI/IngameDebug.cs @@ -3,6 +3,7 @@ using HarmonyLib; using Multiplayer.Client.Desyncs; using Multiplayer.Client.Util; +using Multiplayer.Common; using RimWorld; using UnityEngine; using Verse; @@ -14,10 +15,6 @@ public static class IngameDebug private static double avgDelta; private static double avgTickTime; - public static float tps; - private static float lastTicksAt; - private static int lastTicks; - private const float BtnMargin = 8f; private const float BtnHeight = 27f; private const float BtnWidth = 80f; @@ -51,7 +48,7 @@ internal static void DoDebugPrintout() var async = Find.CurrentMap.AsyncTime(); StringBuilder text = new StringBuilder(); text.Append( - $"{Multiplayer.game.sync.knownClientOpinions.Count} {Multiplayer.game.sync.knownClientOpinions.FirstOrDefault()?.startTick} {async.mapTicks} {TickPatch.serverFrozen} {TickPatch.frozenAt} "); + $"{Find.IdeoManager.classicMode} {Multiplayer.game.sync.knownClientOpinions.Count} {Multiplayer.game.sync.knownClientOpinions.FirstOrDefault()?.startTick} {async.mapTicks} {TickPatch.serverFrozen} {TickPatch.frozenAt} "); text.Append( $"z: {Find.CurrentMap.haulDestinationManager.AllHaulDestinationsListForReading.Count()} d: {Find.CurrentMap.designationManager.designationsByDef.Count} hc: {Find.CurrentMap.listerHaulables.ThingsPotentiallyNeedingHauling().Count}"); @@ -88,7 +85,7 @@ internal static void DoDebugPrintout() : $"\n{Find.WindowStack.focusedWindow}"); text.Append($"\n{UI.CurUICellSize()} {Find.WindowStack.windows.ToStringSafeEnumerable()}"); - text.Append($"\n\nMap TPS: {tps:0.00}"); + text.Append($"\n\nMap TPS: {IngameUIPatch.tps:0.00}"); text.Append($"\nDelta: {Time.deltaTime * 1000f}"); text.Append($"\nAverage ft: {TickPatch.avgFrameTime}"); text.Append($"\nServer tpt: {TickPatch.serverTimePerTick}"); @@ -100,13 +97,6 @@ internal static void DoDebugPrintout() Rect rect1 = new Rect(80f, 170f, 330f, Text.CalcHeight(text.ToString(), 330f)); Widgets.Label(rect1, text.ToString()); - - if (Time.time - lastTicksAt > 0.5f) - { - tps = (tps + (async.mapTicks - lastTicks) * 2f) / 2f; - lastTicks = async.mapTicks; - lastTicksAt = Time.time; - } } //if (Event.current.type == EventType.Repaint) @@ -159,7 +149,8 @@ internal static float DoTimeDiffLabel(float y) { float x = UI.screenWidth - BtnWidth - BtnMargin; - if (Multiplayer.Client != null && + if (MpVersion.IsDebug && + Multiplayer.Client != null && !Multiplayer.GameComp.asyncTime && Find.CurrentMap.AsyncTime() != null && Find.CurrentMap.AsyncTime().mapTicks != Multiplayer.AsyncWorldTime.worldTicks) diff --git a/Source/Client/UI/IngameUI.cs b/Source/Client/UI/IngameUI.cs index 84d0563c..d936c74c 100644 --- a/Source/Client/UI/IngameUI.cs +++ b/Source/Client/UI/IngameUI.cs @@ -24,6 +24,11 @@ public static class IngameUIPatch private const float BtnHeight = 27f; private const float BtnWidth = 80f; + public static float tps; + private static float lastTicksAt; + private static int lastTicks; + private static int lastTicksMapId; + static bool Prefix() { Text.Font = GameFont.Small; @@ -32,6 +37,22 @@ static bool Prefix() IngameDebug.DoDebugPrintout(); } + if (Multiplayer.Client != null && Find.CurrentMap != null && Time.time - lastTicksAt > 0.5f) + { + var async = Find.CurrentMap.AsyncTime(); + + if (lastTicksMapId != Find.CurrentMap.uniqueID) + { + lastTicksMapId = Find.CurrentMap.uniqueID; + lastTicks = async.mapTicks; + tps = 0; + } + + tps = (tps + (async.mapTicks - lastTicks) * 2f) / 2f; + lastTicks = async.mapTicks; + lastTicksAt = Time.time; + } + if (Multiplayer.IsReplay && Multiplayer.session.showTimeline || TickPatch.Simulating) ReplayTimeline.DrawTimeline(); @@ -145,7 +166,7 @@ private static void IndicatorInfo(out Color color, out string text, out bool slo } if (!WorldRendererUtility.WorldRenderedNow) - text += $"\n\nCurrent map avg TPS: {IngameDebug.tps:0.00}"; + text += $"\n\nCurrent map avg TPS: {tps:0.00}"; } private static void HandleUiEventsWhenSimulating() diff --git a/Source/Client/UI/MainMenuPatches.cs b/Source/Client/UI/MainMenuPatches.cs index e37838bf..a58cceb5 100644 --- a/Source/Client/UI/MainMenuPatches.cs +++ b/Source/Client/UI/MainMenuPatches.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; +using Multiplayer.Client.Factions; using Multiplayer.Client.Saving; using UnityEngine; using Verse; @@ -113,7 +114,7 @@ static void Prefix(Rect rect, List optList) static void ShowModDebugInfo() { - Find.WindowStack.Add(new DisconnectedWindow(new SessionDisconnectInfo() { specialButtonTranslated = "Special btn"})); + Find.WindowStack.Add(new Page_ChooseIdeo_Multifaction()); return; var info = new RemoteData();