Search in sources :

Example 1 with RSIndexData

use of net.runelite.rs.api.RSIndexData in project runelite by runelite.

the class RSIndexDataBaseMixin method rl$getConfigData.

@Replace("getConfigData")
public byte[] rl$getConfigData(int archiveId, int fileId) {
    byte[] rsData = rs$getConfigData(archiveId, fileId);
    RSIndexData indexData = (RSIndexData) this;
    if (!OverlayIndex.hasOverlay(indexData.getIndex(), archiveId)) {
        return rsData;
    }
    InputStream in = getClass().getResourceAsStream("/runelite/" + indexData.getIndex() + "/" + archiveId);
    if (in == null) {
        log.warn("Missing overlay data for {}/{}", indexData.getIndex(), archiveId);
        return rsData;
    }
    InputStream in2 = getClass().getResourceAsStream("/runelite/" + indexData.getIndex() + "/" + archiveId + ".hash");
    if (rsData == null) {
        if (in2 != null) {
            log.warn("Hash file for non existing archive {}/{}", indexData.getIndex(), archiveId);
            return null;
        }
        log.debug("Adding archive {}/{}", indexData.getIndex(), archiveId);
        try {
            return ByteStreams.toByteArray(in);
        } catch (IOException ex) {
            log.warn("error loading archive replacement", ex);
        }
        return null;
    }
    if (in2 == null) {
        log.warn("Missing hash file for {}/{}", indexData.getIndex(), archiveId);
        return rsData;
    }
    HashCode rsDataHash = Hashing.sha256().hashBytes(rsData);
    String rsHash = BaseEncoding.base16().encode(rsDataHash.asBytes());
    try {
        String replaceHash = CharStreams.toString(new InputStreamReader(in2));
        if (replaceHash.equals(rsHash)) {
            log.debug("Replacing archive {}/{}", indexData.getIndex(), archiveId);
            return ByteStreams.toByteArray(in);
        }
        log.warn("Mismatch in overlaid cache archive hash for {}/{}: {} != {}", indexData.getIndex(), archiveId, replaceHash, rsHash);
    } catch (IOException ex) {
        log.warn("error checking hash", ex);
    }
    return rsData;
}
Also used : RSIndexData(net.runelite.rs.api.RSIndexData) HashCode(com.google.common.hash.HashCode) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) IOException(java.io.IOException) Replace(net.runelite.api.mixins.Replace)

Aggregations

HashCode (com.google.common.hash.HashCode)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Replace (net.runelite.api.mixins.Replace)1 RSIndexData (net.runelite.rs.api.RSIndexData)1