mirror of
https://github.com/TheEntropyShard/JDarkroom.git
synced 2024-11-21 20:36:21 +03:00
Code improvements, now decoding works properly
This commit is contained in:
parent
8994bcf209
commit
2025e371e6
8 changed files with 38 additions and 49 deletions
|
@ -63,22 +63,29 @@ public enum Decoder {
|
|||
bytes[byteInd] ^= (1 << bitInd);
|
||||
}
|
||||
|
||||
return Decoder.readInternetCode(bytes);
|
||||
return Decoder.getGameInfo(bytes);
|
||||
}
|
||||
|
||||
private static String readInternetCode(byte[] bytes) {
|
||||
public static String getGameInfo(byte[] bytes) {
|
||||
String resultLabel = I18N.getString("resultLabel");
|
||||
String[] internetCodes = Decoder.readInternetCode(bytes).split("_");
|
||||
String totalPlaytime = Decoder.readTotalPlaytime(bytes);
|
||||
return String.format(resultLabel, internetCodes[0], internetCodes[1], totalPlaytime);
|
||||
}
|
||||
|
||||
public static String readInternetCode(byte[] bytes) {
|
||||
int intCode = 0;
|
||||
intCode |= (bytes[8] & (0x1E000000 >> 25)) << 25;
|
||||
intCode |= (bytes[9] & (0x01000000 >> 19)) << 19;
|
||||
intCode |= (bytes[9] & (0x00001F00 >> 8)) << 8;
|
||||
intCode |= (bytes[8] & (0x1E000000 >> 25)) << 25;
|
||||
intCode |= (bytes[9] & (0x01000000 >> 19)) << 19;
|
||||
intCode |= (bytes[9] & (0x00001F00 >> 8)) << 8;
|
||||
intCode |= (bytes[10] & (0x001F0000 >> 14)) << 14;
|
||||
intCode |= (bytes[10] & (0x0000000C >> 2)) << 2;
|
||||
intCode |= (bytes[11] & (0x00000003 << 4)) >> 4;
|
||||
intCode |= (bytes[10] & (0x0000000C >> 2)) << 2;
|
||||
intCode |= (bytes[11] & (0x00000003 << 4)) >> 4;
|
||||
|
||||
int l1 = (intCode >> 24) & 0xFF;
|
||||
int d1 = (intCode >> 16) & 0xFF;
|
||||
int l2 = (intCode >> 8) & 0xFF;
|
||||
int d2 = (intCode >> 0) & 0xFF;
|
||||
int l2 = (intCode >> 8) & 0xFF;
|
||||
int d2 = (intCode >> 0) & 0xFF;
|
||||
|
||||
String[] letters1 = DecodingData.BYTES_TO_CODE.get(Integer.valueOf(l1).byteValue());
|
||||
String[] letters2 = DecodingData.BYTES_TO_CODE.get(Integer.valueOf(l2).byteValue());
|
||||
|
@ -89,9 +96,12 @@ public enum Decoder {
|
|||
String russianCode = letters1[1] + d1 + letters2[1] + d2;
|
||||
String englishCode = letters1[0] + d1 + letters2[0] + d2;
|
||||
|
||||
// I could put this in PRSF (private static final), but it might be not initialized yet
|
||||
String russianLabel = I18N.getString("codeLabelRu");
|
||||
String englishLabel = I18N.getString("codeLabelEn");
|
||||
return String.format("%s: %s %s %s: %s", russianLabel, russianCode, I18N.getString("andText"), englishLabel, englishCode);
|
||||
return russianCode + "_" + englishCode;
|
||||
}
|
||||
|
||||
public static String readTotalPlaytime(byte[] bytes) {
|
||||
return (bytes[14] < 10 ? "0" + bytes[14] : "" + bytes[14]) + ":" +
|
||||
(bytes[13] < 10 ? "0" + bytes[13] : "" + bytes[13]) + ":" +
|
||||
(bytes[15] < 10 ? "0" + bytes[15] : "" + bytes[15]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,11 @@ public enum DecodingData {
|
|||
*/
|
||||
public static final long CODE_OFFSET = 0x00002D58L;
|
||||
|
||||
/**
|
||||
* Offset, where total play time in seconds located in save
|
||||
*/
|
||||
public static final long TOTAL_PLAYTIME_OFFSET = 0x00000D4CL;
|
||||
|
||||
/**
|
||||
* Key for decoding Internet Code
|
||||
*/
|
||||
|
|
|
@ -45,20 +45,11 @@ public enum I18N {
|
|||
I18N.TRANSLATION.put("en.badFile", "Bad file given!");
|
||||
I18N.TRANSLATION.put("ru.badFile", "Перемещен плохой файл!");
|
||||
|
||||
I18N.TRANSLATION.put("ru.andText", "и");
|
||||
I18N.TRANSLATION.put("en.andText", "and");
|
||||
|
||||
I18N.TRANSLATION.put("ru.codeLabelRu", "Русский код");
|
||||
I18N.TRANSLATION.put("ru.codeLabelEn", "Английский код");
|
||||
|
||||
I18N.TRANSLATION.put("en.codeLabelRu", "Russian code");
|
||||
I18N.TRANSLATION.put("en.codeLabelEn", "English code");
|
||||
I18N.TRANSLATION.put("en.resultLabel", "<html>Russian code: %s and English code: %s<br>Total time played: %s</html>");
|
||||
I18N.TRANSLATION.put("ru.resultLabel", "<html>Русский код: %s и Английский код: %s<br>Всего времени отыграно: %s</html>");
|
||||
}
|
||||
|
||||
public static String getString(String key) {
|
||||
/*if(key.indexOf(".") == 2) {
|
||||
return I18N.TRANSLATION.get(key);
|
||||
}*/
|
||||
return I18N.TRANSLATION.get(I18N.LANGUAGE + "." + key);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,17 +19,6 @@ package me.theentropyshard.jdarkroom;
|
|||
|
||||
public class JDarkroom {
|
||||
public JDarkroom() {
|
||||
if(instance != null) {
|
||||
throw new IllegalStateException("JDarkroom already running!");
|
||||
}
|
||||
instance = this;
|
||||
|
||||
new View();
|
||||
}
|
||||
|
||||
private static JDarkroom instance;
|
||||
|
||||
public static JDarkroom getInstance() {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,8 +24,8 @@ import java.util.regex.Pattern;
|
|||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Pattern localePattern = Pattern.compile("([a-z]{2})-([A-Z]{2})$");
|
||||
if(args.length > 0) {
|
||||
Pattern localePattern = Pattern.compile("([a-z]{2})-([A-Z]{2})$");
|
||||
Matcher matcher = localePattern.matcher(args[0]);
|
||||
if(matcher.matches()) {
|
||||
try {
|
||||
|
@ -34,6 +34,8 @@ public class Main {
|
|||
} catch (Exception se) {
|
||||
se.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
System.err.println("Incorrect locale supplied: " + args[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ public enum SaveFileReader {
|
|||
|
||||
StringBuilder russianCode = new StringBuilder();
|
||||
StringBuilder englishCode = new StringBuilder();
|
||||
String totalPlaytime = "00:00:00";
|
||||
try(RandomAccessFile raf = new RandomAccessFile(file, "r")) {
|
||||
if(raf.length() <= 0) {
|
||||
return null;
|
||||
|
@ -51,9 +52,7 @@ public enum SaveFileReader {
|
|||
return null;
|
||||
}
|
||||
|
||||
String russianLabel = I18N.getString("codeLabelRu");
|
||||
String englishLabel = I18N.getString("codeLabelEn");
|
||||
String andText = I18N.getString("andText");
|
||||
return String.format("%s: %s %s %s: %s", russianLabel, russianCode, andText, englishLabel, englishCode);
|
||||
String resultLabel = I18N.getString("resultLabel");
|
||||
return String.format(resultLabel, russianCode, englishCode, totalPlaytime);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,10 +39,8 @@ public enum Utils {
|
|||
Utils.IMAGE_CACHE.put(path, bufferedImage);
|
||||
return bufferedImage;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,10 +68,4 @@ public enum Utils {
|
|||
bytes[byteInd1] |= 1 << bi1;
|
||||
}
|
||||
}
|
||||
|
||||
/*public static final class StrIntBiMap extends HashMap<String, Integer> {
|
||||
public Integer getValueByKey(String key) {
|
||||
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
|
|
@ -223,6 +223,7 @@ public final class View extends JPanel {
|
|||
cardLayout.show(this, "dropFilePanel");
|
||||
|
||||
JFrame frame = new JFrame("JDarkroom");
|
||||
frame.setResizable(false);
|
||||
frame.add(this, BorderLayout.CENTER);
|
||||
frame.pack();
|
||||
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
|
|
Loading…
Add table
Reference in a new issue