-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from KSP2Community/dev
Version 0.14.0
- Loading branch information
Showing
12 changed files
with
144 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<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"> | ||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=KSP/@EntryIndexedValue">KSP</s:String> | ||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=KSP/@EntryIndexedValue">VAB</s:String> | ||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=STFU/@EntryIndexedValue">STFU</s:String></wpf:ResourceDictionary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using HarmonyLib; | ||
using JetBrains.Annotations; | ||
using KSP.Sim.impl; | ||
|
||
namespace CommunityFixes.Fix.KSP2SaveFix; | ||
|
||
[HarmonyPatch(typeof(VesselComponent), nameof(VesselComponent.GetState))] | ||
public class KSP2SaveFixPatch | ||
{ | ||
/// Called before VesselComponent.GetState | ||
/// This is the part that crashes during serialization | ||
/// | ||
/// Last 3 functions in the call stack after a save: | ||
/// [EXC 20:35:06.678] NullReferenceException: Object reference not set to an instance of an object | ||
/// KSP.Sim.impl.VesselComponent.GetState() | ||
/// KSP.Game.Serialization.SerializationUtility.VesselToSerializable(KSP.Sim.impl.SimulationObjectModel vessel, | ||
/// System.Boolean isAutosave) | ||
/// KSP.Game.Load.CollectFlightDataFlowAction.CollectVesselComponents(System.Byte playerID) | ||
/// | ||
/// Occurs because the controlOwner hasn't been correctly set after decoupling / undocking | ||
/// After saving in a file or in memory and loading afterwards (this can also be triggered after reverting to VAB), | ||
/// the faulty controlOwner is set to null | ||
/// Once controlOwner is set to null, it crashes during the GetState() call | ||
/// | ||
/// Ideal fix would be to fix the decoupling / docking, I will look into it later if needed but this is a decent | ||
/// workaround until the patch comes out | ||
[UsedImplicitly] | ||
// ReSharper disable once InconsistentNaming | ||
public static void Prefix(VesselComponent __instance) | ||
{ | ||
// Check if control owner is already set | ||
if (__instance.GetControlOwner() is not null) | ||
{ | ||
return; | ||
} | ||
|
||
KSP2SaveFix.Instance.Logger.LogInfo($"Control 0wner not found for {__instance.GlobalId}"); | ||
// Gather command modules | ||
var partModules = __instance.SimulationObject.PartOwner.GetPartModules<PartComponentModule_Command>(); | ||
// Set ownership to the first command module | ||
if (partModules.Count > 0) | ||
{ | ||
KSP2SaveFix.Instance.Logger.LogInfo($"Set control to {partModules[0].Part.GlobalId}"); | ||
__instance.SetControlOwner(partModules[0].Part); | ||
} | ||
// Otherwise try to set it to the root part, whatever it is | ||
else if (__instance.SimulationObject.PartOwner != null) | ||
{ | ||
KSP2SaveFix.Instance.Logger.LogInfo( | ||
$"Set control to {__instance.SimulationObject.PartOwner.RootPart.GlobalId}" | ||
); | ||
__instance.SetControlOwner(__instance.SimulationObject.PartOwner.RootPart); | ||
} | ||
} | ||
} |
49 changes: 0 additions & 49 deletions
49
src/CommunityFixes/Fix/KSP2SaveFix/KSP2SaveFix_GetState.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,17 @@ | ||
using HarmonyLib; | ||
using KSP.Game; | ||
using KSP.Logging; | ||
using KSP.Map; | ||
using KSP.Sim.impl; | ||
using SpaceWarp.API.Game; | ||
|
||
namespace CommunityFixes.Fix.STFUFix; | ||
|
||
internal class STFUPatches | ||
{ | ||
[HarmonyPatch(typeof(Map3DTrajectoryEvents), nameof(Map3DTrajectoryEvents.UpdateViewForOrbiter))] | ||
[HarmonyPrefix] | ||
// ReSharper disable once InconsistentNaming | ||
public static bool BetterUpdateViewForOrbiter(Map3DTrajectoryEvents __instance, OrbiterComponent orbiter) | ||
{ | ||
if (orbiter == null) | ||
GlobalLog.Warn("GenerateEventsForVessel() called with vessel.Orbiter == null! Events will not be updated"); | ||
else if (orbiter.PatchedConicSolver == null) | ||
{ | ||
var activeVessel = GameManager.Instance?.Game?.ViewController?.GetActiveVehicle(true)?.GetSimVessel(true); | ||
var currentTarget = activeVessel?.TargetObject; | ||
if (!currentTarget.IsCelestialBody) | ||
GlobalLog.Warn( | ||
"GenerateEventsForVessel() called with vessel.Orbiter.patchedConicSolver == null. Events will not be updated"); | ||
} | ||
else if (__instance._mapCamera?.UnityCamera == null) | ||
{ | ||
GlobalLog.Warn("GenerateEventsForVessel() called with a null map camera. Events will not be updated"); | ||
} | ||
else | ||
{ | ||
IGGuid globalId = orbiter.SimulationObject.GlobalId; | ||
__instance.UpdateViewForCurrentTrajectory(orbiter, globalId); | ||
__instance.UpdateViewForManeuverTrajectory(orbiter, globalId); | ||
__instance.UpdateViewForTargeter(orbiter.OrbitTargeter, orbiter, globalId); | ||
} | ||
|
||
return false; | ||
return orbiter.PatchedConicSolver != null || Vehicle.ActiveSimVessel?.TargetObject?.IsCelestialBody is not true; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/CommunityFixes/Fix/SaveLoadDateTimeFix/SaveLoadDateTimeFix.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace CommunityFixes.Fix.SaveLoadDateTimeFix; | ||
|
||
[Fix("Save/Load Date/Time Fix")] | ||
public class SaveLoadDateTimeFix : BaseFix | ||
{ | ||
public override void OnInitialized() | ||
{ | ||
HarmonyInstance.PatchAll(typeof(SaveLoadDateTimeFix_Patch)); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/CommunityFixes/Fix/SaveLoadDateTimeFix/SaveLoadDateTimeFix_Patch.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using HarmonyLib; | ||
using KSP.Game; | ||
using UnityEngine.UI; | ||
|
||
namespace CommunityFixes.Fix.SaveLoadDateTimeFix; | ||
|
||
internal class SaveLoadDateTimeFix_Patch | ||
{ | ||
[HarmonyPatch(typeof(SaveLoadDialogFileEntry), nameof(SaveLoadDialogFileEntry.Initialize), new Type[] { typeof(ExtendedSaveFileInfo), typeof(bool), typeof(bool) })] | ||
[HarmonyPrefix] | ||
public static void SaveLoadDialogFileEntry_Initialize(SaveLoadDialogFileEntry __instance, ExtendedSaveFileInfo fileInfo, bool loading, bool isLastPlayed) | ||
{ | ||
Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture; | ||
} | ||
|
||
[HarmonyPatch(typeof(SaveLoadDialog), nameof(SaveLoadDialog.UpdateLoadMenuGameInformation), new Type[] { typeof(ExtendedSaveFileInfo), typeof(Image) })] | ||
[HarmonyPrefix] | ||
public static void SaveLoadDialog_UpdateLoadMenuGameInformation(SaveLoadDialog __instance, ExtendedSaveFileInfo fileInfo, Image thumnailScreenshot) | ||
{ | ||
Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture; | ||
} | ||
|
||
[HarmonyPatch(typeof(CampaignLoadMenu), nameof(CampaignLoadMenu.UpdateLoadMenuGameInformation), new Type[] { typeof(ExtendedSaveFileInfo), typeof(Image) })] | ||
[HarmonyPrefix] | ||
public static void CampaignLoadMenu_UpdateLoadMenuGameInformation(CampaignLoadMenu __instance, ExtendedSaveFileInfo fileInfo, Image thumnailScreenshot) | ||
{ | ||
Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture; | ||
} | ||
|
||
[HarmonyPatch(typeof(CampaignTileEntry), nameof(CampaignTileEntry.Initialize), new Type[] { typeof(ExtendedSaveFileInfo), typeof(CampaignLoadMenu), typeof(CampaignMenu) })] | ||
[HarmonyPrefix] | ||
public static void CampaignTileEntry_UpdateLoadMenuGameInformation(CampaignTileEntry __instance, ExtendedSaveFileInfo fileInfo, CampaignLoadMenu loadMenu, CampaignMenu campaignMenu) | ||
{ | ||
Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters