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

Fix not applying DepartmentConfig.HeadImage #47

Merged
merged 2 commits into from
Jun 25, 2022
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
3 changes: 3 additions & 0 deletions GameData/KSPCommunityFixes/Settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ KSP_COMMUNITY_FIXES
// science data they carry not being recovered, depending on the EVA kerbal variant/suit.
EVAKerbalRecovery = true

// Fix Admin Building not using HeadImage if that is defined for a Department but a kerbal prefab is not
DepartmentHeadImage = true

// ##########################
// Obsolete bugfixes
// ##########################
Expand Down
41 changes: 41 additions & 0 deletions KSPCommunityFixes/BugFixes/DepartmentHeadImage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
The core of the issue is the asteroid/comet spawner passing a random int for the "id" argument of the ProtoVessel.CreatePartNode() method.
This id is affected to the part.flightId field, which must be unique game-wide and should have been generated by calling
ShipConstruction.GetUniqueFlightID(). Failing to produce an unique flightId result in various issues, especially with mods as they often
rely on that id.

Note that by fixing this, we replace how the asteroid/comet "seed" is generated, which technically affect further calls to UnityEngine.Random(),
but this shouldn't have any effect on the actual randomness/distribution of the generated stuff.
*/

using System;
using System.Collections.Generic;
using HarmonyLib;
using KSP.UI.Screens;

namespace KSPCommunityFixes.BugFixes
{
class DepartmentHeadImage : BasePatch
{
protected override Version VersionMin => new Version(1, 8, 0);

protected override void ApplyPatches(List<PatchInfo> patches)
{
patches.Add(new PatchInfo(
PatchMethodType.Postfix,
AccessTools.Method(typeof(Administration), "AddKerbalListItem"),
this));
}

static void Administration_AddKerbalListItem_Postfix(Administration __instance, ref Strategies.DepartmentConfig dep)
{
if (dep.AvatarPrefab != null || dep.HeadImage == null)
return;

KSP.UI.UIListItem item = __instance.scrollListKerbals.GetUilistItemAt(__instance.scrollListKerbals.Count - 1);
KerbalListItem kerbal = item.GetComponent<KerbalListItem>();
kerbal.kerbalImage.texture = dep.HeadImage;
kerbal.kerbalImage.material = kerbal.kerbalImage.defaultMaterial;
}
}
}
1 change: 1 addition & 0 deletions KSPCommunityFixes/KSPCommunityFixes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="BasePatch.cs" />
<Compile Include="BugFixes\DepartmentHeadImage.cs" />
<Compile Include="BugFixes\StickySplashedFixer.cs" />
<Compile Include="BugFixes\AsteroidSpawnerUniqueFlightId.cs" />
<Compile Include="BugFixes\AutoStrutDrift.cs" />
Expand Down