Skip to content

Commit

Permalink
Fix powder keg crash by creating and using a larger texture. (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
louist103 authored Apr 8, 2024
1 parent cfd5195 commit 293c892
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions mm/assets/overlays/ovl_En_Bom/ovl_En_Bom.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include "align_asset_macro.h"

#define dgPowderKegFuseVtx "__OTR__overlays/ovl_En_Bom/gPowderKegFuseVtx"
static const ALIGN_ASSET(2) char gPowderKegFuseVtx[] = dgPowderKegFuseVtx;

#define dgPowderKegFuseTex "__OTR__overlays/ovl_En_Bom/gPowderKegFuseTex"
static const ALIGN_ASSET(2) char gPowderKegFuseTex[] = dgPowderKegFuseTex;

Expand Down
3 changes: 3 additions & 0 deletions mm/assets/xml/overlays/ovl_En_Bom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<!-- Assets for the Powder Keg -->
<File Name="ovl_En_Bom" BaseAddress="0x80870DB0" RangeStart="0x2160" RangeEnd="0x3610">
<!-- Texture and DisplayLists for the Powder Keg's fuse -->
<Array Name="gPowderKegFuseVtx" Count="8" Offset="0x2160">
<Vtx/>
</Array>
<Texture Name="gPowderKegFuseTex" OutName="powder_keg_fuse" Format="i8" Width="2" Height="2" Offset="0x21E0"/>
<DList Name="gPowderKegFuseMaterialDL" Offset="0x21E8"/>
<DList Name="gPowderKegFuseModel1DL" Offset="0x2270"/>
Expand Down
27 changes: 23 additions & 4 deletions mm/src/overlays/actors/ovl_En_Bom/z_en_bom.c
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,12 @@ void func_808726DC(PlayState* play, Vec3f* arg1, Vec3f* arg2, Vec3f* arg3, s32 a
Math_Vec3f_Copy(arg1, &fuseSegmentPtr->pos);
}

void EnBom_DrawKeg(PlayState* play, s32 arg1) {

// 2S2H [Port] See comment in the draw function.
#define dgPowderKegFuseTexLarger "__OTR__overlays/ovl_En_Bom/gPowderKegFuseTexLarger"
static const ALIGN_ASSET(2) char gPowderKegFuseTexLarger[] = dgPowderKegFuseTexLarger;

void EnBom_DrawKeg(PlayState* play, s32 timer) {
s32 temp_s5;
s32 i;
PowderKegFuseSegment* fuseSegmentPtr = &sPowderKegFuseSegments[0];
Expand All @@ -800,9 +805,23 @@ void EnBom_DrawKeg(PlayState* play, s32 arg1) {
Matrix_Scale(0.01f, 0.01f, 0.01f, MTXMODE_APPLY);

gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
gSPDisplayList(POLY_OPA_DISP++, gPowderKegFuseMaterialDL);

temp_s5 = (arg1 / 240) + 1;
// 2S2H [Port] This was originally a static DL in the OTR file. The normal texture is too small to be rendered by Fast3D
// and causes a crash.
// This adds a custom texture in the OTR file and changes the DList to use the new size. At some point this should be
// done in the GFX patcher.
gDPPipeSync(POLY_OPA_DISP++);
gDPSetTextureLUT(POLY_OPA_DISP++, G_TT_NONE);
gSPClearGeometryMode(POLY_OPA_DISP++, G_CULL_BOTH);
gSPSetGeometryMode(POLY_OPA_DISP++, G_LIGHTING);
gDPSetCombineMode(POLY_OPA_DISP++, G_CC_MODULATEIDECALA, G_CC_MODULATEI_PRIM2);
gDPSetRenderMode(POLY_OPA_DISP++, G_RM_FOG_SHADE_A, G_RM_AA_ZB_OPA_SURF2);
gSPTexture(POLY_OPA_DISP++, 0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON);
gDPLoadTextureBlock(POLY_OPA_DISP++, gPowderKegFuseTexLarger, G_IM_FMT_I, G_IM_SIZ_8b, 8, 8, 0,
G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, 1, 1, G_TX_NOLOD, G_TX_NOLOD);
gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 200, 200, 0, 255);
gSPVertex(POLY_OPA_DISP++, gPowderKegFuseVtx, 4, 0);

temp_s5 = (timer / 240) + 1;
fuseSegmentPtr2 = &sPowderKegFuseSegments[1];

for (i = 1; i < temp_s5; i++, fuseSegmentPtr2++) {
Expand Down

0 comments on commit 293c892

Please sign in to comment.