Skip to content

Commit

Permalink
Fixed issue causing some Aether Revolt cards to not import correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueRaja committed Jan 29, 2017
1 parent 2aaec48 commit ba6f185
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
Expand Up @@ -34,7 +34,7 @@ public void clear() {
_cardEntries.clear();
}

public Iterable<CardData> getAllCards() {
public List<CardData> getAllCards() {
return _cardEntries;
}

Expand Down
Expand Up @@ -26,15 +26,16 @@ public MagicDuelsDeckManager(CardDataManager cardDataManager, String profilePath

public Deck getOwnedCards() throws IOException {
Profile profile = getProfile();
byte[] cardsArray = profile.readCards();
int numCards = _cardDataManager.getAllCards().size();
byte[] cardsArray = profile.readCards(numCards);
Deck deck = new Deck("Magic Duels collection");

for(int i = 0; i < cardsArray.length; i++) {
Optional<CardData> cardData = _cardDataManager.getDataForMagicDuelsId(i);
int numCards = cardsArray[i]&7; //number of cards are determined by 3 LSB
if(numCards > 0) {
int numOwned = cardsArray[i]&7; //number of cards are determined by 3 LSB
if(numOwned > 0) {
if(cardData.isPresent()) {
deck.addCard(cardData.get(), numCards);
deck.addCard(cardData.get(), numOwned);
} else {
System.out.println("Missing data for magic duels card #" + i + ", which is owned");
}
Expand Down
12 changes: 7 additions & 5 deletions src/com/blueraja/magicduelsimporter/magicduels/Profile.java
Expand Up @@ -29,12 +29,14 @@ public Profile(File profileFile) throws FileNotFoundException, IOException {
content[0x45A] ^= content[0x459+fieldLen];
}

public byte[] readCards() {
byte[] cards = new byte[1024];
public byte[] readCards(int numCards) {
byte[] cards = new byte[numCards+1];
int offset = (content[0x45E] & 0xFF) + ((content[0x45F] & 0xFF)<<8) + 0x4E0;
for (int i=0; i<512; i++) {
for (int i=0; i<numCards/2; i++) {
cards[2*i] = (byte)(content[offset+i] & 0x0F);
cards[2*i+1] = (byte)((content[offset+i]>>4) & 0x0F);
if(2*i+1 < cards.length) {
cards[2*i+1] = (byte) ((content[offset + i]>>4) & 0x0F);
}
}
return cards;
}
Expand Down Expand Up @@ -326,7 +328,7 @@ public static void main(String[] args) {
File profileFile = new File(fileName);
Profile myProfile = new Profile(profileFile);
myProfile.exportProfile(profileFile.toString()+".bin");
byte[] cards = myProfile.readCards();
byte[] cards = myProfile.readCards(1024);
(new RandomAccessFile("Cards.bin", "rw")).write(cards);
// (new RandomAccessFile("Cards.bin", "r")).read(cards);
// myProfile.writeCards(cards);
Expand Down

0 comments on commit ba6f185

Please sign in to comment.