using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using EquinoxsModUtils;
using EquinoxsModUtils.Additions;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("CrusherCoreBoost")]
[assembly: AssemblyDescription("A Mod for the game Techtonica that adds a Core Boost for Crushers")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CrusherCoreBoost")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("db6a7a72-f63f-49be-8f0d-d89bf33b55e4")]
[assembly: AssemblyFileVersion("1.0.2")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.2.0")]
namespace CrusherCoreBoost
{
[BepInPlugin("com.jrinker03.CrusherCoreBoost", "CrusherCoreBoost", "1.0.2")]
public class CrusherCoreBoostPlugin : BaseUnityPlugin
{
private const string MyGUID = "com.jrinker03.CrusherCoreBoost";
private const string PluginName = "CrusherCoreBoost";
private const string VersionString = "1.0.2";
private const string UnlockDisplayName = "Core Boost (Crushing)";
private static readonly Harmony Harmony = new Harmony("com.jrinker03.CrusherCoreBoost");
public static ConfigEntry<int> CoresToUnlock;
public static ManualLogSource Log = new ManualLogSource("CrusherCoreBoost");
public static int UnlockId { get; private set; }
private void Awake()
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: CrusherCoreBoost, VersionString: 1.0.2 is loading...");
Harmony.PatchAll();
CreateConfigEntries();
CreateUnlock();
Events.GameDefinesLoaded += OnGameDefinesLoaded;
Events.SaveStateLoaded += OnSaveStateLoaded;
((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: CrusherCoreBoost, VersionString: 1.0.2 is loaded.");
Log = ((BaseUnityPlugin)this).Logger;
}
private void CreateConfigEntries()
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Expected O, but got Unknown
CoresToUnlock = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Cores To Unlock", 250, new ConfigDescription("How many yellow cores required to unlock 'Core Boost (Crushing)' in Tech Tree.", (AcceptableValueBase)null, Array.Empty<object>()));
}
private void CreateUnlock()
{
//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_0010: 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_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_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_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Expected O, but got Unknown
EMUAdditions.AddNewUnlock(new NewUnlockDetails
{
displayName = "Core Boost (Crushing)",
description = "Increase speed of all Crushers by 0.01% per Core Cluster.",
category = (TechCategory)5,
requiredTier = (ResearchTier)33554432,
coreTypeNeeded = (CoreType)3,
coreCountNeeded = CoresToUnlock.Value,
dependencyNames = new List<string> { "Core Boost (Threshing)" }
}, false);
}
private void OnGameDefinesLoaded()
{
//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)
Unlock unlockByName = Unlocks.GetUnlockByName("Core Boost (Crushing)", false);
if ((Object)(object)unlockByName == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogError((object)"Unable to find unlock 'Core Boost (Crushing)'. Halting unlock setup.");
}
UnlockId = ((UniqueIdScriptableObject)unlockByName).uniqueId;
unlockByName.requiredTier = Unlocks.GetUnlockByName("Core Boost (Assembly)", false).requiredTier;
unlockByName.treePosition = (int)Unlocks.GetUnlockByName("Core Boost (Threshing)", false).treePosition;
unlockByName.sprite = Resources.GetResourceInfoByName("Crusher", false).rawSprite;
}
private void OnSaveStateLoaded(object sender, EventArgs e)
{
}
}
}
namespace CrusherCoreBoost.Patches
{
[HarmonyPatch(typeof(CrusherInspector))]
[HarmonyPatch("Set")]
internal class CrusherInspector_Set_Patch
{
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
//IL_000f: 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_004a: Expected O, but got Unknown
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Expected O, but got Unknown
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Expected O, but got Unknown
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Expected O, but got Unknown
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Expected O, but got Unknown
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Expected O, but got Unknown
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Expected O, but got Unknown
int matches = 0;
CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).Start();
FieldInfo field = typeof(SchematicsRecipeData).GetField("duration");
CodeMatch[] toMatch = (CodeMatch[])(object)new CodeMatch[5]
{
new CodeMatch((OpCode?)OpCodes.Ldloc_0, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldfld, (object)field, (string)null),
new CodeMatch((OpCode?)OpCodes.Div, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldc_R4, (object)60f, (string)null),
new CodeMatch((OpCode?)OpCodes.Mul, (object)null, (string)null)
};
FieldInfo field2 = typeof(TechTreeStatePatches).GetField("crusherSpeedMultiplier", BindingFlags.Static | BindingFlags.NonPublic);
CodeInstruction[] newInstructions = (CodeInstruction[])(object)new CodeInstruction[2]
{
new CodeInstruction(OpCodes.Ldsfld, (object)field2),
new CodeInstruction(OpCodes.Mul, (object)null)
};
val.MatchForward(false, toMatch).Repeat((Action<CodeMatcher>)delegate(CodeMatcher cm)
{
cm.InsertAndAdvance(newInstructions);
cm.Advance(toMatch.Length);
matches++;
}, (Action<string>)null);
if (matches == 3)
{
CrusherCoreBoostPlugin.Log.LogInfo((object)"CrusherInspector.Set() updated.");
instructions = val.Instructions();
}
else
{
CrusherCoreBoostPlugin.Log.LogError((object)"Unable to update CrusherInspector.Set(). The code has likely changed.");
}
return instructions;
}
}
[HarmonyPatch(typeof(CrusherInstance))]
[HarmonyPatch("UpdateCrafting")]
public class CrusherInstance_UpdateCrafting_Patch
{
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
//IL_0002: 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_003e: Expected O, but got Unknown
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Expected O, but got Unknown
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Expected O, but got Unknown
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Expected O, but got Unknown
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Expected O, but got Unknown
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Expected O, but got Unknown
CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).Start();
bool flag = false;
FieldInfo field = typeof(CrusherInstance).GetField("progress");
CodeMatch[] array = (CodeMatch[])(object)new CodeMatch[4]
{
new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldfld, (object)field, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldarg_1, (object)null, (string)null)
};
val.MatchForward(true, array).Advance(1);
if (val.IsValid)
{
flag = true;
FieldInfo field2 = typeof(TechTreeStatePatches).GetField("crusherSpeedMultiplier", BindingFlags.Static | BindingFlags.NonPublic);
CodeInstruction[] array2 = (CodeInstruction[])(object)new CodeInstruction[2]
{
new CodeInstruction(OpCodes.Ldsfld, (object)field2),
new CodeInstruction(OpCodes.Mul, (object)null)
};
val.Insert(array2);
}
if (flag)
{
CrusherCoreBoostPlugin.Log.LogInfo((object)"CrusherInstance.UpdateCrafting() updated.");
instructions = val.Instructions();
}
else
{
CrusherCoreBoostPlugin.Log.LogError((object)"Unable to update CrusherInstance.UpdateCrafting(). The code has likely changed.");
}
return instructions;
}
}
[HarmonyPatch(typeof(TechTreeState))]
public class TechTreeStatePatches
{
internal static float freeCoresCrushing = 0f;
internal static float crusherSpeedMultiplier = 1f;
[HarmonyPatch("ResetAtStartOfFrame")]
[HarmonyPrefix]
public static void ResetAtStartOfFrame_Prefix()
{
crusherSpeedMultiplier = 1f + freeCoresCrushing;
}
[HarmonyPatch("HandleEndOfFrame")]
[HarmonyPostfix]
public static void HandleEndOfFrame_Postfix()
{
TechTreeState instance = TechTreeState.instance;
if (instance.unlockStates.Length > CrusherCoreBoostPlugin.UnlockId && instance.IsUnlockActive(CrusherCoreBoostPlugin.UnlockId))
{
freeCoresCrushing = (float)instance.freeCores * 0.001f;
}
else
{
freeCoresCrushing = 0f;
}
}
}
}