using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Diagnostics;
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.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
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.3")]
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_006c: 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_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: 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_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_0139: 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_015f: Unknown result type (might be due to invalid IL or missing references)
//IL_0169: 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_01c4: Unknown result type (might be due to invalid IL or missing references)
//IL_01d4: 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_01f4: Unknown result type (might be due to invalid IL or missing references)
//IL_0208: Unknown result type (might be due to invalid IL or missing references)
//IL_024f: Unknown result type (might be due to invalid IL or missing references)
//IL_025f: Unknown result type (might be due to invalid IL or missing references)
//IL_026f: Unknown result type (might be due to invalid IL or missing references)
//IL_027f: Unknown result type (might be due to invalid IL or missing references)
//IL_0293: 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_04bf: Unknown result type (might be due to invalid IL or missing references)
//IL_04c4: Unknown result type (might be due to invalid IL or missing references)
//IL_0567: Unknown result type (might be due to invalid IL or missing references)
//IL_056e: Expected O, but got Unknown
//IL_05a2: 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())
{
Enumerator<LG_Tile> enumerator2 = enumerator.Current.Tiles.GetEnumerator();
while (enumerator2.MoveNext())
{
LG_Tile current = enumerator2.Current;
List<GameObject> list = new List<GameObject>();
LG_Geomorph geoRoot = current.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.Contains("infront") || text.Contains("behind") || text.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_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0103: 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_0322: Unknown result type (might be due to invalid IL or missing references)
//IL_0127: Unknown result type (might be due to invalid IL or missing references)
//IL_034f: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Unknown result type (might be due to invalid IL or missing references)
//IL_037d: Unknown result type (might be due to invalid IL or missing references)
//IL_0384: Expected O, but got Unknown
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
//IL_017b: 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_01aa: Unknown result type (might be due to invalid IL or missing references)
//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
//IL_01fb: 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;
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 || Mathf.RoundToInt(val.z / 64f) > ((CellGridBase<LG_Grid, LG_Tile, LG_Cell>)(object)current.Grid).m_sizeX || 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));
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(19, 3, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("added 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);
}
}
}
enumerator2 = current.Tiles.GetEnumerator();
while (enumerator2.MoveNext())
{
LG_Tile current4 = enumerator2.Current;
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);
}
}
}
}
internal static ManualLogSource L;
public override void Load()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
L = ((BasePlugin)this).Log;
new Harmony("bcf").PatchAll();
}
}
[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;
}
}