mirror of
https://github.com/zeldaret/oot.git
synced 2025-08-30 18:55:54 +00:00
wip: New assets system tm
Builds gc-eu-mq-dbg OK from clean after 1) make setup 2) python3 -m tools.assets.extract -j 3) replace 0x80A8E610 with sShadowTex in extracted/gc-eu-mq-dbg/assets/overlays/ovl_En_Jsjutan/sShadowMaterialDL.inc.c 4) make various symbols in extracted data like sTex static
This commit is contained in:
parent
748859595a
commit
8411c34b38
80 changed files with 535882 additions and 112 deletions
86
tools/assets/bin2c/bin2c.c
Normal file
86
tools/assets/bin2c/bin2c.c
Normal file
|
@ -0,0 +1,86 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 2) {
|
||||
usage:
|
||||
fprintf(stderr, "%s <u8|u32|u64>\n", argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
char* bytes_per_elem_str = argv[1];
|
||||
struct {
|
||||
size_t num;
|
||||
char* str;
|
||||
} bytes_per_elem_arg_info[] = {
|
||||
{ 1, "u8" },
|
||||
{ 4, "u32" },
|
||||
{ 8, "u64" },
|
||||
};
|
||||
size_t bytes_per_elem = 0;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (strcmp(bytes_per_elem_arg_info[i].str, bytes_per_elem_str) == 0) {
|
||||
bytes_per_elem = bytes_per_elem_arg_info[i].num;
|
||||
}
|
||||
}
|
||||
if (bytes_per_elem == 0) {
|
||||
goto usage;
|
||||
}
|
||||
|
||||
FILE* in_bin = stdin;
|
||||
FILE* out_c = stdout;
|
||||
|
||||
fprintf(out_c, "{\n");
|
||||
|
||||
int cur_line_nelems = 0;
|
||||
|
||||
while (true) {
|
||||
uint8_t buffer[bytes_per_elem];
|
||||
size_t nread = fread(buffer, 1, bytes_per_elem, in_bin);
|
||||
|
||||
if (nread == 0 && feof(in_bin)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (nread != bytes_per_elem) {
|
||||
if (feof(in_bin)) {
|
||||
fprintf(stderr, "Input has unaligned size\n");
|
||||
} else {
|
||||
fprintf(stderr, "Error reading from input\n");
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cur_line_nelems == 0) {
|
||||
fprintf(out_c, " ");
|
||||
}
|
||||
|
||||
fprintf(out_c, "0x");
|
||||
for (size_t i = 0; i < bytes_per_elem; i++) {
|
||||
fprintf(out_c, "%02X", buffer[i]);
|
||||
}
|
||||
fprintf(out_c, ",");
|
||||
|
||||
cur_line_nelems++;
|
||||
|
||||
int bytes_per_line = bytes_per_elem == 1 ? 0x10 : 0x20;
|
||||
|
||||
if (cur_line_nelems * bytes_per_elem >= bytes_per_line) {
|
||||
fprintf(out_c, "\n");
|
||||
cur_line_nelems = 0;
|
||||
} else {
|
||||
fprintf(out_c, " ");
|
||||
}
|
||||
}
|
||||
|
||||
if (cur_line_nelems != 0) {
|
||||
fprintf(out_c, "\n");
|
||||
}
|
||||
|
||||
fprintf(out_c, "}\n");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue