diff --git a/src/main/java/net/runelite/deob/updater/GameConfig.java b/src/main/java/net/runelite/deob/updater/GameConfig.java new file mode 100644 index 0000000000..82111e2940 --- /dev/null +++ b/src/main/java/net/runelite/deob/updater/GameConfig.java @@ -0,0 +1,74 @@ +package net.runelite.deob.updater; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; +import java.net.URLConnection; +import java.util.HashMap; +import java.util.Map; + +public class GameConfig +{ + private static final String URL = "http://192.168.1.2/rs/jav_config.ws"; + //private static final String URL = "http://oldschool.runescape.com/jav_config.ws"; // https redirects to rs3 + + private final Map properties = new HashMap<>(), + appletProperties = new HashMap<>(); + + public void fetch() throws IOException + { + URLConnection conn = new URL(URL).openConnection(); + try (BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()))) + { + String str; + + while ((str = in.readLine()) != null) + { + int idx = str.indexOf('='); + + if (idx == -1) + continue; + + String s = str.substring(0, idx); + + if (s.equals("param")) + { + str = str.substring(idx + 1); + idx = str.indexOf('='); + s = str.substring(0, idx); + + appletProperties.put(s, str.substring(idx + 1)); + } + else if (s.equals("msg")) + { + // ignore + } + else + { + properties.put(s, str.substring(idx + 1)); + } + } + } + } + + public String getProperty(String name) + { + return properties.get(name); + } + + public Map getProperties() + { + return properties; + } + + public String getAppletProperty(String name) + { + return appletProperties.get(name); + } + + public Map getAppletProperties() + { + return appletProperties; + } +} diff --git a/src/main/java/net/runelite/deob/updater/GameConfigUpdateDetector.java b/src/main/java/net/runelite/deob/updater/GameConfigUpdateDetector.java new file mode 100644 index 0000000000..16a9c9b4cb --- /dev/null +++ b/src/main/java/net/runelite/deob/updater/GameConfigUpdateDetector.java @@ -0,0 +1,36 @@ +package net.runelite.deob.updater; + +import com.google.common.base.Strings; + +public class GameConfigUpdateDetector +{ + private final GameConfig g1, g2; + + public GameConfigUpdateDetector(GameConfig g1, GameConfig g2) + { + this.g1 = g1; + this.g2 = g2; + } + + public boolean hasUpdated() + { + // between game updatesthe parameters are scrambled, so detect when that happens. + // normally only one parameter changes, which is some integer value (+ the world) + // + // N.B. my other idea is to compare content-length in HEAD requests for the gamepack. + // the httpd doesn't support if-match and does not etag anything, and the last-modified time + // appears to be constant NOW-1 week (it moves per request) + + int differences = 0; + + for (String key : g1.getProperties().keySet()) + { + String value = g1.getAppletProperty(key), otherValue = g2.getAppletProperty(value); + + if (!Strings.nullToEmpty(value).equals(Strings.nullToEmpty(otherValue))) + ++differences; + } + + return differences > 2; // random number, world + } +} diff --git a/src/test/java/net/runelite/deob/updater/GameConfigTest.java b/src/test/java/net/runelite/deob/updater/GameConfigTest.java new file mode 100644 index 0000000000..28c2d6e4cb --- /dev/null +++ b/src/test/java/net/runelite/deob/updater/GameConfigTest.java @@ -0,0 +1,17 @@ +package net.runelite.deob.updater; + +import java.io.IOException; +import org.junit.Test; + +public class GameConfigTest +{ + @Test + public void testGetAppletProperties() throws IOException + { + GameConfig config = new GameConfig(); + config.fetch(); + System.out.println(config.getProperties()); + System.out.println(config.getAppletProperties()); + } + +} diff --git a/src/test/java/net/runelite/deob/updater/GameConfigUpdateDetectorTest.java b/src/test/java/net/runelite/deob/updater/GameConfigUpdateDetectorTest.java new file mode 100644 index 0000000000..5d1e421180 --- /dev/null +++ b/src/test/java/net/runelite/deob/updater/GameConfigUpdateDetectorTest.java @@ -0,0 +1,20 @@ +package net.runelite.deob.updater; + +import java.io.IOException; +import org.junit.Assert; +import org.junit.Test; + +public class GameConfigUpdateDetectorTest +{ + @Test + public void testHasUpdated() throws IOException + { + GameConfig c1 = new GameConfig(), c2 = new GameConfig(); + c1.fetch(); + c2.fetch(); + + GameConfigUpdateDetector gcu = new GameConfigUpdateDetector(c1, c2); + Assert.assertFalse(gcu.hasUpdated()); + } + +}