-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New KSP bugfix (issue #42) : Fix audio source not being centered/alig…
…ned with the current vessel after scene switches, causing loss of vessel effects audio and random volume or left/right channel weirdness. Thanks to @ensou04 for uncovering the cause of this bug.
- Loading branch information
1 parent
18e152b
commit 502f00c
Showing
4 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using HarmonyLib; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using System.Reflection.Emit; | ||
using UnityEngine; | ||
|
||
namespace KSPCommunityFixes.BugFixes | ||
{ | ||
class LostSoundAfterSceneSwitch : BasePatch | ||
{ | ||
protected override Version VersionMin => new Version(1, 12, 0); | ||
|
||
protected override void ApplyPatches(ref List<PatchInfo> patches) | ||
{ | ||
patches.Add(new PatchInfo( | ||
PatchMethodType.Transpiler, | ||
AccessTools.Method(typeof(FlightCamera), nameof(FlightCamera.EnableCamera)), | ||
this)); | ||
|
||
patches.Add(new PatchInfo( | ||
PatchMethodType.Transpiler, | ||
AccessTools.Method(typeof(FlightCamera), nameof(FlightCamera.DisableCamera), new[] {typeof(bool)}), | ||
this)); | ||
} | ||
|
||
static IEnumerable<CodeInstruction> FlightCamera_EnableCamera_Transpiler(IEnumerable<CodeInstruction> instructions) | ||
{ | ||
MethodInfo setParentOriginal = AccessTools.Method(typeof(Transform), nameof(Transform.SetParent), new[] {typeof(Transform)}); | ||
MethodInfo setParentReplacement = AccessTools.Method(typeof(Transform), nameof(Transform.SetParent), new[] { typeof(Transform), typeof(bool) }); | ||
List<CodeInstruction> code = new List<CodeInstruction>(instructions); | ||
|
||
for (int i = 0; i < code.Count; i++) | ||
{ | ||
if (code[i].opcode == OpCodes.Callvirt && ReferenceEquals(code[i].operand, setParentOriginal)) | ||
{ | ||
code[i].operand = setParentReplacement; | ||
code.Insert(i, new CodeInstruction(OpCodes.Ldc_I4_0)); | ||
} | ||
} | ||
|
||
|
||
return code; | ||
} | ||
|
||
static IEnumerable<CodeInstruction> FlightCamera_DisableCamera_Transpiler(IEnumerable<CodeInstruction> instructions) | ||
{ | ||
MethodInfo setParentOriginal = AccessTools.Method(typeof(Transform), nameof(Transform.SetParent), new[] { typeof(Transform) }); | ||
MethodInfo setParentReplacement = AccessTools.Method(typeof(Transform), nameof(Transform.SetParent), new[] { typeof(Transform), typeof(bool) }); | ||
|
||
List<CodeInstruction> code = new List<CodeInstruction>(instructions); | ||
|
||
for (int i = 0; i < code.Count; i++) | ||
{ | ||
if (code[i].opcode == OpCodes.Callvirt && ReferenceEquals(code[i].operand, setParentOriginal)) | ||
{ | ||
code[i].operand = setParentReplacement; | ||
code.Insert(i, new CodeInstruction(OpCodes.Ldc_I4_0)); | ||
} | ||
} | ||
|
||
return code; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters