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 PlayerTeleportScroll v1.2.0
PlayerTeleportScroll/PlayerTeleportScroll.dll
Decompiled 2 weeks agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.Rendering; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("PlayerTeleportScroll")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("PlayerTeleportScroll")] [assembly: AssemblyTitle("PlayerTeleportScroll")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace PlayerTeleportScroll { [BepInPlugin("paradaj.playerteleportscroll", "PlayerTeleportScroll", "1.0.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public const string ModGuid = "paradaj.playerteleportscroll"; public const string ModName = "PlayerTeleportScroll"; public const string ModVersion = "1.0.1"; public const string PrefabName = "TeleportScroll_KP"; private const string BasePrefab = "Thunderstone"; private const string RpcRequest = "KP_TPScroll_Request"; private const string RpcReply = "KP_TPScroll_Reply"; private const string RpcServerPing = "KP_TPScroll_ServerPing"; private const string RpcServerPong = "KP_TPScroll_ServerPong"; internal static Plugin Instance; private ConfigEntry<bool> _cfgCraftable; internal ConfigEntry<bool> CfgSoldByTrader; internal ConfigEntry<string> CfgTraders; internal ConfigEntry<int> CfgPrice; internal ConfigEntry<int> CfgTraderStack; internal ConfigEntry<string> CfgRequiredKey; private ConfigEntry<string> _cfgRecipe; private ConfigEntry<string> _cfgStation; private ConfigEntry<int> _cfgStationLevel; private ConfigEntry<float> _cfgCooldown; private ConfigEntry<float> _cfgChannelTime; private ConfigEntry<float> _cfgReplyTimeout; private ConfigEntry<bool> _cfgNotifyTarget; private ConfigEntry<bool> _cfgTestFakePlayer; private bool _menuOpen; private Vector2 _scrollPos; private Rect _windowRect = new Rect(0f, 0f, 340f, 420f); private float _lastUse = -100000f; private bool _busy; private bool _channeling; private long _pendingTarget; private string _pendingName; private int _requestId; private bool _serverHasMod; private bool _serverCheckDone; private int _serverPingToken; private readonly Harmony _harmony = new Harmony("paradaj.playerteleportscroll"); private CustomLocalization _loc; private static Texture2D _scrollTexture; internal bool ServerOffersScroll { get { if (!((Object)(object)ZNet.instance != (Object)null) || !ZNet.instance.IsServer()) { return _serverHasMod; } return true; } } private void Awake() { Instance = this; AddLocalizations(); CfgSoldByTrader = Synced("Trader", "SoldByTrader", value: true, "Czy handlarz sprzedaje zwój."); CfgTraders = Synced("Trader", "Traders", "Haldor", "Którzy handlarze sprzedają zwój (nazwy oddzielone przecinkami): Haldor, Hildir, BogWitch."); CfgPrice = Synced("Trader", "Price", 150, "Cena w monetach."); CfgTraderStack = Synced("Trader", "StackSize", 1, "Ile zwojów dostajesz za jeden zakup."); CfgRequiredKey = Synced("Trader", "RequiredGlobalKey", "", "Klucz świata wymagany, by zwój był w sklepie (pusto = zawsze). Np. defeated_eikthyr, defeated_gdking, defeated_bonemass."); _cfgCraftable = Synced("Recipe", "Craftable", value: false, "Czy zwój można też craftować."); _cfgRecipe = Synced("Recipe", "Requirements", "Coins:50,GreydwarfEye:5,Resin:5", "Koszt zwoju: Prefab:ilosc oddzielone przecinkami."); _cfgStation = Synced("Recipe", "CraftingStation", "piece_workbench", "Stol do craftu (prefab), np. piece_workbench, forge, piece_artisanstation."); _cfgStationLevel = Synced("Recipe", "StationLevel", 2, "Wymagany poziom stolu."); _cfgCooldown = Synced("General", "CooldownSeconds", 300f, "Czas odnowienia zwoju (sekundy)."); _cfgChannelTime = Synced("General", "ChannelSeconds", 3f, "Ile sekund trwa czytanie zwoju przed teleportem."); _cfgReplyTimeout = Synced("General", "ReplyTimeoutSeconds", 10f, "Ile czekac na odpowiedz od gracza docelowego."); _cfgNotifyTarget = Synced("General", "NotifyTarget", value: true, "Pokaz graczowi docelowemu komunikat, ze ktos sie do niego teleportuje."); _cfgTestFakePlayer = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "TestFakePlayer", false, "Tylko na tym komputerze, nie idzie na serwer. Dodaje Testowego gracza, który przenosi 8 m do przodu."); PrefabManager.OnVanillaPrefabsAvailable += AddScrollItem; ItemManager.OnItemsRegistered += ApplyRecipe; SynchronizationManager.OnConfigurationSynchronized += delegate { ApplyRecipe(); }; ((BaseUnityPlugin)this).Config.SettingChanged += delegate { ApplyRecipe(); }; _harmony.PatchAll(); } private ConfigEntry<T> Synced<T>(string section, string key, T value, string description) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown return ((BaseUnityPlugin)this).Config.Bind<T>(section, key, value, new ConfigDescription(description, (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); } private void OnDestroy() { _harmony.UnpatchSelf(); } private void AddLocalizations() { _loc = LocalizationManager.Instance.GetLocalization(); CustomLocalization loc = _loc; string text = "English"; loc.AddTranslation(ref text, new Dictionary<string, string> { { "item_teleportscroll_kp", "Teleport Scroll" }, { "item_teleportscroll_kp_desc", "Use it to teleport to a chosen player." }, { "kp_tps_busy", "You are already reading a scroll..." }, { "kp_tps_cooldown", "The scroll will be ready in {0} s" }, { "kp_tps_noteleport", "You are carrying items that cannot be teleported" }, { "kp_tps_searching", "Looking for {0}..." }, { "kp_tps_noreply", "{0} is not responding (do they have this mod installed?)" }, { "kp_tps_channel", "Teleporting to {0} in {1} s..." }, { "kp_tps_noscroll", "You no longer have the scroll" }, { "kp_tps_incoming", "{0} is teleporting to you" }, { "kp_tps_pick", "Choose a player:" }, { "kp_tps_none", "No other players on the server." }, { "kp_tps_cancel", "Cancel" }, { "kp_tps_testname", "Test player" }, { "kp_tps_noserver", "The server does not have this mod" }, { "kp_tps_servercheck", "Checking whether the server has this mod..." } }); CustomLocalization loc2 = _loc; text = "Polish"; loc2.AddTranslation(ref text, new Dictionary<string, string> { { "item_teleportscroll_kp", "Zwój teleportacji" }, { "item_teleportscroll_kp_desc", "Użyj, aby przenieść się do wybranego gracza." }, { "kp_tps_busy", "Już czytasz zwój..." }, { "kp_tps_cooldown", "Zwój będzie gotowy za {0} s" }, { "kp_tps_noteleport", "Masz przedmioty, których nie można teleportować" }, { "kp_tps_searching", "Szukam gracza {0}..." }, { "kp_tps_noreply", "{0} nie odpowiada (czy ma zainstalowany ten mod?)" }, { "kp_tps_channel", "Teleportacja do {0} za {1} s..." }, { "kp_tps_noscroll", "Nie masz już zwoju" }, { "kp_tps_incoming", "{0} teleportuje się do ciebie" }, { "kp_tps_pick", "Wybierz gracza:" }, { "kp_tps_none", "Brak innych graczy na serwerze." }, { "kp_tps_cancel", "Anuluj" }, { "kp_tps_testname", "Testowy gracz" }, { "kp_tps_noserver", "Serwer nie ma tego moda" }, { "kp_tps_servercheck", "Sprawdzam, czy serwer ma ten mod..." } }); } private string L(string token, params object[] args) { string text = ((_loc != null) ? _loc.TryTranslate(token) : token); if (args.Length != 0) { return string.Format(text, args); } return text; } private void AddScrollItem() { //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_0021: 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_0033: 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_0066: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Expected O, but got Unknown //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Expected O, but got Unknown PrefabManager.OnVanillaPrefabsAvailable -= AddScrollItem; ItemConfig val = new ItemConfig { Name = "$item_teleportscroll_kp", Description = "$item_teleportscroll_kp_desc", Amount = 1, Enabled = _cfgCraftable.Value, CraftingStation = _cfgStation.Value, MinStationLevel = _cfgStationLevel.Value, Requirements = ((IEnumerable<KeyValuePair<string, int>>)ParseRequirements(_cfgRecipe.Value)).Select((Func<KeyValuePair<string, int>, RequirementConfig>)((KeyValuePair<string, int> r) => new RequirementConfig(r.Key, r.Value, 0, true))).ToArray() }; Sprite val2 = LoadIcon(); if ((Object)(object)val2 != (Object)null) { val.Icon = val2; } CustomItem val3 = new CustomItem("TeleportScroll_KP", "Thunderstone", val); SharedData shared = val3.ItemDrop.m_itemData.m_shared; shared.m_maxStackSize = 20; shared.m_weight = 0.5f; shared.m_teleportable = true; ApplyScrollModel(val3.ItemPrefab); ItemManager.Instance.AddItem(val3); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Zwój teleportacji dodany."); } private static Sprite LoadIcon() { //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown //IL_006b: 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_0072: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: 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_0088: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) try { Assembly executingAssembly = Assembly.GetExecutingAssembly(); string name = executingAssembly.GetManifestResourceNames().First((string n) => n.EndsWith("icon.png")); using Stream stream = executingAssembly.GetManifestResourceStream(name); using MemoryStream memoryStream = new MemoryStream(); stream.CopyTo(memoryStream); Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false); LoadPng(val, memoryStream.ToArray()); Color32[] pixels = val.GetPixels32(); for (int num = 0; num < pixels.Length; num++) { Color32 val2 = pixels[num]; if (val2.r < 12 && val2.g < 12 && val2.b < 12) { pixels[num] = new Color32((byte)0, (byte)0, (byte)0, (byte)0); } } val.SetPixels32(pixels); val.Apply(); _scrollTexture = val; return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f)); } catch (Exception ex) { ((BaseUnityPlugin)Instance).Logger.LogWarning((object)("Nie udało się wczytać ikony zwoju: " + ex.Message)); return null; } } private static void LoadPng(Texture2D tex, byte[] data) { Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "UnityEngine.ImageConversionModule"); if (assembly == null) { assembly = Assembly.Load("UnityEngine.ImageConversionModule"); } assembly.GetType("UnityEngine.ImageConversion").GetMethods(BindingFlags.Static | BindingFlags.Public).First(delegate(MethodInfo m) { if (m.Name != "LoadImage") { return false; } ParameterInfo[] parameters = m.GetParameters(); return parameters.Length == 3 && parameters[1].ParameterType == typeof(byte[]) && parameters[2].ParameterType == typeof(bool); }) .Invoke(null, new object[3] { tex, data, false }); } private static void ApplyScrollModel(GameObject prefab) { //IL_00c8: 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_00d9: Expected O, but got Unknown //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Expected O, but got Unknown //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_0140: 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_0154: Unknown result type (might be due to invalid IL or missing references) Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].enabled = false; } Light[] componentsInChildren2 = prefab.GetComponentsInChildren<Light>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { ((Behaviour)componentsInChildren2[i]).enabled = false; } Shader val = Shader.Find("Sprites/Default") ?? Shader.Find("Unlit/Transparent") ?? Shader.Find("UI/Default"); if ((Object)(object)val == (Object)null || (Object)(object)_scrollTexture == (Object)null) { ((BaseUnityPlugin)Instance).Logger.LogWarning((object)"Nie udało się podmienić modelu zwoju."); componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].enabled = true; } return; } Material val2 = new Material(val) { mainTexture = (Texture)(object)_scrollTexture }; Material val3 = new Material(val) { color = new Color(0.55f, 0.36f, 0.18f, 1f) }; GameObject val4 = new GameObject("ScrollModel"); val4.transform.SetParent(prefab.transform, false); val4.transform.localPosition = new Vector3(0f, 0.02f, 0f); val4.transform.localScale = Vector3.one * 0.42f; val4.AddComponent<MeshFilter>().mesh = CreateScrollMesh(); MeshRenderer val5 = val4.AddComponent<MeshRenderer>(); ((Renderer)val5).sharedMaterials = (Material[])(object)new Material[2] { val2, val3 }; ((Renderer)val5).shadowCastingMode = (ShadowCastingMode)0; } private static Mesh CreateScrollMesh() { //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_0011: Expected O, but got Unknown //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_009b: 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_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_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_0102: 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_011e: 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_013a: Unknown result type (might be due to invalid IL or missing references) //IL_013f: 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_015b: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_0177: 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_0193: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01af: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: 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_01fe: Unknown result type (might be due to invalid IL or missing references) //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_021a: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_023b: Unknown result type (might be due to invalid IL or missing references) //IL_0252: Unknown result type (might be due to invalid IL or missing references) //IL_0257: Unknown result type (might be due to invalid IL or missing references) //IL_026e: Unknown result type (might be due to invalid IL or missing references) //IL_0273: Unknown result type (might be due to invalid IL or missing references) //IL_028a: Unknown result type (might be due to invalid IL or missing references) //IL_028f: Unknown result type (might be due to invalid IL or missing references) //IL_02a6: 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_02c9: Unknown result type (might be due to invalid IL or missing references) //IL_02ce: Unknown result type (might be due to invalid IL or missing references) //IL_02df: 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_02f5: Unknown result type (might be due to invalid IL or missing references) //IL_02fa: Unknown result type (might be due to invalid IL or missing references) //IL_030b: Unknown result type (might be due to invalid IL or missing references) //IL_0310: Unknown result type (might be due to invalid IL or missing references) //IL_0321: Unknown result type (might be due to invalid IL or missing references) //IL_0326: Unknown result type (might be due to invalid IL or missing references) //IL_0337: 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_034d: Unknown result type (might be due to invalid IL or missing references) //IL_0352: Unknown result type (might be due to invalid IL or missing references) //IL_0363: 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_036f: Unknown result type (might be due to invalid IL or missing references) //IL_0374: Unknown result type (might be due to invalid IL or missing references) //IL_037c: Unknown result type (might be due to invalid IL or missing references) //IL_0381: Unknown result type (might be due to invalid IL or missing references) //IL_0389: Unknown result type (might be due to invalid IL or missing references) //IL_038e: Unknown result type (might be due to invalid IL or missing references) //IL_0396: Unknown result type (might be due to invalid IL or missing references) //IL_039b: Unknown result type (might be due to invalid IL or missing references) //IL_03a3: Unknown result type (might be due to invalid IL or missing references) //IL_03a8: Unknown result type (might be due to invalid IL or missing references) //IL_03b0: Unknown result type (might be due to invalid IL or missing references) //IL_03b5: Unknown result type (might be due to invalid IL or missing references) //IL_03bd: Unknown result type (might be due to invalid IL or missing references) //IL_03c2: Unknown result type (might be due to invalid IL or missing references) //IL_03ca: Unknown result type (might be due to invalid IL or missing references) //IL_03cf: Unknown result type (might be due to invalid IL or missing references) //IL_03d7: Unknown result type (might be due to invalid IL or missing references) //IL_03dc: Unknown result type (might be due to invalid IL or missing references) //IL_03e4: Unknown result type (might be due to invalid IL or missing references) //IL_03e9: Unknown result type (might be due to invalid IL or missing references) //IL_03f1: Unknown result type (might be due to invalid IL or missing references) //IL_03f6: Unknown result type (might be due to invalid IL or missing references) //IL_03fe: Unknown result type (might be due to invalid IL or missing references) //IL_0403: Unknown result type (might be due to invalid IL or missing references) //IL_040b: Unknown result type (might be due to invalid IL or missing references) //IL_0410: Unknown result type (might be due to invalid IL or missing references) //IL_0418: Unknown result type (might be due to invalid IL or missing references) //IL_041d: Unknown result type (might be due to invalid IL or missing references) //IL_0425: Unknown result type (might be due to invalid IL or missing references) //IL_042a: Unknown result type (might be due to invalid IL or missing references) //IL_0432: Unknown result type (might be due to invalid IL or missing references) //IL_0437: Unknown result type (might be due to invalid IL or missing references) Mesh val = new Mesh { name = "ScrollMesh" }; val.vertices = (Vector3[])(object)new Vector3[24] { new Vector3(-0.5f, 0.07f, -0.5f), new Vector3(0.5f, 0.07f, -0.5f), new Vector3(-0.5f, 0.07f, 0.5f), new Vector3(0.5f, 0.07f, 0.5f), new Vector3(-0.5f, 0f, -0.5f), new Vector3(0.5f, 0f, -0.5f), new Vector3(-0.5f, 0f, 0.5f), new Vector3(0.5f, 0f, 0.5f), new Vector3(-0.5f, 0f, -0.5f), new Vector3(0.5f, 0f, -0.5f), new Vector3(0.5f, 0.07f, -0.5f), new Vector3(-0.5f, 0.07f, -0.5f), new Vector3(-0.5f, 0f, 0.5f), new Vector3(0.5f, 0f, 0.5f), new Vector3(0.5f, 0.07f, 0.5f), new Vector3(-0.5f, 0.07f, 0.5f), new Vector3(-0.5f, 0f, -0.5f), new Vector3(-0.5f, 0f, 0.5f), new Vector3(-0.5f, 0.07f, 0.5f), new Vector3(-0.5f, 0.07f, -0.5f), new Vector3(0.5f, 0f, -0.5f), new Vector3(0.5f, 0f, 0.5f), new Vector3(0.5f, 0.07f, 0.5f), new Vector3(0.5f, 0.07f, -0.5f) }; val.uv = (Vector2[])(object)new Vector2[24] { new Vector2(0f, 0f), new Vector2(1f, 0f), new Vector2(0f, 1f), new Vector2(1f, 1f), new Vector2(0f, 0f), new Vector2(1f, 0f), new Vector2(0f, 1f), new Vector2(1f, 1f), Vector2.zero, Vector2.zero, Vector2.zero, Vector2.zero, Vector2.zero, Vector2.zero, Vector2.zero, Vector2.zero, Vector2.zero, Vector2.zero, Vector2.zero, Vector2.zero, Vector2.zero, Vector2.zero, Vector2.zero, Vector2.zero }; val.subMeshCount = 2; val.SetTriangles(new int[12] { 0, 2, 1, 2, 3, 1, 4, 5, 6, 5, 7, 6 }, 0); val.SetTriangles(new int[24] { 8, 9, 10, 8, 10, 11, 12, 15, 14, 12, 14, 13, 16, 17, 18, 16, 18, 19, 20, 23, 22, 20, 22, 21 }, 1); val.RecalculateNormals(); return val; } private static List<KeyValuePair<string, int>> ParseRequirements(string raw) { List<KeyValuePair<string, int>> list = new List<KeyValuePair<string, int>>(); string[] array = raw.Split(new char[1] { ',' }); for (int i = 0; i < array.Length; i++) { string[] array2 = array[i].Trim().Split(new char[1] { ':' }); if (array2.Length == 2 && int.TryParse(array2[1].Trim(), out var result)) { list.Add(new KeyValuePair<string, int>(array2[0].Trim(), result)); } } return list; } private void ApplyRecipe() { //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_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Expected O, but got Unknown ObjectDB instance = ObjectDB.instance; if ((Object)(object)instance == (Object)null || instance.m_recipes == null) { return; } Recipe val = ((IEnumerable<Recipe>)instance.m_recipes).FirstOrDefault((Func<Recipe, bool>)((Recipe r) => (Object)(object)r != (Object)null && (Object)(object)r.m_item != (Object)null && ((Object)r.m_item).name == "TeleportScroll_KP")); if ((Object)(object)val == (Object)null) { return; } val.m_enabled = _cfgCraftable.Value && ServerOffersScroll; List<Requirement> list = new List<Requirement>(); foreach (KeyValuePair<string, int> item in ParseRequirements(_cfgRecipe.Value)) { GameObject itemPrefab = instance.GetItemPrefab(item.Key); ItemDrop val2 = (((Object)(object)itemPrefab != (Object)null) ? itemPrefab.GetComponent<ItemDrop>() : null); if ((Object)(object)val2 == (Object)null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Nieznany przedmiot w recepturze: " + item.Key)); continue; } list.Add(new Requirement { m_resItem = val2, m_amount = item.Value, m_recover = true }); } val.m_resources = list.ToArray(); GameObject val3 = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab(_cfgStation.Value) : null); CraftingStation val4 = (((Object)(object)val3 != (Object)null) ? val3.GetComponent<CraftingStation>() : null); if ((Object)(object)val4 != (Object)null) { val.m_craftingStation = val4; } val.m_minStationLevel = _cfgStationLevel.Value; } internal void RegisterRpcs() { ZRoutedRpc.instance.Register<string>("KP_TPScroll_Request", (Action<long, string>)RPC_Request); ZRoutedRpc.instance.Register<Vector3, Quaternion>("KP_TPScroll_Reply", (Action<long, Vector3, Quaternion>)RPC_Reply); ZRoutedRpc.instance.Register<int>("KP_TPScroll_ServerPing", (Action<long, int>)RPC_ServerPing); ZRoutedRpc.instance.Register<int>("KP_TPScroll_ServerPong", (Action<long, int>)RPC_ServerPong); ((MonoBehaviour)this).StartCoroutine(DetectServer()); } private IEnumerator DetectServer() { _serverHasMod = false; _serverCheckDone = false; if ((Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer()) { _serverHasMod = true; _serverCheckDone = true; ApplyRecipe(); yield break; } ZNetPeer server = null; for (int i = 0; i < 50; i++) { if (server != null) { break; } server = (((Object)(object)ZNet.instance != (Object)null) ? ZNet.instance.GetServerPeer() : null); if (server == null) { yield return (object)new WaitForSeconds(0.2f); } } if (server == null) { _serverCheckDone = true; ApplyRecipe(); yield break; } int token = ++_serverPingToken; ZRoutedRpc.instance.InvokeRoutedRPC(server.m_uid, "KP_TPScroll_ServerPing", new object[1] { token }); yield return (object)new WaitForSeconds(3f); if (token == _serverPingToken) { _serverCheckDone = true; } ApplyRecipe(); } private void RPC_ServerPing(long sender, int token) { if (!((Object)(object)ZNet.instance == (Object)null) && ZNet.instance.IsServer()) { ZRoutedRpc.instance.InvokeRoutedRPC(sender, "KP_TPScroll_ServerPong", new object[1] { token }); } } private void RPC_ServerPong(long sender, int token) { if (token == _serverPingToken) { _serverHasMod = true; _serverCheckDone = true; ApplyRecipe(); } } private void RPC_Request(long sender, string requesterName) { //IL_0057: 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) Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null)) { if (_cfgNotifyTarget.Value) { ((Character)localPlayer).Message((MessageType)2, L("$kp_tps_incoming", requesterName), 0, (Sprite)null, false); } Transform transform = ((Component)localPlayer).transform; ZRoutedRpc.instance.InvokeRoutedRPC(sender, "KP_TPScroll_Reply", new object[2] { transform.position, transform.rotation }); } } private void RPC_Reply(long sender, Vector3 position, Quaternion rotation) { //IL_001d: 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) if (_busy && !_channeling && sender == _pendingTarget) { ((MonoBehaviour)this).StartCoroutine(ChannelAndTeleport(position, rotation)); } } internal void OnScrollUsed() { if (_busy) { Msg(L("$kp_tps_busy")); return; } float num = _lastUse + _cfgCooldown.Value - Time.time; if (num > 0f) { Msg(L("$kp_tps_cooldown", Mathf.CeilToInt(num))); } else if (!ServerOffersScroll) { Msg(L(_serverCheckDone ? "$kp_tps_noserver" : "$kp_tps_servercheck")); } else { OpenMenu(); } } private void SelectTarget(PlayerInfo target) { //IL_004f: Unknown result type (might be due to invalid IL or missing references) CloseMenu(); Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null)) { if (!((Humanoid)localPlayer).IsTeleportable(false)) { Msg(L("$kp_tps_noteleport")); return; } _busy = true; _pendingTarget = ((ZDOID)(ref target.m_characterID)).UserID; _pendingName = target.m_name; int requestId = ++_requestId; ZRoutedRpc.instance.InvokeRoutedRPC(_pendingTarget, "KP_TPScroll_Request", new object[1] { localPlayer.GetPlayerName() }); Msg(L("$kp_tps_searching", _pendingName)); ((MonoBehaviour)this).StartCoroutine(ReplyTimeout(requestId)); } } private void SelectTestTarget() { //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0079: 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) CloseMenu(); Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null)) { if (!((Humanoid)localPlayer).IsTeleportable(false)) { Msg(L("$kp_tps_noteleport")); return; } _busy = true; _pendingTarget = 0L; _pendingName = L("$kp_tps_testname"); Transform transform = ((Component)localPlayer).transform; ((MonoBehaviour)this).StartCoroutine(ChannelAndTeleport(transform.position + transform.forward * 8f, transform.rotation)); } } private IEnumerator ReplyTimeout(int requestId) { yield return (object)new WaitForSeconds(_cfgReplyTimeout.Value); if (_busy && !_channeling && requestId == _requestId) { _busy = false; Msg(L("$kp_tps_noreply", _pendingName)); } } private IEnumerator ChannelAndTeleport(Vector3 targetPos, Quaternion targetRot) { //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) //IL_0015: 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) _channeling = true; Msg(L("$kp_tps_channel", _pendingName, _cfgChannelTime.Value.ToString("0"))); yield return (object)new WaitForSeconds(_cfgChannelTime.Value); Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead()) { ResetState(); yield break; } if (!((Humanoid)localPlayer).IsTeleportable(false)) { Msg(L("$kp_tps_noteleport")); ResetState(); yield break; } Inventory inventory = ((Humanoid)localPlayer).GetInventory(); ItemData val = ((IEnumerable<ItemData>)inventory.GetAllItems()).FirstOrDefault((Func<ItemData, bool>)((ItemData i) => (Object)(object)i.m_dropPrefab != (Object)null && ((Object)i.m_dropPrefab).name == "TeleportScroll_KP")); if (val == null) { Msg(L("$kp_tps_noscroll")); ResetState(); yield break; } inventory.RemoveOneItem(val); Vector3 val2 = targetPos + targetRot * Vector3.back * 1.5f + Vector3.up * 0.5f; ((Character)localPlayer).TeleportTo(val2, targetRot, true); _lastUse = Time.time; ResetState(); } private void ResetState() { _busy = false; _channeling = false; } private void OpenMenu() { _menuOpen = true; GUIManager.BlockInput(true); } private void CloseMenu() { if (_menuOpen) { _menuOpen = false; GUIManager.BlockInput(false); } } private void OnGUI() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Invalid comparison between Unknown and I4 //IL_007c: 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_00a2: Expected O, but got Unknown //IL_009d: 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_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Invalid comparison between Unknown and I4 if (_menuOpen) { Event current = Event.current; if ((int)current.type == 4 && (int)current.keyCode == 27) { current.Use(); CloseMenu(); } else { ((Rect)(ref _windowRect)).x = ((float)Screen.width - ((Rect)(ref _windowRect)).width) / 2f; ((Rect)(ref _windowRect)).y = ((float)Screen.height - ((Rect)(ref _windowRect)).height) / 2f; _windowRect = GUI.Window(48151623, _windowRect, new WindowFunction(DrawWindow), L("$item_teleportscroll_kp")); } } } private void DrawWindow(int id) { //IL_0041: 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_005e: 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_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: 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_0109: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; List<PlayerInfo> list = (((Object)(object)ZNet.instance != (Object)null) ? ZNet.instance.GetPlayerList() : new List<PlayerInfo>()); GUILayout.Label(L("$kp_tps_pick"), Array.Empty<GUILayoutOption>()); _scrollPos = GUILayout.BeginScrollView(_scrollPos, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(320f) }); bool flag = false; if (_cfgTestFakePlayer.Value) { flag = true; if (GUILayout.Button(L("$kp_tps_testname"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(32f) })) { SelectTestTarget(); } } foreach (PlayerInfo item in list) { ZDOID characterID = item.m_characterID; if (!((ZDOID)(ref characterID)).IsNone() && (!((Object)(object)localPlayer != (Object)null) || !(item.m_characterID == ((Character)localPlayer).GetZDOID()))) { flag = true; if (GUILayout.Button(item.m_name, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(32f) })) { SelectTarget(item); break; } } } if (!flag) { GUILayout.Label(L("$kp_tps_none"), Array.Empty<GUILayoutOption>()); } GUILayout.EndScrollView(); if (GUILayout.Button(L("$kp_tps_cancel"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) })) { CloseMenu(); } } private static void Msg(string text) { Player localPlayer = Player.m_localPlayer; if (localPlayer != null) { ((Character)localPlayer).Message((MessageType)2, text, 0, (Sprite)null, false); } } } [HarmonyPatch(typeof(Humanoid), "UseItem")] internal static class UseItemPatch { private static bool Prefix(Humanoid __instance, ItemData item) { if ((Object)(object)item?.m_dropPrefab == (Object)null || ((Object)item.m_dropPrefab).name != "TeleportScroll_KP") { return true; } if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer) { Plugin.Instance.OnScrollUsed(); } return false; } } [HarmonyPatch(typeof(Trader), "GetAvailableItems")] internal static class TraderItemsPatch { private static void Postfix(Trader __instance, ref List<TradeItem> __result) { //IL_0162: 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_016f: 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_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Expected O, but got Unknown Plugin instance = Plugin.Instance; if ((Object)(object)instance == (Object)null || !instance.CfgSoldByTrader.Value || __result == null || !instance.ServerOffersScroll) { return; } string traderName = ((Object)((Component)__instance).gameObject).name.Replace("(Clone)", "").Trim(); if (!(from s in instance.CfgTraders.Value.Split(new char[1] { ',' }) select s.Trim() into s where s.Length > 0 select s).Any((string a) => traderName.IndexOf(a, StringComparison.OrdinalIgnoreCase) >= 0)) { return; } string text = instance.CfgRequiredKey.Value.Trim(); if ((text.Length <= 0 || (!((Object)(object)ZoneSystem.instance == (Object)null) && ZoneSystem.instance.GetGlobalKey(text))) && !__result.Any((TradeItem t) => (Object)(object)t.m_prefab != (Object)null && ((Object)t.m_prefab).name == "TeleportScroll_KP")) { ObjectDB instance2 = ObjectDB.instance; GameObject val = ((instance2 != null) ? instance2.GetItemPrefab("TeleportScroll_KP") : null); ItemDrop val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ItemDrop>() : null); if (!((Object)(object)val2 == (Object)null)) { __result.Add(new TradeItem { m_prefab = val2, m_stack = Mathf.Max(1, instance.CfgTraderStack.Value), m_price = Mathf.Max(0, instance.CfgPrice.Value), m_requiredGlobalKey = "" }); } } } } [HarmonyPatch(typeof(ZNet), "Awake")] internal static class ZNetAwakePatch { private static void Postfix() { Plugin.Instance.RegisterRpcs(); } } }