Skip to content

Commit

Permalink
ignore field if no graphics (very silly)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddio0141 committed Sep 5, 2024
1 parent 12face8 commit 647d358
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion UniTAS/Patcher/Patches/Preloader/StaticCtorHeaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Mono.Cecil.Rocks;
using UniTAS.Patcher.Extensions;
using UniTAS.Patcher.Interfaces;
using UniTAS.Patcher.ManualServices;
using UniTAS.Patcher.ManualServices.Trackers;
using UniTAS.Patcher.Utils;
using FieldAttributes = Mono.Cecil.FieldAttributes;
Expand Down Expand Up @@ -186,6 +187,15 @@ public static class PatchMethods
// dictionary here are for different threads
private static readonly ConcurrentDictionary<int, List<Type>> PendingIgnoreAddingInvokeList = new();

private static readonly ConcurrentDictionary<string, List<string>> FieldIgnoreListConditional = new();

static PatchMethods()
{
// add this if no graphics (very silly)
if (GameInfoManual.NoGraphics)
FieldIgnoreListConditional.TryAdd("UnityEngine.Rendering.OnDemandRendering", ["m_RenderFrameInterval"]);
}

public static void StaticCtorStart()
{
var type = new StackFrame(1).GetMethod()?.DeclaringType;
Expand All @@ -202,15 +212,21 @@ public static void StaticCtorStart()
invokeStack.Add(type);

var stackCount = invokeStack.Count;
var typeSaneFullName = type.SaneFullName();
StaticLogger.Log.LogDebug(
$"Start of static ctor {type.SaneFullName()}, stack count: {stackCount}, thread id: {threadId}");
$"Start of static ctor {typeSaneFullName}, stack count: {stackCount}, thread id: {threadId}");
if (IsNotFirstInvoke(type)) return;
StaticLogger.Trace("First static ctor invoke");

// first invoke zone

// find and store static fields for later
var declaredFields = AccessTools.GetDeclaredFields(type).Where(x => x.IsStatic && !x.IsLiteral);
if (FieldIgnoreListConditional.TryRemove(typeSaneFullName, out var ignoreFields))
{
declaredFields = declaredFields.Where(x => !ignoreFields.Contains(x.Name));
}

ClassStaticInfoTracker.AddStaticFields(declaredFields);

// if this is chain called, store dependency
Expand Down

0 comments on commit 647d358

Please sign in to comment.