using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using GUIFramework; using HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.Rendering; using UnityEngine.SceneManagement; using UnityEngine.UI; using Valheim.SettingsGui; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: IgnoresAccessChecksTo("assembly_guiutils")] [assembly: IgnoresAccessChecksTo("assembly_valheim")] [assembly: AssemblyCompany("BowTrajectory")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.7.0")] [assembly: AssemblyInformationalVersion("1.0.7")] [assembly: AssemblyProduct("BowTrajectory")] [assembly: AssemblyTitle("BowTrajectory")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.7.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 BowTrajectory { [BepInPlugin("ModdedWolf.BowTrajectory", "Bow Trajectory", "1.0.7")] public class BowTrajectoryPlugin : BaseUnityPlugin { public const string GUID = "ModdedWolf.BowTrajectory"; public const string NAME = "Bow Trajectory"; public const string VERSION = "1.0.7"; internal static BowTrajectoryPlugin Instance; internal static ManualLogSource Log; internal static ConfigEntry Enabled; internal static ConfigEntry ToggleKey; internal static ConfigEntry MinDrawPercent; internal static ConfigEntry StopAtCharacters; internal static ConfigEntry ShowForCrossbows; internal static ConfigEntry StartColor; internal static ConfigEntry StartColorHex; internal static ConfigEntry EndColor; internal static ConfigEntry EndColorHex; internal static ConfigEntry LineWidth; internal static ConfigEntry ShowImpactMarker; internal static ConfigEntry ImpactColor; internal static ConfigEntry ImpactColorHex; internal static ConfigEntry ImpactMarkerSize; internal static ConfigEntry MaxPoints; private GameObject _manager; private void Awake() { //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Expected O, but got Unknown //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Expected O, but got Unknown //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01c7: Expected O, but got Unknown //IL_021e: Unknown result type (might be due to invalid IL or missing references) //IL_0228: Expected O, but got Unknown //IL_026e: Unknown result type (might be due to invalid IL or missing references) //IL_0278: Expected O, but got Unknown //IL_02cf: Unknown result type (might be due to invalid IL or missing references) //IL_02d9: Expected O, but got Unknown //IL_0309: Unknown result type (might be due to invalid IL or missing references) //IL_0313: Expected O, but got Unknown //IL_0396: Unknown result type (might be due to invalid IL or missing references) //IL_03a6: Unknown result type (might be due to invalid IL or missing references) //IL_03b0: Expected O, but got Unknown Instance = this; Log = ((BaseUnityPlugin)this).Logger; int num = (int)(0u | (ConfigMigration.ScrubLegacyColorPreset(((BaseUnityPlugin)this).Config, "Appearance", "StartColor", "StartColorHex", ColorConfig.ToDisplayName(ColorPreset.White)) ? 1u : 0u) | (ConfigMigration.ScrubLegacyColorPreset(((BaseUnityPlugin)this).Config, "Appearance", "EndColor", "EndColorHex", ColorConfig.ToDisplayName(ColorPreset.Red)) ? 1u : 0u)) | (ConfigMigration.ScrubLegacyColorPreset(((BaseUnityPlugin)this).Config, "Appearance", "ImpactColor", "ImpactColorHex", ColorConfig.ToDisplayName(ColorPreset.Red)) ? 1 : 0); Enabled = ((BaseUnityPlugin)this).Config.Bind("General", "Enabled", true, "Master toggle for the trajectory preview."); ToggleKey = ((BaseUnityPlugin)this).Config.Bind("General", "ToggleKey", new KeyboardShortcut((KeyCode)98, Array.Empty()), "Hotkey to toggle the trajectory preview on/off while playing."); MinDrawPercent = ((BaseUnityPlugin)this).Config.Bind("General", "MinDrawPercent", 0.05f, new ConfigDescription("Only show the bow trajectory once the draw passes this fraction (0-1).", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 1f), Array.Empty())); ShowForCrossbows = ((BaseUnityPlugin)this).Config.Bind("General", "ShowForCrossbows", true, "Also show the trajectory while aiming a crossbow (crossbows always fire at full power)."); StopAtCharacters = ((BaseUnityPlugin)this).Config.Bind("General", "StopAtCharacters", true, "If true, the predicted path and impact marker stop on creatures/animals/players too, not just terrain and structures. Set false to let the line pass through characters and only land on the world."); AcceptableValueList val = new AcceptableValueList(ColorConfig.PresetDisplayNames); StartColor = ((BaseUnityPlugin)this).Config.Bind("Appearance", "StartColor", ColorConfig.ToDisplayName(ColorPreset.White), new ConfigDescription("Line color near the bow. Named color, RGB Cycle Slow/Medium/Fast, or Custom + StartColorHex.", (AcceptableValueBase)(object)val, Array.Empty())); StartColorHex = ((BaseUnityPlugin)this).Config.Bind("Appearance", "StartColorHex", "#FFFFFFD9", "Used only when StartColor is Custom. Hex as #RRGGBB or #RRGGBBAA."); EndColor = ((BaseUnityPlugin)this).Config.Bind("Appearance", "EndColor", ColorConfig.ToDisplayName(ColorPreset.Red), new ConfigDescription("Line color near the impact point. Named color, RGB Cycle Slow/Medium/Fast, or Custom + EndColorHex.", (AcceptableValueBase)(object)val, Array.Empty())); EndColorHex = ((BaseUnityPlugin)this).Config.Bind("Appearance", "EndColorHex", "#FF4033D9", "Used only when EndColor is Custom. Hex as #RRGGBB or #RRGGBBAA."); LineWidth = ((BaseUnityPlugin)this).Config.Bind("Appearance", "LineWidth", 0.06f, new ConfigDescription("Width of the trajectory line in meters.", (AcceptableValueBase)(object)new AcceptableValueRange(0.01f, 0.5f), Array.Empty())); ShowImpactMarker = ((BaseUnityPlugin)this).Config.Bind("Appearance", "ShowImpactMarker", true, "Show a ring marker where the arrow is predicted to land."); ImpactColor = ((BaseUnityPlugin)this).Config.Bind("Appearance", "ImpactColor", ColorConfig.ToDisplayName(ColorPreset.Red), new ConfigDescription("Color of the impact marker ring. Named color, RGB Cycle Slow/Medium/Fast, or Custom + ImpactColorHex.", (AcceptableValueBase)(object)val, Array.Empty())); ImpactColorHex = ((BaseUnityPlugin)this).Config.Bind("Appearance", "ImpactColorHex", "#FF4033E6", "Used only when ImpactColor is Custom. Hex as #RRGGBB or #RRGGBBAA."); ImpactMarkerSize = ((BaseUnityPlugin)this).Config.Bind("Appearance", "ImpactMarkerSize", 0.5f, new ConfigDescription("Radius of the impact marker ring in meters.", (AcceptableValueBase)(object)new AcceptableValueRange(0.1f, 3f), Array.Empty())); MaxPoints = ((BaseUnityPlugin)this).Config.Bind("Advanced", "MaxPoints", 400, new ConfigDescription("Maximum number of simulated points along the path. The simulation always uses the game's live physics timestep so the predicted arc matches the real arrow.", (AcceptableValueBase)(object)new AcceptableValueRange(16, 2048), Array.Empty())); if (num != 0) { ((BaseUnityPlugin)this).Config.Save(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Migrated legacy Appearance color values to presets / Custom + Hex."); } ConfigMigration.MigrateFromLegacy(((BaseUnityPlugin)this).Config, ((BaseUnityPlugin)this).Logger, Enabled, ToggleKey, MinDrawPercent, ShowForCrossbows, StopAtCharacters, StartColor, StartColorHex, EndColor, EndColorHex, LineWidth, ShowImpactMarker, ImpactColor, ImpactColorHex, ImpactMarkerSize, MaxPoints); new Harmony("ModdedWolf.BowTrajectory").PatchAll(); _manager = new GameObject("BowTrajectory_Manager"); _manager.AddComponent(); Object.DontDestroyOnLoad((Object)(object)_manager); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Bow Trajectory v1.0.7 loaded."); } internal static Color ResolveStartColor() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) return ColorConfig.Resolve(StartColor.Value, StartColorHex.Value, ColorConfig.DefaultLineAlpha); } internal static Color ResolveEndColor() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) return ColorConfig.Resolve(EndColor.Value, EndColorHex.Value, ColorConfig.DefaultLineAlpha, 0.15f); } internal static Color ResolveImpactColor() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) return ColorConfig.Resolve(ImpactColor.Value, ImpactColorHex.Value, ColorConfig.DefaultMarkerAlpha); } private void OnDestroy() { if ((Object)(object)_manager != (Object)null) { Object.Destroy((Object)(object)_manager); _manager = null; } } } internal sealed class BowTrajectorySettingsTab : MonoBehaviour, ISettingsTab { private const string PageName = "BowTrajectorySettings"; private const string TabButtonLabel = "Bow Trajectory"; private const float DropdownWidth = 180f; private GuiDropdown _trajectoryDropdown; private GuiDropdown _impactDropdown; private Slider _lineWidthSlider; private TMP_Text _lineWidthValueText; private Slider _impactSizeSlider; private TMP_Text _impactSizeValueText; private Toggle _enabledToggle; private Toggle _showImpactToggle; private Toggle _showCrossbowToggle; private Button _defaultButton; public event Action SharedSettingChanged; internal static void TryInjectTab(Settings settings) { //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Expected O, but got Unknown //IL_0149: Expected O, but got Unknown try { if ((Object)(object)settings == (Object)null) { return; } TabHandler componentInChildren = ((Component)settings).GetComponentInChildren(true); if ((Object)(object)componentInChildren == (Object)null || componentInChildren.m_tabs == null || componentInChildren.m_tabs.Count == 0) { LogWarning("Could not find TabHandler tabs. Skipping Bow Trajectory settings tab."); } else { if ((Object)(object)FindExistingPage(componentInChildren) != (Object)null) { return; } Tab val = FindTemplateTab(componentInChildren); if (val == null || (Object)(object)val.m_button == (Object)null || (Object)(object)val.m_page == (Object)null) { LogWarning("Could not find a settings tab template. Skipping Bow Trajectory settings tab."); return; } Button val2 = CloneTabButton(val.m_button, "Bow Trajectory"); if ((Object)(object)val2 == (Object)null) { LogWarning("Failed to clone settings tab button. Skipping Bow Trajectory settings tab."); return; } RectTransform val3 = CreatePage(val.m_page); if ((Object)(object)val3 == (Object)null) { Object.Destroy((Object)(object)((Component)val2).gameObject); LogWarning("Failed to create Bow Trajectory settings page. Skipping tab."); return; } if (!((Component)val3).gameObject.AddComponent().TryBuildUi(settings, val3)) { Object.Destroy((Object)(object)((Component)val2).gameObject); Object.Destroy((Object)(object)((Component)val3).gameObject); LogWarning("Failed to build Bow Trajectory settings UI. Skipping tab."); return; } componentInChildren.m_tabs.Add(new Tab { m_button = val2, m_page = val3, m_default = false, m_onClick = new UnityEvent() }); LogInfo("Added Bow Trajectory settings tab."); } } catch (Exception ex) { LogWarning("Failed to inject Bow Trajectory settings tab: " + ex.Message); } } public void Initialize() { SyncFromConfig(); } public void OnTabOpen(Button backButton, Button okButton) { try { SyncFromConfig(); Selectable lastSelectable = GetLastSelectable(); if (!((Object)(object)lastSelectable == (Object)null)) { if ((Object)(object)backButton != (Object)null) { GuiUtils.SetNavigationDown(lastSelectable, (Selectable)(object)backButton); GuiUtils.SetNavigationUp((Selectable)(object)backButton, lastSelectable); } if ((Object)(object)okButton != (Object)null) { GuiUtils.SetNavigationUp((Selectable)(object)okButton, lastSelectable); } } } catch (Exception ex) { LogWarning("Failed to update Bow Trajectory tab navigation: " + ex.Message); } } public void OnOkAsync(OkActionCompletedHandler okActionCompletedCallback) { if (okActionCompletedCallback != null) { okActionCompletedCallback.Invoke(); } } public void OnBack() { } public void OnSharedSettingChanged(string setting, int value) { } public void Terminate() { } private bool TryBuildUi(Settings settings, RectTransform page) { GuiDropdown val = FindDropdownTemplate(settings); if ((Object)(object)val == (Object)null) { LogWarning("Could not find a GuiDropdown template (Graphics tab)."); return false; } Slider val2 = FindSliderTemplate(settings); if ((Object)(object)val2 == (Object)null) { LogWarning("Could not find a Slider template."); return false; } Toggle val3 = FindToggleTemplate(settings); TMP_Text labelTemplate = FindLabelTemplate(settings, val3, val2); Transform parent = CreateContentRoot(page); if ((Object)(object)val3 != (Object)null) { _enabledToggle = CreateToggleRow(parent, val3, labelTemplate, "Show trajectory", OnEnabledChanged); _showImpactToggle = CreateToggleRow(parent, val3, labelTemplate, "Show impact marker", OnShowImpactChanged); _showCrossbowToggle = CreateToggleRow(parent, val3, labelTemplate, "Show for crossbows", OnShowCrossbowChanged); } else { LogWarning("Could not find a Toggle template; skipping trajectory toggles."); } _trajectoryDropdown = CreateDropdownRow(parent, val, labelTemplate, "Bow trajectory color", OnTrajectoryChanged); _impactDropdown = CreateDropdownRow(parent, val, labelTemplate, "Impact marker color", OnImpactChanged); GetFloatRange(BowTrajectoryPlugin.LineWidth, 0.01f, 0.5f, out var min, out var max); GetFloatRange(BowTrajectoryPlugin.ImpactMarkerSize, 0.1f, 3f, out var min2, out var max2); CreateSliderRow(parent, val2, labelTemplate, "Line width", min, max, OnLineWidthChanged, out _lineWidthSlider, out _lineWidthValueText); CreateSliderRow(parent, val2, labelTemplate, "Impact marker size", min2, max2, OnImpactSizeChanged, out _impactSizeSlider, out _impactSizeValueText); _defaultButton = CreateDefaultButton(parent, settings); WireSelectableNavigation(); SyncFromConfig(); if ((Object)(object)_trajectoryDropdown != (Object)null && (Object)(object)_impactDropdown != (Object)null && (Object)(object)_lineWidthSlider != (Object)null) { return (Object)(object)_impactSizeSlider != (Object)null; } return false; } private Button CreateDefaultButton(Transform parent, Settings settings) { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Expected O, but got Unknown Button val = FindButtonTemplate(settings); if ((Object)(object)val == (Object)null) { LogWarning("Could not find a Button template for Default reset; skipping."); return null; } GameObject val2 = new GameObject("DefaultSpacer", new Type[1] { typeof(RectTransform) }); val2.transform.SetParent(parent, false); LayoutElement obj = val2.AddComponent(); obj.flexibleHeight = 1f; obj.minHeight = 16f; Transform val3 = CreateRow(parent, "Default"); HorizontalLayoutGroup component = ((Component)val3).GetComponent(); if ((Object)(object)component != (Object)null) { ((LayoutGroup)component).childAlignment = (TextAnchor)4; } GameObject val4 = Object.Instantiate(((Component)val).gameObject, val3); ((Object)val4).name = "DefaultButton"; val4.SetActive(true); LayoutElement obj2 = val4.GetComponent() ?? val4.AddComponent(); obj2.minWidth = 140f; obj2.preferredWidth = 180f; obj2.flexibleWidth = 0f; obj2.minHeight = 36f; obj2.preferredHeight = 40f; Button component2 = val4.GetComponent