using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using Rewired; using Rewired.Data; using Rewired.Utils.Libraries.TinyJson; using UnityEngine; using YawOnMouse.Blacklist; using YawOnMouse.Helpers; [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: AssemblyCompany("YawOnMouse")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.1.0.0")] [assembly: AssemblyInformationalVersion("1.1.0+40e90b669fbd0d69d7af571261dd1f8347f812c5")] [assembly: AssemblyProduct("YawOnMouse")] [assembly: AssemblyTitle("YawOnMouse")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.1.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.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 YawOnMouse { public enum AxisPatchType { Roll = 0, Yaw = 2 } public static class PluginInfo { public const string PLUGIN_GUID = "YawOnMouse"; public const string PLUGIN_NAME = "YawOnMouse"; public const string PLUGIN_VERSION = "2.1.0"; } [BepInPlugin("YawOnMouse", "YawOnMouse", "2.1.0")] public class Plugin : BaseUnityPlugin { internal static ManualLogSource Logger; public static ConfigEntry Enabled; public static ConfigEntry AxisPatchType; public static ConfigEntry UseCraftWhitelist; public WhitelistConfigManager WhitelistConfigManager; public static Plugin Instance; public const string ACTION_TOGGLE = "YawOnMouse::Toggle"; public static bool RewiredReady; private bool _scanComplete; private void Awake() { //IL_0090: Unknown result type (might be due to invalid IL or missing references) Logger = ((BaseUnityPlugin)this).Logger; Instance = this; WhitelistConfigManager = new WhitelistConfigManager(); Enabled = ((BaseUnityPlugin)this).Config.Bind("Config", "PlayerAxisControls_Patch", true, "Enable/Disable controller roll input patch"); AxisPatchType = ((BaseUnityPlugin)this).Config.Bind("Config", "AxisPatchType", YawOnMouse.AxisPatchType.Yaw, "What you want the patch to do on the x-axis (can only be changed before startup not at runtime.)"); UseCraftWhitelist = ((BaseUnityPlugin)this).Config.Bind("Config", "UseCraftWhitelist", false, "When enabled the mod will only work on the aircraft specified in the whitelist"); Logger.LogInfo((object)"Plugin YawOnMouse is loaded!"); new Harmony("YawOnMouse").PatchAll(); } private void Update() { if (RewiredReady) { PlayerHelper players = ReInput.players; Player val = ((players != null) ? players.GetPlayer(0) : null); if (val != null && val.GetButtonDown("YawOnMouse::Toggle")) { Enabled.Value = !Enabled.Value; ((BaseUnityPlugin)this).Config.Save(); } } if (!_scanComplete) { _scanComplete = WhitelistConfigManager.TryScanForAircraft(); } } } public static class MyPluginInfo { public const string PLUGIN_GUID = "YawOnMouse"; public const string PLUGIN_NAME = "YawOnMouse"; public const string PLUGIN_VERSION = "1.1.0"; } } namespace YawOnMouse.Blacklist { public class WhitelistConfig { public Dictionary Whitelist = new Dictionary(); public bool Enabled(string name) { foreach (KeyValuePair item in Whitelist) { if (name.Contains(item.Key) && item.Value) { return true; } } return false; } public void Add(string name, bool enabled) { Whitelist.Add(name, enabled); } public void Remove(string name) { Whitelist.Remove(name); } } public class WhitelistConfigManager { private readonly string _whitelistConfigPath; public WhitelistConfig Config { get; private set; } public WhitelistConfigManager() { _whitelistConfigPath = Path.Combine(Paths.ConfigPath, "AircraftWhitelistConfig.json"); LoadOrCreateConfig(); } public bool TryScanForAircraft() { Aircraft[] array = Resources.FindObjectsOfTypeAll(); Plugin.Logger.LogInfo((object)$"Aircraft scan: found {((array != null) ? array.Length : 0)}"); if (array == null || array.Length == 0) { return false; } bool flag = false; Aircraft[] array2 = array; for (int i = 0; i < array2.Length; i++) { string text = ((Object)((Component)array2[i]).gameObject).name.Replace("(Clone)", "").Trim(); if (!Config.Whitelist.ContainsKey(text)) { Config.Whitelist.Add(text, value: false); Plugin.Logger.LogInfo((object)("Discovered " + text)); flag = true; } } if (flag) { SaveConfig(); } return true; } private void LoadOrCreateConfig() { if (!File.Exists(_whitelistConfigPath)) { Config = GenerateDefaultConfig(); SaveConfig(); Plugin.Logger.LogInfo((object)("Config file " + _whitelistConfigPath + " has been created!")); return; } try { string text = File.ReadAllText(_whitelistConfigPath); Config = JsonParser.FromJson(text); Plugin.Logger.LogInfo((object)"permission config loaded."); } catch (Exception ex) { Plugin.Logger.LogError((object)("failed to load permission config: " + ex.Message)); Config = GenerateDefaultConfig(); SaveConfig(); } } private void SaveConfig() { try { string contents = JsonWriter.ToJson((object)Config); File.WriteAllText(_whitelistConfigPath, contents); Plugin.Logger.LogInfo((object)"permission config saved."); } catch (Exception ex) { Plugin.Logger.LogError((object)("failed to save permission config: " + ex.Message)); } } private WhitelistConfig GenerateDefaultConfig() { return new WhitelistConfig { Whitelist = new Dictionary() }; } } } namespace YawOnMouse.Patches { public class PilotPlayerStatePatches { [HarmonyPatch(typeof(PilotPlayerState), "PlayerAxisControls")] private static class PlayerAxisControls { private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator il) { List list = new List(instructions); if (Plugin.AxisPatchType.Value == AxisPatchType.Roll) { return instructions; } if (Plugin.AxisPatchType.Value == AxisPatchType.Yaw) { return Yaw(list, il); } return list; } private static IEnumerable Yaw(List codes, ILGenerator il) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Expected O, but got Unknown //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Expected O, but got Unknown //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Expected O, but got Unknown //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Expected O, but got Unknown //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Expected O, but got Unknown CodeMatcher val = new CodeMatcher((IEnumerable)codes, (ILGenerator)null); MatchRollInputInstruction(val, useEnd: false); if (val.IsInvalid) { Plugin.Logger.LogError((object)"Could not find instructions for Yaw"); return codes; } int pos = val.Pos; List