portx64: pd-extract: replaced stdint types with ultratypes

This commit is contained in:
Raf committed 2024-08-02 16:48:35 +08:00
1 parent 06c01208d3
commit 167a4a5d81
7 files changed
+482 -482

No files matched your search

+98 -98
View File
@@ -9,44 +9,44 @@ enum {
};
struct generic_adpcm_book {
int32_t order;
int32_t npredictors;
int16_t book[128];
s32 order;
s32 npredictors;
s16 book[128];
};
struct generic_adpcm_loop {
uint32_t start;
uint32_t end;
uint32_t count;
int16_t state[16];
u32 start;
u32 end;
u32 count;
s16 state[16];
};
struct generic_raw_loop {
uint32_t start;
uint32_t end;
uint32_t count;
u32 start;
u32 end;
u32 count;
};
struct generic_envelope {
int32_t attackTime;
int32_t decayTime;
int32_t releaseTime;
uint8_t attackVolume;
uint8_t decayVolume;
s32 attackTime;
s32 decayTime;
s32 releaseTime;
u8 attackVolume;
u8 decayVolume;
};
struct generic_keymap {
uint8_t velocityMin;
uint8_t velocityMax;
uint8_t keyMin;
uint8_t keyMax;
uint8_t keyBase;
int8_t detune;
u8 velocityMin;
u8 velocityMax;
u8 keyMin;
u8 keyMax;
u8 keyBase;
s8 detune;
};
struct n64_adpcm_waveinfo {
uint32_t loop; // ptr to struct generic_adpcm_loop
uint32_t book; // ptr to struct generic_adpcm_book
u32 loop; // ptr to struct generic_adpcm_loop
u32 book; // ptr to struct generic_adpcm_book
};
struct host_adpcm_waveinfo {
@@ -55,7 +55,7 @@ struct host_adpcm_waveinfo {
};
struct n64_raw_waveinfo {
uint32_t loop; // ptr to struct generic_raw_loop
u32 loop; // ptr to struct generic_raw_loop
};
struct host_raw_waveinfo {
@@ -63,10 +63,10 @@ struct host_raw_waveinfo {
};
struct n64_wavetable {
uint32_t base;
int32_t len;
uint8_t type;
uint8_t flags;
u32 base;
s32 len;
u8 type;
u8 flags;
union {
struct n64_adpcm_waveinfo adpcmWave;
struct n64_raw_waveinfo rawWave;
@@ -75,9 +75,9 @@ struct n64_wavetable {
struct host_wavetable {
uintptr_t base;
int32_t len;
uint8_t type;
uint8_t flags;
s32 len;
u8 type;
u8 flags;
union {
struct host_adpcm_waveinfo adpcmWave;
struct host_raw_waveinfo rawWave;
@@ -85,90 +85,90 @@ struct host_wavetable {
};
struct n64_sound {
uint32_t envelope; // ptr to struct generic_envelope
uint32_t keyMap; // ptr to struct generic_keymap
uint32_t wavetable; // ptr to struct n64_wavetable
uint8_t samplePan;
uint8_t sampleVolume;
uint8_t flags;
u32 envelope; // ptr to struct generic_envelope
u32 keyMap; // ptr to struct generic_keymap
u32 wavetable; // ptr to struct n64_wavetable
u8 samplePan;
u8 sampleVolume;
u8 flags;
};
struct host_sound {
uintptr_t envelope; // ptr to struct generic_envelope
uintptr_t keyMap; // ptr to struct generic_keymap
uintptr_t wavetable; // ptr to struct host_wavetable
uint8_t samplePan;
uint8_t sampleVolume;
uint8_t flags;
u8 samplePan;
u8 sampleVolume;
u8 flags;
};
struct n64_instrument {
uint8_t volume;
uint8_t pan;
uint8_t priority;
uint8_t flags;
uint8_t tremType;
uint8_t tremRate;
uint8_t tremDepth;
uint8_t tremDelay;
uint8_t vibType;
uint8_t vibRate;
uint8_t vibDepth;
uint8_t vibDelay;
int16_t bendRange;
int16_t soundCount;
uint32_t soundArray[1]; // ptr to struct n64_sound
u8 volume;
u8 pan;
u8 priority;
u8 flags;
u8 tremType;
u8 tremRate;
u8 tremDepth;
u8 tremDelay;
u8 vibType;
u8 vibRate;
u8 vibDepth;
u8 vibDelay;
s16 bendRange;
s16 soundCount;
u32 soundArray[1]; // ptr to struct n64_sound
};
struct host_instrument {
uint8_t volume;
uint8_t pan;
uint8_t priority;
uint8_t flags;
uint8_t tremType;
uint8_t tremRate;
uint8_t tremDepth;
uint8_t tremDelay;
uint8_t vibType;
uint8_t vibRate;
uint8_t vibDepth;
uint8_t vibDelay;
int16_t bendRange;
int16_t soundCount;
u8 volume;
u8 pan;
u8 priority;
u8 flags;
u8 tremType;
u8 tremRate;
u8 tremDepth;
u8 tremDelay;
u8 vibType;
u8 vibRate;
u8 vibDepth;
u8 vibDelay;
s16 bendRange;
s16 soundCount;
uintptr_t soundArray[1]; // ptr to struct host_sound
};
struct n64_bank {
int16_t instCount;
uint8_t flags;
uint8_t pad;
int32_t sampleRate;
uint32_t percussion; // ptr to struct n64_instrument
uint32_t instArray[1]; // ptr to struct n64_instrument
s16 instCount;
u8 flags;
u8 pad;
s32 sampleRate;
u32 percussion; // ptr to struct n64_instrument
u32 instArray[1]; // ptr to struct n64_instrument
};
struct host_bank {
int16_t instCount;
uint8_t flags;
uint8_t pad;
int32_t sampleRate;
s16 instCount;
u8 flags;
u8 pad;
s32 sampleRate;
uintptr_t percussion; // ptr to struct host_instrument
uintptr_t instArray[1]; // ptr to struct host_instrument
};
struct n64_bankfile {
int16_t revision;
int16_t bankCount;
uint32_t bankArray[1]; // ptr to struct n64_bank
s16 revision;
s16 bankCount;
u32 bankArray[1]; // ptr to struct n64_bank
};
struct host_bankfile {
int16_t revision;
int16_t bankCount;
s16 revision;
s16 bankCount;
uintptr_t bankArray[1]; // ptr to struct host_bank
};
static int convert_audio_envelope(uint8_t *dst, int dstpos, uint8_t *src, int srcpos)
static int convert_audio_envelope(u8 *dst, int dstpos, u8 *src, int srcpos)
{
struct generic_envelope *n64_envelope = (struct generic_envelope *) &src[srcpos];
struct generic_envelope *host_envelope = (struct generic_envelope *) &dst[dstpos];
@@ -184,7 +184,7 @@ static int convert_audio_envelope(uint8_t *dst, int dstpos, uint8_t *src, int sr
return dstpos;
}
static int convert_audio_keymap(uint8_t *dst, int dstpos, uint8_t *src, int srcpos)
static int convert_audio_keymap(u8 *dst, int dstpos, u8 *src, int srcpos)
{
struct generic_keymap *n64_keymap = (struct generic_keymap *) &src[srcpos];
struct generic_keymap *host_keymap = (struct generic_keymap *) &dst[dstpos];
@@ -201,7 +201,7 @@ static int convert_audio_keymap(uint8_t *dst, int dstpos, uint8_t *src, int srcp
return dstpos;
}
static int convert_audio_adpcm_loop(uint8_t *dst, int dstpos, uint8_t *src, int srcpos)
static int convert_audio_adpcm_loop(u8 *dst, int dstpos, u8 *src, int srcpos)
{
struct generic_adpcm_loop *n64_loop = (struct generic_adpcm_loop *) &src[srcpos];
struct generic_adpcm_loop *host_loop = (struct generic_adpcm_loop *) &dst[dstpos];
@@ -219,7 +219,7 @@ static int convert_audio_adpcm_loop(uint8_t *dst, int dstpos, uint8_t *src, int
return dstpos;
}
static int convert_audio_adpcm_book(uint8_t *dst, int dstpos, uint8_t *src, int srcpos)
static int convert_audio_adpcm_book(u8 *dst, int dstpos, u8 *src, int srcpos)
{
struct generic_adpcm_book *n64_book = (struct generic_adpcm_book *) &src[srcpos];
struct generic_adpcm_book *host_book = (struct generic_adpcm_book *) &dst[dstpos];
@@ -236,7 +236,7 @@ static int convert_audio_adpcm_book(uint8_t *dst, int dstpos, uint8_t *src, int
return dstpos;
}
static int convert_audio_raw_loop(uint8_t *dst, int dstpos, uint8_t *src, int srcpos)
static int convert_audio_raw_loop(u8 *dst, int dstpos, u8 *src, int srcpos)
{
struct generic_raw_loop *n64_loop = (struct generic_raw_loop *) &src[srcpos];
struct generic_raw_loop *host_loop = (struct generic_raw_loop *) &dst[dstpos];
@@ -250,7 +250,7 @@ static int convert_audio_raw_loop(uint8_t *dst, int dstpos, uint8_t *src, int sr
return dstpos;
}
static int convert_audio_wavetable(uint8_t *dst, int dstpos, uint8_t *src, int srcpos)
static int convert_audio_wavetable(u8 *dst, int dstpos, u8 *src, int srcpos)
{
struct n64_wavetable *n64_wavetable = (struct n64_wavetable *) &src[srcpos];
struct host_wavetable *host_wavetable = (struct host_wavetable *) &dst[dstpos];
@@ -291,7 +291,7 @@ static int convert_audio_wavetable(uint8_t *dst, int dstpos, uint8_t *src, int s
return dstpos;
}
static int convert_audio_sound(uint8_t *dst, int dstpos, uint8_t *src, int srcpos)
static int convert_audio_sound(u8 *dst, int dstpos, u8 *src, int srcpos)
{
struct n64_sound *n64_sound = (struct n64_sound *) &src[srcpos];
struct host_sound *host_sound = (struct host_sound *) &dst[dstpos];
@@ -329,7 +329,7 @@ static int convert_audio_sound(uint8_t *dst, int dstpos, uint8_t *src, int srcpo
return dstpos;
}
static int convert_audio_instrument(uint8_t *dst, int dstpos, uint8_t *src, int srcpos)
static int convert_audio_instrument(u8 *dst, int dstpos, u8 *src, int srcpos)
{
struct n64_instrument *n64_instrument = (struct n64_instrument *) &src[srcpos];
struct host_instrument *host_instrument = (struct host_instrument *) &dst[dstpos];
@@ -361,7 +361,7 @@ static int convert_audio_instrument(uint8_t *dst, int dstpos, uint8_t *src, int
return dstpos;
}
static int convert_audio_bank(uint8_t *dst, int dstpos, uint8_t *src, int srcpos)
static int convert_audio_bank(u8 *dst, int dstpos, u8 *src, int srcpos)
{
struct n64_bank *n64_bank = (struct n64_bank *) &src[srcpos];
struct host_bank *host_bank = (struct host_bank *) &dst[dstpos];
@@ -391,7 +391,7 @@ static int convert_audio_bank(uint8_t *dst, int dstpos, uint8_t *src, int srcpos
return dstpos;
}
static int convert_audio_bankfile(uint8_t *dst, uint8_t *src)
static int convert_audio_bankfile(u8 *dst, u8 *src)
{
struct n64_bankfile *n64_bankfile = (struct n64_bankfile *)src;
struct host_bankfile *host_bankfile = (struct host_bankfile *)dst;
@@ -401,21 +401,21 @@ static int convert_audio_bankfile(uint8_t *dst, uint8_t *src)
host_bankfile->bankCount = htodst16(bankCount);
uint32_t dstpos = sizeof(struct host_bankfile) + sizeof(uintptr_t) * (bankCount - 1);
u32 dstpos = sizeof(struct host_bankfile) + sizeof(uintptr_t) * (bankCount - 1);
for (int i = 0; i < bankCount; i++) {
host_bankfile->bankArray[i] = htodst32(dstpos);
uint32_t srcpos = srctoh32(n64_bankfile->bankArray[i]);
u32 srcpos = srctoh32(n64_bankfile->bankArray[i]);
dstpos = convert_audio_bank(dst, dstpos, src, srcpos);
}
return dstpos;
}
uint8_t *preprocessALBankFile_x64(uint8_t *src, uint32_t size, uint32_t *outSize)
u8 *preprocessALBankFile_x64(u8 *src, u32 size, u32 *outSize)
{
size_t dstlen = size * 4;
uint8_t *dst = calloc(1, dstlen);
u8 *dst = calloc(1, dstlen);
*outSize = convert_audio_bankfile(dst, src);
*outSize = ALIGN16(*outSize);
+104 -104
View File
@@ -7,7 +7,7 @@
#include "platform.h"
struct ptrmarker {
uint32_t ptr_src;
u32 ptr_src;
uintptr_t ptr_host;
};
@@ -16,7 +16,7 @@ struct ptrmarker m_PtrMarkers[2048];
int m_NumPtrMarkers;
int m_SizeGDLs;
static void add_marker(uint32_t ptr_src, uintptr_t ptr_host)
static void add_marker(u32 ptr_src, uintptr_t ptr_host)
{
if (m_NumPtrMarkers >= ARRAYCOUNT(m_PtrMarkers)) {
sysLogPrintf(LOG_ERROR, "[BG] Marker limit exceeded");
@@ -77,23 +77,23 @@ static void reset_markers()
*/
struct fileheader {
uint32_t primary_infsize;
uint32_t section1_cmpsize;
uint32_t primary_cmpsize;
u32 primary_infsize;
u32 section1_cmpsize;
u32 primary_cmpsize;
};
struct sectionheader {
uint16_t infsize;
uint16_t cmpsize;
u16 infsize;
u16 cmpsize;
};
struct n64_primaryheader {
uint32_t unused1;
uint32_t ptr_rooms;
uint32_t ptr_portals;
uint32_t ptr_bgcmds;
uint32_t ptr_lights;
uint32_t unused2;
u32 unused1;
u32 ptr_rooms;
u32 ptr_portals;
u32 ptr_bgcmds;
u32 ptr_lights;
u32 unused2;
};
struct host_primaryheader {
@@ -106,63 +106,63 @@ struct host_primaryheader {
};
struct n64_room {
uint32_t ptr_gfxdata;
uint32_t pos[3];
uint8_t br_light_min;
uint8_t br_light_max;
u32 ptr_gfxdata;
u32 pos[3];
u8 br_light_min;
u8 br_light_max;
};
struct host_room {
uintptr_t ptr_gfxdata;
uint32_t pos[3];
uint8_t br_light_min;
uint8_t br_light_max;
u32 pos[3];
u8 br_light_min;
u8 br_light_max;
};
struct portal {
uint16_t verticesoffset;
int16_t roomnum1;
int16_t roomnum2;
uint8_t flags;
u16 verticesoffset;
s16 roomnum1;
s16 roomnum2;
u8 flags;
};
struct portalvertices {
uint8_t count;
uint32_t vertices[1][3];
u8 count;
u32 vertices[1][3];
};
struct bgcmd {
uint8_t type;
uint8_t len;
int32_t param;
u8 type;
u8 len;
s32 param;
};
struct light {
uint16_t roomnum;
uint16_t colour;
uint8_t brightness;
uint8_t sparkable : 1;
uint8_t healthy : 1;
uint8_t on : 1;
uint8_t sparking : 1;
uint8_t vulnerable : 1;
uint8_t brightnessmult;
int8_t dirx;
int8_t diry;
int8_t dirz;
int16_t bbox[4][3];
u16 roomnum;
u16 colour;
u8 brightness;
u8 sparkable : 1;
u8 healthy : 1;
u8 on : 1;
u8 sparking : 1;
u8 vulnerable : 1;
u8 brightnessmult;
s8 dirx;
s8 diry;
s8 dirz;
s16 bbox[4][3];
};
struct n64_roomblock {
uint8_t type;
uint32_t ptr_next;
uint32_t ptr_gdl;
uint32_t ptr_vertices;
uint32_t ptr_colours;
u8 type;
u32 ptr_next;
u32 ptr_gdl;
u32 ptr_vertices;
u32 ptr_colours;
};
struct host_roomblock {
uint8_t type;
u8 type;
uintptr_t ptr_next;
uintptr_t ptr_gdl;
uintptr_t ptr_vertices;
@@ -170,14 +170,14 @@ struct host_roomblock {
};
struct n64_roomgfxdata {
uint32_t ptr_vertices;
uint32_t ptr_colours;
uint32_t ptr_opablocks;
uint32_t ptr_xlublocks;
int16_t lightsindex;
int16_t numlights;
int16_t numvertices;
int16_t numcolours;
u32 ptr_vertices;
u32 ptr_colours;
u32 ptr_opablocks;
u32 ptr_xlublocks;
s16 lightsindex;
s16 numlights;
s16 numvertices;
s16 numcolours;
// roomblocks[]
};
@@ -186,26 +186,26 @@ struct host_roomgfxdata {
uintptr_t ptr_colours;
uintptr_t ptr_opablocks;
uintptr_t ptr_xlublocks;
int16_t lightsindex;
int16_t numlights;
int16_t numvertices;
int16_t numcolours;
s16 lightsindex;
s16 numlights;
s16 numvertices;
s16 numcolours;
// roomblocks[]
};
struct vtx {
int16_t coord[3];
uint8_t flag;
uint8_t color;
uint16_t s;
uint16_t t;
s16 coord[3];
u8 flag;
u8 color;
u16 s;
u16 t;
};
int m_NumRooms;
uint32_t m_AllocSizes[512];
u32 m_AllocSizes[512];
static void convert_primary_rooms(uint8_t *dst, uint32_t *dstpos, uint8_t *src, uint32_t *srcpos)
static void convert_primary_rooms(u8 *dst, u32 *dstpos, u8 *src, u32 *srcpos)
{
struct n64_room *n64_rooms = (struct n64_room *) &src[*srcpos];
struct host_room *host_rooms = (struct host_room *) &dst[*dstpos];
@@ -229,7 +229,7 @@ static void convert_primary_rooms(uint8_t *dst, uint32_t *dstpos, uint8_t *src,
*dstpos += sizeof(*host_rooms) * (m_NumRooms +2);
}
static void convert_primary_portals(uint8_t *dst, uint32_t *dstpos, uint8_t *src, uint32_t *srcpos, uint32_t *src_portalvtxs, uint32_t *dst_portalvtxs)
static void convert_primary_portals(u8 *dst, u32 *dstpos, u8 *src, u32 *srcpos, u32 *src_portalvtxs, u32 *dst_portalvtxs)
{
struct portal *n64_portals = (struct portal *) &src[*srcpos];
struct portal *host_portals = (struct portal *) &dst[*dstpos];
@@ -274,7 +274,7 @@ static void convert_primary_portals(uint8_t *dst, uint32_t *dstpos, uint8_t *src
}
}
static void convert_primary_bgcmds(uint8_t *dst, uint32_t *dstpos, uint8_t *src, uint32_t dst_portalvtxs, uint32_t src_portalvtxs)
static void convert_primary_bgcmds(u8 *dst, u32 *dstpos, u8 *src, u32 dst_portalvtxs, u32 src_portalvtxs)
{
struct bgcmd *n64_cmds = (struct bgcmd *) src;
struct bgcmd *host_cmds = (struct bgcmd *) &dst[*dstpos];
@@ -292,7 +292,7 @@ static void convert_primary_bgcmds(uint8_t *dst, uint32_t *dstpos, uint8_t *src,
host_cmds[i].param = srctodst32(n64_cmds[i].param);
if (host_cmds[i].type == 0x64) {
uint32_t offset = host_cmds[i].param - src_portalvtxs;
u32 offset = host_cmds[i].param - src_portalvtxs;
host_cmds[i].param = dst_portalvtxs + offset;
}
}
@@ -300,7 +300,7 @@ static void convert_primary_bgcmds(uint8_t *dst, uint32_t *dstpos, uint8_t *src,
*dstpos += sizeof(*host_cmds) * num_cmds;
}
static void convert_primary_lights(uint8_t *dst, uint32_t *dstpos, uint8_t *src, uint32_t *srcpos, uint32_t end)
static void convert_primary_lights(u8 *dst, u32 *dstpos, u8 *src, u32 *srcpos, u32 end)
{
struct light *n64_lights = (struct light *) &src[*srcpos];
struct light *host_lights = (struct light *) &dst[*dstpos];
@@ -347,11 +347,11 @@ void relink_ptr(uintptr_t** ptr)
*ptr = marker->ptr_host;
}
static uint32_t convert_section1_roomgfxdata(uint8_t *dst, uint8_t *src, uint32_t infsize, uint32_t src_ofs)
static u32 convert_section1_roomgfxdata(u8 *dst, u8 *src, u32 infsize, u32 src_ofs)
{
reset_markers();
uint32_t dst_roomoffset = src_ofs;
u32 dst_roomoffset = src_ofs;
uintptr_t gdls_addr[64];
int numgdls = 0;
@@ -407,8 +407,8 @@ static uint32_t convert_section1_roomgfxdata(uint8_t *dst, uint8_t *src, uint32_
// block coords
for (size_t i = 0; i < ncoords; i++) {
uint32_t *src_coord = (uint32_t*)(src + curpos_src);
uint32_t *dst_coord = (uint32_t*)(dst + curpos_dst);
u32 *src_coord = (u32*)(src + curpos_src);
u32 *dst_coord = (u32*)(dst + curpos_dst);
dst_coord[0] = srctoh32(src_coord[0]);
dst_coord[1] = srctoh32(src_coord[1]);
@@ -420,8 +420,8 @@ static uint32_t convert_section1_roomgfxdata(uint8_t *dst, uint8_t *src, uint32_
add_marker(curpos_src + src_ofs, curpos_dst + dst_roomoffset);
curpos_src += 6 * sizeof(uint32_t);
curpos_dst += 6 * sizeof(uint32_t);
curpos_src += 6 * sizeof(u32);
curpos_dst += 6 * sizeof(u32);
}
curpos_dst = ALIGN8(curpos_dst);
@@ -492,8 +492,8 @@ static uint32_t convert_section1_roomgfxdata(uint8_t *dst, uint8_t *src, uint32_
if (block->type == BLOCK_LEAF) {
relink_ptr(&block->ptr_gdl);
uint32_t offset_vtx = block->ptr_vertices - ptr_src_vertices - src_ofs;
uint32_t offset_col = block->ptr_colours - ptr_src_colors - src_ofs;
u32 offset_vtx = block->ptr_vertices - ptr_src_vertices - src_ofs;
u32 offset_col = block->ptr_colours - ptr_src_colors - src_ofs;
block->ptr_vertices = ptr_dst_vertices + offset_vtx;
block->ptr_colours = ptr_dst_colors + offset_col;
@@ -513,17 +513,17 @@ static uint32_t convert_section1_roomgfxdata(uint8_t *dst, uint8_t *src, uint32_
return curpos_dst;
}
static uint32_t convert_section1(uint8_t *dst, uint8_t *src, uint32_t ofs)
static u32 convert_section1(u8 *dst, u8 *src, u32 ofs)
{
// Convert primary
uint32_t srcpos = 0;
uint32_t dstpos = 0;
u32 srcpos = 0;
u32 dstpos = 0;
struct host_primaryheader *host_primary_header = (struct host_primaryheader *) dst;
struct n64_primaryheader *n64_primary_header = (struct n64_primaryheader *) src;
srcpos += sizeof(struct n64_primaryheader);
dstpos += sizeof(*host_primary_header);
uint32_t src_bgcmds = srctodst32(n64_primary_header->ptr_bgcmds) - ofs;
u32 src_bgcmds = srctodst32(n64_primary_header->ptr_bgcmds) - ofs;
host_primary_header->unused1 = 0;
host_primary_header->unused2 = 0;
@@ -539,7 +539,7 @@ static uint32_t convert_section1(uint8_t *dst, uint8_t *src, uint32_t ofs)
host_primary_header->ptr_portals = dstpos + ofs;
srcpos = srctodst32(n64_primary_header->ptr_portals) - ofs;
uint32_t src_portalvtxs, dst_portalvtxs;
u32 src_portalvtxs, dst_portalvtxs;
convert_primary_portals(dst, &dstpos, src, &srcpos, &src_portalvtxs, &dst_portalvtxs);
host_primary_header->ptr_bgcmds = dstpos + ofs;
@@ -548,11 +548,11 @@ static uint32_t convert_section1(uint8_t *dst, uint8_t *src, uint32_t ofs)
return dstpos;
}
static void convert_section2_texturenums(uint8_t *dst, uint32_t *dstpos, uint8_t *src, uint32_t *srcpos, uint32_t srclen)
static void convert_section2_texturenums(u8 *dst, u32 *dstpos, u8 *src, u32 *srcpos, u32 srclen)
{
uint16_t *src_ids = (uint16_t *) &src[*srcpos];
uint16_t *dst_ids = (uint16_t *) &dst[*dstpos];
int count = srclen / sizeof(uint16_t);
u16 *src_ids = (u16 *) &src[*srcpos];
u16 *dst_ids = (u16 *) &dst[*dstpos];
int count = srclen / sizeof(u16);
for (int i = 0; i < count; i++) {
dst_ids[i] = srctodst16(src_ids[i]);
@@ -562,10 +562,10 @@ static void convert_section2_texturenums(uint8_t *dst, uint32_t *dstpos, uint8_t
*dstpos += srclen;
}
static void convert_section3_bboxes(uint8_t *dst, uint32_t *dstpos, uint8_t *src, uint32_t *srcpos)
static void convert_section3_bboxes(u8 *dst, u32 *dstpos, u8 *src, u32 *srcpos)
{
int16_t *src_bboxes = (int16_t *) &src[*srcpos];
int16_t *dst_bboxes = (int16_t *) &dst[*dstpos];
s16 *src_bboxes = (s16 *) &src[*srcpos];
s16 *dst_bboxes = (s16 *) &dst[*dstpos];
for (int i = 0; i < m_NumRooms; i++) {
dst_bboxes[i * 6 + 0] = srctodst16(src_bboxes[i * 6 + 0]);
@@ -576,23 +576,23 @@ static void convert_section3_bboxes(uint8_t *dst, uint32_t *dstpos, uint8_t *src
dst_bboxes[i * 6 + 5] = srctodst16(src_bboxes[i * 6 + 5]);
}
*srcpos += sizeof(int16_t) * 6 * (m_NumRooms - 1);
*dstpos += sizeof(int16_t) * 6 * (m_NumRooms - 1);
*srcpos += sizeof(s16) * 6 * (m_NumRooms - 1);
*dstpos += sizeof(s16) * 6 * (m_NumRooms - 1);
}
static void convert_section3_allocsizes(uint8_t *dst, uint32_t *dstpos, uint8_t *src, uint32_t *srcpos)
static void convert_section3_allocsizes(u8 *dst, u32 *dstpos, u8 *src, u32 *srcpos)
{
uint16_t *dst_sizes = (uint16_t *) &dst[*dstpos];
u16 *dst_sizes = (u16 *) &dst[*dstpos];
for (int i = 0; i < m_NumRooms; i++) {
dst_sizes[i] = (m_AllocSizes[i] - 0x100) / 0x10;
}
*srcpos += sizeof(uint16_t) * (m_NumRooms - 1);
*dstpos += sizeof(uint16_t) * (m_NumRooms - 1);
*srcpos += sizeof(u16) * (m_NumRooms - 1);
*dstpos += sizeof(u16) * (m_NumRooms - 1);
}
static void convert_section3_lightcounts(uint8_t *dst, uint32_t *dstpos, uint8_t *src, uint32_t *srcpos)
static void convert_section3_lightcounts(u8 *dst, u32 *dstpos, u8 *src, u32 *srcpos)
{
memcpy(&dst[*dstpos], &src[*srcpos], m_NumRooms);
@@ -601,11 +601,11 @@ static void convert_section3_lightcounts(uint8_t *dst, uint32_t *dstpos, uint8_t
}
#ifdef PLATFORM_64BIT
void preprocessBgSection1(uint8_t *data, uint32_t size, uint32_t ofs)
void preprocessBgSection1(u8 *data, u32 size, u32 ofs)
{
uint8_t *dst = sysMemZeroAlloc(size);
u8 *dst = sysMemZeroAlloc(size);
uint32_t newSize = convert_section1(dst, data, ofs);
u32 newSize = convert_section1(dst, data, ofs);
if (newSize > size) {
sysLogPrintf(LOG_ERROR, "overflow when trying to preprocess a bg file, size %d newsize %d", size, newSize);
@@ -616,11 +616,11 @@ void preprocessBgSection1(uint8_t *data, uint32_t size, uint32_t ofs)
sysMemFree(dst);
}
uint32_t preprocessBgRoom(uint8_t *data, uint32_t size, uint32_t room_ofs)
u32 preprocessBgRoom(u8 *data, u32 size, u32 room_ofs)
{
size *= 2;
uint8_t *dst = sysMemZeroAlloc(size);
uint32_t newSize = convert_section1_roomgfxdata(dst, data, size, room_ofs);
u8 *dst = sysMemZeroAlloc(size);
u32 newSize = convert_section1_roomgfxdata(dst, data, size, room_ofs);
if (newSize > size) {
sysLogPrintf(LOG_ERROR, "overflow when trying to preprocess a bg room, size %d newsize %d", size, newSize);
+14 -14
View File
@@ -4,10 +4,10 @@
#include "common.h"
#include "system.h"
static int get_next_nonzero(uint8_t *src, uint32_t offset, size_t len)
static int get_next_nonzero(u8 *src, u32 offset, size_t len)
{
uint32_t *ptr = (uint32_t *) &src[offset];
uint32_t *end = (uint32_t *) &src[len];
u32 *ptr = (u32 *) &src[offset];
u32 *end = (u32 *) &src[len];
while (ptr < end) {
if (*ptr != 0) {
@@ -20,21 +20,21 @@ static int get_next_nonzero(uint8_t *src, uint32_t offset, size_t len)
return 0;
}
static int get_num_strings(uint8_t *src, size_t len)
static int get_num_strings(u8 *src, size_t len)
{
uint32_t ptr_table_len = get_next_nonzero(src, 0, len);
u32 ptr_table_len = get_next_nonzero(src, 0, len);
if (ptr_table_len) {
return ptr_table_len / sizeof(uint32_t);
return ptr_table_len / sizeof(u32);
}
return 1;
}
uint32_t convert_lang_file(uint8_t *dst, uint8_t *src, size_t srclen)
u32 convert_lang_file(u8 *dst, u8 *src, size_t srclen)
{
// Convert it
uint32_t *src_offsets = (uint32_t *) src;
u32 *src_offsets = (u32 *) src;
size_t src_ptr_table_len = srctoh32(src_offsets[0]);
size_t src_str_table_len = srclen - src_ptr_table_len;
int num_strings = get_num_strings(src, srclen);
@@ -46,14 +46,14 @@ uint32_t convert_lang_file(uint8_t *dst, uint8_t *src, size_t srclen)
uintptr_t *dst_offsets = (uintptr_t *) dst;
for (int i = 0; i < num_strings; i++) {
uint32_t src_offset = srctoh32(src_offsets[i]);
u32 src_offset = srctoh32(src_offsets[i]);
if (src_offset) {
// Write pointer
dst_offsets[i] = htodst32(cur_dst_offset);
// Write string
uint32_t end = get_next_nonzero(src, (i + 1) * 4, num_strings * 4);
u32 end = get_next_nonzero(src, (i + 1) * 4, num_strings * 4);
if (!end) {
end = srclen;
@@ -73,11 +73,11 @@ uint32_t convert_lang_file(uint8_t *dst, uint8_t *src, size_t srclen)
return ALIGN16(cur_dst_offset);
}
uint8_t *preprocessLangFile_x64(uint8_t *data, uint32_t size, uint32_t *outSize) {
uint32_t newSizeEstimated = (uint32_t)(size * 1.3);
uint8_t *dst = sysMemZeroAlloc(newSizeEstimated);
u8 *preprocessLangFile_x64(u8 *data, u32 size, u32 *outSize) {
u32 newSizeEstimated = (u32)(size * 1.3);
u8 *dst = sysMemZeroAlloc(newSizeEstimated);
uint32_t newSize = convert_lang_file(dst, data, size);
u32 newSize = convert_lang_file(dst, data, size);
if (newSize > newSizeEstimated) {
sysLogPrintf(LOG_ERROR, "overflow when trying to preprocess a lang file, size %d newsize %d", size, newSize);
+158 -158
View File
@@ -29,9 +29,9 @@ enum contenttype {
};
struct marker {
uint32_t src_offset;
uint32_t dst_offset;
uint32_t parent_src_offset;
u32 src_offset;
u32 dst_offset;
u32 parent_src_offset;
enum contenttype type;
};
@@ -90,40 +90,40 @@ int m_NumMarkers;
#define MODELNODETYPE_0200 0x0200
struct src_modeldef {
uint32_t ptr_rootnode;
uint32_t ptr_skel;
uint32_t ptr_parts;
int16_t numparts;
int16_t nummatrices;
uint32_t scale;
uint16_t rwdatalen;
uint16_t numtexconfigs;
uint32_t ptr_texconfigs;
u32 ptr_rootnode;
u32 ptr_skel;
u32 ptr_parts;
s16 numparts;
s16 nummatrices;
u32 scale;
u16 rwdatalen;
u16 numtexconfigs;
u32 ptr_texconfigs;
};
struct dst_modeldef {
uintptr_t ptr_rootnode;
uintptr_t ptr_skel;
uintptr_t ptr_parts;
int16_t numparts;
int16_t nummatrices;
uint32_t scale;
uint16_t rwdatalen;
uint16_t numtexconfigs;
s16 numparts;
s16 nummatrices;
u32 scale;
u16 rwdatalen;
u16 numtexconfigs;
uintptr_t ptr_texconfigs;
};
struct src_modelnode {
uint16_t type;
uint32_t ptr_rodata;
uint32_t ptr_parent;
uint32_t ptr_next;
uint32_t ptr_prev;
uint32_t ptr_child;
u16 type;
u32 ptr_rodata;
u32 ptr_parent;
u32 ptr_next;
u32 ptr_prev;
u32 ptr_child;
};
struct dst_modelnode {
uint16_t type;
u16 type;
uintptr_t ptr_rodata;
uintptr_t ptr_parent;
uintptr_t ptr_next;
@@ -132,26 +132,26 @@ struct dst_modelnode {
};
struct generic_rodata_chrinfo {
uint16_t animpart;
int16_t mtxindex;
uint32_t unk04;
uint16_t rwdataindex;
u16 animpart;
s16 mtxindex;
u32 unk04;
u16 rwdataindex;
};
struct generic_rodata_position {
uint32_t pos[3];
uint16_t part;
int16_t mtxindexes[3];
uint32_t drawdist;
u32 pos[3];
u16 part;
s16 mtxindexes[3];
u32 drawdist;
};
struct src_rodata_gundl {
uint32_t ptr_opagdl;
uint32_t ptr_xlugdl;
uint32_t ptr_baseaddr;
uint32_t ptr_vertices;
int16_t numvertices;
int16_t unk12;
u32 ptr_opagdl;
u32 ptr_xlugdl;
u32 ptr_baseaddr;
u32 ptr_vertices;
s16 numvertices;
s16 unk12;
};
struct dst_rodata_gundl {
@@ -159,130 +159,130 @@ struct dst_rodata_gundl {
uintptr_t ptr_xlugdl;
uintptr_t ptr_baseaddr;
uintptr_t ptr_vertices;
int16_t numvertices;
int16_t unk12;
s16 numvertices;
s16 unk12;
};
struct src_rodata_distance {
uint32_t near;
uint32_t far;
uint32_t ptr_target;
uint16_t rwdataindex;
u32 near;
u32 far;
u32 ptr_target;
u16 rwdataindex;
};
struct dst_rodata_distance {
uint32_t near;
uint32_t far;
u32 near;
u32 far;
uintptr_t ptr_target;
uint16_t rwdataindex;
u16 rwdataindex;
};
struct src_rodata_reorder {
uint32_t unk00;
uint32_t unk04;
uint32_t unk08;
uint32_t unk0c[3];
uint32_t ptr_node_unk18;
uint32_t ptr_node_unk1c;
int16_t side;
uint16_t rwdataindex;
u32 unk00;
u32 unk04;
u32 unk08;
u32 unk0c[3];
u32 ptr_node_unk18;
u32 ptr_node_unk1c;
s16 side;
u16 rwdataindex;
};
struct dst_rodata_reorder {
uint32_t unk00;
uint32_t unk04;
uint32_t unk08;
uint32_t unk0c[3];
u32 unk00;
u32 unk04;
u32 unk08;
u32 unk0c[3];
uintptr_t ptr_node_unk18;
uintptr_t ptr_node_unk1c;
int16_t side;
uint16_t rwdataindex;
s16 side;
u16 rwdataindex;
};
struct generic_rodata_bbox {
int32_t hitpart;
uint32_t bbox[6];
s32 hitpart;
u32 bbox[6];
};
struct src_rodata_chrgunfire {
uint32_t pos[3];
uint32_t dim[3];
uint32_t ptr_texture;
uint32_t unk1c;
uint16_t rwdataindex;
uint32_t ptr_baseaddr;
u32 pos[3];
u32 dim[3];
u32 ptr_texture;
u32 unk1c;
u16 rwdataindex;
u32 ptr_baseaddr;
};
struct dst_rodata_chrgunfire {
uint32_t pos[3];
uint32_t dim[3];
u32 pos[3];
u32 dim[3];
uintptr_t ptr_texture;
uint32_t unk1c;
uint16_t rwdataindex;
u32 unk1c;
u16 rwdataindex;
uintptr_t ptr_baseaddr;
};
struct src_rodata_type11 {
uint32_t unk00;
uint32_t unk04;
uint32_t unk08;
uint32_t unk0c;
uint32_t unk10;
uint32_t ptr_unk14;
u32 unk00;
u32 unk04;
u32 unk08;
u32 unk0c;
u32 unk10;
u32 ptr_unk14;
};
struct dst_rodata_type11 {
uint32_t unk00;
uint32_t unk04;
uint32_t unk08;
uint32_t unk0c;
uint32_t unk10;
u32 unk00;
u32 unk04;
u32 unk08;
u32 unk0c;
u32 unk10;
uintptr_t ptr_unk14;
};
struct src_rodata_toggle {
uint32_t ptr_target;
uint16_t rwdataindex;
u32 ptr_target;
u16 rwdataindex;
};
struct dst_rodata_toggle {
uintptr_t ptr_target;
uint16_t rwdataindex;
u16 rwdataindex;
};
struct generic_rodata_positionheld {
uint32_t pos[3];
int16_t mtxindex;
uint32_t unk10;
u32 pos[3];
s16 mtxindex;
u32 unk10;
};
struct src_rodata_stargunfire {
uint32_t unk00;
uint32_t ptr_vertices;
uint32_t ptr_gdl;
uint32_t ptr_baseaddr;
u32 unk00;
u32 ptr_vertices;
u32 ptr_gdl;
u32 ptr_baseaddr;
};
struct dst_rodata_stargunfire {
uint32_t unk00;
u32 unk00;
uintptr_t ptr_vertices;
uintptr_t ptr_gdl;
uintptr_t ptr_baseaddr;
};
struct generic_rodata_headspot {
uint16_t rwdataindex;
u16 rwdataindex;
};
struct src_rodata_dl {
uint32_t ptr_opagdl;
uint32_t ptr_xlugdl;
uint32_t ptr_colours;
uint32_t ptr_vertices; // colours follow this array
int16_t numvertices;
int16_t mcount;
uint16_t rwdataindex;
uint16_t numcolours;
u32 ptr_opagdl;
u32 ptr_xlugdl;
u32 ptr_colours;
u32 ptr_vertices; // colours follow this array
s16 numvertices;
s16 mcount;
u16 rwdataindex;
u16 numcolours;
};
struct dst_rodata_dl {
@@ -290,42 +290,42 @@ struct dst_rodata_dl {
uintptr_t ptr_xlugdl;
uintptr_t ptr_colours;
uintptr_t ptr_vertices; // colours follow this array
int16_t numvertices;
int16_t mcount;
uint16_t rwdataindex;
uint16_t numcolours;
s16 numvertices;
s16 mcount;
u16 rwdataindex;
u16 numcolours;
};
struct generic_rodata_type19 {
uint32_t numvertices;
uint32_t vertices[3];
u32 numvertices;
u32 vertices[3];
};
struct src_texconfig {
uint32_t ptr;
uint8_t width;
uint8_t height;
uint8_t level;
uint8_t format;
uint8_t depth;
uint8_t s;
uint8_t t;
uint8_t unk0b;
u32 ptr;
u8 width;
u8 height;
u8 level;
u8 format;
u8 depth;
u8 s;
u8 t;
u8 unk0b;
};
struct dst_texconfig {
uintptr_t ptr;
uint8_t width;
uint8_t height;
uint8_t level;
uint8_t format;
uint8_t depth;
uint8_t s;
uint8_t t;
uint8_t unk0b;
u8 width;
u8 height;
u8 level;
u8 format;
u8 depth;
u8 s;
u8 t;
u8 unk0b;
};
static struct marker *find_marker(uint32_t src_offset)
static struct marker *find_marker(u32 src_offset)
{
for (int i = 0; i < m_NumMarkers; i++) {
if (m_Markers[i].src_offset == src_offset) {
@@ -336,7 +336,7 @@ static struct marker *find_marker(uint32_t src_offset)
return NULL;
}
static void set_marker(uint32_t src_offset, enum contenttype type, uint32_t parent_src_offset)
static void set_marker(u32 src_offset, enum contenttype type, u32 parent_src_offset)
{
if (src_offset == 0) {
return;
@@ -388,7 +388,7 @@ enum contenttype m_NodeTypeToContentType[] = {
/*0x19*/ CT_RODATA_19,
};
static void populate_markers(uint8_t *src)
static void populate_markers(u8 *src)
{
m_NumMarkers = 0;
@@ -398,13 +398,13 @@ static void populate_markers(uint8_t *src)
struct marker *marker = &m_Markers[i];
void *src_thing = &src[marker->src_offset];
int numvtx = 0;
uint32_t colstart = 0;
u32 colstart = 0;
switch (marker->type) {
case CT_MODELDEF:
struct src_modeldef *src_modeldef = src_thing;
int num_texconfigs = srctoh16(src_modeldef->numtexconfigs);
uint32_t texconfigpos = srctoh32(src_modeldef->ptr_texconfigs);
u32 texconfigpos = srctoh32(src_modeldef->ptr_texconfigs);
set_marker(srctoh32(src_modeldef->ptr_rootnode), CT_NODE, marker->src_offset);
set_marker(srctoh32(src_modeldef->ptr_parts), CT_PARTS, marker->src_offset);
@@ -414,7 +414,7 @@ static void populate_markers(uint8_t *src)
break;
case CT_NODE:
struct src_modelnode *src_node = src_thing;
uint32_t node_type = srctoh16(src_node->type) & 0xff;
u32 node_type = srctoh16(src_node->type) & 0xff;
set_marker(srctoh32(src_node->ptr_rodata), m_NodeTypeToContentType[node_type], marker->src_offset);
set_marker(srctoh32(src_node->ptr_parent), CT_NODE, marker->src_offset);
set_marker(srctoh32(src_node->ptr_next), CT_NODE, marker->src_offset);
@@ -429,7 +429,7 @@ static void populate_markers(uint8_t *src)
break;
case CT_PARTS:
struct src_modeldef *src_modeldef2 = (struct src_modeldef *) src;
uint32_t *src_parts = (uint32_t *) src_thing;
u32 *src_parts = (u32 *) src_thing;
int num_parts = srctoh16(src_modeldef2->numparts);
for (int i = 0; i < num_parts; i++) {
@@ -503,7 +503,7 @@ static void populate_markers(uint8_t *src)
static void sort_markers(void)
{
for (int i = 0; i < m_NumMarkers - 1; i++) {
uint32_t min_offset = 0xffffffff;
u32 min_offset = 0xffffffff;
int min_index = -1;
for (int j = i + 1; j < m_NumMarkers; j++) {
@@ -521,15 +521,15 @@ static void sort_markers(void)
}
}
static uint32_t convert_content(uint8_t *dst, uint8_t *src, uint32_t src_file_len)
static u32 convert_content(u8 *dst, u8 *src, u32 src_file_len)
{
uint32_t dstpos = 0;
u32 dstpos = 0;
for (int i = 0; i < m_NumMarkers; i++) {
struct marker *marker = &m_Markers[i];
void *src_thing = &src[marker->src_offset];
uint32_t src_end = i < m_NumMarkers - 1 ? m_Markers[i + 1].src_offset : src_file_len;
uint32_t src_len = src_end - marker->src_offset;
u32 src_end = i < m_NumMarkers - 1 ? m_Markers[i + 1].src_offset : src_file_len;
u32 src_len = src_end - marker->src_offset;
dstpos = ALIGN(dstpos, m_AlignConfigs[marker->type].before);
@@ -584,16 +584,16 @@ static uint32_t convert_content(uint8_t *dst, uint8_t *src, uint32_t src_file_le
break;
case CT_PARTS:
struct src_modeldef *src_modeldef2 = (struct src_modeldef *) src;
uint32_t *src_parts = (uint32_t *) src_thing;
u32 *src_parts = (u32 *) src_thing;
uintptr_t *dst_parts = (uintptr_t *) dst_thing;
int num_parts = srctoh16(src_modeldef2->numparts);
uint16_t *src_nums = (uint16_t *) &src_parts[num_parts];
uint16_t *dst_nums = (uint16_t *) &dst_parts[num_parts];
u16 *src_nums = (u16 *) &src_parts[num_parts];
u16 *dst_nums = (u16 *) &dst_parts[num_parts];
for (int i = 0; i < num_parts; i++) {
dst_nums[i] = srctodst16(src_nums[i]);
}
dstpos += num_parts * sizeof(uintptr_t) + num_parts * sizeof(uint16_t);
dstpos += num_parts * sizeof(uintptr_t) + num_parts * sizeof(u16);
if (num_parts) {
dstpos = ALIGN8(dstpos);
}
@@ -604,8 +604,8 @@ static uint32_t convert_content(uint8_t *dst, uint8_t *src, uint32_t src_file_le
break;
case CT_GDL:
struct marker *parent = find_marker(marker->parent_src_offset);
uint32_t src_vtx;
uint32_t dst_vtx;
u32 src_vtx;
u32 dst_vtx;
if (parent->type == CT_RODATA_GUNDL) {
struct src_rodata_gundl *src_rodata = (struct src_rodata_gundl *) &src[parent->src_offset];
@@ -754,18 +754,18 @@ static uint32_t convert_content(uint8_t *dst, uint8_t *src, uint32_t src_file_le
case CT_RODATA_19:
struct generic_rodata_type19 *src_type19 = src_thing;
struct generic_rodata_type19 *dst_type19 = dst_thing;
uint32_t *src_vertices = src_thing + sizeof(uint32_t);
uint32_t *dst_vertices = dst_thing + sizeof(uint32_t);
u32 *src_vertices = src_thing + sizeof(u32);
u32 *dst_vertices = dst_thing + sizeof(u32);
int num_vertices = srctoh32(src_type19->numvertices);
dst_type19->numvertices = htodst32(num_vertices);
dstpos += sizeof(uint32_t);
dstpos += sizeof(u32);
for (int i = 0; i < num_vertices; i++) {
dst_vertices[i * 3 + 0] = srctodst32(src_vertices[i * 3 + 0]);
dst_vertices[i * 3 + 1] = srctodst32(src_vertices[i * 3 + 1]);
dst_vertices[i * 3 + 2] = srctodst32(src_vertices[i * 3 + 2]);
dstpos += sizeof(uint32_t) * 3;
dstpos += sizeof(u32) * 3;
}
break;
}
@@ -776,7 +776,7 @@ static uint32_t convert_content(uint8_t *dst, uint8_t *src, uint32_t src_file_le
return dstpos;
}
static uint32_t resolve_pointer(uint32_t src_offset)
static u32 resolve_pointer(u32 src_offset)
{
if (src_offset == 0) {
return 0;
@@ -786,7 +786,7 @@ static uint32_t resolve_pointer(uint32_t src_offset)
return marker ? (0x05000000 | marker->dst_offset) : 0;
}
static void relink_pointers(uint8_t *dst, uint8_t *src)
static void relink_pointers(u8 *dst, u8 *src)
{
for (int i = 0; i < m_NumMarkers; i++) {
struct marker *marker = &m_Markers[i];
@@ -820,7 +820,7 @@ static void relink_pointers(uint8_t *dst, uint8_t *src)
break;
case CT_PARTS:
struct src_modeldef *src_modeldef2 = (struct src_modeldef *) src;
uint32_t *src_parts = (uint32_t *) src_thing;
u32 *src_parts = (u32 *) src_thing;
uintptr_t *dst_parts = (uintptr_t *) dst_thing;
int num_parts = srctoh16(src_modeldef2->numparts);
@@ -918,9 +918,9 @@ static void relink_pointers(uint8_t *dst, uint8_t *src)
}
}
static int convert_model(uint8_t *dst, uint8_t *src, uint32_t srclen)
static int convert_model(u8 *dst, u8 *src, u32 srclen)
{
uint32_t dstpos;
u32 dstpos;
populate_markers(src);
sort_markers();
@@ -931,14 +931,14 @@ static int convert_model(uint8_t *dst, uint8_t *src, uint32_t srclen)
return dstpos;
}
uint8_t *preprocessModelFile_x64(uint8_t *data, uint32_t size, uint32_t *outSize)
u8 *preprocessModelFile_x64(u8 *data, u32 size, u32 *outSize)
{
gbi_reset();
uint32_t newSizeEstimated = (uint32_t)(size * 1.7);
uint8_t *dst = sysMemZeroAlloc(newSizeEstimated);
u32 newSizeEstimated = (u32)(size * 1.7);
u8 *dst = sysMemZeroAlloc(newSizeEstimated);
uint32_t newSize = convert_model(dst, data, size);
u32 newSize = convert_model(dst, data, size);
if (newSize > newSizeEstimated) {
sysLogPrintf(LOG_ERROR, "overflow when trying to preprocess model, size %d newsize %d", size, newSize);
+52 -52
View File
@@ -16,66 +16,66 @@
#define PADFLAG_HASBBOXDATA 0x0200
struct n64_header {
int32_t num_pads;
int32_t num_covers;
uint32_t ptr_waypoints;
uint32_t ptr_waygroups;
uint32_t ptr_cover;
s32 num_pads;
s32 num_covers;
u32 ptr_waypoints;
u32 ptr_waygroups;
u32 ptr_cover;
};
struct host_header {
int32_t num_pads;
int32_t num_covers;
s32 num_pads;
s32 num_covers;
uintptr_t ptr_waypoints;
uintptr_t ptr_waygroups;
uintptr_t ptr_cover;
};
struct padheader {
uint32_t flags : 18;
uint32_t room : 10;
uint32_t liftnum : 4;
u32 flags : 18;
u32 room : 10;
u32 liftnum : 4;
};
struct n64_waypoint {
int32_t padnum;
uint32_t ptr_neighbours;
int32_t groupnum;
int32_t step;
s32 padnum;
u32 ptr_neighbours;
s32 groupnum;
s32 step;
};
struct host_waypoint {
int32_t padnum;
s32 padnum;
uintptr_t ptr_neighbours;
int32_t groupnum;
int32_t step;
s32 groupnum;
s32 step;
};
struct n64_waygroup {
uint32_t ptr_neighbours;
uint32_t ptr_waypoints;
int32_t step;
u32 ptr_neighbours;
u32 ptr_waypoints;
s32 step;
};
struct host_waygroup {
uintptr_t ptr_neighbours;
uintptr_t ptr_waypoints;
int32_t step;
s32 step;
};
struct coverdefinition {
uint32_t pos[3];
uint32_t dir[3];
uint16_t flags;
uint16_t unk1a;
u32 pos[3];
u32 dir[3];
u16 flags;
u16 unk1a;
};
static int convert_pads(uint8_t *dst, int dstpos, uint8_t *src, int srcpos, int num_pads)
static int convert_pads(u8 *dst, int dstpos, u8 *src, int srcpos, int num_pads)
{
uint16_t *src_offsets = (uint16_t *) &src[srcpos];
uint16_t *dst_offsets = (uint16_t *) &dst[dstpos];
u16 *src_offsets = (u16 *) &src[srcpos];
u16 *dst_offsets = (u16 *) &dst[dstpos];
dstpos += num_pads * sizeof(uint16_t);
dstpos += num_pads * sizeof(u16);
for (int i = 0; i < num_pads; i++) {
dstpos = ALIGN4(dstpos);
@@ -84,19 +84,19 @@ static int convert_pads(uint8_t *dst, int dstpos, uint8_t *src, int srcpos, int
dst_offsets[i] = htodst16(dstpos);
// Header
uint32_t n64_padheader = srctoh32(*(uint32_t *) &src[srcpos]);
u32 n64_padheader = srctoh32(*(u32 *) &src[srcpos]);
struct padheader *host_padheader = (struct padheader *) &dst[dstpos];
uint32_t flags = (n64_padheader >> 14) & 0x3ffff;
u32 flags = (n64_padheader >> 14) & 0x3ffff;
*(uint32_t*)host_padheader = htodst32(n64_padheader);
*(u32*)host_padheader = htodst32(n64_padheader);
srcpos += sizeof(struct padheader);
dstpos += sizeof(struct padheader);
// Position
if (flags & PADFLAG_INTPOS) {
int16_t *srcptr = (int16_t *) &src[srcpos];
int16_t *dstptr = (int16_t *) &dst[dstpos];
s16 *srcptr = (s16 *) &src[srcpos];
s16 *dstptr = (s16 *) &dst[dstpos];
dstptr[0] = srctodst16(srcptr[0]);
dstptr[1] = srctodst16(srcptr[1]);
@@ -105,8 +105,8 @@ static int convert_pads(uint8_t *dst, int dstpos, uint8_t *src, int srcpos, int
srcpos += 8;
dstpos += 8;
} else {
uint32_t *srcptr = (uint32_t *) &src[srcpos];
uint32_t *dstptr = (uint32_t *) &dst[dstpos];
u32 *srcptr = (u32 *) &src[srcpos];
u32 *dstptr = (u32 *) &dst[dstpos];
dstptr[0] = srctodst32(srcptr[0]);
dstptr[1] = srctodst32(srcptr[1]);
@@ -118,8 +118,8 @@ static int convert_pads(uint8_t *dst, int dstpos, uint8_t *src, int srcpos, int
// Up
if ((flags & (PADFLAG_UPALIGNTOX | PADFLAG_UPALIGNTOY | PADFLAG_UPALIGNTOZ)) == 0) {
uint32_t *srcptr = (uint32_t *) &src[srcpos];
uint32_t *dstptr = (uint32_t *) &dst[dstpos];
u32 *srcptr = (u32 *) &src[srcpos];
u32 *dstptr = (u32 *) &dst[dstpos];
dstptr[0] = srctodst32(srcptr[0]);
dstptr[1] = srctodst32(srcptr[1]);
@@ -131,8 +131,8 @@ static int convert_pads(uint8_t *dst, int dstpos, uint8_t *src, int srcpos, int
// Look
if ((flags & (PADFLAG_LOOKALIGNTOX | PADFLAG_LOOKALIGNTOY | PADFLAG_LOOKALIGNTOZ)) == 0) {
uint32_t *srcptr = (uint32_t *) &src[srcpos];
uint32_t *dstptr = (uint32_t *) &dst[dstpos];
u32 *srcptr = (u32 *) &src[srcpos];
u32 *dstptr = (u32 *) &dst[dstpos];
dstptr[0] = srctodst32(srcptr[0]);
dstptr[1] = srctodst32(srcptr[1]);
@@ -144,8 +144,8 @@ static int convert_pads(uint8_t *dst, int dstpos, uint8_t *src, int srcpos, int
// Bbox
if (flags & PADFLAG_HASBBOXDATA) {
uint32_t *srcptr = (uint32_t *) &src[srcpos];
uint32_t *dstptr = (uint32_t *) &dst[dstpos];
u32 *srcptr = (u32 *) &src[srcpos];
u32 *dstptr = (u32 *) &dst[dstpos];
dstptr[0] = srctodst32(srcptr[0]);
dstptr[1] = srctodst32(srcptr[1]);
@@ -162,7 +162,7 @@ static int convert_pads(uint8_t *dst, int dstpos, uint8_t *src, int srcpos, int
return dstpos;
}
static int convert_waypoints(uint8_t *dst, int dstpos, uint8_t *src, int srcpos)
static int convert_waypoints(u8 *dst, int dstpos, u8 *src, int srcpos)
{
struct n64_waypoint *n64_waypoints = (struct n64_waypoint *) &src[srcpos];
struct host_waypoint *host_waypoints = (struct host_waypoint *) &dst[dstpos];
@@ -172,7 +172,7 @@ static int convert_waypoints(uint8_t *dst, int dstpos, uint8_t *src, int srcpos)
dstpos += (num_waypoints + 1) * sizeof(struct host_waypoint);
uint32_t *host_neighbours = (uint32_t *) &dst[dstpos];
u32 *host_neighbours = (u32 *) &dst[dstpos];
int n = 0;
for (int i = 0; i < num_waypoints; i++) {
@@ -181,7 +181,7 @@ static int convert_waypoints(uint8_t *dst, int dstpos, uint8_t *src, int srcpos)
host_waypoints[i].groupnum = srctodst32(n64_waypoints[i].groupnum);
host_waypoints[i].step = 0;
uint32_t *n64_neighbours = (uint32_t *) &src[srctoh32(n64_waypoints[i].ptr_neighbours)];
u32 *n64_neighbours = (u32 *) &src[srctoh32(n64_waypoints[i].ptr_neighbours)];
for (int j = 0; n64_neighbours[j] != 0xffffffff; j++) {
host_neighbours[n++] = srctodst32(n64_neighbours[j]);
@@ -201,7 +201,7 @@ static int convert_waypoints(uint8_t *dst, int dstpos, uint8_t *src, int srcpos)
return dstpos;
}
static int convert_waygroups(uint8_t *dst, int dstpos, uint8_t *src, int srcpos)
static int convert_waygroups(u8 *dst, int dstpos, u8 *src, int srcpos)
{
struct n64_waygroup *n64_waygroups = (struct n64_waygroup *) &src[srcpos];
struct host_waygroup *host_waygroups = (struct host_waygroup *) &dst[dstpos];
@@ -212,14 +212,14 @@ static int convert_waygroups(uint8_t *dst, int dstpos, uint8_t *src, int srcpos)
dstpos += (num_waygroups + 1) * sizeof(struct host_waygroup);
// Waygroups and child waypoints
uint32_t *host_waypoints = (uint32_t *) &dst[dstpos];
u32 *host_waypoints = (u32 *) &dst[dstpos];
int n = 0;
for (int i = 0; i < num_waygroups; i++) {
host_waygroups[i].ptr_waypoints = htodst32(dstpos);
host_waygroups[i].step = 0;
uint32_t *n64_waypoints = (uint32_t *) &src[srctoh32(n64_waygroups[i].ptr_waypoints)];
u32 *n64_waypoints = (u32 *) &src[srctoh32(n64_waygroups[i].ptr_waypoints)];
for (int j = 0; n64_waypoints[j] != 0xffffffff; j++) {
host_waypoints[n++] = srctodst32(n64_waypoints[j]);
@@ -236,13 +236,13 @@ static int convert_waygroups(uint8_t *dst, int dstpos, uint8_t *src, int srcpos)
host_waygroups[num_waygroups].step = 0;
// Waygroup neighbours
uint32_t *host_neighbours = (uint32_t *) &dst[dstpos];
u32 *host_neighbours = (u32 *) &dst[dstpos];
n = 0;
for (int i = 0; i < num_waygroups; i++) {
host_waygroups[i].ptr_neighbours = htodst32(dstpos);
uint32_t *n64_neighbours = (uint32_t *) &src[srctoh32(n64_waygroups[i].ptr_neighbours)];
u32 *n64_neighbours = (u32 *) &src[srctoh32(n64_waygroups[i].ptr_neighbours)];
for (int j = 0; n64_neighbours[j] != 0xffffffff; j++) {
host_neighbours[n++] = srctodst32(n64_neighbours[j]);
@@ -256,7 +256,7 @@ static int convert_waygroups(uint8_t *dst, int dstpos, uint8_t *src, int srcpos)
return dstpos;
}
static int convert_cover(uint8_t *dst, int dstpos, uint8_t *src, int srcpos, int num_covers)
static int convert_cover(u8 *dst, int dstpos, u8 *src, int srcpos, int num_covers)
{
struct coverdefinition *n64_covers = (struct coverdefinition *) &src[srcpos];
struct coverdefinition *host_covers = (struct coverdefinition *) &dst[dstpos];
@@ -277,7 +277,7 @@ static int convert_cover(uint8_t *dst, int dstpos, uint8_t *src, int srcpos, int
return dstpos;
}
static int convert_pads_file(uint8_t *dst, uint8_t *src)
static int convert_pads_file(u8 *dst, u8 *src)
{
int dstpos = 0;
struct n64_header *n64_header = (struct n64_header *) src;
+26 -26
View File
@@ -6,37 +6,37 @@
struct tile {
uint8_t type;
uint8_t numvertices;
uint16_t flags;
uint16_t floortype;
uint8_t xmin;
uint8_t ymin;
uint8_t zmin;
uint8_t xmax;
uint8_t ymax;
uint8_t zmax;
uint16_t floorcol;
u8 type;
u8 numvertices;
u16 flags;
u16 floortype;
u8 xmin;
u8 ymin;
u8 zmin;
u8 xmax;
u8 ymax;
u8 zmax;
u16 floorcol;
};
uint32_t convert_tiles(uint8_t *dst, uint8_t *src, size_t srclen)
u32 convert_tiles(u8 *dst, u8 *src, size_t srclen)
{
int num_rooms = srctoh32(*(uint32_t *) src);
int num_rooms = srctoh32(*(u32 *) src);
size_t src_ptr_table_len = (num_rooms + 1) * 4;
size_t dst_ptr_table_len = (num_rooms + 1) * sizeof(uint32_t);
size_t dst_ptr_table_len = (num_rooms + 1) * sizeof(u32);
uint32_t *src_offsets = (uint32_t *) &src[4];
u32 *src_offsets = (u32 *) &src[4];
size_t data_len = srclen - src_ptr_table_len - 4;
*(uint32_t *) dst = htodst32(num_rooms);
*(u32 *) dst = htodst32(num_rooms);
uint32_t *dst_offsets = (uint32_t *) (dst + sizeof(uint32_t));
uint32_t cur_dst_offset = dst_ptr_table_len + sizeof(uint32_t);
u32 *dst_offsets = (u32 *) (dst + sizeof(u32));
u32 cur_dst_offset = dst_ptr_table_len + sizeof(u32);
uint32_t cur_src_offset = srctoh32(src_offsets[0]);
uint32_t end_src_offset = srctoh32(src_offsets[num_rooms]);
u32 cur_src_offset = srctoh32(src_offsets[0]);
u32 end_src_offset = srctoh32(src_offsets[num_rooms]);
int room = 0;
while (1) {
@@ -73,9 +73,9 @@ uint32_t convert_tiles(uint8_t *dst, uint8_t *src, size_t srclen)
// Write tile vertices
for (int i = 0; i < hosttile.numvertices; i++) {
*(int16_t *) &dst[cur_dst_offset + 0] = srctodst16(*(int16_t *) &src[cur_src_offset + 0]);
*(int16_t *) &dst[cur_dst_offset + 2] = srctodst16(*(int16_t *) &src[cur_src_offset + 2]);
*(int16_t *) &dst[cur_dst_offset + 4] = srctodst16(*(int16_t *) &src[cur_src_offset + 4]);
*(s16 *) &dst[cur_dst_offset + 0] = srctodst16(*(s16 *) &src[cur_src_offset + 0]);
*(s16 *) &dst[cur_dst_offset + 2] = srctodst16(*(s16 *) &src[cur_src_offset + 2]);
*(s16 *) &dst[cur_dst_offset + 4] = srctodst16(*(s16 *) &src[cur_src_offset + 4]);
cur_dst_offset += 6;
cur_src_offset += 6;
}
@@ -84,11 +84,11 @@ uint32_t convert_tiles(uint8_t *dst, uint8_t *src, size_t srclen)
return ALIGN16(cur_dst_offset);
}
uint8_t *preprocessTilesFile_x64(uint8_t *data, uint32_t size, uint32_t *outSize)
u8 *preprocessTilesFile_x64(u8 *data, u32 size, u32 *outSize)
{
uint8_t *dst = sysMemZeroAlloc(size);
u8 *dst = sysMemZeroAlloc(size);
uint32_t newSize = convert_tiles(dst, data, size);
u32 newSize = convert_tiles(dst, data, size);
if (newSize > size) {
sysLogPrintf(LOG_ERROR, "overflow when trying to preprocess a tiles file, size %d newsize %d", size, newSize);
+30 -30
View File
@@ -7,44 +7,44 @@
#include "system.h"
struct n64fontchar {
uint8_t index;
int8_t baseline;
uint8_t height;
uint8_t width;
int32_t kerningindex;
uint32_t pixeldata;
u8 index;
s8 baseline;
u8 height;
u8 width;
s32 kerningindex;
u32 pixeldata;
};
struct hostfontchar {
uint8_t index;
int8_t baseline;
uint8_t height;
uint8_t width;
int32_t kerningindex;
u8 index;
s8 baseline;
u8 height;
u8 width;
s32 kerningindex;
uintptr_t pixeldata;
};
struct n64fontcharjpn {
uint16_t index;
int8_t baseline;
uint8_t height;
uint8_t width;
int16_t kerningindex;
uint32_t pixeldata;
u16 index;
s8 baseline;
u8 height;
u8 width;
s16 kerningindex;
u32 pixeldata;
};
struct hostfontcharjpn {
uint16_t index;
int8_t baseline;
uint8_t height;
uint8_t width;
int16_t kerningindex;
u16 index;
s8 baseline;
u8 height;
u8 width;
s16 kerningindex;
uintptr_t pixeldata;
};
struct fontdef {
const char *name;
uint32_t offsets[3];
u32 offsets[3];
int pal_extra_chars;
};
@@ -64,24 +64,24 @@ u8* preprocessFont_x64(u8 *src, u32 srclen, u32 *outSize)
#endif
size_t dstlen = srclen - (num_chars * sizeof(struct n64fontchar)) + (num_chars * sizeof(struct hostfontchar)) + 0x20;
uint8_t* dst = sysMemZeroAlloc(dstlen);
u8* dst = sysMemZeroAlloc(dstlen);
// Kerning table
int32_t *src_kerning_table = (int32_t *)src;
int32_t *dst_kerning_table = (int32_t *)dst;
s32 *src_kerning_table = (s32 *)src;
s32 *dst_kerning_table = (s32 *)dst;
for (int i = 0; i < 13 * 13; i++) {
dst_kerning_table[i] = srctodst32(src_kerning_table[i]);
}
uint32_t src_offset = ALIGN(13 * 13 * 4, sizeof(uint32_t));
uint32_t dst_offset = ALIGN(13 * 13 * 4, sizeof(uintptr_t));
u32 src_offset = ALIGN(13 * 13 * 4, sizeof(u32));
u32 dst_offset = ALIGN(13 * 13 * 4, sizeof(uintptr_t));
// Character table
#if VERSION == VERSION_JPN_FINAL
struct n64fontcharjpn *src_char_table = (struct n64fontcharjpn *) &src[src_offset];
struct hostfontcharjpn *dst_char_table = (struct hostfontcharjpn *) &dst[dst_offset];
uint32_t diff = (dst_offset + num_chars * sizeof(struct hostfontcharjpn)) - (src_offset + num_chars * sizeof(struct n64fontcharjpn));
u32 diff = (dst_offset + num_chars * sizeof(struct hostfontcharjpn)) - (src_offset + num_chars * sizeof(struct n64fontcharjpn));
for (int i = 0; i < num_chars; i++) {
dst_char_table[i].index = srctodst16(src_char_table[i].index);
@@ -97,7 +97,7 @@ u8* preprocessFont_x64(u8 *src, u32 srclen, u32 *outSize)
#else
struct n64fontchar *src_char_table = (struct n64fontchar *) &src[src_offset];
struct hostfontchar *dst_char_table = (struct hostfontchar *) &dst[dst_offset];
uint32_t diff = (dst_offset + num_chars * sizeof(struct hostfontchar)) - (src_offset + num_chars * sizeof(struct n64fontchar));
u32 diff = (dst_offset + num_chars * sizeof(struct hostfontchar)) - (src_offset + num_chars * sizeof(struct n64fontchar));
for (int i = 0; i < num_chars; i++) {
dst_char_table[i].index = src_char_table[i].index;