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;
[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
};
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 (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;
}
}
[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_0003: 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_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Invalid comparison between Unknown and I4
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Invalid comparison between Unknown and I4
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: Unknown result type (might be due to invalid IL or missing references)
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
//IL_0154: Unknown result type (might be due to invalid IL or missing references)
//IL_0193: Unknown result type (might be due to invalid IL or missing references)
//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
//IL_01b7: 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)
bool result = true;
EVeinType resourceForGlobalMining = PlanetwideMining.ResourceForGlobalMining;
if ((int)resourceForGlobalMining > 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)
{
if (val.paramCount == 0)
{
val.parameters = new int[2048];
val.paramCount = 2048;
}
PrefabDesc desc = val.desc;
if (desc.isVeinCollector || desc.veinMiner)
{
List<int> list = new List<int>();
VeinData[] veinPool = factory.veinPool;
VeinData[] array = veinPool;
foreach (VeinData val2 in array)
{
int id = val2.id;
EVeinType type = val2.type;
if (type == resourceForGlobalMining)
{
list.Add(id);
}
}
int count = list.Count;
if (count > 0)
{
PrebuildData val3 = default(PrebuildData);
((PrebuildData)(ref val3)).InitParametersArray(veinPool.Length);
val3.parameters = list.ToArray();
val3.paramCount = count;
((PrebuildData)(ref val3)).ArrangeParametersArray();
Array.Resize(ref val.parameters, val.paramCount + val3.paramCount);
Array.Copy(val3.parameters, 0, val.parameters, val.paramCount, val3.paramCount);
val.paramCount += val3.paramCount;
}
else
{
val.condition = (EBuildCondition)25;
}
Array.Clear(____tmp_ids, 0, ____tmp_ids.Length);
__result = true;
result = false;
}
}
}
}
}
}
return result;
}
}