using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using FishNet;
using FishNet.Broadcast;
using FishNet.Connection;
using FishNet.Object;
using FishNet.Serializing;
using FishNet.Transporting;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("FishNet.Runtime")]
[assembly: AssemblyCompany("SpongeMods")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Shared plumbing for Sponge mods: messaging, persistence, timing.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+a149c533da6d929b7267867242f5011f9c2152dc")]
[assembly: AssemblyProduct("SpongeMods.Core")]
[assembly: AssemblyTitle("SpongeMods.Core")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace SpongeMods.Core
{
public abstract class Link
{
private bool _server;
private bool _client;
private bool _described;
public bool Attached
{
get
{
if (!_server)
{
return _client;
}
return true;
}
}
protected virtual void AttachServer()
{
}
protected virtual void AttachClient()
{
}
protected virtual void DetachServer()
{
}
protected virtual void DetachClient()
{
}
protected virtual void Describe()
{
}
public void Step()
{
if (!_described)
{
_described = true;
Describe();
}
bool flag = (Object)(object)InstanceFinder.NetworkManager != (Object)null && InstanceFinder.IsServerStarted && (Object)(object)InstanceFinder.ServerManager != (Object)null;
bool flag2 = (Object)(object)InstanceFinder.NetworkManager != (Object)null && InstanceFinder.IsClientStarted && (Object)(object)InstanceFinder.ClientManager != (Object)null;
if (flag && !_server)
{
AttachServer();
_server = true;
}
else if (!flag && _server)
{
DetachServer();
_server = false;
}
if (flag2 && !_client)
{
AttachClient();
_client = true;
}
else if (!flag2 && _client)
{
DetachClient();
_client = false;
}
}
public void Drop()
{
if (_server)
{
DetachServer();
_server = false;
}
if (_client)
{
DetachClient();
_client = false;
}
}
public static void Tell<T>(T message) where T : struct, IBroadcast
{
if (InstanceFinder.IsClientStarted && (Object)(object)InstanceFinder.ClientManager != (Object)null)
{
InstanceFinder.ClientManager.Broadcast<T>(message, (Channel)0);
}
}
public static void TellAll<T>(T message) where T : struct, IBroadcast
{
if (InstanceFinder.IsServerStarted && (Object)(object)InstanceFinder.ServerManager != (Object)null)
{
InstanceFinder.ServerManager.Broadcast<T>(message, true, (Channel)0);
}
}
public static void TellOne<T>(NetworkConnection who, T message) where T : struct, IBroadcast
{
if (who != (NetworkConnection)null && InstanceFinder.IsServerStarted && (Object)(object)InstanceFinder.ServerManager != (Object)null)
{
InstanceFinder.ServerManager.Broadcast<T>(who, message, true, (Channel)0);
}
}
public static void Describe<T>(Action<Writer, T> write, Func<Reader, T> read)
{
GenericWriter<T>.SetWrite(write);
GenericReader<T>.SetRead(read);
}
public static Player Who(NetworkConnection connection)
{
if (connection == (NetworkConnection)null)
{
return null;
}
List<Player> players = PlayerManager.Players;
for (int i = 0; i < players.Count; i++)
{
Player val = players[i];
if ((Object)(object)val != (Object)null && ((NetworkBehaviour)val).Owner == connection)
{
return val;
}
}
return null;
}
public static string Clip(string text, int longest)
{
if (string.IsNullOrEmpty(text))
{
return string.Empty;
}
if (text.Length > longest)
{
return text.Substring(0, longest);
}
return text;
}
public static int Sane(int count, int most)
{
if (count < 0)
{
return 0;
}
if (count <= most)
{
return count;
}
return most;
}
}
[BepInPlugin("SpongeMods.Core", "Sponge's Core", "1.0.0")]
public sealed class CorePlugin : BaseUnityPlugin
{
public const string Id = "SpongeMods.Core";
public const string Version = "1.0.0";
}
public static class SideCar
{
public static string Folder
{
get
{
string saveFolder = SaveSystem._saveFolder;
if (!string.IsNullOrEmpty(saveFolder))
{
return saveFolder;
}
return Path.Combine(Application.persistentDataPath, "Saves");
}
}
public static string PathFor(string mod, string save = null)
{
string text = (string.IsNullOrEmpty(save) ? mod : (mod + "-" + Clean(save)));
return Path.Combine(Folder, text + ".json");
}
public static string Clean(string name)
{
if (string.IsNullOrEmpty(name))
{
return "unnamed";
}
char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
foreach (char oldChar in invalidFileNameChars)
{
name = name.Replace(oldChar, '_');
}
return name;
}
public static T Read<T>(string path, Action<string> grumble = null) where T : new()
{
try
{
if (!File.Exists(path))
{
return new T();
}
T val = JsonUtility.FromJson<T>(File.ReadAllText(path));
return (val != null) ? val : new T();
}
catch (Exception ex)
{
grumble?.Invoke("Could not read " + Path.GetFileName(path) + ", starting fresh: " + ex.Message);
return new T();
}
}
public static bool Write(string path, object contents, Action<string> grumble = null)
{
try
{
File.WriteAllText(path, JsonUtility.ToJson(contents, true));
return true;
}
catch (Exception ex)
{
grumble?.Invoke("Could not write " + Path.GetFileName(path) + ": " + ex.Message);
return false;
}
}
}
public sealed class Beat
{
private readonly float _gap;
private float _next;
public Beat(float seconds)
{
_gap = Mathf.Max(0.01f, seconds);
}
public bool Due()
{
if (Time.unscaledTime < _next)
{
return false;
}
_next = Time.unscaledTime + _gap;
return true;
}
public void Now()
{
_next = 0f;
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
internal IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}