using System;
using System.Collections;
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 BepInEx.Logging;
using DroneSpeedRocket.patches;
using HarmonyLib;
using SpaceCraft;
using Unity.Netcode;
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("DroneSpeedRocket")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DroneSpeedRocket")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("642bd83d-87c5-4bb7-bbc6-bac6a2dafdda")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace DroneSpeedRocket
{
[BepInPlugin("blue.nova.dronespeedrocket", "DroneSpeedRocket", "1.0.0")]
public class DroneSpeedRocketBase : BaseUnityPlugin
{
public const string modId = "blue.nova.dronespeedrocket";
public const string modName = "DroneSpeedRocket";
public const string modVersion = "1.0.0";
public const string author = "BlueNova";
public static ConfigEntry<float> configDroneSpeed;
public static ConfigEntry<float> configSpeedIncrement;
public static ConfigEntry<bool> configAutoUnlock;
private readonly Harmony harmony = new Harmony("blue.nova.dronespeedrocket");
private static DroneSpeedRocketBase instance;
public static ManualLogSource mls;
private void Awake()
{
if ((Object)(object)instance != (Object)null)
{
Object.Destroy((Object)(object)this);
return;
}
configDroneSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Drone Speed", 20f, "The default speed of the T2 drones. This default value is vanilla.");
configSpeedIncrement = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Speed Increment", 100f, "The amount the drone speed will increase by when a drone speed rocket is launched. Default value is balanced imo.");
configAutoUnlock = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Auto Unlock", false, "If true, the drone speed rocket will be unlocked at the start of the game. Otherwise will be unlocked at 1kg insects.");
instance = this;
mls = ((BaseUnityPlugin)this).Logger;
harmony.PatchAll(typeof(DroneSpeedRocketBase));
harmony.PatchAll(typeof(DroneSpeedSaveManager));
harmony.PatchAll(typeof(DroneSpeedRocket.patches.DroneSpeedRocket));
harmony.PatchAll(typeof(DroneSpeedManager));
((BaseUnityPlugin)this).Logger.LogInfo((object)"DroneSpeedRocket version 1.0.0 by BlueNova has loaded!");
}
}
}
namespace DroneSpeedRocket.patches
{
internal class DroneSpeedManager
{
private const string DRONE_2_CLONE_NAME = "Drone2(Clone)";
private static float droneSpeed = 20f;
private static float defaultSpeed = DroneSpeedRocketBase.configDroneSpeed.Value;
private static float speedIncrament = DroneSpeedRocketBase.configSpeedIncrement.Value;
[HarmonyPrefix]
[HarmonyPatch(typeof(ActionSendInSpace), "HandleRocketMultiplier")]
public static void Prefix(WorldObject worldObjectToSend)
{
Group group = worldObjectToSend.GetGroup();
string id = group.GetId();
if (id == DroneSpeedRocket.getRocketID())
{
IncreaseDroneSpeed();
applySpeedAllFlyingDrones();
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Drone), "Start")]
public static void Patch_Drone_Start(Drone __instance)
{
if ((Object)(object)__instance != (Object)null)
{
ApplySpeedToDrone(__instance);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(MachineDroneStation), "TryToReleaseOneDrone")]
public static void Patch_TryToReleaseOneDrone_Post(GameObject __result)
{
if ((Object)(object)__result == (Object)null)
{
return;
}
Transform val = __result.transform.Find("Drone2(Clone)");
if (!((Object)(object)val == (Object)null))
{
Drone component = ((Component)val).GetComponent<Drone>();
if (!((Object)(object)component == (Object)null))
{
ApplySpeedToDrone(component);
}
}
}
private static void IncreaseDroneSpeed()
{
droneSpeed += speedIncrament;
DroneSpeedSaveManager.saveNewSpeed();
}
private static Array applySpeedAllFlyingDrones()
{
LogisticManager manager = Managers.GetManager<LogisticManager>();
if ((Object)(object)manager != (Object)null)
{
try
{
FieldInfo field = typeof(LogisticManager).GetField("_droneFleet", BindingFlags.Instance | BindingFlags.NonPublic);
if (field != null)
{
List<Drone> list = (List<Drone>)field.GetValue(manager);
if (list != null)
{
Drone[] array = list.ToArray();
foreach (Drone drone in array)
{
ApplySpeedToDrone(drone);
}
}
}
else
{
DroneSpeedRocketBase.mls.LogError((object)"_droneFleet field not found in LogisticManager.");
}
}
catch (Exception ex)
{
DroneSpeedRocketBase.mls.LogError((object)("Error accessing drone fleet: " + ex.ToString()));
}
}
else
{
DroneSpeedRocketBase.mls.LogError((object)"LogisticManager not found.");
}
return null;
}
private static void ApplySpeedToDrone(Drone drone)
{
drone.forwardSpeed = droneSpeed;
drone.rotationSpeed = droneSpeed;
drone.distanceMinToTarget = 5f;
}
public static float getDroneSpeed()
{
return droneSpeed;
}
public static void setDroneSpeed(float speed)
{
droneSpeed = speed;
applySpeedAllFlyingDrones();
}
public static void resetDroneSpeed(bool apply)
{
droneSpeed = defaultSpeed;
if (apply)
{
applySpeedAllFlyingDrones();
}
}
}
internal class DroneSpeedRocket
{
private const string ROCKET_ID = "RocketDroneSpeed1";
[HarmonyPrefix]
[HarmonyPatch(typeof(StaticDataHandler), "LoadStaticData")]
public static void Patch_LoadStaticData(List<GroupData> ___groupsData)
{
for (int num = ___groupsData.Count - 1; num >= 0; num--)
{
GroupData val = ___groupsData[num];
if ((Object)(object)val == (Object)null || ((Object)(object)val.associatedGameObject == (Object)null && val.id.Equals("RocketDroneSpeed1")))
{
___groupsData.RemoveAt(num);
}
}
GroupData item = addCustomRocketToGameData(___groupsData);
___groupsData.Add(item);
DroneSpeedRocketBase.mls.LogInfo((object)"Added RocketDroneSpeed1");
}
private static GroupData addCustomRocketToGameData(List<GroupData> groupsData)
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Expected O, but got Unknown
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Expected O, but got Unknown
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Expected O, but got Unknown
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Expected O, but got Unknown
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Expected O, but got Unknown
//IL_0103: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Expected O, but got Unknown
//IL_012e: Unknown result type (might be due to invalid IL or missing references)
GroupDataItem val = (GroupDataItem)Object.Instantiate<GroupData>(groupsData.Find((GroupData data) => data.id == "RocketMap1"));
GroupDataItem val2 = (GroupDataItem)groupsData.Find((GroupData data) => data.id == "CircuitBoard1");
GroupDataItem val3 = (GroupDataItem)groupsData.Find((GroupData data) => data.id == "FusionEnergyCell");
GroupDataItem val4 = (GroupDataItem)groupsData.Find((GroupData data) => data.id == "RocketReactor");
GroupDataItem val5 = (GroupDataItem)groupsData.Find((GroupData data) => data.id == "Rod-alloy");
GroupDataItem val6 = (GroupDataItem)groupsData.Find((GroupData data) => data.id == "Rod-osmium");
((GroupData)val).id = "RocketDroneSpeed1";
((Object)val).name = "Drone Speed Rocket";
((GroupData)val).unlockingValue = 1000f;
((GroupData)val).unlockingWorldUnit = (WorldUnitType)8;
((GroupData)val).associatedGameObject = Object.Instantiate<GameObject>(((GroupData)val).associatedGameObject);
((Object)((GroupData)val).associatedGameObject).name = "Drone Speed Rocket";
((GroupData)val).recipeIngredients = new List<GroupDataItem>();
((GroupData)val).recipeIngredients.Add(Object.Instantiate<GroupDataItem>(val3));
((GroupData)val).recipeIngredients.Add(Object.Instantiate<GroupDataItem>(val2));
((GroupData)val).recipeIngredients.Add(Object.Instantiate<GroupDataItem>(val5));
((GroupData)val).recipeIngredients.Add(Object.Instantiate<GroupDataItem>(val6));
((GroupData)val).recipeIngredients.Add(Object.Instantiate<GroupDataItem>(val5));
((GroupData)val).recipeIngredients.Add(Object.Instantiate<GroupDataItem>(val4));
return (GroupData)(object)val;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UnlockedGroupsHandler), "SetUnlockedGroups")]
public static void unlockRocket(NetworkList<int> ____unlockedGroups)
{
if (DroneSpeedRocketBase.configAutoUnlock.Value)
{
string text = "RocketDroneSpeed1";
Group groupViaId = GroupsHandler.GetGroupViaId(text);
DroneSpeedRocketBase.mls.LogInfo((object)("Unlocking " + text));
____unlockedGroups.Add(groupViaId.stableHashCode);
}
}
public static string getRocketID()
{
return "RocketDroneSpeed1";
}
}
internal class DroneSpeedSaveManager
{
[CompilerGenerated]
private sealed class <WaitForProceduralInstances>d__4 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public PlanetLoader __instance;
private Group <gr>5__1;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <WaitForProceduralInstances>d__4(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<gr>5__1 = null;
<>1__state = -2;
}
private bool MoveNext()
{
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
break;
case 1:
<>1__state = -1;
break;
}
if (!__instance.GetIsLoaded())
{
<>2__current = null;
<>1__state = 1;
return true;
}
myModStorage = WorldObjectsHandler.Instance.GetWorldObjectViaId(218151451);
if (myModStorage == null)
{
<gr>5__1 = GroupsHandler.GetGroupViaId("Iron");
myModStorage = WorldObjectsHandler.Instance.CreateNewWorldObject(<gr>5__1, 218151451, (GameObject)null, true);
DroneSpeedManager.resetDroneSpeed(apply: true);
SaveDroneSpeedToWorldObject();
myModStorage.SetDontSaveMe(false);
<gr>5__1 = null;
}
DroneSpeedRocketBase.mls.LogInfo((object)("Loaded drone speed is:" + LoadDroneSpeedFromWorldObject()));
DroneSpeedManager.setDroneSpeed(LoadDroneSpeedFromWorldObject());
return false;
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
private const int myModStorageId = 218151451;
private const string DRONE_SPEED_PREFIX = "droneSpeed:";
private static WorldObject myModStorage;
[HarmonyPostfix]
[HarmonyPatch(typeof(PlanetLoader), "HandleDataAfterLoad")]
private static void Patch_PlanetLoader_HandleDataAfterLoad(PlanetLoader __instance)
{
((MonoBehaviour)__instance).StartCoroutine(WaitForProceduralInstances(__instance));
}
[IteratorStateMachine(typeof(<WaitForProceduralInstances>d__4))]
private static IEnumerator WaitForProceduralInstances(PlanetLoader __instance)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <WaitForProceduralInstances>d__4(0)
{
__instance = __instance
};
}
[HarmonyPrefix]
[HarmonyPatch(typeof(UiWindowPause), "OnQuit")]
private static void Patch_UiWindowPause_OnQuit()
{
SaveDroneSpeedToWorldObject();
DroneSpeedRocketBase.mls.LogInfo((object)("Saved drone speed is:" + LoadDroneSpeedFromWorldObject()));
DroneSpeedManager.resetDroneSpeed(apply: false);
}
private static void SaveDroneSpeedToWorldObject()
{
myModStorage.SetText("droneSpeed:" + DroneSpeedManager.getDroneSpeed());
}
private static float LoadDroneSpeedFromWorldObject()
{
float result = 20f;
string text = myModStorage.GetText();
if (text != null && text.StartsWith("droneSpeed:"))
{
text = text.Substring(11);
result = float.Parse(text);
}
return result;
}
public static void saveNewSpeed()
{
SaveDroneSpeedToWorldObject();
}
}
}