Skip to content

Commit

Permalink
V1.17 :
Browse files Browse the repository at this point in the history
- New KSP bugfix : [StickySplashedFixer](#44) (@NathanKell)
- New modding bugfix : [DepartmentHeadImage](#47) (@NathanKell)
- PersistentIConfigNode patch : added `Guid` serialization support to `CreateObjectFromConfig()`, `LoadObjectFromConfig()` and `CreateConfigFromObject()` methods (@NathanKell).
  • Loading branch information
gotmachine committed Jan 30, 2023
1 parent a94f48a commit 40491c7
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 45 deletions.
2 changes: 1 addition & 1 deletion GameData/KSPCommunityFixes/KSPCommunityFixes.version
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"NAME": "KSPCommunityFixes",
"URL": "https://raw.githubusercontent.com/KSPModdingLibs/KSPCommunityFixes/master/GameData/KSPCommunityFixes/KSPCommunityFixes.version",
"DOWNLOAD": "https://github.com/KSPModdingLibs/KSPCommunityFixes/releases",
"VERSION": {"MAJOR": 1, "MINOR": 16, "PATCH": 1, "BUILD": 0},
"VERSION": {"MAJOR": 1, "MINOR": 17, "PATCH": 0, "BUILD": 0},
"KSP_VERSION": {"MAJOR": 1, "MINOR": 12, "PATCH": 3},
"KSP_VERSION_MIN": {"MAJOR": 1, "MINOR": 8, "PATCH": 0},
"KSP_VERSION_MAX": {"MAJOR": 1, "MINOR": 12, "PATCH": 3}
Expand Down
35 changes: 12 additions & 23 deletions KSPCommunityFixes/BugFixes/StickySplashedFixer.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
/*
The core of the issue is the asteroid/comet spawner passing a random int for the "id" argument of the ProtoVessel.CreatePartNode() method.
This id is affected to the part.flightId field, which must be unique game-wide and should have been generated by calling
ShipConstruction.GetUniqueFlightID(). Failing to produce an unique flightId result in various issues, especially with mods as they often
rely on that id.
Note that by fixing this, we replace how the asteroid/comet "seed" is generated, which technically affect further calls to UnityEngine.Random(),
but this shouldn't have any effect on the actual randomness/distribution of the generated stuff.
*/

using System;
using System;
using System.Collections.Generic;
using HarmonyLib;
using KSP.UI.Screens;

namespace KSPCommunityFixes.BugFixes
{
Expand All @@ -23,27 +12,27 @@ protected override void ApplyPatches(List<PatchInfo> patches)
{
patches.Add(new PatchInfo(
PatchMethodType.Prefix,
AccessTools.Method(typeof(Vessel), "updateSituation"),
AccessTools.Method(typeof(Vessel), nameof(Vessel.updateSituation)),
this));

patches.Add(new PatchInfo(
PatchMethodType.Prefix,
AccessTools.Method(typeof(Part), "Die"),
AccessTools.Method(typeof(Part), nameof(Part.Die)),
this));

patches.Add(new PatchInfo(
PatchMethodType.Postfix,
AccessTools.Method(typeof(Part), "Die"),
AccessTools.Method(typeof(Part), nameof(Part.Die)),
this));

patches.Add(new PatchInfo(
PatchMethodType.Prefix,
AccessTools.Method(typeof(Part), "decouple"),
AccessTools.Method(typeof(Part), nameof(Part.decouple)),
this));

patches.Add(new PatchInfo(
PatchMethodType.Postfix,
AccessTools.Method(typeof(Part), "decouple"),
AccessTools.Method(typeof(Part), nameof(Part.decouple)),
this));
}

Expand Down Expand Up @@ -114,25 +103,25 @@ static bool Vessel_updateSituation_Prefix(Vessel __instance)
// so a vessel isn't processed more than once if, say, multiple parts detach on the
// same frame. But the landed/splash check isn't very expensive so I'm not worried.

static void Part_die_Prefix(Part __instance, out Vessel __state)
static void Part_Die_Prefix(Part __instance, out Vessel __state)
{
__state = __instance.vessel;
}

static void Part_die_Postfix(Part __instance, Vessel __state)
static void Part_Die_Postfix(Vessel __state)
{
if (__state.IsNotNullOrDestroyed())
if (__state.IsNotNullOrDestroyed() && __state.state != Vessel.State.DEAD)
__state.UpdateLandedSplashed();
}

static void Part_Decouple_Prefix(Part __instance, out Vessel __state)
static void Part_decouple_Prefix(Part __instance, out Vessel __state)
{
__state = __instance.vessel;
}

static void Part_Decouple_Postfix(Part __instance, Vessel __state)
static void Part_decouple_Postfix(Vessel __state)
{
if (__state.IsNotNullOrDestroyed())
if (__state.IsNotNullOrDestroyed() && __state.state != Vessel.State.DEAD)
__state.UpdateLandedSplashed();

// New vessel (on __instance) will run Initialize.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
/*
The core of the issue is the asteroid/comet spawner passing a random int for the "id" argument of the ProtoVessel.CreatePartNode() method.
This id is affected to the part.flightId field, which must be unique game-wide and should have been generated by calling
ShipConstruction.GetUniqueFlightID(). Failing to produce an unique flightId result in various issues, especially with mods as they often
rely on that id.
Note that by fixing this, we replace how the asteroid/comet "seed" is generated, which technically affect further calls to UnityEngine.Random(),
but this shouldn't have any effect on the actual randomness/distribution of the generated stuff.
*/

using System;
using System;
using System.Collections.Generic;
using HarmonyLib;
using KSP.UI.Screens;

namespace KSPCommunityFixes.BugFixes
namespace KSPCommunityFixes.Modding
{
class DepartmentHeadImage : BasePatch
{
Expand All @@ -23,7 +13,7 @@ protected override void ApplyPatches(List<PatchInfo> patches)
{
patches.Add(new PatchInfo(
PatchMethodType.Postfix,
AccessTools.Method(typeof(Administration), "AddKerbalListItem"),
AccessTools.Method(typeof(Administration), nameof(Administration.AddKerbalListItem)),
this));
}

Expand Down
9 changes: 5 additions & 4 deletions KSPCommunityFixes/Modding/PersistentIConfigNode.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using HarmonyLib;
// - Add support for IConfigNode serialization
// - Add support for Guid serialization

using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using static ConfigNode;
using Random = System.Random;

// TODO: use transpilers instead of overriding the stock methods...

namespace KSPCommunityFixes.Modding
{
class PersistentIConfigNode : BasePatch
Expand Down Expand Up @@ -247,7 +248,7 @@ public class PersistentIConfigNodeTestModule : PartModule
[KSPEvent(active = true, guiActive = true, guiActiveEditor = true, guiName = "IConfigNode test")]
public void Test()
{
Random rnd = new Random();
System.Random rnd = new System.Random();

foo = new FloatCurve();
float time = rnd.Next(100);
Expand Down
4 changes: 2 additions & 2 deletions KSPCommunityFixes/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.16.1.0")]
[assembly: AssemblyFileVersion("1.16.1.0")]
[assembly: AssemblyVersion("1.17.0.0")]
[assembly: AssemblyFileVersion("1.17.0.0")]
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ User options are available from the "ESC" in-game settings menu :<br/><img src="
- **[ScatterDistribution](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/41)** [KSP 1.8.0 - 1.12.3]<br/>Fix incorrect terrain scatter distribution when a partial longitude range is defined in the PQSLandControl definition.
- **[LostSoundAfterSceneSwitch](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/42)** [KSP 1.12.0 - 1.12.3]<br/> Fix audio source not being centered/aligned with the current vessel after scene switches, causing loss of vessel effects audio and random volume or left/right channel weirdness.
- **[EVAKerbalRecovery](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/43)** [KSP 1.11.0 - 1.12.3]<br/> Fix recovery of EVAing kerbals either causing their inventory to be recovered twice or the science data they carry not being recovered, depending on the EVA kerbal variant/suit.

- **[StickySplashedFixer](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/44)** [KSP 1.8.0 - 1.12.3]<br/> Fix vessel never leaving the splashed state if it starts out splashed, and decouples from its only splashed parts. This also fixes an issue where Splashed overrides Prelaunch as a situation.

#### Quality of Life tweaks

Expand Down Expand Up @@ -90,8 +90,9 @@ User options are available from the "ESC" in-game settings menu :<br/><img src="
- **OnSymmetryFieldChanged** [KSP 1.8.0 - 1.12.3]<br/> Disabled by default, you can enable it with a MM patch. Change the `UI_Control.onSymmetryFieldChanged` callback to behave identically to the `UI_Control.onFieldChanged` callback :
- The callback will only be called when the field value has actually been modified.
- The "object" argument will contain the previous field value (instead of the new value).
- **PersistentIConfigNode** [KSP 1.8.0 - 1.12.3]<br/>Disabled by default, you can enable it with a MM patch. Implement `IConfigNode` members marked as `[Persistent]` serialization support when using the `CreateObjectFromConfig()`, `LoadObjectFromConfig()` and `CreateConfigFromObject()` methods.
- **PersistentIConfigNode** [KSP 1.8.0 - 1.12.3]<br/>Disabled by default, you can enable it with a MM patch. Implement `IConfigNode` members marked as `[Persistent]` serialization support when using the `CreateObjectFromConfig()`, `LoadObjectFromConfig()` and `CreateConfigFromObject()` methods. Also implements `Guid` serialization support for those methods.
- **ReflectionTypeLoadExceptionHandler** [KSP 1.8.0 - 1.12.3]<br/>Patch the BCL `Assembly.GetTypes()` method to always handle (gracefully) an eventual `ReflectionTypeLoadException`. Since having an assembly failing to load is a quite common scenario, this ensure such a situation won't cause issues with other plugins. Those exceptions are logged (but not re-thrown), and detailed information about offending plugins is shown on screen during loading so users are aware there is an issue with their install. This patch is always enabled and has no entry in `Settings.cfg`.
- **[DepartmentHeadImage](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/47)** [KSP 1.8.0 - 1.12.3]<br/> Fix administration building custom departement head image not being used when added by a mod.

### License

Expand Down Expand Up @@ -127,6 +128,11 @@ If doing so in the `Debug` configuration and if your KSP install is modified to

### Changelog

##### 1.17.0
- New KSP bugfix : [StickySplashedFixer](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/44) (@NathanKell)
- New modding bugfix : [DepartmentHeadImage](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/47) (@NathanKell)
- PersistentIConfigNode patch : added `Guid` serialization support to `CreateObjectFromConfig()`, `LoadObjectFromConfig()` and `CreateConfigFromObject()` methods (@NathanKell).

##### 1.16.1
- RoboticsDrift : fix "Servo info not found" log spam originating from servo parts for which the drift correction isn't enabled.

Expand Down

0 comments on commit 40491c7

Please sign in to comment.