using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FistVR;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using NGA;
using Sirdoggy.ItemSpawnerTweaks.Common;
using Sirdoggy.ItemSpawnerTweaks.Data;
using Sirdoggy.ItemSpawnerTweaks.Tags;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("Sirdoggy")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Fixes and quality-of-life improvements for the item spawner")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: AssemblyProduct("Sirdoggy.ItemSpawnerTweaks")]
[assembly: AssemblyTitle("ItemSpawnerTweaks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.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.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]
[Microsoft.CodeAnalysis.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]
[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 BepInEx
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class BepInAutoPluginAttribute : Attribute
{
public BepInAutoPluginAttribute(string id = null, string name = null, string version = null)
{
}
}
}
namespace BepInEx.Preloader.Core.Patching
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class PatcherAutoPluginAttribute : Attribute
{
public PatcherAutoPluginAttribute(string id = null, string name = null, string version = null)
{
}
}
}
namespace Sirdoggy.ItemSpawnerTweaks
{
[HarmonyWrapSafe]
[HarmonyPatch(typeof(FVRPointableButton))]
internal class FVRPointableButtonPatcher
{
private const int FileNamesOnPage = 20;
private const float HideFilePreviewDelay = 0.02f;
[HarmonyPrefix]
[HarmonyPatch("Update")]
private static void Update_Prefix(FVRPointableButton __instance)
{
VaultFileButtonTag component = ((Component)__instance).GetComponent<VaultFileButtonTag>();
if (!Object.op_Implicit((Object)(object)component))
{
return;
}
ItemSpawnerV2Tag component2 = ((Component)component.ItemSpawner).GetComponent<ItemSpawnerV2Tag>();
if (!Object.op_Implicit((Object)(object)component2) || !Plugin.PluginConfig.PreviewVaultFilesOnHover.Value || component.ItemSpawner.m_isFileUnsaved)
{
return;
}
if (((FVRPointable)__instance).m_isBeingPointedAt)
{
if (component.ExecuteCodeOnHover)
{
component.ExecuteCodeOnHover = false;
PreviewVaultFile(component, component2);
}
}
else if (!component.ExecuteCodeOnHover)
{
component.ExecuteCodeOnHover = true;
component.HideVaultFilePreviewCoroutine = CoroutineRunner.Run(ScheduleHideVaultFilePreview(component, component2));
}
}
private static void PreviewVaultFile(VaultFileButtonTag tag, ItemSpawnerV2Tag spawnerTag)
{
//IL_003b: 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_0050: 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_0065: Expected I4, but got Unknown
//IL_00b4: 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)
if (tag.HideVaultFilePreviewCoroutine != null)
{
CoroutineRunner.Stop(tag.HideVaultFilePreviewCoroutine);
}
ItemSpawnerV2 itemSpawner = tag.ItemSpawner;
spawnerTag.VaultFilePreviewCounter++;
tag.VaultFilePreviewCounterLocal = spawnerTag.VaultFilePreviewCounter;
tag.FileDisplayModeOnLastPreview = itemSpawner.FileDisplayMode;
VaultFileDisplayMode fileDisplayMode = itemSpawner.FileDisplayMode;
List<string> list;
int num;
switch ((int)fileDisplayMode)
{
default:
return;
case 1:
list = itemSpawner.m_vaultFileList_Loadouts;
num = itemSpawner.m_vaultFilePage_Loadouts;
break;
case 2:
list = itemSpawner.m_vaultFileList_SceneConfigs;
num = itemSpawner.m_vaultFilePage_SceneConfigs;
break;
case 0:
list = itemSpawner.m_vaultFileList_SingleObjects;
num = itemSpawner.m_vaultFilePage_SingleObjects;
break;
}
int num2 = num * 20 + tag.FileIndexOnPage;
if (num2 < list.Count)
{
string text = list[num2];
if (VaultSystem.DoesVaultFileExist(itemSpawner.FileDisplayMode, text) && VaultSystem.LoadVaultFile(text, itemSpawner.FileDisplayMode, ref itemSpawner.m_displayedFile))
{
itemSpawner.m_fileNameField = itemSpawner.m_displayedFile.FileName;
itemSpawner.RedrawVaultDetailsCanvas();
}
}
}
private static IEnumerator ScheduleHideVaultFilePreview(VaultFileButtonTag tag, ItemSpawnerV2Tag spawnerTag)
{
yield return (object)new WaitForSecondsRealtime(0.02f);
HideVaultFilePreview(tag, spawnerTag);
}
private static void HideVaultFilePreview(VaultFileButtonTag tag, ItemSpawnerV2Tag spawnerTag)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
if (spawnerTag.VaultFilePreviewCounter <= tag.VaultFilePreviewCounterLocal && (VaultFileDisplayMode?)tag.ItemSpawner.FileDisplayMode == tag.FileDisplayModeOnLastPreview)
{
tag.ItemSpawner.m_displayedFile = spawnerTag.LastSelectedVaultFile;
tag.ItemSpawner.m_fileNameField = spawnerTag.LastSelectedVaultFile?.FileName;
tag.ItemSpawner.RedrawVaultDetailsCanvas();
}
}
}
[HarmonyWrapSafe]
[HarmonyPatch(typeof(ItemSpawnerV2))]
internal static class ItemSpawnerV2Patcher
{
private static OptionsPanel_ButtonSet? _topBarCategoryButtonSet;
private static OptionsPanel_ButtonSet? _vaultFilesSortModeButtonSet;
private static OptionsPanel_ButtonSet? _itemDetailsListModeButtonSet;
private const int VaultFilesSortModeLastModifiedButtonIndex = 0;
private const int VaultFilesSortModeLastOpenedButtonIndex = 1;
private const int VaultFilesSortModeAlphabeticalButtonIndex = 2;
private const int TopBarCategoryMainMenuIndex = 0;
private const int TopBarCategoryFirearmsIndex = 1;
private const int TopBarCategorySaveAndLoadButtonIndex = 6;
private const int ItemDetailsListModeVaultFilesButtonIndex = 1;
[HarmonyPostfix]
[HarmonyPatch("Start")]
private static void Start_Postfix(ItemSpawnerV2 __instance)
{
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Expected I4, but got Unknown
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_014e: Expected I4, but got Unknown
//IL_0159: Unknown result type (might be due to invalid IL or missing references)
//IL_015e: Unknown result type (might be due to invalid IL or missing references)
//IL_0160: Unknown result type (might be due to invalid IL or missing references)
//IL_0173: Expected I4, but got Unknown
Plugin.Log.LogInfo((object)"Setting initial item spawner preferences.");
if (!Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<ItemSpawnerV2Tag>()))
{
((Object)((Component)__instance).gameObject.AddComponent<ItemSpawnerV2Tag>()).hideFlags = (HideFlags)61;
}
SaveUIReferences(__instance);
if (Plugin.PluginConfig.OpenRelatedVaultFilesByDefault.Value)
{
__instance.m_detailsLinkedResourceMode = (DetailsLinkedResourceMode)1;
OptionsPanel_ButtonSet? itemDetailsListModeButtonSet = _itemDetailsListModeButtonSet;
if (itemDetailsListModeButtonSet != null)
{
itemDetailsListModeButtonSet.SetSelectedButton(1);
}
}
ItemSpawnerDefaultPageDto value = Plugin.PluginConfig.ItemSpawnerDefaultPage.Value;
PageMode? val = value switch
{
ItemSpawnerDefaultPageDto.WelcomePage => (PageMode)0,
ItemSpawnerDefaultPageDto.Firearms => (PageMode)1,
ItemSpawnerDefaultPageDto.SaveAndLoad => (PageMode)7,
_ => null,
};
int? num = value switch
{
ItemSpawnerDefaultPageDto.WelcomePage => 0,
ItemSpawnerDefaultPageDto.Firearms => 1,
ItemSpawnerDefaultPageDto.SaveAndLoad => 6,
_ => null,
};
if (val.HasValue)
{
__instance.SetPageMode((int)val.Value);
}
if (num.HasValue)
{
OptionsPanel_ButtonSet? topBarCategoryButtonSet = _topBarCategoryButtonSet;
if (topBarCategoryButtonSet != null)
{
topBarCategoryButtonSet.SetSelectedButton(num.Value);
}
}
if (Plugin.PluginConfig.RememberLastUsedSortMode.Value)
{
CynJsonSortingMode? sortMode = ItemSpawnerPreferencesStore.SortMode;
if (sortMode.HasValue)
{
__instance.SetFileListSortMode((int)sortMode.Value);
int selectedButton = sortMode switch
{
1L => 0,
2L => 1,
0L => 2,
_ => 0,
};
OptionsPanel_ButtonSet? vaultFilesSortModeButtonSet = _vaultFilesSortModeButtonSet;
if (vaultFilesSortModeButtonSet != null)
{
vaultFilesSortModeButtonSet.SetSelectedButton(selectedButton);
}
}
}
Plugin.Log.LogInfo((object)"Finished setting initial item spawner preferences.");
}
private static void SaveUIReferences(ItemSpawnerV2 __instance)
{
Transform transform = ((Component)__instance).transform;
Transform val = transform.Find("Canvas/0_TopBar/BTNSet_Cat");
Transform val2 = transform.Find("Canvas/4_VaultFileList/BTNSet_SortMode");
Transform val3 = transform.Find("Canvas/3_ItemDetailsPage/BTNSet_DetailListMode");
if (Object.op_Implicit((Object)(object)val))
{
_topBarCategoryButtonSet = ((Component)val).GetComponentInChildren<OptionsPanel_ButtonSet>(true);
}
else
{
Plugin.Log.LogError((object)"_topBarCategoryButtonSet is null");
}
if (Object.op_Implicit((Object)(object)val2))
{
_vaultFilesSortModeButtonSet = ((Component)val2).GetComponentInChildren<OptionsPanel_ButtonSet>(true);
}
else
{
Plugin.Log.LogError((object)"_vaultFilesSortModeButtonSet is null");
}
if (Object.op_Implicit((Object)(object)val3))
{
_itemDetailsListModeButtonSet = ((Component)val3).GetComponentInChildren<OptionsPanel_ButtonSet>(true);
}
else
{
Plugin.Log.LogError((object)"_itemDetailsListModeButtonSet is null");
}
Transform val4 = transform.Find("Canvas/4_VaultFileList/FileList");
if ((Object)(object)val4 == (Object)null)
{
Plugin.Log.LogError((object)"vaultFileListGameO is null");
return;
}
List<GameObject> allChildren = val4.GetAllChildren();
int num = 0;
foreach (GameObject item in allChildren)
{
if (((Object)item).name.StartsWith("BTN_FileSystem_", StringComparison.OrdinalIgnoreCase))
{
if (!Object.op_Implicit((Object)(object)item.GetComponent<VaultFileButtonTag>()))
{
VaultFileButtonTag vaultFileButtonTag = item.gameObject.AddComponent<VaultFileButtonTag>();
vaultFileButtonTag.ItemSpawner = __instance;
vaultFileButtonTag.FileIndexOnPage = num;
((Object)vaultFileButtonTag).hideFlags = (HideFlags)61;
}
Plugin.Log.LogDebug((object)("Attached VaultFileButtonTag to '" + ((Object)item).name + "'"));
num++;
}
}
}
[HarmonyPrefix]
[HarmonyPatch("BTN_Vault_SetFileListSortMode")]
private static void BTN_Vault_SetFileListSortMode_Prefix(ItemSpawnerV2 __instance, ref int i)
{
i = i switch
{
0 => 1,
1 => 2,
2 => 0,
_ => i,
};
Plugin.Log.LogInfo((object)$"Applied item spawner sort button bugfix, new value: '{i}'.");
}
[HarmonyPostfix]
[HarmonyPatch("BTN_Vault_SetFileListSortMode")]
private static void BTN_Vault_SetFileListSortMode_Postfix(ItemSpawnerV2 __instance)
{
//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)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
CynJsonSortingMode vaultFileSortMode = __instance.m_vaultFileSortMode;
ItemSpawnerPreferencesStore.SortMode = vaultFileSortMode;
Plugin.Log.LogInfo((object)$"Finished saving item spawner sort mode '{vaultFileSortMode}'.");
}
[HarmonyPostfix]
[HarmonyPatch("BTN_Details_PressTutorialVaultButton")]
private static void BTN_Details_PressTutorialVaultButton_Postfix(ItemSpawnerV2 __instance)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Invalid comparison between Unknown and I4
if ((int)__instance.m_detailsLinkedResourceMode == 1)
{
OptionsPanel_ButtonSet? topBarCategoryButtonSet = _topBarCategoryButtonSet;
if (topBarCategoryButtonSet != null)
{
topBarCategoryButtonSet.SetSelectedButton(6);
}
ItemSpawnerV2Tag component = ((Component)__instance).GetComponent<ItemSpawnerV2Tag>();
if (Object.op_Implicit((Object)(object)component))
{
component.LastSelectedVaultFile = __instance.m_displayedFile;
}
}
}
[HarmonyPostfix]
[HarmonyPatch("SelectVaultFile")]
private static void SelectVaultFile_Postfix(ItemSpawnerV2 __instance)
{
ItemSpawnerV2Tag component = ((Component)__instance).GetComponent<ItemSpawnerV2Tag>();
if (Object.op_Implicit((Object)(object)component))
{
component.LastSelectedVaultFile = __instance.m_displayedFile;
}
}
[HarmonyPostfix]
[HarmonyPatch("ScanPointedObject")]
private static void ScanPointedObject_Postfix(ItemSpawnerV2 __instance)
{
AutoName(__instance);
}
[HarmonyPostfix]
[HarmonyPatch("ScanItemOnShelf")]
private static void ScanItemOnShelf_Postfix(ItemSpawnerV2 __instance)
{
AutoName(__instance);
}
private static void AutoName(ItemSpawnerV2 __instance)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
if (!Plugin.PluginConfig.AutoNameNewScans.Value || __instance.m_displayedFile == null || __instance.m_fileNameField != string.Empty || (int)__instance.FileDisplayMode != 0)
{
return;
}
string text = null;
foreach (VaultObject @object in __instance.m_displayedFile.Objects)
{
foreach (VaultElement element in @object.Elements)
{
if (!IM.OD.ContainsKey(element.ObjectID) || !IM.HasSpawnedID(IM.OD[element.ObjectID].SpawnedFromId))
{
continue;
}
ItemSpawnerID spawnerID = IM.GetSpawnerID(IM.OD[element.ObjectID].SpawnedFromId);
if (spawnerID.IsMainItem())
{
if (text != null)
{
Plugin.Log.LogDebug((object)"File contains more than one main item. Can't use auto-name.");
return;
}
text = StringUtils.RemoveNonAlphanumericAndSpace(spawnerID.DisplayName);
}
}
}
if (text != null)
{
__instance.m_fileNameField = text;
__instance.RedrawVaultDetailsCanvas();
}
}
[HarmonyPostfix]
[HarmonyPatch("Vault_SetFileDisplayMode")]
private static void Vault_SetFileDisplayMode_Postfix(ItemSpawnerV2 __instance)
{
ItemSpawnerV2Tag component = ((Component)__instance).GetComponent<ItemSpawnerV2Tag>();
if (Object.op_Implicit((Object)(object)component))
{
component.LastSelectedVaultFile = null;
}
}
[HarmonyPostfix]
[HarmonyPatch("Vault_ClearSelection")]
private static void Vault_ClearSelection_Postfix(ItemSpawnerV2 __instance)
{
ItemSpawnerV2Tag component = ((Component)__instance).GetComponent<ItemSpawnerV2Tag>();
if (Object.op_Implicit((Object)(object)component))
{
component.LastSelectedVaultFile = null;
}
}
[HarmonyPostfix]
[HarmonyPatch("SaveNewFile")]
private static void SaveNewFile_Postfix(ItemSpawnerV2 __instance)
{
ItemSpawnerV2Tag component = ((Component)__instance).GetComponent<ItemSpawnerV2Tag>();
if (Object.op_Implicit((Object)(object)component))
{
component.LastSelectedVaultFile = __instance.m_displayedFile;
}
}
}
[BepInProcess("h3vr.exe")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("Sirdoggy.ItemSpawnerTweaks", "ItemSpawnerTweaks", "1.0.2")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Log;
internal static PluginConfig PluginConfig;
public const string Id = "Sirdoggy.ItemSpawnerTweaks";
public static string Name => "ItemSpawnerTweaks";
public static string Version => "1.0.2";
private void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
PluginConfig = new PluginConfig();
ItemSpawnerPreferencesStore.Init();
CoroutineRunner.Run(WaitForGM());
}
private IEnumerator WaitForGM()
{
yield return (object)new WaitUntil((Func<bool>)(() => (Object)(object)ManagerSingleton<GM>.Instance != (Object)null));
int version_UpdateNumber = GM.Version_UpdateNumber;
int version_AlphaNumber = GM.Version_AlphaNumber;
int version_PatchNumber = GM.Version_PatchNumber;
int version_BuildIndex = GM.Version_BuildIndex;
((BaseUnityPlugin)this).Logger.LogInfo((object)$"GM Versions: update '{version_UpdateNumber}', alpha '{version_AlphaNumber}', patch {version_PatchNumber}, 'build {version_BuildIndex}'");
if (version_UpdateNumber > 119)
{
((BaseUnityPlugin)this).Logger.LogFatal((object)("Incompatible version detected! The version of this mod you're using does not " + $"support Update {version_UpdateNumber}. If you want to continue using this mod you can download " + "a preview version from GitLab."));
yield break;
}
Harmony.CreateAndPatchAll(typeof(ItemSpawnerV2Patcher), (string)null);
Harmony.CreateAndPatchAll(typeof(FVRPointableButtonPatcher), (string)null);
}
internal static string GetPluginDirectoryName()
{
return "Sirdoggy.ItemSpawnerTweaks".Replace('.', '-');
}
}
internal class PluginConfig
{
private const string ConfigFileName = "Sirdoggy.ItemSpawnerTweaks.cfg";
public ConfigEntry<ItemSpawnerDefaultPageDto> ItemSpawnerDefaultPage { get; }
public ConfigEntry<bool> OpenRelatedVaultFilesByDefault { get; }
public ConfigEntry<bool> RememberLastUsedSortMode { get; }
public ConfigEntry<bool> AutoNameNewScans { get; }
public ConfigEntry<bool> PreviewVaultFilesOnHover { get; }
public PluginConfig()
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Expected O, but got Unknown
ConfigFile val = new ConfigFile(Path.Combine(Paths.ConfigPath, "Sirdoggy.ItemSpawnerTweaks.cfg"), true);
ItemSpawnerDefaultPage = val.Bind<ItemSpawnerDefaultPageDto>("Item Spawner Settings", "Default open page", ItemSpawnerDefaultPageDto.Firearms, "Controls which item spawner page should be open by default. Set the value to 'WelcomePage' for vanilla behaviour.");
OpenRelatedVaultFilesByDefault = val.Bind<bool>("Item Spawner Settings", "Display related vault files by default", true, "Controls whether related vault files should be displayed in the item details panel by default. Set the value to 'false' for vanilla behaviour, which will display the tutorials list instead.");
RememberLastUsedSortMode = val.Bind<bool>("Item Spawner Settings", "Remember last used vault sort mode", true, "Controls whether the last used vault sort mode should be saved and restored. Set the value to 'false' for vanilla behaviour.");
AutoNameNewScans = val.Bind<bool>("Item Spawner Settings", "Auto-name new vault scans", true, "Controls whether new vault scans should be auto-named based on the scanned item. Auto-name will not work for loadouts and when scanning several non-miscellaneous items. Miscellaneous items like attachments and magazines will be ignored. Set the value to 'false' for vanilla behaviour.");
PreviewVaultFilesOnHover = val.Bind<bool>("Item Spawner Settings", "Preview vault files on hover", true, "Enables previews of a vault files when hovering over them in the file list.");
}
}
}
namespace Sirdoggy.ItemSpawnerTweaks.Tags
{
internal class ItemSpawnerV2Tag : MonoBehaviour
{
public VaultFile? LastSelectedVaultFile { get; set; }
public long VaultFilePreviewCounter { get; set; }
}
internal class VaultFileButtonTag : MonoBehaviour
{
public ItemSpawnerV2 ItemSpawner { get; set; }
public int FileIndexOnPage { get; set; }
public bool ExecuteCodeOnHover { get; set; } = true;
public long VaultFilePreviewCounterLocal { get; set; }
public Coroutine? HideVaultFilePreviewCoroutine { get; set; }
public VaultFileDisplayMode? FileDisplayModeOnLastPreview { get; set; }
}
}
namespace Sirdoggy.ItemSpawnerTweaks.Data
{
internal enum CynJsonSortingModeDto
{
Alphabetical,
LastModified,
LastAccessed
}
internal enum DetailsLinkedResourceModeDto
{
Tutorials,
RelatedVaultFiles
}
internal enum ItemSpawnerDefaultPageDto
{
WelcomePage,
Firearms,
SaveAndLoad
}
internal static class ItemSpawnerPreferencesStore
{
private const string PreferencesFileName = "preferences";
private const string SortModeKey = "SortMode";
private static ExtensibleDictionary _preferences;
public static CynJsonSortingMode? SortMode
{
get
{
string valueOrNull = _preferences.GetValueOrNull("SortMode");
if (valueOrNull == null)
{
return null;
}
return ((CynJsonSortingModeDto)Enum.Parse(typeof(CynJsonSortingModeDto), valueOrNull)).ToDomain();
}
set
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
try
{
if (value.HasValue)
{
string text = value.Value.ToDtoThrowing().ToString();
_preferences.InsertOrUpdateEntry("SortMode", text);
SavePreferencesToFile();
}
}
catch (Exception ex)
{
Plugin.Log.LogError((object)ex.Message);
}
}
}
public static void Init()
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Expected O, but got Unknown
string text = FileIO.ReadFile(Plugin.GetPluginDirectoryName(), "preferences");
if (text == null)
{
_preferences = new ExtensibleDictionary();
}
else
{
_preferences = ExtensibleDictionary.FromJson(text);
}
}
private static void SavePreferencesToFile()
{
string text = _preferences.ToJson();
FileIO.WriteToFile(Plugin.GetPluginDirectoryName(), "preferences", text);
}
}
internal static class Mappers
{
public static CynJsonSortingModeDto? ToDtoThrowing(this CynJsonSortingMode domain)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected I4, but got Unknown
return (int)domain switch
{
0 => CynJsonSortingModeDto.Alphabetical,
2 => CynJsonSortingModeDto.LastAccessed,
1 => CynJsonSortingModeDto.LastModified,
_ => throw new NotSupportedException("Can't map unknown field to dto"),
};
}
public static CynJsonSortingMode? ToDomain(this CynJsonSortingModeDto domain)
{
return domain switch
{
CynJsonSortingModeDto.Alphabetical => (CynJsonSortingMode)0,
CynJsonSortingModeDto.LastAccessed => (CynJsonSortingMode)2,
CynJsonSortingModeDto.LastModified => (CynJsonSortingMode)1,
_ => null,
};
}
public static DetailsLinkedResourceMode? ToDomain(this DetailsLinkedResourceModeDto dto)
{
return dto switch
{
DetailsLinkedResourceModeDto.RelatedVaultFiles => (DetailsLinkedResourceMode)1,
DetailsLinkedResourceModeDto.Tutorials => (DetailsLinkedResourceMode)0,
_ => null,
};
}
}
}
namespace Sirdoggy.ItemSpawnerTweaks.Common
{
internal class CoroutineRunner : MonoBehaviour
{
private static CoroutineRunner _instance;
public static Coroutine Run(IEnumerator coroutine)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
if (!Object.op_Implicit((Object)(object)_instance))
{
GameObject val = new GameObject("CoroutineRunner")
{
hideFlags = (HideFlags)61
};
Object.DontDestroyOnLoad((Object)val);
_instance = val.AddComponent<CoroutineRunner>();
}
return ((MonoBehaviour)_instance).StartCoroutine(coroutine);
}
public static void Stop(Coroutine coroutine)
{
((MonoBehaviour)_instance).StopCoroutine(coroutine);
}
}
internal static class ExtensibleDictionaryExtensions
{
public static string? GetValueOrNull(this ExtensibleDictionary dictionary, string key)
{
if (!dictionary.ContainsKey(key))
{
return null;
}
return dictionary.GetValue(key);
}
}
internal static class TransformExtensions
{
public static List<GameObject> GetAllChildren(this Transform gameObject)
{
List<GameObject> list = new List<GameObject>();
for (int i = 0; i < ((Component)gameObject).transform.childCount; i++)
{
GameObject gameObject2 = ((Component)((Component)gameObject).transform.GetChild(i)).gameObject;
list.Add(gameObject2);
}
return list;
}
}
internal static class ItemSpawnerIDExtensions
{
public static bool IsMainItem(this ItemSpawnerID id)
{
//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)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Expected I4, but got Unknown
EItemCategory category = id.Category;
return (int)category switch
{
5 => true,
0 => true,
1 => true,
2 => true,
3 => true,
9 => true,
_ => false,
};
}
}
internal static class StringUtils
{
public static string RemoveNonAlphanumericAndSpace(string input)
{
if (string.IsNullOrEmpty(input))
{
return input;
}
StringBuilder stringBuilder = new StringBuilder();
foreach (char item in input.Where((char c) => char.IsLetterOrDigit(c) || c == ' '))
{
stringBuilder.Append(item);
}
return stringBuilder.ToString();
}
}
}