mirror of
https://github.com/HarbourMasters/SpaghettiKart
synced 2026-08-09 03:05:47 -04:00
Fix menu bug & kart textures (#32)
* Fix menu bug * Fix undefined behaviour * Fix kart textures * Fix boost texture * Rename as per review * Fix buffer overflows --------- Co-authored-by: MegaMech <7255464+MegaMech@users.noreply.github.com>
This commit is contained in:
+63
-31
@@ -1401,7 +1401,8 @@ void func_80091B78(void) {
|
||||
D_8018EDF5 = 5;
|
||||
D_8018EDF6 = 10;
|
||||
if (osEepromProbe(&gSIEventMesgQueue) != 0) {
|
||||
load_save_data();
|
||||
// save data disabled for now due to array overflow
|
||||
//load_save_data();
|
||||
}
|
||||
if (func_80091D74() != 0) {
|
||||
gMenuSelection = CONTROLLER_PAK_MENU;
|
||||
@@ -1638,19 +1639,29 @@ void func_80092290(s32 arg0, s32 *arg1, s32 *arg2) {
|
||||
}
|
||||
//vtx = (Vtx *) segmented_to_virtual_dupe_2(&v1[0]);
|
||||
|
||||
|
||||
temp_v1 = (*arg1 * 2) + 2;
|
||||
|
||||
//! @bug vtx array overflow temp fix
|
||||
if ((vtx+temp_v1) >= 54) {
|
||||
return;
|
||||
}
|
||||
temp_t6 = (vtx+temp_v1)->v.cn[0] * (256 - *arg2);
|
||||
temp_t9 = (vtx+temp_v1)->v.cn[1] * (256 - *arg2);
|
||||
temp_t7 = (vtx+temp_v1)->v.cn[2] * (256 - *arg2);
|
||||
temp_t8_2 = (vtx+temp_v1)->v.cn[3] * (256 - *arg2);
|
||||
|
||||
|
||||
temp_v1 = (((*arg1 * 2) + 2) % 6) + 2;
|
||||
a = ((vtx+temp_v1)->v.cn[0] * *arg2);
|
||||
b = ((vtx+temp_v1)->v.cn[1] * *arg2);
|
||||
c = ((vtx+temp_v1)->v.cn[2] * *arg2);
|
||||
d = ((vtx+temp_v1)->v.cn[3] * *arg2);
|
||||
|
||||
//! @bug vtx array overflow temp fix
|
||||
if ((vtx+idx) >= 54) {
|
||||
return;
|
||||
}
|
||||
|
||||
(vtx+idx)->v.cn[0] = (temp_t6 + a) / 256;
|
||||
(vtx+idx)->v.cn[1] = (temp_t9 + b) / 256;
|
||||
@@ -3606,7 +3617,7 @@ void func_80099184(MkTexture *arg0)
|
||||
while (var_s1->textureData != NULL) {
|
||||
var_a1 = 0;
|
||||
for (var_v0 = 0; var_v0 < gNumD_8018E118Entries; var_v0++) {
|
||||
if ( var_s1->textureData == (thing+var_v0)->textureData) {
|
||||
if (var_s1->textureData == (thing+var_v0)->textureData) {
|
||||
var_a1 = 1;
|
||||
break;
|
||||
}
|
||||
@@ -3624,10 +3635,13 @@ void func_80099184(MkTexture *arg0)
|
||||
}
|
||||
//dma_copy_base_729a30(var_s1->textureData, var_a1_2, D_8018D9B4);
|
||||
//mio0decode(D_8018D9B4, &D_8018D9B0[gD_8018E118TotalSize]);
|
||||
memcpy(&D_8018D9B0[gD_8018E118TotalSize], var_s1->textureData, var_a1_2);
|
||||
//size_t texSize = ResourceGetTexSizeByName(var_s1->textureData);
|
||||
//memcpy(&D_8018D9B0[gD_8018E118TotalSize], var_s1->textureData, texSize);
|
||||
strcpy(&D_8018D9B0[gD_8018E118TotalSize], var_s1->textureData);
|
||||
} else {
|
||||
//dma_copy_base_729a30(var_s1->textureData, (var_s1->height * var_s1->width) * 2, &D_8018D9B0[gD_8018E118TotalSize]);
|
||||
memcpy(&D_8018D9B0[gD_8018E118TotalSize], var_s1->textureData, var_s1->width * var_s1->height*2);
|
||||
//memcpy(&D_8018D9B0[gD_8018E118TotalSize], var_s1->textureData, var_s1->width * var_s1->height*2);
|
||||
strcpy(&D_8018D9B0[gD_8018E118TotalSize], var_s1->textureData);
|
||||
}
|
||||
thing[gNumD_8018E118Entries].textureData = var_s1->textureData;
|
||||
thing[gNumD_8018E118Entries].offset = gD_8018E118TotalSize;
|
||||
@@ -3744,7 +3758,7 @@ void func_800996BC(MkTexture *arg0, s32 arg1) {
|
||||
s32 var_a1;
|
||||
u8 var_v0_2;
|
||||
MkTexture *texture;
|
||||
struct_8018E118_entry *thing;
|
||||
struct_8018E118_entry *thing = &D_8018E118[0];
|
||||
|
||||
texture = segmented_to_virtual_dupe(arg0);
|
||||
|
||||
@@ -3759,8 +3773,7 @@ void func_800996BC(MkTexture *arg0, s32 arg1) {
|
||||
while (texture->textureData != NULL) {
|
||||
var_a1 = 0;
|
||||
for (var_v0 = 0; var_v0 < gNumD_8018E118Entries; var_v0++) {
|
||||
// wtf is going on here?
|
||||
if (D_8018E118[var_v0].textureData == (*texture).textureData) {
|
||||
if (texture->textureData == (thing+var_v0)->textureData) {
|
||||
var_a1 = 1;
|
||||
break;
|
||||
}
|
||||
@@ -3807,10 +3820,8 @@ void func_800996BC(MkTexture *arg0, s32 arg1) {
|
||||
break;
|
||||
}
|
||||
|
||||
thing = &D_8018E118[gNumD_8018E118Entries];
|
||||
thing->textureData = texture->textureData;
|
||||
thing = &D_8018E118[gNumD_8018E118Entries];
|
||||
thing->offset = gD_8018E118TotalSize;
|
||||
thing[gNumD_8018E118Entries].textureData = texture->textureData;
|
||||
thing[gNumD_8018E118Entries].offset = gD_8018E118TotalSize;
|
||||
gD_8018E118TotalSize += texture->height * texture->width;
|
||||
gD_8018E118TotalSize = ((gD_8018E118TotalSize / 8) * 8) + 8;
|
||||
gNumD_8018E118Entries += 1;
|
||||
@@ -10093,19 +10104,27 @@ void func_800AAE18(struct_8018D9E0_entry *arg0) {
|
||||
* is found.
|
||||
**/
|
||||
struct_8018D9E0_entry *func_800AAE68(void) {
|
||||
struct_8018D9E0_entry *entry = D_8018D9E0;
|
||||
s32 thing = gPlayerCount - 1;
|
||||
|
||||
for(; !(entry > &D_8018D9E0[D_8018D9E0_SIZE]); entry++) {
|
||||
if ((thing + 0xB) == entry->type) {
|
||||
goto escape;
|
||||
s32 count = gPlayerCount - 1;
|
||||
for (size_t i = 0; i < ARRAY_COUNT(D_8018D9E0); i++) {
|
||||
if (D_8018D9E0[i].type == (count + 0xB)) {
|
||||
return &D_8018D9E0[i];
|
||||
}
|
||||
}
|
||||
printf("Error: func_800AAE68 returned a null value when searching id 0x%X", count+0xB);
|
||||
return NULL;
|
||||
// struct_8018D9E0_entry *entry = D_8018D9E0;
|
||||
// s32 thing = gPlayerCount - 1;
|
||||
|
||||
// Something VERY wrong has occurred
|
||||
while(true);
|
||||
escape:
|
||||
return entry;
|
||||
// for(; !(entry > &D_8018D9E0[D_8018D9E0_SIZE]); entry++) {
|
||||
// if ((thing + 0xB) == entry->type) {
|
||||
// goto escape;
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Something VERY wrong has occurred
|
||||
// while(true);
|
||||
// escape:
|
||||
// return entry;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -10114,18 +10133,27 @@ escape:
|
||||
* is found.
|
||||
**/
|
||||
struct_8018D9E0_entry *func_800AAEB4(s32 arg0) {
|
||||
struct_8018D9E0_entry *entry = D_8018D9E0;
|
||||
|
||||
for(; !(entry > &D_8018D9E0[D_8018D9E0_SIZE]); entry++) {
|
||||
if ((arg0 + 0x2B) == entry->type) {
|
||||
goto escape;
|
||||
for (size_t i = 0; i < ARRAY_COUNT(D_8018D9E0); i++) {
|
||||
if (D_8018D9E0[i].type == (arg0 + 0x2B)) {
|
||||
return &D_8018D9E0[i];
|
||||
}
|
||||
}
|
||||
printf("Error: func_800AAEB4 returned a null value when searching id 0x%X", arg0+0x2B);
|
||||
return NULL;
|
||||
|
||||
// Something VERY wrong has occurred
|
||||
while(true);
|
||||
escape:
|
||||
return entry;
|
||||
// struct_8018D9E0_entry *entry = D_8018D9E0;
|
||||
|
||||
// for(; !(entry > &D_8018D9E0[D_8018D9E0_SIZE]); entry++) {
|
||||
// if ((arg0 + 0x2B) == entry->type) {
|
||||
// goto escape;
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Something VERY wrong has occurred
|
||||
// while(true);
|
||||
// escape:
|
||||
// return entry;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -10140,10 +10168,11 @@ escape:
|
||||
**/
|
||||
struct_8018D9E0_entry *find_8018D9E0_entry_dupe(s32 arg0) {
|
||||
for (size_t i = 0; i < ARRAY_COUNT(D_8018D9E0); i++) {
|
||||
if (&D_8018D9E0[i].type == arg0) {
|
||||
if (D_8018D9E0[i].type == arg0) {
|
||||
return &D_8018D9E0[i];
|
||||
}
|
||||
}
|
||||
printf("Error: find_8018D9E0_entry_dupe returned a null value when searching id 0x%X", arg0);
|
||||
return NULL;
|
||||
|
||||
|
||||
@@ -10162,10 +10191,13 @@ struct_8018D9E0_entry *find_8018D9E0_entry_dupe(s32 arg0) {
|
||||
|
||||
struct_8018D9E0_entry *find_8018D9E0_entry(s32 arg0) {
|
||||
for (size_t i = 0; i < ARRAY_COUNT(D_8018D9E0); i++) {
|
||||
if (&D_8018D9E0[i].type == arg0) {
|
||||
if (D_8018D9E0[i].type == arg0) {
|
||||
return &D_8018D9E0[i];
|
||||
}
|
||||
}
|
||||
// No printf here as returning null seems to be normal game logic
|
||||
//printf("Error: find_8018D9E0_entry returned a null value when searching id 0x%X",
|
||||
// arg0);
|
||||
return NULL;
|
||||
|
||||
// struct_8018D9E0_entry *entry = D_8018D9E0;
|
||||
|
||||
Reference in New Issue
Block a user