private void VerifyHTMemory(LegalityAnalysis data)
    {
        var pk   = data.Entity;
        var mem  = (ITrainerMemories)pk;
        var Info = data.Info;

        var memory = mem.HT_Memory;

        if (pk.IsUntraded)
        {
            if (memory == 4 && WasTradedSWSHEgg(pk))
            {
                // Untraded link trade eggs in Gen8 have HT link trade memory applied erroneously.
                // Verify the link trade memory later.
            }
            else
            {
                VerifyHTMemoryNone(data, mem);
                return;
            }
        }

        if (pk.Format == 7)
        {
            VerifyHTMemoryTransferTo7(data, pk, Info);
            return;
        }

        var memoryGen = pk.Format >= 8 ? 8 : 6;

        // Bounds checking
        var context = Memories.GetContext(memoryGen);

        if (!context.CanObtainMemoryHT((GameVersion)pk.Version, memory))
        {
            data.AddLine(GetInvalid(string.Format(LMemoryArgBadID, L_XHT)));
        }

        // Verify memory if specific to HT
        switch (memory)
        {
        // No Memory
        case 0:     // SWSH memory application has an off-by-one error: [0,99] + 1 <= chance --> don't apply
            data.AddLine(Get(LMemoryMissingHT, memoryGen == 8 ? ParseSettings.Gen8MemoryMissingHT : Severity.Invalid));
            VerifyHTMemoryNone(data, mem);
            return;

        // {0} met {1} at... {2}. {1} threw a Poké Ball at it, and they started to travel together. {4} that {3}.
        case 1:
            data.AddLine(GetInvalid(string.Format(LMemoryArgBadCatch, L_XHT)));
            return;

        // {0} hatched from an Egg and saw {1} for the first time at... {2}. {4} that {3}.
        case 2:
            data.AddLine(GetInvalid(string.Format(LMemoryArgBadHatch, L_XHT)));
            return;

        // {0} went to the Pokémon Center in {2} with {1} and had its tired body healed there. {4} that {3}.
        case 6 when !context.HasPokeCenter(GameVersion.Any, mem.HT_TextVar):
            data.AddLine(GetInvalid(string.Format(LMemoryArgBadLocation, L_XHT)));
            return;

        // {0} was with {1} when {1} caught {2}. {4} that {3}.
        case 14:
            var result = GetCanBeCaptured(mem.HT_TextVar, memoryGen, GameVersion.Any)     // Any Game in the Handling Trainer's generation
                    ? GetValid(string.Format(LMemoryArgSpecies, L_XHT))
                    : GetInvalid(string.Format(LMemoryArgBadSpecies, L_XHT));
            data.AddLine(result);
            return;
        }

        var commonResult = VerifyCommonMemory(pk, 1, memoryGen, Info, context);

        data.AddLine(commonResult);
    }
    private void VerifyOTMemory(LegalityAnalysis data)
    {
        var pk   = data.Entity;
        var mem  = (ITrainerMemories)pk;
        var Info = data.Info;

        // If the encounter has a memory from the OT that could never have it replaced, ensure it was not modified.
        switch (data.EncounterMatch)
        {
        case WC6 {
                IsEgg: false
        } g when g.OTGender != 3 :
            VerifyOTMemoryIs(data, g.OT_Memory, g.OT_Intensity, g.OT_TextVar, g.OT_Feeling);
            return;

        case WC7 {
                IsEgg: false
        } g when g.OTGender != 3 :
            VerifyOTMemoryIs(data, g.OT_Memory, g.OT_Intensity, g.OT_TextVar, g.OT_Feeling);
            return;

        case WC8 {
                IsEgg: false
        } g when g.OTGender != 3 :
            VerifyOTMemoryIs(data, g.OT_Memory, g.OT_Intensity, g.OT_TextVar, g.OT_Feeling);
            return;

        case IMemoryOT t and not MysteryGift:     // Ignore Mystery Gift cases (covered above)
            VerifyOTMemoryIs(data, t.OT_Memory, t.OT_Intensity, t.OT_TextVar, t.OT_Feeling);
            return;
        }

        int memoryGen = Info.Generation;
        var memory    = mem.OT_Memory;

        if (pk.IsEgg)
        {
            // Traded unhatched eggs in Gen8 have OT link trade memory applied erroneously.
            // They can also have the box-inspect memory!
            if (memoryGen != 8 || !((pk.Met_Location == Locations.LinkTrade6 && memory == 4) || memory == 85))
            {
                VerifyOTMemoryIs(data, 0, 0, 0, 0); // empty
                return;
            }
        }
        else if (!CanHaveMemoryForOT(pk, memoryGen, memory, Info.EvoChainsAllGens))
        {
            VerifyOTMemoryIs(data, 0, 0, 0, 0); // empty
            return;
        }

        // Bounds checking
        var context = Memories.GetContext(memoryGen);

        if (!context.CanObtainMemoryOT((GameVersion)pk.Version, memory))
        {
            data.AddLine(GetInvalid(string.Format(LMemoryArgBadID, L_XOT)));
        }

        // Verify memory if specific to OT
        switch (memory)
        {
        // No Memory
        case 0:     // SWSH trades don't set HT memories immediately, which is hilarious.
            data.AddLine(Get(LMemoryMissingOT, memoryGen == 8 ? Severity.Fishy : Severity.Invalid));
            VerifyOTMemoryIs(data, 0, 0, 0, 0);
            return;

        // {0} hatched from an Egg and saw {1} for the first time at... {2}. {4} that {3}.
        case 2 when !Info.EncounterMatch.EggEncounter:
            data.AddLine(GetInvalid(string.Format(LMemoryArgBadHatch, L_XOT)));
            break;

        // {0} became {1}’s friend when it arrived via Link Trade at... {2}. {4} that {3}.
        case 4 when Info.Generation == 6:     // gen8 applies this memory erroneously
            data.AddLine(GetInvalid(string.Format(LMemoryArgBadOTEgg, L_XOT)));
            return;

        // {0} went to the Pokémon Center in {2} with {1} and had its tired body healed there. {4} that {3}.
        case 6 when !context.HasPokeCenter((GameVersion)pk.Version, mem.OT_TextVar):
            data.AddLine(GetInvalid(string.Format(LMemoryArgBadLocation, L_XOT)));
            return;

        // {0} was with {1} when {1} caught {2}. {4} that {3}.
        case 14:
            var result = GetCanBeCaptured(mem.OT_TextVar, Info.Generation, (GameVersion)pk.Version)     // Any Game in the Handling Trainer's generation
                    ? GetValid(string.Format(LMemoryArgSpecies, L_XOT))
                    : GetInvalid(string.Format(LMemoryArgBadSpecies, L_XOT));
            data.AddLine(result);
            return;
        }

        data.AddLine(VerifyCommonMemory(pk, 0, Info.Generation, Info, context));
    }