Skip to content

Commit

Permalink
Start the update to U53-640445. Quite a bit was changed, this update …
Browse files Browse the repository at this point in the history
…excludes Fast Track, but the other mods seem to have mostly survived.
  • Loading branch information
peterhaneve committed Nov 23, 2024
1 parent a706f0b commit 21928d6
Show file tree
Hide file tree
Showing 48 changed files with 256 additions and 234 deletions.
4 changes: 2 additions & 2 deletions AIImprovements/AIImprovements.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyTitle>AI Improvements</AssemblyTitle>
<FileVersion>2.8.0.0</FileVersion>
<FileVersion>2.9.0.0</FileVersion>
<RootNamespace>PeterHan.AIImprovements</RootNamespace>
<Description>Makes Duplicants just a little smarter during common tasks to reduce cases of entrapment and entombment.</Description>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
<CopyPreview>true</CopyPreview>
<LastWorkingBuild>525812</LastWorkingBuild>
<LastWorkingBuild>600112</LastWorkingBuild>
<Platforms>Vanilla;Mergedown</Platforms>
</PropertyGroup>
</Project>
28 changes: 12 additions & 16 deletions AIImprovements/AIImprovementsPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ internal static bool IsValidNavCell(Navigator navigator, int cell) {
!Grid.Solid[above] && !Grid.DupeImpassable[above] && !Grid.HasDoor[cell];
}

/// <summary>
/// Applied to MinionConfig to add the navigator transition for keeping track of
/// their location history. Big Brother is watching...
/// </summary>
[PLibPatch(RunAt.AfterDbInit, nameof(MinionConfig.OnSpawn),
RequireType = nameof(MinionConfig), PatchType = HarmonyPatchType.Postfix)]
internal static void MinionSpawn_Postfix(GameObject go) {
if (go.TryGetComponent(out Navigator nav))
nav.transitionDriver.overrideLayers.Add(new LocationHistoryTransitionLayer(
nav));
}

[PLibMethod(RunAt.AfterDbInit)]
internal static void OnDbInit() {
var db = Db.Get();
Expand Down Expand Up @@ -261,21 +273,5 @@ internal static bool Prefix(FallMonitor.Instance __instance,
return !moved;
}
}

/// <summary>
/// Applied to MinionConfig to add the navigator transition for keeping track of
/// their location history. Big Brother is watching...
/// </summary>
[HarmonyPatch(typeof(MinionConfig), "OnSpawn")]
public static class MinionConfig_OnSpawn_Patch {
/// <summary>
/// Applied after OnSpawn runs.
/// </summary>
internal static void Postfix(GameObject go) {
if (go.TryGetComponent(out Navigator nav))
nav.transitionDriver.overrideLayers.Add(new LocationHistoryTransitionLayer(
nav));
}
}
}
}
4 changes: 2 additions & 2 deletions AirlockDoor/AirlockDoor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyTitle>Airlock Door</AssemblyTitle>
<FileVersion>3.11.0.0</FileVersion>
<FileVersion>3.12.0.0</FileVersion>
<RootNamespace>PeterHan.AirlockDoor</RootNamespace>
<Description>A powered airlock door that allows passage without ever exchanging liquid or gas.</Description>
<AssemblyVersion>3.1.0.0</AssemblyVersion>
<LastWorkingBuild>575720</LastWorkingBuild>
<LastWorkingBuild>600112</LastWorkingBuild>
<Platforms>Vanilla;Mergedown</Platforms>
</PropertyGroup>
</Project>
51 changes: 25 additions & 26 deletions AirlockDoor/AirlockDoorPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using PeterHan.PLib.Database;
using System.Collections.Generic;
using KMod;
using PeterHan.PLib.PatchManager;
using UnityEngine;

