Skip to content

Commit

Permalink
Merge branch 'alexbatalov:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Northfear authored Jan 21, 2023
2 parents a3ced07 + 3aea6a9 commit b67b308
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 25 deletions.
34 changes: 34 additions & 0 deletions src/art.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,40 @@ static int artReadHeader(Art* art, File* stream)
return 0;
}

// NOTE: Original function was slightly different, but never used. Basically
// it's a memory allocating variant of `artRead` (which reads data into given
// buffer). This function is useful to load custom `frm` files since `Art` now
// needs more memory then it's on-disk size (due to memory padding).
//
// 0x419EC0
Art* artLoad(const char* path)
{
File* stream = fileOpen(path, "rb");
if (stream == nullptr) {
return nullptr;
}

Art header;
if (artReadHeader(&header, stream) != 0) {
fileClose(stream);
return nullptr;
}

fileClose(stream);

unsigned char* data = reinterpret_cast<unsigned char*>(internal_malloc(artGetDataSize(&header)));
if (data == nullptr) {
return nullptr;
}

if (artRead(path, data) != 0) {
internal_free(data);
return nullptr;
}

return reinterpret_cast<Art*>(data);
}

// 0x419FC0
int artRead(const char* path, unsigned char* data)
{
Expand Down
1 change: 1 addition & 0 deletions src/art.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ int _art_alias_num(int a1);
int artCritterFidShouldRun(int a1);
int artAliasFid(int fid);
int buildFid(int objectType, int frmId, int animType, int a4, int rotation);
Art* artLoad(const char* path);
int artRead(const char* path, unsigned char* data);
int artWrite(const char* path, unsigned char* data);

Expand Down
36 changes: 11 additions & 25 deletions src/interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2483,30 +2483,26 @@ static void customInterfaceBarInit()
{
gInterfaceBarContentOffset = gInterfaceBarWidth - 640;

char path[COMPAT_MAX_PATH];
snprintf(path, sizeof(path), "art\\intrface\\HR_IFACE_%d.FRM", gInterfaceBarWidth);
if (gInterfaceBarContentOffset > 0 && screenGetWidth() > 640) {
char path[COMPAT_MAX_PATH];
snprintf(path, sizeof(path), "art\\intrface\\HR_IFACE_%d.FRM", gInterfaceBarWidth);

gCustomInterfaceBarBackground = artLoad(path);
}

int size;
if (dbGetFileSize(path, &size) != 0 || gInterfaceBarContentOffset <= 0 || screenGetWidth() <= 640) {
if (gCustomInterfaceBarBackground != nullptr) {
gInterfaceBarIsCustom = true;
} else {
gInterfaceBarContentOffset = 0;
gInterfaceBarWidth = 640;
gInterfaceBarIsCustom = false;
} else {
gInterfaceBarIsCustom = true;

gCustomInterfaceBarBackground = (Art*)(malloc(size));
if (artRead(path, (unsigned char*)gCustomInterfaceBarBackground) != 0) {
gInterfaceBarIsCustom = false;
free(gCustomInterfaceBarBackground);
gCustomInterfaceBarBackground = nullptr;
}
}
}

static void customInterfaceBarExit()
{
if (gCustomInterfaceBarBackground != nullptr) {
free(gCustomInterfaceBarBackground);
internal_free(gCustomInterfaceBarBackground);
gCustomInterfaceBarBackground = nullptr;
}
}
Expand Down Expand Up @@ -2585,21 +2581,11 @@ static void sidePanelsShow()

static void sidePanelsDraw(const char* path, int win, bool isLeading)
{
int size;
if (dbGetFileSize(path, &size) != 0) {
return;
}

Art* image = reinterpret_cast<Art*>(internal_malloc(size));
Art* image = artLoad(path);
if (image == nullptr) {
return;
}

if (artRead(path, reinterpret_cast<unsigned char*>(image)) != 0) {
internal_free(image);
return;
}

unsigned char* imageData = artGetFrameData(image, 0, 0);

int imageWidth = artGetWidth(image, 0, 0);
Expand Down

0 comments on commit b67b308

Please sign in to comment.