using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using GalacticScale;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using NebulaCompatibility;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace GalacticScalePatch
{
public static class GalacticScaleFixes
{
private sealed class TintCache
{
public Cubemap map;
public Color tint;
}
private static volatile bool scanMemoryExhausted;
private static readonly Dictionary<GSTheme, List<Object>> owned = new Dictionary<GSTheme, List<Object>>();
private static readonly ConditionalWeakTable<GSAmbientSettings, TintCache> tints = new ConditionalWeakTable<GSAmbientSettings, TintCache>();
private static readonly List<RaycastResult> hits = new List<RaycastResult>();
public static bool AlreadyFixed()
{
return AccessTools.Method(typeof(Modeler), "CancelPendingScans", (Type[])null, (Type[])null) != null;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(GS2), "ProcessGalaxy")]
private static void LockGeneration(out object __state)
{
__state = PlanetModelingManager.planetProcessingLock;
Monitor.Enter(__state);
Modeler.Reset();
SystemDisplay.inSystemDisplay = false;
SystemDisplay.viewStar = null;
SystemDisplay.systemLabelsHidden = false;
SystemDisplay.altWasDown = false;
}
[HarmonyFinalizer]
[HarmonyPatch(typeof(GS2), "ProcessGalaxy")]
private static Exception UnlockGeneration(object __state, Exception __exception)
{
if (__state != null)
{
Monitor.Exit(__state);
}
return __exception;
}
private static void CancelPendingScans()
{
lock (PlanetModelingManager.scnPlanetReqList)
{
while (PlanetModelingManager.scnPlanetReqList.Count > 0)
{
PlanetModelingManager.scnPlanetReqList.Dequeue().scanning = false;
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Modeler), "Reset")]
private static void AfterReset()
{
scanMemoryExhausted = false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Modeler), "Scan")]
private static bool Scan()
{
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Invalid comparison between Unknown and I4
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
Thread planetScanThread;
lock (PlanetModelingManager.planetProcessingLock)
{
planetScanThread = PlanetModelingManager.planetScanThread;
}
while (true)
{
PlanetData val = null;
lock (PlanetModelingManager.planetProcessingLock)
{
lock (PlanetModelingManager.planetScanThreadFlagLock)
{
if (planetScanThread != PlanetModelingManager.planetScanThread)
{
GS2.Log("End due to planetCalculateThread mismatch", 73);
return false;
}
if ((int)PlanetModelingManager.planetScanThreadFlag != 1)
{
GS2.Log("ThreadFlag: Ending => Ended", 78);
PlanetModelingManager.planetScanThreadFlag = (ThreadFlag)0;
return false;
}
}
if (scanMemoryExhausted)
{
CancelPendingScans();
}
lock (PlanetModelingManager.scnPlanetReqList)
{
if (PlanetModelingManager.scnPlanetReqList.Count > 0)
{
val = PlanetModelingManager.scnPlanetReqList.Dequeue();
}
}
if (val != null && val.loading)
{
val.scanning = false;
val = null;
}
if (val != null)
{
Modeler.processing.Add(val);
bool flag = val.data != null;
bool flag2 = false;
try
{
Modeler.ScanPlanetGS(val);
flag2 = true;
}
catch (Exception ex)
{
lock (PlanetModelingManager.planetScanThreadError)
{
if (string.IsNullOrEmpty(PlanetModelingManager.planetScanThreadError))
{
PlanetModelingManager.planetScanThreadError = ex.ToString();
}
}
if (ex is OutOfMemoryException)
{
scanMemoryExhausted = true;
CancelPendingScans();
}
GS2.Warn($"Error during calculating planet {val.name}: {ex}", 114);
if (val != GameMain.localPlanet && !flag && val.data != null)
{
Modeler.FreeScanData(val);
}
val.scanned = false;
Modeler.processing.Remove(val);
}
finally
{
val.scanning = false;
val.scanned = flag2 && ((Object)(object)UIRoot.instance == (Object)null || !UIRoot.instance.backToMainMenu);
if (Modeler.processing.Contains(val))
{
Modeler.processing.Remove(val);
}
}
}
}
Thread.Sleep((val == null) ? 50 : 2);
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Modeler), "ScanPlanetGS")]
private static bool ScanPlanetGS(PlanetData calcPlanet)
{
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Expected O, but got Unknown
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Expected O, but got Unknown
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Expected O, but got Unknown
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Invalid comparison between Unknown and I4
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0103: Invalid comparison between Unknown and I4
PlanetAlgorithm val = PlanetModelingManager.Algorithm(calcPlanet);
if (val == null)
{
return false;
}
bool flag = calcPlanet.data != null;
GS2.Log("Scanning " + calcPlanet.name + ((val is GS2PlanetAlgorithm) ? " (GS)" : ""), 138);
HighStopwatch val2 = new HighStopwatch();
val2.Begin();
try
{
if (!flag)
{
calcPlanet.data = new PlanetRawData(calcPlanet.precision);
calcPlanet.modData = calcPlanet.data.InitModData(calcPlanet.modData);
calcPlanet.data.CalcVerts();
calcPlanet.aux = new PlanetAuxData(calcPlanet);
}
try
{
val.GenerateTerrain(calcPlanet.mod_x, calcPlanet.mod_y);
}
catch (Exception ex)
{
Modeler.LogTerrainGenerationFailure(calcPlanet, val, ex);
throw;
}
val.CalcWaterPercent();
double duration = val2.duration;
val2.Begin();
calcPlanet.data.vegeCursor = 1;
if ((int)calcPlanet.type != 5)
{
val.GenerateVegetables();
}
double duration2 = val2.duration;
val2.Begin();
calcPlanet.data.veinCursor = 1;
if ((int)calcPlanet.type != 5)
{
val.GenerateVeins();
}
calcPlanet.SummarizeVeinGroups();
calcPlanet.GenBirthPoints();
double duration3 = val2.duration;
if (PlanetModelingManager.planetScanThreadLogs != null)
{
lock (PlanetModelingManager.planetScanThreadLogs)
{
PlanetModelingManager.planetScanThreadLogs.Add($"[Terrain]:{duration:F3}s [Vegetables]:{duration2:F3}s [Veins]:{duration3:F3}s Planet: {calcPlanet.displayName}");
}
}
}
finally
{
if (calcPlanet != GameMain.localPlanet && !flag && calcPlanet.data != null)
{
calcPlanet.data.Free();
calcPlanet.data = null;
if (calcPlanet.aux != null)
{
calcPlanet.aux.Free();
calcPlanet.aux = null;
}
}
}
GS2.Log("Finished calculating planet " + calcPlanet.name, 193);
calcPlanet.NotifyScanEnded();
return false;
}
public static T Own<T>(T resource, GSTheme theme) where T : Object
{
if (resource != null && theme != null)
{
if (!owned.TryGetValue(theme, out var value))
{
value = (owned[theme] = new List<Object>());
}
value.Add((Object)(object)resource);
}
return resource;
}
public static T Share<T>(T resource) where T : Object
{
return resource;
}
public static Cubemap CachedTint(Cubemap map, Color tint, GSAmbientSettings settings, GSTheme theme)
{
//IL_002a: 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_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
TintCache orCreateValue = tints.GetOrCreateValue(settings);
if ((Object)(object)orCreateValue.map == (Object)null || orCreateValue.tint != tint)
{
orCreateValue.map = GalacticScaleFixes.Own<Cubemap>(Utils.TintCubeMap(map, tint), theme);
orCreateValue.tint = tint;
}
return orCreateValue.map;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(GSSettings), "Reset")]
private static void ReleaseGenerationResources()
{
HashSet<GSTheme> hashSet = new HashSet<GSTheme>(((Dictionary<string, GSTheme>)(object)ThemeLibrary.Vanilla()).Values);
if (GS2.externalThemes != null)
{
hashSet.UnionWith(((Dictionary<string, GSTheme>)(object)GS2.externalThemes).Values);
}
HashSet<Object> hashSet2 = new HashSet<Object>();
foreach (GSTheme item in hashSet)
{
if (item != null)
{
if (owned.TryGetValue(item, out var value))
{
hashSet2.UnionWith(value);
}
hashSet2.UnionWith((IEnumerable<Object>)(object)new Object[10]
{
(Object)item.terrainMat,
(Object)item.oceanMat,
(Object)item.atmosMat,
(Object)item.nephogramMat,
(Object)item.cloudMat,
(Object)item.thumbMat,
(Object)item.minimapMat,
(Object)item.ambientDesc,
(Object)(item.ambientDesc?.reflectionMap),
(Object)(item.AmbientSettings?.ReflectionMap)
});
}
}
foreach (GSTheme item2 in new List<GSTheme>(owned.Keys))
{
if (hashSet.Contains(item2))
{
continue;
}
foreach (Object item3 in owned[item2])
{
if (item3 != (Object)null && !hashSet2.Contains(item3))
{
Component val = (Component)(object)((item3 is Component) ? item3 : null);
Object.Destroy((Object)((val != null) ? ((object)val.gameObject) : ((object)item3)));
}
}
owned.Remove(item2);
}
}
private static bool IsInstantiate(CodeInstruction c, Type type)
{
if (c.opcode == OpCodes.Call && c.operand is MethodInfo { Name: "Instantiate" } methodInfo && methodInfo.DeclaringType == typeof(Object) && methodInfo.IsGenericMethod && methodInfo.GetParameters().Length == 1)
{
return methodInfo.GetGenericArguments()[0] == type;
}
return false;
}
private static bool IsCall(CodeInstruction c, Type type, string name)
{
if (c.opcode == OpCodes.Call && c.operand is MethodInfo methodInfo && methodInfo.DeclaringType == type)
{
return methodInfo.Name == name;
}
return false;
}
private static MethodInfo OwnOf(Type t)
{
return AccessTools.Method(typeof(GalacticScaleFixes), "Own", (Type[])null, (Type[])null).MakeGenericMethod(t);
}
private static List<CodeInstruction> OwnResults(IEnumerable<CodeInstruction> instructions, Func<CodeInstruction, Type> resultType, int expected, string where)
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Expected O, but got Unknown
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Expected O, but got Unknown
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
int num = 0;
for (int i = 0; i < list.Count; i++)
{
Type type = resultType(list[i]);
if (!(type == null))
{
list.Insert(i + 1, new CodeInstruction(OpCodes.Ldarg_0, (object)null));
list.Insert(i + 2, new CodeInstruction(OpCodes.Call, (object)OwnOf(type)));
i += 2;
num++;
}
}
Il.Require(num == expected, where + " (" + num + " of " + expected + ")");
return list;
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(GSTheme), "CopyFrom")]
private static IEnumerable<CodeInstruction> CopyFrom(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
int num = 0;
foreach (CodeInstruction item in list)
{
if (IsInstantiate(item, typeof(AudioClip)))
{
item.operand = AccessTools.Method(typeof(GalacticScaleFixes), "Share", (Type[])null, (Type[])null).MakeGenericMethod(typeof(AudioClip));
num++;
}
}
Il.Require(num == 1, "GSTheme.CopyFrom ambientSfx copy");
return OwnResults(list, (CodeInstruction c) => (!IsInstantiate(c, typeof(Material))) ? ((!IsInstantiate(c, typeof(AmbientDesc))) ? null : typeof(AmbientDesc)) : typeof(Material), 8, "GSTheme.CopyFrom material copies");
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(GSTheme), "CreateMaterial")]
private static IEnumerable<CodeInstruction> CreateMaterial(IEnumerable<CodeInstruction> instructions)
{
return OwnResults(instructions, (CodeInstruction c) => (!IsInstantiate(c, typeof(Material))) ? ((!IsCall(c, typeof(Utils), "GetTextureFromFile")) ? null : typeof(Texture)) : typeof(Material), 3, "GSTheme.CreateMaterial copies");
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(GSTheme), "ProcessTints")]
private static IEnumerable<CodeInstruction> ProcessTints(IEnumerable<CodeInstruction> instructions)
{
return OwnResults(instructions, (CodeInstruction c) => (!IsCall(c, typeof(GSTheme), "TintMaterial")) ? null : typeof(Material), 2, "GSTheme.ProcessTints tinted materials");
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(GSAmbientSettings), "ToTheme")]
private static IEnumerable<CodeInstruction> ToTheme(IEnumerable<CodeInstruction> instructions)
{
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Expected O, but got Unknown
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Expected O, but got Unknown
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Expected O, but got Unknown
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
int num = list.FindIndex((CodeInstruction c) => IsCall(c, typeof(Utils), "TintCubeMap"));
Il.Require(num >= 0 && Il.Count(list, (CodeInstruction c) => IsCall(c, typeof(Utils), "TintCubeMap")) == 1, "GSAmbientSettings.ToTheme TintCubeMap");
list[num] = CodeInstructionExtensions.MoveLabelsFrom(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(GalacticScaleFixes), "CachedTint", (Type[])null, (Type[])null)), list[num]);
list.InsertRange(num, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[2]
{
new CodeInstruction(OpCodes.Ldarg_0, (object)null),
new CodeInstruction(OpCodes.Ldarg_1, (object)null)
});
return list;
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(GSAmbientSettings), "Clone")]
private static IEnumerable<CodeInstruction> AmbientClone(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
int num = 0;
foreach (CodeInstruction item in list)
{
if (IsInstantiate(item, typeof(Cubemap)))
{
item.operand = AccessTools.Method(typeof(GalacticScaleFixes), "Share", (Type[])null, (Type[])null).MakeGenericMethod(typeof(Cubemap));
num++;
}
}
Il.Require(num == 1, "GSAmbientSettings.Clone cubemap copy");
return list;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(GS2), "LoadSettingsFromJson")]
private static void RequireSettings(bool __result, string path)
{
if (!__result && path != null && path.EndsWith(".gs2", StringComparison.OrdinalIgnoreCase))
{
throw new FileNotFoundException("GalacticScale settings file is missing.", path);
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(GS2), "DumpException")]
private static void FullException(Exception e)
{
GS2.Error(e.ToString(), 344);
}
[HarmonyPrefix]
[HarmonyPatch(typeof(PatchOnUIGalaxySelect), "SetStarmapGalaxy")]
private static bool DeferWhileDragging(ref UIGalaxySelect __0, ref bool __result)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
if (!NebulaCompat.IsMultiplayerActive)
{
UIVirtualStarmap starmap = __0.starmap;
if (((starmap != null) ? starmap.galaxyData : null) != null && VFInput.rtsConfirm.pressing)
{
if ((Object)(object)PatchOnUIGalaxySelect.delayer == (Object)null)
{
PatchOnUIGalaxySelect.delayer = ((Component)__0.starCountSlider).gameObject.AddComponent<Delayer>();
}
PatchOnUIGalaxySelect.delayer.Wait();
__result = false;
return false;
}
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Delayer), "Wait")]
private static bool Wait(Delayer __instance)
{
((MonoBehaviour)__instance).StopAllCoroutines();
__instance.active = true;
((MonoBehaviour)__instance).StartCoroutine(CommitAfterRelease(__instance));
return false;
}
private static IEnumerator CommitAfterRelease(Delayer delayer)
{
yield return (object)new WaitUntil((Func<bool>)(() => !VFInput.rtsConfirm.pressing));
if (delayer.active)
{
delayer.active = false;
if (((ManualBehaviour)UIRoot.instance.galaxySelect).active)
{
UIRoot.instance.galaxySelect.SetStarmapGalaxy();
}
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(SystemDisplay), "OnStarMapClick")]
private static bool StarMapClick()
{
if (!PressOnControl())
{
return !DragFromControl();
}
return false;
}
private static bool DragFromControl()
{
EventSystem current = EventSystem.current;
GameObject val = ((current != null) ? current.currentSelectedGameObject : null);
if ((Object)(object)val != (Object)null)
{
return (Object)(object)val.GetComponentInParent<Selectable>() != (Object)null;
}
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(SystemDisplay), "OnStarMapRightClick")]
private static bool StarMapRightClick()
{
return !PressOnControl();
}
private static bool PressOnControl()
{
//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_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_003c: Expected O, but got Unknown
//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)
EventSystem current = EventSystem.current;
if ((Object)(object)current == (Object)null)
{
return false;
}
hits.Clear();
current.RaycastAll(new PointerEventData(current)
{
position = Vector2.op_Implicit(Input.mousePosition)
}, hits);
foreach (RaycastResult hit in hits)
{
RaycastResult current2 = hit;
if ((Object)(object)((RaycastResult)(ref current2)).gameObject.GetComponentInParent<Selectable>() != (Object)null)
{
return true;
}
}
return false;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(SpraycoaterComponent), "Reshape")]
private static void CoaterShape(SpraycoaterComponent __instance, PlanetFactory factory, AnimData[] _animPool)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_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_0040: 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_004d: Unknown result type (might be due to invalid IL or missing references)
int entityId = __instance.entityId;
if (((factory != null) ? factory.planet : null) != null && _animPool != null && entityId > 0 && entityId < _animPool.Length)
{
Vector3 normalized = ((Vector3)(ref factory.entityPool[entityId].pos)).normalized;
if (!(normalized.x * normalized.x + normalized.z * normalized.z <= 1E-06f))
{
_animPool[entityId].prepare_length = Repack(_animPool[entityId].prepare_length, factory.planet.realRadius);
}
}
}
public static float Repack(float packed, float radius)
{
if (radius <= 0f || radius == 200f)
{
return packed;
}
float num = radius * 2f;
float num2 = Mathf.Round(packed / num);
return Mathf.Round((packed - num2 * num) / radius * 200f) + Mathf.Round(num2 / radius * 200f) * 400f;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(PlanetFactory), "Import")]
private static void ReshapeLoadedCoaters(PlanetFactory __instance)
{
try
{
CargoTraffic cargoTraffic = __instance.cargoTraffic;
if (cargoTraffic?.spraycoaterPool == null || __instance.planet == null || __instance.planet.realRadius == 200f)
{
return;
}
for (int i = 1; i < cargoTraffic.spraycoaterCursor; i++)
{
if (cargoTraffic.spraycoaterPool[i].id == i && cargoTraffic.spraycoaterPool[i].entityId > 0)
{
((SpraycoaterComponent)(ref cargoTraffic.spraycoaterPool[i])).Reshape(__instance, __instance.entityAnimPool);
}
}
}
catch (Exception ex)
{
Plugin.Log.LogWarning((object)("Spray coaters keep their saved shape: " + ex.Message));
}
}
}
[BepInPlugin("bug.dsp.galacticscalepatch", "BUG_GalacticScalePatch", "1.0.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
public const string Guid = "bug.dsp.galacticscalepatch";
public const string GalacticScale = "dsp.galactic-scale.2";
internal static ManualLogSource Log;
private void Awake()
{
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
if (GalacticScaleFixes.AlreadyFixed())
{
Log.LogInfo((object)"GalacticScale already contains these fixes, nothing patched");
return;
}
PluginInfo value;
string text = (Chainloader.PluginInfos.TryGetValue("dsp.galactic-scale.2", out value) ? value.Metadata.Version.ToString() : "?");
Harmony val = new Harmony("bug.dsp.galacticscalepatch");
try
{
val.PatchAll(typeof(GalacticScaleFixes));
Log.LogInfo((object)("GalacticScale " + text + " patched"));
}
catch (Exception ex)
{
Log.LogError((object)("GalacticScale " + text + " could not be patched; it is left as it is. " + ex));
Undo.All(val);
}
}
}
internal static class Undo
{
internal static void All(Harmony harmony)
{
foreach (MethodBase item in new List<MethodBase>(harmony.GetPatchedMethods()))
{
try
{
harmony.Unpatch(item, (HarmonyPatchType)0, harmony.Id);
}
catch (Exception ex)
{
Plugin.Log.LogError((object)("Could not remove the patch on " + item.DeclaringType?.Name + "." + item.Name + ": " + ex.Message));
}
}
}
}
internal static class Il
{
internal static void Require(bool found, string what)
{
if (!found)
{
throw new InvalidOperationException("pattern not found: " + what);
}
}
internal static int Count(List<CodeInstruction> code, Func<CodeInstruction, bool> match)
{
int num = 0;
foreach (CodeInstruction item in code)
{
if (match(item))
{
num++;
}
}
return num;
}
}
}