Search in sources :

Example 1 with UnderlayDefinition

use of net.runelite.cache.definitions.UnderlayDefinition in project runelite by runelite.

the class UnderlayLoader method load.

public UnderlayDefinition load(int id, byte[] b) {
    UnderlayDefinition def = new UnderlayDefinition();
    InputStream is = new InputStream(b);
    def.setId(id);
    for (; ; ) {
        int opcode = is.readUnsignedByte();
        if (opcode == 0) {
            break;
        }
        if (opcode == 1) {
            int color = is.read24BitInt();
            def.setColor(color);
        }
    }
    def.calculateHsl();
    return def;
}
Also used : InputStream(net.runelite.cache.io.InputStream) UnderlayDefinition(net.runelite.cache.definitions.UnderlayDefinition)

Example 2 with UnderlayDefinition

use of net.runelite.cache.definitions.UnderlayDefinition in project runelite by runelite.

the class UnderlayDumper method extract.

@Test
public void extract() throws IOException {
    File base = StoreLocation.LOCATION, outDir = folder.newFolder();
    int count = 0;
    try (Store store = new Store(base)) {
        store.load();
        Storage storage = store.getStorage();
        Index index = store.getIndex(IndexType.CONFIGS);
        Archive archive = index.getArchive(ConfigType.UNDERLAY.getId());
        byte[] archiveData = storage.loadArchive(archive);
        ArchiveFiles files = archive.getFiles(archiveData);
        for (FSFile file : files.getFiles()) {
            UnderlayLoader loader = new UnderlayLoader();
            UnderlayDefinition underlay = loader.load(file.getFileId(), file.getContents());
            Files.write(gson.toJson(underlay), new File(outDir, file.getFileId() + ".json"), Charset.defaultCharset());
            ++count;
        }
    }
    logger.info("Dumped {} underlays to {}", count, outDir);
}
Also used : Storage(net.runelite.cache.fs.Storage) Archive(net.runelite.cache.fs.Archive) ArchiveFiles(net.runelite.cache.fs.ArchiveFiles) Store(net.runelite.cache.fs.Store) UnderlayDefinition(net.runelite.cache.definitions.UnderlayDefinition) Index(net.runelite.cache.fs.Index) File(java.io.File) FSFile(net.runelite.cache.fs.FSFile) UnderlayLoader(net.runelite.cache.definitions.loaders.UnderlayLoader) FSFile(net.runelite.cache.fs.FSFile) Test(org.junit.Test)

Example 3 with UnderlayDefinition

use of net.runelite.cache.definitions.UnderlayDefinition in project runelite by runelite.

the class ModelViewer method loadUnderlays.

