using System;
using System.CodeDom.Compiler;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Bounce.ManagedCollections;
using Bounce.Singletons;
using Bounce.TaleSpire.AssetManagement;
using Bounce.Unmanaged;
using Bounce.UnsafeViews;
using DataModel;
using HarmonyLib;
using HideVolumeExtensions.Patches;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using RadialUI;
using RadialUI.Extensions;
using Spaghet.Runtime;
using Spaghet.VM;
using TaleSpire.ContentManagement;
using Unity.Collections;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("HVHP")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("TaleSpire Modding Community")]
[assembly: AssemblyProduct("HVHP")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4e4deb5e-97f9-4901-bf67-6748a9c1229a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
}
}
}
namespace HideVolumeExtensions
{
[BepInPlugin("org.HF.plugins.HVE", "Hide Volume Extensions", "1.0.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public sealed class HVEPlugin : BaseUnityPlugin
{
public const string Guid = "org.HF.plugins.HVE";
public const string Version = "1.0.0.0";
private const string Name = "Hide Volume Extensions";
internal static Harmony harmony;
internal static ManualLogSource _logger;
internal static ConfigEntry<bool> HideOnClose;
internal static string LocalHidden;
internal static ConcurrentStack<HideVolumeItem> HVToDeactivate = new ConcurrentStack<HideVolumeItem>();
internal static ConcurrentStack<HideVolumeItem> HVToActivate = new ConcurrentStack<HideVolumeItem>();
private HideVolumeItem lastItem;
public static void DoPatching()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
harmony = new Harmony("org.HF.plugins.HVE");
harmony.PatchAll();
_logger.LogInfo((object)"Hide Volume Extensions: Patched.");
}
private static void DoConfig(ConfigFile config)
{
HideOnClose = config.Bind<bool>("Door Volume Linking", "Hide On Close", false, (ConfigDescription)null);
}
public static void UnPatch()
{
harmony.UnpatchSelf();
_logger.LogDebug((object)"Hide Volume Extensions: UnPatched.");
}
private void Awake()
{
//IL_005d: 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_0069: 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_0097: Expected O, but got Unknown
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Expected O, but got Unknown
_logger = ((BaseUnityPlugin)this).Logger;
LocalHidden = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location) + "/BoardData";
Directory.CreateDirectory(LocalHidden);
DoConfig(((BaseUnityPlugin)this).Config);
DoPatching();
_logger.LogInfo((object)"Hide Volume Extensions is Active.");
RadialUIPlugin.AddOnHideVolume("org.HF.plugins.HVEAddDoor", new ItemArgs
{
CloseMenuOnActivate = true,
Title = "Show on Door Open",
Action = AddDoorOpen
}, (Func<HideVolumeItem, bool>)CanAddVolume);
RadialUIPlugin.AddOnHideVolume("org.HF.plugins.HVERemoveDoor", new ItemArgs
{
CloseMenuOnActivate = true,
Title = "Remove show on Door Open",
Action = RemoveDoorOpen
}, (Func<HideVolumeItem, bool>)CanRemoveVolume);
}
private void Update()
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: 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)
if (HVToDeactivate.TryPop(out var result))
{
_logger.LogDebug((object)$"Processing HideVolumeItem: {result.HideVolume.Id}");
result.ChangeIsActive(false);
SimpleSingletonBehaviour<HideVolumeManager>.Instance.SetHideVolumeState(result.HideVolume);
}
if (HVToActivate.TryPop(out var result2))
{
_logger.LogDebug((object)$"Processing HideVolumeItem: {result2.HideVolume.Id}");
result2.ChangeIsActive(true);
SimpleSingletonBehaviour<HideVolumeManager>.Instance.SetHideVolumeState(result2.HideVolume);
}
}
private bool CanAddVolume(HideVolumeItem item)
{
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
lastItem = item;
if (!string.IsNullOrEmpty(HideVolumeExtensions.Patches.Patches.selectedDoor))
{
string selectedDoor = HideVolumeExtensions.Patches.Patches.selectedDoor;
SMMPatch.LoadDoorHideVolumes();
int result;
if (SMMPatch.DoorHideVolumes.ContainsKey(selectedDoor))
{
List<string> list = SMMPatch.DoorHideVolumes[selectedDoor];
HideVolume hideVolume = lastItem.HideVolume;
result = ((!list.Contains(((object)(NGuid)(ref hideVolume.Id)).ToString())) ? 1 : 0);
}
else
{
result = 1;
}
return (byte)result != 0;
}
return false;
}
private bool CanRemoveVolume(HideVolumeItem item)
{
//IL_0047: 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)
lastItem = item;
if (!string.IsNullOrEmpty(HideVolumeExtensions.Patches.Patches.selectedDoor))
{
string selectedDoor = HideVolumeExtensions.Patches.Patches.selectedDoor;
SMMPatch.LoadDoorHideVolumes();
if (SMMPatch.DoorHideVolumes.ContainsKey(selectedDoor))
{
List<string> list = SMMPatch.DoorHideVolumes[selectedDoor];
HideVolume hideVolume = lastItem.HideVolume;
return list.Contains(((object)(NGuid)(ref hideVolume.Id)).ToString());
}
return false;
}
return false;
}
private void AddDoorOpen(MapMenuItem i, object o)
{
//IL_007d: 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_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: 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)
if (string.IsNullOrEmpty(HideVolumeExtensions.Patches.Patches.selectedDoor))
{
_logger.LogWarning((object)"No door selected. Please select a door first.");
return;
}
SMMPatch.LoadDoorHideVolumes();
string selectedDoor = HideVolumeExtensions.Patches.Patches.selectedDoor;
if (!SMMPatch.DoorHideVolumes.ContainsKey(selectedDoor))
{
_logger.LogDebug((object)("Adding new door hide volume for contentId: " + selectedDoor));
SMMPatch.DoorHideVolumes[selectedDoor] = new List<string>();
}
List<string> list = SMMPatch.DoorHideVolumes[selectedDoor];
HideVolume hideVolume = lastItem.HideVolume;
if (list.Contains(((object)(NGuid)(ref hideVolume.Id)).ToString()))
{
_logger.LogWarning((object)$"Hide volume {lastItem.HideVolume.Id} already exists for door {selectedDoor}. Skipping addition.");
return;
}
List<string> list2 = SMMPatch.DoorHideVolumes[selectedDoor];
hideVolume = lastItem.HideVolume;
list2.Add(((object)(NGuid)(ref hideVolume.Id)).ToString());
SMMPatch.SaveDoorHideVolumes();
}
private void RemoveDoorOpen(MapMenuItem i, object o)
{
//IL_0057: 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_008b: 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)
if (string.IsNullOrEmpty(HideVolumeExtensions.Patches.Patches.selectedDoor))
{
_logger.LogWarning((object)"No door selected. Please select a door first.");
return;
}
SMMPatch.LoadDoorHideVolumes();
string selectedDoor = HideVolumeExtensions.Patches.Patches.selectedDoor;
if (SMMPatch.DoorHideVolumes.ContainsKey(selectedDoor))
{
List<string> list = SMMPatch.DoorHideVolumes[selectedDoor];
HideVolume hideVolume = lastItem.HideVolume;
if (list.Contains(((object)(NGuid)(ref hideVolume.Id)).ToString()))
{
List<string> list2 = SMMPatch.DoorHideVolumes[selectedDoor];
hideVolume = lastItem.HideVolume;
list2.Remove(((object)(NGuid)(ref hideVolume.Id)).ToString());
}
SMMPatch.SaveDoorHideVolumes();
}
}
}
}
namespace HideVolumeExtensions.Properties
{
[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[DebuggerNonUserCode]
[CompilerGenerated]
internal class Resources
{
private static ResourceManager resourceMan;
private static CultureInfo resourceCulture;
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static ResourceManager ResourceManager
{
get
{
if (resourceMan == null)
{
ResourceManager resourceManager = new ResourceManager("HideVolumeExtensions.Properties.Resources", typeof(Resources).Assembly);
resourceMan = resourceManager;
}
return resourceMan;
}
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
internal Resources()
{
}
}
}
namespace HideVolumeExtensions.Patches
{
[HarmonyPatch(typeof(HideVolumeManager), "AddHideVolume")]
[HarmonyPatch(typeof(HideVolumeManager), "RemoveHideVolume")]
[HarmonyPatch(typeof(HideVolumeManager), "OnHideVolumeAdded")]
[HarmonyPatch(typeof(HideVolumeManager), "OnHideVolumeRemoved")]
[HarmonyPatch(typeof(HideVolumeManager), "OnHideVolumeStateChanged")]
internal sealed class HVMPatch
{
internal static Dictionary<string, HideVolumeItem> _hideVolumeItems;
private static void Postfix(ref BList<HideVolumeItem> ____hideVolumeItems)
{
_hideVolumeItems = ((IEnumerable<HideVolumeItem>)____hideVolumeItems).ToDictionary(delegate(HideVolumeItem hv)
{
//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)
HideVolume hideVolume = hv.HideVolume;
return ((object)(NGuid)(ref hideVolume.Id)).ToString();
});
HVEPlugin._logger.LogDebug((object)$"HideVolumeManager Patched. Total HideVolumes: {_hideVolumeItems.Count}");
HVEPlugin._logger.LogDebug((object)("HideVolumeManager Patched. HideVolumes: " + string.Join(", ", _hideVolumeItems.Keys)));
}
}
[HarmonyPatch(typeof(PlaceableHandle), "Interact")]
internal sealed class Patches
{
internal static string? selectedDoor;
internal static string? lastDoor;
private static void Postfix(ref PlaceableHandle __instance, ref Zone ____zone)
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: 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)
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_010f: Expected O, but got Unknown
if (!LocalClient.IsInGmMode)
{
return;
}
HVEPlugin._logger.LogDebug((object)"Placeable Interacted with");
UnsafeView<PlaceableDataV0> val = default(UnsafeView<PlaceableDataV0>);
PlaceableRef val2 = default(PlaceableRef);
if (!__instance.HasValue || !InternalPackManager.Placeables.TryGetValue(__instance.ContentId, ref val) || !__instance.TryGetPlaceableRef(ref val2))
{
return;
}
int scriptIndex = ((Placeable)((PlaceableRef)(ref val2)).Data).ScriptIndex;
if (scriptIndex != -1)
{
NativeList<PrivateState> val3 = default(NativeList<PrivateState>);
NativeSharedIntArray val4 = default(NativeSharedIntArray);
NativeParallelHashMap<UniqueScriptId, int> val5 = default(NativeParallelHashMap<UniqueScriptId, int>);
____zone.StateMachineManager.GetInternalState(ref val3, ref val4, ref val5);
ref PrivateState reference = ref NativeCollectionExtensionMethods.ElementReadOnlyRef<PrivateState>(val3, scriptIndex);
ushort executionStateCode = reference.ExecutionState.ExecutionStateCode;
if (executionStateCode < val.Value.StateMachineScript.GetValue().Menus.TakeView().Length)
{
lastDoor = $"{reference.ScriptId}:{____zone.Coord}";
MapMenu mapMenu = MapMenuManagerPatch.mapMenu;
ItemArgs val6 = new ItemArgs();
val6.Action = SelectDoor;
val6.Title = "Select Door";
val6.CloseMenuOnActivate = true;
mapMenu.AddItem(val6);
}
}
}
private static void SelectDoor(MapMenuItem item, object o)
{
HVEPlugin._logger.LogDebug((object)("Door value " + selectedDoor));
selectedDoor = lastDoor;
HVEPlugin._logger.LogDebug((object)("Door updated to " + selectedDoor));
}
}
[HarmonyPatch(typeof(StateMachineManager), "ReceiveMessage")]
internal sealed class SMMPatch
{
private static BoardGuid CurrentBoard;
internal static Dictionary<string, List<string>> DoorHideVolumes;
internal static void LoadDoorHideVolumes()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: 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)
if (!(CurrentBoard != BoardSessionManager.CurrentBoardInfo.Id))
{
return;
}
CurrentBoard = BoardSessionManager.CurrentBoardInfo.Id;
try
{
string path = Path.Join(string.op_Implicit(HVEPlugin.LocalHidden), string.op_Implicit(((object)(BoardGuid)(ref BoardSessionManager.CurrentBoardInfo.Id)).ToString()));
if (File.Exists(path))
{
string text = File.ReadAllText(path);
DoorHideVolumes = JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(text) ?? new Dictionary<string, List<string>>();
}
else
{
DoorHideVolumes = new Dictionary<string, List<string>>();
}
}
catch (Exception ex)
{
HVEPlugin._logger.LogWarning((object)("Failed to load door hide volumes: " + ex.Message));
DoorHideVolumes = new Dictionary<string, List<string>>();
}
}
internal static void SaveDoorHideVolumes()
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
string contents = JsonConvert.SerializeObject((object)DoorHideVolumes, (Formatting)1);
File.WriteAllText(Path.Join(string.op_Implicit(HVEPlugin.LocalHidden), string.op_Implicit(((object)(BoardGuid)(ref BoardSessionManager.CurrentBoardInfo.Id)).ToString())), contents);
}
private static void Postfix(ref StateMessageV6 msg, ref bool resetLocalTime, ref StateMachineManager __instance)
{
//IL_0029: 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_0124: Unknown result type (might be due to invalid IL or missing references)
//IL_0129: Unknown result type (might be due to invalid IL or missing references)
//IL_0243: Unknown result type (might be due to invalid IL or missing references)
//IL_0248: Unknown result type (might be due to invalid IL or missing references)
string arg = ((object)(UniqueScriptId)(ref msg.QualifiedScriptId.ScriptId)).ToString();
HVEPlugin._logger.LogDebug((object)$"{arg}:{msg.QualifiedScriptId.ZoneCoord}");
arg = $"{arg}:{msg.QualifiedScriptId.ZoneCoord}";
LoadDoorHideVolumes();
HideVolume hideVolume;
if (msg.ExecutionStateCode == 0)
{
HVEPlugin._logger.LogDebug((object)$"message state code: {msg.ExecutionStateCode}");
if (!DoorHideVolumes.ContainsKey(arg))
{
return;
}
HVEPlugin._logger.LogDebug((object)("Door Hide Volumes found for " + arg));
{
foreach (string item in DoorHideVolumes[arg].Where((string volumeId) => HVMPatch._hideVolumeItems.ContainsKey(volumeId)))
{
HVEPlugin._logger.LogDebug((object)("Processing volume " + item + " for door " + arg));
hideVolume = HVMPatch._hideVolumeItems[item].HideVolume;
if (((HideVolume)(ref hideVolume)).IsActive)
{
HVEPlugin.HVToDeactivate.Push(HVMPatch._hideVolumeItems[item]);
}
}
return;
}
}
if (msg.ExecutionStateCode != 1 || !HVEPlugin.HideOnClose.Value)
{
return;
}
HVEPlugin._logger.LogDebug((object)$"message state code: {msg.ExecutionStateCode}");
if (!DoorHideVolumes.ContainsKey(arg))
{
return;
}
HVEPlugin._logger.LogDebug((object)("Door Hide Volumes found for " + arg));
foreach (string item2 in DoorHideVolumes[arg].Where((string volumeId) => HVMPatch._hideVolumeItems.ContainsKey(volumeId)))
{
HVEPlugin._logger.LogDebug((object)("Processing volume " + item2 + " for door " + arg));
hideVolume = HVMPatch._hideVolumeItems[item2].HideVolume;
if (!((HideVolume)(ref hideVolume)).IsActive)
{
HVEPlugin.HVToActivate.Push(HVMPatch._hideVolumeItems[item2]);
}
}
}
}
}