using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using CG;
using CG.Game.SpaceObjects.Controllers;
using CG.Ship.Hull;
using CG.Ship.Modules;
using Gameplay.Atmosphere;
using Gameplay.DataTables;
using Gameplay.Defects;
using Gameplay.Power;
using Gameplay.SpacePlatforms;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;
using VC.Common.PlayerShip;
using VoidManager;
using VoidManager.MPModChecks;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("NeoLorem")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Two extra module slots at the rear of the Striker (Void Crew).")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("StrikerExtraModules")]
[assembly: AssemblyTitle("StrikerExtraModules")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace StrikerExtraModules
{
internal static class ExtraCells
{
private static readonly Vector3 Half = new Vector3(2.1f, 2.4f, 1.95f);
private static readonly Vector3 Middle = new Vector3(0f, 1.9f, 0f);
private static readonly List<(Transform copy, Transform source)> Cells = new List<(Transform, Transform)>();
internal static void Add(Transform copy, Transform source)
{
Cells.RemoveAll(((Transform copy, Transform source) c) => (Object)(object)c.copy == (Object)null || (Object)(object)c.source == (Object)null);
Cells.Add((copy, source));
}
internal static bool TryMap(Vector3 position, out Vector3 mapped)
{
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: 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_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
foreach (var (val, val2) in Cells)
{
if (!((Object)(object)val == (Object)null) && !((Object)(object)val2 == (Object)null))
{
Vector3 val3 = Quaternion.Inverse(val.rotation) * (position - val.position);
Vector3 val4 = val3 - Middle;
if (Mathf.Abs(val4.x) <= Half.x && Mathf.Abs(val4.y) <= Half.y && Mathf.Abs(val4.z) <= Half.z)
{
mapped = val2.position + val2.rotation * val3;
return true;
}
}
}
mapped = position;
return false;
}
}
[HarmonyPatch]
internal static class RoomLookupPatch
{
private static bool looking;
private static readonly Func<RoomCollection, Vector3, float, Room> FindAt = AccessTools.MethodDelegate<Func<RoomCollection, Vector3, float, Room>>(AccessTools.Method(typeof(RoomCollection), "FindRoomAtPoint", new Type[2]
{
typeof(Vector3),
typeof(float)
}, (Type[])null), (object)null, true);
[HarmonyPatch(typeof(RoomCollection), "FindRoomAtPoint", new Type[]
{
typeof(Vector3),
typeof(float)
})]
[HarmonyPostfix]
private static void AtPosition(RoomCollection __instance, Vector3 position, float searchRadius, ref Room __result)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
Remap(__instance, position, searchRadius, ref __result);
}
[HarmonyPatch(typeof(RoomCollection), "FindRoomAtPoint", new Type[]
{
typeof(RoomPoint),
typeof(float)
})]
[HarmonyPostfix]
private static void AtRoomPoint(RoomCollection __instance, RoomPoint roomPoint, float searchRadius, ref Room __result)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)roomPoint != (Object)null)
{
Remap(__instance, ((Component)roomPoint).transform.position, searchRadius, ref __result);
}
}
private static void Remap(RoomCollection collection, Vector3 position, float radius, ref Room result)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
if (looking || ((Object)(object)result != (Object)null && !result.InSpace) || !ExtraCells.TryMap(position, out var mapped))
{
return;
}
looking = true;
try
{
Room val = FindAt(collection, mapped, radius);
if ((Object)(object)val != (Object)null && !val.InSpace)
{
result = val;
}
}
finally
{
looking = false;
}
}
}
[HarmonyPatch(typeof(CustomObjectPool), "Instantiate")]
internal static class ShipSpawnPatch
{
private static void Postfix(GameObject __result)
{
if ((Object)(object)__result == (Object)null || (Object)(object)__result.GetComponent<BuildSocketController>() == (Object)null)
{
return;
}
try
{
ExtraSlots.AddTo(__result);
}
catch (Exception arg)
{
Plugin.Log.LogError((object)$"Adding the extra slots failed: {arg}");
}
}
}
internal static class ExtraSlots
{
internal const float SlotSize = 4f;
private const int WalkingLayer = 27;
internal static bool IsStriker(GameObject ship)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Invalid comparison between Unknown and I4
AbstractCloneStarObject component = ship.GetComponent<AbstractCloneStarObject>();
OrbitObjectRuntimeVisualsTable instance = DataTable<OrbitObjectRuntimeVisualsTable>.Instance;
PlayerShipType val = default(PlayerShipType);
if ((Object)(object)component != (Object)null && (Object)(object)instance != (Object)null && instance.TryGetShipType(component.ContainerGuid, ref val))
{
return (int)val == 1;
}
return false;
}
internal static void AddTo(GameObject ship)
{
//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
if (!IsStriker(ship))
{
return;
}
BuildSocketController component = ship.GetComponent<BuildSocketController>();
if (component.Sockets == null || component.Sockets.Count == 0)
{
BuildSocket[] componentsInChildren = ship.GetComponentsInChildren<BuildSocket>(true);
component.Sockets = new List<BuildSocket>(componentsInChildren);
for (int i = 0; i < componentsInChildren.Length; i++)
{
componentsInChildren[i].Index = i;
}
}
int count = component.Sockets.Count;
for (int j = 0; j < Plugin.Slots.Length; j++)
{
SlotDef slotDef = Plugin.Slots[j];
if (slotDef.SourceSocket >= count)
{
Plugin.Log.LogWarning((object)$"Extra slot {j + 1}: source slot {slotDef.SourceSocket} doesn't exist (the Striker has {count})");
continue;
}
BuildSocket val = component.Sockets[slotDef.SourceSocket];
Transform copied;
BuildSocket val2 = AddSlot(component, val, slotDef, j + 1, out copied);
ConnectPower(val2, j + 1);
ExtraCells.Add(((Component)val2).transform, ((Component)val).transform);
Remove(ship.transform, slotDef.Remove, j + 1);
if ((Object)(object)copied != (Object)(object)((Component)val2).transform)
{
GiveFloorAndWalls(ship.transform, val, val2, copied, j + 1);
}
string text = WallCut.Cut(ship.transform, slotDef, ((Component)val2).transform, copied);
text = text + ", " + ClearCell(ship.transform, ((Component)val2).transform, copied, j + 1);
Plugin.Log.LogInfo((object)($"Extra slot {j + 1}: added as slot {val2.Index} ({val2.Size}), copied from slot {slotDef.SourceSocket} " + "(" + (((Object)(object)copied != (Object)(object)((Component)val2).transform) ? ("with its workshop " + ((Object)copied).name) : "slot only") + "), " + text));
}
}
internal static Transform OwnWorkshop(BuildSocket socket)
{
Transform parent = ((Component)socket).transform.parent;
if (!((Object)(object)parent != (Object)null) || !((Object)(object)((Component)parent).GetComponent<BuildSocketController>() == (Object)null) || ((Component)parent).GetComponentsInChildren<BuildSocket>(true).Length != 1)
{
return null;
}
return parent;
}
internal static void TargetPose(BuildSocket source, SlotDef slot, out Vector3 position, out Quaternion rotation)
{
//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_0018: 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_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
position = ((Component)source).transform.position + ((Component)source).transform.rotation * slot.Offset;
rotation = ((Component)source).transform.rotation;
}
internal static List<string> Paths(string value)
{
return (from p in (value ?? "").Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries)
select p.Trim() into p
where p.Length > 0
select p).ToList();
}
private static BuildSocket AddSlot(BuildSocketController controller, BuildSocket source, SlotDef slot, int number, out Transform copied)
{
//IL_00d7: 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_00ea: 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_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: 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_0053: 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_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
TargetPose(source, slot, out var position, out var rotation);
Transform val = OwnWorkshop(source);
BuildSocket val3;
if ((Object)(object)val != (Object)null)
{
Quaternion val2 = rotation * Quaternion.Inverse(((Component)source).transform.rotation);
copied = Object.Instantiate<GameObject>(((Component)val).gameObject, val.parent).transform;
copied.SetPositionAndRotation(position + val2 * (val.position - ((Component)source).transform.position), val2 * val.rotation);
copied.localScale = val.localScale;
((Object)copied).name = $"{((Object)val).name} (Extra {number})";
val3 = ((Component)copied).GetComponentInChildren<BuildSocket>(true);
}
else
{
val3 = Object.Instantiate<BuildSocket>(source, ((Component)source).transform.parent);
((Component)val3).transform.SetPositionAndRotation(position, rotation);
((Component)val3).transform.localScale = ((Component)source).transform.localScale;
copied = ((Component)val3).transform;
}
((Object)val3).name = $"{((Object)source).name} (Extra {number})";
val3.Index = controller.Sockets.Count;
val3.BuildSocketNeighbors = new List<BuildSocket>();
val3.DisableWhenOccupied = KeepOwn(copied, val3.DisableWhenOccupied, "DisableWhenOccupied", number);
val3.ConnectedColliders = KeepOwn<Collider>(copied, val3.ConnectedColliders, "ConnectedColliders", number);
controller.Sockets.Add(val3);
return val3;
}
private static void ConnectPower(BuildSocket copy, int number)
{
PowerPropagator powerProp = copy.PowerProp;
PowerDistributor val = (((Object)(object)powerProp != (Object)null) ? powerProp.ConnectedToSystem : null);
if ((Object)(object)val == (Object)null)
{
Plugin.Log.LogWarning((object)$"Extra slot {number}: the slot has no power system to join");
return;
}
if (!val.Propagators.Contains(powerProp))
{
val.ConnectPropagator(powerProp);
}
Plugin.Log.LogInfo((object)$"Extra slot {number}: joined power system {((Object)val).name} ({val.Propagators.Count} links)");
}
private static void GiveFloorAndWalls(Transform ship, BuildSocket source, BuildSocket copy, Transform copied, int number)
{
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00df: 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_01b8: Unknown result type (might be due to invalid IL or missing references)
//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
//IL_01c5: 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_01c9: Unknown result type (might be due to invalid IL or missing references)
//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
//IL_01df: Unknown result type (might be due to invalid IL or missing references)
//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
//IL_0201: Unknown result type (might be due to invalid IL or missing references)
//IL_0212: 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_022a: 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_0242: Unknown result type (might be due to invalid IL or missing references)
//IL_024e: 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_0286: Expected O, but got Unknown
//IL_029c: Unknown result type (might be due to invalid IL or missing references)
//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
//IL_02b5: 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_02bf: Unknown result type (might be due to invalid IL or missing references)
//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
//IL_02ea: 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_0306: Unknown result type (might be due to invalid IL or missing references)
//IL_0317: 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_0327: Unknown result type (might be due to invalid IL or missing references)
List<string> list = new List<string>();
Collider[] componentsInChildren = ((Component)copied).GetComponentsInChildren<Collider>(true);
foreach (Collider val in componentsInChildren)
{
if (!val.isTrigger && !((Component)val).gameObject.activeSelf && (Object)(object)((Component)val).GetComponentInParent<BuildSocket>(true) == (Object)null)
{
((Component)val).gameObject.SetActive(true);
((Component)val).gameObject.layer = 27;
list.Add(((Object)val).name);
}
}
Transform val2 = OwnWorkshop(source);
Transform transform = ((Component)source).transform;
Transform transform2 = ((Component)copy).transform;
Quaternion val3 = transform2.rotation * Quaternion.Inverse(transform.rotation);
Matrix4x4 val4 = Matrix4x4.TRS(transform.position + transform.rotation * new Vector3(0f, 1.6f, 0f), transform.rotation, Vector3.one);
Matrix4x4 inverse = ((Matrix4x4)(ref val4)).inverse;
Vector3 val5 = default(Vector3);
((Vector3)(ref val5))..ctor(2f, 2f, 2f);
componentsInChildren = ((Component)ship).GetComponentsInChildren<Collider>(true);
foreach (Collider val6 in componentsInChildren)
{
if (!val6.isTrigger && val6.enabled && ActiveUnder(ship, ((Component)val6).transform) && ((Component)val6).gameObject.layer == 27 && (!((Object)(object)val2 != (Object)null) || !((Component)val6).transform.IsChildOf(val2)) && !((Component)val6).transform.IsChildOf(copied) && !((Object)(object)((Component)val6).GetComponentInParent<BuildSocket>(true) != (Object)null) && !((Object)(object)((Component)val6).GetComponentInParent<CellModule>(true) != (Object)null) && WorldBox(val6, out var min, out var max))
{
Vector3 val7 = max - min;
Vector3 val8 = ((Matrix4x4)(ref inverse)).MultiplyPoint3x4((min + max) * 0.5f);
if (!(val7.x > 7f) && !(val7.y > 7f) && !(val7.z > 7f) && !(Mathf.Abs(val8.x) > val5.x) && !(Mathf.Abs(val8.y) > val5.y) && !(Mathf.Abs(val8.z) > val5.z))
{
GameObject val9 = new GameObject(((Object)val6).name + $" (Extra {number})")
{
layer = 27
};
val9.transform.SetParent(copied, false);
val9.transform.SetPositionAndRotation(transform2.position + val3 * (((Component)val6).transform.position - transform.position), val3 * ((Component)val6).transform.rotation);
val9.transform.localScale = Vector3.Scale(((Component)val6).transform.lossyScale, new Vector3(1f / copied.lossyScale.x, 1f / copied.lossyScale.y, 1f / copied.lossyScale.z));
CopyShape(val6, val9);
list.Add(PathFrom(ship, ((Component)val6).transform));
}
}
}
Plugin.Log.LogInfo((object)string.Format("Extra slot {0}: floor and walls: {1}", number, (list.Count > 0) ? string.Join("; ", list) : "none found"));
}
private static bool ActiveUnder(Transform ship, Transform t)
{
Transform val = t;
while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)ship)
{
if (!((Component)val).gameObject.activeSelf)
{
return false;
}
val = val.parent;
}
return true;
}
private static void CopyShape(Collider source, GameObject to)
{
//IL_0031: 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_0085: 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)
BoxCollider val = (BoxCollider)(object)((source is BoxCollider) ? source : null);
if (val == null)
{
MeshCollider val2 = (MeshCollider)(object)((source is MeshCollider) ? source : null);
if (val2 == null)
{
SphereCollider val3 = (SphereCollider)(object)((source is SphereCollider) ? source : null);
if (val3 == null)
{
CapsuleCollider val4 = (CapsuleCollider)(object)((source is CapsuleCollider) ? source : null);
if (val4 != null)
{
CapsuleCollider obj = to.AddComponent<CapsuleCollider>();
obj.center = val4.center;
obj.radius = val4.radius;
obj.height = val4.height;
obj.direction = val4.direction;
((Collider)obj).sharedMaterial = ((Collider)val4).sharedMaterial;
}
}
else
{
SphereCollider obj2 = to.AddComponent<SphereCollider>();
obj2.center = val3.center;
obj2.radius = val3.radius;
((Collider)obj2).sharedMaterial = ((Collider)val3).sharedMaterial;
}
}
else
{
MeshCollider obj3 = to.AddComponent<MeshCollider>();
obj3.sharedMesh = val2.sharedMesh;
obj3.convex = val2.convex;
((Collider)obj3).sharedMaterial = ((Collider)val2).sharedMaterial;
}
}
else
{
BoxCollider obj4 = to.AddComponent<BoxCollider>();
obj4.center = val.center;
obj4.size = val.size;
((Collider)obj4).sharedMaterial = ((Collider)val).sharedMaterial;
}
}
private static T[] KeepOwn<T>(Transform root, T[] items, string field, int number) where T : Component
{
return KeepOwn(root, items?.Select((T c) => (!((Object)(object)c != (Object)null)) ? null : ((Component)c).gameObject).ToArray(), field, number)?.Select((GameObject go) => go.GetComponent<T>()).ToArray();
}
private static GameObject[] KeepOwn(Transform root, GameObject[] items, string field, int number)
{
if (items == null)
{
return null;
}
List<GameObject> list = new List<GameObject>();
foreach (GameObject val in items)
{
if ((Object)(object)val != (Object)null && val.transform.IsChildOf(root))
{
list.Add(val);
}
else if ((Object)(object)val != (Object)null)
{
Plugin.Log.LogInfo((object)$"Extra slot {number}: {field} entry \"{((Object)val).name}\" belongs to the source slot, left out");
}
}
return list.ToArray();
}
private static void Remove(Transform ship, string[] paths, int number)
{
foreach (string text in paths)
{
Transform val = ship.Find(text);
if ((Object)(object)val == (Object)null)
{
Plugin.Log.LogWarning((object)$"Extra slot {number}: nothing to hide at \"{text}\"");
continue;
}
Defect[] defects = ((Component)val).GetComponentsInChildren<Defect>(true);
if (defects.Length == 0)
{
((Component)val).gameObject.SetActive(false);
Plugin.Log.LogInfo((object)$"Extra slot {number}: turned off \"{text}\"");
continue;
}
DefectSystem[] componentsInChildren = ((Component)ship).GetComponentsInChildren<DefectSystem>(true);
for (int j = 0; j < componentsInChildren.Length; j++)
{
componentsInChildren[j].AvailableDefects.RemoveAll((Defect d) => defects.Contains(d));
}
SpaceObjectDefectController[] componentsInChildren2 = ((Component)ship).GetComponentsInChildren<SpaceObjectDefectController>(true);
for (int j = 0; j < componentsInChildren2.Length; j++)
{
foreach (DefectCluster item in Traverse.Create((object)componentsInChildren2[j]).Field("defectClusters").GetValue<List<DefectCluster>>() ?? new List<DefectCluster>())
{
item.Defects?.RemoveAll((Defect d) => defects.Contains(d));
}
}
Object.DestroyImmediate((Object)(object)((Component)val).gameObject);
Plugin.Log.LogInfo((object)$"Extra slot {number}: removed {defects.Length} defect(s) at \"{text}\"");
}
}
private static string ClearCell(Transform ship, Transform slot, Transform exclude, int number)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: 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_0101: 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_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: 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_013b: 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_0159: Unknown result type (might be due to invalid IL or missing references)
//IL_015b: Unknown result type (might be due to invalid IL or missing references)
//IL_0165: 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_0171: 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_0185: Unknown result type (might be due to invalid IL or missing references)
//IL_0191: Unknown result type (might be due to invalid IL or missing references)
//IL_0199: Unknown result type (might be due to invalid IL or missing references)
//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
//IL_0203: Unknown result type (might be due to invalid IL or missing references)
Matrix4x4 val = Matrix4x4.TRS(slot.position + slot.rotation * new Vector3(0f, 1.8f, 0f), slot.rotation, Vector3.one);
Matrix4x4 inverse = ((Matrix4x4)(ref val)).inverse;
Vector3 val2 = default(Vector3);
((Vector3)(ref val2))..ctor(1.9f, 1.8f, 1.9f);
int num = 0;
Collider[] componentsInChildren = ((Component)ship).GetComponentsInChildren<Collider>(true);
foreach (Collider val3 in componentsInChildren)
{
if (val3.isTrigger || !val3.enabled || !ActiveUnder(ship, ((Component)val3).transform) || ((Component)val3).gameObject.layer != 27 || ((Component)val3).transform.IsChildOf(exclude) || (Object)(object)((Component)val3).GetComponentInParent<BuildSocket>(true) != (Object)null || (Object)(object)((Component)val3).GetComponentInParent<CellModule>(true) != (Object)null || !WorldBox(val3, out var min, out var max))
{
continue;
}
Vector3 val4 = max - min;
if (!(val4.x > 7f) && !(val4.y > 7f) && !(val4.z > 7f) && Reaches(min, max, inverse, val2))
{
string text = PathFrom(ship, ((Component)val3).transform);
Vector3 val5 = ((Matrix4x4)(ref inverse)).MultiplyPoint3x4((min + max) * 0.5f);
bool flag = Mathf.Abs(val5.x) <= val2.x && Mathf.Abs(val5.y) <= val2.y && Mathf.Abs(val5.z) <= val2.z;
if (flag)
{
val3.enabled = false;
num++;
}
Plugin.Log.LogInfo((object)string.Format("Extra slot {0}: walking collider {1} (size {2:0.0} {3:0.0} {4:0.0}) {5}", number, text, val4.x, val4.y, val4.z, flag ? "turned off, it's inside the cell" : "kept, it only reaches in"));
}
}
return $"{num} collider(s) cleared from the cell";
}
private static bool WorldBox(Collider collider, out Vector3 min, out Vector3 max)
{
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_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_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_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: 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_00fb: 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_0102: 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_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: 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_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: 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_00a6: 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_012a: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_014d: 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_0165: 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_016c: Unknown result type (might be due to invalid IL or missing references)
//IL_0171: 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_017f: Unknown result type (might be due to invalid IL or missing references)
//IL_0184: Unknown result type (might be due to invalid IL or missing references)
BoxCollider val = (BoxCollider)(object)((collider is BoxCollider) ? collider : null);
Vector3 center;
Vector3 val5;
if (val == null)
{
MeshCollider val2 = (MeshCollider)(object)((collider is MeshCollider) ? collider : null);
if (val2 == null)
{
SphereCollider val3 = (SphereCollider)(object)((collider is SphereCollider) ? collider : null);
if (val3 == null)
{
CapsuleCollider val4 = (CapsuleCollider)(object)((collider is CapsuleCollider) ? collider : null);
if (val4 == null)
{
goto IL_00f1;
}
center = val4.center;
val5 = Vector3.one * val4.radius;
((Vector3)(ref val5))[val4.direction] = Mathf.Max(val4.radius, val4.height * 0.5f);
}
else
{
center = val3.center;
val5 = Vector3.one * val3.radius;
}
}
else
{
if (!((Object)(object)val2.sharedMesh != (Object)null))
{
goto IL_00f1;
}
Bounds bounds = val2.sharedMesh.bounds;
center = ((Bounds)(ref bounds)).center;
bounds = val2.sharedMesh.bounds;
val5 = ((Bounds)(ref bounds)).extents;
}
}
else
{
center = val.center;
val5 = val.size * 0.5f;
}
min = Vector3.positiveInfinity;
max = Vector3.negativeInfinity;
for (int i = 0; i < 8; i++)
{
Vector3 val6 = ((Component)collider).transform.TransformPoint(center + Vector3.Scale(val5, new Vector3((float)(((i & 1) != 0) ? 1 : (-1)), (float)(((i & 2) != 0) ? 1 : (-1)), (float)(((i & 4) != 0) ? 1 : (-1)))));
min = Vector3.Min(min, val6);
max = Vector3.Max(max, val6);
}
return true;
IL_00f1:
min = (max = Vector3.zero);
return false;
}
private static bool Reaches(Vector3 min, Vector3 max, Matrix4x4 toCell, Vector3 half)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: 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_007c: 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_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: 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_003d: 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_00bc: 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_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: 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_005d: 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_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
Vector3 val = Vector3.positiveInfinity;
Vector3 val2 = Vector3.negativeInfinity;
for (int i = 0; i < 8; i++)
{
Vector3 val3 = ((Matrix4x4)(ref toCell)).MultiplyPoint3x4(new Vector3(((i & 1) == 0) ? min.x : max.x, ((i & 2) == 0) ? min.y : max.y, ((i & 4) == 0) ? min.z : max.z));
val = Vector3.Min(val, val3);
val2 = Vector3.Max(val2, val3);
}
if (val.x <= half.x && val2.x >= 0f - half.x && val.y <= half.y && val2.y >= 0f - half.y && val.z <= half.z)
{
return val2.z >= 0f - half.z;
}
return false;
}
internal static string PathFrom(Transform root, Transform t)
{
List<string> list = new List<string>();
Transform val = t;
while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)root)
{
list.Add(((Object)val).name);
val = val.parent;
}
list.Reverse();
return string.Join("/", list);
}
}
internal static class MyPluginInfo
{
public const string GUID = "StrikerExtraModules";
public const string Name = "Striker Extra Modules";
public const string Version = "1.0.0";
}
internal class SlotDef
{
public int SourceSocket;
public Vector3 Offset;
public string[] Remove;
public Vector3 CutCenter;
public Vector3 CutSize = new Vector3(3.8f, 3f, 0.7f);
public bool WholeTriangles;
}
[BepInPlugin("StrikerExtraModules", "Striker Extra Modules", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Log;
internal static Plugin Instance;
internal static readonly string[] CutMeshes = new string[4] { "MTM_Striker_Interior_01/Graphics/RightWing_Hallway/MTM_Striker_Interior_RightWing_Hallway/", "MTM_Striker_Interior_01/Graphics/RightWing_Hallway/Colliders/", "MTM_Striker_Interior_01/Graphics/LeftWing_Hallway/MTM_Striker_Interior_LeftWing_Hallway/", "MTM_Striker_Interior_01/Graphics/LeftWing_Hallway/Colliders/" };
internal static readonly SlotDef[] Slots = new SlotDef[2]
{
new SlotDef
{
SourceSocket = 3,
Offset = new Vector3(4f, 0f, 0f),
CutCenter = new Vector3(0.1f, 1.5f, -2f),
Remove = new string[4] { "Defects_Striker/DefectTubes/Defect_Tube_06", "Defects_Striker/Defect Pipes/Defect_WallBox_06", "Defects_Striker/Defect Pipes/Defect_WallBox_07", "MTM_Striker_Interior_01/Graphics/RightWing_Hallway/Colliders/MTM_Striker_Interior_RightWing_Hallway_Colliders/Striker_Interior_R_Wing_RearWallBlock_Collider" }
},
new SlotDef
{
SourceSocket = 6,
Offset = new Vector3(-4f, 0f, 0f),
CutCenter = new Vector3(-0.1f, 1.5f, -2f),
Remove = new string[2] { "Defects_Striker/DefectTubes/Defect_Tube_05", "MTM_Striker_Interior_01/Graphics/LeftWing_Hallway/Colliders/MTM_Striker_Interior_LeftWing_Hallway_Colliders/Striker_Interior_L_Wing_RearWallBlock_Collider" }
}
};
private void Awake()
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
Log = ((BaseUnityPlugin)this).Logger;
Instance = this;
new Harmony("StrikerExtraModules").PatchAll();
Log.LogInfo((object)"Striker Extra Modules 1.0.0 loaded");
}
}
public class VoidManagerPlugin : VoidPlugin
{
public override MultiplayerType MPType => (MultiplayerType)30;
public override string Author => "NeoLorem";
public override string Description => "Two extra module slots at the rear of the Striker.";
}
[HarmonyPatch(typeof(MovingSpacePlatform), "SetUpSimulationScene")]
internal static class WalkingSceneBuiltPatch
{
private static void Postfix(MovingSpacePlatform __instance)
{
if (((Component)__instance).GetComponentsInChildren<BuildSocket>(true).Any((BuildSocket s) => ((Object)s).name.Contains("(Extra ")) && (Object)(object)Plugin.Instance != (Object)null)
{
((MonoBehaviour)Plugin.Instance).StartCoroutine(ClearLater(__instance));
}
}
private static IEnumerator ClearLater(MovingSpacePlatform platform)
{
yield return null;
yield return (object)new WaitForFixedUpdate();
if ((Object)(object)platform != (Object)null)
{
WalkingClear.Run(platform, clear: true);
}
}
}
internal static class WalkingClear
{
private static readonly Vector3 Middle = new Vector3(0f, 1.9f, 0f);
private static readonly Vector3 Half = new Vector3(1.6f, 1.5f, 1.8f);
internal static string Run(MovingSpacePlatform platform, bool clear)
{
//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_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: 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_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)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_012c: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
//IL_013a: 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_0143: Unknown result type (might be due to invalid IL or missing references)
PhysicsScene value = Traverse.Create((object)platform).Field("physicsScene").GetValue<PhysicsScene>();
if (!((PhysicsScene)(ref value)).IsValid())
{
return "the walking physics isn't set up";
}
Dictionary<Collider, Collider> dictionary = new Dictionary<Collider, Collider>();
foreach (KeyValuePair<Collider, Collider> item in platform.PassiveColliders.Concat(platform.ActiveColliders))
{
if ((Object)(object)item.Value != (Object)null)
{
dictionary[item.Value] = item.Key;
}
}
Transform root = ((Component)platform).transform.root;
List<string> list = new List<string>();
Collider[] array = (Collider[])(object)new Collider[64];
foreach (BuildSocket item2 in from s in ((Component)root).GetComponentsInChildren<BuildSocket>(true)
where ((Object)s).name.Contains("(Extra ")
select s)
{
Transform val = CopiedRoot(((Component)item2).transform);
Transform transform = ((Component)item2).transform;
Vector3 val2 = root.InverseTransformPoint(transform.position + transform.rotation * Middle);
Quaternion val3 = Quaternion.Inverse(root.rotation) * transform.rotation;
int num = ((PhysicsScene)(ref value)).OverlapBox(val2, Half, array, val3, -1, (QueryTriggerInteraction)1);
int num2 = 0;
for (int num3 = 0; num3 < num; num3++)
{
Collider val4 = array[num3];
dictionary.TryGetValue(val4, out var value2);
string text = (((Object)(object)value2 != (Object)null) ? ExtraSlots.PathFrom(root, ((Component)value2).transform) : (((Object)val4).name + " (added by the game, no ship collider)"));
bool flag = (Object)(object)value2 != (Object)null && (((Component)value2).transform.IsChildOf(val) || (Object)(object)((Component)value2).GetComponentInParent<BuildSocket>(true) != (Object)null || (Object)(object)((Component)value2).GetComponentInParent<CellModule>(true) != (Object)null);
bool flag2 = clear && (Object)(object)value2 != (Object)null && !flag && val4.enabled;
if (flag2)
{
val4.enabled = false;
num2++;
}
Plugin.Log.LogInfo((object)($"{((Object)item2).name}: walking collider {text} (layer {((Component)val4).gameObject.layer}, size {Size(val4)}) " + (flag2 ? "turned off" : (flag ? "kept (the cell's own)" : ((!val4.enabled) ? "already off" : "kept")))));
}
list.Add(string.Format("{0}: {1} walking collider(s) in the cell{2}", ((Object)item2).name, num, clear ? $", {num2} turned off" : ""));
}
string text2 = ((list.Count > 0) ? string.Join("; ", list) : "no extra slots on this ship");
Plugin.Log.LogInfo((object)("Walking colliders: " + text2));
return text2;
}
private static Transform CopiedRoot(Transform socket)
{
string value = ((Object)socket).name.Substring(((Object)socket).name.IndexOf("(Extra "));
Transform val = socket;
while ((Object)(object)val.parent != (Object)null && ((Object)val.parent).name.EndsWith(value))
{
val = val.parent;
}
return val;
}
private static string Size(Collider collider)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
Bounds bounds = collider.bounds;
Vector3 size = ((Bounds)(ref bounds)).size;
return $"{size.x:0.0} {size.y:0.0} {size.z:0.0}";
}
}
internal static class WallCut
{
internal static string Cut(Transform ship, SlotDef slot, Transform at, Transform exclude)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
return Cut(ship, slot, at.position, at.rotation, exclude);
}
internal static string Cut(Transform ship, SlotDef slot, Vector3 position, Quaternion rotation, Transform exclude)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: 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_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: 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_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)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_00dd: 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_00ea: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: 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_0143: 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)
Matrix4x4 val = Matrix4x4.TRS(position + rotation * slot.CutCenter, rotation, Vector3.one);
Matrix4x4 inverse = ((Matrix4x4)(ref val)).inverse;
Vector3 half = slot.CutSize * 0.5f;
string[] cutMeshes = Plugin.CutMeshes;
int num = 0;
int num2 = 0;
List<string> list = new List<string>();
foreach (Component item in ((Component)ship).GetComponentsInChildren<MeshFilter>(true).Cast<Component>().Concat((IEnumerable<Component>)(object)((Component)ship).GetComponentsInChildren<MeshCollider>(true)))
{
if ((Object)(object)exclude != (Object)null && item.transform.IsChildOf(exclude))
{
continue;
}
string path = ExtraSlots.PathFrom(ship, item.transform);
if (!cutMeshes.Any((string p) => path.StartsWith(p)))
{
continue;
}
Mesh val2 = MeshOf(item);
if ((Object)(object)val2 == (Object)null)
{
continue;
}
Matrix4x4 meshToBox = inverse * item.transform.localToWorldMatrix;
if (!Overlaps(val2.bounds, meshToBox, half))
{
continue;
}
Mesh val3 = (val2.isReadable ? val2 : ReadBack(val2, path, retry: true));
if ((Object)(object)val3 == (Object)null)
{
list.Add(path);
continue;
}
int num3 = CutMesh(item, val2, val3, meshToBox, half, slot.WholeTriangles);
if (num3 > 0)
{
num++;
num2 += num3;
Plugin.Log.LogInfo((object)string.Format("Wall cut: {0} triangles out of {1} ({2})", num3, path, (item is MeshCollider) ? "collider" : "mesh"));
}
}
string text = $"wall cut: {num2} triangles from {num} mesh(es)";
if (list.Count > 0)
{
text += string.Format(", {0} mesh(es) can't be read: {1}", list.Count, string.Join("; ", list));
Plugin.Log.LogWarning((object)("Wall cut: these meshes aren't readable, so they can't be cut: " + string.Join("; ", list)));
}
return text;
}
private static Mesh MeshOf(Component part)
{
MeshFilter val = (MeshFilter)(object)((part is MeshFilter) ? part : null);
if (val == null)
{
MeshCollider val2 = (MeshCollider)(object)((part is MeshCollider) ? part : null);
if (val2 == null)
{
return null;
}
return val2.sharedMesh;
}
return val.sharedMesh;
}
private static void SetMesh(Component part, Mesh mesh)
{
MeshFilter val = (MeshFilter)(object)((part is MeshFilter) ? part : null);
if (val != null)
{
val.sharedMesh = mesh;
return;
}
MeshCollider val2 = (MeshCollider)(object)((part is MeshCollider) ? part : null);
if (val2 != null)
{
val2.sharedMesh = mesh;
}
}
private static Mesh ReadBack(Mesh mesh, string path, bool retry)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
Mesh val = ReadBack(mesh, path);
if ((Object)(object)val == (Object)null && retry && (mesh.vertexBufferTarget & 0x20) == 0)
{
try
{
mesh.vertexBufferTarget = (Target)(mesh.vertexBufferTarget | 0x20);
mesh.indexBufferTarget = (Target)(mesh.indexBufferTarget | 0x20);
val = ReadBack(mesh, path);
}
catch (Exception ex)
{
Fail(path, "raw buffer access: " + ex.Message);
}
}
if ((Object)(object)val != (Object)null)
{
Plugin.Log.LogInfo((object)$"Wall cut: read {path} back from the GPU ({val.vertexCount} vertices)");
}
return val;
}
private static Mesh ReadBack(Mesh mesh, string path)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Expected O, but got Unknown
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_014c: 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)
try
{
Mesh val = new Mesh
{
name = ((Object)mesh).name,
indexFormat = mesh.indexFormat
};
val.SetVertexBufferParams(mesh.vertexCount, mesh.GetVertexAttributes());
for (int i = 0; i < mesh.vertexBufferCount; i++)
{
GraphicsBuffer vertexBuffer = mesh.GetVertexBuffer(i);
try
{
if (vertexBuffer == null)
{
return Fail(path, $"no vertex buffer {i}");
}
byte[] array = new byte[vertexBuffer.count * vertexBuffer.stride];
vertexBuffer.GetData((Array)array);
val.SetVertexBufferData<byte>(array, 0, 0, array.Length, i, (MeshUpdateFlags)13);
}
finally
{
((IDisposable)vertexBuffer)?.Dispose();
}
}
GraphicsBuffer indexBuffer = mesh.GetIndexBuffer();
try
{
if (indexBuffer == null)
{
return Fail(path, "no index buffer");
}
val.SetIndexBufferParams(indexBuffer.count, mesh.indexFormat);
if ((int)mesh.indexFormat == 0)
{
ushort[] array2 = new ushort[indexBuffer.count];
indexBuffer.GetData((Array)array2);
val.SetIndexBufferData<ushort>(array2, 0, 0, array2.Length, (MeshUpdateFlags)13);
}
else
{
int[] array3 = new int[indexBuffer.count];
indexBuffer.GetData((Array)array3);
val.SetIndexBufferData<int>(array3, 0, 0, array3.Length, (MeshUpdateFlags)13);
}
}
finally
{
((IDisposable)indexBuffer)?.Dispose();
}
val.subMeshCount = mesh.subMeshCount;
for (int j = 0; j < mesh.subMeshCount; j++)
{
val.SetSubMesh(j, mesh.GetSubMesh(j), (MeshUpdateFlags)13);
}
val.bounds = mesh.bounds;
if (val.vertices.All((Vector3 v) => v == Vector3.zero))
{
Object.Destroy((Object)(object)val);
return Fail(path, "the vertex data read back empty");
}
return val;
}
catch (Exception ex)
{
return Fail(path, ex.Message);
}
}
private static Mesh Fail(string path, string why)
{
Plugin.Log.LogWarning((object)("Wall cut: couldn't read " + path + " back from the GPU (" + why + ")"));
return null;
}
private static int CutMesh(Component part, Mesh mesh, Mesh readable, Matrix4x4 meshToBox, Vector3 half, bool whole)
{
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_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)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: 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_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: 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)
Vector3[] vertices = readable.vertices;
List<int[]> list = new List<int[]>();
int num = 0;
for (int i = 0; i < readable.subMeshCount; i++)
{
int[] triangles = readable.GetTriangles(i);
List<int> list2 = new List<int>(triangles.Length);
for (int j = 0; j + 2 < triangles.Length; j += 3)
{
Vector3 val = vertices[triangles[j]];
Vector3 val2 = vertices[triangles[j + 1]];
Vector3 val3 = vertices[triangles[j + 2]];
bool num2;
if (!whole)
{
num2 = Inside(((Matrix4x4)(ref meshToBox)).MultiplyPoint3x4((val + val2 + val3) / 3f), half);
}
else
{
if (!Inside(((Matrix4x4)(ref meshToBox)).MultiplyPoint3x4(val), half) || !Inside(((Matrix4x4)(ref meshToBox)).MultiplyPoint3x4(val2), half))
{
goto IL_00cc;
}
num2 = Inside(((Matrix4x4)(ref meshToBox)).MultiplyPoint3x4(val3), half);
}
if (num2)
{
num++;
continue;
}
goto IL_00cc;
IL_00cc:
list2.Add(triangles[j]);
list2.Add(triangles[j + 1]);
list2.Add(triangles[j + 2]);
}
list.Add(list2.ToArray());
}
if (num == 0)
{
if ((Object)(object)readable != (Object)(object)mesh)
{
Object.Destroy((Object)(object)readable);
}
return 0;
}
Mesh val4 = (((Object)(object)readable != (Object)(object)mesh) ? readable : Object.Instantiate<Mesh>(mesh));
((Object)val4).name = ((Object)mesh).name + " (extra slots cut)";
for (int k = 0; k < list.Count; k++)
{
val4.SetTriangles(list[k], k);
}
SetMesh(part, val4);
return num;
}
private static bool Inside(Vector3 p, Vector3 half)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: 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_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
if (Mathf.Abs(p.x) <= half.x && Mathf.Abs(p.y) <= half.y)
{
return Mathf.Abs(p.z) <= half.z;
}
return false;
}
private static bool Overlaps(Bounds bounds, Matrix4x4 meshToBox, Vector3 half)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: 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_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: 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_008d: 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_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: 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_00be: 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_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: 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_0057: 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_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_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)
Vector3 val = Vector3.positiveInfinity;
Vector3 val2 = Vector3.negativeInfinity;
for (int i = 0; i < 8; i++)
{
Vector3 val3 = ((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)(((i & 1) != 0) ? 1 : (-1)), (float)(((i & 2) != 0) ? 1 : (-1)), (float)(((i & 4) != 0) ? 1 : (-1))));
Vector3 val4 = ((Matrix4x4)(ref meshToBox)).MultiplyPoint3x4(val3);
val = Vector3.Min(val, val4);
val2 = Vector3.Max(val2, val4);
}
if (val.x <= half.x && val2.x >= 0f - half.x && val.y <= half.y && val2.y >= 0f - half.y && val.z <= half.z)
{
return val2.z >= 0f - half.z;
}
return false;
}
}
}