private static void loadUnderlays() throws IOException {
    for (int i = 0; i < NUM_UNDERLAYS; ++i) {
        try (FileInputStream fin = new FileInputStream("underlays/" + i + ".json")) {
            UnderlayDefinition underlay = new Gson().fromJson(new InputStreamReader(fin), UnderlayDefinition.class);
            underlays[i] = underlay;
        } catch (FileNotFoundException ex) {
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) FileNotFoundException(java.io.FileNotFoundException) UnderlayDefinition(net.runelite.cache.definitions.UnderlayDefinition) Gson(com.google.gson.Gson) FileInputStream(java.io.FileInputStream)

Example 4 with UnderlayDefinition

use of net.runelite.cache.definitions.UnderlayDefinition in project runelite by runelite.

the class ModelViewer method drawRegion.

private static void drawRegion(Region region) {
    if (region == null) {
        return;
    }
    for (int regionX = 0; regionX < Region.X; ++regionX) {
        for (int regionY = 0; regionY < Region.Y; ++regionY) {
            int x = regionX;
            int y = regionY;
            x *= TILE_SCALE;
            y *= TILE_SCALE;
            /*
				 Split into two triangles with vertices
				 x,y,z1   x+1,y,z2 x,y+1,z3
				 x,y+1,z3 x+1,y,z2 x+1,y+1,z4
				
				 z1 = height
				 z2 = height of tile x+1
				 z3 = height of tile y-1
				
				 in rs 0,0 (x,y) is the bottom left with
				 y increasing going further from you
				
				 in opengl, 0,0 (x,z) is the bottom left
				 with z decreasing going further from you
				
				 in rs, height is also negative
				
				 so we do rs(x,y,z) -> opengl(x,-z,-y)
				 */
            int z1 = -region.getTileHeight(0, regionX, regionY);
            int z2 = regionX + 1 < Region.X ? -region.getTileHeight(0, regionX + 1, regionY) : z1;
            int z3 = regionY + 1 < Region.Y ? -region.getTileHeight(0, regionX, regionY + 1) : z1;
            int z4 = regionX + 1 < Region.X && regionY + 1 < Region.Y ? -region.getTileHeight(0, regionX + 1, regionY + 1) : z1;
            // scale down height
            z1 /= HEIGHT_MOD;
            z2 /= HEIGHT_MOD;
            z3 /= HEIGHT_MOD;
            z4 /= HEIGHT_MOD;
            int underlayId = region.getUnderlayId(0, regionX, regionY);
            int overlayId = region.getOverlayId(0, regionX, regionY);
            Color color = null;
            int glTexture = -1;
            if (underlayId > 0) {
                UnderlayDefinition ud = underlays[underlayId - 1];
                color = new Color(ud.getColor());
            }
            if (overlayId > 0) {
                OverlayDefinition od = overlays[overlayId - 1];
                color = new Color(od.getRgbColor());
                if (od.getSecondaryRgbColor() > -1) {
                    color = new Color(od.getSecondaryRgbColor());
                }
                if (od.getTexture() > -1) {
                    color = Color.WHITE;
                    Texture texture = getTexture(od.getTexture());
                    glTexture = texture.getOpenglId();
                    assert glTexture > -1;
                    GL11.glEnable(GL11.GL_TEXTURE_2D);
                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, glTexture);
                }
            }
            GL11.glBegin(GL11.GL_TRIANGLES);
            if (color != null) {
                GL11.glColor3f((float) color.getRed() / 255f, (float) color.getGreen() / 255f, (float) color.getBlue() / 255f);
            }
            // triangle 1
            if (glTexture > -1) {
                GL11.glTexCoord2f(0, 0);
            }
            GL11.glVertex3i(x, z1, -y);
            if (glTexture > -1) {
                GL11.glTexCoord2f(1, 0);
            }
            GL11.glVertex3i(x + TILE_SCALE, z2, -y);
            if (glTexture > -1) {
                GL11.glTexCoord2f(0, 1);
            }
            GL11.glVertex3i(x, z3, -(y + TILE_SCALE));
            // triangle 2
            if (glTexture > -1) {
                GL11.glTexCoord2f(0, 1);
            }
            GL11.glVertex3i(x, z3, -(y + TILE_SCALE));
            if (glTexture > -1) {
                GL11.glTexCoord2f(1, 0);
            }
            GL11.glVertex3i(x + TILE_SCALE, z2, -y);
            if (glTexture > -1) {
                GL11.glTexCoord2f(1, 1);
            }
            GL11.glVertex3i(x + TILE_SCALE, z4, -(y + TILE_SCALE));
            GL11.glEnd();
            if (glTexture > -1) {
                GL11.glDisable(GL11.GL_TEXTURE_2D);
            }
        }
    }
    drawLocations(region);
}
Also used : OverlayDefinition(net.runelite.cache.definitions.OverlayDefinition) Color(java.awt.Color) UnderlayDefinition(net.runelite.cache.definitions.UnderlayDefinition)

Example 5 with UnderlayDefinition

use of net.runelite.cache.definitions.UnderlayDefinition in project runelite by runelite.

the class MapImageDumper method drawMap.

private void drawMap(int[][] pixels, Region region, int z) {
    int baseX = region.getBaseX();
    int baseY = region.getBaseY();
    int len = Region.X + BLEND * 2;
    int[] hues = new int[len];
    int[] sats = new int[len];
    int[] light = new int[len];
    int[] mul = new int[len];
    int[] num = new int[len];
    boolean hasLeftRegion = regionLoader.findRegionForWorldCoordinates(baseX - 1, baseY) != null;
    boolean hasRightRegion = regionLoader.findRegionForWorldCoordinates(baseX + Region.X, baseY) != null;
    boolean hasUpRegion = regionLoader.findRegionForWorldCoordinates(baseX, baseY + Region.Y) != null;
    boolean hasDownRegion = regionLoader.findRegionForWorldCoordinates(baseX, baseY - 1) != null;
    for (int xi = (hasLeftRegion ? -BLEND * 2 : -BLEND); xi < Region.X + (hasRightRegion ? BLEND * 2 : BLEND); ++xi) {
        for (int yi = (hasDownRegion ? -BLEND : 0); yi < Region.Y + (hasUpRegion ? BLEND : 0); ++yi) {
            int xr = xi + BLEND;
            if (xr >= (hasLeftRegion ? -BLEND : 0) && xr < Region.X + (hasRightRegion ? BLEND : 0)) {
                Region r = regionLoader.findRegionForWorldCoordinates(baseX + xr, baseY + yi);
                if (r != null) {
                    int underlayId = r.getUnderlayId(z, convert(xr), convert(yi));
                    if (underlayId > 0) {
                        UnderlayDefinition underlay = findUnderlay(underlayId - 1);
                        hues[yi + BLEND] += underlay.getHue();
                        sats[yi + BLEND] += underlay.getSaturation();
                        light[yi + BLEND] += underlay.getLightness();
                        mul[yi + BLEND] += underlay.getHueMultiplier();
                        num[yi + BLEND]++;
                    }
                }
            }
            int xl = xi - BLEND;
            if (xl >= (hasLeftRegion ? -BLEND : 0) && xl < Region.X + (hasRightRegion ? BLEND : 0)) {
                Region r = regionLoader.findRegionForWorldCoordinates(baseX + xl, baseY + yi);
                if (r != null) {
                    int underlayId = r.getUnderlayId(z, convert(xl), convert(yi));
                    if (underlayId > 0) {
                        UnderlayDefinition underlay = findUnderlay(underlayId - 1);
                        hues[yi + BLEND] -= underlay.getHue();
                        sats[yi + BLEND] -= underlay.getSaturation();
                        light[yi + BLEND] -= underlay.getLightness();
                        mul[yi + BLEND] -= underlay.getHueMultiplier();
                        num[yi + BLEND]--;
                    }
                }
            }
        }
        if (xi >= 0 && xi < Region.X) {
            int runningHues = 0;
            int runningSat = 0;
            int runningLight = 0;
            int runningMultiplier = 0;
            int runningNumber = 0;
            for (int yi = (hasDownRegion ? -BLEND * 2 : -BLEND); yi < Region.Y + (hasUpRegion ? BLEND * 2 : BLEND); ++yi) {
                int yu = yi + BLEND;
                if (yu >= (hasDownRegion ? -BLEND : 0) && yu < Region.Y + (hasUpRegion ? BLEND : 0)) {
                    runningHues += hues[yu + BLEND];
                    runningSat += sats[yu + BLEND];
                    runningLight += light[yu + BLEND];
                    runningMultiplier += mul[yu + BLEND];
                    runningNumber += num[yu + BLEND];
                }
                int yd = yi - BLEND;
                if (yd >= (hasDownRegion ? -BLEND : 0) && yd < Region.Y + (hasUpRegion ? BLEND : 0)) {
                    runningHues -= hues[yd + BLEND];
                    runningSat -= sats[yd + BLEND];
                    runningLight -= light[yd + BLEND];
                    runningMultiplier -= mul[yd + BLEND];
                    runningNumber -= num[yd + BLEND];
                }
                if (yi >= 0 && yi < Region.Y) {
                    Region r = regionLoader.findRegionForWorldCoordinates(baseX + xi, baseY + yi);
                    if (r != null) {
                        int underlayId = r.getUnderlayId(z, convert(xi), convert(yi));
                        int overlayId = r.getOverlayId(z, convert(xi), convert(yi));
                        if (underlayId > 0 || overlayId > 0) {
                            int underlayHsl = -1;
                            if (underlayId > 0) {
                                int avgHue = runningHues * 256 / runningMultiplier;
                                int avgSat = runningSat / runningNumber;
                                int avgLight = runningLight / runningNumber;
                                if (avgLight < 0) {
                                    avgLight = 0;
                                } else if (avgLight > 255) {
                                    avgLight = 255;
                                }
                                underlayHsl = packHsl(avgHue, avgSat, avgLight);
                            }
                            int underlayRgb = 0;
                            if (underlayHsl != -1) {
                                int var0 = method1792(underlayHsl, 96);
                                underlayRgb = colorPalette[var0];
                            }
                            int shape, rotation;
                            Integer overlayRgb = null;
                            if (overlayId == 0) {
                                shape = rotation = 0;
                            } else {
                                shape = r.getOverlayPath(z, convert(xi), convert(yi)) + 1;
                                rotation = r.getOverlayRotation(z, convert(xi), convert(yi));
                                OverlayDefinition overlayDefinition = findOverlay(overlayId - 1);
                                int overlayTexture = overlayDefinition.getTexture();
                                int rgb;
                                if (overlayTexture >= 0) {
                                    rgb = rsTextureProvider.getAverageTextureRGB(overlayTexture);
                                } else if (overlayDefinition.getRgbColor() == 0xFF_00FF) {
                                    rgb = -2;
                                } else {
                                    // randomness added here
                                    int overlayHsl = packHsl(overlayDefinition.getHue(), overlayDefinition.getSaturation(), overlayDefinition.getLightness());
                                    rgb = overlayHsl;
                                }
                                overlayRgb = 0;
                                if (rgb != -2) {
                                    int var0 = adjustHSLListness0(rgb, 96);
                                    overlayRgb = colorPalette[var0];
                                }
                                if (overlayDefinition.getSecondaryRgbColor() != -1) {
                                    int hue = overlayDefinition.getOtherHue();
                                    int sat = overlayDefinition.getOtherSaturation();
                                    int olight = overlayDefinition.getOtherLightness();
                                    rgb = packHsl(hue, sat, olight);
                                    int var0 = adjustHSLListness0(rgb, 96);
                                    overlayRgb = colorPalette[var0];
                                }
                            }
                            if (shape == 0) {
                                int drawX = xi;
                                int drawY = Region.Y - 1 - yi;
                                if (underlayRgb != 0) {
                                    drawMapSquare(pixels, drawX, drawY, underlayRgb);
                                }
                            } else if (shape == 1) {
                                int drawX = xi;
                                int drawY = Region.Y - 1 - yi;
                                drawMapSquare(pixels, drawX, drawY, overlayRgb);
                            } else {
                                int drawX = xi * MAP_SCALE;
                                int drawY = (Region.Y - 1 - yi) * MAP_SCALE;
                                int[] tileShapes = TILE_SHAPE_2D[shape];
                                int[] tileRotations = TILE_ROTATION_2D[rotation];
                                if (underlayRgb != 0) {
                                    int rotIdx = 0;
                                    for (int i = 0; i < Region.Z; ++i) {
                                        int p1 = tileShapes[tileRotations[rotIdx++]] == 0 ? underlayRgb : overlayRgb;
                                        int p2 = tileShapes[tileRotations[rotIdx++]] == 0 ? underlayRgb : overlayRgb;
                                        int p3 = tileShapes[tileRotations[rotIdx++]] == 0 ? underlayRgb : overlayRgb;
                                        int p4 = tileShapes[tileRotations[rotIdx++]] == 0 ? underlayRgb : overlayRgb;
                                        pixels[drawX + 0][drawY + i] = p1;
                                        pixels[drawX + 1][drawY + i] = p2;
                                        pixels[drawX + 2][drawY + i] = p3;
                                        pixels[drawX + 3][drawY + i] = p4;
                                    }
                                } else {
                                    int rotIdx = 0;
                                    for (int i = 0; i < Region.Z; ++i) {
                                        int p1 = tileShapes[tileRotations[rotIdx++]];
                                        int p2 = tileShapes[tileRotations[rotIdx++]];
                                        int p3 = tileShapes[tileRotations[rotIdx++]];
                                        int p4 = tileShapes[tileRotations[rotIdx++]];
                                        if (p1 != 0) {
                                            pixels[drawX + 0][drawY + i] = overlayRgb;
                                        }
                                        if (p2 != 0) {
                                            pixels[drawX + 1][drawY + i] = overlayRgb;
                                        }
                                        if (p3 != 0) {
                                            pixels[drawX + 2][drawY + i] = overlayRgb;
                                        }
                                        if (p4 != 0) {
                                            pixels[drawX + 3][drawY + i] = overlayRgb;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : OverlayDefinition(net.runelite.cache.definitions.OverlayDefinition) Region(net.runelite.cache.region.Region) UnderlayDefinition(net.runelite.cache.definitions.UnderlayDefinition)

Aggregations

UnderlayDefinition (net.runelite.cache.definitions.UnderlayDefinition)6 OverlayDefinition (net.runelite.cache.definitions.OverlayDefinition)2 UnderlayLoader (net.runelite.cache.definitions.loaders.UnderlayLoader)2 Archive (net.runelite.cache.fs.Archive)2 ArchiveFiles (net.runelite.cache.fs.ArchiveFiles)2 FSFile (net.runelite.cache.fs.FSFile)2 Index (net.runelite.cache.fs.Index)2 Storage (net.runelite.cache.fs.Storage)2 Gson (com.google.gson.Gson)1 Color (java.awt.Color)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStreamReader (java.io.InputStreamReader)1 Store (net.runelite.cache.fs.Store)1 InputStream (net.runelite.cache.io.InputStream)1 Region (net.runelite.cache.region.Region)1 Test (org.junit.Test)1