using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace DysonSphereVegeDrop;
[BepInPlugin("w-gates.dysonsphereprogram.vegedrop", "DSP Vege Drop", "1.0.0")]
[BepInProcess("DSPGAME.exe")]
[BepInProcess("Dyson Sphere Program.exe")]
public class DysonSphereVegeDrop : BaseUnityPlugin
{
public enum Substate
{
NORMAL,
PLANET
}
[Serializable]
[CompilerGenerated]
private sealed class <>c
{
public static readonly <>c <>9 = new <>c();
public static UnityAction <>9__38_0;
public static Func<string, short> <>9__46_0;
internal void <GameMain_Begin_Prefix>b__38_0()
{
configEnableMod.Value = !configEnableMod.Value;
OnConfigEnableChanged();
}
internal short <OnConfigDisableItemIdsChanged>b__46_0(string s)
{
if (!short.TryParse(s, out var result))
{
return 0;
}
return result;
}
}
public const string pluginGuid = "w-gates.dysonsphereprogram.vegedrop";
public const string pluginName = "DSP Vege Drop";
public const string pluginVersion = "1.0.0";
internal static ManualLogSource Logger;
internal static ConfigFile Config;
private Harmony harmony;
public static ConfigEntry<bool> configEnableMod;
public static ConfigEntry<bool> configEnableDebug;
public static ConfigEntry<bool> configEnableClearingItemTree;
public static ConfigEntry<bool> configEnableClearingItemStone;
public static ConfigEntry<bool> configEnableClearingItemDetail;
public static ConfigEntry<bool> configEnableClearingItemIce;
public static ConfigEntry<bool> configEnableClearingItemSpaceCapsule;
public static ConfigEntry<string> configDisableClearingItemIds_StringConfigEntry;
public static short[] configDisableClearingItemIds_ShortArray;
public static ConfigEntry<bool> configEnableClearingPlanetAridDesert;
public static ConfigEntry<bool> configEnableClearingPlanetAshenGelisol;
public static ConfigEntry<bool> configEnableClearingPlanetBarrenDesert;
public static ConfigEntry<bool> configEnableClearingPlanetGobi;
public static ConfigEntry<bool> configEnableClearingPlanetIceFieldGelisol;
public static ConfigEntry<bool> configEnableClearingPlanetLava;
public static ConfigEntry<bool> configEnableClearingPlanetMediterranean;
public static ConfigEntry<bool> configEnableClearingPlanetOceanWorld;
public static ConfigEntry<bool> configEnableClearingPlanetOceanicJungle;
public static ConfigEntry<bool> configEnableClearingPlanetPrairie;
public static ConfigEntry<bool> configEnableClearingPlanetRedStone;
public static ConfigEntry<bool> configEnableClearingPlanetVolcanicAsh;
public static ConfigEntry<Color> configIconColor_enabled;
public static ConfigEntry<Color> configIconColor_disabled;
public static ConfigEntry<Color> configIconColor_planet;
public static Substate enableSubstate;
public static RectTransform enableDisableButton;
public static Sprite enabledSprite;
public static Sprite disabledSprite;
public static Sprite pausedSprite_planet;
public static bool clearVegDropOnNextTick;
public static long lastDisplayTime;
public void Awake()
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Expected O, but got Unknown
Logger = ((BaseUnityPlugin)this).Logger;
Config = ((BaseUnityPlugin)this).Config;
Logger.LogDebug((object)"DSP Vege Drop: Awake.");
InitialConfigSetup();
try
{
harmony = new Harmony("w-gates.dysonsphereprogram.vegedrop");
harmony.PatchAll(typeof(DysonSphereVegeDrop));
}
catch (Exception ex)
{
Logger.LogDebug((object)"DSP Vege Drop: Awake - Unable to patch.");
throw ex;
}
Logger.LogInfo((object)"Initialization complete.");
}
[HarmonyPrefix]
[HarmonyPatch(typeof(GameMain), "Begin")]
public static void GameMain_Begin_Prefix()
{
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0171: Unknown result type (might be due to invalid IL or missing references)
//IL_0180: Unknown result type (might be due to invalid IL or missing references)
//IL_018c: Unknown result type (might be due to invalid IL or missing references)
//IL_0198: Unknown result type (might be due to invalid IL or missing references)
//IL_019e: Unknown result type (might be due to invalid IL or missing references)
//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
//IL_01db: Expected O, but got Unknown
if (configEnableDebug.Value)
{
Logger.LogDebug((object)"DSP Vege Drop: Calling - GameMain_Begin_Prefix.");
}
Config.Reload();
if (!((Object)(object)GameMain.instance != (Object)null) || !Object.op_Implicit((Object)(object)GameObject.Find("Game Menu/button-1-bg")) || !((Object)(object)enableDisableButton == (Object)null))
{
return;
}
RectTransform component = GameObject.Find("Game Menu").GetComponent<RectTransform>();
RectTransform component2 = GameObject.Find("Game Menu/button-1-bg").GetComponent<RectTransform>();
Vector3 localPosition = ((Transform)GameObject.Find("Game Menu/button-1-bg").GetComponent<RectTransform>()).localPosition;
enableDisableButton = Object.Instantiate<RectTransform>(component2);
((Object)((Component)enableDisableButton).gameObject).name = "w-gates-vege-drop-enable-button";
((Component)enableDisableButton).GetComponent<UIButton>().tips.tipTitle = (configEnableMod.Value ? "Vege Drop Enabled" : "Vege Drop Disabled");
((Component)enableDisableButton).GetComponent<UIButton>().tips.tipText = (configEnableMod.Value ? "Click to disable Vege Drop" : "Click to enable Vege Drop");
((Component)enableDisableButton).GetComponent<UIButton>().tips.delay = 0f;
((Component)((Component)enableDisableButton).transform.Find("button-1/icon")).GetComponent<Image>().sprite = (configEnableMod.Value ? enabledSprite : disabledSprite);
((Transform)enableDisableButton).SetParent((Transform)(object)component);
((Transform)enableDisableButton).localScale = new Vector3(0.35f, 0.35f, 0.35f);
((Transform)enableDisableButton).localPosition = new Vector3(localPosition.x + 96f, localPosition.y + 161f, localPosition.z);
ButtonClickedEvent onClick = ((Component)enableDisableButton).GetComponent<UIButton>().button.onClick;
object obj = <>c.<>9__38_0;
if (obj == null)
{
UnityAction val = delegate
{
configEnableMod.Value = !configEnableMod.Value;
OnConfigEnableChanged();
};
<>c.<>9__38_0 = val;
obj = (object)val;
}
((UnityEvent)onClick).AddListener((UnityAction)obj);
}
public static void UpdateTipText(string details)
{
((Component)((Component)enableDisableButton).transform.Find("button-1/icon")).GetComponent<Image>().sprite = ((!configEnableMod.Value) ? disabledSprite : ((enableSubstate == Substate.PLANET) ? pausedSprite_planet : enabledSprite));
((Component)enableDisableButton).GetComponent<UIButton>().tips.tipText = (configEnableMod.Value ? ("Click to disable vege drop\n" + details) : "Click to enable vege drop");
((Component)enableDisableButton).GetComponent<UIButton>().UpdateTip();
}
public static Sprite GetSprite(Color color)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: 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)
Texture2D val = new Texture2D(48, 48, (TextureFormat)4, false);
for (int i = 0; i < 48; i++)
{
for (int j = 0; j < 48; j++)
{
if ((i >= 9 && i <= 17 && j >= 2 && j <= 38) || (i >= 15 && i <= 23 && j >= 12 && j <= 38) || (i >= 21 && i <= 29 && j >= 18 && j <= 38) || (i >= 27 && i <= 35 && j >= 24 && j <= 38) || (i >= 33 && i <= 44 && j >= 30 && j <= 38))
{
val.SetPixel(i, j, color);
}
else
{
val.SetPixel(i, j, new Color(0f, 0f, 0f, 0f));
}
}
}
((Object)val).name = "w-gates-vege-drop-enable-icon";
val.Apply();
return Sprite.Create(val, new Rect(0f, 0f, 48f, 48f), new Vector2(0f, 0f), 1000f);
}
public void InitialConfigSetup()
{
//IL_0260: Unknown result type (might be due to invalid IL or missing references)
//IL_0270: Unknown result type (might be due to invalid IL or missing references)
//IL_027a: Expected O, but got Unknown
//IL_028e: Unknown result type (might be due to invalid IL or missing references)
//IL_029e: Unknown result type (might be due to invalid IL or missing references)
//IL_02a8: Expected O, but got Unknown
//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
//IL_02d6: Expected O, but got Unknown
configEnableMod = Config.Bind<bool>("Config", "Enable", true, "Enable/disable vege drop mod.");
configEnableDebug = Config.Bind<bool>("Config", "EnableDebug", false, "Enabling debug will add more feedback to the BepInEx console. This includes the reasons why drones are not clearing.");
configEnableClearingItemTree = Config.Bind<bool>("Items", "IncludeTrees", true, "Enabling drop of trees.");
configEnableClearingItemStone = Config.Bind<bool>("Items", "IncludeStone", true, "Enabling drop of stones which can block the mecha's movement.");
configEnableClearingItemDetail = Config.Bind<bool>("Items", "IncludePebbles", false, "Enabling drop of tiny stones which won't block the mecha's movement.");
configEnableClearingItemIce = Config.Bind<bool>("Items", "IncludeIce", true, "Enabling drop of ice.");
configDisableClearingItemIds_StringConfigEntry = Config.Bind<string>("Items", "DisableItemIds", "", "Disable drop of specific vege proto IDs. String is a comma-separated list of shorts. This mod will print to the debug console all vege proto IDs which are mined so you can see what IDs you're mining. See README for this mod for more information.");
configEnableClearingPlanetAridDesert = Config.Bind<bool>("Planets", "IncludeAridDesert", true, "Enable drop on arid desert planets.");
configEnableClearingPlanetAshenGelisol = Config.Bind<bool>("Planets", "IncludeAshenGelisol", true, "Enable drop on ashen gelisol planets.");
configEnableClearingPlanetBarrenDesert = Config.Bind<bool>("Planets", "IncludeBarrenDesert", true, "Enable drop on barren desert planets.");
configEnableClearingPlanetGobi = Config.Bind<bool>("Planets", "IncludeGobi", true, "Enable drop on gobi planets.");
configEnableClearingPlanetIceFieldGelisol = Config.Bind<bool>("Planets", "IncludeIceFieldGelisol", true, "Enable drop on ice field gelisol planets.");
configEnableClearingPlanetLava = Config.Bind<bool>("Planets", "IncludeLava", true, "Enable drop on lava planets.");
configEnableClearingPlanetMediterranean = Config.Bind<bool>("Planets", "IncludeMediterranean", true, "Enable drop on mediterranean planets.");
configEnableClearingPlanetOceanWorld = Config.Bind<bool>("Planets", "IncludeOceanWorld", true, "Enable drop on ocean world planets.");
configEnableClearingPlanetOceanicJungle = Config.Bind<bool>("Planets", "IncludeOceanicJungle", true, "Enable drop on oceanic jungle planets.");
configEnableClearingPlanetPrairie = Config.Bind<bool>("Planets", "IncludePrairie", true, "Enable drop on prairie planets.");
configEnableClearingPlanetRedStone = Config.Bind<bool>("Planets", "IncludeRedStone", true, "Enable drop on red stone (mushroom) planets.");
configEnableClearingPlanetVolcanicAsh = Config.Bind<bool>("Planets", "IncludeVolcanicAsh", true, "Enable drop on volcanic ash planets.");
configIconColor_enabled = Config.Bind<Color>("IconColors", "EnabledNormal", Color.green, new ConfigDescription("The color of the drop icon when this mod is enabled.", (AcceptableValueBase)null, Array.Empty<object>()));
configIconColor_disabled = Config.Bind<Color>("IconColors", "Disabled", Color.grey, new ConfigDescription("The color of the drop icon when this mod is disabled.", (AcceptableValueBase)null, Array.Empty<object>()));
configIconColor_planet = Config.Bind<Color>("IconColors", "PausedPlanet", Color.green, new ConfigDescription("The color of the drop icon when drop is paused on the current planet type per configuration. See configuration settings for planets.", (AcceptableValueBase)null, Array.Empty<object>()));
OnConfigReload();
Config.ConfigReloaded += OnConfigReload;
Config.SettingChanged += OnConfigSettingChanged;
}
public static void OnConfigReload(object sender, EventArgs e)
{
OnConfigReload();
}
public static void OnConfigReload()
{
OnConfigDisableItemIdsChanged();
OnConfigEnableChanged();
OnConfigIconColorChanged();
Logger.LogInfo((object)"Configuration loaded.");
}
public static void OnConfigSettingChanged(object sender, SettingChangedEventArgs e)
{
ConfigDefinition definition = e.ChangedSetting.Definition;
if (definition.Section == "Config" && definition.Key == "Enable")
{
OnConfigEnableChanged();
}
else if (definition.Section == "Items" && definition.Key == "DisableItemIds")
{
OnConfigDisableItemIdsChanged();
}
else if (definition.Section == "IconColors")
{
OnConfigIconColorChanged();
}
}
public static void OnConfigEnableChanged()
{
if ((Object)(object)enableDisableButton != (Object)null)
{
if (!configEnableMod.Value)
{
clearVegDropOnNextTick = true;
}
((Component)enableDisableButton).GetComponent<UIButton>().tips.tipTitle = (configEnableMod.Value ? "Vege Drop Enabled" : "Vege Drop Disabled");
UpdateTipText("");
}
}
public static void OnConfigDisableItemIdsChanged()
{
if (configDisableClearingItemIds_StringConfigEntry == null)
{
return;
}
configDisableClearingItemIds_ShortArray = (from s in configDisableClearingItemIds_StringConfigEntry.Value.Split(new char[1] { ',' })
select (short)(short.TryParse(s, out var result) ? result : 0)).ToArray();
if (configDisableClearingItemIds_ShortArray.Length == 1 && configDisableClearingItemIds_ShortArray[0] == 0)
{
configDisableClearingItemIds_ShortArray = new short[0];
}
short[] array = configDisableClearingItemIds_ShortArray;
foreach (short num in array)
{
VegeProto val = ((ProtoSet<VegeProto>)(object)LDB.veges).Select((int)num);
if (val == null)
{
Logger.LogError((object)$"ERROR: Configured vege proto ID {num} is invalid. Recommend removing this ID from the config file.");
}
else
{
Logger.LogInfo((object)$"Configured to block vege proto ID {num} for {Localization.Translate(((Proto)val).Name)}");
}
}
}
public static void OnConfigIconColorChanged()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: 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)
enabledSprite = GetSprite(configIconColor_enabled.Value);
disabledSprite = GetSprite(configIconColor_disabled.Value);
pausedSprite_planet = GetSprite(configIconColor_planet.Value);
}
[HarmonyPrefix]
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
public static void PlanetFactory_RemoveVegeWithComponents_Prefix(ref PlanetFactory __instance, int id)
{
//IL_0023: 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_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
//IL_0249: Unknown result type (might be due to invalid IL or missing references)
//IL_024f: Invalid comparison between Unknown and I4
//IL_032f: Unknown result type (might be due to invalid IL or missing references)
//IL_025e: Unknown result type (might be due to invalid IL or missing references)
//IL_0272: Unknown result type (might be due to invalid IL or missing references)
//IL_0279: Invalid comparison between Unknown and I4
//IL_0288: Unknown result type (might be due to invalid IL or missing references)
//IL_028e: Invalid comparison between Unknown and I4
//IL_0388: Unknown result type (might be due to invalid IL or missing references)
//IL_0389: Unknown result type (might be due to invalid IL or missing references)
//IL_0393: Unknown result type (might be due to invalid IL or missing references)
//IL_0394: Unknown result type (might be due to invalid IL or missing references)
//IL_0426: Unknown result type (might be due to invalid IL or missing references)
//IL_0427: Unknown result type (might be due to invalid IL or missing references)
//IL_0433: Unknown result type (might be due to invalid IL or missing references)
//IL_0438: Unknown result type (might be due to invalid IL or missing references)
if (configEnableDebug.Value)
{
Logger.LogDebug((object)"DSP Vege Drop: Calling - PlanetFactory_RemoveVegeWithComponents_Prefix.");
}
VegeData val = __instance.vegePool[id];
if (val.id == 0)
{
return;
}
enableSubstate = Substate.NORMAL;
if (!configEnableMod.Value)
{
if (configEnableDebug.Value)
{
Logger.LogDebug((object)"Skipping because mod is disabled.");
}
return;
}
string displayName = ((ProtoSet<ThemeProto>)(object)LDB.themes).Select(__instance.planet.theme).DisplayName;
if ((!configEnableClearingPlanetAridDesert.Value && displayName == "干旱荒漠") || (!configEnableClearingPlanetAshenGelisol.Value && displayName == "灰烬冻土") || (!configEnableClearingPlanetBarrenDesert.Value && displayName == "贫瘠荒漠") || (!configEnableClearingPlanetGobi.Value && displayName == "戈壁") || (!configEnableClearingPlanetIceFieldGelisol.Value && displayName == "冰原冻土") || (!configEnableClearingPlanetLava.Value && displayName == "熔岩") || (!configEnableClearingPlanetMediterranean.Value && displayName == "地中海") || (!configEnableClearingPlanetOceanWorld.Value && displayName == "水世界") || (!configEnableClearingPlanetOceanicJungle.Value && displayName == "海洋丛林") || (!configEnableClearingPlanetPrairie.Value && displayName == "草原") || (!configEnableClearingPlanetRedStone.Value && displayName == "红石") || (!configEnableClearingPlanetVolcanicAsh.Value && displayName == "火山灰"))
{
if (configEnableDebug.Value)
{
Logger.LogDebug((object)("Skipping planet type " + __instance.planet.typeString));
}
enableSubstate = Substate.PLANET;
UpdateTipText("(Waiting on this planet type.)");
return;
}
VegeProto val2 = ((ProtoSet<VegeProto>)(object)LDB.veges).Select((int)val.protoId);
if (val2 != null && val2.MiningItem.Length != 0)
{
if (((Proto)val2).Name == "飞行舱")
{
if (configEnableDebug.Value)
{
Logger.LogDebug((object)"Skipping Space Capsule");
}
return;
}
if (((int)val2.Type == 1 && !configEnableClearingItemTree.Value) || ((int)val2.Type == 0 && !configEnableClearingItemStone.Value) || ((int)val2.Type == 9 && !configEnableClearingItemDetail.Value) || ((int)val2.Type == 2 && !configEnableClearingItemIce.Value))
{
if (configEnableDebug.Value)
{
Logger.LogDebug((object)("Skipping Disabled Veg Type " + ((object)(EVegeType)(ref val2.Type)).ToString()));
}
return;
}
}
bool flag = false;
short[] array = configDisableClearingItemIds_ShortArray;
foreach (short num in array)
{
if (val.protoId == num)
{
flag = true;
break;
}
}
if (flag)
{
if (configEnableDebug.Value)
{
Logger.LogDebug((object)("Skipping Disabled Veg ID " + val.protoId));
}
return;
}
Random random = new Random(val.id + ((__instance.planet.seed & 0x3FFF) << 14));
int num2 = 0;
for (int j = 0; j < val2.MiningItem.Length; j++)
{
if ((float)random.NextDouble() < val2.MiningChance[j])
{
int num3 = val2.MiningItem[j];
int num4 = (int)((float)val2.MiningCount[j] * (val.scl.y * val.scl.y) + 0.5f);
if (num4 > 0 && ((ProtoSet<ItemProto>)(object)LDB.items).Select(num3) != null)
{
int num5 = GameMain.mainPlayer.TryAddItemToPackage(num3, num4, 0, true, 0, false);
GameMain.statistics.production.factoryStatPool[__instance.index].AddProductionToTotalArray(num3, num4);
GameMain.mainPlayer.controller.gameData.history.AddFeatureValue(2150000 + num3, num4);
UIItemup.Up(num3, num5);
UIRealtimeTip.PopupItemGet(num3, num5, val.pos + ((Vector3)(ref val.pos)).normalized, num2++);
}
}
}
if (configEnableDebug.Value)
{
Logger.LogDebug((object)($"Dropped proto ID {((Proto)val2).ID} (" + Localization.Translate(((Proto)val2).Name) + ")"));
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(GameData), "Destroy")]
public static void GameData_Destroy_Postfix()
{
if (configEnableDebug.Value)
{
Logger.LogDebug((object)"DSP Drone Clearing - Calling: GameData_Destroy_Postfix");
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(GameScenarioLogic), "NotifyOnVegetableMined")]
public static void GameScenarioLogic_NotifyOnVegetableMined_Prefix(int protoId)
{
if (configEnableDebug.Value)
{
Logger.LogDebug((object)"DSP Drone Clearing - Calling: GameScenarioLogic_NotifyOnVegetableMined_Prefix");
VegeProto val = ((ProtoSet<VegeProto>)(object)LDB.veges).Select(protoId);
Logger.LogDebug((object)($"Mined proto ID {protoId} (" + Localization.Translate(((Proto)val).Name) + ")"));
}
}
}