tlac drawing: proper support for different aet files

This commit is contained in:
somewhatlurker
2019-10-24 17:35:47 +11:00
parent 410b4454c1
commit 12a4fa3fa5
3 changed files with 162 additions and 79 deletions
@@ -121,68 +121,6 @@ namespace TLAC::Components
}
};
/* struct MsString {
union {
char* string_ptr;
char string_buf[16];
};
uint64_t len;
uint64_t bufsize;
char* GetCharBuf()
{
if (bufsize > 0xf && string_ptr != nullptr)
return string_ptr;
else
return string_buf;
};
void SetCharBuf(char* newcontent)
{
len = strlen(newcontent);
bufsize = len;
if (len > 0xf)
{
string_ptr = strdup(newcontent);
}
else
{
strcpy_s(string_buf, newcontent);
}
}
}; */
/* struct MsStringW {
union {
wchar_t* string_ptr;
wchar_t string_buf[8];
};
uint64_t len;
uint64_t bufsize;
wchar_t* GetCharBuf()
{
if (bufsize > 0x7 && string_ptr != nullptr)
return string_ptr;
else
return string_buf;
};
void SetCharBuf(wchar_t* newcontent)
{
len = wcslen(newcontent);
bufsize = len;
if (len > 0xf)
{
string_ptr = wcsdup(newcontent);
}
else
{
wcscpy_s(string_buf, newcontent);
}
}
}; */
enum drawTextFlags : uint32_t
{
DRAWTEXT_ENABLE_XADVANCE = 1,
@@ -264,6 +202,129 @@ namespace TLAC::Components
dtParam->fillColour = oldFillColour;
}
struct MsString {
union {
char* string_ptr;
char string_buf[16];
};
uint64_t len;
uint64_t bufsize;
char* GetCharBuf()
{
if (bufsize > 0xf && string_ptr != nullptr)
return string_ptr;
else
return string_buf;
};
void SetCharBuf(char* newcontent)
{
len = strlen(newcontent);
bufsize = len;
if (len > 0xf)
{
string_ptr = _strdup(newcontent);
}
else
{
strcpy_s(string_buf, newcontent);
}
}
};
/* struct MsStringW {
union {
wchar_t* string_ptr;
wchar_t string_buf[8];
};
uint64_t len;
uint64_t bufsize;
wchar_t* GetCharBuf()
{
if (bufsize > 0x7 && string_ptr != nullptr)
return string_ptr;
else
return string_buf;
};
void SetCharBuf(wchar_t* newcontent)
{
len = wcslen(newcontent);
bufsize = len;
if (len > 0xf)
{
string_ptr = wcsdup(newcontent);
}
else
{
wcscpy_s(string_buf, newcontent);
}
}
}; */
struct AetDebugFileInfo
{
MsString name1;
int32_t gameId;
char unk[4]; // seems to be some kind of mode prefix (eg. "GAM_")
MsString name2; // same as name1???
MsString filename;
int32_t dbId1; // not sure what the db ids are... this one might be a position
int32_t dbId12;
};
struct AetFileInfo
{
int32_t id1;
char unk1[4]; // seems to be some kind of mode prefix (eg. "GAM_")
int32_t id2; // same as id1???
int32_t unk2;
MsString name;
int32_t unk3;
int32_t unk4; // might be related to sprites?
};
/*
int findAetDebugFileId(std::string name)
{
AetDebugFileInfo* aetArray = *(AetDebugFileInfo**)AET_DEBUG_ARRAY_POINTER_ADDRESS;
AetDebugFileInfo* aetArrayEndAddress = *(AetDebugFileInfo**)(AET_DEBUG_ARRAY_POINTER_ADDRESS + 0x08);
int id = 0;
while (&aetArray[id] < aetArrayEndAddress)
{
if (name == aetArray[id].name2.GetCharBuf()) // dwgui enum uses name2, so this should too I guess
return aetArray[id].gameId;
else
id++;
}
return -1;
}
*/
// gets a file ID for use with createAetLayer
// returns -1 if the file was not found
// note: names are a little different to in 2dauth test -- it seems like they have "_MAIN" appended
int findAetFileId(std::string name)
{
AetFileInfo* aetArray = *(AetFileInfo**)AET_ARRAY_POINTER_ADDRESS;
AetFileInfo* aetArrayEndAddress = *(AetFileInfo**)(AET_ARRAY_POINTER_ADDRESS + 0x08);
int id = 0;
while (&aetArray[id] < aetArrayEndAddress)
{
if (name == aetArray[id].name.GetCharBuf()) // dwgui enum uses name2, so this should too I guess
return aetArray[id].id1;
else
id++;
}
return -1;
}
enum createAetFlags : uint32_t
{
CREATEAET_20000 = 0x20000,
@@ -271,24 +332,24 @@ namespace TLAC::Components
// draw an aet layer (with all settings)
// aetSpeedCallback is actually a pointer to a class or struct with the callback address at offset +0x8
int createAetLayer(int32_t unk1, uint32_t drawLayer, createAetFlags flags, const char* name, const Point* loc, int32_t unk2, const char* animation, const char* animation2, float animationInTime, float animationOutTime, const Point* scale, const void* aetSpeedCallback)
int createAetLayer(int32_t fileId, uint32_t drawLayer, createAetFlags flags, const char* name, const Point* loc, int32_t unk2, const char* animation, const char* animation2, float animationInTime, float animationOutTime, const Point* scale, const void* aetSpeedCallback)
{
return ((int(*)(int32_t, uint32_t, createAetFlags, const char*, const Point*, int32_t, const char*, const char*, float, float, const Point*, const void*))0x14013be60)(unk1, drawLayer, flags, name, loc, unk2, animation, animation2, animationInTime, animationOutTime, scale, aetSpeedCallback);
return ((int(*)(int32_t, uint32_t, createAetFlags, const char*, const Point*, int32_t, const char*, const char*, float, float, const Point*, const void*))0x14013be60)(fileId, drawLayer, flags, name, loc, unk2, animation, animation2, animationInTime, animationOutTime, scale, aetSpeedCallback);
}
// draw an aet layer (with animation timing override)
int createAetLayer(uint32_t drawLayer, createAetFlags flags, const char* name, const Point* loc, float animationInTime, float animationOutTime)
int createAetLayer(int32_t fileId, uint32_t drawLayer, createAetFlags flags, const char* name, const Point* loc, float animationInTime, float animationOutTime)
{
return createAetLayer(3, drawLayer, flags, name, loc, 0, 0, 0, animationInTime, animationOutTime, 0, 0);
return createAetLayer(fileId, drawLayer, flags, name, loc, 0, 0, 0, animationInTime, animationOutTime, 0, 0);
}
// draw an aet layer (with scale)
int createAetLayer(uint32_t drawLayer, createAetFlags flags, const char* name, const Point* loc, const Point* scale)
int createAetLayer(int32_t fileId, uint32_t drawLayer, createAetFlags flags, const char* name, const Point* loc, const Point* scale)
{
return createAetLayer(3, drawLayer, flags, name, loc, 0, 0, 0, -1, -1, scale, 0);
return createAetLayer(fileId, drawLayer, flags, name, loc, 0, 0, 0, -1, -1, scale, 0);
}
// draw an aet layer
int createAetLayer(uint32_t drawLayer, createAetFlags flags, const char* name, const Point* loc)
int createAetLayer(int32_t fileId, uint32_t drawLayer, createAetFlags flags, const char* name, const Point* loc)
{
return createAetLayer(3, drawLayer, flags, name, loc, 0, 0, 0, -1, -1, 0, 0);
return createAetLayer(fileId, drawLayer, flags, name, loc, 0, 0, 0, -1, -1, 0, 0);
}
void destroyAetLayer(int &layer)
@@ -14,6 +14,7 @@ namespace TLAC::Components
bool Pause::isPaused = false;
bool Pause::giveUp = false;
bool Pause::showUI = true;
int Pause::keyWinAet = 0;
int Pause::triangleAet = 0;
int Pause::squareAet = 0;
int Pause::crossAet = 0;
@@ -145,6 +146,7 @@ namespace TLAC::Components
else
{
// clear these from the screen too
destroyAetLayer(keyWinAet);
destroyAetLayer(triangleAet);
destroyAetLayer(squareAet);
destroyAetLayer(crossAet);
@@ -213,6 +215,7 @@ namespace TLAC::Components
*playstate = streamPlayStates[i];
}
destroyAetLayer(keyWinAet);
destroyAetLayer(triangleAet);
destroyAetLayer(squareAet);
destroyAetLayer(crossAet);
@@ -250,6 +253,8 @@ namespace TLAC::Components
FontInfo fontInfo(0x11);
DrawParams dtParams(&fontInfo);
dtParams.layer = bgLayer;
Point aetScale = { 0.66667, 0.7 };
Point aetLoc = { (1280 - aetScale.x * 1280) / 2, (720 - aetScale.y * 720) / 2 };
// get aspect ratio
float aspect = *(float*)UI_ASPECT_RATIO;
@@ -289,6 +294,21 @@ namespace TLAC::Components
dtParams.layer = contentLayer;
// bg box
/*
static int keyWinFile = 0;
if (keyWinFile == 0)
{
keyWinFile = findAetFileId("AET_KEY_WIN_MAIN");
//printf("keyWinFile: %d\n", keyWinFile);
}
destroyAetLayer(keyWinAet);
if (keyWinFile != -1)
keyWinAet = createAetLayer(keyWinFile, dtParams.layer, CREATEAET_20000, "win_in", &aetLoc, 0, nullptr, nullptr, 4.6, 4.6, &aetScale, 0);
*/
// selection cursor
int menuOrigin = menuY - menuItemHeight * (menu[curMenuSet].items.size() / 2.0);
if (curMenuSet != MENUSET_MAIN)
@@ -360,27 +380,27 @@ namespace TLAC::Components
dtParams.lineOriginLoc = dtParams.textCurrentLoc;
const float spriteSize = 18;
const float halfSpriteSize = spriteSize / 2;
Point spriteLoc = { 0, dtParams.textCurrentLoc.y + halfSpriteSize }; // the aets are centered on their location, so fudge this a little
const Point spriteScale = { spriteSize / 64, spriteSize / 64 }; // just approximated
aetLoc = { 0, dtParams.textCurrentLoc.y + halfSpriteSize }; // the aets are centered on their location, so fudge this a little
aetScale = { spriteSize / 64, spriteSize / 64 }; // just approximated
dtParams.colour = 0xffffffff;
drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_XADVANCE), L"L/R:Move ");
spriteLoc.x = dtParams.textCurrentLoc.x + halfSpriteSize;
squareAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_shikaku", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, nullptr);
aetLoc.x = dtParams.textCurrentLoc.x + halfSpriteSize;
squareAet = createAetLayer(3, dtParams.layer, CREATEAET_20000, "button_shikaku", &aetLoc, 0, nullptr, nullptr, 0, 0, &aetScale, nullptr);
dtParams.textCurrentLoc.x += spriteSize;
drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_XADVANCE), L":Hide Menu ");
spriteLoc.x = dtParams.textCurrentLoc.x + halfSpriteSize;
crossAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_batsu", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, nullptr);
aetLoc.x = dtParams.textCurrentLoc.x + halfSpriteSize;
crossAet = createAetLayer(3, dtParams.layer, CREATEAET_20000, "button_batsu", &aetLoc, 0, nullptr, nullptr, 0, 0, &aetScale, nullptr);
dtParams.textCurrentLoc.x += spriteSize;
if (curMenuSet == MENUSET_MAIN)
drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_XADVANCE), L":Close ");
else
drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_XADVANCE), L":Back ");
spriteLoc.x = dtParams.textCurrentLoc.x + halfSpriteSize;
circleAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_maru", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, nullptr);
aetLoc.x = dtParams.textCurrentLoc.x + halfSpriteSize;
circleAet = createAetLayer(3, dtParams.layer, CREATEAET_20000, "button_maru", &aetLoc, 0, nullptr, nullptr, 0, 0, &aetScale, nullptr);
dtParams.textCurrentLoc.x += spriteSize;
drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_XADVANCE), L":Select");
}
@@ -2,6 +2,7 @@
#include "../Constants.h"
#include "EmulatorComponent.h"
#include "PlayerData.h"
#include "GameState.h"
#include "Input/InputState.h"
#include "Input/TouchSliderState.h"
#include <string>
@@ -64,6 +65,7 @@ namespace TLAC::Components
static bool showUI;
static int keyWinAet;
static int triangleAet;
static int squareAet;
static int crossAet;
@@ -103,7 +105,7 @@ namespace TLAC::Components
static void mainmenu() { setMenuPos(MENUSET_MAIN, mainMenuPos); };
static void unpause() { pause = false; };
//static void restart() { *(uint8_t*)0x140d0b538 = 1; unpause(); }
//static void restart() { *(uint8_t*)0x140d0b512 = 2; ((void(*)(uint64_t))0x140127a30)(0x140d0b510); ((void(*)(uint64_t))0x140674e20)(PV_GAME_BASE_ADDRESS); /* *(uint8_t*)0x140d0b512 = 1; *(uint8_t*)0x140d0b513 = 1; *(int32_t*)0x140d0b534 = 0; ((void(*)(uint64_t))0x140127a30)(0x140d0b510); */ unpause(); }
static void giveup() { giveUp = true; };
static void sevolmenu() { setMenuPos(MENUSET_SEVOL, 1); };