From 34fe5009a0c6e5cc9bd5b054181f89d831e5fd3e Mon Sep 17 00:00:00 2001 From: STApps Date: Tue, 27 Dec 2022 23:18:13 +0100 Subject: [PATCH 01/10] fix: sorting is now working again after sorting the ControlPoints list too --- .../Managers/ParallelRoadToolManager.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ParallelRoadTool/Managers/ParallelRoadToolManager.cs b/ParallelRoadTool/Managers/ParallelRoadToolManager.cs index c2ac502..ddfe439 100644 --- a/ParallelRoadTool/Managers/ParallelRoadToolManager.cs +++ b/ParallelRoadTool/Managers/ParallelRoadToolManager.cs @@ -679,12 +679,24 @@ private void RefreshNetworks(bool sort = false) if (sort) { // Sort networks based on ascending HorizontalOffset - var sorted = SelectedNetworkTypes.OrderBy(r => r.HorizontalOffset).ToList(); + // Since we need to sort the ControlPoints buffer too we include indexes in our sorted list. + // This way we can re-use them to move ControlPoints in the right place on the list. + var sorted = SelectedNetworkTypes + .Select((item, index) => new { Item = item, Index = index }) + .OrderBy(r => r.Item.HorizontalOffset).ToList(); // Clear and rebuild the list with the currently selected networks SelectedNetworkTypes.Clear(); - SelectedNetworkTypes.AddRange(sorted); + SelectedNetworkTypes.AddRange(sorted.Select(i => i.Item)); + + // Sort control points buffer too. + // We clone the list to an array to select items using the right index, taken from previously sorted collection. + var tmpControlPoints = _controlPointsBuffer.ToArray(); _controlPointsBuffer.Clear(); + foreach (var item in sorted) + { + _controlPointsBuffer.Add(tmpControlPoints[item.Index]); + } } // Update the UI From 5f2c7d4d7c58f8592067f4b5adc3f02582bcd59d Mon Sep 17 00:00:00 2001 From: STApps Date: Tue, 27 Dec 2022 23:20:28 +0100 Subject: [PATCH 02/10] chore: bumped version to 3.0.1 --- ParallelRoadTool/Properties/AssemblyInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ParallelRoadTool/Properties/AssemblyInfo.cs b/ParallelRoadTool/Properties/AssemblyInfo.cs index 0b9c0ce..c193ba6 100644 --- a/ParallelRoadTool/Properties/AssemblyInfo.cs +++ b/ParallelRoadTool/Properties/AssemblyInfo.cs @@ -36,4 +36,4 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.0.0")] +[assembly: AssemblyVersion("3.0.1")] From bdd41249cda81d2ac83368cff207b3043a51b8ec Mon Sep 17 00:00:00 2001 From: STApps Date: Wed, 28 Dec 2022 22:14:44 +0100 Subject: [PATCH 03/10] fix: added sanity check for Control Points when sorting --- .../Managers/ParallelRoadToolManager.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ParallelRoadTool/Managers/ParallelRoadToolManager.cs b/ParallelRoadTool/Managers/ParallelRoadToolManager.cs index ddfe439..d20b335 100644 --- a/ParallelRoadTool/Managers/ParallelRoadToolManager.cs +++ b/ParallelRoadTool/Managers/ParallelRoadToolManager.cs @@ -32,13 +32,13 @@ public class ParallelRoadToolManager : MonoBehaviour /// Buffer where all the generated during the overlay are stored. /// These points will be retrieved just before network creation so that we don't have to recompute them. /// - private readonly List _controlPointsBuffer = new (); + private readonly List _controlPointsBuffer = new(); /// /// Buffer where nodes metadata will be stored while building. /// This will map any node created with this mod with their corresponding offset one. /// - private readonly Dictionary _nodesBuffer = new (); + private readonly Dictionary _nodesBuffer = new(); /// /// Currently selected using game's . @@ -59,7 +59,7 @@ public class ParallelRoadToolManager : MonoBehaviour /// Gets the containing all the selected objects. /// This contains all the parallel/stacked networks that will be built once a main segment is created. /// - public List SelectedNetworkTypes { get; } = new (); + public List SelectedNetworkTypes { get; } = new(); /// /// Gets containing all the available objects. @@ -693,9 +693,12 @@ private void RefreshNetworks(bool sort = false) // We clone the list to an array to select items using the right index, taken from previously sorted collection. var tmpControlPoints = _controlPointsBuffer.ToArray(); _controlPointsBuffer.Clear(); - foreach (var item in sorted) + if (tmpControlPoints.Any()) { - _controlPointsBuffer.Add(tmpControlPoints[item.Index]); + foreach (var item in sorted) + { + _controlPointsBuffer.Add(tmpControlPoints[item.Index]); + } } } From 81b216ecc763d83462474ce746a853c55bab0c66 Mon Sep 17 00:00:00 2001 From: STApps Date: Sun, 22 Jan 2023 15:54:27 +0100 Subject: [PATCH 04/10] fix: removed typo from log file name --- ParallelRoadTool/Utils/Log.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ParallelRoadTool/Utils/Log.cs b/ParallelRoadTool/Utils/Log.cs index 3025a3f..9ce3c1b 100644 --- a/ParallelRoadTool/Utils/Log.cs +++ b/ParallelRoadTool/Utils/Log.cs @@ -20,7 +20,7 @@ public static class Log { private static readonly object LogLock = new (); - private static readonly string LogFilename = Path.Combine(Application.dataPath, Path.Combine("Logs", "ParallelRoadTtool.log")); + private static readonly string LogFilename = Path.Combine(Application.dataPath, Path.Combine("Logs", "ParallelRoadTool.log")); private static readonly Stopwatch Sw = Stopwatch.StartNew(); From 06b87b3c9d5813124e18ea1427d99376249024c2 Mon Sep 17 00:00:00 2001 From: STApps Date: Sun, 22 Jan 2023 15:55:21 +0100 Subject: [PATCH 05/10] fix: NullReference on roads with missing names chore: bumped version to 3.0.2 --- Docs/workshop/Beta/description.txt | 2 +- Docs/workshop/Stable/description.txt | 2 +- ParallelRoadTool/Models/NetInfoItem.cs | 2 +- ParallelRoadTool/Properties/AssemblyInfo.cs | 2 +- Submodules/AlgernonCommons | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Docs/workshop/Beta/description.txt b/Docs/workshop/Beta/description.txt index a8c8cfc..4b8e902 100644 --- a/Docs/workshop/Beta/description.txt +++ b/Docs/workshop/Beta/description.txt @@ -19,7 +19,7 @@ Main features are: [/quote] [quote] -[h1]Current version: [b]3.0.0-dev[/b][/h1] +[h1]Current version: [b]3.0.2-dev[/b][/h1] [list] [*] Moved mod core to Harmony for better compatibility with other mods [*] Completely rewritten mod's core logic/engine diff --git a/Docs/workshop/Stable/description.txt b/Docs/workshop/Stable/description.txt index a3cbb1a..05cd64a 100644 --- a/Docs/workshop/Stable/description.txt +++ b/Docs/workshop/Stable/description.txt @@ -18,7 +18,7 @@ Main features are: [/quote] [quote] -[h1]Current version: [b]3.0.0[/b][/h1] +[h1]Current version: [b]3.0.2[/b][/h1] [list] [*] Moved mod core to Harmony for better compatibility with other mods [*] Completely rewritten mod's core logic/engine diff --git a/ParallelRoadTool/Models/NetInfoItem.cs b/ParallelRoadTool/Models/NetInfoItem.cs index febec02..a82b4d4 100644 --- a/ParallelRoadTool/Models/NetInfoItem.cs +++ b/ParallelRoadTool/Models/NetInfoItem.cs @@ -54,7 +54,7 @@ public NetInfoItem(NetInfo netInfo, float horizontalOffset, float verticalOffset /// /// Gets network's name, used also as a unique id. /// - public string Name => NetInfo.name; + public string Name => NetInfo?.name ?? "null"; /// /// Gets a generated name used for display purposes. diff --git a/ParallelRoadTool/Properties/AssemblyInfo.cs b/ParallelRoadTool/Properties/AssemblyInfo.cs index c193ba6..d024621 100644 --- a/ParallelRoadTool/Properties/AssemblyInfo.cs +++ b/ParallelRoadTool/Properties/AssemblyInfo.cs @@ -36,4 +36,4 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.0.1")] +[assembly: AssemblyVersion("3.0.2")] diff --git a/Submodules/AlgernonCommons b/Submodules/AlgernonCommons index 6653978..611a8a2 160000 --- a/Submodules/AlgernonCommons +++ b/Submodules/AlgernonCommons @@ -1 +1 @@ -Subproject commit 6653978f20aec30d19e47909a42a0fe8ebd5c46a +Subproject commit 611a8a2365c603f41c361db5790396357a45dd07 From 8784858b7c9b04e73f3f5a4eca713419356991af Mon Sep 17 00:00:00 2001 From: STApps Date: Sat, 4 Mar 2023 13:37:05 +0100 Subject: [PATCH 06/10] fix: minor exception while loading presets --- ParallelRoadTool/UI/Presets/UIPresetDetailsPanel.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ParallelRoadTool/UI/Presets/UIPresetDetailsPanel.cs b/ParallelRoadTool/UI/Presets/UIPresetDetailsPanel.cs index 8339af4..b79590d 100644 --- a/ParallelRoadTool/UI/Presets/UIPresetDetailsPanel.cs +++ b/ParallelRoadTool/UI/Presets/UIPresetDetailsPanel.cs @@ -29,7 +29,10 @@ public UIPresetDetailsPanel() public void ClearPreset() { - _netItemsList.Clear(); + if (_netItemsList != null) + { + _netItemsList.Clear(); + } } public void LoadPreset(IEnumerable networks) From 54d81ae009d172bd44296bdc59258c9491fae6f8 Mon Sep 17 00:00:00 2001 From: STApps Date: Sun, 5 Mar 2023 16:49:58 +0100 Subject: [PATCH 07/10] fix: reduced exceptions during overlay but this still doesn't fixes the root cause --- ParallelRoadTool/Patches/NetToolNodePatch.cs | 54 ++++++++++++++++++++ ParallelRoadTool/Utils/ControlPointUtils.cs | 46 ++++++++++------- 2 files changed, 82 insertions(+), 18 deletions(-) diff --git a/ParallelRoadTool/Patches/NetToolNodePatch.cs b/ParallelRoadTool/Patches/NetToolNodePatch.cs index 69f2e22..485a311 100644 --- a/ParallelRoadTool/Patches/NetToolNodePatch.cs +++ b/ParallelRoadTool/Patches/NetToolNodePatch.cs @@ -303,6 +303,60 @@ private static bool CanRun(bool test, bool visualize, bool switchDir) [HarmonyPatch] internal static class NetToolReversePatch { + [HarmonyFinalizer] + [HarmonyPatch( + typeof(NetTool), + nameof(NetTool.CreateNode), + new[] + { + typeof(NetInfo), + typeof(NetTool.ControlPoint), + typeof(NetTool.ControlPoint), + typeof(NetTool.ControlPoint), + typeof(FastList), + typeof(int), + typeof(bool), + typeof(bool), + typeof(bool), + typeof(bool), + typeof(bool), + typeof(bool), + typeof(ushort), + typeof(ushort), + typeof(ushort), + typeof(int), + typeof(int), + }, + new[] + { + ArgumentType.Normal, + ArgumentType.Normal, + ArgumentType.Normal, + ArgumentType.Normal, + ArgumentType.Normal, + ArgumentType.Normal, + ArgumentType.Normal, + ArgumentType.Normal, + ArgumentType.Normal, + ArgumentType.Normal, + ArgumentType.Normal, + ArgumentType.Normal, + ArgumentType.Normal, + ArgumentType.Out, + ArgumentType.Out, + ArgumentType.Out, + ArgumentType.Out, + })] + static Exception Finalizer(Exception __exception) + { + if (__exception != null) + { + Log._Debug($"[{nameof(NetToolReversePatch)}.{nameof(Finalizer)}] Got exception: {__exception.Message}"); + } + + return null; + } + [HarmonyReversePatch] [HarmonyPatch( typeof(NetTool), diff --git a/ParallelRoadTool/Utils/ControlPointUtils.cs b/ParallelRoadTool/Utils/ControlPointUtils.cs index 8e2e8ec..ee84df5 100644 --- a/ParallelRoadTool/Utils/ControlPointUtils.cs +++ b/ParallelRoadTool/Utils/ControlPointUtils.cs @@ -11,6 +11,7 @@ namespace ParallelRoadTool.Utils; using Extensions; using Managers; using Patches; +using System; using UnityEngine; internal static class ControlPointUtils @@ -258,23 +259,32 @@ public static bool CanCreate( NetTool.ControlPoint currentEndPoint, bool isReversed) { - return NetToolReversePatch.CreateNode( - netInfo, - currentStartPoint, - currentMiddlePoint, - currentEndPoint, - NetTool.m_nodePositionsSimulation, - 1000, - true, - false, - true, - true, - false, - isReversed, - 0, - out _, - out _, - out _, - out _) == ToolBase.ToolErrors.None; + try + { + return NetToolReversePatch.CreateNode( + netInfo, + currentStartPoint, + currentMiddlePoint, + currentEndPoint, + NetTool.m_nodePositionsSimulation, + 1000, + true, + false, + true, + true, + false, + isReversed, + 0, + out _, + out _, + out _, + out _) == ToolBase.ToolErrors.None; + } + catch (Exception ex) + { + Log._Debug($"[{nameof(ControlPointUtils)}.{nameof(CanCreate)}] Caused an exception: {ex.Message}"); + return false; + } + } } From ab9ea39de41b4629f687e834a97d4491450bd17a Mon Sep 17 00:00:00 2001 From: STApps Date: Sun, 5 Mar 2023 16:52:41 +0100 Subject: [PATCH 08/10] chore: bumped version to 3.0.3 --- Docs/workshop/Beta/description.txt | 2 +- Docs/workshop/Stable/description.txt | 2 +- ParallelRoadTool/Properties/AssemblyInfo.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Docs/workshop/Beta/description.txt b/Docs/workshop/Beta/description.txt index 4b8e902..a6bfbc4 100644 --- a/Docs/workshop/Beta/description.txt +++ b/Docs/workshop/Beta/description.txt @@ -19,7 +19,7 @@ Main features are: [/quote] [quote] -[h1]Current version: [b]3.0.2-dev[/b][/h1] +[h1]Current version: [b]3.0.3-dev[/b][/h1] [list] [*] Moved mod core to Harmony for better compatibility with other mods [*] Completely rewritten mod's core logic/engine diff --git a/Docs/workshop/Stable/description.txt b/Docs/workshop/Stable/description.txt index 05cd64a..eea3f6a 100644 --- a/Docs/workshop/Stable/description.txt +++ b/Docs/workshop/Stable/description.txt @@ -18,7 +18,7 @@ Main features are: [/quote] [quote] -[h1]Current version: [b]3.0.2[/b][/h1] +[h1]Current version: [b]3.0.3[/b][/h1] [list] [*] Moved mod core to Harmony for better compatibility with other mods [*] Completely rewritten mod's core logic/engine diff --git a/ParallelRoadTool/Properties/AssemblyInfo.cs b/ParallelRoadTool/Properties/AssemblyInfo.cs index d024621..3f30a43 100644 --- a/ParallelRoadTool/Properties/AssemblyInfo.cs +++ b/ParallelRoadTool/Properties/AssemblyInfo.cs @@ -36,4 +36,4 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.0.2")] +[assembly: AssemblyVersion("3.0.3")] From 1e4a892f1a3ff91aeb68a473426ac5a8db3fc54e Mon Sep 17 00:00:00 2001 From: STApps Date: Mon, 29 May 2023 21:08:15 +0200 Subject: [PATCH 09/10] chore: bumped to 3.0.4 to support v1.17 --- Docs/workshop/Beta/description.txt | 4 ++-- Docs/workshop/Stable/description.txt | 4 ++-- ParallelRoadTool/Mod.cs | 2 +- ParallelRoadTool/Properties/AssemblyInfo.cs | 2 +- Translations/en-EN.csv | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Docs/workshop/Beta/description.txt b/Docs/workshop/Beta/description.txt index a6bfbc4..560e758 100644 --- a/Docs/workshop/Beta/description.txt +++ b/Docs/workshop/Beta/description.txt @@ -15,11 +15,11 @@ Main features are: [quote] [h1][b]Stable version is [url=https://steamcommunity.com/sharedfiles/filedetails/?id=1440928803]here[/url][/b].[/h1] [h1][b]The beta version is meant for testing only and it can be unstable.[/b][/h1] -[b]Tested on C:S version 1.16.0-f3[/b] +[b]Tested on C:S version 1.17.0-f3[/b] [/quote] [quote] -[h1]Current version: [b]3.0.3-dev[/b][/h1] +[h1]Current version: [b]3.0.4-dev[/b][/h1] [list] [*] Moved mod core to Harmony for better compatibility with other mods [*] Completely rewritten mod's core logic/engine diff --git a/Docs/workshop/Stable/description.txt b/Docs/workshop/Stable/description.txt index eea3f6a..7431ce3 100644 --- a/Docs/workshop/Stable/description.txt +++ b/Docs/workshop/Stable/description.txt @@ -14,11 +14,11 @@ Main features are: [quote] [h1]For new features and/or debugging, you can subscribe to the [url=https://steamcommunity.com/sharedfiles/filedetails/?id=1400711138]beta version[/url][/h1] -[b]Tested on C:S version 1.16.0-f3[/b] +[b]Tested on C:S version 1.17.0-f3[/b] [/quote] [quote] -[h1]Current version: [b]3.0.3[/b][/h1] +[h1]Current version: [b]3.0.4[/b][/h1] [list] [*] Moved mod core to Harmony for better compatibility with other mods [*] Completely rewritten mod's core logic/engine diff --git a/ParallelRoadTool/Mod.cs b/ParallelRoadTool/Mod.cs index 4e27828..0dd422b 100644 --- a/ParallelRoadTool/Mod.cs +++ b/ParallelRoadTool/Mod.cs @@ -23,7 +23,7 @@ public sealed class Mod : PatcherMod, IUserMod /// /// Minimum minor version that is compatible with the mod. /// - private const string CompatibleVersion = "1.16"; + private const string CompatibleVersion = "1.17"; /// /// Simplified name, used for file-system operations. diff --git a/ParallelRoadTool/Properties/AssemblyInfo.cs b/ParallelRoadTool/Properties/AssemblyInfo.cs index 3f30a43..608431c 100644 --- a/ParallelRoadTool/Properties/AssemblyInfo.cs +++ b/ParallelRoadTool/Properties/AssemblyInfo.cs @@ -36,4 +36,4 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.0.3")] +[assembly: AssemblyVersion("3.0.4")] diff --git a/Translations/en-EN.csv b/Translations/en-EN.csv index 6480206..65dc698 100644 --- a/Translations/en-EN.csv +++ b/Translations/en-EN.csv @@ -13,7 +13,7 @@ "HARMONY_NOT_INSTALLED","The required Harmony 2 mod dependency was not installed","Possible cause of Harmony error - Harmony not installed." "HARMONY_MOD_ERROR","An old and/or broken mod is preventing Harmony 2 from operating properly","Possible cause of Harmony error - a broken mod (not this one) can cause things to stop working." "HARMONY_MOD_CONFLICT","Another mod may be trying to apply a conflicting Harmony patch","Possible cause of Harmony error - two mods trying to patch the same thing at once." -"WRONG_VERSION","Loading Screen Mod Revisited is not compatible with this game version.","Warning displayed on startup if an incompatible game version is detected" +"WRONG_VERSION","Parallel Road Tool is not compatible with this game version.","Warning displayed on startup if an incompatible game version is detected" "SHUT_DOWN","As a safety measure, the mod has shut down and will not operate.","Warning displayed on startup if an incompatible game version is detected" "MOD_DESCRIPTION","Helps you easily drawing parallel and stacked networks" "FAILED","failed" From 817c2f19400d2bd02efc6e488af45c828b3555a9 Mon Sep 17 00:00:00 2001 From: STApps Date: Mon, 29 May 2023 23:53:09 +0200 Subject: [PATCH 10/10] chore: updated compatibility image --- Docs/workshop/Beta/description.txt | 2 +- Docs/workshop/Stable/description.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Docs/workshop/Beta/description.txt b/Docs/workshop/Beta/description.txt index 560e758..d4de1d6 100644 --- a/Docs/workshop/Beta/description.txt +++ b/Docs/workshop/Beta/description.txt @@ -1,4 +1,4 @@ -[img]https://i.imgur.com/eFtUCf9.png[/img] +[img]https://i.imgur.com/a0VrMRr.png[/img] [h1][b][BETA] Parallel Road Tool[/b][/h1] helps you easily drawing parallel and stacked networks. diff --git a/Docs/workshop/Stable/description.txt b/Docs/workshop/Stable/description.txt index 7431ce3..aca3e7d 100644 --- a/Docs/workshop/Stable/description.txt +++ b/Docs/workshop/Stable/description.txt @@ -1,4 +1,4 @@ -[img]https://i.imgur.com/eFtUCf9.png[/img] +[img]https://i.imgur.com/a0VrMRr.png[/img] [h1][b]Parallel Road Tool[/b][/h1] helps you easily drawing parallel and stacked networks.