Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Graphics2D;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.io.FileFilter;
- import java.io.FileInputStream;
- import java.io.FileWriter;
- import java.io.PrintWriter;
- import javax.imageio.ImageIO;
- public class KatAMMap {
- public static String path = "C:\\Users\\Alex\\Desktop\\KatAM\\";
- public static String gba = "C:\\Users\\Alex\\Desktop\\katam.gba";
- public static int ROOM_PROP_TABLE = 0x903338;
- public static int OBJ_LIST_PTR_TABLE = 0xD2EBC0;
- public static byte[] rom;
- public static boolean drawbackground = true;
- public static void main(String [] args) {
- try (PrintWriter out = new PrintWriter(new FileWriter(new File("out.log")))) {
- try (FileInputStream in = new FileInputStream(gba)) {
- rom = new byte[(int)in.getChannel().size()];
- in.read(rom, 0, rom.length);
- } catch (Exception e) {
- e.printStackTrace();
- }
- File objectImages = new File(path + "_OBJ\\");
- File[] objImgs = objectImages.listFiles();
- File root = new File(path);
- File[] levels = root.listFiles(new FileFilter() {
- @Override
- public boolean accept(File file) {
- return file.isDirectory() && (file.getName().contains("level-912") || file.getName().contains("level-916"));
- }
- });
- for (File lvl : levels) {
- if (lvl.getName().equals("_OBJ")) {
- continue;
- }
- int lvlNo = Integer.parseInt(lvl.getName().substring(lvl.getName().indexOf("-")+1,lvl.getName().indexOf("_")));
- int ptrIdx = get16(ROOM_PROP_TABLE + 0x28 * lvlNo + 0x20)+1;
- int objPtr = get24(OBJ_LIST_PTR_TABLE + 0x4 * ptrIdx);
- File [] imgs = lvl.listFiles();
- int [][] pos = new int[imgs.length][2];
- String foldername = lvl.getName();
- int w = Integer.parseInt(foldername.substring(foldername.indexOf("w-")+2, foldername.indexOf("_h")));
- int h = Integer.parseInt(foldername.substring(foldername.indexOf("h-")+2)) - 32;
- File background = null;
- for (int i = 0; i < imgs.length; i++) {
- String filename = imgs[i].getName();
- if (filename.equals("b.png")) {
- background = imgs[i];
- pos[i][1] = -100000;
- } else {
- pos[i][1] = Integer.parseInt(filename.substring(2,filename.indexOf("_")));
- pos[i][0] = Integer.parseInt(filename.substring(filename.indexOf("x-")+2, filename.indexOf(".png")));
- }
- }
- BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
- Graphics2D g = (Graphics2D)bi.getGraphics();
- g.setBackground(Color.red);
- g.setColor(Color.black);
- BufferedImage bg = null;
- if (background != null) {
- bg = ImageIO.read(background);
- }
- for (int i = 0; i < imgs.length; i++) {
- BufferedImage image = ImageIO.read(imgs[i]);
- BufferedImage imageWAlpha = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
- ((Graphics2D)(imageWAlpha.getGraphics())).drawImage(image, 0, 0, null);
- for (int y = 0; y < imageWAlpha.getHeight(); ++y) {
- for (int x = 0; x < imageWAlpha.getWidth(); ++x) {
- int argb = imageWAlpha.getRGB(x, y);
- if ((argb & 0x00FFFFFF) == 0x00FF00FF)
- {
- imageWAlpha.setRGB(x, y, 0);
- }
- }
- }
- if (drawbackground && bg != null) {
- g.drawImage(bg, pos[i][0], pos[i][1], null);
- }
- g.drawImage(imageWAlpha, pos[i][0], pos[i][1], null);
- }
- out.printf("%x%n", objPtr);
- int m = get16(objPtr + 0x10);
- int o = 0;
- while (m == 0x2401) {
- int ox = get16(objPtr + o * 36 + 0x10 + 6);
- int oy = get16(objPtr + o * 36 + 0x10 + 8);
- int ot = get8(objPtr + o * 36 + 0x10 + 0xC);
- int oa = get8(objPtr + o * 36 + 0x10 + 0xE);
- File oImg = null;
- for (File f : objImgs) {
- if (f.getName().indexOf(ot + "_") == 0) {
- if (
- ot == 0x92 || ot == 0x93 || ot == 0x94 || ot == 0x95 || // ability trophy
- ot == 0x97 || // fancy door
- ot == 0x00 || // waddle dee
- ot == 0x2D // batty
- ) {
- if (f.getName().indexOf("(" + oa + ")") != -1) {
- oImg = f;
- break;
- }
- } else {
- oImg = f;
- break;
- }
- }
- }
- if (oImg == null) {
- g.clearRect(ox, oy, 16, 16);
- out.printf("Sprite %x (level %d) - ", ot, lvlNo);
- out.println();
- } else {
- BufferedImage objBi = ImageIO.read(oImg);
- int xOffset = Integer.parseInt(oImg.getName().substring(oImg.getName().indexOf("[")+1,oImg.getName().indexOf(",")));
- int yOffset = Integer.parseInt(oImg.getName().substring(oImg.getName().indexOf(",")+1,oImg.getName().indexOf("]")));
- g.drawImage(objBi, ox + xOffset, oy + yOffset, null);
- }
- for (int i = 0; i < 36; i+=2) {
- out.printf("%4x|", get16(objPtr + o * 36 + 0x10 + i));
- }
- out.println();
- //g.drawString(String.format("T: %x", ot), ox, oy);
- o++;
- m = get16(objPtr + o * 36 + 0x10);
- }
- String newname = lvl.toString().substring(0,lvl.toString().indexOf("_w"));
- ImageIO.write(bi, "png", new File(newname + ".png"));
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static int get8(int i) {
- int a = 0xff&rom[i];
- return a;
- }
- public static int get16(int i) {
- int a = 0xff&rom[i], b = 0xff&rom[i + 1];
- return b * 0x100 + a;
- }
- public static int get24(int i) {
- int a = 0xff&rom[i], b = 0xff&rom[i + 1], c = 0xff&rom[i + 2];
- return c * 0x10000 + b * 0x100 + a;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement