using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using AIGraph;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using GTFO.API;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using LevelGeneration;
using LevelGeneration.Core;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("BorkenCellGeoFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BorkenCellGeoFix")]
[assembly: AssemblyTitle("BorkenCellGeoFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.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]
[Microsoft.CodeAnalysis.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;
}
}
}
namespace BorkenCellGeoFix
{
[BepInPlugin("com.hirnukuono.BorkenCellGeoFix", "BorkenCellGeoFix", "0.0.8")]
public class Plugin : BasePlugin
{
[HarmonyPatch]
public class BorkenCellGeoFixPatches
{
private static bool plugsdone;
private static bool geosdone;
[HarmonyPatch(typeof(LG_LoadComplexDataSetResourcesJob), "Build")]
[HarmonyPrefix]
private static void SetPlugsDoneFalse(LG_LoadComplexDataSetResourcesJob __instance)
{
plugsdone = false;
geosdone = false;
}
[HarmonyPatch(typeof(LG_LateGeomorphScanJob), "Build")]
[HarmonyPrefix]
[HarmonyWrapSafe]
private static void Prefix(LG_LateGeomorphScanJob __instance)
{
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: 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_010d: Unknown result type (might be due to invalid IL or missing references)
//IL_011e: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
//IL_013c: Unknown result type (might be due to invalid IL or missing references)
//IL_0185: Unknown result type (might be due to invalid IL or missing references)
//IL_019c: Unknown result type (might be due to invalid IL or missing references)
//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
//IL_0214: Unknown result type (might be due to invalid IL or missing references)
//IL_0225: Unknown result type (might be due to invalid IL or missing references)
//IL_0236: Unknown result type (might be due to invalid IL or missing references)
//IL_0246: Unknown result type (might be due to invalid IL or missing references)
//IL_025a: Unknown result type (might be due to invalid IL or missing references)
//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
//IL_034a: Unknown result type (might be due to invalid IL or missing references)
//IL_0528: Unknown result type (might be due to invalid IL or missing references)
//IL_052d: Unknown result type (might be due to invalid IL or missing references)
//IL_05d1: Unknown result type (might be due to invalid IL or missing references)
//IL_05d8: Expected O, but got Unknown
//IL_060d: Unknown result type (might be due to invalid IL or missing references)
if (geosdone)
{
return;
}
geosdone = true;
Enumerator<Dimension> enumerator = Builder.CurrentFloor.m_dimensions.GetEnumerator();
bool flag = default(bool);
while (enumerator.MoveNext())
{
Dimension current = enumerator.Current;
if (current.DimensionData.IsStaticDimension)
{
continue;
}
Enumerator<LG_Tile> enumerator2 = current.Tiles.GetEnumerator();
while (enumerator2.MoveNext())
{
LG_Tile current2 = enumerator2.Current;
if (!_cleanUp.Value)
{
L.LogInfo((object)"decorative object cleanup skipped as per config file");
return;
}
List<GameObject> list = new List<GameObject>();
if ((Object)(object)current2.m_geoRoot == (Object)null)
{
continue;
}
LG_Geomorph geoRoot = current2.m_geoRoot;
if ((Object)(object)((Component)geoRoot).GetComponent<AIG_GeomorphNodeVolume>().m_sizeOverrideTransform != (Object)null)
{
continue;
}
Vector3 localPosition = ((Component)geoRoot).gameObject.transform.localPosition;
((Component)geoRoot).gameObject.transform.localPosition = new Vector3(0f, -2000f, 0f);
((Component)geoRoot).gameObject.active = true;
Physics.SyncTransforms();
Collider[] array = Il2CppArrayBase<Collider>.op_Implicit((Il2CppArrayBase<Collider>)(object)Physics.OverlapBox(new Vector3(((Component)geoRoot).transform.position.x - 50f, ((Component)geoRoot).transform.position.y, ((Component)geoRoot).transform.position.z), new Vector3(16f, 200f, 16f)));
if (array.Length != 0)
{
Collider[] array2 = array;
foreach (Collider val in array2)
{
list.Add(((Component)val).gameObject);
}
}
Collider[] array3 = Il2CppArrayBase<Collider>.op_Implicit((Il2CppArrayBase<Collider>)(object)Physics.OverlapBox(new Vector3(((Component)geoRoot).transform.position.x + 50f, ((Component)geoRoot).transform.position.y, ((Component)geoRoot).transform.position.z), new Vector3(16f, 200f, 16f)));
if (array3.Length != 0)
{
Collider[] array2 = array3;
foreach (Collider val2 in array2)
{
list.Add(((Component)val2).gameObject);
}
}
Collider[] array4 = Il2CppArrayBase<Collider>.op_Implicit((Il2CppArrayBase<Collider>)(object)Physics.OverlapBox(new Vector3(((Component)geoRoot).transform.position.x, ((Component)geoRoot).transform.position.y, ((Component)geoRoot).transform.position.z - 50f), new Vector3(16f, 200f, 16f)));
if (array4.Length != 0)
{
Collider[] array2 = array4;
foreach (Collider val3 in array2)
{
list.Add(((Component)val3).gameObject);
}
}
Collider[] array5 = Il2CppArrayBase<Collider>.op_Implicit((Il2CppArrayBase<Collider>)(object)Physics.OverlapBox(new Vector3(((Component)geoRoot).transform.position.x, ((Component)geoRoot).transform.position.y, ((Component)geoRoot).transform.position.z + 50f), new Vector3(16f, 200f, 16f)));
if ((array5.Length != 0) & !((Object)geoRoot).name.Contains("elevator"))
{
Collider[] array2 = array5;
foreach (Collider val4 in array2)
{
list.Add(((Component)val4).gameObject);
}
}
((Component)geoRoot).transform.localPosition = localPosition;
Physics.SyncTransforms();
for (int j = 0; j < list.Count; j++)
{
GameObject val5 = list[j];
string text = string.Join("/", ((IEnumerable<Transform>)((Component)val5.transform).GetComponentsInParent<Transform>()).Select((Transform t) => ((Object)t).name).Reverse().ToArray());
if (text.ToLower().Contains("infront") || text.ToLower().Contains("behind") || text.ToLower().Contains("crossing") || (((Object)val5).name.Contains("Interaction") | ((Object)val5).name.Contains("MapLookatRevealer") | ((Object)val5).name.Contains("Gate") | ((Object)val5).name.Contains("Door") | ((Object)val5).name.Contains("Floor") | ((Object)val5).name.Contains("floor")) || (((Object)val5).name.Contains("InterAction") | ((Object)val5.transform.parent).name.Contains("MapLookatRevealer") | ((Object)val5).name.Contains("Gate") | ((Object)val5.transform.parent).name.Contains("Door") | ((Object)val5.transform.parent).name.Contains("Floor") | ((Object)val5.transform.parent).name.Contains("floor")))
{
continue;
}
MeshRenderer componentInChildren = ((Component)val5.transform.parent).GetComponentInChildren<MeshRenderer>();
if ((Object)(object)componentInChildren == (Object)null)
{
continue;
}
_ = ((Object)val5).name;
Vector3 position = val5.transform.position;
foreach (LG_Area item in (Il2CppArrayBase<LG_Area>)(object)geoRoot.m_areas)
{
if (item.CullBucket != null && item.CullBucket.Renderers.Contains((Renderer)(object)componentInChildren))
{
item.CullBucket.Renderers.Remove((Renderer)(object)componentInChildren);
}
}
if ((Object)(object)val5.gameObject != (Object)null)
{
Object.Destroy((Object)(object)val5.gameObject);
}
if ((Object)(object)((Component)componentInChildren).gameObject != (Object)null)
{
Object.Destroy((Object)(object)((Component)componentInChildren).gameObject);
}
ManualLogSource l = L;
BepInExInfoLogInterpolatedStringHandler val6 = new BepInExInfoLogInterpolatedStringHandler(28, 3, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<string>(((Object)geoRoot).name);
((BepInExLogInterpolatedStringHandler)val6).AppendLiteral(" - destroyed object ");
((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<string>(text);
((BepInExLogInterpolatedStringHandler)val6).AppendLiteral(" pos ");
((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<Vector3>(position);
((BepInExLogInterpolatedStringHandler)val6).AppendLiteral(" ..");
}
l.LogInfo(val6);
}
}
}
}
[HarmonyPatch(typeof(LG_BuildPlugBaseJob), "SpawnPlug")]
[HarmonyPrefix]
private static void FixCells(LG_BuildPlugBaseJob __instance)
{
//IL_0128: 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)
//IL_0134: Unknown result type (might be due to invalid IL or missing references)
//IL_0139: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: 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_0183: Unknown result type (might be due to invalid IL or missing references)
//IL_019b: Unknown result type (might be due to invalid IL or missing references)
//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_021e: Unknown result type (might be due to invalid IL or missing references)
//IL_0232: Unknown result type (might be due to invalid IL or missing references)
//IL_0239: Expected O, but got Unknown
//IL_0341: 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_039b: Unknown result type (might be due to invalid IL or missing references)
//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
//IL_03fd: Expected O, but got Unknown
if (plugsdone)
{
return;
}
plugsdone = true;
Enumerator<Dimension> enumerator = Builder.CurrentFloor.m_dimensions.GetEnumerator();
LG_GridPosition val2 = default(LG_GridPosition);
bool flag = default(bool);
while (enumerator.MoveNext())
{
Dimension current = enumerator.Current;
List<Vector2> list = new List<Vector2>();
if (current.IsArenaDimension || current.DimensionData.IsStaticDimension)
{
continue;
}
Enumerator<LG_Tile> enumerator2 = current.Tiles.GetEnumerator();
while (enumerator2.MoveNext())
{
LG_Tile current2 = enumerator2.Current;
if (current2 == null || (Object)(object)current2.m_geoRoot == (Object)null || ((CellGroupingBase<LG_Tile, LG_Cell>)(object)current2).m_cells == null || ((CellGroupingBase<LG_Tile, LG_Cell>)(object)current2).m_cells.Count == 0)
{
continue;
}
list.Add(new Vector2((float)((CellBase<LG_Tile, LG_Cell>)(object)((CellGroupingBase<LG_Tile, LG_Cell>)(object)current2).m_cells[0]).x, (float)((CellBase<LG_Tile, LG_Cell>)(object)((CellGroupingBase<LG_Tile, LG_Cell>)(object)current2).m_cells[0]).z));
if ((Object)(object)((Component)current2.m_geoRoot).GetComponent<AIG_GeomorphNodeVolume>().m_sizeOverrideTransform == (Object)null)
{
continue;
}
foreach (Transform componentsInChild in ((Component)current2.m_geoRoot).GetComponentsInChildren<Transform>())
{
float num = (float)(((CellGridBase<LG_Grid, LG_Tile, LG_Cell>)(object)current.Grid).m_sizeX * 64) * 0.5f;
Vector3 val = new Vector3(num, 0f, num) + componentsInChild.position;
if (Mathf.RoundToInt(val.x / 64f) > ((CellGridBase<LG_Grid, LG_Tile, LG_Cell>)(object)current.Grid).m_sizeX - 1 || Mathf.RoundToInt(val.z / 64f) > ((CellGridBase<LG_Grid, LG_Tile, LG_Cell>)(object)current.Grid).m_sizeX - 1 || Mathf.RoundToInt(val.x / 64f) < 0 || Mathf.RoundToInt(val.z / 64f) < 0)
{
continue;
}
((LG_GridPosition)(ref val2))..ctor(Mathf.RoundToInt(val.x / 64f), Mathf.RoundToInt(val.z / 64f));
try
{
LG_Cell cell = ((CellGridBase<LG_Grid, LG_Tile, LG_Cell>)(object)current.Grid).GetCell(val2);
if (cell != null && ((CellBase<LG_Tile, LG_Cell>)(object)cell).m_grouping == null)
{
((CellGroupingBase<LG_Tile, LG_Cell>)(object)current2).AddCell(cell);
list.Add(new Vector2((float)((CellBase<LG_Tile, LG_Cell>)(object)cell).x, (float)((CellBase<LG_Tile, LG_Cell>)(object)cell).z));
ManualLogSource l = L;
BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(21, 3, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("added a cell at ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(((CellBase<LG_Tile, LG_Cell>)(object)cell).x);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(((CellBase<LG_Tile, LG_Cell>)(object)cell).z);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" to ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(((Object)current2.m_geoRoot).name);
}
l.LogInfo(val3);
}
}
catch
{
}
}
}
enumerator2 = current.Tiles.GetEnumerator();
while (enumerator2.MoveNext())
{
LG_Tile current4 = enumerator2.Current;
if (current4 != null && !((Object)(object)current4.m_geoRoot == (Object)null) && ((CellGroupingBase<LG_Tile, LG_Cell>)(object)current4).m_cells != null && ((CellGroupingBase<LG_Tile, LG_Cell>)(object)current4).m_cells.Count != 0)
{
int x = ((CellBase<LG_Tile, LG_Cell>)(object)((CellGroupingBase<LG_Tile, LG_Cell>)(object)current4).m_cells[0]).x;
int z = ((CellBase<LG_Tile, LG_Cell>)(object)((CellGroupingBase<LG_Tile, LG_Cell>)(object)current4).m_cells[0]).z;
if (!list.Contains(new Vector2((float)(x - 1), (float)z)))
{
((CellGroupingBase<LG_Tile, LG_Cell>)(object)current4).AddCell(((CellGridBase<LG_Grid, LG_Tile, LG_Cell>)(object)current.Grid).GetCell(x - 1, z));
}
if (!list.Contains(new Vector2((float)(x + 1), (float)z)))
{
((CellGroupingBase<LG_Tile, LG_Cell>)(object)current4).AddCell(((CellGridBase<LG_Grid, LG_Tile, LG_Cell>)(object)current.Grid).GetCell(x + 1, z));
}
if (!list.Contains(new Vector2((float)x, (float)(z - 1))))
{
((CellGroupingBase<LG_Tile, LG_Cell>)(object)current4).AddCell(((CellGridBase<LG_Grid, LG_Tile, LG_Cell>)(object)current.Grid).GetCell(x, z - 1));
}
if (!list.Contains(new Vector2((float)x, (float)(z + 1))))
{
((CellGroupingBase<LG_Tile, LG_Cell>)(object)current4).AddCell(((CellGridBase<LG_Grid, LG_Tile, LG_Cell>)(object)current.Grid).GetCell(x, z + 1));
}
ManualLogSource l2 = L;
BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(53, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("tile ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(((Object)current4.m_geoRoot).name);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" padded with buffer cells (if skirting the void)");
}
l2.LogInfo(val3);
}
}
}
}
}
public static string CONFIG_PATH = Path.Combine(Paths.ConfigPath, "BorkenCellGeoFix.cfg");
public static ConfigFile config = new ConfigFile(CONFIG_PATH, true);
public static ConfigEntry<bool> _cleanUp;
internal static ManualLogSource L;
public override void Load()
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Expected O, but got Unknown
//IL_002a: Expected O, but got Unknown
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
_cleanUp = config.Bind<bool>(new ConfigDefinition("General", "Cleanup"), true, new ConfigDescription("Do cleanup of objects outside geomorph limits?", (AcceptableValueBase)null, Array.Empty<object>()));
L = ((BasePlugin)this).Log;
new Harmony("bcf").PatchAll();
EventAPI.OnExpeditionStarted += CargoFix;
}
public static void CargoFix()
{
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
ElevatorCargoCage val = Object.FindObjectOfType<ElevatorCargoCage>();
if ((Object)(object)val == (Object)null)
{
return;
}
foreach (ItemCuller componentsInChild in ((Component)val).GetComponentsInChildren<ItemCuller>())
{
componentsInChild.MoveToNode(Builder.CurrentFloor.allZones[0].m_areas[0].m_courseNode.m_cullNode, ((Component)val).transform.position);
}
}
}
[GeneratedCode("VersionInfoGenerator", "2.0.0+git50a4b1a-master")]
[CompilerGenerated]
internal static class VersionInfo
{
public const string RootNamespace = "BorkenCellGeoFix";
public const string Version = "1.0.0";
public const string VersionPrerelease = null;
public const string VersionMetadata = null;
public const string SemVer = "1.0.0";
public const string GitRevShort = null;
public const string GitRevLong = null;
public const string GitBranch = null;
public const string GitTag = null;
public const bool GitIsDirty = false;
}
}