using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("DungeonSplitter")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DungeonSplitter")]
[assembly: AssemblyTitle("DungeonSplitter")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.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 DungeonSplitter
{
[BepInPlugin("dungeon_splitter", "Dungeon Splitter", "1.1")]
public class DungeonSplitter : BaseUnityPlugin
{
public const string GUID = "dungeon_splitter";
public const string NAME = "Dungeon Splitter";
public const string VERSION = "1.1";
public const float DungeonHeight = 1500f;
public static ConfigEntry<string> configAlwaysSend;
public void Awake()
{
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
configAlwaysSend = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Always send", "", "List of object ids that are always sent to clients. Separate with commas.");
configAlwaysSend.SettingChanged += delegate
{
DungeonPrefabs.Postfix();
};
SetupWatcher();
new Harmony("dungeon_splitter").PatchAll();
}
private void OnDestroy()
{
((BaseUnityPlugin)this).Config.Save();
}
private void SetupWatcher()
{
FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Path.GetDirectoryName(((BaseUnityPlugin)this).Config.ConfigFilePath), Path.GetFileName(((BaseUnityPlugin)this).Config.ConfigFilePath));
fileSystemWatcher.Changed += ReadConfigValues;
fileSystemWatcher.Created += ReadConfigValues;
fileSystemWatcher.Renamed += ReadConfigValues;
fileSystemWatcher.IncludeSubdirectories = true;
fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
fileSystemWatcher.EnableRaisingEvents = true;
}
private void ReadConfigValues(object sender, FileSystemEventArgs e)
{
if (!File.Exists(((BaseUnityPlugin)this).Config.ConfigFilePath))
{
return;
}
try
{
((BaseUnityPlugin)this).Config.Reload();
}
catch
{
Debug.LogWarning((object)"Failed to reload config file");
}
}
}
[HarmonyPatch(typeof(ZDOMan), "CreateSyncList")]
public class CreateSyncList
{
private static void Prefix(ZDOPeer peer)
{
FindObjects.InDungeon = peer.m_peer.m_refPos.y >= 1500f;
FindObjects.SendDungeons = true;
}
}
[HarmonyPatch(typeof(ZDOMan), "ReleaseNearbyZDOS")]
public class ReleaseNearbyZDOS
{
private static void Prefix(Vector3 refPosition)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
FindObjects.InDungeon = refPosition.y >= 1500f;
FindObjects.SendDungeons = false;
}
}
[HarmonyPatch(typeof(ZNetScene), "CreateDestroyObjects")]
public class CreateDestroyObjects
{
private static void Prefix()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
FindObjects.InDungeon = ZNet.instance.GetReferencePosition().y >= 1500f;
FindObjects.SendDungeons = false;
}
}
[HarmonyPatch(typeof(ZNetScene), "IsAreaReady")]
public class IsAreaReady
{
private static void Prefix(Vector3 point)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
FindObjects.InDungeon = point.y >= 1500f;
FindObjects.SendDungeons = false;
}
}
[HarmonyPatch(typeof(ZDOMan), "FindObjects")]
public class FindObjects
{
public static HashSet<int> DungeonHashes = new HashSet<int>();
public static HashSet<int> TeleportHashes = new HashSet<int>();
public static bool SendDungeons;
public static bool InDungeon;
private static bool Prefix(ZDOMan __instance, Vector2i sector, List<ZDO> objects)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
int num = __instance.SectorToIndex(sector);
List<ZDO> value;
if (num >= 0)
{
if (__instance.m_objectsBySector[num] != null)
{
objects.AddRange(__instance.m_objectsBySector[num].Where(IsOk).ToList());
return false;
}
}
else if (__instance.m_objectsByOutsideSector.TryGetValue(sector, out value))
{
objects.AddRange(value.Where(IsOk).ToList());
}
return false;
}
public static bool IsOk(ZDO zdo)
{
if (!TeleportHashes.Contains(zdo.m_prefab) && InDungeon != zdo.m_position.y >= 1500f)
{
if (SendDungeons)
{
return DungeonHashes.Contains(zdo.m_prefab);
}
return false;
}
return true;
}
}
[HarmonyPatch(typeof(ZDOMan), "FindDistantObjects")]
public class FindDistantObjects
{
private static bool Prefix(ZDOMan __instance, Vector2i sector, List<ZDO> objects)
{
//IL_0001: 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)
int num = __instance.SectorToIndex(sector);
if (num >= 0)
{
List<ZDO> list = __instance.m_objectsBySector[num];
if (list == null)
{
return false;
}
objects.AddRange(list.Where((ZDO zdo) => zdo.Distant && zdo.m_position.y >= 1500f == FindObjects.InDungeon).ToList());
return false;
}
if (__instance.m_objectsByOutsideSector.TryGetValue(sector, out var value))
{
objects.AddRange(value.Where((ZDO zdo) => zdo.Distant && zdo.m_position.y >= 1500f == FindObjects.InDungeon).ToList());
}
return false;
}
}
[HarmonyPatch(typeof(ZoneSystem), "Start")]
public class DungeonPrefabs
{
public static int ProxyHash = StringExtensionMethods.GetStableHashCode("LocationProxy");
public static void Postfix()
{
FindObjects.TeleportHashes = (from prefab in ZNetScene.instance.m_namedPrefabs.Values
where Object.op_Implicit((Object)(object)prefab.GetComponentInChildren<Teleport>())
select StringExtensionMethods.GetStableHashCode(((Object)prefab).name)).ToHashSet();
FindObjects.TeleportHashes.Add(ProxyHash);
FindObjects.DungeonHashes = (from prefab in ZNetScene.instance.m_namedPrefabs.Values
where Object.op_Implicit((Object)(object)prefab.GetComponent<DungeonGenerator>())
select StringExtensionMethods.GetStableHashCode(((Object)prefab).name)).ToHashSet();
foreach (string item in from str in DungeonSplitter.configAlwaysSend.Value.Split(new char[1] { ',' })
select str.Trim() into str
where !string.IsNullOrEmpty(str)
select str)
{
FindObjects.DungeonHashes.Add(StringExtensionMethods.GetStableHashCode(item));
}
}
}
}