Decompiled source of TerrainRandomiser v1.2.0
TerrainRandomiser.dll
Decompiled a week ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.CodeDom.Compiler; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Resources; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using ExitGames.Client.Photon; using HarmonyLib; using Microsoft.CodeAnalysis; using Newtonsoft.Json; using Peak; using Photon.Pun; using Photon.Realtime; using PhotonCustomPropsUtils; using Steamworks; using TerrainRandomiser.TerrainGeneration; using Unity.Burst; using Unity.Collections; using Unity.Jobs; using Unity.Mathematics; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.UIElements; using Zorro.ControllerSupport; using Zorro.Core; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("TerrainRandomiser")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.2.0")] [assembly: AssemblyInformationalVersion("1.2.0+4a7d996943cdfa67586040dcbcc0d312c9b94f32")] [assembly: AssemblyProduct("TerrainRandomiser")] [assembly: AssemblyTitle("TerrainRandomiser")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.2.0.0")] [module: UnverifiableCode] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } } public static class AreaVoxeliser { [BurstCompile] private struct BuildOverlapCommandsFirstPassJob : IJobParallelFor { [WriteOnly] public NativeArray<OverlapBoxCommand> commands; public int broadCellsX; public int broadCellsY; public int broadCellSize; public float spacing; public float3 offset; public QueryParameters query; public void Execute(int index) { //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_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_006c: 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_0082: 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_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0097: 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_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: 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) int num = index % broadCellsX; int num2 = index / broadCellsX; int num3 = num2 % broadCellsY; int num4 = num2 / broadCellsY; float num5 = (float)broadCellSize * spacing; float3 val = default(float3); ((float3)(ref val))..ctor((float)num, (float)num3, (float)num4); float3 val2 = default(float3); ((float3)(ref val2))..ctor(1f, 1f, 1f); float3 val3 = offset + val * num5 + val2 * ((num5 - spacing) * 0.5f); commands[index] = new OverlapBoxCommand(float3.op_Implicit(val3), float3.op_Implicit(val2 * num5 * 0.5f), quaternion.op_Implicit(quaternion.identity), query); } } [BurstCompile] private struct ProcessFirstPassResultsJob : IJobParallelFor { [ReadOnly] public NativeArray<ColliderHit> results; [WriteOnly] public NativeArray<byte> activeBlocks; public void Execute(int index) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) ref NativeArray<byte> reference = ref activeBlocks; ColliderHit val = results[index]; reference[index] = (byte)((((ColliderHit)(ref val)).instanceID != 0) ? 1 : 0); } } [BurstCompile] private struct BuildOverlapCommandsSecondPassJob : IJobParallelFor { [WriteOnly] public NativeArray<OverlapBoxCommand> commands; [ReadOnly] public NativeList<int> firstPassOccupiedIndexes; public int blocksX; public int blocksY; public int broadCellCoverage; public float spacing; public float3 offset; public QueryParameters query; public void Execute(int index) { //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: 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_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: 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_00fc: 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_0103: 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_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011a: 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_0124: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) int num = firstPassOccupiedIndexes[index]; int num2 = num % blocksX; int num3 = num / blocksX; int num4 = num3 % blocksY; int num5 = num3 / blocksY; int num6 = broadCellCoverage * broadCellCoverage * broadCellCoverage; float num7 = (float)broadCellCoverage * spacing; float3 val = default(float3); ((float3)(ref val))..ctor((float)num2, (float)num4, (float)num5); float3 val2 = default(float3); ((float3)(ref val2))..ctor(1f, 1f, 1f); float3 val3 = default(float3); for (int i = 0; i < num6; i++) { int num8 = i % broadCellCoverage; int num9 = i / broadCellCoverage; int num10 = num9 % broadCellCoverage; int num11 = num9 / broadCellCoverage; ((float3)(ref val3))..ctor((float)num8, (float)num10, (float)num11); float3 val4 = offset + (val * (float)broadCellCoverage + val3) * spacing; commands[index * num6 + i] = new OverlapBoxCommand(float3.op_Implicit(val4), float3.op_Implicit(val2 * spacing * 0.5f), quaternion.op_Implicit(quaternion.identity), query); } } } [BurstCompile] public struct FillOccupancyJob : IJobParallelFor { [ReadOnly] public NativeList<int> firstPassOccupiedIndexes; [ReadOnly] public NativeArray<ColliderHit> results; [WriteOnly] public NativeArray<uint> occupancy; public int3 gridRes; public int broadCellsX; public int broadCellsY; public int broadCellCoverage; public int innerCellCount; public void Execute(int i) { //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) int num = firstPassOccupiedIndexes[i]; int num2 = num % broadCellsX; int num3 = num / broadCellsX; int num4 = num3 % broadCellsY; int num5 = num3 / broadCellsY; for (int j = 0; j < innerCellCount; j++) { int num6 = j % broadCellCoverage; int num7 = j / broadCellCoverage; int num8 = num7 % broadCellCoverage; int num9 = num7 / broadCellCoverage; int num10 = num2 * broadCellCoverage + num6; int num11 = num4 * broadCellCoverage + num8; int num12 = num5 * broadCellCoverage + num9; if (num10 < gridRes.x && num11 < gridRes.y && num12 < gridRes.z) { int num13 = num10 + num11 * gridRes.x + num12 * gridRes.x * gridRes.y; int num14 = i * innerCellCount + j; ColliderHit val = results[num14]; if (((ColliderHit)(ref val)).instanceID != 0) { occupancy[num13] = 1u; } } } } } public class TempLayerAssignment { public GameObject go; public int originalLayer; } private const int TempLayer = 19; private const int BatchSize = 128; private const int BroadCellCoverage = 4; public static List<TempLayerAssignment> tempLayerAssignments = new List<TempLayerAssignment>(); private static NativeArray<OverlapBoxCommand> commands; private static NativeArray<ColliderHit> results; private static NativeArray<byte> activeCells; private static NativeList<int> occupiedIndexes; public static NativeArray<uint> BuildOccupancyGrid() { //IL_002f: 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_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0058: 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_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: 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) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_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_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: 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_010a: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0189: 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_0195: 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_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01c9: Unknown result type (might be due to invalid IL or missing references) //IL_022b: Unknown result type (might be due to invalid IL or missing references) //IL_0230: Unknown result type (might be due to invalid IL or missing references) //IL_0247: Unknown result type (might be due to invalid IL or missing references) //IL_024c: Unknown result type (might be due to invalid IL or missing references) //IL_0263: Unknown result type (might be due to invalid IL or missing references) //IL_0268: Unknown result type (might be due to invalid IL or missing references) //IL_0277: Unknown result type (might be due to invalid IL or missing references) //IL_027c: Unknown result type (might be due to invalid IL or missing references) //IL_0283: Unknown result type (might be due to invalid IL or missing references) //IL_0288: Unknown result type (might be due to invalid IL or missing references) //IL_02b1: Unknown result type (might be due to invalid IL or missing references) //IL_02b3: Unknown result type (might be due to invalid IL or missing references) //IL_02ba: Unknown result type (might be due to invalid IL or missing references) //IL_02bc: Unknown result type (might be due to invalid IL or missing references) //IL_02d0: Unknown result type (might be due to invalid IL or missing references) //IL_02d6: Unknown result type (might be due to invalid IL or missing references) //IL_02d8: Unknown result type (might be due to invalid IL or missing references) //IL_02dd: Unknown result type (might be due to invalid IL or missing references) //IL_02df: Unknown result type (might be due to invalid IL or missing references) //IL_02e4: Unknown result type (might be due to invalid IL or missing references) //IL_02ef: Unknown result type (might be due to invalid IL or missing references) //IL_02f1: Unknown result type (might be due to invalid IL or missing references) //IL_02f6: Unknown result type (might be due to invalid IL or missing references) //IL_0302: Unknown result type (might be due to invalid IL or missing references) //IL_0307: Unknown result type (might be due to invalid IL or missing references) //IL_030e: Unknown result type (might be due to invalid IL or missing references) //IL_0313: Unknown result type (might be due to invalid IL or missing references) //IL_0328: Unknown result type (might be due to invalid IL or missing references) //IL_032a: Unknown result type (might be due to invalid IL or missing references) //IL_032f: Unknown result type (might be due to invalid IL or missing references) //IL_034d: Unknown result type (might be due to invalid IL or missing references) //IL_0352: Unknown result type (might be due to invalid IL or missing references) //IL_0359: Unknown result type (might be due to invalid IL or missing references) //IL_035e: Unknown result type (might be due to invalid IL or missing references) //IL_0365: Unknown result type (might be due to invalid IL or missing references) //IL_0367: Unknown result type (might be due to invalid IL or missing references) //IL_036e: Unknown result type (might be due to invalid IL or missing references) //IL_036f: Unknown result type (might be due to invalid IL or missing references) //IL_03ae: Unknown result type (might be due to invalid IL or missing references) //IL_03b4: Unknown result type (might be due to invalid IL or missing references) //IL_03b6: Unknown result type (might be due to invalid IL or missing references) //IL_03bb: Unknown result type (might be due to invalid IL or missing references) //IL_03f7: Unknown result type (might be due to invalid IL or missing references) //IL_03f9: Unknown result type (might be due to invalid IL or missing references) //IL_03fd: Unknown result type (might be due to invalid IL or missing references) LightVolume instance = LightVolume.instance; int3 val = default(int3); ((int3)(ref val))..ctor((int)instance.gridRes.x, (int)instance.gridRes.y, (int)instance.gridRes.z); int num = val.x * val.y * val.z; float raySpacing = instance.raySpacing; float3 offset = float3.op_Implicit(instance.gridOffset); int num2 = Mathf.CeilToInt((float)(val.x / 4)); int num3 = Mathf.CeilToInt((float)(val.y / 4)); int num4 = Mathf.CeilToInt((float)(val.z / 4)); int num5 = num2 * num3 * num4; LayerMask occluderMask = instance.occluderMask; LayerMask val2 = LayerMask.op_Implicit(LayerMask.op_Implicit(occluderMask) & -524289); MoveDoNotBakeToSeperateLayer(); commands = new NativeArray<OverlapBoxCommand>(num5, (Allocator)3, (NativeArrayOptions)0); results = new NativeArray<ColliderHit>(num5, (Allocator)3, (NativeArrayOptions)1); activeCells = new NativeArray<byte>(num5, (Allocator)3, (NativeArrayOptions)1); QueryParameters query = new QueryParameters { layerMask = LayerMask.op_Implicit(val2), hitTriggers = (QueryTriggerInteraction)1 }; BuildOverlapCommandsFirstPassJob buildOverlapCommandsFirstPassJob = new BuildOverlapCommandsFirstPassJob { commands = commands, broadCellsX = num2, broadCellsY = num3, broadCellSize = 4, spacing = raySpacing, offset = offset, query = query }; JobHandle val3 = IJobParallelForExtensions.Schedule<BuildOverlapCommandsFirstPassJob>(buildOverlapCommandsFirstPassJob, num5, 128, default(JobHandle)); JobHandle val4 = OverlapBoxCommand.ScheduleBatch(commands, results, 128, 1, val3); ProcessFirstPassResultsJob processFirstPassResultsJob = new ProcessFirstPassResultsJob { results = results, activeBlocks = activeCells }; JobHandle val5 = IJobParallelForExtensions.Schedule<ProcessFirstPassResultsJob>(processFirstPassResultsJob, num5, 128, val4); ((JobHandle)(ref val5)).Complete(); occupiedIndexes = new NativeList<int>(0, AllocatorHandle.op_Implicit((Allocator)3)); for (int i = 0; i < num5; i++) { if (activeCells[i] != 0) { occupiedIndexes.Add(ref i); } } int length = occupiedIndexes.Length; int num6 = 64; commands.Dispose(); commands = new NativeArray<OverlapBoxCommand>(length * num6, (Allocator)3, (NativeArrayOptions)0); results.Dispose(); results = new NativeArray<ColliderHit>(length * num6, (Allocator)3, (NativeArrayOptions)1); activeCells.Dispose(); activeCells = new NativeArray<byte>(length * num6, (Allocator)3, (NativeArrayOptions)1); BuildOverlapCommandsSecondPassJob buildOverlapCommandsSecondPassJob = new BuildOverlapCommandsSecondPassJob { commands = commands, firstPassOccupiedIndexes = occupiedIndexes, blocksX = num2, blocksY = num3, broadCellCoverage = 4, spacing = raySpacing, offset = offset, query = query }; JobHandle val6 = IJobParallelForExtensions.Schedule<BuildOverlapCommandsSecondPassJob>(buildOverlapCommandsSecondPassJob, length, 128, default(JobHandle)); JobHandle val7 = OverlapBoxCommand.ScheduleBatch(commands, results, 128, 1, val6); ProcessFirstPassResultsJob processFirstPassResultsJob2 = new ProcessFirstPassResultsJob { results = results, activeBlocks = activeCells }; JobHandle val8 = IJobParallelForExtensions.Schedule<ProcessFirstPassResultsJob>(processFirstPassResultsJob2, length * num6, 128, val7); ((JobHandle)(ref val8)).Complete(); NativeArray<uint> val9 = default(NativeArray<uint>); val9..ctor(num, (Allocator)4, (NativeArrayOptions)1); FillOccupancyJob fillOccupancyJob = new FillOccupancyJob { firstPassOccupiedIndexes = occupiedIndexes, results = results, occupancy = val9, gridRes = val, broadCellsX = num2, broadCellsY = num3, broadCellCoverage = 4, innerCellCount = num6 }; JobHandle val10 = IJobParallelForExtensions.Schedule<FillOccupancyJob>(fillOccupancyJob, occupiedIndexes.Length, 128, default(JobHandle)); ((JobHandle)(ref val10)).Complete(); commands.Dispose(); results.Dispose(); activeCells.Dispose(); occupiedIndexes.Dispose(); RestoreTempLayerAssignments(); return val9; } private static void MoveDoNotBakeToSeperateLayer() { tempLayerAssignments.Clear(); GameObject[] array = GameObject.FindGameObjectsWithTag("DoNotBake"); GameObject[] array2 = array; foreach (GameObject val in array2) { Collider[] componentsInChildren = val.GetComponentsInChildren<Collider>(); Collider[] array3 = componentsInChildren; foreach (Collider val2 in array3) { GameObject gameObject = ((Component)val2).gameObject; tempLayerAssignments.Add(new TempLayerAssignment { go = gameObject, originalLayer = gameObject.layer }); gameObject.layer = 19; } } } private static void RestoreTempLayerAssignments() { foreach (TempLayerAssignment tempLayerAssignment in tempLayerAssignments) { if ((Object)(object)tempLayerAssignment.go != (Object)null) { tempLayerAssignment.go.layer = tempLayerAssignment.originalLayer; } } tempLayerAssignments.Clear(); } } namespace TerrainRandomiser { public static class BiomeDatabase { public static List<SectionData> Sections = new List<SectionData> { new SectionData { sectionName = "Biome_1", biomes = new Dictionary<BiomeType, BiomeData> { [(BiomeType)0] = new BiomeData { variants = new List<string> { "Default", "SnakeBeach", "RedBeach", "BlueBeach", "JellyHell", "BlackSand" }, variantSelectionType = VariantSelectionType.BiomeVariant } } }, new SectionData { sectionName = "Biome_2", biomes = new Dictionary<BiomeType, BiomeData> { [(BiomeType)1] = new BiomeData { variants = new List<string> { "Default", "Lava", "Pillars", "Thorny", "Bombs", "Ivy", "SkyJungle" }, variantSelectionType = VariantSelectionType.BiomeVariant }, [(BiomeType)7] = new BiomeData { variants = new List<string> { "Default", "Cave Mania", "Deep Water", "Deep Woods", "Clearcut" }, variantSelectionType = VariantSelectionType.VariantObject } } }, new SectionData { sectionName = "Biome_3", biomes = new Dictionary<BiomeType, BiomeData> { [(BiomeType)2] = new BiomeData { variants = new List<string> { "Default", "Lava", "Spiky", "GeyserHell" }, variantSelectionType = VariantSelectionType.BiomeVariant }, [(BiomeType)6] = new BiomeData { variants = new List<string> { "NoVariant", "ScorpionsHell", "CacusHell", "CactusForest", "DynamiteHell", "TumblerHell" }, variantSelectionType = VariantSelectionType.VariantObject } } }, new SectionData { sectionName = "Biome_4", biomes = new Dictionary<BiomeType, BiomeData> { [(BiomeType)3] = new BiomeData { variants = new List<string>(), variantSelectionType = VariantSelectionType.VariantObject }, [(BiomeType)8] = new BiomeData { variants = new List<string>(), variantSelectionType = VariantSelectionType.VariantObject } } } }; } public enum VariantSelectionType { BiomeVariant, VariantObject } [Serializable] public class MapSettings { public bool enableRandomiser; public int seed; public bool autoRandomSeed; public bool fullyRandom; public List<SectionSettings> sectionSettings = new List<SectionSettings>(); public static MapSettings CreateDefaultMapSettings() { //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_0052: 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_009f: 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) List<SectionSettings> list = new List<SectionSettings>(); foreach (SectionData section in BiomeDatabase.Sections) { if (section.biomes.Count != 0) { BiomeType key = section.biomes.FirstOrDefault().Key; string selectedVariant = ((section.biomes[key].variants.Count > 0) ? section.biomes[key].variants[0] : ""); list.Add(new SectionSettings { overrideEnabled = true, sectionName = section.sectionName, selectedBiomeType = key, selectedVariant = selectedVariant }); } } return new MapSettings { seed = 42, autoRandomSeed = false, fullyRandom = false, sectionSettings = list }; } } [Serializable] public class SectionSettings { public bool overrideEnabled; public string sectionName; public BiomeType selectedBiomeType; public string selectedVariant; public bool randomBiome; public bool randomVariant; } [Serializable] public class SectionData { public string sectionName; public Dictionary<BiomeType, BiomeData> biomes = new Dictionary<BiomeType, BiomeData>(); } [Serializable] public class BiomeData { public BiomeType biomeType; public List<string> variants = new List<string>(); public VariantSelectionType variantSelectionType = VariantSelectionType.BiomeVariant; } [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInPlugin("com.snosz.terrainrandomiser", "TerrainRandomiser", "1.2.0")] public class Plugin : BaseUnityPlugin { [HarmonyPatch(typeof(BoardingPass), "Initialize")] private static class BoardingPassInitializePatch { private static void Postfix(BoardingPass __instance) { Instance.CreateUI(__instance); } } [HarmonyPatch(typeof(BoardingPass), "StartGame")] private static class BoardingPassStartGamePatch { private static bool Prefix(BoardingPass __instance) { if (!PhotonNetwork.IsMasterClient) { return true; } if (!Instance.mapSettings.enableRandomiser) { Instance.roomMapSettings = Instance.mapSettings; SaveMapSettings(); SyncWithClients(Instance.mapSettings); return true; } MapSettings mapSettings = Instance.mapSettings; SaveMapSettings(); if (mapSettings.fullyRandom || mapSettings.autoRandomSeed) { RandomiseSeed(mapSettings); } if (mapSettings.fullyRandom) { RandomiseAllSections(mapSettings); } else { RandomiseOverrides(mapSettings); } SyncWithClients(mapSettings); LoadWilIsland(); return false; } } [HarmonyPatch(typeof(NavigationContainerHandler), "LateUpdate")] internal static class NavHandler_LateUpdate_Patch { public static bool Prefix() { if ((Object)(object)GUIManager.instance == (Object)null || (Object)(object)GUIManager.instance.boardingPass == (Object)null) { return true; } if (((MenuWindow)GUIManager.instance.boardingPass).isOpen) { return false; } return true; } } [HarmonyPatch(typeof(SteamLobbyHandler), "OnLobbyEnter")] private static class OnLobbyEnter { private static void Postfix(SteamLobbyHandler __instance, LobbyEnter_t param) { //IL_0001: 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) if (param.m_EChatRoomEnterResponse == 1) { string lobbyData = SteamMatchmaking.GetLobbyData(__instance.LobbySteamId, "TR_roomMapSettings"); if (!string.IsNullOrEmpty(lobbyData)) { Instance.roomMapSettings = JsonConvert.DeserializeObject<MapSettings>(lobbyData); } } } } public static Plugin Instance; private static Harmony _harmony; public static List<int> viewIDsToSend; public static List<PhotonView>? viewsRequiringIDs; public static List<int> receivedViewIDs; public static bool awaitingViewIDs = false; public AssetBundle seedPickerUIBundle; public const int MAX_SEED_VALUE = 999999999; public MapSettings mapSettings; public MapSettings roomMapSettings; private RandomiserUIManager uiManager; private PhotonScopedManager photonManager; private GameObject uidocObject; public AssetBundle visibilityComputeBundle; private static readonly string SavePath = Path.Combine(Application.persistentDataPath, "TerrainRandomiser", "MapSettings.json"); public static ConfigEntry<bool> EnableLightMapBaking; public static bool loadingQuickSave; public static bool hasQuickSave; public static int masterSeed => Instance.roomMapSettings.seed; private void Awake() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown Instance = this; _harmony = new Harmony("com.snosz.terrainrandomiser"); ((BaseUnityPlugin)this).Config.SaveOnConfigSet = true; EnableLightMapBaking = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableLightMapBaking", true, "Generates a lightmap which is used for certain game mechanics. Disable this if the game crashes."); byte[] terrainrandomiser = Resource1.terrainrandomiser; seedPickerUIBundle = AssetBundle.LoadFromMemory(terrainrandomiser); byte[] visibilitycompute = Resource1.visibilitycompute; visibilityComputeBundle = AssetBundle.LoadFromMemory(visibilitycompute); LightMapBaker.computeShader = visibilityComputeBundle.LoadAsset<ComputeShader>("SkyVisibilityDDA"); LoadMapSettings(); if (mapSettings == null) { mapSettings = MapSettings.CreateDefaultMapSettings(); } AddPhotonManager(); _harmony.PatchAll(); } private void OnDestroy() { _harmony.UnpatchSelf(); if ((Object)(object)seedPickerUIBundle != (Object)null) { if ((Object)(object)uidocObject != (Object)null) { uidocObject.GetComponent<UIDocument>().rootVisualElement.Clear(); Object.Destroy((Object)(object)uidocObject); } seedPickerUIBundle.Unload(true); seedPickerUIBundle = null; } } private void AddPhotonManager() { photonManager = PhotonCustomPropsUtilsPlugin.GetManager("com.snosz.terrainrandomiser"); photonManager.RegisterOnJoinedRoom((Action<Player>)delegate { if (PhotonNetwork.IsMasterClient) { string text = JsonConvert.SerializeObject((object)mapSettings, (Formatting)0); photonManager.SetRoomProperty("roomMapSettings", (object)text); } }); photonManager.RegisterRoomProperty<string>("roomMapSettings", (RoomEventType)2, (Action<string>)delegate(string value) { roomMapSettings = JsonConvert.DeserializeObject<MapSettings>(value); }); photonManager.RegisterRoomProperty<int[]>("propViews", (RoomEventType)2, (Action<int[]>)delegate(int[] val) { if (!PhotonNetwork.IsMasterClient) { if (receivedViewIDs == null) { receivedViewIDs = new List<int>(); } else { receivedViewIDs.Clear(); } receivedViewIDs = val.ToList(); if (awaitingViewIDs) { Instance.UpdateRequiredViewIDs(); } } }); } public void UpdateRequiredViewIDs() { if (PhotonNetwork.IsMasterClient) { return; } if (viewsRequiringIDs == null || receivedViewIDs == null) { Debug.LogError((object)"[TerrainRandomiser] Required lists did not initialize or have already been resolved."); return; } if (viewsRequiringIDs.Count > receivedViewIDs.Count) { Debug.LogError((object)"[TerrainRandomiser] ID Count mismatch! Map will be out of sync!"); return; } for (int i = 0; i < viewsRequiringIDs.Count; i++) { if ((Object)(object)viewsRequiringIDs[i] != (Object)null && (Object)(object)((Component)viewsRequiringIDs[i]).gameObject != (Object)null) { viewsRequiringIDs[i].ViewID = receivedViewIDs[i]; } else { Debug.LogError((object)$"Null or destroyed PhotonView at index {i}"); } } Debug.LogError((object)$"[TerrainRandomiser] Updated receivedViewIDs with {receivedViewIDs.Count} IDs"); receivedViewIDs.Clear(); viewsRequiringIDs.Clear(); viewsRequiringIDs = null; awaitingViewIDs = false; } private void CreateUI(BoardingPass bpInstance) { GameObject val = Instance.seedPickerUIBundle.LoadAsset<GameObject>("UIDocument"); Instance.uidocObject = Object.Instantiate<GameObject>(val, ((Component)bpInstance).transform); uiManager = Instance.uidocObject.AddComponent<RandomiserUIManager>(); } public static void LoadWilIsland() { AirportCheckInKiosk val = Object.FindFirstObjectByType<AirportCheckInKiosk>(); if (!((Object)(object)val == (Object)null)) { int ascentIndex = GUIManager.instance.boardingPass.ascentIndex; ((MonoBehaviourPun)val).photonView.RPC("BeginIslandLoadRPC", (RpcTarget)0, new object[3] { "WilIsland", ascentIndex, RunSettings.GetSerializedRunSettings() }); } } private static void RandomiseSeed(MapSettings settings) { settings.seed = Random.Range(0, 999999999); } private static void RandomiseAllSections(MapSettings settings) { List<SectionData> sections = BiomeDatabase.Sections; for (int i = 0; i < sections.Count; i++) { ApplyRandomBiomeAndVariant(settings, i, sections[i]); } } private static void RandomiseOverrides(MapSettings settings) { //IL_0060: Unknown result type (might be due to invalid IL or missing references) List<SectionData> sections = BiomeDatabase.Sections; for (int i = 0; i < settings.sectionSettings.Count; i++) { SectionSettings sectionSettings = settings.sectionSettings[i]; if (sectionSettings.overrideEnabled) { if (sectionSettings.randomBiome) { ApplyRandomBiomeAndVariant(settings, i, sections[i]); } else if (sectionSettings.randomVariant) { ApplyRandomVariant(settings, i, sections[i].biomes[sectionSettings.selectedBiomeType]); } } } } private static void ApplyRandomBiomeAndVariant(MapSettings settings, int index, SectionData section) { //IL_002e: 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) int index2 = Random.Range(0, section.biomes.Count); KeyValuePair<BiomeType, BiomeData> keyValuePair = section.biomes.ElementAt(index2); settings.sectionSettings[index].selectedBiomeType = keyValuePair.Key; ApplyRandomVariant(settings, index, keyValuePair.Value); } private static void ApplyRandomVariant(MapSettings settings, int index, BiomeData biomeData) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) if (biomeData.variants.Count != 0) { BiomeType selectedBiomeType = settings.sectionSettings[index].selectedBiomeType; int index2 = Random.Range(0, biomeData.variants.Count); settings.sectionSettings[index].selectedVariant = biomeData.variants[index2]; } } public static void SyncWithClients(MapSettings settings) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) Instance.roomMapSettings = settings; string text = JsonConvert.SerializeObject((object)Instance.roomMapSettings, (Formatting)0); Instance.photonManager.SetRoomProperty("roomMapSettings", (object)text); SteamLobbyHandler service = GameHandler.GetService<SteamLobbyHandler>(); SteamMatchmaking.SetLobbyData(service.LobbySteamId, "TR_roomMapSettings", text); } public void SendViewIDsToClients(List<int> viewIDs) { photonManager.SetRoomProperty("propViews", (object)viewIDs.ToArray()); } public static void SaveMapSettings() { string contents = JsonConvert.SerializeObject((object)Instance.mapSettings, (Formatting)1); File.WriteAllText(SavePath, contents); } public static void LoadMapSettings() { string directoryName = Path.GetDirectoryName(SavePath); if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } if (!File.Exists(SavePath)) { return; } string text = File.ReadAllText(SavePath); MapSettings mapSettings = JsonConvert.DeserializeObject<MapSettings>(text); if (mapSettings != null) { Instance.mapSettings = mapSettings; if (Instance.mapSettings.sectionSettings.Count < 4) { Instance.mapSettings = MapSettings.CreateDefaultMapSettings(); } } } } internal class QuickSavePatches { public class TRSaveData { public string runId; public MapSettings mapSettings; } [HarmonyPatch(typeof(Quicksave), "SaveNow")] private static class SaveNowPatch { private static bool Prefix() { //IL_003f: 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_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.Instance.roomMapSettings.enableRandomiser) { return true; } Debug.Log((object)("Saving game to app data folder as " + Quicksave.s_SaveName)); try { Singleton<ReconnectHandler>.Instance.UpdateForAllCharacters(); SaveData val = SaveData.Create(); string contents = JsonUtility.ToJson((object)val); File.WriteAllText(Quicksave.SaveFile.FullName, contents); TRSaveData tRSaveData = new TRSaveData { runId = val.run.runId, mapSettings = Plugin.Instance.roomMapSettings }; string contents2 = JsonConvert.SerializeObject((object)tRSaveData); string path = Path.Join((ReadOnlySpan<char>)Application.persistentDataPath, (ReadOnlySpan<char>)"trquicksave.peak"); File.WriteAllText(path, contents2); } catch (Exception arg) { Console.WriteLine($"Failed to create save file: {arg}"); throw; } return false; } } [HarmonyPatch(typeof(Quicksave), "LoadSaveData")] private static class LoadSaveDataPatch { private static void Postfix(Action<bool> onLoaded = null) { try { string path = Path.Join((ReadOnlySpan<char>)Application.persistentDataPath, (ReadOnlySpan<char>)"trquicksave.peak"); string text = File.ReadAllText(path); TRSaveData tRSaveData = JsonConvert.DeserializeObject<TRSaveData>(text); if (tRSaveData != null && Quicksave._loadedData.run.runId == tRSaveData.runId) { Plugin.Instance.roomMapSettings = tRSaveData.mapSettings; Plugin.hasQuickSave = true; } else { Plugin.hasQuickSave = false; } } catch (Exception) { Plugin.hasQuickSave = false; } } } [HarmonyPatch(typeof(Quicksave), "LoadSavedGameScene")] private static class LoadSavedGameScenePatch { private static void Postfix() { if (Plugin.hasQuickSave) { Plugin.loadingQuickSave = true; } } } public const string tr_saveName = "trquicksave.peak"; } public class RandomiserUIManager : MonoBehaviour { [SerializeField] private UIDocument uiDocument; private IntegerField seedInput; private Button randomSeedButton; private Toggle autoSeedToggle; private Toggle fullyRandomToggle; private Toggle enableRandomiserToggle; private VisualElement randomiserMenu; private VisualElement biomeTabContainer; private List<Toggle> biomeOverrideToggles = new List<Toggle>(); private List<DropdownField> biomeDropdowns = new List<DropdownField>(); private List<DropdownField> variantDropdowns = new List<DropdownField>(); private MapSettings mapSettings; public void OnEnable() { mapSettings = Plugin.Instance.mapSettings; biomeOverrideToggles.Clear(); biomeDropdowns.Clear(); variantDropdowns.Clear(); uiDocument = ((Component)this).GetComponent<UIDocument>(); VisualElement rootVisualElement = uiDocument.rootVisualElement; seedInput = UQueryExtensions.Q<IntegerField>(rootVisualElement, "seedInput", (string)null); randomSeedButton = UQueryExtensions.Q<Button>(rootVisualElement, "randomSeedButton", (string)null); autoSeedToggle = UQueryExtensions.Q<Toggle>(rootVisualElement, "autoSeedToggle", (string)null); fullyRandomToggle = UQueryExtensions.Q<Toggle>(rootVisualElement, "fullyRandomToggle", (string)null); randomiserMenu = UQueryExtensions.Q<VisualElement>(rootVisualElement, "SeedPicker", (string)null); enableRandomiserToggle = UQueryExtensions.Q<Toggle>(rootVisualElement, "enableRandomiserToggle", (string)null); biomeTabContainer = (VisualElement)(object)UQueryExtensions.Q<TabView>(rootVisualElement, (string)null, (string)null); for (int i = 0; i < BiomeDatabase.Sections.Count; i++) { VisualElement val = UQueryExtensions.Q<VisualElement>(rootVisualElement, $"biome{i + 1}Tab", (string)null); biomeOverrideToggles.Add(UQueryExtensions.Q<Toggle>(val, "overrideBiomeToggle", (string)null)); biomeDropdowns.Add(UQueryExtensions.Q<DropdownField>(val, "biomeDropdown", (string)null)); variantDropdowns.Add(UQueryExtensions.Q<DropdownField>(val, "variantDropdown", (string)null)); } SetupBindings(); } private unsafe void SetupBindings() { //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_02e4: Unknown result type (might be due to invalid IL or missing references) //IL_03a0: Unknown result type (might be due to invalid IL or missing references) //IL_03a5: Unknown result type (might be due to invalid IL or missing references) ((BaseField<bool>)(object)enableRandomiserToggle).value = Plugin.Instance.mapSettings.enableRandomiser; INotifyValueChangedExtensions.RegisterValueChangedCallback<bool>((INotifyValueChanged<bool>)(object)enableRandomiserToggle, (EventCallback<ChangeEvent<bool>>)delegate(ChangeEvent<bool> evt) { OnEnableRandomiserChanged(evt.newValue); }); OnEnableRandomiserChanged(Plugin.Instance.mapSettings.enableRandomiser); randomSeedButton.clicked += OnRandomSeedPressed; ((BaseField<int>)(object)seedInput).value = mapSettings.seed; INotifyValueChangedExtensions.RegisterValueChangedCallback<int>((INotifyValueChanged<int>)(object)seedInput, (EventCallback<ChangeEvent<int>>)delegate(ChangeEvent<int> evt) { mapSettings.seed = evt.newValue; }); ((BaseField<bool>)(object)autoSeedToggle).value = mapSettings.autoRandomSeed; INotifyValueChangedExtensions.RegisterValueChangedCallback<bool>((INotifyValueChanged<bool>)(object)autoSeedToggle, (EventCallback<ChangeEvent<bool>>)delegate(ChangeEvent<bool> evt) { OnAutoSeedChanged(evt.newValue); }); OnAutoSeedChanged(mapSettings.autoRandomSeed); ((BaseField<bool>)(object)fullyRandomToggle).value = mapSettings.fullyRandom; INotifyValueChangedExtensions.RegisterValueChangedCallback<bool>((INotifyValueChanged<bool>)(object)fullyRandomToggle, (EventCallback<ChangeEvent<bool>>)delegate(ChangeEvent<bool> evt) { OnFullyRandomChanged(evt.newValue); }); OnFullyRandomChanged(mapSettings.fullyRandom); for (int num = 0; num < BiomeDatabase.Sections.Count; num++) { int index = num; SectionData sectionData = BiomeDatabase.Sections[num]; SectionSettings biomeSettings = ((num <= mapSettings.sectionSettings.Count) ? mapSettings.sectionSettings[num] : new SectionSettings { sectionName = $"Biome_{num + 1}", selectedBiomeType = sectionData.biomes.FirstOrDefault().Key }); ((BaseField<bool>)(object)biomeOverrideToggles[num]).value = biomeSettings.overrideEnabled; INotifyValueChangedExtensions.RegisterValueChangedCallback<bool>((INotifyValueChanged<bool>)(object)biomeOverrideToggles[num], (EventCallback<ChangeEvent<bool>>)delegate(ChangeEvent<bool> evt) { OnOverrideBiomeChanged(index, evt.newValue); }); OnOverrideBiomeChanged(index, biomeSettings.overrideEnabled); if (BiomeDatabase.Sections[num].biomes.Count > 1) { ((BasePopupField<string, string>)(object)biomeDropdowns[num]).choices.Add("Random"); } ((BasePopupField<string, string>)(object)biomeDropdowns[num]).choices.AddRange(sectionData.biomes.Keys.Select((BiomeType key) => ((object)(*(BiomeType*)(&key))/*cast due to .constrained prefix*/).ToString())); ((BaseField<string>)(object)biomeDropdowns[num]).value = (biomeSettings.randomBiome ? "Random" : ((object)Unsafe.As<BiomeType, BiomeType>(ref biomeSettings.selectedBiomeType)/*cast due to .constrained prefix*/).ToString()); INotifyValueChangedExtensions.RegisterValueChangedCallback<string>((INotifyValueChanged<string>)(object)biomeDropdowns[num], (EventCallback<ChangeEvent<string>>)delegate(ChangeEvent<string> evt) { OnBiomeChanged(index, evt.newValue); }); List<string> variants = sectionData.biomes[mapSettings.sectionSettings[num].selectedBiomeType].variants; if (variants.Count > 1) { ((BasePopupField<string, string>)(object)variantDropdowns[num]).choices.Add("Random"); } ((BasePopupField<string, string>)(object)variantDropdowns[num]).choices.AddRange(variants); ((BaseField<string>)(object)variantDropdowns[num]).value = (biomeSettings.randomVariant ? "Random" : biomeSettings.selectedVariant); INotifyValueChangedExtensions.RegisterValueChangedCallback<string>((INotifyValueChanged<string>)(object)variantDropdowns[num], (EventCallback<ChangeEvent<string>>)delegate(ChangeEvent<string> evt) { OnBiomeVariantChanged(index, biomeSettings, evt.newValue); }); TabView val = UQueryExtensions.Q<TabView>(uiDocument.rootVisualElement, (string)null, (string)null); List<Tab> list = UQueryExtensions.Query<Tab>((VisualElement)(object)val, (string)null, (string)null).ToList(); SectionSettings sectionSettings = mapSettings.sectionSettings[num]; list[num].label = ((object)Unsafe.As<BiomeType, BiomeType>(ref sectionSettings.selectedBiomeType)/*cast due to .constrained prefix*/).ToString().ToUpper(); } } private unsafe void OnBiomeChanged(int index, string value) { //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) if (value == "Random") { mapSettings.sectionSettings[index].randomBiome = true; mapSettings.sectionSettings[index].randomVariant = true; ((BasePopupField<string, string>)(object)variantDropdowns[index]).choices.Clear(); ((BasePopupField<string, string>)(object)variantDropdowns[index]).choices.Add("Random"); ((BaseField<string>)(object)variantDropdowns[index]).SetValueWithoutNotify("Random"); OnBiomeVariantChanged(index, mapSettings.sectionSettings[index], "Random"); TabView val = UQueryExtensions.Q<TabView>(uiDocument.rootVisualElement, (string)null, (string)null); val.activeTab.label = "RANDOM"; return; } Enum.TryParse<BiomeType>(value, out BiomeType result); mapSettings.sectionSettings[index].randomBiome = false; List<string> variants = BiomeDatabase.Sections[index].biomes[result].variants; ((BasePopupField<string, string>)(object)variantDropdowns[index]).choices.Clear(); if (variants.Count > 1) { ((BasePopupField<string, string>)(object)variantDropdowns[index]).choices.Add("Random"); } ((BasePopupField<string, string>)(object)variantDropdowns[index]).choices.AddRange(variants); mapSettings.sectionSettings[index].selectedBiomeType = result; TabView val2 = UQueryExtensions.Q<TabView>(uiDocument.rootVisualElement, (string)null, (string)null); val2.activeTab.label = ((object)(*(BiomeType*)(&result))/*cast due to .constrained prefix*/).ToString().ToUpper(); ((BaseField<string>)(object)variantDropdowns[index]).SetValueWithoutNotify("Random"); OnBiomeVariantChanged(index, mapSettings.sectionSettings[index], "Random"); } private void OnBiomeVariantChanged(int index, SectionSettings biome, string value) { if (value == "Random") { mapSettings.sectionSettings[index].randomVariant = true; } else { mapSettings.sectionSettings[index].randomVariant = false; } biome.selectedVariant = value; } private void OnOverrideBiomeChanged(int index, bool value) { mapSettings.sectionSettings[index].overrideEnabled = value; ((VisualElement)biomeDropdowns[index]).SetEnabled(value); ((VisualElement)variantDropdowns[index]).SetEnabled(value); } private void OnRandomSeedPressed() { int value = Random.Range(0, 999999999); ((BaseField<int>)(object)seedInput).value = value; } private void OnAutoSeedChanged(bool value) { if (((BaseField<bool>)(object)fullyRandomToggle).value && !value) { ((BaseField<bool>)(object)autoSeedToggle).SetValueWithoutNotify(true); return; } mapSettings.autoRandomSeed = value; ((VisualElement)seedInput).SetEnabled(!value); ((VisualElement)randomSeedButton).SetEnabled(!value); } private void OnEnableRandomiserChanged(bool value) { randomiserMenu.visible = value; mapSettings.enableRandomiser = value; } private void OnFullyRandomChanged(bool value) { if (value && !((BaseField<bool>)(object)autoSeedToggle).value) { ((BaseField<bool>)(object)autoSeedToggle).value = true; } biomeTabContainer.SetEnabled(!value); ((VisualElement)autoSeedToggle).SetEnabled(!value); mapSettings.fullyRandom = value; } } [GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "18.0.0.0")] [DebuggerNonUserCode] [CompilerGenerated] internal class Resource1 { private static ResourceManager resourceMan; private static CultureInfo resourceCulture; [EditorBrowsable(EditorBrowsableState.Advanced)] internal static ResourceManager ResourceManager { get { if (resourceMan == null) { ResourceManager resourceManager = new ResourceManager("TerrainRandomiser.Resource1", typeof(Resource1).Assembly); resourceMan = resourceManager; } return resourceMan; } } [EditorBrowsable(EditorBrowsableState.Advanced)] internal static CultureInfo Culture { get { return resourceCulture; } set { resourceCulture = value; } } internal static byte[] terrainrandomiser { get { object obj = ResourceManager.GetObject("terrainrandomiser", resourceCulture); return (byte[])obj; } } internal static byte[] visibilitycompute { get { object obj = ResourceManager.GetObject("visibilitycompute", resourceCulture); return (byte[])obj; } } internal Resource1() { } } } namespace TerrainRandomiser.TerrainGeneration { public static class GenerationPatches { [HarmonyPatch] public static class RemoveDebugLogsPatch { [HarmonyTranspiler] [HarmonyPatch(typeof(JungleVine), "Awake")] [HarmonyPatch(typeof(JungleVine), "PickTreePlatforms")] [HarmonyPatch(typeof(SpawnConnectingBridge), "CheckCondition")] private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { MethodInfo logMethod = AccessTools.Method(typeof(Debug), "Log", new Type[1] { typeof(object) }, (Type[])null); MethodInfo logErrorMethod = AccessTools.Method(typeof(Debug), "LogError", new Type[1] { typeof(object) }, (Type[])null); foreach (CodeInstruction instruction in instructions) { if (CodeInstructionExtensions.Calls(instruction, logMethod) || CodeInstructionExtensions.Calls(instruction, logErrorMethod)) { yield return new CodeInstruction(OpCodes.Pop, (object)null); } else { yield return instruction; } } } } [HarmonyPatch(typeof(Looker), "ToggleLookers")] internal static class ToggleLookersPatch { public static bool Prefix(Looker __instance) { Looker[] componentsInChildren = ((Component)((Component)__instance).transform.parent).GetComponentsInChildren<Looker>(); int num = Random.Range(0, componentsInChildren.Length); if (Random.value < 0.95f) { num = -1; } Looker[] array = componentsInChildren; Looker[] array2 = array; foreach (Looker val in array2) { if ((Object)(object)val.view == (Object)null) { val.view = ((Component)val).GetComponent<PhotonView>(); } if (((Component)val).transform.GetSiblingIndex() != num) { val.view.RPC("RPCA_DisableLooker", (RpcTarget)3, Array.Empty<object>()); } } return false; } } [HarmonyPatch(typeof(FakeItemManager), "RefreshList")] internal static class RefreshListPatch { public static bool Prefix(FakeItemManager __instance) { __instance.allFakeItems = Object.FindObjectsByType<FakeItem>((FindObjectsInactive)1, (FindObjectsSortMode)1).ToList(); for (int i = 0; i < __instance.allFakeItems.Count; i++) { __instance.allFakeItems[i].index = i; } return false; } } [HarmonyPatch(typeof(RandomizeAnimatorParameter), "OnEnable")] internal static class OnEnablePatch { public static bool Prefix(RandomizeAnimatorParameter __instance) { return false; } } [HarmonyPatch(typeof(LavaRiver), "Apply")] private static class LavaRiverApplyPatch { private static void Postfix(LavaRiver __instance) { if (Plugin.Instance.roomMapSettings != null && Plugin.Instance.roomMapSettings.enableRandomiser) { ((Component)__instance).gameObject.SetActive(false); ((Component)__instance).gameObject.SetActive(true); } } } [HarmonyPatch(typeof(VariantObjectSelector), "SelectVariations")] private static class VariantObjectSelectorPatch { private static bool Prefix(VariantObjectSelector __instance) { if (Plugin.Instance.roomMapSettings == null || !Plugin.Instance.roomMapSettings.enableRandomiser) { return true; } return false; } } [HarmonyPatch(typeof(VariationSwapper), "EnableRandom")] private static class VariationSwapperPatch { private static bool Prefix(VariationSwapper __instance) { if (Plugin.Instance.roomMapSettings == null || !Plugin.Instance.roomMapSettings.enableRandomiser) { return true; } return false; } } [HarmonyPatch(typeof(BreakableBridge), "AddCollisionModifiers")] private static class BreakableBridgePatch { private static bool Prefix(BreakableBridge __instance) { Collider[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<Collider>(); for (int i = 0; i < componentsInChildren.Length; i++) { CollisionModifier val = ((Component)componentsInChildren[i]).gameObject.AddComponent<CollisionModifier>(); val.applyEffects = false; val.onCollide = (Action<Character, CollisionModifier, Collision, Bodypart>)Delegate.Combine(val.onCollide, new Action<Character, CollisionModifier, Collision, Bodypart>(__instance.OnBridgeCollision)); } return false; } } [HarmonyPatch(typeof(TowerStacker), "ExecuteRoutine")] internal static class TowerStackerExecuteRoutinePatch { public static bool Prefix(TowerStacker __instance) { //IL_006b: 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_007c: 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_0088: 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_00c0: Unknown result type (might be due to invalid IL or missing references) if (Plugin.Instance.roomMapSettings == null || !Plugin.Instance.roomMapSettings.enableRandomiser) { return true; } List<GameObject> list = __instance.parts.OrderBy((GameObject x) => Random.value).ToList(); for (int num = 0; num < __instance.stackHeight; num++) { Vector3 position = ((Component)__instance).transform.position + __instance.direction * __instance.offset * (float)num; GameObject val = Object.Instantiate<GameObject>(list[num % list.Count], ((Component)__instance).transform); val.transform.position = position; val.transform.Rotate(Vector3.up, Random.value * 360f); LevelGenStep[] componentsInChildren = val.GetComponentsInChildren<LevelGenStep>(); LevelGenStep[] array = componentsInChildren; foreach (LevelGenStep val2 in array) { val2.ExecuteImmediately(); } __instance.stack.Add(val); } return false; } } } public static class LightMapBaker { public static ComputeShader computeShader; public static int rayCount = 32; public static int maxSteps = 32; public static void RunBake() { //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_0078: 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_0085: Unknown result type (might be due to invalid IL or missing references) LightVolume val = LightVolume.Instance(); Shader.SetGlobalTexture("_LightMap", (Texture)null); Stopwatch stopwatch = Stopwatch.StartNew(); NativeArray<uint> occupancy = AreaVoxeliser.BuildOccupancyGrid(); stopwatch.Stop(); Debug.Log((object)("[TerrainRandomiser] Occupancy took: " + stopwatch.ElapsedMilliseconds)); stopwatch = Stopwatch.StartNew(); Vector3Int gridRes = default(Vector3Int); ((Vector3Int)(ref gridRes))..ctor((int)val.gridRes.x, (int)val.gridRes.y, (int)val.gridRes.z); RenderTexture val2 = DispatchAndCreateRenderTexture(computeShader, occupancy, gridRes, rayCount, maxSteps, val.skyColor); occupancy.Dispose(); RenderTexture val4 = default(RenderTexture); RenderTexture val3 = val.RunBlur(val2, ref val4); ((Object)val3).name = "LightVolumeRenderTexture"; val.SetShaderVars(); val.SaveTex(val3, true); stopwatch.Stop(); } private static RenderTexture DispatchAndCreateRenderTexture(ComputeShader cs, NativeArray<uint> occupancy, Vector3Int gridRes, int rayCount, int maxSteps, Color skyColor) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Expected O, but got Unknown //IL_0056: 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_0074: Expected O, but got Unknown //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_009a: 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_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Expected O, but got Unknown //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) int num = cs.FindKernel("SkyVisibilityDDA"); Vector3[] data = BuildHemisphereDirections(rayCount); ComputeBuffer val = new ComputeBuffer(rayCount, 12); val.SetData((Array)data); cs.SetBuffer(num, "_RayDirections", val); int num2 = ((Vector3Int)(ref gridRes)).x * ((Vector3Int)(ref gridRes)).y * ((Vector3Int)(ref gridRes)).z; ComputeBuffer val2 = new ComputeBuffer(num2, 4); val2.SetData<uint>(occupancy); List<GpuLight> list = BuildLights(); ComputeBuffer val3 = new ComputeBuffer(list.Count, 52); val3.SetData<GpuLight>(list); RenderTexture val4 = new RenderTexture(((Vector3Int)(ref gridRes)).x, ((Vector3Int)(ref gridRes)).y, 0) { enableRandomWrite = true, format = (RenderTextureFormat)2, dimension = (TextureDimension)3, volumeDepth = ((Vector3Int)(ref gridRes)).z, wrapMode = (TextureWrapMode)1, filterMode = (FilterMode)1 }; val4.Create(); LightVolume val5 = LightVolume.Instance(); cs.SetInts("_GridRes", new int[3] { ((Vector3Int)(ref gridRes)).x, ((Vector3Int)(ref gridRes)).y, ((Vector3Int)(ref gridRes)).z }); cs.SetVector("_GridOffset", Vector4.op_Implicit(val5.gridOffset)); cs.SetFloat("_RaySpacing", val5.raySpacing); cs.SetBuffer(num, "_Occupancy", val2); cs.SetTexture(num, "_LightMap", (Texture)(object)val4); cs.SetInt("_RayCount", rayCount); cs.SetInt("_MaxSteps", maxSteps); cs.SetVector("_SkyColor", Color.op_Implicit(skyColor)); cs.SetBuffer(num, "_LightBuffer", val3); cs.SetInt("_LightBufferLength", list.Count); int num3 = (((Vector3Int)(ref gridRes)).x + 3) / 4; int num4 = (((Vector3Int)(ref gridRes)).y + 3) / 4; int num5 = (((Vector3Int)(ref gridRes)).z + 3) / 4; cs.Dispatch(num, num3, num4, num5); val2.Release(); val3.Release(); val.Release(); return val4; } public static List<GpuLight> BuildLights() { //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_007d: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_0160: 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_0086: Invalid comparison between Unknown and I4 //IL_00b5: 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_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: 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_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) LightVolume val = LightVolume.Instance(); List<GpuLight> list = new List<GpuLight>(); GameObject val2 = (((Object)(object)val.sceneParent == (Object)null) ? ((Component)val).gameObject : val.sceneParent); BakedVolumeLight[] componentsInChildren = val2.GetComponentsInChildren<BakedVolumeLight>(); BakedVolumeLight[] array = componentsInChildren; Vector3 val4 = default(Vector3); foreach (BakedVolumeLight val3 in array) { ((Vector3)(ref val4))..ctor(val3.color.r, val3.color.g, val3.color.b); LightModes mode = val3.mode; if (1 == 0) { } float num; if ((int)mode != 0) { if ((int)mode != 1) { throw new Exception(); } num = val3.coneSize * (MathF.PI / 180f); } else { num = 0f; } if (1 == 0) { } float coneSize = num; list.Add(new GpuLight { Position = ((Component)val3).transform.position, ConeSize = coneSize, Direction = ((Component)val3).transform.forward, Radius = val3.radius, Color = val4 * val3.intensity, Falloff = val3.falloff, ConeFalloff = val3.coneFalloff }); } if (list.Count == 0) { list.Add(default(GpuLight)); } return list; } private static Vector3[] BuildHemisphereDirections(int rayCount) { //IL_0058: 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) Vector3[] array = (Vector3[])(object)new Vector3[rayCount]; for (int i = 0; i < rayCount; i++) { float num = ((float)i + 0.5f) / (float)rayCount; float num2 = 1f - num; float num3 = Mathf.Sqrt(1f - num2 * num2); float num4 = ((float)i + 0.5f) * 2.3999631f; array[i] = new Vector3(num3 * Mathf.Cos(num4), num2, num3 * Mathf.Sin(num4)); } return array; } } public class MapHandlerPatches { [HarmonyPatch(typeof(MapHandler), "InitializeMap")] private static class MapHandlerInitializeMapPatch { private static bool Prefix(MapHandler __instance) { //IL_011a: 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_0132: 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) //IL_0167: Unknown result type (might be due to invalid IL or missing references) if (Plugin.Instance.roomMapSettings == null || !Plugin.Instance.roomMapSettings.enableRandomiser) { return true; } MapSettings roomMapSettings = Plugin.Instance.roomMapSettings; Plugin.viewIDsToSend = new List<int>(); Plugin.viewsRequiringIDs = new List<PhotonView>(); Debug.Log((object)$"[TerrainRandomiser] Starting generation with seed: {roomMapSettings.seed}"); string text = JsonConvert.SerializeObject((object)roomMapSettings, (Formatting)0); Debug.Log((object)text); Random.InitState(roomMapSettings.seed); LevelGeneration val = Object.FindFirstObjectByType<LevelGeneration>(); BiomeSelector[] componentsInChildren = ((Component)val).GetComponentsInChildren<BiomeSelector>(); PeakHandler[] array = Object.FindObjectsByType<PeakHandler>((FindObjectsInactive)1, (FindObjectsSortMode)0); PeakHandler[] array2 = array; foreach (PeakHandler val2 in array2) { ((Component)val2).gameObject.SetActive(false); } for (int j = 0; j < componentsInChildren.Length; j++) { if (j >= roomMapSettings.sectionSettings.Count || !roomMapSettings.sectionSettings[j].overrideEnabled) { continue; } BiomeType selectedBiomeType = roomMapSettings.sectionSettings[j].selectedBiomeType; BiomeData biomeData = BiomeDatabase.Sections[j].biomes[selectedBiomeType]; foreach (BiomeOption biome in componentsInChildren[j].Biomes) { bool flag = biome.biomeParent.biomeType == selectedBiomeType; ((Component)biome.biomeParent).gameObject.SetActive(flag); if (!flag) { continue; } if (biomeData.variantSelectionType == VariantSelectionType.BiomeVariant) { VariationSwapper componentInChildren = ((Component)biome.biomeParent).GetComponentInChildren<VariationSwapper>(); Variation[] variations = componentInChildren.Variations; foreach (Variation val3 in variations) { bool active = ((Object)val3.parent).name == roomMapSettings.sectionSettings[j].selectedVariant; val3.parent.SetActive(active); } } else if (biomeData.variantSelectionType == VariantSelectionType.VariantObject) { VariantObject[] componentsInChildren2 = ((Component)biome.biomeParent).GetComponentsInChildren<VariantObject>(true); VariantObject[] array3 = componentsInChildren2; foreach (VariantObject val4 in array3) { bool active2 = ((Object)val4).name.ToLower().Contains(roomMapSettings.sectionSettings[j].selectedVariant.ToLower()); ((Component)val4).gameObject.SetActive(active2); } } } } IGenConfigStep[] componentsInChildren3 = ((Component)val).GetComponentsInChildren<IGenConfigStep>(); IGenConfigStep[] array4 = componentsInChildren3; foreach (IGenConfigStep val5 in array4) { val5.RunStep(); } PropGrouper component = ((Component)Singleton<MapHandler>.Instance).GetComponent<PropGrouper>(); component.ClearAll(); Object.FindFirstObjectByType<LightVolume>().SetSize(); Physics.SyncTransforms(); component.RunImmediatelySimple(); FakeItemManager.Instance.RefreshList(); Singleton<MapHandler>.Instance.DetectBiomes(); for (int n = 0; n < componentsInChildren.Length; n++) { foreach (BiomeOption biome2 in componentsInChildren[n].Biomes) { if (!((Component)biome2.biomeParent).gameObject.activeSelf) { Object.DestroyImmediate((Object)(object)((Component)biome2.biomeParent).gameObject); } } } PeakHandler[] array5 = array; foreach (PeakHandler val6 in array5) { if ((Object)(object)val6 != (Object)null) { ((Component)val6).gameObject.SetActive(true); } } return true; } private static void Postfix(MapHandler __instance) { if (Plugin.Instance.roomMapSettings != null && Plugin.Instance.roomMapSettings.enableRandomiser) { if (!PhotonNetwork.IsMasterClient) { Plugin.Instance.roomMapSettings = null; } HandleUnassignedViews(); } } } public static void HandleUnassignedViews() { PhotonView[] componentsInChildren = ((Component)Singleton<MapHandler>.Instance).gameObject.GetComponentsInChildren<PhotonView>(true); if (Plugin.viewsRequiringIDs == null) { Plugin.viewsRequiringIDs = new List<PhotonView>(); } for (int i = 0; i < componentsInChildren.Length; i++) { if (componentsInChildren[i].ViewID != 0) { continue; } if (PhotonNetwork.IsMasterClient) { if (PhotonNetwork.MasterClient.ActorNumber == -1) { Plugin.viewsRequiringIDs.Add(componentsInChildren[i]); continue; } int num = PhotonNetwork.AllocateViewID(false); componentsInChildren[i].ViewID = num; Plugin.viewIDsToSend.Add(num); } else { Plugin.viewsRequiringIDs.Add(componentsInChildren[i]); } } if (PhotonNetwork.IsMasterClient) { Plugin.Instance.SendViewIDsToClients(Plugin.viewIDsToSend); return; } Plugin.awaitingViewIDs = true; if (Plugin.receivedViewIDs != null && Plugin.receivedViewIDs.Count > 0) { Plugin.Instance.UpdateRequiredViewIDs(); } } private static void ApplyBiomeVariant(MapSegment seg, SectionSettings biomeSettings) { BiomeVariant[] componentsInChildren = seg.segmentParent.GetComponentsInChildren<BiomeVariant>(true); BiomeVariant val = ((IEnumerable<BiomeVariant>)componentsInChildren).FirstOrDefault((Func<BiomeVariant, bool>)((BiomeVariant v) => ((Component)v).gameObject.activeSelf)); BiomeVariant val2 = ((IEnumerable<BiomeVariant>)componentsInChildren).FirstOrDefault((Func<BiomeVariant, bool>)((BiomeVariant v) => ((Object)v).name == biomeSettings.selectedVariant)); if ((Object)(object)val2 == (Object)null || (Object)(object)val == (Object)(object)val2) { return; } PropGrouper component = seg.segmentParent.gameObject.GetComponent<PropGrouper>(); if ((Object)(object)component == (Object)null) { seg.segmentParent.gameObject.AddComponent<PropGrouper>(); } if ((Object)(object)val != (Object)null) { PropGrouper component2 = ((Component)val).GetComponent<PropGrouper>(); if (component2 != null) { component2.ClearAll(); } ((Component)val).gameObject.SetActive(false); } ((Component)val2).gameObject.SetActive(true); } public static void ApplyBiomeToSegment(MapHandler handler, int index, SectionSettings biomeSettings) { //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) MapSegment val = handler.segments[index]; if (val.biome == biomeSettings.selectedBiomeType) { ApplyVariant(val, biomeSettings, index); } else { SwapBiome(val, handler, biomeSettings, index); } } private static void ApplyVariant(MapSegment seg, SectionSettings biomeSettings, int index) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) switch (BiomeDatabase.Sections[index].biomes[biomeSettings.selectedBiomeType].variantSelectionType) { case VariantSelectionType.BiomeVariant: ApplyBiomeVariant(seg, biomeSettings); break; case VariantSelectionType.VariantObject: ApplyVariantObject(seg, biomeSettings); break; } } private static void ApplyVariantObject(MapSegment seg, SectionSettings biomeSettings) { //IL_004e: Unknown result type (might be due to invalid IL or missing references) VariantObject[] componentsInChildren = seg.segmentParent.GetComponentsInChildren<VariantObject>(true); VariantObject val = ((IEnumerable<VariantObject>)componentsInChildren).FirstOrDefault((Func<VariantObject, bool>)((VariantObject v) => ((Object)v).name.ToLower().Contains(biomeSettings.selectedVariant.ToLower()))); if (!((Object)(object)val == (Object)null)) { VariantObject[] array = componentsInChildren; foreach (VariantObject val2 in array) { bool active = (int)val2.group == 0 && ((Object)val2).name.ToLower().Contains(biomeSettings.selectedVariant.ToLower()); ((Component)val2).gameObject.SetActive(active); } } } private static void SwapBiome(MapSegment seg, MapHandler handler, SectionSettings biomeSettings, int index) { //IL_006c: Unknown result type (might be due to invalid IL or missing references) PropGrouper component = seg.segmentParent.GetComponent<PropGrouper>(); if (component != null) { component.ClearAll(); } ((Component)seg.segmentParent.transform.parent).gameObject.SetActive(false); int index2 = handler.biomes.FindIndex((BiomeType x) => x == seg.biome); handler.biomes[index2] = biomeSettings.selectedBiomeType; ((Component)seg.segmentParent.transform.parent).gameObject.SetActive(true); GameObject segmentCampfire = seg.segmentCampfire; PropGrouper val = segmentCampfire.GetComponent<PropGrouper>(); if ((Object)(object)val == (Object)null) { val = segmentCampfire.AddComponent<PropGrouper>(); } val.RunAll(true, true); ApplyVariant(seg, biomeSettings, index); } } internal class NetworkConnectorPatches { [HarmonyPatch(typeof(NetworkConnector), "OnJoinedRoom")] private static class OnJoinedRoomPatch { private static void Postfix(NetworkConnector __instance) { if (!PhotonNetwork.IsMasterClient || !Plugin.loadingQuickSave) { return; } if (Plugin.viewIDsToSend == null) { Plugin.viewIDsToSend = new List<int>(); } for (int i = 0; i < Plugin.viewsRequiringIDs.Count; i++) { if (Plugin.viewsRequiringIDs[i].ViewID == 0 && PhotonNetwork.IsMasterClient) { int num = PhotonNetwork.AllocateViewID(false); Plugin.viewsRequiringIDs[i].ViewID = num; Plugin.viewIDsToSend.Add(num); } } Plugin.loadingQuickSave = false; Plugin.SyncWithClients(Plugin.Instance.roomMapSettings); Plugin.Instance.SendViewIDsToClients(Plugin.viewIDsToSend); } } } public static class PropGrouperPatches { [HarmonyPatch(typeof(PropGrouper), "RunImmediatelySimple")] private static class RunImmediatelySimplePatch { private static bool Prefix(PropGrouper __instance) { //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_003d: 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_0041: 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_004a: Invalid comparison between Unknown and I4 //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Invalid comparison between Unknown and I4 //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Invalid comparison between Unknown and I4 //IL_01a0: Unknown result type (might be due to invalid IL or missing references) __instance.ClearAll(); LevelGenStep[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<LevelGenStep>(); List<LevelGenStep> list = new List<LevelGenStep>(); List<LevelGenStep> list2 = new List<LevelGenStep>(); Dictionary<DeferredStepTiming, List<IDeferredStep>> deferredSteps = new Dictionary<DeferredStepTiming, List<IDeferredStep>>(); for (int i = 0; i < componentsInChildren.Length; i++) { PropGrouperTiming timing = ((Component)componentsInChildren[i]).GetComponentInParent<PropGrouper>().timing; PropGrouperTiming val = timing; if ((int)val != 0) { if ((int)val == 1) { list2.Add(componentsInChildren[i]); } } else { list.Add(componentsInChildren[i]); } } Debug.Log((object)"Starting Early steps."); Stopwatch stopwatch = Stopwatch.StartNew(); runningEarly = true; foreach (LevelGenStep item in list) { item.ExecuteImmediately(); if ((int)item.DeferredTiming > 0) { AddToStepList(item.DeferredTiming, item.ConstructDeferred((IMayHaveDeferredStep)(object)item)); } } runningEarly = false; stopwatch.Stop(); Debug.LogError((object)("[TerrainRandomiser] EarlySpawners took: " + stopwatch.ElapsedMilliseconds)); ((PhotonPeer)PhotonNetwork.NetworkingClient.LoadBalancingPeer).SendOutgoingCommands(); Debug.Log((object)"Starting on early deferred steps."); ExecuteAndClearDeferredStepsFor((DeferredStepTiming)2); if (Plugin.EnableLightMapBaking.Value) { LightMapBaker.RunBake(); } Debug.Log((object)"Starting Late steps."); stopwatch = Stopwatch.StartNew(); foreach (LevelGenStep item2 in list2) { item2.ExecuteImmediately(); if ((int)item2.DeferredTiming > 0) { AddToStepList(item2.DeferredTiming, item2.ConstructDeferred((IMayHaveDeferredStep)(object)item2)); } } stopwatch.Stop(); Debug.LogError((object)("[TerrainRandomiser] LateSpawners took: " + stopwatch.ElapsedMilliseconds)); ((PhotonPeer)PhotonNetwork.NetworkingClient.LoadBalancingPeer).SendOutgoingCommands(); Debug.Log((object)"Starting on final deferred steps."); ExecuteAndClearDeferredStepsFor((DeferredStepTiming)2); Debug.Log((object)"Finalizing level."); ILevelGenFinalizer[] componentsInChildren2 = ((Component)__instance).GetComponentsInChildren<ILevelGenFinalizer>(); ILevelGenFinalizer[] array = componentsInChildren2; for (int j = 0; j < array.Length; j++) { array[j].OnLevelGenFinished(); } ((PhotonPeer)PhotonNetwork.NetworkingClient.LoadBalancingPeer).SendOutgoingCommands(); return false; void AddToStepList(DeferredStepTiming key, IDeferredStep stepToAdd) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) if (!deferredSteps.ContainsKey(key)) { deferredSteps.Add(key, new List<IDeferredStep>()); } deferredSteps[key].Add(stepToAdd); } void ExecuteAndClearDeferredStepsFor(DeferredStepTiming key) { //IL_0007: 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_003f: 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 (deferredSteps.ContainsKey(key)) { Debug.Log((object)$"Executing {deferredSteps[key].Count} steps now that group is finished."); foreach (IDeferredStep item3 in deferredSteps[key]) { item3.DeferredGo(); } deferredSteps[key].Clear(); } } } } public static bool runningEarly; } internal class PropSpawnerPatches { [HarmonyPatch(typeof(PropSpawner), "ExecuteImmediately")] private static class ExecuteImmediatelyPatch { private static bool Prefix(PropSpawner __instance) { if (Plugin.Instance.roomMapSettings == null || !Plugin.Instance.roomMapSettings.enableRandomiser) { return true; } ((LevelGenStep)__instance).Clear(); if (CanBatch(__instance)) { SpawnNewBatched(__instance); } else { SpawnNewStrict(__instance); } return false; } private static bool SpawnNewBatched(PropSpawner __instance) { //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: 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_00e2: 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_00ef: 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_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0152: 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_015c: 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) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Expected O, but got Unknown //IL_02d5: Unknown result type (might be due to invalid IL or missing references) //IL_02db: Invalid comparison between Unknown and I4 if (__instance.chanceToUseSpawner < 0.999f && Random.value > __instance.chanceToUseSpawner) { return false; } Physics.SyncTransforms(); int num = __instance.nrOfSpawns; if (__instance.randomSpawns) { num = Random.Range(__instance.minSpawnCount, __instance.nrOfSpawns); } int num2 = Mathf.Min(Mathf.Max(5000, 1500 * num), 50000); int num3 = 0; int num4 = 0; int num5 = 0; int num6 = 0; LayerMask mask = HelperFunctions.GetMask(__instance.layerType); int num7 = 256; QueryParameters queryParams = QueryParameters.Default; queryParams.layerMask = ((LayerMask)(ref mask)).value; queryParams.hitTriggers = (QueryTriggerInteraction)1; NativeArray<RaycastHit> val = default(NativeArray<RaycastHit>); val..ctor(num7, (Allocator)3, (NativeArrayOptions)1); NativeArray<RaycastCommand> val2 = default(NativeArray<RaycastCommand>); val2..ctor(num7, (Allocator)3, (NativeArrayOptions)1); Vector2[] array = (Vector2[])(object)new Vector2[num7]; while (num3 + num5 < num && num4 < num2) { PrepareRaycastCommands(__instance, val2, queryParams, array); JobHandle val3 = RaycastCommand.ScheduleBatch(val2, val, 4, default(JobHandle)); ((JobHandle)(ref val3)).Complete(); num4 += num7; num6++; int num8 = 0; for (int i = 0; i < num7; i++) { if (num3 >= num) { break; } RaycastHit hit = val[i]; if (!Object.op_Implicit((Object)(object)((RaycastHit)(ref hit)).transform)) { continue; } SpawnData val4 = new SpawnData { pos = ((RaycastHit)(ref hit)).point, normal = ((RaycastHit)(ref hit)).normal }; RaycastCommand val5 = val2[i]; val4.rayDir = ((RaycastCommand)(ref val5)).direction; val4.hit = hit; val4.spawnerTransform = ((Component)__instance).transform; val4.placement = array[i]; SpawnData val6 = val4; if (!PropSpawner.AllConstraintsPass((IEnumerable<PropSpawnerConstraint>)__instance.constraints, val6)) { continue; } val6.spawnCount = num3; GameObject val7 = __instance.Spawn(val6); if ((Object)(object)val7 != (Object)null) { __instance.AllSpawnData[val7] = val6; num3++; num8++; if (__instance.syncTransforms) { Physics.SyncTransforms(); } } } if (num8 == 0) { num5++; } } val2.Dispose(); val.Dispose(); __instance.currentSpawns = ((Component)__instance).transform.childCount; foreach (object item in __instance.SpawnDecor()) { } foreach (PostSpawnBehavior postSpawnBehavior in __instance.postSpawnBehaviors) { if (!postSpawnBehavior.mute) { if ((int)postSpawnBehavior.DeferredTiming != 2) { postSpawnBehavior.RunBehavior(__instance.SpawnedProps); } else { __instance._deferredSteps.Add(postSpawnBehavior.ConstructDeferred((IMayHaveDeferredStep)(object)__instance)); } } } return true; } private static bool CanBatch(PropSpawner __instance) { if (!__instance.raycastPosition) { return false; } if (PropGrouperPatches.runningEarly) { return false; } return true; } public static void PrepareRaycastCommands(PropSpawner spawner, NativeArray<RaycastCommand> commands, QueryParameters queryParams, Vector2[] placements) { //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_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown //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_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_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Expected O, but got Unknown if (spawner is PropSpawner_Sphere) { BuildRaycastCommands_Sphere((PropSpawner_Sphere)spawner, commands, queryParams, placements); } else if (spawner is PropSpawner_Line) { BuildRaycastCommands_Line((PropSpawner_Line)spawner, commands, queryParams, placements); } else { BuildRaycastCommands(spawner, commands, queryParams, placements); } } public static void BuildRaycastCommands_Sphere(PropSpawner_Sphere spawner, NativeArray<RaycastCommand> commands, QueryParameters queryParams, Vector2[] placements) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i < commands.Length; i++) { int num = i; Vector3 position = ((Component)spawner).transform.position; Vector3 onUnitSphere = Random.onUnitSphere; commands[num] = new RaycastCommand(position, ((Vector3)(ref onUnitSphere)).normalized, queryParams, ((PropSpawner)spawner).rayLength); } } public static void BuildRaycastCommands_Line(PropSpawner_Line spawner, NativeArray<RaycastCommand> commands, QueryParameters queryParams, Vector2[] placements) { //IL_000f: 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_0033: 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_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: 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_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005e: 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_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_009f: 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_00a9: 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_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_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_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: 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_00fc: 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_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_0117: 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_011c: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i < commands.Length; i++) { Vector3 val = ((Component)spawner).transform.position + ((Component)spawner).transform.up * Mathf.Lerp(-0.5f, 0.5f, Random.value) * spawner.height; Vector3 val2 = Vector3.ProjectOnPlane(Random.onUnitSphere, ((Component)spawner).transform.up); Vector3 normalized = ((Vector3)(ref val2)).normalized; normalized += new Vector3(Random.Range(0f - spawner.RayWiggle, spawner.RayWiggle), Random.Range(0f - spawner.RayWiggle, spawner.RayWiggle), Random.Range(0f - spawner.RayWiggle, spawner.RayWiggle)); float num = ((Random.Range(0f, 1f) > spawner.castDirectionBias) ? (-1f) : 1f); Vector3 val3 = val + normalized * spawner.coreWidth; Vector3 val4 = val + normalized * ((PropSpawner)spawner).rayLength * num; Vector3 val5 = val4 - val3; float num2 = Vector3.Distance(val3, val4); commands[i] = new RaycastCommand(val3, val5, queryParams, num2); } } public static void BuildRaycastCommands(PropSpawner spawner, NativeArray<RaycastCommand> commands, QueryParameters queryParams, Vector2[] placements) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: 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_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_004c: 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_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008e: 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_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_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_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: 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_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) Vector3 val = ((Component)spawner).transform.forward * spawner.rayNearCutoff; Vector2 val2 = default(Vector2); for (int i = 0; i < commands.Length; i++) { Vector3 position = ((Component)spawner).transform.position; ((Vector2)(ref val2))..ctor(Random.value, Random.value); placements[i] = val2; position += ((Component)spawner).transform.right * Mathf.Lerp((0f - spawner.area.x) * 0.5f, spawner.area.x * 0.5f, val2.x); position += ((Component)spawner).transform.up * Mathf.Lerp((0f - spawner.area.y) * 0.5f, spawner.area.y * 0.5f, val2.y); int num = i; Vector3 val3 = position; Vector3 val4 = ((Component)spawner).transform.forward + val + spawner.rayDirectionOffset; commands[num] = new RaycastCommand(val3, ((Vector3)(ref val4)).normalized, queryParams, spawner.rayLength - spawner.rayNearCutoff); } } } private static bool SpawnNewStrict(PropSpawner __instance) { //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Invalid comparison between Unknown and I4 if (__instance.chanceToUseSpawner < 0.999f && Random.value > __instance.chanceToUseSpawner) { return false; } Physics.SyncTransforms(); int num = __instance.nrOfSpawns; if (__instance.randomSpawns) { num = Random.Range(__instance.minSpawnCount, __instance.nrOfSpawns); } int num2 = Mathf.Min(Mathf.Max(5000, 1500 * num), 50000); int num3 = 0; int num4 = 0; int num5 = 0; while (num3 + num5 < num && num4 < num2) { int num6 = 0; while (num6 < 1500) { num4++; num6++; if (__instance.TryToSpawn(num3)) { num3++; if (__instance.syncTransforms) { Physics.SyncTransforms(); } break; } } if (num6 == 1500) { num5++; break; } } if (num4 == num2) { Debug.LogWarning((object)$"{((Object)((Component)__instance).gameObject).na