Merge pull request #3217 from l2-/cacheTransformer

This commit is contained in:
Owain van Brakel
2022-06-16 07:45:04 +02:00
committed by GitHub
2 changed files with 26 additions and 0 deletions

View File

@@ -27,8 +27,10 @@ package net.runelite.api.overlay;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Function;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
@@ -38,6 +40,15 @@ public class OverlayIndex
@Getter
private static final Set<Integer> overlays = new HashSet<>();
/**
* Stores transformer callbacks for given cache object.
* The key is of format (indexId << 16 | archiveId).
* The value is of format:
* byte[] function(originalBytesFromCache){ if (doNothing) return originalBytesFromCache; else return customBytes; }
*/
@Getter
private static final HashMap<Integer, Function<byte[], byte[]>> cacheTransformers = new HashMap<>();
static
{
try (InputStream indexStream = OverlayIndex.class.getResourceAsStream("/runelite/index");
@@ -55,6 +66,16 @@ public class OverlayIndex
}
}
public static boolean hasCacheTransformer(int indexId, int archiveId)
{
return cacheTransformers.containsKey(indexId << 16 | archiveId);
}
public static Function<byte[], byte[]> getCacheTransformer(int indexId, int archiveId)
{
return cacheTransformers.get(indexId << 16 | archiveId);
}
public static boolean hasOverlay(int indexId, int archiveId)
{
return overlays.contains(indexId << 16 | archiveId);

View File

@@ -45,6 +45,11 @@ public abstract class RSAbstractArchiveMixin implements RSAbstractArchive
final byte[] rsData = copy$getConfigData(groupId, fileId);
final int archiveId = ((RSArchive) this).getIndex();
if (OverlayIndex.hasCacheTransformer(archiveId, groupId))
{
return OverlayIndex.getCacheTransformer(archiveId, groupId).apply(rsData);
}
if (!OverlayIndex.hasOverlay(archiveId, groupId))
{
return rsData;