-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge 1.34 from dev to master (#188)
* New KSP QoL/performance patch : [**LowerMinPhysicsDTPerFrame**](#175) : Allow a min value of 0.02 instead of 0.03 for the "Max Physics Delta-Time Per Frame" main menu setting. This was already possible by manually editing the `settings.cfg` file, but changes would revert when going into the settings screen. * Add tooltip describing the "Max Physics Delta-Time Per Frame" main menu setting * merging master to dev (#181) * zh-cn localization for ManufacturerFixes.cfg (#178) * Remove ENABLE_PROFILER define that got added recently --------- Co-authored-by: zhangyuesai <[email protected]> * Fix #182: ModulePartInventory now accounts for changes to a part's mass or volume -for example, changing a part's variant (rcs thruster blocks, structural tube) or its resource level could change its mass, but when you store it in inventory the mass would always use the value from the prefab * oops, revert a couple changes to the csproj that made it into the last commit by accident * Fix #185: calculate the correct mass for parts when picking them up off the ground in EVA construction * Fix #104 : set dead kerbals to missing when loading a game and respawning is enabled * Standardize spaces for indent in .editorconfig and add it to the SLN (note personally I'd prefer tabs for indents, but all the existing code in here that didn't come from me uses spaces and consistency is more important) * Change tabs -> spaces in the few files that used it Whitespace-only change. (note most of these were originally authored by me, but the project as a whole uses spaces pretty consistently) * Fix #180: add ZeroCostTechNode patch * Better editor undo redo (#176) * BetterEditorUndoRedo : Exploratory fix for undo/redo state, doesn't work because of VesselCrewManifest side effects See #172 * BetterEditorUndoRedo : functional, obvious issues fixed, still likely to cause side effects. * disable BetterEditorUndoRedo by default --------- Co-authored-by: JonnyOThan <[email protected]> * PAWGroupMemory is no longer per-window, but rather per-group (#186) * Fix #50: PAWGroupMemory is no longer per-PAW, but stores the expansion state for all windows and is not cleared on scene changes -possible future work: persist the collapse state to disk * collapse or expand PAW groups when the PAW is shown * Fix #179: ModulePartVariants now applies node position changes in all scenes * enable BetterEditorUndoRedo by default * Merge master -> dev (#187) * zh-cn localization for ManufacturerFixes.cfg (#178) * Remove ENABLE_PROFILER define that got added recently --------- Co-authored-by: zhangyuesai <[email protected]> * update readme with the new fixes --------- Co-authored-by: gotmachine <[email protected]> Co-authored-by: zhangyuesai <[email protected]>
- Loading branch information
1 parent
a01a702
commit baf96a7
Showing
21 changed files
with
1,150 additions
and
121 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
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
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
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
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
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,55 @@ | ||
using HarmonyLib; | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection.Emit; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace KSPCommunityFixes.BugFixes | ||
{ | ||
// https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/185 | ||
|
||
class EVAConstructionMass : BasePatch | ||
{ | ||
protected override Version VersionMin => new Version(1, 12, 3); | ||
|
||
protected override void ApplyPatches(List<PatchInfo> patches) | ||
{ | ||
patches.Add(new PatchInfo( | ||
PatchMethodType.Transpiler, | ||
AccessTools.Method(typeof(EVAConstructionModeEditor), nameof(EVAConstructionModeEditor.PickupPart)), | ||
this)); | ||
} | ||
|
||
// the stock code sets selectedpart.mass to the prefab mass, which breaks terribly in cases where there are mass modifiers involved | ||
// I suspect this code exists at all because ModuleCargoPart.MakePartSettle alters the part's prefabMass to make it harder to move the part around when it's been dropped on the ground | ||
// To fix this, we restore the *prefabMass* field from the prefab, and then call UpdateMass so that IPartMassModifiers can do their thing. | ||
static IEnumerable<CodeInstruction> EVAConstructionModeEditor_PickupPart_Transpiler(IEnumerable<CodeInstruction> instructions) | ||
{ | ||
FieldInfo partMassField = AccessTools.Field(typeof(Part), nameof(Part.mass)); | ||
FieldInfo partPrefabMassField = AccessTools.Field(typeof(Part), nameof(Part.prefabMass)); | ||
FieldInfo EditorLogicBase_selectedPart = AccessTools.Field(typeof(EditorLogicBase), nameof(EditorLogicBase.selectedPart)); | ||
MethodInfo Part_UpdateMass = AccessTools.Method(typeof(Part), nameof(Part.UpdateMass)); | ||
foreach (var instruction in instructions) | ||
{ | ||
if (instruction.StoresField(partMassField)) | ||
{ | ||
instruction.operand = partPrefabMassField; | ||
yield return instruction; | ||
|
||
// call Part.UpdateMass | ||
yield return new CodeInstruction(OpCodes.Ldarg_0); | ||
yield return new CodeInstruction(OpCodes.Ldfld, EditorLogicBase_selectedPart); | ||
yield return new CodeInstruction(OpCodes.Call, Part_UpdateMass); | ||
} | ||
else | ||
{ | ||
yield return instruction; | ||
} | ||
} | ||
} | ||
} | ||
} |
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,167 @@ | ||
using HarmonyLib; | ||
using KSP.Localization; | ||
using KSP.UI.Screens; | ||
using KSP.UI.Screens.Editor; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace KSPCommunityFixes.BugFixes | ||
{ | ||
// https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/182 | ||
|
||
class InventoryPartMass : BasePatch | ||
{ | ||
protected override Version VersionMin => new Version(1, 12, 0); | ||
|
||
protected override void ApplyPatches(List<PatchInfo> patches) | ||
{ | ||
patches.Add(new PatchInfo( | ||
PatchMethodType.Prefix, | ||
AccessTools.Method(typeof(ModuleInventoryPart), nameof(ModuleInventoryPart.UpdateCapacityValues)), | ||
this)); | ||
|
||
var EditorPartIcon_Create_ArgTypes = new Type[] | ||
{ | ||
typeof(EditorPartList), | ||
typeof(AvailablePart), | ||
typeof(StoredPart), | ||
typeof(float), | ||
typeof(float), | ||
typeof(float), | ||
typeof(Callback<EditorPartIcon>), | ||
typeof(bool), | ||
typeof(bool), | ||
typeof(PartVariant), | ||
typeof(bool), | ||
typeof(bool) | ||
}; | ||
|
||
patches.Add(new PatchInfo( | ||
PatchMethodType.Postfix, | ||
AccessTools.Method(typeof(KSP.UI.Screens.EditorPartIcon), nameof(KSP.UI.Screens.EditorPartIcon.Create), EditorPartIcon_Create_ArgTypes), | ||
this)); | ||
|
||
patches.Add(new PatchInfo( | ||
PatchMethodType.Postfix, | ||
AccessTools.Method(typeof(InventoryPartListTooltip), nameof(InventoryPartListTooltip.CreateInfoWidgets)), | ||
this)); | ||
|
||
// Making packedVolume persistent helps track what cargo modules *should* be if they were changed from the prefab before being added to the inventory | ||
StaticHelpers.EditPartModuleKSPFieldAttributes(typeof(ModuleCargoPart), nameof(ModuleCargoPart.packedVolume), field => field.isPersistant = true); | ||
} | ||
|
||
// the stock version of this function uses values from the prefab only, which is incorrect when mass modifiers are used (e.g. ModulePartVariants) or the packed volume is changed (e.g. TweakScale) or the resource levels are changed | ||
static bool ModuleInventoryPart_UpdateCapacityValues_Prefix(ModuleInventoryPart __instance) | ||
{ | ||
__instance.volumeOccupied = 0.0f; | ||
__instance.massOccupied = 0.0f; | ||
foreach (StoredPart storedPart in __instance.storedParts.ValuesList) | ||
{ | ||
if (storedPart != null && storedPart.snapshot != null) | ||
{ | ||
__instance.massOccupied += GetPartSnapshotMass(storedPart.snapshot) * storedPart.quantity; // This won't be correct if different parts in the stack have different mass modifiers, but really they shouldn't have been stacked in the first place | ||
__instance.volumeOccupied += GetPartSnapshotVolume(storedPart.snapshot) * storedPart.quantity; // see above. | ||
} | ||
} | ||
__instance.UpdateMassVolumeDisplay(true, false); | ||
return false; | ||
} | ||
|
||
static float GetPartSnapshotMass(ProtoPartSnapshot partSnapshot) | ||
{ | ||
double mass = partSnapshot.mass; | ||
|
||
foreach (var resource in partSnapshot.resources) | ||
{ | ||
mass += resource.amount * resource.definition.density; | ||
} | ||
|
||
return (float)mass; | ||
} | ||
|
||
static float GetPartSnapshotVolume(ProtoPartSnapshot partSnapshot) | ||
{ | ||
// fetch the volume from the cargo module snapshot | ||
foreach (var moduleSnapshot in partSnapshot.modules) | ||
{ | ||
if (moduleSnapshot.moduleName != nameof(ModuleCargoPart)) continue; | ||
|
||
float packedVolume = 0; | ||
if (moduleSnapshot.moduleValues.TryGetValue(nameof(ModuleCargoPart.packedVolume), ref packedVolume)) | ||
{ | ||
return packedVolume; | ||
} | ||
} | ||
|
||
// otherwise we have to fall back to the prefab volume (this is stock behavior) | ||
ModuleCargoPart moduleCargoPart = partSnapshot.partPrefab.FindModuleImplementing<ModuleCargoPart>(); | ||
if (moduleCargoPart != null) | ||
{ | ||
return moduleCargoPart.packedVolume; | ||
} | ||
return 0f; | ||
} | ||
|
||
// the game doesn't handle swapping variants very well for parts in inventories - mass and cost modifiers are not applied, etc. | ||
// It would be possible but messy and bug-prone to go modify the partsnapshot in the inventory when you swap variants | ||
// To sidestep the whole thing, just disallow changing variants for parts that have cost or mass modifiers while they're in inventory. | ||
static void EditorPartIcon_Create_Postfix(EditorPartIcon __instance, AvailablePart part, bool inInventory) | ||
{ | ||
if (!inInventory || part.Variants == null || __instance.btnSwapTexture == null) return; | ||
|
||
foreach (var variant in part.Variants) | ||
{ | ||
if (variant.cost != 0 || variant.mass != 0) | ||
{ | ||
__instance.btnSwapTexture.gameObject.SetActive(false); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
// The stock method gets the ModuleInfo strings from the prefab. ModuleCargoPart reports the dry mass and packed volume of the part, and | ||
// swapping variants in the editor parts list will change this so that it doesn't reflect the state of the part that's actually in inventory. | ||
// We don't have a good way to get an updated moduleinfo from the part in inventory (it requires a live part, and it's not stored in the part snapshot) | ||
static void InventoryPartListTooltip_CreateInfoWidgets_Postfix(InventoryPartListTooltip __instance) | ||
{ | ||
string moduleTitle = KSPUtil.PrintModuleName(nameof(ModuleCargoPart)); | ||
|
||
// find the widget corresponding to ModuleCargoPart | ||
foreach (var moduleInfo in __instance.partInfo.moduleInfos) | ||
{ | ||
if (moduleInfo.moduleName == moduleTitle) | ||
{ | ||
foreach (var widget in __instance.extInfoModules) | ||
{ | ||
if (widget.gameObject.activeSelf && widget.textName.text == moduleInfo.moduleDisplayName) | ||
{ | ||
widget.textInfo.text = GetModuleCargoPartInfo(__instance.inventoryStoredPart); | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
// this is effectively ModuleCargoPart.GetInfo but can operate on a storedPart instead | ||
static string GetModuleCargoPartInfo(StoredPart storedPart) | ||
{ | ||
float packedVolume = GetPartSnapshotVolume(storedPart.snapshot); | ||
int stackableQuantity = storedPart.snapshot.moduleCargoStackableQuantity; | ||
|
||
string text = ""; | ||
text = ((!(packedVolume < 0f)) ? Localizer.Format("#autoLOC_8002220") : Localizer.Format("#autoLOC_6002641")); | ||
text += "\n\n"; | ||
text = text + Localizer.Format("#autoLOC_8002186") + " " + storedPart.snapshot.mass.ToString("F3") + " t\\n"; | ||
if (packedVolume > 0f) | ||
{ | ||
text = text + Localizer.Format("#autoLOC_8004190", Localizer.Format("#autoLOC_8003414"), Localizer.Format("<<1>><<2>>", packedVolume.ToString("0.0"), "L")) + "\n"; | ||
} | ||
if (stackableQuantity > 1) | ||
{ | ||
text = text + Localizer.Format("#autoLOC_8004190", Localizer.Format("#autoLOC_8003418"), stackableQuantity.ToString("0")) + "\n"; | ||
} | ||
return text; | ||
} | ||
} | ||
} |
Oops, something went wrong.