using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Unity.IL2CPP;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Mirror;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("LanternPercent")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LanternPercent")]
[assembly: AssemblyTitle("LanternPercent")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BigWalkLanternPercent;
[BepInPlugin("com.tetraflash.bigwalk.BigWalkLanternPercent", "Lantern Percent", "1.0.4")]
public class LanternPercentPlugin : BasePlugin
{
internal static ConfigFile ModConfigFile;
internal static ConfigEntry<int> FontSizeEntry;
internal static ConfigEntry<int> ColorIndexEntry;
internal static ConfigEntry<bool> ShowPercentageEntry;
public override void Load()
{
ModConfigFile = ((BasePlugin)this).Config;
FontSizeEntry = ModConfigFile.Bind<int>("HUD", "FontSize", 36, "Font size of the buoy counter in the top-right corner (adjust in-game with Alt + and Alt -).");
ColorIndexEntry = ModConfigFile.Bind<int>("HUD", "ColorIndex", 1, "Color of the buoy counter (1 to 8, cycle in-game with Ctrl + and Ctrl -): 1 = Orange, 2 = Yellow, 3 = Green, 4 = Cyan, 5 = Blue, 6 = Purple, 7 = Pink, 8 = Red.");
ShowPercentageEntry = ModConfigFile.Bind<bool>("HUD", "ShowPercentage", false, "Whether to display the completion percentage next to the buoy count (toggle in-game with Shift + 5).");
ModConfigFile.Save();
((BasePlugin)this).Log.LogInfo((object)"Lantern Percent Mod v1.0.26 has loaded!");
ClassInjector.RegisterTypeInIl2Cpp<TextBehaviour>();
ClassInjector.RegisterTypeInIl2Cpp<BuoyCompassBehaviour>();
((BasePlugin)this).AddComponent<TextBehaviour>();
}
internal static void SaveHudSettings(int fontSize, int colorIndex, bool showPercentage)
{
try
{
if (FontSizeEntry != null)
{
FontSizeEntry.Value = fontSize;
}
if (ColorIndexEntry != null)
{
ColorIndexEntry.Value = colorIndex;
}
if (ShowPercentageEntry != null)
{
ShowPercentageEntry.Value = showPercentage;
}
ConfigFile modConfigFile = ModConfigFile;
if (modConfigFile != null)
{
modConfigFile.Save();
}
}
catch (Exception ex)
{
Debug.LogWarning(Object.op_Implicit("[LanternPercent] Failed to save HUD config: " + ex.Message));
}
}
}
public class TextBehaviour : MonoBehaviour
{
private struct UnlitBuoyEntry
{
public Transform buoyTransform;
public Transform lightTransform;
public string deterministicKey;
public int priorityScore;
}
private class Spark
{
public Vector2 position;
public Vector2 velocity;
public Color color;
public float lifetime;
}
private static readonly Color[] HudCounterColors = (Color[])(object)new Color[8]
{
new Color(1f, 0.5f, 0f),
new Color(1f, 0.92f, 0f),
new Color(0.1f, 1f, 0.25f),
new Color(0f, 1f, 1f),
new Color(0.25f, 0.6f, 1f),
new Color(0.75f, 0.35f, 1f),
new Color(1f, 0.25f, 0.8f),
new Color(1f, 0.2f, 0.2f)
};
private static readonly string[] HudCounterColorNames = new string[8] { "Orange", "Yellow", "Green", "Cyan", "Blue", "Purple", "Pink", "Red" };
public const float NeedleMeshAngleOffset = 180f;
public static readonly Vector3 MapRoomSpawnPos = new Vector3(-121.6115f, 48.8635f, -505.5f);
public const string LostAndFoundSaveKey = "lantern_percent_compass_laf";
private const string BuoySaveKeyPrefix = "lp_buoy_lit_";
private const ushort BaseCustomTicket = 58624;
private const uint CustomCompassAssetIdBase = 146815488u;
private const int SessionSeedCount = 256;
private static int receivedNetworkSeed = 0;
private int lastAppliedSessionSeed = -1;
private const float SaveRestoreDelaySeconds = 6f;
private int litBuoys = 0;
private int totalBuoys = 0;
private string displayText = "Initializing Scanner...";
private float timer = 0f;
private float updateInterval = 0.5f;
private float worldReadyTime = -1f;
private bool worldWasReady = false;
private int currentFontSize = 36;
private int currentColorIndex = 1;
private bool showPercentage = false;
private bool configLoaded = false;
private Transform currentTrackedBuoy = null;
private Transform currentTrackedBuoyLight = null;
private string currentTrackedBuoyKey = null;
private Dictionary<int, string> buoyKeyCache = new Dictionary<int, string>();
private Dictionary<int, Color> buoyVibrantColors = new Dictionary<int, Color>();
private Dictionary<int, bool> buoyLastLitState = new Dictionary<int, bool>();
private HashSet<int> nonPedestalBuoyIds = new HashSet<int>();
private HashSet<int> restoredBuoyIdsThisLoad = new HashSet<int>();
private Dictionary<int, bool> nonPedestalSavedStateCache = new Dictionary<int, bool>();
private List<string> victoryTextHexColors = new List<string>();
private bool hasWon = false;
private bool isFireworksActive = false;
private float fireworksEndTime = 0f;
private float nextExplosionTime = 0f;
private List<Spark> activeSparks = new List<Spark>();
public static GameObject purpleCompassInstance = null;
private static GameObject compassTemplate = null;
private static Transform templateHolder = null;
private SpawnDelegate cachedSpawnDelegate = null;
private UnSpawnDelegate cachedUnspawnDelegate = null;
public static Vector2 TargetUnlitBuoyXZ { get; private set; }
public static float CurrentLineLength { get; private set; }
public static float CurrentLineBearingDeg { get; private set; }
public static bool HasUnlitBuoy { get; private set; }
public static bool AllBuoysLit { get; private set; }
public static Transform ActiveCompassTransform { get; set; }
public static int SessionSeed { get; private set; } = 0;
public TextBehaviour(IntPtr handle)
: base(handle)
{
}
private void Start()
{
LoadHudSettingsFromConfig();
EnsureSpawnHandlersRegistered();
}
private void LoadHudSettingsFromConfig()
{
if (configLoaded)
{
return;
}
configLoaded = true;
if (LanternPercentPlugin.FontSizeEntry != null)
{
currentFontSize = Mathf.Max(10, LanternPercentPlugin.FontSizeEntry.Value);
}
if (LanternPercentPlugin.ColorIndexEntry != null)
{
int num = LanternPercentPlugin.ColorIndexEntry.Value;
if (num < 1 || num > HudCounterColors.Length)
{
num = 1;
}
currentColorIndex = num;
}
if (LanternPercentPlugin.ShowPercentageEntry != null)
{
showPercentage = LanternPercentPlugin.ShowPercentageEntry.Value;
}
}
private void Update()
{
//IL_0423: Unknown result type (might be due to invalid IL or missing references)
//IL_042a: Unknown result type (might be due to invalid IL or missing references)
//IL_0434: Unknown result type (might be due to invalid IL or missing references)
//IL_0439: Unknown result type (might be due to invalid IL or missing references)
//IL_043e: Unknown result type (might be due to invalid IL or missing references)
//IL_0378: Unknown result type (might be due to invalid IL or missing references)
if (!configLoaded)
{
LoadHudSettingsFromConfig();
}
EnsureSpawnHandlersRegistered();
if (receivedNetworkSeed > 0 && SessionSeed != receivedNetworkSeed)
{
SessionSeed = receivedNetworkSeed;
}
if (!NetworkClient.active && !NetworkServer.active && !WorldManager.isReadyForEffects)
{
receivedNetworkSeed = 0;
SessionSeed = 0;
}
bool flag = Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307);
bool flag2 = Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305);
bool flag3 = Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303);
if (flag && !flag2)
{
if (Input.GetKeyDown((KeyCode)61) || Input.GetKeyDown((KeyCode)270))
{
currentFontSize += 2;
LanternPercentPlugin.SaveHudSettings(currentFontSize, currentColorIndex, showPercentage);
}
else if (Input.GetKeyDown((KeyCode)45) || Input.GetKeyDown((KeyCode)269))
{
currentFontSize = Mathf.Max(10, currentFontSize - 2);
LanternPercentPlugin.SaveHudSettings(currentFontSize, currentColorIndex, showPercentage);
}
}
if (flag2 && !flag)
{
if (Input.GetKeyDown((KeyCode)61) || Input.GetKeyDown((KeyCode)270))
{
currentColorIndex = currentColorIndex % HudCounterColors.Length + 1;
LanternPercentPlugin.SaveHudSettings(currentFontSize, currentColorIndex, showPercentage);
Debug.Log(Object.op_Implicit($"[LanternPercent] Counter color set to #{currentColorIndex} ({HudCounterColorNames[currentColorIndex - 1]})."));
}
else if (Input.GetKeyDown((KeyCode)45) || Input.GetKeyDown((KeyCode)269))
{
currentColorIndex = ((currentColorIndex <= 1) ? HudCounterColors.Length : (currentColorIndex - 1));
LanternPercentPlugin.SaveHudSettings(currentFontSize, currentColorIndex, showPercentage);
Debug.Log(Object.op_Implicit($"[LanternPercent] Counter color set to #{currentColorIndex} ({HudCounterColorNames[currentColorIndex - 1]})."));
}
}
if (flag3)
{
if (Input.GetKeyDown((KeyCode)53))
{
showPercentage = !showPercentage;
LanternPercentPlugin.SaveHudSettings(currentFontSize, currentColorIndex, showPercentage);
UpdateBuoyCount();
}
if (Input.GetKeyDown((KeyCode)114) && (Object)(object)purpleCompassInstance != (Object)null && NetworkServer.active)
{
SaveManager.SetIntValue("lantern_percent_compass_laf", 0);
BuoyCompassBehaviour.TeleportCompassTo(MapRoomSpawnPos, anchorUntilPlayerNear: true);
Debug.Log(Object.op_Implicit("[LanternPercent] Purple compass recalled to Map Room by Host."));
}
}
if (isFireworksActive)
{
if (Time.unscaledTime > fireworksEndTime)
{
isFireworksActive = false;
}
else if (Time.unscaledTime >= nextExplosionTime)
{
SpawnExplosion();
nextExplosionTime = Time.unscaledTime + Random.Range(0.3f, 1.2f);
}
}
for (int num = activeSparks.Count - 1; num >= 0; num--)
{
Spark spark = activeSparks[num];
spark.position += spark.velocity * Time.unscaledDeltaTime;
spark.velocity.y += 400f * Time.unscaledDeltaTime;
spark.lifetime -= Time.unscaledDeltaTime;
if (spark.lifetime <= 0f)
{
activeSparks.RemoveAt(num);
}
}
if (!WorldManager.isReadyForEffects)
{
if (worldWasReady)
{
worldWasReady = false;
worldReadyTime = -1f;
lastAppliedSessionSeed = -1;
currentTrackedBuoy = null;
currentTrackedBuoyLight = null;
currentTrackedBuoyKey = null;
HasUnlitBuoy = false;
buoyKeyCache.Clear();
buoyVibrantColors.Clear();
buoyLastLitState.Clear();
nonPedestalBuoyIds.Clear();
restoredBuoyIdsThisLoad.Clear();
nonPedestalSavedStateCache.Clear();
victoryTextHexColors.Clear();
}
return;
}
if (!worldWasReady)
{
worldWasReady = true;
worldReadyTime = Time.unscaledTime;
GetOrCaptureCompassTemplate();
CacheInitialBuoysOnLoad();
if (NetworkServer.active && SessionSeed == 0)
{
SessionSeed = Random.Range(1, 256);
receivedNetworkSeed = SessionSeed;
Debug.Log(Object.op_Implicit($"[LanternPercent] Host initialized SessionSeed = {SessionSeed}"));
}
}
if (NetworkServer.active && (Object)(object)purpleCompassInstance == (Object)null && Time.unscaledTime - worldReadyTime > 0.5f)
{
TrySpawnNativePurpleCompassOnServer();
}
timer += Time.deltaTime;
if (timer >= updateInterval)
{
timer = 0f;
UpdateBuoyCount();
}
}
private void LateUpdate()
{
if ((Object)(object)BuoyCompassBehaviour.Instance != (Object)null)
{
BuoyCompassBehaviour.Instance.TickCompass();
}
}
private void CacheInitialBuoysOnLoad()
{
try
{
Il2CppArrayBase<PropKernal> val = Object.FindObjectsOfType<PropKernal>();
if (val == null)
{
return;
}
int num = 0;
foreach (PropKernal item in val)
{
if ((Object)(object)item == (Object)null)
{
continue;
}
Transform val2 = ((Component)item).transform.Find("buoy");
if (!((Object)(object)val2 == (Object)null))
{
int instanceID = ((Object)item).GetInstanceID();
GetDeterministicBuoyKey(item, val2);
if (DetectNonPedestalBuoy(item) && nonPedestalBuoyIds.Add(instanceID))
{
num++;
}
}
}
Debug.Log(Object.op_Implicit($"[LanternPercent] Cached initial buoy roster ({num} non-pedestal/unsaved buoy(s) tracked for custom save/restore)."));
}
catch (Exception ex)
{
Debug.LogWarning(Object.op_Implicit("[LanternPercent] CacheInitialBuoysOnLoad warning: " + ex.Message));
}
}
private bool DetectNonPedestalBuoy(PropKernal kernal)
{
Prop componentInParent = ((Component)kernal).GetComponentInParent<Prop>();
GameObject val = (((Object)(object)componentInParent != (Object)null) ? ((Component)componentInParent).gameObject : ((Component)kernal).gameObject);
string name = ((Object)val).name;
if ((name.StartsWith("BuoyProp", StringComparison.Ordinal) || name.StartsWith("BuoyRedProp", StringComparison.Ordinal)) && ((Object)(object)componentInParent == (Object)null || (Object)(object)componentInParent.startHome == (Object)null))
{
return true;
}
if ((Object)(object)componentInParent != (Object)null && (Object)(object)componentInParent.startHome == (Object)null && (Object)(object)componentInParent.currentHome == (Object)null)
{
return true;
}
Il2CppArrayBase<TrackedPeckState> componentsInChildren = val.GetComponentsInChildren<TrackedPeckState>(true);
if (componentsInChildren != null && componentsInChildren.Length > 0)
{
bool flag = false;
foreach (TrackedPeckState item in componentsInChildren)
{
if ((Object)(object)item != (Object)null && (Object)(object)item.saveIdentity != (Object)null && !string.IsNullOrEmpty(item.saveIdentity.saveGuid))
{
flag = true;
break;
}
}
if (!flag)
{
return true;
}
}
return false;
}
private void RestoreNonPedestalBuoyOnServer(PropKernal kernal, Transform buoyTransform, Transform lightTransform, string buoyKey)
{
if (!NetworkServer.active || (Object)(object)kernal == (Object)null)
{
return;
}
try
{
Prop componentInParent = ((Component)kernal).GetComponentInParent<Prop>();
GameObject val = (((Object)(object)componentInParent != (Object)null) ? ((Component)componentInParent).gameObject : ((Component)kernal).gameObject);
bool value = false;
Il2CppArrayBase<TrackedPeckState> componentsInChildren = val.GetComponentsInChildren<TrackedPeckState>(true);
if (componentsInChildren != null)
{
foreach (TrackedPeckState item in componentsInChildren)
{
if (!((Object)(object)item == (Object)null))
{
if (item.currentPeckContext.state < 1)
{
item.SetState(1);
}
value = true;
}
}
}
Il2CppArrayBase<PeckSwitch> componentsInChildren2 = val.GetComponentsInChildren<PeckSwitch>(true);
if (componentsInChildren2 != null)
{
foreach (PeckSwitch item2 in componentsInChildren2)
{
if ((Object)(object)item2 != (Object)null && (Object)(object)item2.trackedStateSystem != (Object)null)
{
if (item2.trackedStateSystem.currentPeckContext.state < 1)
{
item2.trackedStateSystem.SetState(1);
}
value = true;
}
}
}
if ((Object)(object)lightTransform != (Object)null && !((Component)lightTransform).gameObject.activeSelf)
{
((Component)lightTransform).gameObject.SetActive(true);
}
foreach (Transform componentsInChild in val.GetComponentsInChildren<Transform>(true))
{
if ((Object)(object)componentsInChild != (Object)null && ((Object)componentsInChild).name == "LobbyFlareMesh" && !((Component)componentsInChild).gameObject.activeSelf)
{
((Component)componentsInChild).gameObject.SetActive(true);
}
}
Debug.Log(Object.op_Implicit($"[LanternPercent] Restored saved lit state for non-pedestal buoy '{buoyKey}' (via PeckState={value})."));
}
catch (Exception ex)
{
Debug.LogWarning(Object.op_Implicit("[LanternPercent] Failed to restore non-pedestal buoy '" + buoyKey + "': " + ex.Message));
}
}
private void EnsureSpawnHandlersRegistered()
{
try
{
if (NetworkClient.spawnHandlers == null || !NetworkClient.spawnHandlers.ContainsKey(146815489u))
{
if ((Delegate)(object)cachedSpawnDelegate == (Delegate)null)
{
cachedSpawnDelegate = DelegateSupport.ConvertDelegate<SpawnDelegate>((Delegate)new Func<Vector3, uint, GameObject>(OnClientSpawnCompass));
}
if ((Delegate)(object)cachedUnspawnDelegate == (Delegate)null)
{
cachedUnspawnDelegate = DelegateSupport.ConvertDelegate<UnSpawnDelegate>((Delegate)new Action<GameObject>(OnClientUnSpawnCompass));
}
for (uint num = 0u; num < 256; num++)
{
uint num2 = 146815488 + num;
NetworkClient.RegisterSpawnHandler(num2, cachedSpawnDelegate, cachedUnspawnDelegate);
}
Debug.Log(Object.op_Implicit("[LanternPercent] Registered Mirror client spawn handlers for PurpleBuoyCompass."));
}
}
catch
{
}
}
private GameObject OnClientSpawnCompass(Vector3 position, uint assetId)
{
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Expected O, but got Unknown
//IL_0104: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
try
{
int num = (int)(assetId - 146815488);
if (num > 0 && num < 256)
{
receivedNetworkSeed = num;
SessionSeed = num;
}
if (NetworkServer.active && (Object)(object)purpleCompassInstance != (Object)null)
{
return purpleCompassInstance;
}
Debug.Log(Object.op_Implicit($"[LanternPercent] Client received networked PurpleBuoyCompass from Host at {position} (SessionSeed = {SessionSeed})."));
GameObject val = BuildNeutralizedCompassClone(position, anchorOnServer: false);
if ((Object)(object)val != (Object)null)
{
purpleCompassInstance = val;
return val;
}
}
catch (Exception ex)
{
Debug.LogError(Object.op_Implicit("[LanternPercent] OnClientSpawnCompass error: " + ex.Message));
}
GameObject val2 = new GameObject("PurpleBuoyCompass_Placeholder");
val2.transform.position = position;
val2.AddComponent<NetworkIdentity>();
return val2;
}
private void OnClientUnSpawnCompass(GameObject spawned)
{
if ((Object)(object)spawned != (Object)null)
{
if ((Object)(object)purpleCompassInstance == (Object)(object)spawned)
{
purpleCompassInstance = null;
}
Object.Destroy((Object)(object)spawned);
}
}
public static int DeterministicHash(string text, int seed)
{
uint num = (uint)(-2128831035 ^ seed);
if (!string.IsNullOrEmpty(text))
{
for (int i = 0; i < text.Length; i++)
{
num ^= text[i];
num *= 16777619;
}
}
num ^= num >> 16;
num *= 2246822507u;
num ^= num >> 13;
num *= 3266489909u;
num ^= num >> 16;
return (int)(num & 0x7FFFFFFF);
}
private string GetDeterministicBuoyKey(PropKernal kernal, Transform buoyTransform)
{
int instanceID = ((Object)kernal).GetInstanceID();
if (buoyKeyCache.TryGetValue(instanceID, out var value))
{
return value;
}
Prop componentInParent = ((Component)kernal).GetComponentInParent<Prop>();
if ((Object)(object)componentInParent != (Object)null && !string.IsNullOrEmpty(componentInParent.savablePropGuid))
{
buoyKeyCache[instanceID] = componentInParent.savablePropGuid;
return componentInParent.savablePropGuid;
}
SaveIdentity val = (((Object)(object)componentInParent != (Object)null) ? ((Component)componentInParent).GetComponentInChildren<SaveIdentity>(true) : null) ?? ((Component)kernal).GetComponentInChildren<SaveIdentity>(true);
if ((Object)(object)val != (Object)null && !string.IsNullOrEmpty(val.saveGuid))
{
buoyKeyCache[instanceID] = val.saveGuid;
return val.saveGuid;
}
Transform val2 = (((Object)(object)componentInParent != (Object)null) ? ((Component)componentInParent).transform : ((Component)kernal).transform);
StringBuilder stringBuilder = new StringBuilder(128);
Transform val3 = val2;
while ((Object)(object)val3 != (Object)null)
{
stringBuilder.Insert(0, $"/{((Object)val3).name}[{val3.GetSiblingIndex()}]");
val3 = val3.parent;
}
string text = stringBuilder.ToString();
buoyKeyCache[instanceID] = text;
return text;
}
public static Color GenerateVibrantColor(Random rng)
{
//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_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
float num = (float)rng.NextDouble();
float num2 = 0.11f + num * 0.92999995f;
if (num2 >= 1f)
{
num2 -= 1f;
}
float num3 = 0.85f + (float)rng.NextDouble() * 0.15f;
Color val = Color.HSVToRGB(num2, num3, 1f);
float num4 = 0.299f * val.r + 0.587f * val.g + 0.114f * val.b;
if (num4 < 0.45f)
{
val.r = Mathf.Max(val.r, 0.35f);
val.g = Mathf.Max(val.g, 0.45f);
}
val.a = 1f;
return val;
}
private void GenerateVictoryTextPalette(int count, int seed)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: 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)
victoryTextHexColors.Clear();
Random rng = new Random(DeterministicHash("VictoryPalette", seed));
for (int i = 0; i < count; i++)
{
Color val = GenerateVibrantColor(rng);
victoryTextHexColors.Add("#" + ColorUtility.ToHtmlStringRGB(val));
}
}
private void ApplyVibrantBuoyColor(PropKernal buoyProp, Transform buoyTransform, Transform lightTransform, Color vibrantColor, bool isLit)
{
//IL_0014: 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_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: 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_0246: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Expected O, but got Unknown
//IL_0166: Unknown result type (might be due to invalid IL or missing references)
//IL_0175: Unknown result type (might be due to invalid IL or missing references)
//IL_0184: Unknown result type (might be due to invalid IL or missing references)
//IL_0287: Unknown result type (might be due to invalid IL or missing references)
//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
try
{
Color val = (isLit ? (vibrantColor * 1.35f) : (vibrantColor * 1.15f));
val.a = 1f;
Il2CppArrayBase<PropertyBlockHelper> componentsInChildren = ((Component)buoyProp).GetComponentsInChildren<PropertyBlockHelper>(true);
if (componentsInChildren != null)
{
foreach (PropertyBlockHelper item in componentsInChildren)
{
if ((Object)(object)item == (Object)null)
{
continue;
}
Il2CppReferenceArray<ColorSetting> colorSettings = item.colorSettings;
if (colorSettings != null && ((Il2CppArrayBase<ColorSetting>)(object)colorSettings).Length > 0)
{
for (int i = 0; i < ((Il2CppArrayBase<ColorSetting>)(object)colorSettings).Length; i++)
{
ColorSetting val2 = ((Il2CppArrayBase<ColorSetting>)(object)colorSettings)[i];
val2.color = val;
((Il2CppArrayBase<ColorSetting>)(object)colorSettings)[i] = val2;
}
item.Refresh();
}
}
}
Il2CppArrayBase<MeshRenderer> componentsInChildren2 = ((Component)buoyProp).GetComponentsInChildren<MeshRenderer>(true);
if (componentsInChildren2 != null)
{
foreach (MeshRenderer item2 in componentsInChildren2)
{
if (!((Object)(object)item2 == (Object)null))
{
MaterialPropertyBlock val3 = new MaterialPropertyBlock();
((Renderer)item2).GetPropertyBlock(val3);
if (((Object)((Component)item2).gameObject).name == "LobbyFlareMesh")
{
val3.SetColor("_MainColor", vibrantColor);
val3.SetColor("_TintColor", vibrantColor);
val3.SetColor("_Color", vibrantColor);
}
else if ((Object)(object)((Component)item2).transform == (Object)(object)buoyTransform || ((Object)((Component)item2).gameObject).name.StartsWith("buoy", StringComparison.OrdinalIgnoreCase))
{
val3.SetColor("_TintColor", val);
val3.SetColor("_MainColor", vibrantColor);
val3.SetColor("_Color", val);
val3.SetColor("_BaseColor", val);
}
((Renderer)item2).SetPropertyBlock(val3);
}
}
}
if ((Object)(object)lightTransform != (Object)null)
{
Light component = ((Component)lightTransform).GetComponent<Light>();
if ((Object)(object)component != (Object)null)
{
component.color = vibrantColor;
}
}
Il2CppArrayBase<Light> componentsInChildren3 = ((Component)buoyProp).GetComponentsInChildren<Light>(true);
if (componentsInChildren3 == null)
{
return;
}
foreach (Light item3 in componentsInChildren3)
{
if ((Object)(object)item3 != (Object)null)
{
item3.color = vibrantColor;
}
}
}
catch (Exception ex)
{
Debug.LogWarning(Object.op_Implicit("[LanternPercent] Failed to tint buoy: " + ex.Message));
}
}
private void SpawnExplosion()
{
//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_008b: 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_00aa: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
float num = Random.Range(100f, (float)Screen.width - 100f);
float num2 = Random.Range(50f, (float)Screen.height / 2f);
Random rng = new Random(Random.Range(1, int.MaxValue));
Color color = GenerateVibrantColor(rng);
int num3 = Random.Range(40, 80);
for (int i = 0; i < num3; i++)
{
float num4 = Random.Range(0f, (float)Math.PI * 2f);
float num5 = Random.Range(50f, 250f);
activeSparks.Add(new Spark
{
position = new Vector2(num, num2),
velocity = new Vector2(Mathf.Cos(num4) * num5, Mathf.Sin(num4) * num5),
color = color,
lifetime = Random.Range(1f, 2.5f)
});
}
}
public static void CalculateLineFromCompass(Vector3 compassWorldPos)
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: 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_0042: Unknown result type (might be due to invalid IL or missing references)
if (!HasUnlitBuoy)
{
CurrentLineLength = 0f;
CurrentLineBearingDeg = 0f;
return;
}
float num = TargetUnlitBuoyXZ.x - compassWorldPos.x;
float num2 = TargetUnlitBuoyXZ.y - compassWorldPos.z;
CurrentLineLength = Mathf.Sqrt(num * num + num2 * num2);
CurrentLineBearingDeg = Mathf.Atan2(num, num2) * 57.29578f;
}
private Vector3 DetermineSpawnPosition(out bool spawnedInLostAndFound)
{
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
//IL_0165: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: 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_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_012f: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Unknown result type (might be due to invalid IL or missing references)
spawnedInLostAndFound = false;
try
{
if (SaveManager.GetIntValue("lantern_percent_compass_laf", 0, false) == 1)
{
SaveManager.SetIntValue("lantern_percent_compass_laf", 0);
Il2CppArrayBase<InventorySpawn> val = Object.FindObjectsOfType<InventorySpawn>();
if (val != null && val.Length > 0)
{
Vector3 val2 = (((Object)(object)Camera.main != (Object)null) ? ((Component)Camera.main).transform.position : Vector3.zero);
InventorySpawn val3 = val[0];
float num = float.MaxValue;
foreach (InventorySpawn item in val)
{
if (!((Object)(object)item == (Object)null))
{
float num2 = Vector3.Distance(val2, ((Component)item).transform.position);
if (num2 < num)
{
num = num2;
val3 = item;
}
}
}
if ((Object)(object)val3 != (Object)null)
{
spawnedInLostAndFound = true;
Vector3 nextSpawnPosition = val3.GetNextSpawnPosition();
Debug.Log(Object.op_Implicit($"[LanternPercent] Spawning Purple Compass in Lost & Found at {nextSpawnPosition}"));
return nextSpawnPosition;
}
}
}
}
catch (Exception ex)
{
Debug.LogWarning(Object.op_Implicit("[LanternPercent] Could not query InventorySpawn, defaulting to Map Room: " + ex.Message));
}
return MapRoomSpawnPos;
}
private static GameObject GetOrCaptureCompassTemplate()
{
//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0106: Expected O, but got Unknown
if ((Object)(object)compassTemplate != (Object)null)
{
return compassTemplate;
}
Il2CppArrayBase<Prop> val = Object.FindObjectsByType<Prop>((FindObjectsInactive)1, (FindObjectsSortMode)0);
if (val == null)
{
return null;
}
Prop val2 = null;
foreach (Prop item in val)
{
if (!((Object)(object)item == (Object)null) && !((Object)(object)((Component)item).gameObject == (Object)null))
{
string name = ((Object)((Component)item).gameObject).name;
if (name.StartsWith("CompassProp", StringComparison.Ordinal) && !name.Contains("PurpleBuoyCompass") && !name.Contains("LP_Template"))
{
val2 = item;
break;
}
}
}
if ((Object)(object)val2 == (Object)null)
{
return null;
}
if ((Object)(object)templateHolder == (Object)null)
{
GameObject val3 = new GameObject("LP_Compass_Template_Holder");
val3.SetActive(false);
Object.DontDestroyOnLoad((Object)(object)val3);
templateHolder = val3.transform;
}
bool activeSelf = ((Component)val2).gameObject.activeSelf;
GameObject val4;
try
{
((Component)val2).gameObject.SetActive(false);
val4 = Object.Instantiate<GameObject>(((Component)val2).gameObject, templateHolder);
}
finally
{
if (activeSelf)
{
((Component)val2).gameObject.SetActive(true);
}
}
((Object)val4).name = "CompassProp_LP_Template";
val4.SetActive(false);
NetworkIdentity component = val4.GetComponent<NetworkIdentity>();
if ((Object)(object)component != (Object)null)
{
component.sceneId = 0uL;
}
compassTemplate = val4;
return compassTemplate;
}
private static GameObject BuildNeutralizedCompassClone(Vector3 targetSpawnPos, bool anchorOnServer)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_039f: Unknown result type (might be due to invalid IL or missing references)
//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
//IL_03da: Unknown result type (might be due to invalid IL or missing references)
GameObject orCaptureCompassTemplate = GetOrCaptureCompassTemplate();
if ((Object)(object)orCaptureCompassTemplate == (Object)null)
{
return null;
}
GameObject val = Object.Instantiate<GameObject>(orCaptureCompassTemplate, targetSpawnPos, Quaternion.identity);
((Object)val).name = "PurpleBuoyCompass";
NetworkIdentity component = val.GetComponent<NetworkIdentity>();
if ((Object)(object)component != (Object)null)
{
component.sceneId = 0uL;
GetPrivatePropertySetter<NetworkIdentity>("hasSpawned")?.Invoke(component, new object[1] { false });
}
Prop component2 = val.GetComponent<Prop>();
if ((Object)(object)component2 != (Object)null)
{
component2.saveablePropName = (SaveablePropName)0;
component2.propSaveType = (PropSaveType)2;
component2.startHome = null;
if ((Object)(object)component2.useHeldSwitch != (Object)null && !((Component)component2.useHeldSwitch).transform.IsChildOf(val.transform))
{
component2.useHeldSwitch = null;
}
if ((Object)(object)component2.useHeldUpSwitch != (Object)null && !((Component)component2.useHeldUpSwitch).transform.IsChildOf(val.transform))
{
component2.useHeldUpSwitch = null;
}
if ((Object)(object)component2.onDropSwitch != (Object)null && !((Component)component2.onDropSwitch).transform.IsChildOf(val.transform))
{
component2.onDropSwitch = null;
}
if ((Object)(object)component2.onEjectSwitch != (Object)null && !((Component)component2.onEjectSwitch).transform.IsChildOf(val.transform))
{
component2.onEjectSwitch = null;
}
if ((Object)(object)component2.onUseAsKey != (Object)null && !((Component)component2.onUseAsKey).transform.IsChildOf(val.transform))
{
component2.onUseAsKey = null;
}
if ((Object)(object)component2.onPickUpSwitch != (Object)null && !((Component)component2.onPickUpSwitch).transform.IsChildOf(val.transform))
{
component2.onPickUpSwitch = null;
}
}
foreach (SaveIdentity componentsInChild in val.GetComponentsInChildren<SaveIdentity>(true))
{
Object.DestroyImmediate((Object)(object)componentsInChild);
}
ushort num = 58624;
foreach (PropHome componentsInChild2 in val.GetComponentsInChildren<PropHome>(true))
{
if (!((Object)(object)componentsInChild2 == (Object)null) && componentsInChild2.ticket != 0)
{
componentsInChild2.ticket = num++;
}
}
foreach (PeckSwitch componentsInChild3 in val.GetComponentsInChildren<PeckSwitch>(true))
{
if (!((Object)(object)componentsInChild3 == (Object)null) && componentsInChild3.ticket != 0)
{
componentsInChild3.ticket = num++;
}
}
foreach (TrackedPeckState componentsInChild4 in val.GetComponentsInChildren<TrackedPeckState>(true))
{
if (!((Object)(object)componentsInChild4 == (Object)null))
{
componentsInChild4.saveIdentity = null;
componentsInChild4.savableSystem = (SavableSystem)0;
if (componentsInChild4.ticket != 0)
{
componentsInChild4.ticket = num++;
}
}
}
Transform val2 = val.transform.Find("Kernal");
if ((Object)(object)val2 != (Object)null)
{
val2.localPosition = Vector3.zero;
val2.localRotation = Quaternion.identity;
}
GameObject val3 = (((Object)(object)val2 != (Object)null) ? ((Component)val2).gameObject : val);
BuoyCompassBehaviour buoyCompassBehaviour = val3.AddComponent<BuoyCompassBehaviour>();
buoyCompassBehaviour.InitializeAnchor(val, targetSpawnPos, anchorOnServer);
val.SetActive(true);
if ((Object)(object)component != (Object)null)
{
GetPrivatePropertySetter<NetworkIdentity>("SpawnedFromInstantiate")?.Invoke(component, new object[1] { false });
}
return val;
}
private void TrySpawnNativePurpleCompassOnServer()
{
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: 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)
if (!NetworkServer.active)
{
return;
}
try
{
if (SessionSeed <= 0 || SessionSeed >= 256)
{
SessionSeed = Random.Range(1, 256);
}
receivedNetworkSeed = SessionSeed;
bool spawnedInLostAndFound;
Vector3 val = DetermineSpawnPosition(out spawnedInLostAndFound);
GameObject val2 = BuildNeutralizedCompassClone(val, !spawnedInLostAndFound);
if ((Object)(object)val2 == (Object)null)
{
return;
}
purpleCompassInstance = val2;
uint num = (uint)(146815488 + SessionSeed);
NetworkServer.Spawn(val2, num, (NetworkConnection)null);
Prop component = val2.GetComponent<Prop>();
if ((Object)(object)component != (Object)null)
{
try
{
component.ServerSetUnpinned();
}
catch
{
}
component.SetLoose();
}
BuoyCompassBehaviour.TeleportCompassTo(val, !spawnedInLostAndFound);
NetworkIdentity component2 = val2.GetComponent<NetworkIdentity>();
Debug.Log(Object.op_Implicit($"[LanternPercent] Host spawned networked PurpleBuoyCompass at {val} (netId={(((Object)(object)component2 != (Object)null) ? component2.netId : 0)}, SessionSeed={SessionSeed})!"));
}
catch (Exception ex)
{
Debug.LogError(Object.op_Implicit("[LanternPercent] Failed to spawn native compass on server: " + ex.Message));
}
}
internal static MethodInfo GetPrivatePropertySetter<T>(string propertyName)
{
return typeof(T).GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetSetMethod(nonPublic: true);
}
private void UpdateBuoyCount()
{
//IL_05ce: Unknown result type (might be due to invalid IL or missing references)
//IL_05d3: Unknown result type (might be due to invalid IL or missing references)
//IL_05d5: Unknown result type (might be due to invalid IL or missing references)
//IL_05dc: Unknown result type (might be due to invalid IL or missing references)
//IL_05e3: Unknown result type (might be due to invalid IL or missing references)
//IL_0607: Unknown result type (might be due to invalid IL or missing references)
//IL_05fb: Unknown result type (might be due to invalid IL or missing references)
//IL_040b: Unknown result type (might be due to invalid IL or missing references)
//IL_0410: Unknown result type (might be due to invalid IL or missing references)
//IL_041a: Unknown result type (might be due to invalid IL or missing references)
//IL_060c: Unknown result type (might be due to invalid IL or missing references)
//IL_060e: Unknown result type (might be due to invalid IL or missing references)
//IL_0657: Unknown result type (might be due to invalid IL or missing references)
//IL_0678: Unknown result type (might be due to invalid IL or missing references)
//IL_0480: Unknown result type (might be due to invalid IL or missing references)
try
{
Il2CppArrayBase<PropKernal> val = Object.FindObjectsOfType<PropKernal>();
if (val == null)
{
return;
}
if (receivedNetworkSeed > 0 && SessionSeed != receivedNetworkSeed)
{
SessionSeed = receivedNetworkSeed;
}
float num = ((worldReadyTime > 0f) ? (Time.unscaledTime - worldReadyTime) : 0f);
bool flag = SessionSeed > 0 || num >= 5f;
int num2 = ((SessionSeed <= 0) ? 1 : SessionSeed);
if (flag && num2 != lastAppliedSessionSeed)
{
lastAppliedSessionSeed = num2;
buoyVibrantColors.Clear();
buoyLastLitState.Clear();
GenerateVictoryTextPalette(64, num2);
Debug.Log(Object.op_Implicit($"[LanternPercent] Applying synchronized buoy colors using SessionSeed = {num2}."));
}
int num3 = 0;
int num4 = 0;
List<UnlitBuoyEntry> list = new List<UnlitBuoyEntry>();
foreach (PropKernal item in val)
{
if ((Object)(object)item == (Object)null)
{
continue;
}
Transform val2 = ((Component)item).transform.Find("buoy");
Transform val3 = ((Component)item).transform.Find("bouyLight");
if (!((Object)(object)val2 != (Object)null))
{
continue;
}
num3++;
int instanceID = ((Object)item).GetInstanceID();
string deterministicBuoyKey = GetDeterministicBuoyKey(item, val2);
if (!nonPedestalBuoyIds.Contains(instanceID) && DetectNonPedestalBuoy(item))
{
nonPedestalBuoyIds.Add(instanceID);
}
bool flag2 = nonPedestalBuoyIds.Contains(instanceID);
bool flag3 = (Object)(object)val3 != (Object)null && ((Component)val3).gameObject.activeInHierarchy;
if (NetworkServer.active && flag2 && worldReadyTime > 0f)
{
string text = "lp_buoy_lit_" + deterministicBuoyKey;
bool value;
if (num >= 1.5f && !restoredBuoyIdsThisLoad.Contains(instanceID))
{
restoredBuoyIdsThisLoad.Add(instanceID);
bool flag4 = SaveManager.GetIntValue(text, 0, false) == 1;
nonPedestalSavedStateCache[instanceID] = flag4;
if (flag4 && !flag3)
{
RestoreNonPedestalBuoyOnServer(item, val2, val3, deterministicBuoyKey);
flag3 = (Object)(object)val3 != (Object)null && ((Component)val3).gameObject.activeInHierarchy;
}
}
else if (restoredBuoyIdsThisLoad.Contains(instanceID) && (!nonPedestalSavedStateCache.TryGetValue(instanceID, out value) || value != flag3))
{
nonPedestalSavedStateCache[instanceID] = flag3;
SaveManager.SetIntValue(text, flag3 ? 1 : 0);
Debug.Log(Object.op_Implicit($"[LanternPercent] Saved non-pedestal buoy '{deterministicBuoyKey}' lit state = {flag3}."));
}
}
if (flag3)
{
num4++;
}
else
{
int priorityScore = DeterministicHash(deterministicBuoyKey, num2 * 104729 + 31);
list.Add(new UnlitBuoyEntry
{
buoyTransform = val2,
lightTransform = val3,
deterministicKey = deterministicBuoyKey,
priorityScore = priorityScore
});
}
if (flag)
{
bool flag5 = false;
bool value3;
if (!buoyVibrantColors.TryGetValue(instanceID, out var value2))
{
int seed = DeterministicHash(deterministicBuoyKey, num2 * 7919 + 17);
value2 = GenerateVibrantColor(new Random(seed));
buoyVibrantColors[instanceID] = value2;
buoyLastLitState[instanceID] = flag3;
flag5 = true;
}
else if (!buoyLastLitState.TryGetValue(instanceID, out value3) || value3 != flag3)
{
buoyLastLitState[instanceID] = flag3;
flag5 = true;
}
if (flag5)
{
ApplyVibrantBuoyColor(item, val2, val3, value2, flag3);
}
}
}
totalBuoys = num3;
litBuoys = num4;
AllBuoysLit = litBuoys == totalBuoys && totalBuoys > 0;
if (worldReadyTime > 0f && num >= 6f && flag)
{
if (AllBuoysLit || list.Count == 0)
{
currentTrackedBuoy = null;
currentTrackedBuoyLight = null;
currentTrackedBuoyKey = null;
HasUnlitBuoy = false;
}
else
{
list.Sort(delegate(UnlitBuoyEntry a, UnlitBuoyEntry b)
{
int num5 = a.priorityScore.CompareTo(b.priorityScore);
return (num5 != 0) ? num5 : string.CompareOrdinal(a.deterministicKey, b.deterministicKey);
});
UnlitBuoyEntry unlitBuoyEntry = list[0];
bool flag6 = (Object)(object)currentTrackedBuoy != (Object)(object)unlitBuoyEntry.buoyTransform || currentTrackedBuoyKey != unlitBuoyEntry.deterministicKey;
currentTrackedBuoy = unlitBuoyEntry.buoyTransform;
currentTrackedBuoyLight = unlitBuoyEntry.lightTransform;
currentTrackedBuoyKey = unlitBuoyEntry.deterministicKey;
HasUnlitBuoy = true;
Vector3 position = currentTrackedBuoy.position;
TargetUnlitBuoyXZ = new Vector2(position.x, position.z);
Vector3 compassWorldPos = (((Object)(object)ActiveCompassTransform != (Object)null) ? ActiveCompassTransform.position : MapRoomSpawnPos);
CalculateLineFromCompass(compassWorldPos);
if (flag6)
{
Debug.Log(Object.op_Implicit($"[LanternPercent] Locked onto shared unlit buoy '{unlitBuoyEntry.deterministicKey}' at (X: {position.x:F1}, Z: {position.z:F1}) [SessionSeed={num2}, Remaining={list.Count}, Line={CurrentLineLength:F1}m]."));
}
}
}
int value4 = ((totalBuoys > 0) ? Mathf.RoundToInt((float)litBuoys / (float)totalBuoys * 100f) : 0);
if (AllBuoysLit)
{
if (!hasWon)
{
hasWon = true;
isFireworksActive = true;
fireworksEndTime = Time.unscaledTime + 20f;
GenerateVictoryTextPalette(64, num2);
}
string input = "Congratulations on Completing Lantern Percent!!!";
displayText = MakeVibrantVictoryText(input, num2);
return;
}
hasWon = false;
isFireworksActive = false;
displayText = $"Lit Buoys: {litBuoys} / {totalBuoys}";
if (showPercentage)
{
displayText += $" ({value4}%)";
}
}
catch (Exception ex)
{
Debug.LogError(Object.op_Implicit("Error counting buoys: " + ex.Message));
}
}
private string MakeVibrantVictoryText(string input, int seed)
{
if (victoryTextHexColors.Count < input.Length)
{
GenerateVictoryTextPalette(input.Length + 16, seed);
}
string text = "";
int num = 0;
for (int i = 0; i < input.Length; i++)
{
char c = input[i];
if (c == ' ')
{
text += c;
continue;
}
text += $"<color={victoryTextHexColors[num]}>{c}</color>";
num = (num + 1) % victoryTextHexColors.Count;
}
return text;
}
private void OnGUI()
{
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Expected O, but got Unknown
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: Expected O, but got Unknown
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_0123: Unknown result type (might be due to invalid IL or missing references)
//IL_0158: Unknown result type (might be due to invalid IL or missing references)
//IL_015d: Unknown result type (might be due to invalid IL or missing references)
//IL_0173: Unknown result type (might be due to invalid IL or missing references)
//IL_017e: Unknown result type (might be due to invalid IL or missing references)
//IL_018b: Unknown result type (might be due to invalid IL or missing references)
//IL_0193: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: 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_0050: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
if (totalBuoys == 0)
{
return;
}
if (activeSparks.Count > 0)
{
Color color = GUI.color;
foreach (Spark activeSpark in activeSparks)
{
GUI.color = activeSpark.color;
GUI.DrawTexture(new Rect(activeSpark.position.x, activeSpark.position.y, 4f, 4f), (Texture)(object)Texture2D.whiteTexture);
}
GUI.color = color;
}
int num = Mathf.Clamp(currentColorIndex, 1, HudCounterColors.Length) - 1;
GUIStyle val = new GUIStyle();
val.fontSize = currentFontSize;
val.normal.textColor = HudCounterColors[num];
val.alignment = (TextAnchor)4;
val.richText = true;
GUIContent val2 = new GUIContent(displayText);
Vector2 val3 = val.CalcSize(val2);
float num2 = val3.x + 20f;
float num3 = val3.y + 10f;
float num4 = (float)Screen.width - num2 - 20f;
float num5 = 20f;
Rect val4 = default(Rect);
((Rect)(ref val4))..ctor(num4, num5, num2, num3);
Color color2 = GUI.color;
GUI.color = new Color(0f, 0f, 0f, 0.6f);
GUI.DrawTexture(val4, (Texture)(object)Texture2D.whiteTexture);
GUI.color = color2;
GUI.Label(val4, val2, val);
}
}
public class BuoyCompassBehaviour : MonoBehaviour
{
private GameObject rootPropObject;
private Prop compassProp;
private Transform originalNeedle;
private Transform customNeedle;
private Transform compassDialParent;
private Vector3 needleRestLocalPos = Vector3.zero;
private Vector3 needleRestLocalScale = Vector3.one;
private Quaternion baseNeedleLocalRotation = Quaternion.Euler(270f, 0f, 0f);
private Vector3 anchorPosition;
private bool isAnchored = false;
private bool lastSavedAttachmentState = false;
private float attachmentCheckTimer = 0f;
private float currentSpinAngle = 0f;
private float spinSpeed = 720f;
public static BuoyCompassBehaviour Instance { get; private set; }
public BuoyCompassBehaviour(IntPtr handle)
: base(handle)
{
}//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: 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_0011: 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_002b: Unknown result type (might be due to invalid IL or missing references)
public void InitializeAnchor(GameObject rootObj, Vector3 targetPos, bool anchorUntilPlayerNear)
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
Instance = this;
rootPropObject = rootObj;
compassProp = (((Object)(object)rootObj != (Object)null) ? rootObj.GetComponent<Prop>() : null);
anchorPosition = targetPos;
isAnchored = anchorUntilPlayerNear && NetworkServer.active;
}
public static void TeleportCompassTo(Vector3 targetPos, bool anchorUntilPlayerNear)
{
//IL_0073: 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_0089: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)Instance == (Object)null || !NetworkServer.active)
{
return;
}
if ((Object)(object)Instance.compassProp != (Object)null)
{
ReleaseFromAnyPlayerHands(Instance.compassProp);
try
{
Instance.compassProp.ServerSetUnpinned();
}
catch
{
}
Instance.compassProp.SetLoose();
}
Instance.anchorPosition = targetPos;
Instance.isAnchored = anchorUntilPlayerNear;
Instance.ForcePosition(targetPos);
}
private static void ReleaseFromAnyPlayerHands(Prop prop)
{
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Expected O, but got Unknown
try
{
List<PlayerCharacter> allPlayerCharacters = PlayerCharacter.allPlayerCharacters;
if (allPlayerCharacters == null || (Object)(object)prop == (Object)null)
{
return;
}
NetworkIdentity component = ((Component)prop).GetComponent<NetworkIdentity>();
Enumerator<PlayerCharacter> enumerator = allPlayerCharacters.GetEnumerator();
while (enumerator.MoveNext())
{
PlayerCharacter current = enumerator.Current;
if ((Object)(object)current == (Object)null)
{
continue;
}
if (current.hands != null && (Object)(object)current.hands.heldProp == (Object)(object)prop)
{
try
{
current.hands.Drop(new PlayerHeldInformation(prop));
}
catch
{
}
}
PlayerNetworking playerNetworking = current.playerNetworking;
if ((Object)(object)playerNetworking != (Object)null && (Object)(object)component != (Object)null)
{
PlayerHeldInformation playerHeldInformation = playerNetworking.playerHeldInformation;
if (playerHeldInformation != null && (Object)(object)playerHeldInformation.identity == (Object)(object)component)
{
playerHeldInformation.identity = null;
playerHeldInformation.heldType = (HeldType)0;
playerHeldInformation.hasDropData = false;
playerHeldInformation.actionNumber += 1;
playerNetworking.NetworkplayerHeldInformation = playerHeldInformation;
}
}
}
}
catch
{
}
}
private void ForcePosition(Vector3 pos)
{
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: 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_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
if (!NetworkServer.active)
{
return;
}
if ((Object)(object)rootPropObject != (Object)null)
{
rootPropObject.transform.position = pos;
rootPropObject.transform.rotation = Quaternion.identity;
}
((Component)this).transform.position = pos;
((Component)this).transform.rotation = Quaternion.identity;
foreach (Rigidbody componentsInChild in ((Component)this).GetComponentsInChildren<Rigidbody>(true))
{
if ((Object)(object)componentsInChild != (Object)null)
{
componentsInChild.position = pos;
componentsInChild.velocity = Vector3.zero;
componentsInChild.angularVelocity = Vector3.zero;
}
}
}
private static bool IsAnyPlayerNear(Vector3 pos, float radius)
{
//IL_0071: 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_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
List<PlayerCharacter> allPlayerCharacters = PlayerCharacter.allPlayerCharacters;
if (allPlayerCharacters != null)
{
Enumerator<PlayerCharacter> enumerator = allPlayerCharacters.GetEnumerator();
while (enumerator.MoveNext())
{
PlayerCharacter current = enumerator.Current;
if ((Object)(object)current == (Object)null || !(Vector3.Distance(((Component)current).transform.position, pos) < radius))
{
continue;
}
return true;
}
}
if ((Object)(object)Camera.main != (Object)null && Vector3.Distance(((Component)Camera.main).transform.position, pos) < radius)
{
return true;
}
return false;
}
private void Start()
{
Instance = this;
SetupVisualsAndNeedle();
}
private void SetupVisualsAndNeedle()
{
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Expected O, but got Unknown
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_0117: 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_0185: Unknown result type (might be due to invalid IL or missing references)
//IL_018a: Unknown result type (might be due to invalid IL or missing references)
//IL_0196: Unknown result type (might be due to invalid IL or missing references)
//IL_019b: Unknown result type (might be due to invalid IL or missing references)
//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
//IL_01ac: Expected O, but got Unknown
//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
//IL_01db: Unknown result type (might be due to invalid IL or missing references)
//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
//IL_024e: Unknown result type (might be due to invalid IL or missing references)
//IL_0255: Expected O, but got Unknown
try
{
Transform val = null;
Transform val2 = (((Object)(object)rootPropObject != (Object)null) ? rootPropObject.transform : ((Component)this).transform);
foreach (Transform componentsInChild in ((Component)val2).GetComponentsInChildren<Transform>(true))
{
if (((Object)componentsInChild).name == "compass_base")
{
val = componentsInChild;
}
if (((Object)componentsInChild).name == "compass_needle")
{
originalNeedle = componentsInChild;
}
if (((Object)componentsInChild).name == "CustomBuoyNeedle")
{
customNeedle = componentsInChild;
}
}
if ((Object)(object)val != (Object)null)
{
baseNeedleLocalRotation = val.localRotation;
MeshRenderer component = ((Component)val).GetComponent<MeshRenderer>();
if ((Object)(object)component != (Object)null)
{
MaterialPropertyBlock val3 = new MaterialPropertyBlock();
((Renderer)component).GetPropertyBlock(val3);
Color val4 = default(Color);
((Color)(ref val4))..ctor(0.85f, 0.55f, 1f);
val3.SetColor("_TintColor", val4);
val3.SetColor("_Color", val4);
val3.SetColor("_BaseColor", val4);
((Renderer)component).SetPropertyBlock(val3);
}
}
if ((Object)(object)originalNeedle != (Object)null && (Object)(object)customNeedle == (Object)null)
{
compassDialParent = originalNeedle.parent;
TextBehaviour.ActiveCompassTransform = compassDialParent;
needleRestLocalPos = originalNeedle.localPosition;
needleRestLocalScale = originalNeedle.localScale;
GameObject val5 = new GameObject("CustomBuoyNeedle");
val5.transform.SetParent(compassDialParent, false);
val5.transform.localPosition = needleRestLocalPos;
val5.transform.localRotation = baseNeedleLocalRotation;
val5.transform.localScale = needleRestLocalScale;
customNeedle = val5.transform;
MeshFilter component2 = ((Component)originalNeedle).GetComponent<MeshFilter>();
MeshRenderer component3 = ((Component)originalNeedle).GetComponent<MeshRenderer>();
if ((Object)(object)component2 != (Object)null && (Object)(object)component3 != (Object)null)
{
Mesh sharedMesh = component2.sharedMesh;
Il2CppReferenceArray<Material> sharedMaterials = ((Renderer)component3).sharedMaterials;
MaterialPropertyBlock val6 = new MaterialPropertyBlock();
((Renderer)component3).GetPropertyBlock(val6);
MeshFilter val7 = val5.AddComponent<MeshFilter>();
val7.sharedMesh = sharedMesh;
MeshRenderer val8 = val5.AddComponent<MeshRenderer>();
((Renderer)val8).sharedMaterials = sharedMaterials;
((Renderer)val8).SetPropertyBlock(val6);
component2.sharedMesh = null;
((Renderer)component3).enabled = false;
((Renderer)component3).forceRenderingOff = true;
}
}
}
catch (Exception ex)
{
Debug.LogWarning(Object.op_Implicit("[LanternPercent] SetupVisualsAndNeedle warning: " + ex.Message));
}
}
private void HideAllOtherNeedleRenderers()
{
if ((Object)(object)compassDialParent == (Object)null)
{
return;
}
foreach (Renderer componentsInChild in ((Component)compassDialParent).GetComponentsInChildren<Renderer>(true))
{
if (!((Object)(object)componentsInChild == (Object)null))
{
string name = ((Object)((Component)componentsInChild).gameObject).name;
if (name != "compass_base" && name != "CustomBuoyNeedle")
{
componentsInChild.enabled = false;
componentsInChild.forceRenderingOff = true;
}
}
}
}
private bool IsAttachedToPlayerOrGear()
{
try
{
if ((Object)(object)compassProp == (Object)null && (Object)(object)rootPropObject != (Object)null)
{
compassProp = rootPropObject.GetComponent<Prop>();
}
if ((Object)(object)compassProp != (Object)null && (Object)(object)compassProp.currentHome != (Object)null)
{
PropHome currentHome = compassProp.currentHome;
if ((Object)(object)currentHome.parentCharacter != (Object)null)
{
return true;
}
if ((Object)(object)currentHome.parentProp != (Object)null)
{
string name = ((Object)((Component)currentHome.parentProp).gameObject).name;
if (name.StartsWith("BackpackProp", StringComparison.Ordinal) || name.StartsWith("HolsterProp", StringComparison.Ordinal) || name.StartsWith("GourdCartonProp", StringComparison.Ordinal))
{
return true;
}
}
}
List<PlayerCharacter> allPlayerCharacters = PlayerCharacter.allPlayerCharacters;
if (allPlayerCharacters != null && (Object)(object)compassProp != (Object)null)
{
Enumerator<PlayerCharacter> enumerator = allPlayerCharacters.GetEnumerator();
while (enumerator.MoveNext())
{
PlayerCharacter current = enumerator.Current;
if ((Object)(object)current == (Object)null || current.hands == null || !((Object)(object)current.hands.heldProp == (Object)(object)compassProp))
{
continue;
}
return true;
}
}
Transform parent = ((Component)this).transform.parent;
while ((Object)(object)parent != (Object)null)
{
string name2 = ((Object)parent).name;
if (name2.IndexOf("PlayerCharacter", StringComparison.OrdinalIgnoreCase) >= 0 || name2.IndexOf("grasperHand", StringComparison.OrdinalIgnoreCase) >= 0 || name2.IndexOf("Backpack", StringComparison.OrdinalIgnoreCase) >= 0 || name2.IndexOf("Holster", StringComparison.OrdinalIgnoreCase) >= 0)
{
return true;
}
parent = parent.parent;
}
}
catch
{
}
return false;
}
private void LateUpdate()
{
TickCompass();
}
public void TickCompass()
{
//IL_0145: Unknown result type (might be due to invalid IL or missing references)
//IL_0157: Unknown result type (might be due to invalid IL or missing references)
//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
//IL_01db: Unknown result type (might be due to invalid IL or missing references)
//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
//IL_0201: Unknown result type (might be due to invalid IL or missing references)
//IL_0236: Unknown result type (might be due to invalid IL or missing references)
//IL_0238: Unknown result type (might be due to invalid IL or missing references)
//IL_023d: Unknown result type (might be due to invalid IL or missing references)
//IL_023f: Unknown result type (might be due to invalid IL or missing references)
//IL_0246: Unknown result type (might be due to invalid IL or missing references)
//IL_0272: Unknown result type (might be due to invalid IL or missing references)
//IL_0278: Unknown result type (might be due to invalid IL or missing references)
//IL_027d: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)customNeedle == (Object)null || (Object)(object)compassDialParent == (Object)null)
{
SetupVisualsAndNeedle();
if ((Object)(object)customNeedle == (Object)null || (Object)(object)compassDialParent == (Object)null)
{
return;
}
}
HideAllOtherNeedleRenderers();
TextBehaviour.ActiveCompassTransform = compassDialParent;
try
{
if (NetworkServer.active)
{
if (isAnchored)
{
if (IsAttachedToPlayerOrGear() || IsAnyPlayerNear(anchorPosition, 15f))
{
isAnchored = false;
}
else
{
ForcePosition(anchorPosition);
}
}
if (WorldManager.isReadyForEffects)
{
attachmentCheckTimer += Time.unscaledDeltaTime;
if (attachmentCheckTimer >= 0.5f)
{
attachmentCheckTimer = 0f;
bool flag = IsAttachedToPlayerOrGear();
if (flag != lastSavedAttachmentState)
{
lastSavedAttachmentState = flag;
SaveManager.SetIntValue("lantern_percent_compass_laf", flag ? 1 : 0);
}
}
}
}
}
catch
{
}
try
{
customNeedle.localPosition = needleRestLocalPos;
customNeedle.localScale = needleRestLocalScale;
if (TextBehaviour.AllBuoysLit)
{
currentSpinAngle = (currentSpinAngle + spinSpeed * Time.unscaledDeltaTime) % 360f;
customNeedle.localRotation = Quaternion.Euler(0f, currentSpinAngle, 0f) * baseNeedleLocalRotation;
}
else if (TextBehaviour.HasUnlitBuoy)
{
Vector3 position = compassDialParent.position;
TextBehaviour.CalculateLineFromCompass(position);
float num = TextBehaviour.TargetUnlitBuoyXZ.x - position.x;
float num2 = TextBehaviour.TargetUnlitBuoyXZ.y - position.z;
Vector3 val = default(Vector3);
((Vector3)(ref val))..ctor(num, 0f, num2);
if (((Vector3)(ref val)).sqrMagnitude > 0.0001f)
{
Vector3 val2 = compassDialParent.InverseTransformDirection(val);
float num3 = Mathf.Atan2(val2.x, val2.z) * 57.29578f + 180f;
customNeedle.localRotation = Quaternion.Euler(0f, num3, 0f) * baseNeedleLocalRotation;
}
}
}
catch (Exception ex)
{
Debug.LogWarning(Object.op_Implicit("[LanternPercent] Needle rotation error: " + ex.Message));
}
}
}