mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-27 06:20:25 +00:00
Extract gc version IDs to separate logic
This commit is contained in:
parent
ebc7c6ae29
commit
5765ce8229
5 changed files with 62 additions and 30 deletions
57
PKHeX.Core/Game/GCVersion.cs
Normal file
57
PKHeX.Core/Game/GCVersion.cs
Normal file
|
@ -0,0 +1,57 @@
|
|||
namespace PKHeX.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// <see cref="GameVersion"/> analogues used by Colosseum/XD instead of the main-series values.
|
||||
/// </summary>
|
||||
public enum GCVersion
|
||||
{
|
||||
None = 0,
|
||||
FR = 1,
|
||||
LG = 2,
|
||||
S = 8,
|
||||
R = 9,
|
||||
E = 10,
|
||||
CXD = 11,
|
||||
}
|
||||
|
||||
public static class GCVersionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Translates a main-series <see cref="GameVersion"/> to the corresponding <see cref="GCVersion"/> value.
|
||||
/// </summary>
|
||||
/// <param name="gbaVersion">Version ID while present in the main-series games</param>
|
||||
/// <returns>Version ID while present in the GameCube games</returns>
|
||||
public static GCVersion GetCXDVersionID(this GameVersion gbaVersion)
|
||||
{
|
||||
switch (gbaVersion)
|
||||
{
|
||||
case GameVersion.S: return GCVersion.S;
|
||||
case GameVersion.R: return GCVersion.R;
|
||||
case GameVersion.E: return GCVersion.E;
|
||||
case GameVersion.FR: return GCVersion.FR;
|
||||
case GameVersion.LG: return GCVersion.LG;
|
||||
case GameVersion.CXD: return GCVersion.CXD;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Translates a <see cref="GCVersion"/> to the corresponding main-series <see cref="GameVersion"/> value.
|
||||
/// </summary>
|
||||
/// <param name="gcVersion">Version ID while present in the GameCube games</param>
|
||||
/// <returns>Version ID while present in the main-series games</returns>
|
||||
public static GameVersion GetG3VersionID(this GCVersion gcVersion)
|
||||
{
|
||||
switch (gcVersion)
|
||||
{
|
||||
case GCVersion.S: return GameVersion.S;
|
||||
case GCVersion.R: return GameVersion.R;
|
||||
case GCVersion.E: return GameVersion.E;
|
||||
case GCVersion.FR: return GameVersion.FR;
|
||||
case GCVersion.LG: return GameVersion.LG;
|
||||
case GCVersion.CXD: return GameVersion.CXD;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -48,7 +48,7 @@ namespace PKHeX.Core
|
|||
public override int Species { get => SpeciesConverter.GetG4Species(BigEndian.ToUInt16(Data, 0x00)); set => BigEndian.GetBytes((ushort)SpeciesConverter.GetG3Species(value)).CopyTo(Data, 0x00); }
|
||||
// 02-04 unused
|
||||
public override uint PID { get => BigEndian.ToUInt32(Data, 0x04); set => BigEndian.GetBytes(value).CopyTo(Data, 0x04); }
|
||||
public override int Version { get => SaveUtil.GetG3VersionID(Data[0x08]); set => Data[0x08] = (byte)SaveUtil.GetCXDVersionID(value); }
|
||||
public override int Version { get => GetGBAVersionID(Data[0x08]); set => Data[0x08] = GetGCVersionID(value); }
|
||||
public int CurrentRegion { get => Data[0x09]; set => Data[0x09] = (byte)value; }
|
||||
public int OriginalRegion { get => Data[0x0A]; set => Data[0x0A] = (byte)value; }
|
||||
public override int Language { get => PKX.GetMainLangIDfromGC(Data[0x0B]); set => Data[0x0B] = PKX.GetGCLangIDfromMain((byte)value); }
|
||||
|
|
|
@ -86,6 +86,9 @@
|
|||
return value ^ x;
|
||||
}
|
||||
|
||||
protected static byte GetGBAVersionID(byte gc) => (byte)((GCVersion)gc).GetG3VersionID();
|
||||
protected static byte GetGCVersionID(int gba) => (byte)((GameVersion)gba).GetCXDVersionID();
|
||||
|
||||
/// <summary>
|
||||
/// Interconversion for Generation 3 <see cref="PKM"/> formats.
|
||||
/// </summary>
|
||||
|
|
|
@ -77,7 +77,7 @@ namespace PKHeX.Core
|
|||
public override bool FatefulEncounter { get => Data[0x30] == 1; set => Data[0x30] = (byte)(value ? 1 : 0); }
|
||||
// 0x31-0x32 Unknown
|
||||
public new int EncounterType { get => Data[0x33]; set => Data[0x33] = (byte)value; }
|
||||
public override int Version { get => SaveUtil.GetG3VersionID(Data[0x34]); set => Data[0x34] = (byte)SaveUtil.GetCXDVersionID(value); }
|
||||
public override int Version { get => GetGBAVersionID(Data[0x34]); set => Data[0x34] = GetGCVersionID(value); }
|
||||
public int CurrentRegion { get => Data[0x35]; set => Data[0x35] = (byte)value; }
|
||||
public int OriginalRegion { get => Data[0x36]; set => Data[0x36] = (byte)value; }
|
||||
public override int Language { get => PKX.GetMainLangIDfromGC(Data[0x37]); set => Data[0x37] = PKX.GetGCLangIDfromMain((byte)value); }
|
||||
|
|
|
@ -722,34 +722,6 @@ namespace PKHeX.Core
|
|||
bool IsGameMatchHeader(IEnumerable<string> headers, byte[] data) => headers.Contains(Encoding.ASCII.GetString(data, 0, 4));
|
||||
}
|
||||
|
||||
public static int GetCXDVersionID(int gen3version)
|
||||
{
|
||||
switch (gen3version)
|
||||
{
|
||||
case (int)GameVersion.FR: return 1;
|
||||
case (int)GameVersion.LG: return 2;
|
||||
case (int)GameVersion.S: return 8;
|
||||
case (int)GameVersion.R: return 9;
|
||||
case (int)GameVersion.E: return 10;
|
||||
case (int)GameVersion.CXD: return 11;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static int GetG3VersionID(int CXDversion)
|
||||
{
|
||||
switch (CXDversion)
|
||||
{
|
||||
case 1: return (int)GameVersion.FR;
|
||||
case 2: return (int)GameVersion.LG;
|
||||
case 8: return (int)GameVersion.S;
|
||||
case 9: return (int)GameVersion.R;
|
||||
case 10: return (int)GameVersion.E;
|
||||
case 11: return (int)GameVersion.CXD;
|
||||
default: return (int)GameVersion.Invalid;
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] DecryptGC(byte[] input, int start, int end, ushort[] keys)
|
||||
{
|
||||
byte[] output = (byte[])input.Clone();
|
||||
|
|
Loading…
Reference in a new issue