using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using LazyBearTechnology;
using Microsoft.CodeAnalysis;
using Pathfinding;
using Timbn.GraveyardKeeperTwo.Core.Framework;
using Timbn.GraveyardKeeperTwo.VanillaTweaks.Tweaks;
using UnityEngine;
using UnityEngine.Rendering;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Timbn.GraveyardKeeperTwo.VanillaTweaks")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Fixes bugs and soft locks and adds light tweaks that keep the vanilla experience without cheating. Almost every fix and tweak can be turned off on its own.")]
[assembly: AssemblyFileVersion("1.14.0.0")]
[assembly: AssemblyInformationalVersion("1.14.0+41ae4f520037baace18326e3b35b7269374ca2d4")]
[assembly: AssemblyProduct("Timbn Vanilla Tweaks")]
[assembly: AssemblyTitle("Timbn.GraveyardKeeperTwo.VanillaTweaks")]
[assembly: AssemblyVersion("1.14.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace Timbn.GraveyardKeeperTwo.VanillaTweaks
{
[BepInPlugin("Timbn.GraveyardKeeperTwo.VanillaTweaks", "Timbn Vanilla Tweaks", "1.14.0")]
[BepInDependency("Timbn.GraveyardKeeperTwo.Core", "2.2.0")]
public class Plugin : TimbnFrameworkPlugin<Plugin>
{
internal UnreachableDismantle Dismantle { get; private set; }
internal ConveyorLoopCrash ConveyorLoops { get; private set; }
internal SortIntoBags BagSorting { get; } = new SortIntoBags();
protected override TimbnModInfo ModInfo => new TimbnModInfo
{
ModGroupName = "Timbn Mods",
ModGroupId = "338834e9-f5a5-4d7b-9773-17dfe3d5a954",
Description = "Fixes bugs and soft locks, with a few light tweaks and no cheating.",
Author = "Timbn",
NexusLink = "https://www.nexusmods.com/graveyardkeeper2/mods/66",
SteamWorkshopLink = "https://steamcommunity.com/sharedfiles/filedetails/?id=3810071056",
ThunderstoreLink = "https://thunderstore.io/c/graveyard-keeper-2/p/Timbn/TimbnVanillaTweaks/"
};
protected override void BindConfig(ConfigFile config)
{
PluginConfig.Bind(config);
}
protected override void OnAwake()
{
TechPointCap.Register((TimbnFrameworkPlugin)(object)this);
StrayTechPoints.Register((TimbnFrameworkPlugin)(object)this);
StuckCarriers.Register((TimbnFrameworkPlugin)(object)this);
StuckResourceWorkers.Register((TimbnFrameworkPlugin)(object)this);
BuiltEarlyQuests.Register((TimbnFrameworkPlugin)(object)this);
Dismantle = UnreachableDismantle.Register((TimbnFrameworkPlugin)(object)this);
LostItems.Register((TimbnFrameworkPlugin)(object)this);
BedSaveWhenRested.Register((TimbnFrameworkPlugin)(object)this);
ConveyorLoops = ConveyorLoopCrash.Register((TimbnFrameworkPlugin)(object)this);
}
protected override void OnUpdate()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
if (TimbnInput.IsDownWithControl(PluginConfig.UnstuckKey.Value))
{
Unstuck.Run(PluginConfig.UnstuckRange.Value);
}
}
}
internal static class PluginConfig
{
private const string _bugFixes = "Bug Fixes";
private const string _softLocks = "Soft Locks";
private const string _tweaks = "Tweaks";
public static ConfigEntry<bool> CollectStrayTechPoints { get; private set; }
public static ConfigEntry<bool> SermonFaithRounding { get; private set; }
public static ConfigEntry<bool> StuckCarriers { get; private set; }
public static ConfigEntry<bool> StuckResourceWorkers { get; private set; }
public static ConfigEntry<bool> ConveyorLoopCrash { get; private set; }
public static ConfigEntry<bool> HighlightConveyorLoops { get; private set; }
public static ConfigEntry<bool> BuiltEarlyQuests { get; private set; }
public static ConfigEntry<bool> DismantleUnreachable { get; private set; }
public static ConfigEntry<bool> SoftLockedBoards { get; private set; }
public static ConfigEntry<bool> LostQuestItems { get; private set; }
public static ConfigEntry<bool> MoveIdenticalFromBags { get; private set; }
public static ConfigEntry<bool> SortIntoBags { get; private set; }
public static ConfigEntry<KeyboardShortcut> UnstuckKey { get; private set; }
public static ConfigEntry<float> UnstuckRange { get; private set; }
public static ConfigEntry<bool> BedSaveWhenRested { get; private set; }
public static ConfigEntry<int> TechPointCap { get; private set; }
public static void Bind(ConfigFile config)
{
//IL_015f: Unknown result type (might be due to invalid IL or missing references)
CollectStrayTechPoints = config.Bind<bool>("Bug Fixes", "CollectStrayTechPoints", true, "Pulls a tech point orb to you when it settles off the walkable ground and out of reach of the game's magnet. The game only gathers those when you sleep.");
SermonFaithRounding = config.Bind<bool>("Bug Fixes", "SermonFaithRounding", true, "Rounds ceremony faith the way the numbers say. Priest makes Basic Prayer pay 0.35 faith per parishioner, but the game stores 0.35 as a number just under it, so at 10, 30, 50 parishioners and so on a total of 3.5 can land just under 3.5 and round down, and Priest adds nothing.");
StuckCarriers = config.Bind<bool>("Bug Fixes", "StuckCarriers", true, "When a zombie supplier has nowhere to put its item, it shows the no storage icon the game already uses for gardeners and walks back to its Zombie Supplier Station instead of standing where it is. It goes on with its work as soon as there is room, as it would anyway.");
StuckResourceWorkers = config.Bind<bool>("Bug Fixes", "StuckResourceWorkers", true, "Keeps lumberjack, miner, clay digger and sand digger zombies working. Each of them walks out to one of a few work spots, and dismantling a stand while its zombie was out left that spot taken for good. Once every spot was taken, a zombie stood in place swinging its tool forever. Spots are now freed when a zombie leaves its stand, spots already lost in a save are freed when it loads, and a stranded zombie goes back to work as soon as a spot is free.");
ConveyorLoopCrash = config.Bind<bool>("Bug Fixes", "ConveyorLoopCrash", true, "Stops the game from closing on its own a few seconds after a save loads when a loop of conveyors feeds another loop and the first one runs empty or jams, for example a splitter that sends part of its coal back into the chest before it. Your conveyors keep moving items as before.");
HighlightConveyorLoops = config.Bind<bool>("Bug Fixes", "HighlightConveyorLoops", true, "When a conveyor loop like that is found, traces it with arrows and draws a red square on the belt to remove to break it. A notice shows either way. Needs ConveyorLoopCrash.");
BuiltEarlyQuests = config.Bind<bool>("Soft Locks", "BuiltEarlyQuests", true, "Finishes Agatha's choir step and the woodcarver's organ step when you built the choir or organ before being asked. The game only checks the moment you build it, and it can be built once, so building it early locks the quest line for good. Checked when a save loads and when the step starts.");
DismantleUnreachable = config.Bind<bool>("Soft Locks", "DismantleUnreachable", true, "A station up against a fence or wall might be blocked from dismantling. This will allow you to still work on it.");
SoftLockedBoards = config.Bind<bool>("Soft Locks", "SoftLockedBoards", true, "If you have fewer than two boards and no sawhorse or circular saw, Larry will offer you two when you talk to him.");
LostQuestItems = config.Bind<bool>("Soft Locks", "LostQuestItems", true, "If you lose the Inquisitor's medallion before opening the tower prison bars, Larry will have found it.");
MoveIdenticalFromBags = config.Bind<bool>("Tweaks", "MoveIdenticalFromBags", true, "The chest window's move all identical items button also takes matching items out of your bags, not just your main inventory.");
SortIntoBags = config.Bind<bool>("Tweaks", "SortIntoBags", true, "Items you pick up, craft, buy, or take from a chest go straight into the bag made for them, such as fish and bait into a fishing bag or seeds into a farming bag, while it has room. Universal bags work as before and only take what they already hold or what no longer fits in your inventory.");
UnstuckKey = config.Bind<KeyboardShortcut>("Tweaks", "UnstuckKey", new KeyboardShortcut((KeyCode)117, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), "Moves you to the nearest open ground when you are boxed in, say between chests or inside a collider. Only works while you can move, so not with a window open or during dialog or a cutscene. Clear it to turn the key off.");
UnstuckRange = TimbnConfig.BindRange<float>(config, "Tweaks", "UnstuckRange", 30f, "How far Unstuck may move you, in world units.", 1f, 100f);
BedSaveWhenRested = config.Bind<bool>("Tweaks", "BedSaveWhenRested", false, "Saves the game when you use the bed with full energy and the Keeper refuses to sleep. The game only saves when you actually sleep.");
TechPointCap = TimbnConfig.BindRange<int>(config, "Tweaks", "TechPointCap", 999, "The most red, green, or blue tech points you can hold. The game caps each at 999 and throws away anything past it. Set to 999 to keep the game's cap.", 999, 999999);
TimbnConfig.CarryOver(config, new(ConfigEntryBase, string, string)[10]
{
((ConfigEntryBase)(object)CollectStrayTechPoints, "TechPoints", "CollectStray"),
((ConfigEntryBase)(object)SermonFaithRounding, "Sermons", "FaithRounding"),
((ConfigEntryBase)(object)StuckCarriers, "Carriers", "ShowWhenStuck"),
((ConfigEntryBase)(object)BuiltEarlyQuests, "Quests", "BuiltEarly"),
((ConfigEntryBase)(object)DismantleUnreachable, "Building", "DismantleUnreachable"),
((ConfigEntryBase)(object)SoftLockedBoards, "Boards", "SoftLockedBoards"),
((ConfigEntryBase)(object)UnstuckKey, "Unstuck", "Key"),
((ConfigEntryBase)(object)UnstuckRange, "Unstuck", "Range"),
((ConfigEntryBase)(object)BedSaveWhenRested, "Bed", "SaveWhenRested"),
((ConfigEntryBase)(object)TechPointCap, "TechPoints", "Cap")
});
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "Timbn.GraveyardKeeperTwo.VanillaTweaks";
public const string PLUGIN_NAME = "Timbn Vanilla Tweaks";
public const string PLUGIN_VERSION = "1.14.0";
}
}
namespace Timbn.GraveyardKeeperTwo.VanillaTweaks.Tweaks
{
internal static class BedSaveWhenRested
{
public static void Register(TimbnFrameworkPlugin plugin)
{
plugin.Settings.While(PluginConfig.BedSaveWhenRested, (Func<IDisposable>)(() => plugin.Events.SleepRefused((Action<bool>)Save)));
}
private static void Save(bool wouldSave)
{
if (wouldSave && TimbnGame.SaveNow())
{
TimbnFrameworkPlugin<Plugin>.Logger.LogInfo((object)"Saved from the bed without sleeping.");
}
}
}
internal sealed class BuiltEarlyQuests
{
private static readonly (string Quest, string Building, string Wgo)[] _quests = new(string, string, string)[2]
{
("74_crossroad_chore_build", "zmb_choir_unlock_s", "zmb_choir_unlock"),
("96_crossroad_organ_build", "zmb_organ_unlock_s", "zmb_organ_unlock")
};
private bool _pending;
public static void Register(TimbnFrameworkPlugin plugin)
{
BuiltEarlyQuests builtEarly = new BuiltEarlyQuests();
plugin.Settings.Toggle(PluginConfig.BuiltEarlyQuests, (Action)builtEarly.Queue, (Action)null);
plugin.Settings.While(PluginConfig.BuiltEarlyQuests, (Func<IDisposable>)(() => plugin.Events.QuestStarted((Action<QuestData>)builtEarly.OnQuestStarted)));
plugin.Settings.While(PluginConfig.BuiltEarlyQuests, (Func<IDisposable>)(() => plugin.Events.Update((Action)builtEarly.Tick)));
}
private void Queue()
{
_pending = true;
}
private void OnQuestStarted(QuestData quest)
{
(string, string, string)[] quests = _quests;
for (int i = 0; i < quests.Length; i++)
{
if (quests[i].Item1 == ((ObjectLinkedToDefinition<QuestDef>)(object)quest).id)
{
_pending = true;
}
}
}
private void Tick()
{
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Invalid comparison between Unknown and I4
if (!_pending)
{
return;
}
_pending = false;
(string, string, string)[] quests = _quests;
for (int i = 0; i < quests.Length; i++)
{
(string, string, string) tuple = quests[i];
if ((int)TimbnQuests.StatusOf(tuple.Item1).GetValueOrDefault() == 2 && TimbnPlayer.HasBuilt(tuple.Item2))
{
TimbnFrameworkPlugin<Plugin>.Logger.LogInfo((object)(tuple.Item2 + " was built before " + tuple.Item1 + " started, finishing the quest."));
TimbnQuests.FireStoryTrigger((Type)9, tuple.Item3);
}
}
}
}
internal sealed class ConveyorLoopCrash
{
private const float _half = 0.3f;
private const string _alertKey = "timbn_conveyor_loop_stuck";
private const float _expireAfter = 10f;
private const float _tickInterval = 0.5f;
private static readonly Color _red = new Color(1f, 0.15f, 0.1f, 1f);
private static readonly Color _yellow = new Color(1f, 0.85f, 0.2f, 1f);
private readonly List<ConveyorComponent> _path = new List<ConveyorComponent>();
private readonly HashSet<ConveyorComponent> _walked = new HashSet<ConveyorComponent>();
private readonly Dictionary<SGuid, GameObject> _marked = new Dictionary<SGuid, GameObject>();
private readonly HashSet<SGuid> _reported = new HashSet<SGuid>();
private readonly Dictionary<SGuid, float> _lastCaught = new Dictionary<SGuid, float>();
private Material? _material;
public static ConveyorLoopCrash Register(TimbnFrameworkPlugin plugin)
{
ConveyorLoopCrash conveyorLoopCrash = new ConveyorLoopCrash();
plugin.Settings.Toggle(PluginConfig.ConveyorLoopCrash, (Action)conveyorLoopCrash.Restore, (Action)conveyorLoopCrash.Restore);
plugin.Settings.While(PluginConfig.ConveyorLoopCrash, (Func<IDisposable>)(() => plugin.Events.EveryRealSeconds(0.5f, (Action)conveyorLoopCrash.Tick)));
plugin.Events.SaveClosed((Action)conveyorLoopCrash.Restore);
return conveyorLoopCrash;
}
public bool Enter(ConveyorComponent component, ConveyorComponent cycleStart, out bool entered)
{
entered = false;
if (!PluginConfig.ConveyorLoopCrash.Value)
{
return true;
}
if (!_walked.Add(component))
{
Highlight(component, cycleStart);
return false;
}
_path.Add(component);
entered = true;
return true;
}
public void Exit(bool entered)
{
if (entered)
{
_path.RemoveAt(_path.Count - 1);
if (_path.Count == 0)
{
_walked.Clear();
}
}
}
private void Tick()
{
if (!TimbnGame.IsInGame)
{
return;
}
foreach (SGuid item in _lastCaught.Keys.ToList())
{
if (!(Time.time - _lastCaught[item] < 10f) || TimbnWorld.Find(item) == null)
{
_lastCaught.Remove(item);
_reported.Remove(item);
if (_marked.Remove(item, out GameObject value) && (Object)(object)value != (Object)null)
{
Object.Destroy((Object)(object)value);
}
}
}
}
private void Restore()
{
ClearMarkers();
_reported.Clear();
_lastCaught.Clear();
_path.Clear();
_walked.Clear();
if ((Object)(object)_material != (Object)null)
{
Object.Destroy((Object)(object)_material);
}
_material = null;
}
private void ClearMarkers()
{
foreach (GameObject value in _marked.Values)
{
if ((Object)(object)value != (Object)null)
{
Object.Destroy((Object)(object)value);
}
}
_marked.Clear();
}
private void Highlight(ConveyorComponent repeated, ConveyorComponent cycleStart)
{
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: Unknown result type (might be due to invalid IL or missing references)
//IL_0169: Unknown result type (might be due to invalid IL or missing references)
int num = _path.IndexOf(repeated);
if (num < 0 || repeated.wasPerformedItemTransfer || repeated.ParentsData.Values.Contains(cycleStart.WgoData))
{
return;
}
List<ConveyorComponent> list = _path.Skip(num).ToList();
List<Vector3> ring = Enumerable.Reverse(list).Select(delegate(ConveyorComponent component)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
ConveyorWgoData wgoData2 = component.WgoData;
return (wgoData2 == null) ? Vector3.zero : ((WgoData)wgoData2).Position;
}).ToList();
ConveyorWgoData wgoData = (((IEnumerable<ConveyorComponent>)list).FirstOrDefault((Func<ConveyorComponent, bool>)((ConveyorComponent component) => component is ConveyorSplitterComponent)) ?? list[0]).WgoData;
if (wgoData != null)
{
_lastCaught[((WgoData)wgoData).UniqueId] = Time.time;
if (_reported.Add(((WgoData)wgoData).UniqueId))
{
TimbnFrameworkPlugin<Plugin>.Logger.LogWarning((object)($"Conveyor loop of {list.Count} pieces would never end. Removing the {((ObjectLinkedToDefinition<WGODef>)(object)wgoData).id} at " + $"({((WgoData)wgoData).Position.x:0.0}, {((WgoData)wgoData).Position.z:0.0}) breaks it."));
TimbnUI.NotifyOnce("timbn_conveyor_loop_stuck");
}
if (!PluginConfig.HighlightConveyorLoops.Value)
{
ClearMarkers();
}
else if (!_marked.ContainsKey(((WgoData)wgoData).UniqueId))
{
_marked[((WgoData)wgoData).UniqueId] = Mark(((WgoData)wgoData).Position, ring);
}
}
}
private GameObject Mark(Vector3 position, List<Vector3> ring)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Expected O, but got Unknown
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
//IL_0101: Unknown result type (might be due to invalid IL or missing references)
//IL_0106: Unknown result type (might be due to invalid IL or missing references)
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_0122: Unknown result type (might be due to invalid IL or missing references)
//IL_0123: Unknown result type (might be due to invalid IL or missing references)
//IL_012a: Unknown result type (might be due to invalid IL or missing references)
//IL_012c: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_0139: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Unknown result type (might be due to invalid IL or missing references)
//IL_014b: Unknown result type (might be due to invalid IL or missing references)
//IL_0150: Unknown result type (might be due to invalid IL or missing references)
//IL_015a: Unknown result type (might be due to invalid IL or missing references)
//IL_015f: Unknown result type (might be due to invalid IL or missing references)
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
//IL_0162: Unknown result type (might be due to invalid IL or missing references)
//IL_0164: Unknown result type (might be due to invalid IL or missing references)
//IL_016e: Unknown result type (might be due to invalid IL or missing references)
//IL_0173: Unknown result type (might be due to invalid IL or missing references)
//IL_017a: Unknown result type (might be due to invalid IL or missing references)
//IL_017f: Unknown result type (might be due to invalid IL or missing references)
//IL_0184: Unknown result type (might be due to invalid IL or missing references)
//IL_0189: Unknown result type (might be due to invalid IL or missing references)
//IL_019b: Unknown result type (might be due to invalid IL or missing references)
//IL_019d: Unknown result type (might be due to invalid IL or missing references)
//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
//IL_01be: Unknown result type (might be due to invalid IL or missing references)
//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
//IL_01da: Unknown result type (might be due to invalid IL or missing references)
//IL_01df: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("Timbn conveyor loop marker");
float num = position.y + 0.05f;
AddLine(val, true, _red, 0.07f, new Vector3(position.x - 0.3f, num, position.z - 0.3f), new Vector3(position.x - 0.3f, num, position.z + 0.3f), new Vector3(position.x + 0.3f, num, position.z + 0.3f), new Vector3(position.x + 0.3f, num, position.z - 0.3f));
for (int i = 0; i < ring.Count; i++)
{
Vector3 val2 = ring[i] + Vector3.up * 0.05f;
Vector3 val3 = ring[(i + 1) % ring.Count] + Vector3.up * 0.05f;
AddLine(val, false, _yellow, 0.05f, val2, val3);
Vector3 val4 = val3 - val2;
Vector3 normalized = ((Vector3)(ref val4)).normalized;
Vector3 val5 = Vector3.Cross(normalized, Vector3.up) * 0.1f;
Vector3 val6 = (val2 + val3) / 2f + normalized * 0.12f;
AddLine(val, false, _yellow, 0.05f, val6 - normalized * 0.15f + val5, val6, val6 - normalized * 0.15f - val5);
}
return val;
}
private void AddLine(GameObject parent, bool loop, Color color, float width, params Vector3[] points)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
LineRenderer obj = new GameObject("line").AddComponent<LineRenderer>();
((Component)obj).transform.SetParent(parent.transform, false);
((Renderer)obj).sharedMaterial = _material ?? (_material = CreateMaterial());
obj.useWorldSpace = true;
obj.loop = loop;
obj.widthMultiplier = width;
Color startColor = (obj.endColor = color);
obj.startColor = startColor;
((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
((Renderer)obj).receiveShadows = false;
obj.positionCount = points.Length;
obj.SetPositions(points);
}
private static Material CreateMaterial()
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Expected O, but got Unknown
Material val = new Material(Shader.Find("Hidden/Internal-Colored") ?? Shader.Find("Sprites/Default"));
val.SetInt("_ZTest", 8);
val.SetInt("_ZWrite", 0);
val.SetInt("_Cull", 0);
val.renderQueue = 4000;
return val;
}
}
internal static class LostItems
{
private sealed class LostItem
{
public string TalkId { get; }
public string Id { get; }
public int Count { get; }
public Lines Lines { get; }
public LostItem(string talkId, string id, int count, Func<bool> isEnabled, Func<bool> isNeeded, Lines lines)
{
<isEnabled>P = isEnabled;
<isNeeded>P = isNeeded;
TalkId = talkId;
Id = id;
Count = count;
Lines = lines;
base..ctor();
}
public bool IsLost()
{
if (<isEnabled>P() && <isNeeded>P())
{
return TimbnItems.CountAnywhere(Id, Count) < Count;
}
return false;
}
}
private sealed class Lines(string asked, string found, string accept, string given, string thanks, string decline, string declined)
{
public string Asked { get; } = asked;
public string Found { get; } = found;
public string Accept { get; } = accept;
public string Given { get; } = given;
public string Thanks { get; } = thanks;
public string Decline { get; } = decline;
public string Declined { get; } = declined;
}
private const string _npcId = "npc_larry";
private static readonly string[] _boardMakerIds = new string[4] { "sawhorse", "sawhorse_place", "circular_saw", "circular_saw_place" };
private static readonly LostItem[] _items = new LostItem[2]
{
new LostItem("timbn_larry_boards_talk", "flitch", 2, () => PluginConfig.SoftLockedBoards.Value, () => TimbnPlayer.HasTech("wood_basic") && !_boardMakerIds.Any((string id) => TimbnWorld.FindAll(id).Count > 0), new Lines("I may have run out of boards with no way to get more.", "No sawhorse, no boards. No boards, no sawhorse...", "Got any boards lying around?", "Lucky for you, there are a few spare boards in my box. Here you go.", "Thank you, I will be more careful next time.", "I'll figure something out.", "Suit yourself... I'll be right here.")),
new LostItem("timbn_larry_medallion_talk", "intro_prison_medallion", 1, () => PluginConfig.LostQuestItems.Value, delegate
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Invalid comparison between Unknown and I4
if (TimbnQuests.HasStarted("1_intro_prison_find_key"))
{
QuestStatus? val = TimbnQuests.StatusOf("22_doctor_tower_door");
return !val.HasValue || (int)val.GetValueOrDefault() != 3;
}
return false;
}, new Lines("Have you seen an Inquisitor's medallion anywhere?", "Funny thing, one rolled up against my box this morning.", "That's the one! Can I have it back?", "Here you go.", "Thank you, Larry. I'll hold on to it this time.", "No, that can't be mine.", "Suit yourself..."))
};
public static void Register(TimbnFrameworkPlugin plugin)
{
LostItem[] items = _items;
foreach (LostItem item in items)
{
Lines lines = item.Lines;
plugin.Dialog.AddTalk("npc_larry", item.TalkId, (Func<bool>)item.IsLost, (Action<TimbnLines>)delegate(TimbnLines talk)
{
((TimbnTalk<TimbnLines>)(object)((TimbnTalk<TimbnLines>)(object)((TimbnTalk<TimbnLines>)(object)talk).PlayerSay(lines.Asked, Array.Empty<object>())).Say(lines.Found, Array.Empty<object>())).Ask((Action<TimbnAsk>)delegate(TimbnAsk ask)
{
ask.Answer(lines.Accept, (Action<TimbnLines>)delegate(TimbnLines then)
{
((TimbnTalk<TimbnLines>)(object)((TimbnTalk<TimbnLines>)(object)((TimbnTalk<TimbnLines>)(object)then).Give(item.Id, item.Count)).Say(lines.Given, Array.Empty<object>())).PlayerSay(lines.Thanks, Array.Empty<object>());
}, (Action<TimbnNeeds>)null, (Action<TimbnCost>)null, (Action<TimbnRewards>)null, (string)null).Answer(lines.Decline, (Action<TimbnLines>)delegate(TimbnLines then)
{
((TimbnTalk<TimbnLines>)(object)then).Say(lines.Declined, Array.Empty<object>());
}, (Action<TimbnNeeds>)null, (Action<TimbnCost>)null, (Action<TimbnRewards>)null, (string)null);
});
}, (TimbnTalkOptions)null);
}
}
}
internal static class MoveIdenticalFromBags
{
public static bool Applies(Inventory target, Inventory? source)
{
if (PluginConfig.MoveIdenticalFromBags.Value && source != null)
{
PlayerData playerData = MainGame.PlayerData;
if (source == ((playerData != null) ? playerData.Inventory : null) && target.Data != null)
{
return !target.Data.IsBag;
}
}
return false;
}
}
internal sealed class SortIntoBags
{
private const string _universalBagGroup = "u_bag";
private bool _movingFromChest;
public void BeginMove(Inventory from, Inventory to)
{
int movingFromChest;
if (PluginConfig.SortIntoBags.Value && IsPlayerInventory(to.Data) && !IsPlayerInventory(from.Data))
{
Item data = from.Data;
if (data != null && !data.IsBag)
{
movingFromChest = ((from != MainGame.PlayerData.toolBeltInventory) ? 1 : 0);
goto IL_004c;
}
}
movingFromChest = 0;
goto IL_004c;
IL_004c:
_movingFromChest = (byte)movingFromChest != 0;
}
public void EndMove()
{
_movingFromChest = false;
}
public bool TreatAsPickup(Item inventory)
{
if (_movingFromChest)
{
return IsPlayerInventory(inventory);
}
return false;
}
public static bool TryFill(Item inventory, Item sourceItem, Item? ignoredBag, bool ignoreAllBags, out List<Item> addedItems)
{
addedItems = new List<Item>();
if (!PluginConfig.SortIntoBags.Value || ignoreAllBags || sourceItem == null || sourceItem.IsEmpty || sourceItem.Count <= 0 || sourceItem.IsBag || !IsPlayerInventory(inventory))
{
return false;
}
List<Item> collection = default(List<Item>);
foreach (Item item in (from bag in inventory.Inventory
where IsMatchingBag(bag, sourceItem, ignoredBag)
orderby bag.GetTotalCountInInventory(((ObjectLinkedToDefinition<ItemDef>)(object)sourceItem).id, (Item)null, false) > 0 descending
select bag).ToList())
{
if (item.AddItemToInventory(sourceItem, ref collection, (Item)null, true))
{
addedItems.AddRange(collection);
}
if (sourceItem.Count <= 0 || (((ObjectLinkedToDefinition<ItemDef>)(object)sourceItem).Definition.stackCount == 1 && addedItems.Count > 0))
{
break;
}
}
return addedItems.Count > 0;
}
private static bool IsMatchingBag(Item bag, Item sourceItem, Item? ignoredBag)
{
if (bag.IsBag && !((ObjectLinkedToDefinition<ItemDef>)(object)bag).Definition.bagItemGroups.Contains("u_bag") && ((ObjectLinkedToDefinition<ItemDef>)(object)sourceItem).Definition.CanBeInsertedInBag(((ObjectLinkedToDefinition<ItemDef>)(object)bag).Definition))
{
if (ignoredBag != null)
{
return bag.UniqueId.Guid != ignoredBag.UniqueId.Guid;
}
return true;
}
return false;
}
private static bool IsPlayerInventory(Item? inventory)
{
if (inventory != null)
{
PlayerData playerData = MainGame.PlayerData;
object obj;
if (playerData == null)
{
obj = null;
}
else
{
Inventory inventory2 = playerData.Inventory;
obj = ((inventory2 != null) ? inventory2.Data : null);
}
return inventory == obj;
}
return false;
}
}
internal sealed class StrayTechPoints
{
private const float _interval = 1f;
private const float _collectDuration = 1f;
private static readonly FieldRef<List<TechPointDrop>> _activeDrops = AccessTools.StaticFieldRefAccess<List<TechPointDrop>>(AccessTools.Field(typeof(TechPointDrop), "activeDrops"));
private static readonly FieldRef<TechPointDrop, bool> _isTimedCollecting = AccessTools.FieldRefAccess<TechPointDrop, bool>("isTimedCollecting");
private static readonly FieldRef<TechPointDrop, float> _curTime = AccessTools.FieldRefAccess<TechPointDrop, float>("curTime");
private static readonly FieldRef<TechPointDrop, float> _collectDelay = AccessTools.FieldRefAccess<TechPointDrop, float>("collectDelay");
private static readonly FieldRef<TechPointDrop, float> _magnetRadius = AccessTools.FieldRefAccess<TechPointDrop, float>("magnetRadius");
private readonly HashSet<TechPointDrop> _offMeshLastCheck = new HashSet<TechPointDrop>();
public static void Register(TimbnFrameworkPlugin plugin)
{
StrayTechPoints strayTechPoints = new StrayTechPoints();
plugin.Settings.Toggle(PluginConfig.CollectStrayTechPoints, (Action)strayTechPoints.Reset, (Action)strayTechPoints.Reset);
plugin.Settings.While(PluginConfig.CollectStrayTechPoints, (Func<IDisposable>)(() => plugin.Events.EveryRealSeconds(1f, (Action)strayTechPoints.Tick)));
}
private void Reset()
{
_offMeshLastCheck.Clear();
}
private void Tick()
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
PlayerController playerController = MainGame.PlayerController;
RecastGraph val = (((Object)(object)playerController != (Object)null) ? playerController.SceneRecastGraph : null);
if (val == null)
{
_offMeshLastCheck.Clear();
return;
}
Vector3 position = ((Component)playerController).transform.position;
List<TechPointDrop> list = new List<TechPointDrop>();
foreach (TechPointDrop item in _activeDrops.Invoke())
{
if (!((Object)(object)item == (Object)null) && !_isTimedCollecting.Invoke(item) && !(_curTime.Invoke(item) < _collectDelay.Invoke(item)))
{
Vector3 position2 = ((Component)item).transform.position;
Vector3 val2 = VectorExtensions.XZ(position - position2);
if (!(((Vector3)(ref val2)).sqrMagnitude <= _magnetRadius.Invoke(item)) && !((NavGraph)val).IsPointOnNavmesh(VectorExtensions.XZ(position2)))
{
list.Add(item);
}
}
}
foreach (TechPointDrop item2 in list)
{
if (_offMeshLastCheck.Contains(item2))
{
item2.MoveToCollectorTimed(((Component)playerController).transform, 1f);
}
}
_offMeshLastCheck.Clear();
_offMeshLastCheck.UnionWith(list);
}
}
internal sealed class StuckCarriers
{
private const float _interval = 0.5f;
private HashSet<ZombieWgoData> _stuck = new HashSet<ZombieWgoData>();
public static bool IsStuck(ZombieWgoData zombie)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Invalid comparison between Unknown and I4
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Invalid comparison between Unknown and I4
if ((int)zombie.ZombieType == 2)
{
return (int)zombie.CaretakerState == 11;
}
return false;
}
public static void Register(TimbnFrameworkPlugin plugin)
{
StuckCarriers stuckCarriers = new StuckCarriers();
plugin.Settings.Toggle(PluginConfig.StuckCarriers, (Action)stuckCarriers.Reset, (Action)stuckCarriers.Revert);
plugin.Settings.While(PluginConfig.StuckCarriers, (Func<IDisposable>)(() => plugin.Events.EveryRealSeconds(0.5f, (Action)stuckCarriers.Tick)));
}
private void Tick()
{
HashSet<ZombieWgoData> stuck = TimbnZombies.All().Where(IsStuck).ToHashSet();
foreach (ZombieWgoData item in stuck.Where((ZombieWgoData z) => !_stuck.Contains(z)))
{
Redraw(item);
WalkToStation(item);
TimbnFrameworkPlugin<Plugin>.Logger.LogInfo((object)($"Zombie supplier {item.Name} has nowhere to put {item.CaretakerPortableItem.Count} " + ((ObjectLinkedToDefinition<ItemDef>)(object)item.CaretakerPortableItem).id + " in " + ((ObjectLinkedToDefinition<WorldZoneDef>)(object)((WgoData)item).WorldZoneData)?.id + "."));
}
foreach (ZombieWgoData item2 in _stuck.Where((ZombieWgoData z) => !stuck.Contains(z)))
{
Redraw(item2);
}
_stuck = stuck;
}
public void Reset()
{
_stuck.Clear();
}
public void Revert()
{
if (TimbnGame.IsInGame)
{
foreach (ZombieWgoData item in _stuck)
{
Redraw(item);
}
}
_stuck.Clear();
}
private static void Redraw(ZombieWgoData zombie)
{
Wgo obj = TimbnWorld.ViewOf((WgoData)(object)zombie);
if (obj != null)
{
obj.DrawWidgets();
}
}
private static void WalkToStation(ZombieWgoData zombie)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
WorldZoneData worldZoneData = ((WgoData)zombie).WorldZoneData;
WgoData attachedWgoData = zombie.AttachedWgoData;
MovementComponent movementComponent = ((WgoData)zombie).MovementComponent;
if (worldZoneData != null && attachedWgoData != null && movementComponent != null && !movementComponent.IsMoving)
{
DockPointData nearestDockPointData = attachedWgoData.GetNearestDockPointData(((WgoData)zombie).Position, (Availability)0);
Vector3 nearestDockPointDataWorldPositionOrMyPosition = attachedWgoData.GetNearestDockPointDataWorldPositionOrMyPosition(((WgoData)zombie).Position, (Availability)1, (Func<DockPointData, Vector3, bool>)((DockPointData point, Vector3 _) => !point.BakedData.DisableTargetingForCaretaker));
GraphMask val = NavigationGraphMaskUtils.ToGraphMask((IEnumerable<Graph>)worldZoneData.MovementGraphs, worldZoneData.navigationGraph);
if (nearestDockPointData != null)
{
movementComponent.StartPath(nearestDockPointDataWorldPositionOrMyPosition, nearestDockPointData.BakedData, val, ((WgoData)zombie).WorldId, 1.5f, "", (Action)null);
}
else
{
movementComponent.StartPath(nearestDockPointDataWorldPositionOrMyPosition, val, ((WgoData)zombie).WorldId, 1.5f, "", (Action)null, (DestinationType)0);
}
}
}
}
internal static class StuckResourceWorkers
{
private sealed class Station(string prefix, string standId, string builderId)
{
public string Prefix { get; } = prefix;
public string StandId { get; } = standId;
public string BuilderId { get; } = builderId;
public string PointKey => Prefix + "_point";
public string WaitFlag => "wait_for_zombie_at_" + Prefix;
public string WorkEvent => Prefix + "_craft_start";
}
private const string _craftStartEvent = "craft_start";
private static readonly Station[] _stations = new Station[4]
{
new Station("sawmill", "sawmill_wood_crafter", "builder_sawmill"),
new Station("mine", "mine_ore_coal_crafter", "builder_mine"),
new Station("clay", "clay_zombie_crafter", "builder_clay_sand"),
new Station("sand", "sand_zombie_crafter", "builder_clay_sand")
};
public static void Register(TimbnFrameworkPlugin plugin)
{
plugin.Settings.Toggle(PluginConfig.StuckResourceWorkers, (Action)Repair, (Action)null);
}
public static void Repair()
{
if (!PluginConfig.StuckResourceWorkers.Value)
{
return;
}
Station[] stations = _stations;
foreach (Station station in stations)
{
WgoData builder = TimbnWorld.Find(station.BuilderId);
if (builder == null)
{
continue;
}
List<ZombieWgoData> source = Workers(station).ToList();
HashSet<string> held = new HashSet<string>();
foreach (ZombieWgoData item in source.Where((ZombieWgoData z) => ((WgoData)z).GameResStr.Has(station.PointKey)))
{
if (HasLeftSpot(item, station))
{
((WgoData)item).GameResStr.Remove(station.PointKey);
}
else
{
held.Add(((WgoData)item).GameResStr.Get(station.PointKey, ""));
}
}
List<string> list = new List<string>();
while (TimbnWorld.Point($"{station.Prefix}_zombie_{list.Count + 1}") != null)
{
list.Add($"{station.Prefix}_zombie_{list.Count + 1}");
}
foreach (string item2 in list.Where((string p) => builder.GetGameResInt(p) == 1 && !held.Contains(p)))
{
builder.SetGameRes(item2, 0);
TimbnFrameworkPlugin<Plugin>.Logger.LogInfo((object)("Freed work spot " + item2 + ", which no " + station.Prefix + " zombie was using."));
}
int count = list.Count((string p) => builder.GetGameResInt(p) == 0);
foreach (ZombieWgoData item3 in source.Where((ZombieWgoData z) => IsStranded(z, station)).Take(count))
{
TimbnFrameworkPlugin<Plugin>.Logger.LogInfo((object)("Sent a stranded " + station.StandId + " zombie back to work."));
item3.AttachedWgoData.FireEvent("craft_start");
}
}
}
public static void OnDetaching(ZombieWgoData zombie)
{
if (!PluginConfig.StuckResourceWorkers.Value)
{
return;
}
Station station = Find(zombie.AttachedWgoData);
if (station == null || !((WgoData)zombie).GameResStr.Has(station.PointKey))
{
return;
}
string text = ((WgoData)zombie).GameResStr.Get(station.PointKey, "");
if (IsHolding(zombie, station))
{
WgoData obj = TimbnWorld.Find(station.BuilderId);
if (obj != null)
{
obj.SetGameRes(text, 0);
}
TimbnFrameworkPlugin<Plugin>.Logger.LogInfo((object)("Freed work spot " + text + " as its zombie left the " + station.StandId + "."));
}
((WgoData)zombie).GameResStr.Remove(station.PointKey);
}
private static bool IsHolding(ZombieWgoData zombie, Station station)
{
WgoData attachedWgoData = zombie.AttachedWgoData;
object obj;
if (attachedWgoData == null)
{
obj = null;
}
else
{
CraftComponent craftComponent = attachedWgoData.CraftComponent;
obj = ((craftComponent != null) ? craftComponent.CurrentCraftElement : null);
}
if (obj != null)
{
return !HasLeftSpot(zombie, station);
}
return false;
}
private static bool HasLeftSpot(ZombieWgoData zombie, Station station)
{
WgoData attachedWgoData = zombie.AttachedWgoData;
object obj;
if (attachedWgoData == null)
{
obj = null;
}
else
{
CraftComponent craftComponent = attachedWgoData.CraftComponent;
obj = ((craftComponent != null) ? craftComponent.CurrentCraftElement : null);
}
CraftElementBase val = (CraftElementBase)obj;
if (val == null)
{
return false;
}
MovementComponent movementComponent = ((WgoData)zombie).MovementComponent;
if (val.ParamsData.customRes.GetInt(station.WaitFlag) == 1)
{
if (movementComponent.IsMoving)
{
return !(movementComponent.OnPathCompleteEvent == station.WorkEvent);
}
return true;
}
return false;
}
private static bool IsStranded(ZombieWgoData zombie, Station station)
{
CraftComponent craftComponent = zombie.AttachedWgoData.CraftComponent;
CraftElementBase val = ((craftComponent != null) ? craftComponent.CurrentCraftElement : null);
if (val != null && val.IsStarted && val.ParamsData.customRes.GetInt(station.WaitFlag) == 1 && !((WgoData)zombie).MovementComponent.IsMoving)
{
return !((WgoData)zombie).GameResStr.Has(station.PointKey);
}
return false;
}
private static Station? Find(WgoData? stand)
{
if (stand != null)
{
return _stations.FirstOrDefault((Station s) => s.StandId == ((ObjectLinkedToDefinition<WGODef>)(object)stand).id);
}
return null;
}
private static IEnumerable<ZombieWgoData> Workers(Station station)
{
return (from stand in TimbnWorld.FindAll(station.StandId)
select stand.Worker).OfType<ZombieWgoData>();
}
}
internal static class TechPointCap
{
private const int _gameCap = 999;
private static readonly string[] _resourceIds = new string[3] { "tech_red", "tech_green", "tech_blue" };
public static void Register(TimbnFrameworkPlugin plugin)
{
string[] resourceIds = _resourceIds;
foreach (string id in resourceIds)
{
plugin.Settings.While<int>(PluginConfig.TechPointCap, (Func<int, bool>)((int cap) => cap > 999), (Func<IDisposable>)(() => Edit(plugin, id)));
}
}
private static IDisposable Edit(TimbnFrameworkPlugin plugin, string id)
{
LazyExpression original = null;
return plugin.Balance.Edit<GameResSystemDef>(id, (Action<GameResSystemDef>)delegate(GameResSystemDef definition)
{
original = null;
int value = PluginConfig.TechPointCap.Value;
float num = definition.max.EvaluateFloat();
if (num >= (float)value)
{
TimbnFrameworkPlugin<Plugin>.Logger.LogInfo((object)$"{id} already caps at {num}, leaving it alone.");
}
else
{
original = definition.max;
definition.max = TimbnBalance.Expression(value.ToString(CultureInfo.InvariantCulture));
TimbnFrameworkPlugin<Plugin>.Logger.LogInfo((object)$"{id} now caps at {value}.");
}
}, (Action<GameResSystemDef>)delegate(GameResSystemDef definition)
{
if (original != null)
{
definition.max = original;
original = null;
}
});
}
}
internal sealed class UnreachableDismantle
{
private DockPoint? _standIn;
private WgoData? _station;
private bool _on;
public static UnreachableDismantle Register(TimbnFrameworkPlugin plugin)
{
UnreachableDismantle unreachableDismantle = new UnreachableDismantle();
plugin.Settings.Toggle(PluginConfig.DismantleUnreachable, (Action)unreachableDismantle.Apply, (Action)unreachableDismantle.Revert);
return unreachableDismantle;
}
public void Apply()
{
_on = true;
}
public void Revert()
{
_on = false;
if ((Object)(object)_standIn != (Object)null)
{
Object.Destroy((Object)(object)((Component)_standIn).gameObject);
}
_standIn = null;
_station = null;
}
public DockPoint? StandInFor(PlayerWorkComponent work, Wgo station, Transform player, Vector2 facing)
{
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
if (!_on || (Object)(object)station == (Object)null || (Object)(object)station.MainWgoPart == (Object)null || !IsMarkedForDismantle(station.Data) || !work.CanWorkOn(station.Data))
{
return null;
}
if (_station != station.Data)
{
TimbnFrameworkPlugin<Plugin>.Logger.LogInfo((object)("Working " + ((ObjectLinkedToDefinition<WGODef>)(object)station.Data).id + " from where you stand, since none of its work spots can be reached."));
}
_station = station.Data;
DockPoint standIn = GetStandIn();
standIn.Init(station.MainWgoPart);
standIn.direction = DirectionExtensions.ConvertFromVector2(facing);
((Component)standIn).transform.position = player.position;
return standIn;
}
public bool TryGetDropPosition(WgoData data, out Vector3 position)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
position = TimbnPlayer.Position;
if (_on && data == _station)
{
return IsMarkedForDismantle(data);
}
return false;
}
private static bool IsMarkedForDismantle(WgoData? data)
{
if (data == null)
{
return false;
}
CraftComponent craftComponent = data.CraftComponent;
return ((craftComponent != null) ? new bool?(craftComponent.IsDestroyingCraftActive) : ((bool?)null)) == true;
}
private DockPoint GetStandIn()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Expected O, but got Unknown
if ((Object)(object)_standIn != (Object)null)
{
return _standIn;
}
GameObject val = new GameObject("VanillaTweaks stand in dock point")
{
hideFlags = (HideFlags)61
};
Object.DontDestroyOnLoad((Object)(object)val);
_standIn = val.AddComponent<DockPoint>();
return _standIn;
}
}
internal static class Unstuck
{
private const float _step = 0.5f;
private const float _clearance = 0.3f;
private const int _blockingLayers = 257;
private const float _fallbackDistance = 1f;
public static bool Run(float range)
{
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
NavGraph val = default(NavGraph);
if (!TimbnGame.IsInGame || !TimbnWorld.TryGetNavGraph((string)null, ref val))
{
TimbnFrameworkPlugin<Plugin>.Logger.LogWarning((object)"No recast graph in this scene.");
return false;
}
Dictionary<uint, int> areaSizes = new Dictionary<uint, int>();
int value2;
val.GetNodes((Action<GraphNode>)delegate(GraphNode val4)
{
if (val4.Walkable)
{
areaSizes[val4.Area] = ((!areaSizes.TryGetValue(val4.Area, out value2)) ? 1 : (value2 + 1));
}
});
Vector3 position = TimbnPlayer.Position;
GraphNode node = val.GetNearest(position).node;
int value;
int hereSize = ((node != null && areaSizes.TryGetValue(node.Area, out value)) ? value : 0);
bool overlapping = IsBlocked(position);
HashSet<string> zones = WorldZonesAt(position);
Vector3? val2 = FindOpenGround(val, position, 0f, range, zones, (GraphNode val4) => overlapping || (areaSizes.TryGetValue(val4.Area, out value2) ? value2 : 0) > hereSize);
Vector3? val3 = val2;
if (!val3.HasValue)
{
val2 = FindOpenGround(val, position, 1f, range, zones, (GraphNode _) => true);
}
if (!val2.HasValue)
{
TimbnFrameworkPlugin<Plugin>.Logger.LogWarning((object)$"No open ground within {range:0} m.");
return false;
}
TimbnPlayer.TeleportTo(val2.Value);
TimbnFrameworkPlugin<Plugin>.Logger.LogMessage((object)$"Unstuck, moved {Vector3.Distance(position, val2.Value):0.0} m.");
return true;
}
private static Vector3? FindOpenGround(NavGraph graph, Vector3 from, float minDistance, float range, HashSet<string> zones, Func<GraphNode, bool> accept)
{
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
for (float num = Mathf.Max(0.5f, minDistance); num <= range; num += 0.5f)
{
int num2 = Mathf.Max(8, Mathf.CeilToInt(MathF.PI * 2f * num / 0.5f));
for (int i = 0; i < num2; i++)
{
float num3 = MathF.PI * 2f * (float)i / (float)num2;
Vector3 val = from + new Vector3(Mathf.Cos(num3), 0f, Mathf.Sin(num3)) * num;
NNInfo nearest = graph.GetNearest(val);
if (nearest.node != null && nearest.node.Walkable && !(Vector3.Distance(val, nearest.position) > 0.3f) && accept(nearest.node) && !IsBlocked(nearest.position) && SharesZone(zones, nearest.position))
{
return nearest.position;
}
}
}
return null;
}
private static bool SharesZone(HashSet<string> zones, Vector3 position)
{
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
if (zones.Count != 0)
{
return zones.Overlaps(WorldZonesAt(position));
}
return true;
}
private static HashSet<string> WorldZonesAt(Vector3 position)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
HashSet<string> hashSet = new HashSet<string>();
foreach (string item in from zone in TimbnWorld.ZonesAt(position, (GameSceneData)null)
select ((ObjectLinkedToDefinition<WorldZoneDef>)(object)zone).id)
{
hashSet.Add(item);
}
return hashSet;
}
private static bool IsBlocked(Vector3 position)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
Transform transform = ((Component)MainGame.PlayerController).transform;
Collider[] array = Physics.OverlapSphere(position, 0.3f, 257);
foreach (Collider val in array)
{
if (!val.isTrigger && !((Component)val).transform.IsChildOf(transform))
{
return true;
}
}
return false;
}
}
}
namespace Timbn.GraveyardKeeperTwo.VanillaTweaks.Patches
{
[TimbnFeature("ConveyorLoopCrash")]
[HarmonyPatch]
internal static class ConveyorComponentPatch
{
private static IEnumerable<MethodBase> TargetMethods()
{
return from type in typeof(ConveyorComponent).Assembly.GetTypes()
where type.IsSubclassOf(typeof(ConveyorComponent))
select type.GetMethod("HandleCycleDependency", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public) into method
where method != null
select method;
}
[HarmonyPrefix]
private static bool HandleCycleDependencyPreFix(ConveyorComponent __instance, ConveyorComponent __0, out bool __state)
{
__state = false;
return TimbnFrameworkPlugin<Plugin>.Instance?.ConveyorLoops.Enter(__instance, __0, out __state) ?? true;
}
[HarmonyFinalizer]
private static void HandleCycleDependencyFinalizer(bool __state)
{
TimbnFrameworkPlugin<Plugin>.Instance?.ConveyorLoops.Exit(__state);
}
}
[TimbnFeature("MoveIdenticalFromBags")]
[HarmonyPatch(typeof(Inventory))]
internal static class InventoryPatch
{
[HarmonyPatch("TakeAllItemsExistingInMeFromOtherInventory")]
[HarmonyPrefix]
private static void TakeAllItemsExistingInMeFromOtherInventoryPreFix(Inventory __instance, Inventory otherInventory, ref bool ignoreOtherBags)
{
if (MoveIdenticalFromBags.Applies(__instance, otherInventory))
{
ignoreOtherBags = false;
}
}
[HarmonyPatch("CanTakeAnyItemsExistingInMeFromOtherInventory")]
[HarmonyPrefix]
private static void CanTakeAnyItemsExistingInMeFromOtherInventoryPreFix(Inventory __instance, Inventory otherInventory, ref bool ignoreOtherBags)
{
if (MoveIdenticalFromBags.Applies(__instance, otherInventory))
{
ignoreOtherBags = false;
}
}
}
[TimbnFeature("SortIntoBags")]
[HarmonyPatch(typeof(InventoryUIItemMoveOpHandler))]
internal static class InventoryUIItemMoveOpHandlerPatch
{
[HarmonyPatch("TryMoveItem")]
[HarmonyPrefix]
private static void TryMoveItemPreFix(Inventory from, Inventory to)
{
TimbnFrameworkPlugin<Plugin>.Instance?.BagSorting.BeginMove(from, to);
}
[HarmonyPatch("TryMoveItem")]
[HarmonyFinalizer]
private static void TryMoveItemFinalizer()
{
TimbnFrameworkPlugin<Plugin>.Instance?.BagSorting.EndMove();
}
}
[TimbnFeature("SortIntoBags")]
[HarmonyPatch(typeof(Item))]
internal static class ItemPatch
{
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
[HarmonyPrefix]
private static bool AddItemToInventoryPreFix(Item __instance, Item sourceItem, ref List<Item> addedItems, Item? ignoredBag, ref bool ignoreAllBags, ref bool __result, out List<Item>? __state)
{
__state = null;
Plugin instance = TimbnFrameworkPlugin<Plugin>.Instance;
if (instance != null && instance.BagSorting.TreatAsPickup(__instance))
{
ignoreAllBags = false;
}
if (!SortIntoBags.TryFill(__instance, sourceItem, ignoredBag, ignoreAllBags, out List<Item> addedItems2))
{
return true;
}
if (sourceItem.Count > 0 && ((ObjectLinkedToDefinition<ItemDef>)(object)sourceItem).Definition.stackCount > 1)
{
__state = addedItems2;
return true;
}
addedItems = addedItems2;
__result = true;
return false;
}
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
[HarmonyPostfix]
private static void AddItemToInventoryPostFix(ref List<Item> addedItems, ref bool __result, List<Item>? __state)
{
if (__state != null)
{
addedItems.InsertRange(0, __state);
__result = true;
}
}
}
[TimbnFeature("DismantleUnreachable")]
[HarmonyPatch(typeof(PlayerWorkComponent))]
internal static class PlayerWorkComponentPatch
{
[HarmonyPatch("FindNearestDockPoint")]
[HarmonyPostfix]
private static void FindNearestDockPointPostFix(PlayerWorkComponent __instance, PlayerController ___playerController, Vector2 direction, List<Wgo>? onlyWgoInList, ref DockPoint? __result)
{
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)__result == (Object)null && onlyWgoInList != null && onlyWgoInList.Count == 1)
{
Wgo station = onlyWgoInList[0];
__result = TimbnFrameworkPlugin<Plugin>.Instance?.Dismantle.StandInFor(__instance, station, ((Component)___playerController).transform, direction);
}
}
}
[TimbnFeature("SermonFaithRounding")]
[HarmonyPatch]
internal static class SermonResultDataPatch
{
private const int _snapDecimals = 4;
private static readonly MethodInfo _gameRound = AccessTools.Method(typeof(Math), "Round", new Type[2]
{
typeof(double),
typeof(MidpointRounding)
}, (Type[])null);
private static readonly MethodInfo _faithRound = AccessTools.Method(typeof(SermonResultDataPatch), "RoundFaith", (Type[])null, (Type[])null);
private static IEnumerable<MethodBase> TargetMethods()
{
yield return AccessTools.Constructor(typeof(SermonResultData), new Type[6]
{
typeof(string),
typeof(string),
typeof(int),
typeof(bool),
typeof(int),
typeof(int)
}, false);
yield return AccessTools.PropertyGetter(typeof(SermonResultData), "FaithOnlyParishioners");
yield return AccessTools.PropertyGetter(typeof(SermonResultData), "FaithOnlyBonus");
}
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
foreach (CodeInstruction instruction in instructions)
{
if (CodeInstructionExtensions.Calls(instruction, _gameRound))
{
instruction.operand = _faithRound;
}
yield return instruction;
}
}
private static double RoundFaith(double value, MidpointRounding mode)
{
return Math.Round(PluginConfig.SermonFaithRounding.Value ? Math.Round(value, 4) : value, mode);
}
}
[TimbnFeature("DismantleUnreachable")]
[HarmonyPatch(typeof(WgoData))]
internal static class WgoDataPatch
{
[HarmonyPatch("GetDropPos")]
[HarmonyPostfix]
private static void GetDropPosPostFix(WgoData __instance, ref Vector3 __result)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
Plugin instance = TimbnFrameworkPlugin<Plugin>.Instance;
if (instance != null && instance.Dismantle.TryGetDropPosition(__instance, out var position))
{
__result = position;
}
}
}
[TimbnFeature("StuckCarriers")]
[HarmonyPatch(typeof(ZombieWgoData))]
internal static class ZombieWgoDataStuckCarriersPatch
{
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
[HarmonyPostfix]
private static void ShouldShowNoStorageIconPostFix(ZombieWgoData __instance, ref bool __result)
{
if (!__result && PluginConfig.StuckCarriers.Value && StuckCarriers.IsStuck(__instance))
{
__result = true;
}
}
}
[TimbnFeature("StuckResourceWorkers")]
[HarmonyPatch(typeof(ZombieWgoData))]
internal static class ZombieWgoDataStuckResourceWorkersPatch
{
[HarmonyPatch("UnAttachFromWgoData")]
[HarmonyPrefix]
private static void UnAttachFromWgoDataPreFix(ZombieWgoData __instance)
{
StuckResourceWorkers.OnDetaching(__instance);
}
}
}