Decompiled source of UCustomPrefabs Peak v0.0.2
UCustomPrefabs/PixelTools.dll
Decompiled a month agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using Microsoft.CodeAnalysis; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using ScottyFoxArt.PixelTools.ShaderTextures; using UnityEngine; using UnityEngine.Events; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.0.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.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } [Serializable] [RequireComponent(typeof(Renderer))] public class PeakLayeredTextureHelper : MonoBehaviour { public Vector2Int TextureSize = new Vector2Int(512, 512); public List<Texture2D> LayerBundleTextures; public List<Texture2D> LayerBundleMasks; public string LayerBundleData; public LayerBundle layerbundle = new LayerBundle(); public void Start() { Deserialize(); } public void Deserialize() { if (string.IsNullOrWhiteSpace(LayerBundleData)) { return; } try { layerbundle = JsonConvert.DeserializeObject<LayerBundle>(LayerBundleData); layerbundle.ReapplyTextures(LayerBundleTextures, LayerBundleMasks); } catch (Exception ex) { Debug.LogError((object)ex); } } public Texture2D RenderTextureBundle() { return ShaderTextureBuilder.RenderBundle(layerbundle, ((Vector2Int)(ref TextureSize)).x, ((Vector2Int)(ref TextureSize)).y); } } namespace ScottyFoxArt.PixelTools.Utilities { public static class BlendModeUtils { private static Color white = new Color(1f, 1f, 1f, 1f); public static Color Burn(Color a, Color b, float opacity = 1f) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: 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 Color.LerpUnclamped(a, white - Divide(white - b, a), opacity); } public static Color Darken(Color a, Color b, float opacity = 1f) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: 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) //IL_0028: 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_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0052: 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_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) Color val = default(Color); val.r = Mathf.Min(a.r, b.r); val.g = Mathf.Min(a.g, b.g); val.b = Mathf.Min(a.b, b.b); val.a = Mathf.Min(a.a, b.a); return Color.LerpUnclamped(a, val, opacity); } public static Color Difference(Color a, Color b, float opacity = 1f) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0042: 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_005b: 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_006d: 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) Color val = default(Color); val.r = Mathf.Abs(b.r - a.r); val.g = Mathf.Abs(b.g - a.g); val.b = Mathf.Abs(b.b - a.b); val.a = Mathf.Abs(b.a - a.a); return Color.LerpUnclamped(a, val, opacity); } public static Color Divide(Color a, Color b, float opacity = 1f) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0044: 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_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) Color val = default(Color); val.r = a.r / (b.r + 1E-12f); val.g = a.g / (b.g + 1E-12f); val.b = a.b / (b.b + 1E-12f); val.a = a.a / (b.a + 1E-12f); return Color.LerpUnclamped(a, val, opacity); } public static Color Dodge(Color a, Color b, float opacity = 1f) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0015: 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_003e: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0067: 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_0090: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) Color val = default(Color); val.r = a.r / (1f - Mathf.Clamp(b.r, 1E-06f, 0.999999f)); val.g = a.g / (1f - Mathf.Clamp(b.g, 1E-06f, 0.999999f)); val.b = a.b / (1f - Mathf.Clamp(b.b, 1E-06f, 0.999999f)); val.a = a.a / (1f - Mathf.Clamp(b.a, 1E-06f, 0.999999f)); return Color.LerpUnclamped(a, val, opacity); } public static Color Exclusion(Color a, Color b, float opacity = 1f) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: 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_0013: 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_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) return Color.LerpUnclamped(a, b + a - 2f * b * a, opacity); } public static Color HardLight(Color a, Color b, float opacity = 1f) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) Color val = default(Color); val.r = HardLight_float(a.r, b.r); val.g = HardLight_float(a.g, b.g); val.b = HardLight_float(a.b, b.b); val.a = HardLight_float(a.a, b.a); return Color.LerpUnclamped(a, val, opacity); } private static float HardLight_float(float a, float b, float opacity = 1f) { float num = ((!(b < 0.5f)) ? (2f * a * b) : (1f - 2f * (1f - a) * (1f - b))); return Mathf.LerpUnclamped(a, num, opacity); } public static Color HardMix(Color a, Color b, float opacity = 1f) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: 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: Unknown result type (might be due to invalid IL or missing references) return Color.LerpUnclamped(a, Step(white - a, b), opacity); } public static Color Lighten(Color a, Color b, float opacity = 1f) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: 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) //IL_0028: 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_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0052: 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_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) Color val = default(Color); val.r = Mathf.Max(a.r, b.r); val.g = Mathf.Max(a.g, b.g); val.b = Mathf.Max(a.b, b.b); val.a = Mathf.Max(a.a, b.a); return Color.LerpUnclamped(a, val, opacity); } public static Color LinearBurn(Color a, Color b, float opacity = 1f) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: 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_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) return Color.LerpUnclamped(a, a + b - white, opacity); } public static Color LinearDodge(Color a, Color b, float opacity = 1f) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) return Color.LerpUnclamped(a, a + b, opacity); } public static Color LinearLight(Color a, Color b, float opacity = 1f) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) Color val = default(Color); val.r = LinearLight_float(a.r, b.r); val.g = LinearLight_float(a.g, b.g); val.b = LinearLight_float(a.b, b.b); val.a = LinearLight_float(a.a, b.a); return Color.LerpUnclamped(a, val, opacity); } private static float LinearLight_float(float a, float b, float opacity = 1f) { if (b < 0.5f) { return Mathf.Max(a + 2f * b - 1f, 0f); } return Mathf.Min(a + 2f * (b - 0.5f), 1f); } public static Color LinearLightAddSub(Color a, Color b, float opacity = 1f) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //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) //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_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) return Color.LerpUnclamped(a, b + 2f * a - white, opacity); } public static Color Multiply(Color a, Color b, float opacity = 1f) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) return Color.LerpUnclamped(a, a * b, opacity); } public static Color Negation(Color a, Color b, float opacity = 1f) { //IL_0002: 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_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0039: 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_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) Color val = default(Color); val.r = 1f - Mathf.Abs(1f - b.r - a.r); val.g = 1f - Mathf.Abs(1f - b.g - a.g); val.b = 1f - Mathf.Abs(1f - b.b - a.b); val.a = 1f - Mathf.Abs(1f - b.a - a.a); return Color.LerpUnclamped(a, val, opacity); } public static Color Overlay(Color a, Color b, float opacity = 1f) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) Color val = default(Color); val.r = Overlay_float(a.r, b.r); val.g = Overlay_float(a.g, b.g); val.b = Overlay_float(a.b, b.b); val.a = Overlay_float(a.a, b.a); return Color.LerpUnclamped(a, val, opacity); } private static float Overlay_float(float a, float b, float opacity = 1f) { float num = ((!(a < 0.5f)) ? (2f * a * b) : (1f - 2f * (1f - a) * (1f - b))); return Mathf.LerpUnclamped(a, num, opacity); } public static Color PinLight(Color a, Color b, float opacity = 1f) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) Color val = default(Color); val.r = PinLight_float(a.r, b.r); val.g = PinLight_float(a.g, b.g); val.b = PinLight_float(a.b, b.b); val.a = PinLight_float(a.a, b.a); return Color.LerpUnclamped(a, val, opacity); } private static float PinLight_float(float a, float b, float opacity = 1f) { float num = ((!(b < 0.5f)) ? Mathf.Max(2f * (b - 0.5f), b) : Mathf.Min(2f * a, b)); return Mathf.LerpUnclamped(a, num, opacity); } public static Color Screen(Color a, Color b, float opacity = 1f) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) return Color.LerpUnclamped(a, white - (white - b) * (white - a), opacity); } public static Color SoftLight(Color a, Color b, float opacity = 1f) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) Color val = default(Color); val.r = SoftLight_float(a.r, b.r); val.g = SoftLight_float(a.g, b.g); val.b = SoftLight_float(a.b, b.b); val.a = SoftLight_float(a.a, b.a); return Color.LerpUnclamped(a, val, opacity); } private static float SoftLight_float(float a, float b, float opacity = 1f) { float num = ((!(b < 0.5f)) ? (Mathf.Sqrt(a) * (2f * b - 1f) + 2f * a * (1f - b)) : (2f * a * b + a * a * (1f - 2f * b))); return Mathf.LerpUnclamped(a, num, opacity); } public static Color Step(Color a, Color b, float opacity = 1f) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: 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) //IL_0028: 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_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0052: 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_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) Color val = default(Color); val.r = Step(a.r, b.r); val.g = Step(a.g, b.g); val.b = Step(a.b, b.b); val.a = Step(a.a, b.a); return Color.LerpUnclamped(a, val, opacity); } private static float Step(float value, float edge) { if (!(value < edge)) { return 1f; } return 0f; } public static Color Subtract(Color a, Color b, float opacity = 1f) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) return Color.LerpUnclamped(a, a - b, opacity); } public static Color VividLight(Color a, Color b, float opacity = 1f) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) Color val = default(Color); val.r = VividLight_float(a.r, b.r); val.g = VividLight_float(a.g, b.g); val.b = VividLight_float(a.b, b.b); val.a = VividLight_float(a.a, b.a); return Color.LerpUnclamped(a, val, opacity); } private static float VividLight_float(float a, float b, float opacity = 1f) { a = Mathf.Clamp(a, 1E-06f, 0.999999f); float num = ((!(b < 0.5f)) ? (b / (2f * (1f - a))) : (1f - (1f - b) / (2f * a))); return Mathf.LerpUnclamped(a, num, opacity); } public static Color Overwrite(Color a, Color b, float opacity = 1f) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) return Color.LerpUnclamped(a, b, opacity); } } public static class PaletteUtils { public static void SampleColors_Dominate(Color[] colors, out Color average, out Color dominate, out Color brightest) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0128: 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_013f: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0172: 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_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0052: 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_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: 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) dominate = Color.white; brightest = Color.black; average = Color.black; Dictionary<Color, int> dictionary = new Dictionary<Color, int>(); int num = 0; float num2 = 0f; float num3 = default(float); float num4 = default(float); float num5 = default(float); float num6 = default(float); float num7 = default(float); foreach (Color val in colors) { if (dictionary.ContainsKey(val)) { dictionary[val]++; } else { dictionary.Add(val, 1); } if (dictionary[val] > num) { num = dictionary[val]; dominate = val; } Color.RGBToHSV(val, ref num3, ref num4, ref num5); Color.RGBToHSV(brightest, ref num3, ref num6, ref num7); if ((double)num5 > 0.5 || num7 == 0f) { if (num4 == num2) { brightest = Color.Lerp(brightest, val, 0.5f); } else if (num4 > num2) { brightest = val; num2 = num4; } } average += val; } average /= (float)colors.Length; float num8 = default(float); float num9 = default(float); float num10 = default(float); Color.RGBToHSV(average, ref num8, ref num9, ref num10); float num11 = default(float); float num12 = default(float); Color.RGBToHSV(brightest, ref num6, ref num11, ref num12); brightest = Color.HSVToRGB(num8, Mathf.Lerp(num9, num11, 0.5f), Mathf.Lerp(num10, num12, 0.5f)); } } public static class TextureUtils { public static Color[] ColorBlock(Color color, int width, int height) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) if (width < 1 || height < 1) { return null; } Color[] array = (Color[])(object)new Color[width * height]; for (int i = 0; i < array.Length; i++) { array[i] = color; } return array; } public static Color[] ColorBlock(Color color, int size) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return ColorBlock(color, size, size); } public static Color[] ColorBlock(Color color, Vector2Int size) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return ColorBlock(color, ((Vector2Int)(ref size)).x, ((Vector2Int)(ref size)).y); } public static Color[] ColorBlock(Color color, Vector2 size) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //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) return ColorBlock(color, (int)size.x, (int)size.y); } } } namespace ScottyFoxArt.PixelTools.ShaderTextures { public enum BlendMode { None, Burn, Darken, Difference, Dodge, Divide, Exclusion, HardLight, HardMix, Lighten, LinearBurn, LinearDodge, LinearLight, LinearLightAddSub, Multiply, Negation, Overlay, PinLight, Screen, SoftLight, Subtract, VividLight, Overwrite, UVDraw } public static class BlendModeShaderLibrary { public static Shader Burn; public static Shader Darken; public static Shader Difference; public static Shader Dodge; public static Shader Divide; public static Shader Exclusion; public static Shader HardLight; public static Shader HardMix; public static Shader Lighten; public static Shader LinearBurn; public static Shader LinearDodge; public static Shader LinearLight; public static Shader LinearLightAddSub; public static Shader Multiply; public static Shader Negation; public static Shader Overlay; public static Shader PinLight; public static Shader Screen; public static Shader SoftLight; public static Shader Subtract; public static Shader VividLight; public static Shader Overwrite; public static Shader UVDraw; private const string PixelTools_ShaderBundle_File = "PixelTools/pixeltoolsshaders"; private static bool _loaded; private static AssetBundle _shaderBundle; public static AssetBundle LoadEmbeddedAssetBundleFromCurrentAssembly(string resourcePath) { Assembly assembly = typeof(BlendModeShaderLibrary).Assembly; string text = resourcePath.Replace("\\", "/").Replace("/", "."); string name = assembly.FullName.Split(new char[1] { ',' })[0] + "." + text; try { using Stream stream = assembly.GetManifestResourceStream(name); if (stream == null) { Debug.LogError((object)"Failed to open stream for embedded AssetBundle."); return null; } byte[] array = new byte[stream.Length]; stream.Read(array, 0, array.Length); return AssetBundle.LoadFromMemory(array); } catch (Exception ex) { Debug.LogError((object)ex); } return null; } private static Shader FetchShaderFromRegistry(string shaderName) { return _shaderBundle.LoadAsset<Shader>(shaderName); } public static Shader GetBlendMode(BlendMode blendmode) { if (!_loaded) { try { _shaderBundle = LoadEmbeddedAssetBundleFromCurrentAssembly("PixelTools/pixeltoolsshaders"); Burn = FetchShaderFromRegistry("LayerBurn"); Darken = FetchShaderFromRegistry("LayerDarken"); Difference = FetchShaderFromRegistry("LayerDifference"); Dodge = FetchShaderFromRegistry("LayerDodge"); Divide = FetchShaderFromRegistry("LayerDivide"); Exclusion = FetchShaderFromRegistry("LayerExclusion"); HardLight = FetchShaderFromRegistry("LayerHardLight"); HardMix = FetchShaderFromRegistry("LayerHardMix"); Lighten = FetchShaderFromRegistry("LayerLighten"); LinearBurn = FetchShaderFromRegistry("LayerLinearBurn"); LinearDodge = FetchShaderFromRegistry("LayerLinearDodge"); LinearLight = FetchShaderFromRegistry("LayerLinearLight"); LinearLightAddSub = FetchShaderFromRegistry("LayerLinearLightAddSub"); Multiply = FetchShaderFromRegistry("LayerMultiply"); Negation = FetchShaderFromRegistry("LayerNegation"); Overlay = FetchShaderFromRegistry("LayerOverlay"); PinLight = FetchShaderFromRegistry("LayerPinLight"); Screen = FetchShaderFromRegistry("LayerScreen"); SoftLight = FetchShaderFromRegistry("LayerSoftLight"); Subtract = FetchShaderFromRegistry("LayerSubtract"); VividLight = FetchShaderFromRegistry("LayerVividLight"); Overwrite = FetchShaderFromRegistry("LayerOverride"); UVDraw = FetchShaderFromRegistry("LayerUVDraw"); _loaded = true; } catch { Debug.LogWarning((object)"Failed To Load PixelTool Shaders...!"); } } if (_loaded) { switch (blendmode) { case BlendMode.Burn: return Burn; case BlendMode.Darken: return Darken; case BlendMode.Difference: return Difference; case BlendMode.Dodge: return Dodge; case BlendMode.Divide: return Divide; case BlendMode.Exclusion: return Exclusion; case BlendMode.HardLight: return HardLight; case BlendMode.HardMix: return HardMix; case BlendMode.Lighten: return Lighten; case BlendMode.LinearBurn: return LinearBurn; case BlendMode.LinearDodge: return LinearDodge; case BlendMode.LinearLight: return LinearLight; case BlendMode.LinearLightAddSub: return LinearLightAddSub; case BlendMode.Multiply: return Multiply; case BlendMode.Negation: return Negation; case BlendMode.Overlay: return Overlay; case BlendMode.PinLight: return PinLight; case BlendMode.Screen: return Screen; case BlendMode.SoftLight: return SoftLight; case BlendMode.Subtract: return Subtract; case BlendMode.VividLight: return VividLight; case BlendMode.Overwrite: return Overwrite; case BlendMode.UVDraw: return UVDraw; } } return null; } } [ExecuteInEditMode] public class BundleWatcher : MonoBehaviour { public LayerBundleData layerBundleData; public Renderer meshRenderer; public int materialIndex; private void OnValidate() { layerBundleData?.onTextureGenerated.RemoveListener((UnityAction<Texture2D>)OnTextureGenerated); layerBundleData?.onTextureGenerated.AddListener((UnityAction<Texture2D>)OnTextureGenerated); } public void OnEnable() { layerBundleData?.onTextureGenerated.AddListener((UnityAction<Texture2D>)OnTextureGenerated); } public void OnDisable() { layerBundleData?.onTextureGenerated.RemoveListener((UnityAction<Texture2D>)OnTextureGenerated); } public void OnDestroy() { layerBundleData?.onTextureGenerated.RemoveListener((UnityAction<Texture2D>)OnTextureGenerated); } public void OnTextureGenerated(Texture2D texture) { if (!((Object)(object)meshRenderer == (Object)null)) { Material[] sharedMaterials = meshRenderer.sharedMaterials; if (materialIndex >= 0 || materialIndex < sharedMaterials.Length) { sharedMaterials[materialIndex].mainTexture = (Texture)(object)texture; } } } } public class ShaderTextureTester : MonoBehaviour { [SerializeReference] public bool generateTextureOutput; public Vector2Int outputSize = new Vector2Int(512, 512); public LayerBundle layerBundle = new LayerBundle(); private void Start() { GenerateTexture(); } public void GenerateTexture() { Texture2D val = ShaderTextureBuilder.RenderBundle(layerBundle, ((Vector2Int)(ref outputSize)).x, ((Vector2Int)(ref outputSize)).y, generateTextureOutput); ((Component)this).GetComponent<Renderer>().sharedMaterial.mainTexture = (Texture)(object)val; if (generateTextureOutput) { File.WriteAllBytes(Path.Combine(Application.dataPath, $"ShaderTextureTest_{((object)val).GetHashCode()}.png"), ImageConversion.EncodeToPNG(val)); } } } public class LayerConverter : JsonConverter<Layer> { public override void WriteJson(JsonWriter writer, Layer value, JsonSerializer serializer) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) JObject val = new JObject(); val.Add("name", JToken.op_Implicit(value.name)); val.Add("enabled", JToken.op_Implicit(value.enabled)); val.Add("mode", JToken.FromObject((object)value.mode)); val.Add("color", JToken.op_Implicit(ColorUtility.ToHtmlStringRGBA(value.color))); ((JToken)val).WriteTo(writer, Array.Empty<JsonConverter>()); } public override Layer ReadJson(JsonReader reader, Type objectType, Layer existingValue, bool hasExistingValue, JsonSerializer serializer) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) JObject val = JObject.Load(reader); string text = ((object)val["color"])?.ToString(); Debug.LogWarning((object)text); Color white = default(Color); if (!ColorUtility.TryParseHtmlString("#" + text, ref white)) { white = Color.white; } Layer result = default(Layer); result.name = ((object)val["name"])?.ToString(); JToken obj = val["enabled"]; result.enabled = obj != null && obj.ToObject<bool>(); JToken obj2 = val["mode"]; result.mode = ((obj2 != null) ? obj2.ToObject<BlendMode>() : BlendMode.None); result.color = white; return result; } } [Serializable] [JsonConverter(typeof(LayerConverter))] public struct Layer { public string name; public bool enabled; public BlendMode mode; public Color color; public Texture2D texture; public Texture2D mask; public Layer(string name = "Layer", bool enabled = true, BlendMode mode = BlendMode.Overwrite, Color color = default(Color), Texture2D texture = null, Texture2D mask = null) { //IL_0016: 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) this.name = name; this.enabled = enabled; this.mode = mode; this.color = color; this.texture = texture; this.mask = mask; } } public class LayerBundleConverter : JsonConverter<LayerBundle> { public override void WriteJson(JsonWriter writer, LayerBundle value, JsonSerializer serializer) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) JObject val = new JObject(); val.Add("backgroundColor", JToken.op_Implicit(ColorUtility.ToHtmlStringRGBA(value.backgroundColor))); val.Add("layers", (JToken)(object)JArray.FromObject((object)value.layers, serializer)); ((JToken)val).WriteTo(writer, Array.Empty<JsonConverter>()); } public override LayerBundle ReadJson(JsonReader reader, Type objectType, LayerBundle existingValue, bool hasExistingValue, JsonSerializer serializer) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected O, but got Unknown //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) JObject obj = JObject.Load(reader); Color white = default(Color); if (!ColorUtility.TryParseHtmlString(((object)obj["color"])?.ToString(), ref white)) { white = Color.white; } JArray val = (JArray)obj["layers"]; return new LayerBundle { backgroundColor = white, layers = (((val != null) ? ((JToken)val).ToObject<List<Layer>>(serializer) : null) ?? new List<Layer>()) }; } } [Serializable] [JsonConverter(typeof(LayerBundleConverter))] public class LayerBundle { public Color backgroundColor = Color.white; public List<Layer> layers = new List<Layer>(); public void ReapplyTextures(List<Texture2D> textures, List<Texture2D> masks) { if (textures.Count != layers.Count || masks.Count != layers.Count) { Debug.LogWarning((object)"Reapply Textures has invalid textures/or/masks count. may throw error."); } for (int i = 0; i < layers.Count; i++) { try { Layer value = layers[i]; value.texture = textures[i]; value.mask = masks[i]; layers[i] = value; } catch { Debug.LogError((object)$"Error Applying Texture To Layer {i}"); } } } public int AddLayer(string name, Texture2D texture, Texture2D mask, Color color, BlendMode mode = BlendMode.Overwrite, bool enabled = true, int index = int.MaxValue) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) Layer layer = new Layer(name, enabled, mode, color, texture, mask); AddLayer(layer, index); return index; } public int AddLayer(Layer layer, int index = int.MaxValue) { index = GetNearestValidIndex(index); if (index == layers.Count) { layers.Add(layer); } else { layers.Insert(index, layer); } return index; } public void AddLayers(IEnumerable<Layer> layers) { foreach (Layer layer in layers) { AddLayer(layer); } } public bool RemoveLayer(int index) { if (!IsValidIndex(index)) { return false; } layers.RemoveAt(index); return true; } public bool RemoveLayer(string name) { return RemoveLayer(FindName(name)); } public bool SetLayer(int index, Layer layer) { if (!IsValidIndex(index)) { return false; } layers[index] = layer; return true; } public bool SetLayer(string name, Layer layer) { return SetLayer(FindName(name), layer); } public int FindName(string name) { int num = 0; using (List<Layer>.Enumerator enumerator = layers.GetEnumerator()) { while (enumerator.MoveNext() && !(enumerator.Current.name == name)) { num++; } } if (num != layers.Count) { return num; } return -1; } public bool TryGetLayer(int index, out Layer layer) { layer = default(Layer); if (!IsValidIndex(index)) { return false; } layer = layers[index]; return true; } public bool TryGetLayer(string name, out Layer layer) { return TryGetLayer(FindName(name), out layer); } public bool IsValidIndex(int index) { if (index >= 0) { return index < layers.Count; } return false; } public int GetNearestValidIndex(int index) { if (index > layers.Count) { index = layers.Count; } else if (index < 0) { index = 0; } return index; } public void SetLayerEnabled(int index, bool enabled) { if (TryGetLayer(index, out var layer)) { layer.enabled = enabled; SetLayer(index, layer); } } public void SetLayerEnabled(string name, bool enabled) { SetLayerEnabled(FindName(name), enabled); } public void SetLayerMode(int index, BlendMode mode) { if (TryGetLayer(index, out var layer)) { layer.mode = mode; SetLayer(index, layer); } } public void SetLayerMode(string name, BlendMode mode) { SetLayerMode(FindName(name), mode); } public void SetLayerTexture(int index, Texture2D texture) { if (TryGetLayer(index, out var layer)) { layer.texture = texture; SetLayer(index, layer); } } public void SetLayerTexture(string name, Texture2D texture) { SetLayerTexture(FindName(name), texture); } public void SetLayerMask(int index, Texture2D mask) { if (TryGetLayer(index, out var layer)) { layer.texture = mask; SetLayer(index, layer); } } public void SetLayerMask(string name, Texture2D mask) { SetLayerMask(FindName(name), mask); } public void SetLayerColor(int index, Color color) { //IL_000e: 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) if (TryGetLayer(index, out var layer)) { layer.color = color; SetLayer(index, layer); } } public void SetLayerColor(string name, Color color) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) SetLayerColor(FindName(name), color); } } [Serializable] [CreateAssetMenu(fileName = "LayerBundleData", menuName = "ScriptableObjects/Layer Bundle Data", order = 1)] public class LayerBundleData : ScriptableObject { public Vector2Int outputSize = new Vector2Int(512, 512); public LayerBundle layerBundle = new LayerBundle(); [NonSerialized] [HideInInspector] public UnityEvent<Texture2D> onTextureGenerated = new UnityEvent<Texture2D>(); public bool updateMaterials; public List<MaterialInfo> materialsToUpdate = new List<MaterialInfo>(); [HideInInspector] public bool generateOutput; [HideInInspector] public string outputLocation = "Output.png"; [NonSerialized] [HideInInspector] public Texture2D texture; private void UpdateMaterials(Texture2D texture) { if (!updateMaterials) { return; } foreach (MaterialInfo item in materialsToUpdate) { if ((Object)(object)item.material == (Object)null || item.textureProperties.Count == 0) { continue; } foreach (string textureProperty in item.textureProperties) { item.material.SetTexture(textureProperty, (Texture)(object)texture); } } } public Texture2D GenerateTexture() { texture = ShaderTextureBuilder.RenderBundle(layerBundle, ((Vector2Int)(ref outputSize)).x, ((Vector2Int)(ref outputSize)).y, generateOutput); if ((Object)(object)texture != (Object)null && generateOutput) { string text = outputLocation.Substring(outputLocation.LastIndexOf(".")).ToUpper(); byte[] array = null; switch (text) { case ".EXR": array = ImageConversion.EncodeToEXR(texture); break; case ".JPG": array = ImageConversion.EncodeToJPG(texture); break; case ".PNG": array = ImageConversion.EncodeToPNG(texture); break; case ".TGA": array = ImageConversion.EncodeToTGA(texture); break; default: outputLocation += ".png"; array = ImageConversion.EncodeToPNG(texture); break; } string text2 = Path.Combine(Application.dataPath, outputLocation); File.WriteAllBytes(text2, array); Debug.Log((object)("Writting Image:\n" + text2)); } UpdateMaterials(texture); onTextureGenerated.Invoke(texture); return texture; } } [Serializable] public struct MaterialInfo { public Material material; public List<string> textureProperties; } public static class ShaderTextureBuilder { public static Texture2D RenderBundle(LayerBundle bundle, int width, int height, bool ReadToMemory = false) { return new ShaderTextureBuilder_Job(null, bundle, width, height, ReadToMemory).Render(); } public static Texture2D RenderBundle(LayerBundleData bundleData) { return new ShaderTextureBuilder_Job(null, bundleData.layerBundle, ((Vector2Int)(ref bundleData.outputSize)).x, ((Vector2Int)(ref bundleData.outputSize)).y, bundleData.generateOutput).Render(); } public static void RenderBundle_Async(Action<Texture2D> listener, LayerBundle bundle, int width, int height, bool ReadToMemory = false) { } public static void RenderBundle_Async(Action<Texture2D> listener, LayerBundleData bundleData) { } } public class ShaderTextureBuilder_Job { private Action<Texture2D> _listener; private LayerBundle _bundle; private int _width = -1; private int _height = -1; public bool _readtomemory; private Texture2D _texture; private RenderTexture _buffer; private Material _material; public ShaderTextureBuilder_Job(Action<Texture2D> listener, LayerBundle bundle, int width, int height, bool readtomemory) { _listener = listener; _bundle = bundle; _width = width; _height = height; _readtomemory = readtomemory; } public Texture2D Render() { if (!Validate()) { return null; } Prepare(); RenderBackground(); foreach (Layer layer in _bundle.layers) { RenderLayer(layer); } if (_readtomemory) { ReadToMemory(); } Cleanup(); _listener?.Invoke(_texture); return _texture; } private bool Validate() { if (_width > 0) { return _height > 0; } return false; } private void Prepare() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Expected O, but got Unknown //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Expected O, but got Unknown _buffer = new RenderTexture(_width, _height, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)2); _texture = new Texture2D(_width, _height, (TextureFormat)5, false, false, true); } private bool FetchShader(Layer layer) { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown Shader blendMode = BlendModeShaderLibrary.GetBlendMode(layer.mode); if ((Object)(object)blendMode == (Object)null) { Debug.Log((object)"Shader Missing!!! Check Library."); return false; } if ((Object)(object)_material == (Object)null) { _material = new Material(blendMode); } if ((Object)(object)_material.shader != (Object)(object)blendMode) { _material.shader = blendMode; } return true; } private void RenderBackground() { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) Color32[] array = (Color32[])(object)new Color32[_width * _height]; for (int i = 0; i < array.Length; i++) { array[i] = Color32.op_Implicit(_bundle.backgroundColor); } _texture.SetPixels32(array); _texture.Apply(); RenderTexture active = RenderTexture.active; Graphics.CopyTexture((Texture)(object)_texture, (Texture)(object)_buffer); RenderTexture.active = active; } private void RenderLayer(Layer layer) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) if (layer.enabled && FetchShader(layer)) { _material.SetColor("_Color", layer.color); _material.SetTexture("_BaseMap", (Texture)(object)_texture); _material.SetTexture("_BlendMap", (Texture)(object)layer.texture); _material.SetTexture("_MaskMap", (Texture)(object)layer.mask); RenderTexture active = RenderTexture.active; Graphics.Blit((Texture)null, _buffer, _material, 0); Graphics.CopyTexture((Texture)(object)_buffer, (Texture)(object)_texture); RenderTexture.active = active; } } private void ReadToMemory() { //IL_002e: Unknown result type (might be due to invalid IL or missing references) RenderTexture active = RenderTexture.active; RenderTexture.active = _buffer; _texture.ReadPixels(new Rect(0f, 0f, (float)_width, (float)_height), 0, 0, false); _texture.Apply(); RenderTexture.active = active; } private void Cleanup() { if ((Object)(object)RenderTexture.active == (Object)(object)_buffer) { RenderTexture.active = null; } _buffer.Release(); Object.DestroyImmediate((Object)(object)_material); Object.DestroyImmediate((Object)(object)_buffer); } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }
UCustomPrefabs/UCustomPrefabsAPI.dll
Decompiled a month agousing System; 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.Text; using Microsoft.CodeAnalysis; using UCustomPrefabsAPI.Extras.AssetBundles; using UCustomPrefabsAPI.Extras.CustomActions; using UCustomPrefabsAPI.Extras.Utility; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("0.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.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace UCustomPrefabsAPI { public class ActionStateMachine { private class StateActions { public List<Action<string>> OnEnter = new List<Action<string>>(); public List<Action> OnUpdate = new List<Action>(); public List<Action<string>> OnExit = new List<Action<string>>(); } private Dictionary<string, StateActions> _StatesActions = new Dictionary<string, StateActions>(); private List<Action<string, string>> OnStateChanged = new List<Action<string, string>>(); private List<Action> OnUpdate = new List<Action>(); private List<Action> OnDestroy = new List<Action>(); private StateActions _CurrentActions; public string State { get; private set; } = string.Empty; public bool HasState(string name) { return _StatesActions.ContainsKey(name); } public void AddState(string name) { Internal_AddState(name); } private StateActions Internal_AddState(string name, bool addState = true) { if (!_StatesActions.TryGetValue(name, out var value) && addState) { value = new StateActions(); _StatesActions.Add(name, value); } return value; } public void AddOnEnter(string name, Action<string> action, bool addState = false) { Internal_AddState(name, addState)?.OnEnter.Add(action); } public void AddOnUpdate(string name, Action action, bool addState = false) { Internal_AddState(name, addState)?.OnUpdate.Add(action); } public void AddOnExit(string name, Action<string> action, bool addState = false) { Internal_AddState(name, addState)?.OnExit.Add(action); } public void AddOnStateChanged(Action<string, string> action) { OnStateChanged.Add(action); } public void AddOnUpdate(Action action) { OnUpdate.Add(action); } public void AddOnDestroy(Action action) { OnDestroy.Add(action); } public void Do_OnEnter() { _CurrentActions?.OnEnter.ForEach(delegate(Action<string> action) { try { action?.Invoke(State); } catch (Exception ex) { Debug.LogError((object)ex); } }); } public void Do_OnExit() { _CurrentActions?.OnExit.ForEach(delegate(Action<string> action) { try { action?.Invoke(State); } catch (Exception ex) { Debug.LogError((object)ex); } }); } public void Do_OnStateChanged(string lastState) { OnStateChanged.ForEach(delegate(Action<string, string> action) { try { action?.Invoke(lastState, State); } catch (Exception ex) { Debug.LogError((object)ex); } }); } public void SetState(string name) { if (!(State == name)) { _StatesActions.TryGetValue(name, out _CurrentActions); State = name; } } public void Update() { _CurrentActions?.OnUpdate.ForEach(delegate(Action action) { action?.Invoke(); }); OnUpdate.ForEach(delegate(Action action) { try { action?.Invoke(); } catch (Exception ex) { Debug.LogError((object)ex); } }); } public void Destroy() { OnDestroy.ForEach(delegate(Action action) { try { action?.Invoke(); } catch (Exception ex) { Debug.LogError((object)ex); } }); } } public abstract class CustomActionsBase : HandlerReferencer, IComparable<CustomActionsBase> { private ActionStateMachine StateMachine => base.Handler?.StateMachine; public int Priority { get; set; } public void AddOnEnter(string name, Action<string> action, bool addState = false) { StateMachine.AddOnEnter(name, action, addState); } public void AddOnUpdate(string name, Action action, bool addState = false) { StateMachine.AddOnUpdate(name, action, addState); } public void AddOnExit(string name, Action<string> action, bool addState = false) { StateMachine.AddOnExit(name, action, addState); } public void AddOnStateChanged(Action<string, string> action) { StateMachine.AddOnStateChanged(action); } public void AddOnUpdate(Action action) { StateMachine.AddOnUpdate(action); } public void AddOnDestroy(Action action) { StateMachine.AddOnDestroy(action); } public abstract void RegisterActions(); public virtual void HandleTemplateData(object[] data) { } public int CompareTo(CustomActionsBase other) { return Priority.CompareTo(other.Priority); } } public static class UCustomPrefabFileHelper { public static List<string> FindDirectoriesWithFileName(string path, string fileName) { List<string> list = new List<string>(); Queue<string> queue = new Queue<string>(); queue.Enqueue(path); while (queue.Count > 0) { string text = queue.Dequeue(); try { if (File.Exists(Path.Combine(text, fileName))) { list.Add(text); } string[] directories = Directory.GetDirectories(text); foreach (string item in directories) { queue.Enqueue(item); } } catch (Exception ex) { Debug.LogError((object)("Unable to Access " + text)); Debug.LogError((object)ex); } } return list; } private static bool IsAssetBundle(string path) { bool result = false; try { using FileStream input = new FileStream(path, FileMode.Open, FileAccess.Read); using BinaryReader binaryReader = new BinaryReader(input); byte[] bytes = binaryReader.ReadBytes(8); string @string = Encoding.ASCII.GetString(bytes); if (@string.StartsWith("UnityFS") || @string.StartsWith("UnityRaw") || @string.StartsWith("UnityWeb")) { result = true; } } catch (Exception ex) { Console.WriteLine("Error Reading File : " + ex.Message); } return result; } public static void TryToLoadTemplateAssetBundlesFromPath<T>(string path) { try { string[] files = Directory.GetFiles(Path.Combine(Path.GetDirectoryName(typeof(T).Assembly.Location), path)); List<string> list = new List<string>(); string[] array = files; foreach (string path2 in array) { if (IsAssetBundle(path2)) { list.Add(Path.Combine(path, Path.GetFileName(path2))); } } foreach (string item in list) { if (AssetBundleRegistry.Register<T>(item, out var name)) { if (!TryToLoadTemplatesFromAssetBundle(name)) { Debug.Log((object)("Unable to load Templates from Assetbundle : " + name)); AssetBundleRegistry.Remove(name, unloadAllLoadedObjects: true); } else { Debug.Log((object)("Registering AssetBundle : " + item)); } } } } catch (Exception ex) { Debug.Log((object)("Unable To Access Path : " + path)); Debug.LogError((object)ex); } } public static bool TryToLoadTemplatesFromAssetBundle(string assetBundleName) { TextAsset val = AssetBundleRegistry.LoadAsset<TextAsset>(assetBundleName, "templates.ucp.txt"); if ((Object)(object)val == (Object)null || string.IsNullOrWhiteSpace(val.text)) { Debug.Log((object)("Unable to Read Templates Json from " + assetBundleName)); return false; } UCustomPrefab_AssetBundle_TemplatesJSON uCustomPrefab_AssetBundle_TemplatesJSON = new UCustomPrefab_AssetBundle_TemplatesJSON(); JsonUtility.FromJsonOverwrite(val.text, (object)uCustomPrefab_AssetBundle_TemplatesJSON); if (!uCustomPrefab_AssetBundle_TemplatesJSON.Verify()) { Debug.Log((object)"Templates Data is Invalid!"); return false; } for (int i = 0; i < uCustomPrefab_AssetBundle_TemplatesJSON.Template_Names.Count; i++) { TemplateRegistry.LateRegister(uCustomPrefab_AssetBundle_TemplatesJSON.Template_Names[i], assetBundleName, uCustomPrefab_AssetBundle_TemplatesJSON.Template_Prefabs[i]); } return true; } } [Serializable] public class UCustomPrefab_AssetBundle_TemplatesJSON { public string Name; public string Author; public string Description; public List<string> Template_Names = new List<string>(); public List<string> Template_Prefabs = new List<string>(); public bool Verify() { if (!string.IsNullOrWhiteSpace(Name) && !string.IsNullOrWhiteSpace(Author) && !string.IsNullOrWhiteSpace(Description) && Template_Names.Count != 0) { return Template_Prefabs.Count != 0; } return false; } } public class InstanceInfo { public string ID { get; private set; } = string.Empty; public Transform Target { get; private set; } public string TemplateUID { get; private set; } = string.Empty; public UCustomPrefabHandler Handler { get; private set; } public InstanceInfo(string id, string template_uid) { ID = id; TemplateUID = template_uid; } public bool SetTarget(Transform target) { if ((Object)(object)target == (Object)null) { Debug.LogWarning((object)"Target Doesn't Exist!"); return false; } Target = target; Reset(); return true; } public bool IsValid() { if ((Object)(object)Handler != (Object)null) { return (Object)(object)Target != (Object)null; } return false; } public void Reset() { if ((Object)(object)Target == (Object)null || (Object)(object)((Component)Target).gameObject == (Object)null || DestroyHandler()) { return; } try { Handler = ((Component)Target).gameObject.AddComponent<UCustomPrefabHandler>(); if (!Object.op_Implicit((Object)(object)Handler)) { Debug.LogWarning((object)"Handler Unable to be added to GameObject. Ignore."); return; } Handler.Instance = this; Handler.Initialize(); } catch (Exception ex) { Debug.LogError((object)ex); } } public bool DestroyHandler(bool reset = true, bool destroy = true) { if ((Object)(object)Handler == (Object)null) { return false; } UCustomPrefabHandler handler = Handler; Handler = null; if (destroy) { handler.HandleDestroy(reset); } return true; } public void PrepareRemove() { DestroyHandler(reset: false); } } public static class InstanceManager { private static Dictionary<string, InstanceInfo> Instances = new Dictionary<string, InstanceInfo>(); public static bool TryGetInstance(string uid, out InstanceInfo instance) { instance = null; if (string.IsNullOrWhiteSpace(uid)) { return false; } Verify(); if (Instances.TryGetValue(uid, out instance)) { return instance != null; } return false; } public static InstanceInfo[] GetInstancesInTarget(Transform target) { if ((Object)(object)target == (Object)null) { return new InstanceInfo[0]; } UCustomPrefabHandler[] components = ((Component)target).gameObject.GetComponents<UCustomPrefabHandler>(); InstanceInfo[] array = new InstanceInfo[components.Length]; for (int i = 0; i < components.Length; i++) { array[i] = components[i]?.Instance; } return array; } public static InstanceInfo[] GetInstancesInTargetChildren(Transform target) { if ((Object)(object)target == (Object)null) { return new InstanceInfo[0]; } UCustomPrefabHandler[] componentsInChildren = ((Component)target).gameObject.GetComponentsInChildren<UCustomPrefabHandler>(true); InstanceInfo[] array = new InstanceInfo[componentsInChildren.Length]; for (int i = 0; i < componentsInChildren.Length; i++) { array[i] = componentsInChildren[i]?.Instance; } return array; } public static InstanceInfo[] GetInstancesInTargetParent(Transform target) { if ((Object)(object)target == (Object)null) { return new InstanceInfo[0]; } UCustomPrefabHandler[] componentsInParent = ((Component)target).gameObject.GetComponentsInParent<UCustomPrefabHandler>(); InstanceInfo[] array = new InstanceInfo[componentsInParent.Length]; for (int i = 0; i < componentsInParent.Length; i++) { array[i] = componentsInParent[i]?.Instance; } return array; } public static bool Register(string uid, string template_uid, Transform target) { if (string.IsNullOrWhiteSpace(uid) || string.IsNullOrWhiteSpace(template_uid) || (Object)(object)target == (Object)null) { return false; } Verify(); if (Instances.ContainsKey(uid)) { return false; } InstanceInfo instanceInfo = new InstanceInfo(uid, template_uid); if (!instanceInfo.SetTarget(target)) { return false; } Instances.Add(uid, instanceInfo); return true; } public static void Verify() { List<string> list = new List<string>(); foreach (KeyValuePair<string, InstanceInfo> instance in Instances) { if (instance.Value == null || !instance.Value.IsValid()) { list.Add(instance.Key); } } foreach (string item in list) { Remove(item); } } public static void RemoveInstancesFromTarget(Transform target) { InstanceInfo[] instancesInTarget = GetInstancesInTarget(target); for (int i = 0; i < instancesInTarget.Length; i++) { Remove(instancesInTarget[i]?.ID); } } public static void RemoveInstancesFromTargetChildren(Transform target) { InstanceInfo[] instancesInTargetChildren = GetInstancesInTargetChildren(target); for (int i = 0; i < instancesInTargetChildren.Length; i++) { Remove(instancesInTargetChildren[i]?.ID); } } public static void RemoveInstancesFromTargetParent(Transform target) { InstanceInfo[] instancesInTargetParent = GetInstancesInTargetParent(target); for (int i = 0; i < instancesInTargetParent.Length; i++) { Remove(instancesInTargetParent[i]?.ID); } } public static void Remove(string uid) { try { if (!string.IsNullOrWhiteSpace(uid) && Instances.TryGetValue(uid, out var value)) { value?.PrepareRemove(); Instances.Remove(uid); } } catch { Debug.LogWarning((object)("Unable to remove Instance ID : \"" + uid + "\" Ignoring.")); } } public static void ResetInstance(string uid) { if (!string.IsNullOrWhiteSpace(uid) && Instances.TryGetValue(uid, out var value)) { value?.Reset(); } } public static void Reset() { foreach (string item in new List<string>(Instances.Keys)) { Remove(item); } Instances.Clear(); } } public class InstanceReferencer { private WeakReference<InstanceInfo> _Instance_Reference = new WeakReference<InstanceInfo>(null); public InstanceInfo Instance { get { _Instance_Reference.TryGetTarget(out var target); return target; } set { _Instance_Reference.SetTarget(value); } } } public class HandlerReferencer { private WeakReference<UCustomPrefabHandler> _Handler_Reference = new WeakReference<UCustomPrefabHandler>(null); public UCustomPrefabHandler Handler { get { _Handler_Reference.TryGetTarget(out var target); return target; } set { _Handler_Reference.SetTarget(value); } } } public class UCustomPrefabHandler : MonoBehaviour { private InstanceReferencer _instanceReferencer = new InstanceReferencer(); private Dictionary<Type, CustomActionsBase> RegisteredCustomActions = new Dictionary<Type, CustomActionsBase>(); public Dictionary<string, Dictionary<string, PrefabTemplate>> Templates = new Dictionary<string, Dictionary<string, PrefabTemplate>>(); private bool IsDestroyed; public InstanceInfo Instance { get { return _instanceReferencer.Instance; } set { _instanceReferencer.Instance = value; } } public ActionStateMachine StateMachine { get; private set; } = new ActionStateMachine(); public Dictionary<string, PrefabTemplate> LoadedTemplates { get; private set; } = new Dictionary<string, PrefabTemplate>(); public void Initialize() { AddState("init"); AddState("default"); RegisterTemplate(); InitializeAndRegisterCustomActions(); SetState("default"); } public void SetState(string name, bool reset = true) { string state = StateMachine.State; StateMachine.Do_OnExit(); ResetTemplates(); InstantiateStateTemplates(name); StateMachine.SetState(name); StateMachine.Do_OnEnter(); StateMachine.Do_OnStateChanged(state); } public void AddState(string name) { if (!StateMachine.HasState(name)) { StateMachine.AddState(name); Templates.Add(name, new Dictionary<string, PrefabTemplate>()); } } public bool TryGetCustomActions<T>(out T customActions) where T : CustomActionsBase { customActions = null; if (RegisteredCustomActions.TryGetValue(typeof(T), out var value)) { customActions = (T)value; } return customActions != null; } public T RegisterCustomActions<T>(object[] data = null, int priority = -1) where T : CustomActionsBase { return (T)RegisterCustomActions(typeof(T), data, priority); } public CustomActionsBase RegisterCustomActions(Type type, object[] data = null, int priority = -1) { if (RegisteredCustomActions.TryGetValue(type, out var value)) { return value; } value = (CustomActionsBase)Activator.CreateInstance(type); if (value == null) { return null; } value.Priority = priority; value.HandleTemplateData(data); RegisteredCustomActions.Add(type, value); return value; } public void InitializeAndRegisterCustomActions() { foreach (KeyValuePair<Type, CustomActionsBase> item in RegisteredCustomActions.OrderBy((KeyValuePair<Type, CustomActionsBase> x) => x.Value.Priority)) { CustomActionsBase value = item.Value; value.Handler = this; value.RegisterActions(); } } public void RegisterTemplate() { if (Instance == null || !TemplateRegistry.TryGetTemplate(Instance.TemplateUID, out var template)) { return; } for (int i = 0; i < template.Templates.Count; i++) { PrefabTemplate prefabTemplate = template.Templates[i]; if (!Templates.ContainsKey(prefabTemplate.State)) { AddState(prefabTemplate.State); } Templates[prefabTemplate.State].Add($"{template.UID}:{i}", prefabTemplate); } foreach (KeyValuePair<Type, object[]> customAction in template.GetCustomActions()) { RegisterCustomActions(customAction.Key, (object[])customAction.Value[1], (int)customAction.Value[0]); } } public void ResetTemplates(bool includePersistent = false) { List<string> list = new List<string>(); foreach (KeyValuePair<string, PrefabTemplate> loadedTemplate in LoadedTemplates) { if ((Object)(object)loadedTemplate.Value == (Object)null || !loadedTemplate.Value.Persistent || includePersistent) { list.Add(loadedTemplate.Key); } } foreach (string item in list) { PrefabTemplate prefabTemplate = LoadedTemplates[item]; if ((Object)(object)prefabTemplate != (Object)null) { Object.Destroy((Object)(object)((Component)prefabTemplate).gameObject); } LoadedTemplates.Remove(item); } } public void InstantiateTemplate(string uid, PrefabTemplate template) { if (!LoadedTemplates.ContainsKey(uid) && !((Object)(object)template == (Object)null)) { template = Object.Instantiate<GameObject>(((Component)template).gameObject, ((Component)this).transform).GetComponent<PrefabTemplate>(); LoadedTemplates.Add(uid, template); } } public void InstantiateStateTemplates(string state) { if (!Templates.TryGetValue(state, out var value)) { return; } foreach (KeyValuePair<string, PrefabTemplate> item in value) { InstantiateTemplate(item.Key, item.Value); } } public PrefabTemplate GetTemplateWithTag(params string[] tags) { foreach (KeyValuePair<string, PrefabTemplate> loadedTemplate in LoadedTemplates) { if (loadedTemplate.Value.HasTag(tags)) { return loadedTemplate.Value; } } return null; } public List<PrefabTemplate> GetTemplatesWithTag(params string[] tags) { List<PrefabTemplate> list = new List<PrefabTemplate>(); foreach (KeyValuePair<string, PrefabTemplate> loadedTemplate in LoadedTemplates) { if (loadedTemplate.Value.HasTag(tags)) { list.Add(loadedTemplate.Value); } } return list; } public TaggedBehaviour GetTagInTemplates(params string[] tags) { foreach (KeyValuePair<string, PrefabTemplate> loadedTemplate in LoadedTemplates) { if (loadedTemplate.Value.HasTag(tags)) { return loadedTemplate.Value; } foreach (TaggedBehaviour item in loadedTemplate.Value.FindTagsInChildren(tags)) { if ((Object)(object)item != (Object)null) { return item; } } } return null; } public List<TaggedBehaviour> GetTagsInTemplates(params string[] tags) { List<TaggedBehaviour> list = new List<TaggedBehaviour>(); foreach (KeyValuePair<string, PrefabTemplate> loadedTemplate in LoadedTemplates) { if (loadedTemplate.Value.HasTag(tags)) { list.Add(loadedTemplate.Value); } list.AddRange(loadedTemplate.Value.FindTagsInChildren(tags)); } return list; } private void Update() { if (!IsDestroyed) { StateMachine.Update(); } } private void FixedUpdate() { } private void LateUpdate() { } private void OnDestroy() { HandleDestroy(); } public void HandleDestroy(bool reset = true) { if (IsDestroyed) { return; } ((Behaviour)this).enabled = false; IsDestroyed = true; StateMachine.Destroy(); ResetTemplates(includePersistent: true); if (Instance != null) { Instance.DestroyHandler(reset: false, destroy: false); if (reset) { Instance.Reset(); } else { InstanceManager.Verify(); } } Object.Destroy((Object)(object)this); } } public static class TemplateRegistry { public class TemplateData { public string UID; public GameObject Container; public List<CustomActionsTemplate> CustomActionsTemplates = new List<CustomActionsTemplate>(); public List<PrefabTemplate> Templates = new List<PrefabTemplate>(); public TemplateData(string uid) { UID = uid; } public void InstantiateContainer() { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown Reset(); GameObject val = new GameObject(UID ?? ""); val.transform.parent = TemplateContainer.transform; Container = val; ((Object)Container).hideFlags = (HideFlags)61; Container.SetActive(false); } public void InstantiatePrefab(GameObject prefab) { Reset(); GameObject val = Object.Instantiate<GameObject>(prefab, TemplateContainer.transform); if (Object.op_Implicit((Object)(object)val)) { Container = val; ((Object)Container).hideFlags = (HideFlags)61; Container.SetActive(false); CustomActionsTemplate[] components = Container.GetComponents<CustomActionsTemplate>(); foreach (CustomActionsTemplate customActions in components) { AddCustomActionsTemplate(customActions); } PrefabTemplate[] componentsInChildren = Container.GetComponentsInChildren<PrefabTemplate>(true); foreach (PrefabTemplate prefab2 in componentsInChildren) { AddTemplate(prefab2); } } } public T InstantiateCustomActionsTemplate<T>() where T : CustomActionsTemplate { if (!Object.op_Implicit((Object)(object)Container)) { Debug.LogWarning((object)"Could not add CustomActionsTemplate. : Container Missing...!"); return null; } return Container.AddComponent<T>(); } public void InstantiateTemplate(GameObject prefab) { if (!Object.op_Implicit((Object)(object)Container)) { Debug.LogWarning((object)"Could not instatiate Template. : Container Missing...!"); return; } GameObject val = Object.Instantiate<GameObject>(prefab, Container.transform); if (!Object.op_Implicit((Object)(object)val)) { Debug.LogWarning((object)"Could not instatiate Template. : Invalid Prefab...!"); return; } PrefabTemplate component = val.GetComponent<PrefabTemplate>(); if (!Object.op_Implicit((Object)(object)component)) { Debug.LogWarning((object)"Template does not have PrefabTemplate component."); } else { AddTemplate(component); } } public void AddCustomActionsTemplate(CustomActionsTemplate customActions) { CustomActionsTemplates.Add(customActions); } public void AddTemplate(PrefabTemplate prefab, bool reParent = false) { if (Object.op_Implicit((Object)(object)prefab)) { if (reParent) { ((Component)prefab).transform.parent = Container.transform; } Templates.Add(prefab); } } public Dictionary<Type, object[]> GetCustomActions() { Dictionary<Type, object[]> dictionary = new Dictionary<Type, object[]>(); foreach (CustomActionsTemplate customActionsTemplate in CustomActionsTemplates) { Type type = customActionsTemplate.RegisterCustomActionsBaseType(); if (type != null && !dictionary.ContainsKey(type)) { dictionary.Add(type, new object[2] { customActionsTemplate.Priority, customActionsTemplate.PrepareTemplateData() }); } } return dictionary; } public void Reset() { Object.DestroyImmediate((Object)(object)Container); CustomActionsTemplates.Clear(); Templates.Clear(); } } private static Dictionary<string, TemplateData> TemplateDatas = new Dictionary<string, TemplateData>(); private static readonly List<string> ReservedNames = new List<string> { "none" }; private static GameObject _templateContainer; private static Queue<string> _LateRegistry = new Queue<string>(); public static string Default { get; private set; } = string.Empty; public static GameObject TemplateContainer { get { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown if ((Object)(object)_templateContainer == (Object)null) { _templateContainer = new GameObject("UCustomPrefabsAPI_Templates"); Object.DontDestroyOnLoad((Object)(object)_templateContainer); ((Object)_templateContainer).hideFlags = (HideFlags)61; _templateContainer.SetActive(false); } return _templateContainer; } } public static void SetDefault(string uid) { if (TemplateDatas.ContainsKey(uid)) { Default = uid; } else { Debug.LogWarning((object)("Tempate uid : \"" + uid + "\" is not registered.")); } } public static bool TryGetTemplate(string uid, out TemplateData template) { bool flag = TemplateDatas.TryGetValue(uid, out template); if (!flag) { flag = TemplateDatas.TryGetValue(Default, out template); Debug.LogWarning((object)("Default Template will be used instead of Template uid : \"" + uid + "\"")); } return flag; } public static void Register(string uid, GameObject prefab) { if (ReservedNames.Contains(uid.ToLower())) { Debug.LogWarning((object)("Template uid : \"" + uid + "\" is reserved.")); return; } if (TemplateDatas.ContainsKey(uid)) { Debug.LogWarning((object)("Template uid : \"" + uid + "\" already registered.")); return; } if (!Object.op_Implicit((Object)(object)prefab)) { Debug.LogWarning((object)("Template uid : \"" + uid + "\" prefab is invalid.")); return; } TemplateData templateData = new TemplateData(uid); templateData.InstantiatePrefab(prefab); TemplateDatas.Add(uid, templateData); } public static void LateRegister(string uid, string assetbundle, string prefabPath) { _LateRegistry.Enqueue(uid); _LateRegistry.Enqueue(assetbundle); _LateRegistry.Enqueue(prefabPath); } public static void CommitLateRegistry() { while (_LateRegistry.Count > 0) { string uid = _LateRegistry.Dequeue(); string assetbundleName = _LateRegistry.Dequeue(); string name = _LateRegistry.Dequeue(); GameObject val = AssetBundleRegistry.LoadPrefab(assetbundleName, name); if (!((Object)(object)val == (Object)null)) { Register(uid, val); } } } public static void RegisterEmpty(string uid) { if (TemplateDatas.ContainsKey(uid)) { Debug.LogWarning((object)("Template uid : \"" + uid + "\" already registered.")); return; } TemplateData templateData = new TemplateData(uid); templateData.InstantiateContainer(); TemplateDatas.Add(uid, templateData); } public static List<string> GetTemplatesWithCustomActions<T>() where T : CustomActionsBase { return GetTemplatesWithCustomActions(typeof(T)); } public static List<string> GetTemplatesWithCustomActions(string customAction_uid) { if (!CustomActionsRegistry.TryGetActions(customAction_uid, out var actionsType)) { return new List<string>(); } return GetTemplatesWithCustomActions(actionsType); } private static List<string> GetTemplatesWithCustomActions(Type customAction_type) { List<string> list = new List<string>(); foreach (KeyValuePair<string, TemplateData> templateData in TemplateDatas) { foreach (CustomActionsTemplate customActionsTemplate in templateData.Value.CustomActionsTemplates) { Type type = customActionsTemplate.RegisterCustomActionsBaseType(); if (!(type == null) && type == customAction_type) { list.Add(templateData.Key); } } } return list; } } public abstract class CustomActionsTemplate : MonoBehaviour { public int Priority; public abstract Type RegisterCustomActionsBaseType(); public virtual object[] PrepareTemplateData() { return null; } } public class PrefabTemplate : TaggedBehaviour { [Tooltip("Determines if this template get's removed on state change.")] public bool Persistent; [Tooltip("State this template is instantiated.")] public string State = "default"; } } namespace UCustomPrefabsAPI.Extras.Utility { public static class SearchUtils { public static Transform RecursivelyFindChild(Transform parent, string name) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Expected O, but got Unknown Debug.Log((object)("RecursivelyFindChild " + ((Object)parent).name + ":" + name)); foreach (Transform item in parent) { Transform val = item; if (((Object)val).name == name) { return val; } Transform val2 = RecursivelyFindChild(val, name); if (Object.op_Implicit((Object)(object)val2)) { return val2; } } return null; } public static Transform IterativelyFindChild(Transform parent, string name) { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Expected O, but got Unknown Debug.Log((object)("IterativelyFindChild " + ((Object)parent).name + ":" + name)); Queue<Transform> queue = new Queue<Transform>(); queue.Enqueue(parent); while (queue.Count != 0) { foreach (Transform item in queue.Dequeue()) { Transform val = item; if (((Object)val).name == name) { return val; } queue.Enqueue(val); } } return null; } public static void RecursivelyCollectChildNames(Transform target, ref Dictionary<string, Transform> looseNameRefs) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Expected O, but got Unknown Debug.Log((object)("RecursivelyCollectChildNames " + ((Object)target).name)); if (looseNameRefs == null) { looseNameRefs = new Dictionary<string, Transform>(); } foreach (Transform item in target) { Transform val = item; if (!looseNameRefs.ContainsKey(((Object)val).name)) { looseNameRefs.Add(((Object)val).name, val); } if (val.childCount > 0) { RecursivelyCollectChildNames(val, ref looseNameRefs); } } } public static void IterativelyCollectChildNames(Transform target, ref Dictionary<string, Transform> looseNameRefs) { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Expected O, but got Unknown Debug.Log((object)("IterativelyCollectChildNames " + ((Object)target).name)); if (looseNameRefs == null) { looseNameRefs = new Dictionary<string, Transform>(); } Queue<Transform> queue = new Queue<Transform>(); queue.Enqueue(target); while (queue.Count != 0) { foreach (Transform item in queue.Dequeue()) { Transform val = item; if (!looseNameRefs.ContainsKey(((Object)val).name)) { looseNameRefs.Add(((Object)val).name, val); } queue.Enqueue(val); } } } public static void FixPaths(ref string[] paths, string replace, string with) { for (int i = 0; i < paths.Length; i++) { paths[i] = paths[i].Replace(replace, with); } } public static string FindPath(Transform root, Transform target) { string text = (Object.op_Implicit((Object)(object)target) ? ((Object)target).name : string.Empty); while ((Object)(object)target != (Object)null && (Object)(object)target.parent != (Object)(object)root) { target = target.parent; text = ((Object)target).name + "/" + text; } return text; } public static string RelativeFindPath(Transform origin, Transform target) { HashSet<Transform> hashSet = MapParentHierarchy(target); string text = string.Empty; if (hashSet.Contains(origin)) { text = FindPath(origin, target); } else { foreach (Transform item in MapParentHierarchy(origin)) { text += "../"; if (hashSet.Contains(item)) { text += FindPath(item, target); break; } } } return text; } public static Transform RelativeFind(Transform origin, string relativePath) { Queue<string> queue = new Queue<string>(relativePath.Split(new char[1] { '/' })); Transform val = origin; try { while ((Object)(object)val != (Object)null && queue.Count > 0) { string text = queue.Dequeue(); switch (text) { case "..": val = val.parent; break; case "*": val = IterativelyFindChild(origin, queue.Dequeue()); break; case "**": val = FindParent(val, queue.Dequeue()); break; case "|": { string assetbundleName = queue.Dequeue(); string name = queue.Dequeue(); Transform val3 = IterativelyFindChild(val, assetbundleName); if (!Object.op_Implicit((Object)(object)val3)) { val3 = IterativelyFindChild(val, name); } val = val3; break; } case "||": { string assetbundleName = queue.Dequeue(); string name = queue.Dequeue(); Transform val3 = FindParent(val, assetbundleName); if (!Object.op_Implicit((Object)(object)val3)) { val3 = FindParent(val, name); } val = val3; break; } case "@": { string assetbundleName = queue.Dequeue(); GameObject val2 = AssetBundleRegistry.LoadPrefab(assetbundleName, string.Join("/", queue)); if (Object.op_Implicit((Object)(object)val2)) { val = val2.transform; } break; } default: val = val.Find(text); break; } } } catch (Exception) { Debug.LogError((object)"Invalid Relative Path."); val = null; } return val; } public static Transform FindParent(Transform origin, string name) { Debug.Log((object)$"FindParent {origin}:{name}"); bool flag = false; Transform val = origin; while (!flag && (Object)(object)val != (Object)null) { val = val.parent; if (((Object)val).name == name) { flag = true; } } if (!flag) { return null; } return val; } public static HashSet<Transform> MapParentHierarchy(Transform root) { HashSet<Transform> hashSet = new HashSet<Transform>(); while ((Object)(object)root.parent != (Object)null) { hashSet.Add(root.parent); root = root.parent; } return hashSet; } } public class TaggedBehaviour : MonoBehaviour { [Tooltip("WIP Tags to help organize things in UCustomPrefabs.")] public string[] Tags; private HashSet<string> _tagset; public HashSet<string> TagSet { get { if (_tagset == null) { _tagset = new HashSet<string>(); InitTags(); } return _tagset; } } private void InitTags() { string[] tags = Tags; foreach (string item in tags) { _tagset.Add(item); } } public virtual void AddTag(params string[] tags) { foreach (string item in tags) { TagSet.Add(item); } } public virtual void RemoveTag(params string[] tags) { foreach (string item in tags) { TagSet.Remove(item); } } public virtual bool HasTag(params string[] tags) { foreach (string item in tags) { if (!TagSet.Contains(item)) { return false; } } return tags.Length != 0; } public virtual void ClearTags() { TagSet.Clear(); } public virtual TaggedBehaviour FindTagInChildren(params string[] tags) { TaggedBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<TaggedBehaviour>(true); foreach (TaggedBehaviour taggedBehaviour in componentsInChildren) { if (taggedBehaviour.HasTag(tags)) { return taggedBehaviour; } } return null; } public virtual List<TaggedBehaviour> FindTagsInChildren(params string[] tags) { List<TaggedBehaviour> list = new List<TaggedBehaviour>(); TaggedBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<TaggedBehaviour>(true); foreach (TaggedBehaviour taggedBehaviour in componentsInChildren) { if (taggedBehaviour.HasTag(tags)) { list.Add(taggedBehaviour); } } return list; } } public class TaggedData : TaggedBehaviour { [Tooltip("WIP Tag Data to help serialize things in UCustomPrefabs.")] public string[] Data; private Dictionary<string, string> _tagdata; public Dictionary<string, string> TagData { get { if (_tagdata == null) { _tagdata = new Dictionary<string, string>(); InitTagData(); } return _tagdata; } } private void InitTagData() { for (int i = 0; i < Data.Length && i < Tags.Length; i++) { try { _tagdata.Add(Tags[i], Data[i]); } catch (Exception ex) { Debug.LogError((object)ex); } } } public override void AddTag(params string[] tags) { for (int i = 0; i + 1 < tags.Length; i += 2) { base.TagSet.Add(tags[i]); try { TagData.Add(tags[i], tags[i + 1]); } catch (Exception ex) { Debug.LogError((object)ex); } } } public override void RemoveTag(params string[] tags) { foreach (string text in tags) { base.TagSet.Remove(text); try { TagData.Remove(text); } catch (Exception ex) { Debug.LogError((object)ex); } } } public bool TryGetTagData(string tag, out string data) { return TagData.TryGetValue(tag, out data); } } } namespace UCustomPrefabsAPI.Extras.Utility.Serialization { public abstract class MonobehaviourSerialized : MonoBehaviour, ISerializationCallbackReceiver { public string Data = string.Empty; public void OnAfterDeserialize() { if (!string.IsNullOrWhiteSpace(Data)) { string data = Data; JsonUtility.FromJsonOverwrite(Data, (object)this); Data = data; } } public void OnBeforeSerialize() { Data = string.Empty; Data = JsonUtility.ToJson((object)this); } } } namespace UCustomPrefabsAPI.Extras.Tokens { public static class TokenRegistry { private static Dictionary<string, string> _tokens = new Dictionary<string, string>(); private static Dictionary<string, HashSet<Action<string>>> _listeners = new Dictionary<string, HashSet<Action<string>>>(); public static void SetToken(string token, string data) { if (!_tokens.ContainsKey(token)) { _tokens.Add(token, data); } else { _tokens[token] = data; } } public static string GetToken(string token) { if (!_tokens.TryGetValue(token, out var value)) { return string.Empty; } return value; } public static void InvokeListeners(string token) { if (!_listeners.TryGetValue(token, out var value)) { return; } foreach (Action<string> item in value) { try { item?.Invoke(token); } catch (Exception ex) { Debug.LogError((object)ex); } } } public static void Listen(string token, Action<string> action) { if (!_listeners.TryGetValue(token, out var value)) { value = new HashSet<Action<string>>(); _listeners.Add(token, value); } value.Add(action); } public static void StopListening(string token, Action<string> action) { if (_listeners.TryGetValue(token, out var value)) { value.Remove(action); } } public static void RemoveListeners(string token) { if (_listeners.TryGetValue(token, out var value)) { value.Clear(); } } } } namespace UCustomPrefabsAPI.Extras.Profiles { public class Profile { private Dictionary<string, ProfileData> _data = new Dictionary<string, ProfileData>(); private List<ProfileData> _list = new List<ProfileData>(); private bool locked; private WeakReference<ProfileManager> _manager; private const char START_TAG = '['; private const char END_TAG = ']'; public int Count => _list.Count; public ProfileManager Manager { get { if (_manager != null && _manager.TryGetTarget(out var target)) { return target; } return null; } } public void SetManager(ProfileManager manager) { if (manager != null) { _manager = new WeakReference<ProfileManager>(manager); } } public Profile(ProfileManager manager) { SetManager(manager); } public Profile Clone() { Profile profile = new Profile(Manager); foreach (KeyValuePair<string, ProfileData> datum in _data) { ProfileData value = datum.Value; profile.SetData(datum.Key, value.Data, value.GetType()); } foreach (KeyValuePair<string, ProfileData> datum2 in _data) { ProfileData value2 = datum2.Value; int index = _list.IndexOf(value2); profile.SetDataIndex(datum2.Key, index); } return profile; } public void SetData(string key, object value, Type type) { if (Manager == null) { return; } if (!_data.TryGetValue(key, out var value2) && !locked) { if (!Manager.TryInstantiateDataType(type, out value2)) { _data.Add(key, value2); } _list.Add(value2); value2.Data = value; } else { value2.Data = value; } } public void SetData<T>(string key, T value) { SetData(key, value, typeof(T)); } public T GetData<T>(string key) { TryGetData<T>(key, out var value); return value; } public bool TryGetData<T>(string key, out T value) { ProfileData value2; bool num = _data.TryGetValue(key, out value2); if (num) { value = (T)value2.Data; return num; } value = default(T); return num; } public bool HasData(string key) { return _data.ContainsKey(key); } public void RemoveData(string key) { if (!locked && _data.TryGetValue(key, out var value)) { _data.Remove(key); _list.Remove(value); } } public void PurgeData() { if (!locked) { _data.Clear(); _list.Clear(); } } public void SetDataIndex(string key, int index) { if (!locked && _data.TryGetValue(key, out var value) && _list.IndexOf(value) != index) { _list.Remove(value); _list.Insert(index, value); } } public int GetDataIndex(string key) { if (!_data.TryGetValue(key, out var value)) { return -1; } return _list.IndexOf(value); } public void LockEdits() { locked = true; } public string Serialize(bool useChecksum = true) { List<string> list = new List<string>(); for (int i = 0; i < Count; i++) { list.Add(string.Empty); } foreach (KeyValuePair<string, ProfileData> datum in _data) { ProfileData value = datum.Value; string text = value.Serailize(); if (value.Size == -1) { text = $"{'['}{text}{']'}"; } list[GetDataIndex(datum.Key)] = text; } string text2 = string.Join(string.Empty, list); if (useChecksum) { text2 = GenerateChecksum(text2) + text2; } return text2; } public void Deserialize(string input, bool hasChecksum = true, int offset = 0) { if (hasChecksum && !ValidateChecksum(input)) { Debug.LogWarning((object)"Profile data does not match checksum--"); Debug.LogWarning((object)"data may be incorrect... Ignoring"); return; } int num = (hasChecksum ? 1 : 0); for (int i = offset; i < _list.Count; i++) { ProfileData profileData = _list[i]; int num2 = profileData.Size; bool flag = num2 == -1; if (flag) { num2 = FindDataSize(input, num); } if (num2 > 0) { string data = ((!flag) ? input.Substring(num, num2) : input.Substring(num + 1, num2 - 1)); profileData.Deserialize(data); num += num2; } } } private bool ValidateChecksum(string input) { char num = input[0]; char c = GenerateChecksum(input, 1); return num == c; } private char GenerateChecksum(string input, int offset = 0) { int i = offset; char c = '#'; for (; i < input.Length; i++) { char c2 = input[i]; c ^= c2; bool num = c % 2 == 0; c = (char)(c % 26 + 65); c = (num ? char.ToUpper(c) : char.ToLower(c)); } return c; } private int FindDataSize(string input, int pointer) { pointer = input.IndexOf('[', pointer); if (pointer < 0) { return -1; } int num = 0; int num2 = 0; while (pointer < input.Length) { switch (input[pointer]) { case '[': num2++; break; case ']': num2--; break; } if (num2 == 0) { break; } num++; pointer++; } return num; } } public abstract class ProfileData { public object Data { get; set; } public Type Type { get; set; } = typeof(string); public int Size { get; set; } = -1; public virtual bool TryGet<T>(out T data) { data = default(T); int num; if (Data != null) { num = (Type.IsInstanceOfType(typeof(T)) ? 1 : 0); if (num != 0) { data = (T)Data; return (byte)num != 0; } } else { num = 0; } Debug.Log((object)"Data is invalid."); return (byte)num != 0; } public virtual string Serailize() { if (Data == null) { return null; } string text = Data.ToString(); if (Size != -1) { try { text = text.Substring(0, Size); } catch (Exception) { Debug.Log((object)"Data is too small."); } } return text; } public virtual void Deserialize(string data) { if (string.IsNullOrEmpty(data)) { return; } if (Size != -1) { try { data = data.Substring(0, Size); } catch (Exception) { Debug.Log((object)"Data is too small."); } } Data = data; } } public class ProfileManager { private Dictionary<string, Profile> Profiles = new Dictionary<string, Profile>(); private Profile Template; private Dictionary<Type, Type> DataTypes = new Dictionary<Type, Type> { { typeof(string), typeof(ProfileData) }, { typeof(float), typeof(ProfileData_Float) }, { typeof(int), typeof(ProfileData_Integer) }, { typeof(bool), typeof(ProfileData_Boolean) }, { typeof(char), typeof(ProfileData_Char) } }; public Profile InstantiateProfile() { return new Profile(this); } public Profile CreateProfile(string name) { if (Template == null) { return null; } if (TryGetProfile(name, out var config)) { return config; } config = Template.Clone(); config.LockEdits(); Profiles.Add(name, config); return config; } public bool TryGetProfile(string name, out Profile config) { return Profiles.TryGetValue(name, out config); } public void RegisterTemplate(Profile profile) { ClearTemplate(); Template = profile; } public void ClearProfiles() { Profiles.Clear(); } public void ClearTemplate() { Template = null; } public void RegisterDataType<T>(Type type) where T : ProfileData { try { DataTypes.Add(type, typeof(T)); } catch (ArgumentException) { Console.WriteLine("Data Type Already Registered."); } } public bool TryInstantiateDataType(Type type, out ProfileData data) { data = null; if (DataTypes.TryGetValue(type, out var value)) { data = (ProfileData)Activator.CreateInstance(value); } return data != null; } } internal static class ProfileRegistry { private static Dictionary<string, ProfileManager> ProfileManagers = new Dictionary<string, ProfileManager>(); public static ProfileManager CreateProfileManager(string uid) { if (ProfileManagers.TryGetValue(uid, out var value)) { return value; } value = new ProfileManager(); ProfileManagers.Add(uid, value); return value; } public static Profile CreateProfile(string uid, string name) { ProfileManagers.TryGetValue(uid, out var value); return value?.CreateProfile(name); } public static void RegisterProfileTemplate(string uid, Profile template) { ProfileManagers.TryGetValue(uid, out var value); value?.RegisterTemplate(template); } public static bool TryGetProfile(string uid, string name, out Profile profile) { profile = null; if (!ProfileManagers.TryGetValue(uid, out var value)) { return false; } return value.TryGetProfile(name, out profile); } } public class ProfileData_Float : ProfileData { public ProfileData_Float() { base.Type = typeof(float); } public override void Deserialize(string data) { if (float.TryParse(data, out var result)) { base.Data = result; } } } public class ProfileData_Integer : ProfileData { public ProfileData_Integer() { base.Type = typeof(int); } public override void Deserialize(string data) { if (int.TryParse(data, out var result)) { base.Data = result; } } } public class ProfileData_Boolean : ProfileData { public ProfileData_Boolean() { base.Type = typeof(bool); base.Size = 1; } public override string Serailize() { if (!TryGet<bool>(out var data)) { return "0"; } if (!data) { return "0"; } return "1"; } public override void Deserialize(string data) { if (string.IsNullOrEmpty(data)) { return; } bool result; if (data.Length == 1) { switch (data.ToUpper()) { case "T": base.Data = true; break; case "F": base.Data = false; break; case "1": base.Data = true; break; case "0": base.Data = false; break; } } else if (bool.TryParse(data, out result)) { base.Data = result; } } } public class ProfileData_Char : ProfileData { public ProfileData_Char() { base.Type = typeof(char); base.Size = 1; } public override void Deserialize(string data) { if (!string.IsNullOrEmpty(data) && data.Length > 0) { base.Data = data[0]; } } } } namespace UCustomPrefabsAPI.Extras.CustomActions { public static class CustomActionsRegistry { private static Dictionary<string, Type> RegisteredCustomActions = new Dictionary<string, Type>(); public static bool TryGetActions(string uid, out Type actionsType) { return RegisteredCustomActions.TryGetValue(uid, out actionsType); } public static void Register<T>(string uid) where T : CustomActionsBase { if (RegisteredCustomActions.ContainsKey(uid)) { Debug.LogWarning((object)("CustomActions uid : \"" + uid + "\" already registered.")); } else { RegisteredCustomActions.Add(uid, typeof(T)); } } } public class LooseReferenceAction : CustomActionsTemplate { [SerializeField] public string CustomActionName; [SerializeField] public string Data; public override Type RegisterCustomActionsBaseType() { CustomActionsRegistry.TryGetActions(CustomActionName, out var actionsType); return actionsType; } public override object[] PrepareTemplateData() { return new object[1] { Data }; } } } namespace UCustomPrefabsAPI.Extras.AssetBundles { public class AssetBundleData { public string name; public string path; public bool embedded; public Assembly assembly; public AssetBundle assetbundle; public AssetBundleData(Type origin, string path, string name = null, bool embedded = false) { assembly = origin.Assembly; this.path = path; this.embedded = embedded; if (string.IsNullOrWhiteSpace(name)) { name = Path.GetFileName(path); } this.name = name; } public bool LoadAssetBundle() { if (string.IsNullOrWhiteSpace(path)) { return false; } if (embedded) { return LoadEmbedded(); } return Load(); } private bool Load() { assetbundle = null; try { string text = Path.Combine(Path.GetDirectoryName(assembly.Location), path); assetbundle = AssetBundle.LoadFromFile(text); } catch (Exception ex) { Debug.Log((object)"Unable to load assetbundle. Make sure your pathing is correct."); Debug.Log((object)"Make sure to use LoadEmbeddedAssetBundle if using an embedded resource"); Debug.LogError((object)ex); } if (!Object.op_Implicit((Object)(object)assetbundle)) { return false; } embedded = false; return true; } private bool LoadEmbedded() { assetbundle = null; try { string text = path.Replace('\\', '.'); text = text.Replace('/', '.'); text = assembly.FullName.Split(new char[1] { ',' })[0] + "." + text; using Stream stream = assembly.GetManifestResourceStream(text); assetbundle = AssetBundle.LoadFromStream(stream); } catch (Exception ex) { Debug.Log((object)"Unable to load assetbundle. Make sure your pathing is correct."); Debug.Log((object)"Embedded Resources use \".\" instead of the usual \"\\\"."); Debug.LogError((object)ex); } if (!Object.op_Implicit((Object)(object)assetbundle)) { return false; } return true; } public GameObject LoadPrefab(string name) { AssetBundle obj = assetbundle; if (obj == null) { return null; } return obj.LoadAsset<GameObject>(name); } public T LoadAsset<T>(string name) where T : Object { AssetBundle obj = assetbundle; if (obj == null) { return default(T); } return obj.LoadAsset<T>(name); } public void Unload(bool unloadAllLoadedObjects) { AssetBundle obj = assetbundle; if (obj != null) { obj.Unload(unloadAllLoadedObjects); } } } public static class AssetBundleRegistry { private static Dictionary<string, AssetBundleData> AssetBundles = new Dictionary<string, AssetBundleData>(); public static bool Register<T>(string path, string name = null) { AssetBundleData assetBundleData = new AssetBundleData(typeof(T), path, name); if (HasAssetBundle(assetBundleData.name) || !assetBundleData.LoadAssetBundle()) { return false; } AssetBundles.Add(assetBundleData.name, assetBundleData); return true; } public static bool Register<T>(string path, out string name) { name = null; AssetBundleData assetBundleData = new AssetBundleData(typeof(T), path); if (HasAssetBundle(assetBundleData.name) || !assetBundleData.LoadAssetBundle()) { return false; } AssetBundles.Add(assetBundleData.name, assetBundleData); name = assetBundleData.name; return true; } public static void RegisterEmbedded<T>(string path, string name = null) { AssetBundleData assetBundleData = new AssetBundleData(typeof(T), path, name, embedded: true); if (!HasAssetBundle(assetBundleData.name) && assetBundleData.LoadAssetBundle()) { AssetBundles.Add(assetBundleData.name, assetBundleData); } } public static void Remove(string assetbundleName, bool unloadAllLoadedObjects) { if (AssetBundles.TryGetValue(assetbundleName, out var value)) { value.Unload(unloadAllLoadedObjects); AssetBundles.Remove(assetbundleName); } } public static bool HasAssetBundle(string name) { return AssetBundles.ContainsKey(name); } public static GameObject LoadPrefab(string assetbundleName, string name) { if (!AssetBundles.TryGetValue(assetbundleName, out var value)) { return null; } return value.LoadPrefab(name); } public static T LoadAsset<T>(string assetbundleName, string name) where T : Object { if (!AssetBundles.TryGetValue(assetbundleName, out var value)) { return default(T); } return value.LoadAsset<T>(name); } } } namespace UCustomPrefabsAPI.Extras.Animation { [Serializable] public class BoneMapPair { public string origin = string.Empty; public string target = string.Empty; } [Serializable] public class BoneMap { public bool UsePaths; private Dictionary<string, BoneMapPair> _dict = new Dictionary<string, BoneMapPair>(); public List<BoneMapPair> bonePairs = new List<BoneMapPair>(); public void AddDefaultHumanBoneNames() { //IL_0013: Unknown result type (might be due to invalid IL or missing references) ClearPairs(); HumanBodyBones[] humanBodyBonesAry = RigUtilities.HumanBodyBonesAry; for (int i = 0; i < humanBodyBonesAry.Length; i++) { HumanBodyBones val = humanBodyBonesAry[i]; AddPair(((object)(HumanBodyBones)(ref val)).ToString(), string.Empty); } } public void AddHumanBones(Animator animator) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)animator)) { Debug.LogWarning((object)"Animator not found."); return; } ClearPairs(); HumanBodyBones[] humanBodyBonesAry = RigUtilities.HumanBodyBonesAry; foreach (HumanBodyBones val in humanBodyBonesAry) { try { Transform boneTransform = animator.GetBoneTransform(val); if (Object.op_Implicit((Object)(object)boneTransform)) { if (UsePaths) { AddPair(Enum.GetName(typeof(HumanBodyBones), val), SearchUtils.FindPath(((Component)animator).transform, boneTransform)); } else { AddPair(Enum.GetName(typeof(HumanBodyBones), val), ((Object)boneTransform).name); } } } catch (Exception) { } } } public void AddRecursiveBones(Transform target) { ClearPairs(); Dictionary<string, Transform> looseNameRefs = new Dictionary<string, Transform>(); SearchUtils.RecursivelyCollectChildNames(target, ref looseNameRefs); foreach (KeyValuePair<string, Transform> item in looseNameRefs) { if (UsePaths) { AddPair(item.Key, SearchUtils.FindPath(target, item.Value)); } else { AddPair(item.Key, item.Key); } } } public List<string> MatchBoneMaps(BoneMap target) { ValidateDict(); List<string> list = new List<string>(); if (target != null) { foreach (BoneMapPair bonePair in bonePairs) { if (target.HasPair(bonePair.origin)) { list.Add(bonePair.origin); } } } return list; } public bool HasPair(string origin) { ValidateDict(); if (!_dict.TryGetValue(origin, out var value)) { return false; } return !string.IsNullOrWhiteSpace(value.target); } public string FetchPair(string origin) { ValidateDict(); if (!_dict.TryGetValue(origin, out var value)) { return string.Empty; } return value.target; } public void AddPair(string origin, string target) { ValidateDict(); if (!_dict.ContainsKey(origin)) { BoneMapPair boneMapPair = new BoneMapPair { origin = origin, target = target }; bonePairs.Add(boneMapPair); _dict.Add(origin, boneMapPair); } } public void RemovePair(string origin) { ValidateDict(); if (_dict.TryGetValue(origin, out var value)) { bonePairs.Remove(value); _dict.Remove(origin); } } public void ClearEmptyPairs() { ValidateDict(); HashSet<string> hashSet = new HashSet<string>(_dict.Keys); foreach (BoneMapPair bonePair in bonePairs) { if (!string.IsNullOrEmpty(bonePair.target)) { hashSet.Remove(bonePair.origin); } } foreach (string item in hashSet) { _dict.Remove(item); } } public void ClearPairs() { _dict.Clear(); bonePairs.Clear(); } public void ValidateDict() { HashSet<string> hashSet = new HashSet<string>(_dict.Keys); foreach (BoneMapPair bonePair in bonePairs) { if (_dict.ContainsKey(bonePair.origin)) { hashSet.Remove(bonePair.origin); } else { _dict.Add(bonePair.origin, bonePair); } } foreach (string item in hashSet) { _dict.Remove(item); } } } [Serializable] public class BoneRigInfo { public string version = string.Empty; public List<Quaternion> rotations = new List<Quaternion>(); public bool useRotations = true; public List<Vector3> positions = new List<Vector3>(); public bool usePositions; public List<string> originPaths = new List<string>(); public List<string> targetPaths = new List<string>(); public int rootIndex = -1; public Vector3 offset = Vector3.zero; public bool originUsePaths; public bool targetUsePaths; } public class BoneRigTracker { public Transform origin; public Transform target; public List<Transform> originBones = new List<Transform>(); public List<Transform> targetBones = new List<Transform>(); public List<Quaternion> rotations = new List<Quaternion>(); public bool useRotations; public List<Vector3> positions = new List<Vector3>(); public bool usePositions; public int rootIndex = -1; public Transform pivot; public Vector3 offset = Vector3.zero; public BoneRigTracker(Transform origin, Transform target) { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) this.origin = origin; this.target = target; } public void SetUpRig(BoneRigInfo info, Transform pivot = null) { if (info != null) { this.pivot = pivot; rotations = new List<Quaternion>(info.rotations); useRotations = info.useRotations; positions = new List<Vector3>(info.positions); usePositions = info.usePositions; rootIndex = info.rootIndex; RegisterBones(info); VerifyBones(); } } private void RegisterBones(BoneRigInfo info) { //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_019b: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)origin) || !Object.op_Implicit((Object)(object)target)) { return; } int count = info.originPaths.Count; originBones = new List<Transform>(count); targetBones = new List<Transform>(count); Dictionary<string, Transform> looseNameRefs = null; Dictionary<string, Transform> looseNameRefs2 = null; if (!info.originUsePaths) { SearchUtils.IterativelyCollectChildNames(origin, ref looseNameRefs); } if (!info.targetUsePaths) { SearchUtils.IterativelyCollectChildNames(target, ref looseNameRefs2); } for (int i = 0; i < count; i++) { Transform value; if (info.originUsePaths) { value = origin.Find(info.originPaths[i]); } else { looseNameRefs.TryGetValue(info.originPaths[i], out value); } Transform value2; if (info.targetUsePaths) { value2 = target.Find(info.targetPaths[i]); } else { looseNameRefs2.TryGetValue(info.targetPaths[i], out value2); } originBones.Add(value); targetBones.Add(value2); } VerifyBones(); if (info.version == "0.0.4") { offset = info.offset; } else if (rootIndex >= 0 && rootIndex < targetBones.Count) { Transform val = targetBones[rootIndex]; offset = val.position - Vector3.Project(info.offset, val.up); offset = val.InverseTransformVector(offset - val.position); } } public void VerifyBones() { for (int i = 0; i < originBones.Count; i++) { if (i >= 0 && (!Object.op_Implicit((Object)(object)originBones[i]) || !Object.op_Implicit((Object)(object)targetBones[i]))) { RemoveBone(i); i--; } } } public void RemoveBone(int index) { Debug.LogWarning((object)"Removing Bone!"); try { originBones.RemoveAt(index); targetBones.RemoveAt(index); if (useRotations) { rotations.RemoveAt(index); } if (usePositions) { positions.RemoveAt(index); } if (index < rootIndex && rootIndex != -1) { rootIndex--; } else if (rootIndex == index || rootIndex < 0 || rootIndex == originBones.Count) { rootIndex = -1; } } catch (Exception ex) { Debug.LogError((object)ex); } } public bool GetBonePair(int index, out Transform origin, out Transform target) { origin = originBones[index]; target = targetBones[index]; if ((Object)(object)origin == (Object)null || (Object)(object)target == (Object)null) { Debug.LogWarning((object)"Bone seem to be invalid, Will Verify Bone Rig."); VerifyBones(); Update(); return false; } return true; } public void Update() { for (int i = 0; i < originBones.Count; i++) { if (!GetBonePair(i, out var val, out var val2)) { return; } if (useRotations) { UpdateBoneRotation(i, val, val2); } if (usePositions) { UpdateBonePosition(i, val, val2); } } UpdatePivotOffset(); } private void UpdateBoneRotation(int index, Transform origin, Transform target) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) RigUtilities.ApplyRotationOffset(origin, target, rotations[index]); } private void UpdateBonePosition(int index, Transform origin, Transform target) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) RigUtilities.ApplyPositionOffset(origin, target, positions[index]); } public void UpdatePivotOffset() { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) if (rootIndex != -1) { if ((Object)(object)pivot != (Object)null) { RigUtilities.ApplyPositionOffset(originBones[rootIndex], pivot, offset); } else { RigUtilities.ApplyPositionOffset(originBones[rootIndex], targetBones[rootIndex], offset); } } } } [Serializable] public class RigBuilder : MonoBehaviour { private BoneRigInfo _rig; public string Data = string.Empty; public BoneRigInfo Rig { get { if (_rig == null) { Deserialize(); } return _rig; } } public void Deserialize() { if (string.IsNullOrWhiteSpace(Data)) { return; } _rig = new BoneRigInfo(); try { JsonUtility.FromJsonOverwrite(Data, (object)_rig); } catch (Exception ex) { Debug.LogError((object)ex); } } } [Serializable] public class RigBuilderTemplate : MonoBehaviour { public GameObject RigPrefab; public AnimationClip ReferencePose; public bool PoseTargetRig; public bool PoseTemplateRig; public string RootName = "Hips"; private BoneMap _bonemap; public string Data = string.Empty; public BoneMap BoneMap { get { if (_bonemap == null) { Deserialize(); } return _bonemap; } } public virtual bool BuildRig(Transform target, BoneMap targetBoneMap, out BoneRigInfo rig) { return RigUtilities.TryBuildRig(this, target, targetBoneMap, out rig); } public void Deserialize() { if (string.IsNullOrEmpty(Data)) { return; } if (_bonemap == null) { _bonemap = new BoneMap(); } try { JsonUtility.FromJsonOverwrite(Data, (object)_bonemap); _bonemap.ValidateDict(); } catch (Exception ex) { Debug.LogError((object)ex); } } } public static class RigUtilities { public const string CurrentRigVersion = "0.0.4"; public static HumanBodyBones[] HumanBodyBonesAry = (HumanBodyBones[])Enum.GetValues(typeof(HumanBodyBones)); public static bool TryBuildRig(RigBuilderTemplate Template, Transform target, BoneMap targetBoneMap, out BoneRigInfo rig) { //IL_0210: Unknown result type (might be due to invalid IL or missing references) //IL_0242: Unknown result type (might be due to invalid IL or missing references) //IL_0247: Unknown result type (might be due to invalid IL or missing references) rig = null; Transform val = null; Transform val2 = null; try { val = ((Component)Object.Instantiate<Transform>(target, (Transform)null)).transform; val2 = Object.Instantiate<GameObject>(Template.RigPrefab, (Transform)null).transform; if (Template.PoseTargetRig) { AnimationClip referencePose = Template.ReferencePose; if (referencePose != null) { referencePose.SampleAnimation(((Component)val).gameObject, 0f); } } if (Template.PoseTemplateRig) { AnimationClip referencePose2 = Template.ReferencePose; if (referencePose2 != null) { referencePose2.SampleAnimation(((Component)val2).gameObject, 0f); } } Dictionary<string, Transform> looseNameRefs = new Dictionary<string, Transform>(); Dictionary<string, Transform> looseNameRefs2 = new Dictionary<string, Transform>(); SearchUtils.RecursivelyCollectChildNames(val, ref looseNameRefs); SearchUtils.RecursivelyCollectChildNames(val2, ref looseNameRefs2); List<string> list = targetBoneMap.MatchBoneMaps(Template.BoneMap); List<KeyValuePair<Transform, Transform>> list2 = new List<KeyValuePair<Transform, Transform>>(); List<string> list3 = new List<string>(); foreach (string item in list) { Transform value = null; Transform value2 = null; string text = targetBoneMap.FetchPair(item); string text2 = Template.BoneMap.FetchPair(item); if (targetBoneMap.UsePaths) { value = val.Find(text); } else { looseNameRefs.TryGetValue(text, out value); } if (Template.BoneMap.UsePaths) { value2 = val2.Find(text2); } else { looseNameRefs2.TryGetValue(text2, out value2); } if (Object.op_Implicit((Object)(object)value2) && Object.op_Implicit((Object)(object)value)) { list2.Add(new KeyValuePair<Transform, Transform>(value, value2)); list3.Add(item); } } int count = list2.Count; rig = new BoneRigInfo(); rig.version = "0.0.4"; rig.originUsePaths = targetBoneMap.UsePaths; rig.targetUsePaths = Template.BoneMap.UsePaths; for (int i = 0; i < count; i++) { string text3 = list3[i]; Transform value3 = list2[i].Value; Transform key = list2[i].Key; rig.targetPaths.Add(Template.BoneMap.FetchPair(text3)); rig.originPaths.Add(targetBoneMap.FetchPair(text3)); rig.rotations.Add(CalculateRotationOffset(value3, key)); if (rig.rootIndex == -1 && text3 == Template.RootName) { rig.rootIndex = i; rig.offset = CalculatePositionOffset(key, value3); } } } catch (Exception ex) { Debug.LogError((object)ex); return false; } finally { Object.DestroyImmediate((Object)(object)((val != null) ? ((Component)val).gameObject : null)); Object.DestroyImmediate((Object)(object)((val2 != null) ? ((Component)val2).gameObject : null)); } return true; } public static float CalculateHeightRatio(Transform origin, Transform target) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) return origin.position.y / target.position.y; } public static Vector3 CalculatePositionOffset(Transform origin, Transform target) { //IL_0002: 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_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) return target.InverseTransformVector(origin.position - target.position); } public static Quaternion CalculateRotationOffset(Transform origin, Transform target) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) return Quaternion.Inverse(origin.rotation) * target.rotation; } public static void ApplyPositionOffset(Transform origin, Transform target, Vector3 offset) { //IL_0002: 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_0009: 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) origin.position = target.position + target.TransformVector(offset); } public static void ApplyRotationOffset(Transform origin, Transform target, Quaternion offset) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //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) origin.rotation = target.rotation * offset; } } }
UCustomPrefabs/UCustomPrefabsAPI.Peak.dll
Decompiled a month ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.Diagnostics; 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 DG.Tweening; using ExitGames.Client.Photon; using HarmonyLib; using Microsoft.CodeAnalysis; using Photon.Pun; using Photon.Realtime; using Steamworks; using TMPro; using UCustomPrefabsAPI.Extras.Animation; using UCustomPrefabsAPI.Extras.AssetBundles; using UCustomPrefabsAPI.Extras.CustomActions; using UCustomPrefabsAPI.Extras.Utility; using UCustomPrefabsAPI.Peak; using UCustomPrefabsAPI.Peak.ActionUtils; using UCustomPrefabsAPI.Peak.CustomActions; using UCustomPrefabsAPI.Peak.Patches.Listeners; using UCustomPrefabsAPI.Peak.Utils; using UCustomPrefabsAPI.PhotonUtils.Networking; using UCustomPrefabsAPI.RuntimeExtras; using UnityEngine; using UnityEngine.Events; using UnityEngine.Rendering; using UnityEngine.UI; using Zorro.Core; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.0.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.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } [Serializable] [RequireComponent(typeof(Renderer))] public class PeakLayeredTextureHelper : MonoBehaviour { private Renderer renderer; private Material material; public Vector2Int TextureSize = new Vector2Int(512, 512); [HideInInspector] public List<Texture2D> LayerBundleTextures; [HideInInspector] public List<Texture2D> LayerBundleMasks; [HideInInspector] public string LayerBundleData; } public class MeshUtils { public static Mesh MakeReadableMeshCopy(Mesh nonReadableMesh) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_001e: 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) //IL_009b: Unknown result type (might be due to invalid IL or missing references) Mesh val = new Mesh(); ((Object)val).name = ((Object)nonReadableMesh).name + "_copy"; val.indexFormat = nonReadableMesh.indexFormat; CopyVertexBuffers(val, nonReadableMesh); val.subMeshCount = nonReadableMesh.subMeshCount; GraphicsBuffer indexBuffer = nonReadableMesh.GetIndexBuffer(); int num = indexBuffer.stride * indexBuffer.count; byte[] array = new byte[num]; indexBuffer.GetData((Array)array); val.SetIndexBufferParams(indexBuffer.count, nonReadableMesh.indexFormat); val.SetIndexBufferData<byte>(array, 0, 0, num, (MeshUpdateFlags)0); indexBuffer.Release(); uint num2 = 0u; for (int i = 0; i < val.subMeshCount; i++) { uint indexCount = nonReadableMesh.GetIndexCount(i); val.SetSubMesh(i, new SubMeshDescriptor((int)num2, (int)indexCount, (MeshTopology)0), (MeshUpdateFlags)0); num2 += indexCount; } CopyBlendShapes(val, nonReadableMesh); val.RecalculateNormals(); val.RecalculateBounds(); val.boneWeights = nonReadableMesh.boneWeights; val.bindposes = nonReadableMesh.bindposes; return val; } private static void CopyBlendShapes(Mesh targetMesh, Mesh sourceMesh) { try { for (int i = 0; i < sourceMesh.blendShapeCount; i++) { string blendShapeName = sourceMesh.GetBlendShapeName(i); int blendShapeFrameCount = sourceMesh.GetBlendShapeFrameCount(i); for (int j = 0; j < blendShapeFrameCount; j++) { float blendShapeFrameWeight = sourceMesh.GetBlendShapeFrameWeight(i, j); Vector3[] array = (Vector3[])(object)new Vector3[sourceMesh.vertexCount]; Vector3[] array2 = (Vector3[])(object)new Vector3[sourceMesh.vertexCount]; Vector3[] array3 = (Vector3[])(object)new Vector3[sourceMesh.vertexCount]; sourceMesh.GetBlendShapeFrameVertices(i, j, array, array2, array3); targetMesh.AddBlendShapeFrame(blendShapeName, blendShapeFrameWeight, array, array2, array3); } } } catch (Exception ex) { Debug.LogException(ex); } } private static void CopyVertexBuffers(Mesh targetMesh, Mesh sourceMesh) { for (int i = 0; i < sourceMesh.vertexBufferCount; i++) { GraphicsBuffer vertexBuffer = sourceMesh.GetVertexBuffer(i); int num = vertexBuffer.stride * vertexBuffer.count; byte[] array = new byte[num]; vertexBuffer.GetData((Array)array); targetMesh.SetVertexBufferParams(sourceMesh.vertexCount, sourceMesh.GetVertexAttributes()); targetMesh.SetVertexBufferData<byte>(array, 0, 0, num, i, (MeshUpdateFlags)0); vertexBuffer.Release(); } } } namespace UCustomPrefabsAPI.PhotonUtils.Networking { public class PlayerConfigHelper : MonoBehaviourPunCallbacks { public const string UCustomPrefabPrefix = "ucp_"; public const string CharacterTag = "ucp_char"; public const string SkeletonTag = "ucp_skel"; public const string ChickenTag = "ucp_chkn"; public UCustomPrefabHandler CharacterHandler; public UCustomPrefabHandler PassportDummy_Handler; public UCustomPrefabHandler ChickenHandler; public string CurrentCharacterTemplate { get { if (((Dictionary<object, object>)(object)((MonoBehaviourPun)this).photonView.Owner.CustomProperties).TryGetValue((object)"ucp_char", out object value)) { return (string)value; } return "NoPreference"; } } public string CurrentSkeletonTemplate { get { if (((Dictionary<object, object>)(object)((MonoBehaviourPun)this).photonView.Owner.CustomProperties).TryGetValue((object)"ucp_skel", out object value)) { return (string)value; } return "NoPreference"; } } public string CurrentChickenTemplate { get { if (((Dictionary<object, object>)(object)((MonoBehaviourPun)this).photonView.Owner.CustomProperties).TryGetValue((object)"ucp_chkn", out object value)) { return (string)value; } return "NoPreference"; } } public PlayerCustomizationDummy PassportDummy { get { PassportManager instance = PassportManager.instance; if (!Object.op_Implicit((Object)(object)instance)) { return null; } return instance.dummy; } } public static bool TryGetConfigHandler(Player player, out PlayerConfigHelper config) { config = ((Component)player.character).GetComponent<PlayerConfigHelper>(); return Object.op_Implicit((Object)(object)config); } public static bool TryGetConfigHandler(Character character, out PlayerConfigHelper config) { config = ((Component)character).GetComponent<PlayerConfigHelper>(); return Object.op_Implicit((Object)(object)config); } public static void UpdatePlayerData() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Expected O, but got Unknown //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Expected O, but got Unknown //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Expected O, but got Unknown //IL_0045: Expected O, but got Unknown Hashtable val = new Hashtable(); ((Dictionary<object, object>)val).Add((object)"ucp_char", (object)Plugin.PreferredCharacterConfig.Value); ((Dictionary<object, object>)val).Add((object)"ucp_skel", (object)Plugin.PreferredSkeletonConfig.Value); ((Dictionary<object, object>)val).Add((object)"ucp_chkn", (object)Plugin.PreferredChickenConfig.Value); Hashtable val2 = val; PhotonNetwork.LocalPlayer.SetCustomProperties(val2, (Hashtable)null, (WebFlags)null); } public override void OnPlayerPropertiesUpdate(Player targetPlayer, Hashtable changedProps) { if (targetPlayer == ((MonoBehaviourPun)this).photonView.Owner) { PurgeInstance(ChickenHandler); PurgeInstance(PassportDummy_Handler); PurgeInstance(CharacterHandler); Hashtable customProperties = targetPlayer.CustomProperties; if (((Dictionary<object, object>)(object)customProperties).TryGetValue((object)"ucp_char", out object value) && value is string token) { UpdateCharacterTemplate(targetPlayer, token); } if (((Dictionary<object, object>)(object)customProperties).TryGetValue((object)"ucp_skel", out value) && value is string token2) { UpdateSkeletonTemplate(targetPlayer, token2); } if (((Dictionary<object, object>)(object)customProperties).TryGetValue((object)"ucp_chkn", out value) && value is string token3) { UpdateChickenTemplate(targetPlayer, token3); } PassportManager instance = PassportManager.instance; if (instance != null) { instance.SetActiveButton(false); } } } public static void SetCharacterTemplate(string template) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected O, but got Unknown //IL_0026: Expected O, but got Unknown Plugin.PreferredCharacterConfig.Value = template; Hashtable val = new Hashtable(); ((Dictionary<object, object>)val).Add((object)"ucp_char", (object)Plugin.PreferredCharacterConfig.Value); Hashtable val2 = val; PhotonNetwork.LocalPlayer.SetCustomProperties(val2, (Hashtable)null, (WebFlags)null); } public static void SetSkeletonTemplate(string template) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected O, but got Unknown //IL_0026: Expected O, but got Unknown Plugin.PreferredSkeletonConfig.Value = template; Hashtable val = new Hashtable(); ((Dictionary<object, object>)val).Add((object)"ucp_skel", (object)Plugin.PreferredSkeletonConfig.Value); Hashtable val2 = val; PhotonNetwork.LocalPlayer.SetCustomProperties(val2, (Hashtable)null, (WebFlags)null); } public static void SetChickenTemplate(string template) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected O, but got Unknown //IL_0026: Expected O, but got Unknown Plugin.PreferredChickenConfig.Value = template; Hashtable val = new Hashtable(); ((Dictionary<object, object>)val).Add((object)"ucp_chkn", (object)Plugin.PreferredChickenConfig.Value); Hashtable val2 = val; PhotonNetwork.LocalPlayer.SetCustomProperties(val2, (Hashtable)null, (WebFlags)null); } private void UpdateCharacterTemplate(Player targetPlayer, string token) { PurgeInstance(CharacterHandler); string text = CustomTemplateUtils.Evaluate_Peak_Custom_Template(this, PeakTemplateType.Character, token); if (!CustomTemplateUtils.IsSpecialTemplate(text)) { RegisterInstance(string.Format("{0}:{1}:{2}", "ucp_char", targetPlayer.ActorNumber, text), text, ((Component)this).transform, out CharacterHandler); } if (((MonoBehaviourPun)this).photonView.IsMine) { PurgeInstance(PassportDummy_Handler); if (!CustomTemplateUtils.IsSpecialTemplate(text)) { RegisterInstance($"dummy:{targetPlayer.ActorNumber}:{text}", text, ((Component)PassportDummy).transform, out PassportDummy_Handler); } } } private void UpdateSkeletonTemplate(Player targetPlayer, string token) { } public void CreateSkeletonInstance(Skelleton skeleton) { string text = CustomTemplateUtils.Evaluate_Peak_Custom_Template(this, PeakTemplateType.Skeleton, CurrentSkeletonTemplate); if (!CustomTemplateUtils.IsSpecialTemplate(text)) { InstanceManager.Register(string.Format("{0}:{1}:{2}:{3}", "ucp_skel", ((MonoBehaviourPun)this).photonView.OwnerActorNr, text, ((Object)skeleton).GetInstanceID()), text, ((Component)skeleton).transform); } } private void UpdateChickenTemplate(Player targetPlayer, string token) { PurgeInstance(ChickenHandler); string text = CustomTemplateUtils.Evaluate_Peak_Custom_Template(this, PeakTemplateType.Chicken, token); if (!CustomTemplateUtils.IsSpecialTemplate(text)) { RegisterInstance(string.Format("{0}:{1}:{2}", "ucp_chkn", targetPlayer.ActorNumber, text), text, ((Component)this).transform, out ChickenHandler); } } public static void PurgeInstance(UCustomPrefabHandler handler) { if (!((Object)(object)handler == (Object)null) && Object.op_Implicit((Object)(object)handler) && handler.Instance != null) { InstanceManager.Remove(handler.Instance.ID); } } public static bool RegisterInstance(string uid, string template_uid, Transform target, out UCustomPrefabHandler handler) { handler = null; if (VerifyTemplate(template_uid) && InstanceManager.Register(uid, template_uid, target)) { InstanceInfo val = default(InstanceInfo); InstanceManager.TryGetInstance(uid, ref val); handler = val.Handler; return true; } return false; } public static bool VerifyTemplate(string templateID) { if (string.IsNullOrWhiteSpace(templateID)) { return false; } TemplateData val = default(TemplateData); return TemplateRegistry.TryGetTemplate(templateID, ref val); } public void Start() { if (((MonoBehaviourPun)this).photonView.IsMine) { UpdatePlayerData(); } ((MonoBehaviourPunCallbacks)this).OnPlayerPropertiesUpdate(((MonoBehaviourPun)this).photonView.Owner, ((MonoBehaviourPun)this).photonView.Owner.CustomProperties); } public void Update() { Update_Debug_Model_Selection(); } public void Update_Debug_Model_Selection() { if (((MonoBehaviourPun)this).photonView.IsMine) { if (Input.GetKeyDown((KeyCode)91)) { PassportManager.instance.OpenTab((Type)(-13377701)); } if (Input.GetKeyDown((KeyCode)93)) { PassportManager.instance.OpenTab((Type)0); } } } } } namespace UCustomPrefabsAPI.RuntimeExtras { public class MeshHider : CustomActionsBase { private static RenderingLayerMask Hidden_Mask = RenderingLayerMask.op_Implicit(0); private Dictionary<Renderer, RenderingLayerMask> _renderers = new Dictionary<Renderer, RenderingLayerMask>(); private Stack<Renderer> _InvalidKeys = new Stack<Renderer>(); public override void RegisterActions() { ((CustomActionsBase)this).AddOnStateChanged((Action<string, string>)Init); ((CustomActionsBase)this).AddOnDestroy((Action)Reset); } public void Init(string last, string state) { RegisterMeshHiderTemplates(); HideRenderers(); } public void Reset() { ResetRenderers(); } public void RegisterMeshHiderTemplates() { TemplateData val = default(TemplateData); if (!TemplateRegistry.TryGetTemplate(((HandlerReferencer)this).Handler.Instance.TemplateUID, ref val)) { return; } foreach (CustomActionsTemplate customActionsTemplate in val.CustomActionsTemplates) { if (customActionsTemplate is MeshHider_Template template) { RegisterRenderers(template); } } } public void RegisterRenderers(MeshHider_Template template) { //IL_0288: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Unknown result type (might be due to invalid IL or missing references) MeshHider_Template.HiderMethod parsedHiderMethod = template.ParsedHiderMethod; List<string> meshesHidden = template.MeshesHidden; switch (parsedHiderMethod) { case MeshHider_Template.HiderMethod.Directory: { foreach (string item in meshesHidden) { Transform val2 = ((Component)((HandlerReferencer)this).Handler).transform.Find(item); if (Object.op_Implicit((Object)(object)val2)) { Renderer component = ((Component)val2).GetComponent<Renderer>(); if (Object.op_Implicit((Object)(object)component)) { _renderers[component] = RenderingLayerMask.op_Implicit(component.renderingLayerMask); } } } break; } case MeshHider_Template.HiderMethod.Name: { Dictionary<string, Transform> dictionary2 = new Dictionary<string, Transform>(); SearchUtils.IterativelyCollectChildNames(((Component)((HandlerReferencer)this).Handler).transform, ref dictionary2); { foreach (string item2 in meshesHidden) { if (dictionary2.TryGetValue(item2, out var value2)) { Renderer component2 = ((Component)value2).GetComponent<Renderer>(); if (Object.op_Implicit((Object)(object)component2)) { _renderers[component2] = RenderingLayerMask.op_Implicit(component2.renderingLayerMask); } } } break; } } case MeshHider_Template.HiderMethod.ChildrenOfDirectory: { foreach (string item3 in meshesHidden) { Transform val4 = ((Component)((HandlerReferencer)this).Handler).transform.Find(item3); if (!Object.op_Implicit((Object)(object)val4)) { continue; } Renderer[] componentsInChildren = ((Component)val4).GetComponentsInChildren<Renderer>(true); foreach (Renderer val5 in componentsInChildren) { if ((Object)(object)((Component)val5).transform != (Object)(object)val4) { _renderers[val5] = RenderingLayerMask.op_Implicit(val5.renderingLayerMask); } } } break; } case MeshHider_Template.HiderMethod.ChildrenOfName: { Dictionary<string, Transform> dictionary = new Dictionary<string, Transform>(); SearchUtils.IterativelyCollectChildNames(((Component)((HandlerReferencer)this).Handler).transform, ref dictionary); { foreach (string item4 in meshesHidden) { if (!dictionary.TryGetValue(item4, out var value)) { continue; } Renderer[] componentsInChildren = ((Component)value).GetComponentsInChildren<Renderer>(true); foreach (Renderer val3 in componentsInChildren) { if ((Object)(object)((Component)val3).transform != (Object)(object)value) { _renderers[val3] = RenderingLayerMask.op_Implicit(val3.renderingLayerMask); } } } break; } } case MeshHider_Template.HiderMethod.Everything: { Renderer[] componentsInChildren = ((Component)((Component)((HandlerReferencer)this).Handler).transform).GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { _renderers[val] = RenderingLayerMask.op_Implicit(val.renderingLayerMask); } break; } case MeshHider_Template.HiderMethod.SearchUtilTokens: Debug.LogWarning((object)"SearchUtilTokens Still TODO, This will be Ignored."); break; default: Debug.LogWarning((object)"Unknown HiderMethod..."); break; } } public void DoPostValidation() { PurgeInvalidRenderers(); } public void PurgeInvalidRenderers() { while (_InvalidKeys.Count > 0) { _renderers.Remove(_InvalidKeys.Pop()); } } public bool ValidateRenderer(Renderer renderer) { if ((Object)(object)renderer != (Object)null && Object.op_Implicit((Object)(object)renderer)) { return true; } _InvalidKeys.Push(renderer); return false; } public void HideRenderers() { foreach (KeyValuePair<Renderer, RenderingLayerMask> renderer in _renderers) { if (ValidateRenderer(renderer.Key)) { renderer.Key.forceRenderingOff = true; } } DoPostValidation(); } public void ResetRenderers() { foreach (KeyValuePair<Renderer, RenderingLayerMask> renderer in _renderers) { if (ValidateRenderer(renderer.Key)) { renderer.Key.forceRenderingOff = false; } } DoPostValidation(); _renderers.Clear(); } public void Update() { } } public class RigHelper : CustomActionsBase { private RigHelper_Template.TargetMethod targetMethod = RigHelper_Template.TargetMethod.Name; private string RigRootPath = "Hip"; private Transform Root; private Dictionary<RigBuilder, BoneRigTracker> Rig_Targets = new Dictionary<RigBuilder, BoneRigTracker>(); private Stack<RigBuilder> BrokenRigs = new Stack<RigBuilder>(); public override void RegisterActions() { ((CustomActionsBase)this).AddOnStateChanged((Action<string, string>)BuildRigs); ((CustomActionsBase)this).AddOnUpdate((Action)Update); ((CustomActionsBase)this).AddOnDestroy((Action)CleanUp); } public override void HandleTemplateData(object[] data) { targetMethod = (RigHelper_Template.TargetMethod)data[0]; RigRootPath = (string)data[1]; } public void CleanUp() { Root = null; foreach (RigBuilder key in Rig_Targets.Keys) { if (Object.op_Implicit((Object)(object)key)) { Object.DestroyImmediate((Object)(object)key); } } Rig_Targets.Clear(); } public void BuildRigs(string last, string state) { CleanUp(); switch (targetMethod) { case RigHelper_Template.TargetMethod.Directory: Root = ((Component)((HandlerReferencer)this).Handler).transform.Find(RigRootPath); break; case RigHelper_Template.TargetMethod.Name: Root = SearchUtils.IterativelyFindChild(((Component)((HandlerReferencer)this).Handler).transform, RigRootPath); break; default: Debug.LogWarning((object)"Unknown TargetMethod"); return; } if (!Object.op_Implicit((Object)(object)Root)) { return; } foreach (KeyValuePair<string, PrefabTemplate> loadedTemplate in ((HandlerReferencer)this).Handler.LoadedTemplates) { RigBuilder[] componentsInChildren = ((Component)loadedTemplate.Value).GetComponentsInChildren<RigBuilder>(true); foreach (RigBuilder rig in componentsInChildren) { SetUpRig(rig, Root.parent); } } Update(); } public void SetUpRig(RigBuilder rig, Transform hips) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected O, but got Unknown if (Object.op_Implicit((Object)(object)Root) && !Rig_Targets.TryGetValue(rig, out var value)) { value = new BoneRigTracker(((Component)rig).transform, hips); value.SetUpRig(rig.Rig, (Transform)null); Rig_Targets.Add(rig, value); } } public void Update() { if (!Object.op_Implicit((Object)(object)Root) || !((Component)Root).gameObject.activeInHierarchy) { return; } foreach (KeyValuePair<RigBuilder, BoneRigTracker> rig_Target in Rig_Targets) { if (!Object.op_Implicit((Object)(object)rig_Target.Key)) { BrokenRigs.Push(rig_Target.Key); } else { rig_Target.Value.Update(); } } ValidateRigs(); } public void ValidateRigs() { if (BrokenRigs.Count != 0) { Debug.LogWarning((object)"Removing Broken Rigs."); } while (BrokenRigs.Count > 0) { Rig_Targets.Remove(BrokenRigs.Pop()); } } } public class ShaderFix : CustomActionsBase { public override void RegisterActions() { ((CustomActionsBase)this).AddOnStateChanged((Action<string, string>)DoInit); } public void DoInit(string last, string state) { foreach (KeyValuePair<string, PrefabTemplate> loadedTemplate in ((HandlerReferencer)this).Handler.LoadedTemplates) { FixShaders(((Component)loadedTemplate.Value).transform); } } public void FixShaders(Transform target) { Renderer[] componentsInChildren = ((Component)target).GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { Material[] sharedMaterials = val.sharedMaterials; for (int j = 0; j < sharedMaterials.Length; j++) { Shader val2 = Shader.Find(((Object)sharedMaterials[j].shader).name); if ((Object)(object)val2 != (Object)null) { sharedMaterials[j].shader = val2; } } val.sharedMaterials = sharedMaterials; } } } public class MeshHider_Template : CustomActionsTemplate { [Serializable] public enum HiderMethod { Directory, Name, ChildrenOfDirectory, ChildrenOfName, Everything, SearchUtilTokens } [SerializeField] [HideInInspector] public string HiderMethod_data; [SerializeField] public List<string> MeshesHidden = new List<string>(); [SerializeField] public bool AlwaysCheck; public HiderMethod ParsedHiderMethod { get { if (!Enum.TryParse<HiderMethod>(HiderMethod_data, out var result)) { return HiderMethod.Directory; } return result; } } public override Type RegisterCustomActionsBaseType() { return typeof(MeshHider); } } public class RigHelper_Template : CustomActionsTemplate { [Serializable] public enum TargetMethod { Directory, Name } [SerializeField] [HideInInspector] public string TargetMethod_data; [SerializeField] public string RigRootPath = "Hip"; public override object[] PrepareTemplateData() { Enum.TryParse<TargetMethod>(TargetMethod_data, out var result); return new object[2] { result, RigRootPath }; } public override Type RegisterCustomActionsBaseType() { return typeof(RigHelper); } } public class ShaderFix_Template : CustomActionsTemplate { public override Type RegisterCustomActionsBaseType() { return typeof(ShaderFix); } } public enum ConstraintTemplatePathingType { ContainerChildren, AllChildren, LastChildren, FirstChildren, Manual } [Serializable] public enum TargetMethod { Directory, Name } [Serializable] public class ConstraintTemplate : MonoBehaviour { public struct BakedConstraintTemplate { public ConstraintTemplate template; public Transform[] followers; public Transform origin; public Transform target; public Vector3[] pos; public Quaternion[] rot; public Vector3[] scl; public BakedConstraintTemplate(ConstraintTemplate template, Transform origin, Transform target) { this.template = template; followers = null; this.origin = origin; this.target = target; pos = null; rot = null; scl = null; ReAttach(origin, target); } public void ReAttach(Transform origin, Transform target) { this.origin = origin; this.target = target; FindFollowers(); } private void FindFollowers() { //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: 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) followers = (Transform[])(object)new Transform[template.Paths.Count]; pos = (Vector3[])(object)new Vector3[template.Paths.Count]; rot = (Quaternion[])(object)new Quaternion[template.Paths.Count]; scl = (Vector3[])(object)new Vector3[template.Paths.Count]; for (int i = 0; i < followers.Length; i++) { Transform val = origin.Find(template.Paths[i]); followers[i] = val; if (Object.op_Implicit((Object)(object)val)) { pos[i] = val.localPosition; rot[i] = val.localRotation; scl[i] = val.localScale; } } } public void UpdateFollowers() { //IL_0028: 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_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: 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) for (int i = 0; i < followers.Length; i++) { Transform val = followers[i]; if (Object.op_Implicit((Object)(object)val)) { Transform obj = target; Vector3 val2 = template.Positions[i]; Quaternion val3 = template.Rotations[i]; Vector3 scale = template.Scales[i]; ApplyOffsets(val, obj, in val2, in val3, in scale); } } } public void RestoreFollowers() { //IL_001d: 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_0041: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i < followers.Length; i++) { Transform val = followers[i]; if (Object.op_Implicit((Object)(object)val)) { val.localPosition = pos[i]; val.localRotation = rot[i]; val.localScale = scl[i]; } } } } public Transform TargetObject; public string TargetPath = string.Empty; public string TargetMethod_data; public List<string> Paths = new List<string>(); public List<Vector3> Positions = new List<Vector3>(); public List<Vector3> Scales = new List<Vector3>(); public List<Quaternion> Rotations = new List<Quaternion>(); public static void ApplyOffsets(Transform origin, Transform target, in Vector3 pos, in Quaternion rot, in Vector3 scale) { //IL_0002: 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_000e: Unknown result type (might be due to invalid IL or missing references) //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_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002a: 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_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0042: 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_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_007e: 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_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) origin.position = target.position + target.rotation * pos; origin.rotation = target.rotation * rot; Vector3 lossyScale = target.lossyScale; Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor(lossyScale.x * scale.x, lossyScale.y * scale.y, lossyScale.z * scale.z); Vector3 lossyScale2 = origin.parent.lossyScale; origin.localScale = new Vector3(val.x / lossyScale2.x, val.y / lossyScale2.y, val.z / lossyScale2.z); } } [Serializable] public class PeakAccessoryTextureHelper : TaggedBehaviour { public string TargetTexture = "_MainTex"; public List<int> TargetMaterials = new List<int>(); public List<Texture> DefaultTextures; public void Reset() { DefaultTextures = null; } public void Register_Default_Textures() { if (DefaultTextures != null) { return; } DefaultTextures = new List<Texture>(); Material[] sharedMaterials = ((Component)this).GetComponent<Renderer>().sharedMaterials; foreach (int targetMaterial in TargetMaterials) { DefaultTextures.Add(sharedMaterials[targetMaterial].GetTexture(TargetTexture)); } } public void Set_Texture(Texture texture) { Register_Default_Textures(); Renderer component = ((Component)this).GetComponent<Renderer>(); if (!Object.op_Implicit((Object)(object)component)) { return; } Material[] materials = component.materials; if ((Object)(object)texture == (Object)null) { for (int i = 0; i < DefaultTextures.Count; i++) { materials[TargetMaterials[i]].SetTexture(TargetTexture, DefaultTextures[i]); } return; } foreach (int targetMaterial in TargetMaterials) { materials[targetMaterial].SetTexture(TargetTexture, texture); } } } public class SteamAvatarHelper : TaggedBehaviour { public string TargetTexture = "_MainTex"; [SerializeField] [HideInInspector] public List<int> TargetMaterials = new List<int>(); private CSteamID ourSteamID; public void Load_Player_Avatar(PhotonView view) { //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_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) if (ourSteamID != default(CSteamID)) { Peak_SteamUtils.Fetch_SteamID_Avatar(ourSteamID, SteamAvatarLoaded); } else { Peak_SteamUtils.Fetch_SteamID(view, SteamID_Loaded); } } private void SteamID_Loaded(CSteamID steamID) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: 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) ourSteamID = steamID; Peak_SteamUtils.Fetch_SteamID_Avatar(ourSteamID, SteamAvatarLoaded); } private void SteamAvatarLoaded(Texture2D avatar) { Renderer component = ((Component)this).GetComponent<Renderer>(); if (!Object.op_Implicit((Object)(object)component)) { return; } Material[] materials = component.materials; foreach (int targetMaterial in TargetMaterials) { materials[targetMaterial].SetTexture(TargetTexture, (Texture)(object)avatar); } } } public class Peak_SteamUtils { public static Dictionary<CSteamID, Texture2D> LoadedAvatars = new Dictionary<CSteamID, Texture2D>(); private const int RequestUserInfo_Interval = 500; public static void Fetch_SteamID(PhotonView view, Action<CSteamID> callback) { if ((Object)(object)view == (Object)null) { return; } TaskAwaiter<CSteamID> awaiter = Fetch_Photonview_SteamID(view).GetAwaiter(); awaiter.OnCompleted(delegate { //IL_0035: Unknown result type (might be due to invalid IL or missing references) object? obj = callback?.Target; Object val = (Object)((obj is Object) ? obj : null); if (val == null || Object.op_Implicit(val)) { callback?.Invoke(awaiter.GetResult()); } }); } public static void Fetch_SteamID_Avatar(CSteamID steamID, Action<Texture2D> callback) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) if (steamID == default(CSteamID)) { return; } TaskAwaiter<Texture2D> awaiter = Fetch_SteamAvatar(steamID).GetAwaiter(); awaiter.OnCompleted(delegate { object? obj = callback?.Target; Object val = (Object)((obj is Object) ? obj : null); if (val == null || Object.op_Implicit(val)) { callback?.Invoke(awaiter.GetResult()); } }); } public static void Clear_Loaded_Avatars() { LoadedAvatars.Clear(); } private static async Task<CSteamID> Fetch_Photonview_SteamID(PhotonView view) { if (view.IsMine) { return SteamUser.GetSteamID(); } if (Object.op_Implicit((Object)(object)view)) { return await Find_Nickname_SteamID(view.Owner.NickName); } return default(CSteamID); } private static async Task<CSteamID> Find_Nickname_SteamID(string nickname) { CSteamID lobbyID = default(CSteamID); if (!GameHandler.GetService<SteamLobbyHandler>().InSteamLobby(ref lobbyID)) { return default(CSteamID); } int numMembers = SteamMatchmaking.GetNumLobbyMembers(lobbyID); new Dictionary<string, CSteamID>(); for (int i = 0; i < numMembers; i++) { CSteamID memberID = SteamMatchmaking.GetLobbyMemberByIndex(lobbyID, i); await RequestUserInfo(memberID, NameOnly: true); if (SteamFriends.GetFriendPersonaName(memberID) == nickname) { return memberID; } } Debug.LogWarning((object)("Unable to find nickname in steam lobby : " + nickname)); return default(CSteamID); } private static async Task<Texture2D> Fetch_SteamAvatar(CSteamID steamID) { //IL_000e: 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) if (LoadedAvatars.TryGetValue(steamID, out var value)) { return value; } await RequestUserInfo(steamID); int largeFriendAvatar = SteamFriends.GetLargeFriendAvatar(steamID); if (largeFriendAvatar == -1) { Debug.LogWarning((object)$"Failed to GetLargeFriendAvatar {steamID}"); return null; } uint num = default(uint); uint num2 = default(uint); if (!SteamUtils.GetImageSize(largeFriendAvatar, ref num, ref num2) || num == 0 || num2 == 0) { Debug.LogWarning((object)$"Failed to GetImageSize {steamID}"); return null; } byte[] image = new byte[4 * num * num2]; if (!SteamUtils.GetImageRGBA(largeFriendAvatar, image, image.Length)) { Debug.LogWarning((object)$"Failed to GetImageRGBA {steamID}"); return null; } FlipImageHorizontally(ref image, num, num2); value = new Texture2D((int)num, (int)num2, (TextureFormat)4, false); value.LoadRawTextureData(image); value.Apply(); LoadedAvatars.Add(steamID, value); return value; } private static void FlipImageHorizontally(ref byte[] image, uint width, uint height) { int num = (int)(width * 4); int num2 = (int)height / 2; for (int i = 0; i < num2; i++) { int num3 = i * num; int num4 = ((int)(height - 1) - i) * num; for (int j = 0; j < num; j += 4) { int num5 = num3 + j; int num6 = num4 + j; byte b = image[num5]; byte b2 = image[num5 + 1]; byte b3 = image[num5 + 2]; byte b4 = image[num5 + 3]; image[num5] = image[num6]; image[num5 + 1] = image[num6 + 1]; image[num5 + 2] = image[num6 + 2]; image[num5 + 3] = image[num6 + 3]; image[num6] = b; image[num6 + 1] = b2; image[num6 + 2] = b3; image[num6 + 3] = b4; } } } private static async Task RequestUserInfo(CSteamID steamID, bool NameOnly = false) { //IL_000e: 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) while (SteamFriends.RequestUserInformation(steamID, NameOnly)) { await Task.Delay(500); } } } } namespace UCustomPrefabsAPI.Peak { public class Peak_Chicken : Peak_Module { private List<Tweener> _activeTweens = new List<Tweener>(); private Dictionary<Renderer, List<float>> OpacityLibrary = new Dictionary<Renderer, List<float>>(); public override void Init() { ToggleChickenInit(); CharacterCustomization_Listeners.BecomeChicken_Postfix.Listen(instance.Character, BecomeChicken); CharacterCustomization_Listeners.BecomeHuman_Postfix.Listen(instance.Character, BecomeHuman); } public override void Reset() { OpacityLibrary = new Dictionary<Renderer, List<float>>(); KillTweeners(); } public override void Destroy() { CharacterCustomization_Listeners.BecomeChicken_Postfix.Un_Listen(instance.Character, BecomeChicken); CharacterCustomization_Listeners.BecomeHuman_Postfix.Un_Listen(instance.Character, BecomeHuman); } public bool TryFindMeshHider(out MeshHider hider) { return ((HandlerReferencer)instance).Handler.TryGetCustomActions<MeshHider>(ref hider); } public void ToggleChickenInit() { if (instance.CharacterCustomization.isCannibalizable) { SetOpacity(instance.IsChickenTemplate ? 1 : 0); } else { SetOpacity((!instance.IsChickenTemplate) ? 1 : 0); } } private void BecomeChicken(CharacterCustomization customization) { DoFadeAnimation(customization, instance.IsChickenTemplate ? 1 : 0); } private void BecomeHuman(CharacterCustomization customization) { DoFadeAnimation(customization, (!instance.IsChickenTemplate) ? 1 : 0); } private List<float> GetOpacityLibrary(Renderer renderer) { if (OpacityLibrary.TryGetValue(renderer, out var value)) { return value; } value = new List<float>(); OpacityLibrary[renderer] = value; Material[] materials = renderer.materials; for (int i = 0; i < materials.Length; i++) { if (materials[i].HasFloat(CharacterCustomization.Opacity)) { value.Add(materials[i].GetFloat(CharacterCustomization.Opacity)); } else { value.Add(1f); } } return value; } private void DoFadeAnimation(CharacterCustomization customization, float opacity) { KillTweeners(); foreach (Renderer template_Renderer in instance.Template_Renderers) { Material[] materials = template_Renderer.materials; List<float> opacityLibrary = GetOpacityLibrary(template_Renderer); for (int i = 0; i < materials.Length; i++) { if (materials[i].HasFloat(CharacterCustomization.Opacity)) { AddTweener((Tweener)(object)ShortcutExtensions.DOFloat(materials[i], opacityLibrary[i] * opacity, CharacterCustomization.Opacity, 1f)); } } } } private void SetOpacity(float opacity) { KillTweeners(); foreach (Renderer template_Renderer in instance.Template_Renderers) { Material[] materials = template_Renderer.materials; List<float> opacityLibrary = GetOpacityLibrary(template_Renderer); for (int i = 0; i < materials.Length; i++) { if (materials[i].HasFloat(CharacterCustomization.Opacity)) { materials[i].SetFloat(CharacterCustomization.Opacity, opacityLibrary[i] * opacity); } } } } private void AddTweener(Tweener tweener) { _activeTweens.Add(tweener); } private void KillTweeners() { foreach (Tweener activeTween in _activeTweens) { if (activeTween != null) { TweenExtensions.Kill((Tween)(object)activeTween, false); } } _activeTweens.Clear(); } } public class Peak_Constraints : Peak_Module { private List<ConstraintTemplate.BakedConstraintTemplate> BakedConstraints = new List<ConstraintTemplate.BakedConstraintTemplate>(); public bool ConstraintsAreActive = true; public override void Init() { RebuildConstraints(); CharacterCustomization_Listeners.BecomeChicken_Prefix.Listen(instance.Character, BecomeChicken); CharacterCustomization_Listeners.BecomeHuman_Prefix.Listen(instance.Character, BecomeHuman); } public override void Update() { UpdateConstraints(); } public override void Reset() { Reset_Constraints(); } public override void Destroy() { CharacterCustomization_Listeners.BecomeChicken_Prefix.Un_Listen(instance.Character, BecomeChicken); CharacterCustomization_Listeners.BecomeHuman_Prefix.Un_Listen(instance.Character, BecomeHuman); } public void RebuildConstraints() { string templateUID = ((HandlerReferencer)instance).Handler.Instance.TemplateUID; TemplateData val = default(TemplateData); if (TemplateRegistry.TryGetTemplate(templateUID, ref val)) { Debug.Log((object)(templateUID ?? "")); ConstraintTemplate[] componentsInChildren = val.Container.GetComponentsInChildren<ConstraintTemplate>(true); foreach (ConstraintTemplate constraintTemplate in componentsInChildren) { foreach (PrefabTemplate value in ((HandlerReferencer)instance).Handler.LoadedTemplates.Values) { RegisterConstraints(((Component)value).transform, val.Container.transform, constraintTemplate); } } } if (instance.CharacterCustomization.isCannibalizable) { Toggle_Constraints(instance.IsChickenTemplate); } else { Toggle_Constraints(!instance.IsChickenTemplate); } UpdateConstraints(); } public void Toggle_Constraints(bool isActive = true) { ConstraintsAreActive = isActive; if (!isActive && BakedConstraints.Count != 0) { for (int num = BakedConstraints.Count - 1; num >= 0; num--) { BakedConstraints[num].RestoreFollowers(); } } } public void Reset_Constraints() { if (BakedConstraints.Count != 0) { for (int num = BakedConstraints.Count - 1; num >= 0; num--) { BakedConstraints[num].RestoreFollowers(); } } BakedConstraints.Clear(); } public void RegisterConstraints(Transform loadedTemplate, Transform refTemplate, ConstraintTemplate constraintTemplate) { Transform origin = null; switch ((TargetMethod)Enum.Parse(typeof(TargetMethod), constraintTemplate.TargetMethod_data)) { case TargetMethod.Directory: origin = ((Component)((HandlerReferencer)instance).Handler).transform.Find(constraintTemplate.TargetPath); break; case TargetMethod.Name: origin = SearchUtils.IterativelyFindChild(((Component)((HandlerReferencer)instance).Handler).transform, constraintTemplate.TargetPath); break; } if (!Object.op_Implicit((Object)(object)refTemplate) || !Object.op_Implicit((Object)(object)constraintTemplate?.TargetObject)) { Debug.LogWarning((object)"Invalid Template Reference, Unable to build constraints."); return; } string text = SearchUtils.FindPath(refTemplate, constraintTemplate.TargetObject); text = text.Substring(text.IndexOf('/') + 1); Transform val = loadedTemplate.Find(text); if (!Object.op_Implicit((Object)(object)val)) { Debug.LogWarning((object)"Invalid Template Root, Unable to build constraints."); Debug.LogWarning((object)text); } else { ConstraintTemplate.BakedConstraintTemplate item = new ConstraintTemplate.BakedConstraintTemplate(constraintTemplate, origin, val); BakedConstraints.Add(item); } } public void UpdateConstraints() { if (!ConstraintsAreActive) { return; } foreach (ConstraintTemplate.BakedConstraintTemplate bakedConstraint in BakedConstraints) { bakedConstraint.UpdateFollowers(); } } private void BecomeChicken(CharacterCustomization customization) { Toggle_Constraints(instance.IsChickenTemplate); } private void BecomeHuman(CharacterCustomization customization) { Toggle_Constraints(!instance.IsChickenTemplate); } } public class Peak_HideTheBody : Peak_Module { public bool IsVertexGhostShowing => instance.Character?.refs.hideTheBody.isShowing ?? false; public override void Init() { Update_Renderers_VertexGhost(); HideTheBody_Listeners.Toggle_Postfix.Listen(instance.Character, Toggle); } public override void Destroy() { HideTheBody_Listeners.Toggle_Postfix.Un_Listen(instance.Character, Toggle); } public void Toggle(HideTheBody hideTheBody) { Update_Renderers_VertexGhost(); } public void Update_Renderers_VertexGhost() { foreach (Renderer template_Renderer in instance.Template_Renderers) { Material[] materials = template_Renderer.materials; for (int i = 0; i < materials.Length; i++) { materials[i].SetFloat(CharacterCustomization.VertexGhost, (float)((!IsVertexGhostShowing) ? 1 : 0)); } } } } public class Peak_LayerFix : Peak_Module { public override void Init() { Do_Layer_Fix(); Hide_Shadows(); } public void Do_Layer_Fix() { foreach (PrefabTemplate template in instance.Templates) { GameObjectExtensions.SetLayerRecursivly(((Component)template).gameObject, LayerMask.NameToLayer("Character")); } } public void Hide_Shadows() { foreach (PrefabTemplate template in instance.Templates) { Renderer[] componentsInChildren = ((Component)template).GetComponentsInChildren<Renderer>(true); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].shadowCastingMode = (ShadowCastingMode)0; } } } } public class Peak_ObjectToggler : Peak_Module { private List<PeakAccessoryObjectToggler> togglers = new List<PeakAccessoryObjectToggler>(); public override void Init() { RegisterObjectTogglers(); CharacterCustomization_Listeners.OnPlayerDataChange_Postfix.Listen(instance.Character, UpdateObjectTogglers); } public override void Reset() { instance.Reset_Customization_Renderers(); togglers.Clear(); } public override void Destroy() { CharacterCustomization_Listeners.OnPlayerDataChange_Postfix.Un_Listen(instance.Character, UpdateObjectTogglers); } public void RegisterObjectTogglers() { togglers = new List<PeakAccessoryObjectToggler>(); foreach (TaggedBehaviour tagsInTemplate in ((HandlerReferencer)instance).Handler.GetTagsInTemplates(new string[1] { "PeakAccessoryObjectToggler" })) { if (tagsInTemplate is PeakAccessoryObjectToggler peakAccessoryObjectToggler) { peakAccessoryObjectToggler.Rebuild(); togglers.Add(peakAccessoryObjectToggler); } } UpdateObjectTogglers(); } public void UpdateObjectTogglers(CharacterCustomization _ = null) { HashSet<PeakAccessoryType> hashSet = new HashSet<PeakAccessoryType>(); foreach (PeakAccessoryObjectToggler toggler in togglers) { ((Component)toggler).gameObject.SetActive(toggler.HideOnTarget); foreach (PeakAccessoryTarget toggleTargetType in toggler.ToggleTargetTypes) { if (instance.Is_PeakAccessoryTarget_Active(toggleTargetType)) { ((Component)toggler).gameObject.SetActive(!toggler.HideOnTarget); if (toggler.HideTargetAccessory) { hashSet.Add(toggleTargetType.type); } } } } instance.Reset_Customization_Renderers(); foreach (PeakAccessoryType item in hashSet) { instance.Toggle_PeakAccessoryType(item); } } } public class Peak_PulseStatus : Peak_Module { public override void Init() { CharacterCustomization_Listeners.PulseStatus_Postfix.Listen(instance.Character, DoPulseStatus); } public override void Destroy() { CharacterCustomization_Listeners.PulseStatus_Postfix.Un_Listen(instance.Character, DoPulseStatus); } public void DoPulseStatus(Color color) { //IL_003b: Unknown result type (might be due to invalid IL or missing references) foreach (Renderer template_Renderer in instance.Template_Renderers) { Material[] materials = template_Renderer.materials; for (int i = 0; i < materials.Length; i++) { if (materials[i].HasColor(CharacterCustomization.StatusColor)) { materials[i].SetColor(CharacterCustomization.StatusColor, color); } if (materials[i].HasFloat(CharacterCustomization.StatusGlow)) { materials[i].SetFloat(CharacterCustomization.StatusGlow, 1f); ShortcutExtensions.DOFloat(materials[i], 0f, CharacterCustomization.StatusGlow, 0.5f); } } } } } public class Peak_ScoutRank : Peak_Module { public override void Init() { } } public class Peak_SkinToneHelper : Peak_Module { public List<PeakSkinToneHelper> Registered_SkinToneHelpers = new List<PeakSkinToneHelper>(); public override void Init() { RegisterSkinToneHelpers(); CharacterCustomization_Listeners.OnPlayerDataChange_Postfix.Listen(instance.Character, UpdateSkinTone); } public override void Reset() { Registered_SkinToneHelpers.Clear(); } public override void Destroy() { CharacterCustomization_Listeners.OnPlayerDataChange_Postfix.Un_Listen(instance.Character, UpdateSkinTone); } public void RegisterSkinToneHelpers() { foreach (TaggedBehaviour tagsInTemplate in ((HandlerReferencer)instance).Handler.GetTagsInTemplates(new string[1] { "SkinTone" })) { if (tagsInTemplate is PeakSkinToneHelper item) { Registered_SkinToneHelpers.Add(item); } } UpdateSkinTone(instance.CharacterCustomization); } public void UpdateSkinTone(CharacterCustomization customization) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) try { Color color = ((Renderer)customization.refs.mainRenderer).material.GetColor(CharacterCustomization.SkinColor); foreach (PeakSkinToneHelper registered_SkinToneHelper in Registered_SkinToneHelpers) { registered_SkinToneHelper.Set_SkinTone(color); } } catch { Debug.LogError((object)"Couldn't Update SkinTone."); } } } public class Peak_Status : Peak_Module { public override void Init() { } } public class Peak_SteamAvatar : Peak_Module { public override void Init() { Update_SteamAvatarHelpers(); } public void Update_SteamAvatarHelpers() { foreach (TaggedBehaviour tagsInTemplate in ((HandlerReferencer)instance).Handler.GetTagsInTemplates(new string[1] { "SteamAvatar" })) { if (tagsInTemplate is SteamAvatarHelper steamAvatarHelper) { steamAvatarHelper.Load_Player_Avatar(instance.PhotonView); } } } } public class Peak_TextureHelper : Peak_Module { private List<PeakAccessoryTextureHelper> textureHelpers = new List<PeakAccessoryTextureHelper>(); public override void Init() { RegisterTextureHelpers(); CharacterCustomization_Listeners.OnPlayerDataChange_Postfix.Listen(instance.Character, UpdateTextureHelpers); } public override void Reset() { textureHelpers.Clear(); } public override void Destroy() { CharacterCustomization_Listeners.OnPlayerDataChange_Postfix.Un_Listen(instance.Character, UpdateTextureHelpers); } public void RegisterTextureHelpers() { foreach (TaggedBehaviour tagsInTemplate in ((HandlerReferencer)instance).Handler.GetTagsInTemplates(new string[1] { "PeakAccessoryTextureHelper" })) { if (tagsInTemplate is PeakAccessoryTextureHelper peakAccessoryTextureHelper) { peakAccessoryTextureHelper.Reset(); textureHelpers.Add(peakAccessoryTextureHelper); } } UpdateTextureHelpers(instance.CharacterCustomization); } public void UpdateTextureHelpers(CharacterCustomization customization) { foreach (PeakAccessoryTextureHelper textureHelper in textureHelpers) { textureHelper.Set_Texture(instance.Fetch_PeakAccessoryType_Texture(PeakAccessoryType.Outfit)); } } } public class Peak_TextureSwapper : Peak_Module { private List<PeakAccessoryTextureSwapper> textureSwappers = new List<PeakAccessoryTextureSwapper>(); public override void Init() { RegisterTextureSwappers(); CharacterCustomization_Listeners.OnPlayerDataChange_Postfix.Listen(instance.Character, UpdateTextureSwappers); } public override void Reset() { textureSwappers.Clear(); } public override void Destroy() { CharacterCustomization_Listeners.OnPlayerDataChange_Postfix.Un_Listen(instance.Character, UpdateTextureSwappers); } public void RegisterTextureSwappers() { foreach (TaggedBehaviour tagsInTemplate in ((HandlerReferencer)instance).Handler.GetTagsInTemplates(new string[1] { "PeakAccessoryTextureSwapper" })) { if (tagsInTemplate is PeakAccessoryTextureSwapper peakAccessoryTextureSwapper) { peakAccessoryTextureSwapper.Reset(); textureSwappers.Add(peakAccessoryTextureSwapper); } } UpdateTextureSwappers(instance.CharacterCustomization); } public void UpdateTextureSwappers(CharacterCustomization customization) { foreach (PeakAccessoryTextureSwapper textureSwapper in textureSwappers) { foreach (PeakAccessoryTarget toggleTargetType in textureSwapper.ToggleTargetTypes) { if (instance.Is_PeakAccessoryTarget_Active(toggleTargetType)) { textureSwapper.Set_CurrentTarget(toggleTargetType); break; } textureSwapper.Set_Texture(null); } } } } public abstract class Peak_Module { public Peak_CustomHelper instance; public virtual void Init() { } public virtual void Update() { } public virtual void Reset() { } public virtual void Destroy() { } } public static class PluginInfo { public const string GUID = "UCustomPrefabsAPI.Peak"; public const string NAME = "UCustomPrefabsAPI.Peak"; public const string VERSION = "0.0.1"; public const string WEBSITE = "https://github.com/ScottyFox/UCustomPrefabsAPI/tree/peak"; } [BepInPlugin("UCustomPrefabsAPI.Peak", "UCustomPrefabsAPI.Peak", "0.0.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public static ConfigFile config; public static ConfigEntry<string> TemplatesFileFinderName; public static ConfigEntry<bool> EveryoneUsePreferredConfig; public static ConfigEntry<string> PreferredCharacterConfig; public static ConfigEntry<string> PreferredSkeletonConfig; public static ConfigEntry<string> PreferredChickenConfig; internal static Harmony instance = new Harmony("UCustomPrefabsAPI.Peak"); private void Awake() { try { SetUpConfig(); RegisterAssetBundles(); RegisterCustomActions(); RegisterCustomTemplates(); instance.PatchAll(Assembly.GetExecutingAssembly()); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin UCustomPrefabsAPI.Peak is loaded!"); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin UCustomPrefabsAPI.Peak failed to load..."); ((BaseUnityPlugin)this).Logger.LogError((object)ex); } } public void SetUpConfig() { config = ((BaseUnityPlugin)this).Config; TemplatesFileFinderName = config.Bind<string>("UCustomPrefabs Config", "Templates Folder Finder File", "ucustomprefabs.templates.txt", (ConfigDescription)null); EveryoneUsePreferredConfig = config.Bind<bool>("Player Config", "Everyone Uses Preferred Templates", false, (ConfigDescription)null); PreferredCharacterConfig = config.Bind<string>("Player Config", "Preferred Character Template", "", (ConfigDescription)null); PreferredSkeletonConfig = config.Bind<string>("Player Config", "Preferred Skeleton Template", "", (ConfigDescription)null); PreferredChickenConfig = config.Bind<string>("Player Config", "Preferred Chicken Template", "", (ConfigDescription)null); } public static void RegisterAssetBundles() { AssetBundleRegistry.RegisterEmbedded<Plugin>("custompassporticons", "CustomPassportIcons"); } public static void RegisterCustomActions() { CustomActionsRegistry.Register<Peak_CustomHelper>("Peak_PlayerHelper"); CustomActionsRegistry.Register<MeshHider>("MeshHider"); CustomActionsRegistry.Register<RigHelper>("RigHelper"); CustomActionsRegistry.Register<ShaderFix>("ShaderFix"); } public static void RegisterCustomTemplates() { } public static void BulkLoadTemplates() { foreach (string item in UCustomPrefabFileHelper.FindDirectoriesWithFileName(Paths.PluginPath, TemplatesFileFinderName.Value)) { UCustomPrefabFileHelper.TryToLoadTemplateAssetBundlesFromPath<Plugin>(item); } TemplateRegistry.CommitLateRegistry(); } } [HarmonyPatch] internal static class CustomizationPatch { [HarmonyPatch(typeof(Customization), "GetList")] [HarmonyPrefix] private static bool GetList_Prefix_Patch(Type type, ref object[] __result) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) if (!PassportHelper.IsSpecialCustomization(type, out var templateType)) { return true; } object[] array = PassportHelper.Construct_Customization_List(templateType); __result = array; return false; } public static CustomizationOption[] Test_list() { return Singleton<Customization>.Instance.GetList((Type)(-13377701)); } } [HarmonyPatch] internal static class GameHandlerPatch { [HarmonyPatch(typeof(GameHandler), "Initialize")] [HarmonyPostfix] private static void Initialize_Postfix_Patch(ref GameHandler __instance) { Plugin.BulkLoadTemplates(); } } [HarmonyPatch] internal static class MainMenuPatch { [HarmonyPatch(typeof(MainMenu), "Start")] [HarmonyPostfix] private static void Start_Postfix_Patch(ref MainMenu __instance) { InstanceManager.Verify(); Peak_SteamUtils.Clear_Loaded_Avatars(); } } [HarmonyPatch] internal static class PassportPatch { [HarmonyPatch(typeof(PassportManager), "SetOption")] [HarmonyPrefix] private static bool SetOption_Prefix_Patch(ref PassportManager __instance, CustomizationOption option) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) Debug.Log((object)"SetOption_Prefix_Patch"); if (!PassportHelper.IsSpecialCustomization(option.type, out var _)) { return true; } Debug.Log((object)"Is Custom Typed SetOption"); if (!(option is PassportHelper.CustomizationOption_Custom customizationOption_Custom)) { return true; } string templateID = customizationOption_Custom.TemplateID; Debug.Log((object)("ID Selected = " + templateID)); switch (customizationOption_Custom.TemplateType) { case PeakTemplateType.Character: PlayerConfigHelper.SetCharacterTemplate(templateID); break; case PeakTemplateType.Skeleton: PlayerConfigHelper.SetSkeletonTemplate(templateID); break; case PeakTemplateType.Chicken: PlayerConfigHelper.SetChickenTemplate(templateID); break; } __instance.SetActiveButton(false); __instance.dummy.UpdateDummy(); return false; } [HarmonyPatch(typeof(PassportManager), "SetActiveButton")] [HarmonyPrefix] private static bool SetActiveButton_Prefix_Patch(ref PassportManager __instance) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) if (!PassportHelper.IsSpecialCustomization(__instance.activeType, out var templateType)) { return true; } if (!PlayerConfigHelper.TryGetConfigHandler(Character.localCharacter, out var config)) { return true; } PassportHelper.Fetch_Template_List(templateType); string text = templateType switch { PeakTemplateType.Character => config.CurrentCharacterTemplate, PeakTemplateType.Skeleton => config.CurrentSkeletonTemplate, PeakTemplateType.Chicken => config.CurrentChickenTemplate, _ => string.Empty, }; PassportHelper.CustomizationOption_Custom customizationOption_Custom = null; PassportButton[] buttons = __instance.buttons; foreach (PassportButton val in buttons) { if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.currentOption) && val.currentOption is PassportHelper.CustomizationOption_Custom customizationOption_Custom2) { if (text == customizationOption_Custom2.TemplateID) { customizationOption_Custom = customizationOption_Custom2; ((Graphic)val.border).color = __instance.activeBorderColor; } else { ((Graphic)val.border).color = __instance.inactiveBorderColor; } } } ((TMP_Text)PassportHelper.Custom_Name_Display).text = customizationOption_Custom?.DisplayName; return false; } [HarmonyPatch(typeof(PassportManager), "OpenTab")] [HarmonyPrefix] private static bool OpenTab_Prefix_Patch(ref PassportManager __instance, Type type) { //IL_0000: 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_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) PassportHelper.SwitchToCustomTab(type); __instance.activeType = type; if (!PassportHelper.IsSpecialCustomization(__instance.activeType, out var _)) { return true; } __instance.CameraOut(); __instance.SetButtons(false); __instance.dummy.UpdateDummy(); return false; } } [HarmonyPatch] internal static class PlayerPatch { [HarmonyPatch(typeof(Character), "Start")] [HarmonyPostfix] private static void Start_Postfix_Patch(ref Character __instance) { if (!__instance.isBot && Object.op_Implicit((Object)(object)((Component)__instance).transform.Find("Scout")) && !Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<PlayerConfigHelper>())) { ((Component)__instance).gameObject.AddComponent<PlayerConfigHelper>(); } } } [HarmonyPatch] internal static class SkeletonPatch { [HarmonyPatch(typeof(Skelleton), "SpawnSkelly")] [HarmonyPostfix] private static void SpawnSkelly_Postfix_Patch(ref Skelleton __instance, Character target) { if (PlayerConfigHelper.TryGetConfigHandler(target, out var config)) { config.CreateSkeletonInstance(__instance); } } } [Serializable] public class PeakAccessoryObjectToggler : TaggedBehaviour { public bool HideOnTarget; public bool HideTargetAccessory = true; public List<string> Hints = new List<string>(); public List<string> Types = new List<string>(); public List<PeakAccessoryTarget> ToggleTargetTypes = new List<PeakAccessoryTarget>(); public void Rebuild() { if (Hints.Count != Types.Count) { Debug.LogWarning((object)("Invalid Hint:Types Count, PeakAccessoryTargets in " + ((Object)((Component)this).gameObject).name + " : PeakAccessoryObjectToggler")); return; } for (int i = 0; i < Hints.Count; i++) { ToggleTargetTypes.Add(new PeakAccessoryTarget(Types[i], Hints[i])); } } } [Serializable] public struct PeakAccessoryTextureSwapperPair { public PeakAccessoryTarget TargetAccessory; public Texture2D Texture; } [Serializable] public class PeakAccessoryTextureSwapper : TaggedBehaviour { public string TargetTexture = "_MainTex"; public List<string> Hints = new List<string>(); public List<string> Types = new List<string>(); public List<Texture2D> Textures = new List<Texture2D>(); public List<int> TargetMaterials = new List<int>(); public List<PeakAccessoryTarget> ToggleTargetTypes = new List<PeakAccessoryTarget>(); public List<Texture> DefaultTextures; public void Reset() { if (Hints.Count != Types.Count) { Debug.LogWarning((object)("Invalid Hint:Types Count, PeakAccessoryTargets in " + ((Object)((Component)this).gameObject).name + " : PeakAccessoryTextureSwapper")); return; } DefaultTextures = null; for (int i = 0; i < Hints.Count; i++) { ToggleTargetTypes.Add(new PeakAccessoryTarget(Types[i], Hints[i])); } } public void Set_CurrentTarget(PeakAccessoryTarget target) { int index = ToggleTargetTypes.IndexOf(target); Set_Texture((Texture)(object)Textures[index]); } public void Register_Default_Textures() { if (DefaultTextures != null) { return; } DefaultTextures = new List<Texture>(); Material[] sharedMaterials = ((Component)this).GetComponent<Renderer>().sharedMaterials; foreach (int targetMaterial in TargetMaterials) { try { DefaultTextures.Add(sharedMaterials[targetMaterial].GetTexture(TargetTexture)); } catch { } } } public void Set_Texture(Texture texture) { Register_Default_Textures(); Renderer component = ((Component)this).GetComponent<Renderer>(); if (!Object.op_Implicit((Object)(object)component)) { return; } Material[] materials = component.materials; if ((Object)(object)texture == (Object)null) { for (int i = 0; i < TargetMaterials.Count; i++) { try { materials[TargetMaterials[i]].SetTexture(TargetTexture, DefaultTextures[i]); } catch { } } return; } foreach (int targetMaterial in TargetMaterials) { try { materials[targetMaterial].SetTexture(TargetTexture, texture); } catch { } } } } public class PeakSkinToneHelper : TaggedBehaviour { [SerializeField] [HideInInspector] public List<int> TargetMaterials = new List<int>(); public void Set_SkinTone(Color skinColor) { //IL_0047: Unknown result type (might be due to invalid IL or missing references) Renderer component = ((Component)this).GetComponent<Renderer>(); if (!Object.op_Implicit((Object)(object)component)) { return; } Material[] materials = component.materials; foreach (int targetMaterial in TargetMaterials) { materials[targetMaterial].SetFloat("_UseSkinTone", 1f); materials[targetMaterial].SetColor(CharacterCustomization.SkinColor, skinColor); } } } public enum PeakAccessoryType { Accessory, Eyes, Outfit, Hat, Mouth, Shorts, Skirt, NoPants, ScoutRank } internal static class Peak_InfoStub { public static readonly string[] Default_Desc = new string[1] { "[?] Custom" }; public static readonly string Default_ID = string.Empty; public static readonly Dictionary<PeakAccessoryType, string[]> Descriptions = new Dictionary<PeakAccessoryType, string[]> { [PeakAccessoryType.Accessory] = new string[21] { "[0] None", "[1] Charlie", "[2] Jagged Hair", "[3] Parted Hair", "[4] Microbangs", "[5] Raised Brow", "[6] Brows Dot", "[7] Brows Thick", "[8] Brows Angry", "[9] Glasses Round", "[10] Aviator", "[11] Cheekbones", "[12] Face Paint", "[13] Scar", "[14] Bow", "[15] Eyepatch", "[16] Glasses Broken", "[17] Groucho", "[18] Tiny Sunglasses", "[19] Scar 2", "[?] Custom" }, [PeakAccessoryType.Eyes] = new string[19] { "[0] Basic", "[1] Lashes", "[2] Half", "[3] Shine", "[4] Squint", "[5] Angry", "[6] Eyeliner", "[7] Sad", "[8] Cry", "[9] Tired", "[10] Almond", "[11] Surprised", "[12] Small", "[13] Concern", "[14] Anime", "[15] Real", "[16] Aggro", "[17] Inverted", "[?] Custom" }, [PeakAccessoryType.Outfit] = new string[19] { "[0] Seagull (Shorts)", "[1] Seagull (Skirt)", "[2] Turtle (Shorts)", "[3] Turtle (Skirt)", "[4] Sailor (Shorts)", "[5] Sailor (Skirt)", "[6] Castaway (Shorts)", "[7] Castaway (Skirt)", "[8] Tropical (Shorts)", "[9] Tropical (Skirt)", "[10] Cookie (Shorts)", "[11] Cookie (Skirt)", "[12] Balloon (Shorts)", "[13] Balloon (Skirt)", "[14] Scoutmaster (Shorts)", "[15] Scoutmaster (Skirt)", "[16] Cowboy", "[17] Astronaut", "[?] Custom" }, [PeakAccessoryType.Hat] = new string[28] { "[0] Cap", "[1] Beret", "[2] Pith (Fedora)", "[3] Propeller", "[4] Straw", "[5] Aviator", "[6] Sailor", "[7] Medic", "[8] Midsummer", "[9] Mushroom", "[10] Crab", "[11] Courier", "[12] Scoutmaster", "[13] Bandana", "[14] Ninja Headband", "[15] Chef Hat", "[16] Wizard Hat", "[17] Wolf Ears", "[18] Crown", "[19] Goat", "[20] DesertHat", "[21] Visor", "[22] SunHat", "[23] Cowboy", "[24] BingBong", "[25] RacingHelmet", "[26] Astronaut", "[?] Custom" }, [PeakAccessoryType.Mouth] = new string[20] { "[0] Smile", "[1] CalArts", "[2] Cat", "[3] Cheek", "[4] Drool", "[5] Sad", "[6] Frown", "[7] Kissy", "[8] Nonplussed", "[9] O", "[10] Squiggle", "[11] Triangle", "[12] Smirk", "[13] Cringe", "[14] Teeth", "[15] Vamp", "[16] Aggro", "[17] Wacky", "[18] Labu", "[?] Custom" }, [PeakAccessoryType.ScoutRank] = new string[10] { "[0] Default", "[1] Ascent 1", "[2] Ascent 2", "[3] Ascent 3", "[4] Ascent 4", "[5] Ascent 5", "[6] Ascent 6", "[7] Ascent 7", "[8] Ascent 8", "[?] Custom" } }; public static readonly Dictionary<PeakAccessoryType, string[]> IDs = new Dictionary<PeakAccessoryType, string[]> { [PeakAccessoryType.Accessory] = new string[21] { "Accessory_None", "Accessory_Charlie", "Accessory_JaggedHair", "Accessory_PartedHair", "Accessory_Microbangs", "Accessory_RaisedBrow", "Accessory_Brows_Dot", "Accessory_Brows_Thick", "Accessory_Brows_Angry", "Accessory_Glasses_Round", "Accessory_Aviator", "Accessory_Cheekbones", "Accessory_Face_Paint", "Accessory_Scar", "Accessory_Bow", "Accessory_Eyepatch", "Accessory_Glasses_Broken", "Accessory_Groucho", "Accessory_Tiny_Sunglasses", "Accessory_Scar2", "[?] Custom" }, [PeakAccessoryType.Eyes] = new string[19] { "Eye_Basic", "Eye_Lashes", "Eye_Half", "Eye_Shine", "Eye_Squint", "Eye_Angry", "Eye_Eyeliner", "Eye_Sad", "Eye_Cry", "Eye_Tired", "Eye_Almond", "Eye_Surprised", "Eye_Small", "Eye_Concern", "Eye_Anime", "Eye_Real", "Eye_Aggro", "Eye_Inverted", "[?] Custom" }, [PeakAccessoryType.Outfit] = new string[19] { "Fit_Seagull_Shorts", "Fit_Seagull_Skirt", "Fit_Turtle_Shorts", "Fit_Turtle_Skirt", "Fit_Sailor_Shorts", "Fit_Sailor_Skirt", "Fit_Castaway_Shorts", "Fit_Castaway_Skirt", "Fit_Tropical_Shorts", "Fit_Tropical_Skirt", "Fit_Cookie_Shorts", "Fit_Cookie_Skirt", "Fit_Balloon_Shorts", "Fit_Balloon_Skirt", "Fit_Scoutmaster_Shorts", "Fit_Scoutmaster_Skirt", "Fit_Cowboy", "Fit_Astronaut", "[?] Custom" }, [PeakAccessoryType.Hat] = new string[28] { "Hat_Cap", "Hat_Beret", "Hat_Pith", "Hat_Propeller", "Hat_Straw", "Hat_Aviator", "Hat_Sailor", "Hat_Medic", "Hat_Midsummer", "Hat_Mushroom", "Hat_Crab", "Hat_Courier", "Hat_Scoutmaster", "Hat_Bandana", "Hat_NinjaHeadband", "Hat_ChefHat", "Hat_WizardHat", "Hat_WolfEars", "Hat_Crown", "Hat_Goat", "Hat_DesertHat", "Hat_Visor", "Hat_SunHat", "Hat_Cowboy", "Hat_BingBong", "Hat_RacingHelmet", "Hat_Astronaut", "[?] Custom" }, [PeakAccessoryType.Mouth] = new string[20] { "Mouth_Smile", "Mouth_CalArts", "Mouth_Cat", "Mouth_Cheek", "Mouth_Drool", "Mouth_Sad", "Mouth_Frown", "Mouth_Kissy", "Mouth_Nonplussed", "Mouth_O", "Mouth_Squiggle", "Mouth_Triangle", "Mouth_Smirk", "Mouth_Cringe", "Mouth_Teeth", "Mouth_Vamp", "Mouth_Aggro", "Mouth_Wacky", "Mouth_Labu", "[?] Custom" }, [PeakAccessoryType.ScoutRank] = new string[10] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "?" } }; public static string[] Fetch_Desc(PeakAccessoryType type) { if (Descriptions.TryGetValue(type, out var value)) { return value; } return Default_Desc; } public static string Fetch_ID(PeakAccessoryType type, int index) { if (!IDs.TryGetValue(type, out var value)) { return Default_ID; } return value[Mathf.Clamp(index, 0, value.Length - 1)]; } } [Serializable] public struct PeakAccessoryTarget { public PeakAccessoryType type; public string hint; public PeakAccessoryTarget(string type, string hint) { Enum.TryParse<PeakAccessoryType>(type.TrimStart(Array.Empty<char>()).TrimEnd(Array.Empty<char>()), ignoreCase: true, out this.type); this.hint = hint; } } } namespace UCustomPrefabsAPI.Peak.Scripts { public static class LobbyAnalyzer { public static void Analyze() { //IL_000e: 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) //IL_001b: Unknown result type (might be due to invalid IL or missing references) CSteamID val = default(CSteamID); if (GameHandler.GetService<SteamLobbyHandler>().InSteamLobby(ref val)) { int numLobbyMembers = SteamMatchmaking.GetNumLobbyMembers(val); for (int i = 0; i < numLobbyMembers; i++) { SteamMatchmaking.GetLobbyMemberByIndex(val, i); } } foreach (Player allPlayer in PlayerHandler.GetAllPlayers()) { _ = allPlayer; } } } public static class MaterialEvaluator { public struct MaterialInfoOutput { public Material materialRef; public Dictionary<string, float> float_dict; public Dictionary<string, Vector4> vector_dict; public Dictionary<string, Texture> texture_dict; public MaterialInfoOutput(Material material) { //IL_007e: Unknown result type (might be due to invalid IL or missing references) materialRef = material; string[] propertyNames = material.GetPropertyNames((MaterialPropertyType)0); string[] propertyNames2 = material.GetPropertyNames((MaterialPropertyType)2); string[] propertyNames3 = material.GetPropertyNames((MaterialPropertyType)4); float_dict = new Dictionary<string, float>(); vector_dict = new Dictionary<string, Vector4>(); texture_dict = new Dictionary<string, Texture>(); string[] array = propertyNames; foreach (string text in array) { float_dict[text] = material.GetFloat(text); } array = propertyNames2; foreach (string text2 in array) { vector_dict[text2] = material.GetVector(text2); } array = propertyNames3; foreach (string text3 in array) { texture_dict[text3] = material.GetTexture(text3); } } public void Retarget(Material material) { //IL_006b: Unknown result type (might be due to invalid IL or missing references) foreach (string key in float_dict.Keys) { material.SetFloat(key, float_dict[key]); } foreach (string key2 in vector_dict.Keys) { material.SetVector(key2, vector_dict[key2]); } foreach (string key3 in texture_dict.Keys) { material.SetTexture(key3, texture_dict[key3]); } } public void Reapply() { //IL_0075: Unknown result type (might be due to invalid IL or missing references) foreach (string key in float_dict.Keys) { materialRef.SetFloat(key, float_dict[key]); } foreach (string key2 in vector_dict.Keys) { materialRef.SetVector(key2, vector_dict[key2]); } foreach (string key3 in texture_dict.Keys) { materialRef.SetTexture(key3, texture_dict[key3]); } } } public static MaterialInfoOutput EvaluateMaterial(Material material) { return new MaterialInfoOutput(material); } } } namespace UCustomPrefabsAPI.Peak.ActionUtils { public class ListenerHelper<A, B> where A : class { private Dictionary<A, List<Action<B>>> listeners = new Dictionary<A, List<Action<B>>>(); public void Listen(A target, Action<B> callback) { if (target != null && callback != null) { if (!listeners.TryGetValue(target, out var value)) { value = new List<Action<B>>(); listeners[target] = value; } if (!value.Contains(callback)) { value.Add(callback); } } } public void Un_Listen(A target, Action<B> callback) { if (target != null && callback != null && listeners.TryGetValue(target, out var value)) { value.Remove(callback); } } public void Clear_Listeners() { listeners.Clear(); } public void Invoke(A target, B args) { if (target == null) { return; } Validate_Listeners(); if (!listeners.TryGetValue(target, out var value)) { return; } for (int i = 0; i < value.Count; i++) { Action<B> action = value[i]; if (action != null) { try { action(args); } catch (Exception) { value.RemoveAt(i--); } } } if (value.Count == 0) { listeners.Remove(target); } } public void Validate_Listeners() { bool flag = false; foreach (List<Action<B>> value in listeners.Values) { if (value == null) { flag = true; break; } } if (!flag) { return; } Debug.LogWarning((object)"Some Listeners have become invalid, Rebuilding Listeners."); Dictionary<A, List<Action<B>>> dictionary = new Dictionary<A, List<Action<B>>>(); foreach (KeyValuePair<A, List<Action<B>>> listener in listeners) { if (listener.Key == null) { continue; } List<Action<B>> list = new List<Action<B>>(); foreach (Action<B> item in list) { if (item != null) { list.Add(item); } } dictionary[listener.Key] = list; } listeners = dictionary; } } } namespace UCustomPrefabsAPI.Peak.Utils { internal static class CustomTemplateUtils { public const string Default_Template = "Default"; public const string NoPreference_Template = "NoPreference"; public static readonly List<string> Special_TemplateNames = new List<string>(2) { "Default", "NoPreference" }; public static List<string> Fetch_Peak_Custom_Template_IDs() { return TemplateRegistry.GetTemplatesWithCustomActions<Peak_CustomHelper>(); } public static Dictionary<string, Peak_Custom_Template> Fetch_Peak_Custom_Templates(PeakTemplateType type) { Dictionary<string, Peak_Custom_Template> dictionary = new Dictionary<string, Peak_Custom_Template>(); TemplateData val = default(TemplateData); foreach (string item in Fetch_Peak_Custom_Template_IDs()) { if (!TemplateRegistry.TryGetTemplate(item, ref val)) { continue; } CustomActionsTemplate val2 = ((IEnumerable<CustomActionsTemplate>)val.CustomActionsTemplates).FirstOrDefault((Func<CustomActionsTemplate, bool>)((CustomActionsTemplate cat) => cat is Peak_Custom_Template)); if (Object.op_Implicit((Object)(object)val2)) { Peak_Custom_Template peak_Custom_Template = (Peak_Custom_Template)(object)val2; if (peak_Custom_Template.TemplateType == type) { dictionary[item] = peak_Custom_Template; } } } return dictionary; } public static Texture Get_Peak_Custom_Template_Icon(string templateID) { Texture result = null; TemplateData val = default(TemplateData); if (TemplateRegistry.TryGetTemplate(templateID, ref val)) { Peak_Custom_Template peak_Custom_Template = (Peak_Custom_Template)(object)((IEnumerable<CustomActionsTemplate>)val.CustomActionsTemplates).FirstOrDefault((Func<CustomActionsTemplate, bool>)((CustomActionsTemplate a) => a is Peak_Custom_Template)); if ((Object)(object)peak_Custom_Template != (Object)null) { result = peak_Custom_Template.PassportIcon; } } return result; } public static string Get_Peak_Custom_Template_DisplayName(string templateID) { string result = null; TemplateData val = default(TemplateData); if (TemplateRegistry.TryGetTemplate(templateID, ref val)) { Peak_Custom_Template peak_Custom_Template = (Peak_Custom_Template)(object)((IEnumerable<CustomActionsTemplate>)val.CustomActionsTemplates).FirstOrDefault((Func<CustomActionsTemplate, bool>)((CustomActionsTemplate a) => a is Peak_Custom_Template)); if ((Object)(object)peak_Custom_Template != (Object)null) { result = peak_Custom_Template.PassportDisplayName; } } return result; } public static bool IsSpecialTemplate(string templateID) { return Special_TemplateNames.Contains(templateID); } public static string Evaluate_Peak_Custom_Template(PlayerConfigHelper config, PeakTemplateType type, string templateID) { if (templateID == "Default") { return "Default"; } Dictionary<string, Peak_Custom_Template> dictionary = Fetch_Peak_Custom_Templates(type); if (!IsSpecialTemplate(templateID) && (string.IsNullOrWhiteSpace(templateID) || !dictionary.TryGetValue(templateID, out var _))) { templateID = "NoPreference"; } if (templateID == "NoPreference") { templateID = Fetch_Preferred_Peak_Custom_Template(dictionary, config, type, templateID); } return templateID; } private static string Fetch_Preferred_Peak_Custom_Template(Dictionary<string, Peak_Custom_Template> templates, PlayerConfigHelper config, PeakTemplateType type, string templateID) { if (type == PeakTemplateType.Character) { return "Default"; } if (Fetch_Peak_Custom_Templates(PeakTemplateType.Character).TryGetValue(config.CurrentCharacterTemplate, out var value)) { Peak_Custom_Template value2; switch (type) { case PeakTemplateType.Skeleton: templateID = ((!(value.PreferredSkeletonID == "Default")) ? ((!templates.TryGetValue(value.PreferredSkeletonID, out value2)) ? "Default" : value.PreferredSkeletonID) : "Default"); break; case PeakTemplateType.Chicken: templateID = ((!(value.PreferredChickenID == "Default")) ? ((!templates.TryGetValue(value.PreferredChickenID, out value2)) ? "Default" : value.PreferredChickenID) : "Default"); break; } } return templateID; } public static PeakTemplateType GetHandlerType(UCustomPrefabHandler handler) { TemplateData val = default(TemplateData); if (!TemplateRegistry.TryGetTemplate(handler.Instance.TemplateUID, ref val)) { return PeakTemplateType.Character; } CustomActionsTemplate val2 = ((IEnumerable<CustomActionsTemplate>)val.CustomActionsTemplates).FirstOrDefault((Func<CustomActionsTemplate, bool>)((CustomActionsTemplate cat) => cat is Peak_Custom_Template)); if (!Object.op_Implicit((Object)(object)val2)) { return PeakTemplateType.Character; } return ((Peak_Custom_Template)(object)val2).TemplateType; } } internal static class PassportHelper { public class CustomizationOption_Custom : CustomizationOption { public string TemplateID = string.Empty; public string DisplayName = string.Empty; public PeakTemplateType TemplateType; } [CompilerGenerated] private static class <>O { public static UnityAction <0>__TogglePassportBookmark; } public const int Character_Enum = -13377701; public const int Skeleton_Enum = -13377702; public const int Chicken_Enum = -13377703; public static Vector3 Original_ButtonContainer_Position; public static readonly Vector3 ButtonContainer_Name_Offset = new Vector3(0f, -20f, 0f); public static List<PassportTab> CustomTabs = new List<PassportTab>(); public static GameObject CustomContainer; public static Button BookmarkButton; public static TextMeshProUGUI Custom_Name_Display; public static Texture NoPreferenceIcon => AssetBundleRegistry.LoadAsset<Texture>("CustomPassportIcons", "NoPreferenceIcon"); public static Texture CustomCharacterIcon => AssetBundleRegistry.LoadAsset<Texture>("CustomPassportIcons", "CustomCharacterPassportIcon"); public static Texture CustomSkeletonIcon => AssetBundleRegistry.LoadAsset<Texture>("CustomPassportIcons", "CustomSkeletonPassportIcon"); public static Texture CustomChickenIcon => AssetBundleRegistry.LoadAsset<Texture>("CustomPassportIcons", "CustomChickenPassportIcon"); public static GameObject CustomBookmarkPrefab => AssetBundleRegistry.LoadPrefab("CustomPassportIcons", "BookmarkButton"); public static Texture EmptyIcon => AssetBundleRegistry.LoadAsset<Texture>("CustomPassportIcons", "Empty"); public static Texture LockedIcon => ((Component)PassportManager.instance.buttons[0]).GetComponent<PassportButton>().lockedIcon.texture; public static Transform OriginalTabContainer => ((Component)PassportManager.instance.tabs[0]).transform.parent; public static Transform OriginalButtonContainer => ((Component)PassportManager.instance.buttons[0]).transform.parent; public static bool IsSpecialCustomization(Type type, out PeakTemplateType templateType) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Expected I4, but got Unknown templateType = PeakTemplateType.Character; switch ((int)type) { case -13377701: templateType = PeakTemplateType.Character; return true; case -13377702: templateType = PeakTemplateType.Skeleton; return true; case -13377703: templateType = PeakTemplateType.Chicken; return true; default: return false; } } public static Type GetSpecialCustomization(PeakTemplateType type) { return (Type)(type switch { PeakTemplateType.Character => -13377701, PeakTemplateType.Skeleton => -13377702, PeakTemplateType.Chicken => -13377703, _ => 0, }); } public static CustomizationOption[] Construct_Customization_List(PeakTemplateType type) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: 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_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0087: 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_00db: 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_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) List<CustomizationOption> list = new List<CustomizationOption>(); Type specialCustomization = GetSpecialCustomization(type); CustomizationOption_Custom customizationOption_Custom = ScriptableObject.CreateInstance<CustomizationOption_Custom>(); ((Object)customizationOption_Custom).SetName("NoPreference"); ((CustomizationOption)customizationOption_Custom).color = Color.white; ((CustomizationOption)customizationOption_Custom).texture = NoPreferenceIcon; ((CustomizationOption)customizationOption_Custom).type = specialCustomization; customizationOption_Custom.TemplateID = "NoPreference"; customizationOption_Custom.DisplayName = "No Preference"; customizationOption_Custom.TemplateType = type; list.Add((CustomizationOption)(object)customizationOption_Custom); CustomizationOption_Custom customizationOption_Custom2 = ScriptableObject.CreateInstance<CustomizationOption_Custom>(); ((Object)customizationOption_Custom2).SetName("Default"); ((CustomizationOption)customizationOption_Custom2).color = Color.white; ((CustomizationOption)customizationOption_Custom2).texture = EmptyIcon; ((CustomizationOption)customizationOption_Custom2).type = specialCustomization; customizationOption_Custom2.TemplateID = "Default"; customizationOption_Custom2.DisplayName = "Default"; customizationOption_Custom2.TemplateType = type; list.Add((CustomizationOption)(object)customizationOption_Custom2); foreach (string item in Fetch_Template_List(type)) { CustomizationOption_Custom customizationOption_Custom3 = ScriptableObject.CreateInstance<CustomizationOption_Custom>(); ((Object)customizationOption_Custom3).SetName(item); ((CustomizationOption)customizationOption_Custom3).color = Color.white; ((CustomizationOption)customizationOption_Custom3).texture = GetTemplateIcon(item); ((CustomizationOption)customizationOption_Custom3).type = specialCustomization; customizationOption_Custom3.DisplayName = GetTemplateDisplayName(item); customizationOption_Custom3.TemplateID = item; customizationOption_Custom3.TemplateType = type; list.Add((CustomizationOption)(object)customizationOption_Custom3); } return list.ToArray(); } public static Texture GetTemplateIcon(string templateID) { Texture val = CustomTemplateUtils.Get_Peak_Custom_Template_Icon(templateID); if ((Object)(object)val == (Object)null) { val = LockedIcon; } return val; } public static string GetTemplateDisplayName(string templateID) { string text = CustomTemplateUtils.Get_Peak_Custom_Template_DisplayName(templateID); if (string.IsNullOrWhiteSpace(text)) { text = templateID; } return text; } public static List<string> Fetch_Template_List(PeakTemplateType type) { return CustomTemplateUtils.Fetch_Peak_Custom_Templates(type).Keys.ToList(); } public static void VerifyAndInitializeCustomTabs() { //IL_02f4: Unknown result type (might be due to invalid IL or missing references) //IL_02f9: Unknown result type (might be due to invalid IL or missing references) //IL_0283: Unknown result type (might be due to invalid IL or missing references) //IL_02a8: 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_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Invalid comparison between Unknown and I4 //IL_01f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Invalid comparison between Unknown and I4 //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0225: Unknown result type (might be due to invalid IL or missing references) //IL_022a: Unknown result type (might be due to invalid IL or missing references) //IL_0230: Expected O, but got Unknown Debug.Log((object)"VerifyAndInitializeCustomTabs"); if (CustomTabs.Count != 0 && !CustomTabs.Any((PassportTab t) => !Object.op_Implicit((Object)(object)t))) { return; } CustomTabs.Clear(); CustomContainer = Object.Instantiate<GameObject>(((Component)OriginalTabContainer).gameObject, OriginalTabContainer.parent); PassportTab[] componentsInChildren = CustomContainer.GetComponentsInChildren<PassportTab>(true); foreach (PassportTab val in componentsInChildren) { Type type = val.type; if ((int)type != 0) { if ((int)type != 10) { if ((int)type == 20) { val.type = (Type)(-13377703); Transform obj = ((Component)val).transform.Find("Panel/Icon"); RawImage val2 = ((obj != null) ? ((Component)obj).GetComponent<RawImage>() : null); if (Object.op_Implicit((Object)(object)val2)) { val2.texture = CustomChickenIcon; } CustomTabs.Add(val); } else { Object.DestroyImmediate((Object)(object)((Component)val).gameObject); } } else { val.type = (Type)(-13377702); Transform obj2 = ((Component)val).transform.Find("Panel/Icon"); RawImage val3 = ((obj2 != null) ? ((Component)obj2).GetComponent<RawImage>() : null); if (Object.op_Implicit((Object)(object)val3)) { val3.texture = CustomSkeletonIcon; } CustomTabs.Add(val); } } else { val.type = (Type)(-13377701); Transform obj3 = ((Component)val).transform.Find("Panel/Icon"); RawImage val4 = ((obj3 != null) ? ((Component)obj3).GetComponent<RawImage>() : null); if (Object.op_Implicit((Object)(object)val4)) { val4.texture = CustomCharacterIcon; } CustomTabs.Add(val); } } PassportManager.instance.tabs = CollectionExtensions.AddRangeToArray<PassportTab>(PassportManager.instance.tabs, CustomTabs.ToArray()); try { GameObject obj4 = Object.Instantiate<GameObject>(CustomBookmarkPrefab, OriginalTabContainer.parent.parent.parent); obj4.transform.localPosition = new Vector3(300f, 307f, 0f); BookmarkButton = obj4.GetComponent<Button>(); Button bookmarkButton = BookmarkButton; if (bookmarkButton != null) { ButtonClickedEvent onClick = bookmarkButton.onClick; object obj5 = <>O.<0>__TogglePassportBookmark; if (obj5 == null) { UnityAction val5 = TogglePassportBookmark; <>O.<0>__TogglePassportBookmark = val5; obj5 = (object)val5; } ((UnityEvent)onClick).AddListener((UnityAction)obj5); } } catch { Debug.LogError((object)"Failed to Create Custom Bookmark"); } try { GameObject obj7 = Object.Instantiate<GameObject>(((Component)PassportManager.instance.nameText).gameObject, OriginalButtonContainer.parent); ((Object)obj7).name = "CustomNameDisplay"; obj7.transform.localPosition = new Vector3(-193f, 95f, 0f); obj7.transform.SetSiblingIndex(0); Custom_Name_Display = obj7.GetComponent<TextMeshProUGUI>(); ((Graphic)Custom_Name_Display).color = Color.black; ((TMP_Text)Custom_Name_Display).alignment = (TextAlignmentOptions)513; ((TMP_Text)Custom_Name_Display).fontStyle = (FontStyles)0; ((TMP_Text)Custom_Name_Display).text = ""; } catch { Debug.LogError((object)"Failed to Create Custom Display Text"); } Original_ButtonContainer_Position = ((Component)OriginalButtonContainer).transform.localPosition; } public static void TogglePassportBookmark() { //IL_0039: Unknown result type (might be due to invalid IL or missing references) RawImage component = ((Component)((Component)BookmarkButton).transform.Find("RawImage_Blue")).GetComponent<RawImage>(); RawImage component2 = ((Component)((Component)BookmarkButton).transform.Find("RawImage_Red")).GetComponent<RawImage>(); if (IsSpecialCustomization(PassportManager.instance.activeType, out var _)) { ((Component)component).gameObject.SetActive(false); ((Component)component2).gameObject.SetActive(true); ((Selectable)BookmarkButton).targetGraphic = (Graphic)(object)component2; PassportManager.instance.OpenTab((Type)0); } else { ((Component)component).gameObject.SetActive(true); ((Component)component2).gameObject.SetActive(false); ((Selectable)BookmarkButton).targetGraphic = (Graphic)(object)component; PassportManager.instance.OpenTab((Type)(-13377701)); } } public static void SwitchToCustomTab(Type type) { //IL_0005: 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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) VerifyAndInitializeCustomTabs(); if (!IsSpecialCustomization(type, out var _)) { CustomContainer.SetActive(false); ((Component)Custom_Name_Display).gameObject.SetActive(false); ((Component)OriginalTabContainer).gameObject.SetActive(true); ((Component)OriginalButtonContainer).transform.localPosition = Original_ButtonContainer_Position; return; } CustomContainer.SetActive(true); ((Component)Custom_Name_Display).gameObject.SetActive(true); ((Component)OriginalTabContainer).gameObject.SetActive(false); ((Component)OriginalButtonContainer).transform.localPosition = ButtonContainer_Name_Offset; foreach (PassportTab customTab in CustomTabs) { if (customTab.type == type) { customTab.Open(); } else { customTab.Close(); } } } } } namespace UCustomPrefabsAPI.Peak.Patches.Listeners { [HarmonyPatch] public static class CharacterCustomization_Listeners { public static ListenerHelper<Character, CharacterCustomization> CharacterDied_Postfix = new ListenerHelper<Character, CharacterCustomization>(); public static ListenerHelper<Character, CharacterCustomization> CharacterPassedOut_Postfix = new ListenerHelper<Character, CharacterCustomization>(); public static ListenerHelper<Character, CharacterCustomization> OnRevive_RPC_Postfix = new ListenerHelper<Character, CharacterCustomization>(); public static ListenerHelper<Character, CharacterCustomization> OnPlayerDataChange_Postfix = new ListenerHelper<Character, CharacterCustomization>(); public static ListenerHelper<Character, Color> PulseStatus_Postfix = new ListenerHelper<Character, Color>(); public static ListenerHelper<Character, CharacterCustomization> BecomeChicken_Prefix = new ListenerHelper<Character, CharacterCustomization>(); public static ListenerHelper<Character, CharacterCustomization> BecomeChicken_Postfix = new ListenerHelper<Character, CharacterCustomization>(); public static ListenerHelper<Character, CharacterCustomization> BecomeHuman_Prefix = new ListenerHelper<Character, CharacterCustomization>(); public static ListenerHelper<Character, CharacterCustomization> BecomeHuman_Postfix = new ListenerHelper<Character, CharacterCustomization>(); public static ListenerHelper<Character, CharacterCustomization> ShowChicken_Postfix = new ListenerHelper<Character, CharacterCustomization>(); public static ListenerHelper<Character, CharacterCu