Skip to content

Commit

Permalink
Update Turn Back the Clock for U53-642443.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterhaneve committed Nov 25, 2024
1 parent f72d49d commit 1eeaab7
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 31 deletions.
36 changes: 19 additions & 17 deletions FastTrack/GamePatches/FastAttributePatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ public static class ManualGenerator_OnWorkTick_Patch {
/// Applied before OnWorkTick runs.
/// </summary>
[HarmonyPriority(Priority.Low)]
internal static bool Prefix(ref bool __result, Generator ___generator, Worker worker,
float dt) {
internal static bool Prefix(ref bool __result, Generator ___generator,
KMonoBehaviour worker, float dt) {
var circuitManager = Game.Instance.circuitManager;
bool charged = false;
if (circuitManager != null) {
Expand Down Expand Up @@ -288,7 +288,8 @@ public static class Workable_GetEfficiencyMultiplier_Patch {
/// Applied before GetEfficiencyMultiplier runs.
/// </summary>
[HarmonyPriority(Priority.Low)]
internal static bool Prefix(Worker worker, ref float __result, Workable __instance) {
internal static bool Prefix(KMonoBehaviour worker, ref float __result,
Workable __instance) {
float mult = 1f;
int cell;
var ac = __instance.attributeConverter;
Expand All @@ -307,7 +308,7 @@ internal static bool Prefix(Worker worker, ref float __result, Workable __instan
bool lit;
if (Grid.LightIntensity[cell] > 0) {
lit = true;
mult += TUNING.DUPLICANTSTATS.LIGHT.LIGHT_WORK_EFFICIENCY_BONUS;
mult += TUNING.DUPLICANTSTATS.STANDARD.Light.LIGHT_WORK_EFFICIENCY_BONUS;
if (hv == Guid.Empty && worker.TryGetComponent(out KSelectable ks))
handle = ks.AddStatusItem(Db.Get().DuplicantStatusItems.
LightWorkEfficiencyBonus, __instance);
Expand All @@ -329,7 +330,7 @@ internal static bool Prefix(Worker worker, ref float __result, Workable __instan
/// <summary>
/// Applied to Worker to work more efficiently using faster attribute leveling!
/// </summary>
[HarmonyPatch(typeof(Worker), nameof(Worker.Work), typeof(float))]
[HarmonyPatch(typeof(StandardWorker), nameof(StandardWorker.Work), typeof(float))]
public static class Worker_Work_Patch {
internal static bool Prepare() => FastTrackOptions.Instance.FastAttributesMode;

Expand All @@ -339,10 +340,10 @@ public static class Worker_Work_Patch {
/// <param name="workAttribute">The attribute being trained.</param>
/// <param name="worker">The worker doing the job.</param>
/// <param name="dt">The time since the last update.</param>
/// <param name="resume">The worker's total experience resume.</param>
private static Workable UpdateExperience(Attribute workAttribute, Worker worker,
float dt, MinionResume resume) {
var workable = worker.workable;
/// <param name="recipient">The location where the experience gained will be stored.</param>
private static Workable UpdateExperience(Attribute workAttribute, WorkerBase worker,
float dt, IExperienceRecipient recipient) {
var workable = worker.GetWorkable();
if (worker.TryGetComponent(out AttributeLevels levels) &&
workAttribute != null && workAttribute.IsTrainable) {
var lookup = LookupAttributeLevel.GetAttributeLookup(levels);
Expand All @@ -354,8 +355,8 @@ private static Workable UpdateExperience(Attribute workAttribute, Worker worker,
levels.AddExperience(workAttribute.Id, dt, exp);
}
string experienceGroup = workable.GetSkillExperienceSkillGroup();
if (resume != null && experienceGroup != null)
resume.AddExperienceWithAptitude(experienceGroup, dt, workable.
if (recipient != null && experienceGroup != null)
recipient.AddExperienceWithAptitude(experienceGroup, dt, workable.
GetSkillExperienceMultiplier());
return workable;
}
Expand All @@ -367,21 +368,22 @@ private static Workable UpdateExperience(Attribute workAttribute, Worker worker,
internal static TranspiledMethod Transpiler(TranspiledMethod instructions) {
var getAttribute = typeof(Workable).GetMethodSafe(nameof(Workable.
GetWorkAttribute), false);
var getResume = typeof(Worker).GetFieldSafe(nameof(Worker.resume), false);
var getTarget = typeof(StandardWorker).GetFieldSafe(nameof(StandardWorker.
experienceRecipient), false);
var updateExp = typeof(Worker_Work_Patch).GetMethodSafe(nameof(UpdateExperience),
true, typeof(Attribute), typeof(Worker), typeof(float), typeof(MinionResume));
true, typeof(Attribute), typeof(StandardWorker), typeof(float), typeof(MinionResume));
var getEfficiency = typeof(Workable).GetMethodSafe(nameof(Workable.
GetEfficiencyMultiplier), false, typeof(Worker));
GetEfficiencyMultiplier), false, typeof(WorkerBase));
int state = 0;
if (getAttribute != null && getEfficiency != null && getResume != null &&
if (getAttribute != null && getEfficiency != null && getTarget != null &&
updateExp != null)
foreach (var instr in instructions) {
if (state == 1 && instr.Is(OpCodes.Callvirt, getEfficiency)) {
state = 2;
// Load this
yield return new CodeInstruction(OpCodes.Ldarg_0);
#if DEBUG
PUtil.LogDebug("Patched Worker.Work");
PUtil.LogDebug("Patched StandardWorker.Work");
#endif
}
if (state != 1)
Expand All @@ -394,7 +396,7 @@ internal static TranspiledMethod Transpiler(TranspiledMethod instructions) {
yield return new CodeInstruction(OpCodes.Ldarg_1);
// Load this.resume
yield return new CodeInstruction(OpCodes.Ldarg_0);
yield return new CodeInstruction(OpCodes.Ldfld, getResume);
yield return new CodeInstruction(OpCodes.Ldfld, getTarget);
// Call our method
yield return new CodeInstruction(OpCodes.Call, updateExp);
state = 1;
Expand Down
7 changes: 4 additions & 3 deletions FastTrack/SensorPatches/FastReachabilityMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,13 @@ internal static bool Prefix(int cell, ref bool __result) {
/// <summary>
/// Applied to MinionGroupProber to use our check for reachability instead of its own.
/// </summary>
[HarmonyPatch(typeof(MinionGroupProber), nameof(MinionGroupProber.IsReachable_AssumeLock))]
public static class MinionGroupProber_IsReachableAssumeLock_Patch {
[HarmonyPatch(typeof(MinionGroupProber), nameof(MinionGroupProber.IsReachable),
typeof(int))]
public static class MinionGroupProber_IsReachable_Patch {
internal static bool Prepare() => FastTrackOptions.Instance.FastReachability;

/// <summary>
/// Applied before IsReachable_AssumeLock runs.
/// Applied before IsReachable runs.
/// </summary>
[HarmonyPriority(Priority.Low)]
internal static bool Prefix(int cell, ref bool __result) {
Expand Down
12 changes: 6 additions & 6 deletions FastTrack/UIPatches/MeterScreenPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ internal static bool Prefix(KMonoBehaviour ___sparkLayer) {
}

/// <summary>
/// Applied to MeterScreen to reduce allocations and speed up getting the list of
/// Applied to MeterScreen_Stress to reduce allocations and speed up getting the list of
/// Duplicants by stress value.
/// </summary>
[HarmonyPatch(typeof(MeterScreen), nameof(MeterScreen.GetStressedMinions))]
public static class MeterScreen_GetStressedMinions_Patch {
[HarmonyPatch(typeof(MeterScreen_Stress), nameof(MeterScreen_Stress.GetStressedMinions))]
public static class MeterScreen_Stress_GetStressedMinions_Patch {
/// <summary>
/// Avoids allocating new lists every frame.
/// </summary>
Expand All @@ -112,13 +112,13 @@ public static class MeterScreen_GetStressedMinions_Patch {
/// Applied before GetStressedMinions runs.
/// </summary>
[HarmonyPriority(Priority.Low)]
internal static bool Prefix(MeterScreen __instance, ref IList<MinionIdentity> __result)
{
internal static bool Prefix(MeterScreen_Stress __instance,
ref IList<MinionIdentity> __result) {
var stressAmount = Db.Get().Amounts.Stress;
var duplicants = __instance.GetWorldMinionIdentities();
var result = CACHED_LIST;
int n = duplicants.Count;
var byStress = ListPool<StressEntry, MeterScreen>.Allocate();
var byStress = ListPool<StressEntry, MeterScreen_Stress>.Allocate();
result.Clear();
// The previous comparer looked up the stress on every comparison!
for (int i = 0; i < n; i++) {
Expand Down
2 changes: 1 addition & 1 deletion MoreAchievements/Criteria/CollectNArtifacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public sealed class CollectNArtifacts : ColonyAchievementRequirement, Achievemen
/// <summary>
/// The number of artifacts required.
/// </summary>
protected int required;
private int required;

public CollectNArtifacts(int required) {
this.required = Math.Max(1, required);
Expand Down
2 changes: 2 additions & 0 deletions SandboxTools/FilteredDestroyTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ internal FilteredDestroyTool() {
SandboxToolsStrings.DESTROY_SHIPPING)
};
pendingCells = new HashSet<int>();
#pragma warning disable CS0168
try {
// Take from stock tool if possible
color = RECENTLY_AFFECTED.Get(SandboxDestroyerTool.instance);
Expand All @@ -142,6 +143,7 @@ internal FilteredDestroyTool() {
// Use default
color = new Color(1f, 1f, 1f, 0.1f);
}
#pragma warning restore CS0168
// Read value at runtime if possible
numObjectLayers = (int)PGameUtils.GetObjectLayer(nameof(ObjectLayer.NumLayers),
ObjectLayer.NumLayers);
Expand Down
4 changes: 2 additions & 2 deletions TurnBackTheClock/MD509629.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ internal static bool Prepare() => TurnBackTheClockOptions.Instance.

internal static void Postfix(Diet.Info[] __result) {
var oldInfo = __result[0];
// BUG: Klei still has not set the disease per produced kg correctly
__result[0] = new Diet.Info(new HashSet<Tag> {
"ForestTree"
}, oldInfo.producedElement, oldInfo.caloriesPerKg, oldInfo.
producedConversionRate, null, oldInfo.diseasePerKgProduced, oldInfo.
produceSolidTile, oldInfo.eatsPlantsDirectly);
produceSolidTile, oldInfo.foodType, oldInfo.emmitDiseaseOnCell,
oldInfo.eatAnims);
}
}

Expand Down
4 changes: 2 additions & 2 deletions TurnBackTheClock/TurnBackTheClock.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyTitle>Turn Back The Clock</AssemblyTitle>
<FileVersion>1.4.0.0</FileVersion>
<FileVersion>1.5.0.0</FileVersion>
<RootNamespace>PeterHan.TurnBackTheClock</RootNamespace>
<Description>Changes the game to be more like previous versions.</Description>
<AssemblyVersion>1.2.0.0</AssemblyVersion>
<CopyPreview>true</CopyPreview>
<SupportedContent>VANILLA_ID</SupportedContent>
<LastWorkingBuild>535720</LastWorkingBuild>
<LastWorkingBuild>642443</LastWorkingBuild>
<Platforms>Vanilla;Mergedown</Platforms>
</PropertyGroup>
</Project>

0 comments on commit 1eeaab7

Please sign in to comment.