Added checks for null characters in Gen4 strings.

Attr: Mythra
This commit is contained in:
Megan Edwards 2024-11-05 21:51:43 -05:00
parent 46d9efb0da
commit 33f6d30e90
5 changed files with 29 additions and 3 deletions

View File

@ -365,6 +365,10 @@ namespace PkmnFoundations.Structures
if (move.MoveID > 467) return new ValidationSummary() { IsValid = false };
}
var thePokemon4 = (Pokemon4)thePokemon;
if (!thePokemon4.NicknameEncoded.IsValid) return new ValidationSummary() { IsValid = false };
if (!thePokemon4.TrainerNameEncoded.IsValid) return new ValidationSummary() { IsValid = false };
return new ValidationSummary() { IsValid = true };
}
}

View File

@ -64,8 +64,8 @@ namespace PkmnFoundations.Structures
BitConverter.ToUInt16(block, 16),
BitConverter.ToUInt16(block, 18));
Unknown7 = new byte[56];
Array.Copy(block, 20, Unknown7, 0, 56);
HeldItemTrash = new byte[56];
Array.Copy(block, 20, HeldItemTrash, 0, 56);
Seals = new byte[24];
Array.Copy(block, 76, Seals, 0, 24);
}
@ -79,7 +79,7 @@ namespace PkmnFoundations.Structures
public byte CapsuleIndex { get; set; }
public override ushort HP { get { return _HP; } } // remaining hp
public ushort _HP { get; set; }
public byte[] Unknown7 { get; set; } // 56 bytes
public byte[] HeldItemTrash { get; set; } // 56 bytes
public byte[] Seals { get; set; } // 24 bytes
// cached stats on the party structure. This gives rise to the

View File

@ -90,6 +90,20 @@ namespace PkmnFoundations.Support
return EncodeString_impl(str, size);
}
public override bool IsValid
{
get
{
for (int i = 0; i < RawData.Length; i += 2)
{
ushort gamecode = BitConverter.ToUInt16(RawData, i);
if (gamecode == 0xffff) break;
if (gamecode == 0x0000) return false;
}
return true;
}
}
public EncodedString4 Clone()
{
return new EncodedString4(RawData);

View File

@ -113,5 +113,12 @@ namespace PkmnFoundations.Support
public virtual int Size { get; protected set; }
public virtual bool IsValid
{
get
{
return true;
}
}
}
}

View File

@ -198,6 +198,7 @@ namespace PkmnFoundations.Wfc
// Forbid ball capsules. Credit: Gannio
if (((PokemonParty4)Pokemon).CapsuleIndex != 0) return false;
if (!TrainerNameEncoded.IsValid) return false;
return true;
}