Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of Nezeritzoloto v0.2.0
Nezeritzoloto.dll
Decompiled a week agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.IO.Compression; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using Microsoft.CodeAnalysis; using REPOLib; using REPOLib.Modules; using UnityEngine; using UnityEngine.Audio; using UnityEngine.Rendering; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace Nezeritzoloto { internal enum Blind { None, White } internal static class GameAudio { private static AudioMixerGroup group; private static bool searched; public static AudioMixerGroup Group { get { if (!searched) { searched = true; int num = -1; AudioMixerGroup[] array = Resources.FindObjectsOfTypeAll<AudioMixerGroup>(); foreach (AudioMixerGroup val in array) { string text = ((Object)val).name.ToLowerInvariant(); int num2 = 0; if (text.Contains("effect") || text.Contains("sfx")) { num2 = 3; } else if (text.Contains("sound")) { num2 = 2; } else if (!text.Contains("music") && !text.Contains("voice") && !text.Contains("master")) { num2 = 1; } if (num2 > num) { num = num2; group = val; } } } return group; } } public static AudioSource MakeSource(GameObject go, bool loop, float maxDistance) { AudioSource val = go.AddComponent<AudioSource>(); val.playOnAwake = false; val.loop = loop; val.spatialBlend = 1f; val.rolloffMode = (AudioRolloffMode)1; val.minDistance = 1.5f; val.maxDistance = maxDistance; val.dopplerLevel = 0f; AudioMixerGroup val2 = Group; if ((Object)(object)val2 != (Object)null) { val.outputAudioMixerGroup = val2; } return val; } } internal class HeldLoop : MonoBehaviour { public AudioClip clip; public float volume = 0.5f; public float maxDistance = 18f; private AudioSource src; private PhysGrabObject pgo; private float current; private void Awake() { pgo = ((Component)this).GetComponentInParent<PhysGrabObject>(); src = GameAudio.MakeSource(((Component)this).gameObject, loop: true, maxDistance); src.clip = clip; } private void Update() { if (!((Object)(object)src == (Object)null) && !((Object)(object)clip == (Object)null)) { bool flag = (Object)(object)pgo != (Object)null && pgo.grabbed; current = Mathf.MoveTowards(current, flag ? 1f : 0f, Time.deltaTime * 4f); src.volume = current * volume * Plugin.SoundVolume.Value; if (flag && !src.isPlaying) { src.Play(); } else if (!flag && current <= 0.001f && src.isPlaying) { src.Stop(); } } } } internal class HeldPulse : MonoBehaviour { public AudioClip clip; public float interval = 3f; public float volume = 1f; public float maxDistance = 30f; private AudioSource src; private PhysGrabObject pgo; private float timer; private bool wasHeld; private void Awake() { pgo = ((Component)this).GetComponentInParent<PhysGrabObject>(); src = GameAudio.MakeSource(((Component)this).gameObject, loop: false, maxDistance); } private void Update() { if ((Object)(object)src == (Object)null || (Object)(object)clip == (Object)null) { return; } bool flag = (Object)(object)pgo != (Object)null && pgo.grabbed; if (flag) { if (!wasHeld) { timer = 0f; } timer -= Time.deltaTime; if (timer <= 0f) { src.PlayOneShot(clip, volume * Plugin.SoundVolume.Value); timer = Mathf.Max(0.2f, interval); } } wasHeld = flag; } } internal class ImpactSound : MonoBehaviour { public AudioClip clip; public float minSpeed = 2.5f; public float maxDistance = 25f; private AudioSource src; private float cooldown; private void Awake() { src = GameAudio.MakeSource(((Component)this).gameObject, loop: false, maxDistance); } private void Update() { if (cooldown > 0f) { cooldown -= Time.deltaTime; } } private void OnCollisionEnter(Collision c) { //IL_002b: 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 (!((Object)(object)src == (Object)null) && !((Object)(object)clip == (Object)null) && !(cooldown > 0f)) { Vector3 relativeVelocity = c.relativeVelocity; float magnitude = ((Vector3)(ref relativeVelocity)).magnitude; if (!(magnitude < minSpeed)) { cooldown = 0.12f; float num = Mathf.Clamp01(magnitude / 12f) * Plugin.SoundVolume.Value; src.pitch = Random.Range(0.92f, 1.08f); src.PlayOneShot(clip, num); } } } } internal class Spinner : MonoBehaviour { public Vector3 axis = Vector3.up; public float speed = 90f; public bool onlyWhenHeld = true; private PhysGrabObject pgo; private float current; private void Awake() { pgo = ((Component)this).GetComponentInParent<PhysGrabObject>(); } private void Update() { //IL_0079: Unknown result type (might be due to invalid IL or missing references) bool flag = !onlyWhenHeld || ((Object)(object)pgo != (Object)null && pgo.grabbed); current = Mathf.MoveTowards(current, flag ? speed : 0f, Mathf.Abs(speed) * Time.deltaTime * 2f); if (Mathf.Abs(current) > 0.01f) { ((Component)this).transform.Rotate(axis, current * Time.deltaTime, (Space)1); } } } internal class Glow : MonoBehaviour { public Color color = Color.white; public float minIntensity = 0.5f; public float maxIntensity = 2f; public float speed = 3f; public Light lightSource; public float lightMax = 1.5f; private Material mat; private void Awake() { Renderer component = ((Component)this).GetComponent<Renderer>(); if ((Object)(object)component != (Object)null) { mat = component.material; } if ((Object)(object)mat != (Object)null) { mat.EnableKeyword("_EMISSION"); mat.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)1; } } private void Update() { //IL_006b: 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) float num = (Mathf.Sin(Time.time * speed + (float)((Object)this).GetInstanceID() * 0.37f) + 1f) * 0.5f; float num2 = Mathf.Lerp(minIntensity, maxIntensity, num); if ((Object)(object)mat != (Object)null && mat.HasProperty("_EmissionColor")) { mat.SetColor("_EmissionColor", color * num2); } if ((Object)(object)lightSource != (Object)null) { lightSource.intensity = Mathf.Lerp(lightMax * 0.5f, lightMax, num); } } } internal class BlindOnHold : MonoBehaviour { public Blind kind = Blind.White; private PhysGrabObject pgo; private void Awake() { pgo = ((Component)this).GetComponentInParent<PhysGrabObject>(); } private void Update() { //IL_009c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)pgo == (Object)null || pgo.playerGrabbing == null) { return; } bool flag = false; foreach (PhysGrabber item in pgo.playerGrabbing) { if ((Object)(object)item != (Object)null && item.isLocal) { flag = true; break; } } if (flag) { float num = 0.88f + 0.12f * Mathf.PerlinNoise(Time.time * 9f, 0.5f); BlindOverlay.Request(new Color(1f, 0.97f, 0.85f), 1f * num); } } } internal class BlindOverlay : MonoBehaviour { private static BlindOverlay inst; private float heldAlpha; private float requested; private Color heldColor = Color.white; private float flashAlpha; private float flashPeak; private float flashHold; private float flashFade = 1f; private Color flashColor = Color.white; private AudioSource ringSrc; public static void Create() { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown if (!((Object)(object)inst != (Object)null)) { GameObject val = new GameObject("MV_BlindOverlay"); Object.DontDestroyOnLoad((Object)(object)val); inst = val.AddComponent<BlindOverlay>(); inst.ringSrc = val.AddComponent<AudioSource>(); inst.ringSrc.playOnAwake = false; inst.ringSrc.spatialBlend = 0f; AudioMixerGroup val2 = GameAudio.Group; if ((Object)(object)val2 != (Object)null) { inst.ringSrc.outputAudioMixerGroup = val2; } } } public static void Request(Color c, float strength) { //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) if (!((Object)(object)inst == (Object)null)) { inst.heldColor = c; inst.requested = Mathf.Max(inst.requested, strength); } } public static void Flash(Color c, float strength, float hold, float fade) { //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) if (!((Object)(object)inst == (Object)null)) { inst.flashColor = c; inst.flashPeak = Mathf.Clamp01(strength); inst.flashAlpha = inst.flashPeak; inst.flashHold = hold; inst.flashFade = Mathf.Max(0.1f, fade); if ((Object)(object)inst.ringSrc != (Object)null && (Object)(object)SoundKit.Ring != (Object)null) { inst.ringSrc.PlayOneShot(SoundKit.Ring, Mathf.Clamp01(strength) * Plugin.SoundVolume.Value); } } } private void LateUpdate() { float unscaledDeltaTime = Time.unscaledDeltaTime; float num = ((requested > heldAlpha) ? 3f : 1.5f); heldAlpha = Mathf.MoveTowards(heldAlpha, requested, unscaledDeltaTime * num); requested = 0f; if (flashHold > 0f) { flashHold -= unscaledDeltaTime; } else if (flashAlpha > 0f) { flashAlpha = Mathf.MoveTowards(flashAlpha, 0f, flashPeak / flashFade * unscaledDeltaTime); } } private void OnGUI() { //IL_0032: 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_0037: 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_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004d: 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) //IL_005f: 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) float num = Mathf.Max(heldAlpha, flashAlpha); if (!(num <= 0.002f)) { Color val = ((flashAlpha >= heldAlpha) ? flashColor : heldColor); GUI.depth = -10000; Color color = GUI.color; GUI.color = new Color(val.r, val.g, val.b, Mathf.Clamp01(num)); GUI.DrawTexture(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), (Texture)(object)Texture2D.whiteTexture); GUI.color = color; } } } internal class MassProbe : MonoBehaviour { private IEnumerator Start() { yield return (object)new WaitForSeconds(1.5f); Rigidbody component = ((Component)this).GetComponent<Rigidbody>(); ((Component)this).GetComponent<ValuableObject>(); string text = (((Object)(object)component == (Object)null) ? "нет Rigidbody" : $"rb.mass={component.mass}, drag={component.linearDamping}, angDrag={component.angularDamping}, constraints={component.constraints}, kinematic={component.isKinematic}, gravity={component.useGravity}"); Plugin.Log.LogInfo((object)("[MassProbe] " + ((Object)this).name + ": " + text)); Collider[] componentsInChildren = ((Component)this).GetComponentsInChildren<Collider>(true); foreach (Collider val in componentsInChildren) { ManualLogSource log = Plugin.Log; object[] obj = new object[5] { ((Object)val).name, ((object)val).GetType().Name, val.enabled, val.isTrigger, null }; Bounds bounds = val.bounds; obj[4] = ((Bounds)(ref bounds)).size; log.LogInfo((object)string.Format("[MassProbe] коллайдер {0} {1} enabled={2} trigger={3} bounds={4}", obj)); } } } internal static class EmbeddedAudio { private static readonly Dictionary<string, AudioClip> Cache = new Dictionary<string, AudioClip>(); public static AudioClip Load(string fileName) { if (Cache.TryGetValue(fileName, out var value) && (Object)(object)value != (Object)null) { return value; } Assembly assembly = typeof(EmbeddedAudio).Assembly; string text = null; string[] manifestResourceNames = assembly.GetManifestResourceNames(); foreach (string text2 in manifestResourceNames) { if (text2.EndsWith(fileName, StringComparison.OrdinalIgnoreCase)) { text = text2; break; } } if (text == null) { throw new FileNotFoundException("В DLL нет встроенного звука " + fileName); } byte[] array; using (Stream stream = assembly.GetManifestResourceStream(text)) { using MemoryStream memoryStream = new MemoryStream(); stream.CopyTo(memoryStream); array = memoryStream.ToArray(); } if (array.Length < 44 || array[0] != 82 || array[1] != 73 || array[2] != 70 || array[3] != 70) { throw new InvalidDataException("Это не WAV: " + fileName); } int num = 1; int num2 = 44100; int num3 = 16; int num4 = 1; int num5 = -1; int num6 = 0; int num7; for (int j = 12; j + 8 <= array.Length; j += 8 + num7 + (num7 & 1)) { char c = (char)array[j]; string text3 = c.ToString(); c = (char)array[j + 1]; string text4 = c.ToString(); c = (char)array[j + 2]; string text5 = c.ToString(); c = (char)array[j + 3]; string text6 = text3 + text4 + text5 + c; num7 = BitConverter.ToInt32(array, j + 4); if (text6 == "fmt ") { num4 = BitConverter.ToInt16(array, j + 8); num = BitConverter.ToInt16(array, j + 10); num2 = BitConverter.ToInt32(array, j + 12); num3 = BitConverter.ToInt16(array, j + 22); } else if (text6 == "data") { num5 = j + 8; num6 = Math.Min(num7, array.Length - num5); break; } } if (num5 < 0 || num4 != 1 || num3 != 16) { throw new InvalidDataException("Нужен WAV PCM 16 бит: " + fileName); } int num8 = num6 / 2; float[] array2 = new float[num8]; for (int k = 0; k < num8; k++) { array2[k] = (float)BitConverter.ToInt16(array, num5 + k * 2) / 32768f; } AudioClip val = AudioClip.Create(Path.GetFileNameWithoutExtension(fileName), num8 / num, num, num2, false); val.SetData(array2, 0); Cache[fileName] = val; return val; } } internal static class ImportedModel { internal class Part { public Transform Transform; public Color Color; public float Emission; public bool Outline; } public static List<Part> Build(Transform parent, string fileName) { //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Expected O, but got Unknown //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_0202: Unknown result type (might be due to invalid IL or missing references) //IL_0207: Unknown result type (might be due to invalid IL or missing references) //IL_0221: Unknown result type (might be due to invalid IL or missing references) //IL_0223: Unknown result type (might be due to invalid IL or missing references) byte[] buffer = ReadResource(fileName); List<Part> list = new List<Part>(); using BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer)); if (new string(binaryReader.ReadChars(4)) != "MVM1") { throw new InvalidDataException("Неверный формат модели: " + fileName); } int num = binaryReader.ReadByte(); Color color = default(Color); for (int i = 0; i < num; i++) { float num2 = binaryReader.ReadSingle(); float num3 = binaryReader.ReadSingle(); float num4 = binaryReader.ReadSingle(); binaryReader.ReadSingle(); float num5 = binaryReader.ReadSingle(); byte b = binaryReader.ReadByte(); int num6 = binaryReader.ReadInt32(); int num7 = binaryReader.ReadInt32(); Vector3[] array = (Vector3[])(object)new Vector3[num6]; for (int j = 0; j < num6; j++) { array[j] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle()); } Vector3[] array2 = (Vector3[])(object)new Vector3[num6]; for (int k = 0; k < num6; k++) { array2[k] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle()); } int[] array3 = new int[num7]; for (int l = 0; l < num7; l++) { array3[l] = binaryReader.ReadUInt16(); } Mesh val = new Mesh { name = fileName + "_" + i }; val.vertices = array; val.normals = array2; val.triangles = array3; Vector2[] array4 = (Vector2[])(object)new Vector2[num6]; for (int m = 0; m < num6; m++) { array4[m] = new Vector2(array[m].x, array[m].z); } val.uv = array4; val.RecalculateBounds(); ((Color)(ref color))..ctor(num2, num3, num4, 1f); float emission = ((num5 > 0f) ? Mathf.Clamp(num5, 0.5f, 2f) : 0f); Transform transform = MeshKit.Part(parent, "Part" + i, val, Vector3.zero, Vector3.zero, color, emission); list.Add(new Part { Transform = transform, Color = color, Emission = emission, Outline = ((b & 1) != 0) }); } return list; } private static byte[] ReadResource(string fileName) { Assembly assembly = typeof(ImportedModel).Assembly; string text = null; string[] manifestResourceNames = assembly.GetManifestResourceNames(); foreach (string text2 in manifestResourceNames) { if (text2.EndsWith(fileName, StringComparison.OrdinalIgnoreCase)) { text = text2; break; } } if (text == null) { throw new FileNotFoundException("В DLL нет встроенной модели " + fileName); } using Stream stream = assembly.GetManifestResourceStream(text); using GZipStream gZipStream = new GZipStream(stream, CompressionMode.Decompress); using MemoryStream memoryStream = new MemoryStream(); gZipStream.CopyTo(memoryStream); return memoryStream.ToArray(); } } internal static class MeshKit { public static Material BaseMaterial; private static bool LoggedShader; private static readonly Dictionary<string, Mesh> MeshCache = new Dictionary<string, Mesh>(); private static readonly Dictionary<string, Material> MatCache = new Dictionary<string, Material>(); private const float BoxR = 0.70710677f; public static Mesh Lathe(string key, float[] r, float[] y, int seg, float angOffsetDeg, Vector3 scale) { //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Expected O, but got Unknown //IL_005a: 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_0061: 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) //IL_0078: 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_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: 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) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_0116: 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_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) if (MeshCache.TryGetValue(key, out var value)) { return value; } List<Vector3> list = new List<Vector3>(); List<int> list2 = new List<int>(); float num = MathF.PI * 2f / (float)seg; float num2 = angOffsetDeg * (MathF.PI / 180f); for (int i = 0; i < r.Length - 1; i++) { for (int j = 0; j < seg; j++) { float num3 = num2 + (float)j * num; float a = num3 + num; Vector3 a2 = P(r[i], y[i], num3, scale); Vector3 b = P(r[i + 1], y[i + 1], num3, scale); Vector3 val = P(r[i + 1], y[i + 1], a, scale); Vector3 c = P(r[i], y[i], a, scale); AddTri(list, list2, a2, b, val); AddTri(list, list2, a2, val, c); } } Mesh val2 = new Mesh { name = key }; val2.SetVertices(list); val2.SetTriangles(list2, 0); Vector2[] array = (Vector2[])(object)new Vector2[list.Count]; for (int k = 0; k < array.Length; k++) { array[k] = new Vector2(list[k].x, list[k].z); } val2.uv = array; val2.RecalculateNormals(); val2.RecalculateBounds(); MeshCache[key] = val2; return val2; } private static Vector3 P(float r, float y, float a, Vector3 scale) { //IL_0008: 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_001f: 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) return new Vector3(r * Mathf.Cos(a) * scale.x, y * scale.y, r * Mathf.Sin(a) * scale.z); } private static void AddTri(List<Vector3> verts, List<int> tris, Vector3 a, Vector3 b, Vector3 c) { //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_0007: 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_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_002c: 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_003a: Unknown result type (might be due to invalid IL or missing references) Vector3 val = Vector3.Cross(b - a, c - a); if (!(((Vector3)(ref val)).sqrMagnitude < 1E-12f)) { int count = verts.Count; verts.Add(a); verts.Add(b); verts.Add(c); tris.Add(count); tris.Add(count + 1); tris.Add(count + 2); } } public static Mesh Box(float w, float h, float d, float topScale = 1f) { //IL_0066: Unknown result type (might be due to invalid IL or missing references) return Lathe($"box_{w:F3}_{h:F3}_{d:F3}_{topScale:F2}", new float[4] { 0f, 0.70710677f, 0.70710677f * topScale, 0f }, new float[4] { -0.5f, -0.5f, 0.5f, 0.5f }, 4, 45f, new Vector3(w, h, d)); } public static Mesh Cyl(float radius, float height, int seg = 8, float topScale = 1f) { //IL_007a: Unknown result type (might be due to invalid IL or missing references) return Lathe($"cyl_{radius:F3}_{height:F3}_{seg}_{topScale:F2}", new float[4] { 0f, radius, radius * topScale, 0f }, new float[4] { (0f - height) / 2f, (0f - height) / 2f, height / 2f, height / 2f }, seg, 0f, Vector3.one); } public static Mesh Cone(float radius, float height, int seg = 8) { //IL_0052: Unknown result type (might be due to invalid IL or missing references) return Lathe($"cone_{radius:F3}_{height:F3}_{seg}", new float[3] { 0f, radius, 0f }, new float[3] { (0f - height) / 2f, (0f - height) / 2f, height / 2f }, seg, 0f, Vector3.one); } public static Mesh Crystal(float radius, float body, float tip, int seg = 6) { //IL_007c: Unknown result type (might be due to invalid IL or missing references) return Lathe($"crystal_{radius:F3}_{body:F3}_{tip:F3}_{seg}", new float[4] { 0f, radius, radius, 0f }, new float[4] { (0f - body) / 2f - tip, (0f - body) / 2f, body / 2f, body / 2f + tip }, seg, 0f, Vector3.one); } public static Mesh Sphere(float radius, int seg = 10) { //IL_0082: Unknown result type (might be due to invalid IL or missing references) string key = $"sphere_{radius:F3}_{seg}"; float[] array = new float[7]; float[] array2 = new float[7]; for (int i = 0; i < 7; i++) { float num = (-90f + (float)i * 30f) * (MathF.PI / 180f); array[i] = Mathf.Max(0f, radius * Mathf.Cos(num)); array2[i] = radius * Mathf.Sin(num); } array[0] = 0f; array[6] = 0f; return Lathe(key, array, array2, seg, 0f, Vector3.one); } public static Transform Group(Transform parent, string name, Vector3 pos, Vector3 euler) { //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_0013: 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) //IL_0025: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name); val.transform.SetParent(parent, false); val.transform.localPosition = pos; val.transform.localEulerAngles = euler; return val.transform; } public static Transform Part(Transform parent, string name, Mesh mesh, Vector3 pos, Vector3 euler, Color color, float emission = 0f) { //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_0013: 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) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0038: 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) GameObject val = new GameObject(name); val.transform.SetParent(parent, false); val.transform.localPosition = pos; val.transform.localEulerAngles = euler; val.AddComponent<MeshFilter>().sharedMesh = mesh; MeshRenderer obj = val.AddComponent<MeshRenderer>(); ((Renderer)obj).sharedMaterial = GetMaterial(color, emission); ((Renderer)obj).shadowCastingMode = (ShadowCastingMode)1; ((Renderer)obj).receiveShadows = true; return val.transform; } public static Transform Part(Transform parent, string name, Mesh mesh, Vector3 pos, Color color, float emission = 0f) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0004: 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 Part(parent, name, mesh, pos, Vector3.zero, color, emission); } public static Material GetMaterial(Color color, float emission) { //IL_000d: 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_0029: 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_00a1: 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_0285: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) string text = $"{color.r:F2}_{color.g:F2}_{color.b:F2}_{emission:F2}"; if (MatCache.TryGetValue(text, out var value) && (Object)(object)value != (Object)null) { return value; } Material val = CreateBase(); ((Object)val).name = "MV_" + text; if (val.HasProperty("_BaseColor")) { val.SetColor("_BaseColor", color); } if (val.HasProperty("_Color")) { val.SetColor("_Color", color); } string[] array = new string[7] { "_MainTex", "_BaseMap", "_BumpMap", "_NormalMap", "_MetallicGlossMap", "_OcclusionMap", "_EmissionMap" }; foreach (string text2 in array) { if (val.HasProperty(text2)) { val.SetTexture(text2, (Texture)null); } } if (val.HasProperty("_Metallic")) { val.SetFloat("_Metallic", 0.15f); } if (val.HasProperty("_Glossiness")) { val.SetFloat("_Glossiness", 0.25f); } if (val.HasProperty("_Smoothness")) { val.SetFloat("_Smoothness", 0.25f); } array = new string[3] { "_EmissionColor", "_EmissiveColor", "_EmissionTint" }; foreach (string text3 in array) { if (val.HasProperty(text3)) { val.SetColor(text3, Color.black); } } if (val.HasProperty("_EmissionIntensity")) { val.SetFloat("_EmissionIntensity", 0f); } val.DisableKeyword("_EMISSION"); if (!LoggedShader) { LoggedShader = true; try { Shader shader = val.shader; StringBuilder stringBuilder = new StringBuilder(); for (int j = 0; j < shader.GetPropertyCount(); j++) { stringBuilder.Append(shader.GetPropertyName(j)).Append(' '); } Debug.Log((object)("[MV] шейдер материала: " + ((Object)shader).name + " | свойства: " + stringBuilder)); } catch (Exception) { } } if (emission > 0f) { val.EnableKeyword("_EMISSION"); val.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)1; if (val.HasProperty("_EmissionColor")) { val.SetColor("_EmissionColor", color * emission); } } MatCache[text] = val; return val; } private static Material CreateBase() { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected O, but got Unknown //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Expected O, but got Unknown //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Expected O, but got Unknown Shader val = Shader.Find("Standard"); if ((Object)(object)val != (Object)null) { Debug.Log((object)"[MV] материал на шейдере Standard"); return new Material(val); } Debug.Log((object)"[MV] Standard не найден, беру материал образца"); if ((Object)(object)BaseMaterial != (Object)null) { Material val2 = new Material(BaseMaterial); if (val2.HasProperty("_Color") || val2.HasProperty("_BaseColor")) { return val2; } } Shader val3 = Shader.Find("Standard") ?? Shader.Find("Universal Render Pipeline/Lit") ?? Shader.Find("HDRP/Lit") ?? Shader.Find("Unlit/Color") ?? Shader.Find("Sprites/Default"); return ((Object)(object)val3 != (Object)null) ? new Material(val3) : new Material(BaseMaterial); } public static bool GetModelBounds(Transform root, out Bounds bounds) { //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_0010: 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_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0056: 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_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0086: 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_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0096: 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) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: 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_00b2: Unknown result type (might be due to invalid IL or missing references) bounds = new Bounds(Vector3.zero, Vector3.zero); bool flag = false; MeshFilter[] componentsInChildren = ((Component)root).GetComponentsInChildren<MeshFilter>(true); foreach (MeshFilter val in componentsInChildren) { if ((Object)(object)val.sharedMesh == (Object)null) { continue; } Bounds bounds2 = val.sharedMesh.bounds; for (int j = 0; j < 8; j++) { Vector3 val2 = ((Bounds)(ref bounds2)).center + Vector3.Scale(((Bounds)(ref bounds2)).extents, new Vector3((float)(((j & 1) != 0) ? 1 : (-1)), (float)(((j & 2) != 0) ? 1 : (-1)), (float)(((j & 4) != 0) ? 1 : (-1)))); Vector3 val3 = root.InverseTransformPoint(((Component)val).transform.TransformPoint(val2)); if (!flag) { bounds = new Bounds(val3, Vector3.zero); flag = true; } else { ((Bounds)(ref bounds)).Encapsulate(val3); } } } return flag; } } internal class Def { public string Id; public string Name; public string Size; public float Value = 1f; public float FixedPrice; public float Mass = 1f; public float Fragility = 1f; public float Durability = 1f; public Loop Loop; public float LoopVolume = 0.5f; public Hit Hit; public Blind Blind; public string PulseSound; public float PulseInterval = 3f; public bool AllowTilt; public Action<Transform> Build; } internal static class Models { public static List<Def> All() { return new List<Def> { new Def { Id = "nezeritzoloto", Name = "Nezeritzoloto", Size = "wide", FixedPrice = Plugin.Price.Value, Mass = Plugin.Weight.Value, Fragility = 0.6f, Hit = Hit.Clang, PulseSound = "hammer.wav", PulseInterval = Plugin.SoundInterval.Value, Build = NezeritzolotoModel } }; } private static void NezeritzolotoModel(Transform t) { ImportedModel.Build(t, "crown.mvm"); } } [BepInPlugin("nezeritzoloto.valuable", "Nezeritzoloto", "0.2.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public const string PluginGuid = "nezeritzoloto.valuable"; public const string PluginName = "Nezeritzoloto"; public const string PluginVersion = "0.2.0"; internal static ManualLogSource Log; internal static ConfigEntry<float> ValueMultiplier; internal static ConfigEntry<float> SoundVolume; internal static ConfigEntry<int> Price; internal static ConfigEntry<float> Weight; internal static ConfigEntry<float> SoundInterval; private readonly Dictionary<string, ConfigEntry<bool>> enabledMap = new Dictionary<string, ConfigEntry<bool>>(); private List<Def> defs; private static readonly string[] Sizes = new string[7] { "tiny", "small", "medium", "big", "wide", "tall", "veryTall" }; private static readonly Dictionary<string, string[]> Fallback = new Dictionary<string, string[]> { { "tiny", new string[2] { "tiny", "small" } }, { "small", new string[3] { "small", "medium", "tiny" } }, { "medium", new string[3] { "medium", "small", "big" } }, { "big", new string[2] { "big", "medium" } }, { "wide", new string[3] { "wide", "big", "medium" } }, { "tall", new string[2] { "tall", "medium" } }, { "veryTall", new string[3] { "veryTall", "tall", "big" } } }; private void Awake() { //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Expected O, but got Unknown //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Expected O, but got Unknown //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; ValueMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ValueMultiplier", 1f, "Общий множитель цены всех ценностей мода (1 = как рассчитано, 2 = в два раза дороже)."); SoundVolume = ((BaseUnityPlugin)this).Config.Bind<float>("General", "SoundVolume", 1f, new ConfigDescription("Громкость звуков мода (в руках и при ударе).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>())); Price = ((BaseUnityPlugin)this).Config.Bind<int>("Valuables", "Price", 14880, "Фиксированная цена ценности в долларах (одинаковая при каждом появлении)."); Weight = ((BaseUnityPlugin)this).Config.Bind<float>("Valuables", "WeightMultiplier", 1.5f, new ConfigDescription("Во сколько раз ценность тяжелее обычной ценности такого же размера (4 = вес в 4 силы).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 20f), Array.Empty<object>())); SoundInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Valuables", "SoundInterval", 3f, new ConfigDescription("Как часто (в секундах) играет звук, пока ценность держат в руках.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 30f), Array.Empty<object>())); defs = Models.All(); foreach (Def def in defs) { enabledMap[def.Id] = ((BaseUnityPlugin)this).Config.Bind<bool>("Valuables", def.Id, true, "Включить: " + def.Name); } SoundKit.Init(); BlindOverlay.Create(); ((MonoBehaviour)this).StartCoroutine(RegisterRoutine()); Log.LogInfo((object)"Nezeritzoloto v0.2.0 загружен, жду готовности игры и REPOLib..."); } private IEnumerator RegisterRoutine() { Dictionary<string, GameObject> sources = null; float waited = 0f; while (waited < 180f) { if (BundlesReady(waited)) { sources = CollectSources(); if (sources.Count > 0) { break; } } waited += Time.unscaledDeltaTime; yield return null; } if (sources == null || sources.Count == 0) { Log.LogError((object)"Не нашёл ни одной ванильной ценности для образца. Регистрация отменена."); yield break; } Log.LogInfo((object)("Образцы найдены: " + string.Join(", ", new List<string>(sources.Keys)))); int ok = 0; foreach (Def def in defs) { if (!enabledMap[def.Id].Value) { continue; } GameObject val = Pick(sources, def.Size); if ((Object)(object)val == (Object)null) { Log.LogWarning((object)("[" + def.Id + "] нет подходящего образца размера " + def.Size + ".")); continue; } try { GameObject val2 = ValuableFactory.Build(def, val, Log); if ((Object)(object)val2 != (Object)null) { Valuables.RegisterValuable(val2); ok++; Log.LogInfo((object)("Зарегистрирована ценность: " + def.Name + " (" + def.Size + ", образец " + ((Object)val).name + ")")); } } catch (Exception arg) { Log.LogError((object)$"[{def.Id}] ошибка: {arg}"); } yield return null; } Log.LogInfo((object)$"Готово: зарегистрировано ценностей {ok} из {defs.Count}."); } private static bool BundlesReady(float waited) { try { PropertyInfo property = typeof(BundleLoader).GetProperty("AllBundlesLoaded", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (property != null) { return (bool)property.GetValue(null, null); } } catch (Exception) { } return waited > 15f; } private static GameObject Pick(Dictionary<string, GameObject> map, string size) { if (!Fallback.TryGetValue(size, out var value)) { value = new string[1] { size }; } string[] array = value; foreach (string key in array) { if (map.TryGetValue(key, out var value2) && (Object)(object)value2 != (Object)null) { return value2; } } return null; } private static Dictionary<string, GameObject> CollectSources() { Dictionary<string, GameObject> dictionary = new Dictionary<string, GameObject>(); RunManager instance = RunManager.instance; if ((Object)(object)instance == (Object)null || instance.levels == null) { return dictionary; } foreach (Level level in instance.levels) { if ((Object)(object)level == (Object)null || level.ValuablePresets == null) { continue; } foreach (LevelValuables valuablePreset in level.ValuablePresets) { if (!((Object)(object)valuablePreset == (Object)null)) { TryAdd(dictionary, "tiny", valuablePreset.tiny); TryAdd(dictionary, "small", valuablePreset.small); TryAdd(dictionary, "medium", valuablePreset.medium); TryAdd(dictionary, "big", valuablePreset.big); TryAdd(dictionary, "wide", valuablePreset.wide); TryAdd(dictionary, "tall", valuablePreset.tall); TryAdd(dictionary, "veryTall", valuablePreset.veryTall); } } } return dictionary; } private static void TryAdd(Dictionary<string, GameObject> map, string size, IEnumerable<PrefabRef> list) { if (list == null || map.ContainsKey(size)) { return; } foreach (PrefabRef item in list) { GameObject val = null; try { val = ((PrefabRef<GameObject>)(object)item)?.Prefab; } catch (Exception) { } if (ValuableFactory.IsCleanSource(val)) { map[size] = val; break; } } } } internal enum Loop { None, Servo, Hum, Beam, Whirr, Hiss, Drill, Belt } internal enum Hit { None, Clang, Thud, Plink } internal static class SoundKit { private const int SR = 44100; private static AudioClip[] loops; private static AudioClip[] hits; public static AudioClip Ring; public static void Init() { loops = (AudioClip[])(object)new AudioClip[Enum.GetValues(typeof(Loop)).Length]; hits = (AudioClip[])(object)new AudioClip[Enum.GetValues(typeof(Hit)).Length]; loops[1] = MakeLoop("mv_servo", Servo); loops[2] = MakeLoop("mv_hum", HumWave); loops[3] = MakeLoop("mv_beam", BeamWave); loops[4] = MakeLoop("mv_whirr", WhirrWave); loops[5] = MakeNoiseLoop("mv_hiss"); loops[6] = MakeLoop("mv_drill", DrillWave); loops[7] = MakeLoop("mv_belt", BeltWave); hits[1] = MakeOneShot("mv_clang", 0.7f, Clang); hits[2] = MakeOneShot("mv_thud", 0.5f, Thud); hits[3] = MakeOneShot("mv_plink", 0.4f, Plink); Ring = MakeOneShot("mv_ring", 3.5f, RingWave); } public static AudioClip GetLoop(Loop l) { if (loops == null) { return null; } return loops[(int)l]; } public static AudioClip GetHit(Hit h) { if (hits == null) { return null; } return hits[(int)h]; } private static AudioClip MakeLoop(string name, Func<float, float> f) { float[] array = new float[44100]; for (int i = 0; i < 44100; i++) { array[i] = f((float)i / 44100f); } Normalize(array, 0.5f); AudioClip obj = AudioClip.Create(name, 44100, 1, 44100, false); obj.SetData(array, 0); return obj; } private static AudioClip MakeOneShot(string name, float seconds, Func<float, float> f) { int num = (int)(44100f * seconds); float[] array = new float[num]; for (int i = 0; i < num; i++) { array[i] = f((float)i / 44100f); } Normalize(array, 0.8f); AudioClip obj = AudioClip.Create(name, num, 1, 44100, false); obj.SetData(array, 0); return obj; } private static AudioClip MakeNoiseLoop(string name) { int num = 4000; int num2 = 44100 + num; float[] array = new float[num2]; Random random = new Random(1337); float num3 = 0f; for (int i = 0; i < num2; i++) { float num4 = (float)(random.NextDouble() * 2.0 - 1.0); num3 += (num4 - num3) * 0.35f; float num5 = 0.65f + 0.35f * Mathf.Sin(MathF.PI * 6f * ((float)i / 44100f)); array[i] = num3 * num5; } float[] array2 = new float[44100]; for (int j = 0; j < 44100; j++) { array2[j] = array[j]; if (j < num) { float num6 = (float)j / (float)num; array2[j] = Mathf.Lerp(array[44100 + j], array[j], num6); } } Normalize(array2, 0.35f); AudioClip obj = AudioClip.Create(name, 44100, 1, 44100, false); obj.SetData(array2, 0); return obj; } private static void Normalize(float[] d, float peak) { float num = 0f; for (int i = 0; i < d.Length; i++) { num = Mathf.Max(num, Mathf.Abs(d[i])); } if (!(num < 1E-05f)) { float num2 = peak / num; for (int j = 0; j < d.Length; j++) { d[j] *= num2; } } } private static float Sin(float hz, float t) { return Mathf.Sin(MathF.PI * 2f * hz * t); } private static float Servo(float t) { float num = 0.75f + 0.25f * Sin(7f, t); return (0.55f * Sin(110f, t) + 0.3f * Sin(220f, t) + 0.15f * Sin(330f, t)) * num + 0.1f * Sin(880f + 40f * Sin(3f, t), t) * (0.5f + 0.5f * Sin(3f, t)); } private static float HumWave(float t) { return (0.8f + 0.2f * Sin(2f, t)) * (0.6f * Sin(55f, t) + 0.3f * Sin(110f, t) + 0.15f * Sin(165f, t) + 0.05f * Sin(331f, t)); } private static float BeamWave(float t) { float num = 0.65f + 0.35f * Mathf.Sign(Sin(120f, t)) * Sin(7f, t); return (0.5f * Sin(440f, t) + 0.5f * Sin(441f, t) + 0.25f * Sin(880f, t)) * num; } private static float WhirrWave(float t) { return (Mathf.Sin(MathF.PI * 600f * t + 2.5f * Sin(6f, t)) + 0.35f * Mathf.Sin(MathF.PI * 1200f * t + 1.5f * Sin(6f, t))) * (0.8f + 0.2f * Sin(12f, t)); } private static float DrillWave(float t) { float num = 0.0625f; float num2 = t % num; float num3 = Mathf.Exp((0f - num2) * 90f); float num4 = Sin(1700f, num2) * 0.5f + Sin(2310f, num2) * 0.35f + Sin(930f, num2) * 0.4f; return num3 * num4 + 0.25f * Sin(96f, t); } private static float BeltWave(float t) { float num = 0.25f; float num2 = t % num; float num3 = Mathf.Exp((0f - num2) * 55f) * (Sin(180f, num2) * 0.8f + Sin(540f, num2) * 0.3f); float num4 = 0.15f * Sin(60f, t) * (0.6f + 0.4f * Sin(4f, t)); return num3 + num4; } private static float Clang(float t) { return 0.55f * Sin(520f, t) * Mathf.Exp((0f - t) * 9f) + 0.4f * Sin(1180f, t) * Mathf.Exp((0f - t) * 14f) + 0.3f * Sin(1960f, t) * Mathf.Exp((0f - t) * 22f) + 0.2f * Sin(3150f, t) * Mathf.Exp((0f - t) * 30f) + 0.6f * (Sin(2200f, t) + Sin(3700f, t)) * Mathf.Exp((0f - t) * 400f); } private static float Thud(float t) { float num = 90f * Mathf.Exp((0f - t) * 6f) + 45f; return Mathf.Sin(MathF.PI * 2f * num * t) * Mathf.Exp((0f - t) * 11f) + 0.25f * Sin(210f, t) * Mathf.Exp((0f - t) * 35f); } private static float RingWave(float t) { float num = Mathf.Exp((0f - t) * 40f) * (Sin(90f, t) + 0.6f * Sin(1400f, t)); float num2 = (0.55f * Sin(3400f, t) + 0.35f * Sin(5100f, t)) * Mathf.Exp((0f - t) * 0.9f); return num + 0.5f * num2; } private static float Plink(float t) { return 0.6f * Sin(1800f, t) * Mathf.Exp((0f - t) * 18f) + 0.4f * Sin(2650f, t) * Mathf.Exp((0f - t) * 24f) + 0.2f * Sin(4100f, t) * Mathf.Exp((0f - t) * 40f); } } internal static class ValuableFactory { private const BindingFlags BF = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; private static readonly string[] Allowed = new string[8] { "PhysGrab", "Valuable", "RoomVolume", "Photon", "Impact", "Durab", "NavMesh", "Collider" }; private static Transform holder; public static Transform Holder { get { //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_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown if ((Object)(object)holder == (Object)null) { GameObject val = new GameObject("MV_PrefabHolder"); val.SetActive(false); Object.DontDestroyOnLoad((Object)val); holder = val.transform; } return holder; } } public static bool IsCleanSource(GameObject prefab) { if ((Object)(object)prefab == (Object)null || (Object)(object)prefab.GetComponent<ValuableObject>() == (Object)null) { return false; } MonoBehaviour[] componentsInChildren = prefab.GetComponentsInChildren<MonoBehaviour>(true); foreach (MonoBehaviour val in componentsInChildren) { if ((Object)(object)val == (Object)null) { return false; } string name = ((object)val).GetType().Name; bool flag = false; string[] allowed = Allowed; foreach (string value in allowed) { if (name.Contains(value)) { flag = true; break; } } if (!flag) { return false; } } return true; } public static GameObject Build(Def def, GameObject source, ManualLogSource log) { //IL_004d: 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_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_01f5: Unknown result type (might be due to invalid IL or missing references) //IL_0251: Unknown result type (might be due to invalid IL or missing references) //IL_0256: Unknown result type (might be due to invalid IL or missing references) //IL_0258: Unknown result type (might be due to invalid IL or missing references) //IL_025d: Unknown result type (might be due to invalid IL or missing references) //IL_02d7: Unknown result type (might be due to invalid IL or missing references) //IL_02e0: Unknown result type (might be due to invalid IL or missing references) //IL_02e7: Unknown result type (might be due to invalid IL or missing references) //IL_02f3: Unknown result type (might be due to invalid IL or missing references) //IL_02f5: 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_0300: Unknown result type (might be due to invalid IL or missing references) //IL_0305: Unknown result type (might be due to invalid IL or missing references) //IL_030a: Unknown result type (might be due to invalid IL or missing references) //IL_0327: Unknown result type (might be due to invalid IL or missing references) //IL_0328: Unknown result type (might be due to invalid IL or missing references) //IL_034f: Unknown result type (might be due to invalid IL or missing references) //IL_035e: Unknown result type (might be due to invalid IL or missing references) //IL_0377: Unknown result type (might be due to invalid IL or missing references) //IL_027f: Unknown result type (might be due to invalid IL or missing references) //IL_0284: Unknown result type (might be due to invalid IL or missing references) //IL_0288: Unknown result type (might be due to invalid IL or missing references) //IL_028d: Unknown result type (might be due to invalid IL or missing references) //IL_028f: Unknown result type (might be due to invalid IL or missing references) //IL_0291: Unknown result type (might be due to invalid IL or missing references) //IL_02ad: Unknown result type (might be due to invalid IL or missing references) //IL_02af: Unknown result type (might be due to invalid IL or missing references) //IL_02ce: Unknown result type (might be due to invalid IL or missing references) //IL_02d3: Unknown result type (might be due to invalid IL or missing references) GameObject val = Object.Instantiate<GameObject>(source, Holder); ((Object)val).name = def.Name; ValuableObject component = val.GetComponent<ValuableObject>(); if ((Object)(object)component == (Object)null) { log.LogWarning((object)("[" + def.Id + "] у образца нет ValuableObject, пропуск.")); Object.DestroyImmediate((Object)(object)val); return null; } Bounds acc = default(Bounds); ((Bounds)(ref acc))..ctor(Vector3.zero, Vector3.zero); bool has = false; Material val2 = null; MeshRenderer[] componentsInChildren = val.GetComponentsInChildren<MeshRenderer>(true); foreach (MeshRenderer val3 in componentsInChildren) { MeshFilter component2 = ((Component)val3).GetComponent<MeshFilter>(); if (!((Object)(object)component2 == (Object)null) && !((Object)(object)component2.sharedMesh == (Object)null)) { if ((Object)(object)val2 == (Object)null && (Object)(object)((Renderer)val3).sharedMaterial != (Object)null) { val2 = ((Renderer)val3).sharedMaterial; } Encapsulate(val.transform, ((Component)val3).transform, component2.sharedMesh.bounds, ref acc, ref has); } } SkinnedMeshRenderer[] componentsInChildren2 = val.GetComponentsInChildren<SkinnedMeshRenderer>(true); foreach (SkinnedMeshRenderer val4 in componentsInChildren2) { if (!((Object)(object)val4.sharedMesh == (Object)null)) { if ((Object)(object)val2 == (Object)null && (Object)(object)((Renderer)val4).sharedMaterial != (Object)null) { val2 = ((Renderer)val4).sharedMaterial; } Encapsulate(val.transform, ((Component)val4).transform, val4.sharedMesh.bounds, ref acc, ref has); } } if ((Object)(object)MeshKit.BaseMaterial == (Object)null && (Object)(object)val2 != (Object)null) { MeshKit.BaseMaterial = val2; } componentsInChildren = val.GetComponentsInChildren<MeshRenderer>(true); for (int i = 0; i < componentsInChildren.Length; i++) { Object.DestroyImmediate((Object)(object)componentsInChildren[i]); } componentsInChildren2 = val.GetComponentsInChildren<SkinnedMeshRenderer>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { Object.DestroyImmediate((Object)(object)componentsInChildren2[i]); } MeshFilter[] componentsInChildren3 = val.GetComponentsInChildren<MeshFilter>(true); for (int i = 0; i < componentsInChildren3.Length; i++) { Object.DestroyImmediate((Object)(object)componentsInChildren3[i]); } Transform transform = new GameObject("MindustryModel").transform; transform.SetParent(val.transform, false); def.Build(transform); if (!MeshKit.GetModelBounds(transform, out var bounds)) { log.LogWarning((object)("[" + def.Id + "] модель пустая, пропуск.")); Object.DestroyImmediate((Object)(object)val); return null; } float num = 1f; Quaternion val5 = Quaternion.identity; Vector3 val6 = Vector3.zero; if (has) { float num2 = -1f; foreach (Quaternion item2 in Orientations(def.AllowTilt)) { float num3 = Fit(((Bounds)(ref acc)).size, RotatedSize(bounds, item2)); if (num3 > num2 * 1.05f) { num2 = num3; val5 = item2; } } num = num2; val6 = ((Bounds)(ref acc)).center; } transform.localRotation = val5; transform.localScale = Vector3.one * num; transform.localPosition = val6 - val5 * (((Bounds)(ref bounds)).center * num); if (has && MeshKit.GetModelBounds(val.transform, out var bounds2)) { FitColliders(val, acc, bounds2, log, def.Id); log.LogInfo((object)$"[{def.Id}] образец {((Bounds)(ref acc)).size:F2}, модель {((Bounds)(ref bounds2)).size:F2}, масштаб {num:F2}, поворот {((Quaternion)(ref val5)).eulerAngles}"); } float item = def.Value * Plugin.ValueMultiplier.Value; if (def.FixedPrice > 0f) { SetFixedValue(component, def.FixedPrice, log, def.Id); } else { CloneAndScale(component, "valuePreset", ("valueMin", item), ("valueMax", item)); } CloneAndScale(component, "durabilityPreset", ("fragility", def.Fragility), ("durability", def.Durability)); CloneAndScale(component, "physAttributePreset", ("mass", def.Mass)); FieldInfo field = ((object)component).GetType().GetField("physAttributePreset", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null && field.GetValue(component) != null) { log.LogInfo((object)string.Format("[{0}] масса после настройки: {1} (x{2} от образца)", def.Id, ReadNumber(field.GetValue(component), "mass"), def.Mass)); } if (def.Loop != Loop.None) { HeldLoop heldLoop = val.AddComponent<HeldLoop>(); heldLoop.clip = SoundKit.GetLoop(def.Loop); heldLoop.volume = def.LoopVolume; } if (!string.IsNullOrEmpty(def.PulseSound)) { val.AddComponent<MassProbe>(); HeldPulse heldPulse = val.AddComponent<HeldPulse>(); heldPulse.clip = EmbeddedAudio.Load(def.PulseSound); heldPulse.interval = def.PulseInterval; } if (def.Hit != Hit.None) { val.AddComponent<ImpactSound>().clip = SoundKit.GetHit(def.Hit); } if (def.Blind != Blind.None) { val.AddComponent<BlindOnHold>().kind = def.Blind; } return val; } private static IEnumerable<Quaternion> Orientations(bool tilt) { yield return Quaternion.identity; yield return Quaternion.Euler(0f, 90f, 0f); if (tilt) { yield return Quaternion.Euler(90f, 0f, 0f); yield return Quaternion.Euler(0f, 0f, 90f); yield return Quaternion.Euler(90f, 90f, 0f); yield return Quaternion.Euler(0f, 90f, 90f); } } private static Vector3 RotatedSize(Bounds b, Quaternion q) { //IL_0030: 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_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0095: 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) //IL_0070: 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_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007b: 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_0082: 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_0084: 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_008a: Unknown result type (might be due to invalid IL or missing references) Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor(float.MaxValue, float.MaxValue, float.MaxValue); Vector3 val2 = default(Vector3); ((Vector3)(ref val2))..ctor(float.MinValue, float.MinValue, float.MinValue); for (int i = 0; i < 8; i++) { Vector3 val3 = q * Vector3.Scale(((Bounds)(ref b)).extents, new Vector3(((i & 1) == 0) ? (-1f) : 1f, ((i & 2) == 0) ? (-1f) : 1f, ((i & 4) == 0) ? (-1f) : 1f)); val = Vector3.Min(val, val3); val2 = Vector3.Max(val2, val3); } return val2 - val; } private static void FitColliders(GameObject go, Bounds src, Bounds dst, ManualLogSource log, string id) { //IL_0004: 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_0021: 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_003e: 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_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_019a: 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) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01cf: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: Unknown result type (might be due to invalid IL or missing references) //IL_01d5: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_0164: 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_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0126: 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_0129: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor(Ratio(((Bounds)(ref dst)).size.x, ((Bounds)(ref src)).size.x), Ratio(((Bounds)(ref dst)).size.y, ((Bounds)(ref src)).size.y), Ratio(((Bounds)(ref dst)).size.z, ((Bounds)(ref src)).size.z)); float num = Mathf.Min(val.x, Mathf.Min(val.y, val.z)); Transform transform = go.transform; Collider[] componentsInChildren = go.GetComponentsInChildren<Collider>(true); foreach (Collider val2 in componentsInChildren) { Transform transform2 = ((Component)val2).transform; BoxCollider val3 = (BoxCollider)(object)((val2 is BoxCollider) ? val2 : null); if (val3 != null) { Bounds val4 = default(Bounds); bool flag = false; for (int j = 0; j < 8; j++) { Vector3 local = val3.center + Vector3.Scale(val3.size * 0.5f, new Vector3(((j & 1) == 0) ? (-1f) : 1f, ((j & 2) == 0) ? (-1f) : 1f, ((j & 4) == 0) ? (-1f) : 1f)); Vector3 val5 = ColliderPointMap(transform, transform2, local, src, dst, val); if (!flag) { ((Bounds)(ref val4))..ctor(val5, Vector3.zero); flag = true; } else { ((Bounds)(ref val4)).Encapsulate(val5); } } val3.center = ((Bounds)(ref val4)).center; val3.size = ((Bounds)(ref val4)).size; continue; } SphereCollider val6 = (SphereCollider)(object)((val2 is SphereCollider) ? val2 : null); if (val6 != null) { val6.center = ColliderPointMap(transform, transform2, val6.center, src, dst, val); val6.radius *= num; continue; } CapsuleCollider val7 = (CapsuleCollider)(object)((val2 is CapsuleCollider) ? val2 : null); if (val7 != null) { val7.center = ColliderPointMap(transform, transform2, val7.center, src, dst, val); val7.radius *= num; val7.height *= num; continue; } log.LogWarning((object)("[" + id + "] коллайдер типа " + ((object)val2).GetType().Name + " (" + ((Object)val2).name + ") не подгоняется.")); } } private static float Ratio(float dst, float src) { if (src < 0.0001f) { return 1f; } return Mathf.Clamp(dst / src, 0.05f, 1.25f); } private static Vector3 ColliderPointMap(Transform root, Transform ct, Vector3 local, Bounds src, Bounds dst, Vector3 ratio) { //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_0010: 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_0018: 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) //IL_0022: 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) //IL_002e: 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_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) Vector3 val = root.InverseTransformPoint(ct.TransformPoint(local)); Vector3 val2 = ((Bounds)(ref dst)).center + Vector3.Scale(val - ((Bounds)(ref src)).center, ratio); return ct.InverseTransformPoint(root.TransformPoint(val2)); } private static void SetFixedValue(ValuableObject vo, float dollars, ManualLogSource log, string id) { FieldInfo field = ((object)vo).GetType().GetField("valuePreset", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field == null) { log.LogWarning((object)("[" + id + "] нет поля valuePreset, цена не задана.")); return; } object obj = field.GetValue(vo); if (obj == null) { log.LogWarning((object)("[" + id + "] valuePreset пуст, цена не задана.")); return; } float num = ReadNumber(obj, "valueMin"); float num2 = ReadNumber(obj, "valueMax"); float num3 = ((num2 > 0f && num2 < 200f) ? 0.001f : 1f); float num4 = dollars * num3; Object val = (Object)((obj is Object) ? obj : null); if (val != null) { obj = Object.Instantiate(val); } else { MethodInfo method = obj.GetType().GetMethod("MemberwiseClone", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (method != null) { obj = method.Invoke(obj, null); } } WriteNumber(obj, "valueMin", num4); WriteNumber(obj, "valueMax", num4); field.SetValue(vo, obj); log.LogInfo((object)$"[{id}] цена ${dollars:N0}: у образца {num}..{num2}, записано {num4} (масштаб {num3})"); } private static float ReadNumber(object o, string field) { FieldInfo field2 = o.GetType().GetField(field, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field2 == null) { return 0f; } object value = field2.GetValue(o); if (value is float) { return (float)value; } if (value is int num) { return num; } return 0f; } private static void WriteNumber(object o, string field, float value) { FieldInfo field2 = o.GetType().GetField(field, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (!(field2 == null)) { object value2 = field2.GetValue(o); if (value2 is float) { field2.SetValue(o, value); } else if (value2 is int) { field2.SetValue(o, Mathf.RoundToInt(value)); } } } private static float Fit(Vector3 target, Vector3 model) { //IL_0006: 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_0014: 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_0048: 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_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0056: 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) float num = float.MaxValue; if (model.x > 0.0001f) { num = Mathf.Min(num, target.x / model.x); } if (model.y > 0.0001f) { num = Mathf.Min(num, target.y / model.y); } if (model.z > 0.0001f) { num = Mathf.Min(num, target.z / model.z); } if (num == float.MaxValue || num <= 0f) { num = 1f; } return num; } private static void Encapsulate(Transform root, Transform part, Bounds b, ref Bounds acc, ref bool has) { //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) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: 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_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: 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_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_0072: 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) for (int i = 0; i < 8; i++) { Vector3 val = ((Bounds)(ref b)).center + Vector3.Scale(((Bounds)(ref b)).extents, new Vector3(((i & 1) == 0) ? (-1f) : 1f, ((i & 2) == 0) ? (-1f) : 1f, ((i & 4) == 0) ? (-1f) : 1f)); Vector3 val2 = root.InverseTransformPoint(part.TransformPoint(val)); if (!has) { acc = new Bounds(val2, Vector3.zero); has = true; } else { ((Bounds)(ref acc)).Encapsulate(val2); } } } private static void CloneAndScale(object owner, string presetField, params (string field, float k)[] scales) { FieldInfo field = owner.GetType().GetField(presetField, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field == null) { return; } object obj = field.GetValue(owner); if (obj == null) { return; } Object val = (Object)((obj is Object) ? obj : null); if (val != null) { obj = Object.Instantiate(val); } else { MethodInfo method = obj.GetType().GetMethod("MemberwiseClone", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (method != null) { obj = method.Invoke(obj, null); } } for (int i = 0; i < scales.Length; i++) { (string field, float k) tuple = scales[i]; string item = tuple.field; float item2 = tuple.k; FieldInfo field2 = obj.GetType().GetField(item, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (!(field2 == null)) { object value = field2.GetValue(obj); if (value is float num) { field2.SetValue(obj, num * item2); } else if (value is int num2) { field2.SetValue(obj, Mathf.RoundToInt((float)num2 * item2)); } } } field.SetValue(owner, obj); } } }