new tool!

This commit is contained in:
Shaffy 2022-11-03 18:24:11 +01:00
parent 1d1acf0db1
commit 65082e9a34
8 changed files with 167 additions and 72 deletions

View File

@ -1,15 +1,52 @@
#include <iostream>
#include "bitmap.h"
#include <map>
void printInstructions() {
std::cout << "R-IQ Tile Fixer.exe -[a][d] input.BMP output.BMP tile.BIN\n\n";
std::cout << "-a: Assembles input into output using the tile arrangement.\n"; //From scramble to original.
std::cout << "-d: Dissasemble input into a output tilemap using the tile arrangement.\n\n"; //From original to scramble.
std::cout << "input and ouput MUST be a 24-bit bitmap.\nAnd tile must be a memory dump of address 0x600E800 of (atleast) size 1276 bytes.\n\n(C)Shaffy - 2022.\n";
std::cout << "R-IQ Tile Fixer.exe -[a][d][r] input.BMP output.BMP tile.BIN paletteid\n\n";
std::cout << "-a: (A)ssembles input into output using the tile arrangement.\n"; //From scramble to original.
std::cout << "-d: (D)issasemble input into a output tilemap using the tile arrangement.\n\n"; //From original to scramble.
std::cout << "-r: (R)ecompile input into a output tilemap using a new tile arrangement.\n"; //From original to scramble.
std::cout << "paletteid: Optional with flag -r, can choose a palette (0-15).\n\n"; //From original to scramble.
std::cout << "input and ouput MUST be a 24-bit bitmap.\nAnd tile must be a memory dump of the address of the BG of (atleast) size 1276 bytes.\nExport the tiles with 32 tile per line.\n\n(C)Shaffy - 2022.\n";
}
struct Tile {
rgb_t pixel[8][8];
bool hrev = false;
bool vrev = false;
void loadTile(bitmap_image& image, unsigned int x, unsigned y, bool ishrev = false, bool isvrev = false) {
for (unsigned int y_ = 0; y_ < 8; y_++) {
for (unsigned int x_ = 0; x_ < 8; x_++) {
int row = !ishrev ? x_ : 7 - x_;
int column = !isvrev ? y_ : 7 - y_;
pixel[row][column] = image.get_pixel(x + x_, y + y_);
}
}
}
void drawTile(bitmap_image& image, unsigned int x, unsigned y) {
for (unsigned int y_ = 0; y_ < 8; y_++) {
for (unsigned int x_ = 0; x_ < 8; x_++) {
int row = !hrev ? x_ : 7 - x_;
int column = !vrev ? y_ : 7 - y_;
image.set_pixel(x + x_, y + y_, pixel[row][column]);
}
}
}
};
int main(int argc, char* argv[])
{
argc = 6;
argv[1] = (char*)"-r";
argv[2] = (char*)"newrap_tile.bmp";
argv[3] = (char*)"test.bmp";
argv[4] = (char*)"rap_tilemap.bin";
argv[5] = (char*)"1";
if (argc < 5) {
printInstructions();
return 1;
@ -24,8 +61,6 @@ int main(int argc, char* argv[])
const char* outputString = argv[3];
const char* tileString = argv[4];
std::fstream file("polyrhythm.bin", std::ios::in | std::ios::binary);
if (argv[1][1] == 'a') {
bitmap_image image(inputString);
bitmap_image image_fix(240, 160);
@ -35,23 +70,24 @@ int main(int argc, char* argv[])
for (unsigned int j = 0; j < 20; j++) {
for (unsigned int i = 0; i < 30; i++) {
char bytes[2];
file.read(bytes, 2);
unsigned char bytes[2];
file.read((char*)bytes, 2);
bool hrev = (bytes[1] >> 2) & 1U;
bool vrev = (bytes[1] >> 3) & 1U;
bytes[1] &= ~0xFC;
unsigned short tileNumber = (((unsigned char)bytes[1] << 8) | ((unsigned char)bytes[0]));
int tileColumn = tileNumber / 30;
int tileRow = tileNumber % 30;
int tileRow = tileNumber % 32;
int tileColumn = tileNumber / 32;
//std::cout << "Tile no." << std::dec << (int)tileNumber << " in tex coords (" << tileRow * 8 << ';' << tileColumn * 8 << ") at img pos (" << i * 8 << ';' << j * 8 << ")";
//std::cout << " - VRAM: 0x" << std::hex << 0x0600E800 + (((j * 30) + i) * 2) << std::endl;
for (unsigned int a = 0; a < 8; a++) { //x
for (unsigned int b = 0; b < 8; b++) { //y
rgb_t pixel = image.get_pixel((tileRow * 8) + a, (tileColumn * 8) + b);
image_fix.set_pixel((i * 8) + a, (j * 8) + b, pixel);
}
}
Tile tile;
tile.hrev = hrev;
tile.vrev = vrev;
tile.loadTile(image, (tileRow * 8), (tileColumn * 8));
tile.drawTile(image_fix, (i * 8), (j * 8));
}
file.seekp(4, file.cur);
@ -64,7 +100,8 @@ int main(int argc, char* argv[])
else if (argv[1][1] == 'd') {
bitmap_image image(inputString);
bitmap_image image_fix(240, 824); //Make it big enough...
bitmap_image image_fix(256, 824); //Make it big enough...
image_fix.set_region(0, 0, 256, 824, 0, 255, 64);
std::fstream file(tileString, std::ios::in | std::ios::binary);
std::cout << "Loaded! width: " << image.width() << " height: " << image.height() << std::endl;
@ -74,21 +111,19 @@ int main(int argc, char* argv[])
char bytes[2];
file.read(bytes, 2);
bool hrev = (bytes[1] >> 2) & 1U;
bool vrev = (bytes[1] >> 3) & 1U;
bytes[1] &= ~0xFC;
unsigned short tileNumber = (((unsigned char)bytes[1] << 8) | ((unsigned char)bytes[0]));
int tileColumn = tileNumber / 30;
int tileRow = tileNumber % 30;
//std::cout << "Tile no." << std::dec << (int)tileNumber << " in tex coords (" << tileRow * 8 << ';' << tileColumn * 8 << ") at img pos (" << i * 8 << ';' << j * 8 << ")";
//std::cout << " - VRAM: 0x" << std::hex << 0x0600E800 + (((j * 30) + i) * 2) << std::endl;
for (unsigned int a = 0; a < 8; a++) { //x
for (unsigned int b = 0; b < 8; b++) { //y
rgb_t pixel = image.get_pixel((i * 8) + a, (j * 8) + b);
image_fix.set_pixel((tileRow * 8) + a, (tileColumn * 8) + b, pixel);
}
}
int tileColumn = tileNumber / 32;
int tileRow = tileNumber % 32;
Tile tile;
tile.loadTile(image, (i * 8), (j * 8), hrev, vrev);
tile.drawTile(image_fix, (tileRow * 8), (tileColumn * 8));
}
file.seekp(4, file.cur);
@ -98,6 +133,75 @@ int main(int argc, char* argv[])
image_fix.save_image(outputString);
}
else if (argv[1][1] == 'r') {
int paletteChoice = 0;
if (argc == 6) {
paletteChoice = std::stoi(argv[5]);
}
std::map<unsigned int, Tile> tiles;
unsigned int currentTile = 0;
bitmap_image image(inputString);
bitmap_image image_fix(256, 824); //Make it big enough...
image_fix.set_region(0, 0, 256, 824, 0, 255, 64);
std::fstream file(tileString, std::ios::out | std::ios::binary);
std::cout << "Loaded! width: " << image.width() << " height: " << image.height() << std::endl;
//read tile left to right top bottom
for (unsigned int j = 0; j < 20; j++) {
for (unsigned int i = 0; i < 30; i++) {
Tile tile;
tile.loadTile(image, i * 8, j * 8);
bool isDuplicate = false;
Tile* tileReference = nullptr;
unsigned int numberReference = 0;
for (auto& tile_ : tiles) {
if (memcmp(&tile, &tile_.second, sizeof(Tile)) == 0) {
isDuplicate = true;
tileReference = &tile_.second;
numberReference = tile_.first;
break;
}
}
if (!isDuplicate) {
tiles[currentTile] = tile;
tileReference = &tile;
numberReference = currentTile;
int tileColumn = currentTile / 32;
int tileRow = currentTile % 32;
tile.drawTile(image_fix, tileRow * 8, tileColumn * 8);
currentTile++;
}
unsigned char littleEndNumber[2];
littleEndNumber[0] = (numberReference & 0x00ff);
littleEndNumber[1] = ((numberReference & 0xff00) >> 8);
littleEndNumber[1] |= (paletteChoice << 4);
int fileseek = file.tellg();
file.write((const char*)littleEndNumber, 2);
}
if (j == 19) {
break;
}
int a = 0;
file.write((const char*)&a, 4);
}
file.close();
image_fix.save_image(outputString);
}
else {
printInstructions();
return 1;

File diff suppressed because one or more lines are too long

View File

@ -109,6 +109,7 @@ tools\rhcomp.exe src/Graphics/ToysMenu/cd931c_toys_screen_map.bin
tools\rhcomp.exe src/Graphics/Drums/cc6ccc_drums_map.bin
tools\rhcomp.exe src/Graphics/MusicSelect/CD62EC_musicselect_map.bin
tools\rhcomp.exe src/Graphics/MusicSelect/CD6434_musicselect_warning_map.bin
tools\rhcomp.exe src/Graphics/EmailSelectScreen/CC7A40_email_select_tilemap.bin
tools\armips.exe tools/ASM/compile.asm
tools\flips.exe "tools\Font Hack 4 - 1px spacer.ips" "ROM\rh-eng.gba"
tools\flips.exe "tools\accents.ips" "ROM\rh-eng.gba"

View File

@ -1,3 +1,9 @@
.org 0x08CC77A4
.dw CC77A4_email_select_tiles |0x80000000
.org 0x08CC7A40
.dw CC7A40_email_select_tilemap_data
.org 0x08CC7A40+4
.dw CC7A40_email_select_tilemap_rle
.org 0x08CC7A40+8
.dh CC7A40_email_select_tilemap_rle_end - CC7A40_email_select_tilemap_rle
;eof

View File

@ -1,4 +1,11 @@
.align 4
CC77A4_email_select_tiles:
.import src/Graphics/EmailSelectScreen/CC77A4_email_select_tiles.cdat
.align 4
CC7A40_email_select_tilemap_data:
.import src/Graphics/EmailSelectScreen/CC7A40_email_select_tilemap.dat
.align 4
CC7A40_email_select_tilemap_rle:
.import src/Graphics/EmailSelectScreen/CC7A40_email_select_tilemap.rle
CC7A40_email_select_tilemap_rle_end:
;eof

BIN
tools/4bmpp.exe Normal file

Binary file not shown.