using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using EquinoxsModUtils;
using HarmonyLib;
using UnityEngine;
using VirtualCores.Patches;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace VirtualCores
{
public static class VirtualCoresManager
{
private static Dictionary<CoreType, int> virtualCoreCounts = new Dictionary<CoreType, int>();
private static bool loaded = false;
public static void AddVirtualCores(CoreType coreType, int count = 1)
{
//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_000c: Unknown result type (might be due to invalid IL or missing references)
virtualCoreCounts[coreType] += count;
Save();
}
public static int GetNumVirtualCores(CoreType coreType)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Invalid comparison between Unknown and I4
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Invalid comparison between Unknown and I4
//IL_000a: 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_002e: Unknown result type (might be due to invalid IL or missing references)
if ((int)coreType == 2)
{
coreType = (CoreType)1;
}
else if ((int)coreType == 1)
{
coreType = (CoreType)2;
}
if (!loaded)
{
return 0;
}
return virtualCoreCounts[coreType];
}
internal static void Save()
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
List<string> list = new List<string>();
foreach (KeyValuePair<CoreType, int> virtualCoreCount in virtualCoreCounts)
{
list.Add($"{virtualCoreCount.Key}:{virtualCoreCount.Value}");
}
string text = string.Join(",", list);
CustomData.Update<string>(0u, "virtualCores", text);
}
internal static void Load()
{
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: 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_003d: 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)
loaded = true;
if (!CustomData.FieldExists<string>(0u, "virtualCores"))
{
foreach (CoreType value2 in Enum.GetValues(typeof(CoreType)))
{
virtualCoreCounts.Add(value2, 0);
}
Save();
return;
}
string text = CustomData.Get<string>(0u, "virtualCores");
string[] array = text.Split(new char[1] { ',' });
string[] array2 = array;
foreach (string text2 in array2)
{
CoreType key2 = (CoreType)Enum.Parse(typeof(CoreType), text2.Split(new char[1] { ':' })[0]);
int value = int.Parse(text2.Split(new char[1] { ':' })[1]);
virtualCoreCounts[key2] = value;
}
}
}
[BepInPlugin("com.equinox.VirtualCores", "VirtualCores", "3.0.0")]
public class VirtualCoresPlugin : BaseUnityPlugin
{
private const string MyGUID = "com.equinox.VirtualCores";
private const string PluginName = "VirtualCores";
private const string VersionString = "3.0.0";
private static readonly Harmony Harmony = new Harmony("com.equinox.VirtualCores");
public static ManualLogSource Log = new ManualLogSource("VirtualCores");
private void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: VirtualCores, VersionString: 3.0.0 is loading...");
ApplyPatches();
BindEvents();
((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: VirtualCores, VersionString: 3.0.0 is loaded.");
}
private void OnSaveStateLoaded(object sender, EventArgs e)
{
VirtualCoresManager.Load();
}
private void ApplyPatches()
{
Harmony.CreateAndPatchAll(typeof(MemoryTreeInstancePatch), (string)null);
Harmony.CreateAndPatchAll(typeof(TechTreeStatePatch), (string)null);
}
private void BindEvents()
{
Events.SaveStateLoaded += OnSaveStateLoaded;
}
}
}
namespace VirtualCores.Patches
{
internal class MemoryTreeInstancePatch
{
[HarmonyPatch(typeof(MemoryTreeInstance), "SimUpdate")]
[HarmonyPostfix]
private static void AddVirtualCore(MemoryTreeInstance __instance)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Invalid comparison between Unknown and I4
//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_002e: 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_00b9: 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_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: 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_009b: Unknown result type (might be due to invalid IL or missing references)
if ((int)((MemoryTreeInstance)(ref __instance)).GetErrorState() != 1)
{
return;
}
GenericMachineInstanceRef targetMachineRef = Player.instance.interaction.TargetMachineRef;
if (((GenericMachineInstanceRef)(ref targetMachineRef)).index != __instance.commonInfo.index)
{
return;
}
for (int i = 0; i < __instance.data.Count; i++)
{
CoreData val = __instance.data[i];
if (val.count != 0)
{
VirtualCoresManager.AddVirtualCores((CoreType)val.coreType);
val.count--;
__instance.data[i] = val;
Debug.Log((object)$"Added 1 {(object)(CoreType)val.coreType}");
break;
}
}
}
}
internal class TechTreeStatePatch
{
[HarmonyPatch(typeof(TechTreeState), "NumCoresOfTypePlaced")]
[HarmonyPostfix]
private static void AddVirtualToCount(ref int __result, int typeIndex)
{
__result += VirtualCoresManager.GetNumVirtualCores((CoreType)(byte)typeIndex);
}
}
}