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 System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("DistributeSpaceWarper")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DistributeSpaceWarper")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("DD23704E-3C0C-4D6B-8EB1-F847CFB2BC2D")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace DistributeSpaceWarper
{
public static class Config
{
public static class General
{
public static ConfigEntry<bool> WarperRemoteMode;
public static ConfigEntry<int> WarperRemoteTransportCost;
public static ConfigEntry<int> WarperTickCount;
public static ConfigEntry<bool> WarperLocalTransportCost;
public static ConfigEntry<bool> WarpersRequiredToggleAutomation;
}
public static class Utility
{
public static ConfigEntry<bool> DisableMod;
public static ConfigEntry<bool> UninstallMod;
}
private static readonly string GENERAL_SECTION = "General";
private static readonly string UTILITY_SECTION = "Utility";
internal static void Init(ConfigFile config)
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Expected O, but got Unknown
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Expected O, but got Unknown
General.WarperTickCount = config.Bind<int>(GENERAL_SECTION, "WarperTickCount", 60, new ConfigDescription("Default number of ticks before distributing warpers. Note: Maximum of 260, defaults to 60", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 275), new object[1]
{
new { }
}));
General.WarperRemoteMode = config.Bind<bool>(GENERAL_SECTION, "WarperRemoteMode", false, "By default only search local ILS/PLS for supplies. Enable this to get Warpers from different planets as well");
General.WarpersRequiredToggleAutomation = config.Bind<bool>(GENERAL_SECTION, "WarpersRequiredToggleAutomation", true, "If enabled, when `Warpers Required` toggle ticked on, this will setup warper slot to default local mode. When toggle is ticked off this will set wraper slot to local supply.");
General.WarperLocalTransportCost = config.Bind<bool>(GENERAL_SECTION, "WarperTransportCost", true, "If enabled, transporting Warpers costs 1 warper. Disable for moving Warpers at no costs.");
General.WarperRemoteTransportCost = config.Bind<int>(GENERAL_SECTION, "WarperRemoteTransportCost", 2, new ConfigDescription("Default cost of transporting Warpers from different planets. Note: Maximum of 10, defaults to 2", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), new object[1]
{
new { }
}));
Utility.DisableMod = config.Bind<bool>(UTILITY_SECTION, "DisableMod", false, "While true this will disable all mod effects but will not remove additional slot from ILS. Useful if uninstalling mod failed for some reason.");
Utility.UninstallMod = config.Bind<bool>(UTILITY_SECTION, "UninstallMod", false, "WARNING!!! BACKUP YOUR SAVE BEFORE DOING THIS!!! This will not work if mod cannot load properly! If this is true, mod will remove additional slot from all current ILS. This will destroy any items in additional slot To correctly uninstall mod and get vanilla save please follow this steps. Step #1: Set UninstallMod to true. Step #2: Load your save. Step #3: Save your game. Step #4: Exit the game and remove this mod.");
}
}
public static class ModDebug
{
private static ManualLogSource Logger { get; set; }
public static void SetLogger(ManualLogSource logger)
{
Logger = logger;
}
public static void Assert(bool condition)
{
}
public static void Log(object message)
{
Logger.Log((LogLevel)16, message);
}
public static void Error(object message)
{
Logger.Log((LogLevel)2, message);
}
public static void Trace(object message)
{
Logger.Log((LogLevel)16, (object)("DISTR_SPACE_WARP-" + message));
}
public static void LogPlanetType(PlanetData planet)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Expected I4, but got Unknown
EPlanetType type = planet.type;
switch ((int)type)
{
case 5:
Log("Gas");
break;
case 3:
Log("Desert");
break;
case 4:
Log("Ice");
break;
case 2:
Log("Ocean");
break;
case 1:
Log("Vocano");
break;
case 0:
Log("None");
break;
}
}
public static void LogCmdMode(int mode)
{
switch (mode)
{
case -1:
Log("CmdMode: Destruct Mode");
break;
case -2:
Log("CmdMode: Upgrade Mode");
break;
case 1:
Log("CmdMode: Normal Build Mode");
break;
case 2:
Log("CmdMode: Build Mode - Belt");
break;
case 3:
Log("CmdMode: Build Mode - Inserter");
break;
case 4:
Log("CmdMode: Build Mode - Ground");
break;
case 0:
break;
}
}
}
internal static class Patch
{
private static bool ModDisabled
{
get
{
if (!Config.Utility.DisableMod.Value)
{
return Config.Utility.UninstallMod.Value;
}
return true;
}
}
private static bool RemoteTransfer => Config.General.WarperRemoteMode.Value;
public static int WarperTickCount => Config.General.WarperTickCount.Value;
public static int WarperLocalTransportCost => Config.General.WarperLocalTransportCost.Value ? 1 : 0;
public static int WarperRemoteTransportCost => Config.General.WarperRemoteTransportCost.Value;
[HarmonyPatch(typeof(PlanetTransport), "GameTick", new Type[]
{
typeof(long),
typeof(bool),
typeof(bool)
})]
[HarmonyPostfix]
public static void PlanetTransport_GameTick_Postfix(PlanetTransport __instance)
{
if (ModDisabled || Time.frameCount % WarperTickCount != 0)
{
return;
}
int warperId = 1210;
int maxWarperCount = 50;
StationComponent[] stationPool = __instance.stationPool;
List<StationComponent> list = new List<StationComponent>(__instance.stationCursor);
for (int i = 1; i < __instance.stationCursor; i++)
{
StationComponent val = stationPool[i];
if (val != null && val.id == i && !val.isCollector && (val.isStellar || (RemoteTransfer && IsRemoteWarperSupplier(val, warperId))))
{
list.Add(val);
}
}
List<StationComponent> list2 = new List<StationComponent>();
List<StationComponent> list3 = new List<StationComponent>();
foreach (StationComponent item in list)
{
if (IsWarperSupplier(item, warperId))
{
list2.Add(item);
}
else if (NeedsWarpers(item, maxWarperCount))
{
list3.Add(item);
}
}
foreach (StationComponent item2 in list3)
{
TransferWarpersToReceiver(__instance, item2, list2, warperId, maxWarperCount);
}
}
private static bool IsWarperSupplier(StationComponent station, int warperId)
{
if (station.warperCount > 0)
{
return station.storage.Any((StationStore s) => s.itemId == warperId && (int)s.localLogic == 1);
}
return false;
}
private static bool IsRemoteWarperSupplier(StationComponent station, int warperId)
{
return station.storage.Any((StationStore s) => s.itemId == warperId && (int)s.remoteLogic == 1);
}
private static bool NeedsWarpers(StationComponent station, int maxWarperCount)
{
if (station.warperCount < maxWarperCount)
{
return station.warperNecessary;
}
return false;
}
private static void TransferWarpersToReceiver(PlanetTransport planetTransport, StationComponent receiver, List<StationComponent> suppliers, int warperId, int maxWarperCount)
{
int num = maxWarperCount - receiver.warperCount;
if (num <= 0)
{
return;
}
foreach (StationComponent supplier in suppliers)
{
if (supplier.warperCount > 0)
{
int num2 = ((supplier.planetId == receiver.planetId) ? WarperLocalTransportCost : WarperRemoteTransportCost);
int num3 = supplier.warperCount - num2;
int num4 = Mathf.Min(num, num3);
num4 = Mathf.Min(num4, supplier.warperCount - num2);
supplier.warperCount -= num4 + num2;
receiver.warperCount += num4;
receiver.UpdateNeeds();
planetTransport.RefreshStationTraffic(0);
planetTransport.RefreshDispenserTraffic(0);
planetTransport.gameData.galacticTransport.RefreshTraffic(receiver.gid);
num -= num4;
if (num <= 0)
{
break;
}
}
}
}
}
[BepInPlugin("BumpyClock.DSP.DistributeSpaceWarper", "Distribute Space Warper", "1.0.2")]
[BepInProcess("DSPGAME.exe")]
public class Plugin : BaseUnityPlugin
{
private static ManualLogSource _logger;
private const string PluginGuid = "BumpyClock.DSP.DistributeSpaceWarper";
private const string PluginName = "Distribute Space Warper";
private const string PluginVersion = "1.0.2";
public void Awake()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
Harmony val = new Harmony("BumpyClock.DSP.DistributeSpaceWarper");
Config.Init(((BaseUnityPlugin)this).Config);
val.PatchAll(typeof(Plugin));
val.PatchAll(typeof(Patch));
}
public void Start()
{
_logger = ((BaseUnityPlugin)this).Logger;
_logger.LogInfo((object)"Loaded!");
ModDebug.SetLogger(_logger);
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "DistributeSpaceWarper";
public const string PLUGIN_NAME = "DistributeSpaceWarper";
public const string PLUGIN_VERSION = "1.0.0";
}
}