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 PluginUtilities;
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.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("HVHP")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Hollo")]
[assembly: AssemblyProduct("HVHP")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4e4deb5e-97f9-4901-bf67-6748a9c1229a")]
[assembly: AssemblyFileVersion("1.2.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.2.1.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.DCHV", "Door Controlled Hide Volumes", "1.2.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public sealed class DoorControlledHideVolumesPlugin : DependencyUnityPlugin
{
public const string Guid = "org.HF.plugins.DCHV";
public const string Version = "1.2.1.0";
private const string Name = "Door Controlled Hide Volumes";
internal static Harmony harmony;
internal static ManualLogSource _logger;
internal static ConfigEntry<bool> HideOnClose;
internal static string LocalHidden;
internal static ConcurrentStack<HideVolumeItem> HVToDeactivate;
internal static ConcurrentStack<HideVolumeItem> HVToActivate;
private HideVolumeItem lastItem;
public static void DoPatching()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Expected O, but got Unknown
harmony = new Harmony("org.HF.plugins.DCHV");
harmony.PatchAll();
_logger.LogInfo((object)"Door Controlled Hide Volumes: Patched.");
}
private static void DoConfig(ConfigFile config)
{
HideOnClose = config.Bind<bool>("Door Volume Linking", "Hide On Close", false, (ConfigDescription)null);
}
protected override void OnAwake()
{
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Expected O, but got Unknown
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: 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();
RadialUIPlugin.AddOnHideVolume("org.HF.plugins.DCHVAddDoor", new ItemArgs
{
CloseMenuOnActivate = true,
Title = "Show on Door Open",
Action = AddDoorOpen
}, (Func<HideVolumeItem, bool>)CanAddVolume);
RadialUIPlugin.AddOnHideVolume("org.HF.plugins.DCHVRemoveDoor", new ItemArgs
{
CloseMenuOnActivate = true,
Title = "Remove show on Door Open",
Action = RemoveDoorOpen
}, (Func<HideVolumeItem, bool>)CanRemoveVolume);
HVToActivate = new ConcurrentStack<HideVolumeItem>();
HVToDeactivate = new ConcurrentStack<HideVolumeItem>();
_logger.LogInfo((object)"Door Controlled Hide Volumes loaded");
}
protected override void OnDestroyed()
{
RadialUIPlugin.RemoveOnHideVolume("org.HF.plugins.DCHVAddDoor");
RadialUIPlugin.RemoveOnHideVolume("org.HF.plugins.DCHVRemoveDoor");
HVToActivate.Clear();
HVToDeactivate.Clear();
harmony.UnpatchSelf();
harmony = null;
HideOnClose = null;
LocalHidden = null;
_logger = null;
HVToActivate = null;
HVToDeactivate = null;
((BaseUnityPlugin)this).Logger.LogDebug((object)"Door Controlled Hide Volumes unloaded");
}
private void Update()
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_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_0096: Unknown result type (might be due to invalid IL or missing references)
ConcurrentStack<HideVolumeItem> hVToDeactivate = HVToDeactivate;
if (hVToDeactivate != null && hVToDeactivate.TryPop(out var result))
{
_logger.LogDebug((object)$"Processing HideVolumeItem: {result.HideVolume.Id}");
result.ChangeIsActive(false);
SimpleSingletonBehaviour<HideVolumeManager>.Instance.SetHideVolumeState(result.HideVolume);
}
ConcurrentStack<HideVolumeItem> hVToActivate = HVToActivate;
if (hVToActivate != null && 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_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
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 true;
}
return false;
}
private bool CanRemoveVolume(HideVolumeItem item)
{
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
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_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
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_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: 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)
{
resourceMan = new ResourceManager("HideVolumeExtensions.Properties.Resources", typeof(Resources).Assembly);
}
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();
});
DoorControlledHideVolumesPlugin._logger.LogDebug((object)$"HideVolumeManager Patched. Total HideVolumes: {_hideVolumeItems.Count}");
DoorControlledHideVolumesPlugin._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 Prefix(ref PlaceableHandle __instance)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
DoorControlledHideVolumesPlugin._logger.LogInfo((object)"Prefix Triggr");
UnsafeView<PlaceableDataV0> val = default(UnsafeView<PlaceableDataV0>);
PlaceableRef val2 = default(PlaceableRef);
if (__instance.HasValue && InternalPackManager.Placeables.TryGetValue(__instance.ContentId, ref val) && __instance.TryGetPlaceableRef(ref val2))
{
DoorControlledHideVolumesPlugin._logger.LogInfo((object)$"Data: {val.Value.Id}: {((Placeable)((PlaceableRef)(ref val2)).Data).WorldOrigin}");
}
}
private static void Postfix(ref PlaceableHandle __instance, ref Zone ____zone)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: 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_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_00ff: Expected O, but got Unknown
if (!LocalClient.IsInGmMode)
{
return;
}
DoorControlledHideVolumesPlugin._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);
if (reference.ExecutionState.ExecutionStateCode < val.Value.StateMachineScript.GetValue().Menus.TakeView().Length)
{
lastDoor = $"{reference.ScriptId}:{____zone.Coord}";
MapMenuManagerPatch.mapMenu.AddItem(new ItemArgs
{
Action = SelectDoor,
Title = "Select Door",
CloseMenuOnActivate = true
});
}
}
}
private static void SelectDoor(MapMenuItem item, object o)
{
DoorControlledHideVolumesPlugin._logger.LogDebug((object)("Door value " + selectedDoor));
selectedDoor = lastDoor;
DoorControlledHideVolumesPlugin._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_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: 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)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: 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(DoorControlledHideVolumesPlugin.LocalHidden), string.op_Implicit(((object)(BoardGuid)(ref BoardSessionManager.CurrentBoardInfo.Id)).ToString()));
if (File.Exists(path))
{
DoorHideVolumes = JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(File.ReadAllText(path)) ?? new Dictionary<string, List<string>>();
}
else
{
DoorHideVolumes = new Dictionary<string, List<string>>();
}
}
catch (Exception ex)
{
DoorControlledHideVolumesPlugin._logger.LogWarning((object)("Failed to load door hide volumes: " + ex.Message));
DoorHideVolumes = new Dictionary<string, List<string>>();
}
}
internal static void SaveDoorHideVolumes()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: 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(DoorControlledHideVolumesPlugin.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_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_0211: Unknown result type (might be due to invalid IL or missing references)
//IL_0216: Unknown result type (might be due to invalid IL or missing references)
string arg = ((object)(UniqueScriptId)(ref msg.QualifiedScriptId.ScriptId)).ToString();
DoorControlledHideVolumesPlugin._logger.LogDebug((object)$"{arg}:{msg.QualifiedScriptId.ZoneCoord}");
arg = $"{arg}:{msg.QualifiedScriptId.ZoneCoord}";
LoadDoorHideVolumes();
HideVolume hideVolume;
if (msg.ExecutionStateCode == 0)
{
DoorControlledHideVolumesPlugin._logger.LogDebug((object)$"message state code: {msg.ExecutionStateCode}");
if (!DoorHideVolumes.ContainsKey(arg))
{
return;
}
DoorControlledHideVolumesPlugin._logger.LogDebug((object)("Door Hide Volumes found for " + arg));
{
foreach (string item in DoorHideVolumes[arg].Where((string volumeId) => HVMPatch._hideVolumeItems.ContainsKey(volumeId)))
{
DoorControlledHideVolumesPlugin._logger.LogDebug((object)("Processing volume " + item + " for door " + arg));
hideVolume = HVMPatch._hideVolumeItems[item].HideVolume;
if (((HideVolume)(ref hideVolume)).IsActive)
{
DoorControlledHideVolumesPlugin.HVToDeactivate.Push(HVMPatch._hideVolumeItems[item]);
}
}
return;
}
}
if (msg.ExecutionStateCode != 1 || !DoorControlledHideVolumesPlugin.HideOnClose.Value)
{
return;
}
DoorControlledHideVolumesPlugin._logger.LogDebug((object)$"message state code: {msg.ExecutionStateCode}");
if (!DoorHideVolumes.ContainsKey(arg))
{
return;
}
DoorControlledHideVolumesPlugin._logger.LogDebug((object)("Door Hide Volumes found for " + arg));
foreach (string item2 in DoorHideVolumes[arg].Where((string volumeId) => HVMPatch._hideVolumeItems.ContainsKey(volumeId)))
{
DoorControlledHideVolumesPlugin._logger.LogDebug((object)("Processing volume " + item2 + " for door " + arg));
hideVolume = HVMPatch._hideVolumeItems[item2].HideVolume;
if (!((HideVolume)(ref hideVolume)).IsActive)
{
DoorControlledHideVolumesPlugin.HVToActivate.Push(HVMPatch._hideVolumeItems[item2]);
}
}
}
}
}