Skip to content
Merged
2 changes: 2 additions & 0 deletions GameData/KSPCommunityFixes/Settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ KSP_COMMUNITY_FIXES
// but this helps a bit in other cases as well.
FloatingOriginPerf = true

PartParsingPerf = true

// ##########################
// Modding
// ##########################
Expand Down
13 changes: 12 additions & 1 deletion KSPCommunityFixes/BasePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ internal class TranspileInDebugAttribute : Attribute
{
}

/// <summary>
/// When applied to a class derived from <see cref="BasePatch"/>, the patch won't be automatically applied.<para/>
/// To apply the patch, call <see cref="BasePatch.Patch"/>. Note that if that call happens before ModuleManager
/// has patched the configs (ie, before part compilation), <see cref="BasePatch.IgnoreConfig"/> must be overriden
/// to return <see langword="true"/>, or the patch won't be applied.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
internal class ManualPatchAttribute : Attribute
{
}

public abstract class BasePatch
{
public static readonly string pluginData = "PluginData";
Expand All @@ -64,7 +75,7 @@ public static void Patch(Type patchType)

if (!patch.IgnoreConfig && !KSPCommunityFixes.enabledPatches.Contains(patchType.Name))
{
Debug.Log($"[KSPCommunityFixes] Patch {patchType.Name} not applied (disabled in Settings.cfg)");
Debug.Log($"[KSPCommunityFixes] Patch {patchType.Name} not applied (not enabled in Settings.cfg)");
return;
}

Expand Down
17 changes: 9 additions & 8 deletions KSPCommunityFixes/KSPCommunityFixes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class KSPCommunityFixes : MonoBehaviour

public static string LOC_KSPCF_Title = "KSP Community Fixes";


public static Harmony Harmony { get; private set; }

public static HashSet<string> enabledPatches = new HashSet<string>();
Expand Down Expand Up @@ -50,6 +49,14 @@ public static Version KspVersion
}
}

static KSPCommunityFixes()
{
Harmony = new Harmony("KSPCommunityFixes");
#if DEBUG
Harmony.DEBUG = true;
#endif
}

public static T GetPatchInstance<T>() where T : BasePatch
{
if (!patchInstances.TryGetValue(typeof(T), out BasePatch instance))
Expand All @@ -72,11 +79,6 @@ void Start()
DontDestroyOnLoad(this);
}

Harmony = new Harmony("KSPCommunityFixes");

#if DEBUG
Harmony.DEBUG = true;
#endif
LocalizationUtils.GenerateLocTemplateIfRequested();
LocalizationUtils.ParseLocalization();

Expand Down Expand Up @@ -113,10 +115,9 @@ public void MMPostLoadCallback()
List<Type> patchesTypes = new List<Type>();
foreach (Type type in Assembly.GetAssembly(basePatchType).GetTypes())
{
if (!type.IsAbstract && type.IsSubclassOf(basePatchType))
if (!type.IsAbstract && type.IsSubclassOf(basePatchType) && type.GetCustomAttribute<ManualPatchAttribute>() == null)
{
patchesTypes.Add(type);

}
}

Expand Down
7 changes: 6 additions & 1 deletion KSPCommunityFixes/KSPCommunityFixes.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Krafs.Publicizer.2.2.1\build\Krafs.Publicizer.props" Condition="Exists('..\packages\Krafs.Publicizer.2.2.1\build\Krafs.Publicizer.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
Expand Down Expand Up @@ -155,13 +155,16 @@
<Compile Include="Library\LocalizationUtils.cs" />
<Compile Include="Library\Numerics.cs" />
<Compile Include="Library\ObjectPool.cs" />
<Compile Include="Library\MuParser.cs" />
<Compile Include="Library\ShaderHelpers.cs" />
<Compile Include="Modding\KSPFieldEnumDesc.cs" />
<Compile Include="Modding\ModUpgradePipeline.cs" />
<Compile Include="Performance\ForceSyncSceneSwitch.cs" />
<Compile Include="Performance\AsteroidAndCometDrillCache.cs" />
<Compile Include="BugFixes\DoubleCurvePreserveTangents.cs" />
<Compile Include="BugFixes\RestoreMaxPhysicsDT.cs" />
<Compile Include="Performance\FloatingOriginPerf.cs" />
<Compile Include="Performance\GameDatabasePerf.cs" />
<Compile Include="Performance\PartSystemsFastUpdate.cs" />
<Compile Include="Performance\CollisionEnhancerFastUpdate.cs" />
<Compile Include="Performance\CollisionManagerFastUpdate.cs" />
Expand All @@ -173,6 +176,7 @@
<Compile Include="Performance\FasterPartFindTransform.cs" />
<Compile Include="Performance\FastLoader.cs" />
<Compile Include="Performance\FlightIntegratorPerf.cs" />
<Compile Include="Performance\PartParsingPerf.cs" />
<Compile Include="Performance\IMGUIOptimization.cs" />
<Compile Include="Performance\LocalizerPerf.cs" />
<Compile Include="Performance\LowerMinPhysicsDTPerFrame.cs" />
Expand Down Expand Up @@ -254,6 +258,7 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<!--Project-specfic configuration-->
<PropertyGroup>
<RepoRootPath>$(SolutionDir)</RepoRootPath>
Expand Down
Loading