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 HarmonyLib;
using StartCreditsPlus.Patches.StartCredits;
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("StartCreditsPlus")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("StartCreditsPlus")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b3121461-c216-47e1-be21-59b8a01cae66")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace StartCreditsPlus
{
internal class ConfigManager
{
internal ConfigEntry<bool> enableStartingCredits;
internal ConfigEntry<int> startingCredits;
internal ConfigEntry<bool> enableRandomStartCredits;
internal ConfigEntry<int> minRandomStartCredits;
internal ConfigEntry<int> maxRandomStartCredits;
internal ConfigEntry<bool> enableDynamicStartCredits;
internal ConfigEntry<int> dynamicStartCreditIncreasePerPlayer;
internal ConfigEntry<int> minPlayersForDynamicCredits;
internal ConfigEntry<int> maxPlayersForDynamicCredits;
private const string staticStartCreditsSection = "Static Start Credits";
private const string dynamicStartCreditsSection = "Dynamic Start Credits";
private const string randomStartCreditsSection = "Random Start Credits";
private const string enabledKey = "Enabled";
private const string startCreditsKey = "Start Credits";
private const string startCreditIncreasePerPlayerKey = "Start Credit Increase Per Player";
private const string minDynamicCreditPlayersKey = "Min Players";
private const string maxDynamicCreditPlayersKey = "Max Players";
private const string minRandomCreditsKey = "Min Additional Start Credits";
private const string maxRandomCreditsKey = "Max Additional Start Credits";
private readonly string staticStartCreditsEnabledDescription = "If true, \"Static Start Credits\" is applied. Turn this off if you want some other mod to manage start credits.";
private readonly string staticStartCreditsAmountDescription = "Modifies how many credits the crew starts with.\n\nEx. \"1000\" means that you have 1000 credits when you start a new run.\n\nDynamic Start Credits are applied on top of this.\n\nEx. if this setting is 60, Dynamic Start Credits is 15 and there are 3 players, then you would start with 60 + 15 * 3 = 105 credits. \n\nBy default you start with 60 credits in unmodded Lethal Company.";
private readonly string dynamicStartCreditsEnabledDescription = "If true, \"Dynamic Start Credits\" is applied. Turn this off if you want some other mod to manage start credits.";
private readonly string dynamicStartCreditIncreasePerPlayerDescription = "Gives extra credits when someone joins the game for the first time and the crew hasn't landed yet.\n\nHost is included.\n\nThis is based on player count rather than WHO joins. If 2 people join, then it adds the bonus twice and until there are more than 3 people (host + 2), it won't apply the bonus again.";
private readonly string minPlayersForDynamicCreditsDescription = "How many players have to be present in the lobby for dynamic credits to be applied.\n\nEx. 0 means that host counts and this will be applied to the host and any other who joins.\n\nEx. 1 means that someone else other than the host would need to join before we apply the \"Start Credit Increase Per Player\" increase.";
private readonly string maxPlayersForDynamicCreditsDescription = "How many players can be in the lobby before we stop applying the \"Start Credit Increase Per Player\" increase.\n\nEx. 4 would mean that the bonus is applied 4 times, host included. If a 5th person joined, host included, then the bonus would NOT be applied.\n\n-1 Means there is no maximum cap.";
private readonly string randomCreditsEnabledDescription = "If true, the crew will get a random amount of credits.\n\nThis will be applied IN ADDITION to any other credits like \"Static Start Credits\".\n\nIf you just want any random amount, you should set \"Static Start Credits\" to 0.\n\nEx. if \"Static Start Credits\" is 200 and this is in range of -100 to 150, then the starting credits could be from 100 (200 - 100) to 350 (200 + 150).";
private readonly string minRandomCreditsDescription = "Minimum amount of credits the crew starts with.\n\nOnly applies to random credits.";
private readonly string maxRandomCreditsDescription = "Maximum amount of credits the crew starts with.\n\nOnly applies to random credits.";
public ConfigManager()
{
StartCreditsPlusPlugin.logger.LogDebug((object)"Loading config...");
ConfigFile config = ((BaseUnityPlugin)StartCreditsPlusPlugin.Instance).Config;
enableStartingCredits = config.Bind<bool>("Static Start Credits", "Enabled", true, staticStartCreditsEnabledDescription);
startingCredits = config.Bind<int>("Static Start Credits", "Start Credits", 60, staticStartCreditsAmountDescription);
enableRandomStartCredits = config.Bind<bool>("Random Start Credits", "Enabled", false, randomCreditsEnabledDescription);
minRandomStartCredits = config.Bind<int>("Random Start Credits", "Min Additional Start Credits", -60, minRandomCreditsDescription);
maxRandomStartCredits = config.Bind<int>("Random Start Credits", "Max Additional Start Credits", 60, maxRandomCreditsDescription);
enableDynamicStartCredits = config.Bind<bool>("Dynamic Start Credits", "Enabled", true, dynamicStartCreditsEnabledDescription);
dynamicStartCreditIncreasePerPlayer = config.Bind<int>("Dynamic Start Credits", "Start Credit Increase Per Player", 15, dynamicStartCreditIncreasePerPlayerDescription);
minPlayersForDynamicCredits = config.Bind<int>("Dynamic Start Credits", "Min Players", 0, minPlayersForDynamicCreditsDescription);
maxPlayersForDynamicCredits = config.Bind<int>("Dynamic Start Credits", "Max Players", -1, maxPlayersForDynamicCreditsDescription);
((BaseUnityPlugin)StartCreditsPlusPlugin.Instance).Config.SettingChanged += OnSettingChanged;
StartCreditsPlusPlugin.logger.LogDebug((object)"Config loaded!");
}
private void OnSettingChanged(object sender = null, SettingChangedEventArgs args = null)
{
StartCreditsPlusPlugin.logger.LogDebug((object)$"Reloading a config value... [Section: {args.ChangedSetting.Definition.Section}, Value: {args.ChangedSetting.BoxedValue}]");
if (args == null || args.ChangedSetting == null)
{
return;
}
if (args.ChangedSetting.Definition.Section == "Static Start Credits")
{
string key = args.ChangedSetting.Definition.Key;
string text = key;
if (!(text == "Enabled"))
{
if (text == "Start Credits")
{
startingCredits.Value = (int)args.ChangedSetting.BoxedValue;
}
}
else
{
enableStartingCredits.Value = (bool)args.ChangedSetting.BoxedValue;
}
}
else if (args.ChangedSetting.Definition.Section == "Dynamic Start Credits")
{
switch (args.ChangedSetting.Definition.Key)
{
case "Enabled":
enableDynamicStartCredits.Value = (bool)args.ChangedSetting.BoxedValue;
break;
case "Start Credit Increase Per Player":
dynamicStartCreditIncreasePerPlayer.Value = (int)args.ChangedSetting.BoxedValue;
break;
case "Min Players":
minPlayersForDynamicCredits.Value = (int)args.ChangedSetting.BoxedValue;
break;
case "Max Players":
maxPlayersForDynamicCredits.Value = (int)args.ChangedSetting.BoxedValue;
break;
}
}
else if (args.ChangedSetting.Definition.Section == "Random Start Credits")
{
switch (args.ChangedSetting.Definition.Key)
{
case "Enabled":
enableRandomStartCredits.Value = (bool)args.ChangedSetting.BoxedValue;
break;
case "Min Additional Start Credits":
minRandomStartCredits.Value = (int)args.ChangedSetting.BoxedValue;
break;
case "Max Additional Start Credits":
maxRandomStartCredits.Value = (int)args.ChangedSetting.BoxedValue;
break;
}
}
StartCreditsPlusPlugin.logger.LogDebug((object)"Reloading complete!");
}
}
[BepInPlugin("pizzagamer777.StartCreditsPlus", "Start Credits Plus", "1.0.0")]
public class StartCreditsPlusPlugin : BaseUnityPlugin
{
public const string modGUID = "pizzagamer777.StartCreditsPlus";
private const string modName = "Start Credits Plus";
private const string modVersion = "1.0.0";
private readonly Harmony harmony = new Harmony("pizzagamer777.StartCreditsPlus");
private static StartCreditsPlusPlugin _instance;
internal static ManualLogSource logger;
internal static ConfigManager configManager;
internal static StartCreditsPlusPlugin Instance
{
get
{
return _instance;
}
set
{
_instance = value;
}
}
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
logger = Logger.CreateLogSource("pizzagamer777.StartCreditsPlus");
configManager = new ConfigManager();
harmony.PatchAll(typeof(StartCreditsPlusPlugin));
StartCredits.patch(harmony);
}
}
}
namespace StartCreditsPlus.Patches.StartCredits
{
[HarmonyPatch(typeof(Terminal))]
internal class TerminalPatch
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void StartPatch()
{
StartCredits.calculateStartGroupCredits();
}
}
internal class StartCredits
{
private static Terminal _terminal;
private static Terminal Terminal
{
get
{
if ((Object)(object)_terminal == (Object)null)
{
_terminal = Object.FindObjectOfType<Terminal>();
}
return _terminal;
}
set
{
_terminal = value;
}
}
internal static void patch(Harmony harmony)
{
harmony.PatchAll(typeof(TerminalPatch));
harmony.PatchAll(typeof(StartOfRoundPatch));
}
private static int getAppliedDynamicCreditPlayerAmount()
{
string text = "pizzagamer777.StartCreditsPlus.dynamicCreditsPlayerAmount";
return ES3.Load<int>(text, GameNetworkManager.Instance.currentSaveFileName, 0);
}
private static bool canModifyStartCredits()
{
if (StartOfRound.Instance.gameStats.daysSpent != 0)
{
return false;
}
if (!Object.op_Implicit((Object)(object)Terminal))
{
StartCreditsPlusPlugin.logger.LogWarning((object)"Terminal not found! Can't modify start credits.");
return false;
}
if (!GameNetworkManager.Instance.isHostingGame)
{
return false;
}
return true;
}
private static bool canApplyStaticCredits()
{
if (!StartCreditsPlusPlugin.configManager.enableStartingCredits.Value)
{
return false;
}
string text = "pizzagamer777.StartCreditsPlus.appliedStaticCredits";
bool flag = ES3.Load<bool>(text, GameNetworkManager.Instance.currentSaveFileName, false);
return !flag;
}
private static bool canApplyRandomCredits()
{
if (!StartCreditsPlusPlugin.configManager.enableRandomStartCredits.Value)
{
return false;
}
string text = "pizzagamer777.StartCreditsPlus.appliedRandomCredits";
bool flag = ES3.Load<bool>(text, GameNetworkManager.Instance.currentSaveFileName, false);
return !flag;
}
private static bool canApplyDynamicCredits()
{
if (!StartCreditsPlusPlugin.configManager.enableDynamicStartCredits.Value)
{
return false;
}
if (getAppliedDynamicCreditPlayerAmount() >= GameNetworkManager.Instance.connectedPlayers)
{
return false;
}
int value = StartCreditsPlusPlugin.configManager.minPlayersForDynamicCredits.Value;
if (GameNetworkManager.Instance.connectedPlayers <= value)
{
return false;
}
int value2 = StartCreditsPlusPlugin.configManager.maxPlayersForDynamicCredits.Value;
if (GameNetworkManager.Instance.connectedPlayers > value2 && value2 > -1)
{
return false;
}
return true;
}
internal static void reset()
{
if (GameNetworkManager.Instance.isHostingGame)
{
ES3.Save<bool>("pizzagamer777.StartCreditsPlus.appliedStaticCredits", false, GameNetworkManager.Instance.currentSaveFileName);
ES3.Save<bool>("pizzagamer777.StartCreditsPlus.appliedRandomCredits", false, GameNetworkManager.Instance.currentSaveFileName);
ES3.Save<int>("pizzagamer777.StartCreditsPlus.dynamicCreditsPlayerAmount", 0, GameNetworkManager.Instance.currentSaveFileName);
calculateStartGroupCredits();
}
}
internal static void calculateStartGroupCredits()
{
if (canModifyStartCredits())
{
int num = Terminal.groupCredits;
if (canApplyStaticCredits())
{
int value = StartCreditsPlusPlugin.configManager.startingCredits.Value;
num = value;
ES3.Save<bool>("pizzagamer777.StartCreditsPlus.appliedStaticCredits", true, GameNetworkManager.Instance.currentSaveFileName);
}
if (canApplyRandomCredits())
{
int value2 = StartCreditsPlusPlugin.configManager.minRandomStartCredits.Value;
int value3 = StartCreditsPlusPlugin.configManager.maxRandomStartCredits.Value;
int num2 = Random.Range(value2, value3);
num += num2;
ES3.Save<bool>("pizzagamer777.StartCreditsPlus.appliedRandomCredits", true, GameNetworkManager.Instance.currentSaveFileName);
}
if (canApplyDynamicCredits())
{
int value4 = StartCreditsPlusPlugin.configManager.dynamicStartCreditIncreasePerPlayer.Value;
int appliedDynamicCreditPlayerAmount = getAppliedDynamicCreditPlayerAmount();
int num3 = GameNetworkManager.Instance.connectedPlayers - appliedDynamicCreditPlayerAmount;
num += value4 * num3;
int num4 = appliedDynamicCreditPlayerAmount + num3;
ES3.Save<int>("pizzagamer777.StartCreditsPlus.dynamicCreditsPlayerAmount", num4, GameNetworkManager.Instance.currentSaveFileName);
}
if (num != Terminal.groupCredits)
{
Terminal.SyncGroupCreditsServerRpc(num, Terminal.numberOfItemsInDropship);
}
}
}
}
[HarmonyPatch(typeof(StartOfRound))]
internal class StartOfRoundPatch
{
[HarmonyPatch("OnClientConnect")]
[HarmonyPostfix]
private static void OnClientConnectPatch()
{
StartCredits.calculateStartGroupCredits();
}
[HarmonyPatch("ResetShip")]
[HarmonyPostfix]
private static void ResetShipPatch()
{
StartCredits.reset();
}
}
}