mirror of
https://github.com/bdnugget/APOS.git
synced 2026-11-07 08:47:27 +00:00
Merge branch 'sleep-hashes' into 'master'
Solve sleep word from image hashes See merge request open-runescape-classic/APOS!87
This commit is contained in:
commit
2feae7731b
3 files changed
+8371
-4
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -21,11 +21,17 @@ final class SleepListener implements ISleepListener {
|
||||
private static final String SLWORD_TXT = Paths.get("slword.txt").toString();
|
||||
private static final String DICT_TXT = Constants.PATH_SLEEP.resolve("dictionary.txt").toString();
|
||||
private static final String MODEL_TXT = Constants.PATH_SLEEP.resolve("model.txt").toString();
|
||||
private static final String HASHES = Constants.PATH_SLEEP.resolve("hashes.properties").toString();
|
||||
|
||||
private static final int FNV1_32_INIT = 0x811c9dc5;
|
||||
private static final int FNV1_PRIME_32 = 16777619;
|
||||
|
||||
private static final int MAXIMUM_INCORRECT_SLEEP_TRIES = 3;
|
||||
|
||||
private final IClient client;
|
||||
|
||||
private Properties hashes;
|
||||
|
||||
private OCR ocr;
|
||||
private OCRType ocrType;
|
||||
private String sleepWord;
|
||||
@@ -83,6 +89,16 @@ final class SleepListener implements ISleepListener {
|
||||
sleepWord = null;
|
||||
}
|
||||
break;
|
||||
case HASH:
|
||||
byte[] image = convertImage(data);
|
||||
int hash = hash32(image);
|
||||
sleepWord = hashes.getProperty(Integer.toString(hash));
|
||||
if (sleepWord == null)
|
||||
sleepWord = "unknown";
|
||||
|
||||
if (client.getSleepFatigue() == 0)
|
||||
onSleepFatigueUpdate(0);
|
||||
break;
|
||||
case JOKER:
|
||||
try (final FileOutputStream out = new FileOutputStream(hc)) {
|
||||
saveBitmap(out, convertImage(data));
|
||||
@@ -236,6 +252,34 @@ final class SleepListener implements ISleepListener {
|
||||
}
|
||||
return var4;
|
||||
}
|
||||
|
||||
/**
|
||||
* FNV1a 32 bit variant.
|
||||
*
|
||||
* @param data - input byte array
|
||||
* @return - hashcode
|
||||
*/
|
||||
private static int hash32(byte[] data) {
|
||||
return hash32(data, data.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* FNV1a 32 bit variant.
|
||||
*
|
||||
* @param data - input byte array
|
||||
* @param length - length of array
|
||||
* @return - hashcode
|
||||
*/
|
||||
private static int hash32(byte[] data, int length) {
|
||||
int hash = FNV1_32_INIT;
|
||||
for (int i = 0; i < length; i++) {
|
||||
hash ^= (data[i] & 0xff);
|
||||
hash *= FNV1_PRIME_32;
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the sleep fatigue and takes appropriate actions based on the fatigue level.
|
||||
*
|
||||
@@ -335,6 +379,15 @@ final class SleepListener implements ISleepListener {
|
||||
this.ocrType = OCRType.MANUAL;
|
||||
}
|
||||
break;
|
||||
case HASH:
|
||||
try (FileInputStream fs = new FileInputStream(HASHES)) {
|
||||
hashes = new Properties();
|
||||
hashes.load(fs);
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
this.ocrType = OCRType.MANUAL;
|
||||
}
|
||||
break;
|
||||
case JOKER:
|
||||
hc = new File(HC_BMP);
|
||||
final Joker joker = Joker.getInstance();
|
||||
|
||||
@@ -6,10 +6,11 @@ public interface ISleepListener {
|
||||
void setOCRType(OCRType ocrType);
|
||||
|
||||
enum OCRType {
|
||||
NUM3(0, "Num3l (Internal)"),
|
||||
JOKER(1, "Joker (Internal/Win32/JNI)"),
|
||||
EXTERNAL(2, "External (HC.BMP/slword.txt)"),
|
||||
MANUAL(3, "Manual");
|
||||
HASH(0, "Image Hashes (OpenRSC)"),
|
||||
NUM3(1, "Num3l (cross-platform)"),
|
||||
JOKER(2, "Joker (Windows only)"),
|
||||
EXTERNAL(3, "External (HC.BMP + slword.txt)"),
|
||||
MANUAL(4, "Manual");
|
||||
|
||||
public static final OCRType[] VALUES = OCRType.values();
|
||||
|
||||
|
||||
Reference in new issue
Block a user