Refresh 3

This commit is contained in:
n64
2019-11-03 14:36:27 -05:00
parent 6b8bc9b9ec
commit a7c423cb43
4603 changed files with 475500 additions and 437701 deletions

2
tools/.gitignore vendored
View File

@@ -9,6 +9,8 @@
/aiff_extract_codebook
/vadpcm_enc
/tabledesign
/extract_data_for_mio
/skyconv
!/ido5.3_compiler/lib/*.so
!/ido5.3_compiler/usr/lib/*.so
!/ido5.3_compiler/usr/lib/*.so.1

View File

@@ -1,6 +1,6 @@
CC := gcc
CFLAGS := -I . -Wall -Wextra -Wno-unused-parameter -pedantic -std=c99 -O3 -s
PROGRAMS := n64graphics n64graphics_ci mio0 n64cksum textconv patch_libultra_math iplfontutil aifc_decode aiff_extract_codebook vadpcm_enc tabledesign
PROGRAMS := n64graphics n64graphics_ci mio0 n64cksum textconv patch_libultra_math iplfontutil aifc_decode aiff_extract_codebook vadpcm_enc tabledesign extract_data_for_mio skyconv
n64graphics_SOURCES := n64graphics.c utils.c
n64graphics_CFLAGS := -DN64GRAPHICS_STANDALONE
@@ -30,6 +30,12 @@ tabledesign_CFLAGS := -Wno-uninitialized -laudiofile
vadpcm_enc_SOURCES := sdk-tools/adpcm/vadpcm_enc.c sdk-tools/adpcm/vpredictor.c sdk-tools/adpcm/quant.c sdk-tools/adpcm/util.c sdk-tools/adpcm/vencode.c
vadpcm_enc_CFLAGS := -Wno-unused-result -Wno-uninitialized -Wno-sign-compare -Wno-absolute-value
extract_data_for_mio_SOURCES := extract_data_for_mio.c
extract_data_for_mio_CFLAGS := -O2
skyconv_SOURCES := skyconv.c n64graphics.c utils.c
skyconv_CFLAGS := -O2 -lm
all: $(PROGRAMS)
clean:

View File

@@ -31,7 +31,7 @@ class Aifc:
class SampleBank:
def __init__(self, name, entries):
self.name = name
self.uses = 0
self.uses = []
self.entries = entries
self.name_to_entry = {}
for e in entries:
@@ -457,7 +457,7 @@ def apply_version_diffs(json, defines):
def mark_sample_bank_uses(bank):
bank.sample_bank.uses += 1
bank.sample_bank.uses.append(bank)
def mark_used(name):
bank.sample_bank.name_to_entry[name].used = True
@@ -492,7 +492,7 @@ def serialize_ctl(bank, base_ser):
">IIII",
len(json["instrument_list"]),
len(drums),
1 if bank.sample_bank.uses > 1 else 0,
1 if len(bank.sample_bank.uses) > 1 else 0,
to_bcd(date),
)
)
@@ -919,7 +919,8 @@ def main():
except Exception as e:
fail("failed to parse bank " + fname + ": " + str(e))
sample_banks = [b for b in sample_banks if b.uses > 0]
sample_banks = [b for b in sample_banks if b.uses]
sample_banks.sort(key=lambda b: b.uses[0].name)
sample_bank_index = {}
for sample_bank in sample_banks:
sample_bank_index[sample_bank] = len(sample_bank_index)

78
tools/demo_data_converter.py Executable file
View File

@@ -0,0 +1,78 @@
#!/usr/bin/env python3
import sys
import re
import json
def main():
need_help = False
defines = []
skip_next = 0
prog_args = []
for i, a in enumerate(sys.argv[1:], 1):
if skip_next > 0:
skip_next -= 1
continue
if a == "--help" or a == "-h":
need_help = True
if a == "-D":
defines.append(sys.argv[i + 1])
skip_next = 1
elif a.startswith("-D"):
defines.append(a[2:])
else:
prog_args.append(a)
defines = [d.split("=")[0] for d in defines]
if len(prog_args) < 1 or need_help:
print("Usage: {} <demo_data.json> [-D <symbol>] > <demo_data.c>".format(sys.argv[0]))
sys.exit(0 if need_help else 1)
with open(prog_args[0], "r") as file:
descr = json.loads(re.sub(r"/\*[\w\W]*?\*/", "", file.read()))
table = []
for item in descr["table"]:
if not "ifdef" in item or any(d in defines for d in item["ifdef"]):
table.append(item)
demofiles = []
for item in descr["demofiles"]:
if not "ifdef" in item or any(d in defines for d in item["ifdef"]):
demofiles.append(item)
structdef = ["u32 numEntries;",
"const void *addrPlaceholder;",
"struct OffsetSizePair entries[" + str(len(table)) + "];"]
structobj = [str(len(table)) + ",",
"NULL,"]
structobj.append("{")
for item in table:
offset_to_data = "offsetof(struct DemoInputsObj, " + item["demofile"] + ")"
size = "sizeof(gDemoInputs." + item["demofile"] + ")"
if "extraSize" in item:
size += " + " + str(item["extraSize"])
structobj.append("{" + offset_to_data + ", " + size + "},")
structobj.append("},")
for item in demofiles:
with open("assets/demos/" + item["name"] + ".bin", "rb") as file:
demobytes = file.read()
structdef.append("u8 " + item["name"] + "[" + str(len(demobytes)) + "];")
structobj.append("{" + ",".join(hex(x) for x in demobytes) + "},")
print("#include \"types.h\"")
print("#include \"stddef.h\"")
print("")
print("struct DemoInputsObj {")
for s in structdef:
print(s)
print("} gDemoInputs = {")
for s in structobj:
print(s)
print("};")
if __name__ == "__main__":
main()

