diff --git a/Docs/workshop/Beta/description.txt b/Docs/workshop/Beta/description.txt index a8c8cfc..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. @@ -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.0-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 a3cbb1a..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. @@ -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.0[/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/Managers/ParallelRoadToolManager.cs b/ParallelRoadTool/Managers/ParallelRoadToolManager.cs index ddfe439..3327015 100644 --- a/ParallelRoadTool/Managers/ParallelRoadToolManager.cs +++ b/ParallelRoadTool/Managers/ParallelRoadToolManager.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) ST-Apps (S. Tenuta). All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. // @@ -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]); + } } } 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/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/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/Properties/AssemblyInfo.cs b/ParallelRoadTool/Properties/AssemblyInfo.cs index c193ba6..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.1")] +[assembly: AssemblyVersion("3.0.4")] 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) 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; + } + } } 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(); 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 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"