using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using JetBrains.Annotations;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("PlanetwideMining")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PlanetwideMining")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5382EB65-83EA-4982-A2EF-4DCA92159BE8")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.1", FrameworkDisplayName = ".NET Framework 4.7.1")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PlanetwideMining;
[HarmonyPatch(typeof(BuildTool_Click))]
[HarmonyPatch("CheckBuildConditions")]
public static class PatchMiners
{
[UsedImplicitly]
public static bool Prefix(BuildTool_Click __instance, ref bool __result, ref int[] ____tmp_ids, ref Collider[] ____tmp_cols, ref int ___tmpInhandId, ref int ___tmpInhandCount, ref StorageComponent ___tmpPackage, ref int ____overlappedCount, ref int[] ____overlappedIds)
{
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: 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_00bb: Invalid comparison between Unknown and I4
//IL_0011: 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_0026: Invalid comparison between Unknown and I4
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Invalid comparison between Unknown and I4
//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
//IL_0298: Unknown result type (might be due to invalid IL or missing references)
//IL_020b: Unknown result type (might be due to invalid IL or missing references)
//IL_024a: Unknown result type (might be due to invalid IL or missing references)
//IL_0258: Unknown result type (might be due to invalid IL or missing references)
//IL_026e: Unknown result type (might be due to invalid IL or missing references)
//IL_0283: Unknown result type (might be due to invalid IL or missing references)
bool result = true;
if (PlanetwideMining.NumlockStateActive)
{
PlanetwideMining.ResourceForGlobalMining = (EVeinType)0;
PlanetData localPlanet = GameMain.localPlanet;
if (localPlanet != null && (int)localPlanet.type != 5)
{
PlanetFactory factory = localPlanet.factory;
if (factory != null)
{
List<BuildPreview> buildPreviews = ((BuildTool)__instance).buildPreviews;
if (buildPreviews.Count == 1)
{
BuildPreview val = buildPreviews[0];
if (val != null)
{
PrefabDesc desc = val.desc;
if (!desc.isVeinCollector && !desc.veinMiner)
{
__result = true;
result = false;
}
}
}
}
}
}
else
{
EVeinType resourceForGlobalMining = PlanetwideMining.ResourceForGlobalMining;
if ((int)resourceForGlobalMining > 0)
{
PlanetData localPlanet2 = GameMain.localPlanet;
if (localPlanet2 != null && (int)localPlanet2.type != 5)
{
PlanetFactory factory2 = localPlanet2.factory;
if (factory2 != null)
{
List<BuildPreview> buildPreviews2 = ((BuildTool)__instance).buildPreviews;
if (buildPreviews2.Count == 1)
{
BuildPreview val2 = buildPreviews2[0];
if (val2 != null)
{
PrefabDesc desc2 = val2.desc;
if (desc2.isVeinCollector || desc2.veinMiner)
{
if (val2.paramCount == 0)
{
val2.parameters = new int[2048];
val2.paramCount = 2048;
}
List<int> list = new List<int>();
VeinData[] veinPool = factory2.veinPool;
VeinData[] array = veinPool;
foreach (VeinData val3 in array)
{
int id = val3.id;
EVeinType type = val3.type;
if (type == resourceForGlobalMining)
{
list.Add(id);
}
}
int count = list.Count;
if (count > 0)
{
PrebuildData val4 = default(PrebuildData);
((PrebuildData)(ref val4)).InitParametersArray(veinPool.Length);
val4.parameters = list.ToArray();
val4.paramCount = count;
((PrebuildData)(ref val4)).ArrangeParametersArray();
Array.Resize(ref val2.parameters, val2.paramCount + val4.paramCount);
Array.Copy(val4.parameters, 0, val2.parameters, val2.paramCount, val4.paramCount);
val2.paramCount += val4.paramCount;
}
else
{
val2.condition = (EBuildCondition)26;
}
Array.Clear(____tmp_ids, 0, ____tmp_ids.Length);
__result = true;
result = false;
}
}
}
}
}
}
}
return result;
}
}
[BepInPlugin("PlanetwideMining", "PlanetwideMining", "0.0.13")]
public class PlanetwideMining : BaseUnityPlugin
{
private const string PluginGuid = "PlanetwideMining";
private const string PluginName = "PlanetwideMining";
private const string PluginVersion = "0.0.13";
public static EVeinType ResourceForGlobalMining = (EVeinType)0;
public static ConfigEntry<bool> SpeedControlsEnabled;
private bool speedControlsEnabledField;
private readonly HashSet<EVeinType> veinTypes = new HashSet<EVeinType>();
private static readonly List<EVeinType> ResourceTypes = new List<EVeinType>
{
(EVeinType)1,
(EVeinType)2,
(EVeinType)3,
(EVeinType)4,
(EVeinType)5,
(EVeinType)6,
(EVeinType)7,
(EVeinType)8,
(EVeinType)9,
(EVeinType)10,
(EVeinType)11,
(EVeinType)12,
(EVeinType)13,
(EVeinType)14
};
public static bool NumlockStateActive { get; set; }
private int LastUsedIndex { get; set; }
private void Awake()
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Expected O, but got Unknown
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin PlanetwideMining is loaded!");
InitConfig(((BaseUnityPlugin)this).Config);
Harmony val = new Harmony("PlanetwideMining");
val.PatchAll();
}
private void InitConfig(ConfigFile config)
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Expected O, but got Unknown
SpeedControlsEnabled = config.Bind<bool>("1. SpeedControls", "SpeedControlsEnabled", true, new ConfigDescription("SpeedControlsEnabled", (AcceptableValueBase)(object)new AcceptableValueRange<bool>(false, true), Array.Empty<object>()));
if (SpeedControlsEnabled != null)
{
speedControlsEnabledField = SpeedControlsEnabled.Value;
}
}
private void Update()
{
if (Input.GetKeyDown((KeyCode)280))
{
SwitchEnumValue(1);
}
if (Input.GetKeyDown((KeyCode)281))
{
SwitchEnumValue(-1);
}
if (Input.GetKeyDown((KeyCode)300))
{
NumlockStateActive = !NumlockStateActive;
}
if (speedControlsEnabledField)
{
if (Input.GetKeyDown((KeyCode)257))
{
SwitchGameSpeed(1f);
}
else if (Input.GetKeyDown((KeyCode)258))
{
SwitchGameSpeed(2f);
}
else if (Input.GetKeyDown((KeyCode)259))
{
SwitchGameSpeed(4f);
}
else if (Input.GetKeyDown((KeyCode)260))
{
SwitchGameSpeed(8f);
}
else if (Input.GetKeyDown((KeyCode)261))
{
SwitchGameSpeed(16f);
}
}
}
private void SwitchGameSpeed(float speed)
{
Time.timeScale = speed;
}
private void SwitchEnumValue(int indexChange)
{
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
RefreshResourcesEnumsForCurrentPlanet();
EVeinType[] array = veinTypes.OrderBy((EVeinType v) => v).ToArray();
int num = LastUsedIndex + indexChange;
if (!IndexInRange(num))
{
num = ((indexChange <= 0) ? (array.Length - 1) : 0);
}
LastUsedIndex = num;
ResourceForGlobalMining = array[num];
}
private void RefreshResourcesEnumsForCurrentPlanet()
{
//IL_004e: 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_0056: 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_005d: 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_0071: Unknown result type (might be due to invalid IL or missing references)
HashSet<EVeinType> hashSet = veinTypes;
hashSet.Clear();
hashSet.Add((EVeinType)0);
PlanetData localPlanet = GameMain.localPlanet;
if (localPlanet == null)
{
return;
}
PlanetFactory factory = localPlanet.factory;
if (factory == null)
{
return;
}
VeinData[] veinPool = factory.veinPool;
VeinData[] array = veinPool;
foreach (VeinData val in array)
{
EVeinType type = val.type;
if (!hashSet.Contains(type))
{
hashSet.Add(type);
}
}
}
private bool IndexInRange(int index)
{
int count = veinTypes.Count;
if (index >= 0 && index < count)
{
return true;
}
return false;
}
}