View File

@@ -12,23 +12,6 @@ import sys
TYPE_CTL = 1
TYPE_TBL = 2
SAMPLE_BANK_IDS = [
"nlist_0",
"nlist_1",
"nlist_2",
"nlist_3",
"nlist_4and5",
"nlist_6",
"nlist_7",
"nlist_8",
"nlist_9",
"nlist_A",
"nlist_B",
"nlist_extra1",
"nlist_extra2",
"nlist_extra3",
]
class AifcEntry:
def __init__(self, data, book, loop):
@@ -399,7 +382,7 @@ def parse_tbl(data, entries):
sample_bank_map = {}
for (offset, length) in entries:
if offset not in seen:
name = gen_name("sample_bank", SAMPLE_BANK_IDS)
name = gen_name("sample_bank")
seen[offset] = name
sample_bank = SampleBank(name, data[offset : offset + length], offset)
sample_banks.append(sample_bank)

View File

@@ -0,0 +1,308 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#define EI_DATA 5
#define EI_NIDENT 16
#define STT_NOTYPE 0
#define STT_OBJECT 1
#define STT_FUNC 2
#define STT_SECTION 3
#define STT_FILE 4
#define STT_COMMON 5
#define STT_TLS 6
#define ELF_ST_TYPE(x) (((unsigned int) x) & 0xf)
typedef uint32_t Elf32_Addr;
typedef uint32_t Elf32_Off;
typedef struct {
unsigned char e_ident[EI_NIDENT];
uint16_t e_type;
uint16_t e_machine;
uint32_t e_version;
Elf32_Addr e_entry;
Elf32_Off e_phoff;
Elf32_Off e_shoff;
uint32_t e_flags;
uint16_t e_ehsize;
uint16_t e_phentsize;
uint16_t e_phnum;
uint16_t e_shentsize;
uint16_t e_shnum;
uint16_t e_shstrndx;
} Elf32_Ehdr;
typedef struct {
uint32_t sh_name;
uint32_t sh_type;
uint32_t sh_flags;
Elf32_Addr sh_addr;
Elf32_Off sh_offset;
uint32_t sh_size;
uint32_t sh_link;
uint32_t sh_info;
uint32_t sh_addralign;
uint32_t sh_entsize;
} Elf32_Shdr;
typedef struct {
uint32_t st_name;
Elf32_Addr st_value;
uint32_t st_size;
unsigned char st_info;
unsigned char st_other;
uint16_t st_shndx;
} Elf32_Sym;
typedef struct {
uint16_t magic; //To verify validity of the table
uint16_t vstamp; //Version stamp
uint32_t ilineMax; //Number of line number entries
uint32_t cbLine; //Number of bytes for line number entries
uint32_t cbLineOffset; //Index to start of line numbers
uint32_t idnMax; //Max index into dense numbers
uint32_t cbDnOffset; //Index to start dense numbers
uint32_t ipdMax; //Number of procedures
uint32_t cbPdOffset; //Index to procedure descriptors
uint32_t isymMax; //Number of local symbols
uint32_t cbSymOffset; //Index to start of local symbols
uint32_t ioptMax; //Maximum index into optimization entries
uint32_t cbOptOffset; //Index to start of optimization entries
uint32_t iauxMax; //Number of auxiliary symbols
uint32_t cbAuxOffset; //Index to the start of auxiliary symbols
uint32_t issMax; //Max index into local strings
uint32_t cbSsOffset; //Index to start of local strings
uint32_t issExtMax; //Max index into external strings
uint32_t cbSsExtOffset; //Index to the start of external strings
uint32_t ifdMax; //Number of file descriptors
uint32_t cbFdOffset; //Index to file descriptor
uint32_t crfd; //Number of relative file descriptors
uint32_t cbRfdOffset; //Index to relative file descriptors
uint32_t iextMax; //Maximum index into external symbols
uint32_t cbExtOffset; //Index to the start of external symbols.
} SymbolicHeader;
typedef struct {
uint32_t adr; // Memory address of start of file
uint32_t rss; // Source file name
uint32_t issBase; // Start of local strings
uint32_t cbSs; // Number of bytes in local strings
uint32_t isymBase; // Start of local symbol entries
uint32_t csym; // Count of local symbol entries
uint32_t ilineBase; // Start of line number entries
uint32_t cline; // Count of line number entries
uint32_t ioptBase; // Start of optimization symbol entries
uint32_t copt; // Count of optimization symbol entries
uint16_t ipdFirst; // Start of procedure descriptor table
uint16_t cpd; // Count of procedures descriptors
uint32_t iauxBase; // Start of auxiliary symbol entries
uint32_t caux; // Count of auxiliary symbol entries
uint32_t rfdBase; // Index into relative file descriptors
uint32_t crfd; // Relative file descriptor count
uint32_t flags;
uint32_t cbLineOffset; // Byte offset from header or file ln's
uint32_t cbLine;
} FileDescriptorTable;
typedef struct {
uint32_t iss;
uint32_t value;
uint32_t st_sc_index;
} LocalSymbolsEntry;
typedef enum {
stNil,
stGlobal,
stStatic,
stParam,
stLocal,
stLabel,
stProc,
stBlock,
stEnd,
stMember,
stTypedef,
stFile,
stStaticProc,
stConstant
} StConstants;
uint32_t u32be(uint32_t val) {
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
return __builtin_bswap32(val);
#else
return val;
#endif
}
uint16_t u16be(uint16_t val) {
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
return __builtin_bswap16(val);
#else
return val;
#endif
}
static bool elf_get_section_range(uint8_t *file, const char *searched_name, uint32_t *address, uint32_t *offset, uint32_t *size, uint32_t *section_index) {
Elf32_Ehdr *ehdr = (Elf32_Ehdr *)file;
for (int i = 0; i < u16be(ehdr->e_shnum); i++) {
if (memcmp("\x7f" "ELF", ehdr->e_ident, 4) != 0) {
fprintf(stderr, "Missing ELF magic\n");
exit(1);
}
if (ehdr->e_ident[EI_DATA] != 2) {
fprintf(stderr, "ELF file is not big-endian\n");
exit(1);
}
Elf32_Shdr *shdr = (Elf32_Shdr *)(file + u32be(ehdr->e_shoff) + i * u16be(ehdr->e_shentsize));
if (u16be(ehdr->e_shstrndx) >= u16be(ehdr->e_shnum)) {
fprintf(stderr, "Invalid ELF file\n");
exit(1);
}
Elf32_Shdr *str_shdr = (Elf32_Shdr *)(file + u32be(ehdr->e_shoff) + u16be(ehdr->e_shstrndx) * u16be(ehdr->e_shentsize));
char *name = (char *)(file + u32be(str_shdr->sh_offset) + u32be(shdr->sh_name));
if (memcmp(name, searched_name, strlen(searched_name)) == 0) {
*address = u32be(shdr->sh_addr);
*offset = u32be(shdr->sh_offset);
*size = u32be(shdr->sh_size);
*section_index = i;
return true;
}
}
return false;
}
int main(int argc, char *argv[]) {
if (argc < 3) {
fprintf(stderr, "Usage: %s INFILE OUTFILE\n", argv[0]);
return 1;
}
FILE *in = fopen(argv[1], "rb");
if (in == NULL) {
perror("fopen couldn't open input file");
exit(1);
}
fseek(in, 0, SEEK_END);
size_t file_size = ftell(in);
fseek(in, 0, SEEK_SET);
uint8_t *file = malloc(file_size);
if (fread(file, 1, file_size, in) != file_size) {
fclose(in);
fprintf(stderr, "Failed to read file: %s\n", argv[1]);
exit(1);
}
fclose(in);
uint32_t data_address, data_offset, data_size, data_index;
if (!elf_get_section_range(file, ".data", &data_address, &data_offset, &data_size, &data_index)) {
fprintf(stderr, "section .data not found\n");
exit(1);
}
uint32_t rodata_address, rodata_offset, rodata_size, rodata_index;
if (elf_get_section_range(file, ".rodata", &rodata_address, &rodata_offset, &rodata_size, &rodata_index)) {
fprintf(stderr, ".rodata section found, please put everything in .data instead (non-const variables)\n");
exit(1);
}
uint32_t symtab_address, symtab_offset, symtab_size, symtab_index;
if (!elf_get_section_range(file, ".symtab", &symtab_address, &symtab_offset, &symtab_size, &symtab_index)) {
fprintf(stderr, "section .symtab not found\n");
exit(1);
}
uint32_t strtab_address, strtab_offset, strtab_size, strtab_index;
if (!elf_get_section_range(file, ".strtab", &strtab_address, &strtab_offset, &strtab_size, &strtab_index)) {
fprintf(stderr, "section .strtab not found\n");
exit(1);
}
// IDO might pad the section to the nearest 16 byte boundary,
// but the mio0 data should not include that. Therefore find
// the "real" end by finding where the last symbol ends.
uint32_t last_symbol_end = 0;
for (uint32_t i = 0; i < symtab_size / sizeof(Elf32_Sym); i++) {
Elf32_Sym *symbol = (Elf32_Sym *)(file + symtab_offset + i * sizeof(Elf32_Sym));
#if DEBUG
const char *name = "(null)";
if (symbol->st_name != 0U) {
name = (const char*)file + strtab_offset + u32be(symbol->st_name);
}
printf("%08x\t%08x\t%02x\t%02x\t%02x\t%s\n", u32be(symbol->st_value), u32be(symbol->st_size), symbol->st_info, symbol->st_other, u16be(symbol->st_shndx), name);
#endif
if (ELF_ST_TYPE(symbol->st_info) == STT_OBJECT && u16be(symbol->st_shndx) == data_index) {
uint32_t symbol_end = u32be(symbol->st_value) + u32be(symbol->st_size);
if (symbol_end > last_symbol_end) {
last_symbol_end = symbol_end;
}
}
}
uint32_t mdebug_address, mdebug_offset, mdebug_size, mdebug_index;
if (elf_get_section_range(file, ".mdebug", &mdebug_address, &mdebug_offset, &mdebug_size, &mdebug_index)) {
SymbolicHeader *symbolic_header = (SymbolicHeader *)(file + mdebug_offset);
for (uint32_t i = 0; i < u32be(symbolic_header->ifdMax); i++) {
FileDescriptorTable *fdt = (FileDescriptorTable *)(file + u32be(symbolic_header->cbFdOffset) + i * sizeof(FileDescriptorTable));
for (uint32_t j = 0; j < u32be(fdt->csym); j++) {
LocalSymbolsEntry lse;
memcpy(&lse, file + u32be(symbolic_header->cbSymOffset) + (u32be(fdt->isymBase) + j) * sizeof(LocalSymbolsEntry), sizeof(LocalSymbolsEntry));
uint32_t value = u32be(lse.value);
uint32_t st_sc_index = u32be(lse.st_sc_index);
uint32_t st = (st_sc_index >> 26);
#ifdef DEBUG
uint32_t sc = (st_sc_index >> 21) & 0x1f;
uint32_t index = st_sc_index & 0xfffff;
uint32_t iss = u32be(lse.iss);
const char *symbol_name = file + u32be(symbolic_header->cbSsOffset) + iss;
printf("%s %08x\n", symbol_name, value);
#endif
if (st == stStatic || st == stGlobal) {
// Right now just assume length 8 since it's quite much work to extract the real size
uint32_t symbol_end = value + 8;
if (symbol_end > last_symbol_end) {
last_symbol_end = symbol_end;
}
}
}
}
}
#ifdef DEBUG
printf("Last symbol end: %08x\n", last_symbol_end);
#endif
size_t new_size = last_symbol_end - data_address;
if (new_size + 16 <= data_size) {
// There seems to be more than 16 bytes padding or non-identified data, so abort and take the original size
new_size = data_size;
} else {
// Make sure we don't cut off non-zero bytes
for (size_t i = new_size; i < data_size; i++) {
if (file[data_offset + i] != 0) {
// Must be some symbol missing, so abort and take the original size
new_size = data_size;
break;
}
}
}
FILE *out = fopen(argv[2], "wb");
fwrite(file + data_offset, 1, new_size, out);
fclose(out);
free(file);
return 0;
}

