Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New QoL/Perf patch : OptionalMakingHistoryDLCFeatures #219

Merged
merged 4 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions GameData/KSPCommunityFixes/Localization/en-us.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ Localization
#KSPCF_AltimeterHorizontalPosition_SettingsTitle = Altimeter pos (Left<->Right)
#KSPCF_AltimeterHorizontalPosition_SettingsTooltip = Set the horizontal position of the flight scene altimeter widget

// OptionalMakingHistoryDLCFeatures

#KSPCF_OptionalMakingHistoryDLCFeatures_MHDLC = Making History features
#KSPCF_OptionalMakingHistoryDLCFeatures_SettingsTooltip = Disable the Making History DLC mission editor and additional launch sites\nThe Making History parts will still be available\nWill reduce memory usage and increase loading speed\nChanges will take effect after restarting KSP

// NoIVA

#KSPCF_NoIVA_KeepAll = Keep all
Expand Down
8 changes: 8 additions & 0 deletions GameData/KSPCommunityFixes/Settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,14 @@ KSP_COMMUNITY_FIXES
// Invert the editor undo state capturing logic so part tweaks aren't lost when undoing.
BetterEditorUndoRedo = true

// Allow to disable the Making History DLC mission editor and additional launch sites features
// to decrease memory usage and increase loading speed. The Making History parts will still be
// available. Can be toggled from the KSPCF in-game settings (requires a restart).
OptionalMakingHistoryDLCFeatures = true

// Optional MM-patcheable toggle to always disable the MH features
OptionalMakingHistoryDLCFeaturesAlwaysDisable = false

// ##########################
// Performance tweaks
// ##########################
Expand Down
28 changes: 28 additions & 0 deletions KSPCommunityFixes/Internal/PatchSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class PatchSettings : BasePatch
private static int entryCount = 0;
private static AltimeterHorizontalPosition altimeterPatch;
private static DisableManeuverTool maneuverToolPatch;
private static OptionalMakingHistoryDLCFeatures disableMHPatch;

