using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Logging; using Eremite.Buildings; using Eremite.Characters; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")] [assembly: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: AssemblyCompany("KeepWorking")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyDescription("Example Mod for Against The Storm")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+d6ada77561ccfe85ca4c2c807fd24c8c3fc0d51c")] [assembly: AssemblyProduct("KeepWorking")] [assembly: AssemblyTitle("KeepWorking")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.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 KeepWorking { [BepInPlugin("hugh.keepworking", "Keep Working", "1.0.0")] public class KeepWorkingPlugin : BaseUnityPlugin { internal static ManualLogSource Log; internal static Harmony HarmonyInstance; private void Awake() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; HarmonyInstance = new Harmony("hugh.keepworking"); HarmonyInstance.PatchAll(); Log.LogInfo((object)"[KeepWorking] Loaded v1.0.0 (Smart Patch: block only PrepareForMoving)."); } } internal static class KeepWorkingState { private static readonly HashSet RelocateAfterTask = new HashSet(); public static void Mark(int actorId) { if (actorId > 0) { RelocateAfterTask.Add(actorId); } } public static bool IsMarked(int actorId) { return actorId > 0 && RelocateAfterTask.Contains(actorId); } public static void Clear(int actorId) { if (actorId > 0) { RelocateAfterTask.Remove(actorId); } } } [HarmonyPatch(typeof(BuildingMover), "ResetWorkers")] internal static class BuildingMover_ResetWorkers_Patch { private static bool Prefix(BuildingMover __instance) { try { FieldInfo fieldInfo = AccessTools.Field(typeof(BuildingMover), "original"); object? value = fieldInfo.GetValue(__instance); Building val = (Building)((value is Building) ? value : null); ProductionBuilding val2 = (ProductionBuilding)(object)((val is ProductionBuilding) ? val : null); if ((Object)(object)val2 == (Object)null) { return false; } int[] workers = val2.Workers; foreach (int num in workers) { if (num > 0) { KeepWorkingState.Mark(num); KeepWorkingPlugin.Log.LogDebug((object)$"[KeepWorking] Marked actor {num} for relocation after task."); } } return false; } catch (Exception arg) { KeepWorkingPlugin.Log.LogError((object)$"[KeepWorking] Error in ResetWorkers prefix: {arg}"); return true; } } } [HarmonyPatch(typeof(ActorTask), "PrepareForMoving")] internal static class ActorTask_PrepareForMoving_Patch { private static bool Prefix(ActorTask __instance) { try { FieldInfo fieldInfo = AccessTools.Field(typeof(ActorTask), "actor"); object? value = fieldInfo.GetValue(__instance); Actor val = (Actor)((value is Actor) ? value : null); if ((Object)(object)val == (Object)null) { return true; } if (!KeepWorkingState.IsMarked(val.Id)) { return true; } KeepWorkingPlugin.Log.LogDebug((object)$"[KeepWorking] Blocked PrepareForMoving() for actor {val.Id} (movement only)."); return false; } catch (Exception arg) { KeepWorkingPlugin.Log.LogError((object)$"[KeepWorking] Error in PrepareForMoving prefix: {arg}"); return true; } } } [HarmonyPatch(typeof(ActorTask), "Complete")] internal static class ActorTask_Complete_Patch { private static void Postfix(ActorTask __instance) { //IL_0050: 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_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Invalid comparison between Unknown and I4 //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Invalid comparison between Unknown and I4 try { FieldInfo fieldInfo = AccessTools.Field(typeof(ActorTask), "actor"); object? value = fieldInfo.GetValue(__instance); Actor val = (Actor)((value is Actor) ? value : null); if ((Object)(object)val == (Object)null || !KeepWorkingState.IsMarked(val.Id)) { return; } ActorTaskType type = __instance.Type; if ((int)type == 208 || (int)type == 209) { KeepWorkingState.Clear(val.Id); if (!val.HasWorkplace()) { KeepWorkingPlugin.Log.LogDebug((object)$"[KeepWorking] Actor {val.Id} idle but has no workplace."); return; } val.ChangeBehaviour((ActorTaskType)302); FieldInfo fieldInfo2 = AccessTools.Field(typeof(Actor), "brain"); object? value2 = fieldInfo2.GetValue(val); ActorBrain val2 = (ActorBrain)((value2 is ActorBrain) ? value2 : null); val2.RebuildStack(); KeepWorkingPlugin.Log.LogDebug((object)$"[KeepWorking] Actor {val.Id} relocated after idle cycle."); } } catch (Exception arg) { KeepWorkingPlugin.Log.LogError((object)$"[KeepWorking] Error in Complete postfix: {arg}"); } } } public static class PluginInfo { public const string PLUGIN_GUID = "KeepWorking"; public const string PLUGIN_NAME = "KeepWorking"; public const string PLUGIN_VERSION = "1.0.0"; } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }