Skip to content

Commit b67b308

Browse files
authored
Merge branch 'alexbatalov:main' into main
2 parents a3ced07 + 3aea6a9 commit b67b308

File tree

3 files changed

+46
-25
lines changed

3 files changed

+46
-25
lines changed

src/art.cc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,40 @@ static int artReadHeader(Art* art, File* stream)
10791079
return 0;
10801080
}
10811081

1082+
// NOTE: Original function was slightly different, but never used. Basically
1083+
// it's a memory allocating variant of `artRead` (which reads data into given
1084+
// buffer). This function is useful to load custom `frm` files since `Art` now
1085+
// needs more memory then it's on-disk size (due to memory padding).
1086+
//
1087+
// 0x419EC0
1088+
Art* artLoad(const char* path)
1089+
{
1090+
File* stream = fileOpen(path, "rb");
1091+
if (stream == nullptr) {
1092+
return nullptr;
1093+
}
1094+
1095+
Art header;
1096+
if (artReadHeader(&header, stream) != 0) {
1097+
fileClose(stream);
1098+
return nullptr;
1099+
}
1100+
1101+
fileClose(stream);
1102+
1103+
unsigned char* data = reinterpret_cast<unsigned char*>(internal_malloc(artGetDataSize(&header)));
1104+
if (data == nullptr) {
1105+
return nullptr;
1106+
}
1107+
1108+
if (artRead(path, data) != 0) {
1109+
internal_free(data);
1110+
return nullptr;
1111+
}
1112+
1113+
return reinterpret_cast<Art*>(data);
1114+
}
1115+
10821116
// 0x419FC0
10831117
int artRead(const char* path, unsigned char* data)
10841118
{

src/art.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ int _art_alias_num(int a1);
147147
int artCritterFidShouldRun(int a1);
148148
int artAliasFid(int fid);
149149
int buildFid(int objectType, int frmId, int animType, int a4, int rotation);
150+
Art* artLoad(const char* path);
150151
int artRead(const char* path, unsigned char* data);
151152
int artWrite(const char* path, unsigned char* data);
152153

src/interface.cc

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2483,30 +2483,26 @@ static void customInterfaceBarInit()
24832483
{
24842484
gInterfaceBarContentOffset = gInterfaceBarWidth - 640;
24852485

2486-
char path[COMPAT_MAX_PATH];
2487-
snprintf(path, sizeof(path), "art\\intrface\\HR_IFACE_%d.FRM", gInterfaceBarWidth);
2486+
if (gInterfaceBarContentOffset > 0 && screenGetWidth() > 640) {
2487+
char path[COMPAT_MAX_PATH];
2488+
snprintf(path, sizeof(path), "art\\intrface\\HR_IFACE_%d.FRM", gInterfaceBarWidth);
2489+
2490+
gCustomInterfaceBarBackground = artLoad(path);
2491+
}
24882492

2489-
int size;
2490-
if (dbGetFileSize(path, &size) != 0 || gInterfaceBarContentOffset <= 0 || screenGetWidth() <= 640) {
2493+
if (gCustomInterfaceBarBackground != nullptr) {
2494+
gInterfaceBarIsCustom = true;
2495+
} else {
24912496
gInterfaceBarContentOffset = 0;
24922497
gInterfaceBarWidth = 640;
24932498
gInterfaceBarIsCustom = false;
2494-
} else {
2495-
gInterfaceBarIsCustom = true;
2496-
2497-
gCustomInterfaceBarBackground = (Art*)(malloc(size));
2498-
if (artRead(path, (unsigned char*)gCustomInterfaceBarBackground) != 0) {
2499-
gInterfaceBarIsCustom = false;
2500-
free(gCustomInterfaceBarBackground);
2501-
gCustomInterfaceBarBackground = nullptr;
2502-
}
25032499
}
25042500
}
25052501

25062502
static void customInterfaceBarExit()
25072503
{
25082504
if (gCustomInterfaceBarBackground != nullptr) {
2509-
free(gCustomInterfaceBarBackground);
2505+
internal_free(gCustomInterfaceBarBackground);
25102506
gCustomInterfaceBarBackground = nullptr;
25112507
}
25122508
}
@@ -2585,21 +2581,11 @@ static void sidePanelsShow()
25852581

25862582
static void sidePanelsDraw(const char* path, int win, bool isLeading)
25872583
{
2588-
int size;
2589-
if (dbGetFileSize(path, &size) != 0) {
2590-
return;
2591-
}
2592-
2593-
Art* image = reinterpret_cast<Art*>(internal_malloc(size));
2584+
Art* image = artLoad(path);
25942585
if (image == nullptr) {
25952586
return;
25962587
}
25972588

2598-
if (artRead(path, reinterpret_cast<unsigned char*>(image)) != 0) {
2599-
internal_free(image);
2600-
return;
2601-
}
2602-
26032589
unsigned char* imageData = artGetFrameData(image, 0, 0);
26042590

26052591
int imageWidth = artGetWidth(image, 0, 0);

0 commit comments

Comments
 (0)