protected override void ApplyPatches(List<PatchInfo> patches)
{
Expand All @@ -39,6 +40,10 @@ protected override void ApplyPatches(List<PatchInfo> patches)
if (maneuverToolPatch != null)
entryCount++;

disableMHPatch = KSPCommunityFixes.GetPatchInstance<OptionalMakingHistoryDLCFeatures>();
if (disableMHPatch != null)
entryCount++;

if (KSPCFFastLoader.IsPatchEnabled)
entryCount++;

Expand All @@ -61,6 +66,22 @@ static void GameplaySettingsScreen_DrawMiniSettings_Postfix(ref DialogGUIBase[]
modifiedResult[count] = new DialogGUIBox(KSPCommunityFixes.LOC_KSPCF_Title, -1f, 18f, null);
count++;

if (disableMHPatch != null)
{
DialogGUIToggle toggle = new DialogGUIToggle(OptionalMakingHistoryDLCFeatures.isMHEnabled,
() => (!OptionalMakingHistoryDLCFeatures.isMHEnabled)
? Localizer.Format("#autoLOC_6001071") //"Disabled"
: Localizer.Format("#autoLOC_6001072"), //"Enabled"
b => OptionalMakingHistoryDLCFeatures.isMHEnabled = b, 150f);
toggle.tooltipText = OptionalMakingHistoryDLCFeatures.LOC_SettingsTooltip;
toggle.OptionInteractableCondition = () => !OptionalMakingHistoryDLCFeatures.isMHDisabledFromConfig;

modifiedResult[count] = new DialogGUIHorizontalLayout(TextAnchor.MiddleLeft,
new DialogGUILabel(() => Localizer.Format(OptionalMakingHistoryDLCFeatures.LOC_MHDLC), 150f), //"Maneuver Tool"
toggle, new DialogGUIFlexibleSpace());
count++;
}

if (maneuverToolPatch != null)
{
DialogGUIToggle toggle = new DialogGUIToggle(DisableManeuverTool.enableManeuverTool,
Expand Down Expand Up @@ -120,6 +141,13 @@ static void GameplaySettingsScreen_DrawMiniSettings_Postfix(ref DialogGUIBase[]

static void GameplaySettingsScreen_ApplySettings_Postfix()
{
if (disableMHPatch != null)
{
ConfigNode node = new ConfigNode();
node.AddValue(nameof(OptionalMakingHistoryDLCFeatures.isMHEnabled), OptionalMakingHistoryDLCFeatures.isMHEnabled);
SaveData<OptionalMakingHistoryDLCFeatures>(node);
}

if (maneuverToolPatch != null)
{
ConfigNode node = new ConfigNode();
Expand Down
1 change: 1 addition & 0 deletions KSPCommunityFixes/KSPCommunityFixes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
<Compile Include="Performance\ProgressTrackingSpeedBoost.cs" />
<Compile Include="QoL\AutostrutActions.cs" />
<Compile Include="QoL\BetterEditorUndoRedo.cs" />
<Compile Include="QoL\OptionalMakingHistoryDLCFeatures.cs" />
<Compile Include="QoL\ToolbarShowHide.cs" />
<Compile Include="QoL\DisableNewGameIntro.cs" />
<Compile Include="QoL\NoIVA.cs" />
Expand Down
72 changes: 72 additions & 0 deletions KSPCommunityFixes/QoL/OptionalMakingHistoryDLCFeatures.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using Expansions;
using HarmonyLib;
using System.Collections;
using System.Collections.Generic;
using System.IO;

namespace KSPCommunityFixes.QoL
{
internal class OptionalMakingHistoryDLCFeatures : BasePatch
{
private const string MH_EXPANSION_FILE = "makinghistory.kspexpansion";
private const string SETTINGS_TOGGLE_VALUE_NAME = "OptionalMakingHistoryDLCFeaturesAlwaysDisable";
internal static string LOC_MHDLC = "Making History features";
internal static string LOC_SettingsTooltip = "Disable the Making History DLC mission editor and additional launch sites\nThe Making History parts will still be available\nWill reduce memory usage and increase loading speed\nChanges will take effect after restarting KSP";
internal static bool isMHEnabled = true;
internal static bool isMHDisabledFromConfig = false;

protected override Version VersionMin => new Version(1, 12, 3);

protected override void ApplyPatches(List<PatchInfo> patches)
{
if (KSPCommunityFixes.SettingsNode.TryGetValue(SETTINGS_TOGGLE_VALUE_NAME, ref isMHDisabledFromConfig) && isMHDisabledFromConfig)
isMHEnabled = false;

patches.Add(new PatchInfo(
PatchMethodType.Prefix,
AccessTools.Method(typeof(ExpansionsLoader), nameof(ExpansionsLoader.InitializeExpansion)),
this));
}

protected override void OnLoadData(ConfigNode node)
{
if (!isMHDisabledFromConfig)
node.TryGetValue(nameof(isMHEnabled), ref isMHEnabled);
}

protected override bool CanApplyPatch(out string reason)
{
if (Directory.Exists(KSPExpansionsUtils.ExpansionsGameDataPath))
{
foreach (string fileName in Directory.GetFiles(KSPExpansionsUtils.ExpansionsGameDataPath, "*" + ExpansionsLoader.expansionsMasterExtension, SearchOption.AllDirectories))
{
if (fileName.EndsWith(MH_EXPANSION_FILE))
{
reason = null;
return true;
}
}
}

reason = "Making History DLC not installed";
return false;
}

static bool ExpansionsLoader_InitializeExpansion_Prefix(string expansionFile, ref IEnumerator __result)
{
if (!isMHEnabled && expansionFile.EndsWith(MH_EXPANSION_FILE))
{
__result = EmptyEnumerator();
return false;
}

return true;
}

static IEnumerator EmptyEnumerator()
{
yield break;
}
}
}
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ User options are available from the "ESC" in-game settings menu :<br/><img src="
- [**ToolbarShowHide**](https://github.com/KSPModdingLibs/KSPCommunityFixes/pull/53) [KSP 1.8.0 - 1.12.5]<br/>Add a button for hiding/showing the stock toolbar. Also allow accessing the toolbar while in the space center facilities windows (mission control, admin building, R&D...).
- **ResourceLockActions** [KSP 1.8.0 - 1.12.5]<br/>Add part actions for locking/unlocking resources flow state.
- [**BetterEditorUndoRedo**](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/172) [KSP 1.12.3 - 1.12.5]<br/>Invert the editor undo state capturing logic so part tweaks aren't lost when undoing. NOTE: this patch is disabled when TweakScale/L is installed.
- [**OptionalMakingHistoryDLCFeatures**](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/218) [KSP 1.12.3 - 1.12.5]<br/>Allow to disable the Making History DLC mission editor and additional launch sites features to decrease memory usage and increase loading speed. The Making History parts will still be available. Can be toggled from the KSPCF in-game settings (requires a restart), or from a MM patch (see `Settings.cfg`).

#### Performance tweaks

Expand Down Expand Up @@ -189,7 +190,8 @@ If doing so in the `Debug` configuration and if your KSP install is modified to
### Changelog

##### 1.35.0
- New KSP performance patch : [**OptimizedModuleRaycasts**](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/216) : Improve engine exhaust damage and solar panel line of sight raycasts performance by avoiding extra physics state synchronization and caching solar panels scaled space raycasts results.
- New KSP performance patch : [**OptimizedModuleRaycasts**](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/216) [KSP 1.12.3 - 1.12.5] : Improve engine exhaust damage and solar panel line of sight raycasts performance by avoiding extra physics state synchronization and caching solar panels scaled space raycasts results.
- New KSP QoL/performance patch : [**OptionalMakingHistoryDLCFeatures**](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/218) [KSP 1.12.3 - 1.12.5] : Allow to disable the Making History DLC mission editor and additional launch sites features to decrease memory usage and increase loading speed. The Making History parts will still be available. Can be toggled from the KSPCF in-game settings (requires a restart), or from a MM patch (see `Settings.cfg`)
- **FastLoader** : Improved DDS loading performance by avoiding an extra copy of the DDS data

##### 1.34.1
Expand Down
Loading