Misc fixes

event flag editor gen5-7
rs/frlg/dp/hgss enc->pkm version choice
pb7 party stats loading
daycare slot now shows when present
remove unnecessary `GameVersion.Unknown`, use Invalid instead. Might be worth removing Invalid in favor of changing `Any=0` to `None=0`.
This commit is contained in:
Kurt 2024-03-05 09:42:20 -06:00
parent 4e87fd7eca
commit f32a1ddc7a
12 changed files with 35 additions and 30 deletions

View file

@ -10,13 +10,13 @@ public sealed class EventWorkspace<TSave, TWork> where TSave : class, IEventFlag
public readonly TWork[] Values;
public readonly EventLabelCollection Labels;
public EventWorkspace(TSave sav)
public EventWorkspace(TSave obj, GameVersion version)
{
SAV = sav;
Flags = sav.GetEventFlags();
Values = sav.GetAllEventWork();
SAV = obj;
Flags = obj.GetEventFlags();
Values = obj.GetAllEventWork();
var game = GetResourceSuffix(sav);
var game = GetResourceSuffix(version);
Labels = new EventLabelCollection(game, Flags.Length, Values.Length);
}
@ -24,11 +24,11 @@ public sealed class EventWorkspace<TSave, TWork> where TSave : class, IEventFlag
{
SAV.SetEventFlags(Flags);
SAV.SetAllEventWork(Values);
if (SAV is SAV7SM s7) // Ensure Magearna event flag has magic constant
if (SAV is EventWork7SM s7) // Ensure Magearna event flag has magic constant
s7.UpdateMagearnaConstant();
}
private static string GetResourceSuffix(TSave version) => GetVersion(version) switch
private static string GetResourceSuffix(GameVersion version) => version switch
{
X or Y or XY => "xy",
OR or AS or ORAS => "oras",
@ -46,11 +46,4 @@ public sealed class EventWorkspace<TSave, TWork> where TSave : class, IEventFlag
GD or SI or GS => "gs",
_ => throw new ArgumentOutOfRangeException(nameof(version), version, null),
};
private static GameVersion GetVersion(TSave version)
{
if (version is IVersion v)
return v.Version;
return Invalid;
}
}

View file

@ -59,6 +59,6 @@ public static class GCVersionExtensions
GCVersion.FR => GameVersion.FR,
GCVersion.LG => GameVersion.LG,
GCVersion.CXD => GameVersion.CXD,
_ => GameVersion.Unknown,
_ => GameVersion.Invalid,
};
}

View file

