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 WoodenDollScrap v1.2.0
BepInEx/plugins/WoodenDollScrap/WoodenDollScrap.dll
Decompiled 4 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Linq; using System.Numerics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using LethalLib.Modules; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.Audio; using UnityEngine.Rendering; using WoodenDollScrap.Geometry; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("WoodenDollScrap")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.2.0.0")] [assembly: AssemblyInformationalVersion("1.2.0")] [assembly: AssemblyProduct("WoodenDollScrap")] [assembly: AssemblyTitle("WoodenDollScrap")] [assembly: AssemblyVersion("1.2.0.0")] [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 WoodenDollScrap { internal sealed class PartConfig { public ConfigEntry<bool> Enabled; public ConfigEntry<int> Rarity; public ConfigEntry<int> MinValue; public ConfigEntry<int> MaxValue; public ConfigEntry<float> WeightLb; public ConfigEntry<string> HeldPositionOffset; public ConfigEntry<string> HeldRotationOffset; } internal sealed class DollConfig { public readonly ConfigEntry<float> Scale; public readonly ConfigEntry<float> RodGlowIntensity; public readonly ConfigEntry<string> RodGlowColor; public readonly ConfigEntry<float> RodHumVolume; public readonly Dictionary<DollPart, PartConfig> Parts = new Dictionary<DollPart, PartConfig>(); public DollConfig(ConfigFile cfg) { //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Expected O, but got Unknown //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Expected O, but got Unknown //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Expected O, but got Unknown //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Expected O, but got Unknown //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Expected O, but got Unknown //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_021b: Expected O, but got Unknown //IL_026a: Unknown result type (might be due to invalid IL or missing references) //IL_0274: Expected O, but got Unknown Scale = cfg.Bind<float>("General", "Scale", 1f, new ConfigDescription("Size multiplier for all doll parts. 1.0 = the size of the default player's body parts. Needs a restart.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.25f, 3f), Array.Empty<object>())); PartDefinition[] all = PartDefinition.All; foreach (PartDefinition partDefinition in all) { string text = partDefinition.Part.ToString(); PartConfig partConfig = new PartConfig { Enabled = cfg.Bind<bool>(text, "Enabled", true, "Spawn this part as scrap. Host's setting decides."), Rarity = cfg.Bind<int>(text, "Rarity", partDefinition.DefaultRarity, new ConfigDescription("Spawn weight on every moon (vanilla scrap uses roughly 5-100). Host's setting decides.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 500), Array.Empty<object>())), MinValue = cfg.Bind<int>(text, "MinValue", 50, new ConfigDescription("Lowest sell value in credits. Host's setting decides.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 5000), Array.Empty<object>())), MaxValue = cfg.Bind<int>(text, "MaxValue", 100, new ConfigDescription("Highest sell value in credits. Host's setting decides.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 5000), Array.Empty<object>())), WeightLb = cfg.Bind<float>(text, "WeightLb", partDefinition.DefaultWeightLb, new ConfigDescription("Carry weight in pounds.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 290f), Array.Empty<object>())), HeldPositionOffset = cfg.Bind<string>(text, "HeldPositionOffset", "0,0,0", "Offset (x,y,z metres) from the hand while held. Tune if the part clips into the camera."), HeldRotationOffset = cfg.Bind<string>(text, "HeldRotationOffset", "0,0,0", "Rotation (x,y,z degrees) while held.") }; if (partConfig.MinValue.Value == 100 && partConfig.MaxValue.Value == 200) { partConfig.MinValue.Value = 50; partConfig.MaxValue.Value = 100; } Parts[partDefinition.Part] = partConfig; } RodGlowIntensity = cfg.Bind<float>("Rod", "GlowIntensity", 10f, new ConfigDescription("Brightness of the rod's bulbs at the peak of a pulse (0 = no glow).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 200f), Array.Empty<object>())); RodGlowColor = cfg.Bind<string>("Rod", "GlowColor", "4DFF9E", "Glow colour of the rod's bulbs as RRGGBB hex."); RodHumVolume = cfg.Bind<float>("Rod", "HumVolume", 0.35f, new ConfigDescription("Volume of the rod's hum (0 = silent).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>())); } public static Color ParseColor(string hex, Color fallback) { //IL_0008: 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_002c: Unknown result type (might be due to invalid IL or missing references) if (string.IsNullOrWhiteSpace(hex)) { return fallback; } string text = hex.Trim().TrimStart('#'); Color result = default(Color); if (!ColorUtility.TryParseHtmlString("#" + text, ref result)) { return fallback; } return result; } public static Vector3 ParseVector(string text, Vector3 fallback) { //IL_0008: 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_005a: 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) if (string.IsNullOrWhiteSpace(text)) { return fallback; } string[] array = text.Split(','); if (array.Length != 3) { return fallback; } float[] array2 = new float[3]; for (int i = 0; i < 3; i++) { if (!float.TryParse(array[i].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out array2[i])) { return fallback; } } return new Vector3(array2[0], array2[1], array2[2]); } } internal static class DollContent { internal sealed class Entry { public PartDefinition Def; public PartConfig Cfg; public Item Item; public GameObject Prefab; } public static readonly List<Entry> Entries = new List<Entry>(); private static Texture2D woodTexture; private static Texture2D faceTexture; private static Material faceMaterial; private static Material woodMaterial; private static Material steelMaterial; private static Material bootMaterial; private static Material glowMaterial; private static AudioClip humClip; private static bool templatesApplied; private const int PropsLayer = 6; private const int ScanNodeLayer = 22; private const int WoodSize = 512; private static readonly string[] OneHandTemplates = new string[5] { "Toy cube", "Hairdryer", "Magnifying glass", "Rubber Ducky", "Whoopie cushion" }; private static readonly string[] TwoHandTemplates = new string[5] { "Toy robot", "Cash register", "V-type engine", "Large axle", "Bottles" }; public static void Register(DollConfig config) { //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_007f: Unknown result type (might be due to invalid IL or missing references) byte[] array = WoodTexture.GenerateRgba(512); woodTexture = MakeTexture("WoodenDollWood", 512, 512, array, (TextureWrapMode)0); faceTexture = MakeTexture("WoodenDollFace", 1024, FaceTexture.Height, FaceTexture.GenerateRgba(array, 512), (TextureWrapMode)1); humClip = BuildHumClip(); RodPulse.GlowIntensity = config.RodGlowIntensity.Value; RodPulse.GlowColor = DollConfig.ParseColor(config.RodGlowColor.Value, RodPulse.GlowColor); RodPulse.HumVolume = config.RodHumVolume.Value; PartDefinition[] all = PartDefinition.All; foreach (PartDefinition partDefinition in all) { PartConfig partConfig = config.Parts[partDefinition.Part]; float value = config.Scale.Value; Vector3 centreOffset; MeshData meshData = DollGeometry.Build(partDefinition.Part, out centreOffset); meshData.Scale(value); Item val = CreateItem(partDefinition, partConfig, meshData); GameObject val2 = CreatePrefab(partDefinition, val, meshData); if (partDefinition.Part == DollPart.Rod) { AddRodEffects(val2, centreOffset, value); } val.spawnPrefab = val2; Entries.Add(new Entry { Def = partDefinition, Cfg = partConfig, Item = val, Prefab = val2 }); int num = (partConfig.Enabled.Value ? Mathf.Max(0, partConfig.Rarity.Value) : 0); Items.RegisterScrap(val, num, (LevelTypes)(-1)); Plugin.Log.LogInfo((object)$"Registered {partDefinition.ItemName} (rarity {num}, value {partConfig.MinValue.Value}-{partConfig.MaxValue.Value})."); } } private static Item CreateItem(PartDefinition def, PartConfig cfg, MeshData data) { //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: 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_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0115: 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_011d: 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) Item obj = ScriptableObject.CreateInstance<Item>(); ((Object)obj).name = def.PrefabName + "Item"; obj.itemName = def.ItemName; obj.isScrap = true; SetRawValues(obj, cfg, 0.4f); obj.weight = 1f + Mathf.Max(0f, cfg.WeightLb.Value) / 105f; obj.twoHanded = def.TwoHanded; obj.twoHandedAnimation = def.TwoHanded; obj.canBeGrabbedBeforeGameStart = true; obj.itemSpawnsOnGround = true; obj.isConductiveMetal = false; obj.requiresBattery = false; obj.allowDroppingAheadOfPlayer = true; obj.toolTips = new string[0]; obj.spawnPositionTypes = new List<ItemGroup>(); obj.restingRotation = def.RestingRotation; obj.positionOffset = DollConfig.ParseVector(cfg.HeldPositionOffset.Value, Vector3.zero); obj.rotationOffset = DollConfig.ParseVector(cfg.HeldRotationOffset.Value, Vector3.zero); obj.grabAnimationTime = (def.TwoHanded ? 0.3f : 0.15f); Vector3 restingRotation = def.RestingRotation; float num = data.LowestPointAfterRotation(new Vector3(restingRotation.x, restingRotation.y, restingRotation.z)); obj.verticalOffset = Mathf.Max(0f, 0f - num - 0.04f + 0.005f); obj.floorYOffset = 0; return obj; } private static GameObject CreatePrefab(PartDefinition def, Item item, MeshData data) { //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_0063: Unknown result type (might be due to invalid IL or missing references) //IL_006e: 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_0076: 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_0109: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) GameObject obj = NetworkPrefabs.CreateNetworkPrefab(def.PrefabName); obj.layer = 6; TrySetTag(obj, "PhysicsProp"); Mesh val = ToUnityMesh(def.PrefabName + "Mesh", data); obj.AddComponent<MeshFilter>().sharedMesh = val; MeshRenderer val2 = obj.AddComponent<MeshRenderer>(); ((Renderer)val2).sharedMaterials = (Material[])(object)new Material[4]; BoxCollider obj2 = obj.AddComponent<BoxCollider>(); Bounds bounds = val.bounds; obj2.center = ((Bounds)(ref bounds)).center; bounds = val.bounds; obj2.size = Vector3.Max(((Bounds)(ref bounds)).size, new Vector3(0.08f, 0.08f, 0.08f)); Rigidbody obj3 = obj.AddComponent<Rigidbody>(); obj3.isKinematic = true; obj3.useGravity = false; AudioSource obj4 = obj.AddComponent<AudioSource>(); obj4.playOnAwake = false; obj4.spatialBlend = 1f; obj4.rolloffMode = (AudioRolloffMode)1; obj4.minDistance = 1f; obj4.maxDistance = 25f; PhysicsProp obj5 = obj.AddComponent<PhysicsProp>(); ((GrabbableObject)obj5).itemProperties = item; ((GrabbableObject)obj5).grabbable = true; ((GrabbableObject)obj5).grabbableToEnemies = true; ((GrabbableObject)obj5).mainObjectRenderer = val2; string itemName = def.ItemName; bounds = val.bounds; AddScanNode(obj, itemName, ((Bounds)(ref bounds)).center); return obj; } private static void AddScanNode(GameObject prefab, string header, Vector3 centre) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Expected O, but got Unknown //IL_0072: 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_0097: Unknown result type (might be due to invalid IL or missing references) GameObject val; if ((Object)(object)Items.scanNodePrefab != (Object)null) { val = Object.Instantiate<GameObject>(Items.scanNodePrefab, prefab.transform); } else { val = new GameObject("ScanNode", new Type[2] { typeof(BoxCollider), typeof(ScanNodeProperties) }); val.transform.SetParent(prefab.transform, false); val.layer = 22; BoxCollider component = val.GetComponent<BoxCollider>(); ((Collider)component).isTrigger = true; component.size = Vector3.one * 0.5f; } ((Object)val).name = "ScanNode"; val.transform.localPosition = centre; ScanNodeProperties component2 = val.GetComponent<ScanNodeProperties>(); component2.headerText = header; component2.subText = "Value: "; component2.nodeType = 2; component2.minRange = 1; component2.maxRange = 13; component2.requiresLineOfSight = true; component2.creatureScanID = -1; } private static void TrySetTag(GameObject go, string tag) { try { go.tag = tag; } catch (Exception ex) { Plugin.Log.LogWarning((object)("Could not set tag " + tag + ": " + ex.Message)); } } private static void AddRodEffects(GameObject prefab, Vector3 centreOffset, float scale) { //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) MeshData meshData = DollGeometry.BuildRodBulb(); meshData.Scale(scale); Mesh sharedMesh = ToUnityMesh("PulsatingRodBulb", meshData); Transform[] array = (Transform[])(object)new Transform[DollGeometry.RodBulbs.Length]; Renderer[] array2 = (Renderer[])(object)new Renderer[array.Length]; for (int i = 0; i < array.Length; i++) { Vector3 vector = (DollGeometry.RodBulbs[i] + centreOffset) * scale; GameObject val = new GameObject("Bulb" + i); val.layer = 6; val.transform.SetParent(prefab.transform, false); val.transform.localPosition = new Vector3(vector.X, vector.Y, vector.Z); val.AddComponent<MeshFilter>().sharedMesh = sharedMesh; MeshRenderer val2 = val.AddComponent<MeshRenderer>(); ((Renderer)val2).sharedMaterials = (Material[])(object)new Material[1]; array[i] = val.transform; array2[i] = (Renderer)(object)val2; } GameObject val3 = new GameObject("Hum"); val3.transform.SetParent(prefab.transform, false); AudioSource val4 = val3.AddComponent<AudioSource>(); val4.clip = humClip; val4.loop = true; val4.playOnAwake = false; val4.spatialBlend = 1f; val4.rolloffMode = (AudioRolloffMode)1; val4.minDistance = 0.5f; val4.maxDistance = 10f; val4.dopplerLevel = 0f; RodPulse rodPulse = prefab.AddComponent<RodPulse>(); rodPulse.Bulbs = array; rodPulse.BulbRenderers = array2; rodPulse.Hum = val4; rodPulse.Prop = prefab.GetComponent<GrabbableObject>(); } private static AudioClip BuildHumClip() { float[] array = new float[88200]; for (int i = 0; i < array.Length; i++) { double num = (double)i / 44100.0; array[i] = (float)(0.3 * Math.Sin(Math.PI * 140.0 * num) + 0.18 * Math.Sin(Math.PI * 70.0 * num) + 0.1 * Math.Sin(Math.PI * 280.0 * num + 0.7) + 0.04 * Math.Sin(Math.PI * 420.0 * num + 1.9)); } AudioClip obj = AudioClip.Create("PulsatingRodHum", array.Length, 1, 44100, false); obj.SetData(array, 0); return obj; } private static Mesh ToUnityMesh(string name, MeshData d) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown Mesh val = new Mesh { name = name }; if (d.Positions.Count > 65000) { val.indexFormat = (IndexFormat)1; } val.SetVertices(((IEnumerable<Vector3>)d.Positions).Select((Func<Vector3, Vector3>)((Vector3 p) => new Vector3(p.X, p.Y, p.Z))).ToList()); val.SetNormals(((IEnumerable<Vector3>)d.Normals).Select((Func<Vector3, Vector3>)((Vector3 n) => new Vector3(n.X, n.Y, n.Z))).ToList()); val.SetUVs(0, ((IEnumerable<Vector2>)d.Uvs).Select((Func<Vector2, Vector2>)((Vector2 t) => new Vector2(t.X, t.Y))).ToList()); val.subMeshCount = 4; for (int num = 0; num < 4; num++) { val.SetTriangles(d.Triangles[num], num); } val.RecalculateBounds(); val.RecalculateTangents(); return val; } private static Texture2D MakeTexture(string name, int width, int height, byte[] raw, TextureWrapMode wrap) { //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) //IL_0011: Expected O, but got Unknown //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(width, height, (TextureFormat)4, true) { name = name }; ((Texture)val).wrapMode = wrap; ((Texture)val).filterMode = (FilterMode)2; ((Texture)val).anisoLevel = 4; Color32[] array = (Color32[])(object)new Color32[width * height]; for (int i = 0; i < array.Length; i++) { array[i] = new Color32(raw[i * 4], raw[i * 4 + 1], raw[i * 4 + 2], raw[i * 4 + 3]); } val.SetPixels32(array, 0); val.Apply(true, false); return val; } public static void SetRawValues(Item item, PartConfig cfg, float multiplier) { if (multiplier <= 0.0001f) { multiplier = 0.4f; } int num = Mathf.Max(1, cfg.MinValue.Value); int num2 = Mathf.Max(num, cfg.MaxValue.Value); item.minValue = Mathf.CeilToInt((float)num / multiplier); item.maxValue = Mathf.FloorToInt(((float)num2 + 0.999f) / multiplier) + 1; if (item.maxValue <= item.minValue) { item.maxValue = item.minValue + 1; } } public static void ApplyValueMultiplier(float multiplier) { foreach (Entry entry in Entries) { SetRawValues(entry.Item, entry.Cfg, multiplier); } } public static void OnStartOfRoundAwake(StartOfRound round) { EnsureMaterials(round); foreach (Entry entry in Entries) { MeshRenderer[] componentsInChildren = entry.Prefab.GetComponentsInChildren<MeshRenderer>(true); foreach (MeshRenderer val in componentsInChildren) { if (!((Object)(object)((Component)val).GetComponent<ScanNodeProperties>() != (Object)null)) { ((Renderer)val).sharedMaterials = (Material[])(object)((!((Object)((Component)val).gameObject).name.StartsWith("Bulb")) ? new Material[4] { woodMaterial, steelMaterial, bootMaterial, faceMaterial } : new Material[1] { glowMaterial }); } } } ApplyMixerGroup(round); if (templatesApplied) { return; } List<Item> list = round?.allItemsList?.itemsList; if (list == null) { return; } foreach (Entry entry2 in Entries) { ApplyTemplate(entry2, list); } templatesApplied = true; } private static void ApplyTemplate(Entry e, List<Item> all) { string[] obj = (e.Def.TwoHanded ? TwoHandTemplates : OneHandTemplates); Item val = null; string[] array = obj; foreach (string n in array) { val = ((IEnumerable<Item>)all).FirstOrDefault((Func<Item, bool>)((Item val2) => (Object)(object)val2 != (Object)null && val2.itemName == n && val2.twoHanded == e.Def.TwoHanded)); if ((Object)(object)val != (Object)null) { break; } } if ((Object)(object)val == (Object)null) { val = ((IEnumerable<Item>)all).FirstOrDefault((Func<Item, bool>)((Item val2) => (Object)(object)val2 != (Object)null && val2.isScrap && val2.twoHanded == e.Def.TwoHanded && (Object)(object)val2.grabSFX != (Object)null && (Object)(object)val2.itemIcon != (Object)null)); } if ((Object)(object)val == (Object)null) { val = ((IEnumerable<Item>)all).FirstOrDefault((Func<Item, bool>)((Item val2) => (Object)(object)val2 != (Object)null && val2.isScrap && (Object)(object)val2.itemIcon != (Object)null)); } if ((Object)(object)val == (Object)null) { Plugin.Log.LogWarning((object)("No vanilla template found for " + e.Def.ItemName + "; it will have no sounds or icon.")); return; } Item item = e.Item; item.grabSFX = val.grabSFX; item.dropSFX = val.dropSFX; item.pocketSFX = val.pocketSFX; item.throwSFX = val.throwSFX; item.itemIcon = val.itemIcon; if (e.Def.TwoHanded) { if (!string.IsNullOrEmpty(val.grabAnim)) { item.grabAnim = val.grabAnim; } item.grabAnimationTime = val.grabAnimationTime; } Plugin.Log.LogInfo((object)(e.Def.ItemName + ": sounds and icon from '" + val.itemName + "'.")); } private static void EnsureMaterials(StartOfRound round) { //IL_0050: 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_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_020a: Unknown result type (might be due to invalid IL or missing references) //IL_021a: Unknown result type (might be due to invalid IL or missing references) //IL_0281: Unknown result type (might be due to invalid IL or missing references) //IL_028b: Unknown result type (might be due to invalid IL or missing references) //IL_0290: Unknown result type (might be due to invalid IL or missing references) //IL_02a3: Unknown result type (might be due to invalid IL or missing references) //IL_02b4: Unknown result type (might be due to invalid IL or missing references) //IL_030b: Unknown result type (might be due to invalid IL or missing references) //IL_0315: Unknown result type (might be due to invalid IL or missing references) //IL_031a: Unknown result type (might be due to invalid IL or missing references) //IL_0326: Unknown result type (might be due to invalid IL or missing references) //IL_0337: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)woodMaterial != (Object)null) || !((Object)(object)glowMaterial != (Object)null) || !((Object)(object)faceMaterial != (Object)null)) { Material val = FindVanillaLitMaterial(round); Shader lit = Shader.Find("HDRP/Lit"); woodMaterial = MakeMaterial(val, lit, "WoodenDollWood"); woodMaterial.color = Color.white; SetIfPresent(woodMaterial, "_BaseColor", Color.white); SetTexIfPresent(woodMaterial, "_BaseColorMap", (Texture)(object)woodTexture); SetTexIfPresent(woodMaterial, "_MainTex", (Texture)(object)woodTexture); SetFloatIfPresent(woodMaterial, "_Smoothness", 0.48f); SetFloatIfPresent(woodMaterial, "_Metallic", 0f); steelMaterial = MakeMaterial(val, lit, "WoodenDollSteel"); Color val2 = default(Color); ((Color)(ref val2))..ctor(0.16f, 0.16f, 0.17f, 1f); steelMaterial.color = val2; SetIfPresent(steelMaterial, "_BaseColor", val2); SetTexIfPresent(steelMaterial, "_BaseColorMap", (Texture)(object)Texture2D.whiteTexture); SetTexIfPresent(steelMaterial, "_MainTex", (Texture)(object)Texture2D.whiteTexture); SetFloatIfPresent(steelMaterial, "_Smoothness", 0.62f); SetFloatIfPresent(steelMaterial, "_Metallic", 0.9f); faceMaterial = MakeMaterial(val, lit, "WoodenDollFace"); faceMaterial.color = Color.white; SetIfPresent(faceMaterial, "_BaseColor", Color.white); SetTexIfPresent(faceMaterial, "_BaseColorMap", (Texture)(object)faceTexture); SetTexIfPresent(faceMaterial, "_MainTex", (Texture)(object)faceTexture); SetFloatIfPresent(faceMaterial, "_Smoothness", 0.48f); SetFloatIfPresent(faceMaterial, "_Metallic", 0f); bootMaterial = MakeMaterial(val, lit, "WoodenDollBoot"); Color val3 = default(Color); ((Color)(ref val3))..ctor(0.3f, 0.17f, 0.11f, 1f); bootMaterial.color = val3; SetIfPresent(bootMaterial, "_BaseColor", val3); SetTexIfPresent(bootMaterial, "_BaseColorMap", (Texture)(object)Texture2D.whiteTexture); SetTexIfPresent(bootMaterial, "_MainTex", (Texture)(object)Texture2D.whiteTexture); SetFloatIfPresent(bootMaterial, "_Smoothness", 0.4f); SetFloatIfPresent(bootMaterial, "_Metallic", 0f); glowMaterial = MakeMaterial(val, lit, "PulsatingRodGlow"); Color val4 = RodPulse.GlowColor * 0.35f; val4.a = 1f; glowMaterial.color = val4; SetIfPresent(glowMaterial, "_BaseColor", val4); SetTexIfPresent(glowMaterial, "_BaseColorMap", (Texture)(object)Texture2D.whiteTexture); SetTexIfPresent(glowMaterial, "_MainTex", (Texture)(object)Texture2D.whiteTexture); SetFloatIfPresent(glowMaterial, "_Smoothness", 0.85f); SetFloatIfPresent(glowMaterial, "_Metallic", 0f); Color c = RodPulse.GlowColor * RodPulse.GlowIntensity; SetIfPresent(glowMaterial, "_EmissiveColor", c); SetIfPresent(glowMaterial, "_EmissionColor", c); glowMaterial.EnableKeyword("_EMISSION"); RodPulse.SharedGlow = glowMaterial; Plugin.Log.LogInfo((object)("Materials use shader '" + ((Object)woodMaterial.shader).name + "'" + (((Object)(object)val != (Object)null) ? (" (copied from '" + ((Object)val).name + "').") : "."))); } } private static Material MakeMaterial(Material source, Shader lit, string name) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Expected O, but got Unknown //IL_0049: 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_009c: Expected O, but got Unknown //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Expected O, but got Unknown Material val; if (!((Object)(object)source != (Object)null)) { val = ((!((Object)(object)lit != (Object)null)) ? new Material(Shader.Find("Standard") ?? Shader.Find("Hidden/InternalErrorShader")) : new Material(lit)); } else { val = new Material(source); SetTexIfPresent(val, "_NormalMap", null); SetTexIfPresent(val, "_MaskMap", null); SetTexIfPresent(val, "_DetailMap", null); SetTexIfPresent(val, "_EmissiveColorMap", null); SetIfPresent(val, "_EmissiveColor", Color.black); val.DisableKeyword("_NORMALMAP"); val.DisableKeyword("_NORMALMAP_TANGENT_SPACE"); val.DisableKeyword("_MASKMAP"); val.DisableKeyword("_DETAIL_MAP"); val.DisableKeyword("_EMISSIVE_COLOR_MAP"); } ((Object)val).name = name; return val; } private static Material FindVanillaLitMaterial(StartOfRound round) { List<Item> list = round?.allItemsList?.itemsList; if (list == null) { return null; } foreach (Item item in list) { if ((Object)(object)item == (Object)null || (Object)(object)item.spawnPrefab == (Object)null) { continue; } MeshRenderer[] componentsInChildren = item.spawnPrefab.GetComponentsInChildren<MeshRenderer>(true); for (int i = 0; i < componentsInChildren.Length; i++) { Material[] sharedMaterials = ((Renderer)componentsInChildren[i]).sharedMaterials; foreach (Material val in sharedMaterials) { if (!((Object)(object)val == (Object)null) && !((Object)(object)val.shader == (Object)null) && !(((Object)val.shader).name != "HDRP/Lit") && (!val.HasProperty("_SurfaceType") || !(val.GetFloat("_SurfaceType") > 0.5f))) { return val; } } } } return null; } private static void ApplyMixerGroup(StartOfRound round) { List<Item> list = round?.allItemsList?.itemsList; if (list == null) { return; } AudioMixerGroup val = null; foreach (Item item in list) { AudioSource val2 = (((Object)(object)item?.spawnPrefab != (Object)null) ? item.spawnPrefab.GetComponent<AudioSource>() : null); if ((Object)(object)val2 != (Object)null && (Object)(object)val2.outputAudioMixerGroup != (Object)null) { val = val2.outputAudioMixerGroup; break; } } if ((Object)(object)val == (Object)null) { return; } foreach (Entry entry in Entries) { AudioSource[] componentsInChildren = entry.Prefab.GetComponentsInChildren<AudioSource>(true); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].outputAudioMixerGroup = val; } } } private static void SetIfPresent(Material m, string prop, Color c) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) if (m.HasProperty(prop)) { m.SetColor(prop, c); } } private static void SetFloatIfPresent(Material m, string prop, float f) { if (m.HasProperty(prop)) { m.SetFloat(prop, f); } } private static void SetTexIfPresent(Material m, string prop, Texture t) { if (m.HasProperty(prop)) { m.SetTexture(prop, t); } } } internal sealed class PartDefinition { public DollPart Part; public string ItemName; public string PrefabName; public bool TwoHanded; public Vector3 RestingRotation; public float DefaultWeightLb; public int DefaultRarity; public static readonly PartDefinition[] All = new PartDefinition[5] { new PartDefinition { Part = DollPart.Head, ItemName = "Wooden doll head", PrefabName = "WoodenDollHead", TwoHanded = false, RestingRotation = new Vector3(0f, 0f, 0f), DefaultWeightLb = 8f, DefaultRarity = 20 }, new PartDefinition { Part = DollPart.Arm, ItemName = "Wooden doll arm", PrefabName = "WoodenDollArm", TwoHanded = false, RestingRotation = new Vector3(0f, 0f, 90f), DefaultWeightLb = 10f, DefaultRarity = 20 }, new PartDefinition { Part = DollPart.Leg, ItemName = "Wooden doll leg", PrefabName = "WoodenDollLeg", TwoHanded = false, RestingRotation = new Vector3(0f, 0f, 90f), DefaultWeightLb = 14f, DefaultRarity = 20 }, new PartDefinition { Part = DollPart.Torso, ItemName = "Wooden doll torso", PrefabName = "WoodenDollTorso", TwoHanded = true, RestingRotation = new Vector3(0f, 0f, 0f), DefaultWeightLb = 24f, DefaultRarity = 15 }, new PartDefinition { Part = DollPart.Rod, ItemName = "The pulsating Rod", PrefabName = "PulsatingRod", TwoHanded = false, RestingRotation = new Vector3(90f, 0f, 0f), DefaultWeightLb = 12f, DefaultRarity = 10 } }; } [BepInPlugin("sara.woodendollscrap", "WoodenDollScrap", "1.2.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public const string Guid = "sara.woodendollscrap"; public const string Name = "WoodenDollScrap"; public const string Version = "1.2.0"; internal static ManualLogSource Log; internal static DollConfig Settings; private void Awake() { //IL_002a: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; Settings = new DollConfig(((BaseUnityPlugin)this).Config); try { DollContent.Register(Settings); new Harmony("sara.woodendollscrap").PatchAll(typeof(Patches)); Log.LogInfo((object)"WoodenDollScrap 1.2.0 loaded: wooden doll parts added as scrap."); } catch (Exception arg) { Log.LogError((object)string.Format("{0} failed to load: {1}", "WoodenDollScrap", arg)); } } } internal static class Patches { [HarmonyPatch(typeof(StartOfRound), "Awake")] [HarmonyPostfix] private static void StartOfRoundAwake(StartOfRound __instance) { try { DollContent.OnStartOfRoundAwake(__instance); } catch (Exception arg) { Plugin.Log.LogError((object)$"Setup in StartOfRound.Awake failed: {arg}"); } } [HarmonyPatch(typeof(RoundManager), "SpawnScrapInLevel")] [HarmonyPrefix] private static void SpawnScrapPrefix(RoundManager __instance) { try { DollContent.ApplyValueMultiplier(__instance.scrapValueMultiplier); } catch (Exception arg) { Plugin.Log.LogError((object)$"Value scaling failed: {arg}"); } } } public class RodPulse : MonoBehaviour { public Transform[] Bulbs; public Renderer[] BulbRenderers; public AudioSource Hum; public GrabbableObject Prop; internal static Material SharedGlow; internal static Color GlowColor = new Color(0.3f, 1f, 0.62f); internal static float GlowIntensity = 10f; internal static float HumVolume = 0.35f; private const float BeatsPerSecond = 1.15f; private const float WaveDelay = 0.22f; private const float Swell = 0.08f; private Material[] instances; private Vector3[] baseScales; private float phase; private void Start() { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) phase = Random.value * 10f; baseScales = (Vector3[])(object)new Vector3[Bulbs.Length]; for (int i = 0; i < Bulbs.Length; i++) { baseScales[i] = Bulbs[i].localScale; } if ((Object)(object)Hum != (Object)null && (Object)(object)Hum.clip != (Object)null) { Hum.time = Random.value * Hum.clip.length * 0.9f; Hum.volume = 0f; } } private void Update() { //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0074: 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_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: 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) if (instances == null && (Object)(object)SharedGlow != (Object)null) { CreateInstances(); } float num = Time.time * 1.15f + phase; float num2 = 0f; for (int i = 0; i < Bulbs.Length; i++) { float num3 = Beat(num - (float)i * 0.22f); num2 = Mathf.Max(num2, num3); Bulbs[i].localScale = baseScales[i] * (1f + 0.08f * num3); if (instances != null) { Color val = GlowColor * (GlowIntensity * (0.25f + 0.75f * num3)); instances[i].SetColor("_EmissiveColor", val); instances[i].SetColor("_EmissionColor", val); } } if ((Object)(object)Hum == (Object)null) { return; } if (!(HumVolume > 0f) || (!((Object)(object)Prop == (Object)null) && (Prop.isPocketed || Prop.deactivated))) { if (Hum.isPlaying) { Hum.Pause(); } return; } if (!Hum.isPlaying) { Hum.Play(); } Hum.volume = HumVolume * (0.45f + 0.55f * num2); Hum.pitch = 0.96f + 0.08f * num2; } private void CreateInstances() { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown instances = (Material[])(object)new Material[BulbRenderers.Length]; for (int i = 0; i < BulbRenderers.Length; i++) { instances[i] = new Material(SharedGlow); BulbRenderers[i].sharedMaterial = instances[i]; } } private static float Beat(float t) { float num = t - Mathf.Floor(t); float num2 = Mathf.Exp(0f - Sq((num - 0.1f) / 0.06f)); float num3 = 0.6f * Mathf.Exp(0f - Sq((num - 0.32f) / 0.07f)); return Mathf.Clamp01(num2 + num3); } private static float Sq(float x) { return x * x; } private void OnDestroy() { if (instances == null) { return; } Material[] array = instances; foreach (Material val in array) { if ((Object)(object)val != (Object)null) { Object.Destroy((Object)(object)val); } } } } } namespace WoodenDollScrap.Geometry { public enum DollPart { Head, Arm, Leg, Torso, Rod } public static class DollGeometry { private const int Seg = 28; private const int SegSmall = 14; public static readonly Vector3[] RodBulbs = new Vector3[3] { new Vector3(0f, -0.21f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0.21f, 0f) }; public static MeshData Build(DollPart part) { Vector3 centreOffset; return Build(part, out centreOffset); } public static MeshData Build(DollPart part, out Vector3 centreOffset) { MeshData meshData = new MeshData(); switch (part) { case DollPart.Head: BuildHead(meshData); break; case DollPart.Arm: BuildArm(meshData); break; case DollPart.Leg: BuildLeg(meshData); break; case DollPart.Torso: BuildTorso(meshData); break; case DollPart.Rod: BuildRodShaft(meshData); break; } meshData.Bounds(out var min, out var max); centreOffset = -(min + max) * 0.5f; meshData.Translate(centreOffset); return meshData; } private static void BuildHead(MeshData m) { Ellipsoid(m, new Vector3(0f, 0f, 0f), FaceLayout.HeadRadii, 48); Segment(m, 0, new Vector3(0f, -0.215f, 0f), new Vector3(0f, -0.16f, 0f), 0.062f, 0.062f, 0.006f, 0f, 28); Pin(m, new Vector3(0f, -0.19f, 0.058f), Vector3.UnitZ, 0.013f); BuildFacePatch(m); BuildNose(m); } private static void BuildFacePatch(MeshData m) { float num = 0f - FaceLayout.HalfWidth; float halfWidth = FaceLayout.HalfWidth; float bottomY = FaceLayout.BottomY; float topY = FaceLayout.TopY; int count = m.Positions.Count; for (int i = 0; i <= 80; i++) { float y = bottomY + (topY - bottomY) * (float)i / 80f; for (int j = 0; j <= 96; j++) { float x = num + (halfWidth - num) * (float)j / 96f; Vector3 normal; Vector3 vector = FaceLayout.Surface(x, y, out normal); m.AddVertex(vector + normal * 0.0006f, normal, FaceLayout.FaceUv(x, y)); } } for (int k = 0; k < 80; k++) { for (int l = 0; l < 96; l++) { float x2 = num + (halfWidth - num) * ((float)l + 0.5f) / 96f; float y2 = bottomY + (topY - bottomY) * ((float)k + 0.5f) / 80f; if (!(FaceLayout.Depth(x2, y2) < 0.3f)) { int num2 = count + k * 97 + l; int b = num2 + 1; int num3 = num2 + 96 + 1; int num4 = num3 + 1; m.AddTriangleFacingNormals(3, num2, b, num4); m.AddTriangleFacingNormals(3, num2, num4, num3); } } } } private static void BuildNose(MeshData m) { Vector2 vector = FaceLayout.ImageToHead(887f, 380f); Vector2 vector2 = FaceLayout.ImageToHead(887f, 672f); float num = 0.010146562f; float num2 = 0.033483654f; float num3 = 0.0036527622f; float num4 = 0.028410371f; Vector3 normal; float z = FaceLayout.Surface(0f, vector.Y, out normal).Z; float z2 = FaceLayout.Surface(0f, vector2.Y, out normal).Z; float sizeFactor = FaceLayout.SizeFactor; float num5 = 0.008f * sizeFactor; float num6 = 0.007f * sizeFactor; float num7 = 0.026f * sizeFactor; float num8 = vector2.Y + 0.004f * sizeFactor; Vector3 vector3 = new Vector3(0f - num2, vector2.Y, z2 - num5); Vector3 vector4 = new Vector3(num2, vector2.Y, z2 - num5); Vector3 vector5 = new Vector3(num, vector.Y, z - num5); Vector3 vector6 = new Vector3(0f - num, vector.Y, z - num5); Vector3 vector7 = new Vector3(0f - num4, num8, z2 + num7); Vector3 vector8 = new Vector3(num4, num8, z2 + num7); Vector3 vector9 = new Vector3(num3, vector.Y - 0.001f, z + num6); Vector3 vector10 = new Vector3(0f - num3, vector.Y - 0.001f, z + num6); Vector3 vector11 = new Vector3((0f - num4) * 0.96f, num8 - 0.005f * sizeFactor, z2 + num7 - 0.004f * sizeFactor); Vector3 vector12 = new Vector3(num4 * 0.96f, num8 - 0.005f * sizeFactor, z2 + num7 - 0.004f * sizeFactor); Vector3 interior = (vector3 + vector4 + vector5 + vector6) * 0.25f + new Vector3(0f, 0f, 0.004f); m.AddFlatPolygon(0, new Vector3[4] { vector7, vector8, vector9, vector10 }, Uv, interior); m.AddFlatPolygon(0, new Vector3[4] { vector3, vector7, vector10, vector6 }, Uv, interior); m.AddFlatPolygon(0, new Vector3[4] { vector4, vector5, vector9, vector8 }, Uv, interior); m.AddFlatPolygon(0, new Vector3[4] { vector6, vector10, vector9, vector5 }, Uv, interior); m.AddFlatPolygon(0, new Vector3[4] { vector7, vector11, vector12, vector8 }, Uv, interior); m.AddFlatPolygon(0, new Vector3[4] { vector11, vector3, vector4, vector12 }, Uv, interior); m.AddFlatPolygon(0, new Vector3[3] { vector3, vector11, vector7 }, Uv, interior); m.AddFlatPolygon(0, new Vector3[3] { vector4, vector8, vector12 }, Uv, interior); static Vector2 Uv(Vector3 p) { Vector3 normal2; return FaceLayout.HeadWoodUv(FaceLayout.Surface(p.X, p.Y, out normal2)); } } private static void BuildArm(MeshData m) { Vector3 unitX = Vector3.UnitX; Vector3 zero = Vector3.Zero; BallJoint(m, zero, 0.068f, unitX); Vector3 vector = -Vector3.UnitY; Vector3 a = zero + vector * 0.05f; Vector3 vector2 = zero + vector * 0.19f; Vector3 b = zero + vector * 0.325f; Segment(m, 0, a, vector2 - vector * 0.002f, 0.06f, 0.059f, 0.012f, 0.002f, 28); Segment(m, 0, vector2 + vector * 0.002f, b, 0.059f, 0.054f, 0.012f, 0.002f, 28); Vector3 vector3 = zero + vector * 0.365f; BallJoint(m, vector3, 0.052f, unitX); float x = Deg(55f); Vector3 vector4 = Vector3.Normalize(new Vector3(0f, 0f - MathF.Cos(x), MathF.Sin(x))); Segment(m, 0, vector3 + vector4 * 0.035f, vector3 + vector4 * 0.285f, 0.055f, 0.045f, 0.012f, 0.003f, 28); Vector3 vector5 = vector3 + vector4 * 0.315f; Sphere(m, vector5, 0.034f, 14); Pin(m, vector5 + unitX * 0.033f, unitX, 0.009f); Pin(m, vector5 - unitX * 0.033f, -unitX, 0.009f); Vector3 vector6 = Vector3.Normalize(Vector3.Cross(unitX, vector4)); Vector3 vector7 = vector5 + vector4 * 0.092f; OrientedEllipsoid(m, vector7, unitX, vector4, vector6, new Vector3(0.026f, 0.07f, 0.054f), 28); float[] array = new float[3] { 0.048f, 0.038f, 0.031f }; float[] array2 = new float[4] { -0.036f, -0.012f, 0.012f, 0.036f }; float[] array3 = new float[4] { 0.86f, 1f, 0.97f, 0.9f }; for (int i = 0; i < 4; i++) { Vector3 vector8 = vector7 + vector4 * 0.052f + vector6 * array2[i] * 0.95f; Vector3 vector9 = Vector3.Normalize(vector4 + vector6 * array2[i] * 1.1f); float num = 0.012f; for (int j = 0; j < 3; j++) { float num2 = array[j] * array3[i]; Vector3 vector10 = vector8 + vector9 * num2; Segment(m, 0, vector8, vector10, num, num * 0.93f, num * 0.6f, 0f, 14); vector8 = vector10 - vector9 * 0.004f; num *= 0.93f; vector9 = Vector3.Normalize(Rotate(vector9, vector6, Deg(13f))); } } Vector3 vector11 = vector7 - vector6 * 0.036f - vector4 * 0.01f; Vector3 vector12 = Vector3.Normalize(vector4 * 0.9f - vector6 * 0.75f - unitX * 0.25f); float num3 = 0.013f; for (int k = 0; k < 2; k++) { Vector3 vector13 = vector11 + vector12 * ((k == 0) ? 0.042f : 0.034f); Segment(m, 0, vector11, vector13, num3, num3 * 0.93f, num3 * 0.6f, 0f, 14); vector11 = vector13 - vector12 * 0.004f; num3 *= 0.93f; vector12 = Vector3.Normalize(Rotate(vector12, unitX, Deg(-15f))); } } private static void BuildLeg(MeshData m) { Vector3 unitX = Vector3.UnitX; Vector3 zero = Vector3.Zero; BallJoint(m, zero, 0.082f, unitX); Vector3 vector = -Vector3.UnitY; Vector3 a = zero + vector * 0.062f; Vector3 vector2 = zero + vector * 0.235f; Vector3 b = zero + vector * 0.41f; Segment(m, 0, a, vector2 - vector * 0.002f, 0.076f, 0.075f, 0.016f, 0.003f, 28); Segment(m, 0, vector2 + vector * 0.002f, b, 0.075f, 0.068f, 0.016f, 0.003f, 28); Vector3 vector3 = zero + vector * 0.462f; BallJoint(m, vector3, 0.066f, unitX); float x = Deg(70f); Vector3 vector4 = Vector3.Normalize(new Vector3(0f, 0f - MathF.Cos(x), 0f - MathF.Sin(x))); Vector3 a2 = vector3 + vector4 * 0.05f; Vector3 vector5 = vector3 + vector4 * 0.41f; Segment(m, 0, a2, vector5, 0.068f, 0.046f, 0.01f, 0.002f, 28); Vector3 vector6 = Vector3.Normalize(new Vector3(0f, 0f - MathF.Sin(x), MathF.Cos(x))); Vector3 vector7 = vector5 + vector4 * 0.012f; Segment(m, 2, vector5 - vector4 * 0.042f, vector7, 0.075f, 0.075f, 0.012f, 0f, 28); Vector3 vector8 = vector7 + vector4 * 0.062f; Vector3 a3 = vector8 - vector6 * 0.085f; Vector3 b2 = vector8 + vector6 * 0.2f; FlatSegment(m, 2, a3, b2, unitX, 0.086f, 0.078f, 0.066f, 0.78f); } private static void BuildTorso(MeshData m) { Ellipsoid(m, new Vector3(0f, 0.12f, 0f), new Vector3(0.205f, 0.165f, 0.14f), 28); Ellipsoid(m, new Vector3(0f, -0.11f, 0.005f), new Vector3(0.175f, 0.15f, 0.128f), 28); Segment(m, 0, new Vector3(0f, 0.265f, 0f), new Vector3(0f, 0.305f, 0f), 0.058f, 0.056f, 0.008f, 0f, 28); Segment(m, 0, new Vector3(0f, 0.3f, 0f), new Vector3(0f, 0.375f, 0f), 0.03f, 0.028f, 0.008f, 0f, 28); float[] array = new float[2] { 1f, -1f }; foreach (float num in array) { Vector3 c = new Vector3(num * 0.205f, 0.175f, 0f); Vector3 axis = new Vector3(num, 0f, 0f); Torus(m, c, axis, 0.05f, 0.019f); } array = new float[2] { 1f, -1f }; foreach (float num2 in array) { Vector3 vector = new Vector3(num2 * 0.085f, -0.245f, 0.035f); Segment(m, 0, vector - Vector3.UnitZ * 0.028f, vector + Vector3.UnitZ * 0.028f, 0.05f, 0.05f, 0.01f, 0f, 28); Segment(m, 1, vector + Vector3.UnitZ * 0.02f, vector + Vector3.UnitZ * 0.034f, 0.021f, 0.021f, 0.004f, 0f, 14); } } private static void BuildRodShaft(MeshData m) { Segment(m, 1, new Vector3(0f, -0.375f, 0f), new Vector3(0f, 0.375f, 0f), 0.02f, 0.02f, 0.004f, 0f, 28); float[] array = new float[2] { -1f, 1f }; foreach (float num in array) { Vector3 vector = new Vector3(0f, num * 0.36f, 0f); Ellipsoid(m, vector, new Vector3(0.05f, 0.042f, 0.05f), 28); Pin(m, vector + new Vector3(0f, num * 0.04f, 0f), new Vector3(0f, num, 0f), 0.02f); } Vector3[] rodBulbs = RodBulbs; foreach (Vector3 vector2 in rodBulbs) { Torus(m, vector2 + new Vector3(0f, -0.066f, 0f), Vector3.UnitY, 0.03f, 0.01f); Torus(m, vector2 + new Vector3(0f, 0.066f, 0f), Vector3.UnitY, 0.03f, 0.01f); } } public static MeshData BuildRodBulb() { MeshData meshData = new MeshData(); List<Vector2> list = new List<Vector2>(); for (int i = 0; i <= 28; i++) { float x = -MathF.PI / 2f + MathF.PI * (float)i / 28f; float num = 1f + 0.07f * MathF.Sin((float)i * MathF.PI * 6f / 28f) * MathF.Cos(x); list.Add(new Vector2(0.062f * MathF.Sin(x), MathF.Max(0f, 0.044f * MathF.Cos(x) * num))); } meshData.Lathe(0, list, 28, Matrix4x4.Identity); return meshData; } private static float Deg(float d) { return d * MathF.PI / 180f; } private static Vector3 Rotate(Vector3 v, Vector3 axis, float angle) { return Vector3.Transform(v, Quaternion.CreateFromAxisAngle(Vector3.Normalize(axis), angle)); } private static Quaternion FromY(Vector3 dir) { dir = Vector3.Normalize(dir); float num = Vector3.Dot(Vector3.UnitY, dir); if (num > 0.99999f) { return Quaternion.Identity; } if (num < -0.99999f) { return Quaternion.CreateFromAxisAngle(Vector3.UnitX, MathF.PI); } return Quaternion.CreateFromAxisAngle(Vector3.Normalize(Vector3.Cross(Vector3.UnitY, dir)), MathF.Acos(num)); } private static void BallJoint(MeshData m, Vector3 c, float r, Vector3 side) { Sphere(m, c, r, 28); Pin(m, c + side * (r * 0.97f), side, r * 0.2f); Pin(m, c - side * (r * 0.97f), -side, r * 0.2f); } private static void Pin(MeshData m, Vector3 centre, Vector3 outward, float r) { outward = Vector3.Normalize(outward); Segment(m, 1, centre - outward * 0.006f, centre + outward * 0.005f, r, r, r * 0.35f, 0f, 14); } private static void Sphere(MeshData m, Vector3 c, float r, int seg) { Ellipsoid(m, c, new Vector3(r), seg); } private static void Ellipsoid(MeshData m, Vector3 c, Vector3 radii, int seg) { Matrix4x4 xf = Matrix4x4.CreateScale(radii) * Matrix4x4.CreateTranslation(c); m.Lathe(0, SphereProfile(seg / 2), seg, xf, 0.6f / radii.Y); } private static void OrientedEllipsoid(MeshData m, Vector3 c, Vector3 ax, Vector3 ay, Vector3 az, Vector3 radii, int seg) { Matrix4x4 matrix4x = new Matrix4x4(ax.X, ax.Y, ax.Z, 0f, ay.X, ay.Y, ay.Z, 0f, az.X, az.Y, az.Z, 0f, 0f, 0f, 0f, 1f); if (matrix4x.GetDeterminant() < 0f) { matrix4x = new Matrix4x4(0f - ax.X, 0f - ax.Y, 0f - ax.Z, 0f, ay.X, ay.Y, ay.Z, 0f, az.X, az.Y, az.Z, 0f, 0f, 0f, 0f, 1f); } Matrix4x4 xf = Matrix4x4.CreateScale(radii) * matrix4x * Matrix4x4.CreateTranslation(c); m.Lathe(0, SphereProfile(seg / 2), seg, xf, 0.6f / radii.Y); } private static void Segment(MeshData m, int sub, Vector3 a, Vector3 b, float r0, float r1, float fillet, float bulge, int seg) { float len = Vector3.Distance(a, b); Matrix4x4 xf = Matrix4x4.CreateFromQuaternion(FromY(b - a)) * Matrix4x4.CreateTranslation(a); m.Lathe(sub, SegmentProfile(len, r0, r1, fillet, bulge), seg, xf); } private static void FlatSegment(MeshData m, int sub, Vector3 a, Vector3 b, Vector3 side, float r0, float r1, float fillet, float flatten) { float len = Vector3.Distance(a, b); Vector3 vector = Vector3.Normalize(b - a); side = Vector3.Normalize(side - vector * Vector3.Dot(side, vector)); Vector3 vector2 = Vector3.Normalize(Vector3.Cross(side, vector)); Matrix4x4 matrix4x = new Matrix4x4(side.X, side.Y, side.Z, 0f, vector.X, vector.Y, vector.Z, 0f, vector2.X, vector2.Y, vector2.Z, 0f, 0f, 0f, 0f, 1f); Matrix4x4 xf = Matrix4x4.CreateScale(1f, 1f, flatten) * matrix4x * Matrix4x4.CreateTranslation(a); m.Lathe(sub, SegmentProfile(len, r0, r1, fillet, 0.004f), 28, xf); } private static void Torus(MeshData m, Vector3 c, Vector3 axis, float major, float minor) { List<Vector2> list = new List<Vector2>(); int num = 16; for (int i = 0; i <= num; i++) { float x = MathF.PI * 2f * (float)i / (float)num; list.Add(new Vector2((0f - minor) * MathF.Sin(x), major - minor * MathF.Cos(x))); } Matrix4x4 xf = Matrix4x4.CreateFromQuaternion(FromY(axis)) * Matrix4x4.CreateTranslation(c); m.Lathe(0, list, 28, xf); } private static List<Vector2> SphereProfile(int rings) { List<Vector2> list = new List<Vector2>(); for (int i = 0; i <= rings; i++) { float x = -MathF.PI / 2f + MathF.PI * (float)i / (float)rings; list.Add(new Vector2(MathF.Sin(x), MathF.Max(MathF.Cos(x), 0f))); } return list; } private static List<Vector2> SegmentProfile(float len, float r0, float r1, float fillet, float bulge) { fillet = MathF.Min(fillet, MathF.Min(MathF.Min(r0, r1) * 0.95f, len * 0.45f)); List<Vector2> list = new List<Vector2>(); list.Add(new Vector2(0f, 0f)); for (int i = 0; i <= 5; i++) { float x = MathF.PI / 2f * (float)i / 5f; list.Add(new Vector2(fillet - fillet * MathF.Cos(x), r0 - fillet + fillet * MathF.Sin(x))); } for (int j = 1; j < 8; j++) { float num = (float)j / 8f; float x2 = fillet + (len - 2f * fillet) * num; float y = r0 + (r1 - r0) * num + bulge * MathF.Sin(MathF.PI * num); list.Add(new Vector2(x2, y)); } for (int k = 0; k <= 5; k++) { float x3 = MathF.PI / 2f * (float)k / 5f; list.Add(new Vector2(len - fillet + fillet * MathF.Sin(x3), r1 - fillet + fillet * MathF.Cos(x3))); } list.Add(new Vector2(len, 0f)); return list; } } public static class FaceLayout { public static readonly Vector3 HeadRadii = new Vector3(0.17f, 0.18f, 0.168f); public const float ImageWidth = 1774f; public const float ImageHeight = 887f; public const float PatchImageHeight = 1300f; public const float PatchWidth = 0.36f; public const float MetresPerPixel = 0.00020293123f; public const float CentreY = 0.02f; public static float HalfWidth => 0.18f; public static float TopY => 0.11f; public static float BottomY => TopY - 0.2638106f; public static float SizeFactor => 1.3846155f; public static Vector2 ImageToHead(float px, float py) { return new Vector2((px - 887f) * 0.00020293123f, TopY - py * 0.00020293123f); } public static Vector3 Surface(float x, float y, out Vector3 normal) { Vector3 headRadii = HeadRadii; float x2 = 1f - x * x / (headRadii.X * headRadii.X) - y * y / (headRadii.Y * headRadii.Y); float num = headRadii.Z * MathF.Sqrt(MathF.Max(x2, 0.0004f)); Vector3 result = new Vector3(x, y, num); normal = Vector3.Normalize(new Vector3(x / (headRadii.X * headRadii.X), y / (headRadii.Y * headRadii.Y), num / (headRadii.Z * headRadii.Z))); return result; } public static Vector2 HeadWoodUv(Vector3 p) { Vector3 headRadii = HeadRadii; float x = p.X / headRadii.X; float x2 = Math.Clamp(p.Y / headRadii.Y, -1f, 1f); float num = MathF.Atan2(p.Z / headRadii.Z, x); if (num < 0f) { num += MathF.PI * 2f; } float num2 = MathF.Asin(x2); return new Vector2(num / (MathF.PI * 2f), (num2 + MathF.PI / 2f) * headRadii.Y / 0.6f); } public static float Depth(float x, float y) { Vector3 headRadii = HeadRadii; return 1f - x * x / (headRadii.X * headRadii.X) - y * y / (headRadii.Y * headRadii.Y); } public static Vector2 FaceUv(float x, float y) { return new Vector2((x + HalfWidth) / 0.36f, (y - BottomY) / (TopY - BottomY)); } } public static class FaceTexture { public const int Width = 1024; public static readonly int Height = (int)MathF.Round(750.3946f); private static readonly Vector3 Outline = new Vector3(0.16f, 0.07f, 0.035f); private static readonly Vector3 EyeWhite = new Vector3(0.95f, 0.95f, 0.97f); private static readonly Vector3 Pupil = new Vector3(0.43f, 0.05f, 0.03f); private static readonly Vector3 PupilEdge = new Vector3(0.3f, 0.03f, 0.02f); private const float LidY = 295f; private const float EyeRx = 297f; private const float EyeRy = 310f; private const float OutlineHalf = 6.5f; private static readonly float[] EyeCx = new float[2] { 510f, 1263f }; private static readonly float[] PupilCx = new float[2] { 537f, 1236f }; private const float PupilCy = 375f; private const float PupilR = 102f; private static readonly Vector2[,] Lines = new Vector2[2, 2] { { new Vector2(510f, 600f), new Vector2(574f, 1120f) }, { new Vector2(1263f, 600f), new Vector2(1199f, 1120f) } }; private const float LineHalf = 5f; private const float MouthCx = 887f; private const float MouthCy = 777f; private const float MouthHalfW = 132f; private const float MouthHalfH = 13f; public static byte[] GenerateRgba(byte[] woodRgba, int woodSize) { byte[] array = new byte[1024 * Height * 4]; for (int i = 0; i < Height; i++) { for (int j = 0; j < 1024; j++) { float num = ((float)j + 0.5f) / 1024f; float num2 = ((float)i + 0.5f) / (float)Height; Vector2 vector = FaceLayout.ImageToHead(num * 1774f, (1f - num2) * 1300f); Vector3 normal; Vector3 wood = SampleWood(woodRgba, woodSize, FaceLayout.HeadWoodUv(FaceLayout.Surface(vector.X, vector.Y, out normal))); Vector3 zero = Vector3.Zero; for (int k = 0; k < 3; k++) { for (int l = 0; l < 3; l++) { float num3 = ((float)j + ((float)l + 0.5f) / 3f) / 1024f; float num4 = ((float)i + ((float)k + 0.5f) / 3f) / (float)Height; float ix = num3 * 1774f; float iy = (1f - num4) * 1300f; zero += Shade(ix, iy, wood); } } zero /= 9f; int num5 = (i * 1024 + j) * 4; array[num5] = ToByte(zero.X); array[num5 + 1] = ToByte(zero.Y); array[num5 + 2] = ToByte(zero.Z); array[num5 + 3] = byte.MaxValue; } } return array; } private static Vector3 Shade(float ix, float iy, Vector3 wood) { Vector3 vector = wood; float num = Sq((ix - 887f) / 175f) + Sq((iy - 690f) / 34f); vector *= 1f - 0.22f * MathF.Exp((0f - num) * 1.6f); float num2 = RoundedRectSdf(ix - 887f, iy - 777f, 132f, 13f, 13f); if (num2 < 0f) { float x = (iy - 764f) / 26f; vector *= 0.5f + 0.3f * Smooth(0.15f, 1f, x); } else if (num2 < 4f && iy > 777f) { vector = Vector3.Lerp(vector, Vector3.Min(vector * 1.18f, Vector3.One), 1f - num2 / 4f); } for (int i = 0; i < 2; i++) { float num3 = SegmentDistance(new Vector2(ix, iy), Lines[i, 0], Lines[i, 1]); vector = Vector3.Lerp(vector, Outline, Coverage(num3 - 5f)); } for (int j = 0; j < 2; j++) { float num4 = ix - EyeCx[j]; float num5 = iy - 295f; float num6 = MathF.Max((MathF.Sqrt(Sq(num4 / 297f) + Sq(num5 / 310f)) - 1f) * 0.5f * 607f, 295f - iy); if (num6 < 7.5f) { Vector3 value = EyeWhite * (0.86f + 0.14f * Smooth(0f, 45f, iy - 295f)); float num7 = MathF.Max(Vector2.Distance(new Vector2(ix, iy), new Vector2(PupilCx[j], 375f)) - 102f, 295f - iy); Vector3 value2 = Vector3.Lerp(Pupil, PupilEdge, Smooth(-30f, 0f, num7)); Vector3 value3 = Vector3.Lerp(value, value2, Coverage(num7)); vector = Vector3.Lerp(vector, value3, Coverage(num6)); vector = Vector3.Lerp(vector, Outline, Coverage(MathF.Abs(num6) - 6.5f)); } } return vector; } private static Vector3 SampleWood(byte[] w, int size, Vector2 uv) { float num = (uv.X - MathF.Floor(uv.X)) * (float)size - 0.5f; float num2 = (uv.Y - MathF.Floor(uv.Y)) * (float)size - 0.5f; int num3 = (int)MathF.Floor(num); int num4 = (int)MathF.Floor(num2); float amount = num - (float)num3; float amount2 = num2 - (float)num4; Vector3 value = Vector3.Lerp(P(num3, num4), P(num3 + 1, num4), amount); Vector3 value2 = Vector3.Lerp(P(num3, num4 + 1), P(num3 + 1, num4 + 1), amount); return Vector3.Lerp(value, value2, amount2); Vector3 P(int xx, int yy) { xx = (xx % size + size) % size; yy = (yy % size + size) % size; int num5 = (yy * size + xx) * 4; return new Vector3((int)w[num5], (int)w[num5 + 1], (int)w[num5 + 2]) / 255f; } } private static float RoundedRectSdf(float x, float y, float hw, float hh, float r) { float x2 = MathF.Abs(x) - hw + r; float num = MathF.Abs(y) - hh + r; return MathF.Sqrt(Sq(MathF.Max(x2, 0f)) + Sq(MathF.Max(num, 0f))) + MathF.Min(MathF.Max(x2, num), 0f) - r; } private static float SegmentDistance(Vector2 p, Vector2 a, Vector2 b) { Vector2 vector = b - a; float num = Math.Clamp(Vector2.Dot(p - a, vector) / vector.LengthSquared(), 0f, 1f); return Vector2.Distance(p, a + vector * num); } private static float Coverage(float sdf) { return Math.Clamp(0.5f - sdf / 1.7f, 0f, 1f); } private static float Smooth(float e0, float e1, float x) { float num = Math.Clamp((x - e0) / (e1 - e0), 0f, 1f); return num * num * (3f - 2f * num); } private static float Sq(float x) { return x * x; } private static byte ToByte(float f) { return (byte)Math.Clamp((int)(f * 255f + 0.5f), 0, 255); } } public sealed class MeshData { public const int Wood = 0; public const int Steel = 1; public const int Boot = 2; public const int Face = 3; public const int SubmeshCount = 4; public readonly List<Vector3> Positions = new List<Vector3>(); public readonly List<Vector3> Normals = new List<Vector3>(); public readonly List<Vector2> Uvs = new List<Vector2>(); public readonly List<int>[] Triangles = new List<int>[4] { new List<int>(), new List<int>(), new List<int>(), new List<int>() }; public void Lathe(int submesh, IList<Vector2> profile, int segments, Matrix4x4 xf, float uvLength = 0.6f) { Matrix4x4.Invert(xf, out var result); Matrix4x4 matrix = Matrix4x4.Transpose(result); int num = segments + 1; int count = Positions.Count; float num2 = 0f; for (int i = 0; i < profile.Count; i++) { if (i > 0) { num2 += Vector2.Distance(profile[i], profile[i - 1]); } Vector2 vector = profile[Math.Max(i - 1, 0)]; Vector2 vector2 = profile[Math.Min(i + 1, profile.Count - 1)] - vector; Vector2 value = new Vector2(0f - vector2.Y, vector2.X); if (value.LengthSquared() < 1E-12f) { value = new Vector2(0f, 1f); } value = Vector2.Normalize(value); for (int j = 0; j <= segments; j++) { double num3 = Math.PI * 2.0 * (double)j / (double)segments; float num4 = (float)Math.Cos(num3); float num5 = (float)Math.Sin(num3); Vector3 position = new Vector3(profile[i].Y * num4, profile[i].X, profile[i].Y * num5); Vector3 normal = new Vector3(value.Y * num4, value.X, value.Y * num5); Positions.Add(Vector3.Transform(position, xf)); Normals.Add(Vector3.Normalize(Vector3.TransformNormal(normal, matrix))); Uvs.Add(new Vector2((float)j / (float)segments, num2 / uvLength)); } } List<int> list = Triangles[submesh]; for (int k = 0; k < profile.Count - 1; k++) { if (!(Vector2.DistanceSquared(profile[k], profile[k + 1]) < 1E-14f)) { for (int l = 0; l < segments; l++) { int num6 = count + k * num + l; int item = num6 + 1; int num7 = num6 + num; int item2 = num7 + 1; list.Add(num6); list.Add(num7); list.Add(item); list.Add(item); list.Add(num7); list.Add(item2); } } } } public int AddVertex(Vector3 p, Vector3 n, Vector2 uv) { Positions.Add(p); Normals.Add(Vector3.Normalize(n)); Uvs.Add(uv); return Positions.Count - 1; } public void AddTriangleFacingNormals(int submesh, int a, int b, int c) { Vector3 vector = Vector3.Cross(Positions[b] - Positions[a], Positions[c] - Positions[a]); Vector3 vector2 = Normals[a] + Normals[b] + Normals[c]; List<int> list = Triangles[submesh]; if (Vector3.Dot(vector, vector2) >= 0f) { list.Add(a); list.Add(b); list.Add(c); } else { list.Add(a); list.Add(c); list.Add(b); } } public void AddFlatPolygon(int submesh, Vector3[] pts, Func<Vector3, Vector2> uv, Vector3 interior) { Vector3 zero = Vector3.Zero; Vector3[] array = pts; foreach (Vector3 vector in array) { zero += vector; } zero /= (float)pts.Length; Vector3 vector2 = Vector3.Cross(pts[1] - pts[0], pts[2] - pts[0]); if (Vector3.Dot(vector2, zero - interior) < 0f) { vector2 = -vector2; } vector2 = Vector3.Normalize(vector2); int count = Positions.Count; array = pts; foreach (Vector3 vector3 in array) { AddVertex(vector3, vector2, uv(vector3)); } for (int j = 1; j < pts.Length - 1; j++) { AddTriangleFacingNormals(submesh, count, count + j, count + j + 1); } } public void Translate(Vector3 delta) { for (int i = 0; i < Positions.Count; i++) { Positions[i] += delta; } } public void Scale(float s) { for (int i = 0; i < Positions.Count; i++) { Positions[i] *= s; } } public void Bounds(out Vector3 min, out Vector3 max) { min = new Vector3(float.MaxValue); max = new Vector3(float.MinValue); foreach (Vector3 position in Positions) { min = Vector3.Min(min, position); max = Vector3.Max(max, position); } } public float LowestPointAfterRotation(Vector3 eulerDeg) { Quaternion rotation = UnityEuler(eulerDeg); float num = float.MaxValue; foreach (Vector3 position in Positions) { num = Math.Min(num, Vector3.Transform(position, rotation).Y); } return num; } public static Quaternion UnityEuler(Vector3 eulerDeg) { Quaternion value = Quaternion.CreateFromAxisAngle(Vector3.UnitX, eulerDeg.X * (MathF.PI / 180f)); Quaternion value2 = Quaternion.CreateFromAxisAngle(Vector3.UnitY, eulerDeg.Y * (MathF.PI / 180f)); return Quaternion.Concatenate(Quaternion.Concatenate(Quaternion.CreateFromAxisAngle(Vector3.UnitZ, eulerDeg.Z * (MathF.PI / 180f)), value), value2); } } public static class WoodTexture { public static byte[] GenerateRgba(int size, int seed = 1337) { byte[] array = new byte[size * size * 4]; float[] array2 = new float[3] { 0.84f, 0.57f, 0.25f }; float[] array3 = new float[3] { 0.76f, 0.49f, 0.2f }; float[] array4 = new float[3] { 0.58f, 0.34f, 0.12f }; for (int i = 0; i < size; i++) { float v = (float)i / (float)size; for (int j = 0; j < size; j++) { float num = (float)j / (float)size; float num2 = Fbm(num, v, 3, 2, 3, seed) * 1.6f; float num3 = num * 9f + num2; float num4 = MathF.Pow(MathF.Abs(MathF.Sin((num3 - MathF.Floor(num3)) * MathF.PI)), 6f); float num5 = 0.5f + 0.5f * MathF.Sin(num3 * 2f * MathF.PI * 0.5f + 1.3f); float num6 = Fbm(num, v, 64, 4, 2, seed + 7); float num7 = Fbm(num, v, 4, 4, 3, seed + 19); float t = 0.35f * num5 + 0.25f * num6 + 0.15f * num7; float a = Lerp(array2[0], array3[0], t); float a2 = Lerp(array2[1], array3[1], t); float a3 = Lerp(array2[2], array3[2], t); float t2 = num4 * 0.55f + MathF.Max(0f, num6 - 0.62f) * 0.9f; a = Lerp(a, array4[0], t2); a2 = Lerp(a2, array4[1], t2); a3 = Lerp(a3, array4[2], t2); int num8 = (i * size + j) * 4; array[num8] = ToByte(a); array[num8 + 1] = ToByte(a2); array[num8 + 2] = ToByte(a3); array[num8 + 3] = byte.MaxValue; } } return array; } private static float Lerp(float a, float b, float t) { return a + (b - a) * Math.Clamp(t, 0f, 1f); } private static byte ToByte(float f) { return (byte)Math.Clamp((int)(f * 255f + 0.5f), 0, 255); } private static float Fbm(float u, float v, int periodX, int periodY, int octaves, int seed) { float num = 0f; float num2 = 0.5f; float num3 = 0f; int num4 = periodX; int num5 = periodY; for (int i = 0; i < octaves; i++) { num += num2 * ValueNoise(u * (float)num4, v * (float)num5, num4, num5, seed + i * 101); num3 += num2; num2 *= 0.5f; num4 *= 2; num5 *= 2; } return num / num3; } private static float ValueNoise(float x, float y, int px, int py, int seed) { int num = (int)MathF.Floor(x); int num2 = (int)MathF.Floor(y); float num3 = x - (float)num; float num4 = y - (float)num2; num3 = num3 * num3 * (3f - 2f * num3); num4 = num4 * num4 * (3f - 2f * num4); float num5 = Hash(Mod(num, px), Mod(num2, py), seed); float num6 = Hash(Mod(num + 1, px), Mod(num2, py), seed); float num7 = Hash(Mod(num, px), Mod(num2 + 1, py), seed); float num8 = Hash(Mod(num + 1, px), Mod(num2 + 1, py), seed); return num5 + (num6 - num5) * num3 + (num7 + (num8 - num7) * num3 - (num5 + (num6 - num5) * num3)) * num4; } private static int Mod(int a, int m) { return (a % m + m) % m; } private static float Hash(int x, int y, int seed) { int num = x * 374761393 + y * 668265263 + seed * 144665; int num2 = (num ^ (num >>> 13)) * 1274126177; return (float)(uint)((num2 ^ (num2 >>> 16)) & 0xFFFFFF) / 16777215f; } } }