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.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Lily.Config;
using Lily.Scripts;
using Microsoft.CodeAnalysis;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Lily")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Lily")]
[assembly: AssemblyTitle("Lily")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace Lily
{
[BepInPlugin("Entity378.Lily", "Lily", "1.0.0")]
[BepInDependency("evaisa.lethallib", "0.14.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
private Harmony harmony = new Harmony("Entity378.Lily");
private const string GUID = "Entity378.Lily";
private const string NAME = "Lily";
private const string VERSION = "1.0.0";
public static AssetBundle bundle;
public static GameObject lilyProjectile;
public static GameObject realmFilterContainer;
public static GameObject realmFilter;
public static bool cullFactory;
private void Awake()
{
if (Chainloader.PluginInfos.ContainsKey("com.fumiko.CullFactory"))
{
cullFactory = true;
((BaseUnityPlugin)this).Logger.LogInfo((object)"LilyLog: CullFactory Founded");
}
LilyConfigs.LoadConfig(((BaseUnityPlugin)this).Config);
harmony.PatchAll();
harmony.PatchAll(typeof(LilyConfigs));
((BaseUnityPlugin)this).Logger.LogInfo((object)"LilyLog: Config loaded");
string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "lily");
bundle = AssetBundle.LoadFromFile(text);
lilyProjectile = bundle.LoadAsset<GameObject>("Assets/LethalCompany/Lily/Lily-Projectile.prefab");
lilyProjectile.AddComponent<Lily_ProjectileScript>();
Item val = bundle.LoadAsset<Item>("Assets/LethalCompany/Lily/Lily-Lantern-Item.asset");
AudioClip lilyLanternUseInside = bundle.LoadAsset<AudioClip>("Assets/LethalCompany/Lily/LilyRealmUse.ogg");
AudioClip lilyLanternEndInside = bundle.LoadAsset<AudioClip>("Assets/LethalCompany/Lily/LilyRealmEnd.ogg");
AudioClip lilyLanternError = bundle.LoadAsset<AudioClip>("Assets/LethalCompany/Lily/LilyRealmError.ogg");
AudioClip lilyLanternUseOutside = bundle.LoadAsset<AudioClip>("Assets/LethalCompany/Lily/LilyUseOutside.ogg");
AudioClip lilyLanternTeleportOutside = bundle.LoadAsset<AudioClip>("Assets/LethalCompany/Lily/LilyTeleportOutside.ogg");
LilyLanternScript lilyLanternScript = val.spawnPrefab.AddComponent<LilyLanternScript>();
((GrabbableObject)lilyLanternScript).itemProperties = val;
lilyLanternScript.lilyLanternUseInside = lilyLanternUseInside;
lilyLanternScript.lilyLanternEndInside = lilyLanternEndInside;
lilyLanternScript.lilyLanternError = lilyLanternError;
lilyLanternScript.lilyLanternUseOutside = lilyLanternUseOutside;
lilyLanternScript.lilyLanternTeleportOutside = lilyLanternTeleportOutside;
NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
Utilities.FixMixerGroups(val.spawnPrefab);
Items.RegisterScrap(val, LilyConfigs.LilySpawnRate, (LevelTypes)(-1));
SceneManager.sceneLoaded += OnSceneRelayLoaded;
}
private void OnSceneRelayLoaded(Scene scene, LoadSceneMode loadMode)
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Expected O, but got Unknown
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: 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)
//IL_0080: 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)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
try
{
if (((Scene)(ref scene)).name == "SampleSceneRelay")
{
GameObject val = GameObject.Find("IngamePlayerHUD");
realmFilterContainer = new GameObject("RealmFilterContainer");
realmFilterContainer.AddComponent<CanvasGroup>();
RectTransform val2 = realmFilterContainer.AddComponent<RectTransform>();
((Transform)val2).parent = val.transform;
((Transform)val2).localScale = Vector3.one;
val2.anchoredPosition = Vector2.zero;
((Transform)val2).localPosition = Vector2.op_Implicit(new Vector2(0f, 0f));
val2.sizeDelta = Vector2.one;
realmFilter = AddImageToHUD("Realm-Filter", scene);
GameObject[] array = (GameObject[])(object)new GameObject[1] { realmFilter };
GameObject[] array2 = array;
foreach (GameObject val3 in array2)
{
val3.transform.parent = realmFilterContainer.transform;
val3.transform.localPosition = Vector2.op_Implicit(Vector2.zero);
}
}
realmFilterContainer.SetActive(false);
}
catch
{
}
}
private GameObject AddImageToHUD(string imageName, Scene scene)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: 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_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: 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_008e: 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)
Sprite val = bundle.LoadAsset<Sprite>("Assets/LethalCompany/Lily/" + imageName + ".png");
GameObject val2 = new GameObject(imageName);
SceneManager.MoveGameObjectToScene(val2, scene);
GameObject val3 = GameObject.Find("IngamePlayerHUD");
RectTransform val4 = val2.AddComponent<RectTransform>();
((Transform)val4).parent = val3.transform;
((Transform)val4).localScale = Vector2.op_Implicit(Vector2.one);
val4.anchoredPosition = Vector2.zero;
((Transform)val4).localPosition = Vector2.op_Implicit(Vector2.zero);
Rect rect = val.rect;
float width = ((Rect)(ref rect)).width;
rect = val.rect;
val4.sizeDelta = new Vector2(width, ((Rect)(ref rect)).height);
Image val5 = val2.AddComponent<Image>();
val5.sprite = val;
CanvasRenderer val6 = val2.AddComponent<CanvasRenderer>();
return val2;
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "Lily";
public const string PLUGIN_NAME = "Lily";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace Lily.Scripts
{
internal class LilyLanternScript : PhysicsProp
{
public float time = LilyConfigs.LilyRealmTime;
public AudioSource audio;
public AudioClip lilyLanternUseInside;
public AudioClip lilyLanternEndInside;
public AudioClip lilyLanternError;
public AudioClip lilyLanternUseOutside;
public AudioClip lilyLanternTeleportOutside;
public float projectileSpeed = 20f;
public override void Start()
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Expected O, but got Unknown
((GrabbableObject)this).grabbable = true;
((GrabbableObject)this).grabbableToEnemies = false;
((GrabbableObject)this).insertedBattery = new Battery(false, 1f);
((GrabbableObject)this).mainObjectRenderer = ((Component)this).GetComponent<MeshRenderer>();
((GrabbableObject)this).useCooldown = LilyConfigs.LilyCooldown;
audio = ((Component)this).GetComponent<AudioSource>();
audio.bypassEffects = true;
audio.bypassListenerEffects = true;
audio.bypassReverbZones = true;
((GrabbableObject)this).Start();
}
public override void DiscardItem()
{
((GrabbableObject)this).DiscardItem();
}
public override void PocketItem()
{
((GrabbableObject)this).PocketItem();
}
public override void EquipItem()
{
((PhysicsProp)this).EquipItem();
}
public override void GrabItem()
{
((GrabbableObject)this).GrabItem();
}
public override void ItemActivate(bool used, bool buttonDown = true)
{
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
//IL_013f: Unknown result type (might be due to invalid IL or missing references)
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_014b: Unknown result type (might be due to invalid IL or missing references)
//IL_014d: Unknown result type (might be due to invalid IL or missing references)
//IL_0197: Unknown result type (might be due to invalid IL or missing references)
//IL_019f: Unknown result type (might be due to invalid IL or missing references)
((GrabbableObject)this).ItemActivate(used, buttonDown);
if (!buttonDown || !((Object)(object)((GrabbableObject)this).playerHeldBy != (Object)null) || !((Object)(object)((Component)((GrabbableObject)this).playerHeldBy).GetComponent<Lily_PlayerRealmScript>() != (Object)null))
{
return;
}
if (((GrabbableObject)this).insertedBattery.charge > 0f)
{
((GrabbableObject)this).insertedBattery.charge = ((GrabbableObject)this).insertedBattery.charge - LilyConfigs.LilyBatteryUsage;
if (((GrabbableObject)this).insertedBattery.charge < 0f)
{
((GrabbableObject)this).insertedBattery.charge = 0f;
}
if (((GrabbableObject)this).playerHeldBy.isInsideFactory && !((Component)((GrabbableObject)this).playerHeldBy).GetComponent<Lily_PlayerRealmScript>().isInRealm)
{
((MonoBehaviour)this).StartCoroutine(TeleportRealm(time));
}
else if (!((GrabbableObject)this).playerHeldBy.isInsideFactory)
{
audio.PlayOneShot(lilyLanternUseOutside);
Vector3 val = default(Vector3);
((Vector3)(ref val))..ctor(0f, 0.5f, 0f);
Vector3 val2 = ((Component)this).gameObject.transform.position + val;
Vector3 forward = ((Component)((GrabbableObject)this).playerHeldBy.gameplayCamera).transform.forward;
GameObject val3 = Object.Instantiate<GameObject>(Plugin.lilyProjectile, val2, Quaternion.identity);
Rigidbody component = val3.GetComponent<Rigidbody>();
val3.GetComponent<Lily_ProjectileScript>().player = ((GrabbableObject)this).playerHeldBy;
val3.GetComponent<Lily_ProjectileScript>().Item = ((Component)this).gameObject;
if ((Object)(object)component != (Object)null)
{
component.velocity = forward * projectileSpeed;
}
}
}
else
{
audio.PlayOneShot(lilyLanternError);
Debug.Log((object)"LilyLog: This item can't be used now");
}
}
private IEnumerator TeleportRealm(float time)
{
PlayerControllerB playerInRealm = ((GrabbableObject)this).playerHeldBy;
if (!((Component)playerInRealm).GetComponent<Lily_PlayerRealmScript>().isInRealm)
{
if ((Object)(object)playerInRealm == (Object)(object)GameNetworkManager.Instance.localPlayerController)
{
audio.PlayOneShot(lilyLanternUseInside);
}
else
{
PlaySoundForOtherPlayers(lilyLanternUseInside, ((Component)playerInRealm).transform.position);
}
if ((Object)(object)playerInRealm == (Object)(object)GameNetworkManager.Instance.localPlayerController)
{
Plugin.realmFilterContainer.SetActive(true);
}
RealmTeleportPlayer(playerInRealm, ((Component)this).gameObject);
yield return (object)new WaitForSeconds(time);
RealmTeleportPlayer(playerInRealm, ((Component)this).gameObject, enter: false);
if ((Object)(object)playerInRealm == (Object)(object)GameNetworkManager.Instance.localPlayerController)
{
Plugin.realmFilterContainer.SetActive(false);
}
audio.PlayOneShot(lilyLanternEndInside);
}
}
private static void RealmTeleportPlayer(PlayerControllerB playerInRealm, GameObject gameObject, bool enter = true)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: 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)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: 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_003a: 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_0042: Unknown result type (might be due to invalid IL or missing references)
Vector3 val = default(Vector3);
((Vector3)(ref val))..ctor(0f, 0.1f, -5000f);
Vector3 val2 = ((Component)playerInRealm).transform.position + val;
Vector3 val3 = ((Component)playerInRealm).transform.position - val;
if (enter)
{
playerInRealm.TeleportPlayer(val2, false, 0f, false, true);
((Component)playerInRealm).GetComponent<Lily_PlayerRealmScript>().isInRealm = true;
Debug.Log((object)("LilyLog: Player " + ((object)playerInRealm)?.ToString() + " is in the ShadowRealm"));
}
else
{
((Component)playerInRealm).GetComponent<Lily_PlayerRealmScript>().isInRealm = false;
playerInRealm.TeleportPlayer(val3, false, 0f, false, true);
Debug.Log((object)("LilyLog: Player " + ((object)playerInRealm)?.ToString() + " leaved the ShadowRealm"));
}
}
public static void PlaySoundForOtherPlayers(AudioClip clip, Vector3 position)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Expected O, but got Unknown
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)clip == (Object)null)
{
Debug.LogWarning((object)"LilyLog: Missing AudioClip!");
return;
}
GameObject val = new GameObject("TempAudioSource");
val.transform.position = position;
AudioSource val2 = val.AddComponent<AudioSource>();
val2.volume = 1f;
val2.spatialBlend = 1f;
val2.rolloffMode = (AudioRolloffMode)0;
val2.bypassEffects = true;
val2.bypassListenerEffects = true;
val2.bypassReverbZones = true;
val2.PlayOneShot(clip);
Object.Destroy((Object)(object)val, clip.length + 0.1f);
}
}
internal class Lily_PlayerRealmScript : MonoBehaviour
{
public bool isInRealm = false;
}
internal class Lily_ProjectileScript : MonoBehaviour
{
public PlayerControllerB player;
public GameObject Item;
public float teleportOffset = 0.5f;
public float checkDistance = 2f;
private void Start()
{
Object.Destroy((Object)(object)((Component)this).gameObject, 5f);
}
private void OnCollisionEnter(Collision collision)
{
//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_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: 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_0075: 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_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)player != (Object)null)
{
Vector3 point = ((ContactPoint)(ref collision.contacts[0])).point;
Vector3 normal = ((ContactPoint)(ref collision.contacts[0])).normal;
Vector3 val = point + normal * teleportOffset;
if (IsValidTeleportPoint(val))
{
player.TeleportPlayer(val, false, 0f, false, true);
}
else
{
Vector3 val2 = FindSafeTeleportPoint(val);
player.TeleportPlayer(val2, false, 0f, false, true);
}
if ((Object)(object)Item.GetComponent<AudioSource>() != (Object)null && (Object)(object)Item.GetComponent<LilyLanternScript>() != (Object)null)
{
Item.GetComponent<AudioSource>().Stop();
Item.GetComponent<AudioSource>().PlayOneShot(Item.GetComponent<LilyLanternScript>().lilyLanternTeleportOutside);
}
else
{
Debug.LogWarning((object)"LilyLog: AudioSource or LilyLanternScript is null");
}
}
Object.Destroy((Object)(object)((Component)this).gameObject);
}
private bool IsValidTeleportPoint(Vector3 point)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
if (Physics.Raycast(point, Vector3.up, checkDistance))
{
return false;
}
if (Physics.Raycast(point, Vector3.down, checkDistance))
{
return false;
}
return true;
}
private Vector3 FindSafeTeleportPoint(Vector3 initialPoint)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: 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_0020: 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_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: 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)
Vector3 val = initialPoint;
while (!IsValidTeleportPoint(val) && val.y > 0f)
{
val.y -= 0.1f;
}
if (IsValidTeleportPoint(val))
{
return val;
}
return initialPoint;
}
}
}
namespace Lily.Patches
{
[HarmonyPatch(typeof(EntranceTeleport))]
internal class EntranceTeleportPlayer_Patch
{
[HarmonyPrefix]
[HarmonyPatch("TeleportPlayer")]
public static bool EntranceTeleportPlayerPatch()
{
if (!Object.op_Implicit((Object)(object)((Component)GameNetworkManager.Instance.localPlayerController).GetComponent<Lily_PlayerRealmScript>()) || ((Component)GameNetworkManager.Instance.localPlayerController).GetComponent<Lily_PlayerRealmScript>().isInRealm)
{
Debug.Log((object)"LilyLog: Teleport Failed");
return false;
}
return true;
}
}
[HarmonyPatch(typeof(StartOfRound))]
internal class OpeningDoorsSequence_Patch
{
public static GameObject RealmInsideLevel;
[HarmonyPostfix]
[HarmonyPatch(typeof(StartOfRound), "openingDoorsSequence")]
private static IEnumerator openingDoorsSequencePatch(IEnumerator result)
{
yield return (object)new WaitForSeconds(1f);
string sceneName = StartOfRound.Instance.currentLevel.sceneName;
Scene currentScene = SceneManager.GetSceneByName(sceneName);
Vector3 bonusCoord = new Vector3(0f, 0f, -5000f);
GameObject levelGeneration = GameObject.Find("/Systems/LevelGeneration/LevelGenerationRoot");
if (((Object)levelGeneration).name == "LevelGenerationRoot")
{
Vector3 originCoord = levelGeneration.transform.position;
Quaternion originRot2 = levelGeneration.transform.rotation;
Vector3 finalCoord2 = originCoord + bonusCoord;
RealmInsideLevel = Object.Instantiate<GameObject>(levelGeneration, finalCoord2, originRot2);
SceneManager.MoveGameObjectToScene(RealmInsideLevel, currentScene);
if (Plugin.cullFactory)
{
RemoveComponentInChildren(RealmInsideLevel, "CullingVisualizer");
RemoveComponentInChildren(RealmInsideLevel, "PortalOcclusionCuller");
RemoveComponentInChildren(RealmInsideLevel, "DepthCuller");
}
EnableLights(flag: LilyConfigs.LilyRealmLights ? 1 : 0, root: RealmInsideLevel);
}
GameObject[] sceneObjects = ((Scene)(ref currentScene)).GetRootGameObjects();
GameObject[] array = sceneObjects;
foreach (GameObject obj in array)
{
if (((Object)obj).name.Contains("EntranceTeleport") || (Object)(object)obj.GetComponent<EntranceTeleport>() != (Object)null)
{
Vector3 originCoord2 = obj.transform.position;
Quaternion originRot = obj.transform.rotation;
Vector3 finalCoord = originCoord2 + bonusCoord;
GameObject door = Object.Instantiate<GameObject>(obj, finalCoord, originRot);
try
{
Object.Destroy((Object)(object)door.GetComponent<EntranceTeleport>());
Object.Destroy((Object)(object)door.GetComponent<InteractTrigger>());
SceneManager.MoveGameObjectToScene(door, currentScene);
}
catch
{
Debug.Log((object)("LilyLog: Door Components Error" + (object)door));
}
}
}
while (result.MoveNext())
{
yield return result.Current;
}
}
private static void RemoveComponentInChildren(GameObject root, string componentName)
{
try
{
Component[] componentsInChildren = root.GetComponentsInChildren<Component>(true);
Component[] array = componentsInChildren;
foreach (Component val in array)
{
if (((object)val).GetType().Name == componentName)
{
Object.Destroy((Object)(object)val);
}
}
}
catch
{
Debug.Log((object)("CLilyLog: omponents with the name " + componentName + " Error"));
}
}
private static void EnableLights(GameObject root, int flag)
{
try
{
Light[] componentsInChildren = root.GetComponentsInChildren<Light>(true);
Light[] array = componentsInChildren;
foreach (Light val in array)
{
if (val.cullingMask != flag)
{
val.cullingMask = flag;
}
}
}
catch
{
Debug.Log((object)"LilyLog: Lights Error");
}
}
}
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerBTeleportPlayer_Patch
{
[HarmonyPrefix]
[HarmonyPatch("TeleportPlayer")]
public static bool PlayerControllerBTeleportPlayerPatch(PlayerControllerB __instance)
{
if (!Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<Lily_PlayerRealmScript>()) || ((Component)__instance).GetComponent<Lily_PlayerRealmScript>().isInRealm)
{
Debug.Log((object)"LilyLog: Teleport Failed");
return false;
}
return true;
}
}
[HarmonyPatch(typeof(ShipTeleporter))]
internal class PressTeleportButtonOnLocalClient_Patch
{
[HarmonyPrefix]
[HarmonyPatch("PressTeleportButtonOnLocalClient")]
public static bool PressTeleportButtonOnLocalClientPatch()
{
if (!Object.op_Implicit((Object)(object)StartOfRound.Instance.mapScreen.targetedPlayer))
{
PlayerControllerB targetedPlayer = StartOfRound.Instance.mapScreen.targetedPlayer;
if (!Object.op_Implicit((Object)(object)((Component)targetedPlayer).GetComponent<Lily_PlayerRealmScript>()) || ((Component)targetedPlayer).GetComponent<Lily_PlayerRealmScript>().isInRealm)
{
Debug.Log((object)"LilyLog: Teleport Failed");
return false;
}
}
return true;
}
}
[HarmonyPatch(typeof(PlayerControllerB))]
internal class Start_Patch
{
[HarmonyPostfix]
[HarmonyPatch("Start")]
public static void StartPatch()
{
List<PlayerControllerB> list = (from PlayerControllerB e in Resources.FindObjectsOfTypeAll(typeof(PlayerControllerB))
where (Object)(object)e != (Object)null
select e).ToList();
foreach (PlayerControllerB item in list)
{
if ((Object)(object)((Component)item).GetComponent<Lily_PlayerRealmScript>() == (Object)null)
{
((Component)item).gameObject.AddComponent<Lily_PlayerRealmScript>();
}
}
}
}
}
namespace Lily.Config
{
internal class LilyConfigs
{
[CompilerGenerated]
private static class <>O
{
public static HandleNamedMessageDelegate <0>__OnRequestSync;
public static HandleNamedMessageDelegate <1>__OnReceiveSync;
}
private const int byteDim = 4;
private const int byteDimConfig = 17;
private static int LilySpawnRateLocal = 10;
private static float LilyCooldownLocal = 5f;
private static float LilyRealmTimeLocal = 3f;
private static float LilyBatteryUsageLocal = 0.34f;
private static bool LilyRealmLightsLocal = true;
public static int LilySpawnRate = 10;
public static float LilyCooldown = 5f;
public static float LilyRealmTime = 3f;
public static float LilyBatteryUsage = 0.34f;
public static bool LilyRealmLights = true;
private static void SetValues(int SpawnRate, float Cooldown, float RealmTime, float BatteryUsage, bool RealmLights)
{
LilySpawnRate = SpawnRate;
LilyCooldown = Cooldown;
LilyRealmTime = RealmTime;
LilyBatteryUsage = BatteryUsage;
LilyRealmLights = RealmLights;
}
private static void SetToLocalValues()
{
SetValues(LilySpawnRateLocal, LilyCooldownLocal, LilyRealmTimeLocal, LilyBatteryUsageLocal, LilyRealmLightsLocal);
}
public static void LoadConfig(ConfigFile config)
{
LilySpawnRateLocal = Math.Clamp(config.Bind<int>("General", "LilySpawnRate", 10, "Sets Lily spawn rate, the higher the value, the more common it will be (recommended to keep it between 5 and 40).").Value, 0, 9999);
LilyCooldownLocal = Mathf.Clamp(config.Bind<int>("General", "LilyCooldown", 5, "Sets Lily cooldown.").Value, 0, 9999);
LilyRealmTimeLocal = Mathf.Clamp(config.Bind<int>("General", "LilyRealmTime", 3, "Sets Lily realm time.").Value, 0, 9999);
LilyBatteryUsageLocal = Mathf.Clamp(config.Bind<float>("General", "LilyBatteryUsage", 0.34f, "Sets Lily battery usage (in the case of the default value it removes 34% of the battery with each use).").Value, 0f, 9999f);
LilyRealmLightsLocal = config.Bind<bool>("General", "LilyRealmLight", true, "Sets the Realm Lights. If FALSE the realm will be without any form of light sourses (Very Dark).").Value;
SetToLocalValues();
}
public static byte[] GetSettings()
{
byte[] array = new byte[17]
{
1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0
};
Array.Copy(BitConverter.GetBytes(LilySpawnRateLocal), 0, array, 1, 4);
Array.Copy(BitConverter.GetBytes(LilyCooldownLocal), 0, array, 5, 4);
Array.Copy(BitConverter.GetBytes(LilyRealmTimeLocal), 0, array, 9, 4);
Array.Copy(BitConverter.GetBytes(LilyBatteryUsageLocal), 0, array, 13, 4);
Array.Copy(BitConverter.GetBytes(LilyRealmLightsLocal), 0, array, 14, 1);
return array;
}
public static void SetSettings(byte[] data)
{
byte b = data[0];
byte b2 = b;
if (b2 == 1)
{
LilySpawnRate = BitConverter.ToInt32(data, 1);
LilyCooldown = BitConverter.ToSingle(data, 5);
LilyRealmTime = BitConverter.ToSingle(data, 9);
LilyBatteryUsage = BitConverter.ToSingle(data, 13);
LilyRealmLights = BitConverter.ToBoolean(data, 14);
Debug.Log((object)"LilyLog: Host config set successfully");
return;
}
throw new Exception("LilyLog: Invalid version byte");
}
private static bool IsHost()
{
return NetworkManager.Singleton.IsHost;
}
public static void OnRequestSync(ulong clientID, FastBufferReader reader)
{
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
if (!IsHost())
{
return;
}
Debug.Log((object)("LilyLog: Sending config to client " + clientID));
byte[] settings = GetSettings();
FastBufferWriter val = default(FastBufferWriter);
((FastBufferWriter)(ref val))..ctor(settings.Length, (Allocator)2, settings.Length);
try
{
((FastBufferWriter)(ref val)).WriteBytes(settings, -1, 0);
NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("Lily_OnReceiveConfigSync", clientID, val, (NetworkDelivery)2);
}
catch (Exception ex)
{
Debug.LogError((object)("LilyLog: Failed to send config: " + ex));
}
finally
{
((FastBufferWriter)(ref val)).Dispose();
}
}
public static void OnReceiveSync(ulong clientID, FastBufferReader reader)
{
Debug.Log((object)"LilyLog: Received config from host");
byte[] settings = new byte[17];
try
{
((FastBufferReader)(ref reader)).ReadBytes(ref settings, 17, 0);
SetSettings(settings);
}
catch (Exception ex)
{
Debug.LogError((object)("LilyLog: Failed to receive config: " + ex));
SetToLocalValues();
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
private static void ServerConnect()
{
//IL_00a7: 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_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Expected O, but got Unknown
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Expected O, but got Unknown
if (IsHost())
{
Debug.Log((object)"LilyLog: Started hosting, using local settings");
SetToLocalValues();
CustomMessagingManager customMessagingManager = NetworkManager.Singleton.CustomMessagingManager;
object obj = <>O.<0>__OnRequestSync;
if (obj == null)
{
HandleNamedMessageDelegate val = OnRequestSync;
<>O.<0>__OnRequestSync = val;
obj = (object)val;
}
customMessagingManager.RegisterNamedMessageHandler("Lily_OnRequestConfigSync", (HandleNamedMessageDelegate)obj);
return;
}
Debug.Log((object)"LilyLog: Connected to server, requesting settings");
CustomMessagingManager customMessagingManager2 = NetworkManager.Singleton.CustomMessagingManager;
object obj2 = <>O.<1>__OnReceiveSync;
if (obj2 == null)
{
HandleNamedMessageDelegate val2 = OnReceiveSync;
<>O.<1>__OnReceiveSync = val2;
obj2 = (object)val2;
}
customMessagingManager2.RegisterNamedMessageHandler("Lily_OnReceiveConfigSync", (HandleNamedMessageDelegate)obj2);
FastBufferWriter val3 = default(FastBufferWriter);
((FastBufferWriter)(ref val3))..ctor(17, (Allocator)2, -1);
NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("Lily_OnRequestConfigSync", 0uL, val3, (NetworkDelivery)2);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(GameNetworkManager), "StartDisconnect")]
private static void ServerDisconnect()
{
Debug.Log((object)"LilyLog: Server disconnect");
SetToLocalValues();
}
}
}