Skip to content

Commit

Permalink
Fix UB
Browse files Browse the repository at this point in the history
  • Loading branch information
Gillou68310 committed Oct 28, 2024
1 parent e973e12 commit f9a6fac
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 8 deletions.
10 changes: 10 additions & 0 deletions src/code0/17B30.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,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;
u8 cond1, cond2, cond3, cond4;
u8 m;

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

m = 0;
ptr = &D_80197E40[gActorSpriteMap[spritenum]];
i = gpSprite[spritenum].unk16;
Expand Down
9 changes: 9 additions & 0 deletions src/code0/1A7C0.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,14 +874,23 @@ void drawString(s16 x, s16 y, char *string)
{
for (ptr = string, x = 0; *ptr != 0; ptr++)
{
#ifdef AVOID_UB
char c = toupper(*ptr);
if (c == ' ')
#else
*ptr = toupper(*ptr);
if (*ptr == ' ')
#endif
{
i = 7;
}
else
{
#ifdef AVOID_UB
switch (c)
#else
switch (*ptr)
#endif
{
case 'M':
case 'W':
Expand Down
45 changes: 38 additions & 7 deletions src/code0/41940.c
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,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 @@ -3108,7 +3115,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 @@ -3197,7 +3209,10 @@ s32 func_80047820(s32 spritenum1, s32 spritenum2, s32 arg2)
goto label1;
}
label2:
gActor[gActorSpriteMap[spritenum2]].unk98 = 0xFF;
#ifdef AVOID_UB
if (gActorSpriteMap[spritenum2] >= 0)
#endif
gActor[gActorSpriteMap[spritenum2]].unk98 = 0xFF;
lotag = gpSprite[spritenum1].lotag;
cond2 = 0;
cond2 = ((lotag == 3) || (lotag == 4) || (lotag == 16) || (lotag == 5) ||
Expand Down Expand Up @@ -3820,6 +3835,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 = gActorSpriteMap[gpSprite[spritenum2].hitag];
Expand All @@ -3829,6 +3848,7 @@ s32 func_800494DC(s32 spritenum1, s32 arg1, s32 spritenum2, s32 arg3)
arg1 = (arg1 * k) / 100;
}
}
}
}

if (arg1 >= 5)
Expand Down Expand Up @@ -4954,9 +4974,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)gActor[gActorSpriteMap[spritenum]].unk2E;
if ((j & 0xC000) && ((j - 0xC000) <= 0))
func_8004CB3C(j);
#ifdef AVOID_UB
if (gActorSpriteMap[spritenum] >= 0)
#endif
{
j = (u16)gActor[gActorSpriteMap[spritenum]].unk2E;
if ((j & 0xC000) && ((j - 0xC000) <= 0))
func_8004CB3C(j);
}

cond = 0;
if (sp2C == 0)
Expand Down Expand Up @@ -5949,7 +5974,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
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
13 changes: 12 additions & 1 deletion src/code0/96A80.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,18 @@ void func_800965F8(s32 spritenum)
xpos = gPlayer[0].xpos;
ypos = gPlayer[0].ypos;
z = gpSprite[gPlayer[0].unk4A].z;
actor = &gActor[gActorSpriteMap[spritenum]];

#ifdef AVOID_UB
if (gActorSpriteMap[spritenum] < 0)
{
actor = NULL;
}
else
#endif
{
actor = &gActor[gActorSpriteMap[spritenum]];
}

ptr2 = &D_8013B2D0[spritenum];

if (i == 302)
Expand Down
10 changes: 10 additions & 0 deletions src/code0/A06F0.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ static void func_800A0014(void)
drawString2((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 @@ -419,7 +422,11 @@ static void func_800A0698(void)
/*800A0BD4*/
static void _drawMapStrInfo(s16 x, s16 y, char *arg2)
{
#ifdef AVOID_UB
char buffer[64];
#else
char buffer[32];
#endif
s16 i, j;

j = 0;
Expand Down Expand Up @@ -662,6 +669,9 @@ void drawHud(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
11 changes: 11 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
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

0 comments on commit f9a6fac

Please # to comment.