Skip to content

Commit

Permalink
Fix UB
Browse files Browse the repository at this point in the history
  • Loading branch information
Gillou68310 committed Jun 1, 2024
1 parent 7cd9329 commit b20727d
Show file tree
Hide file tree
Showing 15 changed files with 161 additions and 43 deletions.
7 changes: 5 additions & 2 deletions src/code0/16FF0.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ void func_800163F0(u8 arg0)

for (i = 0; i < 16; i++)
{
if (pal[i] == 0xF83F)
pal[i] = 0x8420;
#if SYS_ENDIAN == SYS_BIG_ENDIAN
if (pal[i] == 0xF83F) pal[i] = 0x8420;
#else
if (pal[i] == 0x3FF8) pal[i] = 0x2084;
#endif
}
gDPLoadTLUT_pal16(gpDisplayList++, 0, ptr);
}
Expand Down
10 changes: 10 additions & 0 deletions src/code0/17B30.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,23 @@ void func_80017268(s16 spritenum)
_D8D20UnkStruct2 *ptr4;
_D8D20UnkStruct2 *ptr7;
_D8D20UnkStruct2 *ptr5;

#ifdef AVOID_UB
_D8D20UnkStruct2 *ptr6 = NULL;
#else
_D8D20UnkStruct2 *ptr6;
#endif

s32 r;
s16 i, j, k, l;
u8 cond1, cond2, cond3, cond4;
u8 m;

#ifdef AVOID_UB
if (D_80106D50[spritenum] < 0)
return;
#endif

m = 0;
ptr = &D_80197E40[D_80106D50[spritenum]];
i = gpSprite[spritenum].unk16;
Expand Down
45 changes: 38 additions & 7 deletions src/code0/41940.c
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,14 @@ static s32 func_80042C18(s32 spritenum)
static s32 func_80042C98(s32 spritenum)
{
u16 cstat2;
s16 hitsect, hitwall, hitsprite;
s16 hitsect, hitwall;

#ifdef AVOID_UB
s16 hitsprite = 0;
#else
s16 hitsprite;
#endif

s32 hitx, hity, hitz;
s32 vx, vy, vz;

Expand Down Expand Up @@ -3107,7 +3114,12 @@ s32 func_80047820(s32 spritenum1, s32 spritenum2, s32 arg2)
s32 lotag;
u8 cond;
s32 nexti;
s32 i, j, k, l, m, n;
s32 j, k, l, m, n;
#ifdef AVOID_UB
s32 i = 0;
#else
s32 i;
#endif

ret = 0;
spr = &gpSprite[spritenum1];
Expand Down Expand Up @@ -3196,7 +3208,10 @@ s32 func_80047820(s32 spritenum1, s32 spritenum2, s32 arg2)
goto label1;
}
label2:
D_8019B940[D_80106D50[spritenum2]].unk98 = 0xFF;
#ifdef AVOID_UB
if (D_80106D50[spritenum2] >= 0)
#endif
D_8019B940[D_80106D50[spritenum2]].unk98 = 0xFF;
lotag = gpSprite[spritenum1].lotag;
cond2 = 0;
cond2 = ((lotag == 3) || (lotag == 4) || (lotag == 16) || (lotag == 5) ||
Expand Down Expand Up @@ -3819,6 +3834,10 @@ s32 func_800494DC(s32 spritenum1, s32 arg1, s32 spritenum2, s32 arg3)

if (!cond2)
{
#ifdef AVOID_UB
if (gpSprite[spritenum2].hitag < MAXSPRITES)
#endif
{
if (gpSprite[spritenum2].hitag >= 0)
{
m = D_80106D50[gpSprite[spritenum2].hitag];
Expand All @@ -3828,6 +3847,7 @@ s32 func_800494DC(s32 spritenum1, s32 arg1, s32 spritenum2, s32 arg3)
arg1 = (arg1 * k) / 100;
}
}
}
}

if (arg1 >= 5)
Expand Down Expand Up @@ -4953,9 +4973,14 @@ void func_8004BFDC(s32 spritenum, s32 arg1, s32 z, s32 arg3)
else
func_8008E3E0(x1, y1, z1, gpSprite[spritenum].sectnum, 39, 0);

j = (u16)D_8019B940[D_80106D50[spritenum]].unk2E;
if ((j & 0xC000) && ((j - 0xC000) <= 0))
func_8004CB3C(j);
#ifdef AVOID_UB
if (D_80106D50[spritenum] >= 0)
#endif
{
j = (u16)D_8019B940[D_80106D50[spritenum]].unk2E;
if ((j & 0xC000) && ((j - 0xC000) <= 0))
func_8004CB3C(j);
}

