using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCompanyShisha.CustomStateMachineBehaviours;
using LethalCompanyShisha.NetcodePatcher;
using LethalCompanyShisha.Types;
using LethalLib.Modules;
using LobbyCompatibility.Enums;
using LobbyCompatibility.Features;
using Microsoft.CodeAnalysis;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("LethalLib")]
[assembly: AssemblyCompany("Louis")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Lethal Company Shisha")]
[assembly: AssemblyFileVersion("1.1.4.0")]
[assembly: AssemblyInformationalVersion("1.1.4+ff875b84d611e1a8d9c289db4712bb8d86721156")]
[assembly: AssemblyProduct("LethalCompanyShisha")]
[assembly: AssemblyTitle("LethalCompanyShisha")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.4.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
static <Module>()
{
NetworkVariableSerializationTypes.InitializeSerializer_UnmanagedByMemcpy<bool>();
NetworkVariableSerializationTypes.InitializeEqualityChecker_UnmanagedIEquatable<bool>();
}
}
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 LethalCompanyShisha
{
[BepInPlugin("LethalCompanyShisha", "LethalCompanyShisha", "1.1.4")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class ShishaPlugin : BaseUnityPlugin
{
public const string ModGuid = "LCM_Shisha|1.1.4";
private const string ModName = "Lethal Company Shisha Mod";
private const string ModVersion = "1.1.4";
private readonly Harmony _harmony = new Harmony("LCM_Shisha|1.1.4");
public static readonly ManualLogSource Mls = Logger.CreateLogSource("LCM_Shisha|1.1.4");
private static ShishaPlugin _instance;
private static EnemyType _shishaEnemyType;
public static Item ShishaPoopItem;
public static ShishaConfig ShishaConfigInstance { get; internal set; }
private void Awake()
{
if ((Object)(object)_instance == (Object)null)
{
_instance = this;
}
if (LobbyCompatibilityChecker.Enabled)
{
LobbyCompatibilityChecker.Init();
}
InitializeNetworkStuff();
Assets.PopulateAssetsFromFile();
if ((Object)(object)Assets.MainAssetBundle == (Object)null)
{
Mls.LogError((object)"MainAssetBundle is null");
return;
}
_harmony.PatchAll();
ShishaConfigInstance = new ShishaConfig(((BaseUnityPlugin)this).Config);
SetupShisha();
SetupShishaPoop();
_harmony.PatchAll();
_harmony.PatchAll(typeof(ShishaPlugin));
_harmony.PatchAll(typeof(ShishaPoopBehaviour));
Mls.LogInfo((object)"Plugin Lethal Company Shisha Mod is loaded!");
}
private void SetupShisha()
{
_shishaEnemyType = Assets.MainAssetBundle.LoadAsset<EnemyType>("ShishaEnemyType");
_shishaEnemyType.MaxCount = Mathf.Max(0, SyncedInstance<ShishaConfig>.Instance.ShishaMaxAmount.Value);
_shishaEnemyType.PowerLevel = Mathf.Max(0f, SyncedInstance<ShishaConfig>.Instance.ShishaPowerLevel.Value);
_shishaEnemyType.normalizedTimeInDayToLeave = (SyncedInstance<ShishaConfig>.Instance.TimeInDayLeaveEnabled.Value ? 0.6f : 1f);
_shishaEnemyType.canDie = SyncedInstance<ShishaConfig>.Instance.Killable.Value;
TerminalNode terminalNode = Assets.MainAssetBundle.LoadAsset<TerminalNode>("ShishaTerminalNode");
TerminalKeyword terminalKeyword = Assets.MainAssetBundle.LoadAsset<TerminalKeyword>("ShishaTerminalKeyword");
NetworkPrefabs.RegisterNetworkPrefab(_shishaEnemyType.enemyPrefab);
Utilities.FixMixerGroups(_shishaEnemyType.enemyPrefab);
RegisterEnemyWithConfig(SyncedInstance<ShishaConfig>.Instance.ShishaEnabled.Value, SyncedInstance<ShishaConfig>.Instance.ShishaSpawnRarity.Value, _shishaEnemyType, terminalNode, terminalKeyword);
}
private void SetupShishaPoop()
{
ShishaPoopItem = Assets.MainAssetBundle.LoadAsset<Item>("ShishaPoopItemData");
NetworkPrefabs.RegisterNetworkPrefab(ShishaPoopItem.spawnPrefab);
Utilities.FixMixerGroups(ShishaPoopItem.spawnPrefab);
Items.RegisterScrap(ShishaPoopItem, 0, (LevelTypes)(-1));
}
private static void RegisterEnemyWithConfig(bool enemyEnabled, string configMoonRarity, EnemyType enemy, TerminalNode terminalNode, TerminalKeyword terminalKeyword)
{
if (enemyEnabled)
{
var (dictionary, dictionary2) = ConfigParsing(configMoonRarity);
Enemies.RegisterEnemy(enemy, dictionary, dictionary2, terminalNode, terminalKeyword);
}
else
{
Enemies.RegisterEnemy(enemy, 0, (LevelTypes)(-1), terminalNode, terminalKeyword);
}
}
private static (Dictionary<LevelTypes, int> spawnRateByLevelType, Dictionary<string, int> spawnRateByCustomLevelType) ConfigParsing(string configMoonRarity)
{
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: 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)
Dictionary<LevelTypes, int> dictionary = new Dictionary<LevelTypes, int>();
Dictionary<string, int> dictionary2 = new Dictionary<string, int>();
foreach (string item in from s in configMoonRarity.Split(',')
select s.Trim())
{
string[] array = item.Split(':');
if (array.Length != 2)
{
continue;
}
string text = array[0];
if (int.TryParse(array[1], out var result))
{
if (Enum.TryParse<LevelTypes>(text, ignoreCase: true, out LevelTypes result2))
{
dictionary[result2] = result;
Mls.LogDebug((object)$"Registered spawn rate for level type {result2} to {result}");
}
else if (Enum.TryParse<LevelTypes>(text + "Level", ignoreCase: true, out result2))
{
dictionary[result2] = result;
Mls.LogDebug((object)$"Registered spawn rate for level type {result2} to {result}");
}
else
{
dictionary2[text] = result;
Mls.LogDebug((object)$"Registered spawn rate for custom level type {text} to {result}");
}
}
}
return (dictionary, dictionary2);
}
private static void InitializeNetworkStuff()
{
IEnumerable<Type> enumerable;
try
{
enumerable = Assembly.GetExecutingAssembly().GetTypes();
}
catch (ReflectionTypeLoadException ex)
{
enumerable = ex.Types.Where((Type t) => t != null);
}
foreach (Type item in enumerable)
{
MethodInfo[] methods = item.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
foreach (MethodInfo methodInfo in methods)
{
if (methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false).Length != 0)
{
methodInfo.Invoke(null, null);
}
}
}
}
}
internal static class Assets
{
private const string MainAssetBundleName = "shishabundle";
public static AssetBundle MainAssetBundle;
public static void PopulateAssetsFromFile()
{
if ((Object)(object)MainAssetBundle != (Object)null)
{
return;
}
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
if (directoryName != null)
{
MainAssetBundle = AssetBundle.LoadFromFile(Path.Combine(directoryName, "shishabundle"));
if ((Object)(object)MainAssetBundle != (Object)null)
{
return;
}
MainAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Path.Combine(directoryName, "Assets"), "shishabundle"));
}
if ((Object)(object)MainAssetBundle == (Object)null)
{
ShishaPlugin.Mls.LogWarning((object)"Failed to load shishabundle bundle");
}
}
}
[Serializable]
public class SyncedInstance<T>
{
[CompilerGenerated]
private static class <>O
{
public static HandleNamedMessageDelegate <0>__OnRequestSync;
public static HandleNamedMessageDelegate <1>__OnReceiveSync;
}
[NonSerialized]
protected static int IntSize = 4;
internal static CustomMessagingManager MessageManager => NetworkManager.Singleton.CustomMessagingManager;
internal static bool IsClient => NetworkManager.Singleton.IsClient;
internal static bool IsHost => NetworkManager.Singleton.IsHost;
public static T Default { get; private set; }
public static T Instance { get; private set; }
public static bool Synced { get; internal set; }
protected void InitInstance(T instance)
{
Default = instance;
Instance = instance;
IntSize = 4;
}
internal static void SyncInstance(byte[] data)
{
Instance = DeserializeFromBytes(data);
Synced = true;
}
internal static void RevertSync()
{
Instance = Default;
Synced = false;
}
public static byte[] SerializeToBytes(T val)
{
BinaryFormatter binaryFormatter = new BinaryFormatter();
using MemoryStream memoryStream = new MemoryStream();
try
{
binaryFormatter.Serialize(memoryStream, val);
return memoryStream.ToArray();
}
catch (Exception arg)
{
Debug.LogError((object)$"Error serializing instance: {arg}");
return null;
}
}
public static T DeserializeFromBytes(byte[] data)
{
BinaryFormatter binaryFormatter = new BinaryFormatter();
using MemoryStream serializationStream = new MemoryStream(data);
try
{
return (T)binaryFormatter.Deserialize(serializationStream);
}
catch (Exception arg)
{
Debug.LogError((object)$"Error deserializing instance: {arg}");
return default(T);
}
}
private static void RequestSync()
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
if (!IsClient)
{
return;
}
FastBufferWriter val = default(FastBufferWriter);
((FastBufferWriter)(ref val))..ctor(IntSize, (Allocator)2, -1);
try
{
MessageManager.SendNamedMessage("LCM_Shisha|1.1.4_OnRequestConfigSync", 0uL, val, (NetworkDelivery)3);
}
finally
{
((IDisposable)(FastBufferWriter)(ref val)).Dispose();
}
}
private static void OnRequestSync(ulong clientId, FastBufferReader _)
{
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
if (!IsHost)
{
return;
}
Debug.Log((object)$"Config sync request received from client: {clientId}");
byte[] array = SerializeToBytes(Instance);
int num = array.Length;
FastBufferWriter val = default(FastBufferWriter);
((FastBufferWriter)(ref val))..ctor(num + IntSize, (Allocator)2, -1);
try
{
((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives));
((FastBufferWriter)(ref val)).WriteBytesSafe(array, -1, 0);
MessageManager.SendNamedMessage("LCM_Shisha|1.1.4_OnReceiveConfigSync", clientId, val, (NetworkDelivery)3);
}
catch (Exception arg)
{
Debug.Log((object)$"Error occurred syncing config with client: {clientId}\n{arg}");
}
finally
{
((IDisposable)(FastBufferWriter)(ref val)).Dispose();
}
}
private static void OnReceiveSync(ulong _, FastBufferReader reader)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
if (!((FastBufferReader)(ref reader)).TryBeginRead(IntSize))
{
Debug.LogError((object)"Config sync error: Could not begin reading buffer.");
return;
}
int num = default(int);
((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives));
if (!((FastBufferReader)(ref reader)).TryBeginRead(num))
{
Debug.LogError((object)"Config sync error: Host could not sync.");
return;
}
byte[] data = new byte[num];
((FastBufferReader)(ref reader)).ReadBytesSafe(ref data, num, 0);
SyncInstance(data);
Debug.Log((object)"Successfully synced config with host.");
}
[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
public static void InitializeLocalPlayer()
{
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Expected O, but got Unknown
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Expected O, but got Unknown
if (IsHost)
{
CustomMessagingManager messageManager = MessageManager;
object obj = <>O.<0>__OnRequestSync;
if (obj == null)
{
HandleNamedMessageDelegate val = OnRequestSync;
<>O.<0>__OnRequestSync = val;
obj = (object)val;
}
messageManager.RegisterNamedMessageHandler("LCM_Shisha|1.1.4_OnRequestConfigSync", (HandleNamedMessageDelegate)obj);
Synced = true;
return;
}
Synced = false;
CustomMessagingManager messageManager2 = MessageManager;
object obj2 = <>O.<1>__OnReceiveSync;
if (obj2 == null)
{
HandleNamedMessageDelegate val2 = OnReceiveSync;
<>O.<1>__OnReceiveSync = val2;
obj2 = (object)val2;
}
messageManager2.RegisterNamedMessageHandler("LCM_Shisha|1.1.4_OnReceiveConfigSync", (HandleNamedMessageDelegate)obj2);
RequestSync();
}
[HarmonyPostfix]
[HarmonyPatch(typeof(GameNetworkManager), "StartDisconnect")]
public static void PlayerLeave()
{
RevertSync();
}
}
public static class LobbyCompatibilityChecker
{
public static bool Enabled => Chainloader.PluginInfos.ContainsKey("BMX.LobbyCompatibility");
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void Init()
{
PluginHelper.RegisterPlugin("LethalCompanyShisha", Version.Parse("1.1.4"), (CompatibilityLevel)2, (VersionStrictness)3);
}
}
public class ShishaClient : MonoBehaviour
{
private ManualLogSource _mls;
private string _shishaId;
private static readonly int IsRunning = Animator.StringToHash("Run");
private static readonly int IsWalking = Animator.StringToHash("Walk");
public static readonly int IsDead = Animator.StringToHash("Dead");
public static readonly int ForceWalk = Animator.StringToHash("ForceWalk");
private static readonly int WalkSpeed = Animator.StringToHash("WalkSpeed");
private static readonly int RunSpeed = Animator.StringToHash("RunSpeed");
public static readonly int Idle1 = Animator.StringToHash("Idle1");
public static readonly int Idle2 = Animator.StringToHash("Idle2");
public static readonly int Poo = Animator.StringToHash("Poo");
[SerializeField]
private AudioSource creatureVoice;
[SerializeField]
private AudioSource creatureSfx;
[SerializeField]
private Renderer renderer;
[SerializeField]
private Transform poopPlaceholder;
[SerializeField]
private ParticleSystem poofParticleSystem;
[SerializeField]
private GameObject scanNode;
[Header("Movement")]
[Tooltip("The maximum speed that the creature can maintain while still walking")]
public float walkSpeedThreshold = 2f;
[Header("Audio")]
[Tooltip("An array of audio clips that can be played randomly at intervals while the creature is wandering.")]
public AudioClip[] ambientAudioClips;
[Tooltip("The volume for ambient audio.")]
[Range(0f, 2f)]
public float ambientAudioVolume = 1f;
[Space]
[Tooltip("An array of audio clips that can be played randomly at intervals while the creature is moving.")]
public AudioClip[] walkingAudioClips;
[Tooltip("The interval between playing walking audio clips.")]
public float walkingAudioInterval = 0.5f;
private Animator _animator;
private readonly NullableObject<ShishaNetcodeController> _netcodeController = new NullableObject<ShishaNetcodeController>();
private readonly NullableObject<PlayerControllerB> _targetPlayer = new NullableObject<PlayerControllerB>();
private ShishaPoopBehaviour _currentPoop;
private Vector3 _agentLastPosition;
private bool _networkEventsSubscribed;
private const float MaxWalkAnimationSpeedMultiplier = 2f;
private float _agentCurrentSpeed;
private float _walkingAudioTimer;
private int _currentBehaviourStateIndex;
private static readonly int GotHit = Animator.StringToHash("GotHit");
private void OnEnable()
{
SubscribeToNetworkEvents();
}
private void OnDisable()
{
UnsubscribeFromNetworkEvents();
}
private void Start()
{
_mls = Logger.CreateLogSource("LCM_Shisha|1.1.4 | Shisha Client " + _shishaId);
_animator = ((Component)this).GetComponent<Animator>();
_netcodeController.Value = ((Component)this).GetComponent<ShishaNetcodeController>();
if (_netcodeController != null)
{
SubscribeToNetworkEvents();
InitializeConfigValues();
AddStateMachineBehaviours(_animator);
}
else
{
_mls.LogError((object)"Netcode controller is null, this is very bad.");
}
}
private void Update()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
Vector3 position = ((Component)this).transform.position;
float agentCurrentSpeed = _agentCurrentSpeed;
Vector3 val = position - _agentLastPosition;
_agentCurrentSpeed = Mathf.Lerp(agentCurrentSpeed, ((Vector3)(ref val)).magnitude / Time.deltaTime, 0.75f);
_agentLastPosition = position;
int currentBehaviourStateIndex = _currentBehaviourStateIndex;
if (currentBehaviourStateIndex == 0 || currentBehaviourStateIndex == 2)
{
if (_agentCurrentSpeed <= walkSpeedThreshold && _agentCurrentSpeed > 0f)
{
_animator.SetBool(IsWalking, true);
_animator.SetBool(IsRunning, false);
float num = Mathf.Clamp(_agentCurrentSpeed / walkSpeedThreshold, 0f, 2f);
_animator.SetFloat(WalkSpeed, num);
}
else if (_agentCurrentSpeed > walkSpeedThreshold)
{
_animator.SetBool(IsWalking, true);
_animator.SetBool(IsRunning, true);
float num2 = Mathf.Clamp(_agentCurrentSpeed / 4f, 0f, 5f);
_animator.SetFloat(RunSpeed, num2);
}
else
{
_animator.SetBool(IsWalking, false);
_animator.SetBool(IsRunning, false);
}
_walkingAudioTimer -= Time.deltaTime;
if (walkingAudioClips != null && _walkingAudioTimer <= 0f)
{
AudioClip val2 = walkingAudioClips[Random.Range(0, walkingAudioClips.Length)];
creatureSfx.Stop(true);
creatureSfx.PlayOneShot(val2);
WalkieTalkie.TransmitOneShotAudio(creatureSfx, val2, creatureSfx.volume);
_walkingAudioTimer = walkingAudioInterval;
}
}
}
private void HandlePlayAmbientSfx(string receivedShishaId, int clipIndex)
{
if (!(_shishaId != receivedShishaId))
{
AudioClip val = ambientAudioClips[clipIndex];
creatureVoice.PlayOneShot(val);
WalkieTalkie.TransmitOneShotAudio(creatureVoice, val, ambientAudioVolume);
}
}
private void HandleSpawnShishaPoop(string receivedShishaId, NetworkObjectReference poopNetworkObjectReference)
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
NetworkObject val = default(NetworkObject);
if (!(_shishaId != receivedShishaId) && ((NetworkObjectReference)(ref poopNetworkObjectReference)).TryGet(ref val, (NetworkManager)null))
{
LogDebug("Poop network object was not null!");
_currentPoop = ((Component)val).GetComponent<ShishaPoopBehaviour>();
((Component)_currentPoop).transform.position = ((Component)poopPlaceholder).transform.position;
((Component)_currentPoop).transform.rotation = ((Component)poopPlaceholder).transform.rotation;
((Component)_currentPoop).transform.SetParent(poopPlaceholder, false);
LogDebug("Shisha poop spawned");
}
}
public void OnAnimationEventDropShishaPoop()
{
if (!((Object)(object)_currentPoop == (Object)null))
{
((GrabbableObject)_currentPoop).parentObject = null;
((Component)_currentPoop).transform.SetParent(StartOfRound.Instance.propsContainer, true);
((GrabbableObject)_currentPoop).EnablePhysics(true);
((GrabbableObject)_currentPoop).FallToGround(true);
((Component)_currentPoop).transform.SetParent(RoundManager.Instance.spawnedScrapContainer, true);
((GrabbableObject)_currentPoop).isHeld = false;
((GrabbableObject)_currentPoop).grabbable = true;
((GrabbableObject)_currentPoop).grabbableToEnemies = true;
}
}
public void OnAnimationEventDeathAnimationComplete()
{
((MonoBehaviour)this).StartCoroutine(CompleteDeathSequence());
}
private IEnumerator CompleteDeathSequence()
{
LogDebug("In CompleteDeathSequence");
yield return (object)new WaitForSeconds(1f);
poofParticleSystem.Play();
renderer.enabled = false;
creatureSfx.Stop(true);
Object.Destroy((Object)(object)scanNode.gameObject);
yield return (object)new WaitForSeconds(0.1f);
Object.Destroy((Object)(object)((Component)renderer).gameObject);
if (((NetworkBehaviour)_netcodeController.Value).IsServer)
{
SpawnDeathPoopsServerRpc();
yield return (object)new WaitForSeconds(0.5f);
ShishaServer component = ((Component)this).GetComponent<ShishaServer>();
if ((Object)(object)component != (Object)null)
{
Object.Destroy((Object)(object)component);
}
Object.Destroy((Object)(object)this);
}
}
[ServerRpc]
private void SpawnDeathPoopsServerRpc()
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
foreach (int item in new List<int>(3) { 0, 1, 2 })
{
_ = item;
Vector3 randomNavMeshPositionInRadiusSpherical = RoundManager.Instance.GetRandomNavMeshPositionInRadiusSpherical(((Component)this).transform.position, 2f, default(NavMeshHit));
GameObject obj = Object.Instantiate<GameObject>(ShishaPlugin.ShishaPoopItem.spawnPrefab, randomNavMeshPositionInRadiusSpherical, Quaternion.identity, StartOfRound.Instance.propsContainer);
ShishaPoopBehaviour component = obj.GetComponent<ShishaPoopBehaviour>();
((GrabbableObject)component).EnablePhysics(true);
((GrabbableObject)component).FallToGround(true);
((Component)component).transform.SetParent(RoundManager.Instance.spawnedScrapContainer, true);
obj.GetComponent<NetworkObject>().Spawn(false);
}
}
private void InitializeConfigValues()
{
creatureVoice.volume = Mathf.Clamp(SyncedInstance<ShishaConfig>.Default.AmbientSoundEffectsVolume.Value, 0f, 1f) * 2f;
creatureSfx.volume = Mathf.Clamp(SyncedInstance<ShishaConfig>.Default.FootstepSoundEffectsVolume.Value, 0f, 1f) * 2f;
}
private void AddStateMachineBehaviours(Animator receivedAnimator)
{
StateMachineBehaviour[] behaviours = receivedAnimator.GetBehaviours<StateMachineBehaviour>();
for (int i = 0; i < behaviours.Length; i++)
{
if (behaviours[i] is BaseStateMachineBehaviour baseStateMachineBehaviour)
{
baseStateMachineBehaviour.Initialize(_netcodeController.Value);
}
}
}
private void HandleBehaviourStateChanged(int oldValue, int newValue)
{
_currentBehaviourStateIndex = newValue;
LogDebug($"Changed behaviour state to {newValue}");
switch ((ShishaServer.States)newValue)
{
case ShishaServer.States.Roaming:
_animator.SetBool(IsWalking, true);
break;
case ShishaServer.States.Idle:
_animator.SetBool(IsWalking, false);
_animator.SetBool(IsRunning, false);
break;
case ShishaServer.States.RunningAway:
_animator.SetBool(IsWalking, true);
_animator.SetTrigger(GotHit);
break;
case ShishaServer.States.Dead:
_animator.SetBool(IsWalking, false);
_animator.SetBool(IsRunning, false);
_animator.SetBool(IsDead, true);
break;
}
}
private void HandleSetAnimationTrigger(string receivedShishaId, int animationId)
{
if (!(_shishaId != receivedShishaId))
{
_animator.SetTrigger(animationId);
}
}
private void HandleSetAnimationBool(string receivedShishaId, int animationId, bool value)
{
if (!(_shishaId != receivedShishaId))
{
_animator.SetBool(animationId, value);
}
}
private void HandleSyncShishaIdentifier(string receivedShishaId)
{
_shishaId = receivedShishaId;
ManualLogSource mls = _mls;
if (mls != null)
{
mls.Dispose();
}
_mls = Logger.CreateLogSource("LCM_Shisha|1.1.4 | Shisha Client " + _shishaId);
LogDebug("Successfully synced shisha identifier");
}
private void HandleTargetPlayerChanged(ulong oldValue, ulong newValue)
{
_targetPlayer.Value = ((newValue == 69420) ? null : StartOfRound.Instance.allPlayerScripts[newValue]);
LogDebug(_targetPlayer.IsNotNull ? ("Changed target player to " + _targetPlayer.Value?.playerUsername + ".") : "Changed target player to null.");
}
private void SubscribeToNetworkEvents()
{
if (!_networkEventsSubscribed && _netcodeController.IsNotNull)
{
_netcodeController.Value.OnSyncShishaIdentifier += HandleSyncShishaIdentifier;
_netcodeController.Value.OnSetAnimationTrigger += HandleSetAnimationTrigger;
_netcodeController.Value.OnSpawnShishaPoop += HandleSpawnShishaPoop;
_netcodeController.Value.OnPlayAmbientSfx += HandlePlayAmbientSfx;
_netcodeController.Value.OnSetAnimationBool += HandleSetAnimationBool;
NetworkVariable<int> currentBehaviourStateIndex = _netcodeController.Value.CurrentBehaviourStateIndex;
currentBehaviourStateIndex.OnValueChanged = (OnValueChangedDelegate<int>)(object)Delegate.Combine((Delegate?)(object)currentBehaviourStateIndex.OnValueChanged, (Delegate?)(object)new OnValueChangedDelegate<int>(HandleBehaviourStateChanged));
NetworkVariable<ulong> targetPlayerClientId = _netcodeController.Value.TargetPlayerClientId;
targetPlayerClientId.OnValueChanged = (OnValueChangedDelegate<ulong>)(object)Delegate.Combine((Delegate?)(object)targetPlayerClientId.OnValueChanged, (Delegate?)(object)new OnValueChangedDelegate<ulong>(HandleTargetPlayerChanged));
_networkEventsSubscribed = true;
}
}
private void UnsubscribeFromNetworkEvents()
{
if (_networkEventsSubscribed && _netcodeController.IsNotNull)
{
_netcodeController.Value.OnSyncShishaIdentifier -= HandleSyncShishaIdentifier;
_netcodeController.Value.OnSetAnimationTrigger -= HandleSetAnimationTrigger;
_netcodeController.Value.OnSpawnShishaPoop -= HandleSpawnShishaPoop;
_netcodeController.Value.OnPlayAmbientSfx -= HandlePlayAmbientSfx;
_netcodeController.Value.OnSetAnimationBool -= HandleSetAnimationBool;
NetworkVariable<int> currentBehaviourStateIndex = _netcodeController.Value.CurrentBehaviourStateIndex;
currentBehaviourStateIndex.OnValueChanged = (OnValueChangedDelegate<int>)(object)Delegate.Remove((Delegate?)(object)currentBehaviourStateIndex.OnValueChanged, (Delegate?)(object)new OnValueChangedDelegate<int>(HandleBehaviourStateChanged));
NetworkVariable<ulong> targetPlayerClientId = _netcodeController.Value.TargetPlayerClientId;
targetPlayerClientId.OnValueChanged = (OnValueChangedDelegate<ulong>)(object)Delegate.Remove((Delegate?)(object)targetPlayerClientId.OnValueChanged, (Delegate?)(object)new OnValueChangedDelegate<ulong>(HandleTargetPlayerChanged));
_networkEventsSubscribed = false;
}
}
private void LogDebug(string msg)
{
}
}
public class ShishaConfig : SyncedInstance<ShishaConfig>
{
public readonly ConfigEntry<bool> ShishaEnabled;
public readonly ConfigEntry<string> ShishaSpawnRarity;
public readonly ConfigEntry<int> ShishaMaxAmount;
public readonly ConfigEntry<float> ShishaPowerLevel;
public readonly ConfigEntry<int> CommonCrystalChance;
public readonly ConfigEntry<int> UncommonCrystalChance;
public readonly ConfigEntry<int> RareCrystalChance;
public readonly ConfigEntry<int> CommonCrystalMinValue;
public readonly ConfigEntry<int> CommonCrystalMaxValue;
public readonly ConfigEntry<int> UncommonCrystalMinValue;
public readonly ConfigEntry<int> UncommonCrystalMaxValue;
public readonly ConfigEntry<int> RareCrystalMinValue;
public readonly ConfigEntry<int> RareCrystalMaxValue;
public readonly ConfigEntry<float> AmbientSoundEffectsVolume;
public readonly ConfigEntry<float> FootstepSoundEffectsVolume;
public readonly ConfigEntry<float> WanderRadius;
public readonly ConfigEntry<bool> AnchoredWandering;
public readonly ConfigEntry<float> MaxSpeed;
public readonly ConfigEntry<float> MaxAcceleration;
public readonly ConfigEntry<float> RunningAwayMaxSpeed;
public readonly ConfigEntry<float> RunningAwayMaxAcceleration;
public readonly ConfigEntry<float> WanderTimeMin;
public readonly ConfigEntry<float> WanderTimeMax;
public readonly ConfigEntry<float> AmbientSfxTimerMin;
public readonly ConfigEntry<float> AmbientSfxTimerMax;
public readonly ConfigEntry<bool> TimeInDayLeaveEnabled;
public readonly ConfigEntry<bool> PoopBehaviourEnabled;
public readonly ConfigEntry<float> PoopChance;
public readonly ConfigEntry<bool> Killable;
public readonly ConfigEntry<int> Health;
public ShishaConfig(ConfigFile cfg)
{
InitInstance(this);
WanderRadius = cfg.Bind<float>("General", "Wander Radius", 50f, "The maximum distance from the Shisha's current position within which it can wander.");
AnchoredWandering = cfg.Bind<bool>("General", "Anchored Wandering", true, "When enabled, the Shisha will only wander around its spawn point within a radius defined by the Wander Radius. If disabled, the Shisha can wander from any point within the Wander Radius.");
Killable = cfg.Bind<bool>("General", "Killable", true, "Whether the Shisha can be killed.");
Health = cfg.Bind<int>("General", "Health", 3, "The amount of health the Shisha has.");
MaxSpeed = cfg.Bind<float>("General", "Max Speed", 4f, "The maximum speed of the Shisha.");
MaxAcceleration = cfg.Bind<float>("General", "Max Acceleration", 5f, "The maximum acceleration of the Shisha.");
RunningAwayMaxSpeed = cfg.Bind<float>("General", "Running Away Max Speed", 7f, "The maximum speed of the Shisha when running away from someone.");
RunningAwayMaxAcceleration = cfg.Bind<float>("General", "Running Away Max Acceleration", 8f, "The maximum acceleration of the Shisha when running away from someone.");
WanderTimeMin = cfg.Bind<float>("General", "Wander Time Minimum", 5f, "The minimum time that the Shisha will wander for.");
WanderTimeMax = cfg.Bind<float>("General", "Wander Time Maximum", 45f, "The maximum time that the Shisha will wander for.");
AmbientSfxTimerMin = cfg.Bind<float>("General", "Ambient Sfx Time Interval Minimum", 7.5f, "The minimum time gap between any given ambient sound effect.");
AmbientSfxTimerMax = cfg.Bind<float>("General", "Ambient Sfx Time Interval Maximum", 30f, "The maximum time gap between any given ambient sound effect.");
TimeInDayLeaveEnabled = cfg.Bind<bool>("General", "Leave At Night Time Enabled", true, "Toggles whether the Shisha will leave the map when it gets dark like other vanilla daytime entities.");
PoopBehaviourEnabled = cfg.Bind<bool>("General", "Poop Behaviour Enabled", true, "Toggles whether the Shisha can poop when idle.");
PoopChance = cfg.Bind<float>("General", "Poop Chance", 0.05f, "The chance from 0 to 1, of the Shisha pooping while idle.");
ShishaEnabled = cfg.Bind<bool>("Spawn Values", "Shisha Enabled", true, "Whether the Shisha is enabled (will spawn in games).");
ShishaSpawnRarity = cfg.Bind<string>("Spawn Values", "Shisha Spawn Rarity", "All:30", "Spawn weight of the Shisha on all moons. You can to add to it any moon, just follow the format (also needs LLL installed for LE moons to work with this config).");
ShishaMaxAmount = cfg.Bind<int>("Spawn Values", "Max Amount", 4, "The max amount of Shisha's that can spawn.");
ShishaPowerLevel = cfg.Bind<float>("Spawn Values", "Power Level", 0.1f, "The power level of the Shisha.");
CommonCrystalChance = cfg.Bind<int>("Spawn Values", "Common Crystal Spawn Chance", 65, "The percentage chance of the Shisha pooping a common sized crystal. Make sure the values of all the crystals add up to 100.");
UncommonCrystalChance = cfg.Bind<int>("Spawn Values", "Uncommon Crystal Spawn Chance", 25, "The percentage chance of the Shisha pooping a uncommon sized crystal. Make sure the values of all the crystals add up to 100.");
RareCrystalChance = cfg.Bind<int>("Spawn Values", "Rare Crystal Spawn Chance", 10, "The percentage chance of the Shisha pooping a rare sized crystal. Make sure the values of all the crystals add up to 100.");
CommonCrystalMinValue = cfg.Bind<int>("Spawn Values", "Common Crystal Minimum Value", 20, "The minimum value that the common crystal can spawn with.");
CommonCrystalMaxValue = cfg.Bind<int>("Spawn Values", "Common Crystal Maximum Value", 35, "The maximum value that the common crystal can spawn with.");
UncommonCrystalMinValue = cfg.Bind<int>("Spawn Values", "Uncommon Crystal Minimum Value", 40, "The minimum value that the uncommon crystal can spawn with.");
UncommonCrystalMaxValue = cfg.Bind<int>("Spawn Values", "Uncommon Crystal Maximum Value", 75, "The maximum value that the uncommon crystal can spawn with.");
RareCrystalMinValue = cfg.Bind<int>("Spawn Values", "Rare Crystal Minimum Value", 80, "The minimum value that the rare crystal can spawn with.");
RareCrystalMaxValue = cfg.Bind<int>("Spawn Values", "Rare Crystal Maximum Value", 100, "The maximum value that the rare crystal can spawn with.");
AmbientSoundEffectsVolume = cfg.Bind<float>("Audio", "Ambient Sound Effects Volume", 0.4f, "The volume of the ambient sounds of the Shisha from 0 to 1.");
FootstepSoundEffectsVolume = cfg.Bind<float>("Audio", "Footstep Sound Effects Volume", 0.7f, "The volume of the footstep sounds of the Shisha from 0 to 1.");
}
}
public class ShishaNetcodeController : NetworkBehaviour
{
[HideInInspector]
public readonly NetworkVariable<int> CurrentBehaviourStateIndex = new NetworkVariable<int>(0, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);
[HideInInspector]
public readonly NetworkVariable<ulong> TargetPlayerClientId = new NetworkVariable<ulong>(0uL, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);
public event Action<string> OnSyncShishaIdentifier;
public event Action<string> OnIdleCompleteStateBehaviourCallback;
public event Action<string, int> OnSetAnimationTrigger;
public event Action<string, NetworkObjectReference> OnSpawnShishaPoop;
public event Action<string, int> OnPlayAmbientSfx;
public event Action<string, int, bool> OnSetAnimationBool;
[ClientRpc]
public void PlayAmbientSfxClientRpc(string receivedShishaId, int clipIndex)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: 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_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: 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 != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(787179278u, val, (RpcDelivery)0);
bool flag = receivedShishaId != null;
((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
if (flag)
{
((FastBufferWriter)(ref val2)).WriteValueSafe(receivedShishaId, false);
}
BytePacker.WriteValueBitPacked(val2, clipIndex);
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 787179278u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
{
this.OnPlayAmbientSfx?.Invoke(receivedShishaId, clipIndex);
}
}
[ClientRpc]
public void SpawnShishaPoopClientRpc(string receivedShishaId, NetworkObjectReference poopNetworkObjectReference)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: 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_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: 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 != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3512806445u, val, (RpcDelivery)0);
bool flag = receivedShishaId != null;
((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
if (flag)
{
((FastBufferWriter)(ref val2)).WriteValueSafe(receivedShishaId, false);
}
((FastBufferWriter)(ref val2)).WriteValueSafe<NetworkObjectReference>(ref poopNetworkObjectReference, default(ForNetworkSerializable));
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3512806445u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
{
this.OnSpawnShishaPoop?.Invoke(receivedShishaId, poopNetworkObjectReference);
}
}
[ClientRpc]
public void SetAnimationTriggerClientRpc(string receivedShishaId, int animationId)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: 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_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: 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 != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1082093719u, val, (RpcDelivery)0);
bool flag = receivedShishaId != null;
((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
if (flag)
{
((FastBufferWriter)(ref val2)).WriteValueSafe(receivedShishaId, false);
}
BytePacker.WriteValueBitPacked(val2, animationId);
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1082093719u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
{
this.OnSetAnimationTrigger?.Invoke(receivedShishaId, animationId);
}
}
[ClientRpc]
public void SetAnimationBoolClientRpc(string receivedShishaId, int animationId, bool value)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_00fc: 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_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: 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 != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(502806586u, val, (RpcDelivery)0);
bool flag = receivedShishaId != null;
((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
if (flag)
{
((FastBufferWriter)(ref val2)).WriteValueSafe(receivedShishaId, false);
}
BytePacker.WriteValueBitPacked(val2, animationId);
((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref value, default(ForPrimitives));
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 502806586u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
{
this.OnSetAnimationBool?.Invoke(receivedShishaId, animationId, value);
}
}
[ServerRpc(RequireOwnership = false)]
public void IdleCompleteStateBehaviourCallbackServerRpc(string receivedShishaId)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: 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_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: 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(284395386u, val, (RpcDelivery)0);
bool flag = receivedShishaId != null;
((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
if (flag)
{
((FastBufferWriter)(ref val2)).WriteValueSafe(receivedShishaId, false);
}
((NetworkBehaviour)this).__endSendServerRpc(ref val2, 284395386u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
{
this.OnIdleCompleteStateBehaviourCallback?.Invoke(receivedShishaId);
}
}
[ClientRpc]
public void SyncShishaIdentifierClientRpc(string receivedShishaId)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: 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_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: 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 != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2029305066u, val, (RpcDelivery)0);
bool flag = receivedShishaId != null;
((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
if (flag)
{
((FastBufferWriter)(ref val2)).WriteValueSafe(receivedShishaId, false);
}
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2029305066u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
{
this.OnSyncShishaIdentifier?.Invoke(receivedShishaId);
}
}
protected override void __initializeVariables()
{
if (CurrentBehaviourStateIndex == null)
{
throw new Exception("ShishaNetcodeController.CurrentBehaviourStateIndex cannot be null. All NetworkVariableBase instances must be initialized.");
}
((NetworkVariableBase)CurrentBehaviourStateIndex).Initialize((NetworkBehaviour)(object)this);
((NetworkBehaviour)this).__nameNetworkVariable((NetworkVariableBase)(object)CurrentBehaviourStateIndex, "CurrentBehaviourStateIndex");
base.NetworkVariableFields.Add((NetworkVariableBase)(object)CurrentBehaviourStateIndex);
if (TargetPlayerClientId == null)
{
throw new Exception("ShishaNetcodeController.TargetPlayerClientId cannot be null. All NetworkVariableBase instances must be initialized.");
}
((NetworkVariableBase)TargetPlayerClientId).Initialize((NetworkBehaviour)(object)this);
((NetworkBehaviour)this).__nameNetworkVariable((NetworkVariableBase)(object)TargetPlayerClientId, "TargetPlayerClientId");
base.NetworkVariableFields.Add((NetworkVariableBase)(object)TargetPlayerClientId);
((NetworkBehaviour)this).__initializeVariables();
}
[RuntimeInitializeOnLoadMethod]
internal static void InitializeRPCS_ShishaNetcodeController()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Expected O, but got Unknown
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Expected O, but got Unknown
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Expected O, but got Unknown
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Expected O, but got Unknown
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Expected O, but got Unknown
NetworkManager.__rpc_func_table.Add(787179278u, new RpcReceiveHandler(__rpc_handler_787179278));
NetworkManager.__rpc_func_table.Add(3512806445u, new RpcReceiveHandler(__rpc_handler_3512806445));
NetworkManager.__rpc_func_table.Add(1082093719u, new RpcReceiveHandler(__rpc_handler_1082093719));
NetworkManager.__rpc_func_table.Add(502806586u, new RpcReceiveHandler(__rpc_handler_502806586));
NetworkManager.__rpc_func_table.Add(284395386u, new RpcReceiveHandler(__rpc_handler_284395386));
NetworkManager.__rpc_func_table.Add(2029305066u, new RpcReceiveHandler(__rpc_handler_2029305066));
}
private static void __rpc_handler_787179278(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
bool flag = default(bool);
((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
string receivedShishaId = null;
if (flag)
{
((FastBufferReader)(ref reader)).ReadValueSafe(ref receivedShishaId, false);
}
int clipIndex = default(int);
ByteUnpacker.ReadValueBitPacked(reader, ref clipIndex);
target.__rpc_exec_stage = (__RpcExecStage)2;
((ShishaNetcodeController)(object)target).PlayAmbientSfxClientRpc(receivedShishaId, clipIndex);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_3512806445(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: 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_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
bool flag = default(bool);
((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
string receivedShishaId = null;
if (flag)
{
((FastBufferReader)(ref reader)).ReadValueSafe(ref receivedShishaId, false);
}
NetworkObjectReference poopNetworkObjectReference = default(NetworkObjectReference);
((FastBufferReader)(ref reader)).ReadValueSafe<NetworkObjectReference>(ref poopNetworkObjectReference, default(ForNetworkSerializable));
target.__rpc_exec_stage = (__RpcExecStage)2;
((ShishaNetcodeController)(object)target).SpawnShishaPoopClientRpc(receivedShishaId, poopNetworkObjectReference);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_1082093719(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
bool flag = default(bool);
((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
string receivedShishaId = null;
if (flag)
{
((FastBufferReader)(ref reader)).ReadValueSafe(ref receivedShishaId, false);
}
int animationId = default(int);
ByteUnpacker.ReadValueBitPacked(reader, ref animationId);
target.__rpc_exec_stage = (__RpcExecStage)2;
((ShishaNetcodeController)(object)target).SetAnimationTriggerClientRpc(receivedShishaId, animationId);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_502806586(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: 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)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
bool flag = default(bool);
((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
string receivedShishaId = null;
if (flag)
{
((FastBufferReader)(ref reader)).ReadValueSafe(ref receivedShishaId, false);
}
int animationId = default(int);
ByteUnpacker.ReadValueBitPacked(reader, ref animationId);
bool value = default(bool);
((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref value, default(ForPrimitives));
target.__rpc_exec_stage = (__RpcExecStage)2;
((ShishaNetcodeController)(object)target).SetAnimationBoolClientRpc(receivedShishaId, animationId, value);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_284395386(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
bool flag = default(bool);
((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
string receivedShishaId = null;
if (flag)
{
((FastBufferReader)(ref reader)).ReadValueSafe(ref receivedShishaId, false);
}
target.__rpc_exec_stage = (__RpcExecStage)1;
((ShishaNetcodeController)(object)target).IdleCompleteStateBehaviourCallbackServerRpc(receivedShishaId);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_2029305066(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
bool flag = default(bool);
((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
string receivedShishaId = null;
if (flag)
{
((FastBufferReader)(ref reader)).ReadValueSafe(ref receivedShishaId, false);
}
target.__rpc_exec_stage = (__RpcExecStage)2;
((ShishaNetcodeController)(object)target).SyncShishaIdentifierClientRpc(receivedShishaId);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
protected internal override string __getTypeName()
{
return "ShishaNetcodeController";
}
}
public class ShishaPoopBehaviour : PhysicsProp
{
private ManualLogSource _mls;
private string _poopId;
public MeshFilter meshFilter;
public Mesh[] poopMeshVariants;
public Material[] poopMaterialVariants;
private bool _networkEventsSubscribed;
private bool _loadedVariantFromSave;
private CachedValue<ScanNodeProperties> _scanNode;
private CachedValue<NetworkObject> _networkObject;
private readonly NetworkVariable<int> _variantIndex = new NetworkVariable<int>(-1, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);
private readonly NetworkVariable<bool> _isPartOfShisha = new NetworkVariable<bool>(true, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);
private readonly NetworkVariable<int> _scrapValue = new NetworkVariable<int>(69420, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);
private const int ScrapValuePlaceholder = 69420;
private void Awake()
{
_networkObject = new CachedValue<NetworkObject>((Func<NetworkObject>)((Component)this).GetComponent<NetworkObject>, eager: true);
}
private void OnEnable()
{
SubscribeToNetworkEvents();
}
private void OnDisable()
{
UnsubscribeFromNetworkEvents();
}
public override void Start()
{
((GrabbableObject)this).Start();
_scanNode = new CachedValue<ScanNodeProperties>((Func<ScanNodeProperties>)((Component)this).GetComponentInChildren<ScanNodeProperties>, eager: true);
SubscribeToNetworkEvents();
if (((NetworkBehaviour)this).IsServer)
{
_poopId = Guid.NewGuid().ToString();
_mls = Logger.CreateLogSource("LCM_Shisha|1.1.4 | Shisha Poop " + _poopId);
Random.InitState(StartOfRound.Instance.randomMapSeed + _poopId.GetHashCode());
SyncPoopIdClientRpc(_poopId);
if (!_loadedVariantFromSave)
{
_variantIndex.Value = GetRandomVariantIndex();
_scrapValue.Value = CalculateScrapValue(_variantIndex.Value);
_isPartOfShisha.Value = true;
}
}
}
public override void Update()
{
if (((GrabbableObject)this).isHeld && _isPartOfShisha.Value)
{
if (((NetworkBehaviour)this).IsServer)
{
_isPartOfShisha.Value = false;
}
else
{
SetIsPartOfShishaServerRpc(value: false);
}
}
if (!_isPartOfShisha.Value)
{
((GrabbableObject)this).Update();
}
}
public override void LateUpdate()
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
if (_isPartOfShisha.Value)
{
if ((Object)(object)((Component)this).transform.parent != (Object)null)
{
((Component)this).transform.position = ((Component)this).transform.parent.position;
((Component)this).transform.rotation = ((Component)this).transform.parent.rotation;
}
}
else
{
((GrabbableObject)this).LateUpdate();
}
}
[ServerRpc(RequireOwnership = false)]
private void SetIsPartOfShishaServerRpc(bool value)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: 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_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
{
ServerRpcParams val = default(ServerRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(4263262004u, val, (RpcDelivery)0);
((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref value, default(ForPrimitives));
((NetworkBehaviour)this).__endSendServerRpc(ref val2, 4263262004u, val, (RpcDelivery)0);
}
if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
{
_isPartOfShisha.Value = value;
}
}
}
public override void EquipItem()
{
((PhysicsProp)this).EquipItem();
EvaluateIsPartOfShisha();
}
public override void GrabItem()
{
((GrabbableObject)this).GrabItem();
EvaluateIsPartOfShisha();
}
private void EvaluateIsPartOfShisha()
{
if (_isPartOfShisha.Value)
{
if (((NetworkBehaviour)this).IsServer)
{
_isPartOfShisha.Value = false;
}
else
{
SetIsPartOfShishaServerRpc(value: false);
}
}
}
[HarmonyPatch(typeof(BeltBagItem), "PutObjectInBagLocalClient")]
[HarmonyPostfix]
private static void TriggerHeldActions(BeltBagItem __instance, GrabbableObject gObject)
{
if (gObject is ShishaPoopBehaviour shishaPoopBehaviour)
{
((GrabbableObject)shishaPoopBehaviour).EquipItem();
}
}
private static int CalculateScrapValue(int variant)
{
return variant switch
{
0 => Random.Range(SyncedInstance<ShishaConfig>.Instance.CommonCrystalMinValue.Value, SyncedInstance<ShishaConfig>.Instance.CommonCrystalMaxValue.Value + 1),
1 => Random.Range(SyncedInstance<ShishaConfig>.Instance.UncommonCrystalMinValue.Value, SyncedInstance<ShishaConfig>.Instance.UncommonCrystalMaxValue.Value + 1),
2 => Random.Range(SyncedInstance<ShishaConfig>.Instance.RareCrystalMinValue.Value, SyncedInstance<ShishaConfig>.Instance.RareCrystalMaxValue.Value + 1),
_ => 1,
};
}
private void ApplyVariant(int chosenVariantIndex)
{
if (poopMaterialVariants.Length != 0 && poopMeshVariants.Length != 0 && poopMaterialVariants.Length == poopMeshVariants.Length)
{
((Renderer)((GrabbableObject)this).mainObjectRenderer).material = poopMaterialVariants[chosenVariantIndex];
meshFilter.mesh = poopMeshVariants[chosenVariantIndex];
LogDebug($"New random variant applied with index: {chosenVariantIndex}");
}
else
{
_mls.LogError((object)$"No material variants available with index: {chosenVariantIndex}.");
}
}
private static int GetRandomVariantIndex()
{
int num = SyncedInstance<ShishaConfig>.Instance.CommonCrystalChance.Value;
int num2 = SyncedInstance<ShishaConfig>.Instance.UncommonCrystalChance.Value;
int value = SyncedInstance<ShishaConfig>.Instance.RareCrystalChance.Value;
if (num + num2 + value != 100)
{
num = 65;
num2 = 25;
value = 10;
}
int num3 = Random.Range(1, 101);
if (num3 <= num)
{
return 0;
}
if (num3 <= num + num2)
{
return 1;
}
return 2;
}
private void OnScrapValueChanged(int oldValue, int newValue)
{
((GrabbableObject)this).scrapValue = newValue;
_scanNode.Value.scrapValue = newValue;
_scanNode.Value.subText = $"Value: ${newValue}";
}
private void OnVariantIndexChanged(int oldValue, int newValue)
{
ApplyVariant(newValue);
}
private void OnIsPartOfShishaChanged(bool oldValue, bool newValue)
{
((GrabbableObject)this).grabbableToEnemies = !newValue;
((GrabbableObject)this).grabbable = !newValue;
((GrabbableObject)this).fallTime = ((!newValue) ? 1f : 0f);
}
public override int GetItemDataToSave()
{
return int.Parse($"{_variantIndex.Value + 1}{Mathf.Max(_scrapValue.Value, 0)}");
}
public override void LoadItemSaveData(int saveData)
{
_loadedVariantFromSave = true;
string text = $"{saveData}";
int loadedVariantIndex = int.Parse($"{text[0]}") - 1;
string text2 = text;
int loadedScrapValue = int.Parse(text2.Substring(1, text2.Length - 1) ?? "");
((MonoBehaviour)this).StartCoroutine(ApplyItemSaveData(loadedVariantIndex, loadedScrapValue));
}
private IEnumerator ApplyItemSaveData(int loadedVariantIndex, int loadedScrapValue)
{
while (!_networkObject.Value.IsSpawned)
{
yield return null;
}
_variantIndex.Value = loadedVariantIndex;
_scrapValue.Value = loadedScrapValue;
_isPartOfShisha.Value = false;
}
[ClientRpc]
public void SyncPoopIdClientRpc(string poopId)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: 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_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: 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)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(32545544u, val, (RpcDelivery)0);
bool flag = poopId != null;
((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
if (flag)
{
((FastBufferWriter)(ref val2)).WriteValueSafe(poopId, false);
}
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 32545544u, val, (RpcDelivery)0);
}
if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && !((NetworkBehaviour)this).IsServer)
{
_poopId = poopId;
ManualLogSource mls = _mls;
if (mls != null)
{
mls.Dispose();
}
_mls = Logger.CreateLogSource("LCM_Shisha|1.1.4 | Shisha Poop " + _poopId);
}
}
private void SubscribeToNetworkEvents()
{
if (!_networkEventsSubscribed)
{
NetworkVariable<int> variantIndex = _variantIndex;
variantIndex.OnValueChanged = (OnValueChangedDelegate<int>)(object)Delegate.Combine((Delegate?)(object)variantIndex.OnValueChanged, (Delegate?)(object)new OnValueChangedDelegate<int>(OnVariantIndexChanged));
NetworkVariable<bool> isPartOfShisha = _isPartOfShisha;
isPartOfShisha.OnValueChanged = (OnValueChangedDelegate<bool>)(object)Delegate.Combine((Delegate?)(object)isPartOfShisha.OnValueChanged, (Delegate?)(object)new OnValueChangedDelegate<bool>(OnIsPartOfShishaChanged));
NetworkVariable<int> scrapValue = _scrapValue;
scrapValue.OnValueChanged = (OnValueChangedDelegate<int>)(object)Delegate.Combine((Delegate?)(object)scrapValue.OnValueChanged, (Delegate?)(object)new OnValueChangedDelegate<int>(OnScrapValueChanged));
_networkEventsSubscribed = true;
}
}
private void UnsubscribeFromNetworkEvents()
{
if (_networkEventsSubscribed)
{
NetworkVariable<int> variantIndex = _variantIndex;
variantIndex.OnValueChanged = (OnValueChangedDelegate<int>)(object)Delegate.Remove((Delegate?)(object)variantIndex.OnValueChanged, (Delegate?)(object)new OnValueChangedDelegate<int>(OnVariantIndexChanged));
NetworkVariable<bool> isPartOfShisha = _isPartOfShisha;
isPartOfShisha.OnValueChanged = (OnValueChangedDelegate<bool>)(object)Delegate.Remove((Delegate?)(object)isPartOfShisha.OnValueChanged, (Delegate?)(object)new OnValueChangedDelegate<bool>(OnIsPartOfShishaChanged));
NetworkVariable<int> scrapValue = _scrapValue;
scrapValue.OnValueChanged = (OnValueChangedDelegate<int>)(object)Delegate.Remove((Delegate?)(object)scrapValue.OnValueChanged, (Delegate?)(object)new OnValueChangedDelegate<int>(OnScrapValueChanged));
_networkEventsSubscribed = false;
}
}
private void LogDebug(string msg)
{
}
protected override void __initializeVariables()
{
if (_variantIndex == null)
{
throw new Exception("ShishaPoopBehaviour._variantIndex cannot be null. All NetworkVariableBase instances must be initialized.");
}
((NetworkVariableBase)_variantIndex).Initialize((NetworkBehaviour)(object)this);
((NetworkBehaviour)this).__nameNetworkVariable((NetworkVariableBase)(object)_variantIndex, "_variantIndex");
((NetworkBehaviour)this).NetworkVariableFields.Add((NetworkVariableBase)(object)_variantIndex);
if (_isPartOfShisha == null)
{
throw new Exception("ShishaPoopBehaviour._isPartOfShisha cannot be null. All NetworkVariableBase instances must be initialized.");
}
((NetworkVariableBase)_isPartOfShisha).Initialize((NetworkBehaviour)(object)this);
((NetworkBehaviour)this).__nameNetworkVariable((NetworkVariableBase)(object)_isPartOfShisha, "_isPartOfShisha");
((NetworkBehaviour)this).NetworkVariableFields.Add((NetworkVariableBase)(object)_isPartOfShisha);
if (_scrapValue == null)
{
throw new Exception("ShishaPoopBehaviour._scrapValue cannot be null. All NetworkVariableBase instances must be initialized.");
}
((NetworkVariableBase)_scrapValue).Initialize((NetworkBehaviour)(object)this);
((NetworkBehaviour)this).__nameNetworkVariable((NetworkVariableBase)(object)_scrapValue, "_scrapValue");
((NetworkBehaviour)this).NetworkVariableFields.Add((NetworkVariableBase)(object)_scrapValue);
((PhysicsProp)this).__initializeVariables();
}
[RuntimeInitializeOnLoadMethod]
internal static void InitializeRPCS_ShishaPoopBehaviour()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Expected O, but got Unknown
NetworkManager.__rpc_func_table.Add(4263262004u, new RpcReceiveHandler(__rpc_handler_4263262004));
NetworkManager.__rpc_func_table.Add(32545544u, new RpcReceiveHandler(__rpc_handler_32545544));
}
private static void __rpc_handler_4263262004(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
bool isPartOfShishaServerRpc = default(bool);
((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref isPartOfShishaServerRpc, default(ForPrimitives));
target.__rpc_exec_stage = (__RpcExecStage)1;
((ShishaPoopBehaviour)(object)target).SetIsPartOfShishaServerRpc(isPartOfShishaServerRpc);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_32545544(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
bool flag = default(bool);
((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
string poopId = null;
if (flag)
{
((FastBufferReader)(ref reader)).ReadValueSafe(ref poopId, false);
}
target.__rpc_exec_stage = (__RpcExecStage)2;
((ShishaPoopBehaviour)(object)target).SyncPoopIdClientRpc(poopId);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
protected internal override string __getTypeName()
{
return "ShishaPoopBehaviour";
}
}
public class ShishaServer : EnemyAI
{
private enum PathStatus
{
Invalid,
ValidButInLos,
Valid,
Unknown
}
public enum States
{
Roaming,
Idle,
RunningAway,
Dead
}
private ManualLogSource _mls;
private string _shishaId;
[SerializeField]
private AISearchRoutine roamSearchRoutine;
[SerializeField]
private Transform poopPlaceholder;
[Header("Movement")]
[Tooltip("Toggle whether the creature is allowed to wander or not.")]
public bool wanderEnabled = true;
[Tooltip("When enabled, the creature will only wander around its spawn point within a radius defined by the Wander Radius. If disabled, the creature can wander from any point within the Wander Radius.")]
public bool anchoredWandering = true;
[Tooltip("The maximum speed of the creature.")]
public float maxSpeed = 4f;
[Tooltip("The maximum acceleration of the creature.")]
public float maxAcceleration = 5f;
[Tooltip("The creature will wander for a random duration within this range before going to an idle state.")]
public Vector2 wanderTimeRange = new Vector2(5f, 45f);
public Vector2 ambientSfxTimerRange = new Vector2(7.5f, 40f);
public float poopChance = 0.05f;
public float runningAwayMaxSpeed = 4f;
public float runningAwayMaxAcceleration = 8f;
public const ulong NullPlayerId = 69420uL;
private ShishaNetcodeController _netcodeController;
private float _wanderTimer;
private float _agentMaxSpeed;
private float _agentMaxAcceleration;
private float _ambientAudioTimer;
private float _takeDamageCooldown;
private int _numberOfAmbientAudioClips;
private bool _poopBehaviourEnabled;
private bool _killable;
private bool _networkEventsSubscribed;
private Vector3 _idlePosition;
private Vector3 _spawnPosition;
private Transform _runAwayTransform;
private readonly NullableObject<PlayerControllerB> _actualTargetPlayer = new NullableObject<PlayerControllerB>();
private void OnEnable()
{
SubscribeToNetworkEvents();
}
private void OnDisable()
{
UnsubscribeFromNetworkEvents();
}
public override void Start()
{
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Unknown result type (might be due to invalid IL or missing references)
((EnemyAI)this).Start();
if (!((NetworkBehaviour)this).IsServer)
{
return;
}
_shishaId = Guid.NewGuid().ToString();
_mls = Logger.CreateLogSource("LCM_Shisha|1.1.4 | Shisha Server " + _shishaId);
if ((Object)(object)base.agent == (Object)null)
{
base.agent = ((Component)this).GetComponent<NavMeshAgent>();
}
if ((Object)(object)base.creatureAnimator == (Object)null)
{
base.creatureAnimator = ((Component)this).GetComponent<Animator>();
}
_netcodeController = ((Component)this).GetComponent<ShishaNetcodeController>();
if ((Object)(object)_netcodeController != (Object)null)
{
SubscribeToNetworkEvents();
Random.InitState(StartOfRound.Instance.randomMapSeed + _shishaId.GetHashCode() - base.thisEnemyIndex);
_netcodeController.SyncShishaIdentifierClientRpc(_shishaId);
InitializeConfigValues();
base.allAINodes = GameObject.FindGameObjectsWithTag("OutsideAINode");
_spawnPosition = ((Component)this).transform.position;
_numberOfAmbientAudioClips = ((Component)this).GetComponent<ShishaClient>().ambientAudioClips.Length;
if (wanderEnabled)
{
InitializeState(0);
}
LogDebug("Shisha spawned!");
}
else
{
_mls.LogError((object)"Netcode controller is null, aborting spawn.");
Object.Destroy((Object)(object)((Component)this).gameObject);
}
}
public override void Update()
{
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
if (base.isEnemyDead)
{
return;
}
((EnemyAI)this).Update();
if (!((NetworkBehaviour)this).IsServer)
{
return;
}
_takeDamageCooldown -= Time.deltaTime;
if (!wanderEnabled)
{
return;
}
switch (base.currentBehaviourStateIndex)
{
case 0:
_wanderTimer -= Time.deltaTime;
if (_wanderTimer <= 0f)
{
SwitchBehaviourState(1);
}
else
{
MoveWithAcceleration();
}
break;
case 1:
base.agent.speed = 0f;
((Component)this).transform.position = _idlePosition;
break;
case 2:
MoveWithAcceleration();
break;
}
_ambientAudioTimer -= Time.deltaTime;
if (_ambientAudioTimer <= 0f)
{
_ambientAudioTimer = Random.Range(ambientSfxTimerRange.x, ambientSfxTimerRange.y);
if (_numberOfAmbientAudioClips != 0)
{
_netcodeController.PlayAmbientSfxClientRpc(_shishaId, Random.Range(0, _numberOfAmbientAudioClips));
}
}
}
public override void DoAIInterval()
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
((EnemyAI)this).DoAIInterval();
if (((NetworkBehaviour)this).IsServer && !base.isEnemyDead && base.currentBehaviourStateIndex == 2 && Vector3.Distance(((Component)this).transform.position, _runAwayTransform.position) <= 3f)
{
SwitchBehaviourState((!wanderEnabled) ? 1 : 0);
}
}
public override void DaytimeEnemyLeave()
{
if (((NetworkBehaviour)this).IsServer && SyncedInstance<ShishaConfig>.Instance.TimeInDayLeaveEnabled.Value)
{
((MonoBehaviour)this).StartCoroutine(LeaveWhenNoOneIsLooking(Random.Range(5f, 12f)));
((EnemyAI)this).DaytimeEnemyLeave();
}
}
private IEnumerator LeaveWhenNoOneIsLooking(float checkIntervalTimer)
{
while (IsPlayerLookingAtShisha(120f, 80))
{
yield return (object)new WaitForSeconds(checkIntervalTimer);
}
((EnemyAI)this).KillEnemyServerRpc(false);
Object.Destroy((Object)(object)((Component)this).gameObject);
}
private bool IsPlayerLookingAtShisha(float playerViewWidth = 30f, int playerViewRange = 60, float playerProximityAwareness = 3f)
{
return StartOfRound.Instance.allPlayerScripts.Where((PlayerControllerB player) => !player.isPlayerDead).Any((PlayerControllerB player) => player.HasLineOfSightToPosition(((Component)this).transform.position + Vector3.up * 0.5f, playerViewWidth, playerViewRange, playerProximityAwareness));
}
private void MoveWithAcceleration()
{
float num = Time.deltaTime / 2f;
base.agent.speed = Mathf.Lerp(base.agent.speed, _agentMaxSpeed, num);
float deltaTime = Time.deltaTime;
base.agent.acceleration = Mathf.Lerp(base.agent.acceleration, _agentMaxAcceleration, deltaTime);
}
private void InitializeState(int state)
{
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
LogDebug($"Initializing state: {state}");
switch (state)
{
case 0:
_agentMaxSpeed = maxSpeed;
_agentMaxAcceleration = maxAcceleration;
_wanderTimer = Random.Range(wanderTimeRange.x, wanderTimeRange.y);
((EnemyAI)this).StartSearch(anchoredWandering ? _spawnPosition : ((Component)this).transform.position, roamSearchRoutine);
break;
case 1:
base.agent.speed = 0f;
base.agent.acceleration = 40f;
_agentMaxSpeed = 0f;
_agentMaxAcceleration = maxAcceleration;
base.moveTowardsDestination = false;
_idlePosition = ((Component)this).transform.position;
if (roamSearchRoutine.inProgress)
{
((EnemyAI)this).StopSearch(roamSearchRoutine, true);
}
PickRandomIdleAnimation();
break;
case 2:
{
if (roamSearchRoutine.inProgress)
{
((EnemyAI)this).StopSearch(roamSearchRoutine, true);
}
NavMeshAgent agent = base.agent;
agent.speed *= 1.25f;
NavMeshAgent agent2 = base.agent;
agent2.acceleration *= 1.25f;
_agentMaxSpeed = runningAwayMaxSpeed;
_agentMaxAcceleration = runningAwayMaxAcceleration;
break;
}
case 3:
_netcodeController.SetAnimationBoolClientRpc(_shishaId, ShishaClient.IsDead, value: true);
if (roamSearchRoutine.inProgress)
{
((EnemyAI)this).StopSearch(roamSearchRoutine, true);
}
base.agent.speed = 0f;
base.agent.acceleration = 100f;
_agentMaxSpeed = 0f;
_agentMaxAcceleration = 100f;
base.moveTowardsDestination = false;
((EnemyAI)this).KillEnemyServerRpc(false);
break;
}
}
public void HandleIdleCompleteStateBehaviourCallback(string receivedShishaId)
{
if (((NetworkBehaviour)this).IsServer && !(_shishaId != receivedShishaId))
{
SwitchBehaviourState(0);
_netcodeController.SetAnimationTriggerClientRpc(_shishaId, ShishaClient.ForceWalk);
}
}
private void PickRandomIdleAnimation()
{
if (!((NetworkBehaviour)this).IsServer)
{
return;
}
float value = Random.value;
LogDebug($"Random value to determine chance of pooping: {value}");
if (value < poopChance && _poopBehaviourEnabled)
{
SpawnShishaPoop();
_netcodeController.SetAnimationTriggerClientRpc(_shishaId, ShishaClient.Poo);
return;
}
int num = Random.Range(1, 3);
int num2 = num switch
{
1 => ShishaClient.Idle1,
2 => ShishaClient.Idle2,
_ => 0,
};
if (num2 == 0)
{
LogDebug($"Unable to play animation with random number: {num}");
return;
}
LogDebug($"Playing animation with id: ({num}, {num2})");
_netcodeController.SetAnimationTriggerClientRpc(_shishaId, num2);
}
private void SpawnShishaPoop()
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
if (((NetworkBehaviour)this).IsServer)
{
if ((Object)(object)poopPlaceholder == (Object)null)
{
_mls.LogError((object)"PoopBehaviour is null, this should not happen.");
return;
}
GameObject val = Object.Instantiate<GameObject>(ShishaPlugin.ShishaPoopItem.spawnPrefab, poopPlaceholder.position, poopPlaceholder.rotation, poopPlaceholder);
val.GetComponent<ShishaPoopBehaviour>();
val.GetComponent<NetworkObject>().Spawn(false);
_netcodeController.SpawnShishaPoopClientRpc(_shishaId, NetworkObjectReference.op_Implicit(val));
}
}
public override void HitEnemy(int force = 1, PlayerControllerB playerWhoHit = null, bool playHitSFX = false, int hitId = -1)
{
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
((EnemyAI)this).HitEnemy(force, playerWhoHit, playHitSFX, hitId);
if (!((NetworkBehaviour)this).IsServer || base.isEnemyDead || base.currentBehaviourStateIndex == 3 || !_killable || _takeDamageCooldown > 0f)
{
return;
}
base.enemyHP -= force;
_takeDamageCooldown = 0.03f;
if (base.enemyHP > 0)
{
_runAwayTransform = GetFarthestValidNodeFromPosition(out var pathStatus, base.agent, ((Object)(object)playerWhoHit == (Object)null) ? ((Component)this).transform.position : ((Component)playerWhoHit).transform.position, base.allAINodes);
if (pathStatus == PathStatus.Invalid)
{
SwitchBehaviourState(0);
return;
}
((EnemyAI)this).SetDestinationToPosition(_runAwayTransform.position, false);
SwitchBehaviourState(2);
}
else
{
_netcodeController.TargetPlayerClientId.Value = (((Object)(object)playerWhoHit == (Object)null) ? 69420 : playerWhoHit.actualClientId);
SwitchBehaviourState(3);
}
}
private static Transform GetFarthestValidNodeFromPosition(out PathStatus pathStatus, NavMeshAgent agent, Vector3 position, IEnumerable<GameObject> allAINodes, IEnumerable<GameObject> ignoredAINodes = null, bool checkLineOfSight = false, bool allowFallbackIfBlocked = false, float bufferDistance = 1f, ManualLogSource logSource = null)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
return GetValidNodeFromPosition(findClosest: false, out pathStatus, agent, position, allAINodes, ignoredAINodes, checkLineOfSight, allowFallbackIfBlocked, bufferDistance, logSource);
}
private static Transform GetValidNodeFromPosition(bool findClosest, out PathStatus pathStatus, NavMeshAgent agent, Vector3 position, IEnumerable<GameObject> allAINodes, IEnumerable<GameObject> ignoredAINodes, bool checkLineOfSight, bool allowFallbackIfBlocked, float bufferDistance, ManualLogSource logSource)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
HashSet<GameObject> hashSet;
if (ignoredAINodes == null)
{
hashSet = new HashSet<GameObject>();
}
else
{
HashSet<GameObject> hashSet2 = new HashSet<GameObject>();
foreach (GameObject ignoredAINode in ignoredAINodes)
{
hashSet2.Add(ignoredAINode);
}
hashSet = hashSet2;
}
HashSet<GameObject> ignoredNodesSet = hashSet;
List<GameObject> list = allAINodes.Where((GameObject node) => !ignoredNodesSet.Contains(node) && Vector3.Distance(position, node.transform.position) > bufferDistance).ToList();
list.Sort(delegate(GameObject a, GameObject b)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: 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_0023: Unknown result type (might be due to invalid IL or missing references)
float value = Vector3.Distance(position, a.transform.position);
float value2 = Vector3.Distance(position, b.transform.position);
return (!findClosest) ? value2.CompareTo(value) : value.CompareTo(value2);
});
foreach (GameObject item in list)
{
pathStatus = IsPathValid(agent, item.transform.position, checkLineOfSight, 0f, logSource);
if (pathStatus == PathStatus.Valid)
{
return item.transform;
}
if (!(pathStatus == PathStatus.ValidButInLos && allowFallbackIfBlocked))
{
continue;
}
foreach (GameObject item2 in list)
{
if (!((Object)(object)item2 == (Object)(object)item) && IsPathValid(agent, item2.transform.position, checkLineOfSight: false, 0f, logSource) == PathStatus.Valid)
{
pathStatus = PathStatus.ValidButInLos;
return item2.transform;
}
}
}
pathStatus = PathStatus.Invalid;
return null;
}
private static PathStatus IsPathValid(NavMeshAgent agent, Vector3 position, bool checkLineOfSight = false, float bufferDistance = 0f, ManualLogSource logSource = null)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Expected O, but got Unknown
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: 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)
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
if (Vector3.Distance(((Component)agent).transform.position, position) <= bufferDistance)
{
return PathStatus.Valid;
}
NavMeshPath val = new NavMeshPath();
if (!agent.CalculatePath(position, val) || val.corners.Length == 0)
{
return PathStatus.Invalid;
}
if ((int)val.status != 0)
{
return PathStatus.Invalid;
}
if (checkLineOfSight)
{
if ((double)Vector3.Distance(val.corners[^1], RoundManager.Instance.GetNavMeshPosition(position, RoundManager.Instance.navHit, 2.7f, -1)) > 1.5)
{
return PathStatus.ValidButInLos;
}
for (int i = 1; i < val.corners.Length; i++)
{
if (Physics.Linecast(val.corners[i - 1], val.corners[i], 262144))
{
return PathStatus.ValidButInLos;
}
}
}
return PathStatus.Valid;
}
private void InitializeConfigValues()
{
//IL_0204: Unknown result type (might be due to invalid IL or missing references)
//IL_0209: Unknown result type (might be due to invalid IL or missing references)
//IL_022a: Unknown result type (might be due to invalid IL or missing references)
//IL_022f: Unknown result type (might be due to invalid IL or missing references)
if (((NetworkBehaviour)this).IsServer)
{
float num = Mathf.Clamp(SyncedInstance<ShishaConfig>.Instance.WanderTimeMin.Value, 0f, 500f);
float num2 = Mathf.Clamp(SyncedInstance<ShishaConfig>.Instance.AmbientSfxTimerMin.Value, 0f, 500f);
roamSearchRoutine.loopSearch = true;
roamSearchRoutine.searchWidth = Mathf.Clamp(SyncedInstance<ShishaConfig>.Instance.WanderRadius.Value, 50f, 500f);
base.creatureVoice.volume = Mathf.Clamp(SyncedInstance<ShishaConfig>.Default.AmbientSoundEffectsVolume.Value, 0f, 1f) * 2f;
base.creatureSFX.volume = Mathf.Clamp(SyncedInstance<ShishaConfig>.Default.FootstepSoundEffectsVolume.Value, 0f, 1f) * 2f;
anchoredWandering = SyncedInstance<ShishaConfig>.Instance.AnchoredWandering.Value;
maxSpeed = Mathf.Clamp(SyncedInstance<ShishaConfig>.Instance.MaxSpeed.Value, 0.1f, 100f);
maxAcceleration = Mathf.Clamp(SyncedInstance<ShishaConfig>.Instance.MaxAcceleration.Value, 0.1f, 100f);
runningAwayMaxSpeed = Mathf.Clamp(SyncedInstance<ShishaConfig>.Instance.RunningAwayMaxSpeed.Value, 0.1f, 100f);
runningAwayMaxAcceleration = Mathf.Clamp(SyncedInstance<ShishaConfig>.Instance.RunningAwayMaxAcceleration.Value, 0.1f, 100f);
_poopBehaviourEnabled = SyncedInstance<ShishaConfig>.Instance.PoopBehaviourEnabled.Value;
poopChance = Mathf.Clamp(SyncedInstance<ShishaConfig>.Instance.PoopChance.Value, 0f, 1f);
_killable = SyncedInstance<ShishaConfig>.Instance.Killable.Value;
base.enemyHP = Mathf.Max(SyncedInstance<ShishaConfig>.Instance.Health.Value, 1);
wanderTimeRange = new Vector2(num, Mathf.Clamp(SyncedInstance<ShishaConfig>.Instance.WanderTimeMax.Value, num, 1000f));
ambientSfxTimerRange = new Vector2(num2, Mathf.Clamp(SyncedInstance<ShishaConfig>.Instance.AmbientSfxTimerMax.Value, num2, 1000f));
}
}
private void SwitchBehaviourState(int state)
{
if (base.currentBehaviourStateIndex != state)
{
LogDebug($"Switching to behaviour state {state}.");
base.previousBehaviourStateIndex = base.currentBehaviourStateIndex;
base.currentBehaviourStateIndex = state;
_netcodeController.CurrentBehaviourStateIndex.Value = base.currentBehaviourStateIndex;
InitializeState(state);
LogDebug($"Switch to behaviour state {state} complete!");
}
}
private void HandleTargetPlayerChanged(ulong oldValue, ulong newValue)
{
_actualTargetPlayer.Value = ((newValue == 69420) ? null : StartOfRound.Instance.allPlayerScripts[newValue]);
base.targetPlayer = _actualTargetPlayer.Value;
LogDebug(_actualTargetPlayer.IsNotNull ? ("Changed target player to " + _actualTargetPlayer.Value?.playerUsername + ".") : "Changed target player to null.");
}
private void SubscribeToNetworkEvents()
{
if (((NetworkBehaviour)this).IsServer && !_networkEventsSubscribed)
{
_netcodeController.OnIdleCompleteStateBehaviourCallback += HandleIdleCompleteStateBehaviourCallback;
NetworkVariable<ulong> targetPlayerClientId = _netcodeController.TargetPlayerClientId;
targetPlayerClientId.OnValueChanged = (OnValueChangedDelegate<ulong>)(object)Delegate.Combine((Delegate?)(object)targetPlayerClientId.OnValueChanged, (Delegate?)(object)new OnValueChangedDelegate<ulong>(HandleTargetPlayerChanged));
_networkEventsSubscribed = true;
}
}
private void UnsubscribeFromNetworkEvents()
{
if (((NetworkBehaviour)this).IsServer && _networkEventsSubscribed)
{
_netcodeController.OnIdleCompleteStateBehaviourCallback -= HandleIdleCompleteStateBehaviourCallback;
NetworkVariable<ulong> targetPlayerClientId = _netcodeController.TargetPlayerClientId;
targetPlayerClientId.OnValueChanged = (OnValueChangedDelegate<ulong>)(object)Delegate.Remove((Delegate?)(object)targetPlayerClientId.OnValueChanged, (Delegate?)(object)new OnValueChangedDelegate<ulong>(HandleTargetPlayerChanged));
_networkEventsSubscribed = false;
}
}
private void LogDebug(string msg)
{
}
protected override void __initializeVariables()
{
((EnemyAI)this).__initializeVariables();
}
protected internal override string __getTypeName()
{
return "ShishaServer";
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "LethalCompanyShisha";
public const string PLUGIN_NAME = "LethalCompanyShisha";
public const string PLUGIN_VERSION = "1.1.4";
}
}
namespace LethalCompanyShisha.Types
{
public class CachedValue<T>
{
private readonly NullableObject<T> _cachedValue = new NullableObject<T>();
private readonly Func<T> _computeValueFunction;
public T Value
{
get
{
if (!_cachedValue.IsNotNull)
{
_cachedValue.Value = _computeValueFunction();
}
return _cachedValue.Value;
}
}
public CachedValue(Func<T> computeValueFunction, bool eager = false)
{
_computeValueFunction = computeValueFunction ?? throw new ArgumentNullException("computeValueFunction");
if (eager)
{
_cachedValue.Value = _computeValueFunction();
}
}
public void Reset()
{
_cachedValue.Value = default(T);
}
}
public class NullableObject<T>
{
private T _value;
public bool IsNotNull { get; private set; }
public T Value
{
get
{
return _value;
}
set
{
_value = value;
IsNotNull = !EqualityComparer<T>.Default.Equals(_value, default(T));
}
}
public NullableObject(T value = default(T))
{
Value = value;
}
}
}
namespace LethalCompanyShisha.CustomStateMachineBehaviours
{
public class BaseStateMachineBehaviour : StateMachineBehaviour
{
private ManualLogSource _mls;
protected string ShishaId;
protected readonly NullableObject<ShishaNetcodeController> NetcodeController = new NullableObject<ShishaNetcodeController>();
private bool _networkEventsSubscribed;
private void OnEnable()
{
SubscribeToNetworkEvents();
}
private void OnDisable()
{
UnsubscribeFromNetworkEvents();
}
public void Initialize(ShishaNetcodeController receivedNetcodeController)
{
NetcodeController.Value = receivedNetcodeController;
SubscribeToNetworkEvents();
}
private void HandleSyncShishaIdentifier(string receivedShishaId)
{
ShishaId = receivedShishaId;
ManualLogSource mls = _mls;
if (mls != null)
{
mls.Dispose();
}
_mls = Logger.CreateLogSource("Shisha Animation State Behaviour " + ShishaId);
LogDebug("Successfully synced shisha identifier.");
}
private void SubscribeToNetworkEvents()
{
if (!_networkEventsSubscribed && NetcodeController.IsNotNull)
{
NetcodeController.Value.OnSyncShishaIdentifier += HandleSyncShishaIdentifier;
_networkEventsSubscribed = true;
}
}
private void UnsubscribeFromNetworkEvents()
{
if (_networkEventsSubscribed && NetcodeController.IsNotNull)
{
NetcodeController.Value.OnSyncShishaIdentifier -= HandleSyncShishaIdentifier;
_networkEventsSubscribed = false;
}
}
protected void LogDebug(string msg)
{
}
}
public class IdleCompleteStateBehaviour : BaseStateMachineBehaviour
{
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if (!NetcodeController.IsNotNull)
{
LogDebug("Netcode Controller is null");
}
else if (NetworkManager.Singleton.IsServer && ((NetworkBehaviour)NetcodeController.Value).IsOwner)
{
LogDebug("Idle cycle complete");
NetcodeController.Value.IdleCompleteStateBehaviourCallbackServerRpc(ShishaId);
}
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}
namespace LethalCompanyShisha.NetcodePatcher
{
[AttributeUsage(AttributeTargets.Module)]
internal class NetcodePatchedAssemblyAttribute : Attribute
{
}
}