using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Peak.Network;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
using Zorro.Core;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("BlackPeakRemix")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BlackPeakRemix")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("E1651194-D4F9-441D-B2B8-47E358B092B0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 BlackPeakRemix
{
public enum LanternState : byte
{
Omni,
Flashlight
}
public enum BPR_SubType : byte
{
LanternSync,
ConfigSync,
ConfigRequest
}
public enum LanternColorMode
{
Original,
FollowPlayer,
Custom
}
public enum DarknessPreset
{
FullDark,
HalfAndHalf,
NightDark,
DayDark,
Custom
}
public enum LanternBurnDuration
{
Seconds60 = 60,
Seconds120 = 120,
Seconds240 = 240,
Seconds360 = 360,
Seconds600 = 600,
Infinite = 100000
}
[BepInPlugin("HnskNoah.BlackPeakRemix", "BlackPeakRemix", "2.1.8")]
public class BlackPeakRemix : BaseUnityPlugin
{
[CompilerGenerated]
private sealed class <ConfigChangedDebounceRoutine>d__40 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public string changedKey;
public BlackPeakRemix <>4__this;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <ConfigChangedDebounceRoutine>d__40(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Expected O, but got Unknown
int num = <>1__state;
BlackPeakRemix blackPeakRemix = <>4__this;
switch (num)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(0.1f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
if (changedKey == "自定义模式颜色码 (Custom Mode color hex)")
{
blackPeakRemix.ParseHexConfig();
}
UpdateActiveSettings();
if (changedKey == "禁用角色自带光源 (Disable Character Light)")
{
if (!ActiveMasterSwitch)
{
Log.LogWarning((object)"[Config] Cannot toggle Character Light while Master Switch is disabled.");
return false;
}
Patch_Character.ApplyCharacterLightConfig();
}
if (changedKey == "极暗模式 (Extreme Darkness Mode)")
{
if (!ActiveMasterSwitch)
{
Log.LogWarning((object)"[Config] Cannot toggle Extreme Darkness Mode while Master Switch is disabled.");
return false;
}
if (!PhotonNetwork.InRoom || PhotonNetwork.IsMasterClient)
{
if (ConfigExtremeDarknessMode.Value)
{
pitchblackpeak.NightGlobals.ApplySceneOneShots();
ForceEnvironmentUpdate();
}
else
{
pitchblackpeak.NightGlobals.RestoreSceneOneShots();
ForceEnvironmentUpdate();
}
}
}
if (changedKey == "插件总开关 (Master Switch)")
{
if (ConfigMasterSwitch.Value)
{
Patch_CharacterSpawner_FirstSpawn.TryGiveLanternIfNeeded();
ApplyAllSettings();
}
else
{
pitchblackpeak.NightGlobals.RestoreSceneOneShots();
Patch_Character.ApplyCharacterLightConfig();
BPR_EnvironmentController.RestoreDefault();
BPR_EnvironmentController.UpdateSnowMaterials(enhance: false);
ForceEnvironmentUpdate();
}
}
if (!PhotonNetwork.InRoom || PhotonNetwork.IsMasterClient)
{
ForceEnvironmentUpdate();
if (blackPeakRemix._syncDebounceCoroutine != null)
{
((MonoBehaviour)blackPeakRemix).StopCoroutine(blackPeakRemix._syncDebounceCoroutine);
}
blackPeakRemix._syncDebounceCoroutine = ((MonoBehaviour)blackPeakRemix).StartCoroutine(blackPeakRemix.SyncDebounceRoutine());
}
blackPeakRemix._envUpdateDebounceCoroutine = null;
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
[CompilerGenerated]
private sealed class <SyncDebounceRoutine>d__41 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public BlackPeakRemix <>4__this;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <SyncDebounceRoutine>d__41(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Expected O, but got Unknown
int num = <>1__state;
BlackPeakRemix blackPeakRemix = <>4__this;
switch (num)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(1f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
BroadcastConfigs();
blackPeakRemix._syncDebounceCoroutine = null;
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
public const string GUID = "HnskNoah.BlackPeakRemix";
public const byte EVENT_BPR_MAIN = 148;
public const int PROTOCOL_VERSION = 126;
private const float SYNC_DEBOUNCE_DELAY = 1f;
private const float ENV_UPDATE_DEBOUNCE_DELAY = 0.1f;
internal static ManualLogSource Log;
private Coroutine _syncDebounceCoroutine;
private Coroutine _envUpdateDebounceCoroutine;
private static string _lastParsedHexColor = string.Empty;
public static bool IsSyncingFromNet;
public static ConfigEntry<KeyCode> ToggleKey;
public static ConfigEntry<bool> ConfigMasterSwitch;
public static ConfigEntry<bool> ConfigGhostFX;
public static ConfigEntry<bool> ConfigCharacterLight;
public static ConfigEntry<LanternColorMode> ConfigLanternMode;
public static ConfigEntry<string> ConfigLanternHex;
public static ConfigEntry<bool> ConfigExtremeDarknessMode;
public static ConfigEntry<LanternBurnDuration> ConfigLanternBurnDuration;
public static ConfigEntry<DarknessPreset> ConfigMode;
public static ConfigEntry<float> ConfigStartHour;
public static ConfigEntry<float> ConfigEndHour;
public static ConfigEntry<float> ConfigDarknessMultiplier;
public static ConfigEntry<float> ConfigIntensity;
public static ConfigEntry<float> ConfigRange;
public static Color ActiveCustomColor = Color.cyan;
public static float ActiveDarknessMultiplier;
public static float ActiveIntensity;
public static float ActiveRange;
public static float ActiveStartHour;
public static float ActiveEndHour;
public static float ActiveLanternBurnDuration;
public static bool ActiveMasterSwitch;
public static bool ActiveGhostFX;
public static bool ActiveCharacterLight;
public static bool ActiveExtremeDarknessMode;
private void Awake()
{
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
Log = ((BaseUnityPlugin)this).Logger;
Log.LogInfo((object)"[BlackPeakRemix] Plugin initializing...");
InitConfigs();
UpdateActiveSettings();
try
{
new Harmony("HnskNoah.BlackPeakRemix").PatchAll();
Log.LogInfo((object)"[Harmony] Harmony patches applied successfully.");
}
catch (Exception ex)
{
Log.LogError((object)("[Harmony] Patch Error: " + ex.Message + "\n" + ex.StackTrace));
}
Object.DontDestroyOnLoad((Object)(object)((Component)new GameObject("BPR_NetProxy").AddComponent<BPR_NetProxy>()).gameObject);
SceneManager.sceneLoaded += delegate(Scene s, LoadSceneMode m)
{
Log.LogInfo((object)("[SceneManager] Scene loaded: " + ((Scene)(ref s)).name));
Patch_CharacterSpawner_FirstSpawn.ResetSession();
if (ActiveMasterSwitch)
{
UpdateActiveSettings();
Patch_Character.ApplyCharacterLightConfig();
if (ActiveExtremeDarknessMode)
{
pitchblackpeak.NightGlobals.ApplySceneOneShots();
ForceEnvironmentUpdate();
}
else
{
ForceEnvironmentUpdate();
}
}
};
Log.LogInfo((object)"[BlackPeakRemix] Plugin initialization complete!");
}
private void InitConfigs()
{
//IL_0166: Unknown result type (might be due to invalid IL or missing references)
//IL_0170: Expected O, but got Unknown
//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
//IL_01ad: Expected O, but got Unknown
//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
//IL_01ea: Expected O, but got Unknown
//IL_021d: Unknown result type (might be due to invalid IL or missing references)
//IL_0227: Expected O, but got Unknown
//IL_025a: Unknown result type (might be due to invalid IL or missing references)
//IL_0264: Expected O, but got Unknown
Log.LogInfo((object)"[Config] Initializing configuration settings...");
ConfigMasterSwitch = ((BaseUnityPlugin)this).Config.Bind<bool>("Basic Settings", "插件总开关 (Master Switch)", true, "Enable or disable all features of this plugin.");
ConfigLanternBurnDuration = ((BaseUnityPlugin)this).Config.Bind<LanternBurnDuration>("Basic Settings", "提灯燃烧时长 (Lantern Burn Duration)", LanternBurnDuration.Infinite, "Burn time of the lantern 60/120/240/360/600s or Infinite");
ConfigLanternMode = ((BaseUnityPlugin)this).Config.Bind<LanternColorMode>("Basic Settings", "提灯颜色模式 (Lantern Color Mode)", LanternColorMode.FollowPlayer, "Logic for lantern color: Original (Yellow), FollowPlayer (Matches skin color), Custom (Use Hex below).");
ConfigLanternHex = ((BaseUnityPlugin)this).Config.Bind<string>("Basic Settings", "自定义模式颜色码 (Custom Mode color hex)", "0066ff", "Enter a 6-digit hex color value (e.g., ff0000 for Red). Do not include '#'.");
ToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Basic Settings", "模式切换按键 (Toggle Key)", (KeyCode)102, "Keyboard shortcut to toggle between Lantern and Flashlight mode.");
ConfigGhostFX = ((BaseUnityPlugin)this).Config.Bind<bool>("Basic Settings", "幽灵视觉滤镜 (Ghost Vision Filter)", true, "Activate ghost night vision filter upon death.");
ConfigExtremeDarknessMode = ((BaseUnityPlugin)this).Config.Bind<bool>("Basic Settings", "极暗模式 (Extreme Darkness Mode)", false, "Enable extreme darkness mode. Changes take effect immediately on scene load or config change.");
ConfigCharacterLight = ((BaseUnityPlugin)this).Config.Bind<bool>("Basic Settings", "禁用角色自带光源 (Disable Character Light)", true, "Disable character's built-in lights (characterlight/playerlight).");
ConfigMode = ((BaseUnityPlugin)this).Config.Bind<DarknessPreset>("Environment Settings", "黑暗模式预设(Black Mode Time Preset)", DarknessPreset.Custom, "选择预设模式:\nFullDark: 全天黑暗 (0-24)\nHalfAndHalf: 半黑半亮 (5-17)\nNightDark: 夜黑日亮 (21-5)\nDayDark: 日黑夜亮 (5-21)\nCustom: 使用下方自定义时间");
ConfigStartHour = ((BaseUnityPlugin)this).Config.Bind<float>("Environment Settings", "自定义黑暗开始时间 (Custom Black Start Hour)", 5f, new ConfigDescription("The hour when black lighting effects begin (0-24).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 24f), Array.Empty<object>()));
ConfigEndHour = ((BaseUnityPlugin)this).Config.Bind<float>("Environment Settings", "自定义黑暗结束时间 (Custom Black End Hour)", 21f, new ConfigDescription("The hour when black lighting effects end (0-24).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 24f), Array.Empty<object>()));
ConfigDarknessMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Environment Settings", "黑暗亮度系数 (Darkness Intensity)", 0.05f, new ConfigDescription("Multiplier for night darkness. Smaller values are darker (0-0.15).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 0.15f), Array.Empty<object>()));
ConfigIntensity = ((BaseUnityPlugin)this).Config.Bind<float>("Environment Settings", "提灯光照强度 (Light Intensity)", 12f, new ConfigDescription("The brightness intensity of the lantern/flashlight.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 30f), Array.Empty<object>()));
ConfigRange = ((BaseUnityPlugin)this).Config.Bind<float>("Environment Settings", "手电筒照射距离 (Flashlight Range)", 80f, new ConfigDescription("The range of the light in Flashlight mode.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 200f), Array.Empty<object>()));
LogConfigValues();
ParseHexConfig();
((BaseUnityPlugin)this).Config.SettingChanged += delegate(object s, SettingChangedEventArgs e)
{
Log.LogInfo((object)$"[Config] Setting changed: {e.ChangedSetting.Definition.Key} -> {e.ChangedSetting.BoxedValue}");
if (_envUpdateDebounceCoroutine != null)
{
((MonoBehaviour)this).StopCoroutine(_envUpdateDebounceCoroutine);
}
_envUpdateDebounceCoroutine = ((MonoBehaviour)this).StartCoroutine(ConfigChangedDebounceRoutine(e.ChangedSetting.Definition.Key));
};
if ((Object)(object)DayNightManager.instance != (Object)null)
{
BPR_EnvironmentController.UpdateWeight(DayNightManager.instance.timeOfDay);
}
}
private void LogConfigValues()
{
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
Log.LogInfo((object)"[Config] Basic settings loaded:");
Log.LogInfo((object)$" - MasterSwitch: {ConfigMasterSwitch.Value}");
Log.LogInfo((object)$" - LanternBurnDuration: {ConfigLanternBurnDuration.Value}");
Log.LogInfo((object)$" - LanternMode: {ConfigLanternMode.Value}");
Log.LogInfo((object)$" - ToggleKey: {ToggleKey.Value}");
Log.LogInfo((object)$" - GhostFX: {ConfigGhostFX.Value}");
Log.LogInfo((object)$" - CharacterLight: {ConfigCharacterLight.Value}");
Log.LogInfo((object)$" - ExtremeDarknessMode: {ConfigExtremeDarknessMode.Value}");
Log.LogInfo((object)"[Config] Environment settings loaded:");
Log.LogInfo((object)$" - Mode: {ConfigMode.Value}");
Log.LogInfo((object)$" - StartHour: {ConfigStartHour.Value}");
Log.LogInfo((object)$" - EndHour: {ConfigEndHour.Value}");
Log.LogInfo((object)$" - DarknessMultiplier: {ConfigDarknessMultiplier.Value}");
Log.LogInfo((object)$" - Intensity: {ConfigIntensity.Value}");
Log.LogInfo((object)$" - Range: {ConfigRange.Value}");
}
private void ParseHexConfig()
{
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: 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)
string text = ConfigLanternHex.Value.Trim();
if (text.StartsWith("#"))
{
text = text.Substring(1);
}
if (text.Length > 6)
{
text = text.Substring(0, 6);
}
if (!(text == _lastParsedHexColor))
{
Color activeCustomColor = default(Color);
if (ColorUtility.TryParseHtmlString("#" + text, ref activeCustomColor))
{
ActiveCustomColor = activeCustomColor;
ActiveCustomColor.a = 1f;
_lastParsedHexColor = text;
Log.LogInfo((object)$"[Color] Custom color parsed: #{text} -> RGBA({ActiveCustomColor.r:F3}, {ActiveCustomColor.g:F3}, {ActiveCustomColor.b:F3})");
}
else
{
Log.LogWarning((object)("[Color] Failed to parse hex color '" + text + "'. Falling back to default."));
ActiveCustomColor = new Color(1f, 0.6f, 0.3f);
_lastParsedHexColor = text;
}
}
}
public static void UpdateActiveSettings()
{
if (!PhotonNetwork.InRoom || PhotonNetwork.IsMasterClient)
{
ActiveDarknessMultiplier = ConfigDarknessMultiplier.Value;
ActiveIntensity = ConfigIntensity.Value;
ActiveRange = ConfigRange.Value;
DarknessPreset value = ConfigMode.Value;
switch (value)
{
case DarknessPreset.FullDark:
ActiveStartHour = 0f;
ActiveEndHour = 24f;
break;
case DarknessPreset.HalfAndHalf:
ActiveStartHour = 5f;
ActiveEndHour = 17f;
break;
case DarknessPreset.NightDark:
ActiveStartHour = 21f;
ActiveEndHour = 5f;
break;
case DarknessPreset.DayDark:
ActiveStartHour = 5f;
ActiveEndHour = 21f;
break;
case DarknessPreset.Custom:
ActiveStartHour = ConfigStartHour.Value;
ActiveEndHour = ConfigEndHour.Value;
break;
}
if (ConfigExtremeDarknessMode.Value)
{
ActiveStartHour = 0f;
ActiveEndHour = 24f;
ActiveDarknessMultiplier = 0f;
Log.LogInfo((object)"[Settings] Extreme Darkness Mode active: 24/7 dark mode");
}
ActiveMasterSwitch = ConfigMasterSwitch.Value;
ActiveGhostFX = ConfigGhostFX.Value;
ActiveCharacterLight = ConfigCharacterLight.Value;
ActiveExtremeDarknessMode = ConfigExtremeDarknessMode.Value;
ActiveLanternBurnDuration = (float)ConfigLanternBurnDuration.Value;
Log.LogInfo((object)($"[Settings] Active settings (Mode: {value}): Start={ActiveStartHour:F1}, End={ActiveEndHour:F1}, " + $"Mult={ActiveDarknessMultiplier:F3}, Int={ActiveIntensity:F1}, Rng={ActiveRange:F1}"));
Log.LogInfo((object)($"[Settings] Basic: Master={ActiveMasterSwitch}, GhostFX={ActiveGhostFX}, " + $"CharLight={ActiveCharacterLight}, Extreme={ActiveExtremeDarknessMode}, Burn={ActiveLanternBurnDuration:F0}s"));
}
}
[IteratorStateMachine(typeof(<ConfigChangedDebounceRoutine>d__40))]
private IEnumerator ConfigChangedDebounceRoutine(string changedKey)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <ConfigChangedDebounceRoutine>d__40(0)
{
<>4__this = this,
changedKey = changedKey
};
}
[IteratorStateMachine(typeof(<SyncDebounceRoutine>d__41))]
private IEnumerator SyncDebounceRoutine()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <SyncDebounceRoutine>d__41(0)
{
<>4__this = this
};
}
public static void ApplyAllSettings()
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Invalid comparison between Unknown and I4
Patch_Character.ApplyCharacterLightConfig();
if (ActiveExtremeDarknessMode)
{
pitchblackpeak.NightGlobals.ApplySceneOneShots();
}
if ((Object)(object)Singleton<MapHandler>.Instance != (Object)null && (int)Singleton<MapHandler>.Instance.GetCurrentSegment() == 2)
{
BPR_EnvironmentController.UpdateSnowMaterials(enhance: true);
}
ForceEnvironmentUpdate();
}
public static void ForceEnvironmentUpdate()
{
if ((Object)(object)DayNightManager.instance == (Object)null)
{
Log.LogWarning((object)"[Environment] DayNightManager.instance is null, cannot force update.");
}
else if (ActiveMasterSwitch)
{
BPR_EnvironmentController.IsExtremeDarkMode = ActiveExtremeDarknessMode;
BPR_EnvironmentController.UpdateWeight(DayNightManager.instance.timeOfDay);
bool hasNightVision = ((Object)(object)Character.localCharacter != (Object)null && Character.localCharacter.IsGhost) || BPR_BinocularChecker.IsActive;
if (BPR_EnvironmentController.IsExtremeDarkMode)
{
pitchblackpeak.NightGlobals.ApplySkyBlackout(DayNightManager.instance);
pitchblackpeak.NightGlobals.ApplyAmbientDark(hasNightVision);
}
else if (BPR_EnvironmentController.CurrentWeight > 0f)
{
BPR_EnvironmentController.ApplyNightEffect(DayNightManager.instance, ActiveDarknessMultiplier, hasNightVision);
}
else
{
BPR_EnvironmentController.RestoreDefault();
}
}
}
public static void BroadcastConfigs()
{
//IL_017d: Unknown result type (might be due to invalid IL or missing references)
//IL_0182: 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_0189: Unknown result type (might be due to invalid IL or missing references)
//IL_0193: Expected O, but got Unknown
if (!PhotonNetwork.InRoom || !PhotonNetwork.IsMasterClient)
{
Log.LogDebug((object)"[Network] Not in room or not master, skipping broadcast.");
return;
}
object[] array = new object[12]
{
126,
(byte)1,
ActiveDarknessMultiplier,
ActiveIntensity,
ActiveRange,
ActiveStartHour,
ActiveEndHour,
ActiveMasterSwitch,
ActiveGhostFX,
ActiveCharacterLight,
ActiveExtremeDarknessMode,
ActiveLanternBurnDuration
};
Log.LogInfo((object)"[Network] Broadcasting config:");
Log.LogInfo((object)($" Env: Mult={ActiveDarknessMultiplier:F3}, Int={ActiveIntensity:F1}, Rng={ActiveRange:F1}, " + $"Start={ActiveStartHour:F1}, End={ActiveEndHour:F1}"));
Log.LogInfo((object)($" Basic: Master={ActiveMasterSwitch}, GhostFX={ActiveGhostFX}, CharLight={ActiveCharacterLight}, " + $"Extreme={ActiveExtremeDarknessMode}, Burn={ActiveLanternBurnDuration:F0}s"));
PhotonNetwork.RaiseEvent((byte)148, (object)array, new RaiseEventOptions
{
Receivers = (ReceiverGroup)0
}, SendOptions.SendReliable);
}
private void Update()
{
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
if (!ActiveMasterSwitch || (Object)(object)Character.localCharacter == (Object)null)
{
return;
}
CharacterData data = Character.localCharacter.data;
Item val = ((data != null) ? data.currentItem : null);
if (!((Object)(object)val != (Object)null) || val.itemID != 42)
{
return;
}
LanternSyncHelper lanternSyncHelper = ((Component)val).GetComponent<LanternSyncHelper>();
if ((Object)(object)lanternSyncHelper == (Object)null)
{
Lantern component = ((Component)val).GetComponent<Lantern>();
if (!((Object)(object)component != (Object)null))
{
return;
}
lanternSyncHelper = ((Component)val).gameObject.getOrAddComponent<LanternSyncHelper>();
lanternSyncHelper.Init(component);
}
Lantern component2 = ((Component)val).GetComponent<Lantern>();
if ((bool)(typeof(Lantern).GetField("lit", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(component2) ?? ((object)false)) && Input.GetKeyDown(ToggleKey.Value))
{
lanternSyncHelper.localInstanceMode = ((lanternSyncHelper.localInstanceMode == LanternState.Omni) ? LanternState.Flashlight : LanternState.Omni);
Log.LogInfo((object)$"[Input] Lantern mode toggled: {lanternSyncHelper.localInstanceMode}");
}
}
}
public class BPR_NetProxy : MonoBehaviourPunCallbacks, IOnEventCallback
{
public override void OnJoinedRoom()
{
//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_005b: 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)
//IL_006a: Expected O, but got Unknown
BlackPeakRemix.Log.LogInfo((object)$"[Network] Joined room. IsMasterClient: {PhotonNetwork.IsMasterClient}");
if (!PhotonNetwork.IsMasterClient)
{
object[] array = new object[2]
{
126,
(byte)2
};
BlackPeakRemix.Log.LogInfo((object)"[Network] Requesting config from Master...");
PhotonNetwork.RaiseEvent((byte)148, (object)array, new RaiseEventOptions
{
Receivers = (ReceiverGroup)2
}, SendOptions.SendReliable);
}
}
public void OnEvent(EventData e)
{
if (e == null || e.Code != 148)
{
return;
}
if (!(e.CustomData is object[] array) || array.Length < 2)
{
BlackPeakRemix.Log.LogWarning((object)"[Network] Invalid event data format.");
return;
}
if (!(array[0] is int num) || num != 126)
{
BlackPeakRemix.Log.LogWarning((object)$"[Network] Version mismatch! Received: {array[0]}, Local: {126}");
return;
}
switch ((BPR_SubType)(byte)array[1])
{
case BPR_SubType.ConfigSync:
if (array.Length < 12)
{
BlackPeakRemix.Log.LogWarning((object)$"[Network] ConfigSync packet length insufficient: {array.Length}/12.");
break;
}
BlackPeakRemix.IsSyncingFromNet = true;
try
{
bool activeMasterSwitch = BlackPeakRemix.ActiveMasterSwitch;
bool activeExtremeDarknessMode = BlackPeakRemix.ActiveExtremeDarknessMode;
bool activeCharacterLight = BlackPeakRemix.ActiveCharacterLight;
BlackPeakRemix.ActiveDarknessMultiplier = Convert.ToSingle(array[2]);
BlackPeakRemix.ActiveIntensity = Convert.ToSingle(array[3]);
BlackPeakRemix.ActiveRange = Convert.ToSingle(array[4]);
BlackPeakRemix.ActiveStartHour = Convert.ToSingle(array[5]);
BlackPeakRemix.ActiveEndHour = Convert.ToSingle(array[6]);
BlackPeakRemix.ActiveMasterSwitch = Convert.ToBoolean(array[7]);
BlackPeakRemix.ActiveGhostFX = Convert.ToBoolean(array[8]);
BlackPeakRemix.ActiveCharacterLight = Convert.ToBoolean(array[9]);
BlackPeakRemix.ActiveExtremeDarknessMode = Convert.ToBoolean(array[10]);
BlackPeakRemix.ActiveLanternBurnDuration = Convert.ToSingle(array[11]);
BlackPeakRemix.Log.LogInfo((object)"[Network] Config synced from Master:");
if (BlackPeakRemix.ActiveMasterSwitch && !activeMasterSwitch)
{
Patch_CharacterSpawner_FirstSpawn.TryGiveLanternIfNeeded();
BlackPeakRemix.ApplyAllSettings();
}
if (BlackPeakRemix.ActiveCharacterLight != activeCharacterLight)
{
if (!BlackPeakRemix.ActiveMasterSwitch)
{
BlackPeakRemix.Log.LogWarning((object)"[Network] Ignoring Character Light change while Master Switch is disabled.");
}
else
{
Patch_Character.ApplyCharacterLightConfig();
}
}
if (BlackPeakRemix.ActiveExtremeDarknessMode != activeExtremeDarknessMode)
{
if (!BlackPeakRemix.ActiveMasterSwitch)
{
BlackPeakRemix.Log.LogWarning((object)"[Network] Ignoring Extreme Darkness Mode change while Master Switch is disabled.");
}
else if (BlackPeakRemix.ActiveExtremeDarknessMode)
{
pitchblackpeak.NightGlobals.ApplySceneOneShots();
}
else
{
pitchblackpeak.NightGlobals.RestoreSceneOneShots();
}
}
if (!BlackPeakRemix.ActiveMasterSwitch)
{
pitchblackpeak.NightGlobals.RestoreSceneOneShots();
BPR_EnvironmentController.RestoreDefault();
BPR_EnvironmentController.UpdateSnowMaterials(enhance: false);
}
BlackPeakRemix.ForceEnvironmentUpdate();
break;
}
catch (Exception ex)
{
BlackPeakRemix.Log.LogError((object)("[Network] Error parsing config: " + ex.Message));
break;
}
finally
{
BlackPeakRemix.IsSyncingFromNet = false;
}
case BPR_SubType.ConfigRequest:
if (PhotonNetwork.IsMasterClient)
{
BlackPeakRemix.Log.LogInfo((object)$"[Network] Config request from Player {e.Sender}. Broadcasting...");
BlackPeakRemix.BroadcastConfigs();
}
break;
}
}
public override void OnEnable()
{
PhotonNetwork.AddCallbackTarget((object)this);
}
public override void OnDisable()
{
PhotonNetwork.RemoveCallbackTarget((object)this);
}
}
public class LanternSyncHelper : MonoBehaviour, IOnEventCallback
{
private Lantern _lantern;
private Light _light;
private PhotonView _view;
private float _smoothInt;
private static FieldInfo _fLit;
private LanternState _remoteMode;
public LanternState localInstanceMode;
private Quaternion _remoteRot = Quaternion.identity;
private Quaternion _lastSentRot = Quaternion.identity;
private LanternState _lastSentMode;
private float _lastSyncTimestamp;
public void Init(Lantern l)
{
_lantern = l;
_light = l.lanternLight;
_view = ((Component)l).GetComponent<PhotonView>();
_fLit = typeof(Lantern).GetField("lit", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
ManualLogSource log = BlackPeakRemix.Log;
PhotonView view = _view;
log.LogInfo((object)$"[LanternSyncHelper] Initialized for ViewID: {((view != null) ? new int?(view.ViewID) : null)}");
}
public void OnEvent(EventData photonEvent)
{
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
if (photonEvent.Code == 148 && !((Object)(object)_view == (Object)null) && photonEvent.CustomData is object[] array && (int)array[0] == 126 && (byte)array[1] == 0 && (int)array[2] == _view.ViewID)
{
_remoteMode = (LanternState)(byte)array[3];
if (array.Length >= 5)
{
_remoteRot = (Quaternion)array[4];
}
}
}
private void Update()
{
//IL_019b: Unknown result type (might be due to invalid IL or missing references)
//IL_01a1: Invalid comparison between Unknown and I4
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_012e: 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_014c: Unknown result type (might be due to invalid IL or missing references)
//IL_0162: Unknown result type (might be due to invalid IL or missing references)
//IL_0179: 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_018a: Unknown result type (might be due to invalid IL or missing references)
if (!Object.op_Implicit((Object)(object)_light) || (Object)(object)_view == (Object)null || (Object)(object)_lantern == (Object)null)
{
return;
}
bool isMine = _view.IsMine;
bool flag = (bool)(_fLit?.GetValue(_lantern) ?? ((object)false));
if (isMine)
{
HandleLocalSync(flag);
}
if (!flag)
{
if (((Behaviour)_light).enabled)
{
((Behaviour)_light).enabled = false;
}
return;
}
if (!((Behaviour)_light).enabled)
{
((Behaviour)_light).enabled = true;
}
_smoothInt = Mathf.Lerp(_smoothInt, BlackPeakRemix.ActiveIntensity, Time.deltaTime * 5f);
if ((isMine ? localInstanceMode : _remoteMode) == LanternState.Flashlight)
{
if ((int)_light.type != 0)
{
_light.type = (LightType)0;
}
_light.intensity = CalculateFlashlightIntensity(_smoothInt, BlackPeakRemix.ActiveRange);
_light.range = BlackPeakRemix.ActiveRange;
_light.spotAngle = 45f;
Quaternion val = ((!isMine) ? _remoteRot : (Object.op_Implicit((Object)(object)Camera.main) ? ((Component)Camera.main).transform.rotation : ((Component)_lantern).transform.rotation));
((Component)_light).transform.rotation = Quaternion.Slerp(((Component)_light).transform.rotation, val, Time.deltaTime * 10f);
}
else
{
if ((int)_light.type != 2)
{
_light.type = (LightType)2;
}
_light.intensity = _smoothInt;
float num = Mathf.Sqrt(_smoothInt / 30f);
_light.range = num * 20f;
}
}
private float CalculateFlashlightIntensity(float baseIntensity, float range)
{
float num = baseIntensity;
if (baseIntensity <= 25f)
{
if (range > 50f)
{
num = baseIntensity * (1f + 0.145f * Mathf.Sqrt(range - 50f));
}
}
else if (range > 100f)
{
num = baseIntensity * (1f + 0.095f * Mathf.Sqrt(range - 100f));
}
return Mathf.Min(num, 50f);
}
private void HandleLocalSync(bool isLit)
{
//IL_0055: 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_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: 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_0076: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
if (!PhotonNetwork.InRoom || _view.ViewID <= 0 || !isLit)
{
return;
}
float num = Time.time - _lastSyncTimestamp;
LanternState lanternState = localInstanceMode;
Quaternion val = (Object.op_Implicit((Object)(object)Camera.main) ? ((Component)Camera.main).transform.rotation : ((Component)_lantern).transform.rotation);
if (lanternState != _lastSentMode)
{
SendSyncPacket(lanternState, val, reliable: true);
_lastSentMode = lanternState;
_lastSentRot = val;
}
else if (lanternState == LanternState.Flashlight && num >= 0.2f)
{
bool num2 = Quaternion.Angle(_lastSentRot, val) > 10f;
bool flag = num > 1f && Quaternion.Angle(_lastSentRot, val) != 0f;
if (num2 || flag)
{
SendSyncPacket(lanternState, val, reliable: false);
_lastSentRot = val;
_lastSyncTimestamp = Time.time;
}
}
}
private void SendSyncPacket(LanternState mode, Quaternion rot, bool reliable)
{
//IL_0037: 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_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: 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_0065: Expected O, but got Unknown
object[] array = new object[5]
{
126,
(byte)0,
_view.ViewID,
(byte)mode,
rot
};
PhotonNetwork.RaiseEvent((byte)148, (object)array, new RaiseEventOptions
{
Receivers = (ReceiverGroup)0
}, reliable ? SendOptions.SendReliable : SendOptions.SendUnreliable);
}
public void OnEnable()
{
PhotonNetwork.AddCallbackTarget((object)this);
}
public void OnDisable()
{
PhotonNetwork.RemoveCallbackTarget((object)this);
}
}
[HarmonyPatch(typeof(Lantern))]
internal static class Patch_Lantern_BurnDuration
{
private static bool IsNormalLantern(Lantern lantern)
{
Item val = ((lantern != null) ? ((Component)lantern).GetComponent<Item>() : null);
if ((Object)(object)val != (Object)null)
{
return val.itemID == 42;
}
return false;
}
[HarmonyPrefix]
[HarmonyPatch("UpdateFuel")]
public static bool PrefixUpdateFuel(Lantern __instance)
{
if (!BlackPeakRemix.ActiveMasterSwitch || !IsNormalLantern(__instance))
{
return true;
}
if (!((ItemComponent)__instance).HasData((DataEntryKey)10))
{
return true;
}
if (!(bool)(typeof(Lantern).GetField("lit", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(__instance) ?? ((object)false)) || !NetworkingUtilities.HasAuthority((MonoBehaviourPunCallbacks)(object)__instance))
{
return false;
}
float activeLanternBurnDuration = BlackPeakRemix.ActiveLanternBurnDuration;
if (activeLanternBurnDuration > 20000f)
{
return false;
}
float num = 60f / activeLanternBurnDuration;
float value = ((ItemComponent)__instance).GetData<FloatItemData>((DataEntryKey)10).Value;
float num2 = Time.deltaTime * num;
float num3 = value - num2;
num3 = Mathf.Clamp(num3, 0f, __instance.startingFuel);
((ItemComponent)__instance).GetData<FloatItemData>((DataEntryKey)10).Value = num3;
Item item = ((ItemComponent)__instance).item;
if (item != null)
{
item.SetUseRemainingPercentage(num3 / __instance.startingFuel);
}
if (num3 <= 0f && ((MonoBehaviourPun)__instance).photonView.IsMine)
{
__instance.SnuffLantern();
}
return false;
}
}
[HarmonyPatch(typeof(Lantern), "Awake")]
internal static class Patch_Lantern_Init
{
private static void Postfix(Lantern __instance)
{
if (BlackPeakRemix.ActiveMasterSwitch && ((int?)((Component)__instance).GetComponent<Item>()?.itemID).GetValueOrDefault() == 42 && (Object)(object)((Component)__instance).GetComponent<PhotonView>() != (Object)null)
{
((Component)__instance).gameObject.getOrAddComponent<LanternSyncHelper>().Init(__instance);
BlackPeakRemix.Log.LogInfo((object)"[LanternInit] LanternSyncHelper attached");
}
}
}
[HarmonyPatch(typeof(Lantern), "Update")]
internal static class Patch_Lantern_Visuals
{
[HarmonyPostfix]
private static void Postfix(Lantern __instance)
{
if (BlackPeakRemix.ActiveMasterSwitch)
{
LanternVisualController.UpdateLanternVisuals(__instance);
}
}
}
[HarmonyPatch(typeof(Campfire))]
[HarmonyPatch(typeof(Campfire), "Update")]
internal static class Patch_Campfire_Glow_Enhanced
{
private static void Postfix(Campfire __instance)
{
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Invalid comparison between Unknown and I4
//IL_002c: 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)
if (BlackPeakRemix.ActiveMasterSwitch)
{
bool active = (int)__instance.state == 1;
BPR_GlowController.ApplyGlow(((Component)__instance).gameObject, "BPR_CampfireLight_Enhanced", new Color(1f, 0.6f, 0.2f), 30f, 50f, active, new Vector3(0f, 3f, 0f), (LightShadows)2);
}
}
}
public static class LanternVisualController
{
public static void UpdateLanternVisuals(Lantern lantern)
{
if (!((Object)(object)lantern.lanternLight == (Object)null))
{
Item component = ((Component)lantern).GetComponent<Item>();
if (!((Object)(object)component == (Object)null) && component.itemID == 42)
{
PhotonView component2 = ((Component)component).GetComponent<PhotonView>();
HandleColorOwnership(lantern, component, component2);
ApplySyncedColor(lantern);
}
}
}
private static void HandleColorOwnership(Lantern lantern, Item item, PhotonView pView)
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: 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_0043: 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)
if ((Object)(object)pView != (Object)null && pView.IsMine && (Object)(object)item.holderCharacter != (Object)null)
{
Color targetColorByConfig = GetTargetColorByConfig(item.holderCharacter);
ColorItemData data = ((ItemComponent)lantern).GetData<ColorItemData>((DataEntryKey)9);
if (data.Value != targetColorByConfig)
{
data.Value = targetColorByConfig;
}
lantern.lanternLight.shadows = (LightShadows)0;
}
}
private static void ApplySyncedColor(Lantern lantern)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: 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_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
if (((ItemComponent)lantern).HasData((DataEntryKey)9))
{
Color value = ((ItemComponent)lantern).GetData<ColorItemData>((DataEntryKey)9).Value;
if (lantern.lanternLight.color != value)
{
lantern.lanternLight.color = value;
}
}
}
private static Color GetTargetColorByConfig(Character holder)
{
//IL_002e: 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_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: 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)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
return (Color)(BlackPeakRemix.ConfigLanternMode.Value switch
{
LanternColorMode.Original => new Color(1f, 0.6f, 0.3f),
LanternColorMode.Custom => BlackPeakRemix.ActiveCustomColor,
LanternColorMode.FollowPlayer => holder.refs.customization.PlayerColor,
_ => new Color(1f, 0.6f, 0.3f),
});
}
}
public static class BPR_GlowController
{
public static void ApplyGlow(GameObject parent, string childName, Color color, float intensity, float range, bool active, Vector3 localPos, LightShadows shadowMode = 0)
{
//IL_005f: 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_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: 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)
Transform obj = parent.transform.Find(childName);
Light val = ((obj != null) ? ((Component)obj).GetComponent<Light>() : null);
if (active)
{
if ((Object)(object)val == (Object)null)
{
GameObject val2 = new GameObject(childName);
val2.transform.SetParent(parent.transform);
val2.transform.localPosition = localPos;
val = val2.AddComponent<Light>();
val.type = (LightType)2;
}
((Behaviour)val).enabled = true;
val.color = color;
val.intensity = intensity;
val.range = range;
if (val.shadows != shadowMode)
{
val.shadows = shadowMode;
}
}
else if ((Object)(object)val != (Object)null)
{
((Behaviour)val).enabled = false;
}
}
}
public static class BPR_Extensions
{
public static T getOrAddComponent<T>(this GameObject go) where T : Component
{
T val = go.GetComponent<T>();
if (!Object.op_Implicit((Object)(object)val))
{
val = go.AddComponent<T>();
}
return val;
}
}
public static class BPR_EnvironmentController
{
public static readonly int ID_Brightness = Shader.PropertyToID("brightness");
public static readonly int ID_AmbienceStrength = Shader.PropertyToID("ambienceStrength");
public static readonly int ID_AmbienceMin = Shader.PropertyToID("ambienceMin");
public static readonly int ID_SkyTop = Shader.PropertyToID("SkyTopColor");
public static readonly int ID_SkyMid = Shader.PropertyToID("SkyMidColor");
public static readonly int ID_SkyBot = Shader.PropertyToID("SkyBottomColor");
private const float TRANSITION_DURATION = 0.5f;
private static readonly Dictionary<Material, (float baseSmooth, float smooth1, float smooth2, float smooth3, float addSpecular, Color tint, Color topColor, Color baseColor)> _originalIceMaterialValues = new Dictionary<Material, (float, float, float, float, float, Color, Color, Color)>();
private static bool _iceMaterialsEnhanced = false;
private static readonly int ID_BaseSmooth = Shader.PropertyToID("_BaseSmooth");
private static readonly int ID_Smooth1 = Shader.PropertyToID("_Smooth1");
private static readonly int ID_Smooth2 = Shader.PropertyToID("_Smooth2");
private static readonly int ID_Smooth3 = Shader.PropertyToID("_Smooth3");
private static readonly int ID_AddSpecular = Shader.PropertyToID("_AddSpecular");
private static readonly int ID_Tint = Shader.PropertyToID("_Tint");
private static readonly int ID_TopColor = Shader.PropertyToID("_TopColor");
private static readonly int ID_BaseColor = Shader.PropertyToID("_BaseColor");
public static float CurrentWeight { get; private set; } = 0f;
public static bool IsExtremeDarkMode { get; set; } = false;
public static void UpdateWeight(float time)
{
float activeStartHour = BlackPeakRemix.ActiveStartHour;
float activeEndHour = BlackPeakRemix.ActiveEndHour;
if (Mathf.Approximately(activeStartHour, activeEndHour))
{
CurrentWeight = 0f;
return;
}
float num = ((activeEndHour > activeStartHour) ? (activeEndHour - activeStartHour) : (24f - activeStartHour + activeEndHour));
if (num >= 23.99f)
{
CurrentWeight = 1f;
return;
}
float num2 = Mathf.Min(0.5f, num / 2f);
float num3 = ((time >= activeStartHour) ? (time - activeStartHour) : (24f - activeStartHour + time));
if (num3 < 0f || num3 > num)
{
CurrentWeight = 0f;
}
else
{
CurrentWeight = ((num3 < num2) ? (num3 / num2) : ((num3 > num - num2) ? ((num - num3) / num2) : 1f));
}
}
public static void ApplyNightEffect(DayNightManager manager, float activeMultiplier, bool hasNightVision)
{
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: 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_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_010f: 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)
if (IsExtremeDarkMode)
{
pitchblackpeak.NightGlobals.ApplySkyBlackout(manager);
pitchblackpeak.NightGlobals.ApplyAmbientDark(hasNightVision);
return;
}
float currentWeight = CurrentWeight;
float num = 1f - (1f - activeMultiplier) * currentWeight;
if ((Object)(object)manager.sun != (Object)null)
{
Light sun = manager.sun;
sun.intensity *= num;
}
if ((Object)(object)manager.moon != (Object)null)
{
Light moon = manager.moon;
moon.intensity *= num;
}
if (hasNightVision)
{
float num2 = (Mathf.Approximately(activeMultiplier, 0.15f) ? 0.18f : 0.15f);
if (num < num2)
{
num = num2;
}
}
float num3 = (hasNightVision ? 0.015f : 0.003f);
Shader.SetGlobalFloat(ID_AmbienceMin, Mathf.Lerp(0.05f, num3, currentWeight));
Shader.SetGlobalFloat(ID_AmbienceStrength, num);
float num4 = 1f - 0.95f * currentWeight;
Shader.SetGlobalColor(ID_SkyTop, Shader.GetGlobalColor(ID_SkyTop) * num4);
Shader.SetGlobalColor(ID_SkyMid, Shader.GetGlobalColor(ID_SkyMid) * num4);
Shader.SetGlobalColor(ID_SkyBot, Shader.GetGlobalColor(ID_SkyBot) * num4);
}
public static void RestoreDefault()
{
Shader.SetGlobalFloat(ID_Brightness, 1f);
Shader.SetGlobalFloat(ID_AmbienceStrength, 1f);
Shader.SetGlobalFloat(ID_AmbienceMin, 0.2f);
RenderSettings.reflectionIntensity = 1f;
IsExtremeDarkMode = false;
CurrentWeight = 0f;
}
public static void UpdateSnowMaterials(bool enhance)
{
//IL_03ef: 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_0436: 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_017c: Unknown result type (might be due to invalid IL or missing references)
//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
try
{
if (enhance)
{
Renderer[] array = Object.FindObjectsByType<Renderer>((FindObjectsSortMode)0);
int num = 0;
int num2 = 0;
Renderer[] array2 = array;
foreach (Renderer val in array2)
{
if ((Object)(object)val == (Object)null || !val.enabled)
{
continue;
}
Material[] sharedMaterials = val.sharedMaterials;
foreach (Material val2 in sharedMaterials)
{
if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.shader == (Object)null) && ((Object)val2.shader).name == "W/Peak_Ice" && ((Object)val2).name == "M_Rock_ice")
{
if (!_originalIceMaterialValues.ContainsKey(val2))
{
num2++;
_originalIceMaterialValues[val2] = (val2.HasProperty(ID_BaseSmooth) ? val2.GetFloat(ID_BaseSmooth) : 0.598f, val2.HasProperty(ID_Smooth1) ? val2.GetFloat(ID_Smooth1) : 0.84f, val2.HasProperty(ID_Smooth2) ? val2.GetFloat(ID_Smooth2) : 0.84f, val2.HasProperty(ID_Smooth3) ? val2.GetFloat(ID_Smooth3) : 0.82f, val2.HasProperty(ID_AddSpecular) ? val2.GetFloat(ID_AddSpecular) : 0.1f, (Color)(val2.HasProperty(ID_Tint) ? val2.GetColor(ID_Tint) : new Color(0.53f, 0.601f, 0.698f)), (Color)(val2.HasProperty(ID_TopColor) ? val2.GetColor(ID_TopColor) : new Color(1f, 1f, 1f, 1f)), (Color)(val2.HasProperty(ID_BaseColor) ? val2.GetColor(ID_BaseColor) : new Color(0.203f, 0.385f, 0.453f)));
}
if (val2.HasProperty(ID_BaseSmooth))
{
val2.SetFloat(ID_BaseSmooth, 0.05f);
}
if (val2.HasProperty(ID_Smooth1))
{
val2.SetFloat(ID_Smooth1, 0.1f);
}
if (val2.HasProperty(ID_Smooth2))
{
val2.SetFloat(ID_Smooth2, 0.1f);
}
if (val2.HasProperty(ID_Smooth3))
{
val2.SetFloat(ID_Smooth3, 0.1f);
}
if (val2.HasProperty(ID_AddSpecular))
{
val2.SetFloat(ID_AddSpecular, 0.3f);
}
num++;
}
}
}
_iceMaterialsEnhanced = true;
BlackPeakRemix.Log.LogInfo((object)$"[SnowFix] Enhanced {num} materials ({num2} new)");
}
else
{
if (!_iceMaterialsEnhanced)
{
return;
}
int num3 = 0;
foreach (KeyValuePair<Material, (float, float, float, float, float, Color, Color, Color)> originalIceMaterialValue in _originalIceMaterialValues)
{
Material key = originalIceMaterialValue.Key;
(float, float, float, float, float, Color, Color, Color) value = originalIceMaterialValue.Value;
if ((Object)(object)key != (Object)null)
{
if (key.HasProperty(ID_BaseSmooth))
{
key.SetFloat(ID_BaseSmooth, value.Item1);
}
if (key.HasProperty(ID_Smooth1))
{
key.SetFloat(ID_Smooth1, value.Item2);
}
if (key.HasProperty(ID_Smooth2))
{
key.SetFloat(ID_Smooth2, value.Item3);
}
if (key.HasProperty(ID_Smooth3))
{
key.SetFloat(ID_Smooth3, value.Item4);
}
if (key.HasProperty(ID_AddSpecular))
{
key.SetFloat(ID_AddSpecular, value.Item5);
}
if (key.HasProperty(ID_Tint))
{
key.SetColor(ID_Tint, value.Item6);
}
if (key.HasProperty(ID_TopColor))
{
key.SetColor(ID_TopColor, value.Item7);
}
if (key.HasProperty(ID_BaseColor))
{
key.SetColor(ID_BaseColor, value.Rest.Item1);
}
num3++;
}
}
_originalIceMaterialValues.Clear();
_iceMaterialsEnhanced = false;
BlackPeakRemix.Log.LogInfo((object)$"[SnowFix] Restored {num3} materials");
}
}
catch (Exception ex)
{
BlackPeakRemix.Log.LogError((object)("[SnowFix] Error: " + ex.Message));
}
}
}
[HarmonyPatch(typeof(DayNightManager), "Update")]
internal static class Patch_DayNight_AdvancedDarkness
{
private static void Postfix(DayNightManager __instance)
{
if ((Object)(object)__instance == (Object)null || !BlackPeakRemix.ActiveMasterSwitch)
{
return;
}
bool hasNightVision = ((Object)(object)Character.localCharacter != (Object)null && Character.localCharacter.IsGhost) || BPR_BinocularChecker.IsActive;
if (BPR_EnvironmentController.IsExtremeDarkMode)
{
BPR_EnvironmentController.ApplyNightEffect(__instance, 0f, hasNightVision);
return;
}
BPR_EnvironmentController.UpdateWeight(__instance.timeOfDay);
if (BPR_EnvironmentController.CurrentWeight > 0f)
{
BPR_EnvironmentController.ApplyNightEffect(__instance, BlackPeakRemix.ActiveDarknessMultiplier, hasNightVision);
}
else
{
BPR_EnvironmentController.RestoreDefault();
}
}
}
[HarmonyPatch(typeof(LightVolume), "SetShaderVars")]
internal static class Patch_LightVolume_Guard
{
private static void Prefix(LightVolume __instance)
{
if (!BlackPeakRemix.ActiveMasterSwitch)
{
return;
}
bool flag = ((Object)(object)Character.localCharacter != (Object)null && Character.localCharacter.IsGhost) || BPR_BinocularChecker.IsActive;
if (BPR_EnvironmentController.IsExtremeDarkMode)
{
if ((Object)(object)Character.localCharacter != (Object)null)
{
pitchblackpeak.NightGlobals.ApplyAmbientDark(flag);
}
}
else
{
if (BPR_EnvironmentController.CurrentWeight <= 0f)
{
return;
}
float currentWeight = BPR_EnvironmentController.CurrentWeight;
float num = 1f - (1f - BlackPeakRemix.ActiveDarknessMultiplier) * currentWeight;
if (flag)
{
float num2 = (Mathf.Approximately(BlackPeakRemix.ActiveDarknessMultiplier, 0.15f) ? 0.18f : 0.15f);
if (num < num2)
{
num = num2;
}
}
__instance.brightness = 1f;
__instance.ambienceStrength = num;
__instance.ambienceMin = Mathf.Lerp(0.05f, flag ? 0.01f : 0f, currentWeight);
}
}
}
[HarmonyPatch]
internal static class Patch_LavaPost
{
[HarmonyPostfix]
[HarmonyPatch(typeof(LavaPost), "LateUpdate")]
private static void PostLate()
{
if (BlackPeakRemix.ActiveMasterSwitch && BPR_EnvironmentController.IsExtremeDarkMode)
{
pitchblackpeak.NightGlobals.ClampLavaAlpha();
}
}
}
[HarmonyPatch(typeof(MapHandler), "GoToSegment")]
[HarmonyPatch(new Type[] { typeof(Segment) })]
internal static class Patch_MapHandler_GoToSegment
{
private static void Postfix(MapHandler __instance, Segment s)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Invalid comparison between Unknown and I4
if (BlackPeakRemix.ActiveMasterSwitch)
{
if ((int)s == 2)
{
Patch_GUIManager_SetHeroTitle.pendingSnowFix = true;
}
else
{
BPR_EnvironmentController.UpdateSnowMaterials(enhance: false);
}
}
}
}
[HarmonyPatch(typeof(GUIManager), "SetHeroTitle")]
internal static class Patch_GUIManager_SetHeroTitle
{
public static bool pendingSnowFix;
private static void Postfix()
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Invalid comparison between Unknown and I4
if (BlackPeakRemix.ActiveMasterSwitch && pendingSnowFix)
{
if ((int)Singleton<MapHandler>.Instance.GetCurrentSegment() == 2)
{
BPR_EnvironmentController.UpdateSnowMaterials(enhance: true);
}
pendingSnowFix = false;
}
}
}
[HarmonyPatch(typeof(MapHandler), "JumpToSegmentLogic")]
[HarmonyPatch(new Type[]
{
typeof(Segment),
typeof(HashSet<int>),
typeof(bool),
typeof(bool)
})]
internal static class Patch_MapHandler_JumpToSegmentLogic
{
private static void Postfix()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Invalid comparison between Unknown and I4
if (BlackPeakRemix.ActiveMasterSwitch)
{
if ((int)Singleton<MapHandler>.Instance.GetCurrentSegment() == 2)
{
Patch_GUIManager_SetHeroTitle.pendingSnowFix = true;
}
else
{
BPR_EnvironmentController.UpdateSnowMaterials(enhance: false);
}
}
}
}
[HarmonyPatch(typeof(CharacterSpawner))]
internal static class Patch_CharacterSpawner_FirstSpawn
{
[CompilerGenerated]
private sealed class <DelayedGiveRoutine>d__3 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public float delay;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <DelayedGiveRoutine>d__3(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(delay);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
_delayedGivePending = false;
if (!BlackPeakRemix.ActiveMasterSwitch)
{
BlackPeakRemix.Log.LogInfo((object)"[AutoGive] Master switch disabled, skipping lantern grant.");
return false;
}
if (_hasGivenLanternThisSession)
{
BlackPeakRemix.Log.LogInfo((object)"[AutoGive] Lantern already given this session, skipping.");
return false;
}
if ((Object)(object)Character.localCharacter?.refs?.items != (Object)null)
{
CharacterItems items = Character.localCharacter.refs.items;
MethodInfo methodInfo = AccessTools.Method(((object)items).GetType(), "SpawnItemInHand", (Type[])null, (Type[])null);
if (methodInfo != null)
{
methodInfo.Invoke(items, new object[1] { "Lantern" });
_hasGivenLanternThisSession = true;
BlackPeakRemix.Log.LogInfo((object)"[AutoGive] Lantern granted after delay.");
}
}
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
private static bool _hasGivenLanternThisSession;
private static bool _delayedGivePending;
[HarmonyPatch("SpawnMyPlayerCharacter")]
[HarmonyPostfix]
private static void Postfix(Character __result, CharacterSpawner __instance)
{
if (BlackPeakRemix.ActiveMasterSwitch && !_hasGivenLanternThisSession && (Object)(object)__result != (Object)null && ((MonoBehaviourPun)__result).photonView.IsMine && !_delayedGivePending)
{
_delayedGivePending = true;
((MonoBehaviour)__instance).StartCoroutine(DelayedGiveRoutine(10f));
}
}
[IteratorStateMachine(typeof(<DelayedGiveRoutine>d__3))]
private static IEnumerator DelayedGiveRoutine(float delay)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <DelayedGiveRoutine>d__3(0)
{
delay = delay
};
}
public static void ResetSession()
{
_hasGivenLanternThisSession = false;
_delayedGivePending = false;
BlackPeakRemix.Log.LogInfo((object)"[AutoGive] Session reset.");
}
public static void TryGiveLanternIfNeeded()
{
if (!_hasGivenLanternThisSession && (Object)(object)Character.localCharacter?.refs?.items != (Object)null)
{
CharacterItems items = Character.localCharacter.refs.items;
MethodInfo methodInfo = AccessTools.Method(((object)items).GetType(), "SpawnItemInHand", (Type[])null, (Type[])null);
if (methodInfo != null)
{
methodInfo.Invoke(items, new object[1] { "Lantern" });
_hasGivenLanternThisSession = true;
_delayedGivePending = false;
BlackPeakRemix.Log.LogInfo((object)"[AutoGive] Lantern granted on master switch toggle.");
}
}
}
}
[HarmonyPatch]
internal static class Patch_Character
{
private static readonly Dictionary<string, bool> _originalLightStates = new Dictionary<string, bool>();
[HarmonyPostfix]
[HarmonyPatch(typeof(Character), "Awake")]
private static void PostAwake(Character __instance)
{
if ((Object)(object)__instance != (Object)(object)Character.localCharacter)
{
return;
}
Light[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<Light>(true);
foreach (Light val in componentsInChildren)
{
if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)((Component)val).gameObject))
{
continue;
}
string text = ((Object)((Component)val).gameObject).name.ToLowerInvariant();
if (text.Contains("characterlight") || text.Contains("playerlight"))
{
string key = $"{((Object)__instance).GetInstanceID()}_{((Object)val).GetInstanceID()}";
if (!_originalLightStates.ContainsKey(key))
{
_originalLightStates[key] = ((Component)val).gameObject.activeSelf;
}
bool flag = BlackPeakRemix.ActiveMasterSwitch && BlackPeakRemix.ActiveCharacterLight;
((Component)val).gameObject.SetActive(!flag && _originalLightStates[key]);
}
}
}
public static void ApplyCharacterLightConfig()
{
if ((Object)(object)Character.localCharacter == (Object)null)
{
return;
}
Light[] componentsInChildren = ((Component)Character.localCharacter).GetComponentsInChildren<Light>(true);
foreach (Light val in componentsInChildren)
{
if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)((Component)val).gameObject))
{
continue;
}
string text = ((Object)((Component)val).gameObject).name.ToLowerInvariant();
if (text.Contains("characterlight") || text.Contains("playerlight"))
{
string key = $"{((Object)Character.localCharacter).GetInstanceID()}_{((Object)val).GetInstanceID()}";
if (!_originalLightStates.ContainsKey(key))
{
_originalLightStates[key] = ((Component)val).gameObject.activeSelf;
}
bool flag = BlackPeakRemix.ActiveMasterSwitch && BlackPeakRemix.ActiveCharacterLight;
((Component)val).gameObject.SetActive(!flag && _originalLightStates[key]);
}
}
}
}
[HarmonyPatch(typeof(GUIManager), "LateUpdate")]
internal static class Patch_GUIManager_GhostFX
{
private static void Postfix(GUIManager __instance)
{
if (BlackPeakRemix.ActiveMasterSwitch && BlackPeakRemix.ActiveGhostFX && (Object)(object)Character.localCharacter != (Object)null && Character.localCharacter.IsGhost && (Object)(object)__instance.poisonSVFX != (Object)null)
{
__instance.poisonSVFX.Play(0.5f);
}
}
}
[HarmonyPatch(typeof(PlayerGhost), "Update")]
internal static class Patch_Character_GhostGlow
{
[HarmonyPostfix]
private static void Postfix(PlayerGhost __instance)
{
//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)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
if (BlackPeakRemix.ActiveMasterSwitch && !((Object)(object)__instance.m_owner == (Object)null))
{
Color playerColor = __instance.m_owner.refs.customization.PlayerColor;
BPR_GlowController.ApplyGlow(((Component)__instance).gameObject, "BPR_GhostGlow", playerColor, 8f, 5f, active: true, Vector3.up * 0.5f, (LightShadows)0);
}
}
}
[HarmonyPatch(typeof(Flare), "Update")]
internal static class Patch_Flare_Visuals_Refined
{
[HarmonyPostfix]
private static void Postfix(Flare __instance)
{
//IL_0021: 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)
if (BlackPeakRemix.ActiveMasterSwitch)
{
bool value = ((ItemComponent)__instance).GetData<BoolItemData>((DataEntryKey)3).Value;
BPR_GlowController.ApplyGlow(((Component)__instance).gameObject, "BPR_FlareLight", __instance.flareColor, BlackPeakRemix.ActiveIntensity * 1.5f, 45f, value, Vector3.zero, (LightShadows)0);
}
}
}
[HarmonyPatch(typeof(Actions_Binoculars))]
internal static class Patch_Binoculars_NightVision
{
[HarmonyPostfix]
[HarmonyPatch("Subscribe")]
private static void PostSubscribe(Actions_Binoculars __instance)
{
if (BlackPeakRemix.ActiveMasterSwitch && !((Object)(object)__instance == (Object)null))
{
((Component)__instance).gameObject.getOrAddComponent<BPR_BinocularChecker>().Init(__instance);
}
}
[HarmonyPostfix]
[HarmonyPatch("Unsubscribe")]
private static void PostUnsubscribe(Actions_Binoculars __instance)
{
if (BlackPeakRemix.ActiveMasterSwitch && !((Object)(object)__instance == (Object)null))
{
BPR_BinocularChecker component = ((Component)__instance).GetComponent<BPR_BinocularChecker>();
if ((Object)(object)component != (Object)null)
{
((Behaviour)component).enabled = false;
}
}
}
}
internal class BPR_BinocularChecker : MonoBehaviour
{
private Action_ShowBinocularOverlay _overlay;
public static bool IsActive { get; private set; }
internal void Init(Actions_Binoculars actions)
{
_overlay = actions?.binocOverlay;
((Behaviour)this).enabled = true;
}
private void Update()
{
IsActive = (Object)(object)_overlay != (Object)null && _overlay.binocularsActive;
}
private void OnDisable()
{
IsActive = false;
}
private void OnDestroy()
{
IsActive = false;
}
}
public class pitchblackpeak
{
internal static class NightGlobals
{
private static readonly int ID_SkyTop = Shader.PropertyToID("SkyTopColor");
private static readonly int ID_SkyMid = Shader.PropertyToID("SkyMidColor");
private static readonly int ID_SkyBot = Shader.PropertyToID("SkyBottomColor");
private static readonly int ID_ExtraFog = Shader.PropertyToID("EXTRAFOG");
private static readonly int ID_brightness = Shader.PropertyToID("brightness");
private static readonly int ID_ambienceStrength = Shader.PropertyToID("ambienceStrength");
private static readonly int ID_ambienceMin = Shader.PropertyToID("ambienceMin");
private static bool _oneShotApplied;
private static readonly Dictionary<int, CameraClearFlags> _originalCameraClearFlags = new Dictionary<int, CameraClearFlags>();
private static readonly Dictionary<int, Color> _originalCameraBackgrounds = new Dictionary<int, Color>();
private static readonly Dictionary<int, bool> _originalSkyboxEnabled = new Dictionary<int, bool>();
private static readonly Dictionary<int, Skybox> _originalSkyboxes = new Dictionary<int, Skybox>();
private static readonly Dictionary<int, float> _originalLightIntensities = new Dictionary<int, float>();
private static readonly Dictionary<int, bool> _originalLightEnabled = new Dictionary<int, bool>();
private static readonly Dictionary<int, bool> _originalObjectActive = new Dictionary<int, bool>();
private static bool _renderSettingsSaved;
private static AmbientMode _originalAmbientMode = (AmbientMode)3;
private static Color _originalAmbientLight = Color.white;
private static float _originalAmbientIntensity = 1f;
private static float _originalReflectionIntensity = 1f;
private static Texture _originalCustomReflectionTexture;
private static Material _originalSkybox;
private static Light _originalSun;
private static readonly Color SkyBlack = new Color(0f, 0f, 0f, 1f);
private const float EXTREME_AmbientBrightness = 0.02f;
private const float EXTREME_AmbientStrength = 0.02f;
private const float EXTREME_AmbienceMin = 0f;
public const float EXNV_Brightness = 0.35f;
public const float EXNV_AmbienceStrength = 0.35f;
public const float EXNV_AmbienceMin = 0.03f;
public static void ApplySceneOneShots()
{
//IL_0151: Unknown result type (might be due to invalid IL or missing references)
//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
//IL_01cd: Invalid comparison between Unknown and I4
try
{
BlackPeakRemix.Log.LogInfo((object)"[NightGlobals] Applying scene one-shot darkness effects...");
Camera[] array = Object.FindObjectsByType<Camera>((FindObjectsSortMode)0);
BlackPeakRemix.Log.LogDebug((object)$"[NightGlobals] Found {array.Length} cameras");
Camera[] array2 = array;
foreach (Camera val in array2)
{
if (!Object.op_Implicit((Object)(object)val))
{
continue;
}
int instanceID = ((Object)val).GetInstanceID();
if (!_originalCameraClearFlags.ContainsKey(instanceID))
{
_originalCameraClearFlags[instanceID] = val.clearFlags;
}
if (!_originalCameraBackgrounds.ContainsKey(instanceID))
{
_originalCameraBackgrounds[instanceID] = val.backgroundColor;
}
val.clearFlags = (CameraClearFlags)2;
val.backgroundColor = Color.black;
Skybox component = ((Component)val).GetComponent<Skybox>();
if (Object.op_Implicit((Object)(object)component))
{
if (!_originalSkyboxEnabled.ContainsKey(instanceID))
{
_originalSkyboxEnabled[instanceID] = ((Behaviour)component).enabled;
}
((Behaviour)component).enabled = false;
}
}
if (!_renderSettingsSaved)
{
_originalAmbientMode = RenderSettings.ambientMode;
_originalAmbientLight = RenderSettings.ambientLight;
_originalAmbientIntensity = RenderSettings.ambientIntensity;
_originalReflectionIntensity = RenderSettings.reflectionIntensity;
_originalCustomReflectionTexture = RenderSettings.customReflectionTexture;
_originalSkybox = RenderSettings.skybox;
_originalSun = RenderSettings.sun;
_renderSettingsSaved = true;
}
RenderSettings.ambientMode = (AmbientMode)3;
RenderSettings.ambientLight = Color.black;
RenderSettings.ambientIntensity = 0f;
RenderSettings.reflectionIntensity = 0f;
RenderSettings.customReflectionTexture = null;
RenderSettings.skybox = null;
RenderSettings.sun = null;
BlackPeakRemix.Log.LogDebug((object)"[NightGlobals] Render settings configured for darkness");
Light[] array3 = Object.FindObjectsByType<Light>((FindObjectsSortMode)0);
int num = 0;
Light[] array4 = array3;
foreach (Light val2 in array4)
{
if (!Object.op_Implicit((Object)(object)val2))
{
continue;
}
string text = ((Object)val2).name.ToLowerInvariant();
if ((int)val2.type == 1 || text.Contains("sun") || text.Contains("moon"))
{
int instanceID2 = ((Object)val2).GetInstanceID();
if (!_originalLightIntensities.ContainsKey(instanceID2))
{
_originalLightIntensities[instanceID2] = val2.intensity;
}
if (!_originalLightEnabled.ContainsKey(instanceID2))
{
_originalLightEnabled[instanceID2] = ((Behaviour)val2).enabled;
}
val2.intensity = 0f;
((Behaviour)val2).enabled = false;
num++;
}
}
BlackPeakRemix.Log.LogDebug((object)$"[NightGlobals] Disabled {num}/{array3.Length} directional/sun/moon lights");
DisableByNameToken("sky");
DisableByNameToken("cloud");
DisableByNameToken("clouds");
DisableByNameToken("stars");
DisableByNameToken("atmosphere");
DisableByNameToken("atmo");
DisableMirrorMountains();
_oneShotApplied = true;
BlackPeakRemix.Log.LogInfo((object)"[NightGlobals] Scene one-shot applied.");
}
catch (Exception ex)
{
BlackPeakRemix.Log.LogError((object)("[NightGlobals] Error in ApplySceneOneShots: " + ex.Message));
}
}
public static void RestoreSceneOneShots()
{
//IL_0058: 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_0152: Unknown result type (might be due to invalid IL or missing references)
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
try
{
if (!_oneShotApplied)
{
BlackPeakRemix.Log.LogDebug((object)"[NightGlobals] One-shot not applied, nothing to restore.");
return;
}
BlackPeakRemix.Log.LogInfo((object)"[NightGlobals] Restoring scene one-shot effects...");
Camera[] array = Object.FindObjectsByType<Camera>((FindObjectsSortMode)0);
foreach (Camera val in array)
{
if (Object.op_Implicit((Object)(object)val))
{
int instanceID = ((Object)val).GetInstanceID();
if (_originalCameraClearFlags.TryGetValue(instanceID, out var value))
{
val.clearFlags = value;
}
if (_originalCameraBackgrounds.TryGetValue(instanceID, out var value2))
{
val.backgroundColor = value2;
}
Skybox component = ((Component)val).GetComponent<Skybox>();
if (Object.op_Implicit((Object)(object)component) && _originalSkyboxEnabled.TryGetValue(instanceID, out var value3))
{
((Behaviour)component).enabled = value3;
}
}
}
Light[] array2 = Object.FindObjectsByType<Light>((FindObjectsSortMode)0);
foreach (Light val2 in array2)
{
if (Object.op_Implicit((Object)(object)val2))
{
int instanceID2 = ((Object)val2).GetInstanceID();
if (_originalLightIntensities.TryGetValue(instanceID2, out var value4))
{
val2.intensity = value4;
}
if (_originalLightEnabled.TryGetValue(instanceID2, out var value5))
{
((Behaviour)val2).enabled = value5;
}
}
}
RestoreByNameToken("sky");
RestoreByNameToken("cloud");
RestoreByNameToken("clouds");
RestoreByNameToken("stars");
RestoreByNameToken("atmosphere");
RestoreByNameToken("atmo");
RestoreMirrorMountains();
if (_renderSettingsSaved)
{
RenderSettings.ambientMode = _originalAmbientMode;
RenderSettings.ambientLight = _originalAmbientLight;
RenderSettings.ambientIntensity = _originalAmbientIntensity;
RenderSettings.reflectionIntensity = _originalReflectionIntensity;
RenderSettings.customReflectionTexture = _originalCustomReflectionTexture;
RenderSettings.skybox = _originalSkybox;
RenderSettings.sun = _originalSun;
BlackPeakRemix.Log.LogDebug((object)"[NightGlobals] Render settings restored");
}
_oneShotApplied = false;
BlackPeakRemix.Log.LogInfo((object)"[NightGlobals] Scene one-shot restored.");
}
catch (Exception ex)
{
BlackPeakRemix.Log.LogError((object)("[NightGlobals] Error in RestoreSceneOneShots: " + ex.Message));
}
}
private static void DisableByNameToken(string token)
{
try
{
Transform[] array = Object.FindObjectsByType<Transform>((FindObjectsSortMode)0);
string value = token.ToLowerInvariant();
int num = 0;
Transform[] array2 = array;
foreach (Transform val in array2)
{
if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)((Component)val).gameObject) && ((Object)val).name.ToLowerInvariant().Contains(value) && !IsUnderCanvas(val))
{
int instanceID = ((Object)val).GetInstanceID();
if (!_originalObjectActive.ContainsKey(instanceID))
{
_originalObjectActive[instanceID] = ((Component)val).gameObject.activeSelf;
}
((Component)val).gameObject.SetActive(false);
num++;
}
}
BlackPeakRemix.Log.LogDebug((object)$"[NightGlobals] Disabled {num} objects matching token '{token}'");
}
catch (Exception ex)
{
BlackPeakRemix.Log.LogWarning((object)("[NightGlobals] Error disabling by token '" + token + "': " + ex.Message));
}
}
private static void RestoreByNameToken(string token)
{
try
{
Transform[] array = Object.FindObjectsByType<Transform>((FindObjectsSortMode)0);
string value = token.ToLowerInvariant();
int num = 0;
Transform[] array2 = array;
foreach (Transform val in array2)
{
if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)((Component)val).gameObject) && ((Object)val).name.ToLowerInvariant().Contains(value) && !IsUnderCanvas(val))
{
int instanceID = ((Object)val).GetInstanceID();
if (_originalObjectActive.TryGetValue(instanceID, out var value2))
{
((Component)val).gameObject.SetActive(value2);
num++;
}
}
}
BlackPeakRemix.Log.LogDebug((object)$"[NightGlobals] Restored {num} objects matching token '{token}'");
}
catch (Exception ex)
{
BlackPeakRemix.Log.LogWarning((object)("[NightGlobals] Error restoring by token '" + token + "': " + ex.Message));
}
}
private static bool IsUnderCanvas(Transform tr)
{
try
{
return Object.op_Implicit((Object)(object)tr) && (Object)(object)((Component)tr).GetComponentInParent<Canvas>(true) != (Object)null;
}
catch
{
return false;
}
}
private static void DisableMirrorMountains()
{
try
{
Transform[] array = Object.FindObjectsByType<Transform>((FindObjectsSortMode)0);
int num = 0;
Transform[] array2 = array;
foreach (Transform val in array2)
{
if (!Object.op_Implicit((Object)(object)val))
{
continue;
}
string text = ((Object)val).name.ToLowerInvariant();
if (!(text == "map") && !text.Contains("[g] map"))
{
continue;
}
Transform[] componentsInChildren = ((Component)val).GetComponentsInChildren<Transform>(true);
foreach (Transform val2 in componentsInChildren)
{
if (Object.op_Implicit((Object)(object)val2) && !IsUnderCanvas(val2) && ((Object)val2).name.ToLowerInvariant().Contains("mountains"))
{
int instanceID = ((Object)val2).GetInstanceID();
if (!_originalObjectActive.ContainsKey(instanceID))
{
_originalObjectActive[instanceID] = ((Component)val2).gameObject.activeSelf;
}
((Component)val2).gameObject.SetActive(false);
num++;
}
}
}
BlackPeakRemix.Log.LogDebug((object)$"[NightGlobals] Disabled {num} mountain objects");
}
catch (Exception ex)
{
BlackPeakRemix.Log.LogWarning((object)("[NightGlobals] Error disabling mirror mountains: " + ex.Message));
}
}
private static void RestoreMirrorMountains()
{
try
{
Transform[] array = Object.FindObjectsByType<Transform>((FindObjectsSortMode)0);
int num = 0;
Transform[] array2 = array;
foreach (Transform val in array2)
{
if (!Object.op_Implicit((Object)(object)val))
{
continue;
}
string text = ((Object)val).name.ToLowerInvariant();
if (!(text == "map") && !text.Contains("[g] map"))
{
continue;
}
Transform[] componentsInChildren = ((Component)val).GetComponentsInChildren<Transform>(true);
foreach (Transform val2 in componentsInChildren)
{
if (Object.op_Implicit((Object)(object)val2) && !IsUnderCanvas(val2) && ((Object)val2).name.ToLowerInvariant().Contains("mountains"))
{
int instanceID = ((Object)val2).GetInstanceID();
if (_originalObjectActive.TryGetValue(instanceID, out var value))
{
((Component)val2).gameObject.SetActive(value);
num++;
}
}
}
}
BlackPeakRemix.Log.LogDebug((object)$"[NightGlobals] Restored {num} mountain objects");
}
catch (Exception ex)
{
BlackPeakRemix.Log.LogWarning((object)("[NightGlobals] Error restoring mirror mountains: " + ex.Message));
}
}
public static void ApplySkyBlackout(DayNightManager dnm)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: 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)
Shader.SetGlobalColor(ID_SkyTop, SkyBlack);
Shader.SetGlobalColor(ID_SkyMid, SkyBlack);
Shader.SetGlobalColor(ID_SkyBot, SkyBlack);
Shader.SetGlobalFloat(ID_ExtraFog, 0f);
try
{
if ((Object)(object)dnm != (Object)null)
{
if ((Object)(object)dnm.sun != (Object)null)
{
dnm.sun.intensity = 0f;
((Behaviour)dnm.sun).enabled = false;
}
if ((Object)(object)dnm.moon != (Object)null)
{
dnm.moon.intensity = 0f;
((Behaviour)dnm.moon).enabled = false;
}
if ((Object)(object)dnm.lensFlare != (Object)null)
{
dnm.lensFlare.intensity = 0f;
}
}
}
catch (Exception ex)
{
BlackPeakRemix.Log.LogWarning((object)("[NightGlobals] Error applying sky blackout: " + ex.Message));
}
}
public static void ApplyAmbientDark(bool hasNightVision)
{
if (hasNightVision)
{
Shader.SetGlobalFloat(ID_brightness, 0.35f);
Shader.SetGlobalFloat(ID_ambienceStrength, 0.35f);
Shader.SetGlobalFloat(ID_ambienceMin, 0.03f);
}
else
{
Shader.SetGlobalFloat(ID_brightness, 0.02f);
Shader.SetGlobalFloat(ID_ambienceStrength, 0.02f);
Shader.SetGlobalFloat(ID_ambienceMin, 0f);
}
}
public static void ClampLavaAlpha()
{
float num = 0.75f;
try
{
if (Shader.GetGlobalFloat("LavaAlpha") > num)
{
Shader.SetGlobalFloat("LavaAlpha", num);
}
}
catch (Exception ex)
{
BlackPeakRemix.Log.LogWarning((object)("[NightGlobals] Error clamping LavaAlpha: " + ex.Message));
Shader.SetGlobalFloat("LavaAlpha", num);
}
}
}
}
}