Skip to content

Commit

Permalink
Merge pull request #41 from KSP2Community/dev
Browse files Browse the repository at this point in the history
Version 0.10.0
  • Loading branch information
jan-bures authored Dec 27, 2023
2 parents 7beb952 + d738e2b commit 8e34d82
Show file tree
Hide file tree
Showing 13 changed files with 215 additions and 37 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build

on:
push:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build the solution
run: dotnet build "CommunityFixes.sln" -c Release

- name: Find zip
id: find-zip
run: |
echo "zip=$(ls -1 dist/CommunityFixes-*.zip | head -n 1)" >> $GITHUB_ENV
echo "artifact_name=CommunityFixesRelease" >> $GITHUB_ENV
- name: Upload zip artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.artifact_name }}
path: ${{ env.zip }}
28 changes: 28 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Upload release

on:
release:
types: [ "published" ]

jobs:
publish:
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build the solution
run: |
dotnet build "CommunityFixes.sln" -c Release
echo "zip=$(ls -1 dist/CommunityFixes-*.zip | head -n 1)" >> $GITHUB_ENV
- name: Upload zip to release
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.upload_url }}
asset_path: ${{ env.zip }}
asset_name: ${{ env.artifact_name }}
asset_content_type: application/zip
18 changes: 0 additions & 18 deletions .github/workflows/spacewarp.yml

This file was deleted.

16 changes: 16 additions & 0 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Verify swinfo.json

on:
push:
branches: [ "main" ]