cond = 0;
if (sp2C == 0)
Expand Down Expand Up @@ -5952,7 +5977,13 @@ void func_8004F044(void)
{
s32 sp10;
SpriteType *spr;
s16 i, j, nexti, temp;
s16 i, j, nexti;

#ifdef AVOID_UB
s16 temp = 0;
#else
s16 temp;
#endif

D_801C0D68 = 0;
D_8012FD88++;
Expand Down
11 changes: 5 additions & 6 deletions src/code0/59D40.c
Original file line number Diff line number Diff line change
Expand Up @@ -2336,23 +2336,22 @@ void func_8005F38C(s32 spritenum, s32 arg1)
void func_8005F560(s32 spritenum, s32 arg1)
{
s16 sectnum;
s32 temp_s0;
s32 x, y, z;
s32 ang;
s32 a, b, c, d;
s32 a, b, c, d, e;

updateSector(0x70FE, 0xA102, &sectnum);
if (D_8012FD88 & 1)
{
z = -0x18DB0;
y = 0xA102;
ang = krand() & 0x3FF;
temp_s0 = (krand() & 0x3FF) + 0x3E8;
temp_s0 = temp_s0 + (krand() & 0x7FF);
e = (krand() & 0x3FF) + 1000;
e = e + (krand() & 0x7FF);
a = ang + 512;
x = gpSinTable[a]; /*FAKEMATCH*/
x = temp_s0 * gpSinTable[a];
c = (temp_s0 * gpSinTable[ang]) >> 14;
x = e * gpSinTable[a];
c = (e * gpSinTable[ang]) >> 14;
x = x >> 14;
b = krand() & 0x7FFF;
y += c;
Expand Down
1 change: 0 additions & 1 deletion src/code0/6ACA0.c
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,6 @@ static void func_8006B278(s16 spritenum)
static void func_8006B384(s32 spritenum)
{
s32 i, x, y;
s32 ret;
u16 num;

num = gpSprite[spritenum].picnum - 1293;
Expand Down
4 changes: 2 additions & 2 deletions src/code0/6D9E0.c
Original file line number Diff line number Diff line change
Expand Up @@ -2715,7 +2715,7 @@ static void func_80074C70(s32 spritenum)
SpriteType *spr;
s16 ang, num2;
s32 ang2, num, i, point2;
s16 cstat, cstat2;
s16 cstat;

spr = &gpSprite[spritenum];
i = spr->unk22 & 0x7F;
Expand Down Expand Up @@ -4319,7 +4319,7 @@ static void func_80078F84(s32 spritenum)
{
s32 ceilz, ceilhit, florz, florhit;
SpriteType *spr;
s32 num, ang, ang2;
s32 num, ang;
u16 cstat;
s32 temp;

Expand Down
7 changes: 7 additions & 0 deletions src/code0/82480.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,9 +617,16 @@ static void func_80083430(s32 arg0, _119280UnkStruct1 *arg1, s32 arg2, s32 arg3,
code0UnkStruct20 sp30;
code0UnkStruct16 sp48;
s32 i;

#ifdef AVOID_UB
u8 *ptr1 = NULL;
u8 *ptr2 = NULL;
u8 *ptr3 = NULL;
#else
u8 *ptr1;
u8 *ptr2;
u8 *ptr3;
#endif

D_801AE52C = arg6;
switch (arg0)
Expand Down
4 changes: 4 additions & 0 deletions src/code0/9410.c
Original file line number Diff line number Diff line change
Expand Up @@ -1608,6 +1608,7 @@ static void initTileMap(void)
/*8000E160*/
static void initTiles(void)
{
#ifdef TARGET_N64
s32 i;

initTileMap();
Expand All @@ -1616,6 +1617,9 @@ static void initTiles(void)
gpTileInfo[i].ramaddr = NULL;
D_80169580[i] = 0;
}
#else
initTileMap();
#endif
}

/*8000E1B4*/
Expand Down
22 changes: 16 additions & 6 deletions src/code0/96A80.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,7 @@ void func_800965F8(s32 spritenum)
code0UnkStruct3 *ptr;
code0UnkStruct5 *ptr2;

s32 i, j, k, l, m, n;
s32 temp_v0_13;
s32 i, j, k, l, m, n, o;
s32 ang, ang2;
s32 xpos, ypos;
s32 z;
Expand All @@ -317,7 +316,18 @@ void func_800965F8(s32 spritenum)
xpos = gPlayer[0].xpos;
ypos = gPlayer[0].ypos;
z = gpSprite[gPlayer[0].unk4A].z;
ptr = &D_8019B940[D_80106D50[spritenum]];

#ifdef AVOID_UB
if (D_80106D50[spritenum] < 0)
{
ptr = NULL;
}
else
#endif
{
ptr = &D_8019B940[D_80106D50[spritenum]];
}

ptr2 = &D_8013B2D0[spritenum];

if (i == 302)
Expand Down Expand Up @@ -1771,14 +1781,14 @@ void func_800965F8(s32 spritenum)
func_80047820(spritenum, (i + 0x4000) & 0xFFFF, 1000);

func_8009635C(spritenum, 9500, 900);
temp_v0_13 = func_800962D0(spr, 360);
k = temp_v0_13 - 8000;
o = func_800962D0(spr, 360);
k = o - 8000;
if (spr->z >= k)
{
spr->z = k;
spr->unk1A = 0;
}
else if ((temp_v0_13 - spr->z) <= 49999)
else if ((o - spr->z) <= 49999)
{
if (k != spr->z)
spr->unk1A += 400;
Expand Down
6 changes: 6 additions & 0 deletions src/code0/A06F0.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@ static void func_800A0014(void)
displayMessage2((D_80119A94 + 80), (D_80199944 + 145), sp20);
gDPSetTextureLUT(gpDisplayList++, G_TT_RGBA16);
gDPSetCombineMode(gpDisplayList++, G_CC_DECALRGBA, G_CC_PASS2);
#ifdef AVOID_UB
D_801A2688 = 0;
#endif
func_8001D238(D_80119A94 + 210, D_80199944 + 145, 3997);
func_8001D238(D_80119A94 + 230, D_80199944 + 145, 3998);
}
Expand Down Expand Up @@ -661,6 +664,9 @@ void func_800A0F84(void)

if (D_8012C470 == 1)
{
#ifdef AVOID_UB
D_801A2688 = 0;
#endif
func_8001D238(D_80119A94 + 20, D_80199944 + 200, 5692);
o = 36;
}
Expand Down
15 changes: 15 additions & 0 deletions src/code0/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,24 @@
#include "code1/EB300.h"
#include "code1/code1.h"

#ifdef AVOID_UB
#define DMA_LEN 16384
#define SFX_BANK_SIZE 131072
#define SFX_PBANK_SIZE 262144
#define AUDIO_HEAP_SIZE 163840
#define MUSIC_PBANK_SIZE 32768
#define MUSIC_BUFFER_SIZE 16384
#define AMBIENT_PBANK_SIZE 16384
#else
#define DMA_LEN 16384
#define SFX_BANK_SIZE 54152
#define SFX_PBANK_SIZE 167600
#define AUDIO_HEAP_SIZE 163840
#define MUSIC_PBANK_SIZE 16400
#define MUSIC_BUFFER_SIZE 8496
#define AMBIENT_PBANK_SIZE 3836
#endif

#define AMBIENT_BUFFER_SIZE 10000

typedef struct {
Expand Down Expand Up @@ -391,7 +402,9 @@ void playMusic(s32 musicnum)
if (gMusicVolume != 0)
{
MusHandleStop(gMusicHandle, 0);
#ifdef TARGET_N64
while (MusHandleAsk(gMusicHandle));
#endif

if (musicnum < 0)
gMusicHandle = 0;
Expand Down Expand Up @@ -430,7 +443,9 @@ void playMusic(s32 musicnum)
void playAmbient(s32 ambientnum)
{
MusHandleStop(gAmbientHandle, 0);
#ifdef TARGET_N64
while (MusHandleAsk(gAmbientHandle));
#endif

if (ambientnum < 0)
gAmbientHandle = 0;
Expand Down
7 changes: 7 additions & 0 deletions src/code0/edl.c
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,13 @@ void edl_80081688(void *handle, s32 id)
edlUnkStruct1 *info;

info = &D_800E0D18[id];
#ifndef TARGET_N64
if((info->handle != NULL) && (*info->handle != NULL))
{
*(u8**)handle = *info->handle;
return;
}
#endif
size = info->romend - info->romstart;
if (size > EDL_FILE_MAX_SIZE)
{
Expand Down
5 changes: 5 additions & 0 deletions src/code0/engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,12 @@ s32 hitScan(s32 xs, s32 ys, s32 zs, s16 sectnum, s32 vx, s32 vy, s32 vz,
/*8002F1B4*/
s32 nearTag(s32 xs, s32 ys, s32 zs, s16 sectnum, s16 ange, s16 *neartagsector, s16 *neartagwall, s16 *neartagsprite, s32 *neartaghitdist, s32 neartagrange, u8 tagsearch)
{
#ifdef AVOID_UB
ModelInfo *ptr = NULL;
#else
ModelInfo *ptr;
#endif

WallType *wal2;
WallType *wall;
SpriteType *spr;
Expand Down
Loading

0 comments on commit b20727d

Please sign in to comment.