Skip to content

Instantly share code, notes, and snippets.

@gotmachine
gotmachine / CustomPartActionControl.cs
Created November 18, 2021 23:59
Create a completely custom PAW control for KSP
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
namespace UINumericFloatEdit
{
[KSPAddon(KSPAddon.Startup.FlightAndEditor, false)]
public class CustomPartActionControlSpawner : MonoBehaviour
{
@gotmachine
gotmachine / KSPInventories.cs
Created June 30, 2021 19:43
KSP : messing around with inventories
[HarmonyPatch(typeof(UIPartActionInventorySlot))]
[HarmonyPatch("OnPointerClick")]
class UIPartActionInventorySlot_OnPointerClick
{
static bool Prefix(UIPartActionInventorySlot __instance, PointerEventData eventData, ModuleInventoryPart ___moduleInventoryPart, InventoryPartListTooltipController ___tooltipController)
{
if (!(___moduleInventoryPart is ModuleActiveInventoryPart activeInventory))
{
return true;
}
@gotmachine
gotmachine / KSPCollapsedPAWInventoriesHarmonyPatch.cs
Last active June 30, 2021 09:28
KSP Collapsed PAW Inventories HarmonyPatch
// Add a collapsed by default PAW group to all ModuleInventoryPart :
[HarmonyPatch(typeof(ModuleInventoryPart))]
[HarmonyPatch("OnStart")]
class ModuleInventoryPart_OnStart
{
static void Postfix(ModuleInventoryPart __instance)
{
__instance.Fields["InventorySlots"].group = new BasePAWGroup("Inventory", "Inventory", true);
}
@gotmachine
gotmachine / KSPRecoveryFix.cs
Created March 22, 2021 14:42
Fix for KSP 1.11+ not accounting for modules implementing IPartCostModifier when refunding parts on vessel recovery
using System;
using KSP.Localization;
using KSP.UI.Screens;
using KSP.UI.Screens.SpaceCenter.MissionSummaryDialog;
using KSP.UI.Util;
using UnityEngine;
namespace TestPlugin
{
[KSPAddon(KSPAddon.Startup.AllGameScenes, false)]
@gotmachine
gotmachine / ResourceBrokerPatch.cs
Created March 3, 2021 13:50
Kerbalism ResourceBroker patch
// Experimental patch that force all BaseConverter derivatives to use the Kerbalism resource simulation, intended for NFE/FFT/SystemHeat support
// This will get ride of the "incoherent producer" message on loaded vessels, but there are some limitations :
// - This bypass resource flow priorities and modes, excepted in the case of a NO_FLOW resource.
// Specifically, NFE reactors should act correctly as far as uranium is concerned.
// - This use the last sim step information to attempt to compensate the stock high timewarp speeds issues,
// but since this works outside of the main kerbalism recipes loop, this will likely still act in weird ways
// when a mix of stock and kerbalism producers/consumers are active for the same resource.
// - This require renaming Kerbalism's own ResourceBroker class to something like KsmResourceBroker so harmony doesn't get confused
using System;
@gotmachine
gotmachine / PhysicsHold.cs
Last active December 5, 2020 04:11
PhysicsHold : KSP proof of concept mod for making landed vessels physicsless.
using KSP.UI.Screens.Flight;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using UnityEngine;
using Debug = UnityEngine.Debug;
/*
@gotmachine
gotmachine / OpenFileDialog
Created October 28, 2020 07:20
P/Invoke OpenFileDialog (no dependency on System.Windows.Forms)
public class OpenFileDialog
{
[DllImport("comdlg32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern bool GetOpenFileName([In, Out] OpenFileName ofn);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
private class OpenFileName
{
public int structSize = 0;
public IntPtr dlgOwner = IntPtr.Zero;