Skip to content

Commit

Permalink
New patch : RescaledRoboticParts, fix rescaled servo parts progating …
Browse files Browse the repository at this point in the history
…their scale to child parts in the editor (issue #48).

Version bump to 1.18
  • Loading branch information
gotmachine committed Jan 30, 2023
1 parent 40491c7 commit 7a04efb
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 8 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
3 changes: 3 additions & 0 deletions GameData/KSPCommunityFixes/Settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,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
// Fix Admin Building not using HeadImage if that is defined for a Department but a kerbal prefab is not
DepartmentHeadImage = true
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;
}
}
}
1 change: 1 addition & 0 deletions KSPCommunityFixes/KSPCommunityFixes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="BasePatch.cs" />
<Compile Include="BugFixes\RescaledRoboticParts.cs" />
<Compile Include="BugFixes\StickySplashedFixer.cs" />
<Compile Include="BugFixes\DepartmentHeadImage.cs" />
<Compile Include="BugFixes\AsteroidSpawnerUniqueFlightId.cs" />
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.17.0.0")]
[assembly: AssemblyFileVersion("1.17.0.0")]
[assembly: AssemblyVersion("1.18.0.0")]
[assembly: AssemblyFileVersion("1.18.0.0")]
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ User options are available from the "ESC" in-game settings menu :<br/><img src="
- **[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.
- **[RescaledRoboticParts](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/48)** [KSP 1.8.0 - 1.12.3]<br/> Fix rescaled robotics parts propagating their scale to childrens after actuating the servo in the editor

#### Quality of Life tweaks

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

### Changelog

##### 1.18.0
- New KSP bugfix : [RescaledRoboticParts](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/48) (thanks to @pap1723)

##### 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).
- New KSP bugfix : [StickySplashedFixer](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/44) (thanks to @NathanKell)
- New modding bugfix : [DepartmentHeadImage](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/47) (thanks to @NathanKell)
- PersistentIConfigNode patch : added `Guid` serialization support to `CreateObjectFromConfig()`, `LoadObjectFromConfig()` and `CreateConfigFromObject()` methods (thanks to @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 All @@ -142,8 +146,8 @@ If doing so in the `Debug` configuration and if your KSP install is modified to
- Codebase cleaning pass, analyzers are now happy (or silenced).

##### 1.15.0
- New KSP bugfix : [ScatterDistribution](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/41) (credit to @R-T-B)
- New KSP bugfix : [LostSoundAfterSceneSwitch](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/42) (credit to @ensou04)
- New KSP bugfix : [ScatterDistribution](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/41) (thanks to @R-T-B)
- New KSP bugfix : [LostSoundAfterSceneSwitch](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/42) (thanks to @ensou04)
- Fixed KerbalInventoryPersistence patch not being applied on KSP 1.12.3

##### 1.14.1
Expand Down

0 comments on commit 7a04efb

Please sign in to comment.