Fix loading custom interface frms
This commit is contained in:
parent
ba49abcea6
commit
3aea6a98ef
34
src/art.cc
34
src/art.cc
|
@ -1079,6 +1079,40 @@ static int artReadHeader(Art* art, File* stream)
|
||||||
return 0;
|
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
|
// 0x419FC0
|
||||||
int artRead(const char* path, unsigned char* data)
|
int artRead(const char* path, unsigned char* data)
|
||||||
{
|
{
|
||||||
|
|
|
@ -147,6 +147,7 @@ int _art_alias_num(int a1);
|
||||||
int artCritterFidShouldRun(int a1);
|
int artCritterFidShouldRun(int a1);
|
||||||
int artAliasFid(int fid);
|
int artAliasFid(int fid);
|
||||||
int buildFid(int objectType, int frmId, int animType, int a4, int rotation);
|
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 artRead(const char* path, unsigned char* data);
|
||||||
int artWrite(const char* path, unsigned char* data);
|
int artWrite(const char* path, unsigned char* data);
|
||||||
|
|
||||||
|
|
|
@ -2483,30 +2483,26 @@ static void customInterfaceBarInit()
|
||||||
{
|
{
|
||||||
gInterfaceBarContentOffset = gInterfaceBarWidth - 640;
|
gInterfaceBarContentOffset = gInterfaceBarWidth - 640;
|
||||||
|
|
||||||
char path[COMPAT_MAX_PATH];
|
if (gInterfaceBarContentOffset > 0 && screenGetWidth() > 640) {
|
||||||
snprintf(path, sizeof(path), "art\\intrface\\HR_IFACE_%d.FRM", gInterfaceBarWidth);
|
char path[COMPAT_MAX_PATH];
|
||||||
|
snprintf(path, sizeof(path), "art\\intrface\\HR_IFACE_%d.FRM", gInterfaceBarWidth);
|
||||||
|
|
||||||
int size;
|
gCustomInterfaceBarBackground = artLoad(path);
|
||||||
if (dbGetFileSize(path, &size) != 0 || gInterfaceBarContentOffset <= 0 || screenGetWidth() <= 640) {
|
}
|
||||||
|
|
||||||
|
if (gCustomInterfaceBarBackground != nullptr) {
|
||||||
|
gInterfaceBarIsCustom = true;
|
||||||
|
} else {
|
||||||
gInterfaceBarContentOffset = 0;
|
gInterfaceBarContentOffset = 0;
|
||||||
gInterfaceBarWidth = 640;
|
gInterfaceBarWidth = 640;
|
||||||
gInterfaceBarIsCustom = false;
|
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()
|
static void customInterfaceBarExit()
|
||||||
{
|
{
|
||||||
if (gCustomInterfaceBarBackground != nullptr) {
|
if (gCustomInterfaceBarBackground != nullptr) {
|
||||||
free(gCustomInterfaceBarBackground);
|
internal_free(gCustomInterfaceBarBackground);
|
||||||
gCustomInterfaceBarBackground = nullptr;
|
gCustomInterfaceBarBackground = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2585,21 +2581,11 @@ static void sidePanelsShow()
|
||||||
|
|
||||||
static void sidePanelsDraw(const char* path, int win, bool isLeading)
|
static void sidePanelsDraw(const char* path, int win, bool isLeading)
|
||||||
{
|
{
|
||||||
int size;
|
Art* image = artLoad(path);
|
||||||
if (dbGetFileSize(path, &size) != 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Art* image = reinterpret_cast<Art*>(internal_malloc(size));
|
|
||||||
if (image == nullptr) {
|
if (image == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (artRead(path, reinterpret_cast<unsigned char*>(image)) != 0) {
|
|
||||||
internal_free(image);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char* imageData = artGetFrameData(image, 0, 0);
|
unsigned char* imageData = artGetFrameData(image, 0, 0);
|
||||||
|
|
||||||
int imageWidth = artGetWidth(image, 0, 0);
|
int imageWidth = artGetWidth(image, 0, 0);
|
||||||
|
|
Loading…
Reference in New Issue