Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
gotmachine committed Jun 30, 2022
2 parents 4969ef4 + 95c269c commit d024670
Show file tree
Hide file tree
Showing 10 changed files with 845 additions and 12 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": 17, "PATCH": 0, "BUILD": 0},
"VERSION": {"MAJOR": 1, "MINOR": 18, "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: 35 additions & 0 deletions GameData/KSPCommunityFixes/Settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ KSP_COMMUNITY_FIXES
// science data they carry not being recovered, depending on the EVA kerbal variant/suit.
EVAKerbalRecovery = true
// Fix rescaled servo parts propagating their scale to childrens after actuating the servo in the editor
RescaledRoboticParts = true
// ##########################
// Obsolete bugfixes
// ##########################
Expand All @@ -135,6 +138,9 @@ KSP_COMMUNITY_FIXES
// Allow tweaking the autostrut mode of wheels/landing legs
TweakableWheelsAutostrut = true
// Autostruts can be controlled with action groups
AutostrutActions = true
// Allow numeric input ("#" button) in "float edit" PAW items
UIFloatEditNumericInput = true
Expand Down Expand Up @@ -171,6 +177,35 @@ KSP_COMMUNITY_FIXES
// when moving around near a body surface
PQSUpdateNoMemoryAlloc = true

// Fix a bunch of managed memory leaks, mainly by proactively removing GameEvents delegates
// originating from destroyed UnityEngine.Object instances. Will log detected leaks and memory
// usage on scene switches.
MemoryLeaks = true

// Additional debugging options for the MemoryLeaks patch. This doesn't provide any user-facing
// benefit, it just enable extra logging options that are useful to track down memory leaks.
MEMORY_LEAKS_DEBUGGING
{
// Set to true if you want a more accurate figure for the managed memory usage logged by KSPCF
// on scene switches.
ForceGCCollect = false
// Enable detailed logging of GameEvents delegate leaks detected on scene switches. This only cover
// leaks originating from destroyed UnityEngine.Object derivatives.
LogDestroyedUnityObjectGameEventsLeaks = false
// This will compare alive GameEvents delegates between the last and current scene switch for a given
// scene, and log detailed information about classes that have an increasing amount of delegates for
// the same GameEvent. Note that this doesn't include destroyed UnityEngine.Object instances leaks, use
// the LogDestroyedUnityObjectGameEventsLeaks option to detect those.
AdvancedGameEventsLeakDetection = false

// Enable detailed logging of all GameEvents delegates remaining after scene destruction.
// By comparing the results between two scene switches, this allow hunting down classes that are
// leaking GameEvent subscriptions.
LogGameEventsSubscribers = false
}

// ##########################
// Modding
// ##########################
Expand Down
63 changes: 63 additions & 0 deletions KSPCommunityFixes/BugFixes/RescaledRoboticParts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Expansions.Serenity;
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using UnityEngine;

// fix scaled servo parts propagating their scale to childrens after actuating the servo in the editor
// see issue #48 : https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/48

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

protected override void ApplyPatches(List<PatchInfo> patches)
{
patches.Add(new PatchInfo(
PatchMethodType.Transpiler,
AccessTools.Method(typeof(BaseServo), nameof(BaseServo.SetChildParentTransform)),
this));
}

private static IEnumerable<CodeInstruction> BaseServo_SetChildParentTransform_Transpiler(IEnumerable<CodeInstruction> instructions)
{
MethodInfo mInfo_TransformSetParent = AccessTools.Method(typeof(Transform), nameof(Transform.SetParent), new Type[] { typeof(Transform) });
MethodInfo mInfo_TransformLocalScale = AccessTools.PropertySetter(typeof(Transform), nameof(Transform.localScale));
FieldInfo fInfo_BaseServoMovingPartObject = AccessTools.Field(typeof(BaseServo), nameof(BaseServo.movingPartObject));

List<CodeInstruction> code = new List<CodeInstruction>(instructions);

for (int i = 0; i < code.Count; i++)
{
if (code[i].opcode == OpCodes.Ldfld && ReferenceEquals(code[i].operand, fInfo_BaseServoMovingPartObject))
{
for (int j = i + 1; j < i + 6; j++)
{
if (code[j].opcode == OpCodes.Callvirt && ReferenceEquals(code[j].operand, mInfo_TransformSetParent))
{
int k = j;
bool end = false;
do
{
k++;
end = code[k].opcode == OpCodes.Callvirt && ReferenceEquals(code[k].operand, mInfo_TransformLocalScale);
code[k].opcode = OpCodes.Nop;
code[k].operand = null;
}
while (!end);

i = k;
break;
}
}
}
}

return code;
}
}
}
9 changes: 5 additions & 4 deletions KSPCommunityFixes/KSPCommunityFixes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class KSPCommunityFixes : MonoBehaviour
public static HashSet<string> enabledPatches = new HashSet<string>();
public static Dictionary<Type, BasePatch> patchInstances = new Dictionary<Type, BasePatch>();

public static ConfigNode SettingsNode { get; private set; }

public static KSPCommunityFixes Instance { get; private set; }

private static string modPath;
Expand Down Expand Up @@ -73,13 +75,12 @@ public void ModuleManagerPostLoad()

UrlDir.UrlConfig[] featuresNodes = GameDatabase.Instance.GetConfigs(CONFIGNODE_NAME);

ConfigNode cfg;
if (featuresNodes != null && featuresNodes.Length == 1)
cfg = featuresNodes[0].config;
SettingsNode = featuresNodes[0].config;
else
cfg = new ConfigNode();
SettingsNode = new ConfigNode();

foreach (ConfigNode.Value value in cfg.values)
foreach (ConfigNode.Value value in SettingsNode.values)
{
if (!bool.TryParse(value.value, out bool patchEnabled) || patchEnabled)
{
Expand Down
3 changes: 3 additions & 0 deletions KSPCommunityFixes/KSPCommunityFixes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="BasePatch.cs" />
<Compile Include="Performance\MemoryLeaks.cs" />
<Compile Include="BugFixes\RescaledRoboticParts.cs" />
<Compile Include="Modding\DepartmentHeadImage.cs" />
<Compile Include="BugFixes\StickySplashedFixer.cs" />
<Compile Include="BugFixes\AsteroidSpawnerUniqueFlightId.cs" />
Expand All @@ -116,6 +118,7 @@
<Compile Include="Modding\OnSymmetryFieldChanged.cs" />
<Compile Include="Modding\ReflectionTypeLoadExceptionHandler.cs" />
<Compile Include="Performance\PQSUpdateNoMemoryAlloc.cs" />
<Compile Include="QoL\AutostrutActions.cs" />
<Compile Include="QoL\DisableNewGameIntro.cs" />
<Compile Include="QoL\NoIVA.cs" />
<Compile Include="Performance\OnDemandPartBuoyancy.cs" />
Expand Down
Loading

0 comments on commit d024670

Please sign in to comment.