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 UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ScalingStartCredits")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ScalingStartCredits")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("332290fd-f4f6-4b02-b7e1-e4a770a28895")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ScalingStartCredits
{
[BepInPlugin("zg.scalingstartingcredits", "Scaling Start Credits", "1.0.6")]
public class ScalingStartCreditsMain : BaseUnityPlugin
{
public const string modGUID = "zg.scalingstartingcredits";
public const string modName = "Scaling Start Credits";
public const string modVersion = "1.0.6";
private readonly Harmony harmony = new Harmony("zg.scalingstartingcredits");
public static ScalingStartCreditsMain Instance;
internal ManualLogSource pnt;
public ConfigEntry<int> configCreditIncrement;
public ConfigEntry<int> configPlayerCountThreshold;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
BindConfiguration();
pnt = Logger.CreateLogSource("zg.scalingstartingcredits");
pnt.LogInfo((object)"Scaling Start Credits Enabled");
pnt.LogInfo((object)"Credit to sunnobunno for the original mod");
harmony.PatchAll();
}
private void BindConfiguration()
{
configCreditIncrement = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Credit Increment", 15, "The amount of credits per player added to the starting group credits");
configPlayerCountThreshold = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Player Threshold", 4, "The number of players required in the lobby before credits are added per new player.");
}
}
}
namespace ScalingStartCredits.Patches
{
[HarmonyPatch(typeof(StartMatchLever))]
internal class StartingCreditsPatch
{
private static ManualLogSource mls = Logger.CreateLogSource("zg.scalingstartingcredits");
private static int groupCreditIncreaseIncrement;
private static int playerThreshold;
private static int playerCount;
private static int days;
private static HUDManager hudManager;
[HarmonyPatch("StartGame")]
[HarmonyPrefix]
private static void StartMatchLeverPatch(ref StartOfRound ___playersManager)
{
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Expected O, but got Unknown
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Expected O, but got Unknown
groupCreditIncreaseIncrement = ScalingStartCreditsMain.Instance.configCreditIncrement.Value;
playerThreshold = ScalingStartCreditsMain.Instance.configPlayerCountThreshold.Value;
playerCount = ___playersManager.fullyLoadedPlayers.Count;
days = ___playersManager.gameStats.daysSpent;
bool flag = true;
mls.LogInfo((object)$"Days: {days}");
mls.LogInfo((object)$"Player Count: {playerCount}");
if (days != 0)
{
mls.LogInfo((object)"No longer first day. Aborting");
flag = false;
}
if (playerCount <= playerThreshold && flag)
{
mls.LogInfo((object)"Player threshold not met. Aborting");
flag = false;
}
if (flag)
{
hudManager = (HUDManager)Object.FindObjectOfType(typeof(HUDManager));
Terminal val = (Terminal)Object.FindObjectOfType(typeof(Terminal));
int num = playerCount - playerThreshold;
int num2 = num * groupCreditIncreaseIncrement;
int num3 = val.groupCredits + num2;
val.SyncGroupCreditsServerRpc(num3, val.numberOfItemsInDropship);
mls.LogInfo((object)$"Credits Added for {num} players above threshold of {playerThreshold}: {num2}");
mls.LogInfo((object)$"Group Credits: {val.groupCredits}");
hudManager.AddTextToChatOnServer($"Credits Added for {num} players above threshold of {playerThreshold}: {num2}", -1);
hudManager.AddTextToChatOnServer($"Group Credits: {val.groupCredits}", -1);
}
}
}
}