Skip to content

Commit

Permalink
New KSP bugfix (issue #107) : ChutePhantomSymmetry
Browse files Browse the repository at this point in the history
  • Loading branch information
gotmachine committed Dec 31, 2022
1 parent 716d0e8 commit e197945
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
3 changes: 3 additions & 0 deletions GameData/KSPCommunityFixes/Settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ KSP_COMMUNITY_FIXES
// Avoids big spikes on the poles and incorrect biomes where the oles have disparate biomes.
MapSOCorrectWrapping = true
// Fix spread angle still being applied after decoupling symmetry-placed parachutes.
ChutePhantomSymmetry = true
// ##########################
// Obsolete bugfixes
// ##########################
Expand Down
70 changes: 70 additions & 0 deletions KSPCommunityFixes/BugFixes/ChutePhantomSymmetry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using HarmonyLib;
using System;
using System.Collections.Generic;
using static PartModule;

namespace KSPCommunityFixes.BugFixes
{
internal class ChutePhantomSymmetry : BasePatch
{
protected override Version VersionMin => new Version(1, 10, 0);

protected override void ApplyPatches(List<PatchInfo> patches)
{
patches.Add(new PatchInfo(
PatchMethodType.Postfix,
AccessTools.Method(typeof(ModuleParachute), nameof(ModuleParachute.OnStart)),
this));

patches.Add(new PatchInfo(
PatchMethodType.Postfix,
AccessTools.Method(typeof(ModuleParachute), nameof(ModuleParachute.OnDestroy)),
this));
}

private static void ModuleParachute_OnStart_Postfix(ModuleParachute __instance, StartState state)
{
if (state == StartState.Editor)
return;

eventHandlers.Add(__instance, new EventHandler(__instance));
}

private static void ModuleParachute_OnDestroy_Postfix(ModuleParachute __instance)
{
if (eventHandlers.Remove(__instance, out EventHandler eventHandler))
eventHandler.OnDestroy();
}

private static Dictionary<ModuleParachute, EventHandler> eventHandlers = new Dictionary<ModuleParachute, EventHandler>(16);

private class EventHandler
{
private ModuleParachute instance;

public EventHandler(ModuleParachute instance)
{
this.instance = instance;
GameEvents.onPartDeCoupleNewVesselComplete.Add(OnEvent);
}

public void OnDestroy()
{
GameEvents.onPartDeCoupleNewVesselComplete.Remove(OnEvent);
}

private void OnEvent(Vessel oldVessel, Vessel newVessel)
{
if (newVessel.NotDestroyedRefNotEquals(instance.vessel))
return;

int count = instance.part.symmetryCounterparts?.Count ?? 0;

if (count > 0)
count++;

instance.symmetryCount = count;
}
}
}
}
1 change: 1 addition & 0 deletions KSPCommunityFixes/KSPCommunityFixes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
<ItemGroup>
<Compile Include="BasePatch.cs" />
<Compile Include="BugFixes\AsteroidInfiniteMining.cs" />
<Compile Include="BugFixes\ChutePhantomSymmetry.cs" />
<Compile Include="BugFixes\MapSOCorrectWrapping.cs" />
<Compile Include="BugFixes\UpgradeBugs.cs" />
<Compile Include="BugFixes\PartTooltipUpgradesApplyToSubstituteParts.cs" />
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ User options are available from the "ESC" in-game settings menu :<br/><img src="
- **[StrategyDuration](https://github.com/KSPModdingLibs/KSPCommunityFixes/pull/70)** [KSP 1.8.0 - 1.12.4]<br/>Fix Strategies not using Duration settings.
- **[UpgradeBugs](https://github.com/KSPModdingLibs/KSPCommunityFixes/pull/63)** [KSP 1.12.0 - 1.12.4]<br/>Fix various bugs with upgrades, like the part stats upgrade module breaking, upgrades not properly applying in the editor, upgrade cost not being applied to part cost, and various issues int the public API.
- **[MapSOCorrectWrapping](https://github.com/KSPModdingLibs/KSPCommunityFixes/pull/83)** [KSP 1.10.0 - 1.12.4]<br/>Fixes issues with biomes crossing the poles (South pole biome at north pole and vice versa). Fixes "polar spikes" in the terrain for 8-bit heightmaps.
- **[ChutePhantomSymmetry](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/107)** [KSP 1.10.0 - 1.12.4]<br/>Fix spread angle still being applied after decoupling symmetry-placed parachutes.

#### Quality of Life tweaks

Expand Down

0 comments on commit e197945

Please sign in to comment.