namespace PeterHan.AirlockDoor {
Expand All @@ -35,17 +36,14 @@ public sealed class AirlockDoorPatches : KMod.UserMod2 {
/// The layer to check for airlock doors.
/// </summary>
private static int BUILDING_LAYER;

/// <summary>
/// Checks to see if a grid cell is solid and not an Airlock Door.
/// Applied to ScoutRoverConfig and/or BaseRoverConfig to ensure they properly use
/// airlock doors.
/// </summary>
/// <param name="cell">The grid cell to check.</param>
/// <returns>true if the cell is solid and not inside an Airlock Door, or false
/// otherwise.</returns>
private static bool SolidAndNotAirlock(ref Grid.BuildFlagsSolidIndexer _, int cell) {
GameObject go;
return Grid.Solid[cell] && (!Grid.IsValidCell(cell) || (go = Grid.Objects[cell,
BUILDING_LAYER]) == null || !go.TryGetComponent(out AirlockDoor _));
private static void AddTransitionLayer(GameObject inst) {
if (inst.TryGetComponent(out Navigator nav))
nav.transitionDriver.overrideLayers.Add(new AirlockDoorTransitionLayer(nav));
}

public override void OnAllModsLoaded(Harmony harmony, IReadOnlyList<Mod> mods) {
Expand All @@ -61,19 +59,33 @@ public override void OnLoad(Harmony harmony) {
BUILDING_LAYER = (int)PGameUtils.GetObjectLayer(nameof(ObjectLayer.Building),
ObjectLayer.Building);
PUtil.InitLibrary();
new PPatchManager(harmony).RegisterPatchClass(typeof(AirlockDoorPatches));
new PBuildingManager().Register(AirlockDoorConfig.CreateBuilding());
new PLocalization().Register();
new PVersionCheck().Register(this, new SteamVersionChecker());
}

/// <summary>
/// Applied to ScoutRoverConfig and/or BaseRoverConfig to ensure they properly use
/// airlock doors.
/// Applied to MinionConfig to add the navigator transition for airlocks.
/// </summary>
private static void AddTransitionLayer(GameObject inst) {
if (inst.TryGetComponent(out Navigator nav))
[PLibPatch(RunAt.AfterDbInit, nameof(MinionConfig.OnSpawn),
RequireType = nameof(MinionConfig), PatchType = HarmonyPatchType.Postfix)]
internal static void MinionSpawn_Postfix(GameObject go) {
if (go.TryGetComponent(out Navigator nav))
nav.transitionDriver.overrideLayers.Add(new AirlockDoorTransitionLayer(nav));
}

/// <summary>
/// Checks to see if a grid cell is solid and not an Airlock Door.
/// </summary>
/// <param name="cell">The grid cell to check.</param>
/// <returns>true if the cell is solid and not inside an Airlock Door, or false
/// otherwise.</returns>
private static bool SolidAndNotAirlock(ref Grid.BuildFlagsSolidIndexer _, int cell) {
GameObject go;
return Grid.Solid[cell] && (!Grid.IsValidCell(cell) || (go = Grid.Objects[cell,
BUILDING_LAYER]) == null || !go.TryGetComponent(out AirlockDoor _));
}

/// <summary>
/// Applied to Constructable to ensure that Duplicants will wait to dig out airlock
Expand Down Expand Up @@ -133,18 +145,5 @@ internal static IEnumerable<CodeInstruction> Transpiler(
MakeByRefType(), typeof(int)));
}
}

/// <summary>
/// Applied to MinionConfig to add the navigator transition for airlocks.
/// </summary>
[HarmonyPatch(typeof(MinionConfig), nameof(MinionConfig.OnSpawn))]
public static class MinionConfig_OnSpawn_Patch {
/// <summary>
/// Applied after OnSpawn runs.
/// </summary>
internal static void Postfix(GameObject go) {
AddTransitionLayer(go);
}
}
}
}
4 changes: 2 additions & 2 deletions DebugNotIncluded/DebugNotIncluded.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyTitle>Debug Not Included</AssemblyTitle>
<FileVersion>2.10.0.0</FileVersion>
<FileVersion>2.11.0.0</FileVersion>
<RootNamespace>PeterHan.DebugNotIncluded</RootNamespace>
<Description>Aids with mod debugging and management. Not intended to be a production mod manager.</Description>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<LastWorkingBuild>616718</LastWorkingBuild>
<LastWorkingBuild>640445</LastWorkingBuild>
<Platforms>Vanilla;Mergedown</Platforms>
</PropertyGroup>
<ItemGroup>
Expand Down
26 changes: 13 additions & 13 deletions DebugNotIncluded/DebugNotIncludedPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ internal static void AfterDbInit(Harmony harmony) {
#endif
harmony.PatchTranspile(typeof(SaveLoader), "OnSpawn", new HarmonyMethod(
typeof(DebugNotIncludedPatches), nameof(TranspileSaveLoader)));
harmony.Patch(typeof(MinionConfig), nameof(MinionConfig.CreatePrefab),
postfix: new HarmonyMethod(typeof(DebugNotIncludedPatches), nameof(
OnMinionSpawn)));
}

