Skip to content

Commit

Permalink
Fix Scarlet & Violet PKM Cards reading
Browse files Browse the repository at this point in the history
  • Loading branch information
Manu098vm committed Nov 19, 2022
1 parent da7f3d7 commit 97b5b34
Show file tree
Hide file tree
Showing 8 changed files with 3,465 additions and 18 deletions.
11 changes: 9 additions & 2 deletions SwitchGiftDataManager.Core/Classes/BCATManager/BCATManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System.Buffers.Binary;
using System.Diagnostics.Metrics;
using System.Globalization;
using System.Reflection.Metadata.Ecma335;
using System.Text;
using Enums;

namespace SwitchGiftDataManager.Core
Expand Down Expand Up @@ -274,11 +277,15 @@ private string ForgeWcFileName(Wondercard wc)
var type = wc.Type!.ToString()!;
var content = type.Equals("Pokemon") ? $"{((PokemonGift)wc.Content!).GetSpeciesName()}" : type;
var str = $"{wc.WCID:0000}_{content}";
System.Text.StringBuilder sb = new();
var sb = new System.Text.StringBuilder();
foreach (char c in str)
if (c != '\\' && c != '/' && c != ':' && c != '*' && c != '?' && c != '"' && c != '<' && c != '>' && c != '|')
sb.Append(c);
return sb.ToString().ToLower();
var _sb = new System.Text.StringBuilder();
foreach (char c in sb.ToString().Normalize(NormalizationForm.FormD))
if (CharUnicodeInfo.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark)
_sb.Append(c);
return _sb.ToString().ToLower();
}

public ReadOnlySpan<byte> ForgeMetaInfo(object? data = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@ public static string GetItemName(ushort id, object type, ushort opt = 0)
str = Properties.Resources.Items.Split(new String[] { Environment.NewLine }, StringSplitOptions.None)[id];
else if ((GiftType9)type is GiftType9.Clothing)
{
var category = (ClothingType8A)id;
var description = ""; //TODO
var category = (ClothingType9)id;
var description = category switch
{
ClothingType9.Bags => Properties.Resources.SCVIClothingBags.Split(new String[] { Environment.NewLine }, StringSplitOptions.None)[opt],
_ => "",
};
if (string.IsNullOrWhiteSpace(description))
description = $"{opt:X4}";
str = $"[{category}] {description}";
Expand Down
13 changes: 8 additions & 5 deletions SwitchGiftDataManager.Core/Classes/WCManager/WC9.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,20 @@ private PokemonGift GetPokemon()
var test = (ShinyType9)Data![ShinyTypeOffset];
var pidtype = (ShinyType9)Data![ShinyTypeOffset] switch
{
ShinyType9.ShinyLocked => PIDType.RandomPID,
ShinyType9.ShinyRandom => PIDType.RandomPID,
ShinyType9.ShinyStar => PIDType.FixedPID,
ShinyType9.ShinySquare => PIDType.FixedPID,
ShinyType9.Fixed => PIDType.FixedPID,
_ => PIDType.RandomPID,
_ => throw new ArgumentOutOfRangeException(),
};
var shinytype = (ShinyType9)Data![ShinyTypeOffset] switch
{
ShinyType9.Fixed => PokemonGift.IsShiny(pid, tid, sid) ? ShinyType.ShinyForced :
PokemonGift.IsTIDAbusePossible(tid, sid, pidtype) ? ShinyType.ShinyTIDAbuse : ShinyType.ShinyLocked,
ShinyType9.ShinyLocked => ShinyType.ShinyLocked,
ShinyType9.Shiny => ShinyType.ShinyForced,
ShinyType9.ShinyRandom => ShinyType.ShinyPossible,
ShinyType9.ShinyHighOdds => ShinyType.ShinyHighOdds,
ShinyType9.ShinyStar or ShinyType9.ShinySquare => ShinyType.ShinyForced,
ShinyType9.Fixed => PokemonGift.IsShiny(pid, tid, sid) ? ShinyType.ShinyForced :
PokemonGift.IsTIDAbusePossible(tid, sid, pidtype) ? ShinyType.ShinyTIDAbuse : ShinyType.ShinyLocked,
_ => throw new ArgumentOutOfRangeException(),
};

Expand Down
2 changes: 1 addition & 1 deletion SwitchGiftDataManager.Core/Classes/WCManager/Wondercard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace SwitchGiftDataManager.Core
internal abstract class Wondercard
{
public static int GenOffset = 0x0F;
protected const int MaxItemCount = 7;
protected const int MaxItemCount = 6;

public Games Game { get; }
public ushort WCID { get; protected set; }
Expand Down
23 changes: 18 additions & 5 deletions SwitchGiftDataManager.Core/Enums/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ internal enum ShinyType8 : byte

internal enum ShinyType9 : byte
{
Fixed = 0,
ShinyLocked = 1,
Shiny = 2,
ShinyRandom = 3,
ShinyHighOdds = 4,
ShinyLocked = 0,
ShinyRandom = 1,
ShinyStar = 2,
ShinySquare = 3,
Fixed = 4,
}

internal enum ClothingType8: byte
Expand Down Expand Up @@ -136,4 +136,17 @@ internal enum ClothingType8A: byte
Eyes = 0x08,
None = 0xFF,
}

internal enum ClothingType9 : byte
{
Heads = 0x00,
Tops = 0x01,
Bottoms = 0x02,
Outfit = 0x03,
Bags = 0x04,
Shoes = 0x5,
Glasses = 0x06,
Eyes = 0x08,
None = 0xFF,
}
}
Loading

0 comments on commit 97b5b34

Please sign in to comment.