From 00896d065ece73064caa43b8153d477b9965dbab Mon Sep 17 00:00:00 2001 From: SirWilliam <93367389+SirrWilliam@users.noreply.github.com> Date: Fri, 18 Jul 2025 22:29:29 +0300 Subject: [PATCH 1/8] Prepatcher Warning (WIP) --- Source/Client/UI/IngameUI.cs | 68 ++++++++++++++- Source/Client/UI/PrepatcherWarning.cs | 116 ++++++++++++++++++++++++++ 2 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 Source/Client/UI/PrepatcherWarning.cs diff --git a/Source/Client/UI/IngameUI.cs b/Source/Client/UI/IngameUI.cs index 18c70520..34d11df0 100644 --- a/Source/Client/UI/IngameUI.cs +++ b/Source/Client/UI/IngameUI.cs @@ -1,11 +1,12 @@ using HarmonyLib; using Multiplayer.Common; using RimWorld; +using RimWorld.Planet; using System; using System.Collections.Generic; +using System.Linq; using UnityEngine; using Verse; -using RimWorld.Planet; namespace Multiplayer.Client { @@ -178,4 +179,69 @@ private static void HandleUiEventsWhenSimulating() } } } + + //Prepatcher Warning server browser + [HarmonyPatch(typeof(UIRoot_Entry), nameof(UIRoot_Entry.UIRootOnGUI))] + static class UIRootEntryPrefix + { + static void Postfix() + { + if (Find.WindowStack.WindowOfType() != null) + { + ServerBrowser serverBrowserWindow = Find.WindowStack.Windows + .FirstOrDefault(w => w.GetType().Name == typeof(ServerBrowser).Name) as ServerBrowser; + + if (serverBrowserWindow == null) + return; + + Rect baseRect = serverBrowserWindow.windowRect; + + float boxWidth = 310f; + float boxHeight = 88f; + float spacing = 5f; + + Rect hintRect = new Rect( + baseRect.xMax + spacing, + baseRect.y, + boxWidth, + boxHeight + ); + + PrepatcherWarning.DoPrepatcherWarning(hintRect); + } + + } + } + + //Prepatcher Warning in-game + [HarmonyPatch(typeof(UIRoot_Play), nameof(UIRoot_Play.UIRootOnGUI))] + static class UIRootPlayPrefix + { + static void Postfix() + { + if (Find.WindowStack.WindowOfType() != null) + { + HostWindow hostWindowWindow = Find.WindowStack.Windows + .FirstOrDefault(w => w.GetType().Name == typeof(HostWindow).Name) as HostWindow; + + if (hostWindowWindow == null) + return; + + Rect baseRect = hostWindowWindow.windowRect; + + float boxWidth = 310f; + float boxHeight = 88f; + float spacing = 5f; + + Rect hintRect = new Rect( + baseRect.xMax + spacing, + baseRect.y, + boxWidth, + boxHeight + ); + + PrepatcherWarning.DoPrepatcherWarning(hintRect); + } + } + } } diff --git a/Source/Client/UI/PrepatcherWarning.cs b/Source/Client/UI/PrepatcherWarning.cs new file mode 100644 index 00000000..047302cf --- /dev/null +++ b/Source/Client/UI/PrepatcherWarning.cs @@ -0,0 +1,116 @@ +using Multiplayer.Client.Factions; +using Multiplayer.Client.Util; +using Multiplayer.Common; +using RimWorld; +using RimWorld.Planet; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using UnityEngine; +using Verse; +using Verse.Sound; +using Verse.Steam; + +namespace Multiplayer.Client +{ + public static class PrepatcherWarning + { + + public static void DoPrepatcherWarning(Rect inRect) + { + GUI.BeginGroup(new Rect(inRect.x, inRect.y, inRect.width, inRect.height)); + { + Rect groupRect = new Rect(0, 0, inRect.width, inRect.height); + DrawWarning(groupRect); + } + GUI.EndGroup(); + } + private static void DrawWarning(Rect inRect) + { + Widgets.DrawMenuSection(inRect); + MouseoverSounds.DoRegion(inRect); + + if (SteamManager.Initialized) + TooltipHandler.TipRegion(inRect, "Open Prepatcher mod on Steam Workshop."); + else + TooltipHandler.TipRegion(inRect, "Open Prepatcher mod on browser."); + + if (Mouse.IsOver(inRect)) + Widgets.DrawHighlight(inRect); + + if (Mouse.IsOver(inRect) && Input.GetMouseButtonDown(0)) + { + SoundDefOf.TabOpen.PlayOneShotOnCamera(); + if (SteamManager.Initialized) + { + SteamUtility.OpenWorkshopPage(new Steamworks.PublishedFileId_t(2934420800)); + } + else + { + Application.OpenURL("https://steamcommunity.com/sharedfiles/filedetails/?id=2934420800"); + } + } + + DrawAnimatedBorder(inRect, 2f, new ColorInt(218, 166, 26).ToColor); + // Create Faction Headline + inRect.yMin += 5f; + using (MpStyle.Set(GameFont.Small)) + using (MpStyle.Set(WordWrap.NoWrap)) + Widgets.Label(inRect.Right(8f), "PREPATCHER NOT FOUND"); + inRect.yMin += 20f; + // END Create Faction Headline + + // Line + float lineX = inRect.x + 8f; + float lineY = inRect.yMin; + float lineWidth = inRect.width - 16f; //16*2 Header + Widgets.DrawLineHorizontal(lineX, lineY, lineWidth); + inRect.yMin += 5f; + // END Line + + // Description text + string warningText = + "Rituals will not work properly in multiplayer without the Prepatcher mod. " + + "Please install and enable it to avoid desync issues."; + using (MpStyle.Set(WordWrap.DoWrap)) + { + Rect textRect = new Rect(inRect.x + 8f, inRect.yMin, inRect.width - 16f, Text.CalcHeight(warningText, inRect.width - 16f)); + Widgets.Label(textRect, warningText); + } + + + } + + private static void DrawAnimatedBorder(Rect inRect, float borderWidth, Color baseColor, float pulseSpeed = 1f) + { + Color prevColor = GUI.color; + + float pulse = Mathf.PingPong(Time.realtimeSinceStartup * pulseSpeed, 1f); + Color animatedColor = Color.Lerp(baseColor, Color.white, pulse); + + GUI.color = animatedColor; + + GUI.DrawTexture(new Rect(inRect.x, inRect.y, inRect.width, borderWidth), BaseContent.WhiteTex); // Up + GUI.DrawTexture(new Rect(inRect.x, inRect.yMax - borderWidth, inRect.width, borderWidth), BaseContent.WhiteTex); // Down + GUI.DrawTexture(new Rect(inRect.x, inRect.y, borderWidth, inRect.height), BaseContent.WhiteTex); // Left + GUI.DrawTexture(new Rect(inRect.xMax - borderWidth, inRect.y, borderWidth, inRect.height), BaseContent.WhiteTex); // Right + + GUI.color = prevColor; + } + + private static void DrawBorder(Rect inRect, float borderWidth, Color color) + { + Color prevColor = GUI.color; + + GUI.color = color; + + GUI.DrawTexture(new Rect(inRect.x, inRect.y, inRect.width, borderWidth), BaseContent.WhiteTex); // Up + GUI.DrawTexture(new Rect(inRect.x, inRect.yMax - borderWidth, inRect.width, borderWidth), BaseContent.WhiteTex); // Down + GUI.DrawTexture(new Rect(inRect.x, inRect.y, borderWidth, inRect.height), BaseContent.WhiteTex); // Left + GUI.DrawTexture(new Rect(inRect.xMax - borderWidth, inRect.y, borderWidth, inRect.height), BaseContent.WhiteTex); // Right + + GUI.color = prevColor; + } + } +} From 6611d21c59ca6cf50d03b6da32168071350c6cd0 Mon Sep 17 00:00:00 2001 From: SirWilliam <93367389+SirrWilliam@users.noreply.github.com> Date: Sat, 19 Jul 2025 19:18:27 +0300 Subject: [PATCH 2/8] Prepatcher warning Update --- Source/Client/UI/IngameUI.cs | 23 +--- Source/Client/UI/PrepatcherWarning.cs | 153 ++++++++++++++++++-------- Source/Client/Util/Extensions.cs | 11 ++ 3 files changed, 123 insertions(+), 64 deletions(-) diff --git a/Source/Client/UI/IngameUI.cs b/Source/Client/UI/IngameUI.cs index 34d11df0..c37fe2e1 100644 --- a/Source/Client/UI/IngameUI.cs +++ b/Source/Client/UI/IngameUI.cs @@ -196,20 +196,14 @@ static void Postfix() Rect baseRect = serverBrowserWindow.windowRect; - float boxWidth = 310f; - float boxHeight = 88f; float spacing = 5f; + float boxWidth = 310f; + float boxHeight = Text.CalcHeight("MpPrepatcherWarnNotFoundDescription".Translate().RemoveRichTextTags(), boxWidth - 16f); - Rect hintRect = new Rect( - baseRect.xMax + spacing, - baseRect.y, - boxWidth, - boxHeight - ); + Rect hintRect = new Rect(baseRect.xMax + spacing, baseRect.y, boxWidth, boxHeight + 35f); PrepatcherWarning.DoPrepatcherWarning(hintRect); } - } } @@ -229,16 +223,11 @@ static void Postfix() Rect baseRect = hostWindowWindow.windowRect; - float boxWidth = 310f; - float boxHeight = 88f; float spacing = 5f; + float boxWidth = 310f; + float boxHeight = Text.CalcHeight("MpPrepatcherWarnNotFoundDescription".Translate().RemoveRichTextTags(), boxWidth - 16f); - Rect hintRect = new Rect( - baseRect.xMax + spacing, - baseRect.y, - boxWidth, - boxHeight - ); + Rect hintRect = new Rect(baseRect.xMax + spacing, baseRect.y, boxWidth, boxHeight + 35f); PrepatcherWarning.DoPrepatcherWarning(hintRect); } diff --git a/Source/Client/UI/PrepatcherWarning.cs b/Source/Client/UI/PrepatcherWarning.cs index 047302cf..64fda94d 100644 --- a/Source/Client/UI/PrepatcherWarning.cs +++ b/Source/Client/UI/PrepatcherWarning.cs @@ -1,22 +1,22 @@ -using Multiplayer.Client.Factions; -using Multiplayer.Client.Util; -using Multiplayer.Common; -using RimWorld; -using RimWorld.Planet; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; using UnityEngine; +using RimWorld; +using Steamworks; using Verse; using Verse.Sound; using Verse.Steam; +using Multiplayer.Client.Util; namespace Multiplayer.Client { public static class PrepatcherWarning { - + private static readonly string prepatcherPackageId = "zetrith.prepatcher"; + private static readonly PublishedFileId_t prepatcherFileId = new PublishedFileId_t(2934420800); + private static ModMetaData prepatcherMetaData; + public static PrepatcherStatus prepatcherStatus = PrepatcherStatus.Unknown; + + private const float Spacing = 8f; + public static void DoPrepatcherWarning(Rect inRect) { GUI.BeginGroup(new Rect(inRect.x, inRect.y, inRect.width, inRect.height)); @@ -26,60 +26,97 @@ public static void DoPrepatcherWarning(Rect inRect) } GUI.EndGroup(); } + private static void DrawWarning(Rect inRect) { + if (prepatcherStatus == PrepatcherStatus.Unknown) + CheckPrepatcherStatus(); + + // Background Widgets.DrawMenuSection(inRect); + DrawAnimatedBorder(inRect, 2f, new ColorInt(218, 166, 26).ToColor); MouseoverSounds.DoRegion(inRect); - if (SteamManager.Initialized) - TooltipHandler.TipRegion(inRect, "Open Prepatcher mod on Steam Workshop."); - else - TooltipHandler.TipRegion(inRect, "Open Prepatcher mod on browser."); - if (Mouse.IsOver(inRect)) Widgets.DrawHighlight(inRect); + // END Background - if (Mouse.IsOver(inRect) && Input.GetMouseButtonDown(0)) + //Headline + inRect.yMin += 5f; + using (MpStyle.Set(GameFont.Small)) + using (MpStyle.Set(WordWrap.NoWrap)) { - SoundDefOf.TabOpen.PlayOneShotOnCamera(); - if (SteamManager.Initialized) + switch (prepatcherStatus) { - SteamUtility.OpenWorkshopPage(new Steamworks.PublishedFileId_t(2934420800)); - } - else - { - Application.OpenURL("https://steamcommunity.com/sharedfiles/filedetails/?id=2934420800"); + case PrepatcherStatus.NotFound: + Widgets.Label(inRect.Right(Spacing), "MpPrepatcherWarnNotFoundHeadline".Translate()); + break; + case PrepatcherStatus.NotActive: + Widgets.Label(inRect.Right(Spacing), "MpPrepatcherWarnDisabledHeadline".Translate()); + break; } } - - DrawAnimatedBorder(inRect, 2f, new ColorInt(218, 166, 26).ToColor); - // Create Faction Headline - inRect.yMin += 5f; - using (MpStyle.Set(GameFont.Small)) - using (MpStyle.Set(WordWrap.NoWrap)) - Widgets.Label(inRect.Right(8f), "PREPATCHER NOT FOUND"); inRect.yMin += 20f; - // END Create Faction Headline + //END Headline // Line - float lineX = inRect.x + 8f; + float lineX = inRect.x + Spacing; float lineY = inRect.yMin; - float lineWidth = inRect.width - 16f; //16*2 Header + float lineWidth = inRect.width - (Spacing * 2); //Cut both sides Widgets.DrawLineHorizontal(lineX, lineY, lineWidth); inRect.yMin += 5f; // END Line - // Description text - string warningText = - "Rituals will not work properly in multiplayer without the Prepatcher mod. " + - "Please install and enable it to avoid desync issues."; + // Description using (MpStyle.Set(WordWrap.DoWrap)) { - Rect textRect = new Rect(inRect.x + 8f, inRect.yMin, inRect.width - 16f, Text.CalcHeight(warningText, inRect.width - 16f)); - Widgets.Label(textRect, warningText); + Rect textRect; + switch (prepatcherStatus) + { + case PrepatcherStatus.NotFound: + textRect = new Rect(inRect.x + Spacing, inRect.yMin, inRect.width - (Spacing * 2), Text.CalcHeight("MpPrepatcherWarnNotFoundDescription".Translate().RemoveRichTextTags(), inRect.width - (Spacing * 2))); + Widgets.Label(textRect, "MpPrepatcherWarnNotFoundDescription".Translate()); + break; + case PrepatcherStatus.NotActive: + textRect = new Rect(inRect.x + Spacing, inRect.yMin, inRect.width - (Spacing * 2), Text.CalcHeight("MpPrepatcherWarnDisabledDescription".Translate().RemoveRichTextTags(), inRect.width - (Spacing * 2))); + Widgets.Label(textRect, "MpPrepatcherWarnDisabledDescription".Translate()); + break; + } + } + // END Description + // Tooltip + if (prepatcherStatus == PrepatcherStatus.NotFound) + { + if (SteamManager.Initialized) + TooltipHandler.TipRegion(inRect, "MpPrepatcherWarnOpenSteamWorkshop".Translate()); + else + TooltipHandler.TipRegion(inRect, "MpPrepatcherWarnOpenBrowser".Translate()); + if (Mouse.IsOver(inRect) && Input.GetMouseButtonDown(0)) + { + SoundDefOf.TabOpen.PlayOneShotOnCamera(); + if (SteamManager.Initialized) + SteamUtility.OpenWorkshopPage(prepatcherFileId); + else + Application.OpenURL("https://steamcommunity.com/sharedfiles/filedetails/?id=2934420800"); + } + } + else + { + //We don't want the game to restart without saving by accident. + if (Current.Game == null) + { + TooltipHandler.TipRegion(inRect, "MpPrepatcherWarnEnableRestart".Translate()); + if (Mouse.IsOver(inRect) && Input.GetMouseButtonDown(0)) + { + SoundDefOf.TabOpen.PlayOneShotOnCamera(); + DoRestart(); + } + } + } + // END Tooltip } private static void DrawAnimatedBorder(Rect inRect, float borderWidth, Color baseColor, float pulseSpeed = 1f) @@ -99,18 +136,40 @@ private static void DrawAnimatedBorder(Rect inRect, float borderWidth, Color bas GUI.color = prevColor; } - private static void DrawBorder(Rect inRect, float borderWidth, Color color) + public static void CheckPrepatcherStatus() { - Color prevColor = GUI.color; + prepatcherMetaData = ModLister.GetModWithIdentifier(prepatcherPackageId); + + if (prepatcherMetaData == null) + { + prepatcherStatus = PrepatcherStatus.NotFound; + return; + } - GUI.color = color; + prepatcherStatus = prepatcherMetaData.Active + ? PrepatcherStatus.Active + : PrepatcherStatus.NotActive; + } - GUI.DrawTexture(new Rect(inRect.x, inRect.y, inRect.width, borderWidth), BaseContent.WhiteTex); // Up - GUI.DrawTexture(new Rect(inRect.x, inRect.yMax - borderWidth, inRect.width, borderWidth), BaseContent.WhiteTex); // Down - GUI.DrawTexture(new Rect(inRect.x, inRect.y, borderWidth, inRect.height), BaseContent.WhiteTex); // Left - GUI.DrawTexture(new Rect(inRect.xMax - borderWidth, inRect.y, borderWidth, inRect.height), BaseContent.WhiteTex); // Right + private static void DoRestart() + { + if (prepatcherMetaData != null) + { + ModsConfig.SetActive(prepatcherMetaData.PackageId, true); + ModsConfig.RestartFromChangedMods(); + } + else { + Messages.Message("MpPrepatcherWarnFail".Translate(), MessageTypeDefOf.NegativeEvent, false); + CheckPrepatcherStatus(); + } + } - GUI.color = prevColor; + public enum PrepatcherStatus + { + Unknown, + NotFound, + NotActive, + Active } } } diff --git a/Source/Client/Util/Extensions.cs b/Source/Client/Util/Extensions.cs index d44c6564..ac189b6e 100644 --- a/Source/Client/Util/Extensions.cs +++ b/Source/Client/Util/Extensions.cs @@ -22,6 +22,7 @@ namespace Multiplayer.Client public static class Extensions { private static Regex methodNameCleaner = new Regex(@"(\?[0-9\-]+)"); + private static readonly Regex richTextTagCleaner = new Regex("(<.*?>)", RegexOptions.Compiled); public static Map GetMap(this ScheduledCommand cmd) { @@ -271,6 +272,16 @@ public static string NormalizePath(this string path) return path.Replace('\\', '/'); } + public static string RemoveRichTextTags(this string str) + { + return richTextTagCleaner.Replace(str, "$1").Replace("", "noparse>"); + } + + public static string RemoveRichTextTags(this TaggedString str) + { + return richTextTagCleaner.Replace(str, "$1").Replace("", "noparse>"); + } + public static MethodInfo PatchMeasure(this Harmony harmony, MethodBase original, HarmonyMethod prefix = null, HarmonyMethod postfix = null, HarmonyMethod transpiler = null, HarmonyMethod finalizer = null) { var watch = Multiplayer.harmonyWatch; From 81b2caa18fb9fad0395ab5c40af0e65eb8839d89 Mon Sep 17 00:00:00 2001 From: SirWilliam <93367389+SirrWilliam@users.noreply.github.com> Date: Sat, 19 Jul 2025 19:42:51 +0300 Subject: [PATCH 3/8] Minor changes --- Languages | 2 +- Source/Client/UI/PrepatcherWarning.cs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Languages b/Languages index 0c38ba2e..1b1226b0 160000 --- a/Languages +++ b/Languages @@ -1 +1 @@ -Subproject commit 0c38ba2e075ab40f676d3658959765464985ceda +Subproject commit 1b1226b09e576f9e5a4b436717e8b689557c4a9f diff --git a/Source/Client/UI/PrepatcherWarning.cs b/Source/Client/UI/PrepatcherWarning.cs index 64fda94d..24c4f1d3 100644 --- a/Source/Client/UI/PrepatcherWarning.cs +++ b/Source/Client/UI/PrepatcherWarning.cs @@ -48,8 +48,8 @@ private static void DrawWarning(Rect inRect) { switch (prepatcherStatus) { - case PrepatcherStatus.NotFound: - Widgets.Label(inRect.Right(Spacing), "MpPrepatcherWarnNotFoundHeadline".Translate()); + case PrepatcherStatus.NotInstalled: + Widgets.Label(inRect.Right(Spacing), "MpPrepatcherWarnNotInstalledHeadline".Translate()); break; case PrepatcherStatus.NotActive: Widgets.Label(inRect.Right(Spacing), "MpPrepatcherWarnDisabledHeadline".Translate()); @@ -73,8 +73,8 @@ private static void DrawWarning(Rect inRect) Rect textRect; switch (prepatcherStatus) { - case PrepatcherStatus.NotFound: - textRect = new Rect(inRect.x + Spacing, inRect.yMin, inRect.width - (Spacing * 2), Text.CalcHeight("MpPrepatcherWarnNotFoundDescription".Translate().RemoveRichTextTags(), inRect.width - (Spacing * 2))); + case PrepatcherStatus.NotInstalled: + textRect = new Rect(inRect.x + Spacing, inRect.yMin, inRect.width - (Spacing * 2), Text.CalcHeight("MpPrepatcherWarnNotInstalledDescription".Translate().RemoveRichTextTags(), inRect.width - (Spacing * 2))); Widgets.Label(textRect, "MpPrepatcherWarnNotFoundDescription".Translate()); break; case PrepatcherStatus.NotActive: @@ -87,7 +87,7 @@ private static void DrawWarning(Rect inRect) // END Description // Tooltip - if (prepatcherStatus == PrepatcherStatus.NotFound) + if (prepatcherStatus == PrepatcherStatus.NotInstalled) { if (SteamManager.Initialized) TooltipHandler.TipRegion(inRect, "MpPrepatcherWarnOpenSteamWorkshop".Translate()); @@ -142,7 +142,7 @@ public static void CheckPrepatcherStatus() if (prepatcherMetaData == null) { - prepatcherStatus = PrepatcherStatus.NotFound; + prepatcherStatus = PrepatcherStatus.NotInstalled; return; } @@ -167,7 +167,7 @@ private static void DoRestart() public enum PrepatcherStatus { Unknown, - NotFound, + NotInstalled, NotActive, Active } From ce12c2e04315216ea405f102a53e1d11041882cd Mon Sep 17 00:00:00 2001 From: SirWilliam <93367389+SirrWilliam@users.noreply.github.com> Date: Sat, 19 Jul 2025 19:43:57 +0300 Subject: [PATCH 4/8] Fix --- Source/Client/UI/PrepatcherWarning.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Client/UI/PrepatcherWarning.cs b/Source/Client/UI/PrepatcherWarning.cs index 24c4f1d3..4c1dd6d2 100644 --- a/Source/Client/UI/PrepatcherWarning.cs +++ b/Source/Client/UI/PrepatcherWarning.cs @@ -75,7 +75,7 @@ private static void DrawWarning(Rect inRect) { case PrepatcherStatus.NotInstalled: textRect = new Rect(inRect.x + Spacing, inRect.yMin, inRect.width - (Spacing * 2), Text.CalcHeight("MpPrepatcherWarnNotInstalledDescription".Translate().RemoveRichTextTags(), inRect.width - (Spacing * 2))); - Widgets.Label(textRect, "MpPrepatcherWarnNotFoundDescription".Translate()); + Widgets.Label(textRect, "MpPrepatcherWarnNotInstalledDescription".Translate()); break; case PrepatcherStatus.NotActive: textRect = new Rect(inRect.x + Spacing, inRect.yMin, inRect.width - (Spacing * 2), Text.CalcHeight("MpPrepatcherWarnDisabledDescription".Translate().RemoveRichTextTags(), inRect.width - (Spacing * 2))); From d33a825627b25eff75dacf4a5e5759d233dcb086 Mon Sep 17 00:00:00 2001 From: SirWilliam <93367389+SirrWilliam@users.noreply.github.com> Date: Sat, 19 Jul 2025 22:39:42 +0300 Subject: [PATCH 5/8] changes --- Source/Client/UI/IngameUI.cs | 54 ---------------- Source/Client/UI/PrepatcherWarning.cs | 88 +++++++++++++++++++++++++-- 2 files changed, 83 insertions(+), 59 deletions(-) diff --git a/Source/Client/UI/IngameUI.cs b/Source/Client/UI/IngameUI.cs index c37fe2e1..a59bd77e 100644 --- a/Source/Client/UI/IngameUI.cs +++ b/Source/Client/UI/IngameUI.cs @@ -179,58 +179,4 @@ private static void HandleUiEventsWhenSimulating() } } } - - //Prepatcher Warning server browser - [HarmonyPatch(typeof(UIRoot_Entry), nameof(UIRoot_Entry.UIRootOnGUI))] - static class UIRootEntryPrefix - { - static void Postfix() - { - if (Find.WindowStack.WindowOfType() != null) - { - ServerBrowser serverBrowserWindow = Find.WindowStack.Windows - .FirstOrDefault(w => w.GetType().Name == typeof(ServerBrowser).Name) as ServerBrowser; - - if (serverBrowserWindow == null) - return; - - Rect baseRect = serverBrowserWindow.windowRect; - - float spacing = 5f; - float boxWidth = 310f; - float boxHeight = Text.CalcHeight("MpPrepatcherWarnNotFoundDescription".Translate().RemoveRichTextTags(), boxWidth - 16f); - - Rect hintRect = new Rect(baseRect.xMax + spacing, baseRect.y, boxWidth, boxHeight + 35f); - - PrepatcherWarning.DoPrepatcherWarning(hintRect); - } - } - } - - //Prepatcher Warning in-game - [HarmonyPatch(typeof(UIRoot_Play), nameof(UIRoot_Play.UIRootOnGUI))] - static class UIRootPlayPrefix - { - static void Postfix() - { - if (Find.WindowStack.WindowOfType() != null) - { - HostWindow hostWindowWindow = Find.WindowStack.Windows - .FirstOrDefault(w => w.GetType().Name == typeof(HostWindow).Name) as HostWindow; - - if (hostWindowWindow == null) - return; - - Rect baseRect = hostWindowWindow.windowRect; - - float spacing = 5f; - float boxWidth = 310f; - float boxHeight = Text.CalcHeight("MpPrepatcherWarnNotFoundDescription".Translate().RemoveRichTextTags(), boxWidth - 16f); - - Rect hintRect = new Rect(baseRect.xMax + spacing, baseRect.y, boxWidth, boxHeight + 35f); - - PrepatcherWarning.DoPrepatcherWarning(hintRect); - } - } - } } diff --git a/Source/Client/UI/PrepatcherWarning.cs b/Source/Client/UI/PrepatcherWarning.cs index 4c1dd6d2..9a536add 100644 --- a/Source/Client/UI/PrepatcherWarning.cs +++ b/Source/Client/UI/PrepatcherWarning.cs @@ -1,10 +1,13 @@ -using UnityEngine; +using HarmonyLib; +using Multiplayer.Client.Util; using RimWorld; using Steamworks; +using System.Linq; +using UnityEngine; using Verse; using Verse.Sound; using Verse.Steam; -using Multiplayer.Client.Util; +using static Multiplayer.Client.PrepatcherWarning; namespace Multiplayer.Client { @@ -29,9 +32,6 @@ public static void DoPrepatcherWarning(Rect inRect) private static void DrawWarning(Rect inRect) { - if (prepatcherStatus == PrepatcherStatus.Unknown) - CheckPrepatcherStatus(); - // Background Widgets.DrawMenuSection(inRect); DrawAnimatedBorder(inRect, 2f, new ColorInt(218, 166, 26).ToColor); @@ -172,4 +172,82 @@ public enum PrepatcherStatus Active } } + + //Prepatcher Warning server browser + [HarmonyPatch(typeof(UIRoot_Entry), nameof(UIRoot_Entry.UIRootOnGUI))] + static class PrepatcherWarningUIRootEntryPatch + { + static void Postfix() + { + if (Find.WindowStack.WindowOfType() != null) + { + ServerBrowser serverBrowserWindow = Find.WindowStack.Windows + .FirstOrDefault(w => w.GetType().Name == typeof(ServerBrowser).Name) as ServerBrowser; + + if (serverBrowserWindow == null) + return; + + //Check before boxWidth calc + if (PrepatcherStatus == PrepatcherStatus.Unknown) + CheckPrepatcherStatus(); + + Rect baseRect = serverBrowserWindow.windowRect; + + float spacing = 5f; + float boxWidth = 310f; + float boxHeight = 60f; + switch (prepatcherStatus) + { + case PrepatcherStatus.NotInstalled: + boxHeight = Text.CalcHeight("MpPrepatcherWarnNotInstalledDescription".Translate().RemoveRichTextTags(), boxWidth - 16f); + break; + case PrepatcherStatus.NotActive: + boxHeight = Text.CalcHeight("MpPrepatcherWarnDisabledDescription".Translate().RemoveRichTextTags(), boxWidth - 16f); + break; + } + + Rect hintRect = new Rect(baseRect.xMax + spacing, baseRect.y, boxWidth, boxHeight + 35f); + PrepatcherWarning.DoPrepatcherWarning(hintRect); + } + } + } + + //Prepatcher Warning in-game + [HarmonyPatch(typeof(UIRoot_Play), nameof(UIRoot_Play.UIRootOnGUI))] + static class PrepatcherWarningUIRootPlayPatch + { + static void Postfix() + { + if (Find.WindowStack.WindowOfType() != null) + { + HostWindow hostWindowWindow = Find.WindowStack.Windows + .FirstOrDefault(w => w.GetType().Name == typeof(HostWindow).Name) as HostWindow; + + if (hostWindowWindow == null) + return; + + //Check before boxWidth calc + if (prepatcherStatus == PrepatcherStatus.Unknown) + CheckPrepatcherStatus(); + + Rect baseRect = hostWindowWindow.windowRect; + + float spacing = 5f; + float boxWidth = 310f; + float boxHeight = 60f; + switch (prepatcherStatus) + { + case PrepatcherStatus.NotInstalled: + boxHeight = Text.CalcHeight("MpPrepatcherWarnNotInstalledDescription".Translate().RemoveRichTextTags(), boxWidth - 16f); + break; + case PrepatcherStatus.NotActive: + boxHeight = Text.CalcHeight("MpPrepatcherWarnDisabledDescription".Translate().RemoveRichTextTags(), boxWidth - 16f); + break; + } + + Rect hintRect = new Rect(baseRect.xMax + spacing, baseRect.y, boxWidth, boxHeight + 35f); + PrepatcherWarning.DoPrepatcherWarning(hintRect); + } + } + } } From c9b64dccb65f3289428eba4e7d9512b5bfcf8f8a Mon Sep 17 00:00:00 2001 From: SirWilliam <93367389+SirrWilliam@users.noreply.github.com> Date: Sat, 19 Jul 2025 22:40:29 +0300 Subject: [PATCH 6/8] fix --- Source/Client/UI/PrepatcherWarning.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Client/UI/PrepatcherWarning.cs b/Source/Client/UI/PrepatcherWarning.cs index 9a536add..aec10aed 100644 --- a/Source/Client/UI/PrepatcherWarning.cs +++ b/Source/Client/UI/PrepatcherWarning.cs @@ -188,7 +188,7 @@ static void Postfix() return; //Check before boxWidth calc - if (PrepatcherStatus == PrepatcherStatus.Unknown) + if (prepatcherStatus == PrepatcherStatus.Unknown) CheckPrepatcherStatus(); Rect baseRect = serverBrowserWindow.windowRect; From 6e089ed39ffde19963505a2c7275d2a27e7a36a7 Mon Sep 17 00:00:00 2001 From: SirWilliam <93367389+SirrWilliam@users.noreply.github.com> Date: Sat, 19 Jul 2025 23:10:50 +0300 Subject: [PATCH 7/8] . --- Source/Client/UI/IngameUI.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/Client/UI/IngameUI.cs b/Source/Client/UI/IngameUI.cs index a59bd77e..18c70520 100644 --- a/Source/Client/UI/IngameUI.cs +++ b/Source/Client/UI/IngameUI.cs @@ -1,12 +1,11 @@ using HarmonyLib; using Multiplayer.Common; using RimWorld; -using RimWorld.Planet; using System; using System.Collections.Generic; -using System.Linq; using UnityEngine; using Verse; +using RimWorld.Planet; namespace Multiplayer.Client { From 7a2732353ee0f245b4f2c578f05e81f7aecdd93e Mon Sep 17 00:00:00 2001 From: SirWilliam <93367389+SirrWilliam@users.noreply.github.com> Date: Sat, 19 Jul 2025 23:19:08 +0300 Subject: [PATCH 8/8] another change --- Source/Client/UI/PrepatcherWarning.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Client/UI/PrepatcherWarning.cs b/Source/Client/UI/PrepatcherWarning.cs index aec10aed..4420ed5d 100644 --- a/Source/Client/UI/PrepatcherWarning.cs +++ b/Source/Client/UI/PrepatcherWarning.cs @@ -100,7 +100,7 @@ private static void DrawWarning(Rect inRect) if (SteamManager.Initialized) SteamUtility.OpenWorkshopPage(prepatcherFileId); else - Application.OpenURL("https://steamcommunity.com/sharedfiles/filedetails/?id=2934420800"); + Application.OpenURL("https://steamcommunity.com/sharedfiles/filedetails/?id="+prepatcherFileId.m_PublishedFileId.ToString()); } } else