From 795a87fb281d904e26b77a884ea3d4dd38b6d005 Mon Sep 17 00:00:00 2001 From: lequietriot Date: Mon, 12 Dec 2022 06:01:10 -0600 Subject: [PATCH] Model viewer improvements - supports RS2 and some RSHD textures --- Old-School-RuneScape-Cache-Tools.iml | 2 +- README.md | 5 +- .../cache/managers/TextureManagerHD.class | Bin 2794 -> 2750 bytes src/java/com/application/GUI.java | 1 - .../controllers/ModelController.java | 4 +- src/java/modelviewer/scene/RSMeshGroup.java | 39 ++ .../cache/loaders/ImageIndexLoader.java | 143 ----- .../runelite/cache/loaders/ImageLoader.java | 13 - .../cache/managers/TextureManagerHD.java | 2 +- src/java/rshd/Class308.java | 50 ++ src/java/rshd/Class316.java | 33 ++ src/java/rshd/Class320.java | 26 + src/java/rshd/Class503.java | 242 ++++++++ src/java/rshd/ImageIndexLoader.java | 144 +++++ src/java/rshd/ImageLoader.java | 21 + src/java/rshd/LinkedNodeList.java | 149 +++++ src/java/rshd/MaterialDefinitions.java | 254 ++++++++ src/java/rshd/MaterialPropSprite.java | 81 +++ src/java/rshd/MaterialProperty.java | 79 +++ src/java/rshd/SpriteDefinitions.java | 552 ++++++++++++++++++ .../loaders => rshd}/TextureLoaderHD.java | 2 +- 21 files changed, 1678 insertions(+), 164 deletions(-) delete mode 100644 src/java/net/runelite/cache/loaders/ImageIndexLoader.java delete mode 100644 src/java/net/runelite/cache/loaders/ImageLoader.java create mode 100644 src/java/rshd/Class308.java create mode 100644 src/java/rshd/Class316.java create mode 100644 src/java/rshd/Class320.java create mode 100644 src/java/rshd/Class503.java create mode 100644 src/java/rshd/ImageIndexLoader.java create mode 100644 src/java/rshd/ImageLoader.java create mode 100644 src/java/rshd/LinkedNodeList.java create mode 100644 src/java/rshd/MaterialDefinitions.java create mode 100644 src/java/rshd/MaterialPropSprite.java create mode 100644 src/java/rshd/MaterialProperty.java create mode 100644 src/java/rshd/SpriteDefinitions.java rename src/java/{net/runelite/cache/loaders => rshd}/TextureLoaderHD.java (99%) diff --git a/Old-School-RuneScape-Cache-Tools.iml b/Old-School-RuneScape-Cache-Tools.iml index 1afd0c8..c9e234c 100644 --- a/Old-School-RuneScape-Cache-Tools.iml +++ b/Old-School-RuneScape-Cache-Tools.iml @@ -1,6 +1,6 @@ - + diff --git a/README.md b/README.md index a92b5e1..6f6144a 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,8 @@ Made with IntelliJ IDEA using Java 1.8 SDK with various libraries including Java * Cache Explorer: Not able to dump/export all files of single archive - only the first file is exported? * Cache Explorer: Some caches may not load correctly * Data Decoders: SoundFont conversion - may not be perfect -* Model Viewer: Does not work on RS2 yet -* Model Viewer: May not work on Mac computers, a workaround would be running the project directly through IntelliJ IDEA. +* Model Viewer: Textures do not work in RS2 caches +* Model Viewer: Textures may not load in all RSHD caches +* Model Viewer: May not work on Mac computers, a workaround would be running the project or jar directly through IntelliJ IDEA. ## That's all for now. Enjoy! \ No newline at end of file diff --git a/out/production/Old-School-RuneScape-Cache-Tools/net/runelite/cache/managers/TextureManagerHD.class b/out/production/Old-School-RuneScape-Cache-Tools/net/runelite/cache/managers/TextureManagerHD.class index 3e7fc49c8ef2e4e4c8072e49d2bbaf536c11b4c0..52e548ee4b47fdbd57d1682e85633724897637aa 100644 GIT binary patch delta 30 icmaDQx=(aNAQPLoPf>A3%H~|A!;Gw=V5T?Ad^P~4cnU}W delta 74 zcmdld`bu;|Ad`%)PhM(?eo<*&YEEWJs(x}}az?6tPJUuaYEkj#aHhkI(%N_w$g|96 F0{{g<8!!L> diff --git a/src/java/com/application/GUI.java b/src/java/com/application/GUI.java index 45412b3..7c9b246 100644 --- a/src/java/com/application/GUI.java +++ b/src/java/com/application/GUI.java @@ -848,7 +848,6 @@ private void loadCache(File cache) { } } - this.revalidate(); } diff --git a/src/java/modelviewer/controllers/ModelController.java b/src/java/modelviewer/controllers/ModelController.java index 74e2e5e..cf10709 100644 --- a/src/java/modelviewer/controllers/ModelController.java +++ b/src/java/modelviewer/controllers/ModelController.java @@ -66,10 +66,10 @@ public void updateModel(CacheLibrary cacheLibrary, int selectedIndex, int select if (AppConstants.cacheType.equals("RuneScape 2")) { ModelLoader modelLoader = new ModelLoader(); ModelDefinition model; - if (selectedIndex == 7) { + if (selectedIndex == 1) { model = modelLoader.load(0, Objects.requireNonNull(cacheLibrary.data(selectedIndex, selectedArchive, selectedFile))); } else { - model = modelLoader.load(0, Objects.requireNonNull(cacheLibrary.data(7, 1, 0))); + model = modelLoader.load(0, Objects.requireNonNull(cacheLibrary.data(1, 1, 0))); } if (model != null) { try { diff --git a/src/java/modelviewer/scene/RSMeshGroup.java b/src/java/modelviewer/scene/RSMeshGroup.java index 500bb22..d19dcf6 100644 --- a/src/java/modelviewer/scene/RSMeshGroup.java +++ b/src/java/modelviewer/scene/RSMeshGroup.java @@ -15,6 +15,7 @@ import net.runelite.cache.definitions.SpriteDefinition; import net.runelite.cache.definitions.loaders.SpriteLoader; import net.runelite.cache.fs.Store; +import rshd.TextureLoaderHD; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; @@ -32,6 +33,7 @@ public class RSMeshGroup { public final float MODEL_SCALE = 0.03f; private TextureManager textureManager; + private TextureLoaderHD textureLoaderHD; public RSMeshGroup(ModelDefinition model) { this.model = model; @@ -40,12 +42,18 @@ public RSMeshGroup(ModelDefinition model) { private Image texture; public void buildMeshes() throws IOException { + if (AppConstants.cacheType.equals("RuneScape 2")) { + + } if (AppConstants.cacheType.equals("Old School RuneScape")) { Store store = new Store(new File(GUI.cacheLibrary.getPath())); store.load(); textureManager = new TextureManager(store); textureManager.load(); } + if (AppConstants.cacheType.equals("RuneScape High Definition")) { + textureLoaderHD = new TextureLoaderHD(); + } model.computeTextureUVCoordinates(); for (int face = 0; face < model.faceCount; face++) { TriangleMesh mesh = new TriangleMesh(); @@ -81,6 +89,13 @@ public void buildMeshes() throws IOException { if (model.faceTextures != null && model.faceTextures[face] != -1 && AppConstants.cacheType.equals("Old School RuneScape")) { texture = exportToImage(textureManager.findTexture(model.faceTextures[face]).getFileIds()[0]); mat.setDiffuseMap(texture); + mat.setDiffuseColor(ColorUtils.rs2HSLToColor(model.faceColors[face], model.faceTransparencies == null ? 0 : model.faceTransparencies[face])); + view.setMaterial(mat); + } + if (model.faceTextures != null && model.faceTextures[face] != -1 && AppConstants.cacheType.equals("RuneScape High Definition")) { + texture = exportToImageHD(model.faceTextures[face]); + mat.setDiffuseMap(texture); + mat.setDiffuseColor(ColorUtils.rs2HSLToColor(model.faceColors[face], 0));//model.faceTransparencies == null ? 0 : model.faceTransparencies[face])); view.setMaterial(mat); } else { @@ -94,6 +109,7 @@ public void buildMeshes() throws IOException { } } + private void initListeners(MeshView view) { view.setOnMouseClicked(event -> { paint(view); @@ -127,4 +143,27 @@ public Image exportToImage(int spriteID) throws IOException ImageIO.write(image, "png", byteArrayOutputStream); return new Image(new ByteArrayInputStream(byteArrayOutputStream.toByteArray())); } + + public Image exportToImageHD(int id) { + byte[] data = GUI.cacheLibrary.data(9, id, 0); + if (data != null) { + if (data[1] == "P".getBytes()[0]) { + return new Image(new ByteArrayInputStream(data)); + } + } + /* + try { + ImageIndexLoader imageIndexLoader = new ImageIndexLoader(GUI.cacheLibrary.index(26), GUI.cacheLibrary.index(9), GUI.cacheLibrary.index(8)); + int[] pixels = imageIndexLoader.renderMaterialPixelsI(id, 256, 256); + BufferedImage bi = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB); + bi.setRGB(0, 0, 256, 256, pixels, 0, 256); + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + ImageIO.write(bi, "png", byteArrayOutputStream); + return new Image(new ByteArrayInputStream(byteArrayOutputStream.toByteArray())); + } catch (IOException e) { + e.printStackTrace(); + } + */ + return null; + } } diff --git a/src/java/net/runelite/cache/loaders/ImageIndexLoader.java b/src/java/net/runelite/cache/loaders/ImageIndexLoader.java deleted file mode 100644 index 078e55f..0000000 --- a/src/java/net/runelite/cache/loaders/ImageIndexLoader.java +++ /dev/null @@ -1,143 +0,0 @@ -package net.runelite.cache.loaders; - -import com.displee.cache.index.Index; -import net.runelite.cache.definitions.TextureDetails; -import osrs.Buffer; - -import java.util.Objects; - -public class ImageIndexLoader implements ImageLoader { - - Index textureIndex; - - Index spriteIndex; - - int textureDefSize; - - TextureDetails[] textures; - - public ImageIndexLoader(Index textureDefIndex, Index textureIndex, Index spriteIndex) { - this.textureIndex = textureIndex; - this.spriteIndex = spriteIndex; - Buffer stream = new Buffer(Objects.requireNonNull(Objects.requireNonNull(textureDefIndex.archive(0)).file(0)).getData()); - textureDefSize = stream.readUnsignedShort(); - textures = new TextureDetails[textureDefSize]; - int i_5; - for (i_5 = 0; i_5 < textureDefSize; i_5++) { - if (stream.readUnsignedByte() == 1) { - textures[i_5] = new TextureDetails(); - } - } - for (i_5 = 0; i_5 < textureDefSize; i_5++) { - if (textures[i_5] != null) { - textures[i_5].isGroundMesh = stream.readUnsignedByte() == 0; - } - } - for (i_5 = 0; i_5 < textureDefSize; i_5++) { - if (textures[i_5] != null) { - textures[i_5].isHalfSize = stream.readUnsignedByte() == 1; - } - } - for (i_5 = 0; i_5 < textureDefSize; i_5++) { - if (textures[i_5] != null) { - textures[i_5].skipTriangles = stream.readUnsignedByte() == 1; - } - } - for (i_5 = 0; i_5 < textureDefSize; i_5++) { - if (textures[i_5] != null) { - textures[i_5].brightness = stream.readByte(); - } - } - for (i_5 = 0; i_5 < textureDefSize; i_5++) { - if (textures[i_5] != null) { - textures[i_5].shadowFactor = stream.readByte(); - } - } - for (i_5 = 0; i_5 < textureDefSize; i_5++) { - if (textures[i_5] != null) { - textures[i_5].effectId = stream.readByte(); - } - } - for (i_5 = 0; i_5 < textureDefSize; i_5++) { - if (textures[i_5] != null) { - textures[i_5].effectParam1 = stream.readByte(); - } - } - for (i_5 = 0; i_5 < textureDefSize; i_5++) { - if (textures[i_5] != null) { - textures[i_5].color = (short) stream.readUnsignedShort(); - } - } - for (i_5 = 0; i_5 < textureDefSize; i_5++) { - if (textures[i_5] != null) { - textures[i_5].textureSpeedU = stream.readByte(); - } - } - for (i_5 = 0; i_5 < textureDefSize; i_5++) { - if (textures[i_5] != null) { - textures[i_5].textureSpeedV = stream.readByte(); - } - } - for (i_5 = 0; i_5 < textureDefSize; i_5++) { - if (textures[i_5] != null) { - textures[i_5].aBool2087 = stream.readUnsignedByte() == 1; - } - } - for (i_5 = 0; i_5 < textureDefSize; i_5++) { - if (textures[i_5] != null) { - textures[i_5].isBrickTile = stream.readUnsignedByte() == 1; - } - } - for (i_5 = 0; i_5 < textureDefSize; i_5++) { - if (textures[i_5] != null) { - textures[i_5].useMipmaps = stream.readByte(); - } - } - for (i_5 = 0; i_5 < textureDefSize; i_5++) { - if (textures[i_5] != null) { - textures[i_5].repeatS = stream.readUnsignedByte() == 1; - } - } - for (i_5 = 0; i_5 < textureDefSize; i_5++) { - if (textures[i_5] != null) { - textures[i_5].repeatT = stream.readUnsignedByte() == 1; - } - } - for (i_5 = 0; i_5 < textureDefSize; i_5++) { - if (textures[i_5] != null) { - textures[i_5].hdr = stream.readUnsignedByte() == 1; - } - } - for (i_5 = 0; i_5 < textureDefSize; i_5++) { - if (textures[i_5] != null) { - textures[i_5].combineMode = stream.readUnsignedByte(); - } - } - for (i_5 = 0; i_5 < textureDefSize; i_5++) { - if (textures[i_5] != null) { - textures[i_5].effectParam2 = stream.readInt(); - } - } - for (i_5 = 0; i_5 < textureDefSize; i_5++) { - if (textures[i_5] != null) { - textures[i_5].blendType = stream.readUnsignedByte(); - } - } - } - - @Override - public int method84() { - return textureDefSize; - } - - @Override - public TextureDetails getTextureDetails(int i_1) { - textures[i_1].id = i_1; - return textures[i_1]; - } - - @Override - public void method161() { - } - -} diff --git a/src/java/net/runelite/cache/loaders/ImageLoader.java b/src/java/net/runelite/cache/loaders/ImageLoader.java deleted file mode 100644 index 5fe0414..0000000 --- a/src/java/net/runelite/cache/loaders/ImageLoader.java +++ /dev/null @@ -1,13 +0,0 @@ -package net.runelite.cache.loaders; - -import net.runelite.cache.definitions.TextureDetails; - -public interface ImageLoader { - - int method84(); - - TextureDetails getTextureDetails(int var1); - - void method161(); - -} diff --git a/src/java/net/runelite/cache/managers/TextureManagerHD.java b/src/java/net/runelite/cache/managers/TextureManagerHD.java index 1fc0dd3..d05abd2 100644 --- a/src/java/net/runelite/cache/managers/TextureManagerHD.java +++ b/src/java/net/runelite/cache/managers/TextureManagerHD.java @@ -3,7 +3,7 @@ import com.displee.cache.CacheLibrary; import com.displee.cache.index.Index; import com.displee.cache.index.archive.Archive; -import net.runelite.cache.loaders.ImageIndexLoader; +import rshd.ImageIndexLoader; import net.runelite.cache.definitions.TextureDefinition; import net.runelite.cache.definitions.TextureDetails; import net.runelite.cache.providers.TextureProvider; diff --git a/src/java/rshd/Class308.java b/src/java/rshd/Class308.java new file mode 100644 index 0000000..a5f40b5 --- /dev/null +++ b/src/java/rshd/Class308.java @@ -0,0 +1,50 @@ +package rshd; + +import osrs.Node; + +public class Class308 { + + public boolean aBool3619; + int[][][] anIntArrayArrayArray3614; + LinkedNodeList aClass473_3612 = new LinkedNodeList(); + int anInt3617; + int anInt3616 = -1; + int anInt3611; + Node[] aNode_Sub16Array3615; + int anInt3613; + + Class308(int i_1, int i_2, int i_3) { + anInt3611 = i_2; + anInt3613 = i_1; + anIntArrayArrayArray3614 = new int[anInt3613][3][i_3]; + } + + void clear() { + for (int i_2 = 0; i_2 < anInt3613; i_2++) { + anIntArrayArrayArray3614[i_2][0] = null; + anIntArrayArrayArray3614[i_2][1] = null; + anIntArrayArrayArray3614[i_2][2] = null; + anIntArrayArrayArray3614[i_2] = null; + } + anIntArrayArrayArray3614 = null; + aClass473_3612.clear(); + aClass473_3612 = null; + } + + public int[][] method5463(int i_1) { + if (anInt3611 == anInt3613) { + aBool3619 = true; + return anIntArrayArrayArray3614[i_1]; + } + if (anInt3613 != 1) { + Node class282_sub16_3 = aNode_Sub16Array3615[i_1]; + aClass473_3612.insertFront(class282_sub16_3); + return anIntArrayArrayArray3614[(int) class282_sub16_3.key]; + } else { + aBool3619 = anInt3616 != i_1; + anInt3616 = i_1; + return anIntArrayArrayArray3614[0]; + } + } + +} diff --git a/src/java/rshd/Class316.java b/src/java/rshd/Class316.java new file mode 100644 index 0000000..4a1815e --- /dev/null +++ b/src/java/rshd/Class316.java @@ -0,0 +1,33 @@ +package rshd; + +import osrs.NodeHashTable; + +public class Class316 { + + public static int[] anIntArray3677; + public static int[] anIntArray3675; + public static int[] anIntArray3672; + public static int anInt3669; + public static int anInt3670; + public static int anInt3678; + public static int[] anIntArray3668; + public static int anInt3673; + public static int anInt3671; + static NodeHashTable aClass223_3679 = new NodeHashTable(16); + + public static void method5586() { + if (anIntArray3677 == null || anIntArray3675 == null) { + anIntArray3677 = new int[256]; + anIntArray3675 = new int[256]; + for (int i_1 = 0; i_1 < 256; i_1++) { + double d_2 = 6.283185307179586D * (i_1 / 255.0D); + anIntArray3677[i_1] = (int) (Math.sin(d_2) * 4096.0D); + anIntArray3675[i_1] = (int) (Math.cos(d_2) * 4096.0D); + } + } + } + + Class316() throws Throwable { + throw new Error(); + } +} diff --git a/src/java/rshd/Class320.java b/src/java/rshd/Class320.java new file mode 100644 index 0000000..c9b4fda --- /dev/null +++ b/src/java/rshd/Class320.java @@ -0,0 +1,26 @@ +package rshd; + +public class Class320 { + + public static int[] VARC_INT; + public boolean aBool3722; + int[][] anIntArrayArray3717; + int anInt3714; + int anInt3718 = -1; + int anInt3715; + + int anInt3716; + + Class320(int i_1, int i_2, int i_3) { + anInt3715 = i_2; + anInt3716 = i_1; + anIntArrayArray3717 = new int[anInt3716][i_3]; + } + + void clear() { + for (int i_2 = 0; i_2 < anInt3716; i_2++) + anIntArrayArray3717[i_2] = null; + anIntArrayArray3717 = null; + } + +} diff --git a/src/java/rshd/Class503.java b/src/java/rshd/Class503.java new file mode 100644 index 0000000..61e4161 --- /dev/null +++ b/src/java/rshd/Class503.java @@ -0,0 +1,242 @@ +package rshd; + +public class Class503 { + + public static void method8351(long[] longs_0, int i_1, long[] longs_2, int i_3, int i_4) { + if (longs_2 == longs_0) { + if (i_3 == i_1) + return; + + if (i_3 > i_1 && i_3 < i_4 + i_1) { + --i_4; + i_1 += i_4; + i_3 += i_4; + i_4 = i_1 - i_4; + + for (i_4 += 3; i_1 >= i_4; longs_2[i_3--] = longs_0[i_1--]) { + longs_2[i_3--] = longs_0[i_1--]; + longs_2[i_3--] = longs_0[i_1--]; + longs_2[i_3--] = longs_0[i_1--]; + } + + for (i_4 -= 3; i_1 >= i_4; longs_2[i_3--] = longs_0[i_1--]) { + } + + return; + } + } + + i_4 += i_1; + + for (i_4 -= 3; i_1 < i_4; longs_2[i_3++] = longs_0[i_1++]) { + longs_2[i_3++] = longs_0[i_1++]; + longs_2[i_3++] = longs_0[i_1++]; + longs_2[i_3++] = longs_0[i_1++]; + } + + for (i_4 += 3; i_1 < i_4; longs_2[i_3++] = longs_0[i_1++]) { + } + + } + + public static void method8352(byte[] bytes_0, int i_1, byte[] bytes_2, int i_3, int i_4) { + if (bytes_2 == bytes_0) { + if (i_3 == i_1) + return; + + if (i_3 > i_1 && i_3 < i_4 + i_1) { + --i_4; + i_1 += i_4; + i_3 += i_4; + i_4 = i_1 - i_4; + + for (i_4 += 7; i_1 >= i_4; bytes_2[i_3--] = bytes_0[i_1--]) { + bytes_2[i_3--] = bytes_0[i_1--]; + bytes_2[i_3--] = bytes_0[i_1--]; + bytes_2[i_3--] = bytes_0[i_1--]; + bytes_2[i_3--] = bytes_0[i_1--]; + bytes_2[i_3--] = bytes_0[i_1--]; + bytes_2[i_3--] = bytes_0[i_1--]; + bytes_2[i_3--] = bytes_0[i_1--]; + } + + for (i_4 -= 7; i_1 >= i_4; bytes_2[i_3--] = bytes_0[i_1--]) { + } + + return; + } + } + + i_4 += i_1; + + for (i_4 -= 7; i_1 < i_4; bytes_2[i_3++] = bytes_0[i_1++]) { + bytes_2[i_3++] = bytes_0[i_1++]; + bytes_2[i_3++] = bytes_0[i_1++]; + bytes_2[i_3++] = bytes_0[i_1++]; + bytes_2[i_3++] = bytes_0[i_1++]; + bytes_2[i_3++] = bytes_0[i_1++]; + bytes_2[i_3++] = bytes_0[i_1++]; + bytes_2[i_3++] = bytes_0[i_1++]; + } + + for (i_4 += 7; i_1 < i_4; bytes_2[i_3++] = bytes_0[i_1++]) { + } + + } + + public static void method8356(float[] floats_0, int i_1, float[] floats_2, int i_3, int i_4) { + if (floats_2 == floats_0) { + if (i_3 == i_1) + return; + + if (i_3 > i_1 && i_3 < i_4 + i_1) { + --i_4; + i_1 += i_4; + i_3 += i_4; + i_4 = i_1 - i_4; + + for (i_4 += 7; i_1 >= i_4; floats_2[i_3--] = floats_0[i_1--]) { + floats_2[i_3--] = floats_0[i_1--]; + floats_2[i_3--] = floats_0[i_1--]; + floats_2[i_3--] = floats_0[i_1--]; + floats_2[i_3--] = floats_0[i_1--]; + floats_2[i_3--] = floats_0[i_1--]; + floats_2[i_3--] = floats_0[i_1--]; + floats_2[i_3--] = floats_0[i_1--]; + } + + for (i_4 -= 7; i_1 >= i_4; floats_2[i_3--] = floats_0[i_1--]) { + } + + return; + } + } + + i_4 += i_1; + + for (i_4 -= 7; i_1 < i_4; floats_2[i_3++] = floats_0[i_1++]) { + floats_2[i_3++] = floats_0[i_1++]; + floats_2[i_3++] = floats_0[i_1++]; + floats_2[i_3++] = floats_0[i_1++]; + floats_2[i_3++] = floats_0[i_1++]; + floats_2[i_3++] = floats_0[i_1++]; + floats_2[i_3++] = floats_0[i_1++]; + floats_2[i_3++] = floats_0[i_1++]; + } + + for (i_4 += 7; i_1 < i_4; floats_2[i_3++] = floats_0[i_1++]) { + } + + } + + public static void method8362(int[] ints_0, int i_1, int[] ints_2, int i_3, int i_4) { + if (ints_2 == ints_0) { + if (i_3 == i_1) + return; + + if (i_3 > i_1 && i_3 < i_4 + i_1) { + --i_4; + i_1 += i_4; + i_3 += i_4; + i_4 = i_1 - i_4; + + for (i_4 += 7; i_1 >= i_4; ints_2[i_3--] = ints_0[i_1--]) { + ints_2[i_3--] = ints_0[i_1--]; + ints_2[i_3--] = ints_0[i_1--]; + ints_2[i_3--] = ints_0[i_1--]; + ints_2[i_3--] = ints_0[i_1--]; + ints_2[i_3--] = ints_0[i_1--]; + ints_2[i_3--] = ints_0[i_1--]; + ints_2[i_3--] = ints_0[i_1--]; + } + + for (i_4 -= 7; i_1 >= i_4; ints_2[i_3--] = ints_0[i_1--]) { + } + + return; + } + } + + i_4 += i_1; + + for (i_4 -= 7; i_1 < i_4; ints_2[i_3++] = ints_0[i_1++]) { + ints_2[i_3++] = ints_0[i_1++]; + ints_2[i_3++] = ints_0[i_1++]; + ints_2[i_3++] = ints_0[i_1++]; + ints_2[i_3++] = ints_0[i_1++]; + ints_2[i_3++] = ints_0[i_1++]; + ints_2[i_3++] = ints_0[i_1++]; + ints_2[i_3++] = ints_0[i_1++]; + } + + for (i_4 += 7; i_1 < i_4; ints_2[i_3++] = ints_0[i_1++]) { + } + + } + + public static void method8365(int[] ints_0, int i_1, int i_2, int i_3) { + for (i_2 = i_2 + i_1 - 7; i_1 < i_2; ints_0[i_1++] = i_3) { + ints_0[i_1++] = i_3; + ints_0[i_1++] = i_3; + ints_0[i_1++] = i_3; + ints_0[i_1++] = i_3; + ints_0[i_1++] = i_3; + ints_0[i_1++] = i_3; + ints_0[i_1++] = i_3; + } + + for (i_2 += 7; i_1 < i_2; ints_0[i_1++] = i_3) { + } + + } + + public static void setSize(Object[] arr_0, int i_1, Object[] arr_2, int i_3, int i_4) { + if (arr_2 == arr_0) { + if (i_3 == i_1) + return; + + if (i_3 > i_1 && i_3 < i_4 + i_1) { + --i_4; + i_1 += i_4; + i_3 += i_4; + i_4 = i_1 - i_4; + + for (i_4 += 7; i_1 >= i_4; arr_2[i_3--] = arr_0[i_1--]) { + arr_2[i_3--] = arr_0[i_1--]; + arr_2[i_3--] = arr_0[i_1--]; + arr_2[i_3--] = arr_0[i_1--]; + arr_2[i_3--] = arr_0[i_1--]; + arr_2[i_3--] = arr_0[i_1--]; + arr_2[i_3--] = arr_0[i_1--]; + arr_2[i_3--] = arr_0[i_1--]; + } + + for (i_4 -= 7; i_1 >= i_4; arr_2[i_3--] = arr_0[i_1--]) { + } + + return; + } + } + + i_4 += i_1; + + for (i_4 -= 7; i_1 < i_4; arr_2[i_3++] = arr_0[i_1++]) { + arr_2[i_3++] = arr_0[i_1++]; + arr_2[i_3++] = arr_0[i_1++]; + arr_2[i_3++] = arr_0[i_1++]; + arr_2[i_3++] = arr_0[i_1++]; + arr_2[i_3++] = arr_0[i_1++]; + arr_2[i_3++] = arr_0[i_1++]; + arr_2[i_3++] = arr_0[i_1++]; + } + + for (i_4 += 7; i_1 < i_4; arr_2[i_3++] = arr_0[i_1++]) { + } + + } + + Class503() throws Throwable { + throw new Error(); + } + +} diff --git a/src/java/rshd/ImageIndexLoader.java b/src/java/rshd/ImageIndexLoader.java new file mode 100644 index 0000000..7b3f472 --- /dev/null +++ b/src/java/rshd/ImageIndexLoader.java @@ -0,0 +1,144 @@ +package rshd; + +import com.displee.cache.index.Index; +import net.runelite.cache.definitions.TextureDetails; +import osrs.Buffer; +import osrs.Node; +import osrs.NodeHashTable; + +import java.util.Objects; + +public class ImageIndexLoader implements ImageLoader { + + NodeHashTable aClass223_3754 = new NodeHashTable(256); + + Index textureIndex; + + Index spriteIndex; + + int textureDefSize; + + TextureDetails[] textures; + + public ImageIndexLoader(Index textureDefIndex, Index textureIndex, Index spriteIndex) { + this.textureIndex = textureIndex; + this.spriteIndex = spriteIndex; + Buffer stream = new Buffer(Objects.requireNonNull(Objects.requireNonNull(textureDefIndex.archive(0)).file(0)).getData()); + textureDefSize = stream.readUnsignedShort(); + textures = new TextureDetails[textureDefSize]; + int i_5; + for (i_5 = 0; i_5 < textureDefSize; i_5++) + if (stream.readUnsignedByte() == 1) + textures[i_5] = new TextureDetails(); + for (i_5 = 0; i_5 < textureDefSize; i_5++) + if (textures[i_5] != null) + textures[i_5].isGroundMesh = stream.readUnsignedByte() == 0; + for (i_5 = 0; i_5 < textureDefSize; i_5++) + if (textures[i_5] != null) + textures[i_5].isHalfSize = stream.readUnsignedByte() == 1; + for (i_5 = 0; i_5 < textureDefSize; i_5++) + if (textures[i_5] != null) + textures[i_5].skipTriangles = stream.readUnsignedByte() == 1; + for (i_5 = 0; i_5 < textureDefSize; i_5++) + if (textures[i_5] != null) + textures[i_5].brightness = stream.readByte(); + for (i_5 = 0; i_5 < textureDefSize; i_5++) + if (textures[i_5] != null) + textures[i_5].shadowFactor = stream.readByte(); + for (i_5 = 0; i_5 < textureDefSize; i_5++) + if (textures[i_5] != null) + textures[i_5].effectId = stream.readByte(); + for (i_5 = 0; i_5 < textureDefSize; i_5++) + if (textures[i_5] != null) + textures[i_5].effectParam1 = stream.readByte(); + for (i_5 = 0; i_5 < textureDefSize; i_5++) + if (textures[i_5] != null) + textures[i_5].color = (short) stream.readUnsignedShort(); + for (i_5 = 0; i_5 < textureDefSize; i_5++) + if (textures[i_5] != null) + textures[i_5].textureSpeedU = stream.readByte(); + for (i_5 = 0; i_5 < textureDefSize; i_5++) + if (textures[i_5] != null) + textures[i_5].textureSpeedV = stream.readByte(); + for (i_5 = 0; i_5 < textureDefSize; i_5++) + if (textures[i_5] != null) + textures[i_5].aBool2087 = stream.readUnsignedByte() == 1; + for (i_5 = 0; i_5 < textureDefSize; i_5++) + if (textures[i_5] != null) + textures[i_5].isBrickTile = stream.readUnsignedByte() == 1; + for (i_5 = 0; i_5 < textureDefSize; i_5++) + if (textures[i_5] != null) + textures[i_5].useMipmaps = stream.readByte(); + for (i_5 = 0; i_5 < textureDefSize; i_5++) + if (textures[i_5] != null) + textures[i_5].repeatS = stream.readUnsignedByte() == 1; + for (i_5 = 0; i_5 < textureDefSize; i_5++) + if (textures[i_5] != null) + textures[i_5].repeatT = stream.readUnsignedByte() == 1; + for (i_5 = 0; i_5 < textureDefSize; i_5++) + if (textures[i_5] != null) + textures[i_5].hdr = stream.readUnsignedByte() == 1; + for (i_5 = 0; i_5 < textureDefSize; i_5++) + if (textures[i_5] != null) + textures[i_5].combineMode = stream.readUnsignedByte(); + for (i_5 = 0; i_5 < textureDefSize; i_5++) + if (textures[i_5] != null) + textures[i_5].effectParam2 = stream.readInt(); + for (i_5 = 0; i_5 < textureDefSize; i_5++) + if (textures[i_5] != null) + textures[i_5].blendType = stream.readUnsignedByte(); + } + + MaterialDefinitions getMaterialDefinitions(int textureId) { + Node cacheablenode_3 = aClass223_3754.get(textureId); + if (cacheablenode_3 != null) { + return (MaterialDefinitions) cacheablenode_3; + } + byte[] bytes_4 = Objects.requireNonNull(Objects.requireNonNull(textureIndex.archive(textureId)).file(0)).getData(); + if (bytes_4 == null) + return null; + else { + MaterialDefinitions texturedefinition_5 = new MaterialDefinitions(new Buffer(bytes_4)); + aClass223_3754.put(texturedefinition_5, textureId); + return texturedefinition_5; + } + } + + @Override + public TextureDetails getTextureDetails(int i_1) { + return textures[i_1]; + } + + @Override + public boolean loadTexture(int var1) { + return true; + } + + @Override + public void method161() { + } + + @Override + public int method84() { + return textureDefSize; + } + + @Override + public float[] renderMaterialPixelsF(int i_1, int i_3, int i_4) { + float[] floats_7 = getMaterialDefinitions(i_1).renderFloatPixels(spriteIndex, this, i_3, i_4, textures[i_1].isBrickTile); + return floats_7; + } + + @Override + public int[] renderMaterialPixelsI(int textureId, int width, int height) { + int[] ints_7 = getMaterialDefinitions(textureId).renderIntPixels(spriteIndex, this, (float) 0.7, width, height, textures[textureId].isBrickTile); + return ints_7; + } + + @Override + public int[] renderTexturePixels(int i_1, float f_2, int i_3, int i_4, boolean bool_5) { + int[] pixels = getMaterialDefinitions(i_1).method14718(spriteIndex, this, f_2, i_3, i_4, bool_5, textures[i_1].isBrickTile); + return pixels; + } + +} \ No newline at end of file diff --git a/src/java/rshd/ImageLoader.java b/src/java/rshd/ImageLoader.java new file mode 100644 index 0000000..2d9add8 --- /dev/null +++ b/src/java/rshd/ImageLoader.java @@ -0,0 +1,21 @@ +package rshd; + +import net.runelite.cache.definitions.TextureDetails; + +public interface ImageLoader { + + TextureDetails getTextureDetails(int var1); + + boolean loadTexture(int var1); + + void method161(); + + int method84(); + + float[] renderMaterialPixelsF(int var1, int var3, int var4); + + int[] renderMaterialPixelsI(int var1, int var3, int var4); + + int[] renderTexturePixels(int var1, float var2, int var3, int var4, boolean var5); + +} \ No newline at end of file diff --git a/src/java/rshd/LinkedNodeList.java b/src/java/rshd/LinkedNodeList.java new file mode 100644 index 0000000..d6ba3ce --- /dev/null +++ b/src/java/rshd/LinkedNodeList.java @@ -0,0 +1,149 @@ +package rshd; + +import osrs.Node; + +public class LinkedNodeList { + + static int anInt5606; + + public static byte[] method7885(CharSequence charsequence_0) { + int i_2 = charsequence_0.length(); + byte[] bytes_3 = new byte[i_2]; + for (int i_4 = 0; i_4 < i_2; i_4++) { + char var_5 = charsequence_0.charAt(i_4); + if (var_5 > 0 && var_5 < 128 || var_5 >= 160 && var_5 <= 255) + bytes_3[i_4] = (byte) var_5; + else if (var_5 == 8364) + bytes_3[i_4] = -128; + else if (var_5 == 8218) + bytes_3[i_4] = -126; + else if (var_5 == 402) + bytes_3[i_4] = -125; + else if (var_5 == 8222) + bytes_3[i_4] = -124; + else if (var_5 == 8230) + bytes_3[i_4] = -123; + else if (var_5 == 8224) + bytes_3[i_4] = -122; + else if (var_5 == 8225) + bytes_3[i_4] = -121; + else if (var_5 == 710) + bytes_3[i_4] = -120; + else if (var_5 == 8240) + bytes_3[i_4] = -119; + else if (var_5 == 352) + bytes_3[i_4] = -118; + else if (var_5 == 8249) + bytes_3[i_4] = -117; + else if (var_5 == 338) + bytes_3[i_4] = -116; + else if (var_5 == 381) + bytes_3[i_4] = -114; + else if (var_5 == 8216) + bytes_3[i_4] = -111; + else if (var_5 == 8217) + bytes_3[i_4] = -110; + else if (var_5 == 8220) + bytes_3[i_4] = -109; + else if (var_5 == 8221) + bytes_3[i_4] = -108; + else if (var_5 == 8226) + bytes_3[i_4] = -107; + else if (var_5 == 8211) + bytes_3[i_4] = -106; + else if (var_5 == 8212) + bytes_3[i_4] = -105; + else if (var_5 == 732) + bytes_3[i_4] = -104; + else if (var_5 == 8482) + bytes_3[i_4] = -103; + else if (var_5 == 353) + bytes_3[i_4] = -102; + else if (var_5 == 8250) + bytes_3[i_4] = -101; + else if (var_5 == 339) + bytes_3[i_4] = -100; + else if (var_5 == 382) + bytes_3[i_4] = -98; + else if (var_5 == 376) + bytes_3[i_4] = -97; + else + bytes_3[i_4] = 63; + } + return bytes_3; + } + + public Node head = new Node(); + + Node current; + + public LinkedNodeList() { + head.next = head; + head.previous = head; + } + + public void clear() { + while (true) { + Node node_1 = head.next; + if (node_1 == head) { + current = null; + return; + } + } + } + + public Node getBack() { + Node node_1 = head.next; + if (node_1 == head) { + current = null; + return null; + } + current = node_1.next; + return node_1; + } + + public Node getNext() { + Node node_1 = head.previous; + if (node_1 == head) { + current = null; + return null; + } + current = node_1.previous; + return node_1; + } + + public Node getPrevious() { + Node node_1 = current; + if (node_1 == head) { + current = null; + return null; + } + current = node_1.next; + return node_1; + } + + public void insertBack(Node node_1) { + node_1.previous = head.previous; + node_1.next = head; + node_1.previous.next = node_1; + node_1.next.previous = node_1; + } + + public void insertFront(Node node_1) { + node_1.previous = head; + node_1.next = head.next; + node_1.previous.next = node_1; + node_1.next.previous = node_1; + } + + public boolean method7861() { + return head.next == head; + } + + public Node popTail() { + Node node_1 = head.next; + if (node_1 == head) + return null; + return node_1; + } +} diff --git a/src/java/rshd/MaterialDefinitions.java b/src/java/rshd/MaterialDefinitions.java new file mode 100644 index 0000000..234f921 --- /dev/null +++ b/src/java/rshd/MaterialDefinitions.java @@ -0,0 +1,254 @@ +package rshd; + +import com.displee.cache.index.Index; +import osrs.Buffer; +import osrs.Node; + +import java.io.FileOutputStream; + +public class MaterialDefinitions extends Node { + + static FileOutputStream aFileOutputStream9481; + static double aDouble9479 = -1.0; + static int[] anIntArray9474 = new int[256]; + int[] spritePropertyIds; + int[] texturePropertyIds; + MaterialProperty opaqueProperty; + MaterialProperty translucentProperty; + MaterialProperty combinedProperty; + + private Index CURR_SPRITE_INDEX; + private ImageLoader IMAGE_LOADER; + + MaterialDefinitions(Buffer buffer) { + int size = buffer.readUnsignedByte(); + int spriteProperties = 0; + int textureProperties = 0; + spritePropertyIds = new int[spriteProperties]; + texturePropertyIds = new int[textureProperties]; + } + + int[] method14718(Index index_1, ImageLoader interface22_2, double d_3, int i_5, int i_6, boolean bool_7, boolean bool_8) { + this.CURR_SPRITE_INDEX = index_1; + this.IMAGE_LOADER = interface22_2; + + int[] ints_24 = new int[i_5 * i_6]; + int i_11; + int i_12; + byte b_13; + if (bool_7) { + i_11 = i_5 - 1; + i_12 = -1; + b_13 = -1; + } else { + i_11 = 0; + i_12 = i_5; + b_13 = 1; + } + + int i_14 = 0; + + int i_15; + for (i_15 = 0; i_15 < i_6; i_15++) { + int[] ints_16; + int[] ints_17; + int[] ints_18; + if (opaqueProperty.noPalette) { + int[] ints_19 = opaqueProperty.method12319(i_15); + ints_16 = ints_19; + ints_17 = ints_19; + ints_18 = ints_19; + } else { + int[][] ints_26 = opaqueProperty.getPixels(i_15); + ints_16 = ints_26[0]; + ints_17 = ints_26[1]; + ints_18 = ints_26[2]; + } + + if (bool_8) + i_14 = i_15; + + for (int i_25 = i_11; i_25 != i_12; i_25 += b_13) { + int i_20 = ints_16[i_25] >> 4; + if (i_20 > 255) + i_20 = 255; + + if (i_20 < 0) + i_20 = 0; + + int i_21 = ints_17[i_25] >> 4; + if (i_21 > 255) + i_21 = 255; + + if (i_21 < 0) + i_21 = 0; + + int i_22 = ints_18[i_25] >> 4; + if (i_22 > 255) + i_22 = 255; + + if (i_22 < 0) + i_22 = 0; + + i_20 = anIntArray9474[i_20]; + i_21 = anIntArray9474[i_21]; + i_22 = anIntArray9474[i_22]; + int i_23 = i_22 + (i_21 << 8) + (i_20 << 16); + if (i_23 != 0) + i_23 |= -16777216; + + ints_24[i_14++] = i_23; + if (bool_8) + i_14 += i_5 - 1; + } + } + + return ints_24; + } + + float[] renderFloatPixels(Index index_1, ImageLoader interface22_2, int i_3, int i_4, boolean blend) { + this.CURR_SPRITE_INDEX = index_1; + this.IMAGE_LOADER = interface22_2; + + float[] floats_18 = new float[i_3 * i_4 * 4]; + int i_8 = 0; + + int i_9; + for (i_9 = 0; i_9 < i_4; i_9++) { + int[] ints_10; + int[] ints_11; + int[] ints_12; + int[] ints_13; + if (opaqueProperty.noPalette) { + ints_13 = opaqueProperty.method12319(i_9); + ints_10 = ints_13; + ints_11 = ints_13; + ints_12 = ints_13; + } else { + int[][] ints_19 = opaqueProperty.getPixels(i_9); + ints_10 = ints_19[0]; + ints_11 = ints_19[1]; + ints_12 = ints_19[2]; + } + + if (translucentProperty.noPalette) + ints_13 = translucentProperty.method12319(i_9); + else + ints_13 = translucentProperty.getPixels(i_9)[0]; + + int[] ints_14; + if (combinedProperty.noPalette) + ints_14 = combinedProperty.method12319(i_9); + else + ints_14 = combinedProperty.getPixels(i_9)[0]; + + if (blend) + i_8 = i_9 << 2; + + for (int i_15 = i_3 - 1; i_15 >= 0; --i_15) { + float f_16 = ints_13[i_15] / 4096.0F; + float f_17 = (1.0F + ints_14[i_15] * 31.0F / 4096.0F) / 4096.0F; + if (f_16 < 0.0F) + f_16 = 0.0F; + else if (f_16 > 1.0F) + f_16 = 1.0F; + + floats_18[i_8++] = ints_10[i_15] * f_17; + floats_18[i_8++] = f_17 * ints_11[i_15]; + floats_18[i_8++] = ints_12[i_15] * f_17; + floats_18[i_8++] = f_16; + if (blend) + i_8 += (i_3 << 2) - 4; + } + } + + return floats_18; + } + + int[] renderIntPixels(Index index_1, ImageLoader interface22_2, double d_3, int width, int height, boolean bool_7) { + opaqueProperty = new MaterialProperty(); + opaqueProperty.noPalette = true; + translucentProperty = new MaterialProperty(); + translucentProperty.noPalette = true; + this.CURR_SPRITE_INDEX = index_1; + this.IMAGE_LOADER = interface22_2; + + int[] ints_21 = new int[width * height]; + int i_10 = 0; + + int i_11; + for (i_11 = 0; i_11 < height; i_11++) { + int[] ints_12; + int[] ints_13; + int[] ints_14; + int[] ints_15; + if (opaqueProperty.noPalette) { + ints_15 = opaqueProperty.method12319(i_11); + ints_12 = ints_15; + ints_13 = ints_15; + ints_14 = ints_15; + } else { + int[][] ints_22 = opaqueProperty.getPixels(i_11); + ints_12 = ints_22[0]; + ints_13 = ints_22[1]; + ints_14 = ints_22[2]; + } + + if (translucentProperty.noPalette) + ints_15 = translucentProperty.method12319(i_11); + else + ints_15 = translucentProperty.getPixels(i_11)[0]; + + if (bool_7) + i_10 = i_11; + + /* + for (int i_16 = width - 1; i_16 >= 0; --i_16) { + int i_17 = ints_12[i_16] >> 4; + if (i_17 > 255) + i_17 = 255; + + if (i_17 < 0) + i_17 = 0; + + int i_18 = ints_13[i_16] >> 4; + if (i_18 > 255) + i_18 = 255; + + if (i_18 < 0) + i_18 = 0; + + int i_19 = ints_14[i_16] >> 4; + if (i_19 > 255) + i_19 = 255; + + if (i_19 < 0) + i_19 = 0; + + i_17 = anIntArray9474[i_17]; + i_18 = anIntArray9474[i_18]; + i_19 = anIntArray9474[i_19]; + int i_20; + if (i_17 == 0 && i_18 == 0 && i_19 == 0) + i_20 = 0; + else { + i_20 = ints_15[i_16] >> 4; + if (i_20 > 255) + i_20 = 255; + + if (i_20 < 0) + i_20 = 0; + } + + ints_21[i_10++] = i_19 + (i_18 << 8) + (i_20 << 24) + (i_17 << 16); + if (bool_7) + i_10 += width - 1; + } + */ + } + + + return ints_21; + } + +} \ No newline at end of file diff --git a/src/java/rshd/MaterialPropSprite.java b/src/java/rshd/MaterialPropSprite.java new file mode 100644 index 0000000..c45d22e --- /dev/null +++ b/src/java/rshd/MaterialPropSprite.java @@ -0,0 +1,81 @@ +package rshd; + +import com.application.GUI; +import osrs.Buffer; + +public class MaterialPropSprite extends MaterialProperty { + + public static int SPRITE_ARCHIVE_ID = -1; + int[] pixels; + int width; + int height; + int spriteId = -1; + + public MaterialPropSprite() { + super(0, false); + } + + @Override + void decode(int opcode, Buffer buffer) { + if (opcode == 0) + spriteId = buffer.readUnsignedShort(); + + } + + @Override + int[][] getPixels(int i_1) { + int[][] ints_3 = aClass308_7670.method5463(i_1); + if (aClass308_7670.aBool3619 && method15398()) { + int[] ints_4 = ints_3[0]; + int[] ints_5 = ints_3[1]; + int[] ints_6 = ints_3[2]; + int i_7 = (height != Class316.anInt3671 ? height * i_1 / Class316.anInt3671 : i_1) * width; + int i_8; + int i_9; + if (width == Class316.anInt3670) + for (i_8 = 0; i_8 < Class316.anInt3670; i_8++) { + i_9 = pixels[i_7++]; + ints_6[i_8] = (i_9 & 0xff) << 4; + ints_5[i_8] = (i_9 & 0xff00) >> 4; + ints_4[i_8] = (i_9 & 0xff0000) >> 12; + } + else + for (i_8 = 0; i_8 < Class316.anInt3670; i_8++) { + i_9 = i_8 * width / Class316.anInt3670; + int i_10 = pixels[i_7 + i_9]; + ints_6[i_8] = (i_10 & 0xff) << 4; + ints_5[i_8] = (i_10 & 0xff00) >> 4; + ints_4[i_8] = (i_10 & 0xff0000) >> 12; + } + } + + return ints_3; + } + + @Override + int getSpriteId() { + return spriteId; + } + + boolean method15398() { + if (pixels != null) + return true; + if (spriteId >= 0) { + SpriteDefinitions sprite = SpriteDefinitions.getSprite(GUI.cacheLibrary.index(8), SPRITE_ARCHIVE_ID, spriteId); + assert sprite != null; + sprite.load(); + pixels = sprite.getPixels(); + width = sprite.width; + height = sprite.height; + return true; + } else + return false; + } + + @Override + void reset() { + super.reset(); + pixels = null; + } + +} diff --git a/src/java/rshd/MaterialProperty.java b/src/java/rshd/MaterialProperty.java new file mode 100644 index 0000000..1474fa3 --- /dev/null +++ b/src/java/rshd/MaterialProperty.java @@ -0,0 +1,79 @@ +package rshd; + +import osrs.Buffer; +import osrs.Node; + +public class MaterialProperty extends Node { + + protected Class308 aClass308_7670; + protected Class320 aClass320_7667; + + MaterialProperty() { + + } + + static MaterialProperty decode(Buffer buffer) { + buffer.readUnsignedByte(); + int opIndex = buffer.readUnsignedByte(); + int numReads = buffer.readUnsignedByte(); + for (int i = 0; i < numReads; i++) { + int opcode = buffer.readUnsignedByte(); + } + return null; + } + static MaterialProperty getById(int i_0) { + return null; + } + protected boolean noPalette; + + int anInt7668; + + MaterialProperty[] params; + + MaterialProperty(int numParams, boolean bool_2) { + noPalette = bool_2; + params = new MaterialProperty[numParams]; + } + + void decode(int i_1, Buffer rsbytebuffer_2) { + } + + int[][] getPixels(int i_1) { + return null; + } + + int getSpriteId() { + return -1; + } + + int getTextureId() { + return -1; + } + + void method12315(int i_1, int i_2) { + int i_4 = anInt7668 == 255 ? i_2 : anInt7668; + } + + int[] method12317(int i_1, int i_2) { + return !params[i_1].noPalette ? params[i_1].getPixels(i_2)[0] : params[i_1].method12319(i_2); + } + + int[] method12319(int i_1) { + return null; + } + + void method12321() { + } + + int[][] method12333(int i_1, int i_2) { + if (params[i_1].noPalette) { + int[] ints_4 = params[i_1].method12319(i_2); + int[][] ints_5 = {ints_4, ints_4, ints_4}; + return ints_5; + } + return params[i_1].getPixels(i_2); + } + + void reset() { + } +} \ No newline at end of file diff --git a/src/java/rshd/SpriteDefinitions.java b/src/java/rshd/SpriteDefinitions.java new file mode 100644 index 0000000..bcd8d07 --- /dev/null +++ b/src/java/rshd/SpriteDefinitions.java @@ -0,0 +1,552 @@ +package rshd; + +import com.displee.cache.index.Index; +import osrs.Buffer; + +import java.util.Objects; + +public class SpriteDefinitions { + + public static SpriteDefinitions[] decode(byte[] data) { + Buffer stream = new Buffer(data); + stream.offset = data.length - 2; + int count = stream.readUnsignedShort(); + SpriteDefinitions[] sprites = new SpriteDefinitions[count]; + + for (int i = 0; i < count; i++) + sprites[i] = new SpriteDefinitions(); + + stream.offset = data.length - 7 - count * 8; + int biggestWidth = stream.readUnsignedShort(); + int biggestHeight = stream.readUnsignedShort(); + int palleteLength = (stream.readUnsignedByte() & 0xff) + 1; + + for (int i = 0; i < count; i++) + sprites[i].minX = stream.readUnsignedShort(); + + for (int i = 0; i < count; i++) + sprites[i].minY = stream.readUnsignedShort(); + + for (int i = 0; i < count; i++) + sprites[i].width = stream.readUnsignedShort(); + + for (int i = 0; i < count; i++) + sprites[i].height = stream.readUnsignedShort(); + + for (int i = 0; i < count; i++) { + SpriteDefinitions sprite = sprites[i]; + sprite.anInt958 = biggestWidth - sprite.width - sprite.minX; + sprite.anInt953 = biggestHeight - sprite.height - sprite.minY; + } + + stream.offset = data.length - 7 - count * 8 - (palleteLength - 1) * 3; + int[] pallete = new int[palleteLength]; + + for (int i = 1; i < palleteLength; i++) { + pallete[i] = stream.read24BitUnsignedInteger(); + if (pallete[i] == 0) + pallete[i] = 1; + } + + for (int i = 0; i < count; i++) + sprites[i].pallete = pallete; + + stream.offset = 0; + + for (int i = 0; i < count; i++) { + SpriteDefinitions sprite = sprites[i]; + int numPixels = sprite.width * sprite.height; + sprite.pixels = new byte[numPixels]; + int flags = stream.readUnsignedByte(); + if ((flags & 0x2) == 0) { + if ((flags & 0x1) == 0) + for (int j = 0; j < numPixels; j++) + sprite.pixels[j] = stream.readByte(); + else + for (int j = 0; j < sprite.width; j++) + for (int k = 0; k < sprite.height; k++) + sprite.pixels[j + k * sprite.width] = stream.readByte(); + } else { + boolean usesAlpha = false; + sprite.alpha = new byte[numPixels]; + if ((flags & 0x1) == 0) { + for (int j = 0; j < numPixels; j++) + sprite.pixels[j] = stream.readByte(); + + for (int j = 0; j < numPixels; j++) { + byte alpha = sprite.alpha[j] = stream.readByte(); + usesAlpha |= alpha != -1; + } + } else { + for (int j = 0; j < sprite.width; j++) + for (int k = 0; k < sprite.height; k++) + sprite.pixels[j + k * sprite.width] = stream.readByte(); + + for (int j = 0; j < sprite.width; j++) + for (int k = 0; k < sprite.height; k++) { + byte alpha = sprite.alpha[j + k * sprite.width] = stream.readByte(); + usesAlpha |= alpha != -1; + } + } + + if (!usesAlpha) + sprite.alpha = null; + } + } + + return sprites; + } + public static SpriteDefinitions getSprite(Index index, int archiveId, int fileId) { + byte[] data = Objects.requireNonNull(Objects.requireNonNull(index.archive(archiveId)).file(fileId)).getData(); + return data == null ? null : decode(data)[0]; + } + public int minX; + public int minY; + public int width; + public int height; + + public int anInt958; + + public int anInt953; + + public int[] pallete; + + public byte[] pixels; + + public byte[] alpha; + + public int getMaxHeight() { + return height + minY + anInt953; + } + + public int getMaxWidth() { + return width + minX + anInt958; + } + + public int[] getPixels() { + int i_1 = getMaxWidth(); + int[] ints_2 = new int[i_1 * getMaxHeight()]; + int i_3; + int i_4; + int i_5; + int i_6; + if (alpha != null) + for (i_3 = 0; i_3 < height; i_3++) { + i_4 = i_3 * width; + i_5 = i_1 * (i_3 + minY) + minX; + + for (i_6 = 0; i_6 < width; i_6++) { + ints_2[i_5++] = alpha[i_4] << 24 | pallete[pixels[i_4] & 0xff]; + ++i_4; + } + } + else + for (i_3 = 0; i_3 < height; i_3++) { + i_4 = i_3 * width; + i_5 = i_1 * (i_3 + minY) + minX; + + for (i_6 = 0; i_6 < width; i_6++) { + int i_7 = pallete[pixels[i_4++] & 0xff]; + if (i_7 != 0) + ints_2[i_5++] = -16777216 | i_7; + else + ints_2[i_5++] = 0; + } + } + + return ints_2; + } + + public void load() { + int i_1 = getMaxWidth(); + int i_2 = getMaxHeight(); + if (i_1 != width || i_2 != height) { + byte[] bytes_3 = new byte[i_1 * i_2]; + int i_5; + int i_6; + int i_7; + if (alpha != null) { + byte[] bytes_4 = new byte[i_1 * i_2]; + i_5 = 0; + + while (true) { + if (i_5 >= height) { + alpha = bytes_4; + break; + } + + i_6 = i_5 * width; + i_7 = i_1 * (i_5 + minY) + minX; + + for (int i_8 = 0; i_8 < width; i_8++) { + bytes_3[i_7] = pixels[i_6]; + bytes_4[i_7++] = alpha[i_6++]; + } + + ++i_5; + } + } else + for (int i_9 = 0; i_9 < height; i_9++) { + i_5 = i_9 * width; + i_6 = i_1 * (i_9 + minY) + minX; + + for (i_7 = 0; i_7 < width; i_7++) + bytes_3[i_6++] = pixels[i_5++]; + } + + anInt953 = 0; + minY = 0; + anInt958 = 0; + minX = 0; + width = i_1; + height = i_2; + pixels = bytes_3; + } + + } + + public void method1524(int i_1) { + int i_2 = -1; + int i_3; + int i_4; + int i_5; + if (pallete.length < 255) { + for (i_3 = 0; i_3 < pallete.length; i_3++) + if (pallete[i_3] == i_1) { + i_2 = i_3; + break; + } + + if (i_2 == -1) { + i_2 = pallete.length; + int[] ints_16 = new int[pallete.length + 1]; + Class503.method8362(pallete, 0, ints_16, 0, pallete.length); + pallete = ints_16; + ints_16[i_2] = i_1; + } + } else { + i_3 = Integer.MAX_VALUE; + i_4 = i_1 >> 16 & 0xff; + i_5 = i_1 >> 8 & 0xff; + int i_6 = i_1 & 0xff; + + for (int i_7 = 0; i_7 < pallete.length; i_7++) { + int i_8 = pallete[i_7]; + int i_9 = i_8 >> 16 & 0xff; + int i_10 = i_8 >> 8 & 0xff; + int i_11 = i_8 & 0xff; + int i_12 = i_4 - i_9; + if (i_12 < 0) + i_12 = -i_12; + + int i_13 = i_5 - i_10; + if (i_13 < 0) + i_13 = -i_13; + + int i_14 = i_6 - i_11; + if (i_14 < 0) + i_14 = -i_14; + + int i_15 = i_12 + i_13 + i_14; + if (i_15 < i_3) { + i_3 = i_15; + i_2 = i_7; + } + } + } + + for (i_3 = height - 1; i_3 > 0; --i_3) { + i_4 = i_3 * width; + + for (i_5 = width - 1; i_5 > 0; --i_5) + if (pallete[pixels[i_5 + i_4] & 0xff] == 0 && pallete[pixels[i_5 + i_4 - 1 - width] & 0xff] != 0) + pixels[i_5 + i_4] = (byte) i_2; + } + + } + + public void method1525() { + byte[] bytes_1 = pixels; + int i_2; + int i_3; + int i_4; + if (alpha == null) + for (i_2 = height - 1; i_2 >= 0; --i_2) { + i_3 = i_2 * width; + + for (i_4 = (i_2 + 1) * width; i_3 < i_4; i_3++) { + --i_4; + byte b_5 = bytes_1[i_3]; + bytes_1[i_3] = bytes_1[i_4]; + bytes_1[i_4] = b_5; + } + } + else { + byte[] bytes_7 = alpha; + + for (i_3 = height - 1; i_3 >= 0; --i_3) { + i_4 = i_3 * width; + + for (int i_8 = (i_3 + 1) * width; i_4 < i_8; i_4++) { + --i_8; + byte b_6 = bytes_1[i_4]; + bytes_1[i_4] = bytes_1[i_8]; + bytes_1[i_8] = b_6; + b_6 = bytes_7[i_4]; + bytes_7[i_4] = bytes_7[i_8]; + bytes_7[i_8] = b_6; + } + } + } + + i_2 = minX; + minX = anInt958; + anInt958 = i_2; + } + + public void method1526() { + byte[] bytes_1 = pixels; + int i_2; + int i_3; + int i_4; + int i_5; + if (alpha == null) + for (i_2 = (height >> 1) - 1; i_2 >= 0; --i_2) { + i_3 = i_2 * width; + i_4 = (height - i_2 - 1) * width; + + for (i_5 = -width; i_5 < 0; i_5++) { + byte b_6 = bytes_1[i_3]; + bytes_1[i_3] = bytes_1[i_4]; + bytes_1[i_4] = b_6; + ++i_3; + ++i_4; + } + } + else { + byte[] bytes_8 = alpha; + + for (i_3 = (height >> 1) - 1; i_3 >= 0; --i_3) { + i_4 = i_3 * width; + i_5 = (height - i_3 - 1) * width; + + for (int i_9 = -width; i_9 < 0; i_9++) { + byte b_7 = bytes_1[i_4]; + bytes_1[i_4] = bytes_1[i_5]; + bytes_1[i_5] = b_7; + b_7 = bytes_8[i_4]; + bytes_8[i_4] = bytes_8[i_5]; + bytes_8[i_5] = b_7; + ++i_4; + ++i_5; + } + } + } + + i_2 = minY; + minY = anInt953; + anInt953 = i_2; + } + + public void method1527() { + byte[] bytes_1 = new byte[width * height]; + int i_2 = 0; + int i_3; + int i_4; + if (alpha == null) { + for (i_3 = 0; i_3 < width; i_3++) + for (i_4 = height - 1; i_4 >= 0; --i_4) + bytes_1[i_2++] = pixels[i_3 + i_4 * width]; + + pixels = bytes_1; + } else { + byte[] bytes_6 = new byte[width * height]; + + for (i_4 = 0; i_4 < width; i_4++) + for (int i_5 = height - 1; i_5 >= 0; --i_5) { + bytes_1[i_2] = pixels[i_4 + i_5 * width]; + bytes_6[i_2++] = alpha[i_4 + i_5 * width]; + } + + pixels = bytes_1; + alpha = bytes_6; + } + + i_3 = minY; + minY = minX; + minX = anInt953; + anInt953 = anInt958; + anInt958 = minY; + i_3 = height; + height = width; + width = i_3; + } + + public void method1529(int i_1, int i_2, int i_3) { + for (int i_4 = 1; i_4 < pallete.length; i_4++) + if (pallete[i_4] != 1 && pallete[i_4] != 16711935) { + int i_5 = pallete[i_4] >> 16 & 0xff; + i_5 += i_1; + if (i_5 < 0) + i_5 = 0; + else if (i_5 > 255) + i_5 = 255; + + int i_6 = pallete[i_4] >> 8 & 0xff; + i_6 += i_2; + if (i_6 < 0) + i_6 = 0; + else if (i_6 > 255) + i_6 = 255; + + int i_7 = pallete[i_4] & 0xff; + i_7 += i_3; + if (i_7 < 0) + i_7 = 0; + else if (i_7 > 255) + i_7 = 255; + + pallete[i_4] = i_5 << 16 | i_6 << 8 | i_7; + } + + } + + public void method1536(int i_1) { + int i_2 = -1; + int i_3; + int i_5; + int i_6; + int i_7; + if (pallete.length < 255) { + for (i_3 = 0; i_3 < pallete.length; i_3++) + if (pallete[i_3] == i_1) { + i_2 = i_3; + break; + } + + if (i_2 == -1) { + i_2 = pallete.length; + int[] ints_16 = new int[pallete.length + 1]; + Class503.method8362(pallete, 0, ints_16, 0, pallete.length); + pallete = ints_16; + ints_16[i_2] = i_1; + } + } else { + i_3 = Integer.MAX_VALUE; + int i_17 = i_1 >> 16 & 0xff; + i_5 = i_1 >> 8 & 0xff; + i_6 = i_1 & 0xff; + + for (i_7 = 0; i_7 < pallete.length; i_7++) { + int i_8 = pallete[i_7]; + int i_9 = i_8 >> 16 & 0xff; + int i_10 = i_8 >> 8 & 0xff; + int i_11 = i_8 & 0xff; + int i_12 = i_17 - i_9; + if (i_12 < 0) + i_12 = -i_12; + + int i_13 = i_5 - i_10; + if (i_13 < 0) + i_13 = -i_13; + + int i_14 = i_6 - i_11; + if (i_14 < 0) + i_14 = -i_14; + + int i_15 = i_12 + i_13 + i_14; + if (i_15 < i_3) { + i_3 = i_15; + i_2 = i_7; + } + } + } + + i_3 = 0; + byte[] bytes_4 = new byte[width * height]; + + for (i_5 = 0; i_5 < height; i_5++) + for (i_6 = 0; i_6 < width; i_6++) { + i_7 = pixels[i_3] & 0xff; + if (pallete[i_7] == 0) + if ((i_6 > 0 && pallete[pixels[i_3 - 1] & 0xff] != 0) || (i_5 > 0 && pallete[pixels[i_3 - width] & 0xff] != 0)) + i_7 = i_2; + else if (i_6 < width - 1 && pallete[pixels[i_3 + 1] & 0xff] != 0) + i_7 = i_2; + else if (i_5 < height - 1 && pallete[pixels[i_3 + width] & 0xff] != 0) + i_7 = i_2; + + bytes_4[i_3++] = (byte) i_7; + } + + pixels = bytes_4; + } + + public void method1554(int i_1) { + int i_2 = getMaxWidth(); + int i_3 = getMaxHeight(); + if (i_2 != width || i_3 != height) { + int i_4 = i_1; + if (i_1 > minX) + i_4 = minX; + + int i_5 = i_1; + if (i_1 + minX + width > i_2) + i_5 = i_2 - minX - width; + + int i_6 = i_1; + if (i_1 > minY) + i_6 = minY; + + int i_7 = i_1; + if (i_1 + minY + height > i_3) + i_7 = i_3 - minY - height; + + int i_8 = i_4 + i_5 + width; + int i_9 = i_6 + i_7 + height; + byte[] bytes_10 = new byte[i_8 * i_9]; + int i_12; + int i_13; + int i_14; + if (alpha == null) + for (int i_11 = 0; i_11 < height; i_11++) { + i_12 = i_11 * width; + i_13 = i_8 * (i_11 + i_6) + i_4; + + for (i_14 = 0; i_14 < width; i_14++) + bytes_10[i_13++] = pixels[i_12++]; + } + else { + byte[] bytes_16 = new byte[i_8 * i_9]; + i_12 = 0; + + while (true) { + if (i_12 >= height) { + alpha = bytes_16; + break; + } + + i_13 = i_12 * width; + i_14 = i_8 * (i_12 + i_6) + i_4; + + for (int i_15 = 0; i_15 < width; i_15++) { + bytes_16[i_14] = alpha[i_13]; + bytes_10[i_14++] = pixels[i_13++]; + } + + ++i_12; + } + } + + minX -= i_4; + minY -= i_6; + anInt958 -= i_5; + anInt953 -= i_7; + width = i_8; + height = i_9; + pixels = bytes_10; + } + + } + +} diff --git a/src/java/net/runelite/cache/loaders/TextureLoaderHD.java b/src/java/rshd/TextureLoaderHD.java similarity index 99% rename from src/java/net/runelite/cache/loaders/TextureLoaderHD.java rename to src/java/rshd/TextureLoaderHD.java index 8bc6780..ac25a38 100644 --- a/src/java/net/runelite/cache/loaders/TextureLoaderHD.java +++ b/src/java/rshd/TextureLoaderHD.java @@ -22,7 +22,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.runelite.cache.loaders; +package rshd; import net.runelite.cache.definitions.TextureDetails; import net.runelite.cache.io.InputStream;