using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ControlTime")]
[assembly: AssemblyDescription("Valheim mod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ControlTime")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("Ujhik")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ControlTime;
[BepInPlugin("ujhik.ControlTime", "ControlTime", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
internal class JotunnModStub : BaseUnityPlugin
{
[HarmonyPatch(typeof(EnvMan), "Awake")]
public static class EnvMan_Awake_Patch
{
private static void Postfix(ref long ___m_dayLengthSec, ref List<EnvSetup> ___m_environments, ref EnvMan ___s_instance)
{
___m_dayLengthSec = getFullDaySecondsLength();
}
}
[HarmonyPatch(typeof(EnvMan), "FixedUpdate")]
public static class EnvMan_Update_Patch
{
private static void Prefix(ref long ___m_dayLengthSec, ref EnvMan ___s_instance)
{
___m_dayLengthSec = getFullDaySecondsLength();
if (Time.frameCount % 30 == 0 && debugLogging)
{
Logger.LogInfo((object)("isAdmin?: " + SynchronizationManager.Instance.PlayerIsAdmin));
Logger.LogInfo((object)("isNight?: " + EnvMan.s_isNight));
Logger.LogInfo((object)("Seconds full day: " + getFullDaySecondsLength()));
Logger.LogInfo((object)("isRemoveRain: " + isRemoveRain.Value));
Logger.LogInfo((object)("isSkipNight: " + isSkipNight.Value));
Logger.LogInfo((object)("smoothDayFraction: " + ___s_instance.m_smoothDayFraction));
Logger.LogInfo((object)("ZNet time: " + ZNet.instance.m_netTime));
}
if (isSkipNight.Value && EnvMan.s_isNight && !isForceTimeOfDay.Value)
{
Logger.LogInfo((object)("isNight?: " + EnvMan.s_isNight));
double timeSeconds = ZNet.instance.GetTimeSeconds();
double num = timeSeconds - (double)((float)___s_instance.m_dayLengthSec * 0.15f);
int day = ___s_instance.GetDay(num);
double morningStartSec = ___s_instance.GetMorningStartSec(day + 1);
___s_instance.m_skipTime = true;
___s_instance.m_skipToTime = morningStartSec;
___s_instance.m_timeSkipSpeed = skipTimeStep.Value;
ZLog.Log((object)("Time " + timeSeconds + ", day:" + day + " nextm:" + morningStartSec + " skipspeed:" + ___s_instance.m_timeSkipSpeed));
}
else
{
___s_instance.m_skipTime = false;
___s_instance.m_timeSkipSpeed = 1.0;
}
if (isRemoveRain.Value && ___s_instance.IsEnvironment(new List<string> { "Rain", "LightRain", "ThunderStorm" }))
{
___s_instance.QueueEnvironment("Twilight_Clear");
___s_instance.QueueEnvironment("Clear");
}
if (isForceTimeOfDay.Value)
{
___s_instance.m_debugTimeOfDay = true;
___s_instance.m_debugTime = forcedTimeOfDayFraction.Value;
}
else
{
___s_instance.m_debugTimeOfDay = false;
}
}
}
public const string PluginGUID = "ujhik.ControlTime";
public const string PluginName = "ControlTime";
public const string PluginVersion = "1.0.0";
private static bool debugLogging = false;
private static ConfigEntry<long> configMinutesFullDayLength;
private static ConfigEntry<bool> isRemoveRain;
private static ConfigEntry<bool> isSkipNight;
private static ConfigEntry<int> skipTimeStep;
private static ConfigEntry<bool> isForceTimeOfDay;
private static ConfigEntry<float> forcedTimeOfDayFraction;
private Harmony _harmony;
public static CustomLocalization Localization = LocalizationManager.Instance.GetLocalization();
private void Awake()
{
CreateConfigValues();
_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "ujhik.ControlTime");
}
private void CreateConfigValues()
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Expected O, but got Unknown
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Expected O, but got Unknown
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Expected O, but got Unknown
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Expected O, but got Unknown
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Expected O, but got Unknown
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Expected O, but got Unknown
//IL_0134: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Expected O, but got Unknown
ConfigurationManagerAttributes val = new ConfigurationManagerAttributes
{
IsAdminOnly = true
};
AcceptableValueRange<float> val2 = new AcceptableValueRange<float>(0f, 1f);
configMinutesFullDayLength = ((BaseUnityPlugin)this).Config.Bind<long>("General", "minutesFullDayLength", 60L, new ConfigDescription("How much minutes a day lasts (From the \"day n\" to the \"day n-1\", so includes daylight/night)", (AcceptableValueBase)null, new object[1] { val }));
isRemoveRain = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "isRemoveRain", false, new ConfigDescription("Disable rain weather", (AcceptableValueBase)null, new object[1] { val }));
isSkipNight = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "isRemoveNight", false, new ConfigDescription("Skip night", (AcceptableValueBase)null, new object[1] { val }));
skipTimeStep = ((BaseUnityPlugin)this).Config.Bind<int>("General", "skipTimeStep", 1, new ConfigDescription("Skip time step", (AcceptableValueBase)null, new object[1] { val }));
isForceTimeOfDay = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "isForceTimeOfDay", false, new ConfigDescription("Force the status of sun/moon fixed in time", (AcceptableValueBase)null, new object[1] { val }));
forcedTimeOfDayFraction = ((BaseUnityPlugin)this).Config.Bind<float>("General", "forcedTimeOfDayFraction", 0.5f, new ConfigDescription("Number between 0 and 1 that represents the time of day. 0-> Night, 0.26 -> Sunrise, 0.5-> Midday, 0.9-> Midnight", (AcceptableValueBase)(object)val2, new object[1] { val }));
}
private void OnDestroy()
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
public static long getFullDaySecondsLength()
{
return configMinutesFullDayLength.Value * 60;
}
}