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.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LCRandomMoons.Patches;
using LethalLevelLoader;
using LethalModDataLib.Attributes;
using TerminalApi;
using TerminalApi.Classes;
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("LCRandomMoons")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LCRandomMoons")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("85ac1375-455d-40e2-91d0-7508359ee71d")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LCRandomMoons
{
[BepInPlugin("KF.LCRandomMoons", "RandomMoons", "1.1.1")]
public class ModBase : BaseUnityPlugin
{
public const string modGUID = "KF.LCRandomMoons";
private const string modName = "RandomMoons";
private const string modVersion = "1.1.1";
private readonly Harmony harmony = new Harmony("KF.LCRandomMoons");
public static ModBase Instance;
public static ManualLogSource Logger;
private static ConfigFile configFile;
public static void InitConfig()
{
StartOfRoundPatch.Blacklist = configFile.Bind<string>("Global", "Blacklist moons", "Liquidation,Embrion,Galetry,Gordion", "Moons that will never make the roster. ").Value;
StartOfRoundPatch.RandomDailyMoon = configFile.Bind<bool>("Random Daily Moon", "Enable daily moon", false, "Random moon every day within the selected route.").Value;
StartOfRoundPatch.RandomDailyMoonRepeat = configFile.Bind<bool>("Random Daily Moon", "Block repeats", true, "When “Random Daily Moon” enable, prevents the same moon from repeating.").Value;
StartOfRoundPatch.CompanyName = configFile.Bind<string>("Random Daily Moon", "Company moon", "Gordion", "When “Random Daily Moon” enable, the last day of the quota will send a ship to that moon.").Value;
StartOfRoundPatch.LowMinPrice = configFile.Bind<int>("Range price", "Low min", 1, "Minimum moon cost to get on the route").Value;
StartOfRoundPatch.LowMaxPrice = configFile.Bind<int>("Range price", "Low max", 500, "Maximum moon cost to get on the route").Value;
StartOfRoundPatch.MidMinPrice = configFile.Bind<int>("Range price", "Mid min", 501, "Minimum moon cost to get on the route").Value;
StartOfRoundPatch.MidMaxPrice = configFile.Bind<int>("Range price", "Mid max", 1500, "Maximum moon cost to get on the route").Value;
StartOfRoundPatch.HighMinPrice = configFile.Bind<int>("Range price", "High min", 1501, "Minimum moon cost to get on the route").Value;
StartOfRoundPatch.HighMaxPrice = configFile.Bind<int>("Range price", "High max", 10000, "Maximum moon cost to get on the route").Value;
StartOfRoundPatch.CustomPriceAll = configFile.Bind<bool>("Custom Price", "All set manual price", false, "You can manually set the cost All route").Value;
StartOfRoundPatch.AllPrice = configFile.Bind<int>("Custom Price", "All route price", 0, "Cost of Free route").Value;
StartOfRoundPatch.CustomPriceFree = configFile.Bind<bool>("Custom Price", "Free set manual price", false, "You can manually set the cost Free route").Value;
StartOfRoundPatch.FreePrice = configFile.Bind<int>("Custom Price", "Free route price", 0, "Cost of All route").Value;
StartOfRoundPatch.CustomPriceLow = configFile.Bind<bool>("Custom Price", "Low set manual price", false, "You can manually set the cost Low route").Value;
StartOfRoundPatch.LowPrice = configFile.Bind<int>("Custom Price", "Low route price", 0, "Cost of Low route").Value;
StartOfRoundPatch.CustomPriceMid = configFile.Bind<bool>("Custom Price", "Mid set manual price", false, "You can manually set the cost Mid route").Value;
StartOfRoundPatch.MidPrice = configFile.Bind<int>("Custom Price", "Mid route price", 0, "Cost of Mid route").Value;
StartOfRoundPatch.CustomPriceHigh = configFile.Bind<bool>("Custom Price", "High set manual price", false, "You can manually set the cost High route").Value;
StartOfRoundPatch.HighPrice = configFile.Bind<int>("Custom Price", "High route price", 0, "Cost of High route").Value;
}
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
Logger = Logger.CreateLogSource("KF.LCRandomMoons");
configFile = ((BaseUnityPlugin)this).Config;
InitConfig();
harmony.PatchAll(typeof(ModBase));
harmony.PatchAll(typeof(StartOfRoundPatch));
}
}
}
namespace LCRandomMoons.Patches
{
[HarmonyPatch(typeof(StartOfRound))]
public class StartOfRoundPatch : NetworkBehaviour
{
private static List<ExtendedLevel> _allMoons = PatchedContent.ExtendedLevels;
private static List<ExtendedLevel> _freeMoons = new List<ExtendedLevel>();
private static List<ExtendedLevel> _lowMoons = new List<ExtendedLevel>();
private static List<ExtendedLevel> _midMoons = new List<ExtendedLevel>();
private static List<ExtendedLevel> _highMoons = new List<ExtendedLevel>();
private static List<ExtendedLevel> _lastRoute;
[ModData(/*Could not decode attribute arguments.*/)]
private static string _lastRouteCategory;
private static readonly Dictionary<string, List<ExtendedLevel>> RouteCategories = new Dictionary<string, List<ExtendedLevel>>
{
{ "free", _freeMoons },
{ "low", _lowMoons },
{ "mid", _midMoons },
{ "high", _highMoons },
{ "all", _allMoons }
};
public static string CompanyName;
private static ExtendedLevel _company;
public static string Blacklist;
private static string[] _blacklistArray;
public static bool RandomDailyMoon;
public static bool RandomDailyMoonRepeat;
public static bool CustomPriceAll;
public static int AllPrice;
public static bool CustomPriceFree;
public static int FreePrice;
public static bool CustomPriceLow;
public static int LowPrice;
public static int LowMinPrice;
public static int LowMaxPrice;
public static bool CustomPriceMid;
public static int MidPrice;
public static int MidMinPrice;
public static int MidMaxPrice;
public static bool CustomPriceHigh;
public static int HighPrice;
public static int HighMinPrice;
public static int HighMaxPrice;
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void SetAllMoonsList()
{
_freeMoons.Clear();
_lowMoons.Clear();
_midMoons.Clear();
_highMoons.Clear();
ModBase.InitConfig();
_blacklistArray = Blacklist.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
foreach (ExtendedLevel allMoon in _allMoons)
{
if (CompanyName == allMoon.NumberlessPlanetName)
{
_company = allMoon;
}
if (!_blacklistArray.Contains(allMoon.NumberlessPlanetName))
{
if (allMoon.RoutePrice == 0)
{
_freeMoons.Add(allMoon);
}
if (allMoon.RoutePrice >= LowMinPrice && allMoon.RoutePrice <= LowMaxPrice)
{
_lowMoons.Add(allMoon);
}
if (allMoon.RoutePrice >= MidMinPrice && allMoon.RoutePrice <= MidMaxPrice)
{
_midMoons.Add(allMoon);
}
if (allMoon.RoutePrice >= HighMinPrice && allMoon.RoutePrice <= HighMaxPrice)
{
_highMoons.Add(allMoon);
}
}
}
if (!CustomPriceAll)
{
AllPrice = GetLevelsPrice(_allMoons);
}
if (!CustomPriceFree)
{
FreePrice = GetLevelsPrice(_freeMoons);
}
if (!CustomPriceLow)
{
LowPrice = GetLevelsPrice(_lowMoons);
}
if (!CustomPriceMid)
{
MidPrice = GetLevelsPrice(_midMoons);
}
if (!CustomPriceHigh)
{
HighPrice = GetLevelsPrice(_highMoons);
}
List<ExtendedLevel> value;
if (string.IsNullOrEmpty(_lastRouteCategory))
{
SetLastRoute(_freeMoons);
}
else if (RouteCategories.TryGetValue(_lastRouteCategory, out value))
{
SetLastRoute(value);
}
else
{
ModBase.Logger.LogError((object)("Invalid route category: " + _lastRouteCategory));
SetLastRoute(_freeMoons);
}
TerminalAPI();
DebugLog();
}
[HarmonyPatch("SetShipReadyToLand")]
[HarmonyPostfix]
private static void RandomDailyMoonR()
{
if (!RandomDailyMoon)
{
return;
}
ModBase.Logger.LogInfo((object)"[RandomDailyMoon] Enable: true");
string numberlessPlanetName = LevelManager.CurrentExtendedLevel.NumberlessPlanetName;
ModBase.Logger.LogInfo((object)("[RandomDailyMoon] Current moon: " + numberlessPlanetName));
if (_blacklistArray.Contains(numberlessPlanetName))
{
ModBase.Logger.LogInfo((object)"[RandomDailyMoon] Auto-travel from blacklisted moon forbidden");
return;
}
if (TimeOfDay.Instance.daysUntilDeadline == 3)
{
SetLastRoute(_freeMoons);
ModBase.Logger.LogInfo((object)"[RandomDailyMoon] First Day Quota. Auto-travel disabled.");
return;
}
PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
if ((Object)(object)localPlayerController == (Object)null || !((NetworkBehaviour)localPlayerController).IsHost || !StartOfRound.Instance.CanChangeLevels())
{
ModBase.Logger.LogInfo((object)"[RandomDailyMoon] Can't change levels");
return;
}
bool flag = TimeOfDay.Instance.daysUntilDeadline == 0;
ExtendedLevel val = (flag ? _company : GetRandomMoon(_lastRoute));
if (RandomDailyMoonRepeat && (Object)(object)val != (Object)(object)_company)
{
int num = 0;
while ((Object)(object)val == (Object)(object)LevelManager.CurrentExtendedLevel && num < 10)
{
val = GetRandomMoon(_lastRoute);
num++;
}
if (num >= 10)
{
ModBase.Logger.LogWarning((object)"[RandomDailyMoon] Failed to find unique moon after 10 attempts");
}
}
ModBase.Logger.LogInfo((object)("[RandomDailyMoon] Next moon: " + val.NumberlessPlanetName + " " + (flag ? "(Last Day)" : "")));
Terminal val2 = Object.FindObjectOfType<Terminal>();
val2.SyncGroupCreditsServerRpc(val2.groupCredits, val2.numberOfItemsInDropship);
StartOfRound.Instance.ChangeLevelServerRpc(val.SelectableLevel.levelID, val2.groupCredits);
}
public static string SetMoon(List<ExtendedLevel> moonlist, int moonlistListPrice, string routeName)
{
//IL_013c: Unknown result type (might be due to invalid IL or missing references)
PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
if ((Object)(object)localPlayerController == (Object)null || !((NetworkBehaviour)localPlayerController).IsHost || !StartOfRound.Instance.CanChangeLevels())
{
return "\n Only the Host can set the route \n You must be on orbit \n\n";
}
SetLastRoute(moonlist);
ExtendedLevel randomMoon = GetRandomMoon(moonlist);
if ((Object)(object)randomMoon == (Object)null)
{
return " \n " + routeName + " list not contain moons \n\n";
}
Terminal val = Object.FindObjectOfType<Terminal>();
if (val.groupCredits < moonlistListPrice)
{
return $"Not enough credits! Need {moonlistListPrice}, have {val.groupCredits} \n\n";
}
val.groupCredits -= moonlistListPrice;
val.SyncGroupCreditsServerRpc(val.groupCredits, val.numberOfItemsInDropship);
StartOfRound.Instance.ChangeLevelServerRpc(randomMoon.SelectableLevel.levelID, val.groupCredits);
return $"\n Route: {routeName} ({moonlistListPrice}) \n\n " + "The ship is headed to the [" + randomMoon.NumberlessPlanetName + "] \n\n RiskLevel: " + randomMoon.SelectableLevel.riskLevel + " \n " + $"Weather: {randomMoon.SelectableLevel.currentWeather} \n\n";
}
public static void SetLastRoute(List<ExtendedLevel> route)
{
_lastRoute = route;
_lastRouteCategory = RouteCategories.FirstOrDefault((KeyValuePair<string, List<ExtendedLevel>> x) => x.Value == route).Key;
}
public static int GetLevelsPrice(List<ExtendedLevel> Levels)
{
int num = 0;
int num2 = 0;
if (Levels.Count != 0)
{
foreach (ExtendedLevel Level in Levels)
{
if (Level.RoutePrice > 0)
{
num += Level.RoutePrice;
num2++;
}
}
if (num2 != 0)
{
num /= num2;
}
}
return num;
}
public static ExtendedLevel GetRandomMoon(List<ExtendedLevel> moonlist)
{
if (moonlist.Count == 0)
{
return null;
}
Random random = new Random();
int index = random.Next(moonlist.Count);
return moonlist[index];
}
public static string GetMoonsList()
{
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Invalid comparison between Unknown and I4
//IL_0174: Unknown result type (might be due to invalid IL or missing references)
//IL_017a: Invalid comparison between Unknown and I4
//IL_0248: Unknown result type (might be due to invalid IL or missing references)
//IL_024e: Invalid comparison between Unknown and I4
//IL_031c: Unknown result type (might be due to invalid IL or missing references)
//IL_0322: Invalid comparison between Unknown and I4
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("Selected route: " + _lastRouteCategory);
stringBuilder.AppendLine();
stringBuilder.AppendLine($"All Route: {AllPrice} credits");
stringBuilder.AppendLine("-------------------------");
stringBuilder.AppendLine("*all*");
stringBuilder.AppendLine();
stringBuilder.AppendLine($"Free Levels: {FreePrice} credits");
stringBuilder.AppendLine("-------------------------");
foreach (ExtendedLevel freeMoon in _freeMoons)
{
string text = "";
if ((int)freeMoon.SelectableLevel.currentWeather != -1)
{
text = " (" + ((object)(LevelWeatherType)(ref freeMoon.SelectableLevel.currentWeather)).ToString() + ")";
}
stringBuilder.AppendLine(freeMoon.SelectableLevel.riskLevel + " " + freeMoon.NumberlessPlanetName + text);
}
stringBuilder.AppendLine();
stringBuilder.AppendLine($"Low Route: {LowPrice} credits");
stringBuilder.AppendLine("-------------------------");
foreach (ExtendedLevel lowMoon in _lowMoons)
{
string text2 = "";
if ((int)lowMoon.SelectableLevel.currentWeather != -1)
{
text2 = " (" + ((object)(LevelWeatherType)(ref lowMoon.SelectableLevel.currentWeather)).ToString() + ")";
}
stringBuilder.AppendLine(lowMoon.SelectableLevel.riskLevel + " " + lowMoon.NumberlessPlanetName + text2);
}
stringBuilder.AppendLine();
stringBuilder.AppendLine($"Mid Route: {MidPrice} credits");
stringBuilder.AppendLine("-------------------------");
foreach (ExtendedLevel midMoon in _midMoons)
{
string text3 = "";
if ((int)midMoon.SelectableLevel.currentWeather != -1)
{
text3 = " (" + ((object)(LevelWeatherType)(ref midMoon.SelectableLevel.currentWeather)).ToString() + ")";
}
stringBuilder.AppendLine(midMoon.SelectableLevel.riskLevel + " " + midMoon.NumberlessPlanetName + text3);
}
stringBuilder.AppendLine();
stringBuilder.AppendLine($"High Route: {HighPrice} credits");
stringBuilder.AppendLine("-------------------------");
foreach (ExtendedLevel highMoon in _highMoons)
{
string text4 = "";
if ((int)highMoon.SelectableLevel.currentWeather != -1)
{
text4 = " (" + ((object)(LevelWeatherType)(ref highMoon.SelectableLevel.currentWeather)).ToString() + ")";
}
stringBuilder.AppendLine(highMoon.SelectableLevel.riskLevel + " " + highMoon.NumberlessPlanetName + text4);
}
return stringBuilder.ToString() + "\n\n";
}
private static void TerminalAPI()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Expected O, but got Unknown
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Expected O, but got Unknown
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Expected O, but got Unknown
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0110: Expected O, but got Unknown
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_0141: Unknown result type (might be due to invalid IL or missing references)
//IL_0154: Expected O, but got Unknown
//IL_015a: Unknown result type (might be due to invalid IL or missing references)
//IL_015f: Unknown result type (might be due to invalid IL or missing references)
//IL_0185: Unknown result type (might be due to invalid IL or missing references)
//IL_0198: Expected O, but got Unknown
//IL_019e: Unknown result type (might be due to invalid IL or missing references)
//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
//IL_01dc: Expected O, but got Unknown
//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
//IL_020d: Unknown result type (might be due to invalid IL or missing references)
//IL_0220: Expected O, but got Unknown
TerminalApi.AddCommand("rd help", new CommandInfo
{
DisplayTextSupplier = delegate
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("Syntax: rd <command>");
stringBuilder.AppendLine("");
stringBuilder.AppendLine("help - display available commands");
stringBuilder.AppendLine("list - display list all the moons by category");
stringBuilder.AppendLine("route - display selected route");
stringBuilder.AppendLine("");
stringBuilder.AppendLine("all - select random moon from [all] route");
stringBuilder.AppendLine("free - select random moon from [free] route");
stringBuilder.AppendLine("low - select random moon from [low] route");
stringBuilder.AppendLine("mid - select random moon from [mid] route");
stringBuilder.AppendLine("high - select random moon from [high] route");
stringBuilder.AppendLine("");
stringBuilder.AppendLine("Example: \"rd mid\" travels ship to a random moon from route \"mid\"");
stringBuilder.AppendLine("\n");
return stringBuilder.ToString();
},
Category = "Other"
}, (string)null, true);
TerminalApi.AddCommand("rd list", new CommandInfo
{
DisplayTextSupplier = () => GetMoonsList(),
Category = "Other"
}, (string)null, true);
TerminalApi.AddCommand("rd route", new CommandInfo
{
DisplayTextSupplier = () => "Selected route: " + _lastRouteCategory + "\n\n",
Category = "Other"
}, (string)null, true);
TerminalApi.AddCommand("rd all", new CommandInfo
{
DisplayTextSupplier = () => SetMoon(_allMoons, AllPrice, "[All]"),
Category = "Other"
}, (string)null, true);
TerminalApi.AddCommand("rd free", new CommandInfo
{
DisplayTextSupplier = () => SetMoon(_freeMoons, FreePrice, "[Free]"),
Category = "Other"
}, (string)null, true);
TerminalApi.AddCommand("rd low", new CommandInfo
{
DisplayTextSupplier = () => SetMoon(_lowMoons, LowPrice, "[Low]"),
Category = "Other"
}, (string)null, true);
TerminalApi.AddCommand("rd mid", new CommandInfo
{
DisplayTextSupplier = () => SetMoon(_midMoons, MidPrice, "[Mid]"),
Category = "Other"
}, (string)null, true);
TerminalApi.AddCommand("rd high", new CommandInfo
{
DisplayTextSupplier = () => SetMoon(_highMoons, HighPrice, "[High]"),
Category = "Other"
}, (string)null, true);
}
public static void DebugLog()
{
ModBase.Logger.LogInfo((object)$"All Route: {AllPrice} credits");
ModBase.Logger.LogInfo((object)"");
ModBase.Logger.LogInfo((object)$"Free Route: {FreePrice} credits");
ModBase.Logger.LogInfo((object)"-------------------------");
foreach (ExtendedLevel freeMoon in _freeMoons)
{
ModBase.Logger.LogInfo((object)(freeMoon.NumberlessPlanetName + " Pr: " + freeMoon.RoutePrice + " ID: " + freeMoon.SelectableLevel.levelID));
}
ModBase.Logger.LogInfo((object)"-------------------------");
ModBase.Logger.LogInfo((object)"");
ModBase.Logger.LogInfo((object)$"Low Route: {LowPrice} credits");
ModBase.Logger.LogInfo((object)"-------------------------");
foreach (ExtendedLevel lowMoon in _lowMoons)
{
ModBase.Logger.LogInfo((object)(lowMoon.NumberlessPlanetName + " Pr: " + lowMoon.RoutePrice + " ID: " + lowMoon.SelectableLevel.levelID));
}
ModBase.Logger.LogInfo((object)"-------------------------");
ModBase.Logger.LogInfo((object)"");
ModBase.Logger.LogInfo((object)$"Mid Route: {MidPrice} credits");
ModBase.Logger.LogInfo((object)"-------------------------");
foreach (ExtendedLevel midMoon in _midMoons)
{
ModBase.Logger.LogInfo((object)(midMoon.NumberlessPlanetName + " Pr: " + midMoon.RoutePrice + " ID: " + midMoon.SelectableLevel.levelID));
}
ModBase.Logger.LogInfo((object)"-------------------------");
ModBase.Logger.LogInfo((object)"");
ModBase.Logger.LogInfo((object)$"High Route: {HighPrice} credits");
ModBase.Logger.LogInfo((object)"-------------------------");
foreach (ExtendedLevel highMoon in _highMoons)
{
ModBase.Logger.LogInfo((object)(highMoon.NumberlessPlanetName + " Pr: " + highMoon.RoutePrice + " ID: " + highMoon.SelectableLevel.levelID));
}
ModBase.Logger.LogInfo((object)"-------------------------");
ModBase.Logger.LogInfo((object)"");
}
}
}