Skip to content

Commit 3e21b5d

Browse files
committed
feat: level0 mod working without database update when offline, include bafflers in swap
1 parent e4398a7 commit 3e21b5d

14 files changed

Lines changed: 331 additions & 120 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
*.apk
33
*.idsig
44
*.split194
5+
*.split3
6+
*.split4
57
public
68
decompiled
79
dataconsult

src/model/AbstractDropmixDataRecord.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public abstract class AbstractDropmixDataRecord {
1616
byte[] raw;// everything including the 32 bit length specifier and whitespace
1717
byte[] recordData; //
1818
boolean iOS;
19+
boolean modified;
1920
public AbstractDropmixDataRecord(byte[] data, int startIdx, boolean iOS) {
2021
this.startIdx = startIdx;
2122
this.dataStartIdx = startIdx + 4;
@@ -28,7 +29,7 @@ public AbstractDropmixDataRecord(byte[] data, int startIdx, boolean iOS) {
2829
}
2930

3031
public String toString() {
31-
return Helpers.byteArrayToString(Helpers.getNRange(raw, 4, dataLength));
32+
return (this.modified ? "[MODIFIED]" : "") + Helpers.byteArrayToString(Helpers.getNRange(raw, 4, dataLength));
3233
}
3334

3435
public boolean validateUpdatedData(byte[] newData) {

src/model/AppState.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import se.vidstige.jadb.JadbDevice;
44
import ui.UIMain;
5+
import util.Helpers;
56

67
import java.io.File;
78
import java.io.IOException;
@@ -18,6 +19,7 @@ public class AppState {
1819
public TreeMap<String, String> playlistSwap = new TreeMap<>();
1920
public JadbDevice adbDevice;
2021
public DropmixSharedAssets assetsHandler;
22+
public DropmixLevel0 level0Handler;
2123
public LogOptions logState = LogOptions.ERROR;
2224
public Process currentProcess = Process.NONE;
2325
public UIMain appFrame; // for forcing refreshes
@@ -31,7 +33,7 @@ public static AppState getInstance() {
3133
public static AppState getInstance(boolean isTest) {
3234
AppState instance = getInstance();
3335
if (isTest) {
34-
instance.setData(instance.loadFile());
36+
instance.setData(Helpers.loadFile("sharedassets0.assets.split194"), Helpers.loadFile("level0.split3"));
3537
}
3638
return instance;
3739
}
@@ -40,8 +42,9 @@ public static AppState getInstance(boolean isTest, UIMain appFrame) {
4042
instance.appFrame = appFrame;
4143
return instance;
4244
}
43-
public void setData(byte[] fileData) {
44-
this.assetsHandler = new DropmixSharedAssets(fileData);
45+
public void setData(byte[] sharedAssets, byte[] level0) {
46+
this.assetsHandler = new DropmixSharedAssets(sharedAssets);
47+
this.level0Handler = new DropmixLevel0(level0);
4548
}
4649

4750
public DropmixSharedAssetsCard[] getCards() {
@@ -95,20 +98,6 @@ public int compare(DropmixSharedAssetsPlaylist o1, DropmixSharedAssetsPlaylist o
9598
});
9699
return seasons.toArray(new DropmixSharedAssetsPlaylist[0]);
97100
}
98-
byte[] loadFile() {
99-
if (rawData != null) {
100-
return rawData;
101-
}
102-
ClassLoader classLoader = getClass().getClassLoader();
103-
104-
try {
105-
String fileByteArrayPathString = classLoader.getResource("sharedassets0.assets.split194").getFile();
106-
rawData = Files.readAllBytes(Paths.get(fileByteArrayPathString));
107-
return rawData;
108-
} catch (IOException | NullPointerException e) {
109-
throw new Error(e);
110-
}
111-
}
112101
public void removePlaylistSwap(String p1) {
113102
String p2 = this.playlistSwap.get(p1);
114103
this.playlistSwap.remove(p1);
@@ -194,7 +183,7 @@ public void reset() {
194183
this.appFrame.addPlaceholders();
195184
}
196185
// builds a card based swap from the playlist swap; may require more careful refinement as assumptions about order persistence exist
197-
public static TreeMap<String, String> getCardSwapFromPlaylist(TreeMap<String, String> plSwap) {
186+
public static TreeMap<String, String> getCardSwapFromPlaylist(TreeMap<String, String> plSwap, boolean includeBafflers) {
198187
for (String key: plSwap.values()) {
199188
String value = plSwap.get(key);
200189
String validator = plSwap.get(value);
@@ -227,6 +216,14 @@ public static TreeMap<String, String> getCardSwapFromPlaylist(TreeMap<String, St
227216
continue;
228217
}
229218
}
219+
if (includeBafflers) {
220+
String srcBaffler = srcPl.getBaffler();
221+
String swapBaffler = swapPl.getBaffler();
222+
if (srcBaffler != null && swapBaffler != null) {
223+
generatedCardSwap.put(srcBaffler, swapBaffler);
224+
generatedCardSwap.put(swapBaffler, srcBaffler);
225+
}
226+
}
230227
alreadySwappedPlaylists.add(playlist);
231228
alreadySwappedPlaylists.add(swapPl.name);
232229
}

src/model/DropmixLevel0.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22

33
import util.Helpers;
44

5+
import java.util.ArrayList;
56
import java.util.HashSet;
7+
import java.util.TreeMap;
68

79
public class DropmixLevel0 {
810
public byte[] raw;
911
public int startIdx;
10-
public static String preData = "\u0000\u0000\u0000\u0000\u0002\u0000\u0000\u0000Ä\u0002\u0000\u0000\u0000\u0000\u0000\u0000\u0003\u0000\u0000\u0000\u0002\u0000\u0000\u0000µ\u0002\u0000\u0000\u0000\u0000\u0000\u0000\u0002\u0000\u0000\u0000Á\u0002\u0000\u0000\u0000\u0000\u0000\u0000\u0002\u0000\u0000\u0000Å\u0002\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000¹\u0001\u0000\u0000";
12+
// public static String preData = "\u0000\u0000\u0000\u0000\u0002\u0000\u0000\u0000Ä\u0002\u0000\u0000\u0000\u0000\u0000\u0000\u0003\u0000\u0000\u0000\u0002\u0000\u0000\u0000µ\u0002\u0000\u0000\u0000\u0000\u0000\u0000\u0002\u0000\u0000\u0000Á\u0002\u0000\u0000\u0000\u0000\u0000\u0000\u0002\u0000\u0000\u0000Å\u0002\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000¹\u0001\u0000\u0000";
13+
public static String preData = "\u0002\u0000\u0000\u0000´\u0002\u0000\u0000\u0000\u0000\u0000\u0000\u0002\u0000\u0000\u0000¾\u0002\u0000\u0000\u0000\u0000\u0000\u0000\u0002\u0000\u0000\u0000Â\u0002\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000¹\u0001\u0000\u0000";
1114
//public static byte[] header = {7,73,68,44,65,114,116,105,115,116,44,78,97,109,101,44,65,117,100,105,111,44,73,108,108,117,115,116,114,97,116,111,114,44,73,109,97,103,101,44,84,121,112,101,44,78,117,109,32,66,97,114,115,44,84,101,115,116,32,80,111,119,101,114,44,73,110,115,116,114,117,109,101,110,116,44,73,110,115,116,114,117,109,101,110,116,32,50,44,73,110,115,116,114,117,109,101,110,116,32,51,44,73,110,115,116,114,117,109,101,110,116,32,52,44,71,101,110,114,101,44,89,101,97,114,44,83,111,117,114,99,101,44,65,98,105,108,105,116,121,44,83,99,114,101,101,110,32,84,101,120,116,44,77,117,115,105,99,32,69,102,102,101,99,116,44,84,101,109,112,111,44,75,101,121,44,77,111,100,101,44,84,114,97,110,115,105,116,105,111,110,44,87,105,108,100,32,66,101,97,116,32,72,97,115,32,75,101,121,44,65,114,116,32,67,114,111,112,32,67,101,110,116,101,114,44,67,44,68,98,44,68,44,69,98,44,69,44,70,44,71,98,44,71,44,65,98,44,65,44,66,98,44,66,44,67,114,101,100,105,116,115};
1215
public DropmixLevel0Card[] cards = new DropmixLevel0Card[440];
1316
public int dataLength;
1417
public boolean iOS = false;
18+
public static String relativePath = "/assets/bin/Data/level0.split4";
1519

1620
public DropmixLevel0(byte[] raw) {
1721
byte[] header = new byte[preData.length()];
@@ -50,4 +54,29 @@ public byte[] backToByteArray() {
5054
}
5155
return rawCopy;
5256
}
57+
public byte[] applySwap(TreeMap<String, String> cardSwaps) {
58+
System.out.printf("Applying swap: %d cards\n", cardSwaps.size());
59+
byte[] cloned = this.raw.clone();
60+
DropmixLevel0 modifiedLevel0 = new DropmixLevel0(cloned);
61+
ArrayList<String> alreadySwapped = new ArrayList<>();
62+
cardSwaps.forEach((s1, s2) -> {
63+
int idx = 0;
64+
for (DropmixLevel0Card c : modifiedLevel0.cards) {
65+
if (alreadySwapped.size() == cardSwaps.values().size()) {
66+
break;
67+
}
68+
String cardId = c.card.data.get("CID");
69+
if (cardId.equals(s1) && !alreadySwapped.contains(s1)) {
70+
c.updateEntry("CID", s2);
71+
alreadySwapped.add(s1);
72+
}
73+
if (cardId.equals(s2) && !alreadySwapped.contains(s2)) {
74+
c.updateEntry("CID", s1);
75+
alreadySwapped.add(s2);
76+
}
77+
idx++;
78+
}
79+
});
80+
return modifiedLevel0.backToByteArray();
81+
}
5382
}

src/model/DropmixLevel0Card.java

Lines changed: 89 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
import util.Helpers;
44

5-
import java.util.Arrays;
6-
import java.util.HashSet;
7-
import java.util.Set;
8-
import java.util.TreeMap;
5+
import java.util.*;
96

107
public class DropmixLevel0Card extends AbstractDropmixDataRecord {
118
// public static final String CID = "CID";
@@ -88,16 +85,64 @@ public class DropmixLevel0Card extends AbstractDropmixDataRecord {
8885
public static final String Credits = "Credits";
8986
public DataRow card;
9087
public Set<String> forceStringFields = new HashSet<>();
88+
public String originalValue;
9189
public DropmixLevel0Card(byte[] rawData, int startIdx, Set<String> forceStringFields, boolean iOS) {
9290
super(rawData, startIdx, iOS);
9391

94-
String rowString = Helpers.bytetoString(this.recordData);
92+
this.originalValue = Helpers.bytetoString(this.recordData);
9593
if (iOS) {
96-
rowString = rowString.replace("\r\n", "");// remove padding at end of listing
94+
this.originalValue = this.originalValue.replace("\r\n", "");// remove padding at end of listing
9795
}
98-
this.card = new DataRow(rowString.split(","), headings, forceStringFields);
96+
97+
// TODO move CSV parser to somewhere more relevant
98+
String[] parsedRow = rowParser(this.originalValue);
99+
this.card = new DataRow(parsedRow, headings, forceStringFields);
100+
}
101+
102+
103+
public static String[] rowParser(String value) {
104+
// hack for headings
105+
if (!value.contains("\"")) {
106+
return value.split(",");
107+
}
108+
// lazy fix for annoying quotes in credits field
109+
String[] quotesHandled = value
110+
.replaceAll(" \"", " '").replaceAll("\" ", "' ").replaceAll("\"\\)", "')")
111+
.split("\"");
112+
ArrayList<String> builder = new ArrayList<>();
113+
boolean firstEmptyInstancePassed = false;
114+
for (String quoteChunk: quotesHandled) {
115+
// skip first empty value
116+
if (quoteChunk.equals("") && builder.size() == 0) {
117+
continue;
118+
}
119+
if (!firstEmptyInstancePassed && quoteChunk.length() == 0) {
120+
firstEmptyInstancePassed = true;
121+
} else if (quoteChunk.length() > 0 && quoteChunk.charAt(0) == ',') {
122+
// if comma between quoted fields, skip
123+
if (quoteChunk.length() == 1) {
124+
continue;
125+
}
126+
String emptyCommaHack = quoteChunk.substring(1).replaceAll(",", ".,");
127+
String[] followingFields = emptyCommaHack.split(",");
128+
for (String field: followingFields) {
129+
String formattedField = field.replaceAll("\\.$", "");
130+
builder.add(formattedField);
131+
}
132+
} else {
133+
builder.add(Helpers.addQuotes(quoteChunk));
134+
}
135+
}
136+
String[] bits = new String[builder.size()];
137+
int i = 0;
138+
for (String b: bits) {
139+
bits[i] = builder.get(i++);
140+
}
141+
142+
return builder.toArray(new String[0]);
99143
}
100144

145+
101146
public void updateEntry(String key, String newData) {
102147
if (key.equals(Credits)) {
103148
throw new Error("cant-update-credits");
@@ -113,6 +158,7 @@ public void updateEntry(String key, String newData) {
113158
if (changeInSize != 0) {
114159
this.card.data.put(Credits, fieldToChange);
115160
}
161+
this.card.data.put(key, newData);
116162
// update length of credits
117163
}
118164
public byte[] backToByteArray() {
@@ -126,7 +172,11 @@ public byte[] backToByteArray() {
126172
field = Helpers.addQuotes(field);
127173
} else {
128174
try {
129-
Integer.parseInt(field);
175+
int intVal = Integer.parseInt(field);
176+
// FIXME issue for Ana Tijoux 1977
177+
if (intVal == 1977 && !h.equals("Year")) {
178+
field = Helpers.addQuotes(field);
179+
}
130180
} catch (Exception e) {
131181
if (field.length() > 0) {
132182
field = Helpers.addQuotes(field);
@@ -140,13 +190,42 @@ public byte[] backToByteArray() {
140190
}
141191
byte[] rowData = Helpers.stringToByte(sb.toString(), true);
142192
int count = 4;
143-
for (byte b : rowData) {
144-
newRaw[count++] = b;
193+
try {
194+
for (byte b : rowData) {
195+
newRaw[count++] = b;
196+
}
197+
} catch (ArrayIndexOutOfBoundsException e) {
198+
System.out.println(this);
199+
throw new Error(e);
145200
}
146201
return newRaw;
147202
}
148203
@Override
149204
public String[] getHeadings() {
150205
return DropmixLevel0Card.headings;
151206
}
207+
public String toString() {
208+
StringBuilder sb = new StringBuilder();
209+
for (String h: headings) {
210+
if (sb.length() > 0) {
211+
sb.append(",");
212+
}
213+
String data = this.card.data.get(h);
214+
if (data == null) {
215+
data = "";
216+
}
217+
try {
218+
Integer.parseInt(data);
219+
if (!h.equals("Year")) {
220+
data = Helpers.addQuotes(data);
221+
}
222+
} catch (Exception e) {
223+
if (data.length() > 0) {
224+
data = Helpers.addQuotes(data);
225+
}
226+
}
227+
sb.append(data);
228+
}
229+
return sb.toString();
230+
}
152231
}

0 commit comments

Comments
 (0)