using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using EasyTextEffects.Editor.MyBoxCopy.Extensions;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Networking;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("baer1")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyCopyright("Copyright (c) baer1 2025")]
[assembly: AssemblyDescription("A collection of useful modding utilities for Lethal Company")]
[assembly: AssemblyFileVersion("0.0.7.0")]
[assembly: AssemblyInformationalVersion("0.0.7+0700a49b744a13fe2991e2e064f03fcda668d874")]
[assembly: AssemblyProduct("LethalModUtils")]
[assembly: AssemblyTitle("baer1.LethalModUtils")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/baerchen201/LethalModUtils.git")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.7.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.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 LethalModUtils
{
public static class Audio
{
public class UnknownTypeError : Exception
{
public UnknownTypeError(string fileExtension)
: base("Unrecognized audio file type: " + fileExtension)
{
}
}
public class RequestError : Exception
{
public RequestError(string errorMessage)
: base("WebRequest error: " + errorMessage)
{
}
}
public class ClipError : Exception
{
public ClipError(AudioDataLoadState? state)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
object obj;
if (!state.HasValue)
{
obj = null;
}
else
{
AudioDataLoadState valueOrDefault = state.GetValueOrDefault();
obj = ((object)(AudioDataLoadState)(ref valueOrDefault)).ToString();
}
if (obj == null)
{
obj = "null";
}
base..ctor("Clip load error: " + (string?)obj);
}
}
public class AudioPlayer
{
private class _MonoBehaviour : MonoBehaviour
{
}
public enum PlayerState
{
Playing,
Paused,
Finished
}
private readonly Action<AudioPlayer>? MainLoop;
internal readonly GameObject GameObject;
internal readonly AudioSource AudioSource;
private bool finished;
public PlayerState State => finished ? PlayerState.Finished : ((!AudioSource.isPlaying) ? PlayerState.Paused : PlayerState.Playing);
public bool Muted
{
get
{
return AudioSource.mute;
}
set
{
AudioSource.mute = value;
}
}
public bool BypassEffects
{
get
{
return AudioSource.bypassEffects;
}
set
{
AudioSource.bypassEffects = value;
}
}
public bool BypassListenerEffects
{
get
{
return AudioSource.bypassListenerEffects;
}
set
{
AudioSource.bypassListenerEffects = value;
}
}
public bool BypassReverbZones
{
get
{
return AudioSource.bypassReverbZones;
}
set
{
AudioSource.bypassReverbZones = value;
}
}
public bool Loop
{
get
{
return AudioSource.loop;
}
set
{
AudioSource.loop = value;
}
}
public int Priority
{
get
{
return AudioSource.priority;
}
set
{
AudioSource.priority = value;
}
}
public float Volume
{
get
{
return AudioSource.volume;
}
set
{
AudioSource.volume = value;
}
}
public float Pitch
{
get
{
return AudioSource.pitch;
}
set
{
AudioSource.pitch = value;
}
}
public float DopplerLevel
{
get
{
return AudioSource.dopplerLevel;
}
set
{
AudioSource.dopplerLevel = value;
}
}
public float MaxDistance => AudioSource.maxDistance;
public float MinDistance => AudioSource.minDistance;
public AudioRolloffMode RolloffMode => AudioSource.rolloffMode;
public AnimationCurve RolloffCurve => AudioSource.GetCustomCurve((AudioSourceCurveType)0);
public AudioSource _audioSource => AudioSource;
private AudioPlayer()
{
throw new InvalidOperationException();
}
internal AudioPlayer(AudioClip audioClip, Action<AudioPlayer>? mainLoop)
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Expected O, but got Unknown
LethalModUtils.Logger.LogDebug((object)$">> AudioPlayer({audioClip}, {mainLoop.str()})");
MainLoop = mainLoop;
GameObject = new GameObject();
AudioSource = GameObject.AddComponent<AudioSource>();
Object.DontDestroyOnLoad((Object)(object)GameObject);
((Object)GameObject).hideFlags = (HideFlags)61;
AudioSource.clip = audioClip;
finished = false;
((MonoBehaviour)GameObject.AddComponent<_MonoBehaviour>()).StartCoroutine(this.mainLoop());
}
public void SetRange(float? maxDistance, float? minDistance = null)
{
AudioSource.spatialBlend = 1f;
if (maxDistance.HasValue)
{
AudioSource.maxDistance = maxDistance.Value;
}
if (minDistance.HasValue)
{
AudioSource.minDistance = minDistance.Value;
}
}
public void SetRange()
{
AudioSource.spatialBlend = 0f;
}
public void SetRolloff(bool linear = true)
{
AudioSource.rolloffMode = (AudioRolloffMode)(linear ? 1 : 0);
}
public void SetRolloff(AnimationCurve curve)
{
AudioSource.SetCustomCurve((AudioSourceCurveType)0, curve);
AudioSource.rolloffMode = (AudioRolloffMode)2;
}
public void Cancel()
{
LethalModUtils.Logger.LogDebug((object)$">> AudioPlayer.Cancel() State:{State} AudioSource:{AudioSource.str()} GameObject:{GameObject.str()}");
if (Object.op_Implicit((Object)(object)AudioSource))
{
Object.Destroy((Object)(object)AudioSource);
}
if (Object.op_Implicit((Object)(object)GameObject))
{
Object.Destroy((Object)(object)GameObject);
}
finished = true;
}
public void Pause()
{
AudioSource audioSource = AudioSource;
if (audioSource != null)
{
audioSource.Pause();
}
}
public void Stop()
{
AudioSource audioSource = AudioSource;
if (audioSource != null)
{
audioSource.Stop();
}
}
public void Resume()
{
AudioSource audioSource = AudioSource;
if (audioSource != null)
{
audioSource.Play();
}
}
private IEnumerator mainLoop()
{
yield return null;
try
{
while (!finished && Object.op_Implicit((Object)(object)AudioSource) && Object.op_Implicit((Object)(object)GameObject))
{
MainLoop?.Invoke(this);
yield return null;
}
}
finally
{
Cancel();
}
}
public override string ToString()
{
return $"{GetType().Name} {{ State:{State}, Volume:{Volume}, Muted:{Muted}, MainLoop:{MainLoop.str()} }}";
}
}
private static AudioType GetAudioType(string ext)
{
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
string text = ext.ToLower();
if (1 == 0)
{
}
AudioType result = (AudioType)(text switch
{
".ogg" => 14,
".mp3" => 13,
".wav" => 20,
".m4a" => 1,
".aiff" => 2,
_ => 0,
});
if (1 == 0)
{
}
return result;
}
public static AudioClip Load(Uri path, TimeSpan? timeout = null)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Invalid comparison between Unknown and I4
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0129: Unknown result type (might be due to invalid IL or missing references)
//IL_012f: Invalid comparison between Unknown and I4
//IL_0173: Unknown result type (might be due to invalid IL or missing references)
//IL_0178: Unknown result type (might be due to invalid IL or missing references)
//IL_017a: Unknown result type (might be due to invalid IL or missing references)
//IL_017d: Invalid comparison between Unknown and I4
//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
string text = Path.GetExtension(path.AbsolutePath).ToLower();
AudioType audioType = GetAudioType(text);
LethalModUtils.Logger.LogDebug((object)$">> Audio.Load({path}, {timeout.str()}) audioType:{audioType}");
if ((int)audioType == 0)
{
UnknownTypeError unknownTypeError = new UnknownTypeError(text);
LethalModUtils.Logger.LogWarning((object)$"Error loading {path}: {unknownTypeError.Message}");
throw unknownTypeError;
}
UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(path, audioType);
((DownloadHandlerAudioClip)audioClip.downloadHandler).streamAudio = !LethalModUtils.Instance.PreloadAudio;
audioClip.SendWebRequest();
if (timeout.HasValue)
{
Task task = Task.Delay(timeout.Value);
while (!audioClip.isDone && !task.IsCompleted)
{
}
if (!audioClip.isDone)
{
TimeoutException ex = new TimeoutException();
LethalModUtils.Logger.LogWarning((object)$"Error loading {path}: {ex.Message}");
throw ex;
}
}
else
{
while (!audioClip.isDone)
{
}
}
if ((int)audioClip.result != 1)
{
RequestError requestError = new RequestError(audioClip.error);
LethalModUtils.Logger.LogWarning((object)$"Error loading {path}: {requestError.Message}");
throw requestError;
}
AudioClip content = DownloadHandlerAudioClip.GetContent(audioClip);
bool flag;
if (content != null)
{
AudioDataLoadState loadState = content.loadState;
if ((int)loadState == 2)
{
flag = false;
goto IL_0189;
}
}
flag = true;
goto IL_0189;
IL_0189:
if (flag)
{
ClipError clipError = new ClipError((content != null) ? new AudioDataLoadState?(content.loadState) : null);
LethalModUtils.Logger.LogWarning((object)$"Error loading {path}: {clipError.Message}");
throw clipError;
}
LethalModUtils.Logger.LogInfo((object)$"Loaded {path}");
return content;
}
public static AudioClip? TryLoad(Uri path, TimeSpan? timeout = null)
{
LethalModUtils.Logger.LogDebug((object)$">> Audio.TryLoad({path}, {timeout.str()})");
try
{
return Load(path, timeout);
}
catch (Exception arg)
{
LethalModUtils.Logger.LogDebug((object)$"<< Audio.TryLoad null ({arg})");
}
return null;
}
public static AudioClip Load(Uri path, out UnityWebRequest webRequest, TimeSpan? timeout = null)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Invalid comparison between Unknown and I4
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_012e: Unknown result type (might be due to invalid IL or missing references)
//IL_0134: Invalid comparison between Unknown and I4
//IL_017a: Unknown result type (might be due to invalid IL or missing references)
//IL_017f: Unknown result type (might be due to invalid IL or missing references)
//IL_0181: Unknown result type (might be due to invalid IL or missing references)
//IL_0184: Invalid comparison between Unknown and I4
//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
string text = Path.GetExtension(path.AbsolutePath).ToLower();
AudioType audioType = GetAudioType(text);
LethalModUtils.Logger.LogDebug((object)$">> Audio.Load({path}, {timeout.str()}) audioType:{audioType}");
if ((int)audioType == 0)
{
UnknownTypeError unknownTypeError = new UnknownTypeError(text);
LethalModUtils.Logger.LogWarning((object)$"Error loading {path}: {unknownTypeError.Message}");
throw unknownTypeError;
}
webRequest = UnityWebRequestMultimedia.GetAudioClip(path, audioType);
((DownloadHandlerAudioClip)webRequest.downloadHandler).streamAudio = !LethalModUtils.Instance.PreloadAudio;
webRequest.SendWebRequest();
if (timeout.HasValue)
{
Task task = Task.Delay(timeout.Value);
while (!webRequest.isDone && !task.IsCompleted)
{
}
if (!webRequest.isDone)
{
TimeoutException ex = new TimeoutException();
LethalModUtils.Logger.LogWarning((object)$"Error loading {path}: {ex.Message}");
throw ex;
}
}
else
{
while (!webRequest.isDone)
{
}
}
if ((int)webRequest.result != 1)
{
RequestError requestError = new RequestError(webRequest.error);
LethalModUtils.Logger.LogWarning((object)$"Error loading {path}: {requestError.Message}");
throw requestError;
}
AudioClip content = DownloadHandlerAudioClip.GetContent(webRequest);
bool flag;
if (content != null)
{
AudioDataLoadState loadState = content.loadState;
if ((int)loadState == 2)
{
flag = false;
goto IL_0190;
}
}
flag = true;
goto IL_0190;
IL_0190:
if (flag)
{
ClipError clipError = new ClipError((content != null) ? new AudioDataLoadState?(content.loadState) : null);
LethalModUtils.Logger.LogWarning((object)$"Error loading {path}: {clipError.Message}");
throw clipError;
}
LethalModUtils.Logger.LogInfo((object)$"Loaded {path}");
return content;
}
public static AudioClip? TryLoad(Uri path, out UnityWebRequest? webRequest, TimeSpan? timeout = null)
{
webRequest = null;
LethalModUtils.Logger.LogDebug((object)$">> Audio.TryLoad({path}, {timeout.str()})");
try
{
return Load(path, out webRequest, timeout);
}
catch (Exception arg)
{
LethalModUtils.Logger.LogDebug((object)$"<< Audio.TryLoad null ({arg})");
}
return null;
}
public static Task<AudioClip> LoadAsync(Uri path, TimeSpan? timeout = null)
{
LethalModUtils.Logger.LogDebug((object)$">> Audio.LoadAsync({path}, {timeout.str()})");
TaskCompletionSource<AudioClip> taskCompletionSource = new TaskCompletionSource<AudioClip>();
((MonoBehaviour)LethalModUtils.Instance).StartCoroutine(LoadEnumerator(path, taskCompletionSource));
if (timeout.HasValue)
{
Task task = Task.Delay(timeout.Value);
if (Task.WhenAny(new Task[2] { taskCompletionSource.Task, task }) == task)
{
TimeoutException ex = new TimeoutException();
LethalModUtils.Logger.LogWarning((object)$"Error loading {path}: {ex.Message}");
throw ex;
}
}
return taskCompletionSource.Task;
}
private static IEnumerator LoadEnumerator(Uri path, TaskCompletionSource<AudioClip> task)
{
string ext = Path.GetExtension(path.AbsolutePath).ToLower();
AudioType audioType = GetAudioType(ext);
LethalModUtils.Logger.LogDebug((object)$">> Audio.LoadEnumerator({path}, {task}) audioType:{audioType}");
if ((int)audioType == 0)
{
UnknownTypeError e2 = new UnknownTypeError(ext);
LethalModUtils.Logger.LogWarning((object)$"Error loading {path}: {e2.Message}");
task.SetException(e2);
yield break;
}
UnityWebRequest webRequest = UnityWebRequestMultimedia.GetAudioClip(path, audioType);
((DownloadHandlerAudioClip)webRequest.downloadHandler).streamAudio = !LethalModUtils.Instance.PreloadAudio;
yield return webRequest.SendWebRequest();
if ((int)webRequest.result != 1)
{
RequestError e3 = new RequestError(webRequest.error);
LethalModUtils.Logger.LogWarning((object)$"Error loading {path}: {e3.Message}");
task.SetException(e3);
yield break;
}
AudioClip audioClip = DownloadHandlerAudioClip.GetContent(webRequest);
bool flag;
if (audioClip != null)
{
AudioDataLoadState loadState = audioClip.loadState;
if ((int)loadState == 2)
{
flag = false;
goto IL_01c8;
}
}
flag = true;
goto IL_01c8;
IL_01c8:
if (flag)
{
ClipError e = new ClipError((audioClip != null) ? new AudioDataLoadState?(audioClip.loadState) : null);
LethalModUtils.Logger.LogWarning((object)$"Error loading {path}: {e.Message}");
task.SetException(e);
}
else
{
LethalModUtils.Logger.LogInfo((object)$"Loaded {path}");
task.SetResult(audioClip);
}
}
public static async Task<AudioClip?> TryLoadAsync(Uri path, TimeSpan? timeout = null)
{
LethalModUtils.Logger.LogDebug((object)$">> Audio.TryLoadAsync({path}, {timeout.str()})");
try
{
return await LoadAsync(path, timeout);
}
catch (Exception ex)
{
Exception e = ex;
LethalModUtils.Logger.LogDebug((object)$"<< Audio.TryLoadAsync null ({e})");
}
return null;
}
public static AudioPlayer Play(this AudioClip audioClip, Action<AudioPlayer>? mainLoop = null)
{
AudioPlayer audioPlayer = new AudioPlayer(audioClip, mainLoop);
audioPlayer.Resume();
return audioPlayer;
}
public static AudioPlayer CreatePlayer(this AudioClip audioClip, Action<AudioPlayer>? mainLoop = null)
{
return new AudioPlayer(audioClip, mainLoop);
}
public static AudioPlayer PlayAt(this AudioClip audioClip, Vector3 position, Action<AudioPlayer>? mainLoop = null)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
AudioPlayer audioPlayer = new AudioPlayer(audioClip, mainLoop);
audioPlayer.GameObject.transform.position = position;
audioPlayer.Resume();
return audioPlayer;
}
public static AudioPlayer PlayAt(this AudioClip audioClip, Transform parent, Action<AudioPlayer>? mainLoop = null)
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
AudioPlayer audioPlayer = new AudioPlayer(audioClip, mainLoop);
audioPlayer.GameObject.transform.parent = parent;
audioPlayer.GameObject.transform.localPosition = Vector3.zero;
audioPlayer.Resume();
return audioPlayer;
}
public static AudioPlayer PlayAt(this AudioClip audioClip, Transform parent, Vector3 offset, Action<AudioPlayer>? mainLoop = null)
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
AudioPlayer audioPlayer = new AudioPlayer(audioClip, mainLoop);
audioPlayer.GameObject.transform.parent = parent;
audioPlayer.GameObject.transform.localPosition = offset;
audioPlayer.Resume();
return audioPlayer;
}
public static AudioPlayer PlayAt(this AudioClip audioClip, Vector3 position, Transform parent, Action<AudioPlayer>? mainLoop = null)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
AudioPlayer audioPlayer = new AudioPlayer(audioClip, mainLoop);
audioPlayer.GameObject.transform.position = position;
audioPlayer.GameObject.transform.parent = parent;
audioPlayer.Resume();
return audioPlayer;
}
public static AudioPlayer CreatePlayerAt(this AudioClip audioClip, Vector3 position, Action<AudioPlayer>? mainLoop = null)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
AudioPlayer audioPlayer = new AudioPlayer(audioClip, mainLoop);
audioPlayer.GameObject.transform.position = position;
return audioPlayer;
}
public static AudioPlayer CreatePlayerAt(this AudioClip audioClip, Transform parent, Action<AudioPlayer>? mainLoop = null)
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
AudioPlayer audioPlayer = new AudioPlayer(audioClip, mainLoop);
audioPlayer.GameObject.transform.parent = parent;
audioPlayer.GameObject.transform.localPosition = Vector3.zero;
return audioPlayer;
}
public static AudioPlayer CreatePlayerAt(this AudioClip audioClip, Transform parent, Vector3 offset, Action<AudioPlayer>? mainLoop = null)
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
AudioPlayer audioPlayer = new AudioPlayer(audioClip, mainLoop);
audioPlayer.GameObject.transform.parent = parent;
audioPlayer.GameObject.transform.localPosition = offset;
return audioPlayer;
}
public static AudioPlayer CreatePlayerAt(this AudioClip audioClip, Vector3 position, Transform parent, Action<AudioPlayer>? mainLoop = null)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
AudioPlayer audioPlayer = new AudioPlayer(audioClip, mainLoop);
audioPlayer.GameObject.transform.position = position;
audioPlayer.GameObject.transform.parent = parent;
return audioPlayer;
}
}
public static class Crc32
{
private static readonly uint[] table = new uint[256]
{
0u, 1996959894u, 3993919788u, 2567524794u, 124634137u, 1886057615u, 3915621685u, 2657392035u, 249268274u, 2044508324u,
3772115230u, 2547177864u, 162941995u, 2125561021u, 3887607047u, 2428444049u, 498536548u, 1789927666u, 4089016648u, 2227061214u,
450548861u, 1843258603u, 4107580753u, 2211677639u, 325883990u, 1684777152u, 4251122042u, 2321926636u, 335633487u, 1661365465u,
4195302755u, 2366115317u, 997073096u, 1281953886u, 3579855332u, 2724688242u, 1006888145u, 1258607687u, 3524101629u, 2768942443u,
901097722u, 1119000684u, 3686517206u, 2898065728u, 853044451u, 1172266101u, 3705015759u, 2882616665u, 651767980u, 1373503546u,
3369554304u, 3218104598u, 565507253u, 1454621731u, 3485111705u, 3099436303u, 671266974u, 1594198024u, 3322730930u, 2970347812u,
795835527u, 1483230225u, 3244367275u, 3060149565u, 1994146192u, 31158534u, 2563907772u, 4023717930u, 1907459465u, 112637215u,
2680153253u, 3904427059u, 2013776290u, 251722036u, 2517215374u, 3775830040u, 2137656763u, 141376813u, 2439277719u, 3865271297u,
1802195444u, 476864866u, 2238001368u, 4066508878u, 1812370925u, 453092731u, 2181625025u, 4111451223u, 1706088902u, 314042704u,
2344532202u, 4240017532u, 1658658271u, 366619977u, 2362670323u, 4224994405u, 1303535960u, 984961486u, 2747007092u, 3569037538u,
1256170817u, 1037604311u, 2765210733u, 3554079995u, 1131014506u, 879679996u, 2909243462u, 3663771856u, 1141124467u, 855842277u,
2852801631u, 3708648649u, 1342533948u, 654459306u, 3188396048u, 3373015174u, 1466479909u, 544179635u, 3110523913u, 3462522015u,
1591671054u, 702138776u, 2966460450u, 3352799412u, 1504918807u, 783551873u, 3082640443u, 3233442989u, 3988292384u, 2596254646u,
62317068u, 1957810842u, 3939845945u, 2647816111u, 81470997u, 1943803523u, 3814918930u, 2489596804u, 225274430u, 2053790376u,
3826175755u, 2466906013u, 167816743u, 2097651377u, 4027552580u, 2265490386u, 503444072u, 1762050814u, 4150417245u, 2154129355u,
426522225u, 1852507879u, 4275313526u, 2312317920u, 282753626u, 1742555852u, 4189708143u, 2394877945u, 397917763u, 1622183637u,
3604390888u, 2714866558u, 953729732u, 1340076626u, 3518719985u, 2797360999u, 1068828381u, 1219638859u, 3624741850u, 2936675148u,
906185462u, 1090812512u, 3747672003u, 2825379669u, 829329135u, 1181335161u, 3412177804u, 3160834842u, 628085408u, 1382605366u,
3423369109u, 3138078467u, 570562233u, 1426400815u, 3317316542u, 2998733608u, 733239954u, 1555261956u, 3268935591u, 3050360625u,
752459403u, 1541320221u, 2607071920u, 3965973030u, 1969922972u, 40735498u, 2617837225u, 3943577151u, 1913087877u, 83908371u,
2512341634u, 3803740692u, 2075208622u, 213261112u, 2463272603u, 3855990285u, 2094854071u, 198958881u, 2262029012u, 4057260610u,
1759359992u, 534414190u, 2176718541u, 4139329115u, 1873836001u, 414664567u, 2282248934u, 4279200368u, 1711684554u, 285281116u,
2405801727u, 4167216745u, 1634467795u, 376229701u, 2685067896u, 3608007406u, 1308918612u, 956543938u, 2808555105u, 3495958263u,
1231636301u, 1047427035u, 2932959818u, 3654703836u, 1088359270u, 936918000u, 2847714899u, 3736837829u, 1202900863u, 817233897u,
3183342108u, 3401237130u, 1404277552u, 615818150u, 3134207493u, 3453421203u, 1423857449u, 601450431u, 3009837614u, 3294710456u,
1567103746u, 711928724u, 3020668471u, 3272380065u, 1510334235u, 755167117u
};
public static uint Calculate(byte[] bytes)
{
return bytes.Aggregate(uint.MaxValue, (uint current, byte b) => (current >> 8) ^ table[(current ^ b) & 0xFF]) ^ 0xFFFFFFFFu;
}
}
internal static class ObjectExtensions
{
internal static string str(this object? obj)
{
return (obj == null) ? "null" : obj.ToString();
}
}
public static class FS
{
public enum ProcessFilter
{
All,
None,
DirectoriesOnly,
FilesOnly
}
public static int IterateDirectories(DirectoryInfo root, Func<FileInfo, bool> callback, Func<DirectoryInfo, ProcessFilter>? filter = null)
{
Func<FileInfo, bool> callback2 = callback;
Func<DirectoryInfo, ProcessFilter> filter2 = filter;
LethalModUtils.Logger.LogDebug((object)$">> IterateDirectories(root: {root}, callback: {callback2}, filter: {filter2})");
if (!root.Exists)
{
return 0;
}
ProcessFilter processFilter = filter2?.Invoke(root) ?? ProcessFilter.All;
int num = 0;
if ((processFilter == ProcessFilter.All || processFilter == ProcessFilter.DirectoriesOnly) ? true : false)
{
num += ((IEnumerable<DirectoryInfo>)root.GetDirectories()).Sum((Func<DirectoryInfo, int>)RecurseWithParameters);
}
if ((processFilter == ProcessFilter.All || processFilter == ProcessFilter.FilesOnly) ? true : false)
{
num += root.GetFiles().Count(callback2);
}
return num;
int RecurseWithParameters(DirectoryInfo _root)
{
return IterateDirectories(_root, callback2, filter2);
}
}
public static void IterateDirectories(DirectoryInfo root, Action<FileInfo> callback, Func<DirectoryInfo, ProcessFilter>? filter = null)
{
Action<FileInfo> callback2 = callback;
Func<DirectoryInfo, ProcessFilter> filter2 = filter;
LethalModUtils.Logger.LogDebug((object)$">> IterateDirectories(root: {root}, callback: {callback2}, filter: {filter2})");
if (root.Exists)
{
ProcessFilter processFilter = filter2?.Invoke(root) ?? ProcessFilter.All;
if ((processFilter == ProcessFilter.All || processFilter == ProcessFilter.DirectoriesOnly) ? true : false)
{
MyCollections.ForEach<DirectoryInfo>((IEnumerable<DirectoryInfo>)root.GetDirectories(), (Action<DirectoryInfo>)RecurseWithParameters);
}
if ((processFilter == ProcessFilter.All || processFilter == ProcessFilter.FilesOnly) ? true : false)
{
MyCollections.ForEach<FileInfo>((IEnumerable<FileInfo>)root.GetFiles(), callback2);
}
}
void RecurseWithParameters(DirectoryInfo _root)
{
IterateDirectories(_root, callback2, filter2);
}
}
}
public class Image
{
public class RequestError : Exception
{
public RequestError(string errorMessage)
: base("WebRequest error: " + errorMessage)
{
}
}
public class TextureError : Exception
{
public TextureError()
: base("Texture is null")
{
}
}
public static Task<Texture2D> LoadAsync(Uri path, TimeSpan? timeout = null)
{
LethalModUtils.Logger.LogDebug((object)$">> Image.LoadAsync({path}, {timeout.str()})");
TaskCompletionSource<Texture2D> taskCompletionSource = new TaskCompletionSource<Texture2D>();
((MonoBehaviour)LethalModUtils.Instance).StartCoroutine(LoadEnumerator(path, taskCompletionSource));
if (timeout.HasValue)
{
Task task = Task.Delay(timeout.Value);
if (Task.WhenAny(new Task[2] { taskCompletionSource.Task, task }) == task)
{
TimeoutException ex = new TimeoutException();
LethalModUtils.Logger.LogWarning((object)$"Error loading {path}: {ex.Message}");
throw ex;
}
}
return taskCompletionSource.Task;
}
private static IEnumerator LoadEnumerator(Uri path, TaskCompletionSource<Texture2D> task)
{
LethalModUtils.Logger.LogDebug((object)$">> Image.LoadEnumerator({path}, {task})");
UnityWebRequest webRequest = UnityWebRequestTexture.GetTexture(path);
yield return webRequest.SendWebRequest();
if ((int)webRequest.result != 1)
{
RequestError e2 = new RequestError(webRequest.error);
LethalModUtils.Logger.LogWarning((object)$"Error loading {path}: {e2.Message}");
task.SetException(e2);
yield break;
}
Texture2D texture2d = DownloadHandlerTexture.GetContent(webRequest);
if (texture2d == null)
{
TextureError e = new TextureError();
LethalModUtils.Logger.LogWarning((object)$"Error loading {path}: {e.Message}");
task.SetException(e);
}
else
{
LethalModUtils.Logger.LogInfo((object)$"Loaded {path}");
task.SetResult(texture2d);
}
}
public static async Task<Texture2D?> TryLoadAsync(Uri path, TimeSpan? timeout = null)
{
LethalModUtils.Logger.LogDebug((object)$">> Image.TryLoadAsync({path}, {timeout.str()})");
try
{
return await LoadAsync(path, timeout);
}
catch (Exception ex)
{
Exception e = ex;
LethalModUtils.Logger.LogDebug((object)$"<< Image.TryLoadAsync null ({e})");
}
return null;
}
public static Sprite Texture2DToSprite(Texture2D texture, bool centered = true)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
return Sprite.Create(texture, new Rect(0f, 0f, (float)((Texture)texture).width, (float)((Texture)texture).height), (Vector2)(centered ? new Vector2(0.5f, 0.5f) : Vector2.zero));
}
}
public static class Texture2DExtensions
{
public static Sprite ToSprite(this Texture2D texture, bool centered = true)
{
return Image.Texture2DToSprite(texture, centered);
}
}
[BepInPlugin("baer1.LethalModUtils", "LethalModUtils", "0.0.7")]
public class LethalModUtils : BaseUnityPlugin
{
private ConfigEntry<bool> preloadAudio = null;
public static LethalModUtils Instance { get; private set; }
internal static ManualLogSource Logger { get; private set; }
internal static Harmony? Harmony { get; set; }
public bool PreloadAudio { get; private set; }
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Instance = this;
InitConfig();
Patch();
Logger.LogInfo((object)"baer1.LethalModUtils v0.0.7 has loaded!");
void InitConfig()
{
preloadAudio = ((BaseUnityPlugin)this).Config.Bind<bool>("Audio", "PreloadAudio", true, "Whether to pre-load audio into RAM");
PreloadAudio = preloadAudio.Value;
}
static void Patch()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected O, but got Unknown
if (Harmony == null)
{
Harmony = new Harmony("baer1.LethalModUtils");
}
Logger.LogDebug((object)"Patching...");
Harmony.PatchAll();
Logger.LogDebug((object)"Finished patching!");
}
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "baer1.LethalModUtils";
public const string PLUGIN_NAME = "LethalModUtils";
public const string PLUGIN_VERSION = "0.0.7";
}
}