mirror of
https://github.com/kwsch/PKHeX
synced 2025-02-16 21:38:40 +00:00
Misc fixes
ty matt & foohyfooh
This commit is contained in:
parent
59ad4d749f
commit
4e87fd7eca
22 changed files with 64 additions and 61 deletions
|
@ -46,7 +46,6 @@ public sealed class EncounterGenerator3 : IEncounterGenerator
|
|||
deferType ??= e;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (e is not EncounterSlot3 slot)
|
||||
{
|
||||
yield return e;
|
||||
|
|
|
@ -44,17 +44,16 @@ public sealed class EncounterGenerator4 : IEncounterGenerator
|
|||
deferTile ??= e;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!IsTypeCompatible(e, pk, info.PIDIV.Type))
|
||||
{
|
||||
deferType ??= e;
|
||||
continue;
|
||||
}
|
||||
if (e is not EncounterSlot4 slot)
|
||||
{
|
||||
yield return e;
|
||||
continue;
|
||||
}
|
||||
if (!IsTypeCompatible(e, pk, info.PIDIV.Type))
|
||||
{
|
||||
deferSlot ??= slot;
|
||||
continue;
|
||||
}
|
||||
|
||||
var evo = LeadFinder.GetLevelConstraint(pk, chain, slot, 4);
|
||||
var lead = LeadFinder.GetLeadInfo4(pk, slot, info.PIDIV, evo);
|
||||
|
|
|
@ -91,6 +91,7 @@ public sealed class SaveBlockAccessor5B2W2(SAV5B2W2 sav)
|
|||
public BoxLayout5 BoxLayout { get; } = new(sav, Block(sav, 0));
|
||||
public MyItem5B2W2 Items { get; } = new(sav, Block(sav, 25));
|
||||
public PlayerData5 PlayerData { get; } = new(sav, Block(sav, 27));
|
||||
public PlayerPosition5 PlayerPosition { get; } = new(sav, Block(sav, 28));
|
||||
public UnityTower5 UnityTower { get; } = new(sav, Block(sav, 29));
|
||||
public MysteryBlock5 Mystery { get; } = new(sav, Block(sav, 34));
|
||||
public GlobalLink5 GlobalLink { get; } = new(sav, Block(sav, 35));
|
||||
|
|
|
@ -86,6 +86,7 @@ public sealed class SaveBlockAccessor5BW(SAV5BW sav) : ISaveBlockAccessor<BlockI
|
|||
public BoxLayout5 BoxLayout { get; } = new(sav, Block(sav, 0));
|
||||
public MyItem5BW Items { get; } = new(sav, Block(sav, 25));
|
||||
public PlayerData5 PlayerData { get; } = new(sav, Block(sav, 27));
|
||||
public PlayerPosition5 PlayerPosition { get; } = new(sav, Block(sav, 28));
|
||||
public UnityTower5 UnityTower { get; } = new(sav, Block(sav, 29));
|
||||
public MysteryBlock5 Mystery { get; } = new(sav, Block(sav, 34));
|
||||
public GlobalLink5 GlobalLink { get; } = new(sav, Block(sav, 35));
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace PKHeX.Core;
|
|||
/// <typeparam name="T">Type of accessor</typeparam>
|
||||
public sealed class SaveBlockMetadata<T>
|
||||
{
|
||||
private readonly Dictionary<IDataIndirect, string> BlockList;
|
||||
private readonly Dictionary<string, IDataIndirect> BlockList;
|
||||
|
||||
public SaveBlockMetadata(ISaveBlockAccessor<T> accessor)
|
||||
{
|
||||
|
@ -19,8 +19,8 @@ public sealed class SaveBlockMetadata<T>
|
|||
|
||||
public IEnumerable<string> GetSortedBlockList()
|
||||
{
|
||||
return BlockList.Select(z => z.Value).OrderBy(z => z);
|
||||
return BlockList.Select(z => z.Key).OrderBy(z => z);
|
||||
}
|
||||
|
||||
public IDataIndirect GetBlock(string name) => BlockList.First(z => z.Value == name).Key;
|
||||
public IDataIndirect GetBlock(string name) => BlockList.First(z => z.Key == name).Value;
|
||||
}
|
||||
|
|
|
@ -101,12 +101,12 @@ public sealed class SCBlockCompare
|
|||
// Replace all const name labels with explicit block property names if they exist.
|
||||
// Since our Block classes do not retain the u32 key they originated from, we need to compare the buffers to see if they match.
|
||||
// Could have just checked ContainsKey then indexed in, but I wanted to play with the higher performance API method to get the bucket and mutate directly.
|
||||
void ReplaceLabels(Dictionary<IDataIndirect, string> list, IEnumerable<SCBlock> blocks)
|
||||
void ReplaceLabels(Dictionary<string, IDataIndirect> list, IEnumerable<SCBlock> blocks)
|
||||
{
|
||||
foreach (var b in blocks)
|
||||
{
|
||||
var match = list.FirstOrDefault(z => z.Key.Equals(b.Data));
|
||||
if (match.Value is not { } x)
|
||||
var match = list.FirstOrDefault(z => z.Value.Equals(b.Data));
|
||||
if (match.Key is not { } x)
|
||||
continue;
|
||||
ref var exist = ref CollectionsMarshal.GetValueRefOrNullRef(names, b.Key);
|
||||
if (!Unsafe.IsNullRef(ref exist))
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace PKHeX.Core;
|
|||
/// </summary>
|
||||
public sealed class SCBlockMetadata
|
||||
{
|
||||
private readonly Dictionary<IDataIndirect, string> BlockList;
|
||||
private readonly Dictionary<string, IDataIndirect> BlockList;
|
||||
private readonly Dictionary<uint, string> ValueList;
|
||||
private readonly SCBlockAccessor Accessor;
|
||||
|
||||
|
@ -98,8 +98,8 @@ public sealed class SCBlockMetadata
|
|||
var obj = BlockList.FirstOrDefault(z => z.Key.Equals(block.Data));
|
||||
if (obj is not (null, null))
|
||||
{
|
||||
saveBlock = obj.Key;
|
||||
return obj.Value;
|
||||
saveBlock = obj.Value;
|
||||
return obj.Key;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -178,6 +178,7 @@ public abstract class SAV5 : SaveFile, ISaveBlock5BW, IEventFlagProvider37, IBox
|
|||
public abstract Daycare5 Daycare { get; }
|
||||
public abstract BoxLayout5 BoxLayout { get; }
|
||||
public abstract PlayerData5 PlayerData { get; }
|
||||
public abstract PlayerPosition5 PlayerPosition { get; }
|
||||
public abstract BattleSubway5 BattleSubway { get; }
|
||||
public abstract Entralink5 Entralink { get; }
|
||||
public abstract Musical5 Musical { get; }
|
||||
|
|
|
@ -43,6 +43,7 @@ public sealed class SAV5B2W2 : SAV5, ISaveBlock5B2W2
|
|||
public override Daycare5 Daycare => Blocks.Daycare;
|
||||
public override BoxLayout5 BoxLayout => Blocks.BoxLayout;
|
||||
public override PlayerData5 PlayerData => Blocks.PlayerData;
|
||||
public override PlayerPosition5 PlayerPosition => Blocks.PlayerPosition;
|
||||
public override BattleSubway5 BattleSubway => Blocks.BattleSubway;
|
||||
public override Entralink5 Entralink => Blocks.Entralink;
|
||||
public override Musical5 Musical => Blocks.Musical;
|
||||
|
|
|
@ -42,6 +42,7 @@ public sealed class SAV5BW : SAV5
|
|||
public override Daycare5 Daycare => Blocks.Daycare;
|
||||
public override BoxLayout5 BoxLayout => Blocks.BoxLayout;
|
||||
public override PlayerData5 PlayerData => Blocks.PlayerData;
|
||||
public override PlayerPosition5 PlayerPosition => Blocks.PlayerPosition;
|
||||
public override BattleSubway5 BattleSubway => Blocks.BattleSubway;
|
||||
public override Entralink5BW Entralink => Blocks.Entralink;
|
||||
public override Musical5 Musical => Blocks.Musical;
|
||||
|
|
|
@ -14,7 +14,7 @@ public sealed class SAV7b : SAV_BEEF, ISaveBlock7b, IGameSync, IMysteryGiftStora
|
|||
|
||||
public override Type PKMType => typeof(PB7);
|
||||
public override PB7 BlankPKM => new();
|
||||
protected override int SIZE_STORED => PokeCrypto.SIZE_6PARTY;
|
||||
protected override int SIZE_STORED => PokeCrypto.SIZE_6STORED;
|
||||
protected override int SIZE_PARTY => PokeCrypto.SIZE_6PARTY;
|
||||
public override int SIZE_BOXSLOT => PokeCrypto.SIZE_6PARTY;
|
||||
public override byte[] GetDataForBox(PKM pk) => pk.EncryptedPartyData;
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace PKHeX.Core;
|
|||
/// <summary>
|
||||
/// Generation 8 <see cref="SaveFile"/> object for <see cref="GameVersion.PLA"/> games.
|
||||
/// </summary>
|
||||
public sealed class SAV8LA : SaveFile, ISaveBlock8LA, ISCBlockArray, ISaveFileRevision, IBoxDetailName
|
||||
public sealed class SAV8LA : SaveFile, ISaveBlock8LA, ISCBlockArray, ISaveFileRevision, IBoxDetailName, IBoxDetailWallpaper
|
||||
{
|
||||
protected internal override string ShortSummary => $"{OT} ({Version}) - {LastSaved.LastSavedTime}";
|
||||
public override string Extension => string.Empty;
|
||||
|
|
|
@ -20,7 +20,7 @@ public abstract class EventWork5(SAV5 sav, Memory<byte> raw) : SaveBlock<SAV5>(s
|
|||
public sealed class EventWork5BW(SAV5BW sav, Memory<byte> raw) : EventWork5(sav, raw)
|
||||
{
|
||||
public const int OffsetEventWork = 0;
|
||||
public const int OffsetEventFlag = OffsetEventWork + (CountEventFlag * sizeof(ushort));
|
||||
public const int OffsetEventFlag = OffsetEventWork + (CountEventWork * sizeof(ushort));
|
||||
|
||||
public const int CountEventWork = 0x13E;
|
||||
public const int CountEventFlag = 0xB60;
|
||||
|
@ -39,7 +39,7 @@ public sealed class EventWork5BW(SAV5BW sav, Memory<byte> raw) : EventWork5(sav,
|
|||
public sealed class EventWork5B2W2(SAV5B2W2 sav, Memory<byte> raw) : EventWork5(sav, raw)
|
||||
{
|
||||
public const int OffsetEventWork = 0;
|
||||
public const int OffsetEventFlag = OffsetEventWork + (CountEventFlag * sizeof(ushort));
|
||||
public const int OffsetEventFlag = OffsetEventWork + (CountEventWork * sizeof(ushort));
|
||||
|
||||
public const int CountEventWork = 0x1AF;
|
||||
public const int CountEventFlag = 0xBF8;
|
||||
|
|
|
@ -83,28 +83,12 @@ public sealed class PlayerData5(SAV5 sav, Memory<byte> raw) : SaveBlock<SAV5>(sa
|
|||
get => Data[0x24 + 3];
|
||||
set => Data[0x24 + 3] = (byte)value;
|
||||
}
|
||||
|
||||
public int M
|
||||
{
|
||||
get => ReadInt32LittleEndian(Data[0x180..]);
|
||||
set => WriteUInt16LittleEndian(Data[0x180..], (ushort)value);
|
||||
}
|
||||
|
||||
public int X
|
||||
{
|
||||
get => ReadUInt16LittleEndian(Data[0x186..]);
|
||||
set => WriteUInt16LittleEndian(Data[0x186..], (ushort)value);
|
||||
}
|
||||
|
||||
public int Z
|
||||
{
|
||||
get => ReadUInt16LittleEndian(Data[0x18A..]);
|
||||
set => WriteUInt16LittleEndian(Data[0x18A..], (ushort)value);
|
||||
}
|
||||
|
||||
public int Y
|
||||
{
|
||||
get => ReadUInt16LittleEndian(Data[0x18E..]);
|
||||
set => WriteUInt16LittleEndian(Data[0x18E..], (ushort)value);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class PlayerPosition5(SAV5 sav, Memory<byte> raw) : SaveBlock<SAV5>(sav, raw)
|
||||
{
|
||||
public int M { get => ReadInt32LittleEndian(Data[0x80..]); set => WriteUInt16LittleEndian(Data[0x80..], (ushort)value); }
|
||||
public int X { get => ReadUInt16LittleEndian(Data[0x86..]); set => WriteUInt16LittleEndian(Data[0x86..], (ushort)value); }
|
||||
public int Z { get => ReadUInt16LittleEndian(Data[0x8A..]); set => WriteUInt16LittleEndian(Data[0x8A..], (ushort)value); }
|
||||
public int Y { get => ReadUInt16LittleEndian(Data[0x8E..]); set => WriteUInt16LittleEndian(Data[0x8E..], (ushort)value); }
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace PKHeX.Core;
|
|||
public sealed class EventWork6(SAV6 sav, Memory<byte> raw) : SaveBlock<SAV6>(sav, raw), IEventFlag37
|
||||
{
|
||||
public const int OffsetEventWork = 0;
|
||||
public const int OffsetEventFlag = OffsetEventWork + (CountEventFlag * sizeof(ushort));
|
||||
public const int OffsetEventFlag = OffsetEventWork + (CountEventWork * sizeof(ushort));
|
||||
|
||||
public const int CountEventWork = 0x178;
|
||||
public const int CountEventFlag = 0xD00; // 3328
|
||||
|
|
|
@ -125,7 +125,7 @@ public sealed class GP1(byte[] Data)
|
|||
{
|
||||
string form = Form > 0 ? $"-{Form:00}" : string.Empty;
|
||||
string star = IsShiny ? " ★" : string.Empty;
|
||||
return $"{Species:000}{form}{star} - {NickStr} - Lv. {Level:00} - {IV_HP:00}.{IV_ATK:00}.{IV_DEF:00} - CP {CP:0000} (Moves {Move1:000}, {Move2:000})";
|
||||
return $"{Species:0000}{form}{star} - {NickStr} - Lv. {Level:00} - {IV_HP:00}.{IV_ATK:00}.{IV_DEF:00} - CP {CP:0000} (Moves {Move1:000}, {Move2:000})";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,15 +7,17 @@ namespace PKHeX.Core;
|
|||
/// </summary>
|
||||
public sealed class Fused8(SAV8SWSH sav, SCBlock block) : SaveBlock<SAV8SWSH>(sav, block.Data)
|
||||
{
|
||||
private const int SizeStored = PokeCrypto.SIZE_8PARTY;
|
||||
|
||||
public static int GetFusedSlotOffset(int slot)
|
||||
{
|
||||
if ((uint)slot >= 3)
|
||||
return -1;
|
||||
return PokeCrypto.SIZE_8PARTY * slot;
|
||||
return SizeStored * slot;
|
||||
}
|
||||
|
||||
public Memory<byte> this[int i] => Raw.Slice(GetFusedSlotOffset(i), PokeCrypto.SIZE_8STORED);
|
||||
private Span<byte> GetSlotSpan(int index) => Data.Slice(GetFusedSlotOffset(index), PokeCrypto.SIZE_8STORED);
|
||||
public Memory<byte> this[int i] => Raw.Slice(GetFusedSlotOffset(i), SizeStored);
|
||||
private Span<byte> GetSlotSpan(int index) => Data.Slice(GetFusedSlotOffset(index), SizeStored);
|
||||
private PK8 GetStoredSlot(int index) => (PK8)SAV.GetStoredSlot(GetSlotSpan(index));
|
||||
private void SetStoredSlot(PK8 pk, int index) => pk.EncryptedBoxData.CopyTo(GetSlotSpan(index));
|
||||
|
||||
|
|
|
@ -193,10 +193,21 @@ public static class ReflectUtil
|
|||
return consts.ToDictionary(z => (T)(z.GetRawConstantValue() ?? throw new NullReferenceException(nameof(z.Name))), z => z.Name);
|
||||
}
|
||||
|
||||
public static Dictionary<T, string> GetAllPropertiesOfType<T>(this Type type, object obj) where T : class
|
||||
public static Dictionary<string, T> GetAllPropertiesOfType<T>(this Type type, object obj) where T : class
|
||||
{
|
||||
var props = type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
|
||||
var ofType = props.Where(fi => typeof(T).IsAssignableFrom(fi.PropertyType));
|
||||
return ofType.ToDictionary(x => (T)(x.GetValue(obj) ?? throw new NullReferenceException(nameof(x.Name))), z => z.Name);
|
||||
var result = new Dictionary<string, T>(props.Length);
|
||||
foreach (var pi in props)
|
||||
{
|
||||
if (!typeof(T).IsAssignableFrom(pi.PropertyType))
|
||||
continue;
|
||||
|
||||
var name = pi.Name;
|
||||
var value = pi.GetValue(obj);
|
||||
if (value is not T t)
|
||||
continue;
|
||||
result.TryAdd(name, t);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,10 +67,13 @@ public partial class EntityInstructionBuilder : UserControl
|
|||
private static bool GetPropertyDisplayText(PropertyInfo pi, PKM pk, out string display)
|
||||
{
|
||||
var type = pi.PropertyType;
|
||||
if (type.IsGenericType && typeof(Span<>) == type.GetGenericTypeDefinition())
|
||||
if (type.IsGenericType)
|
||||
{
|
||||
display = pi.PropertyType.ToString();
|
||||
return false;
|
||||
if (type.GetGenericTypeDefinition().IsByRefLike) // Span, ReadOnlySpan
|
||||
{
|
||||
display = pi.PropertyType.ToString();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var value = pi.GetValue(pk);
|
||||
|
|
|
@ -45,13 +45,13 @@ namespace PKHeX.WinForms
|
|||
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
|
||||
ClientSize = new System.Drawing.Size(284, 261);
|
||||
Controls.Add(FLP_List);
|
||||
Icon = global::PKHeX.WinForms.Properties.Resources.Icon;
|
||||
Icon = Properties.Resources.Icon;
|
||||
MaximizeBox = false;
|
||||
Name = "SAV_EventReset1";
|
||||
StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
||||
Text = "Event Resetter";
|
||||
FormClosing += new System.Windows.Forms.FormClosingEventHandler(SAV_EventReset1_FormClosing);
|
||||
FormClosing += SAV_EventReset1_FormClosing;
|
||||
ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -155,7 +155,7 @@ public partial class SAV_PokedexORAS : Form
|
|||
|
||||
private void SetEntry()
|
||||
{
|
||||
if (species == 0)
|
||||
if ((short)species <= 0)
|
||||
return;
|
||||
|
||||
Zukan.SetCaught(species, CP[0].Checked);
|
||||
|
|
|
@ -146,7 +146,7 @@ public partial class SAV_SimpleTrainer : Form
|
|||
L_Coins.Text = "BP"; // no translation boo
|
||||
MT_Coins.Text = s.BattleSubway.BP.ToString();
|
||||
|
||||
var pd = s.PlayerData;
|
||||
var pd = s.PlayerPosition;
|
||||
NUD_M.Value = pd.M;
|
||||
NUD_X.Value = pd.X;
|
||||
NUD_Z.Value = pd.Z;
|
||||
|
@ -261,7 +261,7 @@ public partial class SAV_SimpleTrainer : Form
|
|||
{
|
||||
if (MapUpdated)
|
||||
{
|
||||
var pd = s.PlayerData;
|
||||
var pd = s.PlayerPosition;
|
||||
pd.M = (int)NUD_M.Value;
|
||||
pd.X = (int)NUD_X.Value;
|
||||
pd.Z = (int)NUD_Z.Value;
|
||||
|
|
Loading…
Add table
Reference in a new issue