Misc tweaks

Fix block editor GUI not showing named blocks (`Equals` is easily repointed...)
No functional change for the others, just reusing/cleaning irks.
This commit is contained in:
Kurt 2024-05-10 01:22:26 -05:00
parent 58a6d453b8
commit bd4ea9656d
8 changed files with 33 additions and 67 deletions

View File

@ -32,20 +32,20 @@ public sealed class QRPK7(Memory<byte> Raw) : IEncounterInfo
public byte Move2_PPUps => Data[9];
public byte Move3_PPUps => Data[0xA];
public byte Move4_PPUps => Data[0xB];
public uint IV32 { get => ReadUInt32LittleEndian(Data.Slice(0xC)); set => WriteUInt32LittleEndian(Data.Slice(0xC), value); }
public uint IV32 { get => ReadUInt32LittleEndian(Data[0xC..]); set => WriteUInt32LittleEndian(Data[0xC..], value); }
public int IV_HP { get => (int)(IV32 >> 00) & 0x1F; set => IV32 = (IV32 & ~(0x1Fu << 00)) | (uint)((value > 31 ? 31 : value) << 00); }
public int IV_ATK { get => (int)(IV32 >> 05) & 0x1F; set => IV32 = (IV32 & ~(0x1Fu << 05)) | (uint)((value > 31 ? 31 : value) << 05); }
public int IV_DEF { get => (int)(IV32 >> 10) & 0x1F; set => IV32 = (IV32 & ~(0x1Fu << 10)) | (uint)((value > 31 ? 31 : value) << 10); }
public int IV_SPE { get => (int)(IV32 >> 15) & 0x1F; set => IV32 = (IV32 & ~(0x1Fu << 15)) | (uint)((value > 31 ? 31 : value) << 15); }
public int IV_SPA { get => (int)(IV32 >> 20) & 0x1F; set => IV32 = (IV32 & ~(0x1Fu << 20)) | (uint)((value > 31 ? 31 : value) << 20); }
public int IV_SPD { get => (int)(IV32 >> 25) & 0x1F; set => IV32 = (IV32 & ~(0x1Fu << 25)) | (uint)((value > 31 ? 31 : value) << 25); }
public uint PID => ReadUInt32LittleEndian(Data.Slice(0x10));
public ushort Species => ReadUInt16LittleEndian(Data.Slice(0x14));
public ushort HeldItem => ReadUInt16LittleEndian(Data.Slice(0x16));
public ushort Move1 => ReadUInt16LittleEndian(Data.Slice(0x18));
public ushort Move2 => ReadUInt16LittleEndian(Data.Slice(0x1A));
public ushort Move3 => ReadUInt16LittleEndian(Data.Slice(0x1C));
public ushort Move4 => ReadUInt16LittleEndian(Data.Slice(0x1E));
public uint PID => ReadUInt32LittleEndian(Data[0x10..]);
public ushort Species => ReadUInt16LittleEndian(Data[0x14..]);
public ushort HeldItem => ReadUInt16LittleEndian(Data[0x16..]);
public ushort Move1 => ReadUInt16LittleEndian(Data[0x18..]);
public ushort Move2 => ReadUInt16LittleEndian(Data[0x1A..]);
public ushort Move3 => ReadUInt16LittleEndian(Data[0x1C..]);
public ushort Move4 => ReadUInt16LittleEndian(Data[0x1E..]);
public byte Unk_20 => Data[0x20];
public byte AbilityIndex => Data[0x21];
public Nature Nature => (Nature)Data[0x22];

View File

@ -3,32 +3,25 @@ namespace PKHeX.Core;
/// <summary>
/// Event variable used to determine game events.
/// </summary>
public abstract class EventVar
public abstract class EventVar(int Index, EventVarType Type, string Name)
{
/// <summary>
/// Name of event variable
/// </summary>
public readonly string Name;
public readonly string Name = Name;
/// <summary>
/// Type of event variable
/// </summary>
public readonly EventVarType Type;
public readonly EventVarType Type = Type;
/// <summary>
/// Unpacked structure's index.
/// </summary>
public readonly int RelativeIndex = Index;
/// <summary>
/// Raw index within the event variable (type) region.
/// </summary>
public int RawIndex;
/// <summary>
/// Unpacked structure's index.
/// </summary>
public readonly int RelativeIndex;
protected EventVar(int index, EventVarType t, string name)
{
RelativeIndex = index;
Type = t;
Name = name;
}
}

View File

