using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using Jotunn; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = "")] [assembly: IgnoresAccessChecksTo("")] [assembly: AssemblyCompany("RepairableTorchMod")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("RepairableTorchMod")] [assembly: AssemblyTitle("RepairableTorchMod")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace RepairableTorchMod { [BepInPlugin("yourname.repairabletorch", "Repairable Torch", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class RepairableTorchPlugin : BaseUnityPlugin { public const string ModGUID = "yourname.repairabletorch"; public const string ModName = "Repairable Torch"; public const string ModVersion = "1.0.0"; private const float MaxDurability = 50f; private const float DurabilityDrainPerSecond = 0.0417f; private static readonly Color TintColor = new Color(0.55f, 0.35f, 0.2f, 1f); private void Awake() { CustomLocalization localization = LocalizationManager.Instance.GetLocalization(); string text = "English"; localization.AddTranslation(ref text, new Dictionary { { "item_repairtorch", "Sturdy Torch" }, { "item_repairtorch_desc", "A reinforced torch bound with leather. Wears down with use but can be repaired for free at a workbench." } }); PrefabManager.OnVanillaPrefabsAvailable += RegisterTorch; } private void RegisterTorch() { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Expected O, but got Unknown //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Expected O, but got Unknown //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Expected O, but got Unknown //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Expected O, but got Unknown ItemConfig val = new ItemConfig(); val.Name = "$item_repairtorch"; val.Description = "$item_repairtorch_desc"; val.CraftingStation = "piece_workbench"; val.RepairStation = "piece_workbench"; val.Requirements = (RequirementConfig[])(object)new RequirementConfig[3] { new RequirementConfig { Item = "RoundLog", Amount = 3 }, new RequirementConfig { Item = "Resin", Amount = 4 }, new RequirementConfig { Item = "DeerHide", Amount = 4 } }; ItemConfig val2 = val; CustomItem val3 = new CustomItem("RepairTorch", "Torch", val2); if ((Object)(object)val3.ItemPrefab == (Object)null) { Logger.LogError((object)"Could not clone vanilla Torch prefab."); return; } SharedData shared = val3.ItemDrop.m_itemData.m_shared; shared.m_useDurability = true; shared.m_maxDurability = 50f; shared.m_durabilityPerLevel = 25f; shared.m_durabilityDrain = 0.0417f; shared.m_canBeReparied = true; shared.m_destroyBroken = false; ApplyDistinctVisuals(val3); ItemManager.Instance.AddItem(val3); Logger.LogInfo((object)"Repairable torch registered."); PrefabManager.OnVanillaPrefabsAvailable -= RegisterTorch; } private void ApplyDistinctVisuals(CustomItem customTorch) { //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) SharedData shared = customTorch.ItemDrop.m_itemData.m_shared; if (shared.m_icons != null && shared.m_icons.Length != 0 && (Object)(object)shared.m_icons[0] != (Object)null) { shared.m_icons[0] = TintSprite(shared.m_icons[0], TintColor); } Renderer[] componentsInChildren = customTorch.ItemPrefab.GetComponentsInChildren(true); if (componentsInChildren.Length == 0) { Logger.LogWarning((object)"Torch clone had no renderers found - model not tinted."); return; } Renderer[] array = componentsInChildren; foreach (Renderer val in array) { if (val is ParticleSystemRenderer) { continue; } string text = ((Object)((Component)val).gameObject).name.ToLowerInvariant(); if (!text.Contains("fire") && !text.Contains("flame")) { Material[] materials = val.materials; foreach (Material material in materials) { ApplyTintToMaterial(material, TintColor); } } } } private static void ApplyTintToMaterial(Material material, Color tint) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) if (material.HasProperty("_MainTex")) { Texture texture = material.GetTexture("_MainTex"); if (texture != null) { Texture2D val = CreateReadableTexture(texture); ApplyTintEffect(val, tint); ((Texture)val).filterMode = texture.filterMode; ((Texture)val).wrapMode = texture.wrapMode; material.SetTexture("_MainTex", (Texture)(object)val); return; } } if (material.HasProperty("_Color")) { material.color *= tint; } } private static Texture2D CreateReadableTexture(Texture source) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Expected O, but got Unknown //IL_0057: Unknown result type (might be due to invalid IL or missing references) RenderTexture temporary = RenderTexture.GetTemporary(source.width, source.height, 0, (RenderTextureFormat)0); Graphics.Blit(source, temporary); RenderTexture active = RenderTexture.active; RenderTexture.active = temporary; Texture2D val = new Texture2D(((Texture)temporary).width, ((Texture)temporary).height, (TextureFormat)4, false); val.ReadPixels(new Rect(0f, 0f, (float)((Texture)temporary).width, (float)((Texture)temporary).height), 0, 0); val.Apply(); RenderTexture.active = active; RenderTexture.ReleaseTemporary(temporary); return val; } private static void ApplyTintEffect(Texture2D texture, Color tint) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) Color[] pixels = texture.GetPixels(); Color val2 = default(Color); for (int i = 0; i < pixels.Length; i++) { Color val = pixels[i]; float num = Mathf.Max(new float[3] { val.r, val.g, val.b }); float num2 = 1f - Mathf.Clamp01((num - 0.55f) / 0.35f); ((Color)(ref val2))..ctor(val.r * tint.r, val.g * tint.g, val.b * tint.b, val.a); pixels[i] = Color.Lerp(val, val2, num2); } texture.SetPixels(pixels); texture.Apply(); } private static Sprite TintSprite(Sprite source, Color tint) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Expected O, but got Unknown //IL_0053: 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_007e: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: 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) Texture2D texture = source.texture; Rect textureRect = source.textureRect; RenderTexture temporary = RenderTexture.GetTemporary(((Texture)texture).width, ((Texture)texture).height, 0, (RenderTextureFormat)0); Graphics.Blit((Texture)(object)texture, temporary); RenderTexture active = RenderTexture.active; RenderTexture.active = temporary; Texture2D val = new Texture2D((int)((Rect)(ref textureRect)).width, (int)((Rect)(ref textureRect)).height, (TextureFormat)4, false); val.ReadPixels(textureRect, 0, 0); val.Apply(); RenderTexture.active = active; RenderTexture.ReleaseTemporary(temporary); ApplyTintEffect(val, tint); ((Texture)val).filterMode = ((Texture)texture).filterMode; ((Texture)val).wrapMode = ((Texture)texture).wrapMode; val.Apply(); return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), source.pixelsPerUnit); } } public static class MyPluginInfo { public const string PLUGIN_GUID = "RepairableTorchMod"; public const string PLUGIN_NAME = "RepairableTorchMod"; public const string PLUGIN_VERSION = "1.0.0"; } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { internal IgnoresAccessChecksToAttribute(string assemblyName) { } } }