mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 12:33:06 +00:00
5af96eab95
Closes #4227 SlotWrite no longer revises the data incorrectly if ot&gender mismatch, clear memories and set new values can retain wrong values by having ot&gender shared between games
48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
using System;
|
|
using static PKHeX.Core.CheckIdentifier;
|
|
|
|
namespace PKHeX.Core.Bulk;
|
|
|
|
public sealed class HandlerChecker : IBulkAnalyzer
|
|
{
|
|
public void Analyze(BulkAnalysis input)
|
|
{
|
|
if (input.Trainer.Generation < 6 || !input.Settings.CheckActiveHandler)
|
|
return; // no HT yet
|
|
CheckHandlerFlag(input);
|
|
}
|
|
|
|
private static void CheckHandlerFlag(BulkAnalysis input)
|
|
{
|
|
for (var i = 0; i < input.AllData.Count; i++)
|
|
{
|
|
if (!input.AllAnalysis[i].Valid)
|
|
continue;
|
|
var cs = input.AllData[i];
|
|
Verify(input, cs);
|
|
}
|
|
}
|
|
|
|
private static void Verify(BulkAnalysis input, SlotCache cs)
|
|
{
|
|
var pk = cs.Entity;
|
|
var tr = cs.SAV;
|
|
var withOT = tr.IsFromTrainer(pk);
|
|
var flag = pk.CurrentHandler;
|
|
var expect = withOT ? 0 : 1;
|
|
if (flag != expect)
|
|
input.AddLine(cs, LegalityCheckStrings.LTransferCurrentHandlerInvalid, Trainer);
|
|
|
|
if (flag != 1)
|
|
return;
|
|
|
|
Span<char> ht = stackalloc char[pk.TrashCharCountTrainer];
|
|
var len = pk.LoadString(pk.HandlingTrainerTrash, ht);
|
|
ht = ht[..len];
|
|
|
|
if (!ht.SequenceEqual(tr.OT))
|
|
input.AddLine(cs, LegalityCheckStrings.LTransferHTMismatchName, Trainer);
|
|
if (pk is IHandlerLanguage h && h.HandlingTrainerLanguage != tr.Language)
|
|
input.AddLine(cs, LegalityCheckStrings.LTransferHTMismatchLanguage, Trainer);
|
|
}
|
|
}
|