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;
}
Aggregations