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 WindstridesArrowTweaks v1.0.0
BepInEx/plugins/WindstridesArrowTweaks.dll
Decompiled 4 days agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [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("WindstridesArrowTweaks")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("WindstridesArrowTweaks")] [assembly: AssemblyTitle("WindstridesArrowTweaks")] [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 WindstridesArrowTweaks { internal static class NockedArrowPatch { private const string DriverTypeName = "QuickMod.BowString.BowDrawDriver"; private static FieldInfo arrowField; private static FieldInfo arrowBackField; private static FieldInfo activeDriversField; private static MethodInfo clearArrowMethod; private static readonly Dictionary<GameObject, string> AmmoByProjectile = new Dictionary<GameObject, string>(); internal static void Install(Harmony harmony) { //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Expected O, but got Unknown Type type = AccessTools.TypeByName("QuickMod.BowString.BowDrawDriver"); MethodInfo methodInfo = ((type == null) ? null : AccessTools.Method(type, "BuildArrow", (Type[])null, (Type[])null)); arrowField = ((type == null) ? null : AccessTools.Field(type, "arrow")); arrowBackField = ((type == null) ? null : AccessTools.Field(type, "arrowBack")); activeDriversField = ((type == null) ? null : AccessTools.Field(type, "ActiveDrivers")); clearArrowMethod = ((type == null) ? null : AccessTools.Method(type, "ClearArrow", (Type[])null, (Type[])null)); if (methodInfo == null || arrowField == null || arrowBackField == null) { Plugin.Log.LogError((object)"Could not find Windstride's Bow Animations nocked-arrow code; this version may be incompatible. Arrow tweaks are disabled."); } else { harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(NockedArrowPatch), "AfterBuildArrow", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } internal static void RebuildNockedArrows() { if (clearArrowMethod == null || !(activeDriversField?.GetValue(null) is IEnumerable enumerable)) { return; } foreach (object item in enumerable) { Object val = (Object)((item is Object) ? item : null); if (val != null && Object.op_Implicit(val)) { clearArrowMethod.Invoke(item, null); } } } private static void AfterBuildArrow(object __instance, GameObject prefab) { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) object? value = arrowField.GetValue(__instance); GameObject val = (GameObject)((value is GameObject) ? value : null); if (Object.op_Implicit((Object)(object)val) && val.transform.childCount != 0) { Transform child = val.transform.GetChild(0); float num = Plugin.GlobalScale.Value * Plugin.ScaleFor(AmmoName(prefab)).Value; if (!Mathf.Approximately(num, 1f)) { child.localScale = Vector3.one * num; arrowBackField.SetValue(__instance, (Vector3)arrowBackField.GetValue(__instance) * num); } ReduceParticles(child, num); DimLights(child); } } private static void ReduceParticles(Transform model, float modelScale) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) float value = Plugin.ParticleAmount.Value; float value2 = Plugin.ParticleSize.Value; ParticleSystem[] componentsInChildren = ((Component)model).GetComponentsInChildren<ParticleSystem>(true); foreach (ParticleSystem val in componentsInChildren) { MainModule main = val.main; EmissionModule emission = val.emission; if (value <= 0f) { ((EmissionModule)(ref emission)).enabled = false; ParticleSystemRenderer component = ((Component)val).GetComponent<ParticleSystemRenderer>(); if (Object.op_Implicit((Object)(object)component)) { ((Renderer)component).enabled = false; } continue; } if (!Mathf.Approximately(modelScale, 1f)) { ((MainModule)(ref main)).scalingMode = (ParticleSystemScalingMode)0; } if (value < 1f) { ((EmissionModule)(ref emission)).rateOverTimeMultiplier = ((EmissionModule)(ref emission)).rateOverTimeMultiplier * value; ((EmissionModule)(ref emission)).rateOverDistanceMultiplier = ((EmissionModule)(ref emission)).rateOverDistanceMultiplier * value; ((MainModule)(ref main)).maxParticles = Mathf.Max(1, Mathf.RoundToInt((float)((MainModule)(ref main)).maxParticles * value)); } if (value2 < 1f) { if (((MainModule)(ref main)).startSize3D) { ((MainModule)(ref main)).startSizeXMultiplier = ((MainModule)(ref main)).startSizeXMultiplier * value2; ((MainModule)(ref main)).startSizeYMultiplier = ((MainModule)(ref main)).startSizeYMultiplier * value2; ((MainModule)(ref main)).startSizeZMultiplier = ((MainModule)(ref main)).startSizeZMultiplier * value2; } else { ((MainModule)(ref main)).startSizeMultiplier = ((MainModule)(ref main)).startSizeMultiplier * value2; } } } } private static void DimLights(Transform model) { float value = Plugin.GlowIntensity.Value; if (value >= 1f) { return; } Light[] componentsInChildren = ((Component)model).GetComponentsInChildren<Light>(true); foreach (Light val in componentsInChildren) { if (value <= 0f) { ((Behaviour)val).enabled = false; } else { val.intensity *= value; } } } private static string AmmoName(GameObject projectile) { //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Invalid comparison between Unknown and I4 if (AmmoByProjectile.TryGetValue(projectile, out var value)) { return value; } if (Object.op_Implicit((Object)(object)ObjectDB.instance)) { foreach (GameObject item in ObjectDB.instance.m_items) { ItemDrop val = (Object.op_Implicit((Object)(object)item) ? item.GetComponent<ItemDrop>() : null); SharedData val2 = (Object.op_Implicit((Object)(object)val) ? val.m_itemData.m_shared : null); if (val2 != null && (int)val2.m_itemType == 9 && val2.m_attack != null && (Object)(object)val2.m_attack.m_attackProjectile == (Object)(object)projectile) { value = ((Object)item).name; break; } } } if (value == null) { return ((Object)projectile).name; } AmmoByProjectile[projectile] = value; return value; } } [BepInPlugin("taylor.windstridesarrowtweaks", "Windstrides Arrow Tweaks", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class Plugin : BaseUnityPlugin { public const string Guid = "taylor.windstridesarrowtweaks"; public const string Name = "Windstrides Arrow Tweaks"; public const string Version = "1.0.0"; internal const string WindstridesGuid = "windstride.bowanimations"; private const string ParticleSection = "1 - Particles"; private const string ScaleSection = "2 - Arrow Scale"; private static readonly string[] VanillaArrows = new string[12] { "ArrowWood", "ArrowFire", "ArrowFlint", "ArrowBronze", "ArrowIron", "ArrowSilver", "ArrowPoison", "ArrowObsidian", "ArrowFrost", "ArrowNeedle", "ArrowCarapace", "ArrowCharred" }; private static readonly Regex InvalidKeyChars = new Regex("[=\\n\\t\\\\\"'\\[\\]]"); internal static ManualLogSource Log; internal static ConfigFile Cfg; internal static ConfigEntry<float> ParticleAmount; internal static ConfigEntry<float> ParticleSize; internal static ConfigEntry<float> GlowIntensity; internal static ConfigEntry<float> GlobalScale; private static readonly Dictionary<string, ConfigEntry<float>> ArrowScales = new Dictionary<string, ConfigEntry<float>>(); private Harmony harmony; private void Awake() { //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Expected O, but got Unknown //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Expected O, but got Unknown //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Expected O, but got Unknown //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; Cfg = ((BaseUnityPlugin)this).Config; ParticleAmount = ((BaseUnityPlugin)this).Config.Bind<float>("1 - Particles", "ParticleAmount", 1f, new ConfigDescription("Fraction of particles emitted by the nocked arrow (fire, frost, poison, etc.). 1 = unchanged, 0 = no particles.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>())); ParticleSize = ((BaseUnityPlugin)this).Config.Bind<float>("1 - Particles", "ParticleSize", 1f, new ConfigDescription("Size multiplier for the nocked arrow's particles. 1 = unchanged.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>())); GlowIntensity = ((BaseUnityPlugin)this).Config.Bind<float>("1 - Particles", "GlowIntensity", 1f, new ConfigDescription("Brightness of the light emitted by glowing nocked arrows (e.g. fire arrows). 1 = unchanged, 0 = no light.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>())); GlobalScale = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Arrow Scale", "AllArrows", 1f, new ConfigDescription("Size multiplier applied to every nocked arrow model. Combined with the per-arrow value below.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 3f), Array.Empty<object>())); string[] vanillaArrows = VanillaArrows; for (int i = 0; i < vanillaArrows.Length; i++) { ScaleFor(vanillaArrows[i]); } ((BaseUnityPlugin)this).Config.SettingChanged += delegate { NockedArrowPatch.RebuildNockedArrows(); }; harmony = new Harmony("taylor.windstridesarrowtweaks"); NockedArrowPatch.Install(harmony); } private void OnDestroy() { Harmony obj = harmony; if (obj != null) { obj.UnpatchSelf(); } } internal static ConfigEntry<float> ScaleFor(string arrowName) { //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown string text = InvalidKeyChars.Replace(arrowName, "_"); if (!ArrowScales.TryGetValue(text, out var value)) { value = Cfg.Bind<float>("2 - Arrow Scale", text, 1f, new ConfigDescription("Size multiplier for the nocked " + arrowName + " model.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 3f), Array.Empty<object>())); ArrowScales[text] = value; } return value; } } }