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 OneShotValuables v0.1.2
OneShotValuables.dll
Decompiled 2 days 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 HarmonyLib; 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 OneShotValuables { 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 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 SunBurst : MonoBehaviour { public float maxDistance = 45f; public float coneDegrees = 80f; public bool requireLineOfSight = true; private bool fired; private bool wasGrabbed; private PhysGrabObject pgo; private void Awake() { pgo = ((Component)this).GetComponentInParent<PhysGrabObject>(); } private void Update() { if (Plugin.DebugSunOnGrab != null && Plugin.DebugSunOnGrab.Value && (Object)(object)pgo != (Object)null) { bool grabbed = pgo.grabbed; if (grabbed && !wasGrabbed) { Fire(force: true); } wasGrabbed = grabbed; } } public static void OnDestroying(Component source) { if (!((Object)(object)source == (Object)null)) { SunBurst componentInParent = source.GetComponentInParent<SunBurst>(); if ((Object)(object)componentInParent != (Object)null) { componentInParent.Fire(force: false); } } } public void Fire(bool force) { //IL_0019: 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_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_0032: 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_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: 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_0056: 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_005c: 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_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0146: 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_00a2: 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) if (fired && !force) { return; } fired = true; Vector3 val = ((Component)this).transform.position + Vector3.up * 0.2f; SpawnWorldFlash(val); Camera val2 = FindPlayerCamera(); if ((Object)(object)val2 == (Object)null) { return; } Vector3 position = ((Component)val2).transform.position; Vector3 val3 = val - position; float magnitude = ((Vector3)(ref val3)).magnitude; if (!(magnitude > maxDistance) && !(magnitude < 0.01f)) { float num = Vector3.Angle(((Component)val2).transform.forward, val3); if (!(num > coneDegrees) && (!requireLineOfSight || !IsBlocked(position, val3 / magnitude, magnitude))) { float num2 = 1f - num / coneDegrees; float num3 = Mathf.Clamp01(1.3f - magnitude / maxDistance); float strength = Mathf.Clamp01((0.6f + 0.4f * num2) * (0.5f + 0.5f * num3)); float hold = Mathf.Lerp(0.8f, 3.5f, num2) * Mathf.Lerp(0.6f, 1f, num3); float fade = Mathf.Lerp(2f, 6f, num2); BlindOverlay.Flash(new Color(1f, 0.97f, 0.85f), strength, hold, fade); } } } private bool IsBlocked(Vector3 from, Vector3 dir, float dist) { //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_0021: 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) RaycastHit[] array = Physics.RaycastAll(from, dir, Mathf.Max(0.1f, dist - 0.3f), -1, (QueryTriggerInteraction)1); for (int i = 0; i < array.Length; i++) { RaycastHit val = array[i]; if (!(((RaycastHit)(ref val)).distance < 1f) && !((Component)((RaycastHit)(ref val)).collider).transform.IsChildOf(((Component)this).transform)) { return true; } } return false; } private static Camera FindPlayerCamera() { Camera main = Camera.main; if ((Object)(object)main != (Object)null && ((Behaviour)main).enabled && ((Component)main).gameObject.activeInHierarchy) { return main; } main = null; Camera[] allCameras = Camera.allCameras; foreach (Camera val in allCameras) { if (!((Object)(object)val == (Object)null) && ((Behaviour)val).enabled && !((Object)(object)val.targetTexture != (Object)null) && ((Object)(object)main == (Object)null || val.depth > main.depth)) { main = val; } } return main; } private static void SpawnWorldFlash(Vector3 pos) { //IL_0005: 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_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("MV_SunFlash"); val.transform.position = pos; Light obj = val.AddComponent<Light>(); obj.type = (LightType)2; obj.range = 30f; obj.intensity = 12f; obj.color = new Color(1f, 0.95f, 0.8f); obj.shadows = (LightShadows)0; val.AddComponent<LightFade>(); } } internal class LightFade : MonoBehaviour { private Light l; private float start; private void Start() { l = ((Component)this).GetComponent<Light>(); start = (((Object)(object)l != (Object)null) ? l.intensity : 0f); } private void Update() { if ((Object)(object)l == (Object)null) { Object.Destroy((Object)(object)((Component)this).gameObject); return; } l.intensity = Mathf.MoveTowards(l.intensity, 0f, start * Time.deltaTime / 1.2f); if (l.intensity <= 0.01f) { Object.Destroy((Object)(object)((Component)this).gameObject); } } } 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, bool noEmission = false) { //IL_00c1: 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_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_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_01ad: Expected O, but got Unknown //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_0262: Unknown result type (might be due to invalid IL or missing references) //IL_027c: Unknown result type (might be due to invalid IL or missing references) //IL_027e: 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)) != "MVM2") { 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(); int num8 = binaryReader.ReadInt32(); int num9 = 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()); } Vector2[] array3 = (Vector2[])(object)new Vector2[num6]; for (int l = 0; l < num6; l++) { array3[l] = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle()); } int[] array4 = new int[num7]; for (int m = 0; m < num7; m++) { array4[m] = binaryReader.ReadUInt16(); } byte[] array5 = ((num8 > 0) ? binaryReader.ReadBytes(num8) : null); byte[] emisPng = ((num9 > 0) ? binaryReader.ReadBytes(num9) : null); Mesh val = new Mesh { name = fileName + "_" + i }; val.vertices = array; val.normals = array2; val.uv = array3; val.triangles = array4; val.RecalculateBounds(); ((Color)(ref color))..ctor(num2, num3, num4, 1f); float emission = (noEmission ? 0f : num5); bool cutout = (b & 2) != 0; Transform transform; if (array5 != null) { Material texturedMaterial = MeshKit.GetTexturedMaterial(fileName + "_" + i, array5, emisPng, cutout, noEmission); transform = MeshKit.PartWithMaterial(parent, "Part" + i, val, texturedMaterial); } else { 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 Transform PartWithMaterial(Transform parent, string name, Mesh mesh, Material mat) { //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_001f: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name); val.transform.SetParent(parent, false); val.AddComponent<MeshFilter>().sharedMesh = mesh; MeshRenderer obj = val.AddComponent<MeshRenderer>(); ((Renderer)obj).sharedMaterial = mat; ((Renderer)obj).shadowCastingMode = (ShadowCastingMode)1; ((Renderer)obj).receiveShadows = true; return val.transform; } public static Material GetTexturedMaterial(string key, byte[] png, byte[] emisPng, bool cutout, bool noEmission) { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Expected O, but got Unknown //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Expected O, but got Unknown //IL_0207: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Unknown result type (might be due to invalid IL or missing references) if (MatCache.TryGetValue("tex_" + key, out var value) && (Object)(object)value != (Object)null) { return value; } Material val = CreateBase(); ((Object)val).name = "MV_tex_" + key; if (val.HasProperty("_BaseColor")) { val.SetColor("_BaseColor", Color.white); } if (val.HasProperty("_Color")) { val.SetColor("_Color", Color.white); } Texture2D val2 = new Texture2D(2, 2, (TextureFormat)4, false); ImageConversion.LoadImage(val2, png); ((Texture)val2).filterMode = (FilterMode)0; ((Texture)val2).wrapMode = (TextureWrapMode)1; if (val.HasProperty("_MainTex")) { val.SetTexture("_MainTex", (Texture)(object)val2); } if (val.HasProperty("_BaseMap")) { val.SetTexture("_BaseMap", (Texture)(object)val2); } if (val.HasProperty("_Metallic")) { val.SetFloat("_Metallic", 0f); } if (val.HasProperty("_Glossiness")) { val.SetFloat("_Glossiness", 0.15f); } if (cutout) { if (val.HasProperty("_Mode")) { val.SetFloat("_Mode", 1f); } if (val.HasProperty("_Cutoff")) { val.SetFloat("_Cutoff", 0.5f); } val.EnableKeyword("_ALPHATEST_ON"); val.renderQueue = 2450; } val.DisableKeyword("_EMISSION"); string[] array = new string[2] { "_EmissionColor", "_EmissiveColor" }; foreach (string text in array) { if (val.HasProperty(text)) { val.SetColor(text, Color.black); } } if (emisPng != null && !noEmission) { Texture2D val3 = new Texture2D(2, 2, (TextureFormat)4, false); ImageConversion.LoadImage(val3, emisPng); ((Texture)val3).filterMode = (FilterMode)0; val.EnableKeyword("_EMISSION"); val.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)1; if (val.HasProperty("_EmissionMap")) { val.SetTexture("_EmissionMap", (Texture)(object)val3); } if (val.HasProperty("_EmissionColor")) { val.SetColor("_EmissionColor", Color.white * 0.6f); } } MatCache["tex_" + key] = val; return val; } 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 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 bool Sun; public bool SingleBox; public bool AllowTilt; public Action<Transform> Build; } internal static class Models { public static List<Def> All() { return new List<Def> { new Def { Id = "sun_lamp", Name = "Sun Lamp", Size = "medium", Value = 2.2f, Mass = 0.8f, Fragility = Plugin.SunFragility.Value, Durability = 0.6f, Loop = Loop.Hum, LoopVolume = 0.25f, Hit = Hit.Plink, Sun = true, SingleBox = true, Build = SunLamp }, new Def { Id = "niko_figure", Name = "Niko Figure", Size = "medium", Value = 2f, Mass = 0.7f, Fragility = 1f, Hit = Hit.Thud, SingleBox = true, Build = NikoFigure } }; } private static void AddGlow(Transform t, Color c, float min, float max, float speed, Light l = null, float lightMax = 1.5f) { //IL_000c: 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) Glow glow = ((Component)t).gameObject.AddComponent<Glow>(); glow.color = c; glow.minIntensity = min; glow.maxIntensity = max; glow.speed = speed; glow.lightSource = l; glow.lightMax = lightMax; } private static void SunLamp(Transform t) { //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_003a: 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_007d: 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 color = default(Color); ((Color)(ref color))..ctor(1f, 0.82f, 0.35f); List<ImportedModel.Part> list = ImportedModel.Build(t, "sun.mvm"); GameObject val = new GameObject("SunLight"); val.transform.SetParent(t, false); val.transform.localPosition = new Vector3(0f, 0.65f, 0f); Light val2 = val.AddComponent<Light>(); val2.type = (LightType)2; val2.range = 7f; val2.intensity = 1.2f; val2.color = color; val2.shadows = (LightShadows)0; if (list.Count > 0) { AddGlow(list[0].Transform, Color.white, 0.35f, 0.9f, 2.5f, val2, 1.4f); } } private static void NikoFigure(Transform t) { ImportedModel.Build(t, "niko.mvm", noEmission: true); } } [HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "DestroyObjectRPC")] internal static class DestroyObjectRpcPatch { [HarmonyPrefix] private static void Prefix(PhysGrabObjectImpactDetector __instance) { try { SunBurst.OnDestroying((Component)(object)__instance); } catch (Exception ex) { Plugin.Log.LogError((object)("SunBurst: " + ex)); } } } [BepInPlugin("oneshot.valuables", "OneShotValuables", "0.1.2")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public const string PluginGuid = "oneshot.valuables"; public const string PluginName = "OneShotValuables"; public const string PluginVersion = "0.1.2"; internal static ManualLogSource Log; internal static ConfigEntry<float> ValueMultiplier; internal static ConfigEntry<float> SoundVolume; internal static ConfigEntry<float> SunFragility; internal static ConfigEntry<bool> DebugSunOnGrab; 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_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Expected O, but got Unknown //IL_014a: Unknown result type (might be due to invalid IL or missing references) 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>())); SunFragility = ((BaseUnityPlugin)this).Config.Bind<float>("Valuables", "SunLampFragility", 4f, new ConfigDescription("Насколько хрупкая Sun Lamp (1 = как обычная ценность, 4 = очень хрупкая, ломается от лёгких ударов). Применяется при запуске игры.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 10f), Array.Empty<object>())); DebugSunOnGrab = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "SunFlashOnGrab", false, "Тест: Sun Lamp даёт вспышку, когда её берут в руки (чтобы проверить эффект, не ломая лампу)."); 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(); try { new Harmony("oneshot.valuables").PatchAll(typeof(Plugin).Assembly); } catch (Exception ex) { Log.LogError((object)("Harmony-патчи не применились (Sun Lamp не будет слепить при разрушении): " + ex)); } ((MonoBehaviour)this).StartCoroutine(RegisterRoutine()); Log.LogInfo((object)"OneShotValuables v0.1.2 загружен, жду готовности игры и 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_0057: 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_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_01ff: Unknown result type (might be due to invalid IL or missing references) //IL_025b: Unknown result type (might be due to invalid IL or missing references) //IL_0260: Unknown result type (might be due to invalid IL or missing references) //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_0267: Unknown result type (might be due to invalid IL or missing references) //IL_02e1: Unknown result type (might be due to invalid IL or missing references) //IL_02ea: Unknown result type (might be due to invalid IL or missing references) //IL_02f1: Unknown result type (might be due to invalid IL or missing references) //IL_02fd: Unknown result type (might be due to invalid IL or missing references) //IL_02ff: Unknown result type (might be due to invalid IL or missing references) //IL_0303: 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_030f: Unknown result type (might be due to invalid IL or missing references) //IL_0314: Unknown result type (might be due to invalid IL or missing references) //IL_0351: Unknown result type (might be due to invalid IL or missing references) //IL_0352: Unknown result type (might be due to invalid IL or missing references) //IL_033f: Unknown result type (might be due to invalid IL or missing references) //IL_0341: Unknown result type (might be due to invalid IL or missing references) //IL_0289: Unknown result type (might be due to invalid IL or missing references) //IL_028e: Unknown result type (might be due to invalid IL or missing references) //IL_0292: Unknown result type (might be due to invalid IL or missing references) //IL_0297: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Unknown result type (might be due to invalid IL or missing references) //IL_029b: Unknown result type (might be due to invalid IL or missing references) //IL_0379: Unknown result type (might be due to invalid IL or missing references) //IL_0388: Unknown result type (might be due to invalid IL or missing references) //IL_03a1: Unknown result type (might be due to invalid IL or missing references) //IL_02b7: Unknown result type (might be due to invalid IL or missing references) //IL_02b9: Unknown result type (might be due to invalid IL or missing references) //IL_02d8: Unknown result type (might be due to invalid IL or missing references) //IL_02dd: Unknown result type (might be due to invalid IL or missing references) GameObject val = Object.Instantiate<GameObject>(source, Holder); ((Object)val).name = "OneShot " + 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)) { if (def.SingleBox) { SingleBox(val, bounds2, acc, log, def.Id); } else { 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; CloneAndScale(component, "valuePreset", ("valueMin", item), ("valueMax", item)); CloneAndScale(component, "durabilityPreset", ("fragility", def.Fragility), ("durability", def.Durability)); CloneAndScale(component, "physAttributePreset", ("mass", def.Mass)); if (def.Loop != Loop.None) { HeldLoop heldLoop = val.AddComponent<HeldLoop>(); heldLoop.clip = SoundKit.GetLoop(def.Loop); heldLoop.volume = def.LoopVolume; } if (def.Hit != Hit.None) { val.AddComponent<ImpactSound>().clip = SoundKit.GetHit(def.Hit); } if (def.Sun) { val.AddComponent<SunBurst>(); } 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 void SingleBox(GameObject go, Bounds model, Bounds src, ManualLogSource log, string id) { //IL_002a: 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_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_003d: 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_004e: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: 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_008e: 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_0098: 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_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) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: 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_00b8: Unknown result type (might be due to invalid IL or missing references) int num = 0; Collider[] componentsInChildren = go.GetComponentsInChildren<Collider>(true); foreach (Collider obj in componentsInChildren) { BoxCollider val = (BoxCollider)(object)((obj is BoxCollider) ? obj : null); if (val == null) { continue; } Transform transform = ((Component)val).transform; Bounds val2 = default(Bounds); bool flag = false; for (int j = 0; j < 8; j++) { Vector3 val3 = ((Bounds)(ref model)).center + Vector3.Scale(((Bounds)(ref model)).size * 0.5f, new Vector3(((j & 1) == 0) ? (-1f) : 1f, ((j & 2) == 0) ? (-1f) : 1f, ((j & 4) == 0) ? (-1f) : 1f)); Vector3 val4 = transform.InverseTransformPoint(go.transform.TransformPoint(val3)); if (!flag) { ((Bounds)(ref val2))..ctor(val4, Vector3.zero); flag = true; } else { ((Bounds)(ref val2)).Encapsulate(val4); } } val.center = ((Bounds)(ref val2)).center; val.size = ((Bounds)(ref val2)).size * 0.96f; num++; } if (num == 0) { FitColliders(go, src, model, log, id); } log.LogInfo((object)$"[{id}] хитбокс по модели: {((Bounds)(ref model)).size:F2}, боксов подогнано: {num}"); } 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 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); } } }