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 VirtualCores.Patches;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: 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_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_0009: 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)
virtualCoreCounts[coreType] += count;
Save();
}
public static int GetNumVirtualCores(CoreType coreType)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Invalid comparison between Unknown and I4
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Invalid comparison between Unknown and I4
//IL_0005: 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_001e: 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_0023: 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_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_00d4: 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_003b: 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[] array = CustomData.Get<string>(0u, "virtualCores").Split(new char[1] { ',' });
foreach (string text in array)
{
CoreType key2 = (CoreType)Enum.Parse(typeof(CoreType), text.Split(new char[1] { ':' })[0]);
int value = int.Parse(text.Split(new char[1] { ':' })[1]);
virtualCoreCounts[key2] = value;
}
}
}
[BepInPlugin("com.equinox.VirtualCores", "VirtualCores", "3.0. 1")]
public class VirtualCoresPlugin : BaseUnityPlugin
{
private const string MyGUID = "com.equinox.VirtualCores";
private const string PluginName = "VirtualCores";
private const string VersionString = "3.0. 1";
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. 1 is loading...");
ApplyPatches();
BindEvents();
((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: VirtualCores, VersionString: 3.0. 1 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_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Invalid comparison between Unknown and I4
//IL_0050: 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_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_001c: 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_003d: 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)
if ((int)((MemoryTreeInstance)(ref __instance)).GetErrorState() != 1)
{
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;
break;
}
}
}
}
internal class TechTreeStatePatch
{
[HarmonyPatch(typeof(TechTreeState), "NumCoresOfTypePlaced")]
[HarmonyPostfix]
private static void AddVirtualToCount(ref int __result, int typeIndex)
{
__result += VirtualCoresManager.GetNumVirtualCores((CoreType)(byte)typeIndex);
}
}
}