diff --git a/.gitignore b/.gitignore index 9491a2f..907070a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,85 +1,42 @@ ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. -## -## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore # User-specific files -*.rsuser *.suo *.user -*.userosscache *.sln.docstates -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Mono auto generated files -mono_crash.* - # Build results [Dd]ebug/ [Dd]ebugPublic/ [Rr]elease/ -[Rr]eleases/ x64/ -x86/ -[Ww][Ii][Nn]32/ -[Aa][Rr][Mm]/ -[Aa][Rr][Mm]64/ +build/ bld/ [Bb]in/ [Oo]bj/ -[Oo]ut/ -[Ll]og/ -[Ll]ogs/ - -# Visual Studio 2015/2017 cache/options directory -.vs/ -# Uncomment if you have tasks that create the project's static files in wwwroot -#wwwroot/ - -# Visual Studio 2017 auto generated files -Generated\ Files/ # MSTest test Results [Tt]est[Rr]esult*/ [Bb]uild[Ll]og.* -# NUnit +#NUNIT *.VisualState.xml TestResult.xml -nunit-*.xml # Build Results of an ATL Project [Dd]ebugPS/ [Rr]eleasePS/ dlldata.c -# Benchmark Results -BenchmarkDotNet.Artifacts/ - -# .NET Core -project.lock.json -project.fragment.lock.json -artifacts/ - -# ASP.NET Scaffolding -ScaffoldingReadMe.txt - -# StyleCop -StyleCopReport.xml - -# Files built by Visual Studio *_i.c *_p.c -*_h.h +*_i.h *.ilk *.meta *.obj -*.iobj *.pch *.pdb -*.ipdb *.pgc *.pgd *.rsp @@ -89,7 +46,6 @@ StyleCopReport.xml *.tlh *.tmp *.tmp_proj -*_wpftmp.csproj *.log *.vspscc *.vssscc @@ -105,21 +61,14 @@ _Chutzpah* ipch/ *.aps *.ncb -*.opendb *.opensdf *.sdf *.cachefile -*.VC.db -*.VC.VC.opendb # Visual Studio profiler *.psess *.vsp *.vspx -*.sap - -# Visual Studio Trace Files -*.e2e # TFS 2012 Local Workspace $tf/ @@ -132,29 +81,19 @@ _ReSharper*/ *.[Rr]e[Ss]harper *.DotSettings.user +# JustCode is a .NET coding addin-in +.JustCode + # TeamCity is a build add-in _TeamCity* # DotCover is a Code Coverage Tool *.dotCover -# AxoCover is a Code Coverage Tool -.axoCover/* -!.axoCover/settings.json - -# Coverlet is a free, cross platform Code Coverage Tool -coverage*.json -coverage*.xml -coverage*.info - -# Visual Studio code coverage results -*.coverage -*.coveragexml - # NCrunch +*.ncrunch* _NCrunch_* .*crunch*.local.xml -nCrunchTemp_* # MightyMoose *.mm.* @@ -182,182 +121,115 @@ publish/ # Publish Web Output *.[Pp]ublish.xml *.azurePubxml -# Note: Comment the next line if you want to checkin your web deploy settings, -# but database connection strings (with potential passwords) will be unencrypted -*.pubxml -*.publishproj - -# Microsoft Azure Web App publish settings. Comment the next line if you want to -# checkin your Azure Web App publish settings, but sensitive information contained -# in these scripts will be unencrypted -PublishScripts/ - -# NuGet Packages -*.nupkg -# NuGet Symbol Packages -*.snupkg -# The packages folder can be ignored because of Package Restore -**/[Pp]ackages/* -# except build/, which is used as an MSBuild target. -!**/[Pp]ackages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/[Pp]ackages/repositories.config -# NuGet v3's project.json files produces more ignorable files -*.nuget.props -*.nuget.targets - -# Microsoft Azure Build Output + +# NuGet Packages Directory +packages/ +## TODO: If the tool you use requires repositories.config uncomment the next line +#!packages/repositories.config + +# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets +# This line needs to be after the ignore of the build folder (and the packages folder if the line above has been uncommented) +!packages/build/ + +# Windows Azure Build Output csx/ *.build.csdef -# Microsoft Azure Emulator -ecf/ -rcf/ - -# Windows Store app package directories and files +# Windows Store app package directory AppPackages/ -BundleArtifacts/ -Package.StoreAssociation.xml -_pkginfo.txt -*.appx -*.appxbundle -*.appxupload - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!?*.[Cc]ache/ # Others +sql/ +*.Cache ClientBin/ +[Ss]tyle[Cc]op.* ~$* *~ *.dbmdl *.dbproj.schemaview -*.jfm *.pfx *.publishsettings -orleans.codegen.cs - -# Including strong name files can present a security risk -# (https://github.com/github/gitignore/pull/2483#issue-259490424) -#*.snk - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) -#bower_components/ +node_modules/ # RIA/Silverlight projects Generated_Code/ -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) _UpgradeReport_Files/ Backup*/ UpgradeLog*.XML UpgradeLog*.htm -ServiceFabricBackup/ -*.rptproj.bak # SQL Server files *.mdf *.ldf -*.ndf # Business Intelligence projects *.rdl.data *.bim.layout *.bim_*.settings -*.rptproj.rsuser -*- [Bb]ackup.rdl -*- [Bb]ackup ([0-9]).rdl -*- [Bb]ackup ([0-9][0-9]).rdl # Microsoft Fakes FakesAssemblies/ -# GhostDoc plugin setting file -*.GhostDoc.xml - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat -node_modules/ - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt +# ========================= +# Operating System Files +# ========================= -# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) -*.vbw +# OSX +# ========================= -# Visual Studio LightSwitch build output -**/*.HTMLClient/GeneratedArtifacts -**/*.DesktopClient/GeneratedArtifacts -**/*.DesktopClient/ModelManifest.xml -**/*.Server/GeneratedArtifacts -**/*.Server/ModelManifest.xml -_Pvt_Extensions +.DS_Store +.AppleDouble +.LSOverride -# Paket dependency manager -.paket/paket.exe -paket-files/ +# Icon must ends with two \r. +Icon -# FAKE - F# Make -.fake/ +# Thumbnails +._* -# CodeRush personal settings -.cr/personal +# Files that might appear on external disk +.Spotlight-V100 +.Trashes -# Python Tools for Visual Studio (PTVS) -__pycache__/ -*.pyc +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk -# Cake - Uncomment if you are using it -# tools/** -# !tools/packages.config -# Tabs Studio -*.tss -# Telerik's JustMock configuration file -*.jmconfig +# Windows +# ========================= -# BizTalk build output -*.btp.cs -*.btm.cs -*.odx.cs -*.xsd.cs +# Windows image file caches +Thumbs.db +ehthumbs.db -# OpenCover UI analysis results -OpenCover/ +# Folder config file +Desktop.ini -# Azure Stream Analytics local run output -ASALocalRun/ +# Recycle Bin used on file shares +$RECYCLE.BIN/ -# MSBuild Binary and Structured Log -*.binlog +# Windows Installer files +*.cab +*.msi +*.msm +*.msp -# NVidia Nsight GPU debugger configuration file -*.nvuser +# Windows shortcuts +*.lnk -# MFractors (Xamarin productivity tool) working folder -.mfractor/ - -# Local History for Visual Studio -.localhistory/ - -# BeatPulse healthcheck temp database -healthchecksdb - -# Backup folder for Package Reference Convert tool in Visual Studio 2017 -MigrationBackup/ - -# Ionide (cross platform F# VS Code tools) working folder -.ionide/ - -# Fody - auto-generated XML schema -FodyWeavers.xsd \ No newline at end of file +# +# Vim files +# +*~ +*.swp +*.dll +*.pdb +.vs diff --git a/Changelog.txt b/Changelog.txt new file mode 100644 index 0000000..ccc615b --- /dev/null +++ b/Changelog.txt @@ -0,0 +1,6 @@ +Changelog + +2.2.0.1 + Adds option added to invert the pitch controls + Reorganized for LGG build process + Added Reflection code to allow compiling on Linux using Roslyn compiler \ No newline at end of file diff --git a/FlyByWireSASMode.sln b/FlyByWireSASMode.sln index 93d68f8..2f3bcc6 100644 --- a/FlyByWireSASMode.sln +++ b/FlyByWireSASMode.sln @@ -3,15 +3,21 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.8.34322.80 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlyByWireSASMode", "FlyByWireSASMode.csproj", "{FCE5C5F0-F2E3-41BA-A33F-0A9888E486F8}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlyByWireSASMode", "Source\FlyByWireSASMode.csproj", "{FCE5C5F0-F2E3-41BA-A33F-0A9888E486F8}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{32A9AB6B-321D-43DE-9A81-8CFF164DBE7E}" ProjectSection(SolutionItems) = preProject - GameData\FlyByWireSASMode\FlyByWireSASMode.version = GameData\FlyByWireSASMode\FlyByWireSASMode.version + buildRelease.bat = buildRelease.bat + Changelog.txt = Changelog.txt + deploy.bat = deploy.bat + FlyByWireSASMode.version = FlyByWireSASMode.version + jenkins.txt = jenkins.txt LICENSE.txt = LICENSE.txt README.md = README.md EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlyByWireSASMode-LGG", "Source\FlyByWireSASMode-LGG.csproj", "{9F83CB2E-FC26-4551-8A6A-DE18F316F556}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -22,6 +28,10 @@ Global {FCE5C5F0-F2E3-41BA-A33F-0A9888E486F8}.Debug|Any CPU.Build.0 = Debug|Any CPU {FCE5C5F0-F2E3-41BA-A33F-0A9888E486F8}.Release|Any CPU.ActiveCfg = Release|Any CPU {FCE5C5F0-F2E3-41BA-A33F-0A9888E486F8}.Release|Any CPU.Build.0 = Release|Any CPU + {9F83CB2E-FC26-4551-8A6A-DE18F316F556}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9F83CB2E-FC26-4551-8A6A-DE18F316F556}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9F83CB2E-FC26-4551-8A6A-DE18F316F556}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9F83CB2E-FC26-4551-8A6A-DE18F316F556}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/FlyByWireSASMode.version b/FlyByWireSASMode.version new file mode 100644 index 0000000..fb1fb18 --- /dev/null +++ b/FlyByWireSASMode.version @@ -0,0 +1,26 @@ +{ + "NAME": "FlyByWireSASMode", + "URL": "https://raw.githubusercontent.com/linuxgurugamer/FlyByWireSASMode/refs/heads/master/FlyByWireSASMode.version", + "DOWNLOAD": "https://github.com/linuxgurugamer/FlyByWireSASMode/releases", + "VERSION": { + "MAJOR": 2, + "MINOR": 2, + "PATCH": 0, + "BUILD": 1 + }, + "KSP_VERSION": { + "MAJOR": 1, + "MINOR": 12, + "PATCH": 5 + }, + "KSP_VERSION_MIN": { + "MAJOR": 1, + "MINOR": 12, + "PATCH": 3 + }, + "KSP_VERSION_MAX": { + "MAJOR": 1, + "MINOR": 12, + "PATCH": 5 + } +} \ No newline at end of file diff --git a/GameData/FlyByWireSASMode/FlyByWireSASMode.version b/GameData/FlyByWireSASMode/FlyByWireSASMode.version deleted file mode 100644 index 16a2e89..0000000 --- a/GameData/FlyByWireSASMode/FlyByWireSASMode.version +++ /dev/null @@ -1,9 +0,0 @@ -{ - "NAME": "FlyByWireSASMode", - "URL": "https://raw.githubusercontent.com/gotmachine/FlyByWireSASMode/master/GameData/FlyByWireSASMode/FlyByWireSASMode.version", - "DOWNLOAD": "https://github.com/gotmachine/FlyByWireSASMode/releases", - "VERSION": {"MAJOR": 1, "MINOR": 2, "PATCH": 0, "BUILD": 0}, - "KSP_VERSION": {"MAJOR": 1, "MINOR": 12, "PATCH": 5}, - "KSP_VERSION_MIN": {"MAJOR": 1, "MINOR": 12, "PATCH": 3}, - "KSP_VERSION_MAX": {"MAJOR": 1, "MINOR": 12, "PATCH": 5} -} diff --git a/GameData/FlyByWireSASMode/LICENSE.txt b/GameData/FlyByWireSASMode/LICENSE.txt new file mode 100644 index 0000000..889ef56 --- /dev/null +++ b/GameData/FlyByWireSASMode/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Gotmachine + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/GameData/FlyByWireSASMode/README.md b/GameData/FlyByWireSASMode/README.md new file mode 100644 index 0000000..7322421 --- /dev/null +++ b/GameData/FlyByWireSASMode/README.md @@ -0,0 +1,43 @@ +# FlyByWire SAS Mode + +This Kerbal Space Program plugin adds four new SAS modes and a new more relaxing way to control your vessel, especially useful for managing your gravity turns on launch : + +![Navball](https://raw.githubusercontent.com/gotmachine/FlyByWireSASMode/master/ReadMeImages/NavballScreenshot.png) + +| **Modes** | | +|:---:|---| +|![](https://raw.githubusercontent.com/gotmachine/FlyByWireSASMode/master/ReadMeImages/FlyByWire.png) | **Fly by wire**
When enabled, pitch and yaw WASD inputs don't control the vessel directly anymore, but instead control the position of a custom navball direction marker that the SAS will follow automatically. You can switch to precision mode (`Caps lock` key) for finer control.| +|![](https://raw.githubusercontent.com/gotmachine/FlyByWireSASMode/master/ReadMeImages/FlyByWirePlane.png) | **Fly by wire (plane mode)**
Identical to the fly by wire mode, but the navball marker stays at a constant position relative to the horizon.| +|![](https://raw.githubusercontent.com/gotmachine/FlyByWireSASMode/master/ReadMeImages/ParallelNeg.png) | **AntiParallel**
Available when a target is selected, will keep the vessel control part in the opposite orientation as the target. Quite useful for docking !| +|![](https://raw.githubusercontent.com/gotmachine/FlyByWireSASMode/master/ReadMeImages/ParallelPos.png) | **Parallel**
Available when a target is selected, will keep the vessel control part in the same orientation as the target.| + +These new modes are available for pilots and probe cores at the same SAS level as the target and maneuver modes, but this is configurable in the ```settings.cfg``` file (doing that with a ModuleManager patch is recommended). + +### Download and installation + +Compatible with **KSP 1.12.3** to **1.12.5** - Available on CKAN + +**Installation** + +- Go to the **[GitHub release page](https://github.com/gotmachine/FlyByWireSASMode/releases)** and download the file named `FlyByWireSASMode_x.x.x.zip` +- Open the downloaded *.zip archive +- Open the `GameData` folder of your KSP installation +- Delete any existing `FlyByWireSASMode` folder in your `GameData` folder +- Copy the `FlyByWireSASMode` folder found in the archive into your `GameData` folder + +### License + +MIT + +### Changelog + +#### 1.2.0 - 01/05/2024 +- Added plane mode +- Fixed a bug where the SAS would keep going toward the fly by wire direction after switching back to the stock stability assist mode. +- Put all icons in a single texture atlas + +#### 1.1.0 - 28/04/2024 +- Added parallel / antiparallel modes + +#### 1.0.0 - 27/04/2024 +- Inital release diff --git a/GameData/FlyByWireSASMode/Settings.cfg b/GameData/FlyByWireSASMode/Settings.cfg index baedd5a..9827243 100644 --- a/GameData/FlyByWireSASMode/Settings.cfg +++ b/GameData/FlyByWireSASMode/Settings.cfg @@ -2,4 +2,5 @@ FLYBYWIRESASMODE { RequiredSASLevel = 3 // 0 to 3 InputSensitivity = 1.0 -} \ No newline at end of file + InvertPitch = false +} diff --git a/Source/AssemblyVersion.cs b/Source/AssemblyVersion.cs new file mode 100644 index 0000000..bd41589 --- /dev/null +++ b/Source/AssemblyVersion.cs @@ -0,0 +1,9 @@ + + // This code was generated by a tool. Any changes made manually will be lost + // the next time this code is regenerated. + // + + using System.Reflection; + + [assembly: AssemblyVersion("1.2.0.1")] + [assembly: AssemblyFileVersion("1.2.0.1")] diff --git a/Source/AssemblyVersion.tt b/Source/AssemblyVersion.tt new file mode 100644 index 0000000..d0c397e --- /dev/null +++ b/Source/AssemblyVersion.tt @@ -0,0 +1,101 @@ +<#@ template debug="false" hostspecific="true" language="C#" #> +<#@ import namespace="System.IO" #> +<#@ output extension=".cs" #> + +<#@ assembly name="EnvDTE" #><# /* This assembly provides access to Visual Studio project properties. */ #> +<# + + // Instructions + // 1. Add a new Text Template to the project + // 2. Copy this file into the new template + // 3. Update the string: versionfile with the complete path to the .version file + // 4. Remove the following line from the file AssemblyInfo.cs (usually located in the "Property" folder inside your C# project): + // [assembly: AssemblyVersion("1.0.0.0")] + // 5. Add the following to the PreBuild steps: + // + // set textTemplatingPath="%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\Common7\IDE\texttransform.exe" + // %textTemplatingPath% "$(ProjectDir)AssemblyVersion.tt" + + + int major = 0; + int minor = 0; + int build = 0; + int patch = 0; + bool versionSection = false; + + int i = 0; + int i2 = 0; + string s; + + // For Visual Studio / MSBuild Build-Time Template Resolution + string RootDirectory = System.IO.Path.GetDirectoryName(Host.TemplateFile) + @"\..\"; + + // + // Update the following with the name of the .version file which is in the root directory + // + string versionfile = RootDirectory + "FlyByWireSASMode.version"; + + + if (!File.Exists(versionfile)) + { + Write("File: " + versionfile + " missing\n"); + } + + try + { + foreach (var line in File.ReadAllLines(versionfile)) + { + if (line != null) + { + if (!versionSection) + { + if (line.Contains("\"VERSION\"")) + versionSection = true; + } + else + { + if (line.Contains("}")) + versionSection = false; + i = line.IndexOf(":"); + i2 = line.IndexOf(","); + if (i2 == -1) + i2 = line.Length; + if (i >= 0 && i2 >= 0) + { + s = line.Substring(i + 1, i2 - i - 1); + + if (line.Contains("MAJOR")) + Int32.TryParse(s, out major); + + if (line.Contains("MINOR")) + Int32.TryParse(s, out minor); + + if (line.Contains("PATCH")) + Int32.TryParse(s, out patch); + + if (line.Contains("BUILD")) + Int32.TryParse(s, out build); + } + } + } + } + + } + catch + { + major = 1; + minor = 0; + patch = 0; + build = 0; + } + //Write("File done"); + + #> + // This code was generated by a tool. Any changes made manually will be lost + // the next time this code is regenerated. + // + + using System.Reflection; + + [assembly: AssemblyVersion("<#= major #>.<#= minor #>.<#= patch #>.<#= build #>")] + [assembly: AssemblyFileVersion("<#= major #>.<#= minor #>.<#= patch #>.<#= build #>")] diff --git a/Source/FlyByWireSASMode-LGG.csproj b/Source/FlyByWireSASMode-LGG.csproj new file mode 100644 index 0000000..a258bd7 --- /dev/null +++ b/Source/FlyByWireSASMode-LGG.csproj @@ -0,0 +1,140 @@ + + + + + + Debug + AnyCPU + {9F83CB2E-FC26-4551-8A6A-DE18F316F556} + Library + Properties + FlyByWireSASMode + FlyByWireSASMode + v4.7.2 + 512 + true + x64 + + + + + true + portable + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + false + portable + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + KSP_x64.exe + KSP.app + KSP.x86_64 + KSP_x64_Data\Managed + KSP.app\Contents\Resources\Data\Managed + KSP_Data\Managed + $(ReferencePath)\$(ManagedRelativePath) + Program + $(ReferencePath)\$(KSPExecutable) + $(ReferencePath) + + + + + + + + + + False + + + False + + + + + + True + True + AssemblyVersion.tt + + + + + + + + + + + + + TextTemplatingFileGenerator + AssemblyVersion.cs + + + + + + + + $(ProjectDir) + FlyByWireSASMode + false + false + FlyByWireSASMode.version + + + + + +set KSPDIR=$(KSPDIR) + +IF "%25KSPDIR%25"=="" ( + + ECHO Configuration error - KSPDIR not specified in project. + + ECHO Either set KSPDIR environment variable or edit BetterLoadSaveGame.Common.props + + PAUSE + + GOTO DONE + +) + +start /D $(SolutionDir) /WAIT deploy.bat $(TargetDir) $(TargetFileName) $(TargetName) + +if $(ConfigurationName) == Release ( + + start /D $(SolutionDir) /WAIT buildRelease.bat $(TargetDir) $(TargetFileName) $(TargetName) + +) + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + "$(DevEnvDir)\texttransform.exe" "$(ProjectDir)AssemblyVersion.tt" + + + \ No newline at end of file diff --git a/FlyByWireSASMode.cs b/Source/FlyByWireSASMode.cs similarity index 96% rename from FlyByWireSASMode.cs rename to Source/FlyByWireSASMode.cs index a890c1a..15c2505 100644 --- a/FlyByWireSASMode.cs +++ b/Source/FlyByWireSASMode.cs @@ -32,6 +32,9 @@ internal class FlyByWireSASMode : MonoBehaviour // config private static AutopilotMode requiredSASMode = AutopilotMode.Maneuver; internal static float inputSensitivity = 1f; + internal static bool invertPitch = false; + internal static KeyBinding LOCAL_PITCH_DOWN; + internal static KeyBinding LOCAL_PITCH_UP; // internal state private bool started; @@ -85,6 +88,17 @@ private void Awake() default: requiredSASMode = AutopilotMode.Maneuver; break; } } + nodes[0].TryGetValue("InvertPitch", ref invertPitch); + if (invertPitch) + { + LOCAL_PITCH_DOWN = GameSettings.PITCH_UP; + LOCAL_PITCH_UP = GameSettings.PITCH_DOWN; + } + else + { + LOCAL_PITCH_DOWN = GameSettings.PITCH_DOWN; + LOCAL_PITCH_UP = GameSettings.PITCH_UP; + } } Texture2D tex = GameDatabase.Instance.GetTexture(TEX_PATH, false); diff --git a/FlyByWireSASMode.csproj b/Source/FlyByWireSASMode.csproj similarity index 100% rename from FlyByWireSASMode.csproj rename to Source/FlyByWireSASMode.csproj diff --git a/Lib.cs b/Source/Lib.cs similarity index 100% rename from Lib.cs rename to Source/Lib.cs diff --git a/Properties/AssemblyInfo.cs b/Source/Properties/AssemblyInfo.cs similarity index 93% rename from Properties/AssemblyInfo.cs rename to Source/Properties/AssemblyInfo.cs index 97d0391..b4b83a7 100644 --- a/Properties/AssemblyInfo.cs +++ b/Source/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.2.0.0")] +//[assembly: AssemblyVersion("1.0.0.0")] +//[assembly: AssemblyFileVersion("1.2.0.0")] diff --git a/Source/VesselAutopilotAccess.cs b/Source/VesselAutopilotAccess.cs new file mode 100644 index 0000000..2f3ae42 --- /dev/null +++ b/Source/VesselAutopilotAccess.cs @@ -0,0 +1,106 @@ +#if UNIX +using System; +using System.Reflection; +using UnityEngine; // KSP1 + +public static class VesselAutopilotAccess +{ + private const BindingFlags InstAll = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; + + // Cached reflection handles + private static PropertyInfo _autopilotProp; // Vessel.autopilot + private static PropertyInfo _modeProp; // VesselAutopilot.mode + + /// + /// Get Vessel.autopilot as a strongly-typed VesselAutopilot. + /// + public static VesselAutopilot GetAutopilot(Vessel vessel) + { + if (vessel == null) throw new ArgumentNullException("vessel"); + + if (_autopilotProp == null) + { + _autopilotProp = typeof(Vessel).GetProperty("autopilot", InstAll); + } + if (_autopilotProp == null) + throw new MissingMemberException("Vessel.autopilot property not found."); + + object value = _autopilotProp.GetValue(vessel, null); + var ap = value as VesselAutopilot; + if (ap != null) + return ap; + + throw new InvalidCastException("Vessel.autopilot is not of type VesselAutopilot."); + } + + /// + /// Read VesselAutopilot.mode as VesselAutopilot.AutopilotMode. + /// + public static VesselAutopilot.AutopilotMode GetAutopilotMode(VesselAutopilot ap) + { + if (ap == null) throw new ArgumentNullException("ap"); + + if (_modeProp == null) + { + _modeProp = typeof(VesselAutopilot).GetProperty("mode", InstAll); + } + if (_modeProp == null) + throw new MissingMemberException("VesselAutopilot.mode property not found."); + + object value = _modeProp.GetValue(ap, null); + + // Direct cast if already correct type + if (value is VesselAutopilot.AutopilotMode) + return (VesselAutopilot.AutopilotMode)value; + + // Coerce from underlying numeric if needed + Type targetType = typeof(VesselAutopilot.AutopilotMode); + Type underlying = Enum.GetUnderlyingType(targetType); + object num = System.Convert.ChangeType(value, underlying); + return (VesselAutopilot.AutopilotMode)Enum.ToObject(targetType, num); + } + + /// + /// Set VesselAutopilot.mode (strongly-typed). + /// + public static void SetAutopilotMode(VesselAutopilot ap, VesselAutopilot.AutopilotMode mode) + { + if (ap == null) throw new ArgumentNullException("ap"); + + if (_modeProp == null) + { + _modeProp = typeof(VesselAutopilot).GetProperty("mode", InstAll); + } + if (_modeProp == null || !_modeProp.CanWrite) + throw new InvalidOperationException("VesselAutopilot.mode not found or not writable."); + + _modeProp.SetValue(ap, mode, null); + } + + // Optional convenience overloads: + + public static void SetAutopilotMode(VesselAutopilot ap, string modeName) + { + if (ap == null) throw new ArgumentNullException("ap"); + if (modeName == null) throw new ArgumentNullException("modeName"); + + var mode = (VesselAutopilot.AutopilotMode)Enum.Parse( + typeof(VesselAutopilot.AutopilotMode), + modeName, + false // case-sensitive as requested + ); + SetAutopilotMode(ap, mode); + } + + public static void SetAutopilotMode(VesselAutopilot ap, int modeValue) + { + if (ap == null) throw new ArgumentNullException("ap"); + + var mode = (VesselAutopilot.AutopilotMode)Enum.ToObject( + typeof(VesselAutopilot.AutopilotMode), + modeValue + ); + SetAutopilotMode(ap, mode); + } +} +#endif \ No newline at end of file diff --git a/VesselState.cs b/Source/VesselState.cs similarity index 86% rename from VesselState.cs rename to Source/VesselState.cs index bf2e46c..c7587de 100644 --- a/VesselState.cs +++ b/Source/VesselState.cs @@ -15,6 +15,9 @@ internal enum CustomSASMode internal class VesselState { public Vessel vessel; +#if UNIX + VesselAutopilot ap; +#endif public CustomSASMode sasMode; public Vector3d direction; private Vector3d previousUp; @@ -22,6 +25,9 @@ internal class VesselState public VesselState(Vessel vessel, CustomSASMode sasMode) { this.vessel = vessel; +#if UNIX + this.ap = VesselAutopilotAccess.GetAutopilot(vessel); +#endif this.sasMode = sasMode; vessel.OnPreAutopilotUpdate += OnPreAutopilotUpdate; ResetDirection(); @@ -36,13 +42,25 @@ public void ResetDirection() public void Destroy() { vessel.OnPreAutopilotUpdate -= OnPreAutopilotUpdate; +#if UNIX + + var m = VesselAutopilotAccess.GetAutopilotMode(ap); + VesselAutopilotAccess.SetAutopilotMode(ap, m); + +#else vessel.Autopilot.SetMode(vessel.autopilot.Mode); +#endif + } private void OnPreAutopilotUpdate(FlightCtrlState st) { // continuously set mode to stability assist so we know which button to disable +#if UNIX + VesselAutopilotAccess.SetAutopilotMode(ap, VesselAutopilot.AutopilotMode.StabilityAssist); +#else vessel.Autopilot.mode = VesselAutopilot.AutopilotMode.StabilityAssist; +#endif if (sasMode == CustomSASMode.FlyByWire || sasMode == CustomSASMode.FlyByWirePlaneMode) { @@ -56,9 +74,9 @@ private void OnPreAutopilotUpdate(FlightCtrlState st) bool precisionMode = FlightInputHandler.fetch.precisionMode; double pitch = GameSettings.AXIS_PITCH.GetAxis(); - if (GameSettings.PITCH_DOWN.GetKey()) - pitch = precisionMode ? -0.25 : - 1.0; - else if (GameSettings.PITCH_UP.GetKey()) + if (FlyByWireSASMode.LOCAL_PITCH_DOWN.GetKey()) + pitch = precisionMode ? -0.25 : - 1.0; + else if (FlyByWireSASMode.LOCAL_PITCH_UP.GetKey()) pitch = precisionMode ? 0.25 : 1.0; double yaw = GameSettings.AXIS_YAW.GetAxis(); diff --git a/buildRelease.bat b/buildRelease.bat new file mode 100644 index 0000000..051a5ce --- /dev/null +++ b/buildRelease.bat @@ -0,0 +1,74 @@ + +@echo off + +rem Put the following text into the Post-build event command line: +rem without the "rem": + +rem start /D D:\Users\jbb\github\IFI-Life-Support /WAIT deploy.bat $(TargetDir) $(TargetFileName) +rem +rem if $(ConfigurationName) == Release ( +rem +rem start /D D:\Users\jbb\github\IFI-Life-Support /WAIT buildRelease.bat $(TargetDir) $(TargetFileName) +rem +rem ) + + +rem Set variables here + +rem H is the destination game folder +rem GAMEDIR is the name of the mod folder (usually the mod name) +rem GAMEDATA is the name of the local GameData +rem VERSIONFILE is the name of the version file, usually the same as GAMEDATA, +rem but not always +rem LICENSE is the license file +rem README is the readme file + +set GAMEDIR=FlyByWireSASMode +set GAMEDATA="GameData\" +set VERSIONFILE=%GAMEDIR%.version +set LICENSE=License.txt +set README=ReadMe.md + +set RELEASEDIR=d:\Users\jbb\release +set ZIP="c:\Program Files\7-zip\7z.exe" + +rem Copy files to GameData locations + +copy /Y "%1%2" "%GAMEDATA%\%GAMEDIR%\Plugins" +copy /Y %VERSIONFILE% %GAMEDATA%\%GAMEDIR%\Plugins + +if "%LICENSE%" NEQ "" copy /y %LICENSE% %GAMEDATA%\%GAMEDIR% +if "%README%" NEQ "" copy /Y %README% %GAMEDATA%\%GAMEDIR% + +rem Get Version info + +copy %VERSIONFILE% tmp.version +set VERSIONFILE=tmp.version +rem The following requires the JQ program, available here: https://stedolan.github.io/jq/download/ +c:\local\jq-win64 ".VERSION.MAJOR" %VERSIONFILE% >tmpfile +set /P major=tmpfile +set /P minor=tmpfile +set /P patch=tmpfile +set /P build= - + \ No newline at end of file