Skip to content

Commit

Permalink
Make the custom LP / hand count optional
Browse files Browse the repository at this point in the history
  • Loading branch information
pixeltris committed May 11, 2020
1 parent 63d259e commit 21bcd28
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 54 deletions.
7 changes: 1 addition & 6 deletions Lotd/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ namespace Lotd
public static class Constants
{
public const GameVersion LatestVersion = GameVersion.LinkEvolution2;

public const int AbsoluteMaxNumCards = 20000;// Keep this as a constant
public static int NumCards { get { return GetNumCards(Program.Version); } }

public static int GetNumCards(GameVersion version)
{
switch (version)
Expand All @@ -24,7 +23,6 @@ public static int GetNumCards(GameVersion version)
}
}

public static int NumCards2 { get { return GetNumCards2(Program.Version); } }
public static int GetNumCards2(GameVersion version)
{
switch (version)
Expand All @@ -49,12 +47,10 @@ public static ushort GetMaxCardId(GameVersion version)
return 14969;
}
}
public static ushort MaxCardId { get { return GetMaxCardId(Program.Version); } }

/// <summary>
/// Number of duel series (YuGiOh, GX, 5D, ZEXAL, ARCV)
/// </summary>
public static int NumDuelSeries { get { return GetNumDuelSeries(Program.Version); } }
public static int GetNumDuelSeries(GameVersion version)
{
switch (version)
Expand All @@ -81,7 +77,6 @@ public static int GetNumDuelSeries(GameVersion version)
/// <summary>
/// Number of deck slots available which map into deckdata_X.bin
/// </summary>
public static int NumDeckDataSlots { get { return GetNumDeckDataSlots(Program.Version); } }
public static int GetNumDeckDataSlots(GameVersion version)
{
switch (version)
Expand Down
2 changes: 1 addition & 1 deletion Lotd/FileFormats/bin/CardManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private void LoadCardProp(CardInfo card, Dictionary<short, CardInfo> cardsById,
cardsById.Add(cardId, card);

// This is a hard coded value in native code. Might as well do the same check here.
Debug.Assert(cardId < Constants.MaxCardId + 1);
Debug.Assert(cardId < Constants.GetMaxCardId(Manager.Version) + 1);

if (!Enum.IsDefined(typeof(MonsterType), monsterType) ||
!Enum.IsDefined(typeof(SpellType), spellType) ||
Expand Down
2 changes: 1 addition & 1 deletion Lotd/FileFormats/bin/RelatedCardData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override void Load(BinaryReader reader, long length)
Clear();

// There doesn't seem to be any identifier which says how many items to read. Assuming it reads until known max cards.
int numCards = Constants.NumCards;
int numCards = Constants.GetNumCards2(File.Archive.Version);

long dataStart = reader.BaseStream.Position + (numCards * 8);

Expand Down
24 changes: 12 additions & 12 deletions Lotd/NativeScript/MemTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ private void ValidateStructs()
Debug.Assert(Marshal.SizeOf(typeof(YdcDeck)) == 304);
Debug.Assert(Marshal.SizeOf(typeof(YdcDeck)) == GameSaveData.GetDecksSize(Version) / Constants.NumUserDecks);
Debug.Assert(Marshal.SizeOf(typeof(CardProps)) == 48);
Debug.Assert(Marshal.SizeOf(typeof(RawPackDefData)) == 56);
Debug.Assert(Marshal.SizeOf(typeof(DuelPlayerInfo)) == 3472);// LE = 3476
Debug.Assert(Marshal.SizeOf(typeof(RawPackDefData)) == 56);// TODO: Update for LE?
Debug.Assert(Marshal.SizeOf(typeof(DuelPlayerInfo)) == 3472);// LE = 3476. TODO: Update for LE
}

private void ValidateNativeScriptStructs()
Expand Down Expand Up @@ -350,7 +350,7 @@ public void SetDeckEditTrunkCards(short[] cardIds, int numTotalCards)
DeckEditFilterCards filterCards = new DeckEditFilterCards();
filterCards.NumFilteredCards = cardIds.Length;
filterCards.NumTotalCards = numTotalCards;
filterCards.CardIds = new short[Constants.NumCards];
filterCards.CardIds = new short[Constants.GetNumCards2(Version)];
Array.Copy(cardIds, filterCards.CardIds, Math.Min(filterCards.CardIds.Length, cardIds.Length));
CallNativeScriptFunctionWithStruct("SetDeckEditTrunkCards", filterCards);

Expand Down Expand Up @@ -387,7 +387,7 @@ public short[] GetDeckEditTrunkCards()
int numFilteredCards = ReadValue<int>(deckEditAddress + addresses.deckEditFilteredCardCountOffset);
IntPtr cardsPtr = ReadValue<IntPtr>(deckEditAddress + addresses.deckEditCardsOffset);

if (numFilteredCards > Constants.NumCards)
if (numFilteredCards > Constants.GetNumCards2(Version))
{
return new short[0];
}
Expand Down Expand Up @@ -577,7 +577,7 @@ private CardState[] ReadDeckEditorOwnedCardsList()
{
return null;
}
return ReadValues<CardState>(saveDataAddress, Constants.NumCards);
return ReadValues<CardState>(saveDataAddress, Constants.GetNumCards2(Version));
}

/// <summary>
Expand All @@ -587,7 +587,7 @@ public CardState[] ReadActualOwnedCardList()
{
CardState[] defaultOwnedCards = ReadDefaultOwnedCardsList();
CardState[] ownedCards = ReadOwnedCardsList();
CardState[] result = new CardState[Constants.NumCards];
CardState[] result = new CardState[Constants.GetNumCards2(Version)];
if (ownedCards != null)
{
for (int i = 0; i < ownedCards.Length && i < result.Length; i++)
Expand Down Expand Up @@ -616,7 +616,7 @@ public CardState[] ReadActualOwnedCardList()
/// <returns></returns>
public CardState[] ReadDefaultOwnedCardsList()
{
CardState[] result = new CardState[Constants.NumCards];
CardState[] result = new CardState[Constants.GetNumCards2(Version)];
YdcDeck[] decks = ReadYdcDecks();
Manager manager = Program.Manager;
if (decks != null && manager != null && manager.CardManager != null)
Expand Down Expand Up @@ -648,7 +648,7 @@ public CardState[] ReadDefaultOwnedCardsList()

foreach(short cardId in cardIds)
{
if (cardId > 0 && cardId <= Constants.MaxCardId)
if (cardId > 0 && cardId <= Constants.GetMaxCardId(Version))
{
FileFormats.CardInfo card;
if (manager.CardManager.Cards.TryGetValue(cardId, out card))
Expand All @@ -674,7 +674,7 @@ public CardState[] ReadOwnedCardsList()
{
return null;
}
return ReadValues<CardState>(saveDataAddress + GameSaveData.GetCardListOffset(Version), Constants.NumCards);
return ReadValues<CardState>(saveDataAddress + GameSaveData.GetCardListOffset(Version), Constants.GetNumCards2(Version));
}

/// <summary>
Expand Down Expand Up @@ -1392,7 +1392,7 @@ public void WriteCustomBattlePackYdcDecks(YdcDeck[] decks)
/// </summary>
public YdcDeck[] ReadYdcDecks()
{
YdcDeck[] decks = ReadValues<YdcDeck>(addresses.ydcDecksAddress, Constants.NumDeckDataSlots);
YdcDeck[] decks = ReadValues<YdcDeck>(addresses.ydcDecksAddress, Constants.GetNumDeckDataSlots(Version));
CheckDecksForUnknownData(decks);
return decks;
}
Expand Down Expand Up @@ -1431,15 +1431,15 @@ private void CheckDecksForUnknownData(YdcDeck[] decks)
/// <returns></returns>
public CardProps[] ReadCardProps()
{
return ReadValues<CardProps>(addresses.cardPropsBinAddress, Constants.MaxCardId + 1);
return ReadValues<CardProps>(addresses.cardPropsBinAddress, Constants.GetMaxCardId(Version) + 1);
}

/// <summary>
/// Writes the the in-memory of card props (each index is a card id)
/// </summary>
public void WriteCardProps(CardProps[] cardProps)
{
Debug.Assert(cardProps.Length <= Constants.MaxCardId + 1);
Debug.Assert(cardProps.Length <= Constants.GetMaxCardId(Version) + 1);
WriteValues(addresses.cardPropsBinAddress, cardProps);
}

Expand Down
Loading

0 comments on commit 21bcd28

Please sign in to comment.