392 lines
17 KiB
C#
392 lines
17 KiB
C#
namespace Harmony.WorldEnvironmentPatches
|
|
{
|
|
internal class WorldEnvironmentPatches
|
|
{
|
|
[HarmonyPatch(typeof(WorldEnvironment))]
|
|
[HarmonyPatch("SpectrumsFrameUpdate")]
|
|
public class SpectrumsFrameUpdatePatch
|
|
{
|
|
public static bool Prefix(WorldEnvironment __instance,
|
|
World ___world,
|
|
EntityPlayerLocal ___localPlayer,
|
|
float ___dayTimeScalar,
|
|
Vector2 ___dataFogPow,
|
|
float ___fogDensityOverride,
|
|
Color ___fogColorOverride,
|
|
ref bool ___isUnderWater,
|
|
Vector2 ___dataFogWater,
|
|
Vector3 ___dataFogWaterColor
|
|
)
|
|
{
|
|
if (___world == null || !___localPlayer)
|
|
{
|
|
return false;
|
|
}
|
|
BiomeAtmosphereEffects biomeAtmosphereEffects = ___world.BiomeAtmosphereEffects;
|
|
if (biomeAtmosphereEffects == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
// Calculate current time of day
|
|
//float currentTime = SkyManager.dayPercent * 24f;
|
|
float currentTimeOfDayHours = GameUtils.WorldTimeToHours(GameManager.Instance.World.worldTime);
|
|
float currentTimeOfDayMinutes = GameUtils.WorldTimeToMinutes(GameManager.Instance.World.worldTime);
|
|
|
|
// Combine hours and minutes into a single float
|
|
float currentTime = currentTimeOfDayHours + (currentTimeOfDayMinutes / 60f);
|
|
|
|
if (RebirthUtilities.ScenarioSkip() && !___world.IsEditor() && !GameUtils.IsPlaytesting() && RebirthUtilities.IsHiveDayActive())
|
|
{
|
|
//Log.Out("WorldEnvironmentPatches-SpectrumsFrameUpdate currentTimeOfDayHours: " + currentTimeOfDayHours);
|
|
//Log.Out("WorldEnvironmentPatches-SpectrumsFrameUpdate currentTimeOfDayMinutes: " + currentTimeOfDayMinutes);
|
|
//Log.Out("WorldEnvironmentPatches-SpectrumsFrameUpdate currentTime: " + currentTime);
|
|
currentTime = 0f;
|
|
}
|
|
|
|
// Get the midnight color values for sky, sun, and moon
|
|
Color midnightSkyColor = biomeAtmosphereEffects.GetSkyColorSpectrum(0f);
|
|
midnightSkyColor = WeatherManager.Instance.GetWeatherSpectrum(midnightSkyColor, AtmosphereEffect.ESpecIdx.Sky, 0f);
|
|
|
|
Color midnightSunColor = biomeAtmosphereEffects.GetSunColorSpectrum(0f);
|
|
midnightSunColor = WeatherManager.Instance.GetWeatherSpectrum(midnightSunColor, AtmosphereEffect.ESpecIdx.Sun, 0f);
|
|
|
|
Color midnightMoonColor = biomeAtmosphereEffects.GetMoonColorSpectrum(0f);
|
|
midnightMoonColor = WeatherManager.Instance.GetWeatherSpectrum(midnightMoonColor, AtmosphereEffect.ESpecIdx.Moon, 0f);
|
|
|
|
Color fogColor = Color.black;
|
|
|
|
// Calculate the darkness factor based on time of day
|
|
float darknessFactor = 0f;
|
|
|
|
if (currentTime >= 18f || currentTime < 6f)
|
|
{
|
|
// Gradual darkening from 20h to midnight (and looping midnight as 0h)
|
|
if (currentTime >= 18f && currentTime < 22f)
|
|
{
|
|
darknessFactor = (currentTime - 18f) / 4f;
|
|
}
|
|
// Fully dark between midnight (0h) and 6h
|
|
else if (currentTime >= 22f && currentTime <= 24f)
|
|
{
|
|
darknessFactor = 1f;
|
|
}
|
|
else if (currentTime >= 0f && currentTime < 6f)
|
|
{
|
|
darknessFactor = 1f;
|
|
}
|
|
}
|
|
else if (currentTime >= 6f && currentTime < 9f)
|
|
{
|
|
// Gradual brightening from 6h to 9h
|
|
darknessFactor = 1f - ((currentTime - 6f) / 3f);
|
|
}
|
|
// Darkness factor remains 0 between 9h and 20h
|
|
else
|
|
{
|
|
darknessFactor = 0f;
|
|
}
|
|
|
|
//Log.Out("WorldEnvironmentPatches-SpectrumsFrameUpdate SkyManager.dayPercent:" + SkyManager.dayPercent);
|
|
//Log.Out("WorldEnvironmentPatches-SpectrumsFrameUpdate currentTime:" + currentTime);
|
|
//Log.Out("WorldEnvironmentPatches-SpectrumsFrameUpdate darknessFactor:" + darknessFactor);
|
|
|
|
Color color = biomeAtmosphereEffects.GetSkyColorSpectrum(___dayTimeScalar);
|
|
color = WeatherManager.Instance.GetWeatherSpectrum(color, AtmosphereEffect.ESpecIdx.Sky, ___dayTimeScalar);
|
|
|
|
bool darkerNights = RebirthVariables.customDarkerNights;
|
|
|
|
//if (darkerNights && !GameManager.Instance.World.IsDaytime())
|
|
if (darkerNights)
|
|
{
|
|
if (currentTime >= 0f && currentTime < 6f)
|
|
{
|
|
color = midnightSkyColor;
|
|
}
|
|
|
|
Color sunColor = Color.black;
|
|
|
|
if (!RebirthUtilities.ScenarioSkip() && RebirthVariables.currentBiome == "burnt_forest")
|
|
{
|
|
sunColor = new Color(150f / 255, 0f / 255, 255f / 255);
|
|
}
|
|
|
|
color = Color.Lerp(color, sunColor, darknessFactor);
|
|
SkyManager.SetSkyColor(color);
|
|
/*if (RebirthUtilities.IsHordeNight())
|
|
{
|
|
Color sky = new Color(0f, 0f, 0f, 1f);
|
|
SkyManager.SetSkyColor(sky);
|
|
}
|
|
else
|
|
{
|
|
if (RebirthVariables.inWasteland)
|
|
{
|
|
Color sky = new Color(0f, 0f, 0f, 1f);
|
|
SkyManager.SetSkyColor(sky);
|
|
}
|
|
else
|
|
{
|
|
Color sky = new Color(0f, 0f, 0f, 1f);
|
|
//Log.Out("WorldEnvironmentPatches-SpectrumsFrameUpdate sky:" + sky);
|
|
SkyManager.SetSkyColor(sky);
|
|
}
|
|
}*/
|
|
}
|
|
else
|
|
{
|
|
SkyManager.SetSkyColor(color);
|
|
}
|
|
|
|
color = biomeAtmosphereEffects.GetSunColorSpectrum(___dayTimeScalar);
|
|
color = WeatherManager.Instance.GetWeatherSpectrum(color, AtmosphereEffect.ESpecIdx.Sun, ___dayTimeScalar);
|
|
|
|
if (darkerNights)
|
|
{
|
|
/*if (RebirthUtilities.IsHordeNight())
|
|
{
|
|
Color sun = new Color(0f, 0f, 0f, 1f);
|
|
SkyManager.SetSunColor(sun);
|
|
}
|
|
else
|
|
{
|
|
if (RebirthVariables.inWasteland)
|
|
{
|
|
Color sun = new Color(color.r, color.g, color.b, 1f);
|
|
SkyManager.SetSunColor(sun);
|
|
}
|
|
else
|
|
{
|
|
Color sun = new Color(0f, 0f, 0f, 1f);
|
|
//Log.Out("WorldEnvironmentPatches-SpectrumsFrameUpdate sun:" + sun);
|
|
SkyManager.SetSunColor(sun);
|
|
}
|
|
}*/
|
|
|
|
if (currentTime >= 0f && currentTime < 6f)
|
|
{
|
|
color = midnightSunColor;
|
|
}
|
|
|
|
color = Color.Lerp(color, Color.black, darknessFactor);
|
|
SkyManager.SetSunColor(color);
|
|
}
|
|
else
|
|
{
|
|
SkyManager.SetSunColor(color);
|
|
}
|
|
|
|
if (darkerNights)
|
|
{
|
|
/*if (RebirthVariables.inWasteland)
|
|
{
|
|
//SkyManager.SetSunIntensity(color.a / 2f);
|
|
SkyManager.SetSunIntensity(0f);
|
|
}
|
|
else
|
|
{
|
|
//SkyManager.SetSunIntensity(color.a / 2f);
|
|
SkyManager.SetSunIntensity(0f);
|
|
}*/
|
|
SkyManager.SetSunIntensity(Mathf.Lerp(color.a * 2f, 0f, darknessFactor));
|
|
}
|
|
else
|
|
{
|
|
SkyManager.SetSunIntensity(color.a * 2f);
|
|
}
|
|
|
|
color = biomeAtmosphereEffects.GetMoonColorSpectrum(___dayTimeScalar);
|
|
color = WeatherManager.Instance.GetWeatherSpectrum(color, AtmosphereEffect.ESpecIdx.Moon, ___dayTimeScalar);
|
|
|
|
Color moon = new Color(0.125f, 0.125f, 0.125f, 1f);
|
|
|
|
/*if (RebirthVariables.currentBiome == "wasteland")
|
|
{
|
|
moon = new Color(0.030f, 0.255f, 0);
|
|
}
|
|
else if (RebirthVariables.currentBiome == "burnt_forest")
|
|
{
|
|
moon = new Color(0.119f, 0.003f, 0.252f);
|
|
}*/
|
|
|
|
if (darkerNights)
|
|
{
|
|
/*if (RebirthUtilities.IsHordeNight())
|
|
{
|
|
Color moon = new Color(0.175f, 0.175f, 0.175f, 1f);
|
|
SkyManager.SetMoonLightColor(moon);
|
|
}
|
|
else
|
|
{
|
|
if (RebirthVariables.inWasteland)
|
|
{
|
|
Color moon = new Color(0.125f, 0.125f, 0.125f, 1f);
|
|
SkyManager.SetMoonLightColor(moon);
|
|
}
|
|
else
|
|
{
|
|
Color moon = new Color(0.125f, 0.125f, 0.125f, 1f);
|
|
//Log.Out("WorldEnvironmentPatches-SpectrumsFrameUpdate color:" + color);
|
|
//Log.Out("WorldEnvironmentPatches-SpectrumsFrameUpdate moon:" + moon);
|
|
SkyManager.SetMoonLightColor(moon);
|
|
}
|
|
}*/
|
|
color = WeatherManager.Instance.GetWeatherSpectrum(color, AtmosphereEffect.ESpecIdx.Moon, ___dayTimeScalar);
|
|
|
|
if (currentTime >= 0f && currentTime < 6f)
|
|
{
|
|
color = midnightMoonColor;
|
|
}
|
|
|
|
color = Color.Lerp(color, moon, darknessFactor);
|
|
SkyManager.SetMoonLightColor(color);
|
|
}
|
|
else
|
|
{
|
|
//Log.Out("WorldEnvironmentPatches-SpectrumsFrameUpdate moon:" + color);
|
|
SkyManager.SetMoonLightColor(color);
|
|
}
|
|
|
|
color = biomeAtmosphereEffects.GetFogColorSpectrum(___dayTimeScalar);
|
|
color = WeatherManager.Instance.GetWeatherSpectrum(color, AtmosphereEffect.ESpecIdx.Fog, ___dayTimeScalar);
|
|
Color color2 = biomeAtmosphereEffects.GetFogFadeColorSpectrum(___dayTimeScalar);
|
|
color2 = WeatherManager.Instance.GetWeatherSpectrum(color2, AtmosphereEffect.ESpecIdx.FogFade, ___dayTimeScalar);
|
|
SkyManager.SetFogFade(1f - color2.r - 0.5f, 1f - color2.a);
|
|
Color b = new Color(color.r, color.g, color.b, 1f);
|
|
float dayPercent = SkyManager.dayPercent;
|
|
|
|
//Log.Out("WorldEnvironmentPatches-SpectrumsFrameUpdate ___dataFogPow:" + ___dataFogPow);
|
|
|
|
float num = Mathf.Pow(color.a, Mathf.LerpUnclamped(___dataFogPow.y, ___dataFogPow.x, dayPercent));
|
|
num += WeatherManager.currentWeather.FogPercent();
|
|
|
|
//Log.Out("WorldEnvironmentPatches-SpectrumsFrameUpdate BEFORE num" + num);
|
|
|
|
if (num > 1f)
|
|
{
|
|
num = 1f;
|
|
}
|
|
|
|
//Log.Out("WorldEnvironmentPatches-SpectrumsFrameUpdate ___fogDensityOverride" + ___fogDensityOverride);
|
|
|
|
if (___fogDensityOverride >= 0f)
|
|
{
|
|
num = ___fogDensityOverride;
|
|
b = ___fogColorOverride;
|
|
}
|
|
float t = 0.01f;
|
|
if (___localPlayer.IsUnderwaterCamera)
|
|
{
|
|
___isUnderWater = true;
|
|
num = ___dataFogWater.x;
|
|
t = ___dataFogWater.y;
|
|
float num2 = 0.35f + SkyManager.dayPercent * 0.65f;
|
|
b = new Color(___dataFogWaterColor.x * num2, ___dataFogWaterColor.y * num2, ___dataFogWaterColor.z * num2, 1f);
|
|
}
|
|
else if (___isUnderWater)
|
|
{
|
|
___isUnderWater = false;
|
|
t = 1f;
|
|
}
|
|
if (___localPlayer.bPlayingSpawnIn)
|
|
{
|
|
t = 1f;
|
|
}
|
|
|
|
if (!darkerNights)
|
|
{
|
|
fogColor = SkyManager.GetFogColor();
|
|
}
|
|
|
|
if (darkerNights) // && !GameManager.Instance.World.IsDaytime())
|
|
{
|
|
/*Color fog = new Color(0f, 0f, 0f, 1f);
|
|
SkyManager.SetFogColor(fog);*/
|
|
color = WeatherManager.Instance.GetWeatherSpectrum(color, AtmosphereEffect.ESpecIdx.Fog, ___dayTimeScalar);
|
|
color = Color.Lerp(color, fogColor, darknessFactor);
|
|
SkyManager.SetFogColor(color);
|
|
}
|
|
else
|
|
{
|
|
SkyManager.SetFogColor(Color.Lerp(fogColor, b, t));
|
|
}
|
|
|
|
string optionWeatherFog = RebirthVariables.customWeatherFog;
|
|
float fogDensity = SkyManager.GetFogDensity();
|
|
|
|
//Log.Out("WorldEnvironmentPatches-SpectrumsFrameUpdate fogDensity" + fogDensity);
|
|
//Log.Out("WorldEnvironmentPatches-SpectrumsFrameUpdate BEFORE num" + num);
|
|
|
|
if (RebirthVariables.currentBiome == "wasteland")
|
|
{
|
|
if (optionWeatherFog == "lower")
|
|
{
|
|
num = 0.15f;
|
|
}
|
|
else if (optionWeatherFog == "higher")
|
|
{
|
|
num = 0.35f;
|
|
}
|
|
else if (optionWeatherFog == "highest")
|
|
{
|
|
num = 0.45f;
|
|
}
|
|
else
|
|
{
|
|
num = 0.25f;
|
|
}
|
|
}
|
|
else if (RebirthVariables.currentBiome == "burnt_forest")
|
|
{
|
|
if (optionWeatherFog == "lower")
|
|
{
|
|
num = 0.2f;
|
|
}
|
|
else if (optionWeatherFog == "higher")
|
|
{
|
|
num = 0.5f;
|
|
}
|
|
else if (optionWeatherFog == "highest")
|
|
{
|
|
num = 0.6f;
|
|
}
|
|
else
|
|
{
|
|
num = 0.4f;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (optionWeatherFog == "lower")
|
|
{
|
|
num = num / 2f;
|
|
}
|
|
else if (optionWeatherFog == "higher")
|
|
{
|
|
num = num * 1.3f;
|
|
}
|
|
else if (optionWeatherFog == "highest")
|
|
{
|
|
num = num * 1.6f;
|
|
}
|
|
}
|
|
|
|
//Log.Out("WorldEnvironmentPatches-SpectrumsFrameUpdate AFTER num" + num);
|
|
//Log.Out("WorldEnvironmentPatches-SpectrumsFrameUpdate t" + t);
|
|
|
|
if (optionWeatherFog == "none" || (RebirthVariables.disableFogOnFlight && ___localPlayer.IsFlyMode.Value)) // || (darkerNights && RebirthUtilities.IsHordeNight()))
|
|
{
|
|
SkyManager.SetFogDensity(0f);
|
|
}
|
|
else
|
|
{
|
|
//Log.Out("WorldEnvironmentPatches-SpectrumsFrameUpdate Lerp" + Mathf.Lerp(fogDensity, num, t));
|
|
SkyManager.SetFogDensity(Mathf.Lerp(fogDensity, num, t));
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|