@ -1,24 +1,17 @@
namespace PKHeX.Core;
namespace PKHeX.Core;
/// <summary>
/// Represents a known value for a <see cref="EventWork{T}"/> of type <see cref="int"/>.
/// </summary>
public sealed class EventWorkVal
public sealed class EventWorkVal(string Text, int Value)
{
public readonly bool Custom;
public readonly string Text;
public readonly int Value;
public readonly string Text = Text;
public readonly int Value = Value;
public EventWorkVal()
public readonly bool Custom;
public EventWorkVal() : this(nameof(Custom), int.MinValue)
{
Custom = true;
Text = nameof(Custom);
Value = int.MinValue;
}
public EventWorkVal(string text, int val)
{
Text = text;
Value = val;
}
}

View File

@ -32,8 +32,7 @@ public static IReadOnlyList<string> GetTextLines(this IEncounterInfo enc, GameSt
}
}
var el = enc as ILocation;
var loc = el?.GetEncounterLocation(enc.Generation, enc.Version);
var loc = enc.GetEncounterLocation(enc.Generation, enc.Version);
if (!string.IsNullOrEmpty(loc))
lines.Add(string.Format(L_F0_1, "Location", loc));

View File

@ -95,7 +95,8 @@ private string GetBlockHint(SCBlock z, int index)
// See if we have a Block object for this block
if (block.Data.Length != 0)
{
var obj = BlockList.FirstOrDefault(z => z.Key.Equals(block.Data));
static bool SameBackingBuffer(IDataIndirect d, ReadOnlyMemory<byte> data) => d.Equals(data);
var obj = BlockList.FirstOrDefault(z => SameBackingBuffer(z.Value, block.Data));
if (obj is not (null, null))
{
saveBlock = obj.Value;

View File

@ -47,7 +47,7 @@ public sealed class EventWork7SM(SAV7SM sav, Memory<byte> raw) : EventWork7(sav,
private const int OffsetWork = 0x0;
private const int OffsetFlag = OffsetWork + (WorkCount * sizeof(ushort)); // 0x7D0
// Hallf of Fame
// Hall of Fame
private const int OffsetPostData = OffsetFlag + (FlagCount / 8); // 0x9C4
public override int EventFlagCount => FlagCount;

View File

@ -229,9 +229,9 @@ public static SaveLanguageResult InferFrom3(ReadOnlySpan<char> name)
if (Contains(name, "bpej")) return (Japanese, E);
if (Contains(name, "bpe")) return (OverrideLanguageGen3RS, E);
if (Contains(name, "bprj")) return (Japanese, FR);
if (Contains(name, "bpr")) return (OverrideLanguageGen3FRLG, FR);
if (Contains(name, "bpr") || Contains(name, "fr") || Contains(name, "fire")) return (OverrideLanguageGen3FRLG, FR);
if (Contains(name, "bpgj")) return (Japanese, LG);
if (Contains(name, "bpg")) return (OverrideLanguageGen3FRLG, LG);
if (Contains(name, "bpg") || Contains(name, "lg") || Contains(name, "leaf")) return (OverrideLanguageGen3FRLG, LG);
return default;
}

View File

@ -133,35 +133,15 @@ public SAV_MailBox(SaveFile sav)
a.DataSource = new BindingSource(species, null);
}
var vers = GameInfo.VersionDataSource
.Where(z => ((GameVersion)z.Value).GetGeneration() == Generation);
CB_AuthorVersion.Items.Clear();
CB_AuthorVersion.InitializeBinding();
CB_AuthorVersion.DataSource = new BindingSource(Generation == 4
? new[] {
new ComboItem("Diamond", (int)GameVersion.D),
new ComboItem("Pearl", (int)GameVersion.P),
new ComboItem("Platinum", (int)GameVersion.Pt),
new ComboItem("HeartGold", (int)GameVersion.HG),
new ComboItem("SoulSilver", (int)GameVersion.SS),
}
: new[] {
new ComboItem("Black", (int)GameVersion.B),
new ComboItem("White", (int)GameVersion.W),
new ComboItem("Black2", (int)GameVersion.B2),
new ComboItem("White2", (int)GameVersion.W2),
}, null);
CB_AuthorVersion.DataSource = new BindingSource(vers, null);
CB_AuthorLang.Items.Clear();
CB_AuthorLang.InitializeBinding();
CB_AuthorLang.DataSource = new BindingSource(new[] {
// not sure
new ComboItem("JPN", 1),
new ComboItem("ENG", 2),
new ComboItem("FRE", 3),
new ComboItem("ITA", 4),
new ComboItem("GER", 5),
new ComboItem("ESP", 7),
new ComboItem("KOR", 8),
}, null);
CB_AuthorLang.DataSource = new BindingSource(GameInfo.LanguageDataSource(SAV.Generation), null);
}
var ItemList = GameInfo.Strings.GetItemStrings(SAV.Context, SAV.Version);