Skip to content

Commit

Permalink
[ND] Add extra sanity checks and logging; Startup speedup
Browse files Browse the repository at this point in the history
  • Loading branch information
ManlyMarco committed Mar 13, 2023
1 parent c4dda0f commit 0b30bbb
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions src/Core_NightDarkener/NightDarkener.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Linq;
using System.Linq;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
using UnityEngine.SceneManagement;

Expand Down Expand Up @@ -68,12 +66,14 @@ public class NightDarkener : BaseUnityPlugin
public static ConfigEntry<bool> UseFog { get; private set; }
public static ConfigEntry<float> Exposure { get; private set; }

private static void SceneManager_sceneLoaded(Scene arg0, LoadSceneMode arg1)
private void SceneManager_sceneLoaded(Scene arg0, LoadSceneMode arg1)
{
var proc = FindObjectOfType<HSceneProc>();

// Only run in free h, not in main game
if (proc == null || !proc.dataH.isFreeH) return;

// Only run if night time of day was selected
var time = (SunLightInfo.Info.Type)proc.dataH.timezoneFreeH;
if (time != SunLightInfo.Info.Type.Night) return;

Expand All @@ -84,26 +84,35 @@ private static void SceneManager_sceneLoaded(Scene arg0, LoadSceneMode arg1)
if (BeSmartAlwaysOnCustom.Value && proc.dataH.mapNoFreeH > 999) return;
}

var amplifyColorEffect = Camera.main?.gameObject.GetComponent<AmplifyColorEffect>();
if (amplifyColorEffect != null)
amplifyColorEffect.Exposure = Exposure.Value;
if (Camera.main != null)
{
var amplifyColorEffect = Camera.main.gameObject.GetComponent<AmplifyColorEffect>();
if (amplifyColorEffect != null)
amplifyColorEffect.Exposure = Exposure.Value;
}

var lightInfo = FindObjectOfType<SunLightInfo>();

foreach (var info in lightInfo.infos)
if (lightInfo != null)
{
if (info.type != SunLightInfo.Info.Type.Night) continue;

if (UseFog.Value)
foreach (var info in lightInfo.infos)
{
info.fogColor = SubtractColor(info.fogColor, 0.1f);
info.fogStart = 1;
info.fogEnd = 50;
}
if (info.type != SunLightInfo.Info.Type.Night) continue;

//bug does this do anything?
info.color = SubtractColor(info.color, 0.2f);
info.intensity = info.intensity / 2f;
if (UseFog.Value)
{
info.fogColor = SubtractColor(info.fogColor, 0.1f);
info.fogStart = 1;
info.fogEnd = 50;
}

//bug does this do anything?
info.color = SubtractColor(info.color, 0.2f);
info.intensity /= 2f;
}
}
else
{
Logger.LogError("SunLightInfo not found for map id " + proc.dataH.mapNoFreeH);
}
}

Expand All @@ -114,7 +123,6 @@ private void Start()
BeSmart = Config.Bind("General", "Only on specific maps", true, "Only darken maps that are unlikely to have lights turned on at night (likely to be vacant). Turn off to make all maps dark at night.");
BeSmartAlwaysOnCustom = Config.Bind("General", "Always enable on custom maps", true, "If the \"Only on specific maps\" setting is enabled, also darken all custom maps (otherwise all custom maps will not be darkened).");

Harmony.CreateAndPatchAll(typeof(NightDarkener));
SceneManager.sceneLoaded += SceneManager_sceneLoaded;
}

Expand Down

0 comments on commit 0b30bbb

Please sign in to comment.