Skip to content

Commit

Permalink
Move harmony patch to separate project
Browse files Browse the repository at this point in the history
  • Loading branch information
StonesmileGit committed Mar 26, 2024
1 parent 5e0932b commit f86c443
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 50 deletions.
41 changes: 41 additions & 0 deletions Source/B9PSPatch/B9PS.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using HarmonyLib;
using System.Linq;
using System.Collections.Generic;
using B9PartSwitch.PartSwitch.PartModifiers;
using B9PartSwitch;

namespace RealFuels.Harmony
{
[HarmonyPatch(typeof(ModuleModifierInfo))]
internal class PatchModuleModifierInfo
{
internal static bool Prepare()
{
bool foundB9PS = AssemblyLoader.loadedAssemblies.FirstOrDefault(a => a.name.Equals("B9PartSwitch", System.StringComparison.OrdinalIgnoreCase)) != null;
return foundB9PS;
}


[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;
}

}
}
}
42 changes: 1 addition & 41 deletions Source/Harmony/B9PS.cs → Source/B9PSPatch/B9PSMFTHandler.cs
Original file line number Diff line number Diff line change
@@ -1,45 +1,5 @@
using HarmonyLib;
using UnityEngine;
using System.Linq;
using System.Collections.Generic;
using B9PartSwitch.PartSwitch.PartModifiers;
using B9PartSwitch;

namespace RealFuels.Harmony
{
[HarmonyPatch(typeof(ModuleModifierInfo))]
internal class PatchModuleModifierInfo
{
internal static bool Prepare()
{
bool foundB9PS = AssemblyLoader.loadedAssemblies.FirstOrDefault(a => a.name.Equals("B9PartSwitch", System.StringComparison.OrdinalIgnoreCase)) != null;
return foundB9PS;
}


[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;
}

}
}
}
using B9PartSwitch.PartSwitch.PartModifiers;

namespace RealFuels.Harmony
{
Expand Down
File renamed without changes.
70 changes: 70 additions & 0 deletions Source/B9PSPatch/RealFuelsB9PSPatch.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?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="B9PS.cs" />
<None Include="tools\git-version-gen" />
<None Include="tools\git-version-mft.sh" />
<None Include="tools\git-version-rf.sh" />
<None Include="tools\post-build-rf.sh" />
</ItemGroup>
<ItemGroup />
</Project>
36 changes: 36 additions & 0 deletions Source/B9PSPatch/assembly/AssemblyInfoB9PSPatch.cs
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)]
9 changes: 0 additions & 9 deletions Source/RealFuels.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,9 @@
<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="ROUtils">
<HintPath>..\..\..\..\..\..\Games\R112\GameData\ROUtils\Plugins\ROUtils.dll</HintPath>
<Private>False</Private>
Expand Down Expand Up @@ -109,8 +102,6 @@
<Compile Include="EntryCosts\UpgradeManager.cs" />
<Compile Include="EntryCosts\EntryCostDatabase.cs" />
<Compile Include="EntryCosts\PartEntryCostHolder.cs" />
<Compile Include="Harmony\HarmonyPatcher.cs" />
<Compile Include="Harmony\B9PS.cs" />
<Compile Include="Pumps\RefuelingPump.cs" />
<Compile Include="Tanks\EditorCrossfeedSetMaintainer.cs" />
<Compile Include="Tanks\FuelInfo.cs" />
Expand Down
1 change: 1 addition & 0 deletions Source/RealFuels.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
VisualStudioVersion = 16.0.31229.75
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RealFuels", "RealFuels.csproj", "{0041813D-DCD1-4AC7-8327-85765BF924A3}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBD}") = "RealFuelsB9PSPatch", "B9PSPatch/RealFuelsB9PSPatch.csproj", "{0041813D-DCD1-4AC7-8327-85765BF924A3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down

0 comments on commit f86c443

Please sign in to comment.