View File

@@ -1,3 +1,6 @@
// WARNING: THIS SCRIPT IS CURRENTLY BROKEN.
// It doesn't handle skyboxes/cake images correctly.
// Usage:
// g++-8 -std=c++17 ./tools/gen_asset_list.cpp -lstdc++fs -O1 -Wall -o tools/gen_asset_list
// ./tools/gen_asset_list
@@ -219,6 +222,7 @@ tuple<string, string, vector<string>> compileSoundData(const string& lang) {
}
int main() {
intentional syntax error; // (see comment at top of file)
map<string, string> assets;
map<string, vector<pair<string, int>>> soundAssets;

158
tools/mario_anims_converter.py Executable file
View File

@@ -0,0 +1,158 @@
#!/usr/bin/env python3
import re
import os
import traceback
import sys
num_headers = 0
items = []
len_mapping = {}
order_mapping = {}
line_number_mapping = {}
def raise_error(filename, lineindex, msg):
raise SyntaxError("Error in " + filename + ":" + str(line_number_mapping[lineindex] + 1) + ": " + msg)
def parse_struct(filename, lines, lineindex, name):
global items, order_mapping
lineindex += 1
if lineindex + 9 >= len(lines):
raise_error(filename, lineindex, "struct Animation must be 11 lines")
v1 = int(lines[lineindex + 0].rstrip(","), 0)
v2 = int(lines[lineindex + 1].rstrip(","), 0)
v3 = int(lines[lineindex + 2].rstrip(","), 0)
v4 = int(lines[lineindex + 3].rstrip(","), 0)
v5 = int(lines[lineindex + 4].rstrip(","), 0)
values = lines[lineindex + 6].rstrip(",")
indices = lines[lineindex + 7].rstrip(",")
items.append(("header", name, (v1, v2, v3, v4, v5, values, indices)))
if lines[lineindex + 9] != "};":
raise_error(filename, lineindex + 9, "Expected \"};\" but got " + lines[lineindex + 9])
order_mapping[name] = len(items)
lineindex += 10
return lineindex
def parse_array(filename, lines, lineindex, name, is_indices):
global items, len_mapping, order_mapping
lineindex += 1
values = []
while lineindex < len(lines) and lines[lineindex] != "};":
line = lines[lineindex].rstrip(",")
if line:
values.extend(line.split(","))
lineindex += 1
if lineindex >= len(lines):
raise_error(filename, lineindex, "Expected \"};\" but reached end of file")
items.append(("array", name, (is_indices, values)))
len_mapping[name] = len(values)
order_mapping[name] = len(items)
lineindex += 1
return lineindex
def parse_file(filename, lines):
global num_headers
lineindex = 0
while lineindex < len(lines):
line = lines[lineindex]
for prefix in ["static ", "const "]:
if line.startswith(prefix):
line = line[len(prefix):]
lines[lineindex] = line
is_struct = line.startswith("struct Animation ") and line.endswith("[] = {")
is_indices = line.startswith("u16 ") and line.endswith("[] = {")
is_values = line.startswith("s16 ") and line.endswith("[] = {")
if not is_struct and not is_indices and not is_values:
raise_error(filename, lineindex, "\"" + line + "\" does not follow the pattern \"static const struct Animation anim_x[] = {\", \"static const u16 anim_x_indices[] = {\" or \"static const s16 anim_x_values[] = {\"")
if is_struct:
name = lines[lineindex][len("struct Animation "):-6]
lineindex = parse_struct(filename, lines, lineindex, name)
num_headers += 1
else:
name = lines[lineindex][len("s16 "):-6]
lineindex = parse_array(filename, lines, lineindex, name, is_indices)
try:
files = os.listdir("assets/anims")
files.sort()
for filename in files:
if filename.endswith(".inc.c"):
lines = []
with open("assets/anims/" + filename) as f:
for i, line in enumerate(f):
line = re.sub(r"/\*.*?\*/", "", line)
if "/*" in line:
line_number_mapping[-1] = i
raise_error(filename, -1, "Multiline comments are not supported")
line = line.split("//", 1)[0].strip()
if line:
line_number_mapping[len(lines)] = i
lines.append(line)
if lines:
parse_file(filename, lines)
structdef = ["u32 numEntries;", "const struct Animation *addrPlaceholder;", "struct OffsetSizePair entries[" + str(num_headers) + "];"]
structobj = [str(num_headers) + ",", "NULL,","{"]
for item in items:
type, name, obj = item
if type == "header":
v1, v2, v3, v4, v5, values, indices = obj
if order_mapping[indices] < order_mapping[name]:
raise SyntaxError("Error: Animation struct must be written before indices array for " + name)
if order_mapping[values] < order_mapping[indices]:
raise SyntaxError("Error: values array must be written after indices array for " + name)
values_num_values = len_mapping[values]
offset_to_struct = "offsetof(struct MarioAnimsObj, " + name + ")"
offset_to_end = "offsetof(struct MarioAnimsObj, " + values + ") + sizeof(gMarioAnims." + values + ")"
structobj.append("{" + offset_to_struct + ", " + offset_to_end + " - " + offset_to_struct + "},")
structobj.append("},")
for item in items:
type, name, obj = item
if type == "header":
v1, v2, v3, v4, v5, values, indices = obj
indices_len = len_mapping[indices] // 6 - 1
values_num_values = len_mapping[values]
offset_to_struct = "offsetof(struct MarioAnimsObj, " + name + ")"
offset_to_end = "offsetof(struct MarioAnimsObj, " + values + ") + sizeof(gMarioAnims." + values + ")"
structdef.append("struct Animation " + name + ";")
structobj.append("{" + ", ".join([
str(v1),
str(v2),
str(v3),
str(v4),
str(v5),
str(indices_len),
"(const s16 *)(offsetof(struct MarioAnimsObj, " + values + ") - " + offset_to_struct + ")",
"(const u16 *)(offsetof(struct MarioAnimsObj, " + indices + ") - " + offset_to_struct + ")",
offset_to_end + " - " + offset_to_struct
]) + "},")
else:
is_indices, arr = obj
type = "u16" if is_indices else "s16"
structdef.append("{} {}[{}];".format(type, name, len(arr)))
structobj.append("{" + ",".join(arr) + "},")
print("#include \"types.h\"")
print("#include \"stddef.h\"")
print("")
print("const struct MarioAnimsObj {")
for s in structdef:
print(s)
print("} gMarioAnims = {")
for s in structobj:
print(s)
print("};")
except Exception as e:
note = "NOTE! The mario animation C files are not processed by a normal C compiler, but by the script in tools/mario_anims_converter.py. The format is much more strict than normal C, so please follow the syntax of existing files.\n"
if e is SyntaxError:
e.msg = note + e.msg
else:
print(note, file=sys.stderr)
traceback.print_exc()
sys.exit(1)

View File

@@ -690,9 +690,9 @@ int main(int argc, char *argv[])
if (config.mode == MODE_IMPORT) {
if (config.truncate) {
fp = fopen(config.bin_filename, "w");
fp = fopen(config.bin_filename, "wb");
} else {
fp = fopen(config.bin_filename, "r+");
fp = fopen(config.bin_filename, "r+b");
}
if (!fp) {
ERROR("Error opening \"%s\"\n", config.bin_filename);
@@ -748,7 +748,7 @@ int main(int argc, char *argv[])
ERROR("Error: must set position width and height for export\n");
return EXIT_FAILURE;
}
fp = fopen(config.bin_filename, "r");
fp = fopen(config.bin_filename, "rb");
if (!fp) {
ERROR("Error opening \"%s\"\n", config.bin_filename);
return -1;

View File

@@ -458,10 +458,10 @@ int main(int argc, char* argv[])
if (config.mode == MODE_IMPORT) {
printf("%s\n", config.bin_filename);
if (config.truncate) {
fp = fopen(config.bin_filename, "w");
fp = fopen(config.bin_filename, "wb");
}
else {
fp = fopen(config.bin_filename, "r+");
fp = fopen(config.bin_filename, "r+b");
}
if (!fp) {
ERROR("Error opening binary file \"%s\"\n", config.bin_filename);
@@ -506,7 +506,7 @@ int main(int argc, char* argv[])
if (config.format == IMG_FORMAT_CI) {
pal_bin_filename = getPaletteFilename(config.bin_filename);
fp_pal = fopen(pal_bin_filename, "w");
fp_pal = fopen(pal_bin_filename, "wb");
INFO("Writing 0x%X bytes to palette file \"%s\"\n", pal_len, pal_bin_filename);
flength = fwrite(pal, 1, pal_len, fp_pal);
if (flength != pal_len) {
@@ -520,7 +520,7 @@ int main(int argc, char* argv[])
ERROR("Error: must set position width and height for export\n");
return EXIT_FAILURE;
}
fp = fopen(config.bin_filename, "r");
fp = fopen(config.bin_filename, "rb");
if (!fp) {
ERROR("Error opening \"%s\"\n", config.bin_filename);
return -1;
@@ -538,7 +538,7 @@ int main(int argc, char* argv[])
case IMG_FORMAT_CI:
// Read Palette file
pal_bin_filename = getPaletteFilename(config.bin_filename);
fp_pal = fopen(pal_bin_filename, "r");
fp_pal = fopen(pal_bin_filename, "rb");
if (!fp_pal) {
ERROR("Error opening \"%s\"\n", pal_bin_filename);
return -1;

651
tools/skyconv.c Normal file

File diff suppressed because it is too large Load Diff