Decompiled source of WKMapLoader v1.4.0
WKMapLoader.dll
Decompiled 5 days ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.Events; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; using UnityEngine.Rendering; using UnityEngine.ResourceManagement.AsyncOperations; using UnityEngine.SceneManagement; using UnityEngine.UI; [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("WKMapLoader")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.3.1.0")] [assembly: AssemblyInformationalVersion("1.3.1+7c75f2ef972887121e5622a5035fc09caa2a34ee")] [assembly: AssemblyProduct("WKMapLoader")] [assembly: AssemblyTitle("WKMapLoader")] [assembly: AssemblyVersion("1.3.1.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 WKMapLoader { internal static class CustomMenu { private const string TabName = "CUSTOM"; private const string ModeDatabaseId = "wkcustommodes"; internal static readonly Dictionary<M_Gamemode, string> ModeToMap = new Dictionary<M_Gamemode, string>(); internal static readonly Dictionary<M_Gamemode, string> Titles = new Dictionary<M_Gamemode, string>(); private static WKAssetDatabase modeDb; private static readonly HashSet<UI_TabGroup> injected = new HashSet<UI_TabGroup>(); public static void TryInject(UI_TabGroup group) { try { Inject(group); } catch (Exception ex) { Plugin.Log.LogError((object)("CUSTOM tab injection failed: " + ex)); } } private static void Inject(UI_TabGroup group) { //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_027a: Unknown result type (might be due to invalid IL or missing references) //IL_043e: 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_0443: Unknown result type (might be due to invalid IL or missing references) //IL_0458: 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_04dd: Unknown result type (might be due to invalid IL or missing references) //IL_04ea: Unknown result type (might be due to invalid IL or missing references) //IL_04ef: Unknown result type (might be due to invalid IL or missing references) //IL_0771: Unknown result type (might be due to invalid IL or missing references) //IL_0776: Unknown result type (might be due to invalid IL or missing references) //IL_0781: Unknown result type (might be due to invalid IL or missing references) //IL_0789: Unknown result type (might be due to invalid IL or missing references) //IL_0791: Unknown result type (might be due to invalid IL or missing references) //IL_0799: Unknown result type (might be due to invalid IL or missing references) //IL_07a6: Expected O, but got Unknown //IL_07e1: Unknown result type (might be due to invalid IL or missing references) //IL_07eb: Expected O, but got Unknown //IL_06f2: Unknown result type (might be due to invalid IL or missing references) //IL_070c: Unknown result type (might be due to invalid IL or missing references) //IL_06da: Unknown result type (might be due to invalid IL or missing references) //IL_06df: Unknown result type (might be due to invalid IL or missing references) //IL_0722: Unknown result type (might be due to invalid IL or missing references) //IL_072e: Unknown result type (might be due to invalid IL or missing references) //IL_0733: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)group == (Object)null || group.tabs == null || injected.Contains(group)) { return; } string text = string.Join("/", group.tabs.Select((Tab t) => t.name)); Tab tmpl = ((IEnumerable<Tab>)group.tabs).FirstOrDefault((Func<Tab, bool>)((Tab x) => x.name != null && x.name.ToLowerInvariant().Contains("event"))) ?? ((IEnumerable<Tab>)group.tabs).FirstOrDefault((Func<Tab, bool>)((Tab x) => x.name != null && x.name.ToLowerInvariant().Contains("challenge"))); if (tmpl == null || (Object)(object)tmpl.button == (Object)null || (Object)(object)tmpl.tabObject == (Object)null) { Plugin.Log.LogDebug((object)("Tab group '" + ((Object)group).name + "' [" + text + "] is not the play screen - skipped.")); return; } injected.Add(group); Scene scene = ((Component)group).gameObject.scene; Plugin.Log.LogInfo((object)("Menu tabs: " + text)); List<string> list = (from g in Plugin.Instance.AllMapFiles().GroupBy<string, string>(Path.GetFileNameWithoutExtension, StringComparer.OrdinalIgnoreCase) select g.First() into p where !Plugin.IsHiddenMap(p) orderby Path.GetFileNameWithoutExtension(p) select p).ToList(); Tab val = ((IEnumerable<Tab>)group.tabs).FirstOrDefault((Func<Tab, bool>)((Tab t) => string.Equals(t.name?.Trim(), "custom", StringComparison.OrdinalIgnoreCase))); if (val != null && (Object)(object)val.button != (Object)null && (Object)(object)val.tabObject != (Object)null) { UseBuiltInTab(val, list, scene); return; } bool activeSelf = tmpl.tabObject.activeSelf; tmpl.tabObject.SetActive(false); GameObject val2 = Object.Instantiate<GameObject>(tmpl.tabObject, tmpl.tabObject.transform.parent); tmpl.tabObject.SetActive(activeSelf); ((Object)val2).name = "CUSTOM Page"; UI_Gamemode_Button[] componentsInChildren = val2.GetComponentsInChildren<UI_Gamemode_Button>(true); UI_Gamemode_Button val3 = componentsInChildren.FirstOrDefault(); if ((Object)(object)val3 == (Object)null) { UI_Gamemode_Button val4 = ((IEnumerable<UI_Gamemode_Button>)Resources.FindObjectsOfTypeAll<UI_Gamemode_Button>()).FirstOrDefault((Func<UI_Gamemode_Button, bool>)((UI_Gamemode_Button c) => ((Component)c).gameObject.scene == scene)); if ((Object)(object)val4 == (Object)null) { Plugin.Log.LogWarning((object)"No level card found to copy - CUSTOM tab not added."); Object.Destroy((Object)(object)val2); return; } val3 = Object.Instantiate<UI_Gamemode_Button>(val4, val2.transform); } UI_Gamemode_Button[] array = componentsInChildren; foreach (UI_Gamemode_Button val5 in array) { if ((Object)(object)val5 != (Object)(object)val3) { Object.Destroy((Object)(object)((Component)val5).gameObject); } } TMP_Text[] componentsInChildren2 = val2.GetComponentsInChildren<TMP_Text>(true); foreach (TMP_Text val6 in componentsInChildren2) { if ((Object)(object)((Component)val6).GetComponentInParent<UI_Gamemode_Button>(true) == (Object)null && val6.text.Trim().Equals(tmpl.name.Trim(), StringComparison.OrdinalIgnoreCase)) { val6.text = "CUSTOM"; } } M_Gamemode gamemode = val3.gamemode; ModeToMap.Clear(); Titles.Clear(); RectTransform component = ((Component)val3).GetComponent<RectTransform>(); bool flag = (Object)(object)((Component)((Component)val3).transform.parent).GetComponent<LayoutGroup>() != (Object)null; Vector2 val7 = (((Object)(object)component != (Object)null) ? component.anchoredPosition : Vector2.zero); float num2; Rect rect; if (!((Object)(object)component != (Object)null)) { num2 = 300f; } else { rect = component.rect; num2 = ((Rect)(ref rect)).width; } float num3 = num2 + 24f; Selectable val8 = null; for (int num4 = 0; num4 < list.Count; num4++) { UI_Gamemode_Button val9 = ((num4 == 0) ? val3 : Object.Instantiate<UI_Gamemode_Button>(val3, ((Component)val3).transform.parent)); ((Object)val9).name = "Card " + Path.GetFileNameWithoutExtension(list[num4]); val9.gamemode = MakeMode(gamemode, list[num4]); if (!flag) { RectTransform component2 = ((Component)val9).GetComponent<RectTransform>(); if (component2 != null) { component2.anchoredPosition = val7 + new Vector2(num3 * (float)num4, 0f); } } if ((Object)(object)val8 == (Object)null) { val8 = ((Component)val9).GetComponent<Selectable>(); } } if (list.Count == 0) { ((Component)val3).gameObject.SetActive(false); } FitContent(((Component)val3).transform.parent); RegisterModes(); Button val10 = (from t in @group.tabs select t.button into b where (Object)(object)b != (Object)null && (Object)(object)((Component)b).transform.parent == (Object)(object)((Component)tmpl.button).transform.parent orderby ((Component)b).transform.GetSiblingIndex() select b).Last(); GameObject val11 = Object.Instantiate<GameObject>(((Component)tmpl.button).gameObject, ((Component)tmpl.button).transform.parent); ((Object)val11).name = "CUSTOM Tab"; val11.transform.SetSiblingIndex(((Component)val10).transform.GetSiblingIndex() + 1); if ((Object)(object)((Component)val11.transform.parent).GetComponent<LayoutGroup>() == (Object)null) { List<RectTransform> list2 = (from t in @group.tabs select t.button into b where (Object)(object)b != (Object)null select ((Component)b).GetComponent<RectTransform>() into rt orderby rt.anchoredPosition.x select rt).ToList(); RectTransform val12 = list2.Last(); float num5; if (list2.Count <= 1) { rect = val12.rect; num5 = ((Rect)(ref rect)).width + 16f; } else { num5 = val12.anchoredPosition.x - list2[list2.Count - 2].anchoredPosition.x; } float num6 = num5; val11.GetComponent<RectTransform>().anchoredPosition = val12.anchoredPosition + new Vector2(num6, 0f); } TMP_Text componentInChildren = val11.GetComponentInChildren<TMP_Text>(true); if ((Object)(object)componentInChildren != (Object)null) { componentInChildren.text = "CUSTOM"; } Button component3 = val11.GetComponent<Button>(); group.tabs.Add(new Tab { name = "CUSTOM", button = component3, tabObject = val2, buttonText = componentInChildren, firstSelect = val8 }); if (typeof(UI_TabGroup).GetField("group", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(group) != null) { ((UnityEvent)component3.onClick).AddListener((UnityAction)delegate { group.SelectTab("CUSTOM"); }); } val2.SetActive(false); if ((Object)(object)componentInChildren != (Object)null) { ((MonoBehaviour)Plugin.Instance).StartCoroutine(KeepLabel(componentInChildren)); } Plugin.Log.LogInfo((object)string.Format("{0} tab added with {1} map card(s): {2}", "CUSTOM", list.Count, string.Join(", ", list.Select(Path.GetFileNameWithoutExtension)))); } private static void UseBuiltInTab(Tab tab, List<string> maps, Scene scene) { //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) tab.onlyDev = false; ((Component)tab.button).gameObject.SetActive(true); TMP_Text val = (((Object)(object)tab.buttonText != (Object)null) ? tab.buttonText : ((Component)tab.button).GetComponentInChildren<TMP_Text>(true)); if ((Object)(object)val != (Object)null) { val.text = "CUSTOM"; ((MonoBehaviour)Plugin.Instance).StartCoroutine(KeepLabel(val)); } GameObject tabObject = tab.tabObject; UI_Gamemode_Button[] componentsInChildren = tabObject.GetComponentsInChildren<UI_Gamemode_Button>(true); UI_Gamemode_Button val2 = ((IEnumerable<UI_Gamemode_Button>)componentsInChildren).FirstOrDefault((Func<UI_Gamemode_Button, bool>)((UI_Gamemode_Button c) => (Object)(object)((Component)c).transform.parent != (Object)null && ((Object)((Component)c).transform.parent).name == "Content")) ?? componentsInChildren.FirstOrDefault(); if ((Object)(object)val2 == (Object)null) { UI_Gamemode_Button val3 = ((IEnumerable<UI_Gamemode_Button>)Resources.FindObjectsOfTypeAll<UI_Gamemode_Button>()).FirstOrDefault((Func<UI_Gamemode_Button, bool>)((UI_Gamemode_Button c) => ((Component)c).gameObject.scene == scene)); if ((Object)(object)val3 == (Object)null) { Plugin.Log.LogWarning((object)"No level card found to copy - CUSTOM tab left empty."); return; } val2 = Object.Instantiate<UI_Gamemode_Button>(val3, tabObject.transform); } foreach (Transform item in ((IEnumerable)((Component)val2).transform.parent).Cast<Transform>().ToList()) { if ((Object)(object)item != (Object)(object)((Component)val2).transform) { Object.Destroy((Object)(object)((Component)item).gameObject); } } tab.firstSelect = FillCards(val2, maps); Plugin.Log.LogInfo((object)string.Format("Built-in Custom tab enabled with {0} map card(s): {1}", maps.Count, string.Join(", ", maps.Select(Path.GetFileNameWithoutExtension)))); } private static Selectable FillCards(UI_Gamemode_Button cardTemplate, List<string> maps) { //IL_004a: 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_004f: 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_0066: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) M_Gamemode gamemode = cardTemplate.gamemode; ModeToMap.Clear(); Titles.Clear(); RectTransform component = ((Component)cardTemplate).GetComponent<RectTransform>(); bool flag = (Object)(object)((Component)((Component)cardTemplate).transform.parent).GetComponent<LayoutGroup>() != (Object)null; Vector2 val = (((Object)(object)component != (Object)null) ? component.anchoredPosition : Vector2.zero); float num; if (!((Object)(object)component != (Object)null)) { num = 300f; } else { Rect rect = component.rect; num = ((Rect)(ref rect)).width; } float num2 = num + 24f; Selectable val2 = null; for (int i = 0; i < maps.Count; i++) { UI_Gamemode_Button val3 = ((i == 0) ? cardTemplate : Object.Instantiate<UI_Gamemode_Button>(cardTemplate, ((Component)cardTemplate).transform.parent)); ((Object)val3).name = "Card " + Path.GetFileNameWithoutExtension(maps[i]); val3.gamemode = MakeMode(gamemode, maps[i]); ((Component)val3).gameObject.SetActive(true); if (!flag) { RectTransform component2 = ((Component)val3).GetComponent<RectTransform>(); if (component2 != null) { component2.anchoredPosition = val + new Vector2(num2 * (float)i, 0f); } } if ((Object)(object)val2 == (Object)null) { val2 = ((Component)val3).GetComponent<Selectable>(); } } if (maps.Count == 0) { ((Component)cardTemplate).gameObject.SetActive(false); } FitContent(((Component)cardTemplate).transform.parent); RegisterModes(); return val2; } private static void FitContent(Transform content) { //IL_001a: 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_002f: 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) //IL_004a: 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_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006f: 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_0086: Unknown result type (might be due to invalid IL or missing references) RectTransform val = (RectTransform)(object)((content is RectTransform) ? content : null); if (val != null && !((Object)(object)((Component)content).GetComponent<HorizontalLayoutGroup>() == (Object)null)) { Rect rect = val.rect; float width = ((Rect)(ref rect)).width; val.anchorMin = new Vector2(0f, val.anchorMin.y); val.anchorMax = new Vector2(0f, val.anchorMax.y); val.pivot = new Vector2(0f, val.pivot.y); val.sizeDelta = new Vector2(width, val.sizeDelta.y); ContentSizeFitter obj = ((Component)content).GetComponent<ContentSizeFitter>() ?? ((Component)content).gameObject.AddComponent<ContentSizeFitter>(); obj.horizontalFit = (FitMode)2; ((Behaviour)obj).enabled = true; } } private static IEnumerator KeepLabel(TMP_Text label) { float until = Time.realtimeSinceStartup + 5f; while ((Object)(object)label != (Object)null && Time.realtimeSinceStartup < until) { if (label.text != "CUSTOM") { label.text = "CUSTOM"; } yield return null; } } private static M_Gamemode MakeMode(M_Gamemode baseMode, string mapPath) { //IL_0278: Unknown result type (might be due to invalid IL or missing references) string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(mapPath); string text = Pretty(fileNameWithoutExtension); string directoryName = Path.GetDirectoryName(mapPath); M_Gamemode val = ((IEnumerable<M_Gamemode>)CL_AssetManager.GetFullCombinedAssetDatabase().gamemodeAssets).FirstOrDefault((Func<M_Gamemode, bool>)((M_Gamemode g) => (Object)(object)g != (Object)null && (((Object)g).name == "GM_Campaign" || g.gamemodeName == "Campaign"))); if ((Object)(object)val != (Object)null) { baseMode = val; } M_Gamemode val2 = Object.Instantiate<M_Gamemode>(baseMode); ((Object)val2).name = "WKMap_" + fileNameWithoutExtension; ((Object)val2).hideFlags = (HideFlags)32; val2.gamemodeName = "Custom Map - " + text; string path = Path.Combine(directoryName, fileNameWithoutExtension + ".txt"); string text2 = (File.Exists(path) ? File.ReadAllText(path).Replace("\r\n", "\n") : null); if (text2 != null) { text2 = string.Join("\n", from l in text2.Split('\n') where !l.TrimStart().StartsWith("loader:", StringComparison.OrdinalIgnoreCase) select l).TrimEnd('\n'); } string text3 = text; if (text2 != null && text2.StartsWith("title:", StringComparison.OrdinalIgnoreCase)) { int num = text2.IndexOf('\n'); text3 = ((num < 0) ? text2.Substring(6) : text2.Substring(6, num - 6)).Trim(); text2 = ((num < 0) ? "" : text2.Substring(num + 1)); if (text3.Length == 0) { text3 = text; } } val2.useCustomCapsuleName = true; val2.capsuleName = text3.ToUpperInvariant(); val2.modeDescription = text2 ?? ("Custom map: " + text + ".\nBuilt in a 3D tool, loaded by WK Map Loader.\nFall off = back to the start. No mass."); val2.introText = text3; val2.newGameText = "Play"; Plugin.Log.LogInfo((object)("[card] '" + text + "' based on '" + baseMode.gamemodeName + "' (scene '" + baseMode.gamemodeScene + "', objects: " + string.Join(", ", from o in baseMode.gamemodeObjects ?? new List<GameObject>() where (Object)(object)o != (Object)null select ((Object)o).name) + ")")); val2.gamemodeScene = "Game-Main"; val2.modeType = (GameType)4; val2.playlistLevelAssets = new List<LevelAssetHolder>(); val2.playlistLevels = new List<M_Level>(); val2.regions = new List<M_Region>(); val2.startItems = new List<SpawnItem>(); val2.gamemodeSettings = new List<GamemodeSetting>(); val2.useGamemodeSettings = false; val2.gamemodeModule = null; val2.modeTags = new List<string> { "custommap" }; val2.isEndless = false; val2.hasRevives = false; val2.hasPerks = false; val2.allowAchievements = false; val2.allowHeightAchievements = false; val2.allowLeaderboardScoring = false; val2.allowCompetitive = false; val2.allowHardmode = false; val2.allowIronKnuckle = false; val2.steamLeaderboardName = ""; val2.roachBankID = "custommap-bank"; val2.showBankAmount = false; val2.saveRoaches = false; val2.gooSpeedMult = 0f; val2.gooSpeedIncreaseMult = 0f; val2.hiddenUntilUnlocked = false; val2.unlockAchievement = ""; val2.unlockHint = ""; val2.devOnly = false; Sprite val3 = LoadSprite(Path.Combine(directoryName, fileNameWithoutExtension + ".png")); if ((Object)(object)val3 != (Object)null) { val2.capsuleArt = val3; val2.screenArt = val3; } Sprite val4 = LoadSprite(Path.Combine(directoryName, fileNameWithoutExtension + "_bg.png")); if ((Object)(object)val4 != (Object)null) { val2.screenArt = val4; } ModeToMap[val2] = mapPath; Titles[val2] = text3; return val2; } private static void RegisterModes() { if ((Object)(object)modeDb == (Object)null) { modeDb = ScriptableObject.CreateInstance<WKAssetDatabase>(); ((Object)modeDb).hideFlags = (HideFlags)32; Plugin.FillNullLists(modeDb); modeDb.id = "wkcustommodes"; CL_AssetManager.AddNewDatabase("wkcustommodes", modeDb); } modeDb.gamemodeAssets.Clear(); modeDb.gamemodeAssets.AddRange(ModeToMap.Keys); CL_AssetManager.RefreshDatabaseList(); } private static Sprite LoadSprite(string png) { //IL_000e: 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_001b: Expected O, but got Unknown //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) if (!File.Exists(png)) { return null; } Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false) { filterMode = (FilterMode)0 }; if (!ImageConversion.LoadImage(val, File.ReadAllBytes(png))) { return null; } ((Object)val).hideFlags = (HideFlags)32; Sprite obj = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f)); ((Object)obj).hideFlags = (HideFlags)32; return obj; } private static string Pretty(string id) { return string.Join(" ", from w in id.Replace('_', ' ').Replace('-', ' ').Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries) select char.ToUpperInvariant(w[0]) + w.Substring(1)); } } [HarmonyPatch(typeof(UI_TabGroup), "Start")] internal static class TabGroupStartPatch { private static void Prefix(UI_TabGroup __instance) { CustomMenu.TryInject(__instance); } } [HarmonyPatch(typeof(UI_GamemodeText), "Refresh")] internal static class GamemodeTextPatch { private static void Postfix(UI_GamemodeText __instance) { M_Gamemode gamemode = CL_GameManager.gamemode; if (!((Object)(object)gamemode == (Object)null) && CustomMenu.Titles.TryGetValue(gamemode, out var value)) { TMP_Text component = ((Component)__instance).GetComponent<TMP_Text>(); if ((Object)(object)component != (Object)null) { component.text = component.text.Replace(gamemode.gamemodeName, value); } } } } [HarmonyPatch(typeof(M_Gamemode), "GetGenerationList")] internal static class CustomModeGenerationPatch { private static void Prefix(M_Gamemode __instance) { //IL_003f: Unknown result type (might be due to invalid IL or missing references) Plugin.Log.LogInfo((object)($"[card] GetGenerationList on '{__instance?.gamemodeName}' (ours: {CustomMenu.ModeToMap.ContainsKey(__instance)}, " + string.Format("type {0}, player {1})", __instance?.modeType, ((Object)(object)ENT_Player.playerObject != (Object)null) ? "yes" : "no"))); if (!CustomMenu.ModeToMap.TryGetValue(__instance, out var value)) { return; } try { LevelAssetHolder val = Plugin.Instance.BuildHolder(value); if (val != null) { __instance.playlistLevelAssets = new List<LevelAssetHolder> { val }; Plugin.Log.LogInfo((object)("[card] built '" + val.id + "' from " + value)); } else { Plugin.Log.LogError((object)("[card] could not build map '" + value + "'.")); } } catch (Exception ex) { Plugin.Log.LogError((object)("[card] building map failed: " + ex)); } } private static void Postfix(M_Gamemode __instance, List<LevelAssetHolder> __result) { if (__result != null) { for (int i = 0; i < __result.Count; i++) { M_Level val = __result[i]?.level; if ((Object)(object)val != (Object)null && val.levelName != null && val.levelName.StartsWith("map_")) { val.lastLevel = i == __result.Count - 1; } } } if (CustomMenu.ModeToMap.ContainsKey(__instance)) { Plugin.Log.LogInfo((object)("[card] generation list: " + ((__result == null) ? "null" : string.Join(", ", __result.Select((LevelAssetHolder h) => h?.id ?? "null"))))); } } } [HarmonyPatch(typeof(FXManager), "FXRender")] internal static class FogPatch { public const float MapFogScale = 0.25f; public static bool Active; private static void Postfix() { //IL_0084: 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_0089: 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_0095: 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_00a2: Unknown result type (might be due to invalid IL or missing references) if (!Active || FXManager.fxData == null) { return; } float? mapAmbient = MapSession.MapAmbient; if (mapAmbient.HasValue) { float valueOrDefault = mapAmbient.GetValueOrDefault(); if (!FXManager.fullBright) { Shader.SetGlobalFloat("_LIGHTOFFSET", FXManager.fxData.lightOffset + valueOrDefault); } } if (FXManager.showFog) { float num = FXManager.fxData.fogMultiplier * (MapSession.MapFog ?? 0.25f); Color val = (Color)(((??)MapSession.MapFogColor) ?? FXManager.fxData.fog); Shader.SetGlobalVector("_FOG", new Vector4(val.r, val.g, val.b, num)); Shader.SetGlobalFloat("_FOGMULT", num); } } } internal static class Buttons { public static void Make(GameObject go, ENT_Player player, int solidLayer) { go.layer = Plugin.InteractLayer(player, solidLayer); if ((Object)(object)go.GetComponent<ObjectTagger>() == (Object)null) { go.AddComponent<ObjectTagger>().AddTag("Button"); } (go.GetComponent<CL_Button>() ?? go.AddComponent<CL_Button>()).pressCooldown = 0.25f; SolidCore(go, solidLayer); } public static void SolidCore(GameObject go, int solidLayer) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0042: 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_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) MeshCollider component = go.GetComponent<MeshCollider>(); if (component != null && !((Object)(object)component.sharedMesh == (Object)null) && !((Object)(object)go.transform.Find("solid_core") != (Object)null)) { GameObject val = new GameObject("solid_core") { layer = solidLayer }; val.transform.SetParent(go.transform, false); val.transform.localScale = Vector3.one * 0.96f; val.AddComponent<MeshCollider>().sharedMesh = component.sharedMesh; } } } public class MapLabel : MonoBehaviour { public string title = ""; public string description = ""; internal static readonly List<MapLabel> All = new List<MapLabel>(); private static TextMeshPro tmp; private static MapLabel shown; private const float Reach = 8f; private void OnEnable() { All.Add(this); } private void OnDisable() { All.Remove(this); if ((Object)(object)shown == (Object)(object)this) { Hide(); } } private Bounds WorldBounds() { //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: 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_009c: 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_0061: 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) List<Renderer> list = (from x in ((Component)this).GetComponentsInChildren<Renderer>() where x.enabled && x is MeshRenderer select x).ToList(); if (list.Count > 0) { Bounds bounds = list[0].bounds; { foreach (Renderer item in list.Skip(1)) { ((Bounds)(ref bounds)).Encapsulate(item.bounds); } return bounds; } } Collider componentInChildren = ((Component)this).GetComponentInChildren<Collider>(); if (!((Object)(object)componentInChildren != (Object)null)) { return new Bounds(((Component)this).transform.position, Vector3.one); } return componentInChildren.bounds; } internal static void Tick() { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_004e: 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) //IL_0072: 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_008b: 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_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) Camera main = Camera.main; if ((Object)(object)main == (Object)null) { Hide(); return; } Ray val = default(Ray); ((Ray)(ref val))..ctor(((Component)main).transform.position, ((Component)main).transform.forward); if (All.Count == 0) { Hide(); return; } MapLabel mapLabel = null; float num = 8f; Bounds val2 = default(Bounds); float num2 = default(float); foreach (MapLabel item in All) { Bounds val3 = item.WorldBounds(); if (((Bounds)(ref val3)).IntersectRay(val, ref num2) && num2 < num) { mapLabel = item; num = num2; val2 = val3; } } RaycastHit val4 = default(RaycastHit); if ((Object)(object)mapLabel != (Object)null && Physics.Raycast(val, ref val4, num, -1, (QueryTriggerInteraction)1) && ((RaycastHit)(ref val4)).distance < num - 0.3f && !((RaycastHit)(ref val4)).transform.IsChildOf(((Component)mapLabel).transform)) { mapLabel = null; } if ((Object)(object)mapLabel == (Object)null) { Hide(); return; } shown = mapLabel; Show("<b>" + mapLabel.title + "</b>" + (string.IsNullOrEmpty(mapLabel.description) ? "" : ("\n<size=55%>" + mapLabel.description + "</size>")), new Vector3(((Bounds)(ref val2)).center.x, ((Bounds)(ref val2)).max.y + 0.25f, ((Bounds)(ref val2)).center.z), main, 0.5f); } private static bool Show(string text, Vector3 at, Camera cam, float minScale) { //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_0064: 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) //IL_006e: 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_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)tmp == (Object)null && !Make()) { return false; } if (((TMP_Text)tmp).text != text) { ((TMP_Text)tmp).text = text; } ((Component)tmp).gameObject.SetActive(true); tmp.transform.position = at; tmp.transform.rotation = Quaternion.LookRotation(at - ((Component)cam).transform.position); float num = Vector3.Distance(((Component)cam).transform.position, at); tmp.transform.localScale = Vector3.one * Mathf.Clamp(num / 5f, minScale, 1.6f); return true; } private static bool Make() { //IL_0016: 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_0080: 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) TMP_FontAsset val = HudFont(); if ((Object)(object)val == (Object)null) { return false; } tmp = new GameObject("map_label").AddComponent<TextMeshPro>(); ((TMP_Text)tmp).font = val; ((TMP_Text)tmp).fontSize = 2.2f; ((TMP_Text)tmp).alignment = (TextAlignmentOptions)1026; ((TMP_Text)tmp).rectTransform.pivot = new Vector2(0.5f, 0f); ((TMP_Text)tmp).rectTransform.sizeDelta = new Vector2(4f, 2f); ((TMP_Text)tmp).enableWordWrapping = true; ((Graphic)tmp).color = Color.white; ((TMP_Text)tmp).richText = true; return true; } private static TMP_FontAsset HudFont() { TMP_Text[] array = Object.FindObjectsByType<TMP_Text>((FindObjectsSortMode)0); foreach (TMP_Text val in array) { if ((Object)(object)val != (Object)null && (Object)(object)val.font != (Object)null && ((Behaviour)val).isActiveAndEnabled) { return val.font; } } return null; } private static void Hide() { shown = null; if ((Object)(object)tmp != (Object)null) { ((Component)tmp).gameObject.SetActive(false); } } } public class MapSign : MonoBehaviour { public string text = ""; public Vector3 size; private IEnumerator Start() { yield return (object)new WaitForSeconds(0.5f); TMP_FontAsset val = null; TMP_Text[] array = Object.FindObjectsByType<TMP_Text>((FindObjectsSortMode)0); foreach (TMP_Text val2 in array) { if ((Object)(object)val2 != (Object)null && (Object)(object)val2.font != (Object)null && ((Behaviour)val2).isActiveAndEnabled) { val = val2.font; break; } } if (!((Object)(object)val == (Object)null)) { bool num = size.x < size.z; Vector3 val3 = (num ? Vector3.right : Vector3.forward); float num2 = (num ? size.x : size.z) / 2f + 0.02f; float num3 = (num ? size.z : size.x); float[] array2 = new float[2] { 1f, -1f }; foreach (float num4 in array2) { GameObject val4 = new GameObject("sign_text"); val4.transform.SetParent(((Component)this).transform, false); val4.transform.localPosition = val3 * num4 * num2; val4.transform.localRotation = Quaternion.LookRotation(-val3 * num4); TextMeshPro obj = val4.AddComponent<TextMeshPro>(); ((TMP_Text)obj).font = val; ((TMP_Text)obj).rectTransform.sizeDelta = new Vector2(num3 * 0.9f, size.y * 0.8f); ((TMP_Text)obj).enableAutoSizing = true; ((TMP_Text)obj).fontSizeMin = 0.5f; ((TMP_Text)obj).fontSizeMax = 20f; ((TMP_Text)obj).alignment = (TextAlignmentOptions)514; ((Graphic)obj).color = Color.white; ((TMP_Text)obj).richText = true; ((TMP_Text)obj).text = text; } } } } public class MapTitle : MonoBehaviour { public string text = ""; private TextMeshPro tmp; private IEnumerator Start() { yield return (object)new WaitForSeconds(0.5f); TMP_FontAsset val = null; TMP_Text[] array = Object.FindObjectsByType<TMP_Text>((FindObjectsSortMode)0); foreach (TMP_Text val2 in array) { if ((Object)(object)val2 != (Object)null && (Object)(object)val2.font != (Object)null && ((Behaviour)val2).isActiveAndEnabled) { val = val2.font; break; } } if (!((Object)(object)val == (Object)null)) { GameObject val3 = new GameObject("title_text"); val3.transform.SetParent(((Component)this).transform, false); tmp = val3.AddComponent<TextMeshPro>(); ((TMP_Text)tmp).font = val; ((TMP_Text)tmp).fontSize = 3f; ((TMP_Text)tmp).enableWordWrapping = false; ((TMP_Text)tmp).alignment = (TextAlignmentOptions)514; ((Graphic)tmp).color = Color.white; ((TMP_Text)tmp).outlineWidth = 0.2f; ((TMP_Text)tmp).outlineColor = Color32.op_Implicit(Color.black); ((TMP_Text)tmp).richText = true; ((TMP_Text)tmp).text = text; } } private void LateUpdate() { //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_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0064: 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) Camera main = Camera.main; if (!((Object)(object)tmp == (Object)null) && !((Object)(object)main == (Object)null)) { Vector3 val = tmp.transform.position - ((Component)main).transform.position; val.y = 0f; if (((Vector3)(ref val)).sqrMagnitude > 0.0001f) { tmp.transform.rotation = Quaternion.LookRotation(val); } } } } public static class MatTools { private static readonly Dictionary<(Material, Color, bool), Material> cache = new Dictionary<(Material, Color, bool), Material>(); private static readonly Dictionary<Color, Texture2D> colorTex = new Dictionary<Color, Texture2D>(); public static Material Tint(Material src, Color color, bool glow) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0046: 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_0053: Expected O, but got Unknown //IL_0054: 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_0078: 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_008d: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Expected O, but got Unknown //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_0286: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)src == (Object)null) { return null; } if (cache.TryGetValue((src, color, glow), out var value) && (Object)(object)value != (Object)null) { return value; } if (!colorTex.TryGetValue(color, out var value2) || (Object)(object)value2 == (Object)null) { value2 = new Texture2D(2, 2) { filterMode = (FilterMode)0 }; value2.SetPixels(Enumerable.Repeat<Color>(color, 4).ToArray()); value2.Apply(); colorTex[color] = value2; } value = new Material(src) { name = (glow ? "WKMap_GlowLit_" : "WKMap_GlowDull_") + ColorUtility.ToHtmlStringRGB(color) }; string[] texturePropertyNames = value.GetTexturePropertyNames(); foreach (string text in texturePropertyNames) { string text2 = text.ToLowerInvariant(); if (!((Object)(object)value.GetTexture(text) == (Object)null) && !text2.Contains("noise") && !text2.Contains("normal") && !text2.Contains("bump")) { value.SetTexture(text, (Texture)(object)((!glow && text2.Contains("emis")) ? Texture2D.blackTexture : value2)); } } if (!glow) { texturePropertyNames = value.GetPropertyNames((MaterialPropertyType)2); foreach (string text3 in texturePropertyNames) { if (text3.ToLowerInvariant().Contains("emis")) { value.SetColor(text3, Color.black); } } texturePropertyNames = value.GetPropertyNames((MaterialPropertyType)0); foreach (string text4 in texturePropertyNames) { string text5 = text4.ToLowerInvariant(); if (text5.Contains("emis") || text5.Contains("gloss") || text5.Contains("smooth") || text5.Contains("metal") || text5.Contains("spec")) { value.SetFloat(text4, 0f); } } value.DisableKeyword("_EMISSION"); } if (value.HasProperty("_EmissionMultiplier")) { value.SetFloat("_EmissionMultiplier", glow ? 3f : 0f); } if (value.HasProperty("_ShimmerColor")) { value.SetColor("_ShimmerColor", color); } if (value.HasProperty("_Shimmer")) { value.SetFloat("_Shimmer", glow ? 1f : 0f); } if (value.HasProperty("_ShimmerSpeed")) { value.SetFloat("_ShimmerSpeed", 2f); } if (value.HasProperty("_ShimmerFrequency")) { value.SetFloat("_ShimmerFrequency", 1f); } cache[(src, color, glow)] = value; return value; } public static GameObject Lamp(Transform parent, Vector3 worldPos, Color color, float range) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: 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_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0042: 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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: 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_008c: Expected O, but got Unknown GameObject val = new GameObject("map_lamp"); val.transform.SetParent(parent, false); val.transform.position = worldPos; CL_Lamp obj = val.AddComponent<CL_Lamp>(); obj.lampActive = true; obj.range = (obj.curRange = range); obj.startColor = (obj.color = color); obj.intensity = 1f; obj.attentuation = 1; obj.emissiveMult = 1f; obj.bypassLightmap = 1f; obj.fadeStart = (obj.fadeTarget = 1f); return val; } } [HarmonyPatch(typeof(CL_AssetManager), "GetLevelAsset")] internal static class MapLevelLookupPatch { private static bool building; private static void Postfix(string name, ref LevelAssetHolder __result) { //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Expected O, but got Unknown if (__result != null || building || name == null || !name.StartsWith("map_", StringComparison.OrdinalIgnoreCase)) { return; } string text = Plugin.Instance?.FindMapPath(name.Substring(4)); if (text == null) { return; } if ((Object)(object)ENT_Player.playerObject == (Object)null) { __result = new LevelAssetHolder { id = name }; return; } building = true; try { __result = Plugin.Instance.BuildHolder(text); } catch (Exception arg) { Plugin.Log.LogError((object)$"Building {name} for a level list failed: {arg}"); } finally { building = false; } if (__result != null) { Plugin.Log.LogInfo((object)("Built '" + __result.id + "' from " + text + " for a level list.")); } } } internal static class StartPlatform { internal const float Size = 27.57f; internal static void Check(M_Level level) { //IL_006f: 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_0080: 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_008b: 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_0095: 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_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Expected O, but got Unknown //IL_0122: 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_0136: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_016d: 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_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01d5: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Unknown result type (might be due to invalid IL or missing references) //IL_01f0: Unknown result type (might be due to invalid IL or missing references) WorldLoader instance = WorldLoader.instance; BranchInfo val = ((instance != null) ? instance.GetCurrentBranch() : null); if (val != null && val.levelTracker.Count != 0 && !((Object)(object)val.levelTracker[0].GetLevel() != (Object)(object)level) && !((Object)(object)level.spawnPosition == (Object)null) && !((Object)(object)((Component)level).transform.Find("start_platform") != (Object)null)) { Vector3 position = level.spawnPosition.position; ENT_Player p = ENT_Player.playerObject; RaycastHit[] array = (from h in Physics.RaycastAll(position + Vector3.up * 0.5f, Vector3.down, 3.5f, -1, (QueryTriggerInteraction)1) where (Object)(object)p == (Object)null || !((Component)((RaycastHit)(ref h)).collider).transform.IsChildOf(((Component)p).transform.root) select h).ToArray(); float num = ((array.Length != 0) ? (array.Min((RaycastHit h) => ((RaycastHit)(ref h)).point.y) - 2.5f) : (position.y - 1.2f)); GameObject val2 = new GameObject("start_platform"); val2.transform.SetParent(((Component)level).transform, false); val2.transform.position = new Vector3(position.x, num - 0.1f, position.z); val2.transform.rotation = ((Component)level).transform.rotation; val2.AddComponent<BoxCollider>().size = new Vector3(27.57f, 0.2f, 27.57f); Plugin.Log.LogInfo((object)string.Format("Start platform under '{0}' at {1} ({2}).", level.levelName, val2.transform.position, (array.Length != 0) ? "2.5 m under the floor" : "no floor under the spawn")); if ((Object)(object)p != (Object)null && ((Component)p).transform.position.y < position.y - 0.5f) { ((GameEntity)p).Teleport(position, level.spawnPosition.rotation, false); } } } } internal static class Links { private static readonly Dictionary<Type, FieldInfo[]> fields = new Dictionary<Type, FieldInfo[]>(); private static readonly FieldInfo calls = typeof(UnityEventBase).GetField("m_PersistentCalls", BindingFlags.Instance | BindingFlags.NonPublic); private static readonly MethodInfo dirty = typeof(UnityEventBase).GetMethod("DirtyPersistentCalls", BindingFlags.Instance | BindingFlags.NonPublic); public static void Each(Component c, Func<Object, Object> swap) { if (!(c is MonoBehaviour)) { return; } try { Walk(c, swap, 0); } catch (Exception ex) { Plugin.Log.LogDebug((object)("links: " + ((object)c).GetType().Name + ": " + ex.Message)); } } private static object Walk(object obj, Func<Object, Object> swap, int depth) { if (obj == null || depth > 4) { return obj; } FieldInfo[] array = Fields(obj.GetType()); foreach (FieldInfo fieldInfo in array) { object value = fieldInfo.GetValue(obj); if (value != null) { object obj2 = Value(value, fieldInfo.FieldType, swap, depth); if (obj2 != value || fieldInfo.FieldType.IsValueType) { fieldInfo.SetValue(obj, obj2); } } } return obj; } private static object Value(object v, Type type, Func<Object, Object> swap, int depth) { Object val = (Object)((v is Object) ? v : null); if (val != null) { object obj; if (!(val == (Object)null)) { obj = swap(val); if (obj == null) { return v; } } else { obj = v; } return obj; } UnityEventBase val2 = (UnityEventBase)((v is UnityEventBase) ? v : null); if (val2 != null) { Event(val2, swap); return v; } if (v is string || type.IsPrimitive || type.IsEnum) { return v; } if (v is IList list) { Type type2 = (type.IsArray ? type.GetElementType() : (type.IsGenericType ? type.GetGenericArguments()[0] : typeof(object))); if (type2.IsPrimitive || type2.IsEnum || type2 == typeof(string) || !Interesting(type2)) { return v; } for (int i = 0; i < list.Count; i++) { object obj2 = list[i]; if (obj2 != null) { object obj3 = Value(obj2, obj2.GetType(), swap, depth + 1); if (obj3 != obj2 || type2.IsValueType) { list[i] = obj3; } } } return v; } if (Interesting(type) && !typeof(Object).IsAssignableFrom(type)) { return Walk(v, swap, depth + 1); } return v; } private static bool Interesting(Type t) { if (!typeof(Object).IsAssignableFrom(t) && !typeof(UnityEventBase).IsAssignableFrom(t)) { if (t.IsSerializable) { return t.Assembly.GetName().Name == "Assembly-CSharp"; } return false; } return true; } private static void Event(UnityEventBase ev, Func<Object, Object> swap) { object obj = calls?.GetValue(ev); if (obj == null || !(obj.GetType().GetField("m_Calls", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(obj) is IList list)) { return; } bool flag = false; foreach (object item in list) { if (item == null) { continue; } FieldInfo field = item.GetType().GetField("m_Target", BindingFlags.Instance | BindingFlags.NonPublic); object? obj2 = field?.GetValue(item); Object val = (Object)((obj2 is Object) ? obj2 : null); if (val != null && val != (Object)null) { Object val2 = swap(val); if (val2 != val) { field.SetValue(item, val2); flag = true; } } object obj3 = item.GetType().GetField("m_Arguments", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(item); FieldInfo fieldInfo = obj3?.GetType().GetField("m_ObjectArgument", BindingFlags.Instance | BindingFlags.NonPublic); object? obj4 = fieldInfo?.GetValue(obj3); Object val3 = (Object)((obj4 is Object) ? obj4 : null); if (val3 != null && val3 != (Object)null) { Object val4 = swap(val3); if (val4 != val3) { fieldInfo.SetValue(obj3, val4); flag = true; } } } if (flag) { dirty?.Invoke(ev, null); } } private static FieldInfo[] Fields(Type t) { if (fields.TryGetValue(t, out var value)) { return value; } List<FieldInfo> list = new List<FieldInfo>(); Type type = t; while (type != null && type != typeof(MonoBehaviour) && type != typeof(object)) { FieldInfo[] array = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in array) { if ((!fieldInfo.IsNotSerialized && !fieldInfo.IsInitOnly && (fieldInfo.IsPublic || ((MemberInfo)fieldInfo).GetCustomAttribute<SerializeField>() != null) && Interesting(fieldInfo.FieldType)) || ListOf(fieldInfo)) { list.Add(fieldInfo); } } type = type.BaseType; } return fields[t] = list.ToArray(); } private static bool ListOf(FieldInfo fi) { if (fi.IsNotSerialized || fi.IsInitOnly || (!fi.IsPublic && ((MemberInfo)fi).GetCustomAttribute<SerializeField>() == null)) { return false; } Type fieldType = fi.FieldType; Type type = (fieldType.IsArray ? fieldType.GetElementType() : ((fieldType.IsGenericType && typeof(IList).IsAssignableFrom(fieldType)) ? fieldType.GetGenericArguments()[0] : null)); if (type != null) { return Interesting(type); } return false; } } public class MapPartInfo { public GameObject GameObject; public string Name; public IReadOnlyList<string> Tags; public Bounds LocalBounds; public Vector3 Scale; public int SolidLayer; public string MapName; public bool Has(string word) { return Find(word) != null; } public string Find(string word) { foreach (string tag in Tags) { if (string.Equals(WKMapLoader.Tags.Word(tag), word, StringComparison.OrdinalIgnoreCase)) { return tag; } } return null; } public string[] Args(string word) { string text = Find(word); if (text != null) { return WKMapLoader.Tags.Args(text); } return new string[0]; } } public static class MapApi { internal static readonly Dictionary<string, Action<MapPartInfo>> tags = new Dictionary<string, Action<MapPartInfo>>(StringComparer.OrdinalIgnoreCase); internal static readonly Dictionary<string, Action<string[]>> actions = new Dictionary<string, Action<string[]>>(StringComparer.OrdinalIgnoreCase); internal static readonly Dictionary<string, Func<string[], string>> presets = new Dictionary<string, Func<string[], string>>(StringComparer.OrdinalIgnoreCase); internal static readonly Dictionary<string, Action<string[]>> commands = new Dictionary<string, Action<string[]>>(StringComparer.OrdinalIgnoreCase); public static bool InCustomMap => Plugin.InCustomMap(); public static event Action MapReset; public static event Action Tick; public static void RegisterTag(string word, Action<MapPartInfo> onBuild) { tags[word] = onBuild; } public static void RegisterAction(string word, Action<string[]> run) { actions[word] = run; } public static void RegisterPreset(string word, Func<string[], string> expand) { presets[word] = expand; } public static void RegisterCommand(string name, Action<string[]> run) { commands[name] = run; Plugin.Instance?.ForceCommandRefresh(); } internal static void RaiseReset() { try { MapApi.MapReset?.Invoke(); } catch (Exception ex) { Plugin.Log.LogError((object)ex); } } internal static void RaiseTick() { try { MapApi.Tick?.Invoke(); } catch (Exception ex) { Plugin.Log.LogError((object)ex); } } public static void ShowTitle(string text) { MapSession.ShowTitle(text); } public static void Say(string text) { Plugin.Say(text); } public static void RunAction(string tag) { Actions.Run(tag, null); } public static string GetVar(string name) { return Vars.Get(name); } public static void SetVar(string name, string value) { Vars.Set(name, value); } public static string Expand(string text) { return Vars.Expand(text); } } internal class MapPart { public string Name = ""; public List<string> Tags = new List<string>(); public List<Vector3> Verts = new List<Vector3>(); public List<int[]> Faces = new List<int[]>(); public List<string> FaceMats = new List<string>(); public Vector3 Position; public Quaternion Rotation = Quaternion.identity; public Vector3 Scale = Vector3.one; public Color? LightColor; public float? LightRange; public bool HasMesh => Faces.Count > 0; public Vector3 WorldCenter { get { //IL_0010: 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_001b: 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_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) if (!HasMesh) { return Position; } Quaternion rotation = Rotation; Bounds val = LocalBounds(); return rotation * ((Bounds)(ref val)).center; } } public Bounds LocalBounds() { //IL_000e: 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_0019: 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_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0055: 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_00ba: 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 (Verts.Count == 0) { return new Bounds(Quaternion.Inverse(Rotation) * Position, Vector3.zero); } Bounds result = default(Bounds); ((Bounds)(ref result))..ctor(Verts[(Faces.Count > 0) ? Faces[0][0] : 0], Vector3.zero); foreach (int[] face in Faces) { foreach (int index in face) { ((Bounds)(ref result)).Encapsulate(Verts[index]); } } return result; } public Bounds WorldBounds() { //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_003a: 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_0009: 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_0013: 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_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0078: 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) if (!HasMesh) { return new Bounds(Position, Vector3.zero); } Bounds result = default(Bounds); ((Bounds)(ref result))..ctor(Rotation * Verts[Faces[0][0]], Vector3.zero); foreach (int[] face in Faces) { foreach (int index in face) { ((Bounds)(ref result)).Encapsulate(Rotation * Verts[index]); } } return result; } } internal class MapData { public List<MapPart> Parts = new List<MapPart>(); public Dictionary<string, Color> MatColors = new Dictionary<string, Color>(StringComparer.OrdinalIgnoreCase); public bool Legacy; } internal static class GlbReader { public static MapData Read(string path) { //IL_0251: Unknown result type (might be due to invalid IL or missing references) //IL_0436: Unknown result type (might be due to invalid IL or missing references) byte[] bin = null; byte[] array = File.ReadAllBytes(path); string text; if (array.Length >= 12 && BitConverter.ToUInt32(array, 0) == 1179937895) { text = null; int num; for (int i = 12; i + 8 <= array.Length; i += 8 + num) { num = BitConverter.ToInt32(array, i); switch (BitConverter.ToUInt32(array, i + 4)) { case 1313821514u: text = Encoding.UTF8.GetString(array, i + 8, num); break; case 5130562u: bin = new byte[num]; Buffer.BlockCopy(array, i + 8, bin, 0, num); break; } } if (text == null) { throw new Exception("no JSON chunk in .glb"); } } else { text = Encoding.UTF8.GetString(array); } Dictionary<string, object> dictionary = (Dictionary<string, object>)Json.Parse(text); MapData data = new MapData(); List<byte[]> buffers = Arr(dictionary, "buffers").Select((object b, int num6) => LoadBuffer((Dictionary<string, object>)b, (num6 == 0) ? bin : null, path)).ToList(); List<Dictionary<string, object>> views = Arr(dictionary, "bufferViews").Cast<Dictionary<string, object>>().ToList(); List<Dictionary<string, object>> accessors = Arr(dictionary, "accessors").Cast<Dictionary<string, object>>().ToList(); List<Dictionary<string, object>> meshes = Arr(dictionary, "meshes").Cast<Dictionary<string, object>>().ToList(); List<Dictionary<string, object>> nodes = Arr(dictionary, "nodes").Cast<Dictionary<string, object>>().ToList(); List<string> matNames = new List<string>(); foreach (Dictionary<string, object> item in Arr(dictionary, "materials")) { string text2 = Str(item, "name") ?? ("material" + matNames.Count); matNames.Add(text2); if (item.TryGetValue("pbrMetallicRoughness", out var value) && value is Dictionary<string, object> dictionary2 && dictionary2.TryGetValue("baseColorFactor", out var value2)) { float[] array2 = ((List<object>)value2).Select(Convert.ToSingle).ToArray(); data.MatColors[text2] = new Color(array2[0], array2[1], array2[2]); } } List<Dictionary<string, object>> lights = new List<Dictionary<string, object>>(); if (Obj(dictionary, "extensions") is Dictionary<string, object> d && Obj(d, "KHR_lights_punctual") is Dictionary<string, object> d2) { lights = Arr(d2, "lights").Cast<Dictionary<string, object>>().ToList(); } int[] parent = new int[nodes.Count]; for (int num2 = 0; num2 < nodes.Count; num2++) { parent[num2] = -1; } for (int num3 = 0; num3 < nodes.Count; num3++) { foreach (object item2 in Arr(nodes[num3], "children")) { parent[Convert.ToInt32(item2)] = num3; } } Matrix4x4[] world = (Matrix4x4[])(object)new Matrix4x4[nodes.Count]; Dictionary<int, MapPart> partOf = new Dictionary<int, MapPart>(); List<object> list = Arr(dictionary, "scenes"); object value3; int num4 = (dictionary.TryGetValue("scene", out value3) ? Convert.ToInt32(value3) : 0); foreach (int item3 in (list.Count > num4) ? Arr((Dictionary<string, object>)list[num4], "nodes").Select(Convert.ToInt32) : (from num6 in Enumerable.Range(0, nodes.Count) where parent[num6] < 0 select num6)) { Walk(item3, Matrix4x4.identity); } for (int num5 = 0; num5 < nodes.Count; num5++) { if (IsTag(num5) && partOf.TryGetValue(parent[num5], out var value4)) { value4.Tags.AddRange(Tags.Split(Str(nodes[num5], "name") ?? "")); } } foreach (MapPart part in data.Parts) { if (part.Tags.Count == 0) { part.Tags.AddRange(Tags.FromOwnName(part.Name)); } } return data; bool IsTag(int num6) { if (parent[num6] >= 0 && !nodes[num6].ContainsKey("mesh") && Arr(nodes[num6], "children").Count == 0) { return LightOf(nodes[num6]) < 0; } return false; } void Walk(int num6, Matrix4x4 parentM) { //IL_0014: 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_001b: 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_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: 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_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //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_02a1: Unknown result type (might be due to invalid IL or missing references) //IL_0222: 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) Dictionary<string, object> dictionary3 = nodes[num6]; world[num6] = parentM * LocalMatrix(dictionary3); if (!IsTag(num6)) { MapPart mapPart = new MapPart { Name = (Str(dictionary3, "name") ?? ("node" + num6)), Position = Vector4.op_Implicit(((Matrix4x4)(ref world[num6])).GetColumn(3)), Rotation = ((Matrix4x4)(ref world[num6])).rotation, Scale = ((Matrix4x4)(ref world[num6])).lossyScale }; int num7 = LightOf(dictionary3); if (num7 >= 0 && parent[num6] >= 0 && Arr(nodes[parent[num6]], "children").Count == 1 && partOf.TryGetValue(parent[num6], out var value5) && !value5.HasMesh) { mapPart = value5; } if (num7 >= 0 && num7 < lights.Count) { Dictionary<string, object> dictionary4 = lights[num7]; float[] array3 = ((Obj(dictionary4, "color") is List<object> source) ? source.Select(Convert.ToSingle).ToArray() : new float[3] { 1f, 1f, 1f }); mapPart.LightColor = new Color(array3[0], array3[1], array3[2]); object value6; float num8 = (dictionary4.TryGetValue("intensity", out value6) ? Convert.ToSingle(value6) : 1f); mapPart.LightRange = (dictionary4.TryGetValue("range", out var value7) ? Convert.ToSingle(value7) : Mathf.Clamp(Mathf.Sqrt(num8) * 2f, 4f, 40f)); } if (dictionary3.TryGetValue("mesh", out var value8)) { AddMesh(mapPart, meshes[Convert.ToInt32(value8)], world[num6], accessors, views, buffers, matNames); } partOf[num6] = mapPart; if (!data.Parts.Contains(mapPart)) { data.Parts.Add(mapPart); } } foreach (object item4 in Arr(dictionary3, "children")) { Walk(Convert.ToInt32(item4), world[num6]); } } } private static int LightOf(Dictionary<string, object> n) { if (!(Obj(n, "extensions") is Dictionary<string, object> d) || !(Obj(d, "KHR_lights_punctual") is Dictionary<string, object> dictionary) || !dictionary.TryGetValue("light", out var value)) { return -1; } return Convert.ToInt32(value); } private static Matrix4x4 LocalMatrix(Dictionary<string, object> n) { //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: 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_00fe: 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_0068: 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) //IL_0072: 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_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0078: 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_007f: Unknown result type (might be due to invalid IL or missing references) if (Obj(n, "matrix") is List<object> list) { Matrix4x4 val = default(Matrix4x4); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { ((Matrix4x4)(ref val))[j, i] = Convert.ToSingle(list[i * 4 + j]); } } Matrix4x4 val2 = Matrix4x4.Scale(new Vector3(-1f, 1f, 1f)); return val2 * val * val2; } float[] array = Floats(n, "translation", default(float), default(float), default(float)); float[] array2 = Floats(n, "rotation", 0f, 0f, 0f, 1f); float[] array3 = Floats(n, "scale", 1f, 1f, 1f); return Matrix4x4.TRS(new Vector3(0f - array[0], array[1], array[2]), new Quaternion(array2[0], 0f - array2[1], 0f - array2[2], array2[3]), new Vector3(array3[0], array3[1], array3[2])); } private static void AddMesh(MapPart part, Dictionary<string, object> mesh, Matrix4x4 world, List<Dictionary<string, object>> accessors, List<Dictionary<string, object>> views, List<byte[]> buffers, List<string> matNames) { //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_000b: 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_00c6: 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_00cf: 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) Quaternion val = Quaternion.Inverse(part.Rotation); foreach (Dictionary<string, object> item2 in Arr(mesh, "primitives")) { if ((item2.TryGetValue("mode", out var value) ? Convert.ToInt32(value) : 4) == 4 && ((Dictionary<string, object>)item2["attributes"]).TryGetValue("POSITION", out var value2)) { float[] array = ReadAccessor(accessors[Convert.ToInt32(value2)], views, buffers); int num = array.Length / 3; int count = part.Verts.Count; for (int i = 0; i < num; i++) { Vector3 val2 = ((Matrix4x4)(ref world)).MultiplyPoint3x4(new Vector3(0f - array[i * 3], array[i * 3 + 1], array[i * 3 + 2])); part.Verts.Add(val * val2); } object value3; float[] array2 = (item2.TryGetValue("indices", out value3) ? ReadAccessor(accessors[Convert.ToInt32(value3)], views, buffers) : Enumerable.Range(0, num).Select((Func<int, float>)((int x) => x)).ToArray()); object value4; string item = ((item2.TryGetValue("material", out value4) && Convert.ToInt32(value4) < matNames.Count) ? matNames[Convert.ToInt32(value4)] : ""); for (int num2 = 0; num2 + 2 < array2.Length; num2 += 3) { part.Faces.Add(new int[3] { count + (int)array2[num2], count + (int)array2[num2 + 1], count + (int)array2[num2 + 2] }); part.FaceMats.Add(item); } } } } private static float[] ReadAccessor(Dictionary<string, object> acc, List<Dictionary<string, object>> views, List<byte[]> buffers) { int num = Convert.ToInt32(acc["count"]); int num2 = Str(acc, "type") switch { "SCALAR" => 1, "VEC2" => 2, "VEC3" => 3, "VEC4" => 4, _ => 1, }; int num3 = Convert.ToInt32(acc["componentType"]); int num4; switch (num3) { default: num4 = 1; break; case 5122: case 5123: num4 = 2; break; case 5125: case 5126: num4 = 4; break; } int num5 = num4; float[] array = new float[num * num2]; if (!acc.TryGetValue("bufferView", out var value)) { return array; } Dictionary<string, object> dictionary = views[Convert.ToInt32(value)]; byte[] array2 = buffers[Convert.ToInt32(dictionary["buffer"])]; object value2; object value3; int num6 = (dictionary.TryGetValue("byteOffset", out value2) ? Convert.ToInt32(value2) : 0) + (acc.TryGetValue("byteOffset", out value3) ? Convert.ToInt32(value3) : 0); object value4; int num7 = (dictionary.TryGetValue("byteStride", out value4) ? Convert.ToInt32(value4) : (num2 * num5)); for (int i = 0; i < num; i++) { for (int j = 0; j < num2; j++) { int num8 = num6 + i * num7 + j * num5; float[] array3 = array; int num9 = i * num2 + j; array3[num9] = num3 switch { 5126 => BitConverter.ToSingle(array2, num8), 5125 => BitConverter.ToUInt32(array2, num8), 5123 => (int)BitConverter.ToUInt16(array2, num8), 5122 => BitConverter.ToInt16(array2, num8), 5121 => (int)array2[num8], _ => (sbyte)array2[num8], }; } } return array; } private static byte[] LoadBuffer(Dictionary<string, object> b, byte[] glbBin, string path) { string text = Str(b, "uri"); if (text == null) { return glbBin ?? new byte[0]; } if (text.StartsWith("data:")) { return Convert.FromBase64String(text.Substring(text.IndexOf(',') + 1)); } return File.ReadAllBytes(Path.Combine(Path.GetDirectoryName(path), Uri.UnescapeDataString(text))); } private static List<object> Arr(Dictionary<string, object> d, string key) { if (!d.TryGetValue(key, out var value) || !(value is List<object> result)) { return new List<object>(); } return result; } private static object Obj(Dictionary<string, object> d, string key) { if (!d.TryGetValue(key, out var value)) { return null; } return value; } private static string Str(Dictionary<string, object> d, string key) { if (!d.TryGetValue(key, out var value)) { return null; } return value as string; } private static float[] Floats(Dictionary<string, object> d, string key, params float[] def) { if (!d.TryGetValue(key, out var value) || !(value is List<object> source)) { return def; } return source.Select(Convert.ToSingle).ToArray(); } } internal static class Json { public static object Parse(string s) { int i = 0; return Value(s, ref i); } private static void Ws(string s, ref int i) { while (i < s.Length && char.IsWhiteSpace(s[i])) { i++; } } private static object Value(string s, ref int i) { Ws(s, ref i); switch (s[i]) { case '{': { Dictionary<string, object> dictionary = new Dictionary<string, object>(); i++; Ws(s, ref i); if (s[i] == '}') { i++; return dictionary; } do { Ws(s, ref i); string key = Str(s, ref i); Ws(s, ref i); i++; dictionary[key] = Value(s, ref i); Ws(s, ref i); } while (s[i++] != '}'); return dictionary; } case '[': { List<object> list = new List<object>(); i++; Ws(s, ref i); if (s[i] == ']') { i++; return list; } do { list.Add(Value(s, ref i)); Ws(s, ref i); } while (s[i++] != ']'); return list; } case '"': return Str(s, ref i); default: { if (string.CompareOrdinal(s, i, "true", 0, 4) == 0) { i += 4; return true; } if (string.CompareOrdinal(s, i, "false", 0, 5) == 0) { i += 5; return false; } if (string.CompareOrdinal(s, i, "null", 0, 4) == 0) { i += 4; return null; } int num = i; while (i < s.Length && "+-0123456789.eE".IndexOf(s[i]) >= 0) { i++; } return double.Parse(s.Substring(num, i - num), CultureInfo.InvariantCulture); } } } private static string Str(string s, ref int i) { StringBuilder stringBuilder = new StringBuilder(); i++; while (s[i] != '"') { if (s[i] == '\\') { char c = s[++i]; switch (c) { case 'n': stringBuilder.Append('\n'); break; case 't': stringBuilder.Append('\t'); break; case 'r': stringBuilder.Append('\r'); break; case 'b': stringBuilder.Append('\b'); break; case 'f': stringBuilder.Append('\f'); break; case 'u': stringBuilder.Append((char)Convert.ToInt32(s.Substring(i + 1, 4), 16)); i += 4; break; default: stringBuilder.Append(c); break; } i++; } else { stringBuilder.Append(s[i++]); } } i++; return stringBuilder.ToString(); } } public class MapTrigger : MonoBehaviour { public enum Kind { Button, Pad, Zone, None } public Kind kind; public bool onStart; public string[] actions = new string[0]; public Vector3 boxCenter; public Vector3 boxSize; internal static readonly List<MapTrigger> All = new List<MapTrigger>(); private bool inside; private void OnEnable() { All.Add(this); } private void OnDisable() { All.Remove(this); } private void Start() { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Expected O, but got Unknown //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected O, but got Unknown if (kind != Kind.Button) { return; } CL_Button[] componentsInChildren = ((Component)this).GetComponentsInChildren<CL_Button>(true); foreach (CL_Button val in componentsInChildren) { if (val.activeEvent == null) { val.activeEvent = new UnityEvent(); } val.activeEvent.AddListener(new UnityAction(Fire)); } } private void Update() { //IL_002f: 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_0039: 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_0070: 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_0091: 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_00c2: 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_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_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_0063: 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_00ca: Unknown result type (might be due to invalid IL or missing references) if (kind != Kind.Pad && kind != Kind.Zone) { return; } ENT_Player playerObject = ENT_Player.playerObject; if (!((Object)(object)playerObject == (Object)null)) { Vector3 val = ((Component)this).transform.InverseTransformPoint(((Component)playerObject).transform.position); Bounds val2 = ((kind == Kind.Pad) ? new Bounds(boxCenter + Vector3.up * (boxSize.y / 2f + 1.2f), new Vector3(boxSize.x + 0.2f, 2.6f, boxSize.z + 0.2f)) : new Bounds(boxCenter, boxSize + Vector3.one * 0.2f)); bool flag = ((Bounds)(ref val2)).Contains(val); if (flag && !inside) { Fire(); } inside = flag; } } public void Fire() { Actions.RunAll(actions, this); } internal Vector3 RespawnPoint() { //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_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: 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_0049: 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_0062: Unknown result type (might be due to invalid IL or missing references) if (kind == Kind.Pad) { return ((Component)this).transform.TransformPoint(boxCenter + Vector3.up * (boxSize.y / 2f)) + Vector3.up * 1.1f; } if (!((Object)(object)ENT_Player.playerObject != (Object)null)) { return ((Component)this).transform.position; } return ((Component)ENT_Player.playerObject).transform.position; } } public class MapPass : MonoBehaviour { private void Start() { Collider[] components = ((Component)this).GetComponents<Collider>(); foreach (Collider obj in components) { MeshCollider val = (MeshCollider)(object)((obj is MeshCollider) ? obj : null); if (val != null) { val.convex = true; } obj.isTrigger = true; } } } public class MapPoint : MonoBehaviour { public string id; internal static readonly List<MapPoint> All = new List<MapPoint>(); private void OnEnable() { All.Add(this); } private void OnDisable() { All.Remove(this); } } internal static class Actions { public static void RunAll(IEnumerable<string> tags, MapTrigger src) { List<string> source = tags.ToList(); foreach (string item in source.Where((string t) => Tags.Word(t) == "clear")) { Run(item, src); } foreach (string item2 in source.Where((string t) => Tags.Word(t) != "clear")) { Run(item2, src); } } public static void Run(string tag, MapTrigger src) { //IL_0490: Unknown result type (might be due to invalid IL or missing references) //IL_039a: Unknown result type (might be due to invalid IL or missing references) //IL_0495: Unknown result type (might be due to invalid IL or missing references) //IL_0488: Unknown result type (might be due to invalid IL or missing references) //IL_047b: 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_03d5: 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_04c7: Unknown result type (might be due to invalid IL or missing references) //IL_04a8: 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_04af: Unknown result type (might be due to invalid IL or missing references) //IL_04b4: Unknown result type (might be due to invalid IL or missing references) tag = Updates.Part(tag); string text = Tags.Word(tag); string[] a = Tags.Args(tag); CultureInfo ic = CultureInfo.InvariantCulture; ENT_Player playerObject = ENT_Player.playerObject; try { switch (text) { case "giveitem": { int count = Mathf.Max(1, (int)Num(1, 1f)); int num = ItemTools.Give(a[0], count); if (num > 0) { MapSession.ShowTitle($"+{num} {ItemTools.ShortName(a[0], num)}"); } break; } case "placeentity": if ((Object)(object)src != (Object)null) { Entities.Place(a[0], Mathf.Max(1, (int)Num(1, 1f)), Entities.SpotOn(((Component)src).gameObject), ((Component)src).transform); } break; case "placeprefab": if ((Object)(object)src != (Object)null) { Prefabs.Place(a[0], Entities.SpotOn(((Component)src).gameObject), ((Component)src).transform.rotation * Vector3.forward, ((Component)src).transform, Prefabs.Wall(a, ((Component)src).transform), Prefabs.Size(a)); } break; case "keepitem": MapSession.Bind(a[0], Mathf.Max(1, (int)Num(1, 1f))); break; case "takeitem": MapSession.Unbind(a[0]); break; case "clear": if (!ItemTools.ClearInventory()) { Plugin.Log.LogWarning((object)"Could not clear inventory."); } MapSession.GiveBound(); break; case "checkpoint": { Vector3 val = (((Object)(object)src != (Object)null) ? src.RespawnPoint() : (((Object)(object)playerObject != (Object)null) ? ((Component)playerObject).transform.position : Vector3.zero)); if (MapSession.SavedRespawn.HasValue) { Vector3 val2 = MapSession.SavedRespawn.Value - val; if (((Vector3)(ref val2)).sqrMagnitude < 1f) { break; } } MapSession.SavedRespawn = val; MapSession.ShowTitle("Checkpoint"); break; } case "reset": MapSession.OnFall(); break; case "kill": if (playerObject != null) { ((GameEntity)playerObject).Kill(""); } break; case "teleport": MapSession.Teleport((a.Length != 0) ? a[0] : null); break; case "msg": MapSession.ShowTitle(Vars.Expand(Tags.Text(Tags.Rest(tag)))); break; case "set": Vars.Set(a[0], Tags.Text(Tags.Rest(tag).Substring(a[0].Length))); break; case "add": Vars.Set(a[0], (Vars.Num(a[0]) + Num(1, 1f)).ToString(ic)); break; case "timer": Vars.Timer(a[0]); break; case "giveperk": Effects.Perk(a[0], Num(1, 0f)); break; case "applybinding": Effects.Binding(a[0], Num(1, 0f)); break; case "givetrinket": if (ItemTools.EnsureTrinket(a[0])) { MapSession.ShowTitle("+" + (ItemTools.FindTrinket(a[0], quiet: true)?.title ?? a[0])); } break; case "giveeffect": Effects.Effect(a[0], (a.Length > 1) ? new float?(Num(1, 0f)) : ((float?)null)); break; case "win": MapSession.Win(); break; case "map": Plugin.Instance?.LoadMapSoon(a[0]); break; case "launch": Launch.Up(Num(0, 10f)); break; default: { if (MapApi.actions.TryGetValue(text, out var value)) { value(a); } else { Plugin.Say("Unknown action '" + tag + "'."); } break; } } } catch (Exception ex) { Plugin.Say("Action '" + tag + "' failed: " + ex.Message); Plugin.Log.LogError((object)ex); } float Num(int i, float def) { if (a.Length <= i || !float.TryParse(a[i], NumberStyles.Float, ic, out var result)) { return def; } return result; } } } internal static class Launch { public static void Up(float metres) { //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_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: 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) ENT_Player playerObject = ENT_Player.playerObject; if ((Object)(object)playerObject == (Object)null || metres <= 0f) { return; } FieldInfo field = typeof(ENT_Player).GetField("gravityMult", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); float g = playerObject.gravity * ((field?.GetValue(playerObject) is float num) ? num : 1f); float dragCoefficient = playerObject.dragCoefficient; float fixedDeltaTime = Time.fixedDeltaTime; float num2 = 0f; float num3 = 1f; while (Apex(num3, g, dragCoefficient, fixedDeltaTime) < metres && num3 < 1000f) { num3 *= 2f; } for (int i = 0; i < 40; i++) { float num4 = (num2 + num3) / 2f; if (Apex(num4, g, dragCoefficient, fixedDeltaTime) < metres) { num2 = num4; } else { num3 = num4; } } Vector3 playerUpVector = playerObject.GetPlayerUpVector(); ((GameEntity)playerObject).SetDirectionalForce(playerUpVector * num3 * 10f); } private static float Apex(float v, float g, float drag, float dt) { float num = 0f; for (int i = 0; i < 20000; i++) { if (!(v > 0f)) { break; } v += g * dt; if (v <= 0f) { break; } v -= Mathf.Min(drag * v * v * dt, v / 2f); num += v * dt * 175f; } return num; } } internal static class Vars { private static readonly Dictionary<string, string> vars = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); private static readonly Dictionary<string, float> bestTimes = new Dictionary<string, float>(StringComparer.OrdinalIgnoreCase); private static float timerStart = -1f; private static float timerStopped; internal static string MapName = ""; public static bool TimerRunning => timerStart >= 0f; private static float TimerValue { get { if (!(timerStart >= 0f)) { return timerStopped; } return Time.time - timerStart; } } public static void Reset() { vars.Clear(); timerStart = -1f; timerStopped = 0f; } public static string Get(string k) { if (!vars.TryGetValue(k, out var value)) { return ""; } return value; } public static void Set(string k, string v) { vars[k] = v; } public static float Num(string k) { if (!float.TryParse(Get(k), NumberStyles.Float, CultureInfo.InvariantCulture, out var result)) { return 0f; } return result; } public static void Timer(string cmd) { switch (cmd.ToLowerInvariant()) { case "start": timerStart = Time.time; break; case "reset": timerStart = -1f; timerStopped = 0f; break; case "stop": if (!(timerStart < 0f)) { timerStopped = Time.time - timerStart; timerStart = -1f; float value; bool flag = !bestTimes.TryGetValue(MapName, out value) || timerStopped < value; if (flag) { bestTimes[MapName] = timerStopped; } MapSession.ShowTitle(Clock(timerStopped) + (flag ? " NEW BEST!" : "")); } break; } } public static string Clock(float t) { return $"{(int)(t / 60f)}:{t % 60f:00.00}"; } public static string Expand(string text) { if (string.IsNullOrEmpty(text) || text.IndexOf('{') < 0) { return text; } return Regex.Replace(text, "\\{(\\w+)\\}", delegate(Match m) { string text2 = m.Groups[1].Value.ToLowerInvariant(); switch (text2) { case "timer": return Clock(TimerValue); case "best": { if (!bestTimes.TryGetValue(MapName, out var value2)) { return "-"; } return Clock(value2); } case "falls": return MapSession.Falls.ToString(); case "map": return MapName; default: { if (!vars.TryGetValue(text2, out var value)) { return "0"; } return value; } } }); } } internal static class Effects { private static readonly List<(Perk perk, float until)> perks = new List<(Perk, float)>(); private static readonly List<string> buffs = new List<string>(); private static float staminaUntil = -1f; public static void Effect(string name, float? value) { ENT_Player playerObject = ENT_Player.playerObject; if (!((Object)(object)playerObject == (Object)null)) { float valueOrDefault = value.GetValueOrDefault(); switch (name.ToLowerInvariant()) { case "refill": Refill(playerObject); break; case "infi_stamina": staminaUntil = ((valueOrDefault > 0f) ? (Time.time + valueOrDefault) : float.MaxValue); Refill(playerObject); break; case "temp_jump": playerObject.AddExtraJumpsOneTime(Mathf.Max(1, (int)(value ?? 1f))); break; case "sticky_hands": Buff("grabAnything", 1f, valueOrDefault); break; case "jump_boost": Buff("addJumpBoost", 0.5f, valueOrDefault); break; default: Buff(name, 1f, valueOrDefault); break; } } } private static void Refill(ENT_Player p) { Hand[] hands = p.hands; foreach (Hand obj in hands) { if (obj != null) { obj.SetGripStrength(999f); } } } public static void Perk(string word, float seconds) { ENT_Player playerObject = ENT_Player.playerObject; if ((Object)(object)playerObject == (Object)null) { return; } Perk val = ItemTools.FindPerk(word); if ((Object)(object)val == (Object)null) { Plugin.Say("No perk matching '" + word + "'. Perks: " + string.Join(", ", from k in CL_AssetManager.GetFullCombinedAssetDatabase().perkAssets where (Object)(object)k != (Object)null select k.id)); } else { Add(playerObject, val, seconds); } } public static void Binding(string word, float seconds) { ENT_Player playerObject = ENT_Player.playerObject; if ((Object)(object)playerObject == (Object)null) { return; } List<Perk> source = CL_AssetManager.GetFullCombinedAssetDatabase().perkAssets.Where((Perk k) => (Object)(object)k != (Object)null && (k.id ?? "").StartsWith("Perk_Binding_")).ToList(); string w = ItemTools.Squash(word); Perk val = ((IEnumerable<Perk>)source).FirstOrDefault((Func<Perk, bool>)((Perk k) => ItemTools.Squash(k.id.Substring("Perk_Binding_".Length)) == w || ItemTools.Squash(k.title) == w)) ?? ((IEnumerable<Perk>)source).FirstOrDefault((Func<Perk, bool>)((Perk k) => ItemTools.Squash(k.id + "|" + k.title).Contains(w))); if ((Object)(object)val == (Object)null) { Plugin.Say("No binding matching '" + word + "'. Bindings: " + string.Join(", ", source.Select((Perk k) => k.id.Substring("Perk_Binding_".Length)))); } else if (!playerObject.HasPerk(val.id)) { Add(playerObject, val, seconds); } } private static void Add(ENT_Player p, Perk asset, float seconds) { Perk item = p.AddPerk(asset, 1, true); perks.Add((item, (seconds > 0f) ? (Time.time + seconds) : float.MaxValue)); } private static void Buff(string id, float amount, float seconds) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown //IL_004d: 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) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Expected O, but got Unknown ENT_Player playerObject = ENT_Player.playerObject; if (!((Object)(object)playerObject == (Object)null)) { string text = "wkmap_" + id; ((GameEntity)playerObject).Buff(new BuffContainer { id = text, buffs = new List<Buff> { new Buff { id = id, maxAmount = amount } }, loseRate = ((seconds > 0f) ? (1f / seconds) : 0f), loseRateEffectedByPerks = false, loseOverTime = (seconds > 0f) }); if (!buffs.Contains(text)) { buffs.Add(text); } } } public static void Tick() { ENT_Player playerObject = ENT_Player.playerObject; if ((Object)(object)playerObject != (Object)null && Time.time < staminaUntil) { Refill(playerObject); } for (int num = perks.Count - 1; num >= 0; num--) { if (Time.time >= perks[num].until) { if ((Object)(object)playerObject != (Object)null && (Object)(object)perks[num].perk != (Object)null) { playerObject.RemovePerk(perks[num].perk, false); } perks.RemoveAt(num); } } } public static void Reset() { ENT_Player playerObject = ENT_Player.playerObject; foreach (var perk in perks) { if ((Object)(object)playerObject != (Object)null && (Object)(object)perk.perk != (Object)null) { playerObject.RemovePerk(perk.perk, false); } } perks.Clear(); foreach (string buff in buffs) { object obj; if (playerObject == null) { obj = null; } else { EntityBuff curBuffs = ((GameEntity)playerObject).curBuffs; obj = ((curBuffs != null) ? curBuffs.GetBuffContainer(buff) : null); } if (obj != null) { ((GameEntity)playerObject).curBuffs.RemoveBuffContainer(buff); } } buffs.Clear(); staminaUntil = -1f; } } internal static class Entities { public static GameObject Find(string name) { List<GameObject> list = new List<GameObject>(); if ((Object)(object)CL_GameManager.gMan != (Object)null && CL_GameManager.gMan.gameEntityPrefabs != null) { list.AddRange(from e in CL_GameManager.gMan.gameEntityPrefabs where (Object)(object)e != (Object)null select ((Component)e).gameObject); } list.AddRange(CL_AssetManager.GetFullCombinedAssetDatabase().itemPrefabs.Where((GameObject p) => (Object)(object)p != (Object)null)); GameObject val = ((IEnumerable<GameObject>)list).FirstOrDefault((Func<GameObject, bool>)((GameObject p) => ((Object)p).name.Equals(name, StringComparison.OrdinalIgnoreCase))); if ((Object)(object)val != (Object)null) { return val; } string n = name.ToLowerInvariant(); string[] words = n.Split(new char[3] { '_', '-', ' ' }, StringSplitOptions.RemoveEmptyEntries); return (from p in list where words.All((string w) => ((Object)p).name.ToLowerInvariant().Contains(w)) where n.Contains("explo") || !((Object)p).name.ToLowerInvariant().Contains("explo") orderby ((Object)p).name.Length select p).FirstOrDefault(); } public static Vector3 SpotOn(GameObject go) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_004d: 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) Renderer component = go.GetComponent<Renderer>(); if ((Object)(object)component == (Object)null) { return go.transform.position; } Bounds bounds = component.bounds; return new Vector3(((Bounds)(ref bounds)).center.x, ((Bounds)(ref bounds)).max.y + 0.3f, ((Bounds)(ref bounds)).center.z); } public static int Place(string name, int count, Vector3 at, Transform near) { //IL_008a: 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_0070: 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_008f: Unknown result type (might be due to invalid IL or missing references) //I