Skip to content

Commit 3d8a086

Browse files
authored
Merge pull request #53 from KSP2Community/dev
Version 0.14.0
2 parents 758c8d2 + b6cf1cb commit 3d8a086

File tree

12 files changed

+144
-107
lines changed

12 files changed

+144
-107
lines changed

CommunityFixes.sln.DotSettings

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=KSP/@EntryIndexedValue">KSP</s:String>
3+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=KSP/@EntryIndexedValue">VAB</s:String>
4+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=STFU/@EntryIndexedValue">STFU</s:String></wpf:ResourceDictionary>

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22
This project aims to bring together community bug fixes for Kerbal Space Program 2 in one centralized place.
33

44
## Compatibility
5-
- Tested with Kerbal Space Program 2 v0.2.1.0.30833
6-
- Requires **[SpaceWarp 1.9.0+](https://github.com/SpaceWarpDev/SpaceWarp/releases/)**
7-
- Requires **[Patch Manager 0.9.3+](https://github.com/KSP2Community/PatchManager/releases/)**
5+
- Tested with Kerbal Space Program 2 v0.2.2.0.32913
6+
- Requires **[SpaceWarp 1.9.5+](https://github.com/SpaceWarpDev/SpaceWarp/releases/)**
7+
- Requires **[Patch Manager 0.11.1+](https://github.com/KSP2Community/PatchManager/releases/)**
88

99
## Implemented fixes
1010
- **KSP 2 Save Fix** by [jayouimet](https://github.com/jayouimet) - Replaces the Control Owner Part to the first available Command module or to the Root part if not found when it is set to null.
11-
- **Vessel Landed State Fix** by [munix](https://github.com/jan-bures) - Checks if the vessel's state is Landed when not actually near the ground and resets it. Should fix [this persistent bug](https://forum.kerbalspaceprogram.com/topic/220260-incorrect-landed-state-causing-lack-of-trajectory-lines/).
11+
- **Vessel Landed State Fix** by [munix](https://github.com/jan-bures) - Checks if the vessel's state is Landed when not actually near the ground and resets it.
1212
- **Suppress Transmissions Falsely Urgent Fix** by [schlosrat](https://github.com/schlosrat) - Suppresses unhelpful map view log messages.
1313
- **VAB Redo Tooltip Fix** by [coldrifting](https://github.com/coldrifting) - Fixes the VAB Redo button tooltip not being at the same height as the button.
1414
- **Revert After Recovery Fix** by [munix](https://github.com/jan-bures) - Fixes the Revert buttons being enabled after recovering a vessel.
1515
- **Stock Mission Fix** by [Cheese](https://github.com/cheese3660) - Fixes the incorrect completion conditions of some stock missions.
1616
- **Resource Manager UI Fix** by [munix](https://github.com/jan-bures) - Fixes the Resource Manager bug where moving a tank from the right pane back to the left pane caused it to duplicate.
1717
- **Decoupled Craft Name Fix** by [munix](https://github.com/jan-bures) - Decoupled and docked/undocked vessels get names based on the original vessels instead of "Default Name" and "(Combined)".
1818
- **Time Warp Thrust Fix** by [SunSerega](https://github.com/SunSerega) - Fixes the bug where thrust under time warp was sometimes not working despite draining fuel.
19+
- **Save/Load DateTime Fix** by [bizzehdee](https://github.com/bizzehdee) - Displays dates and times of save files in the correct locale format.
1920

2021
## Planned fixes
2122
To see what fixes are planned to be implemented, you can visit the [Issues page](https://github.com/KSP2Community/CommunityFixes/issues) on the project's GitHub.
@@ -28,8 +29,9 @@ To see what fixes are planned to be implemented, you can visit the [Issues page]
2829
### Manual
2930
1. Download and extract [UITK for KSP 2](https://github.com/UitkForKsp2/UitkForKsp2/releases) into your game folder (this is a dependency of SpaceWarp).
3031
2. Download and extract [SpaceWarp](https://github.com/SpaceWarpDev/SpaceWarp/releases) into your game folder.
31-
3. Download and extract [Patch Manager](https://github.com/KSP2Community/PatchManager/releases) into your game folder.
32-
4. Download and extract this mod into the game folder. If done correctly, you should have the following folder structure: `<KSP Folder>/BepInEx/plugins/CommunityFixes`.
32+
3. Download and extract [Premonition](https://github.com/cheese3660/Premonition/releases) into your game folder (this is a dependency of Patch Manager).
33+
4. Download and extract [Patch Manager](https://github.com/KSP2Community/PatchManager/releases) into your game folder.
34+
5. Download and extract this mod into the game folder. If done correctly, you should have the following folder structure: `<KSP Folder>/BepInEx/plugins/CommunityFixes`.
3335

3436
## Configuration
3537
If you want to toggle any of the included fixes off, you can do so in game: `Main menu` -> `Settings` -> `Mods` -> `Community Fixes`. The changes will apply after restarting the game.

plugin_template/swinfo.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55
"name": "Community Fixes",
66
"description": "Community project that aims to bring together bug fixes for KSP 2.",
77
"source": "https://github.com/KSP2Community/CommunityFixes",
8-
"version": "0.13.0",
8+
"version": "0.14.0",
99
"version_check": "https://raw.githubusercontent.com/KSP2Community/CommunityFixes/main/plugin_template/swinfo.json",
1010
"ksp2_version": {
11-
"min": "0.2.1",
11+
"min": "0.2.2",
1212
"max": "*"
1313
},
1414
"dependencies": [
1515
{
1616
"id": "com.github.x606.spacewarp",
1717
"version": {
18-
"min": "1.9.0",
18+
"min": "1.9.5",
1919
"max": "*"
2020
}
2121
},
2222
{
2323
"id": "PatchManager",
2424
"version": {
25-
"min": "0.9.3",
25+
"min": "0.11.1",
2626
"max": "*"
2727
}
2828
}

src/CommunityFixes/CommunityFixes.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<PackageReference Include="BepInEx.AssemblyPublicizer.MSBuild" Version="0.4.1" PrivateAssets="all"/>
77
<PackageReference Include="BepInEx.Core" Version="5.*"/>
88
<PackageReference Include="HarmonyX" Version="2.10.1"/>
9-
<PackageReference Include="KerbalSpaceProgram2.GameLibs" Version="0.2.0" PrivateAssets="all" Publicize="true"/>
10-
<PackageReference Include="SpaceWarp" Version="1.6.0"/>
9+
<PackageReference Include="KerbalSpaceProgram2.GameLibs" Version="0.2.2" PrivateAssets="all" Publicize="true"/>
10+
<PackageReference Include="SpaceWarp" Version="1.9.0"/>
1111
<PackageReference Include="SpaceWarp.PluginInfoProps" Version="1.*"/>
1212
<PackageReference Include="UnityEngine.Modules" Version="2022.3.5"/>
1313
</ItemGroup>

src/CommunityFixes/Fix/DecoupledCraftNameFix/DecoupledCraftNameFix.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ private void HandleDecoupleMessage(DecoupleMessage decoupleMessage)
2929

3030
private void HandleUndockMessage(VesselUndockedMessage undockMessage)
3131
{
32-
VesselComponent vessel1 = undockMessage.VesselOne?.Model;
33-
VesselComponent vessel2 = undockMessage.VesselTwo?.Model;
32+
VesselComponent vessel1 = undockMessage.VesselOne == null ? null : undockMessage.VesselOne.Model;
33+
VesselComponent vessel2 = undockMessage.VesselTwo == null ? null : undockMessage.VesselTwo.Model;
3434

3535
HandleSeparationEvent(vessel1, vessel2);
3636
}

src/CommunityFixes/Fix/KSP2SaveFix/KSP2SaveFix.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ public KSP2SaveFix()
1212

1313
public override void OnInitialized()
1414
{
15-
HarmonyInstance.PatchAll(typeof(KSP2SaveFix_GetState));
15+
HarmonyInstance.PatchAll(typeof(KSP2SaveFixPatch));
1616
}
1717
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using HarmonyLib;
2+
using JetBrains.Annotations;
3+
using KSP.Sim.impl;
4+
5+
namespace CommunityFixes.Fix.KSP2SaveFix;
6+
7+
[HarmonyPatch(typeof(VesselComponent), nameof(VesselComponent.GetState))]
8+
public class KSP2SaveFixPatch
9+
{
10+
/// Called before VesselComponent.GetState
11+
/// This is the part that crashes during serialization
12+
///
13+
/// Last 3 functions in the call stack after a save:
14+
/// [EXC 20:35:06.678] NullReferenceException: Object reference not set to an instance of an object
15+
/// KSP.Sim.impl.VesselComponent.GetState()
16+
/// KSP.Game.Serialization.SerializationUtility.VesselToSerializable(KSP.Sim.impl.SimulationObjectModel vessel,
17+
/// System.Boolean isAutosave)
18+
/// KSP.Game.Load.CollectFlightDataFlowAction.CollectVesselComponents(System.Byte playerID)
19+
///
20+
/// Occurs because the controlOwner hasn't been correctly set after decoupling / undocking
21+
/// After saving in a file or in memory and loading afterwards (this can also be triggered after reverting to VAB),
22+
/// the faulty controlOwner is set to null
23+
/// Once controlOwner is set to null, it crashes during the GetState() call
24+
///
25+
/// Ideal fix would be to fix the decoupling / docking, I will look into it later if needed but this is a decent
26+
/// workaround until the patch comes out
27+
[UsedImplicitly]
28+
// ReSharper disable once InconsistentNaming
29+
public static void Prefix(VesselComponent __instance)
30+
{
31+
// Check if control owner is already set
32+
if (__instance.GetControlOwner() is not null)
33+
{
34+
return;
35+
}
36+
37+
KSP2SaveFix.Instance.Logger.LogInfo($"Control 0wner not found for {__instance.GlobalId}");
38+
// Gather command modules
39+
var partModules = __instance.SimulationObject.PartOwner.GetPartModules<PartComponentModule_Command>();
40+
// Set ownership to the first command module
41+
if (partModules.Count > 0)
42+
{
43+
KSP2SaveFix.Instance.Logger.LogInfo($"Set control to {partModules[0].Part.GlobalId}");
44+
__instance.SetControlOwner(partModules[0].Part);
45+
}
46+
// Otherwise try to set it to the root part, whatever it is
47+
else if (__instance.SimulationObject.PartOwner != null)
48+
{
49+
KSP2SaveFix.Instance.Logger.LogInfo(
50+
$"Set control to {__instance.SimulationObject.PartOwner.RootPart.GlobalId}"
51+
);
52+
__instance.SetControlOwner(__instance.SimulationObject.PartOwner.RootPart);
53+
}
54+
}
55+
}

src/CommunityFixes/Fix/KSP2SaveFix/KSP2SaveFix_GetState.cs

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,17 @@
11
using HarmonyLib;
2-
using KSP.Game;
3-
using KSP.Logging;
42
using KSP.Map;
53
using KSP.Sim.impl;
4+
using SpaceWarp.API.Game;
65

76
namespace CommunityFixes.Fix.STFUFix;
87

98
internal class STFUPatches
109
{
1110
[HarmonyPatch(typeof(Map3DTrajectoryEvents), nameof(Map3DTrajectoryEvents.UpdateViewForOrbiter))]
1211
[HarmonyPrefix]
12+
// ReSharper disable once InconsistentNaming
1313
public static bool BetterUpdateViewForOrbiter(Map3DTrajectoryEvents __instance, OrbiterComponent orbiter)
1414
{
15-
if (orbiter == null)
16-
GlobalLog.Warn("GenerateEventsForVessel() called with vessel.Orbiter == null! Events will not be updated");
17-
else if (orbiter.PatchedConicSolver == null)
18-
{
19-
var activeVessel = GameManager.Instance?.Game?.ViewController?.GetActiveVehicle(true)?.GetSimVessel(true);
20-
var currentTarget = activeVessel?.TargetObject;
21-
if (!currentTarget.IsCelestialBody)
22-
GlobalLog.Warn(
23-
"GenerateEventsForVessel() called with vessel.Orbiter.patchedConicSolver == null. Events will not be updated");
24-
}
25-
else if (__instance._mapCamera?.UnityCamera == null)
26-
{
27-
GlobalLog.Warn("GenerateEventsForVessel() called with a null map camera. Events will not be updated");
28-
}
29-
else
30-
{
31-
IGGuid globalId = orbiter.SimulationObject.GlobalId;
32-
__instance.UpdateViewForCurrentTrajectory(orbiter, globalId);
33-
__instance.UpdateViewForManeuverTrajectory(orbiter, globalId);
34-
__instance.UpdateViewForTargeter(orbiter.OrbitTargeter, orbiter, globalId);
35-
}
36-
37-
return false;
15+
return orbiter.PatchedConicSolver != null || Vehicle.ActiveSimVessel?.TargetObject?.IsCelestialBody is not true;
3816
}
3917
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace CommunityFixes.Fix.SaveLoadDateTimeFix;
2+
3+
[Fix("Save/Load Date/Time Fix")]
4+
public class SaveLoadDateTimeFix : BaseFix
5+
{
6+
public override void OnInitialized()
7+
{
8+
HarmonyInstance.PatchAll(typeof(SaveLoadDateTimeFix_Patch));
9+
}
10+
}

0 commit comments

Comments
 (0)