cache transformer mixin addition
This commit is contained in:
@@ -27,8 +27,10 @@ package net.runelite.api.overlay;
|
|||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Function;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@@ -38,6 +40,15 @@ public class OverlayIndex
|
|||||||
@Getter
|
@Getter
|
||||||
private static final Set<Integer> overlays = new HashSet<>();
|
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
|
static
|
||||||
{
|
{
|
||||||
try (InputStream indexStream = OverlayIndex.class.getResourceAsStream("/runelite/index");
|
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)
|
public static boolean hasOverlay(int indexId, int archiveId)
|
||||||
{
|
{
|
||||||
return overlays.contains(indexId << 16 | archiveId);
|
return overlays.contains(indexId << 16 | archiveId);
|
||||||
|
|||||||
@@ -45,6 +45,11 @@ public abstract class RSAbstractArchiveMixin implements RSAbstractArchive
|
|||||||
final byte[] rsData = copy$getConfigData(groupId, fileId);
|
final byte[] rsData = copy$getConfigData(groupId, fileId);
|
||||||
final int archiveId = ((RSArchive) this).getIndex();
|
final int archiveId = ((RSArchive) this).getIndex();
|
||||||
|
|
||||||
|
if (OverlayIndex.hasCacheTransformer(archiveId, groupId))
|
||||||
|
{
|
||||||
|
return OverlayIndex.getCacheTransformer(archiveId, groupId).apply(rsData);
|
||||||
|
}
|
||||||
|
|
||||||
if (!OverlayIndex.hasOverlay(archiveId, groupId))
|
if (!OverlayIndex.hasOverlay(archiveId, groupId))
|
||||||
{
|
{
|
||||||
return rsData;
|
return rsData;
|
||||||
|
|||||||
Reference in New Issue
Block a user