/// <summary>
Expand Down Expand Up @@ -142,6 +145,16 @@ private static void LogAllFailedAsserts(Harmony harmony) {
DebugLogger.BaseLogException(e, null);
}
}

/// <summary>
/// Applied to MinionConfig to add buttons for triggering stress and joy reactions.
///
/// Since Bio-Bots and Scout Rovers would not have these reactions, do not patch
/// BaseMinion.
/// </summary>
private static void OnMinionSpawn(GameObject __result) {
__result.AddOrGet<InstantEmotable>();
}

/// <summary>
/// Handles a mod crash and bypasses disabling the mod if it is this mod.
Expand Down Expand Up @@ -470,19 +483,6 @@ internal static TranspiledMethod Transpiler(TranspiledMethod method) {
}
}

/// <summary>
/// Applied to MinionConfig to add buttons for triggering stress and joy reactions.
/// </summary>
[HarmonyPatch(typeof(MinionConfig), nameof(MinionConfig.CreatePrefab))]
public static class MinionConfig_CreatePrefab_Patch {
/// <summary>
/// Applied after CreatePrefab runs.
/// </summary>
internal static void Postfix(GameObject __result) {
__result.AddOrGet<InstantEmotable>();
}
}

/// <summary>
/// Applied to Mod to reduce logging when checking for archived versions.
/// </summary>
Expand Down
37 changes: 21 additions & 16 deletions DebugNotIncluded/HarmonyPatchInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,28 @@ internal static void CheckType(Type type) {
harmonyAnnotation = hp;
else if (annotation.GetType().Name.Contains("ExcludeInspection"))
return;
if (harmonyAnnotation != null) {
var info = harmonyAnnotation.info;
var target = AccessTools.Method(info.declaringType, info.methodName,
info.argumentTypes);
if (target != null)
// Check each patch for broken ___, __instance and __result parameters
try {
if (harmonyAnnotation != null) {
var info = harmonyAnnotation.info;
var target = AccessTools.Method(info.declaringType, info.methodName,
info.argumentTypes);
if (target != null)
// Check each patch for broken ___, __instance and __result parameters
foreach (var method in type.GetMethods(ALL))
if (IsHarmonyPatchMethod(method))
CheckPatchParameters(method, target);
} else
// Patchy method names?
foreach (var method in type.GetMethods(ALL))
if (IsHarmonyPatchMethod(method))
CheckPatchParameters(method, target);
} else
// Patchy method names?
foreach (var method in type.GetMethods(ALL))
if (HARMONY_NAMES.Contains(method.Name)) {
DebugLogger.LogWarning("Type " + type.FullName +
" looks like a Harmony patch but does not have the annotation!");
break;
}
if (HARMONY_NAMES.Contains(method.Name)) {
DebugLogger.LogWarning("Type " + type.FullName +
" looks like a Harmony patch but does not have the annotation!");
break;
}
} catch (TypeLoadException e) {
DebugLogger.LogWarning("Unable to check type " + type.FullName);
DebugLogger.LogException(e);
}
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@
<DistributeMod>true</DistributeMod>
<ArchivedVersionPath></ArchivedVersionPath>
<UsePublicized>false</UsePublicized>
<PLibVersion>4.16.0.0</PLibVersion>
<PLibVersion>4.17.0.0</PLibVersion>
</PropertyGroup>
</Project>
54 changes: 22 additions & 32 deletions FinishTasks/FinishChoreDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#if DEBUG
using PeterHan.PLib.Core;
#endif
using PeterHan.PLib.Detours;
using System;

using PriorityClass = PriorityScreen.PriorityClass;

Expand All @@ -29,22 +29,16 @@ namespace PeterHan.FinishTasks {
/// </summary>
public sealed class FinishChoreDetector : KMonoBehaviour {
/// <summary>
/// Retrieves the ID of the Duplicant's current schedule block.
/// Retrieves the ID of the current schedule block.
///
/// <param name="schedule">The active schedule.</param>
/// </summary>
public string CurrentScheduleBlock {
get {
string block = "";
Schedulable target;
if (consumer != null && (target = consumer.consumerState?.schedulable) !=
null) {
// ChoreConsumerState.scheduleBlock is only updated on check for new chore
int blockPosition = Schedule.GetBlockIdx();
var schedule = target.GetSchedule();
if (schedule != null)
block = schedule.GetBlock(blockPosition)?.GroupId ?? "";
}
return block;
}
public static string GetScheduleBlock(Schedule schedule) {
string block = "";
// ChoreConsumerState.scheduleBlock is only updated on check for new chore
if (schedule != null)
block = schedule.GetCurrentScheduleBlock()?.GroupId ?? "";
return block;
}

/// <summary>
Expand All @@ -64,12 +58,6 @@ public string CurrentScheduleBlock {
/// </summary>
private bool acquireChore;

/// <summary>
/// The current chore consumer. Cannot be populated with [MyCmpGet] because that force
/// spawns the component if it exists, which crashes on dead Dupes.
/// </summary>
private ChoreConsumer consumer;

/// <summary>
/// The current chore driver. Cannot be populated with [MyCmpGet] because that force
/// spawns the component if it exists, which crashes on dead Dupes.
Expand Down Expand Up @@ -107,23 +95,26 @@ private void CheckAcquireChore() {
}
}

protected override void OnCleanUp() {
public override void OnCleanUp() {
Unsubscribe((int)GameHashes.ScheduleChanged, OnScheduleChanged);
Unsubscribe((int)GameHashes.ScheduleBlocksChanged, OnScheduleChanged);
base.OnCleanUp();
}

/// <summary>
/// Fired when a schedule block boundary is reached.
/// Fired when a schedule block boundary is reached, or the overall schedule changes.
///
/// <param name="parameter">The new schedule.</param>
/// </summary>
private void OnScheduleChanged(object _) {
if (driver != null) {
string groupID = CurrentScheduleBlock, ft = FinishTasksPatches.FinishTask.Id;
private void OnScheduleChanged(object parameter) {
if (driver != null && parameter is Schedule schedule) {
string groupID = GetScheduleBlock(schedule), ft = FinishTasksPatches.
FinishTask.Id;
#if DEBUG
PUtil.LogDebug("{0}: Schedule change from {1} to {2}".F(gameObject.name,
lastGroupID, groupID));
#endif
if (groupID == ft && lastGroupID != ft) {
if (groupID == ft && lastGroupID != null && lastGroupID != ft) {
// Entered Finish Tasks from a non-finish tasks block
acquireChore = true;
CheckAcquireChore();
Expand All @@ -136,13 +127,12 @@ private void OnScheduleChanged(object _) {
}
}

protected override void OnSpawn() {
public override void OnSpawn() {
base.OnSpawn();
TryGetComponent(out consumer);
TryGetComponent(out driver);
Subscribe((int)GameHashes.ScheduleBlocksChanged, OnScheduleChanged);
Subscribe((int)GameHashes.ScheduleChanged, OnScheduleChanged);
lastGroupID = CurrentScheduleBlock;
lastGroupID = null;
acquireChore = lastGroupID == FinishTasksPatches.FinishTask.Id;
allowedChore = null;
}
Expand Down
Loading

0 comments on commit 21928d6

Please sign in to comment.