@ -7,7 +7,6 @@ public enum GameVersion : byte
{
#region Indicators for method empty arguments & result indication. Not stored values.
Any = 0,
Unknown = byte.MaxValue - 1,
Invalid = byte.MaxValue,
#endregion

View file

@ -29,7 +29,7 @@ internal static class LearnVerifierEgg
{
VerifyMovesInitial(result, current, x);
}
else if (enc.Version is not (GameVersion.Any or >= GameVersion.Unknown))
else if (enc.Version is not (GameVersion.Any or >= GameVersion.Invalid))
{
var ls = GameData.GetLearnSource(enc.Version);
var learn = ls.GetLearnset(enc.Species, enc.Form);

View file

@ -15,11 +15,18 @@ public static partial class Extensions
{
private static bool CanBeReceivedBy(this IVersion version, GameVersion game) => version.Version.Contains(game);
/// <summary>
/// Gets a compatible saved version value for the given <see cref="IVersion"/>.
/// </summary>
/// <param name="version">Object requesting a saved version.</param>
/// <param name="prefer">Preferred version to use, if possible.</param>
public static GameVersion GetCompatibleVersion(this IVersion version, GameVersion prefer)
{
if (version.CanBeReceivedBy(prefer) || version.Version == GameVersion.Any)
return prefer;
return version.GetSingleVersion();
if (!version.CanBeReceivedBy(prefer))
return version.GetSingleVersion();
if (!prefer.IsValidSavedVersion())
return prefer.GetSingleVersion();
return prefer;
}
public static GameVersion GetSingleVersion(this IVersion version)

View file

@ -18,6 +18,8 @@ public sealed class SAV7b : SAV_BEEF, ISaveBlock7b, IGameSync, IMysteryGiftStora
protected override int SIZE_PARTY => PokeCrypto.SIZE_6PARTY;
public override int SIZE_BOXSLOT => PokeCrypto.SIZE_6PARTY;
public override byte[] GetDataForBox(PKM pk) => pk.EncryptedPartyData;
public override PB7 GetBoxSlot(int offset) => GetDecryptedPKM(Data.AsSpan(offset, SIZE_PARTY).ToArray()); // party format in boxes!
public override PB7 GetDecryptedPKM(byte[] data) => GetPKM(DecryptPKM(data));
public override PersonalTable7GG Personal => PersonalTable.GG;
public override ReadOnlySpan<ushort> HeldItems => Legal.HeldItems_GG;

View file

@ -100,7 +100,7 @@ public sealed class SAV8BS : SaveFile, ISaveFileRevision, ITrainerStatRecord, IE
private void Initialize()
{
Box = 0x14EF4;
Party = 1;
Party = 0;
ReloadBattleTeams();
TeamSlots = BoxLayout.TeamSlots;
@ -270,6 +270,7 @@ public sealed class SAV8BS : SaveFile, ISaveFileRevision, ITrainerStatRecord, IE
// Storage
public override int GetPartyOffset(int slot) => Party + (SIZE_PARTY * slot);
protected override Span<byte> PartyBuffer => PartyInfo.Data;
public override int GetBoxOffset(int box) => Box + (SIZE_PARTY * box * 30);
public int GetBoxWallpaper(int box) => BoxLayout.GetBoxWallpaper(box);
public void SetBoxWallpaper(int box, int value) => BoxLayout.SetBoxWallpaper(box, value);

View file

@ -58,6 +58,8 @@ public sealed class EventWork7SM(SAV7SM sav, Memory<byte> raw) : EventWork7(sav,
protected override Memory<byte> FameSpan => Raw.Slice(OffsetPostData, HallOfFame7.SIZE);
public const int MagearnaEventFlag = 3100;
public void UpdateMagearnaConstant() => ((SAV7SM)SAV).UpdateMagearnaConstant();
}
public sealed class EventWork7USUM(SAV7USUM sav, Memory<byte> raw) : EventWork7(sav, raw)

View file

@ -64,7 +64,7 @@ public sealed class SaveHandlerGCI : ISaveHandler
/// Checks if the game code is one of the recognizable versions.
/// </summary>
/// <param name="gameCode">4 character game code string</param>
/// <returns>Magic version ID enumeration; <see cref="GameVersion.Unknown"/> if no match.</returns>
/// <returns>Magic version ID enumeration; <see cref="GameVersion.Invalid"/> if no match.</returns>
public static GameVersion GetGameCode(ReadOnlySpan<byte> gameCode)
{
if (IsGameMatchHeader(HEADER_COLO, gameCode))
@ -74,6 +74,6 @@ public sealed class SaveHandlerGCI : ISaveHandler
if (IsGameMatchHeader(HEADER_RSBOX, gameCode))
return GameVersion.RSBOX;
return GameVersion.Unknown;
return GameVersion.Invalid;
}
}

View file

@ -268,7 +268,7 @@ public partial class SAVEditor : UserControl, ISlotViewer<PictureBox>, ISaveFile
}
else
{
L_SlotEXP[i].Visible = TB_SlotEXP[i].Visible = true;
L_SlotEXP[i].Visible = TB_SlotEXP[i].Visible = false;
}
bool occ = s.IsDaycareOccupied(i);
@ -276,6 +276,7 @@ public partial class SAVEditor : UserControl, ISlotViewer<PictureBox>, ISaveFile
if (occ) // If Occupied
{
L_SlotOccupied[i].Text = $"{i + 1}: ✓";
UpdateSlot(i);
}
else
{
@ -627,8 +628,8 @@ public partial class SAVEditor : UserControl, ISlotViewer<PictureBox>, ISaveFile
SAV1 s => (Form)new SAV_EventReset1(s),
SAV7b s => new SAV_EventWork(s),
SAV8BS s => new SAV_FlagWork8b(s),
IEventFlag37 g37 => new SAV_EventFlags(g37),
IEventFlagProvider37 p => new SAV_EventFlags(p.EventWork),
IEventFlag37 g37 => new SAV_EventFlags(g37, SAV.Version),
IEventFlagProvider37 p => new SAV_EventFlags(p.EventWork, SAV.Version),
SAV2 s => new SAV_EventFlags2(s),
_ => throw new Exception(),
};

View file

@ -16,12 +16,12 @@ public sealed partial class SAV_EventFlags : Form
private bool editing;
public SAV_EventFlags(IEventFlag37 sav)
public SAV_EventFlags(IEventFlag37 sav, GameVersion version)
{
InitializeComponent();
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
var editor = Editor = new EventWorkspace<IEventFlag37, ushort>(sav);
var editor = Editor = new EventWorkspace<IEventFlag37, ushort>(sav, version);
DragEnter += Main_DragEnter;
DragDrop += Main_DragDrop;
@ -40,7 +40,7 @@ public sealed partial class SAV_EventFlags : Form
dgv.ResumeLayout();
TLP_Const.ResumeLayout();
Text = $"{Text} ({((IVersion)sav).Version})";
Text = $"{Text} ({version})";
if (CB_Stats.Items.Count > 0)
{

View file

@ -21,7 +21,7 @@ public sealed partial class SAV_EventFlags2 : Form
InitializeComponent();
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
var editor = Editor = new EventWorkspace<SAV2, byte>(sav);
var editor = Editor = new EventWorkspace<SAV2, byte>(sav, sav.Version);
DragEnter += Main_DragEnter;
DragDrop += Main_DragDrop;