-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Harmony patch to handle MFTs in B9PS (#338)
- Loading branch information
1 parent
db3ceb9
commit 2953743
Showing
6 changed files
with
189 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
using B9PartSwitch.PartSwitch.PartModifiers; | ||
|
||
namespace RealFuels.B9PSPatch | ||
{ | ||
public class ModuleFuelTanksHandler : PartModifierBase | ||
{ | ||
public const string PART_ASPECT_LOCK = "ModuleFuelTanks"; | ||
|
||
private readonly PartModule module; | ||
private readonly ConfigNode originalNode; | ||
private readonly ConfigNode dataNode; | ||
private readonly BaseEventDetails moduleDataChangedEventDetails; | ||
public ModuleFuelTanksHandler(PartModule module, ConfigNode originalNode, ConfigNode dataNode, BaseEventDetails moduleDataChangedEventDetails) | ||
{ | ||
this.module = module; | ||
this.originalNode = originalNode; | ||
this.dataNode = dataNode; | ||
this.moduleDataChangedEventDetails = moduleDataChangedEventDetails; | ||
} | ||
|
||
public object PartAspectLock => PART_ASPECT_LOCK; | ||
public override string Description => "a part's ModuleFuelTanks"; | ||
public override void DeactivateOnStartEditor() => Deactivate(); | ||
public override void ActivateOnStartEditor() => Activate(); | ||
public override void DeactivateOnSwitchEditor() => Deactivate(); | ||
public override void ActivateOnSwitchEditor() => Activate(); | ||
|
||
private void Activate() => ApplyNode(dataNode); | ||
private void Deactivate() => ApplyNode(originalNode); | ||
|
||
private void ApplyNode(ConfigNode sourceNode) | ||
{ | ||
var evtDetails = new BaseEventDetails(BaseEventDetails.Sender.USER); | ||
evtDetails.Set<ConfigNode>("MFTNode", sourceNode); | ||
module.Events.Send("LoadMFTModuleFromConfigNode", evtDetails); | ||
module.Events.Send("ModuleDataChanged", moduleDataChangedEventDetails); | ||
} | ||
} | ||
} |
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,32 @@ | ||
using HarmonyLib; | ||
using System.Collections.Generic; | ||
using B9PartSwitch.PartSwitch.PartModifiers; | ||
using B9PartSwitch; | ||
|
||
namespace RealFuels.B9PSPatch | ||
{ | ||
[HarmonyPatch(typeof(ModuleModifierInfo))] | ||
internal class PatchModuleModifierInfo | ||
{ | ||
[HarmonyPostfix] | ||
[HarmonyPatch("CreatePartModifiers")] | ||
internal static IEnumerable<IPartModifier> Postfix_CreatePartModifiers(IEnumerable<IPartModifier> result, Part part, ModuleModifierInfo __instance, BaseEventDetails moduleDataChangedEventDetails) | ||
{ | ||
foreach (var partModifier in result) | ||
{ | ||
if (partModifier is ModuleDataHandlerBasic) | ||
{ | ||
ModuleMatcher moduleMatcher = new ModuleMatcher(__instance.identifierNode); | ||
PartModule module = moduleMatcher.FindModule(part); | ||
ConfigNode originalNode = moduleMatcher.FindPrefabNode(module); | ||
if (module.moduleName == "ModuleFuelTanks") | ||
{ | ||
yield return new ModuleFuelTanksHandler(module, originalNode, __instance.dataNode, moduleDataChangedEventDetails); | ||
continue; | ||
} | ||
} | ||
yield return partModifier; | ||
} | ||
} | ||
} | ||
} |
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,14 @@ | ||
using UnityEngine; | ||
|
||
namespace RealFuels.B9PSPatch | ||
{ | ||
[KSPAddon(KSPAddon.Startup.Instantly, true)] | ||
public class HarmonyPatcher : MonoBehaviour | ||
{ | ||
internal void Start() | ||
{ | ||
var harmony = new HarmonyLib.Harmony("RealFuels.Harmony.HarmonyPatcher"); | ||
harmony.PatchAll(); | ||
} | ||
} | ||
} |
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,66 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{0041813D-DCD1-4AC7-8327-85765BF924A3}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<RootNamespace>RealFuelsB9PSPatch</RootNamespace> | ||
<AssemblyName>RealFuelsB9PSPatch</AssemblyName> | ||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> | ||
<TargetFrameworkProfile /> | ||
<ReleaseVersion>10.8.0</ReleaseVersion> | ||
<BaseIntermediateOutputPath>..\..\Build\RealFuels\obj</BaseIntermediateOutputPath> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugType>portable</DebugType> | ||
<Optimize>False</Optimize> | ||
<BaseIntermediateOutputPath>..\..\Build\RealFuels\obj\</BaseIntermediateOutputPath> | ||
<OutputPath>..\..\RealFuels\Plugins\</OutputPath> | ||
<DefineConstants>DEBUG;ENABLE_PROFILER</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<ConsolePause>False</ConsolePause> | ||
<DebugSymbols>true</DebugSymbols> | ||
<Prefer32Bit>false</Prefer32Bit> | ||
<PlatformTarget>x64</PlatformTarget> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>none</DebugType> | ||
<Optimize>True</Optimize> | ||
<BaseIntermediateOutputPath>..\..\Build\RealFuels\obj\</BaseIntermediateOutputPath> | ||
<OutputPath>..\..\RealFuels\Plugins\</OutputPath> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<ConsolePause>False</ConsolePause> | ||
<DebugSymbols>false</DebugSymbols> | ||
<Prefer32Bit>false</Prefer32Bit> | ||
<PlatformTarget>x64</PlatformTarget> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="0Harmony, Version=2.2.1.0, Culture=neutral, processorArchitecture=MSIL"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="Assembly-CSharp"> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="B9PartSwitch"> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="System"> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="UnityEngine.CoreModule"> | ||
<Private>False</Private> | ||
</Reference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> | ||
<ItemGroup> | ||
<Compile Include="assembly\AssemblyInfoB9PSPatch.cs" /> | ||
<Compile Include="HarmonyPatcher.cs" /> | ||
<Compile Include="B9PSMFTHandler.cs" /> | ||
<Compile Include="Harmony\B9PS.cs" /> | ||
</ItemGroup> | ||
<ItemGroup /> | ||
</Project> |
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,36 @@ | ||
#define CIBUILD_disabled | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
|
||
// Information about this assembly is defined by the following attributes. | ||
// Change them to the values specific to your project. | ||
|
||
[assembly: AssemblyTitle("RealFuelsB9PSPatch")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("")] | ||
[assembly: AssemblyCopyright("KSP-RO Group")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". | ||
// The form "{Major}.{Minor}.*" will automatically update the build and revision, | ||
// and "{Major}.{Minor}.{Build}.*" will update just the revision. | ||
|
||
[assembly: AssemblyVersion("1.0.0.0")] | ||
// [assembly: AssemblyInformationalVersionAttribute("@FULL_VERSION@")] | ||
#if CIBUILD | ||
[assembly: AssemblyFileVersion("@MAJOR@.@MINOR@.@PATCH@.@BUILD@")] | ||
[assembly: KSPAssembly("RealFuelsB9PSPatch", @MAJOR@, @MINOR@, @PATCH@)] | ||
#else | ||
[assembly: AssemblyFileVersion("1.0.0.0")] | ||
[assembly: KSPAssembly("RealFuelsB9PSPatch", 1, 0, 0)] | ||
#endif | ||
|
||
// The following attributes are used to specify the signing key for the assembly, | ||
// if desired. See the Mono documentation for more information about signing. | ||
|
||
//[assembly: AssemblyDelaySign(false)] | ||
//[assembly: AssemblyKeyFile("")] | ||
[assembly: KSPAssemblyDependency("B9PartSwitch", 2, 20)] |
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