using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using AskaPresetSaver.Core;
using AskaShared;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Il2CppSystem.Threading.Tasks;
using Microsoft.CodeAnalysis;
using SSSGame;
using SSSGame.Network;
using SSSGame.UI;
using SandSailorStudio.Inventory;
using SandSailorStudio.Storage;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("PresetSaver")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.2")]
[assembly: AssemblyInformationalVersion("1.2.2+f813b3512979ded091fad812f7b8f5ef7dc00147")]
[assembly: AssemblyProduct("Preset Saver")]
[assembly: AssemblyTitle("PresetSaver")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[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 AskaPresetSaver
{
public sealed class CaptureBehaviour : MonoBehaviour
{
private const float ScanIntervalSeconds = 0.5f;
private PlayerCharacter _player;
private PreferencesManager _pm;
private StorageManager _storage;
private bool _attached;
private float _nextScanTime;
public CaptureBehaviour(IntPtr ptr)
: base(ptr)
{
}
private void Update()
{
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Expected O, but got Unknown
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Expected O, but got Unknown
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Expected O, but got Unknown
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Expected O, but got Unknown
//IL_00df: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Expected O, but got Unknown
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Expected O, but got Unknown
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: Expected O, but got Unknown
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: Expected O, but got Unknown
if (!PresetSaverConfig.Capture.Value)
{
return;
}
if (_attached)
{
if ((Object)_pm == (Object)null || (Object)_player == (Object)null)
{
_attached = false;
_player = null;
_pm = null;
_storage = null;
}
else
{
CaptureTriggers.Tick(_pm, _storage);
}
return;
}
if ((Object)_player == (Object)null)
{
if (Time.unscaledTime < _nextScanTime)
{
return;
}
_nextScanTime = Time.unscaledTime + 0.5f;
_player = Object.FindObjectOfType<PlayerCharacter>();
if ((Object)_player == (Object)null)
{
return;
}
}
if ((Object)_pm == (Object)null)
{
_pm = Object.FindObjectOfType<PreferencesManager>();
}
if (!((Object)_pm == (Object)null) && !((Object)(object)_pm.networkLogic == (Object)null))
{
if ((Object)_storage == (Object)null)
{
_storage = Object.FindObjectOfType<StorageManager>();
}
if (!((Object)_storage == (Object)null))
{
CaptureTriggers.Attach(_pm, _pm.networkLogic, _storage);
_attached = true;
}
}
}
}
internal static class CaptureTriggers
{
private const long DebounceMs = 1000L;
private const long SaveGraceMs = 2000L;
private const long RetryMs = 500L;
private const long StaleFlagMs = 30000L;
private const long ConfirmDelayMs = 3000L;
private const long LoadSettleSuppressMs = 20000L;
private static volatile bool _pending;
private static long _dueAtMs;
private static long _pendingSinceMs;
private static long _suppressUntilMs;
private static long _lastSaveStartedMs = long.MinValue;
private static bool _confirmDone;
private static readonly Action _onSchedulesChangedManaged = OnSchedulesChanged;
private static readonly Action _onSaveStartedManaged = OnSaveStarted;
private static Action _onSchedulesChangedNative;
private static Action _onSaveStartedNative;
private static IntPtr _subscribedNpm;
private static IntPtr _subscribedStorage;
private static Harmony _harmony;
private static bool _taskPatchTried;
private static bool _schedFired;
private static bool _taskFired;
private static bool _saveFired;
private static long NowMs => Environment.TickCount64;
internal static long LastScheduleChangeMs { get; private set; }
internal static long LastTaskLoadMs { get; private set; }
internal static long LastLoadActivityMs => Math.Max(LastTaskLoadMs, LastScheduleChangeMs);
internal static void NoteTaskLoaded()
{
LastTaskLoadMs = NowMs;
}
internal static void Attach(PreferencesManager pm, NetworkPreferencesManager npm, StorageManager storage)
{
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Expected O, but got Unknown
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Expected O, but got Unknown
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Expected O, but got Unknown
bool flag = default(bool);
try
{
if (_onSchedulesChangedNative == null)
{
_onSchedulesChangedNative = DelegateSupport.ConvertDelegate<Action>((Delegate)_onSchedulesChangedManaged);
}
if ((Object)(object)npm != (Object)null && ((Il2CppObjectBase)npm).Pointer != _subscribedNpm)
{
npm.OnSchedulePresetsChanged += _onSchedulesChangedNative;
_subscribedNpm = ((Il2CppObjectBase)npm).Pointer;
Plugin.Log.LogInfo((object)"capture: subscribed to OnSchedulePresetsChanged.");
}
}
catch (Exception ex)
{
ManualLogSource log = Plugin.Log;
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(42, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("capture: schedule-event subscribe failed: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
}
log.LogWarning(val);
}
try
{
if (_onSaveStartedNative == null)
{
_onSaveStartedNative = DelegateSupport.ConvertDelegate<Action>((Delegate)_onSaveStartedManaged);
}
if ((Object)storage != (Object)null && ((Il2CppObjectBase)storage).Pointer != _subscribedStorage)
{
storage.OnSaveStarted += _onSaveStartedNative;
_subscribedStorage = ((Il2CppObjectBase)storage).Pointer;
}
}
catch (Exception ex2)
{
ManualLogSource log2 = Plugin.Log;
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(41, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("capture: OnSaveStarted subscribe failed: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex2.Message);
}
log2.LogWarning(val);
}
InstallTaskPatchOnce();
SuppressFor(20000L);
}
private static void InstallTaskPatchOnce()
{
//IL_014c: Unknown result type (might be due to invalid IL or missing references)
//IL_0152: Expected O, but got Unknown
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
//IL_011e: Expected O, but got Unknown
if (_taskPatchTried)
{
return;
}
_taskPatchTried = true;
if (_harmony == null)
{
_harmony = new Harmony("mugsy33.presetsaver.capture");
}
if (!TryPatch(AccessTools.Method(typeof(PreferencesManager), "CreateTasksPresetDataForStructure", new Type[2]
{
typeof(string),
typeof(Structure)
}, (Type[])null), "CreateTasksPresetDataForStructure") && !TryPatch(AccessTools.Method(typeof(WorkstationMenu), "SaveCurrentTaskPreset", new Type[1] { typeof(Structure) }, (Type[])null), "WorkstationMenu.SaveCurrentTaskPreset (fallback)"))
{
Plugin.Log.LogWarning((object)"capture: no task-preset hook could be installed; task presets will not auto-capture.");
}
try
{
MethodInfo methodInfo = AccessTools.Method(typeof(NetworkPreferencesManager), "AddTaskPresetFromDeserialization", new Type[3]
{
typeof(string),
typeof(int),
typeof(string).MakeByRefType()
}, (Type[])null);
if (methodInfo != null)
{
_harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(TaskLoadedPatch), "Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Plugin.Log.LogInfo((object)"restore: observing AddTaskPresetFromDeserialization for load timing.");
}
else
{
Plugin.Log.LogWarning((object)"restore: AddTaskPresetFromDeserialization not found; load timing falls back to time only.");
}
}
catch (Exception ex)
{
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(34, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("restore: load-timing hook failed: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
}
log.LogWarning(val);
}
}
private static bool TryPatch(MethodBase target, string label)
{
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Expected O, but got Unknown
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Expected O, but got Unknown
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Expected O, but got Unknown
if (target == null)
{
return false;
}
try
{
_harmony.Patch(target, (HarmonyMethod)null, new HarmonyMethod(typeof(TaskPresetCreatedPatch), "Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(33, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("capture: task hook installed on ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(label);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".");
}
log.LogInfo(val);
return true;
}
catch (Exception ex)
{
ManualLogSource log2 = Plugin.Log;
bool flag2 = default(bool);
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(31, 2, ref flag2);
if (flag2)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("capture: task hook on ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(label);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" failed: ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
}
log2.LogWarning(val2);
return false;
}
}
internal static void RequestTask()
{
if (!_taskFired)
{
_taskFired = true;
Plugin.Log.LogInfo((object)"capture trigger: task preset created (first fire).");
}
Request();
}
private static void OnSchedulesChanged()
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Expected O, but got Unknown
try
{
LastScheduleChangeMs = NowMs;
if (!_schedFired)
{
_schedFired = true;
Plugin.Log.LogInfo((object)"capture trigger: schedule presets changed (first fire).");
}
Request();
}
catch (Exception ex)
{
try
{
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(34, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("capture: schedule handler failed: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
}
log.LogWarning(val);
}
catch
{
}
}
}
private static void OnSaveStarted()
{
try
{
_lastSaveStartedMs = NowMs;
if (!_saveFired)
{
_saveFired = true;
Plugin.Log.LogInfo((object)"capture: OnSaveStarted observed.");
}
}
catch
{
}
}
private static void Request()
{
long nowMs = NowMs;
if (!_pending)
{
_pendingSinceMs = nowMs;
}
_pending = true;
_confirmDone = false;
_dueAtMs = nowMs + 1000;
}
internal static void SuppressFor(long ms)
{
_suppressUntilMs = Math.Max(_suppressUntilMs, NowMs + ms);
}
internal static void Tick(PreferencesManager pm, StorageManager storage)
{
//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
//IL_01c0: Expected O, but got Unknown
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Expected O, but got Unknown
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: Expected O, but got Unknown
if (!_pending)
{
return;
}
long nowMs = NowMs;
if (nowMs < _dueAtMs)
{
return;
}
if (nowMs < _suppressUntilMs)
{
_pending = false;
return;
}
if ((Object)pm == (Object)null)
{
_pending = false;
return;
}
if (!pm.IsLocalStorageClient)
{
_pending = false;
return;
}
if (SaveInFlight(storage, nowMs))
{
_dueAtMs = nowMs + 500;
return;
}
_pending = false;
bool flag = default(bool);
try
{
PresetLibraryDto val = PreferencesBridge.Capture(pm);
PresetLibraryDto val2 = PresetStore.Load();
PresetLibraryDto val3 = PresetLibrary.MergeCaptured(val2, val);
if (PresetLibrary.ToJson(val3) != PresetLibrary.ToJson(val2))
{
PresetStore.Save(val3);
int num = 0;
foreach (TasksPresetDto task in val.Tasks)
{
num += task.Rows.Count;
}
ManualLogSource log = Plugin.Log;
BepInExInfoLogInterpolatedStringHandler val4 = new BepInExInfoLogInterpolatedStringHandler(124, 5, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("captured ");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(val.Schedules.Count);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" schedule preset(s) and ");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(val.Tasks.Count);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" task preset(s) (");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(num);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" row(s) total); ");
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("library now holds ");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(val3.Schedules.Count);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" schedule preset(s) and ");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(val3.Tasks.Count);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" task preset(s).");
}
log.LogInfo(val4);
}
}
catch (Exception ex)
{
ManualLogSource log2 = Plugin.Log;
BepInExWarningLogInterpolatedStringHandler val5 = new BepInExWarningLogInterpolatedStringHandler(16, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("capture failed: ");
((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(ex.Message);
}
log2.LogWarning(val5);
}
if (!_confirmDone)
{
_confirmDone = true;
_pending = true;
_pendingSinceMs = nowMs;
_dueAtMs = nowMs + 3000;
}
}
internal static bool SaveInFlight(StorageManager storage, long now)
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Expected O, but got Unknown
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
if (_lastSaveStartedMs != long.MinValue && now - _lastSaveStartedMs < 2000)
{
return true;
}
if ((Object)storage == (Object)null)
{
return false;
}
try
{
Task savingTask = storage._savingTask;
if (savingTask != null && !savingTask.IsCompleted)
{
return true;
}
}
catch
{
}
if (now - _pendingSinceMs < 30000)
{
try
{
if (storage.IsSaving || (int)storage.CurrentSaveStage != 0)
{
return true;
}
}
catch
{
}
}
return false;
}
}
internal static class TaskPresetCreatedPatch
{
internal static void Postfix()
{
CaptureTriggers.RequestTask();
}
}
internal static class TaskLoadedPatch
{
internal static void Postfix()
{
CaptureTriggers.NoteTaskLoaded();
}
}
[BepInPlugin("mugsy33.presetsaver", "Preset Saver", "1.2.2")]
public class Plugin : BasePlugin
{
public const string PluginGuid = "mugsy33.presetsaver";
public const string PluginName = "Preset Saver";
public const string PluginVersion = "1.2.2";
internal static ManualLogSource Log;
public override void Load()
{
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Expected O, but got Unknown
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Expected O, but got Unknown
Log = ((BasePlugin)this).Log;
ConfigMigration.Run(((BasePlugin)this).Config, Log);
PresetSaverConfig.Init(((BasePlugin)this).Config);
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val;
if (!PresetSaverConfig.Enabled.Value)
{
ManualLogSource log = Log;
val = new BepInExInfoLogInterpolatedStringHandler(22, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Preset Saver");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" v");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.2.2");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" disabled by config.");
}
log.LogInfo(val);
return;
}
ClassInjector.RegisterTypeInIl2Cpp<RestoreBehaviour>();
ClassInjector.RegisterTypeInIl2Cpp<CaptureBehaviour>();
((BasePlugin)this).AddComponent<CaptureBehaviour>();
((BasePlugin)this).AddComponent<RestoreBehaviour>();
ManualLogSource log2 = Log;
val = new BepInExInfoLogInterpolatedStringHandler(31, 4, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Preset Saver");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" v");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.2.2");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded ");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("(Capture=");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(PresetSaverConfig.Capture.Value);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", Restore=");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(PresetSaverConfig.Restore.Value);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(").");
}
log2.LogInfo(val);
}
}
internal static class PreferencesBridge
{
internal static PresetLibraryDto Capture(PreferencesManager pm)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Expected O, but got Unknown
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Expected O, but got Unknown
//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
//IL_03ef: Expected O, but got Unknown
//IL_044a: Unknown result type (might be due to invalid IL or missing references)
//IL_0451: Expected O, but got Unknown
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: 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_0132: Expected O, but got Unknown
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Expected O, but got Unknown
//IL_0355: Unknown result type (might be due to invalid IL or missing references)
//IL_035c: Expected O, but got Unknown
//IL_027b: Unknown result type (might be due to invalid IL or missing references)
//IL_0280: Unknown result type (might be due to invalid IL or missing references)
//IL_028d: Unknown result type (might be due to invalid IL or missing references)
//IL_029a: Unknown result type (might be due to invalid IL or missing references)
//IL_02ac: Expected O, but got Unknown
PresetLibraryDto val = new PresetLibraryDto();
if ((Object)(object)pm == (Object)null)
{
return val;
}
bool flag = default(bool);
try
{
List<VillagerSchedulePreset> villagerSchedulePresets = pm.VillagerSchedulePresets;
if (villagerSchedulePresets != null)
{
Enumerator<VillagerSchedulePreset> enumerator = villagerSchedulePresets.GetEnumerator();
while (enumerator.MoveNext())
{
VillagerSchedulePreset current = enumerator.Current;
Il2CppStructArray<int> schedule = current.Schedule;
if (schedule != null)
{
int[] array = new int[((Il2CppArrayBase<int>)(object)schedule).Length];
for (int i = 0; i < ((Il2CppArrayBase<int>)(object)schedule).Length; i++)
{
array[i] = ((Il2CppArrayBase<int>)(object)schedule)[i];
}
val.Schedules.Add(new SchedulePresetDto
{
Name = current.presetName,
Schedule = array
});
}
}
}
}
catch (Exception ex)
{
ManualLogSource log = Plugin.Log;
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(27, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("capture: schedules failed: ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
}
log.LogWarning(val2);
}
try
{
List<TasksPreset> tasksConfigurationPresets = pm.TasksConfigurationPresets;
if (tasksConfigurationPresets != null)
{
Enumerator<TasksPreset> enumerator2 = tasksConfigurationPresets.GetEnumerator();
while (enumerator2.MoveNext())
{
TasksPreset current2 = enumerator2.Current;
try
{
ItemInfo requiredTemplate = current2.requiredTemplate;
if ((Object)(object)requiredTemplate == (Object)null)
{
continue;
}
TasksPresetDto val3 = new TasksPresetDto
{
Name = current2.presetName,
TemplateId = requiredTemplate.id
};
if (pm._tasksPresetsData == null || !pm._tasksPresetsData.ContainsKey(current2.presetName))
{
Plugin.Log.LogWarning((object)("capture: task preset '" + current2.presetName + "' has no entry in _tasksPresetsData; captured with 0 rows."));
val.Tasks.Add(val3);
continue;
}
DataObject val4 = pm._tasksPresetsData[current2.presetName];
object obj2;
if (val4 != null)
{
DataElement obj = FindChild(val4, "tdArray");
obj2 = ((obj != null) ? ((Il2CppObjectBase)obj).TryCast<DataArray>() : null);
}
else
{
obj2 = null;
}
DataArray val5 = (DataArray)obj2;
if (val5 == null)
{
Plugin.Log.LogWarning((object)("capture: task preset '" + current2.presetName + "' has no readable 'tdArray' (missing, or not a DataArray); captured with 0 rows."));
val.Tasks.Add(val3);
continue;
}
int count = val5.Count;
for (int j = 0; j < val5.Count; j++)
{
DataElement obj3 = val5[j];
DataObject val6 = ((obj3 != null) ? ((Il2CppObjectBase)obj3).TryCast<DataObject>() : null);
if (val6 != null)
{
DataElement obj4 = FindChild(val6, "itmInfo");
DataElementInt val7 = ((obj4 != null) ? ((Il2CppObjectBase)obj4).TryCast<DataElementInt>() : null);
DataElement obj5 = FindChild(val6, "taskPrio");
DataElementInt val8 = ((obj5 != null) ? ((Il2CppObjectBase)obj5).TryCast<DataElementInt>() : null);
DataElement obj6 = FindChild(val6, "qttyR");
DataElementFloat val9 = ((obj6 != null) ? ((Il2CppObjectBase)obj6).TryCast<DataElementFloat>() : null);
if (val7 != null && val8 != null && val9 != null)
{
val3.Rows.Add(new TaskRowDto
{
ItemId = val7.value,
Priority = val8.value,
QuantityRatio = val9.value
});
}
}
}
if (count > 0 && val3.Rows.Count == 0)
{
Plugin.Log.LogWarning((object)($"capture: task preset '{current2.presetName}' has {count} row(s) " + "in 'tdArray' but none parsed (unexpected row shape); captured with 0 rows."));
}
else if (val3.Rows.Count < count)
{
ManualLogSource log2 = Plugin.Log;
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(95, 3, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("capture: task preset '");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(current2.presetName);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("': parsed ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(val3.Rows.Count);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" ");
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("of ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(count);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" row(s); the rest had an unreadable shape and were skipped.");
}
log2.LogWarning(val2);
}
val.Tasks.Add(val3);
}
catch (Exception ex2)
{
ManualLogSource log3 = Plugin.Log;
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(33, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("capture: tasks preset '");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(current2.presetName);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("' failed: ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex2.Message);
}
log3.LogWarning(val2);
}
}
}
}
catch (Exception ex3)
{
ManualLogSource log4 = Plugin.Log;
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(23, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("capture: tasks failed: ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex3.Message);
}
log4.LogWarning(val2);
}
return val;
}
private static DataElement FindChild(DataObject obj, string key)
{
Dictionary<string, DataElement> val = ((obj != null) ? obj._elements : null);
if (val == null)
{
return null;
}
Enumerator<string, DataElement> enumerator = val.GetEnumerator();
while (enumerator.MoveNext())
{
KeyValuePair<string, DataElement> current = enumerator.Current;
if (current.Key == key)
{
return current.Value;
}
}
return null;
}
internal static int ScheduleNameMax()
{
try
{
int schedulePresetNameMaxSize = NetworkPreferencesManager.schedulePresetNameMaxSize;
return (schedulePresetNameMaxSize > 0) ? schedulePresetNameMaxSize : 16;
}
catch
{
return 16;
}
}
internal static int TaskNameMax()
{
try
{
int tasksPresetNameMaxSize = NetworkPreferencesManager.tasksPresetNameMaxSize;
return (tasksPresetNameMaxSize > 0) ? tasksPresetNameMaxSize : 16;
}
catch
{
return 16;
}
}
internal static int InjectSchedules(PreferencesManager pm, PresetLibraryDto missing, out int skippedPresent)
{
//IL_0150: Unknown result type (might be due to invalid IL or missing references)
//IL_0157: Expected O, but got Unknown
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Expected O, but got Unknown
int num = 0;
skippedPresent = 0;
int num2 = ScheduleNameMax();
bool flag = default(bool);
foreach (SchedulePresetDto schedule in missing.Schedules)
{
try
{
string text = PresetNames.Normalize(schedule.Name);
if (text.Length == 0 || schedule.Schedule == null || schedule.Schedule.Length == 0)
{
continue;
}
string text2 = PresetNames.Normalize(text, num2);
if ((Object)(object)pm.networkLogic != (Object)null && !pm.networkLogic._IsSchedulePresetNameUnique(text2))
{
skippedPresent++;
continue;
}
if ((Object)(object)pm.networkLogic != (Object)null && pm.networkLogic._GetNextAvailableSchedulePresetSlot() < 0)
{
Plugin.Log.LogWarning((object)("restore: schedule preset capacity full; '" + text + "' and any remaining presets were not injected."));
break;
}
Il2CppStructArray<int> val = new Il2CppStructArray<int>((long)schedule.Schedule.Length);
for (int i = 0; i < schedule.Schedule.Length; i++)
{
((Il2CppArrayBase<int>)(object)val)[i] = schedule.Schedule[i];
}
pm.SaveSchedulePreset(text, val);
num++;
ManualLogSource log = Plugin.Log;
BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(28, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("restored schedule preset '");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(text);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("'.");
}
log.LogInfo(val2);
}
catch (Exception ex)
{
ManualLogSource log2 = Plugin.Log;
BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(29, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("restore: schedule '");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(schedule.Name);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("' failed: ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex.Message);
}
log2.LogWarning(val3);
}
}
return num;
}
internal static int InjectTasks(PreferencesManager pm, PresetLibraryDto missing, out int skippedPresent)
{
//IL_0293: Unknown result type (might be due to invalid IL or missing references)
//IL_029a: Expected O, but got Unknown
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Expected O, but got Unknown
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_011f: Expected O, but got Unknown
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Expected O, but got Unknown
//IL_022d: Unknown result type (might be due to invalid IL or missing references)
//IL_0234: Expected O, but got Unknown
//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
//IL_01df: Expected O, but got Unknown
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Expected O, but got Unknown
int num = 0;
skippedPresent = 0;
if ((Object)(object)pm.networkLogic == (Object)null)
{
return num;
}
int num2 = TaskNameMax();
string text3 = default(string);
bool flag = default(bool);
foreach (TasksPresetDto task in missing.Tasks)
{
try
{
string text = PresetNames.Normalize(task.Name);
if (text.Length == 0)
{
continue;
}
string text2 = PresetNames.Normalize(text, num2);
if (!pm.networkLogic._IsTaskPresetNameUnique(text2) || (pm._tasksPresetsData != null && pm._tasksPresetsData.ContainsKey(text2)))
{
skippedPresent++;
continue;
}
if (pm.networkLogic._GetNextAvailableTaskPresetSlot() < 0)
{
Plugin.Log.LogWarning((object)("restore: task preset capacity full; '" + text + "' and any remaining task presets were not injected."));
break;
}
if (!pm.networkLogic.AddTaskPresetFromDeserialization(text, task.TemplateId, ref text3))
{
ManualLogSource log = Plugin.Log;
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(69, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("restore: task preset '");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' rejected by AddTaskPresetFromDeserialization.");
}
log.LogWarning(val);
continue;
}
DataObject val2 = new DataObject();
DataArray val3 = new DataArray();
if (task.Rows != null)
{
foreach (TaskRowDto row in task.Rows)
{
DataObject val4 = new DataObject();
val4.AddElement("itmInfo", DataElement.op_Implicit(row.ItemId));
val4.AddElement("taskPrio", DataElement.op_Implicit(row.Priority));
val4.AddElement("qttyR", DataElement.op_Implicit(row.QuantityRatio));
val3.AddElement((DataElement)(object)val4);
}
}
val2.AddElement("tdArray", (DataElement)(object)val3);
if (pm._tasksPresetsData == null)
{
ManualLogSource log2 = Plugin.Log;
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(85, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("restore: task preset '");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text3);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' added but _tasksPresetsData is unavailable; rows not written.");
}
log2.LogWarning(val);
continue;
}
pm._tasksPresetsData[text3] = val2;
num++;
ManualLogSource log3 = Plugin.Log;
BepInExInfoLogInterpolatedStringHandler val5 = new BepInExInfoLogInterpolatedStringHandler(34, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("restored task preset '");
((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(text3);
((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("' (");
((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<int>(task.Rows?.Count ?? 0);
((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(" row(s)).");
}
log3.LogInfo(val5);
}
catch (Exception ex)
{
ManualLogSource log4 = Plugin.Log;
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(32, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("restore: task preset '");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(task.Name);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' failed: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
}
log4.LogWarning(val);
}
}
return num;
}
internal static ISet<int> KnownItemIds()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Expected O, but got Unknown
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Expected O, but got Unknown
try
{
ItemDatabaseManager val = Object.FindObjectOfType<ItemDatabaseManager>();
if ((Object)val == (Object)null)
{
return null;
}
ItemInfoDatabase database = val.Database;
if ((Object)database == (Object)null)
{
return null;
}
Dictionary<int, ItemInfo> itemsMap = database._itemsMap;
if (itemsMap == null)
{
return null;
}
HashSet<int> hashSet = new HashSet<int>();
Enumerator<int, ItemInfo> enumerator = itemsMap.GetEnumerator();
while (enumerator.MoveNext())
{
KeyValuePair<int, ItemInfo> current = enumerator.Current;
hashSet.Add(current.Key);
}
return hashSet;
}
catch (Exception ex)
{
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(21, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("KnownItemIds failed: ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
}
log.LogWarning(val2);
return null;
}
}
}
internal static class PresetSaverConfig
{
internal static ConfigEntry<bool> Enabled;
internal static ConfigEntry<bool> Capture;
internal static ConfigEntry<bool> Restore;
internal static void Init(ConfigFile config)
{
Enabled = config.Bind<bool>("PresetSaver", "Enabled", true, "Master switch. When false the mod does nothing at all.");
Capture = config.Bind<bool>("PresetSaver", "Capture", true, "Save presets from your game into the global library when the game saves.");
Restore = config.Bind<bool>("PresetSaver", "Restore", true, "Re-create presets from the global library when a save is loaded. Presets already present in the save are never touched.");
}
}
internal static class PresetStore
{
internal static string Path => System.IO.Path.Combine(Paths.ConfigPath, "PresetSaver", "presets.json");
internal static PresetLibraryDto Load()
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Expected O, but got Unknown
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Expected O, but got Unknown
try
{
if (!File.Exists(Path))
{
return new PresetLibraryDto();
}
return PresetLibrary.FromJson(File.ReadAllText(Path));
}
catch (Exception ex)
{
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(46, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("preset library load failed (");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("); starting empty.");
}
log.LogWarning(val);
return new PresetLibraryDto();
}
}
internal static void Save(PresetLibraryDto library)
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Expected O, but got Unknown
try
{
Directory.CreateDirectory(System.IO.Path.GetDirectoryName(Path));
string text = Path + ".tmp";
File.WriteAllText(text, PresetLibrary.ToJson(library));
File.Copy(text, Path, overwrite: true);
File.Delete(text);
}
catch (Exception ex)
{
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(29, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("preset library write failed: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
}
log.LogWarning(val);
}
}
}
public sealed class RestoreBehaviour : MonoBehaviour
{
private enum GateResult
{
Wait,
Ready,
Abort
}
private const float ScanIntervalSeconds = 0.5f;
private PlayerCharacter _player;
private PreferencesManager _prefs;
private StorageManager _storage;
private bool _armed;
private float _nextScanTime;
private const int MaxItemIdsUnavailableFrames = 300;
private int _itemIdsUnavailableFrames;
private bool _itemsResolved;
private bool _skipValidation;
private ISet<int> _knownItemIds;
private const long LoadQuietMs = 1500L;
private const long EmptySaveTimeoutMs = 8000L;
private const long HardCeilingMs = 60000L;
private long _armedAtMs;
private bool _stageLogged;
private static long NowMs => Environment.TickCount64;
public RestoreBehaviour(IntPtr ptr)
: base(ptr)
{
}
private void Update()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
//IL_0359: Unknown result type (might be due to invalid IL or missing references)
//IL_0360: Expected O, but got Unknown
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Expected O, but got Unknown
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Expected O, but got Unknown
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Expected O, but got Unknown
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Expected O, but got Unknown
//IL_0298: Unknown result type (might be due to invalid IL or missing references)
//IL_029f: Expected O, but got Unknown
if ((Object)_player == (Object)null)
{
_prefs = null;
_storage = null;
if (Time.unscaledTime < _nextScanTime)
{
return;
}
_nextScanTime = Time.unscaledTime + 0.5f;
_player = Object.FindObjectOfType<PlayerCharacter>();
if ((Object)_player == (Object)null)
{
return;
}
_armed = true;
_itemIdsUnavailableFrames = 0;
_itemsResolved = false;
_skipValidation = false;
_knownItemIds = null;
_armedAtMs = NowMs;
_stageLogged = false;
Plugin.Log.LogInfo((object)"restore: armed for this load.");
}
if (!_armed)
{
return;
}
if ((Object)_prefs == (Object)null)
{
_prefs = Object.FindObjectOfType<PreferencesManager>();
if ((Object)_prefs == (Object)null)
{
return;
}
}
PreferencesManager prefs = _prefs;
if (!prefs.IsLocalStorageClient)
{
Plugin.Log.LogInfo((object)"restore skipped: not the local storage client (joined another host's game).");
_armed = false;
}
else
{
if ((Object)(object)prefs.networkLogic == (Object)null)
{
return;
}
if (!PresetSaverConfig.Restore.Value)
{
_armed = false;
return;
}
if ((Object)_storage == (Object)null)
{
_storage = Object.FindObjectOfType<StorageManager>();
}
if (!_itemsResolved)
{
ISet<int> set = PreferencesBridge.KnownItemIds();
if (set == null)
{
_itemIdsUnavailableFrames++;
if (_itemIdsUnavailableFrames < 300)
{
return;
}
_skipValidation = true;
}
_knownItemIds = set;
_itemsResolved = true;
}
switch (GateReady(prefs, _storage))
{
case GateResult.Wait:
return;
case GateResult.Abort:
_armed = false;
return;
}
ISet<int> knownItemIds = _knownItemIds;
bool skipValidation = _skipValidation;
_armed = false;
bool flag = default(bool);
try
{
PresetLibraryDto val = PresetStore.Load();
PresetLibraryDto val2;
if (skipValidation)
{
Plugin.Log.LogWarning((object)($"restore: item database unavailable after {300} " + "frame(s) of polling; SKIPPING template/item id validation and injecting task presets UNVALIDATED."));
val2 = val;
}
else
{
Action<string> action = delegate(string msg)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
ManualLogSource log3 = Plugin.Log;
bool flag2 = default(bool);
BepInExWarningLogInterpolatedStringHandler val6 = new BepInExWarningLogInterpolatedStringHandler(17, 1, ref flag2);
if (flag2)
{
((BepInExLogInterpolatedStringHandler)val6).AppendLiteral("restore: dropped ");
((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<string>(msg);
}
log3.LogWarning(val6);
};
val2 = PresetValidation.DropUnresolvable(val, knownItemIds, (ISet<int>)new HashSet<int>(), action);
}
PresetLibraryDto val3 = PreferencesBridge.Capture(prefs);
PresetLibraryDto missing = PresetLibrary.MissingFrom(val2, val3, PreferencesBridge.ScheduleNameMax(), PreferencesBridge.TaskNameMax());
CaptureTriggers.SuppressFor(2000L);
int skippedPresent;
int num = PreferencesBridge.InjectSchedules(prefs, missing, out skippedPresent);
int skippedPresent2;
int num2 = PreferencesBridge.InjectTasks(prefs, missing, out skippedPresent2);
ManualLogSource log = Plugin.Log;
BepInExInfoLogInterpolatedStringHandler val4 = new BepInExInfoLogInterpolatedStringHandler(174, 6, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("restore complete: ");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(num);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" schedule preset(s) and ");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(num2);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" task preset(s) injected, ");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(val3.Schedules.Count);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" schedule(s) and ");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(val3.Tasks.Count);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" task preset(s) already present, ");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(skippedPresent);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" schedule(s) and ");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(skippedPresent2);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" task preset(s) already present (late).");
}
log.LogInfo(val4);
}
catch (Exception ex)
{
ManualLogSource log2 = Plugin.Log;
BepInExWarningLogInterpolatedStringHandler val5 = new BepInExWarningLogInterpolatedStringHandler(16, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("restore failed: ");
((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(ex.Message);
}
log2.LogWarning(val5);
}
}
}
private GateResult GateReady(PreferencesManager pm, StorageManager storage)
{
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Expected O, but got Unknown
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Expected O, but got Unknown
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Expected O, but got Unknown
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
long nowMs = NowMs;
if (CaptureTriggers.SaveInFlight(storage, nowMs))
{
return GateResult.Wait;
}
bool flag = default(bool);
if (!_stageLogged)
{
_stageLogged = true;
try
{
ManualLogSource log = Plugin.Log;
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(37, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("restore: PreferencesManager stage = ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<StorageSessionStage>(pm.GetStage());
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".");
}
log.LogInfo(val);
}
catch (Exception ex)
{
ManualLogSource log2 = Plugin.Log;
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(35, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("restore: GetStage() unavailable (");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(").");
}
log2.LogInfo(val);
}
}
long lastLoadActivityMs = CaptureTriggers.LastLoadActivityMs;
bool flag2 = lastLoadActivityMs > _armedAtMs;
bool flag3 = nowMs - lastLoadActivityMs >= 1500;
bool flag4 = nowMs - _armedAtMs >= 8000;
bool flag5 = nowMs - _armedAtMs >= 60000;
if (flag5 || (flag2 && flag3) || (!flag2 && flag4))
{
ManualLogSource log3 = Plugin.Log;
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(74, 5, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("restore: gate opened after ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<long>(nowMs - _armedAtMs);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ms ");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("(sawLoad=");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(flag2);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", quietFor=");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<long>(nowMs - lastLoadActivityMs);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ms, empty=");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(!flag2);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", ceiling=");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(flag5);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(").");
}
log3.LogInfo(val);
return GateResult.Ready;
}
return GateResult.Wait;
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "PresetSaver";
public const string PLUGIN_NAME = "Preset Saver";
public const string PLUGIN_VERSION = "1.2.2";
}
}