Skip to content

Commit

Permalink
d_font_manager
Browse files Browse the repository at this point in the history
  • Loading branch information
robojumper committed Jun 20, 2024
1 parent 20ed993 commit b3e23c3
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 21 deletions.
6 changes: 5 additions & 1 deletion config/SOUE01/splits.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ d/d_fader.cpp:
.ctors start:0x804DB678 end:0x804DB67C

d/d_font_manager.cpp:
.text start:0x80053E70 end:0x800541D0
.text start:0x80053E70 end:0x800541EC
.ctors start:0x804DB67C end:0x804DB680
.rodata start:0x804DDFF0 end:0x804DE008
.data start:0x8050D358 end:0x8050D440
.sbss start:0x80575108 end:0x80575110
.bss start:0x80597608 end:0x80597740

d/d_gfx.cpp:
.text start:0x800541F0 end:0x80054B00
Expand Down
43 changes: 23 additions & 20 deletions config/SOUE01/symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2191,17 +2191,17 @@ fn_80053C50 = .text:0x80053C50; // type:function size:0x198
fn_80053DF0 = .text:0x80053DF0; // type:function size:0x1C
fn_80053E10 = .text:0x80053E10; // type:function size:0x38
fn_80053E50 = .text:0x80053E50; // type:function size:0x20
fn_80053E70 = .text:0x80053E70; // type:function size:0x50
fn_80053EC0 = .text:0x80053EC0; // type:function size:0x68
fn_80053F30 = .text:0x80053F30; // type:function size:0x34
fn_80053F70 = .text:0x80053F70; // type:function size:0x14
fn_80053F90 = .text:0x80053F90; // type:function size:0x14
fn_80053FB0 = .text:0x80053FB0; // type:function size:0x18
fn_80053FD0 = .text:0x80053FD0; // type:function size:0x18
fn_80053FF0 = .text:0x80053FF0; // type:function size:0xB4
fn_800540B0 = .text:0x800540B0; // type:function size:0xB4
fn_80054170 = .text:0x80054170; // type:function size:0x58
fn_800541D0 = .text:0x800541D0; // type:function size:0x1C
__ct__10dFontMng_cFv = .text:0x80053E70; // type:function size:0x50
__dt__10dFontMng_cFv = .text:0x80053EC0; // type:function size:0x68
getFont__10dFontMng_cFUc = .text:0x80053F30; // type:function size:0x34
getFontName__FUc = .text:0x80053F70; // type:function size:0x14
getFontManager__10dFontMng_cFi = .text:0x80053F90; // type:function size:0x14
getFontMgrIdx__10dFontMng_cFUc = .text:0x80053FB0; // type:function size:0x18
setFontFile__10dFontMng_cFiPv = .text:0x80053FD0; // type:function size:0x18
getFontPath__10dFontMng_cFUc = .text:0x80053FF0; // type:function size:0xB4
create__10dFontMng_cFv = .text:0x800540B0; // type:function size:0xB4
__sinit_\d_font_manager_cpp = .text:0x80054170; // type:function size:0x58 scope:local
__arraydtor$4302 = .text:0x800541D0; // type:function size:0x1C scope:local
fn_800541F0 = .text:0x800541F0; // type:function size:0xD4
fn_800542D0 = .text:0x800542D0; // type:function size:0x70
fn_80054340 = .text:0x80054340; // type:function size:0x54
Expand Down Expand Up @@ -27834,7 +27834,7 @@ lbl_804DCB24 = .rodata:0x804DCB24; // type:object size:0xCC
DYNAMIC_NAME_TABLE = .rodata:0x804DCBF0; // type:object size:0x13E0
lbl_804DDFD0 = .rodata:0x804DDFD0; // type:object size:0xC data:4byte
lbl_804DDFDC = .rodata:0x804DDFDC; // type:object size:0x14 data:4byte
lbl_804DDFF0 = .rodata:0x804DDFF0; // type:object size:0x18
fontMgrIndex = .rodata:0x804DDFF0; // type:object size:0x14
@stringBase@ = .rodata:0x804DE008; // type:object size:0x28 scope:local data:string_table
lbl_804DE030 = .rodata:0x804DE030; // type:object size:0x28
lbl_804DE058 = .rodata:0x804DE058; // type:object size:0x2C
Expand Down Expand Up @@ -30700,11 +30700,14 @@ __vt__21dDynamicModuleControl = .data:0x8050D330; // type:object size:0xC
lbl_8050D33C = .data:0x8050D33C; // type:object size:0xC
lbl_8050D348 = .data:0x8050D348; // type:object size:0x10
lbl_8050D358 = .data:0x8050D358; // type:object size:0x10 data:string
lbl_8050D368 = .data:0x8050D368; // type:object size:0x14
lbl_8050D37C = .data:0x8050D37C; // type:object size:0x24
lbl_8050D368 = .data:0x8050D368; // type:object size:0x11 data:string
lbl_8050D37C = .data:0x8050D37C; // type:object size:0x11 data:string
systemFonts = .data:0x8050D390; // type:object size:0xC
lbl_8050D3A0 = .data:0x8050D3A0; // type:object size:0x10 data:string
lbl_8050D3B0 = .data:0x8050D3B0; // type:object size:0x14
lbl_8050D3C4 = .data:0x8050D3C4; // type:object size:0x7C
lbl_8050D3B0 = .data:0x8050D3B0; // type:object size:0x11 data:string
fonts = .data:0x8050D3C4; // type:object size:0x14
lbl_8050D420 = .data:0x8050D420; // type:object size:0x9 data:string
lbl_8050D42C = .data:0x8050D42C; // type:object size:0xF data:string
__vt__14dHeapAllocator = .data:0x8050D440; // type:object size:0x18
lbl_8050D458 = .data:0x8050D458; // type:object size:0xC data:string
lbl_8050D464 = .data:0x8050D464; // type:object size:0x10
Expand Down Expand Up @@ -39740,7 +39743,7 @@ cCc_frmHeap__4dDyl = .sbss:0x805750F0; // type:object size:0x4 data:4byte
Initialized__4dDyl = .sbss:0x805750F4; // type:object size:0x1 data:byte
DVD__4dDyl = .sbss:0x805750F8; // type:object size:0x4 data:4byte
lbl_80575100 = .sbss:0x80575100; // type:object size:0x8 data:byte
lbl_80575108 = .sbss:0x80575108; // type:object size:0x8 data:byte
@GUARD@getFontPath__10dFontMng_cFUc@TEMP_FONT_NAME = .sbss:0x80575108; // type:object size:0x1 data:byte
lbl_80575110 = .sbss:0x80575110; // type:object size:0x8 data:4byte
lbl_80575118 = .sbss:0x80575118; // type:object size:0x4 data:4byte
lbl_8057511C = .sbss:0x8057511C; // type:object size:0x4 data:4byte
Expand Down Expand Up @@ -48177,9 +48180,9 @@ lbl_8059752C = .bss:0x8059752C; // type:object size:0x74 data:4byte
lbl_805975A0 = .bss:0x805975A0; // type:object size:0x10 data:float
lbl_805975B0 = .bss:0x805975B0; // type:object size:0x10
lbl_805975C0 = .bss:0x805975C0; // type:object size:0x48
lbl_80597608 = .bss:0x80597608; // type:object size:0x10
lbl_80597618 = .bss:0x80597618; // type:object size:0xA8
lbl_805976C0 = .bss:0x805976C0; // type:object size:0x80 data:byte
lbl_80597608 = .bss:0x80597608; // type:object size:0xC
l_dFontMng_obj = .bss:0x80597618; // type:object size:0xA8
@LOCAL@getFontPath__10dFontMng_cFUc@TEMP_FONT_NAME = .bss:0x805976C0; // type:object size:0x80 data:byte
sAllocator__14dHeapAllocator = .bss:0x80597740; // type:object size:0x18 data:4byte
lbl_80597758 = .bss:0x80597758; // type:object size:0x318
lbl_80597A70 = .bss:0x80597A70; // type:object size:0x10
Expand Down
1 change: 1 addition & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ def nw4rLib(lib_name, objects, extra_cflags=[]):
Object(Matching, "d/d_dvd.cpp"),
Object(NonMatching, "d/d_dvd_unk.cpp"),
Object(NonMatching, "d/d_dylink.cpp"),
Object(Matching, "d/d_font_manager.cpp"),
Object(NonMatching, "d/d_heap.cpp"),
Object(Matching, "d/d_rawarchive.cpp"),
Object(NonMatching, "d/d_stage.cpp"),
Expand Down
35 changes: 35 additions & 0 deletions include/d/d_font_manager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef D_FONT_MANAGER_H
#define D_FONT_MANAGER_H

