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 JerkWad v1.0.0
JerkWad.dll
Decompiled 2 days agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("JerkWad")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+d4fe556bf148f5e3dc62a1b1777cc440101ca75f")] [assembly: AssemblyProduct("JerkWad")] [assembly: AssemblyTitle("JerkWad")] [assembly: AssemblyVersion("1.0.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 DelGryphon.JerkWad { [BepInPlugin("delgryphon.jerkwad", "Jerk Wad", "1.0.0")] [BepInDependency("com.jotunn.jotunn", "2.30.2")] public sealed class JerkWadPlugin : BaseUnityPlugin { [HarmonyPatch(typeof(ItemDrop), "DropItem", new Type[] { typeof(ItemData), typeof(int), typeof(Vector3), typeof(Quaternion) })] private static class JerkyDropSpawnPatch { [HarmonyPrefix] private static void Prefix(ItemData item, ref Vector3 position) { if (!((Object)(object)activePlugin == (Object)null) && item != null) { activePlugin.PrimeBeforeDrop(item, ref position); } } } private struct Ingredient { public readonly string Id; public readonly int Amount; public Ingredient(string id, int amount) { Id = id; Amount = amount; } } private Dictionary<string, byte[]> assets; private readonly Dictionary<string, Sprite> icons = new Dictionary<string, Sprite>(); private bool registered; private Harmony dropPatches; private static JerkWadPlugin activePlugin; private readonly HashSet<string> primedPrefabs = new HashSet<string>(); private readonly Dictionary<string, Mesh> cachedWorldMeshes = new Dictionary<string, Mesh>(); private readonly Dictionary<string, Material> cachedWorldMaterials = new Dictionary<string, Material>(); private readonly HashSet<string> sparklesInstalled = new HashSet<string>(); private float nextWorldScan; private readonly HashSet<int> visualizedObjects = new HashSet<int>(); private readonly HashSet<int> failedVisualObjects = new HashSet<int>(); private static readonly Dictionary<string, string> WorldIds = new Dictionary<string, string> { { "DG_FishJerky", "Fish" }, { "DG_CloudberryLoxJerky", "Lox" }, { "DG_HareJerky", "Hare" }, { "DG_VineberryVoltureJerky", "Volture" }, { "DG_LingonberryMooseJerky", "Moose" } }; private readonly List<string> failures = new List<string>(); private int succeeded; private void ErrorInGame(string context, Exception ex) { string text = context + ": " + ex.GetType().Name + ": " + ex.Message; failures.Add(text); ((BaseUnityPlugin)this).Logger.LogError((object)("Jerk Wad v1.0.0 " + text + "\n" + ex)); } private void Awake() { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Expected O, but got Unknown activePlugin = this; PrefabManager.OnVanillaPrefabsAvailable += RegisterItems; ItemManager.OnItemsRegistered += OnItemsReady; ItemManager.OnItemsRegisteredFejd += OnItemsReady; try { dropPatches = new Harmony("delgryphon.jerkwad.worldspawn.047"); dropPatches.CreateClassProcessor(typeof(JerkyDropSpawnPatch)).Patch(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Jerk Wad: early drop rendering enabled."); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Jerk Wad: using safe world-update fallback: " + ex.Message)); } } private void OnDestroy() { PrefabManager.OnVanillaPrefabsAvailable -= RegisterItems; ItemManager.OnItemsRegistered -= OnItemsReady; ItemManager.OnItemsRegisteredFejd -= OnItemsReady; if (dropPatches != null) { try { dropPatches.UnpatchSelf(); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Jerk Wad cleanup: " + ex.Message)); } } if ((Object)(object)activePlugin == (Object)(object)this) { activePlugin = null; } } private static string SpeciesForItem(ItemData data) { if (data == null || data.m_shared == null) { return null; } if ((Object)(object)data.m_dropPrefab != (Object)null && WorldIds.TryGetValue(((Object)data.m_dropPrefab).name, out var value)) { return value; } switch (data.m_shared.m_name) { case "Fish Jerky": return "Fish"; case "Lox Jerky": case "Cloudberry Lox Jerky": return "Lox"; case "Hare Jerky": return "Hare"; case "Vineberry Volture Jerky": case "Volture Jerky": return "Volture"; case "Lingonberry Moose Jerky": case "Moose Jerky": return "Moose"; default: return null; } } private static string PrefabForSpecies(string species) { foreach (KeyValuePair<string, string> worldId in WorldIds) { if (worldId.Value == species) { return worldId.Key; } } return null; } private void PrimeBeforeDrop(ItemData data, ref Vector3 position) { if ((Object)(object)ObjectDB.instance == (Object)null) { return; } string species = SpeciesForItem(data); string text = PrefabForSpecies(species); if (text == null) { return; } GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(text); if ((Object)(object)itemPrefab == (Object)null) { return; } try { PrimeRegisteredPrefab(itemPrefab, species); data.m_dropPrefab = itemPrefab; position.y += 0.18f; } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Jerk Wad pre-spawn visual fallback: " + ex.Message)); } } private void PrimeRegisteredPrefab(GameObject prefab, string species) { if (!((Object)(object)prefab == (Object)null) && !primedPrefabs.Contains(species)) { AttachVisualAndPhysics(prefab, species); AttachNativeSparkles(prefab); primedPrefabs.Add(species); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Jerk Wad: prefab ready before spawn: " + species)); } } private void PrimeRegisteredPrefabs() { if ((Object)(object)ObjectDB.instance == (Object)null) { return; } foreach (KeyValuePair<string, string> worldId in WorldIds) { if (primedPrefabs.Contains(worldId.Value)) { continue; } GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(worldId.Key); if (!((Object)(object)itemPrefab == (Object)null)) { try { PrimeRegisteredPrefab(itemPrefab, worldId.Value); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Jerk Wad preloaded art " + worldId.Value + ": " + ex.Message)); } } } } private void AttachNativeSparkles(GameObject prefab) { //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_010b: 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_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) if ((Object)(object)prefab == (Object)null || !sparklesInstalled.Add(((Object)prefab).name)) { return; } GameObject prefab2 = PrefabManager.Instance.GetPrefab("BoarJerky"); if ((Object)(object)prefab2 == (Object)null) { prefab2 = PrefabManager.Instance.GetPrefab("WolfJerky"); } if ((Object)(object)prefab2 == (Object)null) { return; } int num = 0; ParticleSystem[] componentsInChildren = prefab2.GetComponentsInChildren<ParticleSystem>(true); foreach (ParticleSystem val in componentsInChildren) { if ((Object)(object)val == (Object)null || (Object)(object)((Component)val).transform == (Object)(object)prefab2.transform) { continue; } GameObject gameObject = ((Component)val).gameObject; if ((Object)(object)gameObject.GetComponent<ItemDrop>() != (Object)null || (Object)(object)gameObject.GetComponent<ZNetView>() != (Object)null) { continue; } try { GameObject obj = Object.Instantiate<GameObject>(gameObject, prefab.transform, false); ((Object)obj).name = "DG_JerkWad_NativeDropSparkle_" + num; obj.transform.localPosition = prefab2.transform.InverseTransformPoint(((Component)val).transform.position); obj.transform.localRotation = Quaternion.Inverse(prefab2.transform.rotation) * ((Component)val).transform.rotation; obj.SetActive(true); ParticleSystem component = obj.GetComponent<ParticleSystem>(); if ((Object)(object)component != (Object)null) { component.Play(true); } num++; } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Jerk Wad sparkle clone failed: " + ex.Message)); } } ((BaseUnityPlugin)this).Logger.LogInfo((object)("Jerk Wad native drop sparkle emitters: " + num)); } private void RegisterItems() { if (!registered) { registered = true; PrefabManager.OnVanillaPrefabsAvailable -= RegisterItems; AddJerky("DG_FishJerky", "Fish", "Fish Jerky", "Dried fish seasoned with a little thistle for a bracing trail ration.", 28f, 28f, 2f, 2, new Ingredient("FishRaw", 1), new Ingredient("Thistle", 1), new Ingredient("Honey", 1)); AddJerky("DG_CloudberryLoxJerky", "Lox", "Lox Jerky", "Rich lox meat cured with sweet-tart cloudberries.", 39f, 39f, 3f, 4, new Ingredient("LoxMeat", 1), new Ingredient("Honey", 1), new Ingredient("Cloudberry", 2)); AddJerky("DG_HareJerky", "Hare", "Hare Jerky", "Tender hare strips, gently dried for long Mistlands journeys.", 46f, 46f, 3f, 5, new Ingredient("HareMeat", 1), new Ingredient("Honey", 1), new Ingredient("MushroomJotunPuffs", 1)); AddJerky("DG_VineberryVoltureJerky", "Volture", "Volture Jerky", "Smoky, chewy strips of volture meat cured with tart vineberries.", 54f, 54f, 4f, 6, new Ingredient("VoltureMeat", 1), new Ingredient("Vineberry", 2), new Ingredient("Honey", 1)); AddJerky("DG_LingonberryMooseJerky", "Moose", "Moose Jerky", "A hearty northern trail ration sharpened by lingonberries.", 63f, 63f, 4f, 7, new Ingredient("MooseMeat", 1), new Ingredient("Lingonberry", 2), new Ingredient("Honey", 1)); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Jerk Wad 0.4.7: independently created jerky prefabs registered."); } } private void AddJerky(string id, string species, string displayName, string description, float health, float stamina, float regen, int cauldronLevel, params Ingredient[] ingredients) { //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Expected O, but got Unknown //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Expected O, but got Unknown //IL_0180: Unknown result type (might be due to invalid IL or missing references) try { Ingredient[] array = ingredients; for (int i = 0; i < array.Length; i++) { Ingredient ingredient = array[i]; if ((Object)(object)PrefabManager.Instance.GetPrefab(ingredient.Id) == (Object)null) { string text = displayName + ": missing ingredient " + ingredient.Id; failures.Add(text); ((BaseUnityPlugin)this).Logger.LogError((object)text); return; } } Sprite val; try { val = LoadIcon(species); } catch (Exception ex) { ErrorInGame("Inventory art " + species, ex); val = EmergencyIcon(species); } ItemConfig val2 = new ItemConfig { Name = displayName, Description = description, Icon = val, CraftingStation = "piece_cauldron", MinStationLevel = cauldronLevel, Amount = 2, Weight = 0.5f, StackSize = 20 }; array = ingredients; for (int i = 0; i < array.Length; i++) { Ingredient ingredient2 = array[i]; val2.AddRequirement(ingredient2.Id, ingredient2.Amount, 0); } CustomItem val3 = new CustomItem(id, true, val2); if ((Object)(object)val3.ItemPrefab == (Object)null || (Object)(object)val3.ItemDrop == (Object)null) { throw new InvalidOperationException("Fresh item prefab/ItemDrop missing"); } ItemData itemData = val3.ItemDrop.m_itemData; if (itemData == null || itemData.m_shared == null) { throw new InvalidOperationException("Fresh ItemDrop shared data missing"); } SharedData shared = itemData.m_shared; shared.m_name = displayName; shared.m_description = description; shared.m_itemType = (ItemType)2; shared.m_food = health; shared.m_foodStamina = stamina; shared.m_foodEitr = 0f; shared.m_foodBurnTime = 1800f; shared.m_foodRegen = regen; shared.m_weight = 0.5f; shared.m_maxStackSize = 20; shared.m_maxQuality = 1; shared.m_icons = (Sprite[])(object)new Sprite[1] { val }; itemData.m_dropPrefab = val3.ItemPrefab; if (!ItemManager.Instance.AddItem(val3)) { throw new InvalidOperationException("Jotunn AddItem rejected new prefab " + id); } try { Rigidbody val4 = val3.ItemPrefab.GetComponent<Rigidbody>(); if ((Object)(object)val4 == (Object)null) { val4 = val3.ItemPrefab.AddComponent<Rigidbody>(); } val4.mass = 0.55f; val4.useGravity = true; val4.drag = 0.5f; val4.angularDrag = 0.8f; } catch (Exception ex2) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Jerk Wad minimal physics " + id + ": " + ex2)); } icons[id] = val; succeeded++; ((BaseUnityPlugin)this).Logger.LogInfo((object)("Jerk Wad item/recipe registered: " + id)); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Jerk Wad: deferred world art " + id)); } catch (Exception ex3) { ErrorInGame("Registration " + displayName, ex3); } } private void Update() { if ((Object)(object)ObjectDB.instance == (Object)null || (Object)(object)Player.m_localPlayer == (Object)null || Time.time < nextWorldScan) { return; } nextWorldScan = Time.time + 0.35f; RepairInventoryPrefabs(); PrimeRegisteredPrefabs(); ItemDrop[] array = Object.FindObjectsOfType<ItemDrop>(); foreach (ItemDrop val in array) { if ((Object)(object)val == (Object)null) { continue; } int instanceID = ((Object)val).GetInstanceID(); if (visualizedObjects.Contains(instanceID) || failedVisualObjects.Contains(instanceID)) { continue; } string text = IdentifyJerky(val); if (text != null) { try { AttachVisualAndPhysics(((Component)val).gameObject, text); visualizedObjects.Add(instanceID); } catch (Exception ex) { failedVisualObjects.Add(instanceID); ((BaseUnityPlugin)this).Logger.LogError((object)("Jerk Wad world rendering " + text + ": " + ex)); } } } } private static string IdentifyJerky(ItemDrop drop) { string text = ((Object)((Component)drop).gameObject).name; int num = text.IndexOf('('); if (num > 0) { text = text.Substring(0, num); } if (WorldIds.TryGetValue(text, out var value)) { return value; } ItemData itemData = drop.m_itemData; if (itemData == null || itemData.m_shared == null) { return null; } if ((Object)(object)itemData.m_dropPrefab != (Object)null && WorldIds.TryGetValue(((Object)itemData.m_dropPrefab).name, out value)) { return value; } switch (itemData.m_shared.m_name) { case "Fish Jerky": return "Fish"; case "Lox Jerky": case "Cloudberry Lox Jerky": return "Lox"; case "Hare Jerky": return "Hare"; case "Vineberry Volture Jerky": case "Volture Jerky": return "Volture"; case "Lingonberry Moose Jerky": case "Moose Jerky": return "Moose"; default: return null; } } private void RepairInventoryPrefabs() { Inventory inventory = ((Humanoid)Player.m_localPlayer).GetInventory(); if (inventory == null) { return; } foreach (ItemData allItem in inventory.GetAllItems()) { if (allItem == null || allItem.m_shared == null) { continue; } string text = null; switch (allItem.m_shared.m_name) { case "Fish Jerky": text = "DG_FishJerky"; break; case "Lox Jerky": case "Cloudberry Lox Jerky": text = "DG_CloudberryLoxJerky"; break; case "Hare Jerky": text = "DG_HareJerky"; break; case "Vineberry Volture Jerky": case "Volture Jerky": text = "DG_VineberryVoltureJerky"; break; case "Lingonberry Moose Jerky": case "Moose Jerky": text = "DG_LingonberryMooseJerky"; break; } if (text != null) { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(text); if ((Object)(object)itemPrefab != (Object)null && (Object)(object)allItem.m_dropPrefab != (Object)(object)itemPrefab) { allItem.m_dropPrefab = itemPrefab; } } } } private void AttachVisualAndPhysics(GameObject prefab, string species) { //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0119: 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_0142: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)prefab == (Object)null) { throw new InvalidOperationException("Missing independent item object"); } Rigidbody val = prefab.GetComponent<Rigidbody>(); if ((Object)(object)val == (Object)null) { val = prefab.AddComponent<Rigidbody>(); } val.mass = 0.55f; val.useGravity = true; val.drag = 0.7f; val.angularDrag = 1.6f; val.collisionDetectionMode = (CollisionDetectionMode)2; val.interpolation = (RigidbodyInterpolation)1; MeshFilter component = prefab.GetComponent<MeshFilter>(); MeshRenderer component2 = prefab.GetComponent<MeshRenderer>(); BoxCollider component3 = prefab.GetComponent<BoxCollider>(); if ((Object)(object)component == (Object)null || (Object)(object)component2 == (Object)null || (Object)(object)component3 == (Object)null) { throw new InvalidOperationException("Fresh primitive missing its mesh or collider"); } if (!cachedWorldMeshes.TryGetValue(species, out var value)) { value = LoadMesh(ReadAsset(species + ".jwm"), species); cachedWorldMeshes.Add(species, value); } component.sharedMesh = value; Bounds bounds = value.bounds; component3.center = ((Bounds)(ref bounds)).center; bounds = value.bounds; Vector3 size = ((Bounds)(ref bounds)).size; component3.size = new Vector3(Mathf.Max(0.25f, size.x + 0.02f), Mathf.Max(0.075f, size.y + 0.015f), Mathf.Max(0.25f, size.z + 0.02f)); ((Collider)component3).isTrigger = false; if (!cachedWorldMaterials.TryGetValue(species, out var value2)) { Texture2D texture = LoadTexture(ReadAsset(species + ".jwt"), species); value2 = CreateMaterial(species, texture); cachedWorldMaterials.Add(species, value2); } ((Renderer)component2).sharedMaterial = value2; ((Renderer)component2).enabled = true; int num = LayerMask.NameToLayer("item"); if (num >= 0) { prefab.layer = num; } } private static Sprite EmergencyIcon(string species) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0091: 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_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false); Color32[] array = (Color32[])(object)new Color32[4096]; for (int i = 0; i < 64; i++) { for (int j = 0; j < 64; j++) { array[i * 64 + j] = ((j > 9 && j < 54 && i > 19 && i < 44) ? new Color32((byte)137, (byte)67, (byte)34, byte.MaxValue) : new Color32((byte)0, (byte)0, (byte)0, (byte)0)); } } val.SetPixels32(array); val.Apply(); Sprite obj = Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f), 100f); ((Object)obj).name = "DG_Emergency_" + species; return obj; } private void OnItemsReady() { if ((Object)(object)ObjectDB.instance == (Object)null) { return; } foreach (KeyValuePair<string, Sprite> icon in icons) { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(icon.Key); if (!((Object)(object)itemPrefab == (Object)null)) { ItemDrop component = itemPrefab.GetComponent<ItemDrop>(); if (!((Object)(object)component == (Object)null) && component.m_itemData != null) { component.m_itemData.m_dropPrefab = itemPrefab; component.m_itemData.m_shared.m_icons = (Sprite[])(object)new Sprite[1] { icon.Value }; } } } } private Material CreateMaterial(string species, Texture2D texture) { //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Expected O, but got Unknown //IL_00c6: 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_0132: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) Material val = null; GameObject prefab = PrefabManager.Instance.GetPrefab("WolfJerky"); if ((Object)(object)prefab != (Object)null) { Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true); foreach (Renderer val2 in componentsInChildren) { if ((Object)(object)val2.sharedMaterial != (Object)null) { val = val2.sharedMaterial; break; } } } Shader val3 = (((Object)(object)val != (Object)null) ? val.shader : Shader.Find("Standard")); if ((Object)(object)val == (Object)null && (Object)(object)val3 == (Object)null) { throw new InvalidOperationException("No compatible food material shader available."); } Material val4 = (((Object)(object)val != (Object)null) ? new Material(val) : new Material(val3)); ((Object)val4).name = "DG_New_" + species + "_Jerky_Surface"; val4.mainTexture = (Texture)(object)texture; val4.color = Color.white; if (val4.HasProperty("_MainTex")) { val4.SetTexture("_MainTex", (Texture)(object)texture); } if (val4.HasProperty("_BaseMap")) { val4.SetTexture("_BaseMap", (Texture)(object)texture); } if (val4.HasProperty("_Color")) { val4.SetColor("_Color", Color.white); } if (val4.HasProperty("_BaseColor")) { val4.SetColor("_BaseColor", Color.white); } if (val4.HasProperty("_EmissionColor")) { val4.SetColor("_EmissionColor", Color.black); } if (val4.HasProperty("_Glossiness")) { val4.SetFloat("_Glossiness", 0.08f); } if (val4.HasProperty("_Metallic")) { val4.SetFloat("_Metallic", 0f); } return val4; } private Sprite LoadIcon(string species) { //IL_0088: 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) Texture2D val = AssetUtils.LoadImage(ReadAsset(species + ".png")); if ((Object)(object)val == (Object)null || ((Texture)val).width != 256 || ((Texture)val).height != 256) { throw new InvalidDataException("Cannot decode native-style icon for " + species); } ((Object)val).name = "DG_" + species + "_Jerky_Icon"; ((Texture)val).wrapMode = (TextureWrapMode)1; ((Texture)val).filterMode = (FilterMode)1; Sprite obj = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f); ((Object)obj).name = ((Object)val).name; return obj; } private byte[] ReadAsset(string name) { if (assets == null) { Dictionary<string, byte[]> dictionary = new Dictionary<string, byte[]>(StringComparer.Ordinal); using (FileStream fileStream = File.OpenRead(((BaseUnityPlugin)this).Info.Location)) { using BinaryReader binaryReader = new BinaryReader(fileStream); if (fileStream.Length < 12) { throw new InvalidDataException("Embedded artwork footer missing."); } fileStream.Seek(-8L, SeekOrigin.End); int num = binaryReader.ReadInt32(); if (Encoding.ASCII.GetString(binaryReader.ReadBytes(4)) != "JWAE" || num < 20 || num > 8000000 || num > fileStream.Length - 8) { throw new InvalidDataException("Embedded artwork footer invalid."); } long num2 = fileStream.Length - 8 - num; fileStream.Seek(num2, SeekOrigin.Begin); if (Encoding.ASCII.GetString(binaryReader.ReadBytes(4)) != "JWAP") { throw new InvalidDataException("Embedded artwork signature invalid."); } int num3 = binaryReader.ReadUInt16(); if (num3 != 15) { throw new InvalidDataException("Expected all 15 visual resources."); } for (int i = 0; i < num3; i++) { int count = binaryReader.ReadByte(); string text = Encoding.UTF8.GetString(binaryReader.ReadBytes(count)); int num4 = binaryReader.ReadInt32(); if (num4 < 1 || num4 > 3000000 || fileStream.Position + num4 > num2 + num) { throw new InvalidDataException("Invalid embedded art: " + text); } byte[] array = binaryReader.ReadBytes(num4); if (array.Length != num4 || dictionary.ContainsKey(text)) { throw new InvalidDataException("Incomplete/duplicate art: " + text); } dictionary.Add(text, array); } if (fileStream.Position != num2 + num) { throw new InvalidDataException("Trailing embedded art bytes."); } } assets = dictionary; } if (!assets.TryGetValue(name, out var value)) { throw new FileNotFoundException("Jerk Wad original art not embedded: " + name); } return value; } private static Mesh LoadMesh(byte[] data, string species) { //IL_00b0: 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_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01bb: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Expected O, but got Unknown using BinaryReader binaryReader = new BinaryReader(new MemoryStream(data)); if (Encoding.ASCII.GetString(binaryReader.ReadBytes(4)) != "JWM1") { throw new InvalidDataException("Invalid jerky mesh signature."); } int num; int num2; checked { num = (int)binaryReader.ReadUInt32(); num2 = (int)binaryReader.ReadUInt32(); } if (num < 3 || num > 65000 || num2 < 3 || num2 > 200000 || num2 % 3 != 0) { throw new InvalidDataException("Invalid mesh counts."); } Vector3[] array = (Vector3[])(object)new Vector3[num]; Vector2[] array2 = (Vector2[])(object)new Vector2[num]; float num3 = float.MaxValue; float num4 = float.MinValue; for (int i = 0; i < num; i++) { float num5 = binaryReader.ReadSingle(); float num6 = binaryReader.ReadSingle(); float num7 = binaryReader.ReadSingle(); array[i] = new Vector3(num5, num7, 0f - num6); array2[i] = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle()); if (num7 < num3) { num3 = num7; } if (num7 > num4) { num4 = num7; } } float num8 = (num3 + num4) * 0.5f; for (int j = 0; j < num; j++) { array[j].y -= num8; } int[] array3 = new int[num2]; for (int k = 0; k < num2; k++) { int num9 = checked((int)binaryReader.ReadUInt32()); if (num9 < 0 || num9 >= num) { throw new InvalidDataException("Out-of-range mesh vertex index."); } array3[k] = num9; } if (binaryReader.BaseStream.Position != binaryReader.BaseStream.Length) { throw new InvalidDataException("Trailing mesh bytes."); } Mesh val = new Mesh { name = "DG_New_" + species + "_Jerky", vertices = array, uv = array2, triangles = array3 }; val.RecalculateNormals(); val.RecalculateBounds(); return val; } private static Texture2D LoadTexture(byte[] data, string species) { //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Expected O, but got Unknown //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) using BinaryReader binaryReader = new BinaryReader(new MemoryStream(data)); if (Encoding.ASCII.GetString(binaryReader.ReadBytes(4)) != "JWT1") { throw new InvalidDataException("Invalid jerky diffuse texture."); } int num = binaryReader.ReadUInt16(); int num2 = binaryReader.ReadUInt16(); if (num < 8 || num2 < 8 || num > 1024 || num2 > 1024) { throw new InvalidDataException("Invalid jerky texture dimensions."); } int num3 = checked(num * num2 * 4); byte[] array = binaryReader.ReadBytes(num3); if (array.Length != num3 || binaryReader.BaseStream.Position != binaryReader.BaseStream.Length) { throw new InvalidDataException("Incomplete jerky texture."); } Texture2D val = new Texture2D(num, num2, (TextureFormat)4, false); ((Object)val).name = "DG_New_" + species + "_Diffuse"; Color32[] array2 = (Color32[])(object)new Color32[num * num2]; int num4 = 0; int num5 = 0; while (num5 < array2.Length) { array2[num5] = new Color32(array[num4], array[num4 + 1], array[num4 + 2], array[num4 + 3]); num5++; num4 += 4; } val.SetPixels32(array2); val.Apply(false, false); ((Texture)val).wrapMode = (TextureWrapMode)0; ((Texture)val).filterMode = (FilterMode)1; return val; } } }