using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using QuotaTourney.Patches;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("QuotaTourney")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("QuotaTourney")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ad905924-f5e1-4c12-97b3-cb78bd1cedb3")]
[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 QuotaTournament
{
[BepInPlugin("OreoM.QuotaTournament", "QuotaTournament", "1.0.3")]
public class QuotaTournament : BaseUnityPlugin
{
private const string modGUID = "OreoM.QuotaTournament";
private const string modNAME = "QuotaTournament";
private const string modVERSION = "1.0.3";
private readonly Harmony harmony = new Harmony("OreoM.QuotaTournament");
internal ManualLogSource logger;
private void Awake()
{
logger = Logger.CreateLogSource("OreoM.QuotaTournament");
logger.LogInfo((object)"QuotaTournament 1.0.3 is patching.");
try
{
harmony.PatchAll(typeof(QuotaTournament));
harmony.PatchAll(typeof(StartOfRoundPatch));
harmony.PatchAll(typeof(TerminalPatch));
logger.LogInfo((object)"QuotaTournament 1.0.3 is done patching.");
}
catch (Exception ex)
{
logger.LogInfo((object)"QuotaTournament 1.0.3 failed to patch.");
Debug.LogException(ex);
}
}
}
}
namespace QuotaTourney.Patches
{
[HarmonyPatch(typeof(StartOfRound))]
internal class StartOfRoundPatch
{
[HarmonyPatch("SetShipReadyToLand")]
[HarmonyPostfix]
private static void SetShipReadyToLandPostPatch(ref StartOfRound __instance)
{
if (__instance.overrideRandomSeed)
{
while ((__instance.overrideSeedNumber ^ 0x5F5E100) % 13 == 11 || (__instance.overrideSeedNumber ^ 0x5F5E100) % 13 == 3)
{
__instance.overrideSeedNumber = NextSeed(__instance.overrideSeedNumber);
}
__instance.ChangeLevelServerRpc((__instance.overrideSeedNumber ^ 0x5F5E100) % 13, Object.FindObjectOfType<Terminal>().groupCredits);
}
}
[HarmonyPatch("StartGame")]
[HarmonyPrefix]
private static void StartGamePrePatch(ref StartOfRound __instance)
{
if (TimeOfDay.Instance.daysUntilDeadline == 1)
{
__instance.isChallengeFile = true;
}
}
[HarmonyPatch("ShipHasLeft")]
[HarmonyPostfix]
private static void ShipHasLeftPostPatch(ref StartOfRound __instance)
{
if (__instance.overrideRandomSeed)
{
__instance.overrideSeedNumber = NextSeed(__instance.overrideSeedNumber);
Debug.Log((object)$"Next seed: {__instance.overrideSeedNumber}");
}
__instance.isChallengeFile = false;
}
public static int NextSeed(int seed)
{
return ((seed + 221573299) ^ 0x5F5E100) % 100000000;
}
}
[HarmonyPatch(typeof(Terminal))]
internal class TerminalPatch
{
[HarmonyPatch("ParsePlayerSentence")]
[HarmonyPrefix]
private static void ParsePlayerSentencePrePatch(Terminal __instance)
{
string text = __instance.screenText.text.Substring(__instance.screenText.text.Length - __instance.textAdded);
StringBuilder stringBuilder = new StringBuilder();
string text2 = text;
foreach (char c in text2)
{
if (!char.IsPunctuation(c))
{
stringBuilder.Append(c);
}
}
string[] array = stringBuilder.ToString().ToLower().Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (array[0] == "seed" && int.TryParse(array[1], out var result) && result > 0 && result < 100000000)
{
while ((result ^ 0x5F5E100) % 13 == 11 || (result ^ 0x5F5E100) % 13 == 3)
{
result = StartOfRoundPatch.NextSeed(result);
}
StartOfRound.Instance.ChangeLevelServerRpc((result ^ 0x5F5E100) % 13, Object.FindObjectOfType<Terminal>().groupCredits);
StartOfRound.Instance.overrideRandomSeed = true;
StartOfRound.Instance.overrideSeedNumber = result;
StartOfRound.Instance.randomMapSeed = (result ^ 0x5F5E100) % 100000000;
StartOfRound.Instance.SetPlanetsWeather(0);
Debug.Log((object)$"Seed set: {result}");
}
}
}
}