Skip to content

Commit

Permalink
Update Fast Track, Moo Reproduction and One Giant Leap for compatibil…
Browse files Browse the repository at this point in the history
…ity with U52-622509.
  • Loading branch information
peterhaneve committed Jul 20, 2024
1 parent 3af5aa8 commit abbb84d
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 88 deletions.
1 change: 0 additions & 1 deletion FastTrack/CritterPatches/ThreatAndCrowdPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/

using HarmonyLib;
using PeterHan.PLib.Core;
#if DEBUG
using PeterHan.PLib.Core;
#endif
Expand Down
6 changes: 3 additions & 3 deletions FastTrack/FastTrack.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyTitle>Fast Track</AssemblyTitle>
<FileVersion>0.13.6.0</FileVersion>
<FileVersion>0.14.0.0</FileVersion>
<RootNamespace>PeterHan.FastTrack</RootNamespace>
<Description>Optimizes Oxygen Not Included to improve performance.</Description>
<AssemblyVersion>0.14.0.0</AssemblyVersion>
<LastWorkingBuild>596100</LastWorkingBuild>
<AssemblyVersion>0.15.0.0</AssemblyVersion>
<LastWorkingBuild>616718</LastWorkingBuild>
<Platforms>Vanilla;Mergedown</Platforms>
<Optimize>true</Optimize>
<UsePublicized>true</UsePublicized>
Expand Down
16 changes: 6 additions & 10 deletions FastTrack/UIPatches/DetailsPanelWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,15 @@ private static string GetCodexLink(GameObject go, CellSelectionObject cso) {
codexText = FormatLinkID(building.Def.PrefabID);
else if (go.TryGetComponent(out KPrefabID id)) {
string prefabID = id.PrefabTag.ToString();
PlantBranch.Instance smi;
if (id.HasTag(GameTags.Creature))
codexText = FormatLinkID(prefabID, "BABY", "");
else if (id.HasTag(GameTags.Plant))
codexText = FormatLinkID(prefabID, "SEED", "");
else if (go.TryGetComponent(out BudUprootedMonitor monitor)) {
KPrefabID parent;
BuddingTrunk trunk;
if ((parent = monitor.parentObject.Get()) != null)
codexText = FormatLinkID(parent.PrefabTag.ToString());
else if (go.TryGetComponent(out TreeBud bud) && (trunk = bud.buddingTrunk.
Get()) != null)
// Special case for trees?
codexText = FormatLinkID(trunk.PrefabID().ToString());
else if ((smi = go.GetSMI<PlantBranch.Instance>()) != null) {
var parent = smi.trunk;
if (parent != null && (id = parent.GetComponent<KPrefabID>()) != null)
codexText = FormatLinkID(id.PrefabTag.ToString());
else
codexText = FormatLinkID(prefabID);
} else
Expand Down Expand Up @@ -361,7 +357,7 @@ internal static bool Prefix(DetailsScreen __instance, string newName) {
/// <summary>
/// Applied to DetailsScreen to make opening the codex entry much faster!
/// </summary>
[HarmonyPatch(typeof(DetailsScreen), nameof(DetailsScreen.OpenCodexEntry))]
[HarmonyPatch(typeof(DetailsScreen), nameof(DetailsScreen.CodexEntryButton_OnClick))]
internal static class OpenCodexEntry_Patch {
internal static bool Prepare() => FastTrackOptions.Instance.SideScreenOpts;

Expand Down
2 changes: 1 addition & 1 deletion MooReproduction/MooReproduction.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyTitle>Moo Reproduction</AssemblyTitle>
<FileVersion>2.8.0.0</FileVersion>
<FileVersion>2.9.0.0</FileVersion>
<RootNamespace>PeterHan.MooReproduction</RootNamespace>
<Description>Allows Gassy Moos to reproduce, giving live birth like mammals should.</Description>
<AssemblyVersion>2.2.0.0</AssemblyVersion>
Expand Down
35 changes: 20 additions & 15 deletions MoreAchievements/AchievementStateComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ public static void OnCritterKilled() {
/// <param name="cause">The cause of death.</param>
public static void OnDeath(Death cause) {
var asc = Instance;
var instance = GameClock.Instance;
var gc = GameClock.Instance;
if (cause != null) {
Trigger(DeathFromCause.PREFIX + cause.Id);
if (instance != null)
asc.LastDeath = instance.GetCycle();
if (gc != null)
asc.LastDeath = gc.GetCycle();
}
}

Expand All @@ -79,27 +79,30 @@ public static void OnGeneShuffleComplete() {
/// </summary>
/// <param name="rating">The rating of the overloaded wire.</param>
public static void OnOverload(Wire.WattageRating rating) {
Trigger(OverloadWire.PREFIX + rating.ToString());
Trigger(OverloadWire.PREFIX + rating);
}

/// <summary>
/// Triggered when a rocket visits, or returns from, a space destination.
/// </summary>
/// <param name="destination">The destination of the mission.</param>
public static void OnVisit(int destination) {
Instance?.PlanetsVisited?.Add(destination);
var asc = Instance;
if (asc != null)
asc.PlanetsVisited?.Add(destination);
}

/// <summary>
/// Triggers the colony achievement requirement with the specified ID.
/// </summary>
/// <param name="achievement">The requirement ID to trigger.</param>
public static void Trigger(string achievement) {
if (!string.IsNullOrEmpty(achievement)) {
var asc = Instance;
if (!string.IsNullOrEmpty(achievement) && asc != null) {
#if DEBUG
PUtil.LogDebug("Achievement requirement triggered: " + achievement);
#endif
var te = Instance?.TriggerEvents;
var te = asc.TriggerEvents;
if (te != null)
te[achievement] = true;
}
Expand Down Expand Up @@ -230,9 +233,9 @@ public AchievementStateComponent() {
private void InitGrimReaper() {
// Look for the last dip in Duplicant count
float lastValue = -1.0f;
RetiredColonyData.RetiredColonyStatistic[] stats;
try {
var data = RetireColonyUtility.GetCurrentColonyRetiredColonyData();
RetiredColonyData.RetiredColonyStatistic[] stats;
if ((stats = data?.Stats) != null && data.cycleCount > 0) {
var liveDupes = new SortedList<int, float>(stats.Length);
// Copy and sort the values
Expand All @@ -253,9 +256,11 @@ private void InitGrimReaper() {
liveDupes.Clear();
}
} catch (Exception e) {
var gc = GameClock.Instance;
PUtil.LogWarning("Unable to determine the last date of death:");
PUtil.LogExcWarn(e);
LastDeath = GameClock.Instance?.GetCycle() ?? 0;
if (gc != null)
LastDeath = gc.GetCycle();
}
}

Expand Down Expand Up @@ -302,7 +307,7 @@ protected override void OnSpawn() {
if (LastDeath <= 0)
InitGrimReaper();
var dbAttr = Db.Get().Attributes;
VarietyAttributes = new Klei.AI.Attribute[] { dbAttr.Art, dbAttr.Athletics,
VarietyAttributes = new[] { dbAttr.Art, dbAttr.Athletics,
dbAttr.Botanist, dbAttr.Caring, dbAttr.Construction, dbAttr.Cooking,
dbAttr.Digging, dbAttr.Learning, dbAttr.Machinery, dbAttr.Ranching,
dbAttr.Strength };
Expand All @@ -315,11 +320,11 @@ protected override void OnSpawn() {
PlanetsRequired = ClusterManager.Instance.worldCount;
else {
// VANILLA STARMAP
var dest = SpacecraftManager.instance?.destinations;
if (dest != null) {
var si = SpacecraftManager.instance;
if (si != null && si.destinations != null) {
int count = 0;
// Exclude unreachable destinations (earth) but include temporal tear
foreach (var destination in dest)
foreach (var destination in si.destinations)
if (destination.GetDestinationType()?.visitable == true)
count++;
if (count > 0)
Expand All @@ -336,8 +341,8 @@ public void Sim1000ms(float dt) {
int have = 0;
// Count artifacts discovered
foreach (var pair in ArtifactConfig.artifactItems)
foreach (string name in pair.Value)
if (DiscoveredResources.Instance.IsDiscovered(Assets.GetPrefab(name).
foreach (string artName in pair.Value)
if (DiscoveredResources.Instance.IsDiscovered(Assets.GetPrefab(artName).
PrefabID()))
have++;
ArtifactsObtained = have;
Expand Down
71 changes: 45 additions & 26 deletions MoreAchievements/MoreAchievementsAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,43 @@ public sealed class MoreAchievementsAPI : PForwardedComponent {
/// <summary>
/// The version of this component.
/// </summary>
internal static readonly Version VERSION = new Version(1, 0, 0, 0);
internal static readonly Version VERSION = new Version(1, 1, 0, 0);

private static void FilterAchievements_Postfix(
Dictionary<string, GameObject> ___achievementEntries) {
var inst = Instance;
if (inst != null)
foreach (var pair in ___achievementEntries) {
var obj = pair.Value;
string id = pair.Key;
var info = inst.GetAchievement(id);
if (obj != null && obj.TryGetComponent(out MultiToggle toggle) &&
info != null && info.Hidden)
// Hide achievements that have never been achieved
obj.SetActive(toggle.CurrentState != 2);
}
}

private static void UpdateAchievementData_Postfix(string[] newlyAchieved,
Dictionary<string, GameObject> ___achievementEntries) {
var newly = HashSetPool<string, AchievementStateComponent>.Allocate();
// Achievements just obtained should always be shown
if (newlyAchieved != null)
foreach (string achieved in newlyAchieved)
newly.Add(achieved);
foreach (var pair in ___achievementEntries) {
var obj = pair.Value;
string id = pair.Key;
var info = Instance?.GetAchievement(id);
if (obj != null && obj.TryGetComponent(out MultiToggle toggle) &&
info != null && info.Hidden)
// Hide achievements that have never been achieved
obj.SetActive(toggle.CurrentState != 2 || newly.Contains(id));
var inst = Instance;
if (inst != null) {
var newly = HashSetPool<string, AchievementStateComponent>.Allocate();
// Achievements just obtained should always be shown
if (newlyAchieved != null)
foreach (string achieved in newlyAchieved)
newly.Add(achieved);
foreach (var pair in ___achievementEntries) {
var obj = pair.Value;
string id = pair.Key;
var info = inst.GetAchievement(id);
if (obj != null && obj.TryGetComponent(out MultiToggle toggle) &&
info != null && info.Hidden)
// Hide achievements that have never been achieved
obj.SetActive(toggle.CurrentState != 2 || newly.Contains(id));
}
newly.Recycle();
}
newly.Recycle();
}

public override Version Version => VERSION;
Expand Down Expand Up @@ -105,27 +123,28 @@ public void AddAchievementInformation(string id, string category,
/// <param name="id">The achievement ID to look up.</param>
/// <returns>The extra information about that achievement.</returns>
internal AchievementInfo GetAchievement(string id) {
if (!allAchievements.TryGetValue(id, out AchievementInfo info))
if (!allAchievements.TryGetValue(id, out var info))
info = null;
return info;
}

public override void Initialize(Harmony plibInstance) {
Instance = this;
foreach (var achievementProvider in PRegistry.Instance.GetAllComponents(ID))
if (achievementProvider != null) {
var toAdd = achievementProvider.GetInstanceDataSerialized<ICollection<
AchievementInfo>>();
if (toAdd != null)
foreach (var achievement in toAdd) {
allAchievements[achievement.ID] = achievement;
foreach (var achievementProvider in PRegistry.Instance.GetAllComponents(ID)) {
var toAdd = achievementProvider?.GetInstanceDataSerialized<ICollection<
AchievementInfo>>();
if (toAdd != null)
foreach (var achievement in toAdd) {
allAchievements[achievement.ID] = achievement;
#if DEBUG
PUtil.LogDebug("Added data for achievement " + achievement.ID);
PUtil.LogDebug("Added data for achievement " + achievement.ID);
#endif
}
}
}
}
plibInstance.Patch(typeof(RetiredColonyInfoScreen), "UpdateAchievementData",
postfix: PatchMethod(nameof(UpdateAchievementData_Postfix)));
plibInstance.Patch(typeof(RetiredColonyInfoScreen), "FilterAchievements",
postfix: PatchMethod(nameof(FilterAchievements_Postfix)));
}

/// <summary>
Expand Down
54 changes: 27 additions & 27 deletions MoreAchievements/MoreAchievementsPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,32 @@ public override void OnLoad(Harmony harmony) {
true);
}

/// <summary>
/// Applied to BuildingHP to check for damage from overloading wires.
/// </summary>
[HarmonyPatch(typeof(BuildingHP), "OnDoBuildingDamage")]
public static class BuildingHP_OnDoBuildingDamage_Patch {
/// <summary>
/// Applied after DoDamage runs.
/// </summary>
internal static void Postfix(BuildingHP __instance, object data) {
if (__instance != null && data is BuildingHP.DamageSourceInfo source &&
(source.source == STRINGS.BUILDINGS.DAMAGESOURCES.CIRCUIT_OVERLOADED ||
source.takeDamageEffect == SpawnFXHashes.BuildingSpark)) {
var obj = __instance.gameObject;
#if DEBUG
PUtil.LogDebug("Wire overloaded: " + obj.name);
#endif
if (obj.TryGetComponent(out Wire wire))
// Wire is overloading
AchievementStateComponent.OnOverload(wire.GetMaxWattageRating());
else if (obj.TryGetComponent(out WireUtilityNetworkLink bridge))
// Wire bridge is overloading
AchievementStateComponent.OnOverload(bridge.GetMaxWattageRating());
}
}
}

/// <summary>
/// Applied to BuildingComplete to update the maximum building temperature seen.
/// </summary>
Expand Down Expand Up @@ -163,32 +189,6 @@ internal static void Postfix(PrimaryElement ___primaryElement) {
}
}

/// <summary>
/// Applied to BuildingHP to check for damage from overloading wires.
/// </summary>
[HarmonyPatch(typeof(BuildingHP), "OnDoBuildingDamage")]
public static class BuildingHP_DoDamage_Patch {
/// <summary>
/// Applied after DoDamage runs.
/// </summary>
internal static void Postfix(BuildingHP __instance, object data) {
if (__instance != null && data is BuildingHP.DamageSourceInfo source &&
(source.source == STRINGS.BUILDINGS.DAMAGESOURCES.CIRCUIT_OVERLOADED ||
source.takeDamageEffect == SpawnFXHashes.BuildingSpark)) {
var obj = __instance.gameObject;
#if DEBUG
PUtil.LogDebug("Wire overloaded: " + obj.name);
#endif
if (obj.TryGetComponent(out Wire wire))
// Wire is overloading
AchievementStateComponent.OnOverload(wire.GetMaxWattageRating());
else if (obj.TryGetComponent(out WireUtilityNetworkLink bridge))
// Wire bridge is overloading
AchievementStateComponent.OnOverload(bridge.GetMaxWattageRating());
}
}
}

/// <summary>
/// Applied to Butcherable to count dying critters if they die at a young age.
/// </summary>
Expand Down Expand Up @@ -275,7 +275,7 @@ internal static void Postfix(bool ___isDigComplete, Diggable __instance) {
/// Applied to DiscoveredResources to grant an achievement upon discovering items.
/// </summary>
[HarmonyPatch(typeof(DiscoveredResources), nameof(DiscoveredResources.Discover),
typeof(Tag))]
typeof(Tag), typeof(Tag))]
public static class DiscoveredResources_Discover_Patch {
/// <summary>
/// Applied after Discover runs.
Expand Down
2 changes: 1 addition & 1 deletion PLib/PLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<Description>PLib - Peter Han's library used for creating mods for Oxygen Not Included, a simulation game by Klei Entertainment.

Contains methods aimed at improving cross-mod compatibility, in-game user interfaces, and game-wide functions such as Actions and Lighting. An easy-to-use Mod Options menu is also included.</Description>
<PackageReleaseNotes>Add compatibility methods to ease porting to U51-595713.</PackageReleaseNotes>
<PackageReleaseNotes>Add compatibility methods to ease porting to U52-622509.</PackageReleaseNotes>
<RootNamespace>PeterHan.PLib</RootNamespace>
<AssemblyVersion>$(PLibVersion)</AssemblyVersion>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
Expand Down
9 changes: 6 additions & 3 deletions PLibCore/PTranspilerTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,13 @@ private static bool GenerateBasicLoad(ILGenerator generator, Type type, object v
else if (type == typeof(double))
// double
generator.Emit(OpCodes.Ldc_R8, (value is double dVal) ? dVal : 0.0);
else if (type == typeof(string))
else if (type == typeof(string)) {
// string
generator.Emit(OpCodes.Ldstr, (value is string sVal) ? sVal : "");
else if (type.IsPointer)
if (value == null)
generator.Emit(OpCodes.Ldnull);
else
generator.Emit(OpCodes.Ldstr, (value is string sVal) ? sVal : "");
} else if (type.IsPointer)
// All pointers
generator.Emit(OpCodes.Ldc_I4_0);
else if (!type.IsValueType)
Expand Down
2 changes: 1 addition & 1 deletion PLibDatabase/PColonyAchievement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public PColonyAchievement(string id) {
/// </summary>
public void AddAchievement() {
if (Requirements == null)
throw new ArgumentNullException("No colony achievement requirements specified");
throw new ArgumentNullException(nameof(Requirements));
var achieve = NEW_COLONY_ACHIEVEMENT.Invoke(ID, "", Name, Description, IsVictory,
Requirements, VictoryTitle, VictoryMessage, VictoryVideoData, VictoryVideoLoop,
OnVictory);
Expand Down

0 comments on commit abbb84d

Please sign in to comment.