Shhh, don't tell Melpontro.

This commit is contained in:
Skyth 2025-02-17 13:03:03 +03:00
parent 716200e7df
commit d64c7e3cc4
5 changed files with 7985 additions and 0 deletions

View file

@ -561,3 +561,6 @@ BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/sounds/sy
BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/sounds/sys_actstg_pausedecide.ogg" DEST_FILE "${RESOURCES_OUTPUT_PATH}/sounds/sys_actstg_pausedecide.ogg" ARRAY_NAME "g_sys_actstg_pausedecide")
BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/sounds/sys_actstg_pausewinclose.ogg" DEST_FILE "${RESOURCES_OUTPUT_PATH}/sounds/sys_actstg_pausewinclose.ogg" ARRAY_NAME "g_sys_actstg_pausewinclose")
BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/sounds/sys_actstg_pausewinopen.ogg" DEST_FILE "${RESOURCES_OUTPUT_PATH}/sounds/sys_actstg_pausewinopen.ogg" ARRAY_NAME "g_sys_actstg_pausewinopen")
## Keyboard QTE ##
BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/common/raw/kb_key_0.png" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/common/raw/kb_key_0.png" ARRAY_NAME "g_kb_key_0" COMPRESSION_TYPE "zstd")

View file

@ -1350,6 +1350,9 @@ struct ImGuiPushConstants
extern ImFontBuilderIO g_fontBuilderIO;
extern void InitKeyboardQTE();
extern void DrawKeyboardQTE();
static void CreateImGuiBackend()
{
ImGuiIO& io = ImGui::GetIO();
@ -1372,6 +1375,7 @@ static void CreateImGuiBackend()
MessageWindow::Init();
OptionsMenu::Init();
InstallerWizard::Init();
InitKeyboardQTE();
ImGui_ImplSDL2_InitForOther(GameWindow::s_pWindow);
@ -2464,6 +2468,7 @@ static void DrawImGui()
InstallerWizard::Draw();
MessageWindow::Draw();
ButtonGuide::Draw();
DrawKeyboardQTE();
Fader::Draw();
BlackBar::Draw();

View file

@ -146,3 +146,193 @@ PPC_FUNC(sub_824C1E60)
__imp__sub_824C1E60(ctx, base);
}
#include <gpu/video.h>
#include <gpu/imgui/imgui_snapshot.h>
#include <res/images/common/raw/kb_key_0.png.h>
#include <decompressor.h>
#include <ui/imgui_utils.h>
#include <exports.h>
#include <words.h>
#include <random>
static std::string g_qteText;
static std::vector<double> g_qteTimes;
static bool g_shouldDrawKeyboardQTE;
static std::unique_ptr<GuestTexture> g_keyboardTexture;
static uint8_t g_prevScanCodes[SDL_NUM_SCANCODES];
static std::default_random_engine g_engine{ std::random_device {}() };
static std::uniform_int_distribution g_intDistribution;
static std::uniform_real_distribution g_floatDistribution(0.0, 1.0);
void InitKeyboardQTE()
{
g_keyboardTexture = LOAD_ZSTD_TEXTURE(g_kb_key_0);
}
void DrawKeyboardQTE()
{
memcpy(g_prevScanCodes, SDL_GetKeyboardState(nullptr), sizeof(g_prevScanCodes));
if (!g_shouldDrawKeyboardQTE)
return;
g_shouldDrawKeyboardQTE = false;
auto drawList = ImGui::GetBackgroundDrawList();
ImFont* font = ImFontAtlasSnapshot::GetFont("FOT-NewRodinPro-DB.otf");
// y: 307
// h: 110
// font: x 36 y 30 30pt
auto& res = ImGui::GetIO().DisplaySize;
constexpr float padding = -40.0f;
float width = Scale(g_qteText.size() * 110 + (g_qteText.size() - 1) * padding);
for (size_t i = 0; i < g_qteText.size(); i++)
{
float x = res.x / 2.0f - width / 2.0f + Scale((110 + padding)) * i;
double motion = ComputeLinearMotion(g_qteTimes[i], 0, 5);
if (g_qteText[i] != ' ')
{
std::stringstream text;
text << std::toupper(g_qteText[i], std::locale::classic());
float x = res.x / 2.0f - width / 2.0f + Scale((110 + padding)) * i;
drawList->AddImage(g_keyboardTexture.get(), { x, Scale(307) }, { x + Scale(110), Scale(307 + 110) }, {0.0f, 0.0f}, {1.0f, 1.0f}, IM_COL32(255, 255, 255, 255 * motion));
drawList->AddText(font, Scale(24.0f), { x + Scale(36), Scale(307 + 28) }, IM_COL32(0, 0, 0, 255 * motion), text.str().c_str());
}
else
{
drawList->AddImage(g_keyboardTexture.get(), { x, Scale(307) }, { x + Scale(110), Scale(307 + 110) }, { 0.0f, 0.0f }, { 1.0f, 1.0f }, IM_COL32(255, 255, 255, 255 * (1.0 - motion)));
}
}
}
// + 100 is success bool
// return true to indicate either succeeded or failed
PPC_FUNC_IMPL(__imp__sub_823329F8);
PPC_FUNC(sub_823329F8)
{
struct DelayCall
{
PPCRegister r3;
uint8_t* base;
PPCRegister time;
DelayCall(PPCRegister& r3, uint8_t* base) : r3(r3), base(base)
{
time.u32 = PPC_LOAD_U32(r3.u32 + 104);
PPCRegister newTime = time;
newTime.f32 *= 5.0f;
PPC_STORE_U32(r3.u32 + 104, newTime.u32);
}
~DelayCall()
{
PPC_STORE_U32(r3.u32 + 104, time.u32);
}
} delayCall(ctx.r3, base);
g_shouldDrawKeyboardQTE = true;
bool foundAny = false;
for (size_t i = 0; i < g_qteText.size(); i++)
{
if (g_qteText[i] != ' ')
{
int lower = std::tolower(g_qteText[i], std::locale::classic());
SDL_Scancode scancode = SDL_GetScancodeFromKey(lower);
for (size_t j = SDL_SCANCODE_A; j <= SDL_SCANCODE_Z; j++)
{
if (g_prevScanCodes[j] == 0 && SDL_GetKeyboardState(nullptr)[j] != 0)
{
if (j == scancode) // pressed the right one
{
g_qteText[i] = ' ';
g_qteTimes[i] = ImGui::GetTime();
ctx.r3.u32 = 0;
Game_PlaySound("objsn_trickjump_button");
return;
}
else // wrong one!
{
PPC_STORE_U8(ctx.r3.u32 + 100, 0);
ctx.r3.u32 = 1;
return;
}
}
}
foundAny = true;
break;
}
}
// ran out of time
if (PPC_LOAD_U32(ctx.r3.u32 + 132) >= PPC_LOAD_U32(ctx.r3.u32 + 104))
{
PPC_STORE_U8(ctx.r3.u32 + 100, 0);
ctx.r3.u32 = 1;
return;
}
if (!foundAny)
{
// pressed all of them correctly
PPC_STORE_U8(ctx.r3.u32 + 100, 1);
ctx.r3.u32 = 1;
return;
}
__imp__sub_823329F8(ctx, base);
ctx.r3.u32 = 0;
return;
}
PPC_FUNC_IMPL(__imp__sub_826117E0);
PPC_FUNC(sub_826117E0)
{
auto counts = reinterpret_cast<uint32_t*>(base + PPC_LOAD_U32(ctx.r3.u32 + 252));
auto times = reinterpret_cast<uint32_t*>(base + PPC_LOAD_U32(ctx.r3.u32 + 236));
for (size_t i = 1; i < 3; i++)
{
if (counts[i] == 0)
{
counts[i] = counts[0];
times[i] = times[0];
}
}
__imp__sub_826117E0(ctx, base);
}
void QteButtonPromptInitMidAsmHook()
{
g_qteText = g_words[g_intDistribution(g_engine) % std::size(g_words)];
g_qteTimes.clear();
g_qteTimes.resize(g_qteText.size(), ImGui::GetTime());
}
void QteButtonPromptUpdateMidAsmHook()
{
}
void TrickJumperCompareMidAsmHook(PPCRegister& r28)
{
if (r28.u32 == 12)
{
if (g_floatDistribution(g_engine) < 0.3)
r28.u32 = 0;
}
}

7772
UnleashedRecomp/words.h Normal file

File diff suppressed because it is too large Load diff

View file

@ -1093,3 +1093,18 @@ registers = ["r31", "r29", "r28"]
name = "ObjGrindDashPanelAllocMidAsmHook"
address = 0x82614948
registers = ["r3"]
[[midasm_hook]]
name = "QteButtonPromptInitMidAsmHook"
address = 0x823339D8
jump_address = 0x82333D14
[[midasm_hook]]
name = "QteButtonPromptUpdateMidAsmHook"
address = 0x82332A90
jump_address = 0x82332BC4
[[midasm_hook]]
name = "TrickJumperCompareMidAsmHook"
address = 0x82611910
registers = ["r28"]