Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of HatLib v0.0.7
HatLib.dll
Decompiled 2 weeks agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; 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 BepInEx.Logging; using Dawn; using Dawn.Internal; using Dawn.Utils; using Dusk; using GameNetcodeStuff; using HarmonyLib; using HatLib.NetcodePatcher; using HatLib.Patches; using HatLib.Tools; using Microsoft.CodeAnalysis; using Newtonsoft.Json.Linq; using Unity.Collections; using Unity.Netcode; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("HatLib")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.0.7.0")] [assembly: AssemblyInformationalVersion("0.0.7")] [assembly: AssemblyProduct("HatLib")] [assembly: AssemblyTitle("HatLib")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.7.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] [module: NetcodePatchedAssembly] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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] [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] [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 HatLib { internal static class ConfigManager { internal static ConfigEntry<bool> DebugLogs { get; private set; } internal static void Bind(ConfigFile config) { DebugLogs = config.Bind<bool>("Internal", "Debug Logs", false, "If true, allows debug logging"); } } internal static class Log { internal static void Debug(string message) { if (ConfigManager.DebugLogs.Value) { Write((LogLevel)32, message); } } internal static void Info(string message) { Write((LogLevel)16, message); } internal static void Warn(string message) { Write((LogLevel)4, message); } internal static void Error(string message) { Write((LogLevel)2, message); } internal static void Fatal(string message) { Write((LogLevel)1, message); } private static void Write(LogLevel logLevel, string message) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) Plugin.mls.Log(logLevel, (object)message); } } [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInPlugin("MrHat.Lib", "HatLib", "0.0.7")] public class Plugin : BaseUnityPlugin { public const string modGUID = "MrHat.Lib"; private const string modName = "HatLib"; private const string modVersion = "0.0.7"; private const string DawnLibGUID = "com.github.teamxiaolan.dawnlib"; private const string DuskGUID = "com.github.teamxiaolan.dawnlib.dusk"; private readonly Harmony _harmony = new Harmony("MrHat.Lib"); internal static ManualLogSource mls; internal static Plugin instance; private void Awake() { instance = this; mls = Logger.CreateLogSource("MrHat.Lib"); ConfigManager.Bind(((BaseUnityPlugin)this).Config); _harmony.PatchAll(typeof(GameNetworkManagerPatches)); _harmony.PatchAll(typeof(ShipBoundPatches)); _harmony.PatchAll(typeof(ShipBuildModeManagerPatches)); _harmony.PatchAll(typeof(StartOfRoundPatches)); mls.LogInfo((object)"HatLib loaded"); } } public class RoundEvents { private static event Action? gameSaved; public static event Action<StartOfRound>? OnRoundStart; public static event Action<StartOfRound>? OnRoundEnd; public static event Action<StartOfRound>? OnShipLeft; public static event Action<StartOfRound>? OnShipReadyToLand; public static event Action<StartOfRound>? OnShipItemsLoaded; public static event Action<StartOfRound>? OnShipUnlockablesSynced; public static event Action<StartOfRound>? OnPlayersLoadedReset; public static event Action<StartOfRound>? OnLocalDisconnect; public static event Action<StartOfRound>? OnDestroy; [Obsolete("Save persistent data when it changes instead")] public static event Action? OnGameSaved { add { gameSaved += value; } remove { gameSaved -= value; } } private RoundEvents() { } internal static void RoundStart(StartOfRound startOfRound) { RoundEvents.OnRoundStart?.Invoke(startOfRound); } internal static void RoundEnd(StartOfRound startOfRound) { RoundEvents.OnRoundEnd?.Invoke(startOfRound); } internal static void ShipLeft(StartOfRound startOfRound) { RoundEvents.OnShipLeft?.Invoke(startOfRound); } internal static void ShipReadyToLand(StartOfRound startOfRound) { RoundEvents.OnShipReadyToLand?.Invoke(startOfRound); } internal static void ShipItemsLoaded(StartOfRound startOfRound) { RoundEvents.OnShipItemsLoaded?.Invoke(startOfRound); } internal static void ShipUnlockablesSynced(StartOfRound startOfRound) { RoundEvents.OnShipUnlockablesSynced?.Invoke(startOfRound); } internal static void PlayersLoadedReset(StartOfRound startOfRound) { RoundEvents.OnPlayersLoadedReset?.Invoke(startOfRound); } internal static void Disconnect(StartOfRound startOfRound) { RoundEvents.OnLocalDisconnect?.Invoke(startOfRound); } internal static void Destroy(StartOfRound startOfRound) { RoundEvents.OnDestroy?.Invoke(startOfRound); } internal static void GameSaved() { RoundEvents.gameSaved?.Invoke(); } } public static class MyPluginInfo { public const string PLUGIN_GUID = "HatLib"; public const string PLUGIN_NAME = "HatLib"; public const string PLUGIN_VERSION = "0.0.7"; } } namespace HatLib.Tools { public static class AudioTools { public static bool PlayOneShot(AudioSource? source, AudioClip? clip) { if ((Object)(object)source == (Object)null || (Object)(object)clip == (Object)null) { return false; } source.PlayOneShot(clip); return true; } public static bool Load(AudioClip? clip) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)clip != (Object)null && (int)clip.loadState == 0) { return clip.LoadAudioData(); } return false; } public static bool Unload(AudioClip? clip) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Invalid comparison between Unknown and I4 if ((Object)(object)clip != (Object)null && (int)clip.loadState == 2) { return clip.UnloadAudioData(); } return false; } public static bool SwapClip(AudioSource? source, AudioClip? clip, bool play) { if ((Object)(object)source == (Object)null) { return false; } source.clip = clip; if (play && (Object)(object)clip != (Object)null) { source.Play(); } return true; } public static bool Stop(AudioSource? source, bool zeroVolume = false) { if ((Object)(object)source == (Object)null) { return false; } if (zeroVolume) { source.volume = 0f; } source.Stop(); return true; } public static int StopMany(bool zeroVolume = false, params AudioSource?[] sources) { if (sources == null) { return 0; } int num = 0; for (int i = 0; i < sources.Length; i++) { if (Stop(sources[i], zeroVolume)) { num++; } } return num; } } public static class CoroutineTools { public static bool Start(MonoBehaviour owner, ref Coroutine? handle, IEnumerator job) { if ((Object)(object)owner == (Object)null) { throw new ArgumentNullException("owner"); } if (job == null) { throw new ArgumentNullException("job"); } if (handle != null) { return false; } handle = owner.StartCoroutine(job); return true; } public static bool Stop(MonoBehaviour owner, ref Coroutine? handle) { if ((Object)(object)owner == (Object)null) { throw new ArgumentNullException("owner"); } if (handle == null) { return false; } owner.StopCoroutine(handle); handle = null; return true; } public static bool Restart(MonoBehaviour owner, ref Coroutine? handle, IEnumerator job) { Stop(owner, ref handle); return Start(owner, ref handle, job); } public static Coroutine? NextFrame(MonoBehaviour owner, Action action) { if ((Object)(object)owner == (Object)null) { throw new ArgumentNullException("owner"); } if (action == null) { throw new ArgumentNullException("action"); } return owner.StartCoroutine(NextFrameWait(action)); } public static Coroutine? Delay(MonoBehaviour owner, float seconds, Action action) { if ((Object)(object)owner == (Object)null) { throw new ArgumentNullException("owner"); } if (action == null) { throw new ArgumentNullException("action"); } return owner.StartCoroutine(DelayWait(seconds, action)); } private static IEnumerator NextFrameWait(Action action) { yield return null; action(); } private static IEnumerator DelayWait(float seconds, Action action) { yield return (object)new WaitForSeconds(seconds); action(); } } public static class DawnSaveData { public static bool ReadText(NamespacedKey key, out string? raw) { if (key == null) { throw new ArgumentNullException("key"); } raw = string.Empty; PersistentDataContainer currentContract = DawnLib.GetCurrentContract(); if (currentContract != null) { return ((DataContainer)currentContract).TryGet<string>(key, ref raw); } return false; } public static bool SaveText(NamespacedKey key, string raw) { return Save(key, raw); } public static bool Read<T>(NamespacedKey key, out T? value) { if (key == null) { throw new ArgumentNullException("key"); } value = default(T); PersistentDataContainer currentContract = DawnLib.GetCurrentContract(); if (currentContract != null) { return ((DataContainer)currentContract).TryGet<T>(key, ref value); } return false; } public static bool Save<T>(NamespacedKey key, T value) { if (key == null) { throw new ArgumentNullException("key"); } if (value == null) { throw new ArgumentNullException("value"); } if (!CanSave()) { return false; } PersistentDataContainer currentContract = DawnLib.GetCurrentContract(); if (currentContract == null) { return false; } using (((DataContainer)currentContract).CreateEditContext()) { ((DataContainer)currentContract).Set<T>(key, value); } return true; } public static bool ReadJson(NamespacedKey parentKey, NamespacedKey childKey, out JObject? value) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown if (parentKey == null) { throw new ArgumentNullException("parentKey"); } if (childKey == null) { throw new ArgumentNullException("childKey"); } value = new JObject(); PersistentDataContainer currentContract = DawnLib.GetCurrentContract(); ChildPersistentDataContainer val = default(ChildPersistentDataContainer); if (currentContract != null && ((DataContainer)currentContract).TryGet<ChildPersistentDataContainer>(parentKey, ref val)) { return ((DataContainer)val).TryGet<JObject>(childKey, ref value); } return false; } public static bool SaveJson(NamespacedKey parentKey, NamespacedKey childKey, JObject value) { return Save<JObject>(parentKey, childKey, value); } public static bool Read<T>(NamespacedKey parentKey, NamespacedKey childKey, out T? value) { if (parentKey == null) { throw new ArgumentNullException("parentKey"); } if (childKey == null) { throw new ArgumentNullException("childKey"); } value = default(T); PersistentDataContainer currentContract = DawnLib.GetCurrentContract(); ChildPersistentDataContainer val = default(ChildPersistentDataContainer); if (currentContract != null && ((DataContainer)currentContract).TryGet<ChildPersistentDataContainer>(parentKey, ref val)) { return ((DataContainer)val).TryGet<T>(childKey, ref value); } return false; } public static bool Save<T>(NamespacedKey parentKey, NamespacedKey childKey, T value) { //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Expected O, but got Unknown if (parentKey == null) { throw new ArgumentNullException("parentKey"); } if (childKey == null) { throw new ArgumentNullException("childKey"); } if (value == null) { throw new ArgumentNullException("value"); } if (!CanSave()) { return false; } PersistentDataContainer currentContract = DawnLib.GetCurrentContract(); if (currentContract == null) { return false; } using (((DataContainer)currentContract).CreateEditContext()) { ChildPersistentDataContainer val = default(ChildPersistentDataContainer); if (!((DataContainer)currentContract).TryGet<ChildPersistentDataContainer>(parentKey, ref val)) { val = new ChildPersistentDataContainer(currentContract); ((DataContainer)currentContract).Set<ChildPersistentDataContainer>(parentKey, val); } ((DataContainer)val).Set<T>(childKey, value); } return true; } public static bool Remove(NamespacedKey key) { if (key == null) { throw new ArgumentNullException("key"); } if (!CanSave()) { return false; } PersistentDataContainer currentContract = DawnLib.GetCurrentContract(); if (currentContract == null) { return false; } using (((DataContainer)currentContract).CreateEditContext()) { ((DataContainer)currentContract).Remove(key); } return true; } public static bool Remove(NamespacedKey parentKey, NamespacedKey childKey, bool removeGroupWhenEmpty = false) { if (parentKey == null) { throw new ArgumentNullException("parentKey"); } if (childKey == null) { throw new ArgumentNullException("childKey"); } if (!CanSave()) { return false; } PersistentDataContainer currentContract = DawnLib.GetCurrentContract(); if (currentContract == null) { return false; } using (((DataContainer)currentContract).CreateEditContext()) { ChildPersistentDataContainer val = default(ChildPersistentDataContainer); if (!((DataContainer)currentContract).TryGet<ChildPersistentDataContainer>(parentKey, ref val)) { return false; } ((DataContainer)val).Remove(childKey); if (removeGroupWhenEmpty && ((DataContainer)val).Count == 0) { ((DataContainer)currentContract).Remove(parentKey); } } return true; } private static bool CanSave() { NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton != (Object)null) { return singleton.IsServer; } return false; } } public class DawnSaveSync { private const float DelaySeconds = 1.25f; private static readonly WaitForSeconds DelayWait = new WaitForSeconds(1.25f); private readonly NamespacedKey dataKey; private readonly NamespacedKey requestKey; private readonly Func<string> saveData; private readonly Action<string> acceptData; private readonly bool saveOnGameSaved; private Coroutine? hostCoroutine; private Coroutine? clientCoroutine; private MonoBehaviour? hostOwner; private MonoBehaviour? clientOwner; private string rawData = string.Empty; private bool dataReceived; private bool listening; private bool HostRestoreFinished { get; set; } = true; private bool ClientDelayFinished { get; set; } public static DawnSaveSync Bind(NamespacedKey dataKey, Func<string> saveData, Action<string> acceptData, bool saveOnGameSaved = true) { DawnSaveSync dawnSaveSync = new DawnSaveSync(dataKey, saveData, acceptData, saveOnGameSaved); dawnSaveSync.Enable(); return dawnSaveSync; } public DawnSaveSync(NamespacedKey dataKey, Func<string> saveData, Action<string> acceptData, bool saveOnGameSaved = true) { this.dataKey = dataKey ?? throw new ArgumentNullException("dataKey"); requestKey = RequestKey(dataKey); this.saveData = saveData ?? throw new ArgumentNullException("saveData"); this.acceptData = acceptData ?? throw new ArgumentNullException("acceptData"); this.saveOnGameSaved = saveOnGameSaved; } public void Enable() { if (!listening) { listening = true; HatNet.Init(); HatNet.AddClientHandler(dataKey, DataReceived); HatNet.AddServerHandler(requestKey, RequestReceived); RoundEvents.OnShipItemsLoaded += ShipItemsLoaded; RoundEvents.OnShipUnlockablesSynced += ShipUnlockablesSynced; RoundEvents.OnLocalDisconnect += Clear; RoundEvents.OnDestroy += Clear; if (saveOnGameSaved) { DawnSaveEvents.OnCollectData += SaveAutomatic; } } } public void Disable() { if (listening) { listening = false; HatNet.RemoveClientHandler(dataKey, DataReceived); HatNet.RemoveServerHandler(requestKey, RequestReceived); RoundEvents.OnShipItemsLoaded -= ShipItemsLoaded; RoundEvents.OnShipUnlockablesSynced -= ShipUnlockablesSynced; RoundEvents.OnLocalDisconnect -= Clear; RoundEvents.OnDestroy -= Clear; DawnSaveEvents.OnCollectData -= SaveAutomatic; Clear(); } } public bool Save() { return Save(saveData() ?? string.Empty); } public bool Save(string data) { if (data == null) { throw new ArgumentNullException("data"); } if (!HostRestoreFinished) { return false; } if (!DawnSaveData.SaveText(dataKey, data)) { return false; } rawData = data; dataReceived = true; return true; } public bool SaveAndPublish() { if (!Save()) { return false; } if (PublishRaw(rawData)) { return true; } Log.Warn($"Dawn save sync saved {dataKey} but could not send it"); return false; } public bool Remove() { if (!HostRestoreFinished) { return false; } if (!DawnSaveData.Remove(dataKey)) { return false; } rawData = string.Empty; dataReceived = true; return true; } public bool Publish() { NetworkManager singleton = NetworkManager.Singleton; if (!HostRestoreFinished || (Object)(object)singleton == (Object)null || !singleton.IsServer) { return false; } rawData = saveData() ?? string.Empty; dataReceived = true; return PublishRaw(rawData); } public bool Request() { NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null || !singleton.IsListening) { return false; } return HatNet.SendToServer(requestKey, string.Empty); } internal void Clear() { StopHostCoroutine(); StopClientCoroutine(); HostRestoreFinished = true; ClientDelayFinished = false; rawData = string.Empty; dataReceived = false; } private static NamespacedKey RequestKey(NamespacedKey key) { return NamespacedKey.From(key.Namespace, key.Key + "_request"); } private void SaveAutomatic(PersistentDataContainer contract) { if (HostRestoreFinished) { rawData = saveData() ?? string.Empty; ((DataContainer)contract).Set<string>(dataKey, rawData); dataReceived = true; } } private void ShipItemsLoaded(StartOfRound startOfRound) { NetworkManager singleton = NetworkManager.Singleton; if (!((Object)(object)singleton == (Object)null) && singleton.IsServer) { StopHostCoroutine(); HostRestoreFinished = false; hostOwner = (MonoBehaviour?)(object)startOfRound; hostCoroutine = ((MonoBehaviour)startOfRound).StartCoroutine(HostRestoreAfterDelay()); } } private void ShipUnlockablesSynced(StartOfRound startOfRound) { NetworkManager singleton = NetworkManager.Singleton; if (!((Object)(object)singleton != (Object)null) || !singleton.IsServer) { StopClientCoroutine(); ClientDelayFinished = false; clientOwner = (MonoBehaviour?)(object)startOfRound; clientCoroutine = ((MonoBehaviour)startOfRound).StartCoroutine(ClientRestoreAfterDelay()); } } private void Clear(StartOfRound startOfRound) { Clear(); } private void RequestReceived(ulong senderClientId, string data) { NetworkManager singleton = NetworkManager.Singleton; if (HostRestoreFinished && !((Object)(object)singleton == (Object)null) && singleton.IsServer) { rawData = saveData() ?? string.Empty; dataReceived = true; HatNet.SendToClient(dataKey, senderClientId, rawData); } } private void DataReceived(ulong senderClientId, string data) { NetworkManager singleton = NetworkManager.Singleton; if (!((Object)(object)singleton != (Object)null) || !singleton.IsServer) { ReceiveData(data); } } private void ReceiveData(string data) { rawData = data ?? string.Empty; dataReceived = true; NetworkManager singleton = NetworkManager.Singleton; if (ClientDelayFinished && ((Object)(object)singleton == (Object)null || !singleton.IsServer)) { acceptData(rawData); } } private IEnumerator HostRestoreAfterDelay() { yield return DelayWait; string raw; string obj = (rawData = ((DawnSaveData.ReadText(dataKey, out raw) && raw != null) ? raw : string.Empty)); dataReceived = true; acceptData(obj); rawData = saveData() ?? string.Empty; PublishRaw(rawData); HostRestoreFinished = true; hostCoroutine = null; hostOwner = null; } private IEnumerator ClientRestoreAfterDelay() { yield return DelayWait; ClientDelayFinished = true; clientCoroutine = null; clientOwner = null; if (dataReceived) { acceptData(rawData); } else { Request(); } } private bool PublishRaw(string data) { NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton != (Object)null && singleton.IsServer) { return HatNet.SendToClients(dataKey, data); } return false; } private void StopHostCoroutine() { if (hostCoroutine != null && !((Object)(object)hostOwner == (Object)null)) { hostOwner.StopCoroutine(hostCoroutine); hostCoroutine = null; hostOwner = null; } } private void StopClientCoroutine() { if (clientCoroutine != null && !((Object)(object)clientOwner == (Object)null)) { clientOwner.StopCoroutine(clientCoroutine); clientCoroutine = null; clientOwner = null; } } } public static class DawnFindResource { [Obsolete("Use OnFreeze and Resolve instead")] public static void Add<TInfo>(Registry<TInfo> registry, NamespacedKey<TInfo> key, Action<TInfo> assign) where TInfo : INamespaced<TInfo> { if (registry == null) { Log.Warn($"Dawn resource {key} could not be found because its registry is missing"); return; } if (assign == null) { Log.Warn($"Dawn resource {key} could not be assigned because its action is missing"); return; } DawnFindResource.OnFreeze<TInfo>(registry, (Action)delegate { if (DawnFindResource.Resolve<TInfo>(registry, key, out TInfo info)) { assign(info); } }); } [Obsolete("Use OnFreeze and Resolve")] public static void Add<TInfo, TValue>(Registry<TInfo> registry, NamespacedKey<TInfo> key, Func<TInfo, TValue?> read, Action<TValue> assign) where TInfo : INamespaced<TInfo> where TValue : class { DawnFindResource.Add<TInfo, TValue>(registry, key, read, typeof(TValue).Name, assign); } [Obsolete("Use OnFreeze and Resolve")] public static void Add<TInfo, TValue>(Registry<TInfo> registry, NamespacedKey<TInfo> key, Func<TInfo, TValue?> read, string name, Action<TValue> assign) where TInfo : INamespaced<TInfo> where TValue : class { if (registry == null) { Log.Warn("Dawn resource " + name + " could not be found because its registry is missing"); return; } if (read == null) { Log.Warn("Dawn resource " + name + " could not be read because its reader is missing"); return; } if (assign == null) { Log.Warn("Dawn resource " + name + " could not be assigned because its action is missing"); return; } DawnFindResource.OnFreeze<TInfo>(registry, (Action)delegate { if (DawnFindResource.Resolve<TInfo, TValue>(registry, key, read, name, out TValue value)) { assign(value); } }); } public static void OnFreeze<TInfo>(Registry<TInfo> registry, Action action) where TInfo : INamespaced<TInfo> { if (registry == null) { throw new ArgumentNullException("registry"); } if (action == null) { throw new ArgumentNullException("action"); } if (registry.IsFrozen) { action(); } else { registry.OnFreeze += action; } } public static bool Resolve<TInfo>(Registry<TInfo> registry, NamespacedKey<TInfo> key, out TInfo info) where TInfo : INamespaced<TInfo> { info = default(TInfo); if (registry == null) { throw new ArgumentNullException("registry"); } if (key == null) { throw new ArgumentNullException("key"); } if (registry.TryGetValue(key, ref info)) { return true; } info = default(TInfo); Log.Warn($"Dawn resource {key} is missing"); return false; } [Obsolete("Use Resolve with a name param")] public static bool Resolve<TInfo, TValue>(Registry<TInfo> registry, NamespacedKey<TInfo> key, Func<TInfo, TValue?> read, out TValue value) where TInfo : INamespaced<TInfo> where TValue : class { return DawnFindResource.Resolve<TInfo, TValue>(registry, key, read, typeof(TValue).Name, out value); } public static bool Resolve<TInfo, TValue>(Registry<TInfo> registry, NamespacedKey<TInfo> key, Func<TInfo, TValue?> read, string name, out TValue value) where TInfo : INamespaced<TInfo> where TValue : class { value = null; if (registry == null) { throw new ArgumentNullException("registry"); } if (key == null) { throw new ArgumentNullException("key"); } if (read == null) { throw new ArgumentNullException("read"); } if (name == null) { throw new ArgumentNullException("name"); } if (!DawnFindResource.Resolve<TInfo>(registry, key, out TInfo info)) { return false; } TValue val = read(info); if (Missing(val)) { Log.Warn("Dawn resource value for " + name + " is missing"); return false; } value = val; return true; } private static bool Missing<TValue>([NotNullWhen(false)] TValue? value) where TValue : class { if (value != null) { Object val = (Object)(object)((value is Object) ? value : null); if (val != null) { return val == (Object)null; } return false; } return true; } } public static class DawnSaveEvents { public static event Action<PersistentDataContainer>? OnCollectData; internal static void Collect() { NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null || !singleton.IsServer) { return; } PersistentDataContainer currentContract = DawnLib.GetCurrentContract(); if (currentContract == null) { return; } ShipBoundsRegistry.MarkItemsInsideExtras(); Action<PersistentDataContainer> onCollectData = DawnSaveEvents.OnCollectData; if (onCollectData == null) { return; } using (((DataContainer)currentContract).CreateEditContext()) { Delegate[] invocationList = onCollectData.GetInvocationList(); for (int i = 0; i < invocationList.Length; i++) { try { ((Action<PersistentDataContainer>)invocationList[i])(currentContract); } catch (Exception arg) { Log.Error($"Dawn save collector failed: {arg}"); } } } } } public class DuskConfigInjector { public readonly string dawnModGUID = dawnModGUID ?? throw new ArgumentNullException("dawnModGUID"); public DuskConfigInjector(string dawnModGUID) { } [Obsolete("Use Read with a section param")] public static T Read<T>(string dawnModGUID, string settingName) { if (string.IsNullOrWhiteSpace(dawnModGUID)) { Log.Warn("Dusk config could not be read because the mod GUID is empty"); return default(T); } if (string.IsNullOrWhiteSpace(settingName)) { Log.Warn("Dusk config could not be read because the setting name is empty"); return default(T); } DuskMod val = ((IEnumerable<DuskMod>)DuskMod.AllMods).FirstOrDefault((Func<DuskMod, bool>)((DuskMod duskMod) => duskMod.Plugin.GUID == dawnModGUID)); if (val == null) { Log.Warn("Dusk config could not be read because " + dawnModGUID + " is missing"); return default(T); } ConfigEntryBase val2 = ((IEnumerable<ConfigEntryBase>)val.ConfigEntries).FirstOrDefault((Func<ConfigEntryBase, bool>)((ConfigEntryBase configEntry) => configEntry.Definition.Key == settingName)); if (val2 == null) { Log.Warn("Dusk config setting " + settingName + " is missing"); return default(T); } if (!(val2 is ConfigEntry<T> val3)) { Log.Warn("Dusk config setting " + settingName + " has the wrong value type"); return default(T); } return val3.Value; } public static T Read<T>(string dawnModGUID, string section, string settingName) { if (dawnModGUID == null) { throw new ArgumentNullException("dawnModGUID"); } if (section == null) { throw new ArgumentNullException("section"); } if (settingName == null) { throw new ArgumentNullException("settingName"); } if (string.IsNullOrWhiteSpace(dawnModGUID)) { Log.Warn("Dusk config could not be read because the mod GUID is empty"); return default(T); } if (string.IsNullOrWhiteSpace(section)) { Log.Warn("Dusk config could not be read because the section is empty"); return default(T); } if (string.IsNullOrWhiteSpace(settingName)) { Log.Warn("Dusk config could not be read because the setting name is empty"); return default(T); } DuskMod val = ((IEnumerable<DuskMod>)DuskMod.AllMods).FirstOrDefault((Func<DuskMod, bool>)((DuskMod duskMod) => duskMod.Plugin.GUID == dawnModGUID)); if (val == null) { Log.Warn("Dusk config could not be read because " + dawnModGUID + " is missing"); return default(T); } ConfigEntryBase val2 = ((IEnumerable<ConfigEntryBase>)val.ConfigEntries).FirstOrDefault((Func<ConfigEntryBase, bool>)((ConfigEntryBase configEntry) => configEntry.Definition.Section == section && configEntry.Definition.Key == settingName)); if (val2 == null) { Log.Warn("Dusk config setting " + section + "/" + settingName + " is missing"); return default(T); } if (!(val2 is ConfigEntry<T> val3)) { Log.Warn("Dusk config setting " + section + "/" + settingName + " has the wrong value type"); return default(T); } return val3.Value; } public ConfigEntry<T>? Bind<T>(string section, string settingName, T defaultValue, string description) { if (section == null) { throw new ArgumentNullException("section"); } if (settingName == null) { throw new ArgumentNullException("settingName"); } if (description == null) { throw new ArgumentNullException("description"); } if (string.IsNullOrWhiteSpace(dawnModGUID)) { Log.Warn("Dusk config could not be made because the mod GUID is empty"); return null; } if (string.IsNullOrWhiteSpace(section)) { Log.Warn("Dusk config could not be made because the section is empty"); return null; } if (string.IsNullOrWhiteSpace(settingName)) { Log.Warn("Dusk config could not be made because the setting name is empty"); return null; } DuskMod val = ((IEnumerable<DuskMod>)DuskMod.AllMods).FirstOrDefault((Func<DuskMod, bool>)((DuskMod duskMod) => duskMod.Plugin.GUID == dawnModGUID)); if (val == null) { Log.Warn("Dusk config could not be made because " + dawnModGUID + " is missing"); return null; } ConfigContext val2 = val.ConfigManager.CreateConfigSection(section); try { return val2.Bind<T>(settingName, description, defaultValue); } finally { ((IDisposable)val2)?.Dispose(); } } public ConfigEntry<T>? Bind<T>(string section, string settingName, T defaultValue, string description, T minValue, T maxValue) where T : IComparable { if (section == null) { throw new ArgumentNullException("section"); } if (settingName == null) { throw new ArgumentNullException("settingName"); } if (description == null) { throw new ArgumentNullException("description"); } if (string.IsNullOrWhiteSpace(dawnModGUID)) { Log.Warn("Dusk config could not be made because the mod GUID is empty"); return null; } if (string.IsNullOrWhiteSpace(section)) { Log.Warn("Dusk config could not be made because the section is empty"); return null; } if (string.IsNullOrWhiteSpace(settingName)) { Log.Warn("Dusk config could not be made because the setting name is empty"); return null; } DuskMod val = ((IEnumerable<DuskMod>)DuskMod.AllMods).FirstOrDefault((Func<DuskMod, bool>)((DuskMod duskMod) => duskMod.Plugin.GUID == dawnModGUID)); if (val == null) { Log.Warn("Dusk config could not be made because " + dawnModGUID + " is missing"); return null; } return ConfigFileExtensions.CleanedBind<T>(val.ConfigManager.File, section, settingName, defaultValue, description, minValue, maxValue); } } public static class FindItems { public static NamespacedKey<DawnItemInfo>? DawnKey(GrabbableObject item) { if ((Object)(object)item == (Object)null) { throw new ArgumentNullException("item"); } if ((Object)(object)item.itemProperties == (Object)null) { Log.Warn("Dawn item key could not be read because the item properties are empty"); return null; } return ((DawnBaseInfo<DawnItemInfo>)(object)ItemExtensions.GetDawnInfo(item.itemProperties))?.TypedKey; } public static bool MatchesDawnKey(GrabbableObject item, NamespacedKey<DawnItemInfo> itemKey) { if ((Object)(object)item == (Object)null) { throw new ArgumentNullException("item"); } if (itemKey == null) { throw new ArgumentNullException("itemKey"); } return ((object)DawnKey(item))?.Equals((object?)itemKey) ?? false; } public static List<GrabbableObject> Active(Func<GrabbableObject, bool>? itemFilter = null) { GrabbableObject[] array = Object.FindObjectsByType<GrabbableObject>((FindObjectsInactive)0, (FindObjectsSortMode)0); List<GrabbableObject> list = new List<GrabbableObject>(); foreach (GrabbableObject val in array) { if (itemFilter == null || itemFilter(val)) { list.Add(val); } } return list; } public static List<GrabbableObject> Active(NamespacedKey<DawnItemInfo> itemKey, Func<GrabbableObject, bool>? itemFilter = null) { if (itemKey == null) { throw new ArgumentNullException("itemKey"); } return Active((Func<GrabbableObject, bool>?)((GrabbableObject item) => MatchesDawnKey(item, itemKey) && (itemFilter == null || itemFilter(item)))); } public static GrabbableObject? ClosestTo(Vector3 position, float radius, Func<GrabbableObject, bool>? itemFilter = null) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) GrabbableObject[] items = Object.FindObjectsByType<GrabbableObject>((FindObjectsInactive)0, (FindObjectsSortMode)0); return ClosestTo(position, radius, items, itemFilter); } public static GrabbableObject? ClosestTo(NamespacedKey<DawnItemInfo> itemKey, Vector3 position, float radius, Func<GrabbableObject, bool>? itemFilter = null) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) if (itemKey == null) { throw new ArgumentNullException("itemKey"); } GrabbableObject[] items = Object.FindObjectsByType<GrabbableObject>((FindObjectsInactive)0, (FindObjectsSortMode)0); return ClosestTo(itemKey, position, radius, items, itemFilter); } public static GrabbableObject? ClosestTo(Vector3 position, float radius, IReadOnlyList<GrabbableObject> items, Func<GrabbableObject, bool>? itemFilter = null) { //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: 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) //IL_0046: Unknown result type (might be due to invalid IL or missing references) if (items == null) { throw new ArgumentNullException("items"); } float num = radius * radius; GrabbableObject result = null; for (int i = 0; i < items.Count; i++) { GrabbableObject val = items[i]; if (!((Object)(object)val == (Object)null) && (itemFilter == null || itemFilter(val))) { Vector3 val2 = ((Component)val).transform.position - position; float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude; if (!(sqrMagnitude >= num)) { num = sqrMagnitude; result = val; } } } return result; } public static GrabbableObject? ClosestTo(NamespacedKey<DawnItemInfo> itemKey, Vector3 position, float radius, IReadOnlyList<GrabbableObject> items, Func<GrabbableObject, bool>? itemFilter = null) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) if (itemKey == null) { throw new ArgumentNullException("itemKey"); } if (items == null) { throw new ArgumentNullException("items"); } return ClosestTo(position, radius, items, (GrabbableObject item) => MatchesDawnKey(item, itemKey) && (itemFilter == null || itemFilter(item))); } } public static class GrabbablePlacement { public static bool Place(GrabbableObject? item, Transform? rootParent, Vector3 worldPosition, Quaternion worldRotation) { //IL_0033: 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_005b: 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_004b: 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_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0079: 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) //IL_007c: 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_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)item == (Object)null) { return false; } item.parentObject = null; if ((Object)(object)((Component)item).transform.parent != (Object)(object)rootParent) { ((Component)item).transform.SetParent(rootParent, true); } if (item.originalScale != Vector3.zero) { ((Component)item).transform.localScale = item.originalScale; } ((Component)item).transform.SetPositionAndRotation(worldPosition, worldRotation); item.startFallingPosition = (item.targetFloorPosition = (((Object)(object)rootParent != (Object)null) ? ((Component)item).transform.localPosition : worldPosition)) + Vector3.up * 0.0001f; item.fallTime = 1f; item.hasHitGround = true; item.reachedFloorTarget = true; return true; } public static bool DropFrom(GrabbableObject? item, Vector3 startPosition, Vector3 floorPosition) { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0044: 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_0022: 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_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)item == (Object)null) { return false; } Transform parent = ((Component)item).transform.parent; if ((Object)(object)parent != (Object)null) { item.startFallingPosition = parent.InverseTransformPoint(startPosition); item.targetFloorPosition = parent.InverseTransformPoint(floorPosition); } else { item.startFallingPosition = startPosition; item.targetFloorPosition = floorPosition; } item.fallTime = 0f; item.hasHitGround = false; item.reachedFloorTarget = false; return true; } } public delegate void HatNetMessageHandler(ulong senderClientId, string data); public static class HatNet { [CompilerGenerated] private static class <>O { public static HandleNamedMessageDelegate <0>__ServerMessageReceived; public static HandleNamedMessageDelegate <1>__ClientMessageReceived; } private const string ServerMessageName = "MrHat.Lib.HatNet.Server"; private const string ClientMessageName = "MrHat.Lib.HatNet.Client"; private static readonly Dictionary<string, List<HatNetMessageHandler>> ServerHandlers = new Dictionary<string, List<HatNetMessageHandler>>(StringComparer.Ordinal); private static readonly Dictionary<string, List<HatNetMessageHandler>> ClientHandlers = new Dictionary<string, List<HatNetMessageHandler>>(StringComparer.Ordinal); private static NetworkManager? messageManager; private static bool messagesReady; internal static void Init() { //IL_0059: 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) //IL_0064: Expected O, but got Unknown //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Expected O, but got Unknown NetworkManager singleton = NetworkManager.Singleton; if (!((Object)(object)singleton == (Object)null) && singleton.CustomMessagingManager != null && (!messagesReady || !((Object)(object)messageManager == (Object)(object)singleton))) { Shutdown(); messageManager = singleton; messagesReady = true; CustomMessagingManager customMessagingManager = singleton.CustomMessagingManager; object obj = <>O.<0>__ServerMessageReceived; if (obj == null) { HandleNamedMessageDelegate val = ServerMessageReceived; <>O.<0>__ServerMessageReceived = val; obj = (object)val; } customMessagingManager.RegisterNamedMessageHandler("MrHat.Lib.HatNet.Server", (HandleNamedMessageDelegate)obj); CustomMessagingManager customMessagingManager2 = singleton.CustomMessagingManager; object obj2 = <>O.<1>__ClientMessageReceived; if (obj2 == null) { HandleNamedMessageDelegate val2 = ClientMessageReceived; <>O.<1>__ClientMessageReceived = val2; obj2 = (object)val2; } customMessagingManager2.RegisterNamedMessageHandler("MrHat.Lib.HatNet.Client", (HandleNamedMessageDelegate)obj2); Log.Info("HatNet messages ready"); } } internal static void Shutdown() { if (!messagesReady || (Object)(object)messageManager == (Object)null || messageManager.CustomMessagingManager == null) { messageManager = null; messagesReady = false; return; } messageManager.CustomMessagingManager.UnregisterNamedMessageHandler("MrHat.Lib.HatNet.Server"); messageManager.CustomMessagingManager.UnregisterNamedMessageHandler("MrHat.Lib.HatNet.Client"); messageManager = null; messagesReady = false; Log.Info("HatNet messages stopped"); } public static void AddServerHandler(NamespacedKey key, HatNetMessageHandler handler) { Add(ServerHandlers, key, handler); } public static void AddClientHandler(NamespacedKey key, HatNetMessageHandler handler) { Add(ClientHandlers, key, handler); } public static void RemoveServerHandler(NamespacedKey key, HatNetMessageHandler handler) { Remove(ServerHandlers, key, handler); } public static void RemoveClientHandler(NamespacedKey key, HatNetMessageHandler handler) { Remove(ClientHandlers, key, handler); } public unsafe static bool SendToServer(NamespacedKey key, string data) { //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) if (key == null) { throw new ArgumentNullException("key"); } if (data == null) { throw new ArgumentNullException("data"); } Init(); NetworkManager val = (NetworkManager)(((Object)(object)messageManager != (Object)null) ? ((object)messageManager) : ((object)NetworkManager.Singleton)); if ((Object)(object)val == (Object)null || !val.IsListening || val.CustomMessagingManager == null) { return false; } FastBufferWriter val2 = CreateWriter(key, data); try { val.CustomMessagingManager.SendNamedMessage("MrHat.Lib.HatNet.Server", 0uL, val2, (NetworkDelivery)4); return true; } finally { ((IDisposable)(*(FastBufferWriter*)(&val2))/*cast due to .constrained prefix*/).Dispose(); } } public unsafe static bool SendToClients(NamespacedKey key, string data) { //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) if (key == null) { throw new ArgumentNullException("key"); } if (data == null) { throw new ArgumentNullException("data"); } Init(); NetworkManager val = (NetworkManager)(((Object)(object)messageManager != (Object)null) ? ((object)messageManager) : ((object)NetworkManager.Singleton)); if ((Object)(object)val == (Object)null || !val.IsListening || !val.IsServer || val.CustomMessagingManager == null) { return false; } FastBufferWriter val2 = CreateWriter(key, data); try { val.CustomMessagingManager.SendNamedMessageToAll("MrHat.Lib.HatNet.Client", val2, (NetworkDelivery)4); return true; } finally { ((IDisposable)(*(FastBufferWriter*)(&val2))/*cast due to .constrained prefix*/).Dispose(); } } public unsafe static bool SendToClient(NamespacedKey key, ulong clientId, string data) { //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: 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) if (key == null) { throw new ArgumentNullException("key"); } if (data == null) { throw new ArgumentNullException("data"); } Init(); NetworkManager val = (NetworkManager)(((Object)(object)messageManager != (Object)null) ? ((object)messageManager) : ((object)NetworkManager.Singleton)); if ((Object)(object)val == (Object)null || !val.IsListening || !val.IsServer || val.CustomMessagingManager == null) { return false; } FastBufferWriter val2 = CreateWriter(key, data); try { val.CustomMessagingManager.SendNamedMessage("MrHat.Lib.HatNet.Client", clientId, val2, (NetworkDelivery)4); return true; } finally { ((IDisposable)(*(FastBufferWriter*)(&val2))/*cast due to .constrained prefix*/).Dispose(); } } private static bool Add(Dictionary<string, List<HatNetMessageHandler>> handlers, NamespacedKey key, HatNetMessageHandler handler) { if (key == null) { throw new ArgumentNullException("key"); } if (handler == null) { throw new ArgumentNullException("handler"); } string key2 = ((object)key).ToString(); if (!handlers.TryGetValue(key2, out List<HatNetMessageHandler> value)) { value = (handlers[key2] = new List<HatNetMessageHandler>()); } if (value.Contains(handler)) { return false; } value.Add(handler); return true; } private static bool Remove(Dictionary<string, List<HatNetMessageHandler>> handlers, NamespacedKey key, HatNetMessageHandler handler) { if (key == null) { throw new ArgumentNullException("key"); } if (handler == null) { throw new ArgumentNullException("handler"); } string key2 = ((object)key).ToString(); if (!handlers.TryGetValue(key2, out List<HatNetMessageHandler> value)) { return false; } if (!value.Remove(handler)) { return false; } if (value.Count == 0) { handlers.Remove(key2); } return true; } private static FastBufferWriter CreateWriter(NamespacedKey key, string data) { //IL_0041: Unknown result type (might be due to invalid IL or missing references) string text = ((object)key).ToString(); int num = Math.Max(64, text.Length * 4 + data.Length * 4 + 64); FastBufferWriter result = default(FastBufferWriter); ((FastBufferWriter)(ref result))..ctor(num, (Allocator)2, -1); ((FastBufferWriter)(ref result)).WriteValueSafe(text, false); ((FastBufferWriter)(ref result)).WriteValueSafe(data, false); return result; } private static void ServerMessageReceived(ulong senderClientId, FastBufferReader reader) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) MessageReceived(senderClientId, reader, ServerHandlers); } private static void ClientMessageReceived(ulong senderClientId, FastBufferReader reader) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) MessageReceived(senderClientId, reader, ClientHandlers); } private static void MessageReceived(ulong senderClientId, FastBufferReader reader, Dictionary<string, List<HatNetMessageHandler>> handlers) { string text = default(string); ((FastBufferReader)(ref reader)).ReadValueSafe(ref text, false); string data = default(string); ((FastBufferReader)(ref reader)).ReadValueSafe(ref data, false); if (!handlers.TryGetValue(text, out List<HatNetMessageHandler> value)) { Log.Debug("HatNet ignored the message for " + text + " because no handler exists"); return; } HatNetMessageHandler[] array = value.ToArray(); for (int i = 0; i < array.Length; i++) { array[i](senderClientId, data); } } } public static class LocalPlayerCollider { public static Collider? Current() { GameNetworkManager instance = GameNetworkManager.Instance; if ((Object)(object)instance == (Object)null) { return null; } PlayerControllerB localPlayerController = instance.localPlayerController; if ((Object)(object)localPlayerController == (Object)null) { return null; } return localPlayerController.playerCollider; } public static bool Matches(Collider other) { if ((Object)(object)other != (Object)null) { return (Object)(object)other == (Object)(object)Current(); } return false; } } [DisallowMultipleComponent] public class LocalPlayerTrigger : MonoBehaviour { private Collider? playerCollider; private bool playerInside; public Collider? PlayerCollider { get { if ((Object)(object)playerCollider == (Object)null) { playerCollider = LocalPlayerCollider.Current(); } return playerCollider; } } public bool PlayerInside => playerInside; public event Action<Collider>? Entered; public event Action<Collider>? Exited; public static LocalPlayerTrigger? Arm(Collider? bounds) { if ((Object)(object)bounds == (Object)null) { return null; } bounds.isTrigger = true; Rigidbody val = default(Rigidbody); if (!((Component)bounds).gameObject.TryGetComponent<Rigidbody>(ref val)) { val = ((Component)bounds).gameObject.AddComponent<Rigidbody>(); } val.isKinematic = false; val.useGravity = false; val.constraints = (RigidbodyConstraints)126; LocalPlayerTrigger result = default(LocalPlayerTrigger); if (!((Component)bounds).TryGetComponent<LocalPlayerTrigger>(ref result)) { return ((Component)bounds).gameObject.AddComponent<LocalPlayerTrigger>(); } return result; } private void OnDisable() { playerInside = false; } private void OnDestroy() { this.Entered = null; this.Exited = null; playerCollider = null; playerInside = false; } private void OnTriggerEnter(Collider other) { MarkEntered(other); } private void OnTriggerStay(Collider other) { MarkEntered(other); } private void OnTriggerExit(Collider other) { if (MatchesPlayer(other)) { playerInside = false; this.Exited?.Invoke(other); } } private void MarkEntered(Collider other) { if (!playerInside && MatchesPlayer(other)) { playerInside = true; this.Entered?.Invoke(other); } } private bool MatchesPlayer(Collider other) { Collider val = LocalPlayerCollider.Current(); if ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)playerCollider) { playerCollider = val; } return (Object)(object)other == (Object)(object)playerCollider; } } public static class NetworkRefs { public static Coroutine? WhenReady(MonoBehaviour? owner, ulong networkObjectId, Action<NetworkObject>? action, float seconds = 8f, int frames = 0) { if (!((Object)(object)owner == (Object)null) && action != null) { return owner.StartCoroutine(Wait(networkObjectId, action, seconds, frames)); } return null; } public static Coroutine? WhenReady<T>(MonoBehaviour? owner, ulong networkObjectId, Action<T>? action, float seconds = 8f, int frames = 0) where T : Component { if (!((Object)(object)owner == (Object)null) && action != null) { return owner.StartCoroutine(Wait(networkObjectId, delegate(NetworkObject networkObject) { T obj = default(T); if (((Component)networkObject).TryGetComponent<T>(ref obj)) { action(obj); } }, seconds, frames)); } return null; } public static Coroutine? WhenReady(MonoBehaviour? owner, NetworkObjectReference reference, Action<NetworkObject>? action, float seconds = 8f, int frames = 0) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)owner == (Object)null) && action != null) { return owner.StartCoroutine(Wait(reference, action, seconds, frames)); } return null; } public static Coroutine? WhenReady<T>(MonoBehaviour? owner, NetworkObjectReference reference, Action<T>? action, float seconds = 8f, int frames = 0) where T : Component { //IL_001f: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)owner == (Object)null) && action != null) { return owner.StartCoroutine(Wait(reference, delegate(NetworkObject networkObject) { T obj = default(T); if (((Component)networkObject).TryGetComponent<T>(ref obj)) { action(obj); } }, seconds, frames)); } return null; } private static IEnumerator Wait(NetworkObjectReference reference, Action<NetworkObject> action, float seconds, int frames) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) NetworkObject networkObject = null; float startedAt = Time.realtimeSinceStartup; while (Time.realtimeSinceStartup - startedAt < seconds && !((NetworkObjectReference)(ref reference)).TryGet(ref networkObject, (NetworkManager)null)) { yield return null; } if (!((Object)(object)networkObject == (Object)null)) { for (int i = 0; i < frames; i++) { yield return null; } action(networkObject); } } private static IEnumerator Wait(ulong networkObjectId, Action<NetworkObject> action, float seconds, int frames) { NetworkObject networkObject = null; float startedAt = Time.realtimeSinceStartup; while (Time.realtimeSinceStartup - startedAt < seconds) { NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton != (Object)null && singleton.SpawnManager.SpawnedObjects.TryGetValue(networkObjectId, out networkObject)) { break; } yield return null; } if (!((Object)(object)networkObject == (Object)null)) { for (int i = 0; i < frames; i++) { yield return null; } action(networkObject); } } } [Serializable] public class PlayerAnimatorSwap { public RuntimeAnimatorController localAnimator; public RuntimeAnimatorController remoteAnimator; } public class PlayerAnimatorTools { private static readonly int SprintingHash = Animator.StringToHash("Sprinting"); private static readonly int JumpingHash = Animator.StringToHash("Jumping"); private static readonly int WalkingHash = Animator.StringToHash("Walking"); private static readonly int CrouchingHash = Animator.StringToHash("crouching"); private static readonly string[] RequiredPlayerLayers = new string[5] { "UpperBodyEmotes", "EmotesNoArms", "HoldingItemsRightHand", "HoldingItemsBothHands", "SpecialAnimations" }; private Animator? animator; private RuntimeAnimatorController? originalAnimator; private RuntimeAnimatorController? replacementAnimator; public bool IsActive { get; private set; } public bool SwapHeld(PlayerControllerB? player, PlayerAnimatorSwap? replacement) { if (IsActive) { return true; } if ((Object)(object)player == (Object)null || replacement == null) { return false; } GameNetworkManager instance = GameNetworkManager.Instance; if ((Object)(object)instance == (Object)null) { return false; } bool flag = (Object)(object)player == (Object)(object)instance.localPlayerController; RuntimeAnimatorController val = (flag ? replacement.localAnimator : replacement.remoteAnimator); RuntimeAnimatorController val2 = (flag ? player.playersManager.localClientAnimatorController : player.playersManager.otherClientsAnimatorController); return Swap(player.playerBodyAnimator, val, val2); } public bool Swap(Animator? playerAnimator, RuntimeAnimatorController? replacementAnimator) { RuntimeAnimatorController val = null; if ((Object)(object)playerAnimator != (Object)null) { val = playerAnimator.runtimeAnimatorController; } return Swap(playerAnimator, replacementAnimator, val); } private bool Swap(Animator? playerAnimator, RuntimeAnimatorController? replacementAnimator, RuntimeAnimatorController? originalAnimator) { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) if (IsActive) { return true; } if ((Object)(object)playerAnimator == (Object)null || (Object)(object)replacementAnimator == (Object)null || (Object)(object)originalAnimator == (Object)null) { return false; } animator = playerAnimator; this.originalAnimator = originalAnimator; this.replacementAnimator = replacementAnimator; AnimatorStateInfo currentAnimatorStateInfo = playerAnimator.GetCurrentAnimatorStateInfo(0); float normalizedTime = ((AnimatorStateInfo)(ref currentAnimatorStateInfo)).normalizedTime; bool flag = playerAnimator.GetBool(CrouchingHash); bool flag2 = playerAnimator.GetBool(WalkingHash); bool flag3 = playerAnimator.GetBool(JumpingHash); bool flag4 = playerAnimator.GetBool(SprintingHash); playerAnimator.runtimeAnimatorController = replacementAnimator; for (int i = 0; i < RequiredPlayerLayers.Length; i++) { if (playerAnimator.GetLayerIndex(RequiredPlayerLayers[i]) < 0) { playerAnimator.runtimeAnimatorController = originalAnimator; Log.Warn("Player animator could not be changed because layer " + RequiredPlayerLayers[i] + " is missing"); animator = null; this.originalAnimator = null; this.replacementAnimator = null; return false; } } playerAnimator.Rebind(); playerAnimator.Play(((AnimatorStateInfo)(ref currentAnimatorStateInfo)).fullPathHash, 0, normalizedTime); playerAnimator.SetBool(CrouchingHash, flag); playerAnimator.SetBool(WalkingHash, flag2); playerAnimator.SetBool(JumpingHash, flag3); playerAnimator.SetBool(SprintingHash, flag4); playerAnimator.Update(0f); IsActive = true; return true; } public void Restore() { //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) if (IsActive) { if ((Object)(object)animator != (Object)null && (Object)(object)animator.runtimeAnimatorController == (Object)(object)replacementAnimator) { AnimatorStateInfo currentAnimatorStateInfo = animator.GetCurrentAnimatorStateInfo(0); float normalizedTime = ((AnimatorStateInfo)(ref currentAnimatorStateInfo)).normalizedTime; bool flag = animator.GetBool(CrouchingHash); bool flag2 = animator.GetBool(WalkingHash); bool flag3 = animator.GetBool(JumpingHash); bool flag4 = animator.GetBool(SprintingHash); animator.runtimeAnimatorController = originalAnimator; animator.Rebind(); animator.Play(((AnimatorStateInfo)(ref currentAnimatorStateInfo)).fullPathHash, 0, normalizedTime); animator.SetBool(CrouchingHash, flag); animator.SetBool(WalkingHash, flag2); animator.SetBool(JumpingHash, flag3); animator.SetBool(SprintingHash, flag4); animator.Update(0f); } animator = null; originalAnimator = null; replacementAnimator = null; IsActive = false; } } } public abstract class PlayerAnimatorReplacement : GrabbableObject { [Header("Player Animator")] [SerializeField] private PlayerAnimatorSwap playerAnimator = new PlayerAnimatorSwap(); private readonly PlayerAnimatorTools playerAnimatorTools = new PlayerAnimatorTools(); protected bool SwapHeldPlayerAnimator() { return playerAnimatorTools.SwapHeld(base.playerHeldBy, playerAnimator); } protected void RestoreHeldPlayerAnimator() { playerAnimatorTools.Restore(); } protected override void __initializeVariables() { ((GrabbableObject)this).__initializeVariables(); } protected override void __initializeRpcs() { ((GrabbableObject)this).__initializeRpcs(); } protected internal override string __getTypeName() { return "PlayerAnimatorReplacement"; } } public static class PrefabSpawns { public static bool Grabbable(Item? item, Vector3 position, Quaternion rotation, out GrabbableObject grabbable, out NetworkObject networkObject, Transform? parent = null) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) grabbable = null; networkObject = null; GameObject val = null; if ((Object)(object)item != (Object)null) { val = item.spawnPrefab; } if ((Object)(object)val != (Object)null) { return Grabbable(val, position, rotation, out grabbable, out networkObject, parent); } return false; } public static bool Grabbable(GameObject? prefab, Vector3 position, Quaternion rotation, out GrabbableObject grabbable, out NetworkObject networkObject, Transform? parent = null) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) grabbable = null; networkObject = null; if ((Object)(object)prefab == (Object)null) { return false; } GameObject val = Object.Instantiate<GameObject>(prefab, position, rotation, parent); GrabbableObject val2 = default(GrabbableObject); NetworkObject val3 = default(NetworkObject); if (!val.TryGetComponent<GrabbableObject>(ref val2) || !val.TryGetComponent<NetworkObject>(ref val3)) { Object.Destroy((Object)(object)val); return false; } grabbable = val2; networkObject = val3; return true; } public static T? Component<T>(T? prefab, Vector3 position, Quaternion rotation, Transform? parent = null) where T : Component { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)prefab == (Object)null)) { return Object.Instantiate<T>(prefab, position, rotation, parent); } return default(T); } public static GameObject? GameObject(GameObject? prefab, Vector3 position, Quaternion rotation, Transform? parent = null) { //IL_000a: 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) if (!((Object)(object)prefab == (Object)null)) { return Object.Instantiate<GameObject>(prefab, position, rotation, parent); } return null; } } internal struct ShipBoundsSwap { internal bool Changed; internal Collider? ShipBounds; internal Collider? InnerBounds; } public static class ShipBoundsRegistry { private static readonly HashSet<Collider> extraShipBounds = new HashSet<Collider>(); private static Collider? vanillaInnerBounds; internal static bool HasExtraBounds { get { extraShipBounds.RemoveWhere((Collider collider) => (Object)(object)collider == (Object)null); return extraShipBounds.Count != 0; } } public static void Add(Collider collider) { if (!((Object)(object)collider == (Object)null) && extraShipBounds.Add(collider)) { ItemSaveDataHandler.AddColliderForItemSaving(collider); } } public static void Remove(Collider collider) { if (!((Object)(object)collider == (Object)null)) { extraShipBounds.Remove(collider); } } public static bool Contains(Vector3 position) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0055: 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) StartOfRound instance = StartOfRound.Instance; if ((Object)(object)vanillaInnerBounds != (Object)null && PositionInside(vanillaInnerBounds, position)) { return true; } Collider val = null; if ((Object)(object)instance != (Object)null) { val = instance.shipInnerRoomBounds; } if ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)vanillaInnerBounds && PositionInside(val, position)) { return true; } return (Object)(object)ExtraColliderAt(position) != (Object)null; } internal static void RememberVanillaBounds(Collider collider) { if ((Object)(object)collider != (Object)null && !extraShipBounds.Contains(collider)) { vanillaInnerBounds = collider; } } internal static Collider? ExtraColliderAt(Vector3 position) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) if (!HasExtraBounds) { return null; } foreach (Collider extraShipBound in extraShipBounds) { if (PositionInside(extraShipBound, position)) { return extraShipBound; } } return null; } internal static ShipBoundsSwap UseExtraBounds(Vector3 position, bool useShipBounds, bool useInnerBounds) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) ShipBoundsSwap result = default(ShipBoundsSwap); Collider val = ExtraColliderAt(position); if ((Object)(object)val == (Object)null) { return result; } StartOfRound instance = StartOfRound.Instance; if ((Object)(object)instance == (Object)null) { return result; } result.Changed = true; result.ShipBounds = instance.shipBounds; result.InnerBounds = instance.shipInnerRoomBounds; if (useShipBounds) { instance.shipBounds = val; } if (useInnerBounds) { instance.shipInnerRoomBounds = val; } return result; } internal static void RestoreBounds(ShipBoundsSwap swap) { if (!swap.Changed) { return; } StartOfRound instance = StartOfRound.Instance; if (!((Object)(object)instance == (Object)null)) { if ((Object)(object)swap.ShipBounds != (Object)null) { instance.shipBounds = swap.ShipBounds; } if ((Object)(object)swap.InnerBounds != (Object)null) { instance.shipInnerRoomBounds = swap.InnerBounds; } } } internal static void MarkItemsInsideExtras() { //IL_001b: Unknown result type (might be due to invalid IL or missing references) if (!HasExtraBounds) { return; } GrabbableObject[] array = Object.FindObjectsByType<GrabbableObject>((FindObjectsSortMode)0); for (int i = 0; i < array.Length; i++) { if ((Object)(object)ExtraColliderAt(((Component)array[i]).transform.position) != (Object)null) { array[i].isInShipRoom = true; } } } internal static void Clear() { extraShipBounds.Clear(); vanillaInnerBounds = null; } private static bool PositionInside(Collider collider, Vector3 position) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0017: 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) if (collider.enabled && ((Component)collider).gameObject.activeInHierarchy) { return collider.ClosestPoint(position) == position; } return false; } } public static class UnlockableTools { public static bool Bought(NamespacedKey<DawnUnlockableItemInfo> key) { if (key == null) { throw new ArgumentNullException("key"); } StartOfRound instance = StartOfRound.Instance; if ((Object)(object)instance == (Object)null) { return false; } UnlockablesList unlockablesList = instance.unlockablesList; if ((Object)(object)unlockablesList == (Object)null) { return false; } List<UnlockableItem> unlockables = unlockablesList.unlockables; for (int i = 0; i < unlockables.Count; i++) { UnlockableItem val = unlockables[i]; if (val != null) { DawnUnlockableItemInfo dawnInfo = UnlockableItemExtensions.GetDawnInfo(val); if (dawnInfo != null && ((object)((DawnBaseInfo<DawnUnlockableItemInfo>)(object)dawnInfo).TypedKey).Equals((object?)key)) { return val.hasBeenUnlockedByPlayer; } } } return false; } public static bool Bought(string namespacedKey) { if (namespacedKey == null) { throw new ArgumentNullException("namespacedKey"); } if (string.IsNullOrWhiteSpace(namespacedKey)) { Log.Warn("Dawn unlockable could not be checked because the key text is empty"); return false; } NamespacedKey val = default(NamespacedKey); if (!NamespacedKey.TryParse(namespacedKey, ref val)) { Log.Warn("Dawn unlockable could not be checked because " + namespacedKey + " is not a valid key"); return false; } return Bought(val.AsTyped<DawnUnlockableItemInfo>()); } } } namespace HatLib.Patches { [HarmonyPatch(typeof(GameNetworkManager))] internal static class GameNetworkManagerPatches { [HarmonyPatch("Start")] [HarmonyPostfix] private static void StartPostfix() { HatNet.Init(); } [HarmonyPatch("SaveGame")] [HarmonyPostfix] private static void SaveGamePostfix() { RoundEvents.GameSaved(); } [HarmonyPatch("SaveItemsInShip")] [HarmonyPostfix] private static void SaveItemsInShipPostfix() { DawnSaveEvents.Collect(); } } internal static class ShipBoundPatches { [HarmonyPatch(typeof(AudioReverbTrigger), "ChangeAudioReverbForPlayer")] [HarmonyPrefix] private static void ChangeAudioReverbForPlayerPrefix(PlayerControllerB pScript, out ShipBoundsSwap __state) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) if (!ShipBoundsRegistry.HasExtraBounds) { __state = default(ShipBoundsSwap); } else { __state = ShipBoundsRegistry.UseExtraBounds(((Component)pScript).transform.position, useShipBounds: true, useInnerBounds: true); } } [HarmonyPatch(typeof(BeltBagItem), "RemoveObjectFromBag")] [HarmonyPatch(typeof(SoccerBallProp), "BeginKickBall")] [HarmonyPrefix] private static void ItemPositionPrefix(GrabbableObject __instance, out ShipBoundsSwap __state) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) if (!ShipBoundsRegistry.HasExtraBounds) { __state = default(ShipBoundsSwap); } else { __state = ShipBoundsRegistry.UseExtraBounds(((Component)__instance).transform.position, useShipBounds: true, useInnerBounds: true); } } [HarmonyPatch(typeof(DeadBodyInfo), "LateUpdate")] [HarmonyPrefix] private static void DeadBodyInfoLateUpdatePrefix(DeadBodyInfo __instance, out ShipBoundsSwap __state) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) if (!ShipBoundsRegistry.HasExtraBounds) { __state = default(ShipBoundsSwap); } else { __state = ShipBoundsRegistry.UseExtraBounds(((Component)__instance).transform.position, useShipBounds: true, useInnerBounds: false); } } [HarmonyPatch(typeof(GrabbableObject), "DiscardItem")] [HarmonyPrefix] private static void DiscardItemPrefix(GrabbableObject __instance, out ShipBoundsSwap __state) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) if (!ShipBoundsRegistry.HasExtraBounds) { __state = default(ShipBoundsSwap); } else { __state = ShipBoundsRegistry.UseExtraBounds(((Component)__instance).transform.position, useShipBounds: false, useInnerBounds: true); } } [HarmonyPatch(typeof(StormyWeather), "PlayThunderEffects")] [HarmonyPrefix] private static void PlayThunderEffectsPrefix(Vector3 strikePosition, out ShipBoundsSwap __state) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) if (!ShipBoundsRegistry.HasExtraBounds) { __state = default(ShipBoundsSwap); } else { __state = ShipBoundsRegistry.UseExtraBounds(strikePosition, useShipBounds: true, useInnerBounds: false); } } [HarmonyPatch(typeof(BaboonBirdAI), "DropHeldItemAndSync")] [HarmonyPrefix] private static void DropHeldItemAndSyncPrefix(BaboonBirdAI __instance, out ShipBoundsSwap __state) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) if (!ShipBoundsRegistry.HasExtraBounds) { __state = default(ShipBoundsSwap); return; } GrabbableObject heldScrap = __instance.heldScrap; __state = (((Object)(object)heldScrap == (Object)null) ? default(ShipBoundsSwap) : ShipBoundsRegistry.UseExtraBounds(heldScrap.GetItemFloorPosition(default(Vector3)), useShipBounds: true, useInnerBounds: false)); } [HarmonyPatch(typeof(GiantKiwiAI), "DropEgg")] [HarmonyPrefix] private static void DropEggPrefix(GiantKiwiAI __instance, bool dropInNest, out ShipBoundsSwap __state) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) if (!ShipBoundsRegistry.HasExtraBounds || dropInNest) { __state = default(ShipBoundsSwap); return; } KiwiBabyItem takeEggBackToNest = __instance.takeEggBackToNest; __state = (((Object)(object)takeEggBackToNest == (Object)null) ? default(ShipBoundsSwap) : ShipBoundsRegistry.UseExtraBounds(((GrabbableObject)takeEggBackToNest).GetItemFloorPosition(default(Vector3)), useShipBounds: true, useInnerBounds: false)); } [HarmonyPatch(typeof(PlayerControllerB), "DiscardHeldObject")] [HarmonyPrefix] private static void DiscardHeldObjectPrefix(PlayerControllerB __instance, bool placeObject, out ShipBoundsSwap __state) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) if (!ShipBoundsRegistry.HasExtraBounds || placeObject) { __state = default(ShipBoundsSwap); return; } GrabbableObject currentlyHeldObjectServer = __instance.currentlyHeldObjectServer; __state = (((Object)(object)currentlyHeldObjectServer == (Object)null) ? default(ShipBoundsSwap) : ShipBoundsRegistry.UseExtraBounds(currentlyHeldObjectServer.GetItemFloorPosition(default(Vector3)), useShipBounds: true, useInnerBounds: false)); } [HarmonyPatch(typeof(PlayerControllerB), "DropHeldItem")] [HarmonyPrefix] private static void DropHeldItemPrefix(GrabbableObject dropItem, Vector3 syncedHeldObjectPosition, out ShipBoundsSwap __state) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: 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_004a: 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 (!ShipBoundsRegistry.HasExtraBounds) { __state = default(ShipBoundsSwap); return; } Vector3 val = ((syncedHeldObjectPosition == default(Vector3)) ? ((Component)dropItem).transform.position : syncedHeldObjectPosition); Vector3 itemFloorPosition = dropItem.GetItemFloorPosition(val + Vector3.up * 0.15f); __state = ShipBoundsRegistry.UseExtraBounds(itemFloorPosition, useShipBounds: true, useInnerBounds: false); } [HarmonyPatch(typeof(FlowerSnakeEnemy), "StopClingingOnLocalClient")] [HarmonyPrefix] private static void StopClingingOnLocalClientPrefix(FlowerSnakeEnemy __instance, out ShipBoundsSwap __state) { //IL_0032: 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_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) if (!ShipBoundsRegistry.HasExtraBounds) { __state = default(ShipBoundsSwap); return; } PlayerControllerB clingingToPlayer = __instance.clingingToPlayer; Vector3 position = (((Object)(object)clingingToPlayer == (Object)null) ? ((Component)__instance).transform.position : ((Component)clingingToPlayer).transform.position); __state = ShipBoundsRegistry.UseExtraBounds(position, useShipBounds: false, useInnerBounds: true); } [HarmonyPatch(typeof(ElevatorAnimationEvents), "SetBodiesKinematic")] [HarmonyPrefix] private static void SetBodiesKinematicPrefix() { //IL_001d: Unknown result type (might be due to invalid IL or missing references) if (!ShipBoundsRegistry.HasExtraBounds) { return; } DeadBodyInfo[] array = Object.FindObjectsByType<DeadBodyInfo>((FindObjectsSortMode)0); for (int i = 0; i < array.Length; i++) { if ((Object)(object)ShipBoundsRegistry.ExtraColliderAt(array[i].bodyParts[5].position) != (Object)null) { array[i].isInShip = true; } } } [HarmonyPatch(typeof(AudioReverbTrigger), "ChangeAudioReverbForPlayer")] [HarmonyPatch(typeof(BeltBagItem), "RemoveObjectFromBag")] [HarmonyPatch(typeof(BaboonBirdAI), "DropHeldItemAndSync")] [HarmonyPatch(typeof(DeadBodyInfo), "LateUpdate")] [HarmonyPatch(typeof(FlowerSnakeEnemy), "StopClingingOnLocalClient")] [HarmonyPatch(typeof(GiantKiwiAI), "DropEgg")] [HarmonyPatch(typeof(GrabbableObject), "DiscardItem")] [HarmonyPatch(typeof(PlayerControllerB), "DiscardHeldObject")] [HarmonyPatch(typeof(PlayerControllerB), "DropHeldItem")] [HarmonyPatch(typeof(SoccerBallProp), "BeginKickBall")] [HarmonyPatch(typeof(StormyWeather), "PlayThunderEffects")] [HarmonyPostfix] private static void RestoreBoundsPostfix(ShipBoundsSwap __state) { ShipBoundsRegistry.RestoreBounds(__state); } } [HarmonyPatch(typeof(ShipBuildModeManager))] internal static class ShipBuildModeManagerPatches { [HarmonyPatch("Update")] [HarmonyPrefix] private static void UpdatePrefix(out ShipBoundsSwap __state) { //IL_0040: Unknown result type (might be due to invalid IL or missing references) if (!ShipBoundsRegistry.HasExtraBounds) { __state = default(ShipBoundsSwap); return; } GameNetworkManager instance = GameNetworkManager.Instance; if ((Object)(object)instance == (Object)null || (Object)(object)instance.localPlayerController == (Object)null) { __state = default(ShipBoundsSwap); } else { __state = ShipBoundsRegistry.UseExtraBounds(((Component)instance.localPlayerController).transform.position, useShipBounds: false, useInnerBounds: true); } } [HarmonyPatch("Update")] [HarmonyPostfix] private static void UpdatePostfix(ShipBoundsSwap __state) { ShipBoundsRegistry.RestoreBounds(__state); } } [HarmonyPatch(typeof(StartOfRound))] internal static class StartOfRoundPatches { [HarmonyPatch("Start")] [HarmonyPostfix] private static void StartPostfix(StartOfRound __instance) { ShipBoundsRegistry.RememberVanillaBounds(__instance.shipInnerRoomBounds); RoundEvents.RoundStart(__instance); } [HarmonyPatch("EndOfGameClientRpc")] [HarmonyPostfix] private static void EndOfGameClientRpcPostfix(StartOfRound __instance) { RoundEvents.RoundEnd(__instance); } [HarmonyPatch("ShipHasLeft")] [HarmonyPostfix] private static void ShipHasLeftPostfix(StartOfRound __instance) { RoundEvents.ShipLeft(__instance); } [HarmonyPatch("SetShipReadyToLand")] [HarmonyPostfix] private static void SetShipReadyToLandPostfix(StartOfRound __instance) { RoundEvents.ShipReadyToLand(__instance); } [HarmonyPatch("LoadShipGrabbableItems")] [HarmonyPostfix] private static void LoadShipGrabbableItemsPostfix(StartOfRound __instance) { RoundEvents.ShipItemsLoaded(__instance); } [HarmonyPatch("SyncShipUnlockablesClientRpc")] [HarmonyPostfix] private static void SyncShipUnlockablesClientRpcPostfix(StartOfRound __instance) { RoundEvents.ShipUnlockablesSynced(__instance); } [HarmonyPatch("ResetPlayersLoadedValueClientRpc")] [HarmonyPostfix] private static void ResetPlayersLoadedValueClientRpcPostfix(StartOfRound __instance) { RoundEvents.PlayersLoadedReset(__instance); } [HarmonyPatch("OnLocalDisconnect")] [HarmonyPostfix] private static void OnLocalDisconnectPostfix(StartOfRound __instance) { RoundEvents.Disconnect(__instance); ShipBoundsRegistry.Clear(); HatNet.Shutdown(); } [HarmonyPatch("OnDestroy")] [HarmonyPostfix] private static void OnDestroyPostfix(StartOfRound __instance) { RoundEvents.Destroy(__instance); ShipBoundsRegistry.Clear(); HatNet.Shutdown(); } [HarmonyPatch("LateUpdate")] [HarmonyPrefix] private static void LateUpdatePrefix(out ShipBoundsSwap __state) { //IL_0040: 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_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) if (!ShipBoundsRegistry.HasExtraBounds) { __state = default(ShipBoundsSwap); return; } GameNetworkManager instance = GameNetworkManager.Instance; if ((Object)(object)instance == (Object)null || (Object)(object)instance.localPlayerController == (Object)null) { __state = default(ShipBoundsSwap); } else { __state = ShipBoundsRegistry.UseExtraBounds(((Component)instance.localPlayerController).transform.position + Vector3.up * 0.25f, useShipBounds: true, useInnerBounds: true); } } [HarmonyPatch("LateUpdate")] [HarmonyPostfix] private static void LateUpdatePostfix(ShipBoundsSwap __state) { ShipBoundsRegistry.RestoreBounds(__state); } [HarmonyPatch("TeleportPlayerInShipIfOutOfRoomBounds")] [HarmonyPrefix] private static bool TeleportPlayerInShipIfOutOfRoomBoundsPrefix() { //IL_0033: Unknown result type (might be due to invalid IL or missing references) if (!ShipBoundsRegistry.HasExtraBounds) { return true; } GameNetworkManager instance = GameNetworkManager.Instance; if ((Object)(object)instance == (Object)null || (Object)(object)instance.localPlayerController == (Object)null) { return true; } return (Object)(object)ShipBoundsRegistry.ExtraColliderAt(((Component)instance.localPlayerController).transform.position) == (Object)null; } [HarmonyPatch("GetValueOfAllScrap")] [HarmonyPrefix] private static void GetValueOfAllScrapPrefix() { if (ShipBoundsRegistry.HasExtraBounds) { ShipBoundsRegistry.MarkItemsInsideExtras(); } } } } namespace __GEN { internal class NetworkVariableSerializationHelper { [RuntimeInitializeOnLoadMethod] internal static void InitializeSerialization() { } } } namespace HatLib.NetcodePatcher { [AttributeUsage(AttributeTargets.Module)] internal class NetcodePatchedAssemblyAttribute : Attribute { } }