diff --git a/src/SB/Core/gc/iSystem.cpp b/src/SB/Core/gc/iSystem.cpp index 403e83f1d..4f5274cb6 100644 --- a/src/SB/Core/gc/iSystem.cpp +++ b/src/SB/Core/gc/iSystem.cpp @@ -751,8 +751,9 @@ static S32 dlFseek(void* fptr, long offset, int origin) bufStart = (fp->unk_283C / (U32)DLFILE_BUF_SIZE) * DLFILE_BUF_SIZE; if (DVDReadPrio(&fp->unk_2800, fp->readBuffer, - (fp->unk_2840 - bufStart <= DLFILE_BUF_SIZE) ? (fp->unk_2840 - bufStart + 31) & ~31 : - DLFILE_BUF_SIZE, + (fp->unk_2840 - bufStart <= DLFILE_BUF_SIZE) ? + (fp->unk_2840 - bufStart + 31) & ~31 : + DLFILE_BUF_SIZE, bufStart, 2) == -1) { fp->unk_283C = oldFPos; @@ -843,8 +844,7 @@ static void* _rwDolphinFSOpen(void* param_1, int param_2, int param_3) } RwFileFunctions* funcs = RwOsGetFileInterface(); - RWPLUGINOFFSET(dlFSUnkGlobals, RwEngineInstance, FSModuleInfo.globalsOffset)->unk_00 = - *funcs; + RWPLUGINOFFSET(dlFSUnkGlobals, RwEngineInstance, FSModuleInfo.globalsOffset)->unk_00 = *funcs; funcs->rwfexist = dlFexist; funcs->rwfopen = dlFopen; diff --git a/src/SB/Core/x/xCM.cpp b/src/SB/Core/x/xCM.cpp index c4a8984cb..58b9970b2 100644 --- a/src/SB/Core/x/xCM.cpp +++ b/src/SB/Core/x/xCM.cpp @@ -1,14 +1,41 @@ #include "xCM.h" #include "xEvent.h" +#include "xFont.h" +#include "xstransvc.h" +#include "xDebug.h" +#include "xVec3.h" +#include +#include #include -volatile static F32 credits_time; +// TODO: find and move to appropriate header +U32 Im2DRenderQuad(F32 x0, F32 y0, F32 x1, F32 y1, F32 z, F32 alpha, F32 uv_offset); + +void __deadstripped_rodata() +{ + const xVec3 dead0 = {}; + const xVec3 dead1 = {}; + const xVec3 dead2 = {}; + const xVec3 dead3 = {}; + const U8 dead4[0x28] = {}; + const U8 dead5[0x28] = {}; + const U8 dead6[0x28] = {}; + const U8 dead7[0x28] = {}; + const U8 dead8[0x28] = {}; + const U8 dead9[0x28] = {}; + const U8 dead10[0x28] = {}; +} + +static const basic_rect screen_bounds = { 0.0f, 0.0f, 1.0f, 1.0f }; +static const basic_rect default_adjust = { 0.0f, 0.0f, 1.0f, 1.0f }; + +F32 dtscale = 1.0f; + +static F32 credits_time = 10000.0f; static xCreditsData* credits_data; static U32 credits_parentID; -F32 dtscale; - static void xCMprep(xCreditsData* data) { /* @@ -27,41 +54,41 @@ static void xCMprep(xCreditsData* data) return; } - xCMcredits* cp = (xCMcredits *)(&hdr[1]); - while ((int)cp - (int)data < hdr->total_size) + xCMcredits* cp = (xCMcredits*)(&hdr[1]); + while ((S32)cp - (S32)data < hdr->total_size) { xCMpreset* pp = (xCMpreset*)(&cp[1]); xCMhunk* hp = (xCMhunk*)(&pp[cp->num_presets]); - for ( ; (int)hp - (int)cp < cp->credits_size; hp = (xCMhunk*)((int)hp + hp->hunk_size)) + for (; (S32)hp - (S32)cp < cp->credits_size; hp = (xCMhunk*)((S32)hp + hp->hunk_size)) { switch (pp[hp->preset].align) { - case 0: - case 1: - case 2: - case 3: + case 0: + case 1: + case 2: + case 3: if (hdr->state == 0) { if (hp->text1 != NULL) { - hp->text1 -= (int)data; + hp->text1 -= (S32)data; } if (hp->text2 != NULL) { - hp->text2 -= (int)data; + hp->text2 -= (S32)data; } } else { if (hp->text1 != NULL) { - hp->text1 += (int)data; + hp->text1 += (S32)data; } if (hp->text2 != NULL) { - hp->text2 += (int)data; + hp->text2 += (S32)data; } } break; @@ -73,12 +100,196 @@ static void xCMprep(xCreditsData* data) hdr->state = hdr->state == 0 ? 1 : 0; } +static iColor_tag xCMcolor_scale(iColor_tag color, F32 t) +{ + F64 r = (F64)color.r; + F64 g = (F64)color.g; + F64 b = (F64)color.b; + F64 a = (F64)color.a * (F64)t; + + iColor_tag ret; + xColorInit(&ret, (U8)r, (U8)g, (U8)b, (U8)a); + return ret; +} + +void __deadstripped_strings(xCMpreset* preset) +{ + switch (preset->align) + { + // TODO: Assign correct cases to these and make an enum/defines out of it + default: + { + xprintf("CM_ALIGN_CENTER"); + xprintf("CM_ALIGN_LEFT"); + xprintf("CM_ALIGN_RIGHT"); + xprintf("CM_ALIGN_INNER"); + xprintf("CM_ALIGN_TEXTURE"); + } + } +} + +static U32 xCMrender(F32 time, xCreditsData* data) +{ + if (data == NULL || ((xCMheader*)data)->magic != 0xBEEEEEEF) + return 0; + + xCMheader* hdr = (xCMheader*)data; + if (hdr->state == 1) + xCMprep(data); + + char* dp = (char*)data; + + xprintf("credits time %6.2f\n", time); + + xCMhunk* hp; + xCMcredits* cp = (xCMcredits*)(dp + sizeof(xCMheader)); + while ((U32)((char*)cp - dp) < hdr->total_size) + { + xCMpreset* pp = (xCMpreset*)((char*)cp + sizeof(xCMcredits)); + hp = (xCMhunk*)((char*)pp + cp->num_presets * sizeof(xCMpreset)); + + for (; (U32)((char*)hp - (char*)cp) < cp->credits_size; + hp = (xCMhunk*)((char*)hp + hp->hunk_size)) + { + if (time >= hp->t0 && time <= hp->t1) + { + F32 t = (time - hp->t0) / (hp->t1 - hp->t0); + xCMpreset* preset = &pp[hp->preset]; + + F32 yScroll = t * (cp->out.y - cp->in.y) + cp->in.y; + + F32 a; + if (t < cp->fin.start || t > cp->fout.end) + a = 0.0f; + else if (t >= cp->fin.start && t <= cp->fin.end) + a = (t - cp->fin.start) / (cp->fin.end - cp->fin.start); + else if (t >= cp->fout.start && t <= cp->fout.end) + a = (cp->fout.end - t) / (cp->fout.end - cp->fout.start); + else + a = 1.0f; + + switch (preset->align) + { + case 4: + { + xCMtexture* tex = (xCMtexture*)&preset->box[0]; + if (tex->texture == NULL) + tex->texture = (RwTexture*)xSTFindAsset(tex->assetID, NULL); + if (tex->texture != NULL) + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, tex->texture->raster); + + F32 x0 = 640.0f * tex->x; + F32 y0 = 480.0f * tex->y; + F32 x1 = 640.0f * (tex->x + tex->w); + F32 y1 = 480.0f * (tex->y + tex->h); + Im2DRenderQuad(x0, y0, x1, y1, 0.0f, 1000000.0f, 0.5f); + xprintf("tex %6.2f,%6.2f - %6.2f,%6.2f\n", x0, y0, x1, y1); + break; + } + case 0: + { + xCMtextbox* box = &preset->box[0]; + + basic_rect bounds = { 0.0f, 0.0f, 0.0f, 0.0f }; + bounds.x = 0.5f * (1.0f - box->box.x); + bounds.y = yScroll; + bounds.w = box->box.x; + bounds.h = box->box.y; + + iColor_tag scaled = xCMcolor_scale(box->color, a); + + xtextbox tb = + xtextbox::create(xfont::create(box->font, NSCREENX(box->char_size.x), + NSCREENY(box->char_size.y), + box->char_spacing.x, scaled, screen_bounds), + bounds, 2, 0.0f, 0.0f, 0.0f, 0.0f); + tb.set_text(hp->text1); + tb.render(true); + break; + } + case 1: + case 2: + case 3: + { + xCMtextbox* box0 = &preset->box[0]; + xCMtextbox* box1 = &preset->box[1]; + + F32 x0 = 0.5f * (1.0f - box0->box.x - preset->innerspace - box1->box.x); + + U32 alignL, alignR; + if (preset->align == 1) + { + alignL = 0; + alignR = 0; + } + else if (preset->align == 2) + { + alignL = 1; + alignR = 1; + } + else + { + alignL = 1; + alignR = 0; + } + + // Scoped because of multiple bounds in dwarf + { + iColor_tag scaled0 = xCMcolor_scale(box0->color, a); + basic_rect bounds = { 0.0f, 0.0f, 0.0f, 0.0f }; + bounds.x = x0; + bounds.y = yScroll; + bounds.w = box0->box.x; + bounds.h = box0->box.y; + + xtextbox tb = xtextbox::create( + xfont::create(box0->font, NSCREENX(box0->char_size.x), + NSCREENY(box0->char_size.y), box0->char_spacing.x, + scaled0, screen_bounds), + bounds, alignL, 0.0f, 0.0f, 0.0f, 0.0f); + tb.set_text(hp->text1); + tb.render(true); + } + + F32 x1 = x0 + box0->box.x + preset->innerspace; + + { + iColor_tag scaled1 = xCMcolor_scale(box1->color, a); + basic_rect bounds = { 0.0f, 0.0f, 0.0f, 0.0f }; + bounds.x = x1; + bounds.y = yScroll; + bounds.w = box1->box.x; + bounds.h = box1->box.y; + + xtextbox tb = xtextbox::create( + xfont::create(box1->font, NSCREENX(box1->char_size.x), + NSCREENY(box1->char_size.y), box1->char_spacing.x, + scaled1, screen_bounds), + bounds, alignR, 0.0f, 0.0f, 0.0f, 0.0f); + tb.set_text(hp->text2); + tb.render(true); + } + break; + } + default: + break; + } + } + } + cp = (xCMcredits*)hp; + } + + if (time >= 0.0f && time <= hdr->total_time) + return 1; + return 0; +} + void xCMupdate(F32 time) { if (credits_data != 0) { credits_time += (time * dtscale); - if (credits_time >= *(F32*)((int)&credits_data->dummy + 0x10)) + if (credits_time >= *(F32*)((S32)&credits_data->dummy + 0x10)) { xCMstop(); } diff --git a/src/SB/Core/x/xCM.h b/src/SB/Core/x/xCM.h index e0ceb582a..a136991d5 100644 --- a/src/SB/Core/x/xCM.h +++ b/src/SB/Core/x/xCM.h @@ -10,87 +10,84 @@ struct xCreditsData U32 dummy; }; -class xCMheader +struct xCMheader { - // total size: 0x18 -public: - unsigned int magic; // offset 0x0, size 0x4 - unsigned int version; // offset 0x4, size 0x4 - unsigned int crdID; // offset 0x8, size 0x4 - unsigned int state; // offset 0xC, size 0x4 - float total_time; // offset 0x10, size 0x4 - unsigned int total_size; // offset 0x14, size 0x4 + U32 magic; // 0x0 + U32 version; // 0x4 + U32 crdID; // 0x8 + U32 state; // 0xC + F32 total_time; // 0x10 + U32 total_size; // 0x14 }; -class sxy +struct sxy { - // total size: 0x8 -public: - float x; // offset 0x0, size 0x4 - float y; // offset 0x4, size 0x4 + F32 x; // 0x0 + F32 y; // 0x4 }; -class fade +struct fade { - // total size: 0x8 -public: - float start; // offset 0x0, size 0x4 - float end; // offset 0x4, size 0x4 + F32 start; // 0x0 + F32 end; // 0x4 }; -class xCMtextbox +struct xCMtextbox { - // total size: 0x20 -public: - unsigned int font; // offset 0x0, size 0x4 - class iColor_tag color; // offset 0x4, size 0x4 - class sxy char_size; // offset 0x8, size 0x8 - class sxy char_spacing; // offset 0x10, size 0x8 - class sxy box; // offset 0x18, size 0x8 + U32 font; // 0x0 + iColor_tag color; // 0x4 + sxy char_size; // 0x8 + sxy char_spacing; // 0x10 + sxy box; // 0x18 }; -class xCMpreset +struct xCMtexture { - // total size: 0x4C -public: - unsigned short num; // offset 0x0, size 0x2 - unsigned short align; // offset 0x2, size 0x2 - float delay; // offset 0x4, size 0x4 - float innerspace; // offset 0x8, size 0x4 - class xCMtextbox box[2]; // offset 0xC, size 0x40 + U32 assetID; // 0x0 + iColor_tag color; // 0x4 + F32 x; // 0x8 + F32 y; // 0xC + F32 w; // 0x10 + F32 h; // 0x14 + RwTexture* texture; // 0x18 + U32 pad; // 0x1C }; -class xCMhunk +struct xCMpreset { - // total size: 0x18 -public: - unsigned int hunk_size; // offset 0x0, size 0x4 - unsigned int preset; // offset 0x4, size 0x4 - float t0; // offset 0x8, size 0x4 - float t1; // offset 0xC, size 0x4 - char * text1; // offset 0x10, size 0x4 - char * text2; // offset 0x14, size 0x4 + U16 num; // 0x0 + U16 align; // 0x2 + F32 delay; // 0x4 + F32 innerspace; // 0x8 + xCMtextbox box[2]; // 0xC }; -class xCMcredits +struct xCMhunk { - // total size: 0x38 -public: - unsigned int credits_size; // offset 0x0, size 0x4 - float len; // offset 0x4, size 0x4 - unsigned int flags; // offset 0x8, size 0x4 - sxy in; // offset 0xC, size 0x8 - sxy out; // offset 0x14, size 0x8 - float scroll_rate; // offset 0x1C, size 0x4 - float lifetime; // offset 0x20, size 0x4 - fade fin; // offset 0x24, size 0x8 - fade fout; // offset 0x2C, size 0x8 - unsigned int num_presets; // offset 0x34, size 0x4 + U32 hunk_size; // 0x0 + U32 preset; // 0x4 + F32 t0; // 0x8 + F32 t1; // 0xC + char* text1; // 0x10 + char* text2; // 0x14 +}; + +struct xCMcredits +{ + U32 credits_size; // 0x0 + F32 len; // 0x4 + U32 flags; // 0x8 + sxy in; // 0xC + sxy out; // 0x14 + F32 scroll_rate; // 0x1C + F32 lifetime; // 0x20 + fade fin; // 0x24 + fade fout; // 0x2C + U32 num_presets; // 0x34 }; void xCMupdate(F32 dt); void xCMrender(); -void xCMrender(F32 time, xCreditsData* data); void xCMstart(xCreditsData* data, F32, xBase* parent); void xCMstop(); diff --git a/src/SB/Core/x/xColor.h b/src/SB/Core/x/xColor.h index fcd3ef124..991586e91 100644 --- a/src/SB/Core/x/xColor.h +++ b/src/SB/Core/x/xColor.h @@ -20,4 +20,12 @@ extern const iColor_tag g_PINK; iColor_tag xColorFromRGBA(U8 r, U8 g, U8 b, U8 a); +inline void xColorInit(iColor_tag* ret, U8 r, U8 g, U8 b, U8 a) +{ + ret->r = r; + ret->g = g; + ret->b = b; + ret->a = a; +} + #endif