#include <d/d_dvd.h>
#include <nw4r/ut/ut_ResFont.h>


class dFontMng_c {
public:
dFontMng_c();
~dFontMng_c();

static nw4r::ut::ResFont *getFont(u8 type);
void setFontFile(int idx, void *fileData);
static dFontMng_c *getFontManager(int idx);
static u8 getFontMgrIdx(u8 type);
static const char *getFontPath(u8 idx);

static bool create();

private:
static char special_01[];
static char special_00[];
static char normal_01[];
static char normal_00[];

nw4r::ut::ResFont mFont;
dDvd::loader_c mLoader;
// The purpose of these two is a bit unclear because they appear
// to be set to the same thing?
nw4r::ut::BinaryFileHeader *mpFontFile;
void *mpFileData;
};

#endif
77 changes: 77 additions & 0 deletions src/d/d_font_manager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include <d/d_font_manager.h>
#include <d/d_heap.h>
#include <sized_string.h>

static dFontMng_c l_dFontMng_obj[3];

static char *systemFonts[] = {"normal_00.brfnt", "special_00.brfnt", "picture_00.brfnt"};
static char *fonts[] = {"normal_00.brfnt", "normal_01.brfnt", "special_00.brfnt", "special_01.brfnt",
"picture_00.brfnt"};

