Please disclose if your mod was created primarily using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of FriendlyCompany v1.1.0
BepInEx/plugins/FriendlyCompany.dll
Decompiled 2 years agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Serialization; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using CSync.Lib; using CSync.Util; using FriendlyCompany.NetcodePatcher; using GameNetcodeStuff; using HarmonyLib; using Microsoft.CodeAnalysis; using Unity.Netcode; using UnityEngine; using ravingdead.FriendlyCompany.patch; [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: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: AssemblyCompany("FriendlyCompany")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("0.0.0.0")] [assembly: AssemblyInformationalVersion("0.0.0-alpha.0.6+8dd8a9085d93af00abaf381e3e6d8c62065f37cc")] [assembly: AssemblyProduct("FriendlyCompany")] [assembly: AssemblyTitle("FriendlyCompany")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] [module: NetcodePatchedAssembly] internal class <Module> { static <Module>() { } } 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 ravingdead.FriendlyCompany { [DataContract] public class ModConfig : SyncedConfig<ModConfig> { internal LogLevel DebugLevel = (LogLevel)16; [DataMember] public SyncedEntry<bool> ConfigEnableBees { get; private set; } public ModConfig(ConfigFile cfg) : base("ravingdead.FriendlyCompany") { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) ConfigManager.Register<ModConfig>(this); ConfigEnableBees = Extensions.BindSyncedEntry<bool>(cfg, "Toggles", "EnableBees", true, "Whether FriendlyBees should be enabled. Setting this to false will also disable any other features related to bees."); Plugin.Log.Log(DebugLevel, (object)$"{ConfigEnableBees.Key} = {ConfigEnableBees.Value}"); ((SyncedInstance<ModConfig>)(object)this).SyncComplete += delegate { if (!SyncedInstance<ModConfig>.IsHost && !NetworkManager.Singleton.IsServer) { Plugin.Log.LogInfo((object)"Config synced!"); } }; } } [BepInPlugin("ravingdead.FriendlyCompany", "FriendlyCompany", "1.1.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { internal const string GUID = "ravingdead.FriendlyCompany"; internal const string PLUGIN_NAME = "FriendlyCompany"; internal const string VERSION = "1.1.0"; private readonly Harmony _harmony = new Harmony("ravingdead.FriendlyCompany"); public static Plugin Instance { get; set; } public static ModConfig ConfigInstance { get; internal set; } public static ManualLogSource Log => ((BaseUnityPlugin)Instance).Logger; public Plugin() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown Instance = this; } private void Awake() { try { Log.LogInfo((object)"Loading mod..."); Log.LogInfo((object)"Loading config..."); ConfigInstance = new ModConfig(((BaseUnityPlugin)this).Config); Log.LogInfo((object)"Applying Patches..."); ApplyPluginPatch(); Log.LogMessage((object)"Loaded FriendlyCompany version 1.1.0 successfully."); } catch (Exception ex) { Log.LogError((object)("Unexpected error occured when initializing: " + ex.Message + "\nSource: " + ex.Source)); } } private void ApplyPluginPatch() { if (ConfigInstance.ConfigEnableBees.Value) { _harmony.PatchAll(typeof(RedLocustBeesPatch)); } } } public static class PluginInfo { public const string PLUGIN_GUID = "FriendlyCompany"; public const string PLUGIN_NAME = "FriendlyCompany"; public const string PLUGIN_VERSION = "1.0.0"; } } namespace ravingdead.FriendlyCompany.patch { public class FriendlyBees : MonoBehaviour { private RedLocustBees __instance; public List<PlayerControllerB> MeanPlayers; public PlayerControllerB GetPlayerHeldBy() { return __instance.hive.playerHeldBy; } public bool GetIsHeld() { return __instance.hive.isHeld; } public bool GetIsHeldByEnemy() { return __instance.hive.isHeldByEnemy; } public bool IsPlayerMean(PlayerControllerB player) { return MeanPlayers.Contains(player); } public void PrintMeanies() { if (MeanPlayers.Count != 0) { Debug.Log((object)$"Mean players (Source: {((Object)__instance).GetInstanceID()})"); for (int i = 0; i < MeanPlayers.Count; i++) { PlayerControllerB val = MeanPlayers[i]; Debug.Log((object)$"[BLAME] {val.playerUsername} (client: {val.playerClientId} - actual: {val.actualClientId} - steam: {val.playerSteamId})"); } } } public void Initialize(RedLocustBees instance) { Plugin.Log.LogInfo((object)$"Initializing FriendlyBees component on {((EnemyAI)instance).__getTypeName()} instance {((Object)this).GetInstanceID()}..."); __instance = instance; MeanPlayers = new List<PlayerControllerB>(); } public void AddMeanPlayer() { if (!IsPlayerMean(GetPlayerHeldBy())) { Plugin.Log.LogFatal((object)("Player " + GetPlayerHeldBy().playerUsername + " is now logged as a mean person >:O")); MeanPlayers.Add(GetPlayerHeldBy()); } else { Plugin.Log.LogFatal((object)("Player " + GetPlayerHeldBy().playerUsername + " was already a mean person >:(")); } } public void TargetMeanPlayer() { //IL_0075: Unknown result type (might be due to invalid IL or missing references) Plugin.Log.LogInfo((object)("Target " + ((EnemyAI)__instance).targetPlayer.playerUsername + " is friendly, switching behavior...")); PlayerControllerB val = FindNearestMeanPlayer(strict: false, no_default: true); if ((Object)(object)val == (Object)null) { __instance.wasInChase = false; if (__instance.IsHiveMissing()) { ((EnemyAI)__instance).SwitchToBehaviourState(1); ((EnemyAI)__instance).StartSearch(((Component)this).transform.position, __instance.searchForHive); } else { ((EnemyAI)__instance).SwitchToBehaviourState(0); ((EnemyAI)__instance).targetPlayer = val; } } } public PlayerControllerB FindNearestMeanPlayer(bool strict = false, bool no_default = false) { //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) PlayerControllerB[] allPlayersInLineOfSight = ((EnemyAI)__instance).GetAllPlayersInLineOfSight(360f, 16, (Transform)null, -1f, -1); PlayerControllerB val = null; if (allPlayersInLineOfSight != null) { float num = 3000f; int num2 = 0; int num3 = -1; for (int i = 0; i < allPlayersInLineOfSight.Length; i++) { if ((Object)(object)allPlayersInLineOfSight[i].currentlyHeldObjectServer != (Object)null) { if (num3 == -1 && allPlayersInLineOfSight[i].currentlyHeldObjectServer.itemProperties.itemId == 1531) { num3 = i; continue; } if ((Object)(object)allPlayersInLineOfSight[i].currentlyHeldObjectServer == (Object)(object)__instance.hive) { Plugin.Log.LogInfo((object)"Defaulting to hive thief (source: You shouldn't have done that.)"); num3 = -1; val = allPlayersInLineOfSight[i]; break; } } if ((!strict || (strict && (Object)(object)((EnemyAI)__instance).targetPlayer == (Object)null)) && IsPlayerMean(allPlayersInLineOfSight[i])) { float num4 = Vector3.Distance(((Component)this).transform.position, ((Component)allPlayersInLineOfSight[i]).transform.position); if (num4 < num) { num = num4; num2 = i; } } } if (num3 != -1 && Vector3.Distance(((Component)this).transform.position, ((Component)allPlayersInLineOfSight[num3]).transform.position) - num > 7f) { Plugin.Log.LogInfo((object)"Defaulting to nearest player (source: Small float difference to tie breaker.)"); val = allPlayersInLineOfSight[num2]; } else if ((Object)(object)val == (Object)null && !no_default) { Plugin.Log.LogInfo((object)"Defaulting to nearest player (source: No hive in sight.)"); val = allPlayersInLineOfSight[num2]; } else if ((Object)(object)val == (Object)null && no_default) { Plugin.Log.LogInfo((object)"Defaulting to null (source: No hive or mean player in sight.)"); } } return val; } } [HarmonyPatch(typeof(RedLocustBees))] public class RedLocustBeesPatch { private static FriendlyBees friendlyBees; private static FriendlyBees GetComponent(RedLocustBees instance) { return ((Component)instance).gameObject.GetComponent<FriendlyBees>(); } [HarmonyPatch(typeof(RedLocustBees), "Start")] [HarmonyPrefix] private static void StartPostFix(ref RedLocustBees __instance) { Plugin.Log.LogDebug((object)"Bees found!"); friendlyBees = ((Component)__instance).gameObject.AddComponent<FriendlyBees>(); friendlyBees.Initialize(__instance); } [HarmonyPatch(typeof(RedLocustBees), "DoAIInterval")] [HarmonyPrefix] private static void DoAIInterval_Pre(ref RedLocustBees __instance) { if (friendlyBees.GetIsHeld() && !friendlyBees.GetIsHeldByEnemy()) { friendlyBees.AddMeanPlayer(); } if ((Object)(object)((EnemyAI)__instance).targetPlayer != (Object)null && !friendlyBees.IsPlayerMean(((EnemyAI)__instance).targetPlayer)) { friendlyBees.TargetMeanPlayer(); } } [HarmonyPatch(typeof(RedLocustBees), "Update")] [HarmonyPostfix] private static void Update_Post(ref RedLocustBees __instance) { //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: 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) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) if (((EnemyAI)__instance).currentBehaviourStateIndex != 1) { return; } PlayerControllerB closestPlayer = ((EnemyAI)__instance).GetClosestPlayer(false, false, false); if (friendlyBees.IsPlayerMean(closestPlayer)) { return; } float num = Time.deltaTime * 0.7f; __instance.beesZappingMode = 0; __instance.ResetBeeZapTimer(); ((EnemyAI)__instance).agent.speed = 4f; ((EnemyAI)__instance).agent.acceleration = 13f; if (!__instance.overrideBeeParticleTarget) { float num2 = Vector3.Distance(((Component)__instance).transform.position, ((Component)__instance.hive).transform.position); if ((Object)(object)__instance.hive != (Object)null && (num2 < 2f || (num2 < 5f && !Physics.Linecast(((EnemyAI)__instance).eye.position, ((Component)__instance.hive).transform.position + Vector3.up * 0.5f, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1)))) { __instance.beeParticlesTarget.position = ((Component)__instance.hive).transform.position; } else { __instance.beeParticlesTarget.position = ((Component)__instance).transform.position + Vector3.up * 1.5f; } } __instance.beesIdle.volume = Mathf.Min(__instance.beesIdle.volume + num, 1f); if (!__instance.beesIdle.isPlaying) { __instance.beesIdle.Play(); } __instance.beesDefensive.volume = Mathf.Max(__instance.beesDefensive.volume - num, 0f); if (__instance.beesDefensive.isPlaying && __instance.beesDefensive.volume <= 0f) { __instance.beesDefensive.Stop(); } __instance.beesAngry.volume = Mathf.Max(__instance.beesAngry.volume - num, 0f); if (__instance.beesAngry.isPlaying && __instance.beesAngry.volume <= 0f) { __instance.beesAngry.Stop(); } } [HarmonyPatch(typeof(RedLocustBees), "ChaseWithPriorities")] [HarmonyPrefix] private static bool ChaseWithPriorities_Pre(ref RedLocustBees __instance, ref PlayerControllerB __result) { __result = friendlyBees.FindNearestMeanPlayer(strict: true); return false; } [HarmonyPatch("OnCollideWithPlayer")] [HarmonyPrefix] private static bool OnCollideWithPlayer_Pre(Collider other, ref RedLocustBees __instance) { //IL_00df: 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) if (((EnemyAI)__instance).debugEnemyAI) { Debug.Log((object)(((Object)((Component)__instance).gameObject).name + ": Collided with player!")); } if (__instance.timeSinceHittingPlayer >= 0.4f) { PlayerControllerB val = ((EnemyAI)__instance).MeetsStandardPlayerCollisionConditions(other, false, false); if ((Object)(object)val != (Object)null && friendlyBees.IsPlayerMean(val)) { friendlyBees.PrintMeanies(); __instance.timeSinceHittingPlayer = 0f; if (val.health <= 10 || val.criticallyInjured) { __instance.BeeKillPlayerOnLocalClient((int)GameNetworkManager.Instance.localPlayerController.playerClientId); __instance.BeeKillPlayerServerRpc((int)GameNetworkManager.Instance.localPlayerController.playerClientId); } else { val.DamagePlayer(10, true, true, (CauseOfDeath)11, 3, false, default(Vector3)); } if (__instance.beesZappingMode != 3) { __instance.beesZappingMode = 3; __instance.EnterAttackZapModeServerRpc((int)GameNetworkManager.Instance.localPlayerController.playerClientId); } } } return false; } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } } namespace FriendlyCompany.NetcodePatcher { [AttributeUsage(AttributeTargets.Module)] internal class NetcodePatchedAssemblyAttribute : Attribute { } }