using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("Gilles Auclair")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("IslandTime")]
[assembly: AssemblyTitle("IslandTime")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace IslandTime
{
[BepInPlugin("gillez.islandtime", "IslandTime", "1.0.0")]
public class IslandTimePlugin : BaseUnityPlugin
{
internal static ConfigEntry<float> DayLengthMultiplier;
public static IslandTimePlugin Instance { get; private set; }
internal static void LogInfo(string message)
{
((BaseUnityPlugin)Instance).Logger.LogInfo((object)message);
}
internal static void LogWarning(string message)
{
((BaseUnityPlugin)Instance).Logger.LogWarning((object)message);
}
private void Awake()
{
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
Instance = this;
DayLengthMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Time", "DayLengthMultiplier", 2f, "Day/night duration factor. 2 = twice as long; 0.5 = twice as fast. Must be > 0.");
DayLengthMultiplier.SettingChanged += delegate
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"DayLengthMultiplier changed; restart the game for it to take effect.");
};
new Harmony("gillez.islandtime").PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)("Loaded. Day length multiplier: " + DayLengthMultiplier.Value + "x"));
}
}
internal static class PluginInfo
{
public const string PLUGIN_GUID = "gillez.islandtime";
public const string PLUGIN_NAME = "IslandTime";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace IslandTime.Patches
{
[HarmonyPatch(typeof(Sun), "Start")]
internal static class SunStartPatch
{
private static void Postfix(Sun __instance)
{
float value = IslandTimePlugin.DayLengthMultiplier.Value;
if (value <= 0f)
{
IslandTimePlugin.LogWarning("DayLengthMultiplier is " + value + "; must be > 0. Skipping timescale patch.");
return;
}
__instance.initialTimescale /= value;
__instance.timescale = __instance.initialTimescale;
float realtimeDayLength = __instance.GetRealtimeDayLength();
IslandTimePlugin.LogInfo("Timescale " + value + "x slower -> ~" + realtimeDayLength.ToString("F1") + " min per 24 in-game hours.");
}
}
}