Decompiled source of GiantPlants v1.5.3
DSPVegetationScale.dll
Decompiled a day ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using DSPPreserveVegetation; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")] [assembly: AssemblyCompany("DSPVegetationScale")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.5.3.0")] [assembly: AssemblyInformationalVersion("1.5.3+7d3e1d269f4b2d0b7b5cdba9dda825f5da403566")] [assembly: AssemblyProduct("DSPVegetationScale")] [assembly: AssemblyTitle("DSPVegetationScale")] [assembly: AssemblyVersion("1.5.3.0")] namespace DSPPreserveVegetation { internal static class ColliderIntersection { private const float RequiredPenetration = 0.001f; internal static bool Overlaps(ColliderData first, ColliderData second) { //IL_0000: 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_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Expected I4, but got Unknown //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0040: 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) if (first.idType == 0 || second.idType == 0) { return false; } EColliderShape shape = ((ColliderData)(ref first)).shape; return (shape - 1) switch { 0 => SphereOverlaps(first, second), 1 => CapsuleOverlaps(first, second), 2 => BoxOverlaps(first, second), _ => false, }; } private static bool SphereOverlaps(ColliderData sphere, ColliderData other) { //IL_0002: 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_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected I4, but got Unknown //IL_001e: 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_0024: 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_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_004a: 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_0055: 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_005b: 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_0067: 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_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_0080: Unknown result type (might be due to invalid IL or missing references) EColliderShape shape = ((ColliderData)(ref other)).shape; switch (shape - 1) { case 0: { Vector3 val = sphere.pos - other.pos; return IsWithinRadius(((Vector3)(ref val)).sqrMagnitude, sphere.radius + other.radius); } case 1: { GetCapsuleSegment(other, out var start, out var end); return IsWithinRadius(PointSegmentDistanceSquared(sphere.pos, start, end), sphere.radius + other.radius); } case 2: return IsWithinRadius(PointBoxDistanceSquared(sphere.pos, other), sphere.radius); default: return false; } } private static bool CapsuleOverlaps(ColliderData capsule, ColliderData other) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000c: 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_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Expected I4, but got Unknown //IL_002a: 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_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_004a: 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_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_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0063: 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_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) GetCapsuleSegment(capsule, out var start, out var end); EColliderShape shape = ((ColliderData)(ref other)).shape; switch (shape - 1) { case 0: return IsWithinRadius(PointSegmentDistanceSquared(other.pos, start, end), capsule.radius + other.radius); case 1: { GetCapsuleSegment(other, out var start2, out var end2); return IsWithinRadius(SegmentSegmentDistanceSquared(start, end, start2, end2), capsule.radius + other.radius); } case 2: return IsWithinRadius(SegmentBoxDistanceSquared(start, end, other), capsule.radius); default: return false; } } private static bool BoxOverlaps(ColliderData box, ColliderData other) { //IL_0002: 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_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected I4, but got Unknown //IL_001e: 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_0024: 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_0036: 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_0041: 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_0048: 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_0055: Unknown result type (might be due to invalid IL or missing references) EColliderShape shape = ((ColliderData)(ref other)).shape; switch (shape - 1) { case 0: return IsWithinRadius(PointBoxDistanceSquared(other.pos, box), other.radius); case 1: { GetCapsuleSegment(other, out var start, out var end); return IsWithinRadius(SegmentBoxDistanceSquared(start, end, box), other.radius); } case 2: return BoxesOverlap(box, other); default: return false; } } private static bool IsWithinRadius(float distanceSquared, float combinedRadius) { float num = combinedRadius - 0.001f; if (num > 0f) { return distanceSquared < num * num; } return false; } private static void GetCapsuleSegment(ColliderData capsule, out Vector3 start, out Vector3 end) { //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_0006: 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_000c: 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_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_002c: 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) Vector3 val = capsule.q * capsule.ext; start = capsule.pos - val; end = capsule.pos + val; } private static float PointSegmentDistanceSquared(Vector3 point, Vector3 start, Vector3 end) { //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_0002: 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_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0029: 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_003d: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //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_0050: 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_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) Vector3 val = end - start; float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude; Vector3 val2; if (sqrMagnitude <= 1E-12f) { val2 = point - start; return ((Vector3)(ref val2)).sqrMagnitude; } float num = Mathf.Clamp01(Vector3.Dot(point - start, val) / sqrMagnitude); val2 = point - (start + val * num); return ((Vector3)(ref val2)).sqrMagnitude; } private static float PointBoxDistanceSquared(Vector3 point, ColliderData box) { //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_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_000c: 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_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_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) return PointAabbDistanceSquared(Inverse(box.q) * (point - box.pos), Absolute(box.ext)); } private static float SegmentBoxDistanceSquared(Vector3 start, Vector3 end, ColliderData box) { //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_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_000c: 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_000e: 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_001e: 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_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_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_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_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) Quaternion val = Inverse(box.q); Vector3 start2 = val * (start - box.pos); Vector3 end2 = val * (end - box.pos); return SegmentAabbDistanceSquared(start2, end2, Absolute(box.ext)); } private static float PointAabbDistanceSquared(Vector3 point, Vector3 extents) { //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_001c: 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_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) float num = Mathf.Max(Mathf.Abs(point.x) - extents.x, 0f); float num2 = Mathf.Max(Mathf.Abs(point.y) - extents.y, 0f); float num3 = Mathf.Max(Mathf.Abs(point.z) - extents.z, 0f); return num * num + num2 * num2 + num3 * num3; } private static float SegmentAabbDistanceSquared(Vector3 start, Vector3 end, Vector3 extents) { //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_0002: 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_0029: 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_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0049: 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_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0063: 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_008e: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0094: 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_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0122: 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_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) Vector3 val = end - start; float[] array = new float[8]; int count = 0; array[count++] = 0f; array[count++] = 1f; AddBreakpoints(start.x, val.x, extents.x, array, ref count); AddBreakpoints(start.y, val.y, extents.y, array, ref count); AddBreakpoints(start.z, val.z, extents.z, array, ref count); Array.Sort(array, 0, count); float num = float.MaxValue; for (int i = 0; i < count; i++) { num = Mathf.Min(num, EvaluateSegmentPoint(start, val, array[i], extents)); if (i != count - 1 && !(array[i + 1] - array[i] <= 1E-07f)) { float num2 = array[i]; float num3 = array[i + 1]; float midpoint = (num2 + num3) * 0.5f; float quadratic = 0f; float linear = 0f; AccumulateDistanceTerm(start.x, val.x, extents.x, midpoint, ref quadratic, ref linear); AccumulateDistanceTerm(start.y, val.y, extents.y, midpoint, ref quadratic, ref linear); AccumulateDistanceTerm(start.z, val.z, extents.z, midpoint, ref quadratic, ref linear); if (quadratic > 1E-12f) { float amount = Mathf.Clamp((0f - linear) / (2f * quadratic), num2, num3); num = Mathf.Min(num, EvaluateSegmentPoint(start, val, amount, extents)); } } } return num; } private static void AddBreakpoints(float start, float direction, float extent, float[] breakpoints, ref int count) { if (!(Mathf.Abs(direction) <= 1E-12f)) { AddBreakpoint((0f - extent - start) / direction, breakpoints, ref count); AddBreakpoint((extent - start) / direction, breakpoints, ref count); } } private static void AddBreakpoint(float value, float[] breakpoints, ref int count) { if (value > 0f && value < 1f) { breakpoints[count++] = value; } } private static void AccumulateDistanceTerm(float start, float direction, float extent, float midpoint, ref float quadratic, ref float linear) { float num = start + direction * midpoint; float num2; if (num < 0f - extent) { num2 = 0f - extent; } else { if (!(num > extent)) { return; } num2 = extent; } quadratic += direction * direction; linear += 2f * direction * (start - num2); } private static float EvaluateSegmentPoint(Vector3 start, Vector3 direction, float amount, Vector3 extents) { //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) return PointAabbDistanceSquared(start + direction * amount, extents); } private static float SegmentSegmentDistanceSquared(Vector3 firstStart, Vector3 firstEnd, Vector3 secondStart, Vector3 secondEnd) { //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_0002: 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_0008: 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_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0010: 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_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0018: 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_0020: 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_0029: 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_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003b: 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_0060: 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_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0073: 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_018c: 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_0190: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) Vector3 val = firstEnd - firstStart; Vector3 val2 = secondEnd - secondStart; Vector3 val3 = firstStart - secondStart; float num = Vector3.Dot(val, val); float num2 = Vector3.Dot(val, val2); float num3 = Vector3.Dot(val2, val2); float num4 = Vector3.Dot(val, val3); float num5 = Vector3.Dot(val2, val3); float num6 = num * num3 - num2 * num2; float num7 = num6; float num8 = num6; if (num <= 1E-12f) { return PointSegmentDistanceSquared(firstStart, secondStart, secondEnd); } if (num3 <= 1E-12f) { return PointSegmentDistanceSquared(secondStart, firstStart, firstEnd); } float num9; float num10; if (num6 < 1E-12f) { num9 = 0f; num7 = 1f; num10 = num5; num8 = num3; } else { num9 = num2 * num5 - num3 * num4; num10 = num * num5 - num2 * num4; if (num9 < 0f) { num9 = 0f; num10 = num5; num8 = num3; } else if (num9 > num7) { num9 = num7; num10 = num5 + num2; num8 = num3; } } if (num10 < 0f) { num10 = 0f; if (0f - num4 < 0f) { num9 = 0f; } else if (0f - num4 > num) { num9 = num7; } else { num9 = 0f - num4; num7 = num; } } else if (num10 > num8) { num10 = num8; if (num2 - num4 < 0f) { num9 = 0f; } else if (num2 - num4 > num) { num9 = num7; } else { num9 = num2 - num4; num7 = num; } } float num11 = ((Mathf.Abs(num9) < 1E-12f) ? 0f : (num9 / num7)); float num12 = ((Mathf.Abs(num10) < 1E-12f) ? 0f : (num10 / num8)); Vector3 val4 = val3 + val * num11 - val2 * num12; return ((Vector3)(ref val4)).sqrMagnitude; } private static bool BoxesOverlap(ColliderData first, ColliderData second) { //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_000c: 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_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_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0098: 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_00a5: 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_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: 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_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0073: 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_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: 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_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_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) Vector3[] boxAxes = GetBoxAxes(first.q); Vector3[] boxAxes2 = GetBoxAxes(second.q); Vector3[] array = (Vector3[])(object)new Vector3[15]; int num = 0; for (int i = 0; i < 3; i++) { array[num++] = boxAxes[i]; array[num++] = boxAxes2[i]; } for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { array[num++] = Vector3.Cross(boxAxes[j], boxAxes2[k]); } } Vector3 extents = Absolute(first.ext); Vector3 extents2 = Absolute(second.ext); Vector3 val = second.pos - first.pos; for (int l = 0; l < num; l++) { Vector3 val2 = array[l]; float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude; if (!(sqrMagnitude <= 1E-10f)) { val2 /= Mathf.Sqrt(sqrMagnitude); float num2 = ProjectBox(boxAxes, extents, val2); float num3 = ProjectBox(boxAxes2, extents2, val2); if (Mathf.Abs(Vector3.Dot(val, val2)) >= num2 + num3 - 0.001f) { return false; } } } return true; } private static Vector3[] GetBoxAxes(Quaternion rotation) { //IL_0008: 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_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: 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_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: 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_003c: 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_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) Vector3[] array = new Vector3[3]; Vector3 val = rotation * Vector3.right; array[0] = ((Vector3)(ref val)).normalized; val = rotation * Vector3.up; array[1] = ((Vector3)(ref val)).normalized; val = rotation * Vector3.forward; array[2] = ((Vector3)(ref val)).normalized; return (Vector3[])(object)array; } private static float ProjectBox(Vector3[] axes, Vector3 extents, Vector3 testAxis) { //IL_0000: 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_0019: 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_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) return extents.x * Mathf.Abs(Vector3.Dot(axes[0], testAxis)) + extents.y * Mathf.Abs(Vector3.Dot(axes[1], testAxis)) + extents.z * Mathf.Abs(Vector3.Dot(axes[2], testAxis)); } private static Vector3 Absolute(Vector3 value) { //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_0016: 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) return new Vector3(Mathf.Abs(value.x), Mathf.Abs(value.y), Mathf.Abs(value.z)); } private static Quaternion Inverse(Quaternion rotation) { //IL_0000: 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_000d: 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_001b: 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_0029: 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_004e: 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_0060: 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_0071: 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) float num = rotation.x * rotation.x + rotation.y * rotation.y + rotation.z * rotation.z + rotation.w * rotation.w; if (num <= 1E-12f) { return Quaternion.identity; } float num2 = 1f / num; return new Quaternion((0f - rotation.x) * num2, (0f - rotation.y) * num2, (0f - rotation.z) * num2, rotation.w * num2); } } } namespace DSPVegetationScale { internal static class EmbeddedBuildingVegetationPatch { private sealed class BuildCollisionContext { internal readonly PlanetFactory Factory; private readonly ColliderData[] buildingColliders; private readonly Vector3 center; private readonly float searchRadius; internal BuildCollisionContext(PlanetFactory factory, ColliderData[] colliders) { //IL_0021: 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_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) Factory = factory; buildingColliders = colliders; center = ((colliders.Length != 0) ? GetCenter(colliders) : Vector3.zero); searchRadius = GetSearchRadius(colliders, center); } internal void RemoveOverlappingVegetation(bool emitEffects, int[] candidateIds) { //IL_0020: 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) if (buildingColliders.Length == 0) { return; } int vegetablesInAreaNonAlloc = Factory.planet.physics.nearColliderLogic.GetVegetablesInAreaNonAlloc(center, searchRadius, candidateIds); for (int i = 0; i < vegetablesInAreaNonAlloc; i++) { int num = candidateIds[i]; if (OverlapsVegetation(num)) { EmitRemovalEffects(emitEffects, Factory.vegePool[num]); Factory.RemoveVegeWithComponents(num); } } } private bool OverlapsVegetation(int vegetationId) { //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_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0095: 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_00a0: 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_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: 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_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: 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_00c8: 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) if (vegetationId <= 0 || vegetationId >= Factory.vegePool.Length || Factory.vegePool[vegetationId].id != vegetationId || Factory.vegePool[vegetationId].protoId >= 9999) { return false; } VegeData val = Factory.vegePool[vegetationId]; ColliderData[] array = ((ProtoSet<VegeProto>)(object)LDB.veges).Select((int)val.protoId)?.prefabDesc?.colliders; if (array != null) { for (int i = 0; i < array.Length; i++) { ColliderData val2 = array[i]; if (val2.idType != 0 && (int)((ColliderData)(ref val2)).usage == 0) { ColliderData bound = ((ColliderData)(ref val2)).BindToObject(vegetationId, 0, (EObjectType)1, val.pos, val.rot, val.scl); VegetationColliderGeometry.CorrectScaledRadius(bound, val.scl, ref bound); if (OverlapsAnyBuilding(bound)) { return true; } } } } return false; } private bool OverlapsAnyBuilding(ColliderData vegetationCollider) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i < buildingColliders.Length; i++) { if (ColliderIntersection.Overlaps(buildingColliders[i], vegetationCollider)) { return true; } } return false; } private void EmitRemovalEffects(bool emitEffects, VegeData vegetation) { //IL_002a: 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_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_0047: 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) if (emitEffects && GameMain.gameTick > 0 && Factory.gameData.localLoadedPlanetFactory == Factory) { VegeProto val = ((ProtoSet<VegeProto>)(object)LDB.veges).Select((int)vegetation.protoId); if (val != null) { VFEffectEmitter.Emit(val.MiningEffect, vegetation.pos, vegetation.rot); VFAudio.Create(val.MiningAudio, (Transform)null, vegetation.pos, true, 1, -1, -1L); } } } private static Vector3 GetCenter(ColliderData[] colliders) { //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_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: 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_002c: Unknown result type (might be due to invalid IL or missing references) Vector3 val = Vector3.zero; for (int i = 0; i < colliders.Length; i++) { val += colliders[i].pos; } return val / (float)colliders.Length; } private static float GetSearchRadius(ColliderData[] colliders, Vector3 origin) { //IL_000c: 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_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Invalid comparison between Unknown and I4 //IL_0031: 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_0039: 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_003b: Unknown result type (might be due to invalid IL or missing references) float num = 0.1f; for (int i = 0; i < colliders.Length; i++) { ColliderData val = colliders[i]; float num2 = (((int)((ColliderData)(ref val)).shape == 1) ? val.radius : (((Vector3)(ref val.ext)).magnitude + val.radius)); num = Mathf.Max(num, Vector3.Distance(origin, val.pos) + num2); } return num + 15f; } } [ThreadStatic] private static BuildCollisionContext pendingBuild; [ThreadStatic] private static int[] candidateVegetationIds; internal static void Apply(Harmony harmony) { MethodInfo methodInfo = RequireMethod(typeof(PlanetFactory), "BuildFinally", new Type[4] { typeof(Player), typeof(int), typeof(bool), typeof(bool) }); MethodInfo methodInfo2 = RequireMethod(typeof(PlanetFactory), "FlattenTerrain", new Type[10] { typeof(Vector3), typeof(Quaternion), typeof(Bounds), typeof(float), typeof(float), typeof(bool), typeof(bool), typeof(bool), typeof(bool), typeof(Bounds) }); harmony.Patch((MethodBase)methodInfo, PatchMethod("BeforeBuildFinally"), (HarmonyMethod)null, (HarmonyMethod)null, PatchMethod("AfterBuildFinally"), (HarmonyMethod)null); harmony.Patch((MethodBase)methodInfo2, PatchMethod("BeforeFlattenTerrain"), PatchMethod("AfterFlattenTerrain"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } private static HarmonyMethod PatchMethod(string name) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown return new HarmonyMethod(AccessTools.Method(typeof(EmbeddedBuildingVegetationPatch), name, (Type[])null, (Type[])null)); } private static MethodInfo RequireMethod(Type type, string name, Type[] parameters) { MethodInfo methodInfo = AccessTools.Method(type, name, parameters, (Type[])null); if (methodInfo == null) { throw new MissingMethodException(type.FullName, name); } return methodInfo; } private static void BeforeBuildFinally(PlanetFactory __instance, int prebuildId, bool flattenTerrain, out BuildCollisionContext __state) { __state = pendingBuild; pendingBuild = (flattenTerrain ? CreateBuildContext(__instance, prebuildId) : null); } private static Exception AfterBuildFinally(Exception __exception, BuildCollisionContext __state) { pendingBuild = __state; return __exception; } private static void BeforeFlattenTerrain(PlanetFactory __instance, ref Bounds removeVegeBound, out BuildCollisionContext __state) { //IL_0032: 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_0050: Unknown result type (might be due to invalid IL or missing references) __state = ((pendingBuild != null && pendingBuild.Factory == __instance) ? pendingBuild : null); if (__state != null) { removeVegeBound = new Bounds(new Vector3(1000000f, 1000000f, 1000000f), new Vector3(0.002f, 0.002f, 0.002f)); } } private static void AfterFlattenTerrain(bool emitEffects, BuildCollisionContext __state) { __state?.RemoveOverlappingVegetation(emitEffects, GetCandidateBuffer()); } private static int[] GetCandidateBuffer() { if (candidateVegetationIds == null) { candidateVegetationIds = new int[16384]; } return candidateVegetationIds; } private static BuildCollisionContext CreateBuildContext(PlanetFactory factory, int prebuildId) { //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_001e: 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_004f: 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_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: 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_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_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) if (prebuildId <= 0 || prebuildId >= factory.prebuildPool.Length) { return null; } PrebuildData val = factory.prebuildPool[prebuildId]; if (val.id != prebuildId) { return null; } PrefabDesc val2 = LDB.models.modelArray[val.modelIndex]?.prefabDesc ?? ((ProtoSet<ItemProto>)(object)LDB.items).Select((int)val.protoId)?.prefabDesc; if (val2?.colliders == null) { return new BuildCollisionContext(factory, (ColliderData[])(object)new ColliderData[0]); } List<ColliderData> list = new List<ColliderData>(val2.colliders.Length); for (int i = 0; i < val2.colliders.Length; i++) { ColliderData val3 = val2.colliders[i]; if (val3.idType != 0 && (int)((ColliderData)(ref val3)).usage == 0) { list.Add(val2.isInserter ? BindInserterCollider(val3, val) : ((ColliderData)(ref val3)).BindToObject(0, 0, (EObjectType)0, val.pos, val.rot)); } } return new BuildCollisionContext(factory, list.ToArray()); } private static ColliderData BindInserterCollider(ColliderData source, PrebuildData prebuild) { //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_0006: 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_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0017: 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_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: 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_003c: 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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_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_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: 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_006a: 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_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: 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_008c: 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_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) Vector3 val = Vector3.Lerp(prebuild.pos, prebuild.pos2, 0.5f); Vector3 val2 = prebuild.rot * Vector3.up + prebuild.rot2 * Vector3.up; Vector3 normalized = ((Vector3)(ref val2)).normalized; Quaternion val3 = Quaternion.LookRotation(prebuild.pos2 - prebuild.pos, normalized); source.ext = new Vector3(source.ext.x, source.ext.y, Vector3.Distance(prebuild.pos2, prebuild.pos) * 0.5f + source.ext.z); return ((ColliderData)(ref source)).BindToObject(0, 0, (EObjectType)0, val, val3); } } internal static class EmbeddedPreservationPatches { internal const string StandalonePluginGuid = "Zincon.DSPPreserveVegetation"; [ThreadStatic] private static bool reducingPlayerCollisionDamage; internal static void Apply(Harmony harmony) { //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Expected O, but got Unknown //IL_0140: Expected O, but got Unknown //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Expected O, but got Unknown Type type = AccessTools.TypeByName("UnityEngine.Collision"); if (type == null) { throw new TypeLoadException("UnityEngine.Collision was not found."); } MethodInfo methodInfo = AccessTools.Method(typeof(PlayerController), "HandleCollision", new Type[2] { type, typeof(bool) }, (Type[])null); if (methodInfo == null || methodInfo.ReturnType != typeof(void) || !methodInfo.IsPrivate) { throw new MissingMethodException("PlayerController.HandleCollision(UnityEngine.Collision, bool) has changed."); } MethodInfo methodInfo2 = AccessTools.Method(typeof(SkillSystem), "DamageGroundObjectByLocalCaster", new Type[5] { typeof(PlanetFactory), typeof(int), typeof(int), typeof(SkillTargetLocal).MakeByRefType(), typeof(SkillTargetLocal).MakeByRefType() }, (Type[])null); if (methodInfo2 == null) { throw new MissingMethodException("SkillSystem.DamageGroundObjectByLocalCaster signature has changed."); } harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(EmbeddedPreservationPatches), "BeforePlayerCollision", (Type[])null) { priority = 800 }, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(EmbeddedPreservationPatches), "AfterPlayerCollision", (Type[])null) { priority = 0 }, (HarmonyMethod)null); harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(EmbeddedPreservationPatches), "ReducePlayerCollisionDamage", (Type[])null) { priority = 0 }, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); EmbeddedBuildingVegetationPatch.Apply(harmony); } private static void BeforePlayerCollision(out bool __state) { __state = reducingPlayerCollisionDamage; reducingPlayerCollisionDamage = true; } private static Exception AfterPlayerCollision(Exception __exception, bool __state) { reducingPlayerCollisionDamage = __state; return __exception; } private static void ReducePlayerCollisionDamage([HarmonyArgument(1)] ref int damage) { if (reducingPlayerCollisionDamage) { float playerCollisionDamageMultiplier = ModConfig.PlayerCollisionDamageMultiplier; damage = ((!(playerCollisionDamageMultiplier <= 0f)) ? Math.Max(1, (int)Math.Ceiling((float)damage * playerCollisionDamageMultiplier)) : 0); } } } internal static class ExistingVegetationMigration { private const string RegistrySection = "0 - General / 常规"; private const string RegistryKey = "Migrated planet factories / 已迁移星球工厂"; private const string GiantRegistryPrefix = "G:"; private const string GiantFifteenRegistryPrefix = "G15:"; private static readonly object RegistryLock = new object(); private static readonly HashSet<string> MigratedPlanets = new HashSet<string>(StringComparer.Ordinal); private static DistributionSettings settings; private static ConfigEntry<string> registry; internal static void Apply(Harmony harmony, DistributionSettings distributionSettings, ConfigFile config) { //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Expected O, but got Unknown settings = distributionSettings ?? throw new ArgumentNullException("distributionSettings"); registry = config.Bind<string>("0 - General / 常规", "Migrated planet factories / 已迁移星球工厂", string.Empty, "Tracks one-time existing-save vegetation migration. Do not edit. / 记录旧存档植被的一次性迁移,请勿修改。"); LoadRegistry(registry.Value); MethodInfo methodInfo = AccessTools.Method(typeof(PlanetFactory), "Init", new Type[3] { typeof(GameData), typeof(PlanetData), typeof(int) }, (Type[])null); MethodInfo methodInfo2 = AccessTools.Method(typeof(PlanetFactory), "Import", new Type[4] { typeof(int), typeof(GameData), typeof(Stream), typeof(BinaryReader) }, (Type[])null); if (methodInfo == null || methodInfo2 == null) { throw new MissingMethodException("PlanetFactory.Init/Import signature has changed."); } HarmonyMethod val = new HarmonyMethod(typeof(ExistingVegetationMigration), "MigrateFactoryPostfix", (Type[])null); harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } private static void MigrateFactoryPostfix(PlanetFactory __instance) { //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) PlanetData val = ((__instance != null) ? __instance.planet : null); if (val == null || __instance.vegePool == null || __instance.vegeCursor <= 1 || settings == null) { return; } string text = CreatePlanetKey(val); string key = "G:" + text; string key2 = "G15:" + text; bool flag = IsMigrated(text); bool flag2 = IsMigrated(key); bool flag3 = IsMigrated(key2); bool flag4 = GiantVegetationApplicator.WasProcessed(val); if (flag && flag2 && flag3) { return; } if (!flag) { if (!flag4 && !AppearsAlreadyScaled(__instance)) { PlanetVegetationProfile profile = VegetationDistribution.CreateProfile(val.seed, val.id, settings); for (int i = 1; i < __instance.vegeCursor; i++) { ref VegeData reference = ref __instance.vegePool[i]; if (reference.id == i) { uint plantKey = VegetationDistribution.CreatePlantKey(val.seed, val.id, i, reference.protoId, reference.pos.x, reference.pos.y, reference.pos.z); ref Vector3 scl = ref reference.scl; scl *= VegetationDistribution.SampleMultiplier(profile, plantKey); } } } MarkMigrated(text); } if (!flag2) { GiantVegetationApplicator.Apply(val, __instance.vegePool, __instance.vegeCursor, settings); MarkMigrated(key); MarkMigrated(key2); } else if (!flag3) { if (ModConfig.UpgradeLegacyGiantVegetation && !flag4) { GiantVegetationApplicator.UpgradeLegacyMultipliers(val, __instance.vegePool, __instance.vegeCursor, settings); } MarkMigrated(key2); } } private static bool AppearsAlreadyScaled(PlanetFactory factory) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_002e: 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_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) int num = 0; int num2 = 0; int num3 = Math.Max(1, (factory.vegeCursor - 1) / 512); for (int i = 1; i < factory.vegeCursor; i += num3) { VegeData val = factory.vegePool[i]; if (val.id != i) { continue; } VegeProto val2 = ((ProtoSet<VegeProto>)(object)LDB.veges).Select((int)val.protoId); if (val2 != null) { Vector4 scaleRange = val2.ScaleRange; float num4 = Math.Max(0.1f, 1f + scaleRange.y); float num5 = num4 * Math.Max(0.1f, 1f + scaleRange.w); num++; if (Mathf.Abs(val.scl.y) > num4 * 1.15f || Mathf.Abs(val.scl.x) > num5 * 1.15f || Mathf.Abs(val.scl.z) > num5 * 1.15f) { num2++; } } } if (num > 0) { if (num2 < 8) { return num2 * 4 >= num; } return true; } return false; } private static string CreatePlanetKey(PlanetData planet) { string text = planet.id.ToString(CultureInfo.InvariantCulture); uint seed = (uint)planet.seed; return text + ":" + seed.ToString("X8", CultureInfo.InvariantCulture); } private static void LoadRegistry(string serialized) { lock (RegistryLock) { MigratedPlanets.Clear(); if (!string.IsNullOrWhiteSpace(serialized)) { string[] array = serialized.Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < array.Length; i++) { MigratedPlanets.Add(array[i]); } } } } private static void MarkMigrated(string key) { lock (RegistryLock) { if (MigratedPlanets.Add(key)) { registry.Value = string.Join(";", MigratedPlanets); } } } private static bool IsMigrated(string key) { lock (RegistryLock) { return MigratedPlanets.Contains(key); } } } internal static class GiantVegetationApplicator { private static readonly object ProcessedPlanetsLock = new object(); private static readonly HashSet<PlanetData> ProcessedPlanets = new HashSet<PlanetData>(); internal static int Apply(PlanetData planet, VegeData[] vegetationPool, int vegetationCursor, DistributionSettings settings) { if (planet == null || settings == null) { return 0; } lock (ProcessedPlanetsLock) { if (ProcessedPlanets.Contains(planet)) { return 0; } int result = ApplyCore(planet, vegetationPool, vegetationCursor, settings, replaceNormalDistributionMultiplier: true); ProcessedPlanets.Add(planet); return result; } } internal static int UpgradeLegacyMultipliers(PlanetData planet, VegeData[] vegetationPool, int vegetationCursor, DistributionSettings settings) { if (planet == null || settings == null) { return 0; } lock (ProcessedPlanetsLock) { if (ProcessedPlanets.Contains(planet)) { return 0; } int result = ApplyCore(planet, vegetationPool, vegetationCursor, settings, replaceNormalDistributionMultiplier: false); ProcessedPlanets.Add(planet); return result; } } internal static bool WasProcessed(PlanetData planet) { if (planet == null) { return false; } lock (ProcessedPlanetsLock) { return ProcessedPlanets.Contains(planet); } } private static int ApplyCore(PlanetData planet, VegeData[] vegetationPool, int vegetationCursor, DistributionSettings settings, bool replaceNormalDistributionMultiplier) { //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_0086: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: 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_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: 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_00c3: Unknown result type (might be due to invalid IL or missing references) if (vegetationPool == null || vegetationPool.Length <= 1 || vegetationCursor <= 1 || settings.GiantMaximumCount <= 0 || !VegetationDistribution.ShouldGenerateGiantVegetation(planet.seed, planet.id, settings)) { return 0; } int giantVegetationCount = VegetationDistribution.GetGiantVegetationCount(planet.seed, planet.id, settings); if (giantVegetationCount <= 0) { return 0; } giantVegetationCount = Math.Min(giantVegetationCount, vegetationPool.Length - 1); int[] array = new int[giantVegetationCount]; uint[] array2 = new uint[giantVegetationCount]; uint[] array3 = new uint[giantVegetationCount]; int num = 0; int num2 = Math.Min(vegetationCursor, vegetationPool.Length); for (int i = 1; i < num2; i++) { VegeData val = vegetationPool[i]; if (val.id != i) { continue; } uint num3 = VegetationDistribution.CreatePlantKey(planet.seed, planet.id, i, val.protoId, val.pos.x, val.pos.y, val.pos.z); uint giantSelectionScore = VegetationDistribution.GetGiantSelectionScore(num3); if (num < giantVegetationCount) { array[num] = i; array2[num] = num3; array3[num] = giantSelectionScore; num++; continue; } int num4 = FindWorstCandidate(array, array3, num); if (IsBetterCandidate(giantSelectionScore, i, array3[num4], array[num4])) { array[num4] = i; array2[num4] = num3; array3[num4] = giantSelectionScore; } } PlanetVegetationProfile profile = (replaceNormalDistributionMultiplier ? VegetationDistribution.CreateProfile(planet.seed, planet.id, settings) : default(PlanetVegetationProfile)); for (int j = 0; j < num; j++) { ref VegeData reference = ref vegetationPool[array[j]]; float num5 = (replaceNormalDistributionMultiplier ? VegetationDistribution.SampleMultiplier(profile, array2[j]) : VegetationDistribution.SampleGiantMultiplier(array2[j], 5f, 7f)); float num6 = VegetationDistribution.SampleGiantMultiplier(array2[j], settings) / num5; reference.scl.x *= num6; reference.scl.y *= num6; reference.scl.z *= num6; } return num; } private static int FindWorstCandidate(int[] ids, uint[] scores, int count) { int num = 0; for (int i = 1; i < count; i++) { if (scores[i] > scores[num] || (scores[i] == scores[num] && ids[i] > ids[num])) { num = i; } } return num; } private static bool IsBetterCandidate(uint score, int vegetationId, uint existingScore, int existingVegetationId) { if (score >= existingScore) { if (score == existingScore) { return vegetationId < existingVegetationId; } return false; } return true; } } internal static class ModConfig { private const string GeneralSection = "0 - General / 常规"; private const string ConfigVersionKey = "Config schema version / 配置版本"; private const int CurrentConfigVersion = 2; internal static bool UpgradeLegacyGiantVegetation { get; private set; } internal static bool DisablePlayerVegetationCollision { get; private set; } internal static float MaximumPlayerColliderScale { get; private set; } = 1.5f; internal static float PlayerCollisionDamageMultiplier { get; private set; } = 0.1f; internal static DistributionSettings Bind(ConfigFile config) { //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Expected O, but got Unknown //IL_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_01bb: Expected O, but got Unknown //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Expected O, but got Unknown //IL_026b: Unknown result type (might be due to invalid IL or missing references) //IL_0275: Expected O, but got Unknown //IL_02a8: Unknown result type (might be due to invalid IL or missing references) //IL_02b2: Expected O, but got Unknown UpgradeLegacyGiantVegetation = false; ConfigEntry<int> val = config.Bind<int>("0 - General / 常规", "Config schema version / 配置版本", 0, "Used for automatic configuration migration. Do not edit. / 用于自动迁移配置,请勿修改。"); AcceptableValueRange<float> range = new AcceptableValueRange<float>(1f, 7f); AcceptableValueRange<float> range2 = new AcceptableValueRange<float>(1f, 15f); ConfigEntry<float> val2 = BindPeak(config, "1 - Super-large / 超大型", "Peak multiplier minimum / 波峰倍数下限", 3.5f, "Each super-large planet selects one peak at 0.1x precision from this inclusive range. / 每个超大型星球会从此闭区间按 0.1 倍精度随机选取一个波峰。", range); ConfigEntry<float> val3 = BindPeak(config, "1 - Super-large / 超大型", "Peak multiplier maximum / 波峰倍数上限", 5f, "The upper endpoint for super-large planet peaks. / 超大型星球波峰倍数的上限。", range); ConfigEntry<float> val4 = BindPeak(config, "2 - Large / 大型", "Peak multiplier minimum / 波峰倍数下限", 2.5f, "Each large planet selects one peak at 0.1x precision from this inclusive range. / 每个大型星球会从此闭区间按 0.1 倍精度随机选取一个波峰。", range); ConfigEntry<float> val5 = BindPeak(config, "2 - Large / 大型", "Peak multiplier maximum / 波峰倍数上限", 3.5f, "The upper endpoint for large planet peaks. / 大型星球波峰倍数的上限。", range); ConfigEntry<float> val6 = BindPeak(config, "3 - Triple peak / 三峰型", "Small peak minimum / 小型峰下限", 1f, "Inclusive range used to choose the smallest peak. / 用于选取最小波峰的闭区间。", range); ConfigEntry<float> val7 = BindPeak(config, "3 - Triple peak / 三峰型", "Small peak maximum / 小型峰上限", 1.5f, "Inclusive range used to choose the smallest peak. / 用于选取最小波峰的闭区间。", range); ConfigEntry<float> val8 = BindPeak(config, "3 - Triple peak / 三峰型", "Medium peak minimum / 中型峰下限", 2.5f, "Inclusive range used to choose the middle peak. / 用于选取中间波峰的闭区间。", range); ConfigEntry<float> val9 = BindPeak(config, "3 - Triple peak / 三峰型", "Medium peak maximum / 中型峰上限", 3.5f, "Inclusive range used to choose the middle peak. / 用于选取中间波峰的闭区间。", range); ConfigEntry<float> val10 = BindPeak(config, "3 - Triple peak / 三峰型", "Large peak minimum / 大型峰下限", 4.75f, "Inclusive range used to choose the largest peak. / 用于选取最大波峰的闭区间。", range); ConfigEntry<float> val11 = BindPeak(config, "3 - Triple peak / 三峰型", "Large peak maximum / 大型峰上限", 6f, "Inclusive range used to choose the largest peak. / 用于选取最大波峰的闭区间。", range); ConfigEntry<float> val12 = config.Bind<float>("4 - Giant vegetation / 巨型植被", "Planet chance / 星球概率", 0.5f, new ConfigDescription("Chance that a planet contains a small group of giant vegetation. / 每个星球出现一小群巨型植被的概率。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>())); ConfigEntry<int> val13 = config.Bind<int>("4 - Giant vegetation / 巨型植被", "Minimum count / 最少数量", 5, new ConfigDescription("Minimum number of unique giant plants on a selected planet. / 被选中星球上的巨型植被最少数量。", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())); ConfigEntry<int> val14 = config.Bind<int>("4 - Giant vegetation / 巨型植被", "Maximum count / 最多数量", 15, new ConfigDescription("Maximum number of unique giant plants on a selected planet. / 被选中星球上的巨型植被最多数量。", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())); ConfigEntry<float> val15 = BindGiantMultiplier(config, "4 - Giant vegetation / 巨型植被", "Minimum multiplier / 最小倍数", 8f, "Minimum final multiplier for giant vegetation. / 巨型植被最终倍数下限。", range2); ConfigEntry<float> val16 = BindGiantMultiplier(config, "4 - Giant vegetation / 巨型植被", "Maximum multiplier / 最大倍数", 15f, "Maximum final multiplier for giant vegetation. / 巨型植被最终倍数上限。", range2); DisablePlayerVegetationCollision = config.Bind<bool>("4 - Player collision / 人物碰撞", "Disable physical collision / 关闭物理碰撞", false, "If enabled, vegetation physics colliders are not registered for the player. Building overlap still uses prototype collider geometry. / 启用后不再为人物注册植被物理碰撞;建筑重叠仍使用原型自带碰撞体。").Value; MaximumPlayerColliderScale = config.Bind<float>("4 - Player collision / 人物碰撞", "Maximum collider scale / 碰撞体最大倍数", 1.5f, new ConfigDescription("Caps the physical collider scale while giant vegetation can visually reach 15x. / 限制人物物理碰撞体倍数,巨型植物视觉体积仍可达到 15 倍。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 7f), Array.Empty<object>())).Value; PlayerCollisionDamageMultiplier = config.Bind<float>("4 - Player collision / 人物碰撞", "Vegetation damage multiplier / 植被伤害倍率", 0.1f, new ConfigDescription("Multiplies vegetation damage caused by player collisions. / 人物碰撞对植被造成的伤害倍率。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>())).Value; if (val.Value < 2) { bool saveOnConfigSet = config.SaveOnConfigSet; config.SaveOnConfigSet = false; try { MigrateLegacyRange(val2, val3, 7f, 7f, 3.5f, 5f); MigrateLegacyRange(val4, val5, 5f, 7f, 2.5f, 3.5f); MigrateLegacyRange(val6, val7, 3f, 6f, 1f, 1.5f); MigrateLegacyRange(val8, val9, 7f, 7f, 2.5f, 3.5f); MigrateLegacyRange(val10, val11, 7f, 7f, 4.75f, 6f); UpgradeLegacyGiantVegetation = MigrateLegacyRange(val15, val16, 5f, 7f, 8f, 15f); val.Value = 2; config.Save(); } finally { config.SaveOnConfigSet = saveOnConfigSet; } } return new DistributionSettings(val2.Value, val3.Value, val4.Value, val5.Value, val6.Value, val7.Value, val8.Value, val9.Value, val10.Value, val11.Value, val12.Value, val13.Value, val14.Value, val15.Value, val16.Value); } private static bool MigrateLegacyRange(ConfigEntry<float> minimum, ConfigEntry<float> maximum, float legacyMinimum, float legacyMaximum, float newMinimum, float newMaximum) { if (NearlyEqual(minimum.Value, legacyMinimum) && NearlyEqual(maximum.Value, legacyMaximum)) { minimum.Value = newMinimum; maximum.Value = newMaximum; return true; } return false; } private static bool NearlyEqual(float first, float second) { return Math.Abs(first - second) < 0.0001f; } private static ConfigEntry<float> BindPeak(ConfigFile config, string section, string key, float defaultValue, string description, AcceptableValueRange<float> range) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown return config.Bind<float>(section, key, defaultValue, new ConfigDescription(description + " Values are hard-limited to 1-7. / 所有倍数均强制限制在 1-7。", (AcceptableValueBase)(object)range, Array.Empty<object>())); } private static ConfigEntry<float> BindGiantMultiplier(ConfigFile config, string section, string key, float defaultValue, string description, AcceptableValueRange<float> range) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown return config.Bind<float>(section, key, defaultValue, new ConfigDescription(description + " Values are hard-limited to 1-15. / 巨型植被倍数强制限制在 1-15。", (AcceptableValueBase)(object)range, Array.Empty<object>())); } } internal static class PlanetInfoUiPatches { private sealed class PanelEntries { internal UIResAmountEntry ScaleEntry { get; } internal UIResAmountEntry GiantEntry { get; } internal PanelEntries(UIResAmountEntry scaleEntry, UIResAmountEntry giantEntry) { ScaleEntry = scaleEntry; GiantEntry = giantEntry; } } private const int ScaleEntryMarker = -73001; private const int GiantEntryMarker = -73002; private static MethodInfo getEntryMethod; private static DistributionSettings settings; private static readonly Dictionary<UIPlanetDetail, PanelEntries> AddedEntries = new Dictionary<UIPlanetDetail, PanelEntries>(); internal static void Apply(Harmony harmony, DistributionSettings distributionSettings) { //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_00b7: Expected O, but got Unknown if (harmony == null) { throw new ArgumentNullException("harmony"); } settings = distributionSettings ?? throw new ArgumentNullException("distributionSettings"); MethodInfo methodInfo = AccessTools.Method(typeof(UIPlanetDetail), "SetResCount", new Type[1] { typeof(int) }, (Type[])null); getEntryMethod = AccessTools.Method(typeof(UIPlanetDetail), "GetEntry", Type.EmptyTypes, (Type[])null); if (methodInfo == null || getEntryMethod == null) { throw new MissingMethodException("UIPlanetDetail.SetResCount/GetEntry has changed."); } harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(PlanetInfoUiPatches), "SetResCountPrefix", (Type[])null) { priority = 800 }, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } private static void SetResCountPrefix(UIPlanetDetail __instance, ref int count, UIResAmountEntry ___tipEntry) { PlanetData val = ((__instance != null) ? __instance.planet : null); List<UIResAmountEntry> list = __instance?.entries; if (val == null || list == null || settings == null) { return; } if (AddedEntries.TryGetValue(__instance, out var value) && list.Contains(value.ScaleEntry) && list.Contains(value.GiantEntry) && value.ScaleEntry.refId == -73001 && value.GiantEntry.refId == -73002) { value.ScaleEntry.valueString = GetVegetationScaleText(val, settings); value.GiantEntry.valueString = GetGiantVegetationCount(val, settings).ToString(); return; } if ((Object)(object)___tipEntry != (Object)null) { list.Remove(___tipEntry); } UIResAmountEntry scaleEntry = AddEntry(__instance, list, GetLabel("植物倍数", "Vegetation scale"), GetVegetationScaleText(val, settings), -73001); UIResAmountEntry giantEntry = AddEntry(__instance, list, GetLabel("巨型植被", "Giant vegetation"), GetGiantVegetationCount(val, settings).ToString(), -73002); if ((Object)(object)___tipEntry != (Object)null) { ___tipEntry.SetIndex(list.Count); list.Add(___tipEntry); } AddedEntries[__instance] = new PanelEntries(scaleEntry, giantEntry); count += 2; } private static UIResAmountEntry AddEntry(UIPlanetDetail panel, ICollection<UIResAmountEntry> entries, string label, string value, int marker) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown UIResAmountEntry val = (UIResAmountEntry)getEntryMethod.Invoke(panel, null); val.SetInfo(entries.Count, label, (Sprite)null, string.Empty, false, false, string.Empty); val.valueString = value; val.refId = marker; entries.Add(val); return val; } internal static string GetVegetationScaleText(PlanetData planet, DistributionSettings distributionSettings) { if (!PlanetCanContainVegetation(planet)) { return "0x"; } PlanetVegetationProfile planetVegetationProfile = VegetationDistribution.CreateProfile(planet.seed, planet.id, distributionSettings); if (planetVegetationProfile.Mode == VegetationSizeMode.TriplePeak) { return FormatMultiplier(planetVegetationProfile.FirstPeak) + "/" + FormatMultiplier(planetVegetationProfile.SecondPeak) + "/" + FormatMultiplier(planetVegetationProfile.ThirdPeak) + "x"; } return FormatMultiplier(planetVegetationProfile.FirstPeak) + "x"; } internal static int GetGiantVegetationCount(PlanetData planet, DistributionSettings distributionSettings) { if (!PlanetCanContainVegetation(planet) || !VegetationDistribution.ShouldGenerateGiantVegetation(planet.seed, planet.id, distributionSettings)) { return 0; } int giantVegetationCount = VegetationDistribution.GetGiantVegetationCount(planet.seed, planet.id, distributionSettings); int num = CountLoadedVegetation(planet); if (num < 0) { return giantVegetationCount; } return Math.Min(giantVegetationCount, num); } private static int CountLoadedVegetation(PlanetData planet) { if (planet.factory?.vegePool != null) { return CountValidVegetation(planet.factory.vegePool, planet.factory.vegeCursor); } if (planet.data?.vegePool != null) { return CountValidVegetation(planet.data.vegePool, planet.data.vegeCursor); } return -1; } private static int CountValidVegetation(VegeData[] pool, int cursor) { int num = 0; int num2 = Math.Min(cursor, pool.Length); for (int i = 1; i < num2; i++) { if (pool[i].id == i) { num++; } } return num; } private static bool PlanetCanContainVegetation(PlanetData planet) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Invalid comparison between Unknown and I4 if (planet == null || (int)planet.type == 5) { return false; } int num = CountLoadedVegetation(planet); if (num >= 0) { return num > 0; } ThemeProto val = ((ProtoSet<ThemeProto>)(object)LDB.themes)?.Select(planet.theme); if (val != null && !HasEntries(val.Vegetables0) && !HasEntries(val.Vegetables1) && !HasEntries(val.Vegetables2) && !HasEntries(val.Vegetables3) && !HasEntries(val.Vegetables4)) { return HasEntries(val.Vegetables5); } return true; } private static bool HasEntries(int[] values) { if (values != null) { return values.Length != 0; } return false; } private static string FormatMultiplier(float multiplier) { return multiplier.ToString("0.#"); } private static string GetLabel(string chinese, string english) { if (!Localization.isZHCN) { return english; } return chinese; } } [BepInPlugin("Zincon.DSPVegetationScale", "Giant Plants", "1.5.3")] [BepInProcess("DSPGAME.exe")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInIncompatibility("Zincon.DSPPreserveVegetation")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class Plugin : BaseUnityPlugin { public const string PluginGuid = "Zincon.DSPVegetationScale"; public const string PluginName = "Giant Plants"; public const string PluginVersion = "1.5.3"; private Harmony generationHarmony; private Harmony migrationHarmony; private Harmony colliderHarmony; private Harmony preservationHarmony; private Harmony planetInfoHarmony; private void Awake() { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Expected O, but got Unknown //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Expected O, but got Unknown //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Expected O, but got Unknown //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Expected O, but got Unknown //IL_0256: Unknown result type (might be due to invalid IL or missing references) //IL_0260: Expected O, but got Unknown //IL_01e4: Unknown result type (might be due to invalid IL or missing references) DistributionSettings distributionSettings; try { distributionSettings = ModConfig.Bind(((BaseUnityPlugin)this).Config); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Failed to load vegetation scale configuration.\n" + ex)); return; } try { generationHarmony = new Harmony("Zincon.DSPVegetationScale.Generation"); int num = VegetationGenerationPatches.Apply(generationHarmony, distributionSettings); ((BaseUnityPlugin)this).Logger.LogInfo((object)($"Vegetation scaling enabled for {num} generators; " + "regular vegetation is capped at 7x and giant vegetation at 15x.")); } catch (Exception ex2) { Harmony obj = generationHarmony; if (obj != null) { obj.UnpatchSelf(); } generationHarmony = null; ((BaseUnityPlugin)this).Logger.LogError((object)("Failed to enable vegetation size distributions.\n" + ex2)); } try { migrationHarmony = new Harmony("Zincon.DSPVegetationScale.Migration"); ExistingVegetationMigration.Apply(migrationHarmony, distributionSettings, ((BaseUnityPlugin)this).Config); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Existing-save vegetation migration enabled."); } catch (Exception ex3) { Harmony obj2 = migrationHarmony; if (obj2 != null) { obj2.UnpatchSelf(); } migrationHarmony = null; ((BaseUnityPlugin)this).Logger.LogError((object)("Failed to enable existing-save vegetation migration.\n" + ex3)); } try { colliderHarmony = new Harmony("Zincon.DSPVegetationScale.Colliders"); VegetationColliderPatches.Apply(colliderHarmony); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Relaxed prototype vegetation colliders enabled; player collider scale is capped at " + $"{ModConfig.MaximumPlayerColliderScale:0.##}x.")); } catch (Exception ex4) { Harmony obj3 = colliderHarmony; if (obj3 != null) { obj3.UnpatchSelf(); } colliderHarmony = null; ((BaseUnityPlugin)this).Logger.LogError((object)("Failed to enable scale-aware vegetation colliders.\n" + ex4)); } try { bool num2 = Chainloader.PluginInfos.ContainsKey("Zincon.DSPPreserveVegetation"); preservationHarmony = new Harmony("Zincon.DSPVegetationScale.Preservation"); EmbeddedPreservationPatches.Apply(preservationHarmony); if (num2) { new Harmony("Zincon.DSPPreserveVegetation").UnpatchSelf(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Standalone DSP Preserve Vegetation detected; its patches were replaced by the embedded scale-aware implementation."); } ((BaseUnityPlugin)this).Logger.LogInfo((object)"Embedded vegetation preservation and physical building clearing enabled."); } catch (Exception ex5) { Harmony obj4 = preservationHarmony; if (obj4 != null) { obj4.UnpatchSelf(); } preservationHarmony = null; ((BaseUnityPlugin)this).Logger.LogError((object)("Failed to enable embedded vegetation preservation.\n" + ex5)); } try { planetInfoHarmony = new Harmony("Zincon.DSPVegetationScale.PlanetInfo"); PlanetInfoUiPatches.Apply(planetInfoHarmony, distributionSettings); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Planet information vegetation rows enabled."); } catch (Exception ex6) { Harmony obj5 = planetInfoHarmony; if (obj5 != null) { obj5.UnpatchSelf(); } planetInfoHarmony = null; ((BaseUnityPlugin)this).Logger.LogError((object)("Failed to add vegetation details to the planet information panel.\n" + ex6)); } } private void OnDestroy() { Harmony obj = generationHarmony; if (obj != null) { obj.UnpatchSelf(); } Harmony obj2 = migrationHarmony; if (obj2 != null) { obj2.UnpatchSelf(); } Harmony obj3 = colliderHarmony; if (obj3 != null) { obj3.UnpatchSelf(); } Harmony obj4 = preservationHarmony; if (obj4 != null) { obj4.UnpatchSelf(); } Harmony obj5 = planetInfoHarmony; if (obj5 != null) { obj5.UnpatchSelf(); } generationHarmony = null; migrationHarmony = null; colliderHarmony = null; preservationHarmony = null; planetInfoHarmony = null; } } internal static class VegetationColliderGeometry { internal static void CorrectScaledRadius(ColliderData source, Vector3 scale, ref ColliderData bound) { //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_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_000f: Invalid comparison between Unknown and I4 //IL_001c: 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_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Invalid comparison between Unknown and I4 Vector3 val = Absolute(scale); if ((int)((ColliderData)(ref source)).shape == 1 || (int)((ColliderData)(ref source)).shape == 2) { bound.radius = source.radius * Mathf.Max(val.x, Mathf.Max(val.y, val.z)); } } internal static void LimitPhysicsColliderScale(ColliderData boundBeforeCorrection, Vector3 actualScale, float maximumScale, ref ColliderData collider) { //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_0006: 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_001b: Invalid comparison between Unknown and I4 //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_007a: 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_009a: Invalid comparison between Unknown and I4 //IL_0029: 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_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Invalid comparison between Unknown and I4 //IL_00d0: 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_00cd: Invalid comparison between Unknown and I4 //IL_00ab: 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_00b8: Unknown result type (might be due to invalid IL or missing references) Vector3 val = Absolute(actualScale); maximumScale = Mathf.Max(1f, maximumScale); if ((int)((ColliderData)(ref collider)).shape == 3) { collider.ext = new Vector3(LimitBoundExtent(collider.ext.x, val.x, maximumScale), LimitBoundExtent(collider.ext.y, val.y, maximumScale), LimitBoundExtent(collider.ext.z, val.z, maximumScale)); return; } float num = Mathf.Max(val.x, Mathf.Max(val.y, val.z)); float num2 = Mathf.Min(num, maximumScale); if ((int)((ColliderData)(ref collider)).shape == 2 && num > 1E-06f) { ref Vector3 ext = ref collider.ext; ext *= num2 / num; } if ((int)((ColliderData)(ref collider)).shape == 1 || (int)((ColliderData)(ref collider)).shape == 2) { collider.radius = boundBeforeCorrection.radius * num2; } } private static float LimitBoundExtent(float boundExtent, float actualScale, float maximumScale) { if (!(actualScale > maximumScale) || !(actualScale > 1E-06f)) { return boundExtent; } return boundExtent * maximumScale / actualScale; } private static Vector3 Absolute(Vector3 value) { //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_0016: 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) return new Vector3(Mathf.Abs(value.x), Mathf.Abs(value.y), Mathf.Abs(value.z)); } } internal static class VegetationColliderPatches { internal static void Apply(Harmony harmony) { //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_007b: Expected O, but got Unknown MethodInfo methodInfo = AccessTools.Method(typeof(PlanetPhysics), "AddColliderData", new Type[1] { typeof(ColliderData) }, (Type[])null); if (methodInfo == null || methodInfo.ReturnType != typeof(int)) { throw new MissingMethodException("PlanetPhysics.AddColliderData(ColliderData) has changed."); } harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(VegetationColliderPatches), "PrepareVegetationColliderPrefix", (Type[])null) { priority = 0 }, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } private static bool PrepareVegetationColliderPrefix(PlanetPhysics __instance, [HarmonyArgument(0)] ref ColliderData collider) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Invalid comparison between Unknown and I4 //IL_0082: 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_008c: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) if ((int)((ColliderData)(ref collider)).objType != 1) { return true; } PlanetFactory val = __instance.planet?.factory; int objId = ((ColliderData)(ref collider)).objId; if (val?.vegePool == null || objId <= 0 || objId >= val.vegePool.Length || val.vegePool[objId].id != objId) { return true; } if (ModConfig.DisablePlayerVegetationCollision && (int)((ColliderData)(ref collider)).usage == 0) { collider.idType = (collider.idType & -1610612737) | 0x40000000; return true; } if ((int)((ColliderData)(ref collider)).usage != 0) { return true; } VegetationColliderGeometry.LimitPhysicsColliderScale(collider, val.vegePool[objId].scl, ModConfig.MaximumPlayerColliderScale, ref collider); return true; } } internal enum VegetationSizeMode { SuperLarge, Large, TriplePeak } internal sealed class DistributionSettings { internal const float HardMaximumMultiplier = 7f; internal const float GiantHardMaximumMultiplier = 15f; internal const float LegacyGiantMinimumMultiplier = 5f; internal const float LegacyGiantMaximumMultiplier = 7f; internal const float MinimumPeakSeparation = 1.25f; internal float SuperLargeMinimum { get; } internal float SuperLargeMaximum { get; } internal float LargeMinimum { get; } internal float LargeMaximum { get; } internal float TripleSmallMinimum { get; } internal float TripleSmallMaximum { get; } internal float TripleMediumMinimum { get; } internal float TripleMediumMaximum { get; } internal float TripleLargeMinimum { get; } internal float TripleLargeMaximum { get; } internal float GiantPlanetChance { get; } internal int GiantMinimumCount { get; } internal int GiantMaximumCount { get; } internal float GiantMinimumMultiplier { get; } internal float GiantMaximumMultiplier { get; } internal DistributionSettings(float superLargeMinimum, float superLargeMaximum, float largeMinimum, float largeMaximum, float tripleSmallMinimum, float tripleSmallMaximum, float tripleMediumMinimum, float tripleMediumMaximum, float tripleLargeMinimum, float tripleLargeMaximum, float giantPlanetChance = 0.5f, int giantMinimumCount = 5, int giantMaximumCount = 15, float giantMinimumMultiplier = 8f, float giantMaximumMultiplier = 15f) { NormalizeRange(superLargeMinimum, superLargeMaximum, out var minimum, out var maximum); SuperLargeMinimum = minimum; SuperLargeMaximum = maximum; NormalizeRange(largeMinimum, largeMaximum, out minimum, out maximum); LargeMinimum = minimum; LargeMaximum = maximum; NormalizeRange(tripleSmallMinimum, tripleSmallMaximum, out minimum, out maximum); TripleSmallMinimum = minimum; TripleSmallMaximum = maximum; NormalizeRange(tripleMediumMinimum, tripleMediumMaximum, out minimum, out maximum); TripleMediumMinimum = minimum; TripleMediumMaximum = maximum; NormalizeRange(tripleLargeMinimum, tripleLargeMaximum, out minimum, out maximum); TripleLargeMinimum = minimum; TripleLargeMaximum = maximum; GiantPlanetChance = Clamp(giantPlanetChance, 0f, 1f); giantMinimumCount = Math.Max(0, Math.Min(100, giantMinimumCount)); giantMaximumCount = Math.Max(0, Math.Min(100, giantMaximumCount)); GiantMinimumCount = Math.Min(giantMinimumCount, giantMaximumCount); GiantMaximumCount = Math.Max(giantMinimumCount, giantMaximumCount); NormalizeGiantRange(giantMinimumMultiplier, giantMaximumMultiplier, out minimum, out maximum); GiantMinimumMultiplier = minimum; GiantMaximumMultiplier = maximum; } internal static DistributionSettings CreateDefaults() { return new DistributionSettings(3.5f, 5f, 2.5f, 3.5f, 1f, 1.5f, 2.5f, 3.5f, 4.75f, 6f); } private static void NormalizeRange(float first, float second, out float minimum, out float maximum) { first = Clamp(first, 1f, 7f); second = Clamp(second, 1f, 7f); minimum = Math.Min(first, second); maximum = Math.Max(first, second); } private static void NormalizeGiantRange(float first, float second, out float minimum, out float maximum) { first = Clamp(first, 1f, 15f); second = Clamp(second, 1f, 15f); minimum = Math.Min(first, second); maximum = Math.Max(first, second); } internal static float Clamp(float value, float minimum, float maximum) { return Math.Min(maximum, Math.Max(minimum, value))