// TODO What's up with these?
char dFontMng_c::normal_01[] = "normal_01.brfnt";
char dFontMng_c::normal_00[] = "normal_00.brfnt";
char dFontMng_c::special_01[] = "special_01.brfnt";
char dFontMng_c::special_00[] = "special_00.brfnt";

const u32 fontMgrIndex[] = {0, 0, 1, 1, 2};

dFontMng_c::dFontMng_c() {
l_dFontMng_obj[0].mpFileData = nullptr;
l_dFontMng_obj[1].mpFileData = nullptr;
l_dFontMng_obj[2].mpFileData = nullptr;
}

dFontMng_c::~dFontMng_c() {}

nw4r::ut::ResFont *dFontMng_c::getFont(u8 type) {
u8 index = getFontMgrIdx(type);
return &l_dFontMng_obj[index].mFont;
}

char *getFontName(u8 type) {
return fonts[type];
}

dFontMng_c *dFontMng_c::getFontManager(int idx) {
return &l_dFontMng_obj[idx];
}

u8 dFontMng_c::getFontMgrIdx(u8 type) {
return fontMgrIndex[type];
}

void dFontMng_c::setFontFile(int idx, void *fileData) {
l_dFontMng_obj[idx].mpFileData = fileData;
}

// getUsedLanguageString
extern "C" const char *fn_801B2DB0();

const char *dFontMng_c::getFontPath(u8 idx) {
static SizedString<128> TEMP_FONT_NAME;
if (idx == 2) {
TEMP_FONT_NAME.sprintf("/Font/%s", systemFonts[idx]);
} else {
TEMP_FONT_NAME.sprintf("/US/Font/%s/%s", fn_801B2DB0(), systemFonts[idx]);
}
return &TEMP_FONT_NAME;
}

bool dFontMng_c::create() {
for (u8 i = 0; i < 3; i++) {
if (l_dFontMng_obj[i].mpFontFile == nullptr) {
const char *path = getFontPath(i);
nw4r::ut::BinaryFileHeader *file = static_cast<nw4r::ut::BinaryFileHeader *>(
l_dFontMng_obj[i].mLoader.request(path, 0, dHeap::fontHeap.heap));
if (file == nullptr) {
return false;
}
l_dFontMng_obj[i].mpFontFile = file;
getFontManager(i)->setFontFile(i, l_dFontMng_obj[i].mpFontFile);
l_dFontMng_obj[i].mFont.SetResource(l_dFontMng_obj[i].mpFontFile);
}
}

return true;
}

0 comments on commit b3e23c3

Please sign in to comment.