using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.IO.Compression; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Logging; using HarmonyLib; using UnityEngine; using UnityEngine.Networking; using YamlDotNet.Serialization; using YamlDotNet.Serialization.NamingConventions; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("Hardheim.Timesave")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Hardheim.Timesave")] [assembly: AssemblyCopyright("Copyright © 2026")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("3739dcd7-5f69-4a5a-bdde-a190eac212ba")] [assembly: AssemblyFileVersion("1.2.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.2.0.0")] [BepInPlugin("hardheim.timedsave", "Hardheim Timed Save", "1.4.0")] public class TimedSave : BaseUnityPlugin { private sealed class ConfigData { public bool enabled { get; set; } public List saveTimes { get; set; } public string timezone { get; set; } public Announce announce { get; set; } public Combat combatCheck { get; set; } public Backup backup { get; set; } public Restart restart { get; set; } public Webhook webhook { get; set; } public Status status { get; set; } public bool logToConsole { get; set; } } private sealed class Announce { public bool enabled { get; set; } public int secondsBefore { get; set; } public string message { get; set; } } private sealed class Combat { public bool enabled { get; set; } public bool delayIfInCombat { get; set; } public int retrySeconds { get; set; } } private sealed class Backup { public bool enabled { get; set; } public string folder { get; set; } public bool zip { get; set; } public int keepLast { get; set; } public int delaySeconds { get; set; } public List worldSearchPaths { get; set; } public string customWorldPath { get; set; } } private sealed class Restart { public bool enabled { get; set; } public List restartTimes { get; set; } public int secondsBefore { get; set; } public string announceMessage { get; set; } public string finalMessage { get; set; } public bool delayIfInCombat { get; set; } public int retrySeconds { get; set; } public bool saveBeforeRestart { get; set; } public bool backupBeforeRestart { get; set; } public bool kickPlayersBeforeRestart { get; set; } public int kickBeforeSeconds { get; set; } public string kickMessage { get; set; } public int kickDelaySeconds { get; set; } public int shutdownDelaySeconds { get; set; } public int forceExitAfterSeconds { get; set; } public int kickMessageLeadSeconds { get; set; } } private sealed class Webhook { public bool enabled { get; set; } public string url { get; set; } public string username { get; set; } public string avatarUrl { get; set; } public string serverName { get; set; } public bool useEmbeds { get; set; } public bool sendOnSuccess { get; set; } public bool sendOnError { get; set; } public bool sendOnRestart { get; set; } public string successMessage { get; set; } public string errorMessage { get; set; } public string restartMessage { get; set; } public string restartErrorMessage { get; set; } } private sealed class Status { public bool enabled { get; set; } public string message { get; set; } public bool onlyWhenPlayersOnline { get; set; } } private enum WebhookEventType { BackupSuccess, BackupError, Restart, RestartError, Status } [Serializable] private sealed class DiscordWebhookPayload { public string content; public string username; public string avatar_url; public DiscordEmbed[] embeds; } [Serializable] private sealed class DiscordEmbed { public string title; public string description; public int color; public DiscordEmbedField[] fields; public string timestamp; public DiscordEmbedFooter footer; } [Serializable] private sealed class DiscordEmbedField { public string name; public string value; public bool inline; } [Serializable] private sealed class DiscordEmbedFooter { public string text; } [CompilerGenerated] private sealed class d__46 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public int seconds; public TimedSave <>4__this; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__46(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = (object)new WaitForSeconds((float)seconds); <>1__state = 1; return true; case 1: <>1__state = -1; Environment.Exit(0); 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 d__47 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public TimedSave <>4__this; private int 5__1; private string 5__2; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__47(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { 5__2 = null; <>1__state = -2; } private bool MoveNext() { //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Expected O, but got Unknown int num = <>1__state; if (num != 0) { if (num != 1) { return false; } <>1__state = -1; } else { <>1__state = -1; if (<>4__this.config.announce == null || !<>4__this.config.announce.enabled) { goto IL_0120; } 5__1 = Mathf.Max(0, <>4__this.config.announce.secondsBefore); 5__2 = (string.IsNullOrWhiteSpace(<>4__this.config.announce.message) ? "Szerver mentés {seconds} mp múlva!" : <>4__this.config.announce.message); 5__2 = 5__2.Replace("{seconds}", 5__1.ToString()); <>4__this.SendCenterMessage(5__2); if (5__1 > 0) { <>2__current = (object)new WaitForSeconds((float)5__1); <>1__state = 1; return true; } } 5__2 = null; goto IL_0120; IL_0120: 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 d__48 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public TimedSave <>4__this; private int 5__1; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__48(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Expected O, but got Unknown int num = <>1__state; if (num != 0) { if (num != 1) { return false; } <>1__state = -1; } else { <>1__state = -1; if (<>4__this.config.combatCheck == null || !<>4__this.config.combatCheck.enabled || !<>4__this.config.combatCheck.delayIfInCombat) { goto IL_00c0; } 5__1 = Mathf.Max(1, <>4__this.config.combatCheck.retrySeconds); } if (<>4__this.IsAnyoneInCombat()) { <>2__current = (object)new WaitForSeconds((float)5__1); <>1__state = 1; return true; } goto IL_00c0; IL_00c0: 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 d__70 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public WebhookEventType eventType; public string serverName; public string worldName; public string backupFolder; public string pathValue; public string error; public int playerCount; public string uptime; public TimedSave <>4__this; private DiscordWebhookPayload 5__1; private string