Please disclose if your mod was created primarily 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 WeedheimShip v1.0.2
plugins/WeedheimShip.dll
Decompiled 9 months agousing System; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Jotunn; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Extensions; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.Networking; using UnityEngine.Serialization; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("WeedheimShip")] [assembly: AssemblyDescription("https://discord.gg/zRucjV8rqc")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("MagicMike")] [assembly: AssemblyProduct("WeedheimShip")] [assembly: AssemblyCopyright("Copyright © MagicMike 2025WeedheimShip")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("DEAF4438-8089-40ED-8175-398E1261D45B")] [assembly: AssemblyFileVersion("1.0.2")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.2.0")] [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.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } public class ShipBattleHorn : MonoBehaviour, Hoverable, Interactable { public string m_name = "$ship_battlehorn"; public float m_useDistance = 3f; public Transform m_attachPoint; public Vector3 m_detachOffset = new Vector3(0f, 0.5f, 0f); public string m_attachAnimation = "emote_drink"; public EffectList m_hornEffect; [FormerlySerializedAs("m_onShip")] public bool m_inShip; private static float m_lastSitTime; public string GetHoverText() { if (Time.time - m_lastSitTime < 8f) { return ""; } if (!InUseDistance((Humanoid)(object)Player.m_localPlayer)) { return Localization.instance.Localize("<color=#888888>$piece_toofar</color>"); } return Localization.instance.Localize(m_name + "\n[<color=yellow><b>$KEY_Use</b></color>] $piece_use"); } public string GetHoverName() { return m_name; } public bool Interact(Humanoid human, bool hold, bool alt) { //IL_0031: 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_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) if (hold) { return false; } Player val = (Player)(object)((human is Player) ? human : null); if (!InUseDistance((Humanoid)(object)val)) { return false; } if (Time.time - m_lastSitTime < 8f) { return false; } Player closestPlayer = Player.GetClosestPlayer(m_attachPoint.position, 0.1f); if ((Object)(object)closestPlayer != (Object)null && (Object)(object)closestPlayer != (Object)(object)Player.m_localPlayer) { ((Character)Player.m_localPlayer).Message((MessageType)2, "$msg_blocked", 0, (Sprite)null); return false; } if (Object.op_Implicit((Object)(object)val)) { if (((Character)val).IsEncumbered()) { return false; } ((Character)val).AttachStart(m_attachPoint, (GameObject)null, false, false, m_inShip, m_attachAnimation, m_detachOffset, (Transform)null); m_lastSitTime = Time.time; m_hornEffect.Create(((Component)this).transform.position, ((Component)this).transform.rotation, (Transform)null, 1f, -1); } return false; } public bool UseItem(Humanoid user, ItemData item) { return false; } private bool InUseDistance(Humanoid human) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) return Vector3.Distance(((Component)human).transform.position, m_attachPoint.position) < m_useDistance; } } namespace WeedheimShip { public class ShipSailURL : MonoBehaviour, Hoverable, Interactable, TextReceiver { [CompilerGenerated] private sealed class <DownloadTexture>d__19 : IEnumerator<object>, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public ShipSailURL <>4__this; public string url; public Action<string, Texture2D> callback; private UnityWebRequest <uwr>5__2; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <DownloadTexture>d__19(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { int num = <>1__state; if (num == -3 || num == 1) { try { } finally { <>m__Finally1(); } } <uwr>5__2 = null; <>1__state = -2; } private bool MoveNext() { //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Invalid comparison between Unknown and I4 //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Invalid comparison between Unknown and I4 //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Expected O, but got Unknown bool result; try { int num = <>1__state; ShipSailURL shipSailURL = <>4__this; switch (num) { default: result = false; break; case 0: <>1__state = -1; shipSailURL.m_url = url; if (Utility.IsNullOrWhiteSpace(shipSailURL.m_url)) { callback(url, null); result = false; break; } <uwr>5__2 = UnityWebRequest.Get(url); <>1__state = -3; <>2__current = <uwr>5__2.SendWebRequest(); <>1__state = 1; result = true; break; case 1: <>1__state = -3; if ((int)<uwr>5__2.result == 3 || (int)<uwr>5__2.result == 2) { Logger.LogError((object)<uwr>5__2.error); } else { Texture2D val = new Texture2D(2, 2); ImageConversion.LoadImage(val, <uwr>5__2.downloadHandler.data); callback(url, val); } result = false; <>m__Finally1(); break; } } catch { //try-fault ((IDisposable)this).Dispose(); throw; } return result; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void <>m__Finally1() { <>1__state = -1; if (<uwr>5__2 != null) { ((IDisposable)<uwr>5__2).Dispose(); } } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } private string m_url; public string m_name = "ShipSailURL"; private const int m_characterLimit = int.MaxValue; private SkinnedMeshRenderer sailRenderer; private Texture origSailTexture; private Texture2D lastAppliedTexture; private ZNetView m_nview; private void Awake() { ZNetView val = default(ZNetView); ((Component)this).TryGetComponent<ZNetView>(ref val); if ((Object)(object)val == (Object)null || !val.IsValid()) { return; } m_nview = val; sailRenderer = ((IEnumerable<SkinnedMeshRenderer>)((Component)this).GetComponentsInChildren<SkinnedMeshRenderer>()).FirstOrDefault((Func<SkinnedMeshRenderer, bool>)((SkinnedMeshRenderer x) => ((x != null) ? ((Object)x).name : null) == "sail_full")); try { SkinnedMeshRenderer obj = sailRenderer; if ((Object)(object)((obj != null) ? ((Renderer)obj).material : null) != (Object)null) { origSailTexture = ((Renderer)sailRenderer).material.GetTexture("_MainTex"); } } catch (Exception arg) { Logger.LogError((object)$"Error getting texture: {arg}"); } ZNetView nview = m_nview; if (((nview != null) ? nview.GetZDO() : null) != null) { ((MonoBehaviour)this).InvokeRepeating("UpdateText", 2f, 2f); m_nview.Register<string>("RPC_GetNewImageAndApply", (Action<long, string>)RPC_GetNewImageAndApply); } } public string GetHoverText() { if (MainConfig.useServerSailURL.Value) { return string.Empty; } if (!WeedheimShipMod.AllowInput()) { return string.Empty; } return Localization.instance.Localize("\n[<color=#FFFF00><b>$KEY_Use</b></color>] $text_set_url"); } public string GetHoverName() { if (MainConfig.useServerSailURL.Value) { return string.Empty; } if (WeedheimShipMod.AllowInput()) { return Localization.instance.Localize("$text_sail_url"); } return string.Empty; } public bool Interact(Humanoid character, bool hold, bool alt) { //IL_003d: Unknown result type (might be due to invalid IL or missing references) if (hold) { return false; } if (MainConfig.useServerSailURL.Value) { if (character != null) { ((Character)character).Message((MessageType)2, Localization.instance.Localize("<color=#FFFF00><b>$piece_noaccess</b></color>\n$text_sail_url_deny"), 0, (Sprite)null); } return false; } if (!WeedheimShipMod.AllowInput()) { return false; } if (!PrivateArea.CheckAccess(((Component)this).transform.position, 0f, true, false)) { if (character != null) { ((Character)character).Message((MessageType)2, "<color=#FFFF00><b>$piece_noaccess</b></color>", 0, (Sprite)null); } return false; } TextInput.instance.RequestText((TextReceiver)(object)this, "$piece_sign_input", int.MaxValue); return true; } private void UpdateText() { string text = GetText(); if (!(m_url == text)) { SetText(text); } } private void FixTexture() { if (!((Object)(object)((Renderer)sailRenderer).material.GetTexture("_MainTex") == (Object)(object)lastAppliedTexture) && !((Object)(object)lastAppliedTexture == (Object)null)) { ((Renderer)sailRenderer).material.SetTexture("_MainTex", (Texture)(string.IsNullOrWhiteSpace(m_url) ? ((object)origSailTexture) : ((object)lastAppliedTexture))); } } public string GetText() { if (!MainConfig.useServerSailURL.Value) { return m_nview.GetZDO().GetString("ShipSailURL", string.Empty); } return MainConfig.serverSailURL.Value; } public bool UseItem(Humanoid user, ItemData item) { return false; } public void SetText(string text) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) if (PrivateArea.CheckAccess(((Component)this).transform.position, 0f, true, false)) { m_nview.InvokeRPC(ZNetView.Everybody, "RPC_GetNewImageAndApply", new object[1] { text }); } } private void RPC_GetNewImageAndApply(long uid, string url) { ((MonoBehaviour)this).StartCoroutine(DownloadTexture(url, ApplyTexture)); } private void ApplyTexture(string url, Texture2D obj) { if (!m_nview.HasOwner()) { m_nview.ClaimOwnership(); UpdateTexture(url, obj); } else { UpdateTexture(url, obj); } } private void UpdateTexture(string url, Texture2D obj) { if (m_nview.IsOwner()) { m_nview.GetZDO().Set("ShipSailURL", url); } lastAppliedTexture = obj; ((Renderer)sailRenderer).material.SetTexture("_MainTex", (Texture)(string.IsNullOrWhiteSpace(url) ? ((object)origSailTexture) : ((object)obj))); } [IteratorStateMachine(typeof(<DownloadTexture>d__19))] public IEnumerator DownloadTexture(string url, Action<string, Texture2D> callback) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <DownloadTexture>d__19(0) { <>4__this = this, url = url, callback = callback }; } } [HarmonyPatch] public class ShipPatches { private static readonly int _isAnchored = StringExtensionMethods.GetStableHashCode("IsAnchored"); private static readonly int _isLightingOn = StringExtensionMethods.GetStableHashCode("IsLightingOn"); private static GameObject s_turretPrefab; public const string turretName = "piece_turret"; [HarmonyPostfix] [HarmonyPatch(typeof(ShipControlls), "Awake")] public static void Awake_Anchor_Postfix(ShipControlls __instance) { if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.m_ship == (Object)null || (Object)(object)__instance.m_nview == (Object)null || !__instance.m_nview.IsValid() || !((Object)((Component)__instance.m_ship).gameObject).name.Contains("wh_lokis_ship")) { return; } Transform val = Utils.FindChild(((Component)__instance.m_ship).transform, "_disabledAnchor", (IterativeSearchType)0); Transform val2 = Utils.FindChild(((Component)__instance.m_ship).transform, "_enabledAnchor", (IterativeSearchType)0); Rigidbody componentInParent = ((Component)__instance).gameObject.GetComponentInParent<Rigidbody>(); if ((Object)(object)componentInParent == (Object)null) { return; } if (__instance.m_nview.GetZDO().GetBool(_isAnchored, false)) { componentInParent.constraints = (RigidbodyConstraints)10; if (((Component)val).gameObject.activeSelf) { ((Component)val).gameObject.SetActive(false); } if (!((Component)val2).gameObject.activeSelf) { ((Component)val2).gameObject.SetActive(true); } } else { componentInParent.constraints = (RigidbodyConstraints)0; if (((Component)val2).gameObject.activeSelf) { ((Component)val2).gameObject.SetActive(false); } if (!((Component)val).gameObject.activeSelf) { ((Component)val).gameObject.SetActive(true); } } } [HarmonyPostfix] [HarmonyPatch(typeof(ShipControlls), "GetHoverText")] public static void GetHoverText_Anchor_Postfix(ShipControlls __instance, ref string __result) { //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_0275: Unknown result type (might be due to invalid IL or missing references) //IL_0277: Unknown result type (might be due to invalid IL or missing references) //IL_029e: Unknown result type (might be due to invalid IL or missing references) //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.m_nview == (Object)null || !__instance.m_nview.IsValid() || (Object)(object)__instance.m_ship == (Object)null || !((Object)((Component)__instance.m_ship).gameObject).name.Contains("wh_lokis_ship")) { return; } Transform val = Utils.FindChild(((Component)__instance.m_ship).transform, "AnchorSound", (IterativeSearchType)0); Transform val2 = Utils.FindChild(((Component)__instance.m_ship).transform, "_disabledAnchor", (IterativeSearchType)0); Transform val3 = Utils.FindChild(((Component)__instance.m_ship).transform, "_enabledAnchor", (IterativeSearchType)0); Rigidbody componentInParent = ((Component)__instance).gameObject.GetComponentInParent<Rigidbody>(); Vector3 position = ((Component)val).gameObject.transform.position; if ((Object)(object)componentInParent == (Object)null) { return; } if (!__instance.m_nview.GetZDO().GetBool(_isAnchored, false)) { if (!__instance.InUseDistance((Humanoid)(object)Player.m_localPlayer)) { __result = Localization.instance.Localize("<color=grey>$piece_toofar</color>"); } __result += string.Format(Localization.instance.Localize("\n[<color=yellow><b>{0}</b></color>] $text_drop_anchor"), MainConfig._anchorKey.Value); } else { if (!__instance.InUseDistance((Humanoid)(object)Player.m_localPlayer)) { __result = Localization.instance.Localize("<color=grey>$piece_toofar</color>"); } __result += string.Format(Localization.instance.Localize("\n[<color=yellow><b>{0}</b></color>] $text_raise_anchor"), MainConfig._anchorKey.Value); } KeyboardShortcut value = MainConfig._anchorKey.Value; if (!((KeyboardShortcut)(ref value)).IsDown()) { return; } if (!__instance.m_nview.GetZDO().GetBool(_isAnchored, false)) { __instance.m_nview.GetZDO().Set(_isAnchored, true); Object.Instantiate<GameObject>(ZNetScene.instance.GetPrefab("sfx_anchor_wh"), position, Quaternion.identity); componentInParent.constraints = (RigidbodyConstraints)10; ZDOMan.instance.ForceSendZDO(ZNetView.Everybody, __instance.m_nview.GetZDO().m_uid); ((Character)Player.m_localPlayer).Message((MessageType)2, string.Format(Localization.instance.Localize("⚓ $text_anchor_dropped"), 0, null), 0, (Sprite)null); if (((Component)val2).gameObject.activeSelf) { ((Component)val2).gameObject.SetActive(false); } if (!((Component)val3).gameObject.activeSelf) { ((Component)val3).gameObject.SetActive(true); } } else { __instance.m_nview.GetZDO().Set(_isAnchored, false); Object.Instantiate<GameObject>(ZNetScene.instance.GetPrefab("sfx_anchor_wh"), position, Quaternion.identity); componentInParent.constraints = (RigidbodyConstraints)0; ZDOMan.instance.ForceSendZDO(ZNetView.Everybody, __instance.m_nview.GetZDO().m_uid); ((Character)Player.m_localPlayer).Message((MessageType)2, string.Format(Localization.instance.Localize("⚓ $text_anchor_raised"), 0, null), 0, (Sprite)null); if (((Component)val3).gameObject.activeSelf) { ((Component)val3).gameObject.SetActive(false); } if (!((Component)val2).gameObject.activeSelf) { ((Component)val2).gameObject.SetActive(true); } } } [HarmonyPostfix] [HarmonyPatch(typeof(ShipControlls), "Awake")] public static void Awake_Lighting_Postfix(ShipControlls __instance) { if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.m_ship == (Object)null || (Object)(object)__instance.m_nview == (Object)null || !__instance.m_nview.IsValid() || !((Object)((Component)__instance.m_ship).gameObject).name.Contains("wh_lokis_ship")) { return; } Transform val = Utils.FindChild(((Component)__instance.m_ship).transform, "_disabledLights", (IterativeSearchType)0); Transform val2 = Utils.FindChild(((Component)__instance.m_ship).transform, "_enabledLights", (IterativeSearchType)0); if (__instance.m_nview.GetZDO().GetBool(_isLightingOn, false)) { if (((Component)val).gameObject.activeSelf) { ((Component)val).gameObject.SetActive(false); } if (!((Component)val2).gameObject.activeSelf) { ((Component)val2).gameObject.SetActive(true); } } else { if (((Component)val2).gameObject.activeSelf) { ((Component)val2).gameObject.SetActive(false); } if (!((Component)val).gameObject.activeSelf) { ((Component)val).gameObject.SetActive(true); } } } [HarmonyPostfix] [HarmonyPatch(typeof(ShipControlls), "GetHoverText")] public static void GetHoverText_Lighting_Postfix(ShipControlls __instance, ref string __result) { //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_0123: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0238: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_0259: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.m_nview == (Object)null || !__instance.m_nview.IsValid() || (Object)(object)__instance.m_ship == (Object)null || !((Object)((Component)__instance.m_ship).gameObject).name.Contains("wh_lokis_ship")) { return; } Transform val = Utils.FindChild(((Component)__instance.m_ship).transform, "_disabledLights", (IterativeSearchType)0); Transform val2 = Utils.FindChild(((Component)__instance.m_ship).transform, "_enabledLights", (IterativeSearchType)0); Vector3 position = ((Component)__instance).transform.position; if (!__instance.m_nview.GetZDO().GetBool(_isLightingOn, false)) { if (!__instance.InUseDistance((Humanoid)(object)Player.m_localPlayer)) { __result = Localization.instance.Localize("<color=grey>$piece_toofar</color>"); } __result += string.Format(Localization.instance.Localize("\n[<color=yellow><b>{0}</b></color>] $lokis_ship_lights_on"), MainConfig._lightsKey.Value); } else { if (!__instance.InUseDistance((Humanoid)(object)Player.m_localPlayer)) { __result = Localization.instance.Localize("<color=grey>$piece_toofar</color>"); } __result += string.Format(Localization.instance.Localize("\n[<color=yellow><b>{0}</b></color>] $lokis_ship_lights_off"), MainConfig._lightsKey.Value); } KeyboardShortcut value = MainConfig._lightsKey.Value; if (!((KeyboardShortcut)(ref value)).IsDown()) { return; } if (!__instance.m_nview.GetZDO().GetBool(_isLightingOn, false)) { __instance.m_nview.GetZDO().Set(_isLightingOn, true); Object.Instantiate<GameObject>(ZNetScene.instance.GetPrefab("sfx_light_switch_wh"), position, Quaternion.identity); ZDOMan.instance.ForceSendZDO(ZNetView.Everybody, __instance.m_nview.GetZDO().m_uid); ((Character)Player.m_localPlayer).Message((MessageType)2, string.Format(Localization.instance.Localize("\ud83d\udca1 $ship_lights_turned_on"), 0, null), 0, (Sprite)null); if (((Component)val).gameObject.activeSelf) { ((Component)val).gameObject.SetActive(false); } if (!((Component)val2).gameObject.activeSelf) { ((Component)val2).gameObject.SetActive(true); } } else { __instance.m_nview.GetZDO().Set(_isLightingOn, false); Object.Instantiate<GameObject>(ZNetScene.instance.GetPrefab("sfx_light_switch_wh"), position, Quaternion.identity); ZDOMan.instance.ForceSendZDO(ZNetView.Everybody, __instance.m_nview.GetZDO().m_uid); ((Character)Player.m_localPlayer).Message((MessageType)2, string.Format(Localization.instance.Localize("\ud83d\udca1 $ship_lights_turned_off"), 0, null), 0, (Sprite)null); if (((Component)val2).gameObject.activeSelf) { ((Component)val2).gameObject.SetActive(false); } if (!((Component)val).gameObject.activeSelf) { ((Component)val).gameObject.SetActive(true); } } } [HarmonyPostfix] [HarmonyPatch(typeof(Turret), "Awake")] private static void Awake_Postfix(Turret __instance, ref int ___m_maxAmmo) { if (!((Object)((Component)__instance).gameObject).name.Contains("lokis_ship_turret") || !MainConfig.turretEnabled.Value) { return; } MainConfig.maxAmmoTurret.SettingChanged += delegate { __instance.m_maxAmmo = MainConfig.maxAmmoTurret.Value; }; ___m_maxAmmo = MainConfig.maxAmmoTurret.Value; if (s_turretPrefab == null) { Turret? obj = ((IEnumerable<Turret>)Resources.FindObjectsOfTypeAll<Turret>()).FirstOrDefault((Func<Turret, bool>)((Turret ws) => ((Object)ws).name == "piece_turret")); s_turretPrefab = ((obj != null) ? ((Component)obj).gameObject : null); } if ((Object)(object)s_turretPrefab != (Object)null) { Turret component = s_turretPrefab.GetComponent<Turret>(); __instance.m_configTargets = component.m_configTargets; } } [HarmonyPostfix] [HarmonyPatch(typeof(Turret), "FixedUpdate")] private static void FixedUpdate_Postfix(Turret __instance) { //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.m_nview == (Object)null || !__instance.m_nview.IsOwner() || !((Object)((Component)__instance).gameObject).name.Contains("lokis_ship_turret") || !MainConfig.turretEnabled.Value || !MainConfig.autoReloadTurret.Value) { return; } Stopwatch gameObjectStopwatch = StorageSearch.GetGameObjectStopwatch(((Component)__instance).gameObject); if (gameObjectStopwatch.IsRunning && gameObjectStopwatch.ElapsedMilliseconds < 1000) { return; } gameObjectStopwatch.Restart(); int num = __instance.m_maxAmmo - __instance.GetAmmo(); float radius = Math.Min(50f, Math.Max(1f, 20f)); bool flag = true; if (num <= 0) { return; } foreach (Container nearbyContainer in StorageSearch.GetNearbyContainers(((Component)__instance).gameObject, radius, !flag)) { foreach (AmmoType item in __instance.m_allowedAmmo) { ItemData itemData = item.m_ammo.m_itemData; int num2 = StorageSearch.DeductItemFromContainer(nearbyContainer, itemData); if (num2 > 0) { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(((Object)((Component)item.m_ammo).gameObject).name); for (int i = 0; i < num2; i++) { __instance.m_nview.InvokeRPC("RPC_AddAmmo", new object[1] { ((Object)itemPrefab).name }); } num -= num2; if (num == 0) { return; } } } } } [HarmonyPostfix] [HarmonyPatch(typeof(Ship), "Awake")] private static void ShipAwakePatch_Postfix(Ship __instance) { if (!((Object)((Component)__instance).gameObject).name.Contains("wh_lokis_ship")) { return; } WearNTear component = ((Component)__instance).GetComponent<WearNTear>(); Transform shipFlag = Utils.FindChild(((Component)__instance).transform, "ShipFlag", (IterativeSearchType)0); Transform shipShields = Utils.FindChild(((Component)__instance).transform, "Shields", (IterativeSearchType)0); Transform shipTurret = Utils.FindChild(((Component)__instance).transform, "lokis_ship_turret", (IterativeSearchType)0); MainConfig.flagEnabled.SettingChanged += delegate { ((Component)shipFlag).gameObject.SetActive(MainConfig.flagEnabled.Value); }; ((Component)shipFlag).gameObject.SetActive(MainConfig.flagEnabled.Value); MainConfig.shieldsEnabled.SettingChanged += delegate { ((Component)shipShields).gameObject.SetActive(MainConfig.shieldsEnabled.Value); }; ((Component)shipShields).gameObject.SetActive(MainConfig.shieldsEnabled.Value); MainConfig.turretEnabled.SettingChanged += delegate { ((Component)shipTurret).gameObject.SetActive(MainConfig.turretEnabled.Value); }; ((Component)shipTurret).gameObject.SetActive(MainConfig.turretEnabled.Value); if (((Component)shipShields).gameObject.activeSelf || ((Component)shipTurret).gameObject.activeSelf) { if (((Component)shipShields).gameObject.activeSelf && ((Component)shipTurret).gameObject.activeSelf) { component.m_health += 800f; } else { component.m_health += 400f; } } } } public class SailPatches { [HarmonyPatch(typeof(Ship), "Awake")] public static class ShipAwakePatch { private static void Postfix(Ship __instance) { if (((Object)((Component)__instance).gameObject).name.Contains("wh_lokis_ship") && MainConfig.enableCustomSails.Value && !Object.op_Implicit((Object)(object)((Component)__instance).gameObject.GetComponent<ShipSailURL>())) { ((Component)__instance).gameObject.AddComponent<ShipSailURL>(); } } } [HarmonyPatch(typeof(Ship), "Awake")] private class Ship_Awake_Patch { private static void Prefix(Ship __instance, Cloth ___m_sailCloth) { if (!((Object)((Component)__instance).gameObject).name.Contains("wh_lokis_ship") || !MainConfig.enableTransparent.Value) { return; } SkinnedMeshRenderer componentInChildren = __instance.m_sailObject.GetComponentInChildren<SkinnedMeshRenderer>(); if (!Object.op_Implicit((Object)(object)componentInChildren)) { return; } Material[] materials = ((Renderer)componentInChildren).materials; foreach (Material val in materials) { Texture mainTexture = val.mainTexture; Texture2D val2 = (Texture2D)(object)((mainTexture is Texture2D) ? mainTexture : null); if (TransparentSails.textureNames.Contains(((Object)val2).name)) { val.mainTexture = (Texture)(object)TransparentSails.originalTextures[((Object)val2).name]; } } } } [HarmonyPatch(typeof(Ship), "UpdateSailSize")] private class Ship_UpdateSailSize_Patch { private static void Postfix(Ship __instance, Cloth ___m_sailCloth) { if (!((Object)(object)Player.m_localPlayer == (Object)null) && ((Object)((Component)__instance).gameObject).name.Contains("wh_lokis_ship") && MainConfig.enableTransparent.Value) { GameObject sailObject = __instance.m_sailObject; int instanceID = ((Object)sailObject).GetInstanceID(); bool shouldBeTransparent = ShouldBeTransparent(__instance, ___m_sailCloth); TransparentSails.UpdateSail(instanceID, shouldBeTransparent, sailObject); } } } public static bool ShouldBeTransparent(Ship ship, Cloth m_sailCloth) { if (!MainConfig.transparencyToggle || !MainConfig.enableTransparent.Value) { return false; } if (!ship.IsPlayerInBoat(Player.m_localPlayer)) { return false; } return m_sailCloth.enabled; } } public class SoundPatch { [HarmonyPatch(typeof(ZNetScene), "Awake")] private static class ZNetSceneSoundsPatch { private static void Postfix(ZNetScene __instance) { GameObject prefab = __instance.GetPrefab("vfx_watersplash_wh"); GameObject prefab2 = __instance.GetPrefab("sfx_anchor_wh"); GameObject prefab3 = __instance.GetPrefab("sfx_light_switch_wh"); GameObject prefab4 = __instance.GetPrefab("sfx_battlehorn_wh"); GameObject prefab5 = __instance.GetPrefab("fx_turret_fire_wh"); GameObject prefab6 = __instance.GetPrefab("fx_turret_addammo_wh"); GameObject prefab7 = __instance.GetPrefab("fx_turret_reload_wh"); try { prefab.GetComponentInChildren<AudioSource>().outputAudioMixerGroup = AudioMan.instance.m_ambientMixer; prefab2.GetComponentInChildren<AudioSource>().outputAudioMixerGroup = AudioMan.instance.m_ambientMixer; prefab3.GetComponentInChildren<AudioSource>().outputAudioMixerGroup = AudioMan.instance.m_ambientMixer; prefab4.GetComponentInChildren<AudioSource>().outputAudioMixerGroup = AudioMan.instance.m_ambientMixer; prefab5.GetComponentInChildren<AudioSource>().outputAudioMixerGroup = AudioMan.instance.m_ambientMixer; prefab6.GetComponentInChildren<AudioSource>().outputAudioMixerGroup = AudioMan.instance.m_ambientMixer; prefab7.GetComponentInChildren<AudioSource>().outputAudioMixerGroup = AudioMan.instance.m_ambientMixer; } catch { Logger.LogError((object)"Error with Lokis Ship SoundPatches!"); } } } } [HarmonyPatch] internal class TurretPatch { [HarmonyPatch(typeof(Turret), "Awake")] private static class Turret_Awake_Patch { [CompilerGenerated] private sealed class <FixShip>d__2 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IDisposable, IEnumerator { private int <>1__state; private CodeInstruction <>2__current; private int <>l__initialThreadId; private IEnumerable<CodeInstruction> code; public IEnumerable<CodeInstruction> <>3__code; private MethodInfo <method>5__2; private MethodInfo <operand>5__3; private IEnumerator<CodeInstruction> <>7__wrap3; CodeInstruction IEnumerator<CodeInstruction>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <FixShip>d__2(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void IDisposable.Dispose() { int num = <>1__state; if (num == -3 || (uint)(num - 1) <= 1u) { try { } finally { <>m__Finally1(); } } <method>5__2 = null; <operand>5__3 = null; <>7__wrap3 = null; <>1__state = -2; } private bool MoveNext() { //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Expected O, but got Unknown try { switch (<>1__state) { default: return false; case 0: <>1__state = -1; <method>5__2 = AccessTools.Method(typeof(Turret_Awake_Patch), "RetZNV", (Type[])null, (Type[])null); <operand>5__3 = AccessTools.Method(typeof(Component), "GetComponent", (Type[])null, (Type[])null).MakeGenericMethod(typeof(ZNetView)); <>7__wrap3 = code.GetEnumerator(); <>1__state = -3; break; case 1: <>1__state = -3; break; case 2: <>1__state = -3; break; } if (<>7__wrap3.MoveNext()) { CodeInstruction current = <>7__wrap3.Current; if (current.opcode == OpCodes.Call && current.operand == <operand>5__3) { <>2__current = new CodeInstruction(OpCodes.Call, (object)<method>5__2); <>1__state = 1; return true; } <>2__current = current; <>1__state = 2; return true; } <>m__Finally1(); <>7__wrap3 = null; return false; } catch { //try-fault ((IDisposable)this).Dispose(); throw; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void <>m__Finally1() { <>1__state = -1; if (<>7__wrap3 != null) { <>7__wrap3.Dispose(); } } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } [DebuggerHidden] IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator() { <FixShip>d__2 <FixShip>d__; if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; <FixShip>d__ = this; } else { <FixShip>d__ = new <FixShip>d__2(0); } <FixShip>d__.code = <>3__code; return <FixShip>d__; } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable<CodeInstruction>)this).GetEnumerator(); } } private static readonly HashSet<string> Names = new HashSet<string> { "lokis_ship_turret" }; private static ZNetView RetZNV(Turret go) { if (!Names.Contains(((Object)go).name)) { return ((Component)go).GetComponent<ZNetView>(); } return ((Component)go).GetComponentInParent<ZNetView>(); } [IteratorStateMachine(typeof(<FixShip>d__2))] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> FixShip(IEnumerable<CodeInstruction> code) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <FixShip>d__2(-2) { <>3__code = code }; } } } internal class TradersPatch { [HarmonyPatch(typeof(Trader), "GetAvailableItems")] public static class GetAvailableItemsPatch { [HarmonyPriority(200)] private static void Postfix(Trader __instance, ref List<TradeItem> __result) { if (__instance.m_name.Equals("Loki")) { string name = ((Object)Cache.GetPrefab<GameObject>("wh_lokis_ship_kit")).name; __result.Add(CreateCustomItem(name, 1, 1000, "KilledTroll")); } } private static TradeItem CreateCustomItem(string itemName, int stackSize, int price, string key) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001d: 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) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown ItemDrop component = ObjectDB.instance.GetItemPrefab(itemName).GetComponent<ItemDrop>(); return new TradeItem { m_prefab = component, m_stack = stackSize, m_price = price, m_requiredGlobalKey = key }; } } } public static class StorageSearch { private static readonly ConcurrentDictionary<float, Stopwatch> _stopwatches = new ConcurrentDictionary<float, Stopwatch>(); private static float GetGameObjectPositionHash(GameObject gameObject) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0011: 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_0024: Unknown result type (might be due to invalid IL or missing references) Vector3 position = gameObject.transform.position; return 1000f * position.x + position.y + 0.001f * position.z; } public static Stopwatch GetGameObjectStopwatch(GameObject gameObject) { float gameObjectPositionHash = GetGameObjectPositionHash(gameObject); if (_stopwatches.TryGetValue(gameObjectPositionHash, out var value)) { return value; } value = new Stopwatch(); _stopwatches.TryAdd(gameObjectPositionHash, value); return value; } public static List<Container> GetNearbyContainers(GameObject gameObject, float radius, bool checkWard = true) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) string[] array = new string[1] { "vehicle" }; IOrderedEnumerable<Collider> orderedEnumerable = from x in Physics.OverlapSphere(gameObject.transform.position, radius, LayerMask.GetMask(array)) orderby Vector3.Distance(((Component)x).gameObject.transform.position, gameObject.transform.position) select x; List<Container> list = new List<Container>(); foreach (Collider item in orderedEnumerable) { Container componentInParent = ((Component)item).GetComponentInParent<Container>(); if (!((Object)(object)componentInParent == (Object)null) && !((Object)(object)Player.m_localPlayer == (Object)null)) { bool flag = componentInParent.CheckAccess(Player.m_localPlayer.GetPlayerID()); if (checkWard) { flag = flag && PrivateArea.CheckAccess(((Component)item).gameObject.transform.position, 0f, false, true); } if ((Object)(object)((Component)componentInParent).GetComponentInParent<Ship>() != (Object)null && flag && componentInParent.GetInventory() != null) { list.Add(componentInParent); } } } return list; } private static bool ContainerContainsItem(Container container, ItemData itemData) { if ((Object)(object)container == (Object)null || !container.m_nview.IsValid() || !container.m_nview.IsOwner() || container.m_inventory == null) { return false; } return container.GetInventory().GetAllItems().Any((ItemData item) => item.m_shared.m_name == itemData.m_shared.m_name); } public static int DeductItemFromContainer(Container container, ItemData itemData, int amount = 1) { if (!ContainerContainsItem(container, itemData)) { return 0; } int num = 0; List<ItemData> allItems = container.GetInventory().GetAllItems(); foreach (ItemData item in allItems.Where((ItemData item) => item.m_shared.m_name == itemData.m_shared.m_name)) { int num2 = Mathf.Min(item.m_stack, amount); item.m_stack -= num2; amount -= num2; num += num2; if (amount <= 0) { break; } } if (num == 0) { return 0; } allItems.RemoveAll((ItemData x) => x.m_stack <= 0); container.m_inventory.m_inventory = allItems; container.Save(); container.GetInventory().Changed(); return num; } public static int DeductItemFromAllNearbyContainers(GameObject gameObject, float radius, ItemData itemData, int amount, bool checkWard = true) { List<Container> nearbyContainers = GetNearbyContainers(gameObject, radius, checkWard); if (amount == 0) { return 0; } int num = 0; foreach (int item in from item in nearbyContainers where (Object)(object)item != (Object)null && item.m_nview.IsValid() && item.m_nview.IsOwner() && item.m_inventory != null && num != amount select DeductItemFromContainer(item, itemData, amount)) { num += item; amount -= item; } return num; } } internal static class TransparentSails { public static readonly Dictionary<int, bool> wasTransparentDict = new Dictionary<int, bool>(); public static HashSet<string> textureNames = new HashSet<string>(new string[2] { "wh_sail_01", "wh_sail_02" }); public static Dictionary<string, Texture2D> originalTextures = new Dictionary<string, Texture2D>(textureNames.Count); public static Dictionary<string, Texture2D> transparentTextures = new Dictionary<string, Texture2D>(textureNames.Count); public static void OnPrefabsLoaded() { SaveOriginalTexture(PrefabManager.Instance.GetPrefab("wh_lokis_ship").GetComponentInChildren<Ship>()); } private static Texture2D ReadableTexture(Texture2D texture) { //IL_002f: 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_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0060: 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_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_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Expected O, but got Unknown RenderTexture temporary = RenderTexture.GetTemporary(((Texture)texture).width, ((Texture)texture).height, 0, (RenderTextureFormat)7, (RenderTextureReadWrite)0); RenderTexture active = RenderTexture.active; RenderTexture.active = temporary; Texture2D val = new Texture2D(((Texture)texture).width, ((Texture)texture).height, (TextureFormat)4, false); Graphics.Blit((Texture)(object)texture, temporary); val.ReadPixels(new Rect(0f, 0f, (float)((Texture)temporary).width, (float)((Texture)temporary).height), 0, 0); val.Apply(); RenderTexture.active = active; RenderTexture.ReleaseTemporary(temporary); Sprite.Create(texture, default(Rect), Vector2.zero); ((Object)val).name = ((Object)texture).name; return val; } private static Texture2D CreateTransparentTexture(Texture2D texture, int dithering, int ditheringXOffset, int ditheringYOffset) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown //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_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) if (dithering == 0) { return texture; } float value = MainConfig.transAmount.Value; Texture2D val = new Texture2D(((Texture)texture).width, ((Texture)texture).height, (TextureFormat)4, false); int num = 0; for (int i = 0; i < ((Texture)texture).width; i++) { num += ditheringXOffset; for (int j = 0; j < ((Texture)texture).height; j++) { num += ditheringYOffset; Color pixel = texture.GetPixel(i, j); float num2 = ((num % dithering <= 0) ? (pixel.a * value) : 0f); val.SetPixel(i, j, new Color(pixel.r, pixel.g, pixel.b, num2)); } } val.Apply(); ((Object)val).name = ((Object)texture).name; return val; } private static void SaveOriginalTexture(Ship ship) { SkinnedMeshRenderer componentInChildren = ship.m_sailObject.GetComponentInChildren<SkinnedMeshRenderer>(); if (!Object.op_Implicit((Object)(object)componentInChildren)) { return; } Material[] materials = ((Renderer)componentInChildren).materials; for (int i = 0; i < materials.Length; i++) { Texture mainTexture = materials[i].mainTexture; Texture2D val = (Texture2D)(object)((mainTexture is Texture2D) ? mainTexture : null); if (textureNames.Contains(((Object)val).name)) { originalTextures[((Object)val).name] = val; break; } } } public static void UpdateSail(int instanceId, bool shouldBeTransparent, GameObject sailObject) { if (wasTransparentDict.TryGetValue(instanceId, out var value) && value == shouldBeTransparent) { return; } wasTransparentDict[instanceId] = shouldBeTransparent; SkinnedMeshRenderer componentInChildren = sailObject.GetComponentInChildren<SkinnedMeshRenderer>(); if (!Object.op_Implicit((Object)(object)componentInChildren)) { return; } Material[] materials = ((Renderer)componentInChildren).materials; foreach (Material val in materials) { val.SetOverrideTag("RenderType", "Transparent"); Texture mainTexture = val.mainTexture; Texture2D val2 = (Texture2D)(object)((mainTexture is Texture2D) ? mainTexture : null); if (textureNames.Contains(((Object)val2).name)) { if (!transparentTextures.ContainsKey(((Object)val2).name)) { transparentTextures[((Object)val2).name] = CreateTransparentTexture(ReadableTexture(originalTextures[((Object)val2).name]), 2, 1, 1); } if (shouldBeTransparent) { val.mainTexture = (Texture)(object)transparentTextures[((Object)val2).name]; } else { val.mainTexture = (Texture)(object)originalTextures[((Object)val2).name]; } } } } } internal class FileWatcher { public static void WatchFileChanges(string path, Action onChanged) { FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(); string directoryName = Path.GetDirectoryName(path); string fileName = Path.GetFileName(path); fileSystemWatcher.Path = directoryName; fileSystemWatcher.Filter = fileName; fileSystemWatcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite; fileSystemWatcher.Changed += delegate { onChanged?.Invoke(); }; fileSystemWatcher.Deleted += delegate { onChanged?.Invoke(); }; fileSystemWatcher.Created += delegate { onChanged?.Invoke(); }; fileSystemWatcher.Renamed += delegate { onChanged?.Invoke(); }; fileSystemWatcher.EnableRaisingEvents = true; } public static void WatchTranslationChanges(string path, Action onChanged) { if (!Directory.Exists(WeedheimShipMod.TranslationFilePath)) { return; } try { WatchFileChanges(Path.Combine(path, "*.*"), onChanged); } catch { Logger.LogError((object)"There was an issue loading Translation files!"); } } } internal static class LocalisedText { public static CustomLocalization Localization = LocalizationManager.Instance.GetLocalization(); public static void AddLocalisations() { CustomLocalization localization = Localization; string text = "English"; localization.AddTranslation(ref text, new Dictionary<string, string> { { "wh_lokis_ship", "Lokis Almighty Ship" }, { "item_lokis_ship_kit", "Lokis Ship Kit" }, { "text_drop_anchor", "Drop Anchors" }, { "text_raise_anchor", "Raise Anchors" }, { "text_anchor_dropped", "Aanchors dropping." }, { "text_anchor_raised", "Anchors raising." }, { "lokis_ship_ladder", "Ship Ladder" }, { "lokis_ship_rope_ladder", "Rope Ladder" }, { "lokis_ship_storage", "Ship Storage" }, { "lokis_ship_turret", "Ship Turret" }, { "piece_turret_target_everything", "Enemies" }, { "lokis_ship_lights_on", "Turn Lights On" }, { "lokis_ship_lights_off", "Turn Lights Off" }, { "ship_lights_turned_on", "Lights Turned On" }, { "ship_lights_turned_off", "Lights Turned Off" }, { "ship_battlehorn", "Battlehorn" }, { "ship_sound_battlehorn", "Blow the horn to alert everyone in long range!" }, { "text_set_url", "Set Sail URL" }, { "text_sail_url", "Sail URL" }, { "text_sail_url_deny", "Server is in control of the URL, denied!" } }); } } internal class MainConfig { internal const string ShipSection = "Ship_Settings"; internal static ConfigEntry<bool> enableLokisShip; internal static ConfigEntry<KeyboardShortcut> _anchorKey; internal static ConfigEntry<KeyboardShortcut> _lightsKey; internal const string CustomSails = "Custom_Sails"; internal static ConfigEntry<bool> enableCustomSails; internal static ConfigEntry<bool> useServerSailURL; internal static ConfigEntry<string> serverSailURL; internal static ConfigEntry<KeyboardShortcut> _sailKey; internal static bool requireKey = true; internal const string TransparentSails = "Transparent_Sails"; internal static ConfigEntry<bool> enableTransparent; internal static ConfigEntry<bool> toggleDefault; internal static ConfigEntry<KeyboardShortcut> _toggleHotKey; internal static ConfigEntry<float> transAmount; internal static bool transparencyToggle; internal const string ShipExtensions = "Ship_Extensions"; internal static ConfigEntry<bool> flagEnabled; internal static ConfigEntry<bool> shieldsEnabled; internal static ConfigEntry<bool> turretEnabled; internal static ConfigEntry<int> maxAmmoTurret; internal static ConfigEntry<bool> autoReloadTurret; public static void InitConfigs(ConfigFile config) { //IL_0036: 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_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) enableLokisShip = ConfigFileExtensions.BindConfigInOrder<bool>(config, "Ship_Settings", "EnableLokisShip", true, "Enable Lokis ship building kit to be sold by Loki.\n", true, true, true, (AcceptableValueBase)null, (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null); _anchorKey = ConfigFileExtensions.BindConfigInOrder<KeyboardShortcut>(config, "Ship_Settings", "AnchorKey", new KeyboardShortcut((KeyCode)287, Array.Empty<KeyCode>()), "Hotkey to raise or drop anchors.\n(Hover your mouse over the rudder control.)\n", false, true, true, (AcceptableValueBase)null, (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null); _lightsKey = ConfigFileExtensions.BindConfigInOrder<KeyboardShortcut>(config, "Ship_Settings", "LightsKey", new KeyboardShortcut((KeyCode)289, Array.Empty<KeyCode>()), "Hotkey to enable or disable ship lights.\n(Hover your mouse over the rudder control.)\n", false, true, true, (AcceptableValueBase)null, (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null); enableCustomSails = ConfigFileExtensions.BindConfigInOrder<bool>(config, "Custom_Sails", "CustomSails", true, "Enable custom sails on Lokis ship?\n", true, true, true, (AcceptableValueBase)null, (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null); useServerSailURL = ConfigFileExtensions.BindConfigInOrder<bool>(config, "Custom_Sails", "UseServerSail", false, "Sets Lokis ship to use the Server Sail URL?\n", true, true, true, (AcceptableValueBase)null, (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null); serverSailURL = ConfigFileExtensions.BindConfigInOrder<string>(config, "Custom_Sails", "ServerSailURL", "https://i.imgur.com/qRKBzGS.png", "This should contain a valid URL of the image to use when `UseServerSail` is enabled.\n", true, true, true, (AcceptableValueBase)null, (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null); _sailKey = ConfigFileExtensions.BindConfigInOrder<KeyboardShortcut>(config, "Ship_Settings", "EditSailKey", new KeyboardShortcut((KeyCode)304, Array.Empty<KeyCode>()), "Hotkey to interact with Lokis ship to change the sail image.\n(Hover your mouse over the ship hull and press the edit key.)\n", false, true, true, (AcceptableValueBase)null, (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null); enableTransparent = ConfigFileExtensions.BindConfigInOrder<bool>(config, "Transparent_Sails", "TransparentSails", true, "Enable transparent sails on Lokis ship?\n", false, true, true, (AcceptableValueBase)null, (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null); toggleDefault = ConfigFileExtensions.BindConfigInOrder<bool>(config, "Transparent_Sails", "ToggleState", false, "Default state of the transparent sail toggle when starting Valheim.\n", false, true, true, (AcceptableValueBase)null, (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null); _toggleHotKey = ConfigFileExtensions.BindConfigInOrder<KeyboardShortcut>(config, "Transparent_Sails", "ToggleKey", new KeyboardShortcut((KeyCode)285, Array.Empty<KeyCode>()), "Hotkey to toggle sail transparency.\n", false, true, true, (AcceptableValueBase)null, (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null); transAmount = ConfigFileExtensions.BindConfigInOrder<float>(config, "Transparent_Sails", "TransparencyAmount", 0.7f, "Amount of sail transparency.\n", false, true, true, (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 0.9f), (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null); flagEnabled = ConfigFileExtensions.BindConfigInOrder<bool>(config, "Ship_Extensions", "EnableFlag", true, "Enable flag on Lokis ship?\n", false, true, true, (AcceptableValueBase)null, (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null); shieldsEnabled = ConfigFileExtensions.BindConfigInOrder<bool>(config, "Ship_Extensions", "EnableShields", true, "Enable shields on Lokis ship?\n(Adds 400 to ship health)\n", false, true, true, (AcceptableValueBase)null, (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null); turretEnabled = ConfigFileExtensions.BindConfigInOrder<bool>(config, "Ship_Extensions", "EnableShipTurret", true, "Enable turret on Lokis ship?\n(Adds 400 to ship health)\n", true, true, true, (AcceptableValueBase)null, (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null); maxAmmoTurret = ConfigFileExtensions.BindConfigInOrder<int>(config, "Ship_Extensions", "MaxAmmoTurret", 200, "Maximum ammo for ship turrets.\n", true, true, true, (AcceptableValueBase)(object)new AcceptableValueRange<int>(50, 200), (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null); autoReloadTurret = ConfigFileExtensions.BindConfigInOrder<bool>(config, "Ship_Extensions", "AutoReloadTurret", true, "Auto reload ship turret.\nAmmo needs to be placed in ships storage.\n", false, true, true, (AcceptableValueBase)null, (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null); transparencyToggle = toggleDefault.Value; _toggleHotKey.SettingChanged += WeedheimShipMod.OnToggleKeyChanged; transAmount.SettingChanged += WeedheimShipMod.OnSettingChanged; } } [BepInPlugin("MagicMike.WeedheimShip", "WeedheimShip", "1.0.2")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public class WeedheimShipMod : BaseUnityPlugin { internal const string PluginName = "WeedheimShip"; internal const string PluginVersion = "1.0.2"; internal const string PluginAuthor = "MagicMike"; internal const string PluginGUID = "MagicMike.WeedheimShip"; internal const string PluginCopy = "Copyright © MagicMike 2025WeedheimShip"; public const string PluginLink = "https://discord.gg/zRucjV8rqc"; private static char pds = Path.DirectorySeparatorChar; public static readonly string _basePath = Paths.ConfigPath + pds + "Weedheim"; public static readonly string TranslationFilePath = _basePath + pds + "Translations"; private CustomLocalization Localization = LocalizationManager.Instance.GetLocalization(); public static WeedheimShipMod plugininstance; public static AssetBundle lokisship; public static string lokiBundle = "whlokisship"; public static GameObject shipCargoCrate = null; public static GameObject shipAnchorDropFX = null; public static GameObject shipAnchorRaiseFX = null; public static GameObject shipLightToggleFX = null; public static GameObject shipBattlehornFX = null; public static GameObject waterSplashFX = null; public static GameObject turretFireFX = null; public static GameObject turretAmmoFX = null; public static GameObject turretReloadFX = null; private Harmony harmony = new Harmony("MagicMike.WeedheimShip"); internal static ConfigFile ConfigFile; internal static ConfigFileWatcher ConfigFileWatcher; private static ButtonConfig buttonTransparentConfig; public void Awake() { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown plugininstance = this; ConfigFile = ((BaseUnityPlugin)this).Config; ConfigFileWatcher = new ConfigFileWatcher(((BaseUnityPlugin)this).Config, 1000L); ((BaseUnityPlugin)this).Config.SaveOnConfigSet = false; MainConfig.InitConfigs(((BaseUnityPlugin)this).Config); if (MainConfig.enableLokisShip.Value) { LoadAssetBundles(); AddFXAssets(); CheckForFolders(); LocalisedText.AddLocalisations(); LoadLocalisationData(TranslationFilePath); FileWatcher.WatchTranslationChanges(TranslationFilePath, delegate { LoadLocalisationData(TranslationFilePath); }); PrefabManager.OnVanillaPrefabsAvailable += AddWHItems; PrefabManager.OnVanillaPrefabsAvailable += AddWHPieces; PrefabManager.OnPrefabsRegistered += TransparentSails.OnPrefabsLoaded; RegisterInputs(); harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "MagicMike.WeedheimShip"); Game.isModded = true; } } public void OnDestroy() { ((BaseUnityPlugin)this).Config.Save(); } public void Update() { if (ZInput.instance != null && CheckInput() && ZInput.GetButtonDown(buttonTransparentConfig.Name)) { MainConfig.transparencyToggle = !MainConfig.transparencyToggle; } } public static string[] GetAcceptableKeyCodes() { Array values = Enum.GetValues(typeof(KeyCode)); int num = 0; string[] array = new string[values.Length]; foreach (object item in values) { array[num++] = item.ToString(); } return array; } private static void RegisterInputs() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: 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) //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_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Expected O, but got Unknown ButtonConfig val = new ButtonConfig { Name = "Transparent_Toggle_Sail" }; Type typeFromHandle = typeof(KeyCode); KeyboardShortcut value = MainConfig._toggleHotKey.Value; val.Key = (KeyCode)Enum.Parse(typeFromHandle, ((object)(KeyboardShortcut)(ref value)).ToString()); buttonTransparentConfig = val; InputManager.Instance.AddButton("MagicMike.WeedheimShip", buttonTransparentConfig); } private static bool CheckInput() { if ((!Object.op_Implicit((Object)(object)Chat.instance) || !Chat.instance.HasFocus()) && !Console.IsVisible() && !InventoryGui.IsVisible() && !StoreGui.IsVisible() && !Menu.IsVisible() && !Minimap.IsOpen() && (Object)(object)Player.m_localPlayer != (Object)null) { return !((Character)Player.m_localPlayer).InCutscene(); } return false; } public static void OnToggleKeyChanged(object sender, EventArgs e) { RegisterInputs(); } public static void OnSettingChanged(object sender, EventArgs e) { TransparentSails.transparentTextures.Clear(); TransparentSails.wasTransparentDict.Clear(); } public static bool AllowInput() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) if (MainConfig.requireKey && MainConfig._sailKey.Value.IsKeyHeld()) { return true; } return !MainConfig.requireKey; } public static void CheckForFolders() { if (!Directory.Exists(_basePath)) { Logger.LogInfo((object)"Creating Weedheim Directory"); Directory.CreateDirectory(_basePath); } if (!Directory.Exists(TranslationFilePath)) { Logger.LogInfo((object)"Creating Translations folder"); Directory.CreateDirectory(TranslationFilePath); } } public void LoadLocalisationData(string directory) { string[] fileSystemEntries = Directory.GetFileSystemEntries(directory, "*.json", SearchOption.AllDirectories); foreach (string path in fileSystemEntries) { string name = new DirectoryInfo(Path.GetDirectoryName(path)).Name; Path.GetFileNameWithoutExtension(path); Localization.AddJsonFile(name, File.ReadAllText(path)); } } public static void LoadAssetBundles() { lokisship = AssetUtils.LoadAssetBundleFromResources(lokiBundle, Assembly.GetExecutingAssembly()); if ((Object)(object)lokisship == (Object)null) { Logger.LogError((object)("Failed to load asset bundle with name: " + lokiBundle)); } } public static void AddFXAssets() { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Expected O, but got Unknown //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Expected O, but got Unknown //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Expected O, but got Unknown //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Expected O, but got Unknown //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Expected O, but got Unknown //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Expected O, but got Unknown //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Expected O, but got Unknown try { shipCargoCrate = lokisship.LoadAsset<GameObject>("WH_CargoCrate"); CustomPrefab val = new CustomPrefab(shipCargoCrate, true); PrefabManager.Instance.AddPrefab(val); shipLightToggleFX = lokisship.LoadAsset<GameObject>("sfx_light_switch_wh"); CustomPrefab val2 = new CustomPrefab(shipLightToggleFX, false); PrefabManager.Instance.AddPrefab(val2); shipAnchorDropFX = lokisship.LoadAsset<GameObject>("sfx_anchor_wh"); CustomPrefab val3 = new CustomPrefab(shipAnchorDropFX, false); PrefabManager.Instance.AddPrefab(val3); shipBattlehornFX = lokisship.LoadAsset<GameObject>("sfx_battlehorn_wh"); CustomPrefab val4 = new CustomPrefab(shipBattlehornFX, false); PrefabManager.Instance.AddPrefab(val4); waterSplashFX = lokisship.LoadAsset<GameObject>("vfx_watersplash_wh"); CustomPrefab val5 = new CustomPrefab(waterSplashFX, true); PrefabManager.Instance.AddPrefab(val5); turretFireFX = lokisship.LoadAsset<GameObject>("fx_turret_fire_wh"); CustomPrefab val6 = new CustomPrefab(turretFireFX, true); PrefabManager.Instance.AddPrefab(val6); turretAmmoFX = lokisship.LoadAsset<GameObject>("fx_turret_addammo_wh"); CustomPrefab val7 = new CustomPrefab(turretAmmoFX, true); PrefabManager.Instance.AddPrefab(val7); turretReloadFX = lokisship.LoadAsset<GameObject>("fx_turret_reload_wh"); CustomPrefab val8 = new CustomPrefab(turretReloadFX, true); PrefabManager.Instance.AddPrefab(val8); } catch (Exception ex) { Logger.LogError((object)("Exception caught while loading Weedheim FX Assets: " + ex.Message)); } } public static void AddWHItems() { try { WH_Items.AddItems(); } catch (Exception ex) { Logger.LogError((object)("Exception caught while adding Lokis Items: " + ex.Message)); } finally { PrefabManager.OnVanillaPrefabsAvailable -= AddWHItems; } } public static void AddWHPieces() { try { WH_Pieces.AddPieces(); } catch (Exception ex) { Logger.LogError((object)("Exception caught while adding Lokis Pieces: " + ex.Message)); } finally { PrefabManager.OnVanillaPrefabsAvailable -= AddWHPieces; } } } public static class KeyboardExtensions { public static bool IsKeyDown(this KeyboardShortcut shortcut) { //IL_0002: 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 ((int)((KeyboardShortcut)(ref shortcut)).MainKey != 0 && Input.GetKeyDown(((KeyboardShortcut)(ref shortcut)).MainKey)) { return ((KeyboardShortcut)(ref shortcut)).Modifiers.All((Func<KeyCode, bool>)Input.GetKey); } return false; } public static bool IsKeyHeld(this KeyboardShortcut shortcut) { //IL_0002: 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 ((int)((KeyboardShortcut)(ref shortcut)).MainKey != 0 && Input.GetKey(((KeyboardShortcut)(ref shortcut)).MainKey)) { return ((KeyboardShortcut)(ref shortcut)).Modifiers.All((Func<KeyCode, bool>)Input.GetKey); } return false; } } internal class WH_Items { public static void AddItems() { AddLokisItems(); } public static void AddLokisItems() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown CustomItem val = new CustomItem(WeedheimShipMod.lokisship.LoadAsset<GameObject>("wh_lokis_ship_kit"), true); ItemManager.Instance.AddItem(val); } } internal class WH_Pieces { public static EffectList buildShip; public static EffectList destroyShip; public static EffectList hitShip; public static EffectList switchShip; public static EffectList impactShip; public static EffectList storageOpen; public static EffectList storageClosed; public static void AddPieces() { LoadFX(); AddLokisShip(); } public static void LoadFX() { //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Expected O, but got Unknown //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Expected O, but got Unknown //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Expected O, but got Unknown //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Expected O, but got Unknown //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Expected O, but got Unknown //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Expected O, but got Unknown //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Expected O, but got Unknown //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Expected O, but got Unknown //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Expected O, but got Unknown //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Expected O, but got Unknown //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Expected O, but got Unknown //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Expected O, but got Unknown //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Expected O, but got Unknown //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Expected O, but got Unknown //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Expected O, but got Unknown //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Expected O, but got Unknown GameObject prefab = Cache.GetPrefab<GameObject>("sfx_build_hammer_wood"); GameObject prefab2 = Cache.GetPrefab<GameObject>("vfx_Place_VikingShip"); GameObject prefab3 = Cache.GetPrefab<GameObject>("vfx_Destroyed_AshlandsShip"); GameObject prefab4 = Cache.GetPrefab<GameObject>("sfx_ship_destroyed"); GameObject prefab5 = Cache.GetPrefab<GameObject>("sfx_ship_impact"); GameObject prefab6 = Cache.GetPrefab<GameObject>("sfx_ship_waterimpact"); GameObject prefab7 = Cache.GetPrefab<GameObject>("sfx_chest_open"); GameObject prefab8 = Cache.GetPrefab<GameObject>("sfx_chest_close"); EffectList val = new EffectList(); val.m_effectPrefabs = (EffectData[])(object)new EffectData[2] { new EffectData { m_prefab = prefab }, new EffectData { m_prefab = prefab2 } }; buildShip = val; val = new EffectList(); val.m_effectPrefabs = (EffectData[])(object)new EffectData[2] { new EffectData { m_prefab = prefab3 }, new EffectData { m_prefab = prefab4 } }; destroyShip = val; val = new EffectList(); val.m_effectPrefabs = (EffectData[])(object)new EffectData[1] { new EffectData { m_prefab = prefab5 } }; hitShip = val; val = new EffectList(); val.m_effectPrefabs = (EffectData[])(object)new EffectData[1] { new EffectData { m_prefab = prefab4 } }; switchShip = val; val = new EffectList(); val.m_effectPrefabs = (EffectData[])(object)new EffectData[1] { new EffectData { m_prefab = prefab6 } }; impactShip = val; val = new EffectList(); val.m_effectPrefabs = (EffectData[])(object)new EffectData[1] { new EffectData { m_prefab = prefab7 } }; storageOpen = val; val = new EffectList(); val.m_effectPrefabs = (EffectData[])(object)new EffectData[1] { new EffectData { m_prefab = prefab8 } }; storageClosed = val; } public static void AddLokisShip() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown //IL_0042: 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) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Expected O, but got Unknown //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Expected O, but got Unknown GameObject val = WeedheimShipMod.lokisship.LoadAsset<GameObject>("wh_lokis_ship"); PieceConfig val2 = new PieceConfig(); val2.CraftingStation = CraftingStations.Workbench; val2.PieceTable = PieceTables.Hammer; val2.Category = PieceCategories.Misc; val2.Requirements = (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig { Item = "wh_lokis_ship_kit", Amount = 1, Recover = true } }; CustomPiece val3 = new CustomPiece(val, true, val2); val.GetComponent<Ship>().m_waterImpactEffect = impactShip; val.GetComponent<Piece>().m_placeEffect = buildShip; WearNTear component = val.GetComponent<WearNTear>(); component.m_destroyedEffect = destroyShip; component.m_hitEffect = hitShip; component.m_switchEffect = switchShip; Container component2 = ((Component)Utils.FindChild(val.transform, "piece_chest", (IterativeSearchType)0)).gameObject.GetComponent<Container>(); component2.m_openEffects = storageOpen; component2.m_closeEffects = storageClosed; AudioSource[] componentsInChildren = val.GetComponentsInChildren<AudioSource>(); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].outputAudioMixerGroup = AudioMan.instance.m_ambientMixer; } PieceManager.Instance.AddPiece(val3); } } }