Skip to content

Commit

Permalink
Start revitalizing Turn Back the Clock to allow turning way back. Fix…
Browse files Browse the repository at this point in the history
… a potential compatibility crash in Fast Track.
  • Loading branch information
peterhaneve committed Dec 17, 2022
1 parent 563a363 commit 037dda5
Show file tree
Hide file tree
Showing 4 changed files with 470 additions and 22 deletions.
46 changes: 24 additions & 22 deletions FastTrack/UIPatches/FormatStringPatches.3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -503,29 +503,31 @@ private static void Init() {
var kb = GameInputMapping.KeyBindings;
var lookup = HOTKEY_LOOKUP;
var steamGamepad = KInputManager.steamInputInterpreter;
int n = kb.Length;
bool isGamepad = KInputManager.currentControllerIsGamepad;
// Precompute the modifier strings
var modText = MODIFERS;
modText[0] = GameUtil.GetKeycodeLocalized(KKeyCode.LeftAlt).ToUpper();
modText[1] = GameUtil.GetKeycodeLocalized(KKeyCode.LeftControl).ToUpper();
modText[2] = GameUtil.GetKeycodeLocalized(KKeyCode.LeftShift).ToUpper();
modText[3] = GameUtil.GetKeycodeLocalized(KKeyCode.CapsLock).ToUpper();
modText[4] = GameUtil.GetKeycodeLocalized(KKeyCode.BackQuote).ToUpper();
for (int i = 0; i < n; i++) {
ref var binding = ref kb[i];
var action = binding.mAction;
// Only perform on entries with a matching key binding
actionBuffer.Clear().Append("<b><color=#F44A4A>");
if (isGamepad)
actionBuffer.Append(steamGamepad.GetActionGlyph(action));
else {
actionBuffer.Append('[');
GetActionString(ref binding, actionBuffer);
actionBuffer.Append(']');
if (kb != null) {
int n = kb.Length;
bool isGamepad = KInputManager.currentControllerIsGamepad;
// Precompute the modifier strings
var modText = MODIFERS;
modText[0] = GameUtil.GetKeycodeLocalized(KKeyCode.LeftAlt).ToUpper();
modText[1] = GameUtil.GetKeycodeLocalized(KKeyCode.LeftControl).ToUpper();
modText[2] = GameUtil.GetKeycodeLocalized(KKeyCode.LeftShift).ToUpper();
modText[3] = GameUtil.GetKeycodeLocalized(KKeyCode.CapsLock).ToUpper();
modText[4] = GameUtil.GetKeycodeLocalized(KKeyCode.BackQuote).ToUpper();
for (int i = 0; i < n; i++) {
ref var binding = ref kb[i];
var action = binding.mAction;
// Only perform on entries with a matching key binding
actionBuffer.Clear().Append("<b><color=#F44A4A>");
if (isGamepad)
actionBuffer.Append(steamGamepad.GetActionGlyph(action));
else {
actionBuffer.Append('[');
GetActionString(ref binding, actionBuffer);
actionBuffer.Append(']');
}
lookup[action.ToString()] = actionBuffer.Append("</b></color>").
ToString();
}
lookup[action.ToString()] = actionBuffer.Append("</b></color>").
ToString();
}
}

Expand Down
178 changes: 178 additions & 0 deletions TurnBackTheClock/MD509629.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
/*
* Copyright 2022 Peter Han
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

using HarmonyLib;
using System;
using System.Collections.Generic;

namespace PeterHan.TurnBackTheClock {
/// <summary>
/// Patches for MD-509629: Fast Friends.
/// </summary>
internal static class MD509629 {
/// <summary>
/// Applied to BaseSquirrelConfig to make Pip unable to eat Thimble Reed.
/// </summary>
[HarmonyPatch(typeof(BaseSquirrelConfig), nameof(BaseSquirrelConfig.BasicDiet))]
public static class BaseSquirrelConfig_BasicDiet_Patch {
internal static bool Prepare() => TurnBackTheClockOptions.Instance.
MD509629_DisableCreatures;

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);
}
}

/// <summary>
/// Applied to ClothingAlterationStationConfig to disable it when MD-509629 buildings
/// are turned off.
/// </summary>
[HarmonyPatch(typeof(ClothingAlterationStationConfig), nameof(IBuildingConfig.
CreateBuildingDef))]
public static class ClothingAlterationStationConfig_CreateBuildingDef_Patch {
internal static bool Prepare() => TurnBackTheClockOptions.Instance.
MD509629_DisableBuildings;

internal static void Postfix(BuildingDef __result) {
__result.Deprecated = true;
}
}

/// <summary>
/// Applied to CrabConfig to make Pokeshell unable to morph (thus disabling the Oakshell
/// and Sanishell).
/// </summary>
[HarmonyPatch(typeof(CrabConfig), nameof(CrabConfig.CreatePrefab))]
public static class CrabConfig_CreatePrefab_Patch {
internal static bool Prepare() => TurnBackTheClockOptions.Instance.
MD509629_DisableCreatures;

internal static void Prefix() {
var chances = CrabTuning.EGG_CHANCES_BASE;
chances.Clear();
chances.Add(new FertilityMonitor.BreedingChance {
egg = CrabConfig.EGG_ID.ToTag(), weight = 1.00f
});
}
}

/// <summary>
/// Applied to GourmetCookingStationConfig to remove the Curried Beans recipe.
/// BUG: recipe overwrites the spicy tofu recipe
/// </summary>
[HarmonyPatch(typeof(GourmetCookingStationConfig), "ConfigureRecipes")]
public static class GourmetCookingStationConfig_CreatePrefab_Patch {
internal static bool Prepare() => TurnBackTheClockOptions.Instance.
MD509629_DisableFood;

internal static void Postfix() {
var recipes = ComplexRecipeManager.Get().recipes;
recipes.RemoveAll((recipe) => recipe.id.Contains(GourmetCookingStationConfig.ID) &&
recipe.id.EndsWith(CurryConfig.ID));
}
}

/// <summary>
/// Applied to ModifierSet to make Pokeshells, Shove Voles and Pips unable to morph
/// (thus disabling the Oakshell, Sanishell, Cuddle Pip, and Delecta Vole).
/// </summary>
[HarmonyPatch(typeof(ModifierSet), nameof(ModifierSet.CreateFertilityModifier))]
public static class ModifierSet_CreateFertilityModifier_Patch {
internal static bool Prepare() => TurnBackTheClockOptions.Instance.
MD509629_DisableCreatures;

internal static bool Prefix(Tag targetTag) {
string tagName = targetTag.Name;
return tagName != MoleConfig.EGG_ID && tagName != SquirrelConfig.EGG_ID &&
tagName != CrabConfig.EGG_ID;
}
}

/// <summary>
/// Applied to MoleConfig to make Shove Vole unable to morph (thus disabling the Delecta
/// Vole).
/// </summary>
[HarmonyPatch(typeof(MoleConfig), nameof(MoleConfig.CreatePrefab))]
public static class MoleConfig_CreatePrefab_Patch {
internal static bool Prepare() => TurnBackTheClockOptions.Instance.
MD509629_DisableCreatures;

internal static void Prefix() {
var chances = MoleTuning.EGG_CHANCES_BASE;
chances.Clear();
chances.Add(new FertilityMonitor.BreedingChance {
egg = MoleConfig.EGG_ID.ToTag(), weight = 1.00f
});
}
}

/// <summary>
/// Applied to RoomTypes to disable the Kitchen when MD-525812 buildings are
/// turned off.
/// </summary>
[HarmonyPatch(typeof(Database.Personalities), MethodType.Constructor, new Type[0])]
public static class Personalities_Constructor_Patch {
internal static bool Prepare() => TurnBackTheClockOptions.Instance.
MD509629_DisableDuplicants;

/// <summary>
/// Removes a Duplicant personality.
/// </summary>
/// <param name="instance">The personalities to alter.</param>
/// <param name="name">The name of the Duplicant to remove.</param>
private static void RemoveDuplicant(Database.Personalities instance,
string name) {
// The base game uses the incorrect uppercase version as well
var dupe = instance.TryGet(name.ToUpper());
if (dupe != null)
instance.Remove(dupe);
}

internal static void Postfix(Database.Personalities __instance) {
RemoveDuplicant(__instance, STRINGS.DUPLICANTS.PERSONALITIES.AMARI.NAME);
RemoveDuplicant(__instance, STRINGS.DUPLICANTS.PERSONALITIES.PEI.NAME);
RemoveDuplicant(__instance, STRINGS.DUPLICANTS.PERSONALITIES.QUINN.NAME);
RemoveDuplicant(__instance, STRINGS.DUPLICANTS.PERSONALITIES.STEVE.NAME);
}
}

/// <summary>
/// Applied to SquirrelConfig to make Pip unable to morph (thus disabling the Cuddle
/// Pip :cry: ).
/// </summary>
[HarmonyPatch(typeof(SquirrelConfig), nameof(SquirrelConfig.CreatePrefab))]
public static class SquirrelConfig_CreatePrefab_Patch {
internal static bool Prepare() => TurnBackTheClockOptions.Instance.
MD509629_DisableCreatures;

internal static void Prefix() {
var chances = SquirrelTuning.EGG_CHANCES_BASE;
chances.Clear();
chances.Add(new FertilityMonitor.BreedingChance {
egg = SquirrelConfig.EGG_ID.ToTag(), weight = 1.00f
});
}
}
}
}
Loading

0 comments on commit 037dda5

Please sign in to comment.