├── PhysicsRangeExtender ├── LocalDev │ ├── 7za_dir.txt │ ├── pdb2mdb_exe.txt │ ├── dist_dir.txt │ ├── ksp_dir.txt │ ├── ksp_dir2.txt │ └── mono_exe.txt ├── Distribution │ └── GameData │ │ └── PhysicsRangeExtender │ │ ├── settings.cfg │ │ ├── Textures │ │ └── icon.png │ │ ├── Plugins │ │ └── PhysicsRangeExtender.dll │ │ ├── README.md │ │ ├── PhysicsRangeExtender.version │ │ ├── LICENSE.txt │ │ └── ChangeLog.txt ├── PRExtensions.cs ├── PhysicsRangeExtender.sln ├── Properties │ └── AssemblyInfo.cs ├── PRESettings.cs ├── PhysicsRangeExtender.csproj ├── Gui.cs ├── TerrainExtender.cs └── PhysicsRangeExtender.cs ├── README.md ├── LICENSE └── .gitignore /PhysicsRangeExtender/LocalDev/7za_dir.txt: -------------------------------------------------------------------------------- 1 | D:\PROGRAMS\7za\x64 -------------------------------------------------------------------------------- /PhysicsRangeExtender/LocalDev/pdb2mdb_exe.txt: -------------------------------------------------------------------------------- 1 | G:\pdb2mdb\pdb2mdb.exe -------------------------------------------------------------------------------- /PhysicsRangeExtender/LocalDev/dist_dir.txt: -------------------------------------------------------------------------------- 1 | E:\PROGRAMACION\KSP_Development -------------------------------------------------------------------------------- /PhysicsRangeExtender/LocalDev/ksp_dir.txt: -------------------------------------------------------------------------------- 1 | D:\GAMES\KERBAL\Kerbal Space Program_112_DEV -------------------------------------------------------------------------------- /PhysicsRangeExtender/LocalDev/ksp_dir2.txt: -------------------------------------------------------------------------------- 1 | G:\GAMES\KERBAL\Kerbal Space Program_191_DEVM2 -------------------------------------------------------------------------------- /PhysicsRangeExtender/LocalDev/mono_exe.txt: -------------------------------------------------------------------------------- 1 | D:\PROGRAMS\Unity\Editor\Data\MonoBleedingEdge\bin -------------------------------------------------------------------------------- /PhysicsRangeExtender/Distribution/GameData/PhysicsRangeExtender/settings.cfg: -------------------------------------------------------------------------------- 1 | PreSettings 2 | { 3 | GlobalRange = 100 4 | ModEnabled = True 5 | CamFixMultiplier = 1.0 6 | TerrainExtenderEnabled = True 7 | } 8 | -------------------------------------------------------------------------------- /PhysicsRangeExtender/Distribution/GameData/PhysicsRangeExtender/Textures/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrodrigv/PhysicsRangeExtender/HEAD/PhysicsRangeExtender/Distribution/GameData/PhysicsRangeExtender/Textures/icon.png -------------------------------------------------------------------------------- /PhysicsRangeExtender/Distribution/GameData/PhysicsRangeExtender/Plugins/PhysicsRangeExtender.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrodrigv/PhysicsRangeExtender/HEAD/PhysicsRangeExtender/Distribution/GameData/PhysicsRangeExtender/Plugins/PhysicsRangeExtender.dll -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PhysicsRangeExtender 2 | This is a KSP mod based on a piece of code written by BahamutoD for BDArmory and improved by myself. 3 | 4 | Basically it extends game physics range(1)! This will allow you to switch between vessel that are far away or even to see an orbital station from a flying plane. 5 | 6 | (1) This mod allows to extended the physics range but it will not prevent the consecuences of doing it. 7 | 8 | You might experience some of the following effects when the range is extended > 100 km: vessel shaking, lights flickering, phatom forces, landed vessels colliding with the ground, etc. 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /PhysicsRangeExtender/Distribution/GameData/PhysicsRangeExtender/README.md: -------------------------------------------------------------------------------- 1 | # PhysicsRangeExtender 2 | This is a KSP mod based on a piece of code written by BahamutoD for BDArmory and improved by myself. 3 | 4 | Basically it extends game physics range(1)! This will allow you to switch between vessel that are far away or even to see an orbital station from a flying plane. 5 | 6 | (1) This mod allows to extended the physics range but it will not prevent the consecuences of doing it. 7 | 8 | You might experience some of the following effects when the range is extended > 100 km: vessel shaking, lights flickering, phatom forces, landed vessels colliding with the ground, etc. 9 | -------------------------------------------------------------------------------- /PhysicsRangeExtender/Distribution/GameData/PhysicsRangeExtender/PhysicsRangeExtender.version: -------------------------------------------------------------------------------- 1 | { 2 | "NAME": "PhysicsRangeExtender", 3 | "URL":"https://github.com/jrodrigv/PhysicsRangeExtender/raw/master/PhysicsRangeExtender/Distribution/GameData/PhysicsRangeExtender/PhysicsRangeExtender.version", 4 | "DOWNLOAD":"https://github.com/jrodrigv/PhysicsRangeExtender/releases/tag/1.21.0", 5 | "CHANGE_LOG_URL":"https://github.com/jrodrigv/PhysicsRangeExtender/raw/master/PhysicsRangeExtender/Distribution/GameData/PhysicsRangeExtender/ChangeLog.txt", 6 | "VERSION": { 7 | "MAJOR": 1, 8 | "MINOR": 21, 9 | "PATCH": 0 10 | }, 11 | "KSP_VERSION": { 12 | "MAJOR": 1, 13 | "MINOR": 12, 14 | "PATCH": 2 15 | }, 16 | "KSP_VERSION_MIN": { 17 | "MAJOR": 1, 18 | "MINOR": 12, 19 | "PATCH": 2 20 | }, 21 | "KSP_VERSION_MAX": { 22 | "MAJOR": 1, 23 | "MINOR": 12, 24 | "PATCH": 99 25 | } 26 | } -------------------------------------------------------------------------------- /PhysicsRangeExtender/PRExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System; 3 | using UniLinq; 4 | using UnityEngine; 5 | 6 | namespace PhysicsRangeExtender 7 | { 8 | public static class PRExtensions 9 | { 10 | public static bool _wasEnabled = false; 11 | 12 | public static void PreOn(string _modName) 13 | { 14 | if (!PreSettings.ModEnabled && _wasEnabled) 15 | { 16 | Debug.Log("[Physic Range Extender] === Being turned on by " + _modName); 17 | 18 | PreSettings.ModEnabled = true; 19 | Gui.Fetch.Apply(); 20 | PreSettings.SaveConfig(); 21 | } 22 | } 23 | 24 | public static void PreOff(string _modName) 25 | { 26 | if (PreSettings.ModEnabled) 27 | { 28 | _wasEnabled = true; 29 | Debug.Log("[Physic Range Extender] === Being turned off by " + _modName); 30 | PreSettings.ModEnabled = false; 31 | PhysicsRangeExtender.RestoreStockRanges(); 32 | PreSettings.SaveConfig(); 33 | } 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /PhysicsRangeExtender/PhysicsRangeExtender.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2000 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PhysicsRangeExtender", "PhysicsRangeExtender.csproj", "{08525C2E-78B0-4105-B56C-45F8936C6302}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {08525C2E-78B0-4105-B56C-45F8936C6302}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {08525C2E-78B0-4105-B56C-45F8936C6302}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {08525C2E-78B0-4105-B56C-45F8936C6302}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {08525C2E-78B0-4105-B56C-45F8936C6302}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {E5AD86CF-BC04-4D47-A332-5CC5C512458B} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /PhysicsRangeExtender/Distribution/GameData/PhysicsRangeExtender/LICENSE.txt: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /PhysicsRangeExtender/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("PhysicsRangeExtender")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("PhysicsRangeExtender")] 12 | [assembly: AssemblyCopyright("Jesús Rodríguez Valencia")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("08525c2e-78b0-4105-b56c-45f8936c6302")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.21.0")] 35 | -------------------------------------------------------------------------------- /PhysicsRangeExtender/PRESettings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace PhysicsRangeExtender 5 | { 6 | [KSPAddon(KSPAddon.Startup.Instantly, false)] 7 | public class PreSettings : MonoBehaviour 8 | { 9 | public static string SettingsConfigUrl = "GameData/PhysicsRangeExtender/settings.cfg"; 10 | public static int GlobalRange { get; set; } 11 | 12 | public static float CamFixMultiplier { get; set; } 13 | 14 | public static bool ConfigLoaded { get; set; } = false; 15 | public static bool ModEnabled { get; set; } 16 | public static bool TerrainExtenderEnabled { get; set; } 17 | 18 | void Awake() 19 | { 20 | LoadConfig(); 21 | ConfigLoaded = true; 22 | } 23 | 24 | public static void LoadConfig() 25 | { 26 | try 27 | { 28 | Debug.Log("[PhysicsRangeExtender]: Loading settings.cfg =="); 29 | 30 | ConfigNode fileNode = ConfigNode.Load(SettingsConfigUrl); 31 | if (!fileNode.HasNode("PreSettings")) return; 32 | 33 | ConfigNode settings = fileNode.GetNode("PreSettings"); 34 | GlobalRange = int.Parse(settings.GetValue("GlobalRange")); 35 | CamFixMultiplier = float.Parse(settings.GetValue("CamFixMultiplier")); 36 | ModEnabled = bool.Parse(settings.GetValue("ModEnabled")); 37 | TerrainExtenderEnabled = bool.Parse(settings.GetValue("TerrainExtenderEnabled")); 38 | } 39 | catch (Exception ex) 40 | { 41 | Debug.Log("[PhysicsRangeExtender]: Failed to load settings config:" + ex.Message); 42 | } 43 | } 44 | 45 | public static void SaveConfig() 46 | { 47 | try 48 | { 49 | Debug.Log("[PhysicsRangeExtender]: Saving settings.cfg =="); 50 | ConfigNode fileNode = ConfigNode.Load(SettingsConfigUrl); 51 | if (!fileNode.HasNode("PreSettings")) return; 52 | ConfigNode settings = fileNode.GetNode("PreSettings"); 53 | 54 | settings.SetValue("GlobalRange", GlobalRange); 55 | settings.SetValue("CamFixMultiplier", CamFixMultiplier); 56 | settings.SetValue("ModEnabled", ModEnabled); 57 | settings.SetValue("TerrainExtenderEnabled", TerrainExtenderEnabled); 58 | fileNode.Save(SettingsConfigUrl); 59 | } 60 | catch (Exception ex) 61 | { 62 | Debug.Log("[PhysicsRangeExtender]: Failed to save settings config:" + ex.Message); throw; 63 | } 64 | } 65 | 66 | 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /PhysicsRangeExtender/Distribution/GameData/PhysicsRangeExtender/ChangeLog.txt: -------------------------------------------------------------------------------- 1 | = v1.21.0 2 | - Recompiled for KSP 1.12.2 3 | 4 | = v1.20.0 5 | - Recompiled for KSP 1.11.0 6 | - Improved physics ease/landing method when TerrainExtender is Enabled 7 | 8 | - Recompiled for KSP 1.9.1 9 | - Fixed critical issue causing KSP to crash when extending terrain in other planets like Moon in RSS. 10 | - Fixed NREs issue when extending terrain in orbit around the Sun 11 | - Increased Crash Tolerance in landed vessel when loaded to avoid RUDs due to physics. 12 | 13 | = v1.18.0 14 | - Recompiled for KSP 1.9.0 15 | - Fixed issue were the camera was broken after switching to a new landed vessel if the active vessel was in IVA. 16 | 17 | = v1.17.0 18 | - Recompiled for KSP 1.8.1 19 | - Added extension method for other mods to enable/disable PRE if needed (Thanks to @DoctorDavinci) 20 | 21 | = v1.16.0 22 | - Recompiled for KSP 1.8.0 23 | 24 | = v1.15.0 25 | - Fixes issue were the initial loading was triggered when a 2nd vessel was loaded. 26 | - Fixes issue in which the active vessel was lifted. 27 | 28 | = v1.14.0 29 | - Hotfixes for KSP 1.7.2. 30 | - Flickering improvements for low altitude vessels. 31 | 32 | = v1.13.0 33 | - Fixes to terrain extender to avoid landed vessels to crash. 34 | - Recompiled for KSP 1.7.2 35 | 36 | = v1.12.0 37 | - More improvements for landing of boosters. 38 | 39 | = v1.11.0 40 | - Full rework of Terrain Extender to enable reusability of boosters. 41 | 42 | = v1.10.0 43 | - Recompiled for KSP 1.7.0 44 | - Fixed critical issue which make landed vessel to crash through the ground when entering into physics range. 45 | 46 | = v1.9.0 47 | - Recompiled for KSP 1.6.0 48 | - Added the Cam fix multiplier option so users can tweak the camera distance if they are not happy with the fix. 49 | (Bear in mind that the camera fix is the only way to prevent the flickering when the active vessel is very far from the floating origin) 50 | 51 | = v1.8.0 52 | - Recompiled for KSP 1.5.1 53 | - Default range reduced to 50 km 54 | - UI simplifed. Removing options that were not used 55 | - Added button to disable de mod. 56 | - Added message to warn the user when the flickering fix is activated. 57 | 58 | = v1.7.0 59 | - Recompiled and upgraded for KSP 1.4.3 60 | - Adding option to extend terrain loading distance (thanks to Gedas) 61 | - Flickering fixed at 99% after applying a dynamic update of the near clip plane of the main camera. 62 | - Landed range removed, only one range is needed now :) 63 | 64 | = v1.6.0 65 | - Recompiled and upgraded for KSP 1.4 66 | 67 | = v1.5.0 68 | - Fixes de-orbit vessels when entering Global Range distance. 69 | - Unload landed or splashed vessels to prevent its destruction when the active vessel is about to change its reference frame (from rotation to inertial). 70 | - If the user decide to increase the range while there are orbiting vessels unloaded. 71 | The new range will not be applied to these vessels to prevent de-orbiting. The game should be saved and loaded again for safety. 72 | - A new toggle button has been added to the UI allowing to "Force" the ranges, overriding all the safety checks. 73 | (This may cause undesired effects like orbiting vessels de-orbit or landed vessels destruction) 74 | - New screen messages have been added to inform the user about events. 75 | - PRE icon visible in all scenes 76 | 77 | = v1.4.0 78 | - Recompiled for KSP 1.3 79 | = v1.3.0 80 | - Added GUI to enable/disable the mod and adjust the ranges 81 | - Several code improvements 82 | = v1.2.0 83 | - Added settings.cfg to allow adjust the ranges. 84 | RangeForLandedVessels: parameter that can be reduced in order to avoid landed vessels to crash into the terrain 85 | GlobalRange: For all scenarios different than Landed. 86 | = v1.1.0 87 | - Extending to 2000km. Compiled for KSP 1.2.9 88 | = v1.0.0 89 | - Release -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | *.VC.VC.opendb 85 | 86 | # Visual Studio profiler 87 | *.psess 88 | *.vsp 89 | *.vspx 90 | *.sap 91 | 92 | # TFS 2012 Local Workspace 93 | $tf/ 94 | 95 | # Guidance Automation Toolkit 96 | *.gpState 97 | 98 | # ReSharper is a .NET coding add-in 99 | _ReSharper*/ 100 | *.[Rr]e[Ss]harper 101 | *.DotSettings.user 102 | 103 | # JustCode is a .NET coding add-in 104 | .JustCode 105 | 106 | # TeamCity is a build add-in 107 | _TeamCity* 108 | 109 | # DotCover is a Code Coverage Tool 110 | *.dotCover 111 | 112 | # NCrunch 113 | _NCrunch_* 114 | .*crunch*.local.xml 115 | nCrunchTemp_* 116 | 117 | # MightyMoose 118 | *.mm.* 119 | AutoTest.Net/ 120 | 121 | # Web workbench (sass) 122 | .sass-cache/ 123 | 124 | # Installshield output folder 125 | [Ee]xpress/ 126 | 127 | # DocProject is a documentation generator add-in 128 | DocProject/buildhelp/ 129 | DocProject/Help/*.HxT 130 | DocProject/Help/*.HxC 131 | DocProject/Help/*.hhc 132 | DocProject/Help/*.hhk 133 | DocProject/Help/*.hhp 134 | DocProject/Help/Html2 135 | DocProject/Help/html 136 | 137 | # Click-Once directory 138 | publish/ 139 | 140 | # Publish Web Output 141 | *.[Pp]ublish.xml 142 | *.azurePubxml 143 | # TODO: Comment the next line if you want to checkin your web deploy settings 144 | # but database connection strings (with potential passwords) will be unencrypted 145 | *.pubxml 146 | *.publishproj 147 | 148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 149 | # checkin your Azure Web App publish settings, but sensitive information contained 150 | # in these scripts will be unencrypted 151 | PublishScripts/ 152 | 153 | # NuGet Packages 154 | *.nupkg 155 | # The packages folder can be ignored because of Package Restore 156 | **/packages/* 157 | # except build/, which is used as an MSBuild target. 158 | !**/packages/build/ 159 | # Uncomment if necessary however generally it will be regenerated when needed 160 | #!**/packages/repositories.config 161 | # NuGet v3's project.json files produces more ignoreable files 162 | *.nuget.props 163 | *.nuget.targets 164 | 165 | # Microsoft Azure Build Output 166 | csx/ 167 | *.build.csdef 168 | 169 | # Microsoft Azure Emulator 170 | ecf/ 171 | rcf/ 172 | 173 | # Windows Store app package directories and files 174 | AppPackages/ 175 | BundleArtifacts/ 176 | Package.StoreAssociation.xml 177 | _pkginfo.txt 178 | 179 | # Visual Studio cache files 180 | # files ending in .cache can be ignored 181 | *.[Cc]ache 182 | # but keep track of directories ending in .cache 183 | !*.[Cc]ache/ 184 | 185 | # Others 186 | ClientBin/ 187 | ~$* 188 | *~ 189 | *.dbmdl 190 | *.dbproj.schemaview 191 | *.pfx 192 | *.publishsettings 193 | node_modules/ 194 | orleans.codegen.cs 195 | 196 | # Since there are multiple workflows, uncomment next line to ignore bower_components 197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 198 | #bower_components/ 199 | 200 | # RIA/Silverlight projects 201 | Generated_Code/ 202 | 203 | # Backup & report files from converting an old project file 204 | # to a newer Visual Studio version. Backup files are not needed, 205 | # because we have git ;-) 206 | _UpgradeReport_Files/ 207 | Backup*/ 208 | UpgradeLog*.XML 209 | UpgradeLog*.htm 210 | 211 | # SQL Server files 212 | *.mdf 213 | *.ldf 214 | 215 | # Business Intelligence projects 216 | *.rdl.data 217 | *.bim.layout 218 | *.bim_*.settings 219 | 220 | # Microsoft Fakes 221 | FakesAssemblies/ 222 | 223 | # GhostDoc plugin setting file 224 | *.GhostDoc.xml 225 | 226 | # Node.js Tools for Visual Studio 227 | .ntvs_analysis.dat 228 | 229 | # Visual Studio 6 build log 230 | *.plg 231 | 232 | # Visual Studio 6 workspace options file 233 | *.opt 234 | 235 | # Visual Studio LightSwitch build output 236 | **/*.HTMLClient/GeneratedArtifacts 237 | **/*.DesktopClient/GeneratedArtifacts 238 | **/*.DesktopClient/ModelManifest.xml 239 | **/*.Server/GeneratedArtifacts 240 | **/*.Server/ModelManifest.xml 241 | _Pvt_Extensions 242 | 243 | # Paket dependency manager 244 | .paket/paket.exe 245 | paket-files/ 246 | 247 | # FAKE - F# Make 248 | .fake/ 249 | 250 | # JetBrains Rider 251 | .idea/ 252 | *.sln.iml 253 | /PhysicsRangeExtender/LocalDev/KSPRefs 254 | -------------------------------------------------------------------------------- /PhysicsRangeExtender/PhysicsRangeExtender.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {08525C2E-78B0-4105-B56C-45F8936C6302} 8 | Library 9 | Properties 10 | PhysicsRangeExtender 11 | PhysicsRangeExtender 12 | v4.7.2 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | false 25 | 26 | 27 | pdbonly 28 | true 29 | bin\Release\ 30 | 31 | 32 | prompt 33 | 4 34 | false 35 | default 36 | 37 | 38 | 39 | False 40 | E:\REPOSITORIO\_LocalDev\KSPRefs\Assembly-CSharp.dll 41 | 42 | 43 | False 44 | E:\REPOSITORIO\_LocalDev\KSPRefs\KSPAssets.dll 45 | 46 | 47 | 48 | False 49 | E:\REPOSITORIO\_LocalDev\KSPRefs\UnityEngine.dll 50 | 51 | 52 | E:\REPOSITORIO\_LocalDev\KSPRefs\UnityEngine.AnimationModule.dll 53 | 54 | 55 | E:\REPOSITORIO\_LocalDev\KSPRefs\UnityEngine.AssetBundleModule.dll 56 | 57 | 58 | E:\REPOSITORIO\_LocalDev\KSPRefs\UnityEngine.CoreModule.dll 59 | 60 | 61 | E:\REPOSITORIO\_LocalDev\KSPRefs\UnityEngine.ImageConversionModule.dll 62 | 63 | 64 | E:\REPOSITORIO\_LocalDev\KSPRefs\UnityEngine.IMGUIModule.dll 65 | 66 | 67 | E:\REPOSITORIO\_LocalDev\KSPRefs\UnityEngine.PhysicsModule.dll 68 | 69 | 70 | E:\REPOSITORIO\_LocalDev\KSPRefs\UnityEngine.TextCoreModule.dll 71 | 72 | 73 | E:\REPOSITORIO\_LocalDev\KSPRefs\UnityEngine.TextRenderingModule.dll 74 | 75 | 76 | False 77 | E:\REPOSITORIO\_LocalDev\KSPRefs\UnityEngine.UI.dll 78 | 79 | 80 | E:\REPOSITORIO\_LocalDev\KSPRefs\UnityEngine.UIElementsModule.dll 81 | 82 | 83 | E:\REPOSITORIO\_LocalDev\KSPRefs\UnityEngine.UIModule.dll 84 | 85 | 86 | E:\REPOSITORIO\_LocalDev\KSPRefs\UnityEngine.UnityWebRequestWWWModule.dll 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | @echo $(Targetname) 116 | @echo ... 117 | @echo set lpath vars from LocalDev storage... 118 | set /p KSP_DIR=<"$(ProjectDir)LocalDev\ksp_dir.txt" 119 | set /p PDB2MDB_EXE=<"$(ProjectDir)LocalDev\pdb2mdb_exe.txt" 120 | set /p ZA_DIR=<"$(ProjectDir)LocalDev\7za_dir.txt" 121 | set /p DIST_DIR=<"$(ProjectDir)LocalDev\dist_dir.txt" 122 | 123 | @echo distributing $(Targetname) files... 124 | copy /Y "$(TargetPath)" "$(ProjectDir)Distribution\GameData\$(Targetname)\Plugins\" 125 | copy /Y "$(TargetDir)CLSInterfaces.dll" "$(ProjectDir)Distribution\GameData\$(Targetname)\Plugins\" 126 | 127 | @echo building $(Targetname).dll.mdb file... 128 | cd "$(TargetDir)" 129 | call "%25PDB2MDB_EXE%25" $(Targetname).dll 130 | 131 | copy /Y "$(TargetDir)$(Targetname).dll.mdb" "%25KSP_DIR%25\GameData\$(Targetname)\Plugins\" 132 | 133 | @echo packaging files... 134 | if exist "E:\PROGRAMACION\KSP_Development\Releases\$(Targetname)\Build\$(Targetname)*.zip" del "E:\PROGRAMACION\KSP_Development\Releases\$(Targetname)\Build\$(Targetname)*.zip" 135 | call "%25ZA_DIR%25\7za.exe" a -tzip -r "%25DIST_DIR%25\$(Targetname).@(VersionNumber)_%25DATE:~4,2%25%25DATE:~7,2%25%25DATE:~10,4%25.zip" "$(ProjectDir)Distribution\*.*" 136 | 137 | @echo Deploy $(Targetname) Distribution files from $(SolutionDir)Distribution\GameData, 138 | @echo to test env: %25KSP_DIR%25\GameData... 139 | xcopy /E /Y "$(SolutionDir)Distribution\GameData" "%25KSP_DIR%25\GameData" 140 | copy /Y "$(TargetDir)$(Targetname).pdb" "%25KSP_DIR%25\GameData\$(Targetname)\Plugins\" 141 | 142 | @echo Build/deploy complete! 143 | 144 | 145 | 152 | -------------------------------------------------------------------------------- /PhysicsRangeExtender/Gui.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using KSP.UI.Screens; 4 | using UnityEngine; 5 | 6 | // ReSharper disable NotAccessedField.Local 7 | 8 | namespace PhysicsRangeExtender 9 | { 10 | [KSPAddon(KSPAddon.Startup.Flight, false)] 11 | public class Gui : MonoBehaviour 12 | { 13 | private const float WindowWidth = 250; 14 | private const float DraggableHeight = 40; 15 | private const float LeftIndent = 12; 16 | private const float ContentTop = 20; 17 | public static Gui Fetch; 18 | public static bool GuiEnabled; 19 | private ApplicationLauncherButton button = null; 20 | private readonly float _incrButtonWidth = 26; 21 | private readonly float contentWidth = WindowWidth - 2 * LeftIndent; 22 | private readonly float entryHeight = 20; 23 | 24 | private bool _gameUiToggle; 25 | private string _guiGlobalRangeForVessels = String.Empty; 26 | 27 | private float _windowHeight = 250; 28 | private Rect _windowRect; 29 | private string _guiCamFixMultiplier; 30 | 31 | private void Awake() 32 | { 33 | if (Fetch) 34 | Destroy(Fetch); 35 | 36 | Fetch = this; 37 | } 38 | 39 | private void Start() 40 | { 41 | _windowRect = new Rect(Screen.width - WindowWidth - 40, 100, WindowWidth, _windowHeight); 42 | AddToolbarButton(); 43 | GameEvents.onHideUI.Add(GameUiDisable); 44 | GameEvents.onShowUI.Add(GameUiEnable); 45 | _gameUiToggle = true; 46 | _guiGlobalRangeForVessels = PreSettings.GlobalRange.ToString(); 47 | _guiCamFixMultiplier = PreSettings.CamFixMultiplier.ToString(CultureInfo.InvariantCulture); 48 | } 49 | 50 | private void OnDestroy() 51 | { 52 | GameEvents.onShowUI.Remove(GameUiEnable); 53 | GameEvents.onHideUI.Remove(GameUiDisable); 54 | ApplicationLauncher.Instance.RemoveModApplication(this.button); 55 | this.button = null; 56 | } 57 | 58 | // ReSharper disable once InconsistentNaming 59 | private void OnGUI() 60 | { 61 | if (!PreSettings.ConfigLoaded) return; 62 | if (GuiEnabled && _gameUiToggle) 63 | _windowRect = GUI.Window(320, _windowRect, GuiWindow, ""); 64 | } 65 | 66 | private void GuiWindow(int windowId) 67 | { 68 | GUI.DragWindow(new Rect(0, 0, WindowWidth, DraggableHeight)); 69 | float line = 0; 70 | 71 | 72 | DrawTitle(); 73 | line++; 74 | if (PreSettings.ModEnabled) 75 | { 76 | DrawGlobalVesselRange(line); 77 | line++; 78 | DrawCamFixMultiplier(line); 79 | line++; 80 | DrawSaveButton(line); 81 | line++; 82 | } 83 | DisableMod(line); 84 | 85 | 86 | _windowHeight = ContentTop + line * entryHeight + entryHeight + entryHeight; 87 | _windowRect.height = _windowHeight; 88 | } 89 | 90 | private void DisableMod(float line) 91 | { 92 | var saveRect = new Rect(LeftIndent, ContentTop + line * entryHeight, contentWidth, entryHeight); 93 | 94 | 95 | if (PreSettings.ModEnabled) 96 | { 97 | if (GUI.Button(saveRect, "Disable Mod")) 98 | { 99 | PreSettings.ModEnabled = false; 100 | PhysicsRangeExtender.RestoreStockRanges(); 101 | PreSettings.SaveConfig(); 102 | } 103 | } 104 | else 105 | { 106 | if (GUI.Button(saveRect, "Enable Mod")) 107 | { 108 | PreSettings.ModEnabled = true; 109 | Apply(); 110 | PreSettings.SaveConfig(); 111 | } 112 | } 113 | } 114 | 115 | 116 | private void DrawGlobalVesselRange(float line) 117 | { 118 | var leftLabel = new GUIStyle 119 | { 120 | alignment = TextAnchor.UpperLeft, 121 | normal = {textColor = Color.white} 122 | }; 123 | 124 | GUI.Label(new Rect(LeftIndent, ContentTop + line * entryHeight, 60, entryHeight), "Global range:", 125 | leftLabel); 126 | float textFieldWidth = 42; 127 | var fwdFieldRect = new Rect(LeftIndent + contentWidth - textFieldWidth - 3 * _incrButtonWidth, 128 | ContentTop + line * entryHeight, textFieldWidth, entryHeight); 129 | _guiGlobalRangeForVessels = GUI.TextField(fwdFieldRect, _guiGlobalRangeForVessels); 130 | 131 | } 132 | 133 | private void DrawCamFixMultiplier(float line) 134 | { 135 | var leftLabel = new GUIStyle 136 | { 137 | alignment = TextAnchor.UpperLeft, 138 | normal = { textColor = Color.white } 139 | }; 140 | 141 | GUI.Label(new Rect(LeftIndent, ContentTop + line * entryHeight, 60, entryHeight), "Cam fix multiplier:", 142 | leftLabel); 143 | float textFieldWidth = 42; 144 | var fwdFieldRect = new Rect(LeftIndent + contentWidth - textFieldWidth - 3 * _incrButtonWidth, 145 | ContentTop + line * entryHeight, textFieldWidth, entryHeight); 146 | 147 | this._guiCamFixMultiplier = GUI.TextField(fwdFieldRect, _guiCamFixMultiplier); 148 | 149 | } 150 | 151 | private void DrawSaveButton(float line) 152 | { 153 | var saveRect = new Rect(LeftIndent, ContentTop + line * entryHeight, contentWidth / 2, entryHeight); 154 | if (GUI.Button(saveRect, "Apply new range")) 155 | Apply(); 156 | } 157 | 158 | public void Apply() 159 | { 160 | if (int.TryParse(_guiGlobalRangeForVessels, out var parseGlobalRange)) 161 | { 162 | PreSettings.GlobalRange = parseGlobalRange; 163 | _guiGlobalRangeForVessels = PreSettings.GlobalRange.ToString(); 164 | } 165 | 166 | if (float.TryParse(_guiCamFixMultiplier, out var parseCamFix)) 167 | { 168 | PreSettings.CamFixMultiplier = parseCamFix; 169 | _guiCamFixMultiplier = PreSettings.CamFixMultiplier.ToString(CultureInfo.InvariantCulture); 170 | } 171 | 172 | 173 | PreSettings.SaveConfig(); 174 | PhysicsRangeExtender.UpdateRanges(true); 175 | } 176 | 177 | private void DrawTitle() 178 | { 179 | var centerLabel = new GUIStyle 180 | { 181 | alignment = TextAnchor.UpperCenter, 182 | normal = {textColor = Color.white} 183 | }; 184 | var titleStyle = new GUIStyle(centerLabel) 185 | { 186 | fontSize = 10, 187 | alignment = TextAnchor.MiddleCenter 188 | }; 189 | GUI.Label(new Rect(0, 0, WindowWidth, 20), "Physics Range Extender", titleStyle); 190 | } 191 | 192 | private void AddToolbarButton() 193 | { 194 | if (null == this.button) 195 | { 196 | Texture buttonTexture = GameDatabase.Instance.GetTexture("PhysicsRangeExtender/Textures/icon", false); 197 | this.button = ApplicationLauncher.Instance.AddModApplication( 198 | EnableGui, DisableGui, Dummy, Dummy, Dummy, Dummy, 199 | ApplicationLauncher.AppScenes.ALWAYS, buttonTexture 200 | ); 201 | } 202 | } 203 | 204 | private void EnableGui() 205 | { 206 | GuiEnabled = true; 207 | Debug.Log("[PhysicsRangeExtender]: Showing PRE GUI"); 208 | } 209 | 210 | private void DisableGui() 211 | { 212 | GuiEnabled = false; 213 | Debug.Log("[PhysicsRangeExtender]: Hiding PRE GUI"); 214 | } 215 | 216 | private void Dummy() 217 | { 218 | } 219 | 220 | private void GameUiEnable() 221 | { 222 | _gameUiToggle = true; 223 | } 224 | 225 | private void GameUiDisable() 226 | { 227 | _gameUiToggle = false; 228 | } 229 | } 230 | } -------------------------------------------------------------------------------- /PhysicsRangeExtender/TerrainExtender.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using UnityEngine; 5 | 6 | namespace PhysicsRangeExtender 7 | { 8 | [KSPAddon(KSPAddon.Startup.Flight, false)] 9 | public class TerrainExtender : MonoBehaviour 10 | { 11 | public enum LandedVesselsStates 12 | { 13 | NotFocused, 14 | Focusing, 15 | Focused, 16 | Lifted, 17 | Landed 18 | } 19 | 20 | private static bool _crashDamage; 21 | private static bool _joints; 22 | private bool _initialLoading; 23 | private bool _loading; 24 | private Vessel _tvel; 25 | 26 | public static List VesselsLandedToLoad { get; set; } = new List(); 27 | 28 | public static void UpdateSphere() 29 | { 30 | var pqs = FlightGlobals.currentMainBody.pqsController; 31 | 32 | pqs.detailAltitudeMax = Mathf.Max(PreSettings.GlobalRange * 1000f, 100000); 33 | pqs.visRadAltitudeMax = Mathf.Max(PreSettings.GlobalRange * 1000f, 100000); 34 | pqs.collapseAltitudeMax = Mathf.Max(PreSettings.GlobalRange * 1000f, 100000) * 10; 35 | pqs.detailSeaLevelQuads = 0; 36 | pqs.detailAltitudeQuads = 0; 37 | pqs.maxQuadLenghtsPerFrame = 0.03f; 38 | pqs.visRadSeaLevelValue = 200; 39 | pqs.collapseSeaLevelValue = 200; 40 | pqs.StartUpSphere(); 41 | } 42 | 43 | private void FixedUpdate() 44 | { 45 | if (!PreSettings.ConfigLoaded) return; 46 | if (!PreSettings.ModEnabled) return; 47 | if (!PreSettings.TerrainExtenderEnabled) return; 48 | if (!FlightGlobals.ready) return; 49 | if (FlightGlobals.currentMainBody == null) return; 50 | if (FlightGlobals.currentMainBody.pqsController == null) return; 51 | if (FlightGlobals.currentMainBody.pqsController.isBuildingMaps) return; 52 | 53 | ExtendTerrainForLandedVessels(); 54 | } 55 | 56 | private void ExtendTerrainForLandedVessels() 57 | { 58 | InitialFetch(); 59 | 60 | VesselsLandedToLoad.RemoveAll(x => x.Vessel == null); 61 | 62 | if (VesselsLandedToLoad.Count == 0) return; 63 | 64 | if (!_loading) 65 | { 66 | _loading = true; 67 | ActivateNoCrashDamage(); 68 | 69 | _tvel = FlightGlobals.ActiveVessel; 70 | } 71 | 72 | foreach (var currentVesselData in VesselsLandedToLoad) 73 | { 74 | var currentVessel = currentVesselData.Vessel; 75 | 76 | if (currentVessel == null) continue; 77 | if (!SortaLanded(currentVessel)) continue; 78 | 79 | switch (currentVesselData.LandedState) 80 | { 81 | case LandedVesselsStates.NotFocused: 82 | 83 | 84 | if (currentVesselData.Vessel != _tvel) 85 | { 86 | if (VesselsLandedToLoad.Any(x => 87 | x.Vessel != currentVessel && x.LandedState == LandedVesselsStates.Focusing)) return; 88 | 89 | if (InternalCamera.Instance.isActiveAndEnabled) 90 | { 91 | InternalCamera.Instance.DisableCamera(); 92 | CameraManager.Instance.SetCameraFlight(); 93 | } 94 | 95 | MakingVesselPartsIndestructible(currentVessel); 96 | 97 | FlightGlobals.ForceSetActiveVessel(currentVessel); 98 | CameraManager.Instance.SetCameraFlight(); 99 | 100 | //UpdateSphere(); 101 | currentVesselData.LandedState = LandedVesselsStates.Focusing; 102 | currentVesselData.TimeOfState = Time.time; 103 | } 104 | else 105 | { 106 | currentVesselData.LandedState = LandedVesselsStates.Focused; 107 | } 108 | 109 | currentVessel.SetPosition(currentVesselData.InitialPosition + currentVessel.up.normalized * currentVessel.vesselSize.magnitude); 110 | currentVessel.SetWorldVelocity(Vector3.zero); 111 | break; 112 | case LandedVesselsStates.Focusing: 113 | 114 | if (Time.time - currentVesselData.TimeOfState > 2) 115 | { 116 | currentVesselData.LandedState = LandedVesselsStates.Focused; 117 | 118 | foreach (var vesselLandedState in VesselsLandedToLoad.Where(x =>x.LandedState == LandedVesselsStates.NotFocused && Vector3.Distance(currentVessel.CoM, x.Vessel.CoM) < 2500)) 119 | { 120 | vesselLandedState.LandedState = LandedVesselsStates.Focused; 121 | } 122 | } 123 | currentVessel.SetPosition(currentVesselData.InitialPosition + currentVessel.up.normalized * currentVessel.vesselSize.magnitude); 124 | currentVessel.SetWorldVelocity(Vector3.zero); 125 | break; 126 | case LandedVesselsStates.Focused: 127 | 128 | currentVessel.SetPosition(currentVesselData.InitialPosition + currentVessel.up.normalized * currentVessel.vesselSize.magnitude); 129 | currentVessel.SetWorldVelocity(Vector3.zero); 130 | currentVessel.UpdateLandedSplashed(); 131 | currentVesselData.LandedState = LandedVesselsStates.Lifted; 132 | 133 | break; 134 | case LandedVesselsStates.Lifted: 135 | 136 | if (!currentVessel.Landed) 137 | { 138 | currentVessel.SetWorldVelocity(currentVessel.gravityForPos.normalized * 20.0f * Time.fixedDeltaTime); 139 | 140 | currentVessel.UpdateLandedSplashed(); 141 | } 142 | else 143 | { 144 | currentVessel.SetWorldVelocity(Vector3.zero); 145 | currentVesselData.LandedState = LandedVesselsStates.Landed; 146 | } 147 | 148 | break; 149 | case LandedVesselsStates.Landed: 150 | currentVessel.SetWorldVelocity(Vector3.zero); 151 | break; 152 | 153 | default: 154 | throw new ArgumentOutOfRangeException(); 155 | } 156 | } 157 | 158 | VesselsLandedToLoad.RemoveAll(x => x.LandedState == LandedVesselsStates.Landed); 159 | 160 | if (FlightGlobals.ActiveVessel != _tvel && VesselsLandedToLoad.All(x => x.LandedState != LandedVesselsStates.NotFocused && x.LandedState != LandedVesselsStates.Focusing)) 161 | { 162 | FlightGlobals.ForceSetActiveVessel(_tvel); 163 | CameraManager.Instance.SetCameraFlight(); 164 | } 165 | 166 | if (VesselsLandedToLoad.Count == 0) 167 | { 168 | DeactivateNoCrashDamage(); 169 | _loading = false; 170 | } 171 | } 172 | 173 | private static void MakingVesselPartsIndestructible(Vessel currentVessel) 174 | { 175 | foreach (var currentVesselPart in currentVessel.parts) 176 | { 177 | currentVesselPart.crashTolerance = Math.Max(currentVesselPart.crashTolerance, 1000); 178 | } 179 | } 180 | 181 | private void InitialFetch() 182 | { 183 | if (_initialLoading && FlightGlobals.VesselsLoaded.Count >= 1) 184 | { 185 | foreach (var vessel in FlightGlobals.VesselsLoaded) 186 | { 187 | if (vessel.isActiveVessel) continue; 188 | 189 | if ((vessel.Landed || SortaLanded(vessel)) && 190 | vessel.vesselType != VesselType.Debris) 191 | VesselsLandedToLoad.Add(new VesselLandedState 192 | { 193 | InitialAltitude = vessel.altitude, 194 | LandedState = LandedVesselsStates.NotFocused, 195 | Vessel = vessel 196 | }); 197 | } 198 | 199 | _initialLoading = false; 200 | } 201 | } 202 | 203 | private void Update() 204 | { 205 | if (!PreSettings.ConfigLoaded) return; 206 | if (!PreSettings.ModEnabled) return; 207 | if (!PreSettings.TerrainExtenderEnabled) return; 208 | 209 | ShowMessageTerrainStatus(); 210 | } 211 | 212 | private void ShowMessageTerrainStatus() 213 | { 214 | if (VesselsLandedToLoad.Count == 0) return; 215 | 216 | var overallStatus = LandedVesselsStates.NotFocused; 217 | 218 | if (VesselsLandedToLoad.Any(x => x.LandedState == LandedVesselsStates.NotFocused)) 219 | overallStatus = LandedVesselsStates.NotFocused; 220 | else if (VesselsLandedToLoad.Any(x => x.LandedState == LandedVesselsStates.Focusing)) 221 | overallStatus = LandedVesselsStates.Focusing; 222 | else if (VesselsLandedToLoad.Any(x => x.LandedState == LandedVesselsStates.Focused)) 223 | overallStatus = LandedVesselsStates.Focused; 224 | else if (VesselsLandedToLoad.Any(x => x.LandedState == LandedVesselsStates.Lifted)) 225 | overallStatus = LandedVesselsStates.Lifted; 226 | else if (VesselsLandedToLoad.Any(x => x.LandedState == LandedVesselsStates.Landed)) 227 | overallStatus = LandedVesselsStates.Landed; 228 | 229 | switch (overallStatus) 230 | { 231 | case LandedVesselsStates.NotFocused: 232 | ScreenMessages.PostScreenMessage( 233 | "[PhysicsRangeExtender]Extending terrain: focusing landed vessels.", 3f, 234 | ScreenMessageStyle.UPPER_CENTER); 235 | break; 236 | case LandedVesselsStates.Focusing: 237 | ScreenMessages.PostScreenMessage( 238 | "[PhysicsRangeExtender]Extending terrain: focusing landed vessels.", 3f, 239 | ScreenMessageStyle.UPPER_CENTER); 240 | break; 241 | case LandedVesselsStates.Focused: 242 | ScreenMessages.PostScreenMessage( 243 | "[PhysicsRangeExtender]Extending terrain: lifting vessels.", 3f, 244 | ScreenMessageStyle.UPPER_CENTER); 245 | break; 246 | case LandedVesselsStates.Lifted: 247 | ScreenMessages.PostScreenMessage( 248 | "[PhysicsRangeExtender]Extending terrain: landing vessels.", 3f, 249 | ScreenMessageStyle.UPPER_CENTER); 250 | break; 251 | case LandedVesselsStates.Landed: 252 | ScreenMessages.PostScreenMessage( 253 | "[PhysicsRangeExtender]Extending terrain: switching to previous vessel.", 3f, 254 | ScreenMessageStyle.UPPER_CENTER); 255 | break; 256 | default: 257 | throw new ArgumentOutOfRangeException(); 258 | } 259 | } 260 | 261 | public static void DeactivateNoCrashDamage() 262 | { 263 | CheatOptions.NoCrashDamage = _crashDamage; 264 | CheatOptions.UnbreakableJoints = _joints; 265 | } 266 | 267 | 268 | private void Start() 269 | { 270 | if (!PreSettings.ModEnabled) return; 271 | if (!PreSettings.TerrainExtenderEnabled) return; 272 | 273 | _initialLoading = true; 274 | } 275 | 276 | 277 | 278 | 279 | public static void ActivateNoCrashDamage() 280 | { 281 | _crashDamage = CheatOptions.NoCrashDamage; 282 | _joints = CheatOptions.UnbreakableJoints; 283 | CheatOptions.NoCrashDamage = true; 284 | CheatOptions.UnbreakableJoints = true; 285 | } 286 | 287 | public static bool SortaLanded(Vessel v) 288 | { 289 | if (v.Splashed) return false; 290 | 291 | return v.mainBody.GetAltitude(v.CoM) - Math.Max(v.terrainAltitude, 0) < 100; 292 | } 293 | 294 | public class VesselLandedState 295 | { 296 | public Vessel Vessel { get; set; } 297 | public LandedVesselsStates LandedState { get; set; } 298 | public double InitialAltitude { get; set; } 299 | 300 | public double TimeOfState { get; set; } 301 | 302 | public Vector3d InitialPosition { get; set; } 303 | } 304 | } 305 | } -------------------------------------------------------------------------------- /PhysicsRangeExtender/PhysicsRangeExtender.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using UnityEngine; 5 | 6 | namespace PhysicsRangeExtender 7 | { 8 | [KSPAddon(KSPAddon.Startup.Flight, false)] 9 | public class PhysicsRangeExtender : MonoBehaviour 10 | { 11 | private static VesselRanges _baseRanges; 12 | private static VesselRanges.Situation _globalSituation; 13 | private static bool _unloadDueToReferenceFrameApplied; 14 | 15 | private static readonly float _initialClippingPlane = 0.21f; 16 | private bool _isSuborbital; 17 | 18 | public List VesselToFreeze { get; set; } = new List(); 19 | 20 | 21 | public double LastFlickeringTime { get; set; } 22 | 23 | private void Start() 24 | { 25 | if (!PreSettings.ConfigLoaded) return; 26 | if (!PreSettings.ModEnabled) return; 27 | 28 | TerrainExtender.UpdateSphere(); 29 | UpdateRanges(); 30 | 31 | GameEvents.onVesselCreate.Add(ApplyPhysRange); 32 | GameEvents.onVesselLoaded.Add(ApplyPhysRangeOnLoad); 33 | GameEvents.onVesselSwitching.Add(ApplyPhysRange); 34 | GameEvents.onVesselGoOffRails.Add(ApplyPhysRange); 35 | GameEvents.onVesselSituationChange.Add(SituationChangeFixes); 36 | } 37 | 38 | private void SituationChangeFixes(GameEvents.HostedFromToAction data) 39 | { 40 | RefreshPqsWhenApproaching(data); 41 | } 42 | 43 | 44 | private void RefreshPqsWhenApproaching(GameEvents.HostedFromToAction data) 45 | { 46 | var curVessel = data.host; 47 | if (!curVessel.mainBody.isHomeWorld || !curVessel.isActiveVessel) return; 48 | 49 | if (data.from == Vessel.Situations.FLYING && data.to == Vessel.Situations.SUB_ORBITAL) 50 | { 51 | _isSuborbital = true; 52 | } 53 | else if (_isSuborbital && data.to == Vessel.Situations.FLYING) 54 | { 55 | _isSuborbital = false; 56 | Debug.Log("[PhysicsRangeExtender]: Calling StartUpSphere() to prevent missing PQ tiles"); 57 | curVessel.mainBody.pqsController.StartUpSphere(); 58 | } 59 | } 60 | 61 | private void ApplyPhysRangeOnLoad(Vessel data) 62 | { 63 | NewVesselIsLoaded(data); 64 | ApplyRangesToVessels(); 65 | } 66 | 67 | private void OnDestroy() 68 | { 69 | if (!PreSettings.ConfigLoaded) return; 70 | if (!PreSettings.ModEnabled) return; 71 | GameEvents.onVesselCreate.Remove(ApplyPhysRange); 72 | GameEvents.onVesselLoaded.Remove(ApplyPhysRangeOnLoad); 73 | GameEvents.onVesselSwitching.Remove(ApplyPhysRange); 74 | GameEvents.onVesselGoOffRails.Remove(ApplyPhysRange); 75 | GameEvents.onVesselSituationChange.Add(SituationChangeFixes); 76 | } 77 | 78 | 79 | private void NewVesselIsLoaded(Vessel vessel) 80 | { 81 | if (vessel != null && !vessel.isActiveVessel && vessel.Landed && vessel.vesselType != VesselType.Debris && Vector3.Distance(vessel.CoM, FlightGlobals.ActiveVessel.CoM) > 2500) 82 | if (TerrainExtender.VesselsLandedToLoad.All(x => x.Vessel != vessel)) 83 | TerrainExtender.VesselsLandedToLoad.Add(new TerrainExtender.VesselLandedState 84 | { 85 | Vessel = vessel, 86 | InitialAltitude = vessel.altitude, 87 | InitialPosition = vessel.GetWorldPos3D(), 88 | LandedState = TerrainExtender.LandedVesselsStates.NotFocused 89 | }); ; 90 | } 91 | 92 | 93 | private void ApplyPhysRange(Vessel data0, Vessel data1) 94 | { 95 | CheckIfFreezeIsNeeded(data0, data1); 96 | ApplyRangesToVessels(); 97 | } 98 | 99 | private void CheckIfFreezeIsNeeded(Vessel from, Vessel to) 100 | { 101 | if (from.Landed && to.situation >= Vessel.Situations.SUB_ORBITAL) 102 | { 103 | TerrainExtender.ActivateNoCrashDamage(); 104 | from.SetWorldVelocity(Vector3d.zero); 105 | VesselToFreeze.Add(from); 106 | VesselToFreeze.AddRange(FlightGlobals.VesselsLoaded.Where(x => x.LandedOrSplashed)); 107 | } 108 | } 109 | 110 | private void ApplyPhysRange(Vessel data) 111 | { 112 | ApplyRangesToVessels(); 113 | } 114 | 115 | 116 | private void Update() 117 | { 118 | if (!PreSettings.ModEnabled) return; 119 | UpdateNearClipPlane(); 120 | AvoidReferenceFrameChangeIssues(); 121 | FreezeLandedVesselWhenSwitching(); 122 | } 123 | 124 | private void UpdateNearClipPlane() 125 | { 126 | if (FlightGlobals.VesselsLoaded.Count > 1 && 127 | FlightGlobals.VesselsLoaded.Count(TerrainExtender.SortaLanded) >= 1) 128 | { 129 | var distanceMultiplier = 130 | _initialClippingPlane * 131 | (FlightGlobals.ActiveVessel.transform.position.sqrMagnitude / (4000f * 4000f)) * 132 | PreSettings.CamFixMultiplier; 133 | 134 | FlightCamera.fetch.mainCamera.nearClipPlane = Mathf.Clamp(distanceMultiplier, _initialClippingPlane, 135 | _initialClippingPlane * 50f); 136 | 137 | if (Time.time - LastFlickeringTime > 60) 138 | { 139 | ScreenMessages.PostScreenMessage( 140 | "[PhysicsRangeExtender] Flickering correction is active, near camera plane is adapting.", 3f, 141 | ScreenMessageStyle.UPPER_CENTER); 142 | LastFlickeringTime = Time.time; 143 | } 144 | } 145 | else 146 | { 147 | FlightCamera.fetch.mainCamera.nearClipPlane = _initialClippingPlane; 148 | } 149 | } 150 | 151 | private void LateUpdate() 152 | { 153 | if (!PreSettings.ConfigLoaded) return; 154 | if (!PreSettings.ModEnabled) return; 155 | UpdateNearClipPlane(); 156 | AvoidReferenceFrameChangeIssues(); 157 | FreezeLandedVesselWhenSwitching(); 158 | } 159 | 160 | private void FixedUpdate() 161 | { 162 | if (!PreSettings.ConfigLoaded) return; 163 | if (!PreSettings.ModEnabled) return; 164 | UpdateNearClipPlane(); 165 | AvoidReferenceFrameChangeIssues(); 166 | FreezeLandedVesselWhenSwitching(); 167 | } 168 | 169 | private void FreezeLandedVesselWhenSwitching() 170 | { 171 | VesselToFreeze.RemoveAll(x => x == null); 172 | VesselToFreeze.RemoveAll(x => !x.loaded); 173 | 174 | if (VesselToFreeze.Count == 0) TerrainExtender.DeactivateNoCrashDamage(); 175 | VesselToFreeze.ForEach(x => x?.SetWorldVelocity(Vector3d.zero)); 176 | } 177 | 178 | private void AvoidReferenceFrameChangeIssues() 179 | { 180 | if (!ShouldLandedVesselsBeLoaded()) 181 | { 182 | if (!_unloadDueToReferenceFrameApplied) 183 | { 184 | UnloadLandedVessels(); 185 | _unloadDueToReferenceFrameApplied = true; 186 | } 187 | } 188 | else if (_unloadDueToReferenceFrameApplied) 189 | { 190 | UpdateRanges(); 191 | _unloadDueToReferenceFrameApplied = false; 192 | } 193 | } 194 | 195 | /// 196 | /// This method will avoid landed vessels to be destroyed due to changes on the referencial frame (inertial vs 197 | /// rotation) when the active vessel is going suborbital 198 | /// 199 | /// if landed vessel should be loaded 200 | private static bool ShouldLandedVesselsBeLoaded() 201 | { 202 | var safetyMargin = 0.90f; 203 | 204 | if (FlightGlobals.ActiveVessel == null || 205 | FlightGlobals.ActiveVessel.LandedOrSplashed || 206 | FlightGlobals.ActiveVessel.orbit == null || 207 | FlightGlobals.ActiveVessel.orbit.referenceBody == null) 208 | return true; 209 | 210 | var altitudeAtPos = 211 | (double)FlightGlobals.getAltitudeAtPos(FlightGlobals.ActiveVessel.transform.position, 212 | FlightGlobals.ActiveVessel.orbit.referenceBody); 213 | 214 | if (altitudeAtPos / FlightGlobals.ActiveVessel.orbit.referenceBody.inverseRotThresholdAltitude > 215 | safetyMargin) 216 | return false; 217 | return true; 218 | } 219 | 220 | /// 221 | /// This method will reduce the load/unload distances using a closer range to avoid issues. 222 | /// 223 | private void UnloadLandedVessels() 224 | { 225 | var vesselsCount = FlightGlobals.VesselsLoaded.Count; 226 | ScreenMessages.PostScreenMessage( 227 | "[PhysicsRangeExtender] Unloading landed vessels during active orbital fly.", 3f, 228 | ScreenMessageStyle.UPPER_CENTER); 229 | for (var i = 0; i < vesselsCount; i++) 230 | if (FlightGlobals.VesselsLoaded[i].LandedOrSplashed) 231 | { 232 | var safeSituation = new VesselRanges.Situation( 233 | FlightGlobals.ActiveVessel.orbit.referenceBody.inverseRotThresholdAltitude * 0.90f, 234 | FlightGlobals.ActiveVessel.orbit.referenceBody.inverseRotThresholdAltitude * 0.95f, 235 | FlightGlobals.ActiveVessel.orbit.referenceBody.inverseRotThresholdAltitude * 1.10f, 236 | FlightGlobals.ActiveVessel.orbit.referenceBody.inverseRotThresholdAltitude * 0.99f); 237 | 238 | var newRanges = new VesselRanges 239 | { 240 | escaping = _globalSituation, 241 | flying = _globalSituation, 242 | landed = safeSituation, 243 | orbit = _globalSituation, 244 | prelaunch = safeSituation, 245 | splashed = safeSituation, 246 | subOrbital = _globalSituation 247 | }; 248 | 249 | FlightGlobals.VesselsLoaded[i].vesselRanges = newRanges; 250 | } 251 | } 252 | 253 | public static void UpdateRanges(bool updatingFromUi = false) 254 | { 255 | Debug.Log("[PhysicsRangeExtender]: Updating ranges"); 256 | FloatingOrigin.fetch.threshold = Mathf.Pow(PreSettings.GlobalRange * 1000 * 1.20f, 2); 257 | 258 | if (updatingFromUi) TerrainExtender.UpdateSphere(); 259 | 260 | _globalSituation = new VesselRanges.Situation( 261 | PreSettings.GlobalRange * 1000, 262 | PreSettings.GlobalRange * 1000 * 1.05f, 263 | PreSettings.GlobalRange * 1000 * 1.10f, 264 | PreSettings.GlobalRange * 1000 * 0.99f); 265 | 266 | _baseRanges = new VesselRanges 267 | { 268 | escaping = _globalSituation, 269 | flying = _globalSituation, 270 | landed = _globalSituation, 271 | orbit = _globalSituation, 272 | prelaunch = _globalSituation, 273 | splashed = _globalSituation, 274 | subOrbital = _globalSituation 275 | }; 276 | ApplyRangesToVessels(updatingFromUi); 277 | } 278 | 279 | private static void ApplyRangesToVessels(bool updatingFromUi = false) 280 | { 281 | if (!PreSettings.ModEnabled) return; 282 | try 283 | { 284 | var vesselsCount = FlightGlobals.Vessels.Count; 285 | 286 | for (var i = 0; i < vesselsCount; i++) 287 | { 288 | // check to avoid landed vessels to be destroyed when the active vessel is sub-orbital 289 | if (FlightGlobals.Vessels[i].LandedOrSplashed && !ShouldLandedVesselsBeLoaded()) continue; 290 | // 291 | if (VesselOrbitingWhileUpdatingRangeFromUi(updatingFromUi, FlightGlobals.Vessels[i])) continue; 292 | 293 | FlightGlobals.Vessels[i].vesselRanges = new VesselRanges(_baseRanges); 294 | } 295 | } 296 | catch (Exception e) 297 | { 298 | Debug.Log("[PhysicsRangeExtender]: Failed to Load Physics Distance -" + e); 299 | } 300 | } 301 | 302 | /// 303 | /// This method will avoid de-orbiting unloaded vessels when a user is extending the range using the UI and orbiting 304 | /// vessels are getting loaded. 305 | /// 306 | /// 307 | /// 308 | /// 309 | private static bool VesselOrbitingWhileUpdatingRangeFromUi(bool updatingFromUi, Vessel vessel) 310 | { 311 | return !vessel.isActiveVessel && updatingFromUi && !vessel.LandedOrSplashed; 312 | } 313 | 314 | public static void RestoreStockRanges() 315 | { 316 | try 317 | { 318 | FlightCamera.fetch.mainCamera.nearClipPlane = _initialClippingPlane; 319 | var vesselsCount = FlightGlobals.Vessels.Count; 320 | 321 | for (var i = 0; i < vesselsCount; i++) FlightGlobals.Vessels[i].vesselRanges = new VesselRanges(); 322 | } 323 | catch (Exception e) 324 | { 325 | Debug.Log("[PhysicsRangeExtender]: Failed to Load Physics Distance -" + e); 326 | } 327 | } 328 | } 329 | } --------------------------------------------------------------------------------