using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using com.github.zehsteam.KidnapperFoxSettings.Patches;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.zehsteam.KidnapperFoxSettings")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+a16e80cb7ca22aaf9b6295b3f0a85c534545d450")]
[assembly: AssemblyProduct("KidnapperFoxSettings")]
[assembly: AssemblyTitle("com.github.zehsteam.KidnapperFoxSettings")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace com.github.zehsteam.KidnapperFoxSettings
{
internal class ConfigManager
{
public ConfigEntry<int> MaxSpawnCount;
public ConfigEntry<int> Health;
public ConfigEntry<bool> DropAllItemsWhenGrabbed;
public ConfigEntry<bool> InstaKillPlayer;
public ConfigEntry<int> Damage;
public ConfigEntry<float> DamageInterval;
public ConfigManager()
{
BindConfigs();
ClearUnusedEntries();
}
private void BindConfigs()
{
ConfigFile config = ((BaseUnityPlugin)Plugin.Instance).Config;
MaxSpawnCount = config.Bind<int>("Kidnapper Fox Settings", "MaxSpawnCount", 1, "The max amount of Kidnapper Foxes that can spawn on a moon.");
Health = config.Bind<int>("Kidnapper Fox Settings", "Health", 7, "The amount of health (shovel hits) the Kidnapper Fox has.");
DropAllItemsWhenGrabbed = config.Bind<bool>("Kidnapper Fox Settings", "DropAllItemsWhenGrabbed", true, "If enabled, you will drop all your items when the Kidnapper Fox grabs you with their tongue.");
InstaKillPlayer = config.Bind<bool>("Kidnapper Fox Settings", "InstaKillPlayer", true, "If enabled, the Kidnapper Fox will insta-kill you when you are taken to their nest.");
Damage = config.Bind<int>("Kidnapper Fox Settings", "Damage", 50, "The amount of the damage the Kidnapper Fox will deal to players per bite. This setting requires InstaKillPlayer to be false.");
DamageInterval = config.Bind<float>("Kidnapper Fox Settings", "DamageInterval", 1f, "The seconds between each bite from the Kidnapper Fox when you are in their nest. This setting requires InstaKillPlayer to be false.");
}
private void ClearUnusedEntries()
{
ConfigFile config = ((BaseUnityPlugin)Plugin.Instance).Config;
PropertyInfo property = ((object)config).GetType().GetProperty("OrphanedEntries", BindingFlags.Instance | BindingFlags.NonPublic);
Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)property.GetValue(config, null);
dictionary.Clear();
config.Save();
}
}
[BepInPlugin("com.github.zehsteam.KidnapperFoxSettings", "KidnapperFoxSettings", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
private readonly Harmony harmony = new Harmony("com.github.zehsteam.KidnapperFoxSettings");
internal static Plugin Instance;
internal static ManualLogSource logger;
internal static ConfigManager ConfigManager;
public static bool IsHostOrServer => NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
logger = Logger.CreateLogSource("com.github.zehsteam.KidnapperFoxSettings");
logger.LogInfo((object)"KidnapperFoxSettings has awoken!");
harmony.PatchAll(typeof(RoundManagerPatch));
harmony.PatchAll(typeof(PlayerControllerBPatch));
harmony.PatchAll(typeof(BushWolfEnemyPatch));
ConfigManager = new ConfigManager();
}
}
internal class Utils
{
public static EnemyType GetEnemyTypeFromResources(string enemyName)
{
try
{
return Resources.FindObjectsOfTypeAll<EnemyType>().Single((EnemyType x) => x.enemyName == enemyName);
}
catch
{
Plugin.logger.LogError((object)("Failed to get \"" + enemyName + "\" EnemyType from Resources."));
}
return null;
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "com.github.zehsteam.KidnapperFoxSettings";
public const string PLUGIN_NAME = "KidnapperFoxSettings";
public const string PLUGIN_VERSION = "1.0.1";
}
}
namespace com.github.zehsteam.KidnapperFoxSettings.Patches
{
[HarmonyPatch(typeof(BushWolfEnemy))]
internal class BushWolfEnemyPatch
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void StartPatch(ref BushWolfEnemy __instance)
{
((EnemyAI)__instance).enemyHP = Plugin.ConfigManager.Health.Value;
}
[HarmonyPatch("OnCollideWithPlayer")]
[HarmonyPrefix]
private static bool OnCollideWithPlayerPatch(ref BushWolfEnemy __instance, Collider other, ref bool ___foundSpawningPoint, ref bool ___inKillAnimation, ref Vector3 ___currentHidingSpot, ref float ___timeSinceTakingDamage, ref PlayerControllerB ___lastHitByPlayer, ref bool ___dragging, ref bool ___startedShootingTongue)
{
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_0155: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: Unknown result type (might be due to invalid IL or missing references)
//IL_0123: Unknown result type (might be due to invalid IL or missing references)
if (Plugin.ConfigManager.InstaKillPlayer.Value)
{
return true;
}
if (___foundSpawningPoint && !___inKillAnimation && !((EnemyAI)__instance).isEnemyDead && (Object)(object)((EnemyAI)__instance).MeetsStandardPlayerCollisionConditions(other, ___inKillAnimation, false) != (Object)null)
{
float num = Vector3.Distance(((Component)__instance).transform.position, ___currentHidingSpot);
bool flag = false;
if (___timeSinceTakingDamage < 2.5f && (Object)(object)___lastHitByPlayer != (Object)null && num < 16f)
{
flag = true;
}
else if (((num < 7f) & ___dragging) && !___startedShootingTongue && (Object)(object)((EnemyAI)__instance).targetPlayer == (Object)(object)GameNetworkManager.Instance.localPlayerController)
{
flag = true;
}
if (flag)
{
int value = Plugin.ConfigManager.Damage.Value;
PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
if (localPlayerController.health <= value)
{
localPlayerController.KillPlayer(Vector3.up * 15f, true, (CauseOfDeath)6, 8, default(Vector3));
__instance.DoKillPlayerAnimationServerRpc((int)((EnemyAI)__instance).targetPlayer.playerClientId);
}
else
{
localPlayerController.DamagePlayer(value, true, true, (CauseOfDeath)6, 8, false, default(Vector3));
((EnemyAI)__instance).SetEnemyStunned(true, Plugin.ConfigManager.DamageInterval.Value, localPlayerController);
}
}
}
return false;
}
public static bool IsLocalPlayerBeingDragged()
{
BushWolfEnemy[] array = Object.FindObjectsByType<BushWolfEnemy>((FindObjectsSortMode)0);
foreach (BushWolfEnemy val in array)
{
if ((Object)(object)((EnemyAI)val).targetPlayer == (Object)(object)GameNetworkManager.Instance.localPlayerController)
{
return true;
}
}
return false;
}
}
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerBPatch
{
[HarmonyPatch("DropAllHeldItemsAndSync")]
[HarmonyPrefix]
private static bool DropAllHeldItemsAndSyncPatch()
{
if (BushWolfEnemyPatch.IsLocalPlayerBeingDragged())
{
return Plugin.ConfigManager.DropAllItemsWhenGrabbed.Value;
}
return true;
}
}
[HarmonyPatch(typeof(RoundManager))]
internal class RoundManagerPatch
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void StartPatch()
{
SetBushWolfMaxSpawnCount();
}
private static void SetBushWolfMaxSpawnCount()
{
EnemyType enemyTypeFromResources = Utils.GetEnemyTypeFromResources("Bush Wolf");
if ((Object)(object)enemyTypeFromResources == (Object)null)
{
Plugin.logger.LogError((object)"Failed to set Kidnapper Fox max spawn count. Could not find EnemyType.");
}
else
{
enemyTypeFromResources.MaxCount = Plugin.ConfigManager.MaxSpawnCount.Value;
}
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}