Skip to content

Commit

Permalink
Fix issues with cheating vessels into orbit
Browse files Browse the repository at this point in the history
  • Loading branch information
siimav committed Oct 11, 2024
1 parent eccc552 commit 7319b86
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ public class KJRGroundJointModule : PartModule
private List<Part> clampParts;
private Dictionary<Part, FixedJoint> joints = new Dictionary<Part, FixedJoint>();
private bool alreadyUnpacked = false;
private bool subscribedToEvents = false;
private bool subscribedToVesselModifEvent = false;

public void Init(List<Part> clampParts)
{
this.clampParts = clampParts;

GameEvents.onPartDie.Add(OnPartDie);

Part[] orderedParts = vessel.parts.OrderByDescending(p => p.physicsMass).ToArray();
int i = 0;
int uniquePartsPicked = 0;
Expand Down Expand Up @@ -67,7 +69,7 @@ public void OnPartUnpack()
if (joints.Count > 0)
{
GameEvents.onVesselWasModified.Add(OnVesselWasModified);
subscribedToEvents = true;
subscribedToVesselModifEvent = true;

// By the time the code gets here, the stock CheckGroundCollision() method has been run at least once.
// With the extra world-space joints, it's safe to make the assumption that the vessel will
Expand All @@ -83,7 +85,17 @@ public void OnPartUnpack()

private void OnVesselWasModified(Vessel v)
{
BreakAllInvalidJoints();
if (v == vessel)
BreakAllInvalidJoints();
}

private void OnPartDie(Part p)
{
if (clampParts.Contains(p))
{
clampParts.Remove(p);
BreakAllInvalidJoints();
}
}

private void BreakAllInvalidJoints()
Expand All @@ -104,10 +116,10 @@ private void BreakAllInvalidJoints()

public void OnPartPack()
{
if (subscribedToEvents)
if (subscribedToVesselModifEvent)
{
GameEvents.onVesselWasModified.Remove(OnVesselWasModified);
subscribedToEvents = false;
subscribedToVesselModifEvent = false;
}

foreach (FixedJoint j in joints.Values)
Expand All @@ -119,11 +131,13 @@ public void OnPartPack()

public void OnDestroy()
{
if (subscribedToEvents)
if (subscribedToVesselModifEvent)
{
GameEvents.onVesselWasModified.Remove(OnVesselWasModified);
}

GameEvents.onPartDie.Remove(OnPartDie);

foreach (FixedJoint j in joints.Values)
Destroy(j);

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ Decoupler Stiffening Extension Types
***********************
****** CHANGELOG ******
***********************
v3.8.1

--Fix issues with cheating vessels into orbit

v3.8.0

--Add option to connect the heaviest parts of the vessel directly to ground. Replaces the lampJointHasInfiniteStrength option.
Expand Down

0 comments on commit 7319b86

Please sign in to comment.