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.Versioning;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using ResourcefulHands.Patches;
using Steamworks;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ResourcefulHands")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+2dee743e64ed4212cfad31f9893a855adcf006bf")]
[assembly: AssemblyProduct("ResourcefulHands")]
[assembly: AssemblyTitle("ResourcefulHands")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 ResourcefulHands
{
public static class MiscUtils
{
private static int StartIndex;
public static string CleanString(string str)
{
char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
foreach (char c in invalidFileNameChars)
{
str = str.Replace(c.ToString(), "");
}
StringBuilder stringBuilder = new StringBuilder();
string text = str;
foreach (char c2 in text)
{
if (c2 <= '\u007f')
{
stringBuilder.Append(c2);
}
}
return stringBuilder.ToString();
}
public static void WriteString(this Stream stream, string value)
{
foreach (char c in value)
{
stream.WriteByte((byte)c);
}
}
public static void WriteInteger(this Stream stream, uint value)
{
stream.WriteByte((byte)(value & 0xFFu));
stream.WriteByte((byte)((value >> 8) & 0xFFu));
stream.WriteByte((byte)((value >> 16) & 0xFFu));
stream.WriteByte((byte)((value >> 24) & 0xFFu));
}
public static void WriteShort(this Stream stream, ushort value)
{
stream.WriteByte((byte)(value & 0xFFu));
stream.WriteByte((byte)((uint)(value >> 8) & 0xFFu));
}
public static RenderTexture ConvertToARGB32(this RenderTexture self)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
if ((int)self.format == 0)
{
return self;
}
RenderTexture temporary = RenderTexture.GetTemporary(((Texture)self).width, ((Texture)self).height, 0, (RenderTextureFormat)0);
Graphics.Blit((Texture)(object)self, temporary);
return temporary;
}
public static AudioClip CreateAudioClip(float[] samples, int sampleRate, int channels, string name = "GeneratedClip")
{
int num = samples.Length / channels;
AudioClip obj = AudioClip.Create(name, num, channels, sampleRate, true);
obj.SetData(samples, 0);
return obj;
}
public static string GetSHA256Checksum(string filePath)
{
using FileStream inputStream = File.OpenRead(filePath);
using SHA256 sHA = SHA256.Create();
byte[] array = sHA.ComputeHash(inputStream);
StringBuilder stringBuilder = new StringBuilder();
byte[] array2 = array;
foreach (byte b in array2)
{
stringBuilder.Append(b.ToString("x2"));
}
return stringBuilder.ToString();
}
public static void Start()
{
StartIndex = 0;
}
public static void End()
{
StartIndex = 0;
}
public static string MeshToString(this MeshFilter mf, Transform t)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//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_0058: 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_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: Unknown result type (might be due to invalid IL or missing references)
//IL_0150: Unknown result type (might be due to invalid IL or missing references)
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
_ = t.localScale;
_ = t.localPosition;
Quaternion localRotation = t.localRotation;
int num = 0;
Mesh sharedMesh = mf.sharedMesh;
if (!Object.op_Implicit((Object)(object)sharedMesh))
{
return "####Error####";
}
Material[] sharedMaterials = ((Component)mf).GetComponent<Renderer>().sharedMaterials;
StringBuilder stringBuilder = new StringBuilder();
Vector3[] vertices = sharedMesh.vertices;
foreach (Vector3 val in vertices)
{
Vector3 val2 = t.TransformPoint(val);
num++;
stringBuilder.Append($"v {val2.x} {val2.y} {0f - val2.z}\n");
}
stringBuilder.Append("\n");
vertices = sharedMesh.normals;
foreach (Vector3 val3 in vertices)
{
Vector3 val4 = localRotation * val3;
stringBuilder.Append($"vn {0f - val4.x} {0f - val4.y} {val4.z}\n");
}
stringBuilder.Append("\n");
Vector2[] uv = sharedMesh.uv;
for (int i = 0; i < uv.Length; i++)
{
Vector3 val5 = Vector2.op_Implicit(uv[i]);
stringBuilder.Append($"vt {val5.x} {val5.y}\n");
}
for (int j = 0; j < sharedMesh.subMeshCount; j++)
{
stringBuilder.Append("\n");
stringBuilder.Append("usemtl ").Append(((Object)sharedMaterials[j]).name).Append("\n");
stringBuilder.Append("usemap ").Append(((Object)sharedMaterials[j]).name).Append("\n");
int[] triangles = sharedMesh.GetTriangles(j);
for (int k = 0; k < triangles.Length; k += 3)
{
stringBuilder.Append(string.Format("f {0}/{0}/{0} {1}/{1}/{1} {2}/{2}/{2}\n", triangles[k] + 1 + StartIndex, triangles[k + 1] + 1 + StartIndex, triangles[k + 2] + 1 + StartIndex));
}
}
StartIndex += num;
return stringBuilder.ToString();
}
}
[BepInPlugin("triggeredidiot.wkd.resourcefulhands", "Resourceful Hands", "0.9.61")]
public class Plugin : BaseUnityPlugin
{
[CompilerGenerated]
private static class <>O
{
public static UnityAction <0>__ReloadPacks;
}
[Serializable]
[CompilerGenerated]
private sealed class <>c
{
public static readonly <>c <>9 = new <>c();
public static Func<UI_TabGroup, bool> <>9__27_0;
public static UnityAction <>9__27_1;
public static Action <>9__31_1;
internal bool <LoadCustomSettings>b__27_0(UI_TabGroup tabGroup)
{
return ((Object)tabGroup).name.ToLower() == "tab selection hor";
}
internal void <LoadCustomSettings>b__27_1()
{
Application.OpenURL("file://" + ConfigFolder.Replace("\\", "/"));
}
internal void <Awake>b__31_1()
{
SpriteRenderer[] array = Object.FindObjectsByType<SpriteRenderer>((FindObjectsSortMode)0);
foreach (SpriteRenderer obj in array)
{
obj.sprite = obj.sprite;
}
}
}
[CompilerGenerated]
private sealed class <>c__DisplayClass27_0
{
public UI_TabGroup tabGroup;
internal void <LoadCustomSettings>b__2()
{
tabGroup.SelectTab("packs");
}
}
[CompilerGenerated]
private sealed class <LoadCustomSettings>d__27 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public UI_SettingsMenu settingsMenu;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <LoadCustomSettings>d__27(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected O, but got Unknown
//IL_014b: Unknown result type (might be due to invalid IL or missing references)
//IL_0150: Unknown result type (might be due to invalid IL or missing references)
//IL_0156: Expected O, but got Unknown
//IL_018a: Unknown result type (might be due to invalid IL or missing references)
//IL_018f: Unknown result type (might be due to invalid IL or missing references)
//IL_0195: Expected O, but got Unknown
//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0300: Unknown result type (might be due to invalid IL or missing references)
//IL_0307: Unknown result type (might be due to invalid IL or missing references)
//IL_0312: Unknown result type (might be due to invalid IL or missing references)
//IL_031c: Expected O, but got Unknown
//IL_0329: Unknown result type (might be due to invalid IL or missing references)
//IL_0333: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSecondsRealtime(1f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
RHLog.Info("Loading custom settings menu...", 123, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Plugin.cs");
if ((Object)(object)Assets == (Object)null)
{
RHLog.Warning("No assets?", 126, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Plugin.cs");
return false;
}
try
{
<>c__DisplayClass27_0 CS$<>8__locals0 = new <>c__DisplayClass27_0();
RHLog.Info("so like assets loadde yaya", 131, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Plugin.cs");
UI_TabGroup[] componentsInChildren = ((Component)settingsMenu).GetComponentsInChildren<UI_TabGroup>();
CS$<>8__locals0.tabGroup = ((IEnumerable<UI_TabGroup>)componentsInChildren).FirstOrDefault((Func<UI_TabGroup, bool>)((UI_TabGroup tabGroup) => ((Object)tabGroup).name.ToLower() == "tab selection hor"));
if ((Object)(object)CS$<>8__locals0.tabGroup != (Object)null)
{
GameObject obj = Object.Instantiate<GameObject>(Assets.LoadAsset<GameObject>("Packs"), ((Component)CS$<>8__locals0.tabGroup).transform, false);
Button componentInChildren = obj.GetComponentInChildren<Button>();
TextMeshProUGUI componentInChildren2 = obj.GetComponentInChildren<TextMeshProUGUI>();
GameObject val = Object.Instantiate<GameObject>(Assets.LoadAsset<GameObject>("Pack Settings"), ((Component)CS$<>8__locals0.tabGroup).transform.parent, false);
ButtonClickedEvent onClick = ((Component)val.transform.Find("Reload")).GetComponentInChildren<Button>().onClick;
object obj2 = <>O.<0>__ReloadPacks;
if (obj2 == null)
{
UnityAction val2 = ResourcePacksManager.ReloadPacks;
<>O.<0>__ReloadPacks = val2;
obj2 = (object)val2;
}
((UnityEvent)onClick).AddListener((UnityAction)obj2);
ButtonClickedEvent onClick2 = ((Component)val.transform.Find("OpenFolder")).GetComponentInChildren<Button>().onClick;
object obj3 = <>c.<>9__27_1;
if (obj3 == null)
{
UnityAction val3 = delegate
{
Application.OpenURL("file://" + ConfigFolder.Replace("\\", "/"));
};
<>c.<>9__27_1 = val3;
obj3 = (object)val3;
}
((UnityEvent)onClick2).AddListener((UnityAction)obj3);
val.AddComponent<UI_RHPacksList>();
val.SetActive(false);
for (int i = 0; i < ((Component)CS$<>8__locals0.tabGroup).transform.childCount; i++)
{
Transform child = ((Component)CS$<>8__locals0.tabGroup).transform.GetChild(i);
string text = ((Object)child).name.ToLower();
if (text.StartsWith("lb") || text.StartsWith("rb"))
{
((Component)child).gameObject.SetActive(false);
}
}
Tab val4 = CS$<>8__locals0.tabGroup.tabs.FirstOrDefault();
if (val4 != null)
{
((TMP_Text)componentInChildren2).font = ((TMP_Text)((Component)val4.button).GetComponentInChildren<TextMeshProUGUI>()).font;
for (int j = 0; j < val4.tabObject.transform.childCount; j++)
{
Transform child2 = val4.tabObject.transform.GetChild(j);
if (((Object)child2).name.ToLower().Contains("title") && Object.op_Implicit((Object)(object)((Component)child2).GetComponentInChildren<TextMeshProUGUI>()))
{
TextMeshProUGUI componentInChildren3 = Object.Instantiate<GameObject>(((Component)child2).gameObject, val.transform, true).GetComponentInChildren<TextMeshProUGUI>();
((TMP_Text)componentInChildren3).text = "PACKS";
TextMeshProUGUI[] componentsInChildren2 = val.GetComponentsInChildren<TextMeshProUGUI>(true);
for (int k = 0; k < componentsInChildren2.Length; k++)
{
((TMP_Text)componentsInChildren2[k]).font = ((TMP_Text)componentInChildren3).font;
}
}
}
}
Tab item = new Tab
{
button = componentInChildren,
name = "packs",
tabObject = val
};
((UnityEvent)componentInChildren.onClick).AddListener((UnityAction)delegate
{
CS$<>8__locals0.tabGroup.SelectTab("packs");
});
CS$<>8__locals0.tabGroup.tabs.Add(item);
}
}
catch (Exception ex)
{
RHLog.Error("Failed to load custom settings menu:\n" + ex.ToString(), 198, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Plugin.cs");
}
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();
}
}
public const string GUID = "triggeredidiot.wkd.resourcefulhands";
public const string ModifiedStr = " [modified asset]";
private static AssetBundle? _assets;
public static Texture2D? CorruptionTexture;
public static Texture2D? Icon;
public static Texture2D? IconGray;
internal static int mainThreadId;
public static AssetBundle? Assets
{
get
{
if ((Object)(object)_assets != (Object)null)
{
return _assets;
}
Assembly executingAssembly = Assembly.GetExecutingAssembly();
string name = "ResourcefulHands.rh_assets.bundle";
using Stream stream = executingAssembly.GetManifestResourceStream(name);
if (stream != null)
{
_assets = AssetBundle.LoadFromStream(stream);
}
AssetBundle? assets = _assets;
CorruptionTexture = ((assets != null) ? assets.LoadAsset<Texture2D>("Corruption1") : null);
AssetBundle? assets2 = _assets;
Icon = ((assets2 != null) ? assets2.LoadAsset<Texture2D>("icon") : null);
AssetBundle? assets3 = _assets;
IconGray = ((assets3 != null) ? assets3.LoadAsset<Texture2D>("gray_icon") : null);
return _assets;
}
private set
{
_assets = value;
}
}
public static Plugin Instance { get; private set; }
internal static ManualLogSource Log { get; private set; }
public static string ConfigFolder => Path.Combine(Paths.ConfigPath, "RHPacks");
public static bool IsDemo
{
get
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
try
{
if (SteamClient.AppId.Value == 3218540)
{
return true;
}
}
catch (Exception data)
{
RHLog.Error(data, 68, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Plugin.cs");
}
return false;
}
}
public Harmony? Harmony { get; private set; }
public static bool IsMainThread => Thread.CurrentThread.ManagedThreadId == mainThreadId;
internal static void RefreshTextures()
{
SpriteRendererPatches._customSpriteCache.Clear();
List<Material> allMaterials = Resources.FindObjectsOfTypeAll<Material>().ToList();
Renderer[] array = Object.FindObjectsOfType<Renderer>(true);
foreach (Renderer val in array)
{
allMaterials.AddRange(val.sharedMaterials.Where((Material mat) => !allMaterials.Contains(mat)));
}
int num = Shader.PropertyToID("_MainTex");
int num2 = Shader.PropertyToID("_CORRUPTTEXTURE");
Texture2D textureFromPacks = ResourcePacksManager.GetTextureFromPacks("_CORRUPTTEXTURE");
foreach (Material item in allMaterials)
{
if ((Object)(object)item != (Object)null)
{
if (item.HasTexture(num))
{
item.mainTexture = item.mainTexture;
}
try
{
item.SetTexture(num2, (Texture)(object)textureFromPacks);
}
catch (Exception data)
{
RHLog.Error(data, 100, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Plugin.cs");
}
}
}
SpriteRenderer[] array2 = Object.FindObjectsOfType<SpriteRenderer>(true);
foreach (SpriteRenderer obj in array2)
{
obj.sprite = obj.sprite;
}
}
internal static void RefreshSounds()
{
foreach (AudioSource item in Resources.FindObjectsOfTypeAll<AudioSource>().ToList())
{
item.clip = item.clip;
}
AudioSource[] array = Object.FindObjectsOfType<AudioSource>(true);
foreach (AudioSource obj in array)
{
obj.clip = obj.clip;
}
}
[IteratorStateMachine(typeof(<LoadCustomSettings>d__27))]
private IEnumerator LoadCustomSettings(UI_SettingsMenu settingsMenu)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <LoadCustomSettings>d__27(0)
{
settingsMenu = settingsMenu
};
}
public void Awake()
{
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Expected O, but got Unknown
mainThreadId = Thread.CurrentThread.ManagedThreadId;
Log = ((BaseUnityPlugin)this).Logger;
Instance = this;
RHLog.Info("Setting up config", 210, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Plugin.cs");
if (!Directory.Exists(ConfigFolder))
{
Directory.CreateDirectory(ConfigFolder);
}
RHConfig.BindConfigs();
Harmony = new Harmony("triggeredidiot.wkd.resourcefulhands");
Harmony.PatchAll();
bool hasLoadedIntro = false;
SceneManager.sceneLoaded += delegate(Scene scene, LoadSceneMode mode)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
if (!((Scene)(ref scene)).name.ToLower().Contains("intro") && !hasLoadedIntro)
{
hasLoadedIntro = true;
RHLog.Info("Loading internal assets...", 224, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Plugin.cs");
AssetBundle? assets = Assets;
if (assets != null)
{
assets.LoadAllAssets();
}
CoroutineDispatcher.AddToUpdate(delegate
{
SpriteRenderer[] array = Object.FindObjectsByType<SpriteRenderer>((FindObjectsSortMode)0);
foreach (SpriteRenderer obj in array)
{
obj.sprite = obj.sprite;
}
});
RHLog.Info("Loading debug tools...", 234, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Plugin.cs");
DebugTools.Create();
}
if (hasLoadedIntro)
{
RHLog.Info("Checking packs state...", 241, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Plugin.cs");
if (ResourcePacksManager.HasPacksChanged)
{
ResourcePacksManager.ReloadPacks();
}
RHLog.Info("Refreshing custom commands...", 245, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Plugin.cs");
RHCommands.RefreshCommands();
RHLog.Info("Loading settings menu...", 248, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Plugin.cs");
UI_SettingsMenu val = ((IEnumerable<UI_SettingsMenu>)Object.FindObjectsOfType<UI_SettingsMenu>(true)).FirstOrDefault((Func<UI_SettingsMenu, bool>)((UI_SettingsMenu m) => ((Component)m).gameObject.scene == scene));
if (Object.op_Implicit((Object)(object)val) && (Object)(object)Assets != (Object)null)
{
CoroutineDispatcher.Dispatch(LoadCustomSettings(val));
}
RHLog.Info("Refreshing assets...", 255, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Plugin.cs");
RefreshTextures();
RefreshSounds();
}
};
RHLog.Info("Resourceful Hands has loaded!", 260, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Plugin.cs");
}
}
public static class RHCommands
{
public const string DumpCommand = "dumptopack";
public const string ReloadCommand = "reloadpacks";
public const string MoveCommand = "reorderpack";
public const string ListCommand = "listpacks";
public const string EnableCommand = "enablepack";
public const string DisableCommand = "disablepack";
public const string ToggleDebug = "rhtoggledebug";
public static void RefreshCommands()
{
CommandConsole instance = CommandConsole.instance;
if (Object.op_Implicit((Object)(object)instance))
{
CommandConsole.RemoveCommand("dumptopack");
CommandConsole.RemoveCommand("reloadpacks");
CommandConsole.RemoveCommand("reorderpack");
CommandConsole.RemoveCommand("listpacks");
CommandConsole.RemoveCommand("enablepack");
CommandConsole.RemoveCommand("disablepack");
CommandConsole.RemoveCommand("rhtoggledebug");
instance.RegisterCommand("dumptopack", (Action<string[]>)DumpAllToPack, false);
instance.RegisterCommand("reloadpacks", (Action<string[]>)ReloadPacks, false);
instance.RegisterCommand("reorderpack", (Action<string[]>)MovePacks, false);
instance.RegisterCommand("listpacks", (Action<string[]>)ListPacks, false);
instance.RegisterCommand("enablepack", (Action<string[]>)EnablePack, false);
instance.RegisterCommand("disablepack", (Action<string[]>)DisablePack, false);
instance.RegisterCommand("rhtoggledebug", (Action<string[]>)delegate
{
DebugTools.isOn = !DebugTools.isOn;
}, false);
}
}
internal static void MovePack(TexturePack pack, bool isUp)
{
TexturePack pack2 = pack;
int num = ResourcePacksManager.LoadedPacks.FindIndex((TexturePack p) => p == pack2);
int num2 = 0;
num2 = (isUp ? Math.Clamp(num - 1, 0, ResourcePacksManager.LoadedPacks.Count - 1) : Math.Clamp(num + 1, 0, ResourcePacksManager.LoadedPacks.Count - 1));
try
{
TexturePack texturePack = ResourcePacksManager.LoadedPacks[num2];
TexturePack texturePack2 = ResourcePacksManager.LoadedPacks[num];
texturePack.GetHashCode();
texturePack2.GetHashCode();
}
catch (ArgumentOutOfRangeException)
{
RHLog.Warning("Failed to move packs!", 62, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\Commands.cs");
return;
}
TexturePack value = ResourcePacksManager.LoadedPacks[num2];
ResourcePacksManager.LoadedPacks[num2] = pack2;
ResourcePacksManager.LoadedPacks[num] = value;
}
private static void MovePacks(string[] args)
{
if (args.Length != 2)
{
RHLog.Player.Error("Invalid number of arguments!");
RHLog.Player.Info("Usage: reorderpack [pack guid/pack index] [up/down]\nResource packs at the bottom of the loaded list will override textures at the top, use this command to move a texture pack up or down the list.");
return;
}
TexturePack texturePack = null;
if (int.TryParse(args[0], out var result))
{
try
{
texturePack = ResourcePacksManager.LoadedPacks[result];
}
catch
{
}
if (texturePack == null)
{
RHLog.Player.Error($"Invalid first argument!\nThe resource pack at index {result} doesn't exist!");
RHLog.Player.Info("Usage: reorderpack [pack guid/pack index] [up/down]\nResource packs at the bottom of the loaded list will override textures at the top, use this command to move a texture pack up or down the list.");
return;
}
}
else
{
string packName = args[0].ToLower();
texturePack = ResourcePacksManager.LoadedPacks.FirstOrDefault((TexturePack p) => p.guid == packName);
if (texturePack == null)
{
RHLog.Player.Error("Invalid first argument!\nThe resource pack with guid '" + packName + "' doesn't exist!");
RHLog.Player.Info("Usage: reorderpack [pack guid/pack index] [up/down]\nResource packs at the bottom of the loaded list will override textures at the top, use this command to move a texture pack up or down the list.");
return;
}
}
string text = args[1].ToLower();
bool flag;
switch (text)
{
case "up":
case "down":
case "u":
case "d":
flag = true;
break;
default:
flag = false;
break;
}
if (!flag)
{
RHLog.Player.Error("Invalid second argument!\nExpected: up or down");
RHLog.Player.Info("Usage: reorderpack [pack guid/pack index] [up/down]\nResource packs at the bottom of the loaded list will override textures at the top, use this command to move a texture pack up or down the list.");
return;
}
flag = ((text == "up" || text == "u") ? true : false);
bool flag2 = flag;
MovePack(texturePack, flag2);
RHLog.Player.Info("Reloading packs...");
ResourcePacksManager.ReloadPacks();
RHLog.Player.Info(string.Format("Moved {0} {1}{2}{3} {4} successfully!", texturePack.name, '{', texturePack.guid, '}', flag2 ? "up" : "down"));
}
private static void ListPacks(string[] args)
{
for (int i = 0; i < ResourcePacksManager.LoadedPacks.Count; i++)
{
TexturePack texturePack = ResourcePacksManager.LoadedPacks[i];
RHLog.Player.Info(((!texturePack.IsActive) ? "[DISABLED] " : $"[{i}] ") + texturePack.name + " by " + texturePack.author + "\n-- description:\n" + texturePack.desc + "\n-- guid: '" + texturePack.guid + "'\n____");
}
}
private static void ReloadPacks(string[] args)
{
ResourcePacksManager.ReloadPacks();
RHLog.Player.Info("Resource packs reloaded successfully!");
}
private static TexturePack? GetPackFromArgs(string[] args, Action<string> logErr)
{
TexturePack texturePack = null;
if (int.TryParse(args[0], out var result))
{
try
{
texturePack = ResourcePacksManager.LoadedPacks[result];
}
catch
{
}
if (texturePack == null)
{
logErr($"Invalid first argument!\nThe resource pack at index {result} doesn't exist!");
return null;
}
}
else
{
string packName = args[0].ToLower();
texturePack = ResourcePacksManager.LoadedPacks.FirstOrDefault((TexturePack p) => p.guid.ToLower() == packName);
if (texturePack == null)
{
logErr("Invalid first argument!\nThe resource pack with guid '" + packName + "' doesn't exist!");
return null;
}
}
return texturePack;
}
private static void DisablePack(string[] args)
{
TexturePack packFromArgs = GetPackFromArgs(args, RHLog.Player.Error);
if (packFromArgs == null)
{
RHLog.Player.Info("Usage: disablepack [pack guid/pack index]\nDisables a resource pack.");
return;
}
packFromArgs.IsActive = false;
RHLog.Player.Info("Reloading packs...");
ResourcePacksManager.ReloadPacks();
RHLog.Player.Info($"Disabled {packFromArgs.name} {'{'}{packFromArgs.guid}{'}'} successfully!");
}
private static void EnablePack(string[] args)
{
TexturePack packFromArgs = GetPackFromArgs(args, RHLog.Player.Error);
if (packFromArgs == null)
{
RHLog.Player.Info("Usage: enablepack [pack guid/pack index]\nEnables a resource pack.");
return;
}
packFromArgs.IsActive = true;
RHLog.Player.Info("Reloading packs...");
ResourcePacksManager.ReloadPacks();
RHLog.Player.Info($"Enabled {packFromArgs.name} {'{'}{packFromArgs.guid}{'}'} successfully!");
}
private static void DumpAllToPack(string[] args)
{
if (args.Any((string arg) => arg.ToLower() == "help"))
{
RHLog.Player.Info("Use this command to generate a resource pack that contains every in-game asset. Good to find assets to replace but beware that there will probably be unused assets!");
return;
}
if (!args.Any((string arg) => arg.ToLower() == "confirm"))
{
RHLog.Player.Error("Warning: This takes up alot of storage space due to uncompressed audio!\nTHIS WILL ALSO END YOUR RUN AND LOAD YOU BACK TO THE MAIN MENU!!\nARE YOU SURE? (type 'dumptopack confirm')");
return;
}
RHLog.Player.Info("Dumping all resources to a template texture pack [this will take some time]...");
List<Texture2D> textures = new List<Texture2D>();
List<Texture2D> spriteTextures = new List<Texture2D>();
List<AudioClip> sounds = new List<AudioClip>();
Texture2D[] source = Resources.FindObjectsOfTypeAll<Texture2D>();
textures.AddRange(source.Where((Texture2D tex) => !textures.Contains(tex)));
AudioClip[] source2 = Resources.FindObjectsOfTypeAll<AudioClip>();
sounds.AddRange(source2.Where((AudioClip sound) => !sounds.Contains(sound)));
Sprite[] source3 = Resources.FindObjectsOfTypeAll<Sprite>();
spriteTextures.AddRange(from sprite in source3
where Object.op_Implicit((Object)(object)sprite.texture) && !spriteTextures.Contains(sprite.texture)
select sprite.texture);
RHLog.Player.Info("Loading Playground [to extract assets]");
SceneManager.LoadScene("Playground");
source = Resources.FindObjectsOfTypeAll<Texture2D>();
textures.AddRange(source.Where((Texture2D tex) => !textures.Contains(tex)));
source2 = Resources.FindObjectsOfTypeAll<AudioClip>();
sounds.AddRange(source2.Where((AudioClip sound) => !sounds.Contains(sound)));
source3 = Resources.FindObjectsOfTypeAll<Sprite>();
spriteTextures.AddRange(from sprite in source3
where Object.op_Implicit((Object)(object)sprite.texture) && !spriteTextures.Contains(sprite.texture)
select sprite.texture);
RHLog.Player.Info("Loading Training-Level [to extract assets]");
SceneManager.LoadScene("Training-Level");
source = Resources.FindObjectsOfTypeAll<Texture2D>();
textures.AddRange(source.Where((Texture2D tex) => !textures.Contains(tex)));
source2 = Resources.FindObjectsOfTypeAll<AudioClip>();
sounds.AddRange(source2.Where((AudioClip sound) => !sounds.Contains(sound)));
source3 = Resources.FindObjectsOfTypeAll<Sprite>();
spriteTextures.AddRange(from sprite in source3
where Object.op_Implicit((Object)(object)sprite.texture) && !spriteTextures.Contains(sprite.texture)
select sprite.texture);
RHLog.Player.Info("Loading Main-Menu [to extract assets and finish]");
SceneManager.LoadScene("Main-Menu");
source = Resources.FindObjectsOfTypeAll<Texture2D>();
textures.AddRange(source.Where((Texture2D tex) => !textures.Contains(tex)));
source2 = Resources.FindObjectsOfTypeAll<AudioClip>();
sounds.AddRange(source2.Where((AudioClip sound) => !sounds.Contains(sound)));
source3 = Resources.FindObjectsOfTypeAll<Sprite>();
spriteTextures.AddRange(from sprite in source3
where Object.op_Implicit((Object)(object)sprite.texture) && !spriteTextures.Contains(sprite.texture)
select sprite.texture);
RHLog.Player.Info("Packing assets...");
int count = textures.Count;
int count2 = spriteTextures.Count;
int count3 = sounds.Count;
string text = Path.Combine(Plugin.ConfigFolder, $"extracted-assets-{count + count3 + count2}-{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}");
if (!Directory.Exists(text))
{
Directory.CreateDirectory(text);
}
string texturesPath = Path.Combine(text, "Textures");
string path = Path.Combine(texturesPath, "Sprites");
string text2 = Path.Combine(text, "Sounds");
if (!Directory.Exists(texturesPath))
{
Directory.CreateDirectory(texturesPath);
}
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
if (!Directory.Exists(text2))
{
Directory.CreateDirectory(text2);
}
StringBuilder stringBuilder = new StringBuilder();
StringBuilder stringBuilder2 = new StringBuilder();
StringBuilder stringBuilder3 = new StringBuilder();
stringBuilder.AppendLine("-- ingame textures list --");
stringBuilder2.AppendLine("-- ingame sprite textures list --");
stringBuilder3.AppendLine("-- ingame sounds list --");
int num = 0;
int num2 = 0;
int num3 = 0;
for (int i = 0; i < count; i++)
{
Texture2D val = textures[i];
RHLog.Player.Info($"Saving textures ({i}/{count})");
stringBuilder.Append(((Object)val).name);
bool flag = false;
try
{
flag = ExportTexture(val);
}
catch (Exception ex)
{
RHLog.Player.Error(((Object)val).name + " failed because " + ex.Message);
}
if (flag)
{
num++;
}
stringBuilder.AppendLine(flag ? "" : " [failed to extract]");
}
for (int j = 0; j < count2; j++)
{
Texture2D val2 = spriteTextures[j];
RHLog.Player.Info($"Saving textures ({j}/{count2})");
stringBuilder2.Append(((Object)val2).name);
bool flag2 = false;
try
{
flag2 = ExportTexture(val2);
}
catch (Exception ex2)
{
RHLog.Player.Error(((Object)val2).name + " failed because " + ex2.Message);
}
if (flag2)
{
num3++;
}
stringBuilder2.AppendLine(flag2 ? "" : " [failed to extract]");
}
for (int k = 0; k < count3; k++)
{
AudioClip val3 = sounds[k];
RHLog.Player.Info($"Saving sounds ({k}/{count3})");
stringBuilder3.Append(((Object)val3).name);
bool flag3 = false;
try
{
string path2 = Path.Combine(text2, ((Object)val3).name + ".wav");
float[] array = new float[val3.samples * val3.channels];
if (!val3.GetData(array, 0))
{
RHLog.Player.Error("Failed to access " + ((Object)val3).name + "'s audio data!");
stringBuilder3.AppendLine(" [failed to extract]");
continue;
}
using (FileStream stream = new FileStream(path2, FileMode.CreateNew, FileAccess.Write))
{
ushort num4 = 16;
string value = "RIFF";
string value2 = "WAVE";
string value3 = "fmt ";
uint value4 = 16u;
ushort value5 = 1;
ushort num5 = (ushort)val3.channels;
uint frequency = (uint)val3.frequency;
uint value6 = (uint)(frequency * val3.channels * num4 / 8);
ushort value7 = (ushort)(num5 * num4 / 8);
string value8 = "data";
uint num6 = (uint)(array.Length * val3.channels * num4 / 8);
uint value9 = 36 + num6;
stream.WriteString(value);
stream.WriteInteger(value9);
stream.WriteString(value2);
stream.WriteString(value3);
stream.WriteInteger(value4);
stream.WriteShort(value5);
stream.WriteShort(num5);
stream.WriteInteger(frequency);
stream.WriteInteger(value6);
stream.WriteShort(value7);
stream.WriteShort(num4);
stream.WriteString(value8);
stream.WriteInteger(num6);
float[] array2 = array;
foreach (float num7 in array2)
{
short num8 = 0;
if (num7 > 0f)
{
float num9 = num7 * 32767f;
if (num9 > 32767f)
{
num9 = 32767f;
}
num8 = (short)num9;
}
if (num7 < 0f)
{
float num10 = num7 * 32768f;
if (num10 < -32768f)
{
num10 = -32768f;
}
num8 = (short)num10;
}
stream.WriteShort((ushort)num8);
}
num2++;
flag3 = true;
}
goto IL_07d9;
}
catch (Exception ex3)
{
RHLog.Player.Info(((Object)val3).name + " failed because " + ex3.Message);
goto IL_07d9;
}
IL_07d9:
stringBuilder3.AppendLine(flag3 ? "" : " [failed to extract]");
}
RHLog.Player.Info("Writing data files");
File.WriteAllText(Path.Combine(text, "info.json"), "{\r\n \"name\":\"generated-game-assets\",\r\n \"desc\":\"Every game asset\",\r\n \r\n \"author\":\"Dark Machine Games\",\r\n \"steamid\":0,\r\n \r\n \"guid\":\"generated-game-assets\",\r\n \r\n \"hidden-from-list\":true,\r\n \"only-in-full-game\":false,\r\n \r\n \"textures-folder\":\"Textures\",\r\n \"sounds-folder\":\"Sounds\",\r\n \"icon-file\":\"pack.png\",\r\n \r\n \"format-version\":2\r\n} ");
File.WriteAllText(Path.Combine(text, "textures_list.txt"), stringBuilder.ToString());
File.WriteAllText(Path.Combine(text, "sprite_textures_list.txt"), stringBuilder2.ToString());
File.WriteAllText(Path.Combine(text, "audio_list.txt"), stringBuilder3.ToString());
RHLog.Player.Info($"Successfully saved {num} of {count} textures!");
RHLog.Player.Info($"Successfully saved {num3} of {count2} sprite textures!");
RHLog.Player.Info($"Successfully saved {num2} of {count3} sounds!");
RHLog.Player.Info("Packed all assets to '" + text + "'");
bool ExportTexture(Texture2D texture)
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Expected O, but got Unknown
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Expected O, but got Unknown
bool result = false;
try
{
if (!((Texture)texture).isReadable)
{
RHLog.Player.Info(((Object)texture).name + " isn't readable, saving the slow way...");
RenderTexture val4 = new RenderTexture(((Texture)texture).width, ((Texture)texture).height, 24);
RenderTexture active = RenderTexture.active;
try
{
RenderTexture.active = val4;
Graphics.Blit((Texture)(object)texture, val4);
RenderTexture val6 = (RenderTexture.active = val4.ConvertToARGB32());
Texture2D val7 = new Texture2D(((Texture)texture).width, ((Texture)texture).height, texture.format, false);
val7.ReadPixels(new Rect(0f, 0f, (float)((Texture)texture).width, (float)((Texture)texture).height), 0, 0);
val7.Apply();
val6.Release();
byte[] bytes = ImageConversion.EncodeToPNG(val7);
File.WriteAllBytes(Path.Combine(texturesPath, ((Object)texture).name + ".png"), bytes);
result = true;
}
catch
{
}
RenderTexture.active = active;
val4.Release();
}
else
{
byte[] bytes2 = ImageConversion.EncodeToPNG(texture);
File.WriteAllBytes(Path.Combine(texturesPath, ((Object)texture).name + ".png"), bytes2);
result = true;
}
}
catch (Exception ex4)
{
RHLog.Player.Error(((Object)texture).name + " failed because " + ex4.Message);
}
return result;
}
}
}
public static class RHConfig
{
internal static ConfigEntry<bool>? AlwaysDebug;
internal static ConfigEntry<bool>? LazyManip;
internal static void BindConfigs()
{
AlwaysDebug = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("General", "Always debug mode", false, "When enabled pack debug mode is always enabled unless toggled via the command (rhtoggledebug).");
LazyManip = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("General", "Lazy Loading", true, "When enabled every pack doesn't get reloaded when reordering or enabling/disabling packs in the settings menu.");
}
}
public class CoroutineDispatcher : MonoBehaviour
{
private static CoroutineDispatcher? _instance;
private static Dictionary<string, Action> updateActions = new Dictionary<string, Action>();
public static Queue<Action> threadQueue = new Queue<Action>();
public static void Dispatch(IEnumerator routine)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)_instance == (Object)null)
{
_instance = new GameObject("CoroutineDispatcher").AddComponent<CoroutineDispatcher>();
Object.DontDestroyOnLoad((Object)(object)_instance);
}
((MonoBehaviour)_instance).StartCoroutine(routine);
}
public static async Task RunOnMainThreadAndWait(Action action, [CallerLineNumber] int lineNumber = 0, [CallerFilePath] string file = "")
{
Action action2 = action;
bool hasRan = false;
threadQueue.Enqueue(delegate
{
try
{
action2();
}
catch (Exception data)
{
RHLog.Error(data, 45, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\CoroutineDispatcher.cs");
}
hasRan = true;
});
while (!hasRan)
{
await Task.Delay(16);
}
}
public static void RunOnMainThread(Action action)
{
threadQueue.Enqueue(action);
}
public static void RunOnMainThreadOrCurrent(Action action)
{
if (Plugin.IsMainThread)
{
action();
}
else
{
threadQueue.Enqueue(action);
}
}
public static string AddToUpdate(Action action)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)_instance == (Object)null)
{
_instance = new GameObject("CoroutineDispatcher").AddComponent<CoroutineDispatcher>();
Object.DontDestroyOnLoad((Object)(object)_instance);
}
string text = Guid.NewGuid().ToString();
updateActions.Add(text, action);
return text;
}
public static void RemoveFromUpdate(string guid)
{
if (updateActions.ContainsKey(guid))
{
updateActions.Remove(guid);
}
}
public void LateUpdate()
{
foreach (Action value in updateActions.Values)
{
value();
}
while (threadQueue.Count > 0)
{
threadQueue.Dequeue()?.Invoke();
}
}
}
public class DebugTools : MonoBehaviour
{
[CompilerGenerated]
private sealed class <_queueSound>d__7 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public bool force;
public AudioClip clip;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <_queueSound>d__7(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
if (!force && _playingClips.Contains(clip))
{
return false;
}
_playingClips.Add(clip);
<>2__current = (object)new WaitForSeconds(1f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
if (Object.op_Implicit((Object)(object)clip))
{
_playingClips.Remove(clip);
}
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();
}
}
public static DebugTools? Instance;
public static bool isOn = false;
private static List<AudioClip> _playingClips = new List<AudioClip>();
private GUIStyle _style = GUIStyle.none;
private bool _enableNextFrame;
internal static void Create()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
Instance = new GameObject("DebugTools").AddComponent<DebugTools>();
Object.DontDestroyOnLoad((Object)(object)Instance);
}
public static void QueueSound(AudioClip clip, bool force = false)
{
CoroutineDispatcher.Dispatch(_queueSound(clip, force));
}
[IteratorStateMachine(typeof(<_queueSound>d__7))]
private static IEnumerator _queueSound(AudioClip clip, bool force)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <_queueSound>d__7(0)
{
clip = clip,
force = force
};
}
public void Awake()
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Expected O, but got Unknown
//IL_004f: Expected O, but got Unknown
Instance = this;
ConfigEntry<bool>? alwaysDebug = RHConfig.AlwaysDebug;
if (alwaysDebug != null && alwaysDebug.Value)
{
isOn = true;
}
_style = new GUIStyle
{
fontSize = 32,
fontStyle = (FontStyle)1,
normal = new GUIStyleState
{
textColor = Color.white
}
};
SceneManager.sceneUnloaded += delegate
{
_enableNextFrame |= isOn;
isOn = false;
};
SceneManager.sceneLoaded += delegate(Scene arg0, LoadSceneMode mode)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
if ((int)mode == 0)
{
_playingClips.Clear();
_enableNextFrame |= isOn;
isOn = false;
}
};
}
public void OnGUI()
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
if (!isOn)
{
return;
}
Color contentColor = GUI.contentColor;
GUI.contentColor = Color.white;
GUILayout.Label("Recent sounds:", _style, Array.Empty<GUILayoutOption>());
foreach (AudioClip playingClip in _playingClips)
{
GUILayout.Label(((Object)playingClip).name, _style, Array.Empty<GUILayoutOption>());
}
GUI.contentColor = contentColor;
}
public void LateUpdate()
{
if (_enableNextFrame)
{
isOn = true;
_enableNextFrame = false;
}
}
}
[HarmonyPatch(typeof(AudioSource))]
[HarmonyPriority(200)]
public static class DEBUG_AudioSourcePatches
{
[HarmonyPatch("set_clip")]
[HarmonyPostfix]
private static void Setter_Postfix(AudioSource __instance, ref AudioClip value)
{
if (DebugTools.isOn && !((Object)(object)value == (Object)null) && (__instance.isPlaying || (__instance.playOnAwake && Time.timeSinceLevelLoad <= 0.25f)))
{
DebugTools.QueueSound(value);
}
}
[HarmonyPatch("get_clip")]
[HarmonyPostfix]
private static void Getter_Postfix(AudioSource __instance, ref AudioClip __result)
{
if (DebugTools.isOn && !((Object)(object)__result == (Object)null) && (__instance.isPlaying || (__instance.playOnAwake && Time.timeSinceLevelLoad <= 0.25f)))
{
DebugTools.QueueSound(__result);
}
}
[HarmonyPatch("Play", new Type[] { typeof(double) })]
[HarmonyPostfix]
private static void Play_Prefix(AudioSource __instance, double delay)
{
if (DebugTools.isOn && !((Object)(object)__instance.clip == (Object)null))
{
DebugTools.QueueSound(__instance.clip);
}
}
[HarmonyPatch("PlayHelper", new Type[]
{
typeof(AudioSource),
typeof(ulong)
})]
[HarmonyPostfix]
private static void PlayHelper_Prefix(AudioSource source, ulong delay)
{
if (DebugTools.isOn && !((Object)(object)source.clip == (Object)null))
{
DebugTools.QueueSound(source.clip);
}
}
}
public static class RHLog
{
public static class Player
{
public static void Message(string message, bool printToConsole = true)
{
CommandConsole.Log("[Resourceful Hands] " + message, printToConsole);
}
public static void Info(string message, bool printToConsole = true)
{
Message(message, printToConsole);
}
public static void Warning(string message, bool printToConsole = true)
{
CommandConsole.Log("[Resourceful Hands] [WARNING] " + message, printToConsole);
}
public static void Error(string message)
{
CommandConsole.LogError("[Resourceful Hands] " + message);
}
}
private const string Prefix = "[Resourceful Hands] ";
[Conditional("DEBUG")]
public static void Debug(object data, [CallerLineNumber] int lineNumber = 0, [CallerFilePath] string file = "")
{
string file2 = file;
object data2 = data;
CoroutineDispatcher.RunOnMainThreadOrCurrent(delegate
{
Plugin.Log.LogDebug((object)$"[{Path.GetFileName(file2)}:{lineNumber}] {data2}");
});
}
public static void Info(object data, [CallerLineNumber] int lineNumber = 0, [CallerFilePath] string file = "")
{
string file2 = file;
object data2 = data;
CoroutineDispatcher.RunOnMainThreadOrCurrent(delegate
{
Plugin.Log.LogInfo((object)$"[{Path.GetFileName(file2)}:{lineNumber}] {data2}");
});
}
public static void Message(object data, [CallerLineNumber] int lineNumber = 0, [CallerFilePath] string file = "")
{
string file2 = file;
object data2 = data;
CoroutineDispatcher.RunOnMainThreadOrCurrent(delegate
{
Plugin.Log.LogMessage((object)$"[{Path.GetFileName(file2)}:{lineNumber}] {data2}");
});
}
public static void Warning(object data, [CallerLineNumber] int lineNumber = 0, [CallerFilePath] string file = "")
{
string file2 = file;
object data2 = data;
CoroutineDispatcher.RunOnMainThreadOrCurrent(delegate
{
Plugin.Log.LogWarning((object)$"[{Path.GetFileName(file2)}:{lineNumber}] {data2}");
});
}
public static void Error(object data, [CallerLineNumber] int lineNumber = 0, [CallerFilePath] string file = "")
{
string file2 = file;
object data2 = data;
CoroutineDispatcher.RunOnMainThreadOrCurrent(delegate
{
Plugin.Log.LogError((object)$"[{Path.GetFileName(file2)}:{lineNumber}] {data2}");
});
}
}
public static class ResourcePacksManager
{
public static bool HasPacksChanged = true;
public const string PackPrefsName = "__ResourcefulHands_Mod_PackOrder";
public const string DisabledPacksPrefsName = "__ResourcefulHands_Mod_DisabledPacks";
private static bool isReloading = false;
public static List<TexturePack> LoadedPacks { get; internal set; } = new List<TexturePack>();
public static TexturePack[] ActivePacks => LoadedPacks.Where((TexturePack pack) => pack.IsActive).ToArray();
public static Texture2D? GetTextureFromPacks(string textureName)
{
Texture2D val = null;
TexturePack[] activePacks = ActivePacks;
for (int i = 0; i < activePacks.Length; i++)
{
Texture2D texture = activePacks[i].GetTexture(textureName);
if ((Object)(object)texture != (Object)null)
{
val = texture;
}
}
if (Object.op_Implicit((Object)(object)val))
{
return val;
}
if (textureName == "DeathFloor_02" || textureName == "_CORRUPTTEXTURE")
{
return Plugin.CorruptionTexture;
}
return null;
}
public static AudioClip? GetSoundFromPacks(string soundName)
{
AudioClip result = null;
TexturePack[] activePacks = ActivePacks;
for (int i = 0; i < activePacks.Length; i++)
{
AudioClip sound = activePacks[i].GetSound(soundName);
if ((Object)(object)sound != (Object)null)
{
result = sound;
}
}
return result;
}
internal static void SaveDisabledPacks()
{
List<string> list = new List<string>();
foreach (TexturePack loadedPack in LoadedPacks)
{
if (!loadedPack.IsActive)
{
list.Add(loadedPack.guid);
}
}
string text = JsonConvert.SerializeObject((object)list.ToArray());
PlayerPrefs.SetString("__ResourcefulHands_Mod_DisabledPacks", text);
}
internal static void LoadDisabledPacks()
{
string @string = PlayerPrefs.GetString("__ResourcefulHands_Mod_DisabledPacks", "");
if (string.IsNullOrWhiteSpace(@string))
{
return;
}
string[] array = JsonConvert.DeserializeObject<string[]>(@string);
if (array == null || array.Length == 0)
{
return;
}
string[] array2 = array;
foreach (string disabledPackGuid in array2)
{
foreach (TexturePack item in LoadedPacks.Where((TexturePack pack) => pack.guid == disabledPackGuid))
{
item.IsActive = false;
}
}
}
internal static void SavePackOrder()
{
string[] array = new string[LoadedPacks.Count];
for (int i = 0; i < LoadedPacks.Count; i++)
{
TexturePack texturePack = LoadedPacks[i];
array[i] = texturePack.guid;
}
string text = JsonConvert.SerializeObject((object)array);
PlayerPrefs.SetString("__ResourcefulHands_Mod_PackOrder", text);
}
internal static void LoadPackOrder()
{
string @string = PlayerPrefs.GetString("__ResourcefulHands_Mod_PackOrder", "");
if (string.IsNullOrWhiteSpace(@string))
{
return;
}
string[] array = JsonConvert.DeserializeObject<string[]>(@string);
if (array == null)
{
return;
}
TexturePack[] array2 = LoadedPacks.ToArray();
TexturePack[] array3 = new TexturePack[array.Length];
for (int i = 0; i < array3.Length; i++)
{
array3[i] = null;
}
for (int j = 0; j < array.Length; j++)
{
string guid = array[j];
TexturePack texturePack = array2.FirstOrDefault((TexturePack p) => p.guid == guid);
if (texturePack != null)
{
array3[j] = texturePack;
}
}
List<TexturePack> list = new List<TexturePack>();
TexturePack[] array4 = array3;
foreach (TexturePack texturePack2 in array4)
{
if (texturePack2 != null)
{
list.Add(texturePack2);
}
}
array4 = array2;
foreach (TexturePack item in array4)
{
if (!list.Contains(item))
{
list.Add(item);
}
}
LoadedPacks = list;
SavePackOrder();
}
public static void ReloadPacks()
{
if (isReloading)
{
RHLog.Warning("Tried to reload while already reloading?", 131, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\ResourcePacksManager.cs");
return;
}
Task.Run(async delegate
{
await ReloadPacks_Internal();
});
}
internal static async Task ReloadPacks_Internal()
{
if (isReloading)
{
return;
}
isReloading = true;
HasPacksChanged = false;
if (LoadedPacks.Count != 0)
{
SavePackOrder();
SaveDisabledPacks();
}
LoadedPacks.Clear();
RHLog.Info("Expanding zips...", 154, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\ResourcePacksManager.cs");
string[] files = Directory.GetFiles(Plugin.ConfigFolder, "*.zip", SearchOption.TopDirectoryOnly);
foreach (string text in files)
{
try
{
RHLog.Info("Expanding texture pack zip: " + text, 160, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\ResourcePacksManager.cs");
bool flag = true;
using (ZipArchive zipArchive = ZipFile.OpenRead(text))
{
flag = zipArchive.GetEntry("info.json") != null;
}
if (flag)
{
DirectoryInfo directoryInfo = Directory.CreateDirectory(Path.Combine(Plugin.ConfigFolder, Path.GetFileNameWithoutExtension(text)));
ZipFile.ExtractToDirectory(text, directoryInfo.FullName);
}
else
{
ZipFile.ExtractToDirectory(text, Plugin.ConfigFolder);
}
File.Delete(text);
RHLog.Info("Expanded!", 174, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\ResourcePacksManager.cs");
}
catch (Exception data)
{
RHLog.Info("Failed to expand!", 178, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\ResourcePacksManager.cs");
RHLog.Error(data, 179, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\ResourcePacksManager.cs");
}
}
RHLog.Info("Loading texture packs...", 182, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\ResourcePacksManager.cs");
List<string> list = new List<string>();
list.AddRange(Directory.GetDirectories(Plugin.ConfigFolder, "*", SearchOption.TopDirectoryOnly));
list.AddRange(Directory.GetDirectories(Paths.PluginPath, "*", SearchOption.AllDirectories));
int failedPacks = 0;
foreach (string path in list)
{
if (!File.Exists(Path.Combine(path, "info.json")))
{
continue;
}
try
{
RHLog.Info("Loading texture pack: " + path, 196, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\ResourcePacksManager.cs");
TexturePack texturePack = await TexturePack.Load(path);
if (texturePack == null)
{
RHLog.Warning("Failed to load pack at " + path + "!", 200, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\ResourcePacksManager.cs");
failedPacks++;
}
else
{
LoadedPacks.Add(texturePack);
RHLog.Info("Loaded!", 206, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\ResourcePacksManager.cs");
}
}
catch (Exception data2)
{
failedPacks++;
RHLog.Info("Failed to load!", 211, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\ResourcePacksManager.cs");
RHLog.Error(data2, 212, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\ResourcePacksManager.cs");
}
}
RHLog.Info("Re-ordering to user order...", 216, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\ResourcePacksManager.cs");
LoadPackOrder();
RHLog.Info("Disabling packs that should be disabled...", 218, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\ResourcePacksManager.cs");
LoadDisabledPacks();
RHLog.Info($"Loaded {LoadedPacks.Count}/{LoadedPacks.Count + failedPacks} texture packs", 221, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\ResourcePacksManager.cs");
if (failedPacks > 0)
{
RHLog.Warning($"{failedPacks} packs failed to load!", 223, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\ResourcePacksManager.cs");
}
await CoroutineDispatcher.RunOnMainThreadAndWait(delegate
{
Plugin.RefreshTextures();
Plugin.RefreshSounds();
if ((Object)(object)UI_RHPacksList.Instance != (Object)null)
{
UI_RHPacksList.Instance?.BuildList();
}
}, 225, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\ResourcePacksManager.cs");
isReloading = false;
}
}
[Serializable]
public class TexturePack
{
public string name = string.Empty;
public string desc = string.Empty;
public string author = string.Empty;
[JsonProperty(/*Could not decode attribute arguments.*/)]
public ulong steamid;
[JsonProperty(/*Could not decode attribute arguments.*/)]
public string guid = string.Empty;
[JsonProperty(/*Could not decode attribute arguments.*/)]
public bool hiddenFromList;
[JsonProperty(/*Could not decode attribute arguments.*/)]
public bool onlyInFullGame;
[JsonProperty(/*Could not decode attribute arguments.*/)]
public string relativeTexturesPath = "Textures";
[JsonProperty(/*Could not decode attribute arguments.*/)]
public string relativeSoundsPath = "Sounds";
[JsonProperty(/*Could not decode attribute arguments.*/)]
public string relativeIconPath = "pack.png";
[JsonProperty(/*Could not decode attribute arguments.*/)]
public int texturePackVersion = 2;
[NonSerialized]
[JsonIgnore]
public const int CurrentFormatVersion = 2;
[NonSerialized]
[JsonIgnore]
public bool IsActive = true;
[NonSerialized]
[JsonIgnore]
public Dictionary<string, Texture2D> Textures = new Dictionary<string, Texture2D>();
[NonSerialized]
[JsonIgnore]
public Dictionary<string, AudioClip> Sounds = new Dictionary<string, AudioClip>();
[NonSerialized]
[JsonIgnore]
protected List<AudioClip> RawSounds = new List<AudioClip>();
[NonSerialized]
[JsonIgnore]
public const string DefaultJson = "{\r\n \"name\":\"generated-game-assets\",\r\n \"desc\":\"Every game asset\",\r\n \r\n \"author\":\"Dark Machine Games\",\r\n \"steamid\":0,\r\n \r\n \"guid\":\"generated-game-assets\",\r\n \r\n \"hidden-from-list\":true,\r\n \"only-in-full-game\":false,\r\n \r\n \"textures-folder\":\"Textures\",\r\n \"sounds-folder\":\"Sounds\",\r\n \"icon-file\":\"pack.png\",\r\n \r\n \"format-version\":2\r\n} ";
[JsonIgnore]
public string PackPath { get; private set; } = string.Empty;
[JsonIgnore]
public Texture2D Icon { get; private set; }
public Texture2D? GetTexture(string textureName)
{
Textures.TryGetValue(textureName, out Texture2D value);
return value;
}
public AudioClip? GetSound(string soundName)
{
Sounds.TryGetValue(soundName, out AudioClip value);
return value;
}
public static async Task<TexturePack?> Load(string path, bool force = false)
{
string jsonPath = Path.Combine(path, "info.json");
if (!File.Exists(jsonPath))
{
RHLog.Warning(path + " doesn't have an info.json!", 141, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\TexturePack.cs");
return null;
}
TexturePack pack = JsonConvert.DeserializeObject<TexturePack>(await File.ReadAllTextAsync(jsonPath));
if (pack == null)
{
RHLog.Warning(jsonPath + " isn't a valid TexturePack json!", 147, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\TexturePack.cs");
RHLog.Info("Example: {\r\n \"name\":\"generated-game-assets\",\r\n \"desc\":\"Every game asset\",\r\n \r\n \"author\":\"Dark Machine Games\",\r\n \"steamid\":0,\r\n \r\n \"guid\":\"generated-game-assets\",\r\n \r\n \"hidden-from-list\":true,\r\n \"only-in-full-game\":false,\r\n \r\n \"textures-folder\":\"Textures\",\r\n \"sounds-folder\":\"Sounds\",\r\n \"icon-file\":\"pack.png\",\r\n \r\n \"format-version\":2\r\n} ", 148, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\TexturePack.cs");
return null;
}
pack.PackPath = path;
if (!force)
{
if (pack.hiddenFromList)
{
RHLog.Info("Not loading texture pack at " + path + " because it is hidden.", 157, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\TexturePack.cs");
return null;
}
if (pack.onlyInFullGame && Plugin.IsDemo)
{
RHLog.Info("Skipping incompatible texture pack (it says it only works for the fullgame): " + path, 162, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\TexturePack.cs");
return null;
}
}
if (pack.texturePackVersion != 2)
{
RHLog.Warning($"Texture pack at {path} is format version {pack.texturePackVersion} which isn't {2} (the current version), it may not function correctly.", 168, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\TexturePack.cs");
}
string iconPath = Path.Combine(path, pack.relativeIconPath);
if (!File.Exists(iconPath))
{
RHLog.Warning(path + " doesn't have an pack.png! (icon path: '" + pack.relativeIconPath + "')", 173, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\TexturePack.cs");
await CoroutineDispatcher.RunOnMainThreadAndWait(delegate
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
pack.Icon = (Texture2D)(((object)Plugin.IconGray) ?? ((object)new Texture2D(2, 2)));
}, 174, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\TexturePack.cs");
}
else
{
byte[] fileBytes2 = await File.ReadAllBytesAsync(iconPath);
await CoroutineDispatcher.RunOnMainThreadAndWait(delegate
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Expected O, but got Unknown
Texture2D val2 = new Texture2D(2, 2);
if (!ImageConversion.LoadImage(val2, fileBytes2, false))
{
RHLog.Warning(iconPath + " isn't a valid texture!", 187, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\TexturePack.cs");
try
{
Object.Destroy((Object)(object)val2);
return;
}
catch
{
return;
}
}
((Object)val2).name = Path.GetFileNameWithoutExtension(iconPath);
((Texture)val2).filterMode = (FilterMode)0;
val2.Apply();
pack.Icon = val2;
}, 182, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\TexturePack.cs");
}
string prevGuid = pack.guid;
if (string.IsNullOrWhiteSpace(pack.guid))
{
pack.guid = pack.author.ToLower() + "." + pack.name.ToLower();
}
pack.guid = MiscUtils.CleanString(pack.guid.Replace(' ', '_'));
if (pack.guid != prevGuid)
{
string contents = JsonConvert.SerializeObject((object)pack);
await File.WriteAllTextAsync(jsonPath, contents);
RHLog.Warning("Corrected " + pack.name + "'s guid: " + prevGuid + " -> " + pack.guid, 209, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\TexturePack.cs");
}
TexturePack texturePack = ResourcePacksManager.LoadedPacks.FirstOrDefault((TexturePack p) => p.guid == pack.guid);
if (texturePack != null)
{
RHLog.Error("Resource pack's guid (" + pack.guid + ") at '" + path + "' is the same as the resource pack's guid at '" + texturePack.PackPath, 215, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\TexturePack.cs");
return null;
}
RHLog.Info("Texture pack at " + path + " is valid, loading assets...", 219, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\TexturePack.cs");
string path2 = Path.Combine(path, pack.relativeTexturesPath);
string path3 = Path.Combine(path, pack.relativeSoundsPath);
string[] array = Array.Empty<string>();
string[] soundFiles = Array.Empty<string>();
if (Directory.Exists(path2))
{
array = Directory.GetFiles(path2, "*.*", SearchOption.AllDirectories);
}
if (Directory.Exists(path3))
{
soundFiles = Directory.GetFiles(path3, "*.*", SearchOption.AllDirectories);
}
int textureCount = array.Length;
int i = 0;
string[] array2 = array;
foreach (string textureFile in array2)
{
RHLog.Info($"Loading textures ({i++}/{textureCount})", 236, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\TexturePack.cs");
string text = Path.GetExtension(textureFile).ToLower();
if (!text.Contains("png") && !text.Contains("jpg"))
{
RHLog.Warning(text + " isn't supported! Only png and jpg files are supported! [at: " + textureFile + "]", 240, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\TexturePack.cs");
continue;
}
byte[] fileBytes = await File.ReadAllBytesAsync(textureFile);
await CoroutineDispatcher.RunOnMainThreadAndWait(delegate
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Expected O, but got Unknown
Texture2D val = new Texture2D(2, 2);
if (!ImageConversion.LoadImage(val, fileBytes, false))
{
RHLog.Warning(textureFile + " isn't a valid texture!", 250, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\TexturePack.cs");
try
{
Object.Destroy((Object)(object)val);
return;
}
catch
{
return;
}
}
((Object)val).name = Path.GetFileNameWithoutExtension(textureFile);
((Texture)val).filterMode = (FilterMode)0;
val.Apply();
if (!pack.Textures.TryAdd(((Object)val).name, val))
{
RHLog.Error("Failed to add " + textureFile + " because texture of that name already exists in the same pack!", 258, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\TexturePack.cs");
}
}, 245, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\TexturePack.cs");
}
await LoadAllSounds(soundFiles, pack);
return pack;
}
private static async Task LoadAllSounds(IEnumerable<string> soundFiles, TexturePack pack)
{
List<Task> soundTasks = new List<Task>();
List<string> list = soundFiles.ToList();
int num = 0;
int count = list.ToList().Count;
foreach (string item in list)
{
RHLog.Info($"Queuing sounds ({++num}/{count})", 278, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\TexturePack.cs");
soundTasks.Add(LoadSound(item, pack));
}
await Task.WhenAll(soundTasks);
RHLog.Info($"Loaded {soundTasks.Count} sounds for {pack.guid}!", 286, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\TexturePack.cs");
}
private static async Task LoadSound(string filepath, TexturePack pack)
{
string clipName = Path.GetFileNameWithoutExtension(filepath);
string extension = Path.GetExtension(filepath);
string text = extension.Substring(1, extension.Length - 1);
AudioClip audioClip = null;
AudioType val = (AudioType)(text.ToLower() switch
{
"wav" => 20,
"ogg" => 14,
"mp3" => 13,
"aiff" => 2,
"wma" => 13,
"acc" => 1,
_ => 0,
});
if ((int)val == 0)
{
RHLog.Error("Failed to load sound file, '" + text + "' is not a supported format [at: " + filepath + "]", 308, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\TexturePack.cs");
return;
}
UnityWebRequest uwr = new UnityWebRequest(filepath, "GET")
{
downloadHandler = (DownloadHandler)new DownloadHandlerAudioClip(filepath, val)
};
DownloadHandlerAudioClip dh = (DownloadHandlerAudioClip)uwr.downloadHandler;
dh.streamAudio = false;
dh.compressed = true;
uwr.SendWebRequest();
try
{
while (!uwr.isDone)
{
await Task.Delay(5);
}
Result result = uwr.result;
if (result - 2 <= 1)
{
RHLog.Error("Error while loading " + clipName + " [at: " + filepath + "]", 327, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\TexturePack.cs");
}
else
{
audioClip = dh.audioClip;
}
}
catch
{
RHLog.Error("Error while loading " + clipName + " [at: " + filepath + "]", 333, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\TexturePack.cs");
}
if ((Object)(object)audioClip == (Object)null)
{
return;
}
pack.RawSounds.Add(audioClip);
((Object)audioClip).name = clipName;
lock (pack.Sounds)
{
if (!pack.Sounds.TryAdd(clipName, audioClip))
{
RHLog.Error("Failed to add " + clipName + " because sound of that name already exists in the same pack! [at: " + filepath + "]", 344, "C:\\Users\\Steve\\RiderProjects\\ResourcefulHands\\Types\\TexturePack.cs");
}
}
}
}
public class UI_RHPack : MonoBehaviour
{
public RawImage? Icon;
public TextMeshProUGUI? Title;
public TextMeshProUGUI? Author;
public Button? SteamAuthor;
public TextMeshProUGUI? Description;
public TextMeshProUGUI? Guid;
public Button? Up;
public Button? Down;
public Button? EnableToggle;
public Image? EnableOn;
public Image? EnableOff;
private TexturePack _pack;
private T? FindAt<T>(string path) where T : Component
{
Transform val = ((Component)this).transform;
string[] array = path.Split('/');
foreach (string text in array)
{
val = val.Find(text);
if ((Object)(object)val == (Object)null)
{
return default(T);
}
}
return ((Component)val).GetComponentInChildren<T>();
}
public void Awake()
{
Icon = FindAt<RawImage>("IconContainer/Icon");
Title = FindAt<TextMeshProUGUI>("Title");
Author = FindAt<TextMeshProUGUI>("AuthorPanel/Author");
SteamAuthor = FindAt<Button>("AuthorPanel/ViewOnSteam");
Description = FindAt<TextMeshProUGUI>("Desc");
Guid = FindAt<TextMeshProUGUI>("Guid");
Up = FindAt<Button>("Up/Arrow");
Down = FindAt<Button>("Down/Arrow");
EnableToggle = FindAt<Button>("Disable");
EnableOff = FindAt<Image>("Disable/Toggle/OffImg");
EnableOn = FindAt<Image>("Disable/Toggle/ToggleImg");
}
public void Load(TexturePack pack, bool active = true)
{
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Expected O, but got Unknown
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_010f: Expected O, but got Unknown
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: Expected O, but got Unknown
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: Expected O, but got Unknown
TexturePack pack2 = pack;
_pack = pack2;
Icon.texture = (Texture)(object)_pack.Icon;
((TMP_Text)Title).text = _pack.name;
((TMP_Text)Author).text = _pack.author;
((TMP_Text)Description).text = _pack.desc;
((TMP_Text)Guid).text = _pack.guid;
((Behaviour)EnableOff).enabled = !active;
((Behaviour)EnableOn).enabled = active;
if (pack2.steamid != 0)
{
Button? steamAuthor = SteamAuthor;
if (steamAuthor != null)
{
((UnityEvent)steamAuthor.onClick).AddListener((UnityAction)delegate
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
SteamFriends.OpenUserOverlay(SteamId.op_Implicit(pack2.steamid), "steamid");
});
}
}
else
{
Button? steamAuthor2 = SteamAuthor;
if (steamAuthor2 != null)
{
((Component)steamAuthor2).gameObject.SetActive(false);
}
}
((UnityEvent)Up.onClick).AddListener((UnityAction)delegate
{
RHCommands.MovePack(_pack, isUp: true);
UI_RHPacksList.Instance?.BuildList();
ConfigEntry<bool>? lazyManip3 = RHConfig.LazyManip;
if (lazyManip3 != null && lazyManip3.Value)
{
Plugin.RefreshTextures();
Plugin.RefreshSounds();
}
else
{
ResourcePacksManager.ReloadPacks();
}
});
((UnityEvent)Down.onClick).AddListener((UnityAction)delegate
{
RHCommands.MovePack(_pack, isUp: false);
UI_RHPacksList.Instance?.BuildList();
ConfigEntry<bool>? lazyManip2 = RHConfig.LazyManip;
if (lazyManip2 != null && lazyManip2.Value)
{
Plugin.RefreshTextures();
Plugin.RefreshSounds();
}
else
{
ResourcePacksManager.ReloadPacks();
}
});
((UnityEvent)EnableToggle.onClick).AddListener((UnityAction)delegate
{
_pack.IsActive = !_pack.IsActive;
UI_RHPacksList.Instance?.BuildList();
ConfigEntry<bool>? lazyManip = RHConfig.LazyManip;
if (lazyManip != null && lazyManip.Value)
{
Plugin.RefreshTextures();
Plugin.RefreshSounds();
}
else
{
ResourcePacksManager.ReloadPacks();
}
});
}
}
public class UI_RHPacksList : MonoBehaviour
{
[CompilerGenerated]
private sealed class <EnableCoroutine>d__5 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public UI_RHPacksList <>4__this;
object? IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object? IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <EnableCoroutine>d__5(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Expected O, but got Unknown
int num = <>1__state;
UI_RHPacksList uI_RHPacksList = <>4__this;
switch (num)
{
default:
return false;
case 0:
{
<>1__state = -1;
Transform? container2 = uI_RHPacksList.container;
if (container2 != null)
{
((Component)container2).gameObject.SetActive(false);
}
<>2__current = (object)new WaitForSecondsRealtime(0.075f);
<>1__state = 1;
return true;
}
case 1:
{
<>1__state = -1;
Transform? container = uI_RHPacksList.container;
if (container != null)
{
((Component)container).gameObject.SetActive(true);
}
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();
}
}
public static UI_RHPacksList? Instance;
public ScrollRect? scrollRect;
public Transform? container;
public UI_RHPack? packTemplate;
public void Awake()
{
Instance = this;
scrollRect = ((Component)this).GetComponentInChildren<ScrollRect>();
container = (Transform?)(object)scrollRect.content;
packTemplate = ((Component)container.Find("Pack")).gameObject.AddComponent<UI_RHPack>();
((Component)packTemplate).gameObject.SetActive(false);
}
[IteratorStateMachine(typeof(<EnableCoroutine>d__5))]
private IEnumerator EnableCoroutine()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <EnableCoroutine>d__5(0)
{
<>4__this = this
};
}
public void OnEnable()
{
BuildList();
CoroutineDispatcher.Dispatch(EnableCoroutine());
}
public void OnDisable()
{
if (ResourcePacksManager.LoadedPacks.Count != 0)
{
ResourcePacksManager.SavePackOrder();
ResourcePacksManager.SaveDisabledPacks();
}
}
private void ClearList()
{
if ((Object)(object)container == (Object)null || (Object)(object)packTemplate == (Object)null)
{
return;
}
for (int i = 0; i < container.childCount; i++)
{
Transform child = container.GetChild(i);
if (!((Object)(object)child == (Object)(object)((Component)packTemplate).transform))
{
Object.Destroy((Object)(object)((Component)child).gameObject);
}
}
}
public void BuildList()
{
ClearList();
foreach (TexturePack loadedPack in ResourcePacksManager.LoadedPacks)
{
UI_RHPack uI_RHPack = Object.Instantiate<UI_RHPack>(packTemplate, container);
if (!((Object)(object)uI_RHPack == (Object)null))
{
TexturePack pack1 = loadedPack;
uI_RHPack.Load(loadedPack, ResourcePacksManager.ActivePacks.FirstOrDefault((TexturePack p) => p == pack1) != null);
((Object)((Component)uI_RHPack).gameObject).name = loadedPack.guid;
((Component)uI_RHPack).gameObject.SetActive(true);
}
}
}
}
}
namespace ResourcefulHands.Patches
{
[HarmonyPatch(typeof(Image))]
public static class ImagePatches
{
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
[HarmonyPostfix]
public static void Getter_sprite_Postfix(Image __instance, ref Sprite __result)
{
if (!((Object)(object)__result == (Object)null))
{
__result = SpriteRendererPatches.GetSprite(__result);
}
}
}
[HarmonyPatch(typeof(SpriteRenderer))]
public static class SpriteRendererPatches
{
private static bool dontPatch = false;
internal static Dictionary<string, Sprite> _customSpriteCache { get; private set; } = new Dictionary<string, Sprite>();
public static Sprite? GetSprite(Sprite sprite)
{
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
//IL_0124: 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_0134: Unknown result type (might be due to invalid IL or missing references)
//IL_013f: Unknown result type (might be due to invalid IL or missing references)
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_014e: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)sprite == (Object)null)
{
return sprite;
}
bool num = ((Object)sprite).name.EndsWith(" [modified asset]");
string text = ((Object)sprite).name;
if (num)
{
text = text.Substring(0, text.Length - " [modified asset]".Length);
}
if (_customSpriteCache.TryGetValue(text, out Sprite value))
{
if ((Object)(object)value != (Object)null)
{
return value;
}
_customSpriteCache.Remove(text);
}
Texture2D textureFromPacks = ResourcePacksManager.GetTextureFromPacks(((Object)sprite.texture).name);
if ((Object)(object)textureFromPacks == (Object)null)
{
return sprite;
}
Rect rect = sprite.rect;
float num2 = Mathf.Clamp(((Rect)(ref rect)).x, 0f, (float)((Texture)textureFromPacks).width);
rect = sprite.rect;
float num3 = Mathf.Clamp(((Rect)(ref rect)).y, 0f, (float)((Texture)textureFromPacks).height);
rect = sprite.rect;
float num4 = Mathf.Clamp(((Rect)(ref rect)).width, 0f, (float)((Texture)textureFromPacks).width - num2);
rect = sprite.rect;
float num5 = Mathf.Clamp(((Rect)(ref rect)).height, 0f, (float)((Texture)textureFromPacks).height - num3);
Rect val = new Rect(num2, num3, num4, num5);
float x = sprite.pivot.x;
rect = sprite.rect;
float num6 = x / ((Rect)(ref rect)).width;
float y = sprite.pivot.y;
rect = sprite.rect;
Sprite val2 = Sprite.Create(textureFromPacks, val, new Vector2(num6, y / ((Rect)(ref rect)).height), sprite.pixelsPerUnit);
((Object)val2).name = text + " [modified asset]";
_customSpriteCache.Add(text, val2);
return val2;
}
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
[HarmonyPostfix]
private static void Constructor_Postfix(SpriteRenderer __instance)
{
__instance.sprite = __instance.sprite;
}
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
[HarmonyPostfix]
private static void Getter_Postfix(SpriteRenderer __instance, ref Sprite __result)
{
if (dontPatch)
{
dontPatch = false;
return;
}
__result = GetSprite(__result);
dontPatch = true;
__instance.sprite = __result;
}
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
[HarmonyPostfix]
private static void Setter_Prefix(SpriteRenderer __instance, ref Sprite value)
{
if (dontPatch)
{
dontPatch = false;
return;
}
value = GetSprite(value);
dontPatch = true;
__instance.sprite = value;
}
}
[HarmonyPatch(typeof(AudioSource))]
public static class AudioSourcePatches
{
private static bool dontPatch;
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
[HarmonyPostfix]
private static void Constructor_Postfix(AudioSource __instance)
{
if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.clip == (Object)null)
{
return;
}
AudioClip soundFromPacks = ResourcePacksManager.GetSoundFromPacks(((Object)__instance.clip).name);
if ((Object)(object)soundFromPacks != (Object)null)
{
__instance.clip = soundFromPacks;
if (__instance.playOnAwake && Time.timeSinceLevelLoad <= 0.25f && !__instance.isPlaying)
{
dontPatch = true;
__instance.Play();
}
}
}
[HarmonyPatch("Play", new Type[] { })]
[HarmonyPrefix]
private static void Play_NoArgs_Postfix(AudioSource __instance)
{
SwapClip(__instance);
}
[HarmonyPatch("Play", new Type[] { typeof(double) })]
[HarmonyPrefix]
private static void Play_DelayDouble_Postfix(AudioSource __instance)
{
SwapClip(__instance);
}
[HarmonyPatch("Play", new Type[] { typeof(ulong) })]
[HarmonyPrefix]
private static void Play_DelayUlong_Postfix(AudioSource __instance)
{
SwapClip(__instance);
}
[HarmonyPatch(typeof(AudioSource), "PlayOneShot", new Type[] { typeof(AudioClip) })]
[HarmonyPrefix]
private static void PlayOneShot_ClipOnly_Postfix(AudioSource __instance, ref AudioClip __0)
{
AudioClip soundFromPacks = ResourcePacksManager.GetSoundFromPacks(((Object)__instance.clip).name);
if (soundFromPacks != null)
{
__0 = soundFromPacks;
}
}
[HarmonyPatch(typeof(AudioSource), "PlayOneShot", new Type[]
{
typeof(AudioClip),
typeof(float)
})]
[HarmonyPrefix]
private static void PlayOneShot_ClipAndVolume_Postfix(AudioSource __instance, ref AudioClip __0)
{
AudioClip soundFromPacks = ResourcePacksManager.GetSoundFromPacks(((Object)__instance.clip).name);
if (soundFromPacks != null)
{
__0 = soundFromPacks;
}
}
private static void SwapClip(AudioSource src)
{
if (dontPatch)
{
dontPatch = false;
}
else if (((src != null) ? src.clip : null) != null)
{
AudioClip soundFromPacks = ResourcePacksManager.GetSoundFromPacks(((Object)src.clip).name);
if (soundFromPacks != null)
{
src.clip = soundFromPacks;
}
}
}
}
[HarmonyPatch(typeof(Material))]
public static class MaterialPatches
{
private static bool dontPatch = false;
internal static Dictionary<string, Texture> previousTextures = new Dictionary<string, Texture>();
private static readonly int MainTex = Shader.PropertyToID("_MainTex");
public static void SetMainTexture(Material m, Texture texture)
{
dontPatch = true;
m.mainTexture = texture;
}
public static Texture GetMainTexture(Material m)
{
dontPatch = true;
return m.mainTexture;
}
[HarmonyPatch("get_mainTexture")]
[HarmonyPostfix]
private static void Getter_Postfix(Material __instance, ref Texture __result)
{
if (dontPatch)
{
dontPatch = false;
}
else
{
if ((Object)(object)__instance == (Object)null || !__instance.HasTexture(MainTex))
{
return;
}
dontPatch = true;
Texture mainTexture = __instance.mainTexture;
if (!((Object)(object)mainTexture == (Object)null))
{
Texture2D textureFromPacks = ResourcePacksManager.GetTextureFromPacks(((Object)mainTexture).name);
if (!((Object)(object)textureFromPacks == (Object)null))
{
((Object)textureFromPacks).name = ((Object)mainTexture).name + " [replaced]";
previousTextures.TryAdd(((Object)mainTexture).name, mainTexture);
__instance.mainTexture = (Texture)(object)textureFromPacks;
}
}
}
}
[HarmonyPatch("set_mainTexture")]
[HarmonyPostfix]
private static void Setter_Prefix(Material __instance, ref Texture value)
{
if (dontPatch)
{
dontPatch = false;
}
else
{
if ((Object)(object)__instance == (Object)null || !__instance.HasTexture(MainTex))
{
return;
}
dontPatch = true;
Texture mainTexture = __instance.mainTexture;
if (!((Object)(object)mainTexture == (Object)null))
{
Texture2D textureFromPacks = ResourcePacksManager.GetTextureFromPacks(((Object)mainTexture).name);
if (!((Object)(object)textureFromPacks == (Object)null))
{
((Object)textureFromPacks).name = ((Object)mainTexture).name + " [replaced]";
previousTextures.TryAdd(((Object)mainTexture).name, mainTexture);
__instance.mainTexture = (Texture)(object)textureFromPacks;
}
}
}
}
}
[HarmonyPatch(typeof(Renderer))]
public static class RendererPatches
{
private static readonly int MainTex = Shader.PropertyToID("_MainTex");
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
[HarmonyPostfix]
private static void Constructor_Postfix(Renderer __instance)
{
if ((Object)(object)__instance == (Object)null || __instance.sharedMaterials == null)
{
return;
}
Material[] sharedMaterials = __instance.sharedMaterials;
foreach (Material val in sharedMaterials)
{
if (val.HasProperty(MainTex))
{
_ = val.mainTexture;
}
}
}
public static void Patch(ref Material material)
{
if (!((Object)(object)material == (Object)null) && material.HasProperty(MainTex))
{
_ = material.mainTexture;
}
}
[HarmonyPatch("get_material")]
[HarmonyPostfix]
private static void Getter_material_Postfix(Renderer __instance, ref Material __result)
{
Patch(ref __result);
}
[HarmonyPatch("set_material")]
[HarmonyPostfix]
private static void Setter_material_Prefix(Renderer __instance, ref Material value)
{
Patch(ref value);
}
[HarmonyPatch("get_materials")]
[HarmonyPostfix]
private static void Getter_materials_Postfix(Renderer __instance, ref Material[] __result)
{
for (int i = 0; i < __result.Length; i++)
{
Patch(ref __result[i]);
}
}
[HarmonyPatch("set_materials")]
[HarmonyPostfix]
private static void Setter_materials_Prefix(Renderer __instance, ref Material[] value)
{
for (int i = 0; i < value.Length; i++)
{
Patch(ref value[i]);
}
}
[HarmonyPatch("get_sharedMaterial")]
[HarmonyPostfix]
private static void Getter_sharedMaterial_Postfix(Renderer __instance, ref Material __result)
{
Patch(ref __result);
}
[HarmonyPatch("set_sharedMaterial")]
[HarmonyPostfix]
private static void Setter_sharedMaterial_Prefix(Renderer __instance, ref Material value)
{
Patch(ref value);
}
[HarmonyPatch("get_sharedMaterials")]
[HarmonyPostfix]
private static void Getter_sharedMaterials_Postfix(Renderer __instance, ref Material[] __result)
{
for (int i = 0; i < __result.Length; i++)
{
Patch(ref __result[i]);
}
}
[HarmonyPatch("set_sharedMaterials")]
[HarmonyPostfix]
private static void Setter_sharedMaterials_Prefix(Renderer __instance, ref Material[] value)
{
for (int i = 0; i < value.Length; i++)
{
Patch(ref value[i]);
}
}
}
}