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 LatchLink v0.9.2
LatchLink.dll
Decompiled 2 months agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using HarmonyLib; using Jotunn; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; 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("LatchLink")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.9.2.0")] [assembly: AssemblyInformationalVersion("0.9.2")] [assembly: AssemblyProduct("LatchLink")] [assembly: AssemblyTitle("LatchLink")] [assembly: AssemblyVersion("0.9.2.0")] namespace DoorSwitch; internal static class DoorInteractionGuard { internal static bool ShouldBlock(Door door) { ZNetView val = (((Object)(object)door != (Object)null) ? ((Component)door).GetComponentInParent<ZNetView>() : null); if ((Object)(object)val == (Object)null || !val.IsValid()) { return false; } ZDO zDO = val.GetZDO(); if (SwitchData.IsDirectInteractionDisabled(zDO)) { return HasValidController(zDO); } return false; } internal static void AddController(ZDO target, ZDOID controllerId) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) if (target != null && !((ZDOID)(ref controllerId)).IsNone()) { ZDOMan instance = ZDOMan.instance; SwitchData.AddController(target, (instance != null) ? instance.GetZDO(controllerId) : null); } } internal static void RemoveController(ZDO target, ZDOID controllerId) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) if (target != null) { ZDOMan instance = ZDOMan.instance; SwitchData.RemoveController(target, (instance != null) ? instance.GetZDO(controllerId) : null); if (SwitchData.ControllerCount(target) == 0) { SwitchData.SetDirectInteractionDisabled(target, disabled: false); } } } private static bool HasValidController(ZDO target) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: 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) foreach (ZDOID item in SwitchData.ReadDoorControllers(target)) { ZDOMan instance = ZDOMan.instance; ZDO val = ((instance != null) ? instance.GetZDO(item) : null); if (val != null && SwitchPieceFactory.IsSwitchPrefab(val.GetPrefab()) && SwitchData.ContainsLink(val, target)) { return true; } } return false; } } [HarmonyPatch(typeof(Door), "Interact")] [HarmonyPriority(0)] [HarmonyAfter(new string[] { "Harmony.Azumatt.WardIsLove" })] internal static class DoorInteractionPatch { private static bool Prefix(Door __instance, Humanoid character, bool hold, bool alt, ref bool __result) { if (hold) { return true; } if (LinkingSession.ShouldHandleDoorInteraction) { __result = LinkingSession.TryHandleDoor(__instance, character, alt); return false; } if (!LinkingSession.IsProgrammaticDoorInteraction && DoorInteractionGuard.ShouldBlock(__instance)) { LinkingSession.ShowMessage("This door is controlled by a linked switch"); __result = true; return false; } return true; } } public sealed class DoorSwitchController : MonoBehaviour, Hoverable, Interactable { private const float StatePollInterval = 0.1f; private const float PositionAnimationSpeed = 0.8f; private const float RotationAnimationSpeed = 240f; public string PieceNameToken; public Transform Actuator; public Vector3 ReleasedPosition; public Vector3 ActivePosition; public Vector3 ReleasedRotation; public Vector3 ActiveRotation; public bool PulseOnActivation; public float PulseDuration = 0.55f; private ZNetView networkView; private bool targetActive; private float nextStatePoll; private int lastActivation; private bool activationInitialized; private float pulseUntil; private void Awake() { networkView = ((Component)this).GetComponent<ZNetView>(); RefreshVisualState(); ApplyVisualState(immediate: true); } private void Update() { if (!((Object)(object)networkView == (Object)null) && networkView.IsValid()) { if (Time.time >= nextStatePoll) { nextStatePoll = Time.time + 0.1f; RefreshVisualState(); } ApplyVisualState(immediate: false); } } public bool Interact(Humanoid character, bool hold, bool alt) { //IL_0026: 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_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008c: 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) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) if (hold || (Object)(object)networkView == (Object)null || !networkView.IsValid()) { return false; } if (!PrivateArea.CheckAccess(((Component)this).transform.position, 0f, true, false)) { return true; } bool flag = alt || ZInput.GetKey((KeyCode)304, false) || ZInput.GetKey((KeyCode)303, false); bool flag2 = ZInput.GetKey((KeyCode)308, false) || ZInput.GetKey((KeyCode)307, false); ZDOID uid = networkView.GetZDO().m_uid; if (flag && flag2) { SwitchRpc.RequestClearLinks(uid); } else if (flag) { LinkingSession.BeginOrCancel(uid); } else if (flag2) { SwitchRpc.RequestCycleMode(uid); } else { SwitchRpc.RequestActivate(uid); } return true; } public bool UseItem(Humanoid user, ItemData item) { return false; } public string GetHoverName() { return Localization.instance.Localize(PieceNameToken); } public float GetHoverOffset() { return 0f; } public string GetHoverText() { if ((Object)(object)networkView == (Object)null || !networkView.IsValid()) { return GetHoverName(); } ZDO zDO = networkView.GetZDO(); string text = string.Concat(str1: string.Format(arg1: SwitchData.LinkCount(zDO), format: " ({0}, {1} linked)\n", arg0: SwitchData.GetModeName(SwitchData.ReadMode(zDO))), str0: GetHoverName(), str2: "[<color=yellow><b>$KEY_Use</b></color>] Activate\n[<color=yellow><b>Shift + $KEY_Use</b></color>] Link [<color=yellow><b>Alt + $KEY_Use</b></color>] Mode"); if (SwitchData.HasLegacyLinks(zDO)) { text += "\nOld links: relink required after update"; } return Localization.instance.Localize(text); } private void RefreshVisualState() { //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) ZDO val = (((Object)(object)networkView != (Object)null && networkView.IsValid()) ? networkView.GetZDO() : null); if (val == null) { targetActive = false; return; } if (PulseOnActivation) { int num = val.GetInt("doorswitch_activation", 0); if (activationInitialized && num != lastActivation) { pulseUntil = Time.time + PulseDuration; } lastActivation = num; activationInitialized = true; } List<ZDOID> list = SwitchData.ReadLinks(val); if (list.Count == 0) { targetActive = false; return; } bool flag = false; bool flag2 = false; foreach (ZDOID item in list) { ZDOMan instance = ZDOMan.instance; ZDO val2 = ((instance != null) ? instance.GetZDO(item) : null); if (val2 != null) { flag = true; if (val2.GetInt(ZDOVars.s_state, 0) != 0) { flag2 = true; break; } } } targetActive = (flag ? flag2 : val.GetBool("doorswitch_last_state", false)); } private void ApplyVisualState(bool immediate) { //IL_0038: 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_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: 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_0081: 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_00a3: 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) //IL_00b4: 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_0069: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)Actuator == (Object)null)) { bool num = (PulseOnActivation ? (Time.time < pulseUntil) : targetActive); Vector3 val = (num ? ActivePosition : ReleasedPosition); Quaternion val2 = Quaternion.Euler(num ? ActiveRotation : ReleasedRotation); if (immediate) { Actuator.localPosition = val; Actuator.localRotation = val2; } else { Actuator.localPosition = Vector3.MoveTowards(Actuator.localPosition, val, 0.8f * Time.deltaTime); Actuator.localRotation = Quaternion.RotateTowards(Actuator.localRotation, val2, 240f * Time.deltaTime); } } } } [BepInPlugin("com.tomtom.latchlink", "LatchLink", "0.9.2")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public sealed class DoorSwitchPlugin : BaseUnityPlugin { public const string ModGuid = "com.tomtom.latchlink"; public const string ModName = "LatchLink"; public const string ModVersion = "0.9.2"; private Harmony harmony; internal static ConfigEntry<int> MaximumLinks { get; private set; } internal static ConfigEntry<float> MaximumLinkDistance { get; private set; } private void Awake() { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Expected O, but got Unknown //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Expected O, but got Unknown MaximumLinks = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Maximum links per switch", 32, new ConfigDescription("Maximum number of doors controlled by one switch.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 256), Array.Empty<object>())); MaximumLinkDistance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Maximum link distance", 100f, new ConfigDescription("Maximum distance in metres between a switch and a linked target.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(2f, 1000f), Array.Empty<object>())); AddLocalizations(); SwitchRpc.Initialize(); PrefabManager.OnVanillaPrefabsAvailable += RegisterPieces; harmony = new Harmony("com.tomtom.latchlink"); harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"LatchLink 0.9.2 loaded"); } private void Update() { LinkingSession.Update(); } private void OnDestroy() { PrefabManager.OnVanillaPrefabsAvailable -= RegisterPieces; Harmony obj = harmony; if (obj != null) { obj.UnpatchSelf(); } } private static void AddLocalizations() { CustomLocalization localization = LocalizationManager.Instance.GetLocalization(); string text = "English"; localization.AddTranslation(ref text, new Dictionary<string, string> { ["doorswitch_wood_name"] = "Wooden Lever", ["doorswitch_wood_description"] = "A simple lever for remotely operating linked doors and gates.", ["doorswitch_iron_name"] = "Iron Button", ["doorswitch_iron_description"] = "A compact mechanical control for linked doors and gates.", ["doorswitch_rune_name"] = "Rune Switch", ["doorswitch_rune_description"] = "A glowing runic control for linked doors and gates.", ["doorswitch_bookshelf_name"] = "Secret Bookshelf", ["doorswitch_bookshelf_description"] = "A disguised control whose telltale book operates linked doors and gates." }); } private static void RegisterPieces() { SwitchPieceFactory.RegisterAll(); PrefabManager.OnVanillaPrefabsAvailable -= RegisterPieces; } } internal static class DoorTargets { internal static bool IsSupported(ZDO target) { //IL_004f: Unknown result type (might be due to invalid IL or missing references) if (target == null || (Object)(object)ZNetScene.instance == (Object)null) { return false; } GameObject prefab = ZNetScene.instance.GetPrefab(target.GetPrefab()); if ((Object)(object)prefab == (Object)null) { return false; } if ((Object)(object)prefab.GetComponentInChildren<Door>(true) != (Object)null) { return true; } if (StoneveilCompatibility.IsConvertedPanel(target)) { return true; } GameObject obj = ZNetScene.instance.FindInstance(target.m_uid); Door val = ((obj != null) ? obj.GetComponentInChildren<Door>(true) : null); if ((Object)(object)val != (Object)null) { return !StoneveilCompatibility.IsAdapter(val); } return false; } } internal static class LinkingSession { private const float SessionDuration = 90f; private static ZDOID switchId = ZDOID.None; private static float expiresAt; private static bool suppressDoorHandling; internal static bool IsActive { get { if (!((ZDOID)(ref switchId)).IsNone()) { return Time.unscaledTime < expiresAt; } return false; } } internal static bool ShouldHandleDoorInteraction { get { if (IsActive) { return !suppressDoorHandling; } return false; } } internal static bool IsProgrammaticDoorInteraction => suppressDoorHandling; internal static void BeginOrCancel(ZDOID id) { //IL_001f: 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_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) if (IsActive && switchId == id) { Cancel("Link mode cancelled"); return; } switchId = id; expiresAt = Time.unscaledTime + 90f; ShowMessage("Link mode: Use links/unlinks; Alt + Use toggles direct door use"); } internal static void Update() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) if (!IsActive) { switchId = ZDOID.None; } else if (ZInput.GetKeyDown((KeyCode)27, false)) { Cancel("Link mode finished"); } } internal static bool TryHandleDoor(Door door, Humanoid user, bool alt) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: 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_008d: Unknown result type (might be due to invalid IL or missing references) if (!IsActive) { return false; } expiresAt = Time.unscaledTime + 90f; if (!PrivateArea.CheckAccess(((Component)door).transform.position, 0f, true, false)) { End(); return true; } ZNetView componentInParent = ((Component)door).GetComponentInParent<ZNetView>(); if ((Object)(object)componentInParent == (Object)null || !componentInParent.IsValid()) { ShowMessage("That target is not networked and cannot be linked"); End(); return true; } if (alt || ZInput.GetKey((KeyCode)308, false) || ZInput.GetKey((KeyCode)307, false)) { SwitchRpc.RequestToggleDirectInteraction(switchId, componentInParent.GetZDO().m_uid); } else { SwitchRpc.RequestToggleLink(switchId, componentInParent.GetZDO().m_uid); } End(); return true; } internal static bool InteractWithoutLinking(Door door, Humanoid user, ZDOID sourceSwitch, bool open, out string failure) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) failure = null; bool flag = suppressDoorHandling; suppressDoorHandling = true; try { if (StoneveilCompatibility.TryInteractFromSwitch(door, user, sourceSwitch, open, out var result)) { if (!result) { failure = StoneveilCompatibility.GetSwitchFailure(door); } return result; } return door.Interact(user, false, false); } finally { suppressDoorHandling = flag; } } private static void Cancel(string message) { End(); ShowMessage(message); } private static void End() { //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) switchId = ZDOID.None; expiresAt = 0f; } internal static void ShowMessage(string message) { if ((Object)(object)Player.m_localPlayer != (Object)null) { ((Character)Player.m_localPlayer).Message((MessageType)2, message, 0, (Sprite)null, false); } } } internal static class StableIdentity { internal const string Key = "latchlink_identity"; private static readonly FieldInfo ObjectsField = AccessTools.Field(typeof(ZDOMan), "m_objectsByID"); private static readonly Stopwatch Clock = Stopwatch.StartNew(); private static readonly Dictionary<string, ZDO> Index = new Dictionary<string, ZDO>(); private static ZDOMan indexedManager; private static long nextRefresh; internal static string Ensure(ZDO zdo) { string text = zdo.GetString("latchlink_identity", string.Empty); if (!Guid.TryParseExact(text, "N", out var _)) { text = Guid.NewGuid().ToString("N"); zdo.Set("latchlink_identity", text); } nextRefresh = 0L; return text; } internal static ZDO Resolve(string identity) { //IL_00e6: Unknown result type (might be due to invalid IL or missing references) ZDOMan instance = ZDOMan.instance; if (instance == null) { return null; } if (instance != indexedManager || Clock.ElapsedMilliseconds >= nextRefresh) { Index.Clear(); indexedManager = instance; nextRefresh = Clock.ElapsedMilliseconds + 1000; foreach (ZDO value2 in ((Dictionary<ZDOID, ZDO>)ObjectsField.GetValue(instance)).Values) { string text = value2.GetString("latchlink_identity", string.Empty); if (!string.IsNullOrEmpty(text)) { if (Index.ContainsKey(text)) { Index[text] = null; } else { Index.Add(text, value2); } } } } if (!Index.TryGetValue(identity, out var value) || value == null) { return null; } if (instance.GetZDO(value.m_uid) != value || !(value.GetString("latchlink_identity", string.Empty) == identity)) { return null; } return value; } } internal static class StoneveilCompatibility { private const string PluginId = "com.tomtom.secret"; private const string StateKey = "com.tomtom.secret.state.v1"; internal static bool IsConvertedPanel(ZDO target) { if (target == null || !Chainloader.PluginInfos.TryGetValue("com.tomtom.secret", out var value)) { return false; } int num = target.GetInt("com.tomtom.secret.state.v1", 0); if (num < 1 || num > 127 || (num & 1) == 0) { return false; } if (AccessTools.Field(((object)value.Instance).GetType(), "Supported")?.GetValue(null) is IDictionary dictionary) { return dictionary.Contains(target.GetPrefab()); } return false; } internal static bool IsAdapter(Door door) { return ((object)door)?.GetType().FullName == "Secret.StoneveilDoor"; } internal static bool TryInteractFromSwitch(Door door, Humanoid user, ZDOID switchId, bool open, out bool result) { //IL_0068: Unknown result type (might be due to invalid IL or missing references) result = false; if (!IsAdapter(door)) { return false; } MethodInfo methodInfo = AccessTools.Method(((object)door).GetType(), "InteractFromSwitch", new Type[3] { typeof(Humanoid), typeof(ZDOID), typeof(bool) }, (Type[])null); if (methodInfo == null) { return false; } result = (bool)methodInfo.Invoke(door, new object[3] { user, switchId, open }); return true; } internal static string GetSwitchFailure(Door door) { if (!IsAdapter(door)) { return null; } return AccessTools.Method(((object)door).GetType(), "GetSwitchFailure", Type.EmptyTypes, (Type[])null)?.Invoke(door, null) as string; } } internal static class SwitchData { internal const string LinksKey = "doorswitch_links"; internal const string ModeKey = "doorswitch_mode"; internal const string LastStateKey = "doorswitch_last_state"; internal const string ActivationKey = "doorswitch_activation"; internal const string DoorControllersKey = "doorswitch_controllers"; internal const string DirectInteractionDisabledKey = "doorswitch_direct_disabled"; internal static List<ZDOID> ReadLinks(ZDO zdo) { return ReadIds(zdo, "doorswitch_links"); } internal static List<ZDOID> ReadDoorControllers(ZDO zdo) { return ReadIds(zdo, "doorswitch_controllers"); } internal static int LinkCount(ZDO zdo) { return Entries(zdo, "doorswitch_links").Count; } internal static bool HasLegacyLinks(ZDO zdo) { return Entries(zdo, "doorswitch_links").Any((string entry) => !IsStable(entry)); } internal static bool ContainsLink(ZDO source, ZDO target) { return Contains(source, "doorswitch_links", target); } internal static void AddLink(ZDO source, ZDO target) { Add(source, "doorswitch_links", target); } internal static void RemoveLink(ZDO source, ZDO target) { Remove(source, "doorswitch_links", target); } internal static void AddController(ZDO target, ZDO controller) { Add(target, "doorswitch_controllers", controller); } internal static void RemoveController(ZDO target, ZDO controller) { Remove(target, "doorswitch_controllers", controller); } internal static int ControllerCount(ZDO target) { return Entries(target, "doorswitch_controllers").Count((string entry) => IsStable(entry)); } internal static void ClearLinks(ZDO source) { source.Set("doorswitch_links", string.Empty); } internal static bool IsDirectInteractionDisabled(ZDO zdo) { if (zdo != null) { return zdo.GetBool("doorswitch_direct_disabled", false); } return false; } internal static void SetDirectInteractionDisabled(ZDO zdo, bool disabled) { if (zdo != null) { zdo.Set("doorswitch_direct_disabled", disabled); } } private static List<string> Entries(ZDO zdo, string key) { return (((zdo != null) ? zdo.GetString(key, string.Empty) : null) ?? string.Empty).Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries).Distinct().ToList(); } private static bool IsStable(string entry) { Guid result; if (entry.StartsWith("g:", StringComparison.Ordinal)) { return Guid.TryParseExact(entry.Substring(2), "N", out result); } return false; } private static List<ZDOID> ReadIds(ZDO zdo, string key) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) List<ZDOID> list = new List<ZDOID>(); foreach (string item in Entries(zdo, key)) { if (IsStable(item)) { ZDO val = StableIdentity.Resolve(item.Substring(2)); if (val != null) { list.Add(val.m_uid); } } } return list; } private static bool Contains(ZDO source, string key, ZDO target) { string text = ((target != null) ? target.GetString("latchlink_identity", string.Empty) : null); if (!string.IsNullOrEmpty(text)) { return Entries(source, key).Contains("g:" + text); } return false; } private static void Add(ZDO source, string key, ZDO target) { if (source != null && target != null) { string item = "g:" + StableIdentity.Ensure(target); List<string> list = Entries(source, key).Where(IsStable).ToList(); if (!list.Contains(item)) { list.Add(item); } source.Set(key, string.Join(";", list)); } } private static void Remove(ZDO source, string key, ZDO target) { if (source != null && target != null) { List<string> list = Entries(source, key); list.Remove("g:" + target.GetString("latchlink_identity", string.Empty)); source.Set(key, string.Join(";", list)); } } internal static SwitchMode ReadMode(ZDO zdo) { int num = ((zdo != null) ? zdo.GetInt("doorswitch_mode", 0) : 0); if (num < 0 || num > 2) { return SwitchMode.Toggle; } return (SwitchMode)num; } internal static string GetModeName(SwitchMode mode) { return mode switch { SwitchMode.Close => "Close", SwitchMode.Open => "Open", _ => "Toggle", }; } } [HarmonyPatch(typeof(Player), "HaveRequirements", new Type[] { typeof(Piece), typeof(RequirementMode) })] internal static class SwitchDiscoveryPatch { private static bool Prefix(Player __instance, Piece piece, RequirementMode mode, ref bool __result) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 if ((int)mode != 1 || !SwitchPieceFactory.IsSwitchPiece(piece)) { return true; } if (piece.m_dlc.Length > 0 && !DLCMan.instance.IsDLCInstalled(piece.m_dlc)) { __result = false; return false; } Requirement[] resources = piece.m_resources; foreach (Requirement val in resources) { if ((Object)(object)val.m_resItem != (Object)null && val.m_amount > 0 && !__instance.IsKnownMaterial(val.m_resItem.m_itemData.m_shared.m_name)) { __result = false; return false; } } __result = true; return false; } } internal static class SwitchIconFactory { private const int Size = 64; internal static Sprite Create(SwitchVisualStyle style) { //IL_001c: 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_0066: 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_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Expected O, but got Unknown //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) Color32[] array = (Color32[])(object)new Color32[4096]; Color32 val = default(Color32); ((Color32)(ref val))..ctor((byte)0, (byte)0, (byte)0, (byte)0); for (int i = 0; i < array.Length; i++) { array[i] = val; } switch (style) { case SwitchVisualStyle.Bookshelf: DrawBookshelf(array); break; case SwitchVisualStyle.IronButton: DrawIronButton(array); break; case SwitchVisualStyle.RuneSwitch: DrawRuneSwitch(array); break; default: DrawWoodLever(array); break; } Texture2D val2 = new Texture2D(64, 64, (TextureFormat)4, false) { name = $"DoorSwitch_{style}_Icon", filterMode = (FilterMode)0, wrapMode = (TextureWrapMode)1 }; val2.SetPixels32(array); val2.Apply(false, false); Sprite obj = Sprite.Create(val2, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f), 64f); ((Object)obj).name = ((Object)val2).name; return obj; } private static void DrawWoodLever(Color32[] pixels) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: 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) DrawPlate(pixels, new Color32((byte)47, (byte)29, (byte)17, byte.MaxValue), new Color32((byte)131, (byte)76, (byte)31, byte.MaxValue), new Color32((byte)188, (byte)116, (byte)48, byte.MaxValue)); DrawLine(pixels, 30, 27, 41, 47, 7, new Color32((byte)48, (byte)31, (byte)18, byte.MaxValue)); DrawLine(pixels, 30, 27, 41, 47, 4, new Color32((byte)222, (byte)153, (byte)54, byte.MaxValue)); FillCircle(pixels, 30, 27, 8, new Color32((byte)48, (byte)31, (byte)18, byte.MaxValue)); FillCircle(pixels, 30, 27, 5, new Color32((byte)230, (byte)165, (byte)65, byte.MaxValue)); FillCircle(pixels, 42, 49, 7, new Color32((byte)48, (byte)31, (byte)18, byte.MaxValue)); FillCircle(pixels, 42, 49, 4, new Color32((byte)244, (byte)183, (byte)72, byte.MaxValue)); } private static void DrawIronButton(Color32[] pixels) { //IL_000c: 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) //IL_0035: 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_0070: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) DrawPlate(pixels, new Color32((byte)25, (byte)29, (byte)32, byte.MaxValue), new Color32((byte)91, (byte)103, (byte)112, byte.MaxValue), new Color32((byte)153, (byte)165, (byte)171, byte.MaxValue)); FillCircle(pixels, 32, 31, 15, new Color32((byte)35, (byte)20, (byte)18, byte.MaxValue)); FillCircle(pixels, 32, 31, 12, new Color32((byte)191, (byte)35, (byte)25, byte.MaxValue)); FillCircle(pixels, 30, 34, 7, new Color32((byte)239, (byte)61, (byte)37, byte.MaxValue)); FillCircle(pixels, 28, 37, 3, new Color32(byte.MaxValue, (byte)146, (byte)100, byte.MaxValue)); DrawRivets(pixels, new Color32((byte)206, (byte)213, (byte)215, byte.MaxValue)); } private static void DrawRuneSwitch(Color32[] pixels) { //IL_000c: 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) //IL_0035: 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_0082: 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_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) DrawPlate(pixels, new Color32((byte)28, (byte)34, (byte)37, byte.MaxValue), new Color32((byte)75, (byte)85, (byte)89, byte.MaxValue), new Color32((byte)130, (byte)141, (byte)145, byte.MaxValue)); Color32 color = default(Color32); ((Color32)(ref color))..ctor((byte)7, (byte)91, (byte)119, byte.MaxValue); Color32 color2 = default(Color32); ((Color32)(ref color2))..ctor((byte)46, (byte)224, byte.MaxValue, byte.MaxValue); DrawLine(pixels, 29, 17, 35, 48, 8, color); DrawLine(pixels, 32, 33, 45, 44, 8, color); DrawLine(pixels, 32, 33, 43, 22, 8, color); DrawLine(pixels, 29, 17, 35, 48, 4, color2); DrawLine(pixels, 32, 33, 45, 44, 4, color2); DrawLine(pixels, 32, 33, 43, 22, 4, color2); } private static void DrawBookshelf(Color32[] pixels) { //IL_002b: 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_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_0206: Unknown result type (might be due to invalid IL or missing references) //IL_0224: Unknown result type (might be due to invalid IL or missing references) //IL_0245: Unknown result type (might be due to invalid IL or missing references) //IL_0266: Unknown result type (might be due to invalid IL or missing references) //IL_0284: Unknown result type (might be due to invalid IL or missing references) Color32 color = default(Color32); ((Color32)(ref color))..ctor((byte)48, (byte)24, (byte)10, byte.MaxValue); Color32 color2 = default(Color32); ((Color32)(ref color2))..ctor((byte)126, (byte)67, (byte)24, byte.MaxValue); FillRect(pixels, 8, 4, 55, 59, color); FillRect(pixels, 12, 8, 51, 55, new Color32((byte)74, (byte)36, (byte)14, byte.MaxValue)); FillRect(pixels, 8, 4, 13, 59, color2); FillRect(pixels, 50, 4, 55, 59, color2); FillRect(pixels, 8, 4, 55, 9, new Color32((byte)169, (byte)96, (byte)35, byte.MaxValue)); FillRect(pixels, 8, 54, 55, 59, color2); FillRect(pixels, 12, 22, 51, 26, color2); FillRect(pixels, 12, 38, 51, 42, color2); FillRect(pixels, 15, 10, 20, 21, new Color32((byte)42, (byte)83, (byte)116, byte.MaxValue)); FillRect(pixels, 21, 11, 26, 21, new Color32((byte)145, (byte)91, (byte)25, byte.MaxValue)); FillRect(pixels, 27, 10, 34, 21, new Color32((byte)45, (byte)101, (byte)56, byte.MaxValue)); FillRect(pixels, 37, 9, 44, 21, new Color32((byte)179, (byte)45, (byte)30, byte.MaxValue)); FillRect(pixels, 45, 11, 49, 21, new Color32((byte)42, (byte)83, (byte)116, byte.MaxValue)); FillRect(pixels, 15, 27, 21, 37, new Color32((byte)145, (byte)91, (byte)25, byte.MaxValue)); FillRect(pixels, 22, 26, 28, 37, new Color32((byte)42, (byte)83, (byte)116, byte.MaxValue)); FillRect(pixels, 31, 25, 38, 37, new Color32((byte)210, (byte)51, (byte)31, byte.MaxValue)); FillRect(pixels, 39, 27, 48, 37, new Color32((byte)45, (byte)101, (byte)56, byte.MaxValue)); FillRect(pixels, 32, 34, 37, 39, new Color32((byte)246, (byte)133, (byte)55, byte.MaxValue)); FillRect(pixels, 15, 43, 20, 53, new Color32((byte)45, (byte)101, (byte)56, byte.MaxValue)); FillRect(pixels, 21, 42, 27, 53, new Color32((byte)42, (byte)83, (byte)116, byte.MaxValue)); FillRect(pixels, 28, 44, 36, 53, new Color32((byte)179, (byte)45, (byte)30, byte.MaxValue)); FillRect(pixels, 37, 42, 43, 53, new Color32((byte)145, (byte)91, (byte)25, byte.MaxValue)); FillRect(pixels, 44, 43, 49, 53, new Color32((byte)42, (byte)83, (byte)116, byte.MaxValue)); } private static void DrawPlate(Color32[] pixels, Color32 border, Color32 face, Color32 highlight) { //IL_0008: 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_0026: 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) FillRect(pixels, 10, 6, 53, 57, border); FillRect(pixels, 14, 10, 49, 53, face); FillRect(pixels, 16, 12, 47, 15, highlight); FillRect(pixels, 16, 16, 19, 50, highlight); } private static void DrawRivets(Color32[] pixels, Color32 color) { //IL_0006: 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_001e: 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) FillCircle(pixels, 18, 15, 2, color); FillCircle(pixels, 46, 15, 2, color); FillCircle(pixels, 18, 49, 2, color); FillCircle(pixels, 46, 49, 2, color); } private static void DrawLine(Color32[] pixels, int x0, int y0, int x1, int y1, int thickness, Color32 color) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) int num = Mathf.Abs(x1 - x0); int num2 = ((x0 < x1) ? 1 : (-1)); int num3 = -Mathf.Abs(y1 - y0); int num4 = ((y0 < y1) ? 1 : (-1)); int num5 = num + num3; while (true) { FillCircle(pixels, x0, y0, thickness / 2, color); if (x0 != x1 || y0 != y1) { int num6 = 2 * num5; if (num6 >= num3) { num5 += num3; x0 += num2; } if (num6 <= num) { num5 += num; y0 += num4; } continue; } break; } } private static void FillCircle(Color32[] pixels, int centerX, int centerY, int radius, Color32 color) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) int num = radius * radius; for (int i = centerY - radius; i <= centerY + radius; i++) { for (int j = centerX - radius; j <= centerX + radius; j++) { int num2 = j - centerX; int num3 = i - centerY; if (num2 * num2 + num3 * num3 <= num) { SetPixel(pixels, j, i, color); } } } } private static void FillRect(Color32[] pixels, int minX, int minY, int maxX, int maxY, Color32 color) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) for (int i = minY; i <= maxY; i++) { for (int j = minX; j <= maxX; j++) { SetPixel(pixels, j, i, color); } } } private static void SetPixel(Color32[] pixels, int x, int y, Color32 color) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) if (x >= 0 && x < 64 && y >= 0 && y < 64) { pixels[y * 64 + x] = color; } } } internal enum SwitchMode { Toggle, Open, Close } internal static class SwitchPieceFactory { private readonly struct Requirement { internal string Item { get; } internal int Amount { get; } internal Requirement(string item, int amount) { Item = item; Amount = amount; } } private const string BasePrefab = "sign"; private static readonly HashSet<int> SwitchPrefabHashes = new HashSet<int>(); internal static void RegisterAll() { Register("doorswitch_wood", "$doorswitch_wood_name", "$doorswitch_wood_description", SwitchVisualStyle.WoodLever, new Requirement[2] { new Requirement("Wood", 4), new Requirement("Resin", 1) }); Register("doorswitch_iron", "$doorswitch_iron_name", "$doorswitch_iron_description", SwitchVisualStyle.IronButton, new Requirement[2] { new Requirement("FineWood", 2), new Requirement("Iron", 2) }); Register("doorswitch_rune", "$doorswitch_rune_name", "$doorswitch_rune_description", SwitchVisualStyle.RuneSwitch, new Requirement[3] { new Requirement("Stone", 4), new Requirement("SurtlingCore", 1), new Requirement("GreydwarfEye", 2) }); Register("doorswitch_bookshelf", "$doorswitch_bookshelf_name", "$doorswitch_bookshelf_description", SwitchVisualStyle.Bookshelf, new Requirement[3] { new Requirement("FineWood", 10), new Requirement("DeerHide", 4), new Requirement("Bronze", 1) }); } internal static bool IsSwitchPrefab(int prefabHash) { return SwitchPrefabHashes.Contains(prefabHash); } private static void Register(string prefabName, string displayName, string description, SwitchVisualStyle style, IEnumerable<Requirement> requirements) { //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_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Expected O, but got Unknown //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Expected O, but got Unknown PieceConfig val = new PieceConfig { Name = displayName, Description = description, PieceTable = PieceTables.Hammer, Category = PieceCategories.Misc, CraftingStation = CraftingStations.Workbench, Icon = SwitchIconFactory.Create(style) }; foreach (Requirement requirement in requirements) { val.AddRequirement(requirement.Item, requirement.Amount, true); } CustomPiece val2 = new CustomPiece(prefabName, "sign", val); PreparePrefab(val2.PiecePrefab, displayName, style); PieceManager.Instance.AddPiece(val2); SwitchPrefabHashes.Add(StringExtensionMethods.GetStableHashCode(prefabName)); } internal static bool IsSwitchPiece(Piece piece) { if ((Object)(object)piece != (Object)null) { return IsSwitchPrefab(StringExtensionMethods.GetStableHashCode(Utils.GetPrefabName(((Component)piece).gameObject))); } return false; } private static void PreparePrefab(GameObject prefab, string displayName, SwitchVisualStyle style) { Material sourceMaterial = (from renderer in prefab.GetComponentsInChildren<Renderer>(true) select renderer.sharedMaterial).FirstOrDefault((Func<Material, bool>)((Material material) => (Object)(object)material != (Object)null)); Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true); for (int num = 0; num < componentsInChildren.Length; num++) { componentsInChildren[num].enabled = false; } Sign[] componentsInChildren2 = prefab.GetComponentsInChildren<Sign>(true); for (int num = 0; num < componentsInChildren2.Length; num++) { Object.DestroyImmediate((Object)(object)componentsInChildren2[num]); } DoorSwitchController doorSwitchController = prefab.AddComponent<DoorSwitchController>(); doorSwitchController.PieceNameToken = displayName; BuildVisual(prefab, doorSwitchController, style, sourceMaterial); } private static void BuildVisual(GameObject prefab, DoorSwitchController controller, SwitchVisualStyle style, Material sourceMaterial) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown //IL_0039: 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) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_0188: 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_019a: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01a0: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_01c9: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_0214: Unknown result type (might be due to invalid IL or missing references) //IL_0228: Unknown result type (might be due to invalid IL or missing references) //IL_022d: Unknown result type (might be due to invalid IL or missing references) //IL_023e: Unknown result type (might be due to invalid IL or missing references) //IL_026c: Unknown result type (might be due to invalid IL or missing references) //IL_0280: Unknown result type (might be due to invalid IL or missing references) //IL_0294: Unknown result type (might be due to invalid IL or missing references) //IL_02b6: Unknown result type (might be due to invalid IL or missing references) //IL_02ca: Unknown result type (might be due to invalid IL or missing references) //IL_02de: Unknown result type (might be due to invalid IL or missing references) //IL_0300: Unknown result type (might be due to invalid IL or missing references) //IL_0314: Unknown result type (might be due to invalid IL or missing references) //IL_0328: Unknown result type (might be due to invalid IL or missing references) //IL_033c: Unknown result type (might be due to invalid IL or missing references) //IL_0341: Unknown result type (might be due to invalid IL or missing references) //IL_0356: Unknown result type (might be due to invalid IL or missing references) //IL_035b: Unknown result type (might be due to invalid IL or missing references) //IL_0362: Unknown result type (might be due to invalid IL or missing references) //IL_0367: Unknown result type (might be due to invalid IL or missing references) //IL_0368: Unknown result type (might be due to invalid IL or missing references) //IL_036a: Unknown result type (might be due to invalid IL or missing references) //IL_036f: Unknown result type (might be due to invalid IL or missing references) //IL_0371: Unknown result type (might be due to invalid IL or missing references) //IL_0387: Unknown result type (might be due to invalid IL or missing references) //IL_03a0: Unknown result type (might be due to invalid IL or missing references) //IL_03b7: Unknown result type (might be due to invalid IL or missing references) //IL_03cb: Unknown result type (might be due to invalid IL or missing references) //IL_03d0: Unknown result type (might be due to invalid IL or missing references) //IL_03e1: Unknown result type (might be due to invalid IL or missing references) //IL_0412: Unknown result type (might be due to invalid IL or missing references) //IL_0426: Unknown result type (might be due to invalid IL or missing references) //IL_043a: Unknown result type (might be due to invalid IL or missing references) //IL_045d: Unknown result type (might be due to invalid IL or missing references) //IL_0471: Unknown result type (might be due to invalid IL or missing references) //IL_0476: Unknown result type (might be due to invalid IL or missing references) //IL_0499: Unknown result type (might be due to invalid IL or missing references) //IL_04ad: Unknown result type (might be due to invalid IL or missing references) //IL_04b2: Unknown result type (might be due to invalid IL or missing references) //IL_04c8: Unknown result type (might be due to invalid IL or missing references) //IL_04cd: Unknown result type (might be due to invalid IL or missing references) //IL_04ce: Unknown result type (might be due to invalid IL or missing references) //IL_04d0: Unknown result type (might be due to invalid IL or missing references) //IL_04d5: Unknown result type (might be due to invalid IL or missing references) //IL_04d7: Unknown result type (might be due to invalid IL or missing references) //IL_04ec: Unknown result type (might be due to invalid IL or missing references) //IL_04f1: Unknown result type (might be due to invalid IL or missing references) //IL_0506: Unknown result type (might be due to invalid IL or missing references) //IL_050b: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("DoorSwitchVisual"); val.transform.SetParent(prefab.transform, false); val.layer = prefab.layer; Material material = CreateMaterial(sourceMaterial, new Color(0.58f, 0.32f, 0.12f), 0f, Color.black); switch (style) { case SwitchVisualStyle.Bookshelf: BuildBookshelf(val.transform, controller, sourceMaterial); break; case SwitchVisualStyle.IronButton: { material = CreateMaterial(sourceMaterial, new Color(0.48f, 0.52f, 0.56f), 0.75f, Color.black); Material material2 = CreateMaterial(sourceMaterial, new Color(0.95f, 0.07f, 0.025f), 0.35f, new Color(1.4f, 0.06f, 0.015f)); CreatePrimitive((PrimitiveType)3, "Plate", val.transform, new Vector3(0f, 0f, 0f), new Vector3(0.38f, 0.42f, 0.09f), Vector3.zero, material); controller.Actuator = CreatePrimitive((PrimitiveType)2, "Actuator", val.transform, new Vector3(0f, 0f, 0.1f), new Vector3(0.12f, 0.055f, 0.12f), new Vector3(90f, 0f, 0f), material2).transform; controller.ReleasedPosition = controller.Actuator.localPosition; controller.ActivePosition = new Vector3(0f, 0f, 0.065f); controller.ReleasedRotation = (controller.ActiveRotation = controller.Actuator.localEulerAngles); break; } case SwitchVisualStyle.RuneSwitch: { material = CreateMaterial(sourceMaterial, new Color(0.42f, 0.44f, 0.46f), 0.05f, Color.black); Material material2 = CreateMaterial(sourceMaterial, new Color(0.02f, 0.82f, 1f), 0.1f, new Color(0.04f, 1.6f, 2.8f)); CreatePrimitive((PrimitiveType)3, "Stone", val.transform, Vector3.zero, new Vector3(0.4f, 0.46f, 0.1f), Vector3.zero, material); Transform transform2 = new GameObject("Actuator").transform; transform2.SetParent(val.transform, false); CreatePrimitive((PrimitiveType)3, "RuneVertical", transform2, new Vector3(0f, 0f, 0.064f), new Vector3(0.045f, 0.27f, 0.025f), new Vector3(0f, 0f, 18f), material2); CreatePrimitive((PrimitiveType)3, "RuneBranchTop", transform2, new Vector3(0.055f, 0.07f, 0.064f), new Vector3(0.035f, 0.15f, 0.025f), new Vector3(0f, 0f, -42f), material2); CreatePrimitive((PrimitiveType)3, "RuneBranchBottom", transform2, new Vector3(0.055f, -0.07f, 0.064f), new Vector3(0.035f, 0.15f, 0.025f), new Vector3(0f, 0f, 42f), material2); controller.Actuator = transform2; controller.ReleasedPosition = Vector3.zero; controller.ActivePosition = new Vector3(0f, 0f, -0.018f); controller.ReleasedRotation = (controller.ActiveRotation = Vector3.zero); break; } default: { Material material2 = CreateMaterial(sourceMaterial, new Color(0.92f, 0.56f, 0.13f), 0.35f, new Color(0.18f, 0.07f, 0.01f)); CreatePrimitive((PrimitiveType)3, "Plate", val.transform, Vector3.zero, new Vector3(0.34f, 0.42f, 0.09f), Vector3.zero, material); Transform transform = new GameObject("Actuator").transform; transform.SetParent(val.transform, false); CreatePrimitive((PrimitiveType)2, "Pivot", transform, new Vector3(0f, 0f, 0.075f), new Vector3(0.09f, 0.045f, 0.09f), new Vector3(90f, 0f, 0f), material2); CreatePrimitive((PrimitiveType)3, "Handle", transform, new Vector3(0f, 0.13f, 0.12f), new Vector3(0.055f, 0.28f, 0.055f), Vector3.zero, material2); CreatePrimitive((PrimitiveType)0, "Knob", transform, new Vector3(0f, 0.27f, 0.12f), new Vector3(0.11f, 0.11f, 0.11f), Vector3.zero, material2); controller.Actuator = transform; controller.ReleasedPosition = (controller.ActivePosition = Vector3.zero); controller.ReleasedRotation = new Vector3(0f, 0f, -25f); controller.ActiveRotation = new Vector3(0f, 0f, 25f); break; } } } private static void BuildBookshelf(Transform root, DoorSwitchController controller, Material sourceMaterial) { //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_0200: 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_0272: Unknown result type (might be due to invalid IL or missing references) //IL_02ab: Unknown result type (might be due to invalid IL or missing references) //IL_02e4: Unknown result type (might be due to invalid IL or missing references) //IL_031d: Unknown result type (might be due to invalid IL or missing references) //IL_035c: Unknown result type (might be due to invalid IL or missing references) //IL_03a1: Unknown result type (might be due to invalid IL or missing references) //IL_03a6: Unknown result type (might be due to invalid IL or missing references) //IL_03ad: Unknown result type (might be due to invalid IL or missing references) //IL_03c4: Unknown result type (might be due to invalid IL or missing references) //IL_03c9: Unknown result type (might be due to invalid IL or missing references) //IL_03ce: Unknown result type (might be due to invalid IL or missing references) //IL_03da: Unknown result type (might be due to invalid IL or missing references) //IL_03df: Unknown result type (might be due to invalid IL or missing references) //IL_03f4: Unknown result type (might be due to invalid IL or missing references) //IL_03f9: Unknown result type (might be due to invalid IL or missing references) //IL_0413: Unknown result type (might be due to invalid IL or missing references) //IL_041f: Unknown result type (might be due to invalid IL or missing references) //IL_0435: Unknown result type (might be due to invalid IL or missing references) //IL_044b: Unknown result type (might be due to invalid IL or missing references) //IL_0462: Unknown result type (might be due to invalid IL or missing references) GameObject val = CreateVanillaVisual("dvergrprops_shelf", root, "VanillaShelf"); if ((Object)(object)val == (Object)null || !NormalizeVisual(val.transform, root, 1.08f, 1.34f, out var bounds)) { if ((Object)(object)val != (Object)null) { Object.DestroyImmediate((Object)(object)val); val = null; } bounds = BuildFallbackBookshelfFrame(root, sourceMaterial); } object source = (((Object)(object)val == (Object)null) ? ((object)sourceMaterial) : ((object)((from renderer in val.GetComponentsInChildren<Renderer>(true) select renderer.sharedMaterial).FirstOrDefault((Func<Material, bool>)((Material material) => (Object)(object)material != (Object)null)) ?? sourceMaterial))); Material pageMaterial = CreateTexturedMaterial((Material)source, new Color(0.68f, 0.6f, 0.43f)); Material coverMaterial = CreateTexturedMaterial((Material)source, new Color(0.38f, 0.075f, 0.045f)); Material coverMaterial2 = CreateTexturedMaterial((Material)source, new Color(0.1f, 0.17f, 0.2f)); Material coverMaterial3 = CreateTexturedMaterial((Material)source, new Color(0.14f, 0.22f, 0.14f)); Material coverMaterial4 = CreateTexturedMaterial((Material)source, new Color(0.3f, 0.19f, 0.09f)); float x = ((Bounds)(ref bounds)).size.x; float y = ((Bounds)(ref bounds)).size.y; float num = Mathf.Clamp(y * 0.17f, 0.19f, 0.25f); float num2 = Mathf.Clamp(x * 0.085f, 0.075f, 0.105f); float num3 = Mathf.Clamp(((Bounds)(ref bounds)).size.z * 0.46f, 0.1f, 0.15f); float z = ((Bounds)(ref bounds)).max.z - num3 * 0.5f; float shelfSurface = ((Bounds)(ref bounds)).min.y + y * 0.59f + 0.06f; float shelfSurface2 = ((Bounds)(ref bounds)).min.y + y * 0.24f + 0.06f; CreateBookOnShelf(root, "UpperBlue", ((Bounds)(ref bounds)).center.x - x * 0.25f, shelfSurface, z, num2, num * 0.92f, num3, coverMaterial2, pageMaterial, 2f); CreateBookOnShelf(root, "UpperBrown", ((Bounds)(ref bounds)).center.x - x * 0.15f, shelfSurface, z, num2 * 0.85f, num, num3, coverMaterial4, pageMaterial, -2f); CreateBookOnShelf(root, "UpperGreen", ((Bounds)(ref bounds)).center.x + x * 0.22f, shelfSurface, z, num2, num * 0.94f, num3, coverMaterial3, pageMaterial, 3f); CreateBookOnShelf(root, "LowerBrown", ((Bounds)(ref bounds)).center.x - x * 0.2f, shelfSurface2, z, num2 * 1.1f, num, num3, coverMaterial4, pageMaterial, -2f); CreateBookOnShelf(root, "LowerBlue", ((Bounds)(ref bounds)).center.x - x * 0.09f, shelfSurface2, z, num2, num * 0.9f, num3, coverMaterial2, pageMaterial, 1f); CreateBookOnShelf(root, "LowerGreen", ((Bounds)(ref bounds)).center.x + x * 0.24f, shelfSurface2, z, num2 * 0.9f, num * 0.96f, num3, coverMaterial3, pageMaterial, -1f); GameObject val2 = CreateBookOnShelf(root, "SecretBook", ((Bounds)(ref bounds)).center.x + x * 0.02f, shelfSurface, z, num2 * 1.15f, num, num3, coverMaterial, pageMaterial, 0f); controller.Actuator = val2.transform; controller.ReleasedPosition = controller.Actuator.localPosition; controller.ActivePosition = controller.ReleasedPosition + new Vector3(0f, -0.015f, num3 * 0.82f); controller.ReleasedRotation = controller.Actuator.localEulerAngles; controller.ActiveRotation = new Vector3(-20f, 0f, 0f); controller.PulseOnActivation = true; BoxCollider obj = ((Component)root).gameObject.AddComponent<BoxCollider>(); obj.center = ((Bounds)(ref bounds)).center; obj.size = new Vector3(Mathf.Max(((Bounds)(ref bounds)).size.x, 0.8f), Mathf.Max(((Bounds)(ref bounds)).size.y, 1f), Mathf.Max(((Bounds)(ref bounds)).size.z + num3, 0.3f)); } private static Bounds BuildFallbackBookshelfFrame(Transform root, Material sourceMaterial) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001a: 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) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: 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_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Unknown result type (might be due to invalid IL or missing references) //IL_01fb: Unknown result type (might be due to invalid IL or missing references) //IL_0200: Unknown result type (might be due to invalid IL or missing references) //IL_021b: Unknown result type (might be due to invalid IL or missing references) //IL_022f: Unknown result type (might be due to invalid IL or missing references) //IL_0234: Unknown result type (might be due to invalid IL or missing references) Material material = CreateMaterial(sourceMaterial, new Color(0.24f, 0.105f, 0.035f), 0f, Color.black); Material material2 = CreateMaterial(sourceMaterial, new Color(0.48f, 0.235f, 0.075f), 0f, Color.black); Material material3 = CreateMaterial(sourceMaterial, new Color(0.68f, 0.385f, 0.13f), 0f, Color.black); CreatePrimitive((PrimitiveType)3, "Back", root, new Vector3(0f, 0f, 0.02f), new Vector3(0.96f, 1.24f, 0.08f), Vector3.zero, material); CreatePrimitive((PrimitiveType)3, "LeftFrame", root, new Vector3(-0.49f, 0f, 0.12f), new Vector3(0.1f, 1.34f, 0.23f), Vector3.zero, material2); CreatePrimitive((PrimitiveType)3, "RightFrame", root, new Vector3(0.49f, 0f, 0.12f), new Vector3(0.1f, 1.34f, 0.23f), Vector3.zero, material2); CreatePrimitive((PrimitiveType)3, "TopFrame", root, new Vector3(0f, 0.64f, 0.12f), new Vector3(1.08f, 0.1f, 0.23f), Vector3.zero, material3); CreatePrimitive((PrimitiveType)3, "BottomFrame", root, new Vector3(0f, -0.64f, 0.12f), new Vector3(1.08f, 0.1f, 0.23f), Vector3.zero, material2); CreatePrimitive((PrimitiveType)3, "UpperShelf", root, new Vector3(0f, 0.21f, 0.13f), new Vector3(0.96f, 0.075f, 0.25f), Vector3.zero, material3); CreatePrimitive((PrimitiveType)3, "LowerShelf", root, new Vector3(0f, -0.23f, 0.13f), new Vector3(0.96f, 0.075f, 0.25f), Vector3.zero, material3); return new Bounds(new Vector3(0f, 0f, 0.12f), new Vector3(1.08f, 1.34f, 0.25f)); } private static GameObject CreateBookOnShelf(Transform parent, string name, float x, float shelfSurface, float z, float width, float height, float depth, Material coverMaterial, Material pageMaterial, float rotation) { return CreateBook(parent, name, x, shelfSurface + height * 0.5f, z, width, height, depth, coverMaterial, pageMaterial, rotation); } private static GameObject CreateBook(Transform parent, string name, float x, float y, float z, float width, float height, float depth, Material coverMaterial, Material pageMaterial, float rotation) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_007e: 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_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name); val.transform.SetParent(parent, false); val.transform.localPosition = new Vector3(x, y, z); val.transform.localEulerAngles = new Vector3(0f, 0f, rotation); val.layer = ((Component)parent).gameObject.layer; CreatePrimitive((PrimitiveType)3, "Pages", val.transform, Vector3.zero, new Vector3(width * 0.82f, height * 0.91f, depth * 0.82f), Vector3.zero, pageMaterial); CreatePrimitive((PrimitiveType)3, "FrontCover", val.transform, new Vector3(0f, 0f, depth * 0.45f), new Vector3(width, height, depth * 0.08f), Vector3.zero, coverMaterial); CreatePrimitive((PrimitiveType)3, "BackCover", val.transform, new Vector3(0f, 0f, (0f - depth) * 0.45f), new Vector3(width, height, depth * 0.08f), Vector3.zero, coverMaterial); CreatePrimitive((PrimitiveType)3, "Spine", val.transform, new Vector3((0f - width) * 0.46f, 0f, 0f), new Vector3(width * 0.08f, height, depth), Vector3.zero, coverMaterial); return val; } private static GameObject CreateVanillaVisual(string prefabName, Transform parent, string name) { //IL_004d: 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_006d: Unknown result type (might be due to invalid IL or missing references) GameObject prefab = PrefabManager.Instance.GetPrefab(prefabName); if ((Object)(object)prefab == (Object)null) { Logger.LogWarning((object)("Vanilla visual prefab '" + prefabName + "' was not found; using the fallback bookshelf.")); return null; } GameObject val = Object.Instantiate<GameObject>(prefab); ((Object)val).name = name; val.transform.SetParent(parent, false); val.transform.localPosition = Vector3.zero; val.transform.localRotation = Quaternion.identity; val.transform.localScale = Vector3.one; Component[] componentsInChildren = val.GetComponentsInChildren<Component>(true); foreach (Component val2 in componentsInChildren) { if (!(val2 is Transform) && !(val2 is MeshFilter) && !(val2 is MeshRenderer) && !(val2 is SkinnedMeshRenderer)) { Object.DestroyImmediate((Object)(object)val2); } } SetLayerRecursively(val.transform, ((Component)parent).gameObject.layer); val.SetActive(true); return val; } private static void SetLayerRecursively(Transform transform, int layer) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown ((Component)transform).gameObject.layer = layer; foreach (Transform item in transform) { SetLayerRecursively(item, layer); } } private static bool NormalizeVisual(Transform visual, Transform relativeTo, float targetWidth, float targetHeight, out Bounds bounds) { //IL_000d: 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_0036: 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_0057: 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_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) if (!TryGetLocalMeshBounds(visual, relativeTo, out bounds) || ((Bounds)(ref bounds)).size.x <= 0f || ((Bounds)(ref bounds)).size.y <= 0f) { return false; } float num = Mathf.Min(targetWidth / ((Bounds)(ref bounds)).size.x, targetHeight / ((Bounds)(ref bounds)).size.y); visual.localScale *= num; if (!TryGetLocalMeshBounds(visual, relativeTo, out bounds)) { return false; } visual.localPosition += new Vector3(0f - ((Bounds)(ref bounds)).center.x, 0f - ((Bounds)(ref bounds)).center.y, 0.015f - ((Bounds)(ref bounds)).min.z); return TryGetLocalMeshBounds(visual, relativeTo, out bounds); } private static bool TryGetLocalMeshBounds(Transform visual, Transform relativeTo, out Bounds bounds) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //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_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: 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_0059: 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_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) bounds = default(Bounds); bool flag = false; MeshFilter[] componentsInChildren = ((Component)visual).GetComponentsInChildren<MeshFilter>(true); foreach (MeshFilter val in componentsInChildren) { Mesh sharedMesh = val.sharedMesh; if ((Object)(object)sharedMesh == (Object)null) { continue; } Matrix4x4 val2 = relativeTo.worldToLocalMatrix * ((Component)val).transform.localToWorldMatrix; Bounds bounds2 = sharedMesh.bounds; Vector3 min = ((Bounds)(ref bounds2)).min; Vector3 max = ((Bounds)(ref bounds2)).max; for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { for (int l = 0; l < 2; l++) { Vector3 val3 = ((Matrix4x4)(ref val2)).MultiplyPoint3x4(new Vector3((j == 0) ? min.x : max.x, (k == 0) ? min.y : max.y, (l == 0) ? min.z : max.z)); if (!flag) { bounds = new Bounds(val3, Vector3.zero); flag = true; } else { ((Bounds)(ref bounds)).Encapsulate(val3); } } } } } return flag; } private static GameObject CreatePrimitive(PrimitiveType type, string name, Transform parent, Vector3 position, Vector3 scale, Vector3 rotation, Material material) { //IL_0000: 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_002c: 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) GameObject obj = GameObject.CreatePrimitive(type); ((Object)obj).name = name; obj.transform.SetParent(parent, false); obj.transform.localPosition = position; obj.transform.localScale = scale; obj.transform.localEulerAngles = rotation; obj.layer = ((Component)parent).gameObject.layer; Collider component = obj.GetComponent<Collider>(); if ((Object)(object)component != (Object)null) { Object.DestroyImmediate((Object)(object)component); } obj.GetComponent<Renderer>().sharedMaterial = material; return obj; } private static Material CreateMaterial(Material source, Color color, float metallic, Color emission) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown //IL_0068: 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_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: 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) if ((Object)(object)source == (Object)null) { throw new InvalidOperationException("No source material was available for the switch visual."); } Material val = new Material(source); if (val.HasProperty("_MainTex")) { val.SetTexture("_MainTex", (Texture)(object)Texture2D.whiteTexture); } if (val.HasProperty("_BaseMap")) { val.SetTexture("_BaseMap", (Texture)(object)Texture2D.whiteTexture); } if (val.HasProperty("_Color")) { val.SetColor("_Color", color); } if (val.HasProperty("_BaseColor")) { val.SetColor("_BaseColor", color); } if (val.HasProperty("_Metallic")) { val.SetFloat("_Metallic", metallic); } if (emission != Color.black) { val.EnableKeyword("_EMISSION"); if (val.HasProperty("_EmissionColor")) { val.SetColor("_EmissionColor", emission); } if (val.HasProperty("_EmissiveColor")) { val.SetColor("_EmissiveColor", emission); } } return val; } private static Material CreateTexturedMaterial(Material source, Color tint) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown //IL_002e: 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_007d: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)source == (Object)null) { throw new InvalidOperationException("No source material was available for the bookshelf visual."); } Material val = new Material(source); if (val.HasProperty("_Color")) { val.SetColor("_Color", tint); } if (val.HasProperty("_BaseColor")) { val.SetColor("_BaseColor", tint); } if (val.HasProperty("_Metallic")) { val.SetFloat("_Metallic", 0f); } if (val.HasProperty("_EmissionColor")) { val.SetColor("_EmissionColor", Color.black); } if (val.HasProperty("_EmissiveColor")) { val.SetColor("_EmissiveColor", Color.black); } val.DisableKeyword("_EMISSION"); return val; } } internal enum SwitchVisualStyle { WoodLever, IronButton, RuneSwitch, Bookshelf } internal static class SwitchRpc { private enum Command : byte { Activate, ToggleLink, ClearLinks, CycleMode, Result, OperateTargets, ToggleDirectInteraction } private static CustomRPC rpc; internal static void Initialize() { //IL_0011: 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_0027: Expected O, but got Unknown //IL_0027: Expected O, but got Unknown rpc = NetworkManager.Instance.AddRPC("DoorSwitch", new CoroutineHandler(OnServerReceive), new CoroutineHandler(OnClientReceive)); } internal static void RequestActivate(ZDOID switchId) { //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) SendToServer(Command.Activate, delegate(ZPackage package) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) package.Write(switchId); }); } internal static void RequestToggleLink(ZDOID switchId, ZDOID targetId) { //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) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) SendToServer(Command.ToggleLink, delegate(ZPackage package) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) package.Write(switchId); package.Write(targetId); }); } internal static void RequestClearLinks(ZDOID switchId) { //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) SendToServer(Command.ClearLinks, delegate(ZPackage package) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) package.Write(switchId); }); } internal static void RequestCycleMode(ZDOID switchId) { //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) SendToServer(Command.CycleMode, delegate(ZPackage package) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) package.Write(switchId); }); } internal static void RequestToggleDirectInteraction(ZDOID switchId, ZDOID targetId) { //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) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) SendToServer(Command.ToggleDirectInteraction, delegate(ZPackage package) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) package.Write(switchId); package.Write(targetId); }); } private static void SendToServer(Command command, Action<ZPackage> writePayload) { //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Expected O, but got Unknown if (rpc == null || (Object)(object)ZNet.instance == (Object)null) { LinkingSession.ShowMessage("The network is not ready"); return; } long num; if (ZNet.instance.IsServer()) { num = ZNet.GetUID(); } else { ZNetPeer serverPeer = ZNet.instance.GetServerPeer(); if (serverPeer == null) { LinkingSession.ShowMessage("The server connection is not ready"); return; } num = serverPeer.m_uid; } ZPackage val = new ZPackage(); val.Write((byte)command); writePayload(val); rpc.SendPackage(num, val); } private static IEnumerator OnServerReceive(long sender, ZPackage package) { switch ((Command)package.ReadByte()) { case Command.Activate: OnActivate(sender, package.ReadZDOID()); break; case Command.ToggleLink: OnToggleLink(sender, package.ReadZDOID(), package.ReadZDOID()); break; case Command.ClearLinks: OnClearLinks(sender, package.ReadZDOID()); break; case Command.CycleMode: OnCycleMode(sender, package.ReadZDOID()); break; case Command.Result: OnResult(package.ReadString()); break; case Command.OperateTargets: if (sender == ZNet.GetUID()) { OnOperateTargets(package); } break; case Command.ToggleDirectInteraction: OnToggleDirectInteraction(sender, package.ReadZDOID(), package.ReadZDOID()); break; } yield break; } private static IEnumerator OnClientReceive(long sender, ZPackage package) { ZNet instance = ZNet.instance; ZNetPeer val = ((instance != null) ? instance.GetServerPeer() : null); if (val != null && sender == val.m_uid) { switch ((Command)package.ReadByte()) { case Command.Result: OnResult(package.ReadString()); break; case Command.OperateTargets: OnOperateTargets(package); break; } } yield break; } private static void OnActivate(long sender, ZDOID switchId) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) if (TryGetServerSwitch(sender, switchId, out var switchZdo)) { List<ZDOID> list = SwitchData.ReadLinks(switchZdo); if (list.Count == 0) { Reply(sender, SwitchData.HasLegacyLinks(switchZdo) ? "Old links need a one-time relink after this update" : ((SwitchData.LinkCount(switchZdo) > 0) ? "Linked doors are unavailable; links have been preserved" : "This switch has no linked doors")); return; } List<ZDO> resolvedTargets = GetResolvedTargets(list); SwitchMode switchMode = SwitchData.ReadMode(switchZdo); bool flag = (byte)(((switchMode != SwitchMode.Close) ? 1u : 0u) & (uint)(switchMode switch { SwitchMode.Toggle => ((resolvedTargets.Count > 0) ? resolvedTargets.Any((ZDO target) => target.GetInt(ZDOVars.s_state, 0) == 0) : (!switchZdo.GetBool("doorswitch_last_state", false))) ? 1 : 0, SwitchMode.Open => 1, _ => 0, })) != 0; SendOperation(sender, switchId, flag, list); switchZdo.Set("doorswitch_last_state", flag); switchZdo.Set("doorswitch_activation", switchZdo.GetInt("doorswitch_activation", 0) + 1); } } private static void OnToggleLink(long sender, ZDOID switchId, ZDOID targetId) { //IL_0001: 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_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003a: 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_00ed: Unknown result type (might be due to invalid IL or missing references) if (!TryGetServerSwitch(sender, switchId, out var switchZdo)) { return; } ZDOMan instance = ZDOMan.instance; ZDO val = ((instance != null) ? instance.GetZDO(targetId) : null); if (!IsDoorTarget(val)) { Reply(sender, "That object is not a supported door, gate, or drawbridge"); return; } float num = Vector3.Distance(switchZdo.GetPosition(), val.GetPosition()); if (num > DoorSwitchPlugin.MaximumLinkDistance.Value) { Reply(sender, $"Target is too far away ({num:0} m; limit {DoorSwitchPlugin.MaximumLinkDistance.Value:0} m)"); } else if (SwitchData.ContainsLink(switchZdo, val)) { SwitchData.RemoveLink(switchZdo, val); DoorInteractionGuard.RemoveController(val, switchId); Reply(sender, $"Target unlinked ({SwitchData.LinkCount(switchZdo)} remaining)"); } else if (!SwitchData.HasLegacyLinks(switchZdo) && SwitchData.LinkCount(switchZdo) >= DoorSwitchPlugin.MaximumLinks.Value) { Reply(sender, $"This switch already has the maximum of {DoorSwitchPlugin.MaximumLinks.Value} links"); } else { SwitchData.AddLink(switchZdo, val); DoorInteractionGuard.AddController(val, switchId); Reply(sender, $"Target linked ({SwitchData.LinkCount(switchZdo)} total)"); } } private static void OnClearLinks(long sender, ZDOID switchId) { //IL_0001: 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) //IL_0021: 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_0034: Unknown result type (might be due to invalid IL or missing references) if (!TryGetServerSwitch(sender, switchId, out var switchZdo)) { return; } foreach (ZDOID item in SwitchData.ReadLinks(switchZdo)) { ZDOMan instance = ZDOMan.instance; DoorInteractionGuard.RemoveController((instance != null) ? instance.GetZDO(item) : null, switchId); } SwitchData.ClearLinks(switchZdo); Reply(sender, "All links removed"); } private static void OnToggleDirectInteraction(long sender, ZDOID switchId, ZDOID targetId) { //IL_0001: 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_0049: Unknown result type (might be due to invalid IL or missing references) if (TryGetServerSwitch(sender, switchId, out var switchZdo)) { ZDOMan instance = ZDOMan.instance; ZDO val = ((instance != null) ? instance.GetZDO(targetId) : null); if (!IsDoorTarget(val)) { Reply(sender, "That object is not a supported door, gate, or drawbridge"); return; } if (!SwitchData.ContainsLink(switchZdo, val)) { Reply(sender, "Link this door before changing its direct interaction"); return; } DoorInteractionGuard.AddController(val, switchId); bool flag = !SwitchData.IsDirectInteractionDisabled(val); SwitchData.SetDirectInteractionDisabled(val, flag); Reply(sender, flag ? "Direct interaction disabled for this door" : "Direct interaction enabled for this door"); } } private static void OnCycleMode(long sender, ZDOID switchId) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) if (TryGetServerSwitch(sender, switchId, out var switchZdo)) { SwitchMode switchMode = (SwitchMode)((int)(SwitchData.ReadMode(switchZdo) + 1) % 3); switchZdo.Set("doorswitch_mode", (int)switchMode); Reply(sender, "Switch mode: " + SwitchData.GetModeName(switchMode)); } } private static bool TryGetServerSwitch(long sender, ZDOID switchId, out ZDO switchZdo) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) switchZdo = null; if ((Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer() || ZDOMan.instance == null) { return false; } switchZdo = ZDOMan.instance.GetZDO(switchId); if (switchZdo == null || !SwitchPieceFactory.IsSwitchPrefab(switchZdo.GetPrefab())) { Reply(sender, "The selected switch no longer exists"); switchZdo = null; return false; } return true; } private static List<ZDO> GetResolvedTargets(IEnumerable<ZDOID> links) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: 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) List<ZDO> list = new List<ZDO>(); foreach (ZDOID link in links) { ZDOMan instance = ZDOMan.instance; ZDO val = ((instance != null) ? instance.GetZDO(link) : null); if (IsDoorTarget(val)) { list.Add(val); } } return list; } private static bool IsDoorTarget(ZDO target) { return DoorTargets.IsSupported(target); } private static void SendOperation(long peerId, ZDOID sourceSwitch, bool desiredOpen, List<ZDOID> targetIds) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_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) ZPackage val = new ZPackage(); val.Write((byte)5); val.Write(sourceSwitch); val.Write(desiredOpen); val.Write(targetIds.Count); foreach (ZDOID targetId in targetIds) { val.Write(targetId); } rpc.SendPackage(peerId, val); } private static void OnOperateTargets(ZPackage package) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: 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_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_010e: 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_0148: Unknown result type (might be due to invalid IL or missing references) ZDOID val = package.ReadZDOID(); bool flag = package.ReadBool(); int num = Mathf.Clamp(package.ReadInt(), 0, 256); int num2 = 0; int num3 = 0; int num4 = 0; List<string> list = new List<string>(); Humanoid localPlayer = (Humanoid)(object)Player.m_localPlayer; Dictionary<ZDOID, Door> dictionary = null; List<ZDOID> list2 = new List<ZDOID>(); for (int i = 0; i < num; i++) { ZDOID val2 = package.ReadZDOID(); ZNetScene instance = ZNetScene.instance; GameObject val3 = ((instance != null) ? instance.FindInstance(val2) : null); Door value = (((Object)(object)val3 != (Object)null) ? val3.GetComponentInChildren<Door>(true) : null); if ((Object)(object)value == (Object)null) { if (dictionary == null) { dictionary = GetLoadedDoorLookup(); } dictionary.TryGetValue(val2, out value); } ZNetView val4 = (((Object)(object)value != (Object)null) ? ((Component)value).GetComponentInParent<ZNetView>() : null); if ((Object)(object)value == (Object)null || (Object)(object)val4 == (Object)null || !val4.IsValid() || (Object)(object)localPlayer == (Object)null) { list2.Add(val2); continue; } num2++; if (val4.GetZDO().GetInt(ZDOVars.s_state, 0) != 0 == flag) { continue; } num3++; if (LinkingSession.InteractWithoutLinking(value, localPlayer, val, flag, out var failure)) { num4++; continue; } if (failure == null) { failure = "Linked door interaction was denied or unavailable"; } list.Add(failure); Logger.LogWarning((object)($"Linked interaction rejected: switch={val}; door={val2}; " + "component=" + ((object)value).GetType().FullName + "; reason=" + failure)); } if (num2 == 0) { Logger.LogWarning((object)($"Could not resolve {list2.Count} linked door(s) locally; " + $"scanned {dictionary?.Count ?? 0} loaded networked Door component(s). " + "Unresolved IDs: " + string.Join(", ", list2))); OnResult("Linked doors are not loaded; move closer and try again"); } else if (num4 > 0) { string text = string.Format("Requested {0} of {1} linked target{2}", flag ? "opening" : "closing", num4, (num4 == 1) ? string.Empty : "s"); OnResult((list.Count > 0) ? (text + $"; {list.Count} rejected: {list[0]}") : text); } else if (num3 == 0) { OnResult("All loaded linked targets are already " + (flag ? "open" : "closed")); } else { OnResult((list.Count > 0) ? list[0] : "Linked door interaction was denied or unavailable"); } } private static Dictionary<ZDOID, Door> GetLoadedDoorLookup() { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) Dictionary<ZDOID, Door> dictionary = new Dictionary<ZDOID, Door>(); Door[] array = Resources.FindObjectsOfTypeAll<Door>(); foreach (Door val in array) { if (!((Object)(object)val == (Object)null)) { ZNetView componentInParent = ((Component)val).GetComponentInParent<ZNetView>(); ZDO val2 = (((Object)(object)componentInParent != (Object)null && componentInParent.IsValid()) ? componentInParent.GetZDO() : null); if (val2 != null && !dictionary.ContainsKey(val2.m_uid)) { dictionary.Add(val2.m_uid, val); } } } return dictionary; } private static void Reply(long peerId, string message) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Expected O, but got Unknown if (rpc != null) { ZPackage val = new ZPackage(); val.Write((byte)4); val.Write(message); rpc.SendPackage(peerId, val); } } private static void OnResult(string message) { LinkingSession.ShowMessage(message); } }