jobs:
verify:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Verify KSP2 Mod
uses: Rexicon226/[email protected]
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This project aims to bring together community bug fixes for Kerbal Space Program
## Compatibility
- Tested with Kerbal Space Program 2 v0.2.0.0.30291
- Requires **[SpaceWarp 1.6.0+](https://github.com/SpaceWarpDev/SpaceWarp/releases/)**
- Requires **[Patch Manager 0.6+](https://github.com/KSP2Community/PatchManager/releases/)**

## Implemented fixes
- **KSP 2 Save Fix** by [jayouimet](https://github.com/jayouimet) - Replaces the Control Owner Part to the first available Command module or to the Root part if not found when it is set to null.
Expand All @@ -12,6 +13,8 @@ This project aims to bring together community bug fixes for Kerbal Space Program
- **Suppress Transmissions Falsely Urgent Fix** by [schlosrat](https://github.com/schlosrat) - Suppresses unhelpful map view log messages.
- **VAB Redo Tooltip Fix** by [coldrifting](https://github.com/coldrifting) - Fixes the VAB Redo button tooltip not being at the same height as the button.
- **Revert After Recovery Fix** by [munix](https://github.com/jan-bures) - Fixes the Revert buttons being enabled after recovering a vessel.
- **Experiment Biome Pause Fix** by [dmarcuse](https://github.com/dmarcuse) - Fixes experiments that don't care about biome pausing when the biome changes.
- **Stock Mission Fix** by [Cheese](https://github.com/cheese3660) - Fixes the incorrect completion conditions of the mission _Second Dibs: Gold Edition_.

## Planned fixes
To see what fixes are planned to be implemented, you can visit the [Issues page](https://github.com/Bit-Studios/CommunityFixes/issues) on the project's GitHub.
Expand All @@ -22,12 +25,13 @@ To see what fixes are planned to be implemented, you can visit the [Issues page]
1. Use [CKAN](https://github.com/KSP-CKAN/CKAN/releases/latest) to download and install Community Fixes.

### Manual
1. Download and extract [UITK for KSP 2](https://github.com/UitkForKsp2/UitkForKsp2/releases) into your game folder.
1. Download and extract [UITK for KSP 2](https://github.com/UitkForKsp2/UitkForKsp2/releases) into your game folder (this is a dependency of SpaceWarp).
2. Download and extract [SpaceWarp](https://github.com/SpaceWarpDev/SpaceWarp/releases) into your game folder.
3. Download and extract this mod into the game folder. If done correctly, you should have the following folder structure: `<KSP Folder>/BepInEx/plugins/CommunityFixes`.
3. Download and extract [Patch Manager](https://github.com/SpaceWarpDev/SpaceWarp/releases) into your game folder.
4. Download and extract this mod into the game folder. If done correctly, you should have the following folder structure: `<KSP Folder>/BepInEx/plugins/CommunityFixes`.

## Configuration
If you want to toggle any of the included fixes off, you can do so in game: `Main menu` -> `Settings` -> `Mods` -> `Community Fixes`. The changes will apply after restarting the game.

## Development wiki
## Contributing
If you'd like to contribute to this project, please take a look at [our wiki](https://github.com/Bit-Studios/CommunityFixes/wiki/Adding-your-fix).
5 changes: 5 additions & 0 deletions plugin_template/patches/pol_flag.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:missions #KSP2Mission_Secondary_Pol_Flag > missionStages > _0 > ConditionSet > PropertyCondition {
isInput: false;
Inputstring: "";
TestWatchedstring: "Pol";
}
11 changes: 9 additions & 2 deletions plugin_template/swinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Community Fixes",
"description": "Community project that aims to bring together bug fixes for KSP 2.",
"source": "https://github.com/KSP2Community/CommunityFixes",
"version": "0.9.0",
"version": "0.10.0",
"version_check": "https://raw.githubusercontent.com/KSP2Community/CommunityFixes/main/plugin_template/swinfo.json",
"ksp2_version": {
"min": "0.2.0",
Expand All @@ -18,6 +18,13 @@
"min": "1.6.0",
"max": "*"
}
},
{
"id": "PatchManager",
"version": {
"min": "0.6.0",
"max": "*"
}
}
]
}
}
6 changes: 3 additions & 3 deletions src/CommunityFixes/CommunityFixes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<PackageReference Include="BepInEx.Analyzers" Version="1.*" PrivateAssets="all"/>
<PackageReference Include="BepInEx.AssemblyPublicizer.MSBuild" Version="0.4.1" PrivateAssets="all"/>
<PackageReference Include="BepInEx.Core" Version="5.*"/>
<PackageReference Include="BepInEx.PluginInfoProps" Version="2.*"/>
<PackageReference Include="HarmonyX" Version="2.10.1"/>
<PackageReference Include="KerbalSpaceProgram2.GameLibs" Version="0.1.5" PrivateAssets="all"/>
<PackageReference Include="SpaceWarp" Version="1.5.2"/>
<PackageReference Include="KerbalSpaceProgram2.GameLibs" Version="0.2.0" PrivateAssets="all" Publicize="true"/>
<PackageReference Include="SpaceWarp" Version="1.6.0"/>
<PackageReference Include="SpaceWarp.PluginInfoProps" Version="1.*"/>
<PackageReference Include="UnityEngine.Modules" Version="2022.3.5"/>
</ItemGroup>
</Project>
8 changes: 6 additions & 2 deletions src/CommunityFixes/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<PowerShellExecutable Condition="'$(OS)' == 'Windows_NT'">powershell</PowerShellExecutable>
<PowerShellExecutable Condition="'$(OS)' != 'Windows_NT'">pwsh</PowerShellExecutable>
</PropertyGroup>
<Target Label="Post build events" Name="PostBuild" AfterTargets="PostBuildEvent">
<Message Text="Cleaning up previous build directory"/>
<RemoveDir Directories="$(SolutionDir)/dist/$(ConfigurationName)"/>
Expand Down Expand Up @@ -33,8 +37,8 @@
<Message Text="Compressing built plugin folder" Condition="$(ConfigurationName) == Release"/>
<Delete Condition="$(ConfigurationName) == Release"
Files="$(SolutionDir)/dist/$(SolutionName)-$(Version).zip"/>
<Exec Condition="$(ConfigurationName) == Release"
Command="powershell Compress-Archive -Path '$(SolutionDir)/dist/$(ConfigurationName)/BepInEx' -DestinationPath '$(SolutionDir)/dist/$(SolutionName)-$(Version).zip'"/>
<Exec Condition="$(ConfigurationName) == 'Release'"
Command="$(PowerShellExecutable) -Command &quot;&amp; {Push-Location '$(SolutionDir)/dist/$(ConfigurationName)'; Compress-Archive -Path './*' -DestinationPath '$(SolutionDir)/dist/$(SolutionName)-$(Version).zip'; Pop-Location}&quot;"/>

<Message Text="Clean up the game's plugin folder" Condition="$(ConfigurationName) == Deploy Or $(ConfigurationName) == DeployAndRun"/>
<RemoveDir Condition="$(ConfigurationName) == Deploy Or $(ConfigurationName) == DeployAndRun"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using HarmonyLib;
using KSP.Game.Science;
using KSP.Sim.impl;
using KSP.Modules;
using System.Reflection;

namespace CommunityFixes.Fix.ExperimentBiomePauseFix;

[Fix("Fix experiments pausing when switching biome for scenarios where biome is irrelevant")]
public class ExperimentBiomePauseFix : BaseFix
{
private static ExperimentBiomePauseFix _instance;

// This fix makes assumptions about the game's code and reads/writes private state, which can end up in save files.
// In order to avoid accidentally breaking anything, we only apply the patch to known-broken versions of the game.
private static readonly HashSet<string> KnownBrokenVersions = new() { "0.2.0.0.30291" };

private static readonly string GameVersion = typeof(VersionID)
.GetField("VERSION_TEXT", BindingFlags.Static | BindingFlags.Public)
?.GetValue(null) as string;

public override void OnInitialized()
{
_instance = this;
if (KnownBrokenVersions.Contains(GameVersion))
{
HarmonyInstance.PatchAll(typeof(ExperimentBiomePauseFix));
}
else
{
Logger.LogError($"Not enabling experiment biome pause fix - game version {GameVersion} may not be broken");
}
}

// RefreshLocationsValidity has a bug where it unconditionally pauses experiments when switching biome, even if the
// experiment is still valid and doesn't care about the biome. To fix this, we prevent the function from being
// called if the part has running experiments, the experiments don't care about the biome, and the other parameters
// of the experiment are unchanged.
// To avoid breaking things when we skip RefreshLocationsValidity, we also update some private state that the method
// is responsible for when skipping it.
[HarmonyPatch(
typeof(PartComponentModule_ScienceExperiment),
nameof(PartComponentModule_ScienceExperiment.RefreshLocationsValidity)
)]
[HarmonyPrefix]
public static bool RefreshLocationsValidityPrefix(
// ReSharper disable once InconsistentNaming
ref VesselComponent ____vesselComponent,
// ReSharper disable once InconsistentNaming
ref ResearchLocation ____currentLocation,
// ReSharper disable once InconsistentNaming
ref Data_ScienceExperiment ___dataScienceExperiment
)
{
if (____vesselComponent?.mainBody == null ||
____vesselComponent?.VesselScienceRegionSituation.ResearchLocation == null)
{
return true;
}

var newLocation = new ResearchLocation(
requiresRegion: true, // Placeholder, assigned per-experiment below
bodyName: ____vesselComponent.mainBody.bodyName,
scienceSituation: ____vesselComponent.VesselScienceRegionSituation.ResearchLocation.ScienceSituation,
scienceRegion: ____vesselComponent.VesselScienceRegionSituation.ResearchLocation.ScienceRegion
);

bool safeToSkip = true;
var newRegions = new List<string>();
foreach (var standing in ___dataScienceExperiment.ExperimentStandings)
{
if (standing.CurrentExperimentState == ExperimentState.RUNNING &&
!standing.RegionRequired &&
standing.ExperimentLocation.BodyName == newLocation.BodyName &&
standing.ExperimentLocation.ScienceSituation == newLocation.ScienceSituation)
{
newLocation.RequiresRegion = standing.RegionRequired;
newRegions.Add(newLocation.ScienceRegion);
continue;
}

safeToSkip = false;
}

if (safeToSkip)
{
_instance.Logger.LogInfo(
"Skipping PartComponentModule_ScienceExperiment.RefreshLocationsValidity - experiment is still valid."
);

____currentLocation = newLocation;
for (int i = 0; i < newRegions.Count; i++)
{
___dataScienceExperiment.ExperimentStandings[i].ExperimentLocation.SetScienceRegion(newRegions[i]);
}
}

return !safeToSkip;
}
}
5 changes: 3 additions & 2 deletions src/CommunityFixes/Fix/KSP2SaveFix/KSP2SaveFix.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
namespace CommunityFixes.Fix.KSP2SaveFix;

[Fix("KSP 2 Save Fix")]
public class KSP2SaveFix: BaseFix
public class KSP2SaveFix : BaseFix
{
public static KSP2SaveFix Instance;

public KSP2SaveFix()
{
Instance = this;
}

public override void OnInitialized()
{
HarmonyInstance.PatchAll(typeof(KSP2SaveFix_GetState));
}
}
}
7 changes: 5 additions & 2 deletions src/CommunityFixes/Fix/STFUFix/STFUPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using KSP.Sim.impl;

namespace CommunityFixes.Fix.STFUFix;

internal class STFUPatches
{
[HarmonyPatch(typeof(Map3DTrajectoryEvents), nameof(Map3DTrajectoryEvents.UpdateViewForOrbiter))]
Expand All @@ -18,7 +19,8 @@ public static bool BetterUpdateViewForOrbiter(Map3DTrajectoryEvents __instance,
var activeVessel = GameManager.Instance?.Game?.ViewController?.GetActiveVehicle(true)?.GetSimVessel(true);
var currentTarget = activeVessel?.TargetObject;
if (!currentTarget.IsCelestialBody)
GlobalLog.Warn("GenerateEventsForVessel() called with vessel.Orbiter.patchedConicSolver == null. Events will not be updated");
GlobalLog.Warn(
"GenerateEventsForVessel() called with vessel.Orbiter.patchedConicSolver == null. Events will not be updated");
}
else if (__instance._mapCamera?.UnityCamera == null)
{
Expand All @@ -31,6 +33,7 @@ public static bool BetterUpdateViewForOrbiter(Map3DTrajectoryEvents __instance,
__instance.UpdateViewForManeuverTrajectory(orbiter, globalId);
__instance.UpdateViewForTargeter(orbiter.OrbitTargeter, orbiter, globalId);
}

return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
namespace CommunityFixes.Fix.VelocityDisplayPrecisionFix;

[Fix("Velocity Display Precision Fix")]
public class VelocityDisplayPrecisionFix: BaseFix
public class VelocityDisplayPrecisionFix : BaseFix
{
private bool _fixed = false;

public void Update()
{
var gameState = Game?.GlobalGameState?.GetGameState();
if (gameState == null || gameState.GameState is GameState.MainMenu or GameState.WarmUpLoading or GameState.Loading)
if (gameState == null ||
gameState.GameState is GameState.MainMenu or GameState.WarmUpLoading or GameState.Loading)
_fixed = false;

if (_fixed) return;

var velocityValue = GameObject.Find("GameManager/Default Game Instance(Clone)/UI Manager(Clone)/" +
"Scaled Main Canvas/FlightHudRoot(Clone)/group_navball(Clone)/Container/" +
"GRP-VEL/Container/DataContainer/Items/Value");
Expand Down

0 comments on commit 8e34d82

Please sign in to comment.