#define DEBUG
using System;
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 OPJosMod.MoreEnemies.Patches;
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("OPJosMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OPJosMod")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("70095872-b952-4e27-bbc4-3d70d0238f39")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace OPJosMod.MoreEnemies
{
public static class ConfigVariables
{
public static bool spawnEnemiesInside;
public static float enemyInsideSpawnMultiplier;
public static float enemyOutsideSpawnMultiplier;
public static bool spawnEnemiesOutside;
}
public static class GeneralUtil
{
public static void ResetSpawnRatesForLevel()
{
if (GlobalVariables.OGenemySpawnChanceThroughoutDay != null && GlobalVariables.OGmaxEnemyPowerCount != 0 && GlobalVariables.OGoutsideEnemySpawnChanceThroughDay != null && GlobalVariables.OGdaytimeEnemySpawnChanceThroughDay != null)
{
RoundManager.Instance.currentLevel.enemySpawnChanceThroughoutDay = GlobalVariables.OGenemySpawnChanceThroughoutDay;
RoundManager.Instance.currentMaxInsidePower = GlobalVariables.OGcurrentMaxInsidePower;
RoundManager.Instance.currentLevel.maxEnemyPowerCount = GlobalVariables.OGmaxEnemyPowerCount;
RoundManager.Instance.currentLevel.outsideEnemySpawnChanceThroughDay = GlobalVariables.OGoutsideEnemySpawnChanceThroughDay;
RoundManager.Instance.currentLevel.daytimeEnemySpawnChanceThroughDay = GlobalVariables.OGdaytimeEnemySpawnChanceThroughDay;
RoundManager.Instance.currentMaxOutsidePower = GlobalVariables.OGcurrentMaxOutsidePower;
RoundManager.Instance.currentLevel.maxOutsideEnemyPowerCount = GlobalVariables.OGmaxOutsideEnemyPowerCount;
}
else
{
Debug.WriteLine("MOREENEMIES: didnt reset spawnrates to orignal spawnrates as orignal spawnrates werent set yet.");
}
}
}
public static class GlobalVariables
{
public static bool ModActivated;
public static AnimationCurve OGenemySpawnChanceThroughoutDay;
public static AnimationCurve OGoutsideEnemySpawnChanceThroughDay;
public static AnimationCurve OGdaytimeEnemySpawnChanceThroughDay;
public static float OGcurrentMaxInsidePower;
public static int OGmaxEnemyPowerCount;
public static float OGcurrentMaxOutsidePower;
public static int OGmaxOutsideEnemyPowerCount;
}
[BepInPlugin("OpJosMod.MoreEnemies", "MoreEnemies", "1.3.1")]
public class OpJosMod : BaseUnityPlugin
{
private const string modGUID = "OpJosMod.MoreEnemies";
private const string modName = "MoreEnemies";
private const string modVersion = "1.3.1";
private readonly Harmony harmony = new Harmony("OpJosMod.MoreEnemies");
private static OpJosMod Instance;
internal ManualLogSource mls;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
mls = Logger.CreateLogSource("OpJosMod.MoreEnemies");
setupConfig();
RoundManagerPatch.SetLogSource(mls);
StartMatchLeverPatch.SetLogSource(mls);
GameNetworkManagerPatch.SetLogSource(mls);
harmony.PatchAll();
}
private void setupConfig()
{
ConfigEntry<bool> val = ((BaseUnityPlugin)this).Config.Bind<bool>("Spawn Inside Enemies", "SpawnInsideEnemeies", true, "Have indoor enemies or not");
ConfigEntry<float> val2 = ((BaseUnityPlugin)this).Config.Bind<float>("Inside Spawn Multiplier", "InsideSpawnMultiplier", 1.5f, "How many more enemies do you want inside?");
ConfigEntry<bool> val3 = ((BaseUnityPlugin)this).Config.Bind<bool>("Spawn Outside Enemies", "SpawnOutsideEnemeies", true, "Have outdoor enemies or not");
ConfigEntry<float> val4 = ((BaseUnityPlugin)this).Config.Bind<float>("Outside Spawn Multiplier", "OutsideSpawnMultiplier", 1.5f, "How many more enemies do you want outside?");
ConfigVariables.spawnEnemiesInside = val.Value;
ConfigVariables.enemyInsideSpawnMultiplier = val2.Value;
ConfigVariables.spawnEnemiesOutside = val3.Value;
ConfigVariables.enemyOutsideSpawnMultiplier = val4.Value;
}
}
}
namespace OPJosMod.MoreEnemies.Utils
{
public class ReflectionUtils
{
public static void InvokeMethod(object obj, string methodName, object[] parameters)
{
Type type = obj.GetType();
MethodInfo method = type.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
method.Invoke(obj, parameters);
}
public static void InvokeMethod(object obj, Type forceType, string methodName, object[] parameters)
{
MethodInfo method = forceType.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
method.Invoke(obj, parameters);
}
public static void SetPropertyValue(object obj, string propertyName, object value)
{
Type type = obj.GetType();
PropertyInfo property = type.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
property.SetValue(obj, value);
}
public static T InvokeMethod<T>(object obj, string methodName, object[] parameters)
{
Type type = obj.GetType();
MethodInfo method = type.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
return (T)method.Invoke(obj, parameters);
}
public static T GetFieldValue<T>(object obj, string fieldName)
{
Type type = obj.GetType();
FieldInfo field = type.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
return (T)field.GetValue(obj);
}
public static void SetFieldValue(object obj, string fieldName, object value)
{
Type type = obj.GetType();
FieldInfo field = type.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
field.SetValue(obj, value);
}
}
}
namespace OPJosMod.MoreEnemies.Patches
{
[HarmonyPatch(typeof(GameNetworkManager))]
internal class GameNetworkManagerPatch
{
private static ManualLogSource mls;
public static void SetLogSource(ManualLogSource logSource)
{
mls = logSource;
}
[HarmonyPatch("Disconnect")]
[HarmonyPrefix]
private static void patchDisconnect(GameNetworkManager __instance)
{
if (__instance.isHostingGame)
{
mls.LogMessage((object)"DISCCONNECTING HIT");
GeneralUtil.ResetSpawnRatesForLevel();
}
else
{
mls.LogMessage((object)"didn't reset spawn rates as you arent host");
}
}
}
[HarmonyPatch(typeof(StartMatchLever))]
internal class StartMatchLeverPatch
{
private static ManualLogSource mls;
public static void SetLogSource(ManualLogSource logSource)
{
mls = logSource;
}
[HarmonyPatch("EndGame")]
[HarmonyPrefix]
private static void patchEndGame(StartMatchLever __instance)
{
if (GameNetworkManager.Instance.isHostingGame)
{
GeneralUtil.ResetSpawnRatesForLevel();
}
else
{
mls.LogMessage((object)"didn't reset spawn rates as you arent host");
}
}
}
[HarmonyPatch(typeof(RoundManager))]
internal class RoundManagerPatch
{
private static ManualLogSource mls;
public static void SetLogSource(ManualLogSource logSource)
{
mls = logSource;
}
[HarmonyPatch("LoadNewLevel")]
[HarmonyPrefix]
private static void loadNewLevelPatch(RoundManager __instance, ref SelectableLevel newLevel)
{
if (GameNetworkManager.Instance.isHostingGame)
{
mls.LogMessage((object)"adjusting enemies spawnrates");
setOGVariables(__instance, newLevel);
if (ConfigVariables.spawnEnemiesInside)
{
newLevel.enemySpawnChanceThroughoutDay = MultiplyAnimationCurve(__instance.currentLevel.enemySpawnChanceThroughoutDay, ConfigVariables.enemyInsideSpawnMultiplier, allowNegative: false);
__instance.currentMaxInsidePower *= ConfigVariables.enemyInsideSpawnMultiplier;
__instance.currentLevel.maxEnemyPowerCount = (int)Math.Round((float)__instance.currentLevel.maxEnemyPowerCount * ConfigVariables.enemyInsideSpawnMultiplier);
}
else
{
__instance.currentMaxInsidePower = 0f;
}
if (ConfigVariables.spawnEnemiesOutside)
{
newLevel.outsideEnemySpawnChanceThroughDay = MultiplyAnimationCurve(__instance.currentLevel.outsideEnemySpawnChanceThroughDay, ConfigVariables.enemyOutsideSpawnMultiplier);
newLevel.daytimeEnemySpawnChanceThroughDay = MultiplyAnimationCurve(__instance.currentLevel.daytimeEnemySpawnChanceThroughDay, ConfigVariables.enemyOutsideSpawnMultiplier);
__instance.currentMaxOutsidePower *= ConfigVariables.enemyOutsideSpawnMultiplier;
__instance.currentLevel.maxOutsideEnemyPowerCount = (int)Math.Round((float)__instance.currentLevel.maxOutsideEnemyPowerCount * ConfigVariables.enemyOutsideSpawnMultiplier);
}
else
{
__instance.currentMaxOutsidePower = 0f;
__instance.currentLevel.maxOutsideEnemyPowerCount = 0;
}
}
else
{
mls.LogMessage((object)"didn't adjust spawn rates as you arent host");
}
}
private static void setOGVariables(RoundManager __instance, SelectableLevel level)
{
GlobalVariables.OGenemySpawnChanceThroughoutDay = level.enemySpawnChanceThroughoutDay;
GlobalVariables.OGcurrentMaxInsidePower = __instance.currentMaxInsidePower;
GlobalVariables.OGmaxEnemyPowerCount = __instance.currentLevel.maxEnemyPowerCount;
GlobalVariables.OGoutsideEnemySpawnChanceThroughDay = level.outsideEnemySpawnChanceThroughDay;
GlobalVariables.OGdaytimeEnemySpawnChanceThroughDay = level.daytimeEnemySpawnChanceThroughDay;
GlobalVariables.OGcurrentMaxOutsidePower = __instance.currentMaxOutsidePower;
GlobalVariables.OGmaxOutsideEnemyPowerCount = __instance.currentLevel.maxOutsideEnemyPowerCount;
}
private static AnimationCurve MultiplyAnimationCurve(AnimationCurve animationCurve, float multiplicative, bool allowNegative = true)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Expected O, but got Unknown
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
AnimationCurve val = new AnimationCurve();
Keyframe val3 = default(Keyframe);
for (int i = 0; i < animationCurve.length; i++)
{
Keyframe val2 = animationCurve[i];
float num = ((!allowNegative) ? Mathf.Max(((Keyframe)(ref val2)).value, 0.1f * (float)(i + 1)) : ((Keyframe)(ref val2)).value);
mls.LogMessage((object)$"{i} OLDKeyframe [{((Keyframe)(ref val2)).time}, {((Keyframe)(ref val2)).value}]");
float num2 = ((num > 0f) ? (num * multiplicative) : num);
((Keyframe)(ref val3))..ctor(((Keyframe)(ref val2)).time, num2);
mls.LogMessage((object)$"{i} NewKeyframe [{((Keyframe)(ref val3)).time}, {((Keyframe)(ref val3)).value}]");
((Keyframe)(ref val3)).inTangent = ((Keyframe)(ref val2)).inTangent;
((Keyframe)(ref val3)).outTangent = ((Keyframe)(ref val2)).outTangent;
val.AddKey(val3);
}
return val;
}
}
}