Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of Agartha v1.0.3
Agartha.dll
Decompiled a month agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using Agartha.Core; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using UnityEngine; using UnityEngine.Rendering; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("Agartha")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+4636d100fbe99bbc6da070991aec6c4307b4871e")] [assembly: AssemblyProduct("Agartha")] [assembly: AssemblyTitle("Agartha")] [assembly: AssemblyVersion("1.0.0.0")] namespace Agartha { internal class WhereCommand : CheatCommand { public override string Name => "agartha_where"; public override string Help => "agartha_where - where is the Polar Gate in this world"; protected override void RunCheat(string[] args) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0021: 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_0038: 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_003f: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; Vector3 val = (((Object)(object)localPlayer != (Object)null) ? ((Component)localPlayer).transform.position : Vector3.zero); CheatCommand.Print(GateLocation.TryFindGate(val, out var gatePos) ? $"agartha_where: Polar Gate at {gatePos:F0} ({Vector3.Distance(val, gatePos):F0} m away)" : "agartha_where: this world has no Polar Gate (created before Agartha was installed?)"); } } internal class TpCommand : CheatCommand { public override string Name => "agartha_tp"; public override string Help => "agartha_tp gate|inside - teleport to the Polar Gate or into Agartha"; protected override void RunCheat(string[] args) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0076: 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_006e: 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_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || args.Length != 1 || (args[0] != "gate" && args[0] != "inside")) { CheatCommand.Print(((ConsoleCommand)this).Help); return; } if (!GateLocation.TryFindGate(((Component)localPlayer).transform.position, out var gatePos)) { CheatCommand.Print("agartha_tp: no Polar Gate in this world"); return; } Vector3 val = ((args[0] == "gate") ? GateExit.Target(gatePos) : Arrival.InsideTarget(gatePos)); ((Character)localPlayer).TeleportTo(val, ((Component)localPlayer).transform.rotation, true); CheatCommand.Print("agartha_tp: teleporting to " + args[0]); } } internal static class AgarthaLight { public const string EnvName = "Agartha"; private const string BaseEnv = "Clear"; private static EnvMan _registeredOn; private static bool _forcing; public static void Tick() { //IL_0038: Unknown result type (might be due to invalid IL or missing references) EnvMan instance = EnvMan.instance; Player localPlayer = Player.m_localPlayer; if (!((Object)(object)instance == (Object)null)) { if ((Object)(object)_registeredOn != (Object)(object)instance) { Register(instance); } bool flag = (Object)(object)localPlayer != (Object)null && LocalPocket.IsInside(((Component)localPlayer).transform.position); if (flag != _forcing) { _forcing = flag; instance.SetForceEnvironment(flag ? "Agartha" : ""); } } } private static void Register(EnvMan env) { //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: 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_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: 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_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) _registeredOn = env; _forcing = false; EnvSetup val = env.m_environments.Find((EnvSetup e) => e.m_name == "Clear"); if (val == null) { Plugin.WarnOnce("env", "Environment 'Clear' not found; Agartha keeps the overworld lighting."); return; } EnvSetup val2 = val.Clone(); val2.m_name = "Agartha"; val2.m_default = false; val2.m_isWet = false; val2.m_isFreezing = false; val2.m_isFreezingAtNight = false; val2.m_isCold = false; val2.m_isColdAtNight = false; val2.m_alwaysDark = false; val2.m_psystems = (GameObject[])(object)new GameObject[0]; val2.m_windMin = 0f; val2.m_windMax = 0.05f; val2.m_ambColorNight = val2.m_ambColorDay; val2.m_fogColorNight = (val2.m_fogColorMorning = (val2.m_fogColorEvening = val2.m_fogColorDay)); val2.m_fogColorSunNight = (val2.m_fogColorSunMorning = (val2.m_fogColorSunEvening = val2.m_fogColorSunDay)); val2.m_fogDensityNight = (val2.m_fogDensityMorning = (val2.m_fogDensityEvening = val2.m_fogDensityDay)); val2.m_sunColorNight = (val2.m_sunColorMorning = (val2.m_sunColorEvening = val2.m_sunColorDay)); val2.m_lightIntensityNight = val2.m_lightIntensityDay; val2.m_aoIntensityNight = (val2.m_aoIntensityMorning = (val2.m_aoIntensityEvening = val2.m_aoIntensityDay)); env.AppendEnvironment(val2); Plugin.Log.LogInfo((object)"Registered eternal-day environment 'Agartha'."); } } internal static class Arrival { public static PocketTerrain Terrain { get { if (WorldGenerator.instance == null) { return null; } return TerrainCache.Get(WorldGenerator.instance.GetSeed()); } } public static Vector3 InsideTarget(Vector3 gatePos) { //IL_0021: 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_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) float num = Terrain?.ArrivalHeight(0f, -20f) ?? 15f; return GateLocation.InteriorOrigin(gatePos) + new Vector3(0f, num, -20f); } } internal static class GateExit { public static Vector3 Target(Vector3 gatePos) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0028: 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_0055: Unknown result type (might be due to invalid IL or missing references) Vector3 val = gatePos + new Vector3(0f, 0f, 4f); float num = (((Object)(object)ZoneSystem.instance != (Object)null) ? ZoneSystem.instance.GetSolidHeight(val) : val.y); val.y = Mathf.Max(num, gatePos.y) + 0.5f; return val; } } internal static class TerrainCache { private static int _seed; private static PocketTerrain _terrain; public static PocketTerrain Get(int seed) { if (_terrain == null || _seed != seed) { _seed = seed; _terrain = new PocketTerrain(seed); } return _terrain; } } internal abstract class CheatCommand : ConsoleCommand { public sealed override bool IsCheat => true; public sealed override void Run(string[] args) { RunCheat(args); } protected abstract void RunCheat(string[] args); protected static void Print(string s) { Console.instance.Print(s); } } internal class DebugCommand : CheatCommand { public override string Name => "agartha_debug"; public override string Help => "agartha_debug - write Agartha state to BepInEx/agartha_debug.txt"; protected override void RunCheat(string[] args) { //IL_0022: 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_0027: 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_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; StringBuilder stringBuilder = new StringBuilder(); Vector3 val = (((Object)(object)localPlayer != (Object)null) ? ((Component)localPlayer).transform.position : Vector3.zero); Vector3 gatePos; bool flag = GateLocation.TryFindGate(val, out gatePos); stringBuilder.AppendLine($"player {val:F1} inside={LocalPocket.IsInside(val)} InInterior={(Object)(object)localPlayer != (Object)null && Character.InInterior(((Component)localPlayer).transform)}"); stringBuilder.AppendLine("gate " + (flag ? ((Vector3)(ref gatePos)).ToString("F1") : "NONE") + " seed " + ((WorldGenerator.instance != null) ? WorldGenerator.instance.GetSeed().ToString() : "?")); EnvMan instance = EnvMan.instance; string arg = ((instance == null) ? null : instance.GetCurrentEnvironment()?.m_name); ZoneSystem instance2 = ZoneSystem.instance; stringBuilder.AppendLine($"env '{arg}' DungeonBuild={((instance2 != null) ? new bool?(instance2.GetGlobalKey((GlobalKeys)34)) : ((bool?)null))}"); PocketBuilder[] array = Object.FindObjectsByType<PocketBuilder>((FindObjectsSortMode)0); foreach (PocketBuilder pocketBuilder in array) { MeshRenderer val2 = ((IEnumerable<MeshRenderer>)((Component)pocketBuilder).GetComponentsInChildren<MeshRenderer>(true)).FirstOrDefault((Func<MeshRenderer, bool>)((MeshRenderer r) => ((Object)r).name == "Ground")); object arg2 = ((Component)pocketBuilder).transform.position; object arg3 = (Object)(object)val2 != (Object)null; object arg4; if (val2 == null) { arg4 = null; } else { Material sharedMaterial = ((Renderer)val2).sharedMaterial; arg4 = ((sharedMaterial != null) ? ((Object)sharedMaterial).name : null); } stringBuilder.AppendLine($"interior {arg2:F1} ground={arg3} material='{arg4}'"); ZNetView componentInParent = ((Component)pocketBuilder).GetComponentInParent<ZNetView>(); stringBuilder.AppendLine(" life flag=" + (((Object)(object)componentInParent != (Object)null && componentInParent.IsValid()) ? componentInParent.GetZDO().GetBool("agartha_life_v1", false).ToString() : "?") + " " + string.Format("shamballa={0} grassRenderers={1}", (Object)(object)((Component)pocketBuilder).transform.Find("Shamballa") != (Object)null, ((Component)pocketBuilder).GetComponentsInChildren<InstanceRenderer>(true).Length)); } string text = Path.Combine(Paths.BepInExRootPath, "agartha_debug.txt"); File.WriteAllText(text, stringBuilder.ToString()); CheatCommand.Print(stringBuilder.ToString().Split(new char[1] { '\n' })[0]); CheatCommand.Print("agartha_debug: written to " + text); } } internal enum DoorKind { Descend, Ascend } internal class Doorway : MonoBehaviour, Hoverable, Interactable { public DoorKind Kind; private static readonly Vector3 DescendSize = new Vector3(4.4f, 12f, 0.8f); private static readonly Vector3 AscendSize = new Vector3(2.2f, 3f, 0.4f); public static GameObject CreateDoor(Transform parent, Vector3 localPos, DoorKind kind) { //IL_0042: 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_0047: 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_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_006a: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) GameObject obj = GameObject.CreatePrimitive((PrimitiveType)3); ((Object)obj).name = ((kind == DoorKind.Descend) ? "DescendDoor" : "AscendDoor"); obj.layer = LayerMask.NameToLayer("static_solid"); obj.transform.SetParent(parent, false); Vector3 val = ((kind == DoorKind.Descend) ? DescendSize : AscendSize); obj.transform.localPosition = localPos + new Vector3(0f, val.y / 2f, 0f); obj.transform.localScale = val; MeshRenderer component = obj.GetComponent<MeshRenderer>(); Material val2 = MaterialFinder.RockMaterial(); if ((Object)(object)val2 != (Object)null) { ((Renderer)component).sharedMaterial = val2; } obj.AddComponent<Doorway>().Kind = kind; return obj; } public string GetHoverText() { return Localization.instance.Localize(GetHoverName() + "\n[<color=yellow><b>$KEY_Use</b></color>] " + ((Kind == DoorKind.Descend) ? "Descend" : "Ascend")); } public string GetHoverName() { if (Kind != DoorKind.Descend) { return "Ascend"; } return "Descend into Agartha"; } public float GetHoverOffset() { return 0f; } public bool Interact(Humanoid user, bool hold, bool alt) { //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_006f: 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_0067: 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_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) if (!hold) { Player val = (Player)(object)((user is Player) ? user : null); if (val != null && !((Object)(object)val != (Object)(object)Player.m_localPlayer)) { Location componentInParent = ((Component)this).GetComponentInParent<Location>(); Vector3 gatePos; if ((Object)(object)componentInParent != (Object)null) { gatePos = ((Component)componentInParent).transform.position; } else if (!GateLocation.TryFindGate(((Component)this).transform.position, out gatePos)) { Plugin.WarnOnce("doorgate", "Doorway could not find its Polar Gate."); return false; } Vector3 val2 = ((Kind == DoorKind.Descend) ? Arrival.InsideTarget(gatePos) : GateExit.Target(gatePos)); ((Character)val).TeleportTo(val2, ((Component)val).transform.rotation, true); return true; } } return false; } public bool UseItem(Humanoid user, ItemData item) { return false; } } internal static class GateLocation { public const string LocationName = "Agartha_PolarGate"; private static bool _registered; public static void Register() { ZoneManager.OnVanillaLocationsAvailable += AddLocation; } private static void AddLocation() { //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_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_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_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Expected O, but got Unknown //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Expected O, but got Unknown if (!_registered) { _registered = true; GameObject val = ZoneManager.Instance.CreateLocationContainer("Agartha_PolarGate"); GameObject val2 = new GameObject("Gate"); val2.transform.SetParent(val.transform, false); GateVisuals.Build(val2.transform); GameObject val3 = new GameObject("Interior"); val3.transform.SetParent(val.transform, false); val3.transform.localPosition = new Vector3(0f, 5000f, 0f); val3.AddComponent<PocketBuilder>(); ZoneManager.Instance.AddCustomLocation(new CustomLocation(val, false, new LocationConfig { Biome = (Biome)64, Quantity = 1, Priotized = true, Unique = true, ExteriorRadius = 15f, ClearArea = true, RandomRotation = false, MinAltitude = 2f, MaxTerrainDelta = 10f, IconPlaced = false, IconAlways = false })); Location component = val.GetComponent<Location>(); if ((Object)(object)component != (Object)null) { component.m_noBuild = false; } else { Plugin.WarnOnce("noloc", "Polar Gate container has no Location component; cannot clear its no-build flag."); } Plugin.Log.LogInfo((object)"Registered location 'Agartha_PolarGate'."); } } public static bool TryFindGate(Vector3 near, out Vector3 gatePos) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)ZNet.instance != (Object)null && !ZNet.instance.IsServer()) { return GateNet.TryGet(out gatePos); } return TryFindGateLocal(near, out gatePos); } public static bool TryFindGateLocal(Vector3 near, out Vector3 gatePos) { //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_0024: 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_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) gatePos = Vector3.zero; if ((Object)(object)ZoneSystem.instance == (Object)null) { return false; } LocationInstance val = default(LocationInstance); if (!ZoneSystem.instance.FindClosestLocation("Agartha_PolarGate", near, ref val)) { return false; } gatePos = val.m_position; return true; } public static Vector3 InteriorOrigin(Vector3 gatePos) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) return gatePos + new Vector3(0f, 5000f, 0f); } } internal static class GateNet { private const string RequestRpc = "Agartha_GateRequest"; private const string ReplyRpc = "Agartha_GateReply"; private static ZRoutedRpc _registeredOn; private static bool _answered; private static bool _found; private static Vector3 _pos; private static float _nextRequest; public static void Tick() { ZRoutedRpc instance = ZRoutedRpc.instance; ZNet instance2 = ZNet.instance; if (instance == null || (Object)(object)instance2 == (Object)null) { return; } if (_registeredOn != instance) { _registeredOn = instance; _answered = false; _found = false; _nextRequest = 0f; instance.Register("Agartha_GateRequest", (Action<long>)OnRequest); instance.Register<bool, Vector3>("Agartha_GateReply", (Action<long, bool, Vector3>)OnReply); } if (!instance2.IsServer() && (!_answered || !_found) && !(Time.time < _nextRequest)) { _nextRequest = Time.time + (_answered ? 30f : 2f); ZNetPeer serverPeer = instance2.GetServerPeer(); if (serverPeer != null) { instance.InvokeRoutedRPC(serverPeer.m_uid, "Agartha_GateRequest", Array.Empty<object>()); } } } public static bool TryGet(out Vector3 pos) { //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) pos = _pos; if (_answered) { return _found; } return false; } private static void OnRequest(long sender) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)ZNet.instance == (Object)null) && ZNet.instance.IsServer()) { Vector3 gatePos; bool flag = GateLocation.TryFindGateLocal(Vector3.zero, out gatePos); ZRoutedRpc.instance.InvokeRoutedRPC(sender, "Agartha_GateReply", new object[2] { flag, gatePos }); } } private static void OnReply(long sender, bool found, Vector3 pos) { //IL_0021: 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_003d: Unknown result type (might be due to invalid IL or missing references) bool num = !_answered || _found != found; _answered = true; _found = found; _pos = pos; if (num) { Plugin.Log.LogInfo((object)(found ? $"Server says the Polar Gate is at {pos:F0}." : "Server says this world has no Polar Gate (will ask again).")); } } } internal static class GateVisuals { private const int RingCount = 10; private const float RingRadius = 9f; public static void Build(Transform parent) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) BuildRockRing(parent); Doorway.CreateDoor(parent, Vector3.zero, DoorKind.Descend); } private static void BuildRockRing(Transform parent) { //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) GameObject[] array = (GameObject[])(((Object)(object)ZNetScene.instance == (Object)null) ? ((Array)new GameObject[0]) : ((Array)(from p in ZNetScene.instance.m_prefabs where (Object)(object)p != (Object)null && ((Object)p).name.ToLowerInvariant().StartsWith("rock") && (Object)(object)p.GetComponentInChildren<MeshRenderer>(true) != (Object)null orderby ((Object)p).name select p).Take(4).ToArray())); if (array.Length == 0) { Plugin.WarnOnce("gaterocks", "No vanilla rock prefabs found; Polar Gate has no rock ring."); return; } for (int num = 0; num < 10; num++) { float num2 = (float)num * (float)Math.PI * 2f / 10f; GameObject obj = VisualClone.Create(array[num % array.Length], parent); obj.transform.localPosition = new Vector3(Mathf.Cos(num2) * 9f, 0f, Mathf.Sin(num2) * 9f); obj.transform.localRotation = Quaternion.Euler(0f, (float)num * 37f, 0f); } } } internal static class GrassBuilder { public static void Build(Transform interior, PocketTerrain terrain, int seed) { //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_0214: Unknown result type (might be due to invalid IL or missing references) //IL_022d: Unknown result type (might be due to invalid IL or missing references) ClutterSystem instance = ClutterSystem.instance; if ((Object)(object)instance == (Object)null) { Plugin.WarnOnce("clutter", "ClutterSystem missing; Agartha has no grass."); return; } List<Clutter> list = instance.m_clutter.Where((Clutter c) => c != null && c.m_enabled && c.m_instanced && (Object)(object)c.m_prefab != (Object)null && (c.m_biome & 1) != 0 && (Object)(object)c.m_prefab.GetComponent<InstanceRenderer>() != (Object)null).ToList(); if (list.Count == 0) { Plugin.WarnOnce("grass", "No instanced Meadows clutter found; Agartha has no grass."); return; } Random random = new Random(seed ^ 0x6A55); float num = 16f; float num2 = 123f; int num3 = 0; for (float num4 = 0f - num2; num4 <= num2; num4 += num) { for (float num5 = 0f - num2; num5 <= num2; num5 += num) { float num6 = num4 + num / 2f; float num7 = num5 + num / 2f; if (num6 * num6 + num7 * num7 > num2 * num2) { continue; } float num8 = num6 - 0f; float num9 = num7 - 45f; bool plaza = num8 * num8 + num9 * num9 < 470.40002f; foreach (Clutter item in list) { int num10 = GrassMath.AmountPerPatch(item.m_amount, instance.m_amountScale, instance.m_grassPatchSize, num, 1.5f, plaza); if (num10 <= 0) { continue; } InstanceRenderer val = null; int num11 = 0; for (int num12 = 0; num12 < num10; num12++) { float num13 = num4 + (float)random.NextDouble() * num; float num14 = num5 + (float)random.NextDouble() * num; if (!(num13 * num13 + num14 * num14 > num2 * num2)) { if ((Object)(object)val == (Object)null || num11 >= 1000) { num11 = 0; val = Object.Instantiate<GameObject>(item.m_prefab, interior.TransformPoint(new Vector3(num6, terrain.Height(num6, num7), num7)), Quaternion.identity, interior).GetComponent<InstanceRenderer>(); val.m_lodMaxDistance = Mathf.Min(val.m_lodMaxDistance, instance.m_distance - num / 2f); num3++; } Vector3 val2 = interior.TransformPoint(new Vector3(num13, terrain.Height(num13, num14), num14)); float num15 = item.m_scaleMin + (float)random.NextDouble() * (item.m_scaleMax - item.m_scaleMin); val.AddInstance(val2, Quaternion.Euler(0f, (float)random.NextDouble() * 360f, 0f), num15); num11++; } } } } } Plugin.Log.LogInfo((object)$"Agartha grass: {num3} patches from {list.Count} clutter types."); } } internal class LifeSpawner : MonoBehaviour { public const string FlagKey = "agartha_life_v1"; private const float Altitude = 5f; private float _nextTry; private bool _done; private void Update() { if (_done || Time.time < _nextTry) { return; } _nextTry = Time.time + 2f; ZNetView componentInParent = ((Component)this).GetComponentInParent<ZNetView>(); if ((Object)(object)componentInParent == (Object)null || !componentInParent.IsValid() || (Object)(object)ZoneSystem.instance == (Object)null) { return; } ZDO zDO = componentInParent.GetZDO(); if (zDO.GetBool("agartha_life_v1", false)) { _done = true; } else if (componentInParent.IsOwner()) { PocketTerrain terrain = Arrival.Terrain; if (terrain != null) { zDO.Set("agartha_life_v1", true); _done = true; int num = Spawn(terrain); Plugin.Log.LogInfo((object)$"Agartha life: spawned {num} vegetation objects."); } } } private int Spawn(PocketTerrain terrain) { //IL_0315: Unknown result type (might be due to invalid IL or missing references) //IL_031a: Unknown result type (might be due to invalid IL or missing references) //IL_031f: Unknown result type (might be due to invalid IL or missing references) //IL_0374: Unknown result type (might be due to invalid IL or missing references) //IL_0379: Unknown result type (might be due to invalid IL or missing references) //IL_0382: Unknown result type (might be due to invalid IL or missing references) //IL_0384: Unknown result type (might be due to invalid IL or missing references) //IL_03cd: Unknown result type (might be due to invalid IL or missing references) //IL_03d4: Unknown result type (might be due to invalid IL or missing references) Random random = new Random(WorldGenerator.instance.GetSeed() ^ 0x4C1FE); Disc[] array = new Disc[2] { new Disc(0f, 45f, 32f), new Disc(0f, -23f, 16f) }; float num = 119f; List<ZoneVegetation> list = (from v in ZoneSystem.instance.m_vegetation where v != null && v.m_enable && (Object)(object)v.m_prefab != (Object)null && (Object)(object)v.m_prefab.GetComponent<ZNetView>() != (Object)null where IsPeacefulNature(v.m_prefab) where (v.m_biome & 9) > 0 where !v.m_snapToWater && v.m_minAltitude <= 5f && v.m_maxAltitude >= 5f select v).ToList(); int[] array2 = new int[list.Count]; int[] array3 = new int[list.Count]; for (int num2 = 0; num2 < list.Count; num2++) { ZoneVegetation val = list[num2]; float num3 = val.m_min + (float)random.NextDouble() * (val.m_max - val.m_min); array2[num2] = Mathf.RoundToInt(num3 * 12f / 4f); float num4 = (float)(Mathf.Max(1, val.m_groupSizeMin) + Mathf.Max(1, val.m_groupSizeMax)) / 2f; array3[num2] = Mathf.RoundToInt((float)array2[num2] * num4); } int[] array4 = VegetationBudget.Share(array3, 600); int num5 = 0; for (int num6 = 0; num6 < list.Count; num6++) { ZoneVegetation val2 = list[num6]; int num7 = 0; foreach (var (num8, num9) in Scatter.Points(random.Next(), array2[num6], num, array)) { if (num7 >= array4[num6]) { break; } int num10 = Mathf.Max(1, val2.m_groupSizeMin); int num11 = Mathf.Max(num10, val2.m_groupSizeMax); int num12 = random.Next(num10, num11 + 1); for (int num13 = 0; num13 < num12; num13++) { if (num7 >= array4[num6]) { break; } float ox = num8 + (float)(random.NextDouble() * 2.0 - 1.0) * val2.m_groupRadius; float oz = num9 + (float)(random.NextDouble() * 2.0 - 1.0) * val2.m_groupRadius; if (!(ox * ox + oz * oz > num * num) && !array.Any((Disc d) => (ox - d.X) * (ox - d.X) + (oz - d.Z) * (oz - d.Z) < d.R * d.R)) { Vector3 val3 = ((Component)this).transform.TransformPoint(new Vector3(ox, terrain.Height(ox, oz) + val2.m_groundOffset, oz)); Quaternion val4 = Quaternion.Euler((float)(random.NextDouble() * 2.0 - 1.0) * val2.m_randTilt, (float)random.NextDouble() * 360f, (float)(random.NextDouble() * 2.0 - 1.0) * val2.m_randTilt); GameObject obj = Object.Instantiate<GameObject>(val2.m_prefab, val3, val4); float num14 = val2.m_scaleMin + (float)random.NextDouble() * (val2.m_scaleMax - val2.m_scaleMin); ZNetView component = obj.GetComponent<ZNetView>(); if ((Object)(object)component != (Object)null && !Mathf.Approximately(num14, 1f)) { component.SetLocalScale(Vector3.one * num14); } num5++; num7++; } } } } return num5; } private static bool IsPeacefulNature(GameObject prefab) { if ((Object)(object)prefab.GetComponentInChildren<SpawnArea>(true) != (Object)null || (Object)(object)prefab.GetComponentInChildren<CreatureSpawner>(true) != (Object)null || (Object)(object)prefab.GetComponentInChildren<Container>(true) != (Object)null || (Object)(object)prefab.GetComponentInChildren<OfferingBowl>(true) != (Object)null) { return false; } if (!((Object)(object)prefab.GetComponent<TreeBase>() != (Object)null) && !((Object)(object)prefab.GetComponent<Pickable>() != (Object)null) && !((Object)(object)prefab.GetComponent<PickableItem>() != (Object)null) && !((Object)(object)prefab.GetComponent<MineRock>() != (Object)null) && !((Object)(object)prefab.GetComponent<MineRock5>() != (Object)null)) { return (Object)(object)prefab.GetComponent<Destructible>() != (Object)null; } return true; } } internal static class MaterialFinder { private static Material _rock; public static Material RockMaterial() { if ((Object)(object)_rock != (Object)null || (Object)(object)ZNetScene.instance == (Object)null) { return _rock; } _rock = (from p in ZNetScene.instance.m_prefabs.Concat(ZNetScene.instance.m_nonNetViewPrefabs) where (Object)(object)p != (Object)null && ((Object)p).name.ToLowerInvariant().Contains("rock") orderby ((Object)p).name select p.GetComponentInChildren<MeshRenderer>(true) into r where (Object)(object)r != (Object)null && (Object)(object)((Renderer)r).sharedMaterial != (Object)null select ((Renderer)r).sharedMaterial).FirstOrDefault(); if ((Object)(object)_rock == (Object)null) { Plugin.WarnOnce("rock", "No vanilla rock material found; Agartha dome/fallback will use the default material."); } return _rock; } } [BepInPlugin("wannie.agartha", "Agartha", "1.0.3")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] internal class Plugin : BaseUnityPlugin { public const string Guid = "wannie.agartha"; public const string Version = "1.0.3"; internal static ManualLogSource Log; private static readonly HashSet<string> Warned = new HashSet<string>(); private void Awake() { //IL_0042: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; GateLocation.Register(); CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new WhereCommand()); CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new TpCommand()); CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new DebugCommand()); new Harmony("wannie.agartha").PatchAll(); } private void Update() { GateNet.Tick(); SafetyHold.Tick(); AgarthaLight.Tick(); } public static void WarnOnce(string key, string message) { if (Warned.Add(key)) { Log.LogWarning((object)message); } } } internal class PocketBuilder : MonoBehaviour { private void Awake() { //IL_0042: Unknown result type (might be due to invalid IL or missing references) PocketTerrain terrain = Arrival.Terrain; if (terrain == null) { Plugin.WarnOnce("noseed", "Agartha interior spawned before the world generator existed; not built."); return; } BuildGround(terrain); float num = terrain.Height(0f, -26f); Doorway.CreateDoor(((Component)this).transform, new Vector3(0f, num, -26f), DoorKind.Ascend); BuildWall(); BuildDome(); BuildSun(); ((Component)this).gameObject.AddComponent<LifeSpawner>(); GrassBuilder.Build(((Component)this).transform, terrain, WorldGenerator.instance.GetSeed()); ShamballaBuilder.Build(((Component)this).transform); } private void BuildWall() { //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_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Expected O, but got Unknown //IL_00fc: 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_0111: Unknown result type (might be due to invalid IL or missing references) Vector3[] array = (Vector3[])(object)new Vector3[144]; int[] array2 = new int[432]; for (int i = 0; i < 72; i++) { float num = (float)i * (float)Math.PI * 2f / 72f; float num2 = Mathf.Cos(num) * 125f; float num3 = Mathf.Sin(num) * 125f; array[i * 2] = new Vector3(num2, -10f, num3); array[i * 2 + 1] = new Vector3(num2, 100f, num3); int num4 = (i + 1) % 72; int num5 = i * 6; array2[num5] = i * 2; array2[num5 + 1] = num4 * 2; array2[num5 + 2] = i * 2 + 1; array2[num5 + 3] = i * 2 + 1; array2[num5 + 4] = num4 * 2; array2[num5 + 5] = num4 * 2 + 1; } Mesh val = new Mesh { name = "Agartha_Wall", vertices = array, triangles = array2 }; val.RecalculateBounds(); GameObject val2 = new GameObject("EdgeWall") { layer = LayerMask.NameToLayer("static_solid") }; val2.transform.SetParent(((Component)this).transform, false); val2.AddComponent<MeshCollider>().sharedMesh = val; } private void BuildDome() { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) GameObject val = GameObject.CreatePrimitive((PrimitiveType)0); Object.DestroyImmediate((Object)(object)val.GetComponent<Collider>()); ((Object)val).name = "Dome"; val.transform.SetParent(((Component)this).transform, false); val.transform.localScale = Vector3.one * 150f * 2f; Mesh val2 = Object.Instantiate<Mesh>(val.GetComponent<MeshFilter>().sharedMesh); int[] triangles = val2.triangles; for (int i = 0; i < triangles.Length; i += 3) { int num = triangles[i]; triangles[i] = triangles[i + 1]; triangles[i + 1] = num; } val2.triangles = triangles; val2.normals = val2.normals.Select((Vector3 n) => -n).ToArray(); val.GetComponent<MeshFilter>().sharedMesh = val2; MeshRenderer component = val.GetComponent<MeshRenderer>(); ((Renderer)component).sharedMaterial = MaterialFinder.RockMaterial(); ((Renderer)component).shadowCastingMode = (ShadowCastingMode)0; } private void BuildSun() { //IL_0044: 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_005e: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Expected O, but got Unknown //IL_0139: Unknown result type (might be due to invalid IL or missing references) GameObject val = GameObject.CreatePrimitive((PrimitiveType)0); Object.DestroyImmediate((Object)(object)val.GetComponent<Collider>()); ((Object)val).name = "InnerSun"; val.transform.SetParent(((Component)this).transform, false); val.transform.localPosition = new Vector3(0f, 90f, 0f); val.transform.localScale = Vector3.one * 14f; Shader val2 = Shader.Find("Sprites/Default"); if ((Object)(object)val2 != (Object)null) { Mesh val3 = Object.Instantiate<Mesh>(val.GetComponent<MeshFilter>().sharedMesh); val3.colors = Enumerable.Repeat<Color>(Color.white, val3.vertexCount).ToArray(); val.GetComponent<MeshFilter>().sharedMesh = val3; ((Renderer)val.GetComponent<MeshRenderer>()).sharedMaterial = new Material(val2) { color = new Color(1f, 0.85f, 0.55f) * 3f }; } else { Plugin.WarnOnce("sunshader", "Sprites/Default shader missing; inner sun orb uses the default material."); } ((Renderer)val.GetComponent<MeshRenderer>()).shadowCastingMode = (ShadowCastingMode)0; Light obj = val.AddComponent<Light>(); obj.type = (LightType)2; obj.range = 300f; obj.intensity = 1.4f; obj.color = new Color(1f, 0.9f, 0.7f); obj.renderMode = (LightRenderMode)1; obj.shadows = (LightShadows)2; } private void BuildGround(PocketTerrain terrain) { //IL_0012: 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_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected O, but got Unknown //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) TerrainMeshData data = terrain.BuildMesh(); Mesh val = new Mesh { name = "Agartha_Ground", indexFormat = (IndexFormat)1 }; val.vertices = ((IEnumerable<Point3>)data.Vertices).Select((Func<Point3, Vector3>)((Point3 p) => new Vector3(p.X, p.Y, p.Z))).ToArray(); val.uv = ((IEnumerable<float>)data.U).Select((Func<float, int, Vector2>)((float u, int i) => new Vector2(u, data.V[i]))).ToArray(); val.triangles = data.Triangles; Color32 biomeColor = Heightmap.GetBiomeColor((Biome)1); val.colors32 = Enumerable.Repeat<Color32>(biomeColor, data.Vertices.Length).ToArray(); val.RecalculateNormals(); val.RecalculateTangents(); val.RecalculateBounds(); GameObject val2 = new GameObject("Ground") { layer = LayerMask.NameToLayer("static_solid") }; val2.transform.SetParent(((Component)this).transform, false); val2.AddComponent<MeshFilter>().sharedMesh = val; ((Renderer)val2.AddComponent<MeshRenderer>()).sharedMaterial = MaterialFinder.RockMaterial(); val2.AddComponent<MeshCollider>().sharedMesh = val; val2.AddComponent<TerrainLook>(); } } internal static class LocalPocket { private static float _nextLookup; private static bool _known; private static Vector3 _origin; public static bool TryGetOrigin(out Vector3 origin) { //IL_005c: 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_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null && Time.time >= _nextLookup) { _known = GateLocation.TryFindGate(((Component)localPlayer).transform.position, out var gatePos); _origin = GateLocation.InteriorOrigin(gatePos); _nextLookup = Time.time + (_known ? 5f : 0.25f); } origin = _origin; return _known; } public static bool IsInside(Vector3 pos) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001f: 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_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_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) if (!TryGetOrigin(out var origin)) { return false; } if (pos.y > origin.y - 300f) { Vector2 val = new Vector2(pos.x - origin.x, pos.z - origin.z); return ((Vector2)(ref val)).magnitude < 150f; } return false; } } internal static class SafetyHold { private const float MaxHoldSeconds = 20f; private static bool _holding; private static Vector3 _holdPos; private static float _holdStart; private static int SolidMask => LayerMask.GetMask(new string[5] { "Default", "static_solid", "Default_small", "piece", "terrain" }); public static void Tick() { //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_0027: 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_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_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_008b: 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_0096: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: 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) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_01bc: Unknown result type (might be due to invalid IL or missing references) //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01d0: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_01fc: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0144: 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_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { return; } Vector3 position = ((Component)localPlayer).transform.position; Vector3 origin; bool flag = LocalPocket.TryGetOrigin(out origin); if ((flag || !(position.y > 4000f) || Physics.Raycast(position + Vector3.up, Vector3.down, 1000f, SolidMask, (QueryTriggerInteraction)1)) && (!flag || !LocalPocket.IsInside(position))) { _holding = false; return; } RaycastHit val = default(RaycastHit); bool num = flag && Physics.Raycast(new Vector3(position.x, origin.y + 200f, position.z), Vector3.down, ref val, 600f, SolidMask, (QueryTriggerInteraction)1); Rigidbody component = ((Component)localPlayer).GetComponent<Rigidbody>(); if (!num) { if (!_holding) { _holding = true; _holdPos = position; _holdStart = Time.time; Plugin.Log.LogInfo((object)$"Safety hold: Agartha ground not loaded yet, holding player at {position:F0}."); } if (Time.time - _holdStart > 20f) { _holding = false; Plugin.Log.LogWarning((object)$"Safety hold timed out after {20f}s at {position:F0}."); if (flag) { ((Character)localPlayer).TeleportTo(GateExit.Target(origin - new Vector3(0f, 5000f, 0f)), ((Component)localPlayer).transform.rotation, true); } } else { ((Component)localPlayer).transform.position = _holdPos; if ((Object)(object)component != (Object)null) { component.linearVelocity = Vector3.zero; } } } else if (_holding) { _holding = false; if (position.y > ((RaycastHit)(ref val)).point.y + 1f) { ((Component)localPlayer).transform.position = ((RaycastHit)(ref val)).point + Vector3.up * 0.5f; } if ((Object)(object)component != (Object)null) { component.linearVelocity = Vector3.zero; } Plugin.Log.LogInfo((object)$"Safety hold released: ground at {((RaycastHit)(ref val)).point:F0}."); } } } internal static class ShamballaBuilder { private static readonly Color CrystalLight = new Color(0.45f, 0.85f, 1f); public static void Build(Transform interior) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: 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) GameObject val = new GameObject("Shamballa"); val.transform.SetParent(interior, false); val.transform.localPosition = new Vector3(0f, 4f, 45f); int num = 0; RuinPiece[] pieces = ShamballaLayout.Pieces; foreach (RuinPiece p in pieces) { if ((Object)(object)Place(val.transform, p) != (Object)null) { num++; } } pieces = ShamballaLayout.Crystals; for (int i = 0; i < pieces.Length; i++) { RuinPiece p2 = pieces[i]; if (!((Object)(object)Place(val.transform, p2) == (Object)null)) { num++; GameObject val2 = new GameObject("CrystalLight"); val2.transform.SetParent(val.transform, false); val2.transform.localPosition = new Vector3(p2.X, p2.Y + 1.5f * p2.Scale, p2.Z); Light obj = val2.AddComponent<Light>(); obj.type = (LightType)2; obj.color = CrystalLight; obj.range = 8f; obj.intensity = 1.2f; } } LoreStone[] stones = Lore.Stones; foreach (LoreStone s in stones) { if (PlaceRunestone(val.transform, s)) { num++; } } Plugin.Log.LogInfo((object)$"Shamballa: placed {num} pieces."); } private static GameObject Place(Transform city, RuinPiece p) { //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: 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) GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab(p.Prefab) : null); if ((Object)(object)val == (Object)null) { Plugin.WarnOnce("ruin_" + p.Prefab, "Shamballa: vanilla '" + p.Prefab + "' not found; skipped."); return null; } GameObject obj = VisualClone.Create(val, city); obj.transform.localPosition = new Vector3(p.X, p.Y, p.Z); obj.transform.localRotation = Quaternion.Euler(p.Tilt, p.Yaw, 0f); obj.transform.localScale = Vector3.one * p.Scale; return obj; } private static bool PlaceRunestone(Transform city, LoreStone s) { //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) GameObject val = GameObject.CreatePrimitive((PrimitiveType)3); ((Object)val).name = "Runestone_" + s.Title; val.layer = LayerMask.NameToLayer("static_solid"); val.transform.SetParent(city, false); val.transform.localPosition = new Vector3(s.X, 1.1f, s.Z); val.transform.localRotation = Quaternion.Euler(0f, s.Yaw, 0f); val.transform.localScale = new Vector3(1.2f, 2.2f, 0.4f); Material val2 = MaterialFinder.RockMaterial(); if ((Object)(object)val2 != (Object)null) { ((Renderer)val.GetComponent<MeshRenderer>()).sharedMaterial = val2; } RuneStone obj = val.AddComponent<RuneStone>(); obj.m_name = "Ancient runestone"; obj.m_topic = s.Title; obj.m_label = s.Title; obj.m_text = s.Text; obj.m_randomTexts = new List<RandomRuneText>(); return true; } } internal class TerrainLook : MonoBehaviour { private static Material s_material; private static MaterialPropertyBlock s_block; private MeshRenderer _renderer; private bool _applied; private float _nextTry; private void Awake() { _renderer = ((Component)this).GetComponent<MeshRenderer>(); } private void Update() { if (!_applied) { if ((Object)(object)s_material == (Object)null && Time.time >= _nextTry) { _nextTry = Time.time + 1f; TryCapture(); } if (!((Object)(object)s_material == (Object)null)) { ((Renderer)_renderer).sharedMaterial = s_material; ((Renderer)_renderer).SetPropertyBlock(s_block); _applied = true; } } } private static void TryCapture() { //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Expected O, but got Unknown //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Expected O, but got Unknown //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_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Expected O, but got Unknown Heightmap[] array = Object.FindObjectsByType<Heightmap>((FindObjectsSortMode)0); foreach (Heightmap val in array) { if (val.IsDistantLod) { continue; } MeshRenderer component = ((Component)val).GetComponent<MeshRenderer>(); if (!((Object)(object)component == (Object)null) && !((Object)(object)((Renderer)component).sharedMaterial == (Object)null) && !((Object)(object)((Renderer)component).sharedMaterial.GetTexture("_DiffuseArrayTex") == (Object)null)) { s_material = new Material(((Renderer)component).sharedMaterial) { name = "Agartha_Terrain" }; Texture2D val2 = new Texture2D(65, 65) { wrapMode = (TextureWrapMode)1, name = "Agartha_Mask" }; Color[] array2 = (Color[])(object)new Color[4225]; for (int j = 0; j < array2.Length; j++) { array2[j] = new Color(0f, 0f, 0f, 1f); } val2.SetPixels(array2); val2.Apply(); s_material.SetTexture("_ClearedMaskTex", (Texture)(object)val2); s_block = new MaterialPropertyBlock(); ((Renderer)component).GetPropertyBlock(s_block); Plugin.Log.LogInfo((object)("Captured live terrain material from '" + ((Object)val).name + "'.")); break; } } } } internal static class VisualClone { public static GameObject Create(GameObject source, Transform parent) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown GameObject val = new GameObject("Agartha_CloneHolder"); val.SetActive(false); GameObject val2 = Object.Instantiate<GameObject>(source, val.transform, false); for (int i = 0; i < 3; i++) { MonoBehaviour[] componentsInChildren = val2.GetComponentsInChildren<MonoBehaviour>(true); foreach (MonoBehaviour val3 in componentsInChildren) { if ((Object)(object)val3 != (Object)null) { Object.DestroyImmediate((Object)(object)val3); } } Rigidbody[] componentsInChildren2 = val2.GetComponentsInChildren<Rigidbody>(true); foreach (Rigidbody val4 in componentsInChildren2) { if ((Object)(object)val4 != (Object)null) { Object.DestroyImmediate((Object)(object)val4); } } } val2.transform.SetParent(parent, false); Object.Destroy((Object)(object)val); val2.SetActive(true); return val2; } } } namespace Agartha.Core { public static class AgarthaLayout { public const float InteriorHeight = 5000f; public const float Size = 250f; public const float GridSpacing = 2f; public const int VertsPerSide = 126; public const float HillHeight = 10f; public const float RimStart = 0.65f; public const float RimEnd = 1.1f; public const float RimHeight = 35f; public const float GroundRadius = 125f; public const float WallHeight = 100f; public const float DomeRadius = 150f; public const float SunHeight = 90f; public const float ArrivalX = 0f; public const float ArrivalZ = -20f; public const float AscendDoorX = 0f; public const float AscendDoorZ = -26f; public const float ShamballaX = 0f; public const float ShamballaZ = 45f; public const float ShamballaRadius = 28f; public const float PlazaHeight = 4f; public const float FlattenBand = 8f; public const float ArrivalPadZ = -23f; public const float ArrivalPadRadius = 10f; public const float ArrivalPadHeight = 3f; public const int VegetationCap = 600; public const float VegetationZones = 12f; public const float GrassPatch = 16f; public const float GrassDensity = 1.5f; public const int MaxGrassPerRenderer = 1000; } public static class GrassMath { public static int AmountPerPatch(int vanillaAmount, float amountScale, float vanillaPatch, float ourPatch, float density, bool plaza) { float num = ourPatch * ourPatch / Math.Max(1f, vanillaPatch * vanillaPatch); return (int)Math.Round((float)vanillaAmount * amountScale * num * density * (plaza ? 0.15f : 1f)); } } public struct LoreStone { public string Title; public string Text; public float X; public float Z; public float Yaw; public LoreStone(string title, string text, float x, float z, float yaw) { Title = title; Text = text; X = x; Z = z; Yaw = yaw; } } public static class Lore { public static readonly LoreStone[] Stones = new LoreStone[5] { new LoreStone("The Inner Sun", "Beneath the ice of the world's crown there burns a second sun. It does not rise and it does not set. Those who found it called it the Smoky God, and under its light no winter ever came.", 3f, -12f, 180f), new LoreStone("The Builders", "The first people of this hollow land did not carve stone; they asked it, and the stone agreed. From its answers they raised Shamballa, a city of black marble and singing crystal.", -12f, 2f, 90f), new LoreStone("The Polar Gate", "One door alone was left open to the world above, far in the frozen north where no ship dares. The builders sealed every other path, for they had seen what walks on the surface.", 12f, 2f, -90f), new LoreStone("The Silence", "The crystals sang for a thousand years and then, in a single night, fell quiet. No enemy came. No fire. The builders simply laid down their tools and walked into the light of the sun.", -6f, 14f, 160f), new LoreStone("To The One Who Descends", "You have come a long way through the cold to stand here, traveller. The city is yours now. Build if you must, but walk softly. Some say the builders are only sleeping.", 6f, 14f, 200f) }; } public sealed class Perlin2D { private readonly int[] _p = new int[512]; public Perlin2D(int seed) { int[] array = new int[256]; for (int i = 0; i < 256; i++) { array[i] = i; } Random random = new Random(seed); for (int num = 255; num > 0; num--) { int num2 = random.Next(num + 1); int num3 = array[num]; array[num] = array[num2]; array[num2] = num3; } for (int j = 0; j < 512; j++) { _p[j] = array[j & 0xFF]; } } public float Noise(float x, float y) { float num = (float)Math.Floor(x); float num2 = (float)Math.Floor(y); int num3 = (int)num & 0xFF; int num4 = (int)num2 & 0xFF; float num5 = x - num; float num6 = y - num2; float t = Fade(num5); float t2 = Fade(num6); int hash = _p[_p[num3] + num4]; int hash2 = _p[_p[num3] + num4 + 1]; int hash3 = _p[_p[num3 + 1] + num4]; int hash4 = _p[_p[num3 + 1] + num4 + 1]; float a = Lerp(Grad(hash, num5, num6), Grad(hash3, num5 - 1f, num6), t); float b = Lerp(Grad(hash2, num5, num6 - 1f), Grad(hash4, num5 - 1f, num6 - 1f), t); return Lerp(a, b, t2); } private static float Fade(float t) { return t * t * t * (t * (t * 6f - 15f) + 10f); } private static float Lerp(float a, float b, float t) { return a + t * (b - a); } private static float Grad(int hash, float x, float y) { return (hash & 3) switch { 0 => x + y, 1 => 0f - x + y, 2 => x - y, _ => 0f - x - y, }; } } public struct Point3 { public float X; public float Y; public float Z; public Point3(float x, float y, float z) { X = x; Y = y; Z = z; } } public sealed class TerrainMeshData { public Point3[] Vertices; public float[] U; public float[] V; public int[] Triangles; } public sealed class PocketTerrain { private readonly Perlin2D _large; private readonly Perlin2D _small; public PocketTerrain(int seed) { _large = new Perlin2D(seed); _small = new Perlin2D(seed ^ 0x5BD1E995); } public float Height(float x, float z) { return Flatten(Flatten(RawHeight(x, z), x, z, 0f, 45f, 28f, 4f), x, z, 0f, -23f, 10f, 3f); } private static float Flatten(float h, float x, float z, float cx, float cz, float radius, float level) { float num = Clamp01(((float)Math.Sqrt((x - cx) * (x - cx) + (z - cz) * (z - cz)) - radius) / 8f); float num2 = 1f - num * num * (3f - 2f * num); return h + (level - h) * num2; } public float RawHeight(float x, float z) { float num = (_large.Noise(x * 0.02f, z * 0.02f) * 0.5f + 0.5f) * 0.8f; float num2 = (_small.Noise(x * 0.08f, z * 0.08f) * 0.5f + 0.5f) * 0.2f; float num3 = Clamp01(num + num2) * 10f; float num4 = Clamp01(((float)Math.Sqrt(x * x + z * z) / 125f - 0.65f) / 0.45000005f); float num5 = num4 * num4 * (3f - 2f * num4) * 35f; return num3 + num5; } public float ArrivalHeight(float x, float z) { return Height(x, z) + 1f; } public TerrainMeshData BuildMesh() { int num = 126; float num2 = 125f; TerrainMeshData terrainMeshData = new TerrainMeshData { Vertices = new Point3[num * num], U = new float[num * num], V = new float[num * num] }; for (int i = 0; i < num; i++) { for (int j = 0; j < num; j++) { int num3 = i * num + j; float x = 0f - num2 + (float)j * 2f; float z = 0f - num2 + (float)i * 2f; terrainMeshData.Vertices[num3] = new Point3(x, Height(x, z), z); terrainMeshData.U[num3] = (float)j / (float)(num - 1); terrainMeshData.V[num3] = (float)i / (float)(num - 1); } } List<int> list = new List<int>((num - 1) * (num - 1) * 6); for (int k = 0; k < num - 1; k++) { for (int l = 0; l < num - 1; l++) { int num4 = k * num + l; if (InsideDisc(terrainMeshData.Vertices[num4]) && InsideDisc(terrainMeshData.Vertices[num4 + 1]) && InsideDisc(terrainMeshData.Vertices[num4 + num]) && InsideDisc(terrainMeshData.Vertices[num4 + num + 1])) { list.Add(num4); list.Add(num4 + num); list.Add(num4 + 1); list.Add(num4 + 1); list.Add(num4 + num); list.Add(num4 + num + 1); } } } terrainMeshData.Triangles = list.ToArray(); return terrainMeshData; } private static bool InsideDisc(Point3 p) { return p.X * p.X + p.Z * p.Z <= 15625f; } private static float Clamp01(float v) { if (!(v < 0f)) { if (!(v > 1f)) { return v; } return 1f; } return 0f; } } public struct Disc { public float X; public float Z; public float R; public Disc(float x, float z, float r) { X = x; Z = z; R = r; } } public static class Scatter { public static List<(float X, float Z)> Points(int seed, int count, float radius, Disc[] keepClear) { Random random = new Random(seed); List<(float, float)> list = new List<(float, float)>(count); int num = 0; while (list.Count < count && num < count * 20) { num++; float num2 = (float)(random.NextDouble() * 2.0 - 1.0) * radius; float num3 = (float)(random.NextDouble() * 2.0 - 1.0) * radius; if (num2 * num2 + num3 * num3 > radius * radius) { continue; } bool flag = false; for (int i = 0; i < keepClear.Length; i++) { Disc disc = keepClear[i]; if ((num2 - disc.X) * (num2 - disc.X) + (num3 - disc.Z) * (num3 - disc.Z) < disc.R * disc.R) { flag = true; break; } } if (!flag) { list.Add((num2, num3)); } } return list; } } public struct RuinPiece { public string Prefab; public float X; public float Z; public float Y; public float Yaw; public float Tilt; public float Scale; public RuinPiece(string prefab, float x, float z, float y = 0f, float yaw = 0f, float tilt = 0f, float scale = 1f) { Prefab = prefab; X = x; Z = z; Y = y; Yaw = yaw; Tilt = tilt; Scale = scale; } } public static class ShamballaLayout { public static readonly RuinPiece[] Pieces = Build(); public static readonly RuinPiece[] Crystals = new RuinPiece[7] { new RuinPiece("crystal_wall_1x1", 0f, 0f, 0f, 0f, 0f, 3f), new RuinPiece("crystal_wall_1x1", 14f, 8f, 0f, 30f, 12f, 2f), new RuinPiece("crystal_wall_1x1", -14f, 8f, 0f, -30f, -10f, 2f), new RuinPiece("crystal_wall_1x1", 18f, -9f, 0f, 60f, 18f, 1.6f), new RuinPiece("crystal_wall_1x1", -18f, -9f, 0f, -60f, -15f, 1.6f), new RuinPiece("crystal_wall_1x1", 6f, 22f, 0f, 10f, 8f, 2.2f), new RuinPiece("crystal_wall_1x1", -8f, 21f, 0f, -20f, -6f, 1.8f) }; private static RuinPiece[] Build() { List<RuinPiece> list = new List<RuinPiece>(); for (int i = -3; i <= 3; i++) { for (int j = -3; j <= 3; j++) { if ((i * 7 + j * 3) % 5 != 0 || (i == 0 && j == 0)) { list.Add(new RuinPiece("blackmarble_floor", (float)i * 2f, (float)j * 2f)); } } } list.Add(new RuinPiece("blackmarble_base_1", 0f, 0f)); for (int k = 0; k < 10; k++) { float num = (float)k * 36f * (float)Math.PI / 180f; float x = (float)Math.Cos(num) * 11f; float z = (float)Math.Sin(num) * 11f; bool flag = k == 2 || k == 7; float scale = ((k % 3 == 0) ? 0.6f : 1f); list.Add(new RuinPiece("blackmarble_column_1", x, z, 0f, (float)k * 36f, flag ? 85f : 0f, scale)); } float[][] array = new float[9][] { new float[3] { -16f, -16f, 0f }, new float[3] { -12f, -16f, 0f }, new float[3] { 12f, -16f, 0f }, new float[3] { 16f, -12f, 90f }, new float[3] { 16f, 4f, 90f }, new float[3] { -16f, -8f, 90f }, new float[3] { -16f, 8f, 90f }, new float[3] { -8f, 18f, 0f }, new float[3] { 10f, 18f, 0f } }; foreach (float[] array2 in array) { list.Add(new RuinPiece("stone_wall_4x2", array2[0], array2[1], 0f, array2[2])); } list.Add(new RuinPiece("stone_wall_2x1", -4f, -16f)); list.Add(new RuinPiece("stone_wall_2x1", 6f, -16f, 0f, 0f, 0f, 0.8f)); list.Add(new RuinPiece("stone_wall_1x1", 16f, -4f, 0f, 90f)); list.Add(new RuinPiece("stone_wall_1x1", 2f, 18f)); list.Add(new RuinPiece("blackmarble_arch", 0f, -16f)); list.Add(new RuinPiece("stone_arch", 0f, 18f)); list.Add(new RuinPiece("stone_stair", 0f, -9f, 0f, 180f)); list.Add(new RuinPiece("stone_pillar", 20f, 12f)); list.Add(new RuinPiece("stone_pillar", -21f, 10f, 0f, 0f, 70f)); list.Add(new RuinPiece("stone_pillar", 22f, -14f, 0f, 0f, 0f, 0.7f)); list.Add(new RuinPiece("stone_pillar", -22f, -14f)); list.Add(new RuinPiece("piece_dvergr_lantern", 7f, 7f)); list.Add(new RuinPiece("piece_dvergr_lantern", -7f, 7f)); list.Add(new RuinPiece("piece_dvergr_lantern", 7f, -7f)); list.Add(new RuinPiece("piece_dvergr_lantern", -7f, -7f)); return list.ToArray(); } } public static class VegetationBudget { public static int[] Share(int[] wanted, int cap) { int num = wanted.Sum(); if (num <= cap) { return (int[])wanted.Clone(); } int num2 = wanted.Count((int w) => w > 0); double scale = (double)Math.Max(0, cap - num2) / (double)num; return wanted.Select((int w) => (w > 0) ? (1 + (int)Math.Floor((double)w * scale)) : 0).ToArray(); } } } namespace Agartha.Patches { [HarmonyPatch(typeof(StaticPhysics), "Awake")] internal static class StaticPhysicsPatch { private static void Postfix(StaticPhysics __instance) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) if (((Component)__instance).transform.position.y > 3000f) { __instance.m_checkSolids = true; } } } }