Mainly more hauling optimizations, utilizing linked storage groups

This also adds an experimental, usually slower, threaded gas grid mode and implements a workaround for the whole mod and game failing to start when opening prepatcher's mod manager with unfortunate timing
This commit is contained in:
bbradson
2024-02-01 19:57:50 +01:00
parent 20aebe4e83
commit 949bde76ce
27 changed files with 451 additions and 280 deletions
@@ -3,6 +3,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
using System.Diagnostics;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Cecil.Rocks;
@@ -75,8 +76,7 @@ public abstract class FishPrepatch : FishPrepatchBase
}
catch (Exception e)
{
Log.Error($"Exception while applying transpiler for {GetType().FullName}\n{e}\n{
Environment.StackTrace /*StackTraceUtility.ExtractStackTrace()*/}");
Log.Error($"Exception while applying transpiler for {GetType().FullName}\n{e}\n{new StackTrace(true)}");
}
var patchVariables = new PatchVariables();
@@ -89,8 +89,7 @@ public abstract class FishPrepatch : FishPrepatchBase
}
catch (Exception e)
{
Log.Error($"Exception while applying prefix for {GetType().FullName}\n{e}\n{
Environment.StackTrace /*StackTraceUtility.ExtractStackTrace()*/}");
Log.Error($"Exception while applying prefix for {GetType().FullName}\n{e}\n{new StackTrace(true)}");
}
}
@@ -102,8 +101,7 @@ public abstract class FishPrepatch : FishPrepatchBase
}
catch (Exception e)
{
Log.Error($"Exception while applying postfix for {GetType().FullName}\n{e}\n{
Environment.StackTrace /*StackTraceUtility.ExtractStackTrace()*/}");
Log.Error($"Exception while applying postfix for {GetType().FullName}\n{e}\n{new StackTrace(true)}");
}
}
@@ -51,7 +51,7 @@ public abstract class FishPrepatchBase : SingletonFactory<FishPrepatchBase>, IEx
: Description
+ $"{(Description?.EndsWith(".") ?? true ? "" : ".")} Disabled for compatibility with {
IncompatibleModIDs.Select(static id => ActiveMods.TryGetModMetaData(id)?.Name)
.Where(static id => id != null).ToCommaList(true)}";
.Where(Is.NotNull).ToCommaList(true)}";
public virtual string? Name => null;
@@ -74,9 +74,11 @@ public unsafe struct FishStash : IEquatable<FishStash>
internal void InitializeActivePrepatchIDs()
{
var activePrepatches = PerformanceFishMod.AllPrepatchClasses!.SelectMany(static patchClass
=> patchClass.Patches.Where(static patch
=> patch.Enabled).Select(static patch => patch.IDNumber)).ToArray();
var activePrepatches = PerformanceFishMod.AllPrepatchClasses!
.SelectMany(static patchClass => patchClass.Patches
.Where(static patch => patch.Enabled)
.Select(static patch => patch.IDNumber))
.ToArray();
var activePrepatchCount = activePrepatches.Length;
_activePrepatchCount = activePrepatchCount;
@@ -13,6 +13,7 @@ using Mono.Collections.Generic;
using nuget::JetBrains.Annotations;
using PerformanceFish.ModCompatibility;
using CollectionExtensions = PerformanceFish.Utility.CollectionExtensions;
using FieldAttributes = Mono.Cecil.FieldAttributes;
using MethodBody = Mono.Cecil.Cil.MethodBody;
namespace PerformanceFish.Prepatching;
@@ -29,6 +30,20 @@ public static class PrepatchManager
ThrowHelper.ThrowInvalidOperationException("Tried running free patches a second time. This should "
+ "never happen. Cancelling now to avoid further issues.");
}
var gasFields = module.GetTypeDefinition(typeof(Gas))!.Fields;
if (gasFields.Any(static field => field.Name == VERIFICATION_FIELD_NAME))
{ // TODO: fix unity logger breaking when getting here
UnityEngine.Debug.Log("Detected second prepatch attempt. This is known to happen after using "
+ "Prepatcher's mod manager. Cancelling and restarting now to prevent issues");
GenCommandLine.Restart();
}
else
{
gasFields.Add(new(VERIFICATION_FIELD_NAME,
FieldAttributes.Private | FieldAttributes.Static | FieldAttributes.Literal,
module.TypeSystem.Byte));
}
Log.Message(LogPatches.PERFORMANCE_FISH_WELCOME_MESSAGE);
if (!ActiveMods.Prepatcher)
@@ -84,7 +99,9 @@ public static class PrepatchManager
Verse.Log.Message($"Performance Fish finished applying prepatches in {
stopwatch.ElapsedSecondsAccurate():N7} seconds");
}
private const string VERIFICATION_FIELD_NAME = "PerformanceFishS1ngl3Pr3p4tchV3r1f1c4t10nF13ld";
// private static readonly FieldInfo? _monoAssemblyField = AccessTools.Field(typeof(Assembly), "_mono_assembly");
//
// internal static unsafe void SetReflectionOnly(Assembly asm, bool value, out bool previousValue)