mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-09-15 03:25:20 -05:00
Extract some logic from QR7
Update notes, update method names. 10 years since this (apparently custom?) format was whipped up. Probably good to have more accurate documentation for this early-injection format?
This commit is contained in:
@@ -37,17 +37,21 @@ public static class QRMessageUtil
|
||||
public static string GetMessage(PKM pk)
|
||||
{
|
||||
if (pk is PK7 pk7)
|
||||
{
|
||||
Span<byte> payload = stackalloc byte[QR7.SIZE];
|
||||
QR7.SetQRData(pk7, payload);
|
||||
return GetMessage(payload);
|
||||
}
|
||||
return GetMessage(pk7);
|
||||
|
||||
var server = GetExploitURLPrefixPKM(pk.Format);
|
||||
var data = pk.EncryptedBoxData;
|
||||
return GetMessageBase64(data, server);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="GetMessage(PKM)"/>
|
||||
public static string GetMessage(PK7 pk7, int box = 0, int slot = 0, int num_copies = 1)
|
||||
{
|
||||
Span<byte> data = stackalloc byte[QR7.SIZE];
|
||||
QR7.SetQRData(pk7, data, box, slot, num_copies);
|
||||
return GetMessage(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a QR Message from the input <see cref="byte"/> data.
|
||||
/// </summary>
|
||||
|
||||
@@ -9,8 +9,9 @@ namespace PKHeX.Core;
|
||||
// u32 slot;
|
||||
// u32 num_copies;
|
||||
// u8 reserved[0x1C];
|
||||
// u8 ek7[0x104];
|
||||
// u8 dex_data[0x60];
|
||||
// u8 ek7[0x104]; -- starts at 0x30
|
||||
// u8 alignment[0xC];
|
||||
// u8 dex_data[0x60]; -- starts at 0x140
|
||||
// u16 crc16
|
||||
// sizeof(QR7) == 0x1A2
|
||||
|
||||
@@ -43,7 +44,7 @@ private static bool IsGenderDifferent(ushort species)
|
||||
return (table[index] & (1 << (species & 7))) != 0;
|
||||
}
|
||||
|
||||
private static void GetRawQR(Span<byte> dest, ushort species, byte form, bool shiny, byte gender)
|
||||
private static void SetDexData(Span<byte> dest, ushort species, byte form, bool shiny, byte gender)
|
||||
{
|
||||
dest[..6].Fill(0xFF);
|
||||
WriteUInt16LittleEndian(dest[0x28..], species);
|
||||
@@ -86,7 +87,7 @@ public static void SetQRData(PK7 pk7, Span<byte> span, int box = 0, int slot = 0
|
||||
WriteInt32LittleEndian(span[0x10..], num_copies); // No need to check max num_copies, payload parser handles it on-console.
|
||||
|
||||
pk7.EncryptedPartyData.CopyTo(span[0x30..]); // Copy in pokemon data
|
||||
GetRawQR(span[0x140..], pk7.Species, pk7.Form, pk7.IsShiny, pk7.Gender);
|
||||
SetDexData(span[0x140..], pk7.Species, pk7.Form, pk7.IsShiny, pk7.Gender);
|
||||
|
||||
var chk = Checksums.CRC16Invert(span[..0x1A0]);
|
||||
WriteUInt16LittleEndian(span[0x1A0..], chk);
|
||||
|
||||
@@ -32,11 +32,7 @@ public static class QREncode
|
||||
/// <param name="copies">The number of copies to encode.</param>
|
||||
/// <returns>A bitmap containing the QR code.</returns>
|
||||
public static Bitmap GenerateQRCode7(PK7 pk7, int box = 0, int slot = 0, int copies = 1)
|
||||
{
|
||||
byte[] data = QR7.GenerateQRData(pk7, box, slot, copies);
|
||||
var msg = QRMessageUtil.GetMessage(data);
|
||||
return GenerateQRCode(msg, ppm: 4);
|
||||
}
|
||||
=> GenerateQRCode(QRMessageUtil.GetMessage(pk7, box, slot, copies), ppm: 4);
|
||||
|
||||
/// <summary>
|
||||
/// Generates a QR code bitmap from a message string.
|
||||
|
||||
Reference in New Issue
Block a user