diff --git a/Makefile b/Makefile index 2ca73284..7d124c0c 100755 --- a/Makefile +++ b/Makefile @@ -126,12 +126,6 @@ endif endif endif endif - -################################ - -# Removes the enums_cache if it exists in the build folde, incase someone modified the include/enums.h file. -DUMMY != rm -Rf build/enums_cache - ################ Target Executable and Sources ############### # BUILD_DIR is location where all build artifacts are placed @@ -381,6 +375,10 @@ dont_remove_asset_files: $(ALL_ASSETS_BUILT) ######## Asset Targets ######## +$(BUILD_DIR)/enumsCache.bin: include/enums.h + $(call print,Building enums.h cache:,$<,$@) + $(V)$(TOOLS_DIR)/dkr_assets_tool -bc $(VERSION) $< + # All assets should output a .bin file # $1 = folder name, $2 = Print Message @@ -402,9 +400,9 @@ endef # $1 = folder name, $2 = Print Message define CREATE_JSON_ASSET_TARGET $(eval VAR_NAME := $(call GET_VAR_NAME,$1)) -$$($$(VAR_NAME)_OUT_DIR)/%.bin: $$($$(VAR_NAME)_IN_DIR)/%.json +$$($$(VAR_NAME)_OUT_DIR)/%.bin: $$($$(VAR_NAME)_IN_DIR)/%.json $(BUILD_DIR)/enumsCache.bin $$(call print,$2:,$$<,$$@) - $$(V)$$(BUILDER) $$^ $$@ + $$(V)$$(BUILDER) $$< $$@ endef $(eval $(call CREATE_BINARY_ASSET_TARGET,audio,Copying Audio Binary)) diff --git a/asm/non_matchings/unknown_0255E0/func_8002C7D4.s b/asm/non_matchings/unknown_0255E0/func_8002C7D4.s deleted file mode 100644 index 692864e6..00000000 --- a/asm/non_matchings/unknown_0255E0/func_8002C7D4.s +++ /dev/null @@ -1,103 +0,0 @@ -glabel func_8002C7D4 -/* 02D3D4 8002C7D4 27BDFFD0 */ addiu $sp, $sp, -0x30 -/* 02D3D8 8002C7D8 AFBF002C */ sw $ra, 0x2c($sp) -/* 02D3DC 8002C7DC AFB40028 */ sw $s4, 0x28($sp) -/* 02D3E0 8002C7E0 AFB30024 */ sw $s3, 0x24($sp) -/* 02D3E4 8002C7E4 AFB20020 */ sw $s2, 0x20($sp) -/* 02D3E8 8002C7E8 AFB1001C */ sw $s1, 0x1c($sp) -/* 02D3EC 8002C7EC 0C002CA4 */ jal func_8000B290 -/* 02D3F0 8002C7F0 AFB00018 */ sw $s0, 0x18($sp) -/* 02D3F4 8002C7F4 3C0E8012 */ lui $t6, %hi(D_8011D384) # $t6, 0x8012 -/* 02D3F8 8002C7F8 8DCED384 */ lw $t6, %lo(D_8011D384)($t6) -/* 02D3FC 8002C7FC 00000000 */ nop -/* 02D400 8002C800 11C00003 */ beqz $t6, .L8002C810 -/* 02D404 8002C804 00000000 */ nop -/* 02D408 8002C808 0C02DF48 */ jal func_800B7D20 -/* 02D40C 8002C80C 00000000 */ nop -.L8002C810: -/* 02D410 8002C810 3C14800E */ lui $s4, %hi(gCurrentLevelModel) # $s4, 0x800e -/* 02D414 8002C814 2694C918 */ addiu $s4, %lo(gCurrentLevelModel) # addiu $s4, $s4, -0x36e8 -/* 02D418 8002C818 8E910000 */ lw $s1, ($s4) -/* 02D41C 8002C81C 00008025 */ move $s0, $zero -/* 02D420 8002C820 862F0018 */ lh $t7, 0x18($s1) -/* 02D424 8002C824 00009025 */ move $s2, $zero -/* 02D428 8002C828 19E0000E */ blez $t7, .L8002C864 -/* 02D42C 8002C82C 00000000 */ nop -.L8002C830: -/* 02D430 8002C830 8E380000 */ lw $t8, ($s1) -/* 02D434 8002C834 00000000 */ nop -/* 02D438 8002C838 0312C821 */ addu $t9, $t8, $s2 -/* 02D43C 8002C83C 8F240000 */ lw $a0, ($t9) -/* 02D440 8002C840 0C01ECAF */ jal free_texture -/* 02D444 8002C844 00000000 */ nop -/* 02D448 8002C848 8E910000 */ lw $s1, ($s4) -/* 02D44C 8002C84C 26100001 */ addiu $s0, $s0, 1 -/* 02D450 8002C850 86280018 */ lh $t0, 0x18($s1) -/* 02D454 8002C854 26520008 */ addiu $s2, $s2, 8 -/* 02D458 8002C858 0208082A */ slt $at, $s0, $t0 -/* 02D45C 8002C85C 1420FFF4 */ bnez $at, .L8002C830 -/* 02D460 8002C860 00000000 */ nop -.L8002C864: -/* 02D464 8002C864 3C048012 */ lui $a0, %hi(D_8011D30C) # $a0, 0x8012 -/* 02D468 8002C868 8C84D30C */ lw $a0, %lo(D_8011D30C)($a0) -/* 02D46C 8002C86C 0C01C450 */ jal free_from_memory_pool -/* 02D470 8002C870 00000000 */ nop -/* 02D474 8002C874 3C048012 */ lui $a0, %hi(D_8011D370) # $a0, 0x8012 -/* 02D478 8002C878 8C84D370 */ lw $a0, %lo(D_8011D370)($a0) -/* 02D47C 8002C87C 0C01C450 */ jal free_from_memory_pool -/* 02D480 8002C880 00000000 */ nop -/* 02D484 8002C884 3C048012 */ lui $a0, %hi(D_8011D374) # $a0, 0x8012 -/* 02D488 8002C888 8C84D374 */ lw $a0, %lo(D_8011D374)($a0) -/* 02D48C 8002C88C 0C01C450 */ jal free_from_memory_pool -/* 02D490 8002C890 00000000 */ nop -/* 02D494 8002C894 8E890000 */ lw $t1, ($s4) -/* 02D498 8002C898 00000000 */ nop -/* 02D49C 8002C89C 8D240020 */ lw $a0, 0x20($t1) -/* 02D4A0 8002C8A0 0C01F32C */ jal free_sprite -/* 02D4A4 8002C8A4 00000000 */ nop -/* 02D4A8 8002C8A8 3C118012 */ lui $s1, %hi(D_8011D350) # $s1, 0x8012 -/* 02D4AC 8002C8AC 3C128012 */ lui $s2, %hi(D_8011D320) # $s2, 0x8012 -/* 02D4B0 8002C8B0 3C108012 */ lui $s0, %hi(D_8011D338) # $s0, 0x8012 -/* 02D4B4 8002C8B4 3C138012 */ lui $s3, %hi(D_8011D348) # $s3, 0x8012 -/* 02D4B8 8002C8B8 2673D348 */ addiu $s3, %lo(D_8011D348) # addiu $s3, $s3, -0x2cb8 -/* 02D4BC 8002C8BC 2610D338 */ addiu $s0, %lo(D_8011D338) # addiu $s0, $s0, -0x2cc8 -/* 02D4C0 8002C8C0 2652D320 */ addiu $s2, %lo(D_8011D320) # addiu $s2, $s2, -0x2ce0 -/* 02D4C4 8002C8C4 2631D350 */ addiu $s1, %lo(D_8011D350) # addiu $s1, $s1, -0x2cb0 -.L8002C8C8: -/* 02D4C8 8002C8C8 8E240000 */ lw $a0, ($s1) -/* 02D4CC 8002C8CC 0C01C450 */ jal free_from_memory_pool -/* 02D4D0 8002C8D0 00000000 */ nop -/* 02D4D4 8002C8D4 8E440000 */ lw $a0, ($s2) -/* 02D4D8 8002C8D8 0C01C450 */ jal free_from_memory_pool -/* 02D4DC 8002C8DC 00000000 */ nop -/* 02D4E0 8002C8E0 8E040000 */ lw $a0, ($s0) -/* 02D4E4 8002C8E4 0C01C450 */ jal free_from_memory_pool -/* 02D4E8 8002C8E8 00000000 */ nop -/* 02D4EC 8002C8EC 26100004 */ addiu $s0, $s0, 4 -/* 02D4F0 8002C8F0 26310004 */ addiu $s1, $s1, 4 -/* 02D4F4 8002C8F4 1613FFF4 */ bne $s0, $s3, .L8002C8C8 -/* 02D4F8 8002C8F8 26520004 */ addiu $s2, $s2, 4 -/* 02D4FC 8002C8FC 0C0095F4 */ jal func_800257D0 -/* 02D500 8002C900 00000000 */ nop -/* 02D504 8002C904 3C048012 */ lui $a0, %hi(D_8011B0B8) # $a0, 0x8012 -/* 02D508 8002C908 8C84B0B8 */ lw $a0, %lo(D_8011B0B8)($a0) -/* 02D50C 8002C90C 00000000 */ nop -/* 02D510 8002C910 10800005 */ beqz $a0, .L8002C928 -/* 02D514 8002C914 00000000 */ nop -/* 02D518 8002C918 0C003FEE */ jal gParticlePtrList_addObject -/* 02D51C 8002C91C 00000000 */ nop -/* 02D520 8002C920 0C004013 */ jal gParticlePtrList_flush -/* 02D524 8002C924 00000000 */ nop -.L8002C928: -/* 02D528 8002C928 0C003181 */ jal func_8000C604 -/* 02D52C 8002C92C 00000000 */ nop -/* 02D530 8002C930 8FBF002C */ lw $ra, 0x2c($sp) -/* 02D534 8002C934 AE800000 */ sw $zero, ($s4) -/* 02D538 8002C938 8FB40028 */ lw $s4, 0x28($sp) -/* 02D53C 8002C93C 8FB00018 */ lw $s0, 0x18($sp) -/* 02D540 8002C940 8FB1001C */ lw $s1, 0x1c($sp) -/* 02D544 8002C944 8FB20020 */ lw $s2, 0x20($sp) -/* 02D548 8002C948 8FB30024 */ lw $s3, 0x24($sp) -/* 02D54C 8002C94C 03E00008 */ jr $ra -/* 02D550 8002C950 27BD0030 */ addiu $sp, $sp, 0x30 - diff --git a/asm/non_matchings/unknown_0255E0/func_8002D30C.s b/asm/non_matchings/unknown_0255E0/func_8002D30C.s deleted file mode 100644 index c0e45cf7..00000000 --- a/asm/non_matchings/unknown_0255E0/func_8002D30C.s +++ /dev/null @@ -1,36 +0,0 @@ -glabel func_8002D30C -/* 02DF0C 8002D30C 27BDFFE0 */ addiu $sp, $sp, -0x20 -/* 02DF10 8002D310 AFB10018 */ sw $s1, 0x18($sp) -/* 02DF14 8002D314 AFB00014 */ sw $s0, 0x14($sp) -/* 02DF18 8002D318 00808025 */ move $s0, $a0 -/* 02DF1C 8002D31C 00A08825 */ move $s1, $a1 -/* 02DF20 8002D320 AFBF001C */ sw $ra, 0x1c($sp) -/* 02DF24 8002D324 12000013 */ beqz $s0, .L8002D374 -/* 02DF28 8002D328 8FBF001C */ lw $ra, 0x1c($sp) -.L8002D32C: -/* 02DF2C 8002D32C 8E020004 */ lw $v0, 4($s0) -/* 02DF30 8002D330 00000000 */ nop -/* 02DF34 8002D334 10400002 */ beqz $v0, .L8002D340 -/* 02DF38 8002D338 00517021 */ addu $t6, $v0, $s1 -/* 02DF3C 8002D33C AE0E0004 */ sw $t6, 4($s0) -.L8002D340: -/* 02DF40 8002D340 8E020008 */ lw $v0, 8($s0) -/* 02DF44 8002D344 00000000 */ nop -/* 02DF48 8002D348 10400002 */ beqz $v0, .L8002D354 -/* 02DF4C 8002D34C 00517821 */ addu $t7, $v0, $s1 -/* 02DF50 8002D350 AE0F0008 */ sw $t7, 8($s0) -.L8002D354: -/* 02DF54 8002D354 8E040004 */ lw $a0, 4($s0) -/* 02DF58 8002D358 0C00B4C3 */ jal func_8002D30C -/* 02DF5C 8002D35C 02202825 */ move $a1, $s1 -/* 02DF60 8002D360 8E100008 */ lw $s0, 8($s0) -/* 02DF64 8002D364 00000000 */ nop -/* 02DF68 8002D368 1600FFF0 */ bnez $s0, .L8002D32C -/* 02DF6C 8002D36C 00000000 */ nop -/* 02DF70 8002D370 8FBF001C */ lw $ra, 0x1c($sp) -.L8002D374: -/* 02DF74 8002D374 8FB00014 */ lw $s0, 0x14($sp) -/* 02DF78 8002D378 8FB10018 */ lw $s1, 0x18($sp) -/* 02DF7C 8002D37C 03E00008 */ jr $ra -/* 02DF80 8002D380 27BD0020 */ addiu $sp, $sp, 0x20 - diff --git a/asm/non_matchings/unknown_0255E0/func_80030DE0.s b/asm/non_matchings/unknown_0255E0/func_80030DE0.s index c0f02ec1..c336bdd8 100644 --- a/asm/non_matchings/unknown_0255E0/func_80030DE0.s +++ b/asm/non_matchings/unknown_0255E0/func_80030DE0.s @@ -125,34 +125,3 @@ glabel func_80030DE0 /* 031B98 80030F98 03E00008 */ jr $ra /* 031B9C 80030F9C 27BD0010 */ addiu $sp, $sp, 0x10 -/* 031BA0 80030FA0 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* 031BA4 80030FA4 AFBF0014 */ sw $ra, 0x14($sp) -/* 031BA8 80030FA8 0C01A748 */ jal func_80069D20 -/* 031BAC 80030FAC 00000000 */ nop -/* 031BB0 80030FB0 3C018012 */ lui $at, %hi(D_8011B0B0) # $at, 0x8012 -/* 031BB4 80030FB4 0C00C406 */ jal func_80031018 -/* 031BB8 80030FB8 AC22B0B0 */ sw $v0, %lo(D_8011B0B0)($at) -/* 031BBC 80030FBC 3C028012 */ lui $v0, %hi(D_8011D468) # $v0, 0x8012 -/* 031BC0 80030FC0 2442D468 */ addiu $v0, %lo(D_8011D468) # addiu $v0, $v0, -0x2b98 -/* 031BC4 80030FC4 8C580008 */ lw $t8, 8($v0) -/* 031BC8 80030FC8 8C4E0000 */ lw $t6, ($v0) -/* 031BCC 80030FCC 44988000 */ mtc1 $t8, $f16 -/* 031BD0 80030FD0 448E2000 */ mtc1 $t6, $f4 -/* 031BD4 80030FD4 468084A0 */ cvt.s.w $f18, $f16 -/* 031BD8 80030FD8 3C014780 */ li $at, 0x47800000 # 65536.000000 -/* 031BDC 80030FDC 44810000 */ mtc1 $at, $f0 -/* 031BE0 80030FE0 468021A0 */ cvt.s.w $f6, $f4 -/* 031BE4 80030FE4 8C4F0004 */ lw $t7, 4($v0) -/* 031BE8 80030FE8 46009103 */ div.s $f4, $f18, $f0 -/* 031BEC 80030FEC 448F4000 */ mtc1 $t7, $f8 -/* 031BF0 80030FF0 00000000 */ nop -/* 031BF4 80030FF4 468042A0 */ cvt.s.w $f10, $f8 -/* 031BF8 80030FF8 44062000 */ mfc1 $a2, $f4 -/* 031BFC 80030FFC 46005383 */ div.s $f14, $f10, $f0 -/* 031C00 80031000 0C007578 */ jal func_8001D5E0 -/* 031C04 80031004 46003303 */ div.s $f12, $f6, $f0 -/* 031C08 80031008 8FBF0014 */ lw $ra, 0x14($sp) -/* 031C0C 8003100C 27BD0018 */ addiu $sp, $sp, 0x18 -/* 031C10 80031010 03E00008 */ jr $ra -/* 031C14 80031014 00000000 */ nop - diff --git a/include/structs.h b/include/structs.h index b8b82570..87b9b3a1 100644 --- a/include/structs.h +++ b/include/structs.h @@ -403,16 +403,19 @@ typedef struct ObjectModel { /* Size: 0x44 bytes */ typedef struct LevelModelSegment { /* 0x00 */ Vertex *vertices; -/* 0x04 */ Triangle *triangles; - u8 pad8[4]; +/* 0x04 */ Triangle *triangles; + u8 pad8[4]; /* 0x0C */ TriangleBatchInfo *batches; - u8 pad10[0x0C]; + s32 unk10; + u8 *unk14; + s16 *unk18; /* 0x1C */ s16 numberOfVertices; /* 0x1E */ s16 numberOfTriangles; /* 0x20 */ s16 numberOfBatches; u8 pad22[0x09]; -/* 0x2B */ s8 unk2B; - u8 pad2C[6]; +/* 0x2B */ s8 unk2B; + u8 pad2C[4]; + s16 unk30; /* 0x32 */ s16 unk32; s16 *unk34; /* 0x38 */ s16 unk38; @@ -451,7 +454,9 @@ typedef struct LevelModel { u8 pad1C[4]; /* 0x20 */ s32 unk20; //spriteIndex? u8 pad24[0x14]; -/* 0x38 */ u32 minimapColor; +/* 0x38 */ u32 minimapColor; + u8 pad3C[0xC]; + s32 modelSize; } LevelModel; typedef struct Object_3C { diff --git a/src/game.c b/src/game.c index 10af0c19..7f7bd4d6 100644 --- a/src/game.c +++ b/src/game.c @@ -124,7 +124,7 @@ extern s32 gShowControllerPakMenu; /************ .bss ************/ -u32 *gTempAssetTable; +s32 *gTempAssetTable; s32 D_80121164; LevelHeader *gCurrentLevelHeader; u8 **gLevelNames; @@ -182,77 +182,82 @@ s32 D_80123560[8]; /******************************/ -#ifdef NON_EQUIVALENT -void func_8006A6B0(void) { - s32 i, count, checksumCount; - s32 temp; - u8 *sp44; - sp44 = allocate_from_main_pool_safe(sizeof(LevelHeader), COLOUR_TAG_YELLOW); - gTempAssetTable = load_asset_section_from_rom(ASSET_LEVEL_HEADERS_TABLE); - for (i = 0; i < 16; i++) { - D_80121180[i] = 0; +#ifdef NON_MATCHING +// Only has regalloc issues. +void func_8006A6B0(void){ + s32 i; + s32 temp; + s32 count; + s32 checksumCount; + u8 *sp44; + s32 temp2; + + sp44 = allocate_from_main_pool_safe(sizeof(LevelHeader), 0xFFFF00FF); + gTempAssetTable = load_asset_section_from_rom(ASSET_LEVEL_HEADERS_TABLE); + i = 0; + while (i < 16) { + D_80121180[i++] = 0; + } + gNumberOfLevelHeaders = 0; + while (gTempAssetTable[gNumberOfLevelHeaders] != (-1)) { + gNumberOfLevelHeaders++; + } + gNumberOfLevelHeaders--; + D_8012117C = allocate_from_main_pool_safe(gNumberOfLevelHeaders * (sizeof(unk8012117C)), 0xFFFF00FF); + gCurrentLevelHeader = sp44; + gNumberOfWorlds = -1; + for (i = 0; i < gNumberOfLevelHeaders; i++){ + load_asset_to_address(ASSET_LEVEL_HEADERS, gCurrentLevelHeader, gTempAssetTable[i], sizeof(LevelHeader)); + if (gNumberOfWorlds < gCurrentLevelHeader->world) { + gNumberOfWorlds = gCurrentLevelHeader->world; } - gNumberOfLevelHeaders = 0; - while (gTempAssetTable[gNumberOfLevelHeaders] != -1) { - gNumberOfLevelHeaders++; + if ((gCurrentLevelHeader->race_type >= 0) && (gCurrentLevelHeader->race_type < 16)) { + D_80121180[gCurrentLevelHeader->race_type]++; } - gNumberOfLevelHeaders--; - D_8012117C = allocate_from_main_pool_safe(gNumberOfLevelHeaders * sizeof(unk8012117C), COLOUR_TAG_YELLOW); - gNumberOfWorlds = -1; - gCurrentLevelHeader = sp44; - for (i = 0; i < gNumberOfLevelHeaders; i++) { - load_asset_to_address(ASSET_LEVEL_HEADERS, gCurrentLevelHeader, gTempAssetTable[i], sizeof(LevelHeader)); - if (gNumberOfWorlds < gCurrentLevelHeader->world) { - gNumberOfWorlds = gCurrentLevelHeader->world; - } - if (gCurrentLevelHeader->race_type >= 0 && gCurrentLevelHeader->race_type < 16) { - D_80121180[gCurrentLevelHeader->race_type]++; - } - D_8012117C[i].unk0 = gCurrentLevelHeader->world; - D_8012117C[i].unk1 = gCurrentLevelHeader->race_type; - D_8012117C[i].unk2 = gCurrentLevelHeader->available_vehicles << 4; - D_8012117C[i].unk2 |= gCurrentLevelHeader->vehicle & 0xF; - D_8012117C[i].unk3 = 1; - D_8012117C[i].unk4 = gCurrentLevelHeader->unkB0; - } - gNumberOfWorlds++; - D_80121178 = allocate_from_main_pool_safe(gNumberOfWorlds, COLOUR_TAG_YELLOW); - for (i = 0; i < gNumberOfWorlds; i++) { - D_80121178[i] = -1; - } - for (i = 0; i < gNumberOfLevelHeaders; i++) { - if (D_8012117C[i].unk1 == 5) { - D_80121178[D_8012117C[i].unk0] = i; - } - } - free_from_memory_pool(gTempAssetTable); - free_from_memory_pool(sp44); + D_8012117C[i].unk0 = gCurrentLevelHeader->world; + D_8012117C[i].unk1 = gCurrentLevelHeader->race_type; + D_8012117C[i].unk2 = ((u16)gCurrentLevelHeader->available_vehicles) << 4; + D_8012117C[i].unk2 |= gCurrentLevelHeader->vehicle & 0xF; + D_8012117C[i].unk3 = 1; + D_8012117C[i].unk4 = gCurrentLevelHeader->unkB0; + } - gTempAssetTable = load_asset_section_from_rom(ASSET_LEVEL_NAMES_TABLE); - count = 0; - while (gTempAssetTable[count] != -1) { - count++; - } - count--; - temp = gTempAssetTable[count] - gTempAssetTable[0]; - // Minor issue here. - gLevelNames = allocate_from_main_pool_safe(count * sizeof(s32), COLOUR_TAG_YELLOW); - D_800DD310 = allocate_from_main_pool_safe(temp, COLOUR_TAG_YELLOW); - load_asset_to_address(ASSET_LEVEL_NAMES, D_800DD310, 0, temp); - for (i = 0; i < count; i++) { - gLevelNames[i] = &D_800DD310[gTempAssetTable[i]]; - } - free_from_memory_pool(gTempAssetTable); - - // Anti-piracy/Anti-tamper check. - checksumCount = 0; - for (i = 0; i < gFunc80068158Length; i++) { - checksumCount += ((u8 *)&func_80068158)[i]; - } - if (checksumCount != gFunc80068158Checksum) { - // Disables button inputs in some parts of the game if the checksum doesn't match. - disable_button_mask(); + gNumberOfWorlds++; + D_80121178 = allocate_from_main_pool_safe(gNumberOfWorlds, 0xFFFF00FF); + for (i = 0; i < gNumberOfWorlds; i++){ + *(D_80121178 + i) = -1; + } + for (i = 0; i < gNumberOfLevelHeaders; i++){ + if ((D_8012117C[i].unk1 == 5) != 0 ){ + D_80121178[D_8012117C[i].unk0] = i; } + } + free_from_memory_pool(gTempAssetTable); + free_from_memory_pool(sp44); + + gTempAssetTable = load_asset_section_from_rom(ASSET_LEVEL_NAMES_TABLE); + + for (i = 0; gTempAssetTable[i] != (-1); i++){} + i--; + + temp = gTempAssetTable[i]; + temp -= gTempAssetTable[0]; + + gLevelNames = allocate_from_main_pool_safe(i * (sizeof(s32)), 0xFFFF00FF); + D_800DD310 = allocate_from_main_pool_safe(temp, 0xFFFF00FF); + load_asset_to_address(ASSET_LEVEL_NAMES, D_800DD310, 0, temp); + for (count = 0; count < i; count++) { + gLevelNames[count] = &D_800DD310[gTempAssetTable[count]]; + } + free_from_memory_pool(gTempAssetTable); + + checksumCount = 0; + for (i = 0; i < gFunc80068158Length; i++) { + checksumCount += ((u8 *) (&func_80068158))[i]; + } + if (checksumCount != gFunc80068158Checksum) { + disable_button_mask(); + } } #else GLOBAL_ASM("asm/non_matchings/game/func_8006A6B0.s") diff --git a/src/unknown_0255E0.c b/src/unknown_0255E0.c index 4e966514..d40cd3ba 100644 --- a/src/unknown_0255E0.c +++ b/src/unknown_0255E0.c @@ -128,8 +128,8 @@ s32 D_8011D164; s32 D_8011D168[84]; s32 D_8011D2B8[20]; s32 D_8011D308; -s32 D_8011D30C; -s32 D_8011D310; +LevelModel *D_8011D30C; +s32 *D_8011D310; s32 D_8011D314; s32 D_8011D318; s32 D_8011D31C; @@ -144,8 +144,8 @@ unk8011D360 *D_8011D360; s32 D_8011D364; s32 D_8011D368; s32 D_8011D36C; -s32 D_8011D370; -s32 D_8011D374; +s32 *D_8011D370; +s32 *D_8011D374; s32 D_8011D378; s32 D_8011D37C; f32 D_8011D380; @@ -886,7 +886,106 @@ s32 func_8002B9BC(Object *obj, f32 *arg1, f32 *arg2, s32 arg3) { } GLOBAL_ASM("asm/non_matchings/unknown_0255E0/func_8002BAB0.s") + +#ifdef NON_EQUIVALENT + +// Maximum size for a level model is 522.5 KiB +#define LEVEL_MODEL_MAX_SIZE 0x82A00 + +#define LOCAL_OFFSET_TO_RAM_ADDRESS(ptr) \ + ptr = (s32)((u8*)ptr) + (s32)((u8*)gCurrentLevelModel) + +// Loads a level track from the index in the models table. +// Has regalloc issues. +void func_8002C0C4(s32 modelId) { + s32 i, j, k; + s32 numLevelModels; + s32 temp_s4; + s32 offset, size; + u8 *compressedRamAddr; + LevelModelSegment *segment; + TriangleBatchInfo *batch; + Vertex *vertex; + + func_8007B374(0xFF00FF); + D_8011D30C = allocate_from_main_pool_safe(LEVEL_MODEL_MAX_SIZE, 0xFFFF00FFU); + gCurrentLevelModel = D_8011D30C; + D_8011D370 = allocate_from_main_pool_safe(0x7D0, 0xFFFF00FFU); + D_8011D374 = allocate_from_main_pool_safe(0x1F4, 0xFFFF00FFU); + D_8011D378 = 0; + D_8011D310 = load_asset_section_from_rom(ASSET_LEVEL_MODELS_TABLE); + for(numLevelModels = 0; D_8011D310[numLevelModels] != -1; numLevelModels++) {} + numLevelModels--; + if (modelId >= numLevelModels) { + modelId = 0; + } + offset = D_8011D310[modelId]; + size = D_8011D310[modelId + 1] - offset; + compressedRamAddr = (u8*)gCurrentLevelModel + (LEVEL_MODEL_MAX_SIZE - size); + compressedRamAddr = compressedRamAddr - (u8*)((s32)compressedRamAddr % 16); + load_asset_to_address(ASSET_LEVEL_MODELS, compressedRamAddr, offset, size); + gzip_inflate((u8*) compressedRamAddr, (u8*) gCurrentLevelModel); + free_from_memory_pool(D_8011D310); // Done with the level models table, so free it. + + LOCAL_OFFSET_TO_RAM_ADDRESS(gCurrentLevelModel->textures); + LOCAL_OFFSET_TO_RAM_ADDRESS(gCurrentLevelModel->segments); + LOCAL_OFFSET_TO_RAM_ADDRESS(gCurrentLevelModel->segmentsBoundingBoxes); + LOCAL_OFFSET_TO_RAM_ADDRESS(gCurrentLevelModel->unkC); + LOCAL_OFFSET_TO_RAM_ADDRESS(gCurrentLevelModel->segmentsBitfields); + LOCAL_OFFSET_TO_RAM_ADDRESS(gCurrentLevelModel->segmentsBspTree); + for(i = 0; i < gCurrentLevelModel->numberOfSegments; i++) { + LOCAL_OFFSET_TO_RAM_ADDRESS(gCurrentLevelModel->segments[i].vertices); + LOCAL_OFFSET_TO_RAM_ADDRESS(gCurrentLevelModel->segments[i].triangles); + LOCAL_OFFSET_TO_RAM_ADDRESS(gCurrentLevelModel->segments[i].batches); + LOCAL_OFFSET_TO_RAM_ADDRESS(gCurrentLevelModel->segments[i].unk14); + } + for(i = 0; i < gCurrentLevelModel->numberOfTextures; i++) { + gCurrentLevelModel->textures[i].texture = load_texture(((s32)gCurrentLevelModel->textures[i].texture) | 0x8000); + } + temp_s4 = (s32)gCurrentLevelModel + gCurrentLevelModel->modelSize; + for(i = 0; i < gCurrentLevelModel->numberOfSegments; i++) { + gCurrentLevelModel->segments[i].unk10 = temp_s4; + temp_s4 = align16((gCurrentLevelModel->segments[i].numberOfTriangles * 2) + temp_s4); + gCurrentLevelModel->segments[i].unk18 = temp_s4; + temp_s4 = &((u8*)temp_s4)[func_8002CC30(&gCurrentLevelModel->segments[i])]; + func_8002C954(&gCurrentLevelModel->segments[i], &gCurrentLevelModel->segmentsBoundingBoxes[i], i); + gCurrentLevelModel->segments[i].unk30 = 0; + gCurrentLevelModel->segments[i].unk34 = temp_s4; + func_8002C71C(&gCurrentLevelModel->segments[i]); + temp_s4 = align16((gCurrentLevelModel->segments[i].unk32 * 2) + temp_s4); + } + temp_s4 -= (s32)gCurrentLevelModel; + if (temp_s4 > LEVEL_MODEL_MAX_SIZE) { + rmonPrintf("ERROR!! TrackMem overflow .. %d\n", temp_s4); + } + set_free_queue_state(0); + free_from_memory_pool(D_8011D30C); + allocate_at_address_in_main_pool(temp_s4, (u8* ) D_8011D30C, 0xFFFF00FFU); + set_free_queue_state(2); + func_800A83B4(gCurrentLevelModel); + + for(i = 0; i < gCurrentLevelModel->numberOfSegments; i++) { + for(j = 0; j < gCurrentLevelModel->segments[i].numberOfBatches; j++) { + for(k = gCurrentLevelModel->segments[i].batches[j].verticesOffset; + k < gCurrentLevelModel->segments[i].batches[j+1].verticesOffset; + k++) { + // Why do this? Why not just set the vertex colors in the model itself? + if(gCurrentLevelModel->segments[i].vertices[k].r == 1 && gCurrentLevelModel->segments[i].vertices[k].g == 1) { + gCurrentLevelModel->segments[i].vertices[k].a = gCurrentLevelModel->segments[i].vertices[k].b; + gCurrentLevelModel->segments[i].vertices[k].r = 0x80; + gCurrentLevelModel->segments[i].vertices[k].g = 0x80; + gCurrentLevelModel->segments[i].vertices[k].b = 0x80; + gCurrentLevelModel->segments[i].batches[j].flags |= 0x08000000; + } + } + } + } + func_8007B374(-0xFF0001); +} + +#else GLOBAL_ASM("asm/non_matchings/unknown_0255E0/func_8002C0C4.s") +#endif void func_8002C71C(LevelModelSegment *segment) { s32 curVertY; @@ -911,12 +1010,38 @@ LevelModel *func_8002C7C4(void) { return gCurrentLevelModel; } -GLOBAL_ASM("asm/non_matchings/unknown_0255E0/func_8002C7D4.s") +void func_8002C7D4(void) { + s32 i; + + func_8000B290(); + if (D_8011D384 != 0) { + func_800B7D20(); + } + for(i = 0; i < gCurrentLevelModel->numberOfTextures; i++) { + free_texture(gCurrentLevelModel->textures[i].texture); + } + free_from_memory_pool(D_8011D30C); + free_from_memory_pool(D_8011D370); + free_from_memory_pool(D_8011D374); + free_sprite((Sprite* ) gCurrentLevelModel->unk20); + for(i = 0; i < 4; i++) { + free_from_memory_pool(D_8011D350[i]); + free_from_memory_pool(D_8011D320[i]); + free_from_memory_pool(D_8011D338[i]); + } + func_800257D0(); + if (D_8011B0B8 != NULL) { + gParticlePtrList_addObject(D_8011B0B8); + gParticlePtrList_flush(); + } + func_8000C604(); + gCurrentLevelModel = NULL; +} + + GLOBAL_ASM("asm/non_matchings/unknown_0255E0/func_8002C954.s") GLOBAL_ASM("asm/non_matchings/unknown_0255E0/func_8002CC30.s") -#ifdef NON_EQUIVALENT - typedef struct unk8002D30C_a0 { u8 pad00[0x04]; struct unk8002D30C_a0 *unk04; @@ -924,12 +1049,13 @@ typedef struct unk8002D30C_a0 { } unk8002D30C_a0; void func_8002D30C(unk8002D30C_a0 *arg0, s32 arg1) { - // Weird issue here with the ra register. - while (arg0 != NULL) { + while(1) { + if(!arg0) { + return; + } if (arg0->unk04) { arg0->unk04 = (unk8002D30C_a0 *)((s32)arg0->unk04 + arg1); } - if (arg0->unk08) { arg0->unk08 = (unk8002D30C_a0 *)((s32)arg0->unk08 + arg1); } @@ -938,9 +1064,6 @@ void func_8002D30C(unk8002D30C_a0 *arg0, s32 arg1) { arg0 = arg0->unk08; } } -#else -GLOBAL_ASM("asm/non_matchings/unknown_0255E0/func_8002D30C.s") -#endif GLOBAL_ASM("asm/non_matchings/unknown_0255E0/render_floor_decal.s") @@ -1051,8 +1174,153 @@ void func_8003093C(s32 arg0) { gDPSetFogColor(D_8011B0A0++, D_8011D388[arg0].unk0 >> 0x10, D_8011D388[arg0].unk4 >> 0x10, D_8011D388[arg0].unk8 >> 0x10, 0xFF); gSPFogPosition(D_8011B0A0++, D_8011D388[arg0].unkC >> 0x10, D_8011D388[arg0].unk10 >> 0x10); } + +#ifdef NON_EQUIVALENT +//unk8011D388 D_8011D388[4]; + +typedef struct Object_64_FogChanger { + s16 unk0; +} Object_64_FogChanger; + +typedef struct Object_3C_FogChanger { + u8 pad0[0x2]; + s16 unk2; + s16 unk4; + s16 unk6; + s8 unk8; + u8 unk9; + u8 unkA; + u8 unkB; + s16 unkC; + s16 unkE; + s16 unk10; +} Object_3C_FogChanger; + +void obj_loop_fogchanger(Object* obj) { + s32 temp_v0; + s32 index; + s32 sp74; + s32 i; + s32 phi_a0, phi_v1; + f32 x, z; + s32 temp_a3, temp_t0, temp_t1, temp_a1; + s32 temp; + Object **sp40; + Object_3C_FogChanger *sp44; + Object *tempObj; + unk8011D388 *temp_v0_3; + ObjectSegment *phi_s3; + + sp40 = NULL; + sp44 = obj->segment.unk3C_a.unk3C; + phi_s3 = NULL; + + // func_80066510() returns the bool D_80120D14. 1 if camera is controlled by cutscene, 0 if controlled by racer. + if (func_80066510()) { + phi_s3 = func_80069D7C(); + sp74 = get_viewport_count() + 1; + } else { + sp40 = get_object_struct_array(&sp74); + } + + for(i = 0; i < sp74; i++) { + index = -1; + if (sp40 != NULL) { + tempObj = sp40[i]; // Might be a player object? + temp_v0 = ((Object_64_FogChanger*)tempObj->unk64)->unk0; + if ((temp_v0 >= 0) && (temp_v0 < 4) && (obj != D_8011D388[i].unk34)) { + index = temp_v0; + x = tempObj->segment.trans.x_position; + z = tempObj->segment.trans.z_position; + } + } else if ((i < 4) && (obj != D_8011D388[i].unk34)) { + index = i; + x = phi_s3[i].trans.x_position; + z = phi_s3[i].trans.z_position; + } + if (index != -1) { + x -= obj->segment.trans.x_position; + z -= obj->segment.trans.z_position; + if (((x * x) + (z * z)) < obj->unk78f) { + phi_a0 = sp44->unkC; + phi_v1 = sp44->unkE; + temp_a3 = sp44->unk9; + temp_t0 = sp44->unkA; + temp_t1 = sp44->unkB; + temp_a1 = sp44->unk10; + if (phi_v1 < phi_a0) { + phi_v1 = sp44->unkC; + phi_a0 = sp44->unkE; + } + if (phi_v1 >= 0x400) { + phi_v1 = 0x3FF; + } + if (phi_a0 >= phi_v1 - 5) { + phi_a0 = phi_v1 - 5; + } + temp_v0_3 = &D_8011D388[index]; + temp_v0_3->unk28 = temp_a3; + temp_v0_3->unk29 = temp_t0; + temp_v0_3->unk2A = temp_t1; + temp_v0_3->unk2C = phi_a0; + temp_v0_3->unk2E = phi_v1; + temp_v0_3->unk14 = ((temp_a3 << 16) - temp_v0_3->unk0) / temp_a1; + temp_v0_3->unk18 = ((temp_t0 << 16) - temp_v0_3->unk4) / temp_a1; + temp_v0_3->unk1C = ((temp_t1 << 16) - temp_v0_3->unk8) / temp_a1; + temp_v0_3->unk20 = ((phi_a0 << 16) - temp_v0_3->unkC) / temp_a1; + temp_v0_3->unk24 = ((phi_v1 << 16) - temp_v0_3->unk10) / temp_a1; + temp_v0_3->unk30 = temp_a1; + temp_v0_3->unk34 = obj; + } + } + } +} + +#else GLOBAL_ASM("asm/non_matchings/unknown_0255E0/obj_loop_fogchanger.s") +#endif + +#ifdef NON_EQUIVALENT +void func_80030DE0(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5, s32 arg6) { + s32 max, min; + unk8011D388 *entry; + + entry = &D_8011D388[arg0]; + max = arg5; + min = arg4; + if (arg5 < arg4) { + max = arg4; + min = arg5; + } + if (max > 0x3FF) { + max = 0x3FF; + } + if (min >= max - 5) { + min = max - 5; + } + entry->unk28 = arg1; + entry->unk29 = arg2; + entry->unk2A = arg3; + entry->unk2C = min; + entry->unk2E = max; + entry->unk14 = ((arg1 << 16) - entry->unk0) / arg6; + entry->unk18 = ((arg2 << 16) - entry->unk4) / arg6; + entry->unk1C = ((arg3 << 16) - entry->unk8) / arg6; + entry->unk20 = ((min << 16) - entry->unkC) / arg6; + entry->unk24 = ((max << 16) - entry->unk10) / arg6; + entry->unk30 = arg6; + entry->unk34 = 0; +} +#else GLOBAL_ASM("asm/non_matchings/unknown_0255E0/func_80030DE0.s") +#endif + +// Unused +void func_80030FA0(void) { + D_8011B0B0 = func_80069D20(); + func_80031018(); + func_8001D5E0((f32) D_8011D468.x / 65536.0f, (f32) D_8011D468.y / 65536.0f, (f32) D_8011D468.z / 65536.0f); +} void func_80031018(void) { Matrix mf; diff --git a/src/unknown_0255E0.h b/src/unknown_0255E0.h index a28e3872..6f82817a 100644 --- a/src/unknown_0255E0.h +++ b/src/unknown_0255E0.h @@ -59,7 +59,7 @@ typedef struct unk8011D388 { s16 unk2C; s16 unk2E; s32 unk30; - s32 unk34; + Object *unk34; } unk8011D388; typedef struct { @@ -124,6 +124,8 @@ void func_8002D670(Object *, Object *); s32 func_8002A900(Object *arg0); Gfx *func_8002581C(u8 *segmentIds, s32 numberOfSegments, s32 currentViewportIndex); s32 func_80027568(void); +void func_8002C954(LevelModelSegment*, LevelModelSegmentBoundingBox*, s32); +s32 func_8002CC30(LevelModelSegment*); //void func_80013DCC(Gfx **arg0, Vertex **arg1, Vertex **arg2, Object *arg3); #endif diff --git a/tools/dkr_assets_tool.cpp b/tools/dkr_assets_tool.cpp index 10337637..da3f835a 100644 --- a/tools/dkr_assets_tool.cpp +++ b/tools/dkr_assets_tool.cpp @@ -1,5 +1,8 @@ /** * This tool handles everything assets-related including extracting and building. + * + * TODO: This file needs a refactor at some point. It is a bit of a mess. + * */ #include @@ -19,6 +22,7 @@ void print_usage() { std::cout << "---- Usages -------------------------------------------------------------" << std::endl; std::cout << "Extracting assets: ./dkr_assets_tool -e " << std::endl; std::cout << "Building an asset: ./dkr_assets_tool -b " << std::endl; + std::cout << "Build enums cache: ./dkr_assets_tool -bc " << std::endl; std::cout << "Creating includes: ./dkr_assets_tool -i " << std::endl; std::cout << "Compiling assets: ./dkr_assets_tool -c " << std::endl; std::cout << "Compress file: ./dkr_assets_tool -fc " << std::endl; @@ -36,6 +40,7 @@ typedef enum _ToolType { TT_ASSET_COMPILE, TT_ASSET_COMPRESS_FILE, TT_ASSET_DECOMPRESS_FILE, + TT_BUILD_ENUMS_CACHE, } ToolType; typedef struct _CmdArgOptions { @@ -56,6 +61,7 @@ std::string get_cmd_from_parse_option(ToolType type) { switch(type) { case TT_EXTRACT: return "-e"; case TT_BUILD: return "-b"; + case TT_BUILD_ENUMS_CACHE: return "-bc"; case TT_ASSET_INCLUDES: return "-i"; case TT_ASSET_COMPILE: return "-c"; case TT_ASSET_COMPRESS_FILE: return "-fc"; @@ -112,6 +118,11 @@ bool parse_options(int argc, char *argv[]) { curOptionState = 6; options.type = TT_ASSET_DECOMPRESS_FILE; parsingCmd = true; + } else if(args[i] == "-bc") { + curOption = PO_TYPE; + curOptionState = 7; + options.type = TT_BUILD_ENUMS_CACHE; + parsingCmd = true; } else if(args[i] == "-h") { return false; } else { @@ -177,6 +188,7 @@ bool parse_options(int argc, char *argv[]) { case 4: // Compile assets case 5: // Compress file case 6: // Decompress file + case 7: // Build enums cache. switch(curOptionArgs) { case 0: // Assets directory / Input filename options.paths.push_back(args[i]); @@ -242,6 +254,15 @@ int main(int argc, char *argv[]) { Builder builder(sourcePath, outputPath); } break; + case TT_BUILD_ENUMS_CACHE: + { + std::string version = options.paths[0]; // us_1.0 + std::string enumsHeaderPath = options.paths[1]; // /include/enums.h + + set_version(version); + generate_enums_cache(enumsHeaderPath); + } + break; case TT_ASSET_INCLUDES: { std::string version = options.paths[0]; // us_1.0 diff --git a/tools/dkr_assets_tool_classes/common/util/enumHelper.cpp b/tools/dkr_assets_tool_classes/common/util/enumHelper.cpp index da01620c..51b44a75 100644 --- a/tools/dkr_assets_tool_classes/common/util/enumHelper.cpp +++ b/tools/dkr_assets_tool_classes/common/util/enumHelper.cpp @@ -8,6 +8,12 @@ bool hasLoadedEnums = false; std::map enums; std::map> enumKeys; +std::string ENUMS_CACHE_PATH = ""; + +void set_enums_cache_path() { + ENUMS_CACHE_PATH = "./build/" + get_version() + "/enumsCache.bin"; +} + int evalulate_enum(std::string &enumValue) { int attempts = 0; std::regex enumNameRegex("([^0-9|^&~+\\-\\/*\\s]+)"); @@ -123,30 +129,32 @@ void load_enums_cache() { } } +void generate_enums_cache(std::string enumsHeaderPath) { + set_enums_cache_path(); + // Generate enums map + path_must_exist(enumsHeaderPath); + std::string enumsIncludeText = read_text_file(enumsHeaderPath); + std::regex enumRegex("enum ([^\\s{]+)\\s*[{]((?:.*\\n)*?)[}]"); + std::smatch sm; + std::string text = enumsIncludeText; + while (regex_search(text, sm, enumRegex)) { + std::string enumName = sm[1]; + std::string enumValuesText = sm[2]; + get_enum_values(enumName, enumValuesText); + text = sm.suffix(); + } + save_enums_cache(); +} + std::mutex enumsMutex; void make_sure_enums_are_loaded() { enumsMutex.lock(); if(!hasLoadedEnums) { - std::string assetsFolderPath = get_asset_folder_path(); - ensure_that_path_exists("build/"); // Make sure build folder exists - if(path_exists(ENUMS_CACHE_PATH)) { - load_enums_cache(); - } else { - // Generate enums map - path_must_exist("include/enums.h"); - std::string enumsIncludeText = read_text_file("include/enums.h"); - std::regex enumRegex("enum ([^\\s{]+)\\s*[{]((?:.*\\n)*?)[}]"); - std::smatch sm; - std::string text = enumsIncludeText; - while (regex_search(text, sm, enumRegex)) { - std::string enumName = sm[1]; - std::string enumValuesText = sm[2]; - get_enum_values(enumName, enumValuesText); - text = sm.suffix(); - } - save_enums_cache(); + if(ENUMS_CACHE_PATH == "") { + set_enums_cache_path(); } + load_enums_cache(); hasLoadedEnums = true; } enumsMutex.unlock(); diff --git a/tools/dkr_assets_tool_classes/common/util/enumHelper.h b/tools/dkr_assets_tool_classes/common/util/enumHelper.h index 6e31cc41..431eb5f6 100644 --- a/tools/dkr_assets_tool_classes/common/util/enumHelper.h +++ b/tools/dkr_assets_tool_classes/common/util/enumHelper.h @@ -15,8 +15,7 @@ #include "fileHelper.h" -#define ENUMS_PATH "../../../../include/enums.h" -#define ENUMS_CACHE_PATH "./build/enums_cache" +void generate_enums_cache(std::string enumsHeaderPath); std::string get_enum_string_from_value(std::string enumName, int value); int get_enum_value_from_string(std::string enumName, std::string value);