using System;
using System.Collections.Generic;
using System.Diagnostics;
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.1")]
public class PlanetwideMining : BaseUnityPlugin
{
private const string PluginGuid = "PlanetwideMining";
private const string PluginName = "PlanetwideMining";
private const string PluginVersion = "0.1";
public static EVeinType ResourceForGlobalMining = (EVeinType)0;
public static ConfigEntry<bool> SpeedControlsEnabled;
private bool speedControlsEnabledField;
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_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
int num = LastUsedIndex + indexChange;
if (!IndexInRange(num))
{
num = ((indexChange <= 0) ? (ResourceTypes.Count - 1) : 0);
}
LastUsedIndex = num;
ResourceForGlobalMining = ResourceTypes[num];
}
private bool IndexInRange(int index)
{
int count = ResourceTypes.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_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
//IL_0162: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0181: Unknown result type (might be due to invalid IL or missing references)
//IL_018f: Unknown result type (might be due to invalid IL or missing references)
//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
bool result = true;
List<BuildPreview> buildPreviews = ((BuildTool)__instance).buildPreviews;
if (buildPreviews != null && buildPreviews.Count == 1)
{
for (int i = 0; i < buildPreviews.Count; i++)
{
BuildPreview val = buildPreviews[i];
PrefabDesc desc = val.desc;
if (desc == null || !desc.veinMiner)
{
continue;
}
Array.Clear(____tmp_ids, 0, ____tmp_ids.Length);
PrebuildData val2 = default(PrebuildData);
VeinData[] veinPool = ((BuildTool)__instance).factory.veinPool;
((PrebuildData)(ref val2)).InitParametersArray(veinPool.Length);
if (val2.parameters != null)
{
EVeinType resourceForGlobalMining = PlanetwideMining.ResourceForGlobalMining;
List<int> list = new List<int>();
for (int j = 0; j < veinPool.Length; j++)
{
if (veinPool[j].type == resourceForGlobalMining)
{
list.Add(veinPool[j].id);
}
}
val2.parameters = list.ToArray();
}
val2.paramCount = val2.parameters.Length;
((PrebuildData)(ref val2)).ArrageParametersArray();
if (val.desc.isVeinCollector)
{
if (val.paramCount == 0)
{
val.parameters = new int[2048];
val.paramCount = 2048;
}
if (val2.paramCount > 0)
{
Array.Resize(ref val.parameters, val.paramCount + val2.paramCount);
Array.Copy(val2.parameters, 0, val.parameters, val.paramCount, val2.paramCount);
val.paramCount += val2.paramCount;
}
}
else
{
val.parameters = val2.parameters;
val.paramCount = val2.paramCount;
}
if (val2.paramCount == 0)
{
val.condition = (EBuildCondition)24;
}
__result = true;
result = false;
}
}
return result;
}
}