Skip to content

Commit

Permalink
fix: Analysis Tech check & Unlock All command (#450)
Browse files Browse the repository at this point in the history
* Remove unnecessary check when adding analysis tech

* Fixed a bug with locked at start tech types

Fixed a bug where locked at start tech types couldn't get unlocked via the `unlockall` command or in creative.

---------

Co-authored-by: Metious <[email protected]>
  • Loading branch information
LeeTwentyThree and Metious committed Aug 27, 2023
1 parent cc750e3 commit fe21c02
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
6 changes: 6 additions & 0 deletions Nautilus/Assets/Gadgets/ScanningGadget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,5 +328,11 @@ protected internal override void Build()

KnownTechPatcher.UnlockedAtStart.Remove(prefab.Info.TechType);
}

if (!KnownTechPatcher.UnlockedAtStart.Contains(prefab.Info.TechType) &&
(CompoundTechsForUnlock is null || CompoundTechsForUnlock.Count <= 0) && RequiredForUnlock == TechType.None && ScannerEntryData is null)
{
KnownTechPatcher.LockedWithNoUnlocks.Add(prefab.Info.TechType);
}
}
}
19 changes: 13 additions & 6 deletions Nautilus/Patchers/KnownTechPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ internal class KnownTechPatcher
{
private static readonly Func<TechType, string> AsStringFunction = (t) => t.AsString();

internal static List<TechType> UnlockedAtStart = new();
internal static HashSet<TechType> UnlockedAtStart = new();
internal static HashSet<TechType> LockedWithNoUnlocks = new();
internal static IDictionary<TechType, KnownTech.AnalysisTech> AnalysisTech = new SelfCheckingDictionary<TechType, KnownTech.AnalysisTech>("AnalysisTech", AsStringFunction);
internal static IDictionary<TechType, KnownTech.CompoundTech> CompoundTech = new SelfCheckingDictionary<TechType, KnownTech.CompoundTech>("CompoundTech", AsStringFunction);
internal static IDictionary<TechType, List<TechType>> RemoveFromSpecificTechs = new SelfCheckingDictionary<TechType, List<TechType>>("RemoveFromSpecificTechs", AsStringFunction);
Expand All @@ -21,7 +22,10 @@ internal class KnownTechPatcher
public static void Patch(Harmony harmony)
{
harmony.Patch(AccessTools.Method(typeof(KnownTech), nameof(KnownTech.Initialize)),
postfix: new HarmonyMethod(AccessTools.Method(typeof(KnownTechPatcher), nameof(KnownTechPatcher.InitializePostfix))));
postfix: new HarmonyMethod(AccessTools.Method(typeof(KnownTechPatcher), nameof(InitializePostfix))));

harmony.Patch(AccessTools.Method(typeof(KnownTech), nameof(KnownTech.GetAllUnlockables)),
postfix: new HarmonyMethod(AccessTools.Method(typeof(KnownTechPatcher), nameof(GetAllUnlockablesPostfix))));
}

internal static void InitializePostfix()
Expand Down Expand Up @@ -106,10 +110,7 @@ internal static void InitializePostfix()
tech.unlockSound = UnlockSound;
}

if (!KnownTech.Contains(tech.techType))
{
analysisTech.Add(tech);
}
analysisTech.Add(tech);
}

List <KnownTech.CompoundTech> validatedCompoundTeches = KnownTech.ValidateCompoundTech(new(CompoundTech.Values));
Expand All @@ -134,4 +135,10 @@ internal static void InitializePostfix()
}
}
}

private static void GetAllUnlockablesPostfix(HashSet<TechType> __result)
{
var filtered = CraftData.FilterAllowed(LockedWithNoUnlocks);
__result.AddRange(filtered);
}
}

0 comments on commit fe21c02

Please sign in to comment.