diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 6d97cd0..e1c3e75 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -15,4 +15,5 @@ jobs:
build:
uses: KSPModdingLibs/KSPBuildTools/.github/workflows/build.yml@main
with:
- solution-file-path: 'Source/KSPCommunityPartModules.sln'
\ No newline at end of file
+ solution-file-path: 'Source/KSPCommunityPartModules.sln'
+ use-ckan: true
diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml
index 6f856a3..17f57e4 100644
--- a/.github/workflows/create-release.yml
+++ b/.github/workflows/create-release.yml
@@ -12,4 +12,5 @@ jobs:
uses: KSPModdingLibs/KSPBuildTools/.github/workflows/create-release.yml@main
with:
solution-file-path: 'Source/KSPCommunityPartModules.sln'
- version-string: ${{ inputs.version-string }}
\ No newline at end of file
+ version-string: ${{ inputs.version-string }}
+ use-ckan: true
diff --git a/GameData/KSPCommunityPartModules/KSPCommunityPartModules.ckan b/GameData/KSPCommunityPartModules/KSPCommunityPartModules.ckan
index 03ec809..e025616 100644
--- a/GameData/KSPCommunityPartModules/KSPCommunityPartModules.ckan
+++ b/GameData/KSPCommunityPartModules/KSPCommunityPartModules.ckan
@@ -9,6 +9,8 @@ description: >-
This mod is meant as community project, so feel free to propose additional module ideas by opening an issue, or contribute with a pull request on GitHub.
ksp_version_min: '1.12.3'
+depends:
+ - name: Harmony2
supports:
- name: BoringCrewServices
- name: BluedogDB
diff --git a/Source/KSPCommunityPartModules.csproj b/Source/KSPCommunityPartModules.csproj
index 0799d2d..9417581 100644
--- a/Source/KSPCommunityPartModules.csproj
+++ b/Source/KSPCommunityPartModules.csproj
@@ -31,7 +31,7 @@
4
-
+
@@ -41,6 +41,11 @@
-
+
+
+ False
+ Harmony2
+
+
\ No newline at end of file
diff --git a/Source/Modules/ModuleAutoCutDrogue.cs b/Source/Modules/ModuleAutoCutDrogue.cs
index a351388..451dd8e 100644
--- a/Source/Modules/ModuleAutoCutDrogue.cs
+++ b/Source/Modules/ModuleAutoCutDrogue.cs
@@ -4,6 +4,8 @@
Originally By: Jsolson
Originally For: Bluedog Design Bureau
*/
+using HarmonyLib;
+using System;
using System.Linq;
using UnityEngine;
@@ -22,6 +24,10 @@ class ModuleAutoCutDrogue : PartModule
public bool triggered = false;
private ModuleParachute chute = null;
+
+ // Technically this creates an edge case where if two loaded vessels deploy a main parachute at the same time only one of the vessels will cut its drogue chutes,
+ // but I feel like its unlikely enough to not warrent the effort required to fix it.
+ private static int lastFrame;
private bool IsChuteDeployed(ModuleParachute pParachute) => pParachute.deploymentState == ModuleParachute.deploymentStates.DEPLOYED
|| pParachute.deploymentState == ModuleParachute.deploymentStates.SEMIDEPLOYED;
public override void OnStart(StartState state)
@@ -32,33 +38,71 @@ public override void OnStart(StartState state)
Fields[nameof(autoCutDrogue)].guiActive = !isDrogueChute;
Fields[nameof(autoCutDrogue)].guiActiveEditor = !isDrogueChute;
+
+ if (!isDrogueChute) ModuleParachuteEvents.OnDeployed += OnParachuteDeployed;
+ if (!isDrogueChute) ModuleParachuteEvents.OnRepacked += OnParachuteRepacked;
}
- public void FixedUpdate()
+ public void OnDestroy()
{
- if (isDrogueChute || chute == null)
- {
- this.isEnabled = false;
- this.enabled = false;
- return;
- }
+ ModuleParachuteEvents.OnDeployed -= OnParachuteDeployed;
+ ModuleParachuteEvents.OnRepacked -= OnParachuteRepacked;
+ }
- if (IsChuteDeployed(chute))
+ private void OnParachuteDeployed(ModuleParachute pChute)
+ {
+ if (autoCutDrogue && !triggered && pChute == chute)
{
- if (!triggered)
+ if (lastFrame != Time.frameCount)
{
var drogues = vessel.FindPartModulesImplementing().Where(d => d.isDrogueChute && d.chute != null);
foreach (ModuleAutoCutDrogue d in drogues)
{
if (IsChuteDeployed(d.chute)) d.chute.CutParachute();
}
- triggered = true;
+ lastFrame = Time.frameCount;
}
+ triggered = true;
}
- else if (chute.deploymentState == ModuleParachute.deploymentStates.STOWED)
- {
- triggered = false;
- }
+ }
+
+ private void OnParachuteRepacked(ModuleParachute pChute)
+ {
+ if (triggered && pChute == chute) triggered = false;
+ }
+ }
+
+ [HarmonyPatch(typeof(ModuleParachute))]
+ internal class ModuleParachuteEvents
+ {
+ public static void ModuleManagerPostLoad()
+ {
+ Harmony harmony = new Harmony("KSPCommunityPartModules");
+ harmony.PatchAll();
+ }
+
+ public static event Action OnDeployed;
+ public static event Action OnRepacked;
+
+ [HarmonyPostfix]
+ [HarmonyPatch("OnParachuteSemiDeployed")]
+ static void RaiseEventOnSemiDeployed(ModuleParachute __instance)
+ {
+ OnDeployed?.Invoke(__instance);
+ }
+
+ [HarmonyPostfix]
+ [HarmonyPatch("OnParachuteFullyDeployed")]
+ static void RaiseEventOnFullyDeployed(ModuleParachute __instance)
+ {
+ OnDeployed?.Invoke(__instance);
+ }
+
+ [HarmonyPostfix]
+ [HarmonyPatch("Repack")]
+ static void RaiseEventOnRepack(ModuleParachute __instance)
+ {
+ OnRepacked?.Invoke(__instance);
}
}
}