using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Windows.Speech;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Sraken")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Sraken")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("16df306f-af90-4255-b69b-ce0bbdb9f662")]
[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")]
internal class <Module>
{
static <Module>()
{
}
}
namespace Sraken
{
public class Networker : NetworkBehaviour
{
public static Networker Instance;
public override void OnNetworkSpawn()
{
Instance = this;
((NetworkBehaviour)this).OnNetworkSpawn();
}
[ServerRpc(RequireOwnership = false)]
public void AngerTheBrackenServerRPC(ulong clientID)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Invalid comparison between Unknown and I4
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager == null || !networkManager.IsListening)
{
return;
}
if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
{
ServerRpcParams val = default(ServerRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(1230259780u, val, (RpcDelivery)0);
BytePacker.WriteValueBitPacked(val2, clientID);
((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1230259780u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage != 1 || (!networkManager.IsServer && !networkManager.IsHost))
{
return;
}
FlowermanAI[] array = (FlowermanAI[])(object)Object.FindObjectsOfType(typeof(FlowermanAI));
if (array.Length == 0)
{
return;
}
FlowermanAI[] array2 = array;
foreach (FlowermanAI val3 in array2)
{
PlayerControllerB[] array3 = Object.FindObjectsOfType<PlayerControllerB>();
foreach (PlayerControllerB val4 in array3)
{
if (val4.playerClientId == clientID && !val4.isPlayerDead)
{
val3.AddToAngerMeter(50f);
((EnemyAI)val3).SetMovingTowardsTargetPlayer(val4);
val3.creatureAngerVoice.clip = Sraken.AngryBracken;
val3.creatureAngerVoice.Play();
Sraken.CustomLogger.LogMessage((object)("Targeting " + val4.playerUsername + "!"));
break;
}
}
}
}
protected override void __initializeVariables()
{
((NetworkBehaviour)this).__initializeVariables();
}
[RuntimeInitializeOnLoadMethod]
internal static void InitializeRPCS_Networker()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
NetworkManager.__rpc_func_table.Add(1230259780u, new RpcReceiveHandler(__rpc_handler_1230259780));
}
private static void __rpc_handler_1230259780(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
ulong clientID = default(ulong);
ByteUnpacker.ReadValueBitPacked(reader, ref clientID);
target.__rpc_exec_stage = (__RpcExecStage)1;
((Networker)(object)target).AngerTheBrackenServerRPC(clientID);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
protected internal override string __getTypeName()
{
return "Networker";
}
}
[BepInPlugin("Theronguard.TheSraken", "The Sraken", "1.0.3")]
public class Sraken : BaseUnityPlugin
{
private const string modGUID = "Theronguard.TheSraken";
private const string modName = "The Sraken";
private const string modVersion = "1.0.3";
public static KeywordRecognizer SpeechRecognizer;
public static ManualLogSource CustomLogger;
public static AssetBundle LoadedAssets;
public static AudioClip AngryBracken;
private readonly Harmony harmony = new Harmony("Theronguard.TheSraken");
public static GameObject NetworkerPrefab;
public static GameObject SpawnedNetworker;
private string[] AngerKeywords = new string[21]
{
"sracken", "sragen", "srahken", "srucken", "slacken", "srahgen", "syraken", "sirahken", "sorahken", "srohken",
"sraahken", "tsracken", "sragen", "sracen", "shraken", "sraken", "tsragen", "sra-ken", "suaken", "suacken",
"suackhen"
};
private string[] NormalKeywords = new string[3] { "bracken", "fucken", "blacken" };
private void Awake()
{
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Expected O, but got Unknown
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Expected O, but got Unknown
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Expected O, but got Unknown
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Expected O, but got Unknown
NetcodeWeaver();
CustomLogger = Logger.CreateLogSource("Theronguard.TheSraken");
LoadedAssets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "thesraken"));
AngryBracken = (AudioClip)LoadedAssets.LoadAsset("sraken");
NetworkerPrefab = (GameObject)LoadedAssets.LoadAsset("Networker");
NetworkerPrefab.AddComponent<Networker>();
try
{
if (PhraseRecognitionSystem.isSupported)
{
CustomLogger.LogInfo((object)"Phrase rec is initialized!");
string[] array = AngerKeywords.Union(NormalKeywords).ToArray();
SpeechRecognizer = new KeywordRecognizer(array, (ConfidenceLevel)2);
((PhraseRecognizer)SpeechRecognizer).OnPhraseRecognized += new PhraseRecognizedDelegate(SpeechRecognized);
((PhraseRecognizer)SpeechRecognizer).Start();
}
}
catch
{
CustomLogger.LogWarning((object)"Sraken recognition cannot proceed!");
}
harmony.PatchAll();
CustomLogger.LogInfo((object)"The Sraken was initialized!");
}
private void SpeechRecognized(PhraseRecognizedEventArgs args)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
if (AngerKeywords.Contains(args.text))
{
CustomLogger.LogInfo((object)"Phrase Recognized");
if (StartOfRound.Instance.localPlayerController.isInsideFactory)
{
CustomLogger.LogInfo((object)"Sending Phrase to Server");
Networker.Instance.AngerTheBrackenServerRPC(StartOfRound.Instance.localPlayerController.playerClientId);
}
}
}
private static void NetcodeWeaver()
{
Type[] types = Assembly.GetExecutingAssembly().GetTypes();
Type[] array = types;
foreach (Type type in array)
{
MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
MethodInfo[] array2 = methods;
foreach (MethodInfo methodInfo in array2)
{
object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
if (customAttributes.Length != 0)
{
methodInfo.Invoke(null, null);
}
}
}
}
}
}
namespace Sraken.Patches
{
[HarmonyPatch(typeof(GameNetworkManager))]
internal class GameNetworkManagerPatch
{
[HarmonyPostfix]
[HarmonyPatch("Start")]
public static void AddPrefab(ref GameNetworkManager __instance)
{
((Component)__instance).GetComponent<NetworkManager>().AddNetworkPrefab(Sraken.NetworkerPrefab);
}
}
[HarmonyPatch(typeof(StartOfRound))]
public class StartRoundPatch : BaseUnityPlugin
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void PatchAwake(StartOfRound __instance)
{
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)Sraken.NetworkerPrefab == (Object)null) && (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer))
{
Sraken.SpawnedNetworker = Object.Instantiate<GameObject>(Sraken.NetworkerPrefab, Vector3.zero, Quaternion.identity);
Sraken.SpawnedNetworker.GetComponent<NetworkObject>().Spawn(false);
}
}
}
}