1.5, added stuff, fixed stuff
- mod icon - fixes for new vanilla clipping issues - GenClosest optimization improving repairing, wardening, tending jobs - caching for new ListerBuildings methods - DynamicDrawManager single threading - Type.GetFields caching - StatParts analyzer category - removed duplicate steam warning and optionally window - added exception handling for debug menu, incidentworker, Graphic_Multi, InitializeComps, making all those now log what mod broke and not cause black screens or whatever
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
// Copyright (c) 2023 bradson
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// 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 JetBrains.Annotations;
|
||||
|
||||
namespace PerformanceFish.Defs;
|
||||
|
||||
[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
|
||||
public record struct DefPair
|
||||
{
|
||||
private uint _data;
|
||||
|
||||
public ushort First
|
||||
{
|
||||
get => (ushort)(_data >> 16);
|
||||
set => _data = (_data & 0x00_00_FF_FF) | ((uint)value << 16);
|
||||
}
|
||||
|
||||
public ushort Second
|
||||
{
|
||||
get => (ushort)_data;
|
||||
set => _data = (_data & 0xFF_FF_00_00) | value;
|
||||
}
|
||||
|
||||
public DefPair(Def first, Def second) : this(first.shortHash, second.shortHash)
|
||||
{
|
||||
}
|
||||
|
||||
public DefPair(ushort first, ushort second) => _data = Create(first, second);
|
||||
|
||||
public bool Equals(DefPair other) => _data == other._data;
|
||||
|
||||
public override int GetHashCode() => unchecked((int)_data);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static uint Create(Def first, Def second) => Create(first.shortHash, second.shortHash);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static uint Create(ushort first, ushort second) => ((uint)first << 16) | second;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
// Copyright (c) 2023 bradson
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// 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 Mono.Cecil;
|
||||
using Mono.Cecil.Cil;
|
||||
using PerformanceFish.Prepatching;
|
||||
|
||||
namespace PerformanceFish.Defs;
|
||||
|
||||
public sealed class IncidentDefFixes : ClassWithFishPrepatches
|
||||
{
|
||||
public sealed class WorkerPatch : FishPrepatch
|
||||
{
|
||||
public override string? Description { get; }
|
||||
= "RimWorld has no checks to verify that IncidentDefs include valid classes with their actual "
|
||||
+ "implementation. This means whenever mods either don't provide one or it simply fails to load for any "
|
||||
+ "reason, entirely uninformative errors get spammed at the point the storyteller tries starting an "
|
||||
+ "incident at. This patch here adds a check, logging the erroneous def with mod source when possible and "
|
||||
+ "disabling the IncidentWorker from running to prevent the error spam.";
|
||||
|
||||
public override MethodBase TargetMethodBase { get; }
|
||||
= AccessTools.DeclaredPropertyGetter(typeof(IncidentDef), nameof(IncidentDef.Worker));
|
||||
|
||||
public override void Transpiler(ILProcessor ilProcessor, ModuleDefinition module)
|
||||
=> ilProcessor.ReplaceBodyWith(Replacement);
|
||||
|
||||
public static IncidentWorker Replacement(IncidentDef instance)
|
||||
{
|
||||
if (instance.workerInt == null)
|
||||
{
|
||||
if (instance.workerClass is null)
|
||||
TryFixAndLogError(instance);
|
||||
|
||||
instance.workerInt = (IncidentWorker)Activator.CreateInstance(instance.workerClass!);
|
||||
instance.workerInt.def = instance;
|
||||
}
|
||||
|
||||
return instance.workerInt;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static void TryFixAndLogError(IncidentDef instance)
|
||||
{
|
||||
instance.workerClass = typeof(IncidentWorker_AlwaysSkip);
|
||||
Log.Error($"Detected missing workerClass in IncidentDef '{
|
||||
instance.defName ?? "null"}' from mod '{
|
||||
instance.modContentPack?.Name ?? "null"}' for IncidentCategoryDef '{
|
||||
instance.category?.defName ?? "null"}'. Disabling now to avoid further issues.");
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class IncidentWorker_AlwaysSkip : IncidentWorker
|
||||
{
|
||||
#if !V1_4
|
||||
public override float ChanceFactorNow(IIncidentTarget target) => 0f;
|
||||
#endif
|
||||
|
||||
public override float BaseChanceThisGame => 0f;
|
||||
|
||||
protected override bool CanFireNowSub(IncidentParms parms) => true;
|
||||
|
||||
protected override bool TryExecuteWorker(IncidentParms parms) => true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// Copyright (c) 2023 bradson
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// 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 Mono.Cecil;
|
||||
using Mono.Cecil.Cil;
|
||||
using PerformanceFish.Prepatching;
|
||||
|
||||
namespace PerformanceFish.Defs;
|
||||
|
||||
public sealed class WorkGiverDefFixes : ClassWithFishPrepatches
|
||||
{
|
||||
public sealed class WorkerPatch : FishPrepatch
|
||||
{
|
||||
public override string? Description { get; }
|
||||
= "RimWorld has no checks to verify that WorkGiverDefs include valid classes with their actual "
|
||||
+ "implementation. This means whenever mods either don't provide one or it simply fails to load for any "
|
||||
+ "reason, entirely uninformative errors get spammed at the point pawns try starting a job at. This patch "
|
||||
+ "here adds a check, logging the erroneous def with mod source when possible and disabling the WorkGiver "
|
||||
+ "from running to prevent the error spam.";
|
||||
|
||||
public override MethodBase TargetMethodBase { get; }
|
||||
= AccessTools.DeclaredPropertyGetter(typeof(WorkGiverDef), nameof(WorkGiverDef.Worker));
|
||||
|
||||
public override void Transpiler(ILProcessor ilProcessor, ModuleDefinition module)
|
||||
=> ilProcessor.ReplaceBodyWith(Replacement);
|
||||
|
||||
public static WorkGiver Replacement(WorkGiverDef instance)
|
||||
{
|
||||
if (instance.workerInt == null)
|
||||
{
|
||||
if (instance.giverClass is null)
|
||||
TryFixAndLogError(instance);
|
||||
|
||||
instance.workerInt = (WorkGiver)Activator.CreateInstance(instance.giverClass!);
|
||||
instance.workerInt.def = instance;
|
||||
}
|
||||
|
||||
return instance.workerInt;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static void TryFixAndLogError(WorkGiverDef instance)
|
||||
{
|
||||
instance.giverClass = typeof(WorkGiver_AlwaysSkip);
|
||||
Log.Error($"Detected missing giverClass in WorkGiverDef '{
|
||||
instance.defName ?? "null"}' from mod '{
|
||||
instance.modContentPack?.Name ?? "null"}' for WorkTypeDef '{
|
||||
instance.workType?.defName ?? "null"}'. Disabling now to avoid further issues.");
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class WorkGiver_AlwaysSkip : WorkGiver
|
||||
{
|
||||
public override bool ShouldSkip(Pawn pawn, bool forced = false) => true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user