runelite-client: script update / outdated rework (thanks TomC)

This commit is contained in:
therealunull
2020-10-29 13:09:29 -04:00
parent 2946f1f472
commit de82f4ade2
84 changed files with 261 additions and 181 deletions

View File

@@ -1,11 +1,15 @@
package net.runelite.mixins;
import com.google.common.base.Charsets;
import com.google.common.hash.Hashing;
import com.google.common.io.ByteStreams;
import com.google.common.io.CharStreams;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.runelite.api.mixins.Copy;
import net.runelite.api.mixins.Inject;
import net.runelite.api.mixins.Mixin;
@@ -15,6 +19,7 @@ import net.runelite.api.overlay.OverlayIndex;
import net.runelite.rs.api.RSAbstractArchive;
import net.runelite.rs.api.RSArchive;
import net.runelite.rs.api.RSClient;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
@Mixin(RSAbstractArchive.class)
@@ -26,6 +31,9 @@ public abstract class RSAbstractArchiveMixin implements RSAbstractArchive
@Inject
private boolean overlayOutdated;
@Inject
private Map<String, String> scriptNames;
@Inject
@Override
public boolean isOverlayOutdated()
@@ -33,6 +41,17 @@ public abstract class RSAbstractArchiveMixin implements RSAbstractArchive
return overlayOutdated;
}
private InputStream getResourceAsStream(String resource) {
final InputStream in
= getContextClassLoader().getResourceAsStream(resource);
return in == null ? getClass().getResourceAsStream(resource) : in;
}
private ClassLoader getContextClassLoader() {
return Thread.currentThread().getContextClassLoader();
}
@SuppressWarnings("InfiniteRecursion")
@Copy("takeFile")
@Replace("takeFile")
@@ -46,6 +65,34 @@ public abstract class RSAbstractArchiveMixin implements RSAbstractArchive
return rsData;
}
if (scriptNames == null)
try
{
scriptNames = new HashMap<>();
InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("scripts/");
if (is != null)
{
List<String> files = IOUtils.readLines(is, Charsets.UTF_8);
for (String s : files)
{
if (s.endsWith(".rs2asm"))
continue;
String scriptName = s.replace(".hash", "");
InputStream hashStream = ClassLoader.getSystemClassLoader().getResourceAsStream("scripts/" + scriptName + ".hash");
if (hashStream != null)
{
String scriptHash = (String) IOUtils.readLines(hashStream, Charsets.UTF_8).toArray()[0];
scriptNames.put(scriptHash, scriptName);
}
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
final Logger log = client.getLogger();
final String path = String.format("/runelite/%s/%s", archiveId, groupId);
@@ -68,8 +115,8 @@ public abstract class RSAbstractArchiveMixin implements RSAbstractArchive
// Check if hash is correct first, so we don't have to load the overlay file if it doesn't match
if (!overlayHash.equalsIgnoreCase(originalHash))
{
log.warn("Mismatch in overlaid cache archive hash for {}/{}: {} != {}",
archiveId, groupId, overlayHash, originalHash);
log.error("Script " + scriptNames.get(overlayHash) + " is invalid, and will not be overlaid. This will break plugin(s)!");
client.setOutdatedScript(scriptNames.get(overlayHash));
overlayOutdated = true;
return rsData;
}

View File

@@ -240,6 +240,9 @@ public abstract class RSClientMixin implements RSClient
@Inject
private boolean comparingAppearance = false;
@Inject
private List<String> outdatedScripts = new ArrayList<>();
@Inject
@Override
public void setPrintMenuActions(boolean yes)
@@ -1973,5 +1976,22 @@ public abstract class RSClientMixin implements RSClient
client.setMusicTrackBoolean(var5);
client.setPcmSampleLength(var0);
}
// this exists because the original got inlined
@Inject
@Override
public void setOutdatedScript(String outdatedScript)
{
if (!outdatedScripts.contains(outdatedScript))
outdatedScripts.add(outdatedScript);
}
// this exists because the original got inlined
@Inject
@Override
public List<String> getOutdatedScripts()
{
return this.outdatedScripts;
}
}