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 BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
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("CurseOfEmbrion")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CurseOfEmbrion")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("8fa82371-2f2d-46f1-9f7f-aa36ef467f88")]
[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 CurseOfEmbrion
{
internal class ConfigManager
{
public static ConfigEntry<int> curseChance;
public static ConfigEntry<bool> onlyBirdsOnCurse;
public static void Init()
{
curseChance = ((BaseUnityPlugin)CurseOfEmbrionMod.instance).Config.Bind<int>("General Settings", "curseChance", 10, "The chance for the curse to apply each moon. Can be set to a minimum of 0 (never occurs) and a maximum of 100 (always occurs).");
onlyBirdsOnCurse = ((BaseUnityPlugin)CurseOfEmbrionMod.instance).Config.Bind<bool>("General Settings", "onlyBirdsOnCurse", false, "Forces all outside enemies to be Old Birds when the curse is present.");
}
}
[BepInPlugin("eXish.CurseOfEmbrion", "CurseOfEmbrion", "1.1.1")]
public class CurseOfEmbrionMod : BaseUnityPlugin
{
private const string mGUID = "eXish.CurseOfEmbrion";
private const string mName = "CurseOfEmbrion";
private const string mVersion = "1.1.1";
private readonly Harmony harmony = new Harmony("eXish.CurseOfEmbrion");
internal static CurseOfEmbrionMod instance;
internal static List<SpawnableEnemyWithRarity> outsideEnemies;
internal static string levelDescription;
internal static int outsidePowerCount;
private void Awake()
{
if ((Object)(object)instance == (Object)null)
{
instance = this;
}
ConfigManager.Init();
if (ConfigManager.curseChance.Value < 0 || ConfigManager.curseChance.Value > 100)
{
((BaseUnityPlugin)instance).Logger.LogWarning((object)$"The value \"{ConfigManager.curseChance.Value}\" is not valid for setting \"curseChance\"! The default will be used instead.");
}
harmony.PatchAll();
((BaseUnityPlugin)instance).Logger.LogInfo((object)"CurseOfEmbrion-1.1.1 loaded!");
}
}
}
namespace CurseOfEmbrion.Patches
{
[HarmonyPatch(typeof(StartOfRound))]
internal class StartOfRoundPatch
{
[HarmonyPatch("StartGame")]
[HarmonyPrefix]
private static void StartGamePatch(StartOfRound __instance)
{
if (!((NetworkBehaviour)__instance).IsHost)
{
return;
}
int num = ConfigManager.curseChance.Value;
if (num < 0 || num > 100)
{
num = (int)((ConfigEntryBase)ConfigManager.curseChance).DefaultValue;
}
if (!(__instance.currentLevel.PlanetName != "71 Gordion") || Random.Range(1, 101) > num)
{
return;
}
bool flag = false;
CurseOfEmbrionMod.levelDescription = __instance.currentLevel.LevelDescription;
SelectableLevel currentLevel = __instance.currentLevel;
currentLevel.LevelDescription += "\n\n<color=red>Curse of Embrion</color>";
CurseOfEmbrionMod.outsidePowerCount = __instance.currentLevel.maxOutsideEnemyPowerCount;
__instance.currentLevel.maxOutsideEnemyPowerCount = __instance.levels[12].maxOutsideEnemyPowerCount;
CurseOfEmbrionMod.outsideEnemies = __instance.currentLevel.OutsideEnemies.ToList();
for (int i = 0; i < __instance.currentLevel.OutsideEnemies.Count; i++)
{
if (((Object)__instance.currentLevel.OutsideEnemies[i].enemyType).name == "RadMech")
{
flag = true;
__instance.currentLevel.OutsideEnemies[i] = __instance.levels[12].OutsideEnemies[3];
}
else
{
__instance.currentLevel.OutsideEnemies[i].rarity = ((!ConfigManager.onlyBirdsOnCurse.Value) ? (__instance.currentLevel.OutsideEnemies[i].rarity / 4) : 0);
}
}
if (!flag)
{
__instance.currentLevel.OutsideEnemies.Add(__instance.levels[12].OutsideEnemies[3]);
}
}
[HarmonyPatch("EndOfGame")]
[HarmonyPrefix]
private static void EndOfGamePatch(StartOfRound __instance)
{
if (((NetworkBehaviour)__instance).IsHost && CurseOfEmbrionMod.outsideEnemies != null)
{
__instance.currentLevel.OutsideEnemies = CurseOfEmbrionMod.outsideEnemies;
__instance.currentLevel.maxOutsideEnemyPowerCount = CurseOfEmbrionMod.outsidePowerCount;
__instance.currentLevel.LevelDescription = CurseOfEmbrionMod.levelDescription;
CurseOfEmbrionMod.outsideEnemies = null;
}
}
}
}