Skip to content

Commit

Permalink
Merge branch 'dev' into PartBoundsIgnoreDisabledRenderers
Browse files Browse the repository at this point in the history
  • Loading branch information
gotmachine authored Apr 4, 2024
2 parents c45af8c + 19a1d6a commit a9fa149
Show file tree
Hide file tree
Showing 13 changed files with 765 additions and 47 deletions.
2 changes: 1 addition & 1 deletion GameData/KSPCommunityFixes/KSPCommunityFixes.version
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"NAME": "KSPCommunityFixes",
"URL": "https://raw.githubusercontent.com/KSPModdingLibs/KSPCommunityFixes/master/GameData/KSPCommunityFixes/KSPCommunityFixes.version",
"DOWNLOAD": "https://github.com/KSPModdingLibs/KSPCommunityFixes/releases",
"VERSION": {"MAJOR": 1, "MINOR": 34, "PATCH": 1, "BUILD": 0},
"VERSION": {"MAJOR": 1, "MINOR": 35, "PATCH": 0, "BUILD": 0},
"KSP_VERSION": {"MAJOR": 1, "MINOR": 12, "PATCH": 5},
"KSP_VERSION_MIN": {"MAJOR": 1, "MINOR": 8, "PATCH": 0},
"KSP_VERSION_MAX": {"MAJOR": 1, "MINOR": 12, "PATCH": 5}
Expand Down
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
12 changes: 12 additions & 0 deletions GameData/KSPCommunityFixes/Settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,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 Expand Up @@ -408,6 +416,10 @@ KSP_COMMUNITY_FIXES
// Allow a min value of 0.02 instead of 0.03 for the "Max Physics Delta-Time Per Frame" main menu setting.
LowerMinPhysicsDTPerFrame = true
// 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.
OptimizedModuleRaycasts = true
// ##########################
// Modding
// ##########################
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
2 changes: 2 additions & 0 deletions KSPCommunityFixes/KSPCommunityFixes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,13 @@
<Compile Include="Modding\ReflectionTypeLoadExceptionHandler.cs" />
<Compile Include="Performance\FewerSaves.cs" />
<Compile Include="Performance\ConfigNodePerf.cs" />
<Compile Include="Performance\OptimizedModuleRaycasts.cs" />
<Compile Include="Performance\PQSCoroutineLeak.cs" />
<Compile Include="Performance\PQSUpdateNoMemoryAlloc.cs" />
<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
5 changes: 5 additions & 0 deletions KSPCommunityFixes/Library/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,10 @@ public static string AssemblyQualifiedName(this object obj)
Type type = obj.GetType();
return $"{type.Assembly.GetName().Name}:{type.Name}";
}

public static bool IsPAWOpen(this Part part)
{
return part.PartActionWindow.IsNotNullOrDestroyed() && part.PartActionWindow.isActiveAndEnabled;
}
}
}
14 changes: 13 additions & 1 deletion KSPCommunityFixes/Performance/FastLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.InteropServices;
using System.Threading;
using TMPro;
using Unity.Collections;
Expand Down Expand Up @@ -1312,7 +1313,18 @@ private TextureInfo LoadDDS()
}
else
{
texture2D.LoadRawTextureData(binaryReader.ReadBytes((int)(binaryReader.BaseStream.Length - binaryReader.BaseStream.Position)));
int position = (int)binaryReader.BaseStream.Position;
GCHandle pinnedHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
try
{
IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, position);
texture2D.LoadRawTextureData(ptr, dataLength - position);
}
finally
{
pinnedHandle.Free();
}

texture2D.Apply(updateMipmaps: false, makeNoLongerReadable: true);
}
}
Expand Down
Loading

0 comments on commit a9fa149

Please sign in to comment.