From 030850a6ddffa439cd198f7e7d4ff82b2eb5ec14 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Sat, 19 Oct 2019 15:29:07 +1100 Subject: [PATCH 01/44] significant work on Pause component (not ready yet, but feel free to test) --- .../TLAC/Components/ComponentsManager.cpp | 10 ++ .../TLAC/Components/ComponentsManager.h | 1 + .../TLAC/Components/EmulatorComponent.h | 1 + .../source/plugins/TLAC/Components/Pause.cpp | 124 ++++++++++++++++++ .../source/plugins/TLAC/Components/Pause.h | 29 ++++ source-code/source/plugins/TLAC/Constants.h | 12 ++ source-code/source/plugins/TLAC/TLAC.vcxproj | 2 + .../source/plugins/TLAC/TLAC.vcxproj.filters | 6 + source-code/source/plugins/TLAC/dllmain.cpp | 2 + 9 files changed, 187 insertions(+) create mode 100644 source-code/source/plugins/TLAC/Components/Pause.cpp create mode 100644 source-code/source/plugins/TLAC/Components/Pause.h diff --git a/source-code/source/plugins/TLAC/Components/ComponentsManager.cpp b/source-code/source/plugins/TLAC/Components/ComponentsManager.cpp index a5599c8..99ccff2 100644 --- a/source-code/source/plugins/TLAC/Components/ComponentsManager.cpp +++ b/source-code/source/plugins/TLAC/Components/ComponentsManager.cpp @@ -12,6 +12,7 @@ #include "DebugComponent.h" #include "ScaleComponent.h" #include "ScoreSaver.h" +#include "Pause.h" #include "GameTargets/TargetInspector.h" using ConfigFile = TLAC::FileSystem::ConfigFile; @@ -36,6 +37,7 @@ namespace TLAC::Components new InputEmulator(), new TouchSliderEmulator(), new TouchPanelEmulator(), + new Pause(), // ensure pause is always immediately after input emulators so it can swallow inputs new PlayerDataManager(), new FrameRateManager(), new FastLoader(), @@ -133,6 +135,14 @@ namespace TLAC::Components component->UpdateInput(); } + void ComponentsManager::UpdatePostInput() + { + for (auto& component : components) + { + component->UpdatePostInput(); + } + } + void ComponentsManager::OnFocusGain() { for (auto& component : components) diff --git a/source-code/source/plugins/TLAC/Components/ComponentsManager.h b/source-code/source/plugins/TLAC/Components/ComponentsManager.h index 0c20c0e..c263f37 100644 --- a/source-code/source/plugins/TLAC/Components/ComponentsManager.h +++ b/source-code/source/plugins/TLAC/Components/ComponentsManager.h @@ -27,6 +27,7 @@ namespace TLAC::Components void Initialize(); void Update(); void UpdateInput(); + void UpdatePostInput(); void OnFocusGain(); void OnFocusLost(); void Dispose(); diff --git a/source-code/source/plugins/TLAC/Components/EmulatorComponent.h b/source-code/source/plugins/TLAC/Components/EmulatorComponent.h index 48b6175..6b940a6 100644 --- a/source-code/source/plugins/TLAC/Components/EmulatorComponent.h +++ b/source-code/source/plugins/TLAC/Components/EmulatorComponent.h @@ -16,6 +16,7 @@ namespace TLAC::Components virtual void Update() = 0; virtual void UpdateInput() {}; + virtual void UpdatePostInput() {}; virtual void OnFocusGain() {}; virtual void OnFocusLost() {}; diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp new file mode 100644 index 0000000..fb349a4 --- /dev/null +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -0,0 +1,124 @@ +#include "Pause.h" +#include "../Constants.h" +#include "GameState.h" +#include "Input/InputState.h" +#include +#include + +namespace TLAC::Components +{ + Pause::Pause() + { + } + + Pause::~Pause() + { + } + + const char* Pause::GetDisplayName() + { + return "pause"; + } + + void Pause::Initialize(ComponentsManager*) + { + origAetMovOp.resize(8); + memcpy(&origAetMovOp[0], aetMovPatchAddress, 8); + } + + void Pause::Update() + { + + } + + void Pause::UpdatePostInput() + { + if (isPaused) + { + // exit pause if key is tapped or no longer in game somehow + if (isPauseKeyTapped() || *(GameState*)CURRENT_GAME_STATE_ADDRESS != GS_GAME || *(SubGameState*)CURRENT_GAME_SUB_STATE_ADDRESS != SUB_GAME_MAIN) + { + setPaused(false); + } + else + { + // swallow all button inputs if paused + InputState* inputState = (InputState*)(*(uint64_t*)INPUT_STATE_PTR_ADDRESS); + inputState->Tapped.Buttons = JVS_NONE; + inputState->DoubleTapped.Buttons = JVS_NONE; + inputState->Down.Buttons = JVS_NONE; + inputState->Released.Buttons = JVS_NONE; + inputState->IntervalTapped.Buttons = JVS_NONE; + // todo: slider + } + } + else + { + // only enter pause if in game + if (*(GameState*)CURRENT_GAME_STATE_ADDRESS == GS_GAME && *(SubGameState*)CURRENT_GAME_SUB_STATE_ADDRESS == SUB_GAME_MAIN) + { + if (isPauseKeyTapped()) + { + setPaused(true); + } + } + } + } + + bool Pause::isPauseKeyTapped() + { + return ((InputState*)(*(uint64_t*)INPUT_STATE_PTR_ADDRESS))->Tapped.Buttons & JVS_START; + } + + void Pause::setPaused(bool pause) + { + uint64_t audioMixerAddr = *(uint64_t*)(AUDIO_MAIN_CLASS_ADDRESS + 0x70); + uint64_t audioStreamsAddress = *(uint64_t*)(audioMixerAddr + 0x18);; + int nAudioStreams = *(uint64_t*)(audioMixerAddr + 0x20); + + if (pause) + { + *(float*)FRAME_SPEED_ADDRESS = 0.0f; // todo: hook getFrameSpeed so this can't be screwed up + ((void(*)())DSC_PAUSE_FUNC_ADDRESS)(); + + InjectCode(aetMovPatchAddress, { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 }); + + for (int i = 0; i < nAudioStreams; i++) + { + uint32_t* playstate = (uint32_t*)(audioStreamsAddress + i * 0x50 + 0x18); + if (i < streamPlayStates.size()) + streamPlayStates[i] = *playstate; + else + streamPlayStates.push_back(*playstate); + + *playstate = 0; + } + } + else + { + *(float*)FRAME_SPEED_ADDRESS = 1.0f; + ((void(*)())DSC_UNPAUSE_FUNC_ADDRESS)(); + + InjectCode(aetMovPatchAddress, origAetMovOp); + + for (int i = 0; i < nAudioStreams; i++) + { + uint32_t* playstate = (uint32_t*)(audioStreamsAddress + i * 0x50 + 0x18); + if (i < streamPlayStates.size()) + *playstate = streamPlayStates[i]; + } + } + + isPaused = pause; + } + + void Pause::InjectCode(void* address, const std::vector data) + { + const size_t byteCount = data.size() * sizeof(uint8_t); + + DWORD oldProtect; + VirtualProtect(address, byteCount, PAGE_EXECUTE_READWRITE, &oldProtect); + memcpy(address, data.data(), byteCount); + VirtualProtect(address, byteCount, oldProtect, nullptr); + } +} diff --git a/source-code/source/plugins/TLAC/Components/Pause.h b/source-code/source/plugins/TLAC/Components/Pause.h new file mode 100644 index 0000000..762845a --- /dev/null +++ b/source-code/source/plugins/TLAC/Components/Pause.h @@ -0,0 +1,29 @@ +#pragma once +#include "EmulatorComponent.h" +#include + +namespace TLAC::Components +{ + class Pause : public EmulatorComponent + { + public: + Pause(); + ~Pause(); + + virtual const char* GetDisplayName() override; + + virtual void Initialize(ComponentsManager*) override; + virtual void Update() override; + virtual void UpdatePostInput() override; + + private: + bool isPaused; + bool isPauseKeyTapped(); + void setPaused(bool pause); + std::vector streamPlayStates; + void InjectCode(void* address, const std::vector data); + + std::vector origAetMovOp; + uint8_t* aetMovPatchAddress = (uint8_t*)0x1401703b3; + }; +} diff --git a/source-code/source/plugins/TLAC/Constants.h b/source-code/source/plugins/TLAC/Constants.h index d5ce191..6f51f6f 100644 --- a/source-code/source/plugins/TLAC/Constants.h +++ b/source-code/source/plugins/TLAC/Constants.h @@ -97,6 +97,18 @@ constexpr uint64_t CURRENT_SONG_ID_ADDRESS = 0x0000000140CDD8E0; constexpr uint64_t SELPV_CURRENT_SONG_ADDRESS = 0x000000014CC12438; constexpr uint64_t SONG_CLEAR_COUNTS_ADDRESS = 0x00000001411A95E8; +constexpr uint64_t AUDIO_MAIN_CLASS_ADDRESS = 0x000000014CC61120; + +constexpr uint64_t DSC_TIME_ADDRESS = 0x0000000140D0B518; +constexpr uint64_t DSC_START_FROM_TIME_ADDRESS = 0x0000000140D0B540; +constexpr uint64_t DSC_START_SYS_TIME_ADDRESS = 0x0000000140D0B548; +constexpr uint64_t DSC_TIME_ADDRESS_2 = 0x0000000140D0B520; +constexpr uint64_t DSC_START_FROM_TIME_ADDRESS_2 = 0x0000000140D0B560; +constexpr uint64_t DSC_START_SYS_TIME_ADDRESS_2 = 0x0000000140D0B568; + +constexpr uint64_t DSC_PAUSE_FUNC_ADDRESS = 0x00000001401295C0; +constexpr uint64_t DSC_UNPAUSE_FUNC_ADDRESS = 0x0000000140129590; + #define XINPUT_A 0x00 #define XINPUT_B 0x01 #define XINPUT_X 0x02 diff --git a/source-code/source/plugins/TLAC/TLAC.vcxproj b/source-code/source/plugins/TLAC/TLAC.vcxproj index 7fa64e0..ca6164c 100644 --- a/source-code/source/plugins/TLAC/TLAC.vcxproj +++ b/source-code/source/plugins/TLAC/TLAC.vcxproj @@ -128,6 +128,7 @@ + @@ -181,6 +182,7 @@ + diff --git a/source-code/source/plugins/TLAC/TLAC.vcxproj.filters b/source-code/source/plugins/TLAC/TLAC.vcxproj.filters index d95a19b..c1a7c42 100644 --- a/source-code/source/plugins/TLAC/TLAC.vcxproj.filters +++ b/source-code/source/plugins/TLAC/TLAC.vcxproj.filters @@ -195,6 +195,9 @@ Header Files + + Header Files + @@ -329,5 +332,8 @@ Source Files + + Source Files + \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/dllmain.cpp b/source-code/source/plugins/TLAC/dllmain.cpp index 26efd73..1b474ef 100644 --- a/source-code/source/plugins/TLAC/dllmain.cpp +++ b/source-code/source/plugins/TLAC/dllmain.cpp @@ -101,6 +101,8 @@ namespace TLAC ComponentsManager.UpdateInput(); } + ComponentsManager.UpdatePostInput(); + if ((framework::inputDisable)) { Input::Keyboard::GetInstance()->PollInput(); From d768fa40f3208eccf58e1af69cc06de5ca717f7a Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Sat, 19 Oct 2019 18:10:51 +1100 Subject: [PATCH 02/44] placeholder pause UI --- .../TLAC/Components/ComponentsManager.cpp | 8 ++ .../TLAC/Components/ComponentsManager.h | 1 + .../TLAC/Components/EmulatorComponent.h | 1 + .../source/plugins/TLAC/Components/Pause.cpp | 74 ++++++++++++++++++- .../source/plugins/TLAC/Components/Pause.h | 23 ++++-- source-code/source/plugins/TLAC/Constants.h | 1 + source-code/source/plugins/TLAC/dllmain.cpp | 16 ++++ 7 files changed, 116 insertions(+), 8 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/ComponentsManager.cpp b/source-code/source/plugins/TLAC/Components/ComponentsManager.cpp index 99ccff2..4a63456 100644 --- a/source-code/source/plugins/TLAC/Components/ComponentsManager.cpp +++ b/source-code/source/plugins/TLAC/Components/ComponentsManager.cpp @@ -143,6 +143,14 @@ namespace TLAC::Components } } + void ComponentsManager::UpdatePostDraw() + { + for (auto& component : components) + { + component->UpdatePostDraw(); + } + } + void ComponentsManager::OnFocusGain() { for (auto& component : components) diff --git a/source-code/source/plugins/TLAC/Components/ComponentsManager.h b/source-code/source/plugins/TLAC/Components/ComponentsManager.h index c263f37..1057940 100644 --- a/source-code/source/plugins/TLAC/Components/ComponentsManager.h +++ b/source-code/source/plugins/TLAC/Components/ComponentsManager.h @@ -28,6 +28,7 @@ namespace TLAC::Components void Update(); void UpdateInput(); void UpdatePostInput(); + void UpdatePostDraw(); void OnFocusGain(); void OnFocusLost(); void Dispose(); diff --git a/source-code/source/plugins/TLAC/Components/EmulatorComponent.h b/source-code/source/plugins/TLAC/Components/EmulatorComponent.h index 6b940a6..20955ae 100644 --- a/source-code/source/plugins/TLAC/Components/EmulatorComponent.h +++ b/source-code/source/plugins/TLAC/Components/EmulatorComponent.h @@ -17,6 +17,7 @@ namespace TLAC::Components virtual void UpdateInput() {}; virtual void UpdatePostInput() {}; + virtual void UpdatePostDraw() {}; virtual void OnFocusGain() {}; virtual void OnFocusLost() {}; diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index fb349a4..9903377 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -2,11 +2,16 @@ #include "../Constants.h" #include "GameState.h" #include "Input/InputState.h" +#include "GL\glut.h" #include #include namespace TLAC::Components { + bool Pause::isPaused = false; + std::vector Pause::origAetMovOp; + std::vector Pause::streamPlayStates; + Pause::Pause() { } @@ -42,8 +47,20 @@ namespace TLAC::Components } else { - // swallow all button inputs if paused InputState* inputState = (InputState*)(*(uint64_t*)INPUT_STATE_PTR_ADDRESS); + + if (inputState->Tapped.Buttons & JVS_SQUARE) + showUI = !showUI; + + if (inputState->Tapped.Buttons & JVS_L) + menuPos -= 1; + + if (inputState->Tapped.Buttons & JVS_R) + menuPos += 1; + + menuPos %= menuItems.size(); + + // swallow all button inputs if paused inputState->Tapped.Buttons = JVS_NONE; inputState->DoubleTapped.Buttons = JVS_NONE; inputState->Down.Buttons = JVS_NONE; @@ -65,6 +82,61 @@ namespace TLAC::Components } } + void Pause::UpdatePostDraw() + { + if (isPaused && showUI) + { + // this isn't imgui code, but I probably wouldn't have gotten this working properly if I didn't reference it, so... umm... yeah lol + glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDisable(GL_CULL_FACE); + glDisable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); + glDisable(GL_COLOR_MATERIAL); + + int width = glutGet(GLUT_WINDOW_WIDTH); + int height = glutGet(GLUT_WINDOW_HEIGHT); + + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrtho(0, 1280, 720, 0, -1.0f, +1.0f); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + + glBegin(GL_QUADS); + glBindTexture(GL_TEXTURE_2D, 0); + + glColor4ub(0, 0, 0, 127); + glVertex2i(0, 0); + glVertex2i(1280, 0); + glVertex2i(1280, 720); + glVertex2i(0, 720); + + glColor4ub(255, 255, 255, 127); + glVertex2i(560, 250); + glVertex2i(620, 250); + glVertex2i(620, 470); + glVertex2i(560, 470); + glVertex2i(660, 250); + glVertex2i(720, 250); + glVertex2i(720, 470); + glVertex2i(660, 470); + + glEnd(); + + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glPopAttrib(); + } + } + bool Pause::isPauseKeyTapped() { return ((InputState*)(*(uint64_t*)INPUT_STATE_PTR_ADDRESS))->Tapped.Buttons & JVS_START; diff --git a/source-code/source/plugins/TLAC/Components/Pause.h b/source-code/source/plugins/TLAC/Components/Pause.h index 762845a..0825cb9 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.h +++ b/source-code/source/plugins/TLAC/Components/Pause.h @@ -15,15 +15,24 @@ namespace TLAC::Components virtual void Initialize(ComponentsManager*) override; virtual void Update() override; virtual void UpdatePostInput() override; + virtual void UpdatePostDraw() override; + static bool isPaused; private: - bool isPaused; - bool isPauseKeyTapped(); - void setPaused(bool pause); - std::vector streamPlayStates; - void InjectCode(void* address, const std::vector data); + // this is a mess of static so that menuItems can work + static bool isPauseKeyTapped(); + static void setPaused(bool pause); + static std::vector streamPlayStates; + static void InjectCode(void* address, const std::vector data); - std::vector origAetMovOp; - uint8_t* aetMovPatchAddress = (uint8_t*)0x1401703b3; + static std::vector origAetMovOp; + static constexpr uint8_t* aetMovPatchAddress = (uint8_t*)0x1401703b3; + + bool showUI = true; + unsigned int menuPos = 0; + static void unpause() { setPaused(false); }; + std::vector> menuItems = { + std::pair(std::string("RESUME"), &unpause), + }; }; } diff --git a/source-code/source/plugins/TLAC/Constants.h b/source-code/source/plugins/TLAC/Constants.h index 6f51f6f..84ec16d 100644 --- a/source-code/source/plugins/TLAC/Constants.h +++ b/source-code/source/plugins/TLAC/Constants.h @@ -8,6 +8,7 @@ constexpr uint8_t JNE_OPCODE = 0x85; //constexpr uint64_t ENGINE_UPDATE_HOOK_TARGET_ADDRESS = 0x000000014018CC40; constexpr uint64_t ENGINE_UPDATE_INPUT_ADDRESS = 0x000000014018CBB0; +constexpr uint64_t ENGINE_FINISH_DRAW_ADDRESS = 0x0000000140192730; constexpr uint64_t CURRENT_GAME_STATE_ADDRESS = 0x0000000140EDA810; constexpr uint64_t CURRENT_GAME_SUB_STATE_ADDRESS = 0x0000000140EDA82C; diff --git a/source-code/source/plugins/TLAC/dllmain.cpp b/source-code/source/plugins/TLAC/dllmain.cpp index 1b474ef..32c0b79 100644 --- a/source-code/source/plugins/TLAC/dllmain.cpp +++ b/source-code/source/plugins/TLAC/dllmain.cpp @@ -19,6 +19,7 @@ #pragma comment(lib, "detours.lib") void(__cdecl* divaEngineUpdate)() = (void(__cdecl*)())0x14018CC40; +void(__cdecl* divaEngineFinishDraw)() = (void(__cdecl*)())ENGINE_FINISH_DRAW_ADDRESS; LRESULT CALLBACK MessageWindowProcessCallback(HWND, UINT, WPARAM, LPARAM); DWORD WINAPI WindowMessageDispatcher(LPVOID); @@ -126,6 +127,11 @@ namespace TLAC ComponentsManager.OnFocusLost(); } + void UpdatePostDraw() + { + ComponentsManager.UpdatePostDraw(); + } + void InitializeExtraSettings() { const LPCTSTR RESOLUTION_CONFIG_FILE_NAME = _T(".\\config.ini"); @@ -342,6 +348,12 @@ void hookedEngineUpdate() //divaEngineUpdate(); } +void hookedEngineFinishDraw() +{ + TLAC::UpdatePostDraw(); + divaEngineFinishDraw(); +} + BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { HWND consoleHandle = GetConsoleWindow(); @@ -362,6 +374,10 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReser DetourUpdateThread(GetCurrentThread()); DetourAttach(&(PVOID&)divaEngineUpdate, hookedEngineUpdate); DetourTransactionCommit(); + DetourTransactionBegin(); + DetourUpdateThread(GetCurrentThread()); + DetourAttach(&(PVOID&)divaEngineFinishDraw, hookedEngineFinishDraw); + DetourTransactionCommit(); TLAC::InitializeExtraSettings(); From 3c7768c147a228df06bacf6921baddff98ccec81 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Sun, 20 Oct 2019 02:49:54 +1100 Subject: [PATCH 03/44] add pause menu (with one option) this is pretty annoying becuase it requires drawing the overlay after drawing text.. it's probably not a bad idea to ship a new text renderer so some of the dodginess can be avoided --- .../TLAC/Components/ComponentsManager.cpp | 8 + .../TLAC/Components/ComponentsManager.h | 1 + .../source/plugins/TLAC/Components/DrawText.h | 195 ++++++++++++++++++ .../TLAC/Components/EmulatorComponent.h | 1 + .../TLAC/Components/Input/InputEmulator.cpp | 5 +- .../source/plugins/TLAC/Components/Pause.cpp | 121 ++++++++++- .../source/plugins/TLAC/Components/Pause.h | 8 + source-code/source/plugins/TLAC/Constants.h | 1 + source-code/source/plugins/TLAC/TLAC.vcxproj | 1 + .../source/plugins/TLAC/TLAC.vcxproj.filters | 3 + source-code/source/plugins/TLAC/dllmain.cpp | 19 ++ 11 files changed, 350 insertions(+), 13 deletions(-) create mode 100644 source-code/source/plugins/TLAC/Components/DrawText.h diff --git a/source-code/source/plugins/TLAC/Components/ComponentsManager.cpp b/source-code/source/plugins/TLAC/Components/ComponentsManager.cpp index 4a63456..22e099d 100644 --- a/source-code/source/plugins/TLAC/Components/ComponentsManager.cpp +++ b/source-code/source/plugins/TLAC/Components/ComponentsManager.cpp @@ -143,6 +143,14 @@ namespace TLAC::Components } } + void ComponentsManager::UpdateDrawSprites() + { + for (auto& component : components) + { + component->UpdateDrawSprites(); + } + } + void ComponentsManager::UpdatePostDraw() { for (auto& component : components) diff --git a/source-code/source/plugins/TLAC/Components/ComponentsManager.h b/source-code/source/plugins/TLAC/Components/ComponentsManager.h index 1057940..cc1a397 100644 --- a/source-code/source/plugins/TLAC/Components/ComponentsManager.h +++ b/source-code/source/plugins/TLAC/Components/ComponentsManager.h @@ -28,6 +28,7 @@ namespace TLAC::Components void Update(); void UpdateInput(); void UpdatePostInput(); + void UpdateDrawSprites(); void UpdatePostDraw(); void OnFocusGain(); void OnFocusLost(); diff --git a/source-code/source/plugins/TLAC/Components/DrawText.h b/source-code/source/plugins/TLAC/Components/DrawText.h new file mode 100644 index 0000000..6ae3487 --- /dev/null +++ b/source-code/source/plugins/TLAC/Components/DrawText.h @@ -0,0 +1,195 @@ +#pragma once +#include +#include + +namespace TLAC::Components +{ +#pragma pack(push, 1) + struct RawFont + { + uint32_t sprId; // ? + uint8_t width1; // glyph? + uint8_t height1; // glyph? + uint8_t width2; // advance? + uint8_t height2; // advance? + uint8_t metric08; // or flag? + uint8_t metric09; // or flag? + uint8_t padding0a[0x06]; + float metric08divby09; + uint64_t _0x10; + int64_t dataBegin; + int64_t dataEnd; + int64_t dataCapacityEnd; + uint8_t padding38[0x8]; + }; + + struct RawFontHolderIdk // ...SeemsPrettyPointlessTbh + { + RawFont* rawfont; + uint16_t width1; + uint16_t height1; + uint16_t zero1; // ? + uint16_t zero2; // ? + uint8_t zero3; // some kind of flag, but seems unused + }; + + struct FontInfo + { + uint32_t fontId; + uint8_t padding04[0x4]; + RawFont* rawfont; + uint16_t flag10; // (zero3 != 0 && padding38[0] != 0) ? 2 : (metric08 != metric09 ? 1 : 0) + uint8_t padding12[0x02]; + float width1; + float height1; + float width2; + float height2; + float userSizeWidth; + float userSizeHeight; + float userSizeWidthMultiplier; // userSizeWidth / width1 + float userSizeHeightMultiplier; // userSizeHeight / width2 + float zero1; // ? + float zero2; // ? + + void setSize(float width, float height) + { + ((void(*)(FontInfo* fi, float width, float height))0x140199e60)(this, width, height); + } + + FontInfo(uint32_t id) + { + ((FontInfo*(*)(FontInfo* fi, uint32_t id))0x140196510)(this, id); + } + }; + + FontInfo*(*getFont)(FontInfo* fi, uint32_t id) = (FontInfo*(*)(FontInfo* fi, uint32_t id))0x140196510; + void(*fontSize)(FontInfo* fi, float width, float height) = (void(*)(FontInfo* fi, float width, float height))0x140199e60; + + struct DrawTextParams + { + uint32_t textColour; // RGBA byte array?, so set as 0xAABBGGRR + uint32_t strokeColour; // ?? RGBA byte array?, so set as 0xAABBGGRR + uint8_t unk08; + uint8_t padding09[0x3]; + uint32_t unk0c; + uint32_t unk10; + uint32_t unk14; + uint32_t unk18; + uint64_t unk1c; + uint32_t unk24; + uint32_t unk28; + float xBegin; // ? + float yBegin; // ? + float xCurrent; // ? + float yCurrent; // ? + uint8_t padding3c[0x4]; + uint64_t unk40; + FontInfo* font; + uint16_t unk50; + + DrawTextParams(FontInfo* fi) + { + textColour = 0xffffffff; + strokeColour = 0xff808080; + unk08 = 0; + unk0c = 0; + unk10 = 0; + unk14 = 0; + unk18 = 0; + unk1c = 0x7; + unk24 = 0xd; + unk28 = 0; + xBegin = 0; + yBegin = 0; + xCurrent = 0; + yCurrent = 0; + unk40 = 0; + font = fi; + unk50 = 0x25a1; + } + + DrawTextParams() + { + DrawTextParams((FontInfo*)0x140eda860); + } + }; + + /* 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); + } + } + }; */ + + // flags aren't really known, but 1 == normal, 2 == right align?, 8 == centered + void drawText(DrawTextParams* dtParam, uint32_t flags, std::string str) + { + ((void(*)(DrawTextParams*, uint32_t, const char*, int64_t))0x140198500)(dtParam, flags, str.c_str(), str.length()); + } + + void drawTextW(DrawTextParams* dtParam, uint32_t flags, std::wstring str) + { + const wchar_t* ptrs[2]; + ptrs[0] = str.c_str(); + ptrs[1] = (wchar_t*)((uint64_t)ptrs[0] + str.length() * 2); + + ((void(*)(DrawTextParams*, uint32_t, const wchar_t**))0x140198380)(dtParam, flags, &ptrs[0]); + } + //void(*drawTextW)(DrawTextParams* dtParam, uint32_t flags, MsStringW str) = (void(*)(DrawTextParams* dtParam, uint32_t flags, MsStringW str))0x140198380; +#pragma pack(pop) +} \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/Components/EmulatorComponent.h b/source-code/source/plugins/TLAC/Components/EmulatorComponent.h index 20955ae..69f63e8 100644 --- a/source-code/source/plugins/TLAC/Components/EmulatorComponent.h +++ b/source-code/source/plugins/TLAC/Components/EmulatorComponent.h @@ -17,6 +17,7 @@ namespace TLAC::Components virtual void UpdateInput() {}; virtual void UpdatePostInput() {}; + virtual void UpdateDrawSprites() {}; virtual void UpdatePostDraw() {}; virtual void OnFocusGain() {}; virtual void OnFocusLost() {}; diff --git a/source-code/source/plugins/TLAC/Components/Input/InputEmulator.cpp b/source-code/source/plugins/TLAC/Components/Input/InputEmulator.cpp index a26b38a..ce6776a 100644 --- a/source-code/source/plugins/TLAC/Components/Input/InputEmulator.cpp +++ b/source-code/source/plugins/TLAC/Components/Input/InputEmulator.cpp @@ -13,6 +13,7 @@ #include "../../Utilities/EnumBitwiseOperations.h" #include "../../FileSystem/ConfigFile.h" #include "../GameState.h" +#include "../Pause.h" const std::string KEY_CONFIG_FILE_NAME = "keyconfig.ini"; @@ -236,13 +237,13 @@ namespace TLAC::Components { JvsButtons buttons = JVS_NONE; - if (!(*(GameState*)CURRENT_GAME_STATE_ADDRESS == GS_GAME && *(SubGameState*)CURRENT_GAME_SUB_STATE_ADDRESS == SUB_GAME_MAIN) && + if ((Pause::isPaused || !(*(GameState*)CURRENT_GAME_STATE_ADDRESS == GS_GAME && *(SubGameState*)CURRENT_GAME_SUB_STATE_ADDRESS == SUB_GAME_MAIN)) && buttonTestFunc(MenuLBinding)) { buttons |= JVS_L; return buttons; } - if (!(*(GameState*)CURRENT_GAME_STATE_ADDRESS == GS_GAME && *(SubGameState*)CURRENT_GAME_SUB_STATE_ADDRESS == SUB_GAME_MAIN) && + if ((Pause::isPaused || !(*(GameState*)CURRENT_GAME_STATE_ADDRESS == GS_GAME && *(SubGameState*)CURRENT_GAME_SUB_STATE_ADDRESS == SUB_GAME_MAIN)) && buttonTestFunc(MenuRBinding)) { buttons |= JVS_R; diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index 9903377..8d198c0 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -1,8 +1,9 @@ #include "Pause.h" #include "../Constants.h" #include "GameState.h" +#include "DrawText.h" #include "Input/InputState.h" -#include "GL\glut.h" +#include "GL/glut.h" #include #include @@ -41,7 +42,7 @@ namespace TLAC::Components if (isPaused) { // exit pause if key is tapped or no longer in game somehow - if (isPauseKeyTapped() || *(GameState*)CURRENT_GAME_STATE_ADDRESS != GS_GAME || *(SubGameState*)CURRENT_GAME_SUB_STATE_ADDRESS != SUB_GAME_MAIN) + if (isUnpauseKeyTapped() || *(GameState*)CURRENT_GAME_STATE_ADDRESS != GS_GAME || *(SubGameState*)CURRENT_GAME_SUB_STATE_ADDRESS != SUB_GAME_MAIN) { setPaused(false); } @@ -60,6 +61,11 @@ namespace TLAC::Components menuPos %= menuItems.size(); + // actually use released when unpausing from a face button so it doesn't trigger input + // (this can trigger an unpause too) + if (inputState->Released.Buttons & JVS_CIRCLE) + menuItems[menuPos].second(); + // swallow all button inputs if paused inputState->Tapped.Buttons = JVS_NONE; inputState->DoubleTapped.Buttons = JVS_NONE; @@ -82,6 +88,47 @@ namespace TLAC::Components } } + void Pause::UpdateDrawSprites() + { + if (isPaused && showUI) + { + FontInfo fontInfo(0x11); + fontInfo.setSize(menuTextSize, menuTextSize); + DrawTextParams dtParams(&fontInfo); + + dtParams.strokeColour = 0xff000000; + + dtParams.xBegin = menuX; + dtParams.yBegin = menuY - menuItemHeight * (menuItems.size() / 2.0); + + for (int i = 0; i < menuItems.size(); i++) + { + std::pair &item = menuItems[i]; + + if (i == menuPos) + dtParams.textColour = 0xffffff00; + else + dtParams.textColour = 0xffffffff; + + dtParams.xCurrent = dtParams.xBegin; + dtParams.yCurrent = dtParams.yBegin; + drawText(&dtParams, 8, item.first); + dtParams.yBegin += menuItemHeight; + } + + fontInfo.setSize(18, 18); + + dtParams.xBegin = menuX; + dtParams.yBegin = 600; + dtParams.xCurrent = dtParams.xBegin; + dtParams.yCurrent = dtParams.yBegin; + + dtParams.textColour = 0xffffffff; + + drawTextW(&dtParams, 8, L"○:Select ×:Close L/R:Move □:Hide Menu"); + } + } + void Pause::UpdatePostDraw() { if (isPaused && showUI) @@ -111,24 +158,69 @@ namespace TLAC::Components glBegin(GL_QUADS); glBindTexture(GL_TEXTURE_2D, 0); - glColor4ub(0, 0, 0, 127); + glColor4ub(0, 0, 0, 64); glVertex2i(0, 0); glVertex2i(1280, 0); glVertex2i(1280, 720); glVertex2i(0, 720); + const int pauseWidth = 80; + const int pauseHeight = 110; + const int pauseGap = 20; + const int pausePosX = 32; + const int pausePosY = 32; + + const int pauseX1 = pausePosX; + const int pauseX2 = pauseX1 + (pauseWidth - pauseGap) / 2; + const int pauseX3 = pauseX2 + pauseGap; + const int pauseX4 = pauseX1 + pauseWidth; + + const int pauseY1 = pausePosY; + const int pauseY2 = pauseY1 + pauseHeight; + glColor4ub(255, 255, 255, 127); - glVertex2i(560, 250); - glVertex2i(620, 250); - glVertex2i(620, 470); - glVertex2i(560, 470); - glVertex2i(660, 250); - glVertex2i(720, 250); - glVertex2i(720, 470); - glVertex2i(660, 470); + glVertex2i(pauseX1, pauseY1); + glVertex2i(pauseX2, pauseY1); + glVertex2i(pauseX2, pauseY2); + glVertex2i(pauseX1, pauseY2); + glVertex2i(pauseX3, pauseY1); + glVertex2i(pauseX4, pauseY1); + glVertex2i(pauseX4, pauseY2); + glVertex2i(pauseX3, pauseY2); glEnd(); + glBegin(GL_QUAD_STRIP); + int selectBoxOrigin = menuY - menuItemHeight * (menuItems.size() / 2.0) - (menuItemHeight - menuTextSize) / 2; + int selectBoxPos = selectBoxOrigin + menuItemHeight * menuPos; + const int selectBoxWidth = 200; + const int selectBoxHeight = menuItemHeight; + const int selectBoxThickness = 2; + + const int selectBoxX1 = menuX - selectBoxWidth / 2; + const int selectBoxX4 = selectBoxX1 + selectBoxWidth; + const int selectBoxX2 = selectBoxX1 + selectBoxThickness; + const int selectBoxX3 = selectBoxX4 - selectBoxThickness; + + const int selectBoxY1 = selectBoxPos; + const int selectBoxY4 = selectBoxY1 + selectBoxHeight; + const int selectBoxY2 = selectBoxY1 + selectBoxThickness; + const int selectBoxY3 = selectBoxY4 - selectBoxThickness; + + glColor4ub(0, 255, 255, 127); + glVertex2i(selectBoxX2, selectBoxY2); + glVertex2i(selectBoxX1, selectBoxY1); + glVertex2i(selectBoxX3, selectBoxY2); + glVertex2i(selectBoxX4, selectBoxY1); + glVertex2i(selectBoxX3, selectBoxY3); + glVertex2i(selectBoxX4, selectBoxY4); + glVertex2i(selectBoxX2, selectBoxY3); + glVertex2i(selectBoxX1, selectBoxY4); + glVertex2i(selectBoxX2, selectBoxY2); + glVertex2i(selectBoxX1, selectBoxY1); + + glEnd(); + glMatrixMode(GL_MODELVIEW); glPopMatrix(); glMatrixMode(GL_PROJECTION); @@ -142,6 +234,13 @@ namespace TLAC::Components return ((InputState*)(*(uint64_t*)INPUT_STATE_PTR_ADDRESS))->Tapped.Buttons & JVS_START; } + bool Pause::isUnpauseKeyTapped() + { + // actually use released when unpausing from a face button so it doesn't trigger input + return ((InputState*)(*(uint64_t*)INPUT_STATE_PTR_ADDRESS))->Tapped.Buttons & JVS_START || + ((InputState*)(*(uint64_t*)INPUT_STATE_PTR_ADDRESS))->Released.Buttons & JVS_CROSS; + } + void Pause::setPaused(bool pause) { uint64_t audioMixerAddr = *(uint64_t*)(AUDIO_MAIN_CLASS_ADDRESS + 0x70); diff --git a/source-code/source/plugins/TLAC/Components/Pause.h b/source-code/source/plugins/TLAC/Components/Pause.h index 0825cb9..70a3c18 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.h +++ b/source-code/source/plugins/TLAC/Components/Pause.h @@ -15,12 +15,14 @@ namespace TLAC::Components virtual void Initialize(ComponentsManager*) override; virtual void Update() override; virtual void UpdatePostInput() override; + virtual void UpdateDrawSprites() override; virtual void UpdatePostDraw() override; static bool isPaused; private: // this is a mess of static so that menuItems can work static bool isPauseKeyTapped(); + static bool isUnpauseKeyTapped(); static void setPaused(bool pause); static std::vector streamPlayStates; static void InjectCode(void* address, const std::vector data); @@ -28,11 +30,17 @@ namespace TLAC::Components static std::vector origAetMovOp; static constexpr uint8_t* aetMovPatchAddress = (uint8_t*)0x1401703b3; + static const int menuX = 640; + static const int menuY = 360; + static const int menuItemHeight = 36; + static const int menuTextSize = 24; + bool showUI = true; unsigned int menuPos = 0; static void unpause() { setPaused(false); }; std::vector> menuItems = { std::pair(std::string("RESUME"), &unpause), + //std::pair(std::string("GIVE UP"), &unpause), }; }; } diff --git a/source-code/source/plugins/TLAC/Constants.h b/source-code/source/plugins/TLAC/Constants.h index 84ec16d..6714d3b 100644 --- a/source-code/source/plugins/TLAC/Constants.h +++ b/source-code/source/plugins/TLAC/Constants.h @@ -8,6 +8,7 @@ constexpr uint8_t JNE_OPCODE = 0x85; //constexpr uint64_t ENGINE_UPDATE_HOOK_TARGET_ADDRESS = 0x000000014018CC40; constexpr uint64_t ENGINE_UPDATE_INPUT_ADDRESS = 0x000000014018CBB0; +constexpr uint64_t ENGINE_DRAW_SPRITES_ADDRESS = 0x0000000140500EA0; constexpr uint64_t ENGINE_FINISH_DRAW_ADDRESS = 0x0000000140192730; constexpr uint64_t CURRENT_GAME_STATE_ADDRESS = 0x0000000140EDA810; diff --git a/source-code/source/plugins/TLAC/TLAC.vcxproj b/source-code/source/plugins/TLAC/TLAC.vcxproj index ca6164c..4ba0caf 100644 --- a/source-code/source/plugins/TLAC/TLAC.vcxproj +++ b/source-code/source/plugins/TLAC/TLAC.vcxproj @@ -111,6 +111,7 @@ + diff --git a/source-code/source/plugins/TLAC/TLAC.vcxproj.filters b/source-code/source/plugins/TLAC/TLAC.vcxproj.filters index c1a7c42..0d80993 100644 --- a/source-code/source/plugins/TLAC/TLAC.vcxproj.filters +++ b/source-code/source/plugins/TLAC/TLAC.vcxproj.filters @@ -198,6 +198,9 @@ Header Files + + Header Files + diff --git a/source-code/source/plugins/TLAC/dllmain.cpp b/source-code/source/plugins/TLAC/dllmain.cpp index 32c0b79..6bdf252 100644 --- a/source-code/source/plugins/TLAC/dllmain.cpp +++ b/source-code/source/plugins/TLAC/dllmain.cpp @@ -19,6 +19,7 @@ #pragma comment(lib, "detours.lib") void(__cdecl* divaEngineUpdate)() = (void(__cdecl*)())0x14018CC40; +void(__cdecl* divaEngineDrawSprites)(void* addr, int idk) = (void(__cdecl*)(void* addr, int idk))ENGINE_DRAW_SPRITES_ADDRESS; void(__cdecl* divaEngineFinishDraw)() = (void(__cdecl*)())ENGINE_FINISH_DRAW_ADDRESS; LRESULT CALLBACK MessageWindowProcessCallback(HWND, UINT, WPARAM, LPARAM); @@ -127,6 +128,11 @@ namespace TLAC ComponentsManager.OnFocusLost(); } + void UpdateDrawSprites() + { + ComponentsManager.UpdateDrawSprites(); + } + void UpdatePostDraw() { ComponentsManager.UpdatePostDraw(); @@ -348,6 +354,13 @@ void hookedEngineUpdate() //divaEngineUpdate(); } +void hookedEngineDrawSprites(void* addr, int idk) +{ + divaEngineDrawSprites(addr, idk); + if (idk == 0x0a) + TLAC::UpdateDrawSprites(); +} + void hookedEngineFinishDraw() { TLAC::UpdatePostDraw(); @@ -374,6 +387,12 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReser DetourUpdateThread(GetCurrentThread()); DetourAttach(&(PVOID&)divaEngineUpdate, hookedEngineUpdate); DetourTransactionCommit(); + + DetourTransactionBegin(); + DetourUpdateThread(GetCurrentThread()); + DetourAttach(&(PVOID&)divaEngineDrawSprites, hookedEngineDrawSprites); + DetourTransactionCommit(); + DetourTransactionBegin(); DetourUpdateThread(GetCurrentThread()); DetourAttach(&(PVOID&)divaEngineFinishDraw, hookedEngineFinishDraw); From d8ac3bbd67593b39d9b4b1be483b834293dd2858 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Sun, 20 Oct 2019 17:35:51 +1100 Subject: [PATCH 04/44] pause: move entire UI to in-engine sprites, make give up work, DrawText.h->Drawing.h, make framespeed modification robust (code's still a mess tho) --- .../TLAC/Components/{DrawText.h => Drawing.h} | 55 +++-- .../source/plugins/TLAC/Components/Pause.cpp | 221 +++++++++--------- .../source/plugins/TLAC/Components/Pause.h | 19 +- source-code/source/plugins/TLAC/Constants.h | 4 + source-code/source/plugins/TLAC/TLAC.vcxproj | 2 +- .../source/plugins/TLAC/TLAC.vcxproj.filters | 2 +- 6 files changed, 166 insertions(+), 137 deletions(-) rename source-code/source/plugins/TLAC/Components/{DrawText.h => Drawing.h} (67%) diff --git a/source-code/source/plugins/TLAC/Components/DrawText.h b/source-code/source/plugins/TLAC/Components/Drawing.h similarity index 67% rename from source-code/source/plugins/TLAC/Components/DrawText.h rename to source-code/source/plugins/TLAC/Components/Drawing.h index 6ae3487..7a17d16 100644 --- a/source-code/source/plugins/TLAC/Components/DrawText.h +++ b/source-code/source/plugins/TLAC/Components/Drawing.h @@ -65,17 +65,20 @@ namespace TLAC::Components FontInfo*(*getFont)(FontInfo* fi, uint32_t id) = (FontInfo*(*)(FontInfo* fi, uint32_t id))0x140196510; void(*fontSize)(FontInfo* fi, float width, float height) = (void(*)(FontInfo* fi, float width, float height))0x140199e60; - struct DrawTextParams + struct DrawParams { - uint32_t textColour; // RGBA byte array?, so set as 0xAABBGGRR - uint32_t strokeColour; // ?? RGBA byte array?, so set as 0xAABBGGRR + uint32_t colour; // RGBA byte array?, so set as 0xAABBGGRR + uint32_t fillColour; // ?? RGBA byte array?, so set as 0xAABBGGRR uint8_t unk08; - uint8_t padding09[0x3]; + uint8_t unk09[0x3]; uint32_t unk0c; uint32_t unk10; uint32_t unk14; uint32_t unk18; - uint64_t unk1c; + uint32_t layer; // 8 seems similar to default but higher + // 0x19 is startup screen + // I noticed some use different scaling + uint32_t unk20; uint32_t unk24; uint32_t unk28; float xBegin; // ? @@ -87,16 +90,17 @@ namespace TLAC::Components FontInfo* font; uint16_t unk50; - DrawTextParams(FontInfo* fi) + DrawParams(FontInfo* fi) { - textColour = 0xffffffff; - strokeColour = 0xff808080; + colour = 0xffffffff; + fillColour = 0xff808080; // except it's not? unk08 = 0; unk0c = 0; unk10 = 0; unk14 = 0; unk18 = 0; - unk1c = 0x7; + layer = 0x7; + unk20 = 0x0; unk24 = 0xd; unk28 = 0; xBegin = 0; @@ -108,9 +112,9 @@ namespace TLAC::Components unk50 = 0x25a1; } - DrawTextParams() + DrawParams() { - DrawTextParams((FontInfo*)0x140eda860); + DrawParams((FontInfo*)0x140eda860); } }; @@ -176,20 +180,37 @@ namespace TLAC::Components } }; */ - // flags aren't really known, but 1 == normal, 2 == right align?, 8 == centered - void drawText(DrawTextParams* dtParam, uint32_t flags, std::string str) + enum drawTextFlags : uint32_t { - ((void(*)(DrawTextParams*, uint32_t, const char*, int64_t))0x140198500)(dtParam, flags, str.c_str(), str.length()); + DRAWTEXT_PARAGRAPH = 1, //? + DRAWTEXT_ALIGN_RIGHT = 2, + DRAWTEXT_ALIGN_CENTRE = 8, + DRAWTEXT_STROKE = 0x10000, + }; + + void drawText(DrawParams* dtParam, drawTextFlags flags, std::string str) + { + ((void(*)(DrawParams*, uint32_t, const char*, int64_t))0x140198500)(dtParam, flags, str.c_str(), str.length()); } - void drawTextW(DrawTextParams* dtParam, uint32_t flags, std::wstring str) + void drawTextW(DrawParams* dtParam, drawTextFlags flags, std::wstring str) { const wchar_t* ptrs[2]; ptrs[0] = str.c_str(); ptrs[1] = (wchar_t*)((uint64_t)ptrs[0] + str.length() * 2); - ((void(*)(DrawTextParams*, uint32_t, const wchar_t**))0x140198380)(dtParam, flags, &ptrs[0]); + ((void(*)(DrawParams*, uint32_t, const wchar_t**))0x140198380)(dtParam, flags, &ptrs[0]); } - //void(*drawTextW)(DrawTextParams* dtParam, uint32_t flags, MsStringW str) = (void(*)(DrawTextParams* dtParam, uint32_t flags, MsStringW str))0x140198380; + //void(*drawTextW)(DrawParams* dtParam, drawTextFlags flags, MsStringW str) = (void(*)(DrawParams* dtParam, drawTextFlags flags, MsStringW str))0x140198380; + + struct RectangleBounds + { + float x; + float y; + float width; + float height; + }; + void(*fillRectangle)(DrawParams* dtParam, RectangleBounds* rect) = (void(*)(DrawParams* dtParam, RectangleBounds* rect))0x140198d80; + void(*drawRectangle)(DrawParams* dtParam, RectangleBounds* rect) = (void(*)(DrawParams* dtParam, RectangleBounds* rect))0x140198320; #pragma pack(pop) } \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index 8d198c0..820d368 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -1,17 +1,23 @@ #include "Pause.h" #include "../Constants.h" #include "GameState.h" -#include "DrawText.h" +#include "Drawing.h" #include "Input/InputState.h" #include "GL/glut.h" +#include "detours.h" #include #include namespace TLAC::Components { bool Pause::isPaused = false; + bool Pause::giveUp = false; + bool Pause::showUI = true; + unsigned int Pause::menuPos = 0; std::vector Pause::origAetMovOp; + std::vector Pause::origFramespeedOp; std::vector Pause::streamPlayStates; + bool(*divaGiveUpFunc)(void*) = (bool(*)(void* cls))GIVEUP_FUNC_ADDRESS; Pause::Pause() { @@ -30,6 +36,14 @@ namespace TLAC::Components { origAetMovOp.resize(8); memcpy(&origAetMovOp[0], aetMovPatchAddress, 8); + + origFramespeedOp.resize(4); + memcpy(&origFramespeedOp[0], framespeedPatchAddress, 4); + + DetourTransactionBegin(); + DetourUpdateThread(GetCurrentThread()); + DetourAttach(&(PVOID&)divaGiveUpFunc, hookedGiveUpFunc); + DetourTransactionCommit(); } void Pause::Update() @@ -66,6 +80,7 @@ namespace TLAC::Components if (inputState->Released.Buttons & JVS_CIRCLE) menuItems[menuPos].second(); + // swallow all button inputs if paused inputState->Tapped.Buttons = JVS_NONE; inputState->DoubleTapped.Buttons = JVS_NONE; @@ -92,11 +107,69 @@ namespace TLAC::Components { if (isPaused && showUI) { + // setup draw objects FontInfo fontInfo(0x11); - fontInfo.setSize(menuTextSize, menuTextSize); - DrawTextParams dtParams(&fontInfo); + DrawParams dtParams(&fontInfo); + dtParams.layer = 0x19; // same as startup screen - dtParams.strokeColour = 0xff000000; + + // bg rect + RectangleBounds rect; + rect = { 0, 0, 1280, 720 }; + dtParams.colour = 0x80000000; + dtParams.fillColour = 0x80000000; + fillRectangle(&dtParams, &rect); + + + // pause icon + const int pauseWidth = 80; + const int pauseHeight = 110; + const int pauseGap = 20; + const int pausePosX = 32; + const int pausePosY = 32; + const int pausePartWidth = (pauseWidth - pauseGap) / 2; + + const int pauseX1 = pausePosX; + const int pauseX2 = pausePosX + pausePartWidth + pauseGap; + const int pauseY1 = pausePosY; + + dtParams.colour = 0x80ffffff; + dtParams.fillColour = 0x80ffffff; + rect = { pauseX1, pauseY1, pausePartWidth, pauseHeight }; + fillRectangle(&dtParams, &rect); + rect = { pauseX2, pauseY1, pausePartWidth, pauseHeight }; + fillRectangle(&dtParams, &rect); + + + // selection cursor + int selectBoxOrigin = menuY - menuItemHeight * (menuItems.size() / 2.0) - (menuItemHeight - menuTextSize) / 2; + int selectBoxPos = selectBoxOrigin + menuItemHeight * menuPos; + const float selectBoxWidth = 200; + const float selectBoxHeight = menuItemHeight; + const float selectBoxThickness = 2; + + const float selectBoxX1 = menuX - selectBoxWidth / 2; + const float selectBoxX2 = selectBoxX1 + selectBoxWidth - selectBoxThickness; + const float selectBoxY1 = selectBoxPos; + const float selectBoxY2 = selectBoxY1 + selectBoxThickness; + const float selectBoxY3 = selectBoxY1 + selectBoxHeight - selectBoxThickness; + const float selectBoxSideHeight = selectBoxHeight - 2 * selectBoxThickness; + + // dirty hack using fillRectangle to get thickness (idk how to set it or it isn't possible to with drawRectangle) + dtParams.colour = 0xc0ffff00; + dtParams.fillColour = 0xc0ffff00; + rect = { selectBoxX1, selectBoxY1, selectBoxWidth, selectBoxThickness }; // top + fillRectangle(&dtParams, &rect); + rect = { selectBoxX1, selectBoxY3, selectBoxWidth, selectBoxThickness }; // bottom + fillRectangle(&dtParams, &rect); + rect = { selectBoxX1, selectBoxY2, selectBoxThickness, selectBoxSideHeight }; + fillRectangle(&dtParams, &rect); + rect = { selectBoxX2, selectBoxY2, selectBoxThickness, selectBoxSideHeight }; + fillRectangle(&dtParams, &rect); + + + // menu + fontInfo.setSize(menuTextSize, menuTextSize); dtParams.xBegin = menuX; dtParams.yBegin = menuY - menuItemHeight * (menuItems.size() / 2.0); @@ -106,126 +179,26 @@ namespace TLAC::Components std::pair &item = menuItems[i]; if (i == menuPos) - dtParams.textColour = 0xffffff00; + dtParams.colour = 0xffffff00; else - dtParams.textColour = 0xffffffff; + dtParams.colour = 0xffffffff; dtParams.xCurrent = dtParams.xBegin; dtParams.yCurrent = dtParams.yBegin; - drawText(&dtParams, 8, item.first); + drawText(&dtParams, (drawTextFlags)(DRAWTEXT_ALIGN_CENTRE), item.first); dtParams.yBegin += menuItemHeight; } + + // key legend fontInfo.setSize(18, 18); dtParams.xBegin = menuX; dtParams.yBegin = 600; dtParams.xCurrent = dtParams.xBegin; dtParams.yCurrent = dtParams.yBegin; - - dtParams.textColour = 0xffffffff; - - drawTextW(&dtParams, 8, L"○:Select ×:Close L/R:Move □:Hide Menu"); - } - } - - void Pause::UpdatePostDraw() - { - if (isPaused && showUI) - { - // this isn't imgui code, but I probably wouldn't have gotten this working properly if I didn't reference it, so... umm... yeah lol - glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT); - - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glDisable(GL_CULL_FACE); - glDisable(GL_DEPTH_TEST); - glDisable(GL_LIGHTING); - glDisable(GL_COLOR_MATERIAL); - - int width = glutGet(GLUT_WINDOW_WIDTH); - int height = glutGet(GLUT_WINDOW_HEIGHT); - - glViewport(0, 0, width, height); - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - glOrtho(0, 1280, 720, 0, -1.0f, +1.0f); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); - - glBegin(GL_QUADS); - glBindTexture(GL_TEXTURE_2D, 0); - - glColor4ub(0, 0, 0, 64); - glVertex2i(0, 0); - glVertex2i(1280, 0); - glVertex2i(1280, 720); - glVertex2i(0, 720); - - const int pauseWidth = 80; - const int pauseHeight = 110; - const int pauseGap = 20; - const int pausePosX = 32; - const int pausePosY = 32; - - const int pauseX1 = pausePosX; - const int pauseX2 = pauseX1 + (pauseWidth - pauseGap) / 2; - const int pauseX3 = pauseX2 + pauseGap; - const int pauseX4 = pauseX1 + pauseWidth; - - const int pauseY1 = pausePosY; - const int pauseY2 = pauseY1 + pauseHeight; - - glColor4ub(255, 255, 255, 127); - glVertex2i(pauseX1, pauseY1); - glVertex2i(pauseX2, pauseY1); - glVertex2i(pauseX2, pauseY2); - glVertex2i(pauseX1, pauseY2); - glVertex2i(pauseX3, pauseY1); - glVertex2i(pauseX4, pauseY1); - glVertex2i(pauseX4, pauseY2); - glVertex2i(pauseX3, pauseY2); - - glEnd(); - glBegin(GL_QUAD_STRIP); - - int selectBoxOrigin = menuY - menuItemHeight * (menuItems.size() / 2.0) - (menuItemHeight - menuTextSize) / 2; - int selectBoxPos = selectBoxOrigin + menuItemHeight * menuPos; - const int selectBoxWidth = 200; - const int selectBoxHeight = menuItemHeight; - const int selectBoxThickness = 2; - - const int selectBoxX1 = menuX - selectBoxWidth / 2; - const int selectBoxX4 = selectBoxX1 + selectBoxWidth; - const int selectBoxX2 = selectBoxX1 + selectBoxThickness; - const int selectBoxX3 = selectBoxX4 - selectBoxThickness; - - const int selectBoxY1 = selectBoxPos; - const int selectBoxY4 = selectBoxY1 + selectBoxHeight; - const int selectBoxY2 = selectBoxY1 + selectBoxThickness; - const int selectBoxY3 = selectBoxY4 - selectBoxThickness; - - glColor4ub(0, 255, 255, 127); - glVertex2i(selectBoxX2, selectBoxY2); - glVertex2i(selectBoxX1, selectBoxY1); - glVertex2i(selectBoxX3, selectBoxY2); - glVertex2i(selectBoxX4, selectBoxY1); - glVertex2i(selectBoxX3, selectBoxY3); - glVertex2i(selectBoxX4, selectBoxY4); - glVertex2i(selectBoxX2, selectBoxY3); - glVertex2i(selectBoxX1, selectBoxY4); - glVertex2i(selectBoxX2, selectBoxY2); - glVertex2i(selectBoxX1, selectBoxY1); - - glEnd(); - - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glPopAttrib(); + dtParams.colour = 0xffffffff; + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ALIGN_CENTRE), L"○:Select ×:Close L/R:Move □:Hide Menu"); } } @@ -249,10 +222,10 @@ namespace TLAC::Components if (pause) { - *(float*)FRAME_SPEED_ADDRESS = 0.0f; // todo: hook getFrameSpeed so this can't be screwed up ((void(*)())DSC_PAUSE_FUNC_ADDRESS)(); InjectCode(aetMovPatchAddress, { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 }); + InjectCode(framespeedPatchAddress, { 0x0f, 0x57, 0xc0, 0xc3 }); // XORPS XMM0,XMM0; RET for (int i = 0; i < nAudioStreams; i++) { @@ -264,13 +237,16 @@ namespace TLAC::Components *playstate = 0; } + + menuPos = 0; + showUI = true; } else { - *(float*)FRAME_SPEED_ADDRESS = 1.0f; ((void(*)())DSC_UNPAUSE_FUNC_ADDRESS)(); InjectCode(aetMovPatchAddress, origAetMovOp); + InjectCode(framespeedPatchAddress, origFramespeedOp); for (int i = 0; i < nAudioStreams; i++) { @@ -283,6 +259,25 @@ namespace TLAC::Components isPaused = pause; } + bool Pause::hookedGiveUpFunc(void* cls) + { + if (giveUp) + { + giveUp = false; + setPaused(false); + return true; + } + else + { + if (divaGiveUpFunc(cls)) + { + setPaused(false); + return true; + } + } + return false; + } + void Pause::InjectCode(void* address, const std::vector data) { const size_t byteCount = data.size() * sizeof(uint8_t); diff --git a/source-code/source/plugins/TLAC/Components/Pause.h b/source-code/source/plugins/TLAC/Components/Pause.h index 70a3c18..747d116 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.h +++ b/source-code/source/plugins/TLAC/Components/Pause.h @@ -1,4 +1,5 @@ #pragma once +#include "../Constants.h" #include "EmulatorComponent.h" #include @@ -16,31 +17,39 @@ namespace TLAC::Components virtual void Update() override; virtual void UpdatePostInput() override; virtual void UpdateDrawSprites() override; - virtual void UpdatePostDraw() override; static bool isPaused; + static bool giveUp; + static void setPaused(bool pause); private: // this is a mess of static so that menuItems can work static bool isPauseKeyTapped(); static bool isUnpauseKeyTapped(); - static void setPaused(bool pause); static std::vector streamPlayStates; static void InjectCode(void* address, const std::vector data); static std::vector origAetMovOp; static constexpr uint8_t* aetMovPatchAddress = (uint8_t*)0x1401703b3; + static std::vector origFramespeedOp; + static constexpr uint8_t* framespeedPatchAddress = (uint8_t*)0x140192D50; + + static bool hookedGiveUpFunc(void* cls); + static const int menuX = 640; static const int menuY = 360; static const int menuItemHeight = 36; static const int menuTextSize = 24; - bool showUI = true; - unsigned int menuPos = 0; + static bool showUI; + static unsigned int menuPos; + static void unpause() { setPaused(false); }; + static void giveup() { giveUp = true; }; + std::vector> menuItems = { std::pair(std::string("RESUME"), &unpause), - //std::pair(std::string("GIVE UP"), &unpause), + std::pair(std::string("GIVE UP"), &giveup), }; }; } diff --git a/source-code/source/plugins/TLAC/Constants.h b/source-code/source/plugins/TLAC/Constants.h index 6714d3b..cfe2a8e 100644 --- a/source-code/source/plugins/TLAC/Constants.h +++ b/source-code/source/plugins/TLAC/Constants.h @@ -111,6 +111,10 @@ constexpr uint64_t DSC_START_SYS_TIME_ADDRESS_2 = 0x0000000140D0B568; constexpr uint64_t DSC_PAUSE_FUNC_ADDRESS = 0x00000001401295C0; constexpr uint64_t DSC_UNPAUSE_FUNC_ADDRESS = 0x0000000140129590; +constexpr uint64_t PV_GAME_BASE_ADDRESS = 0x0000000140C94380; +constexpr uint64_t GIVEUP_FUNC_ADDRESS = 0x000000014010EF00; + + #define XINPUT_A 0x00 #define XINPUT_B 0x01 #define XINPUT_X 0x02 diff --git a/source-code/source/plugins/TLAC/TLAC.vcxproj b/source-code/source/plugins/TLAC/TLAC.vcxproj index 4ba0caf..2c61ae9 100644 --- a/source-code/source/plugins/TLAC/TLAC.vcxproj +++ b/source-code/source/plugins/TLAC/TLAC.vcxproj @@ -111,7 +111,7 @@ - + diff --git a/source-code/source/plugins/TLAC/TLAC.vcxproj.filters b/source-code/source/plugins/TLAC/TLAC.vcxproj.filters index 0d80993..6ec4726 100644 --- a/source-code/source/plugins/TLAC/TLAC.vcxproj.filters +++ b/source-code/source/plugins/TLAC/TLAC.vcxproj.filters @@ -198,7 +198,7 @@ Header Files - + Header Files From cc183348e461846a95b0c4824b6c145b72574d92 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Sun, 20 Oct 2019 19:58:09 +1100 Subject: [PATCH 05/44] pause: don't listen for menu input when menu is hidden, improve keys legend, add pulsing effect to selected item's text, remove isUnpauseKeyTapped --- .../source/plugins/TLAC/Components/Drawing.h | 2 +- .../source/plugins/TLAC/Components/Pause.cpp | 78 +++++++++++++------ .../source/plugins/TLAC/Components/Pause.h | 4 +- 3 files changed, 58 insertions(+), 26 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Drawing.h b/source-code/source/plugins/TLAC/Components/Drawing.h index 7a17d16..773f5f4 100644 --- a/source-code/source/plugins/TLAC/Components/Drawing.h +++ b/source-code/source/plugins/TLAC/Components/Drawing.h @@ -182,7 +182,7 @@ namespace TLAC::Components enum drawTextFlags : uint32_t { - DRAWTEXT_PARAGRAPH = 1, //? + DRAWTEXT_ENABLE_LAYOUT = 1, //? DRAWTEXT_ALIGN_RIGHT = 2, DRAWTEXT_ALIGN_CENTRE = 8, DRAWTEXT_STROKE = 0x10000, diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index 820d368..7652c76 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -7,6 +7,7 @@ #include "detours.h" #include #include +#include namespace TLAC::Components { @@ -14,6 +15,7 @@ namespace TLAC::Components bool Pause::giveUp = false; bool Pause::showUI = true; unsigned int Pause::menuPos = 0; + std::chrono::time_point Pause::menuItemSelectTime; std::vector Pause::origAetMovOp; std::vector Pause::origFramespeedOp; std::vector Pause::streamPlayStates; @@ -55,8 +57,8 @@ namespace TLAC::Components { if (isPaused) { - // exit pause if key is tapped or no longer in game somehow - if (isUnpauseKeyTapped() || *(GameState*)CURRENT_GAME_STATE_ADDRESS != GS_GAME || *(SubGameState*)CURRENT_GAME_SUB_STATE_ADDRESS != SUB_GAME_MAIN) + // always exit pause if key is tapped or no longer in game somehow + if (isPauseKeyTapped() || *(GameState*)CURRENT_GAME_STATE_ADDRESS != GS_GAME || *(SubGameState*)CURRENT_GAME_SUB_STATE_ADDRESS != SUB_GAME_MAIN) { setPaused(false); } @@ -67,18 +69,31 @@ namespace TLAC::Components if (inputState->Tapped.Buttons & JVS_SQUARE) showUI = !showUI; - if (inputState->Tapped.Buttons & JVS_L) - menuPos -= 1; + // only process menu events when UI is visible + if (showUI) + { + if (inputState->Tapped.Buttons & JVS_L) + { + menuPos -= 1; + menuItemSelectTime = std::chrono::high_resolution_clock::now(); + } - if (inputState->Tapped.Buttons & JVS_R) - menuPos += 1; + if (inputState->Tapped.Buttons & JVS_R) + { + menuPos += 1; + menuItemSelectTime = std::chrono::high_resolution_clock::now(); + } - menuPos %= menuItems.size(); + menuPos %= menuItems.size(); - // actually use released when unpausing from a face button so it doesn't trigger input - // (this can trigger an unpause too) - if (inputState->Released.Buttons & JVS_CIRCLE) - menuItems[menuPos].second(); + // use released when unpausing from X so it doesn't trigger input + if (inputState->Released.Buttons & JVS_CROSS) + setPaused(false); + + // use released because this can trigger an unpause too + if (inputState->Released.Buttons & JVS_CIRCLE) + menuItems[menuPos].second(); + } // swallow all button inputs if paused @@ -116,12 +131,13 @@ namespace TLAC::Components // bg rect RectangleBounds rect; rect = { 0, 0, 1280, 720 }; - dtParams.colour = 0x80000000; - dtParams.fillColour = 0x80000000; + dtParams.colour = 0xa0000000; + dtParams.fillColour = 0xa0000000; fillRectangle(&dtParams, &rect); // pause icon + /* const int pauseWidth = 80; const int pauseHeight = 110; const int pauseGap = 20; @@ -139,6 +155,7 @@ namespace TLAC::Components fillRectangle(&dtParams, &rect); rect = { pauseX2, pauseY1, pausePartWidth, pauseHeight }; fillRectangle(&dtParams, &rect); + */ // selection cursor @@ -179,9 +196,16 @@ namespace TLAC::Components std::pair &item = menuItems[i]; if (i == menuPos) - dtParams.colour = 0xffffff00; + { + const int duration = 1500000000; // 1.5s + std::chrono::nanoseconds cyclePos = (std::chrono::high_resolution_clock::now() - menuItemSelectTime) % std::chrono::nanoseconds(duration); + uint8_t alpha = (cosf(cyclePos.count() * 6.283185f / duration) * 0.15 + 0.85) * 255; + dtParams.colour = 0x00ffff00 | (alpha << 24); + } else + { dtParams.colour = 0xffffffff; + } dtParams.xCurrent = dtParams.xBegin; dtParams.yCurrent = dtParams.yBegin; @@ -193,12 +217,24 @@ namespace TLAC::Components // key legend fontInfo.setSize(18, 18); - dtParams.xBegin = menuX; - dtParams.yBegin = 600; + dtParams.xBegin = 32; + dtParams.yBegin = 720 - 40; dtParams.xCurrent = dtParams.xBegin; dtParams.yCurrent = dtParams.yBegin; dtParams.colour = 0xffffffff; - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ALIGN_CENTRE), L"○:Select ×:Close L/R:Move □:Hide Menu"); + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"L/R:Move "); + dtParams.colour = 0xff4040ff; + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"○"); + dtParams.colour = 0xffffffff; + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Select "); + dtParams.colour = 0xffff8000; + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"×"); + dtParams.colour = 0xffffffff; + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Close "); + dtParams.colour = 0xffc0c0ff; + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"□"); + dtParams.colour = 0xffffffff; + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Hide Menu"); } } @@ -207,13 +243,6 @@ namespace TLAC::Components return ((InputState*)(*(uint64_t*)INPUT_STATE_PTR_ADDRESS))->Tapped.Buttons & JVS_START; } - bool Pause::isUnpauseKeyTapped() - { - // actually use released when unpausing from a face button so it doesn't trigger input - return ((InputState*)(*(uint64_t*)INPUT_STATE_PTR_ADDRESS))->Tapped.Buttons & JVS_START || - ((InputState*)(*(uint64_t*)INPUT_STATE_PTR_ADDRESS))->Released.Buttons & JVS_CROSS; - } - void Pause::setPaused(bool pause) { uint64_t audioMixerAddr = *(uint64_t*)(AUDIO_MAIN_CLASS_ADDRESS + 0x70); @@ -240,6 +269,7 @@ namespace TLAC::Components menuPos = 0; showUI = true; + menuItemSelectTime = std::chrono::high_resolution_clock::now(); } else { diff --git a/source-code/source/plugins/TLAC/Components/Pause.h b/source-code/source/plugins/TLAC/Components/Pause.h index 747d116..e36aeff 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.h +++ b/source-code/source/plugins/TLAC/Components/Pause.h @@ -2,6 +2,7 @@ #include "../Constants.h" #include "EmulatorComponent.h" #include +#include namespace TLAC::Components { @@ -24,7 +25,6 @@ namespace TLAC::Components private: // this is a mess of static so that menuItems can work static bool isPauseKeyTapped(); - static bool isUnpauseKeyTapped(); static std::vector streamPlayStates; static void InjectCode(void* address, const std::vector data); @@ -44,6 +44,8 @@ namespace TLAC::Components static bool showUI; static unsigned int menuPos; + static std::chrono::time_point menuItemSelectTime; + static void unpause() { setPaused(false); }; static void giveup() { giveUp = true; }; From 8edbf92649e9845ada30cce8de8535269763ecfc Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Mon, 21 Oct 2019 01:20:44 +1100 Subject: [PATCH 06/44] pause: add SE volume submenu, improve some state management --- .../TLAC/Components/Input/InputEmulator.cpp | 4 +- .../source/plugins/TLAC/Components/Pause.cpp | 181 +++++++++++------- .../source/plugins/TLAC/Components/Pause.h | 41 +++- 3 files changed, 150 insertions(+), 76 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Input/InputEmulator.cpp b/source-code/source/plugins/TLAC/Components/Input/InputEmulator.cpp index ce6776a..f7d6df1 100644 --- a/source-code/source/plugins/TLAC/Components/Input/InputEmulator.cpp +++ b/source-code/source/plugins/TLAC/Components/Input/InputEmulator.cpp @@ -237,13 +237,13 @@ namespace TLAC::Components { JvsButtons buttons = JVS_NONE; - if ((Pause::isPaused || !(*(GameState*)CURRENT_GAME_STATE_ADDRESS == GS_GAME && *(SubGameState*)CURRENT_GAME_SUB_STATE_ADDRESS == SUB_GAME_MAIN)) && + if ((Pause::pause || !(*(GameState*)CURRENT_GAME_STATE_ADDRESS == GS_GAME && *(SubGameState*)CURRENT_GAME_SUB_STATE_ADDRESS == SUB_GAME_MAIN)) && buttonTestFunc(MenuLBinding)) { buttons |= JVS_L; return buttons; } - if ((Pause::isPaused || !(*(GameState*)CURRENT_GAME_STATE_ADDRESS == GS_GAME && *(SubGameState*)CURRENT_GAME_SUB_STATE_ADDRESS == SUB_GAME_MAIN)) && + if ((Pause::pause || !(*(GameState*)CURRENT_GAME_STATE_ADDRESS == GS_GAME && *(SubGameState*)CURRENT_GAME_SUB_STATE_ADDRESS == SUB_GAME_MAIN)) && buttonTestFunc(MenuRBinding)) { buttons |= JVS_R; diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index 7652c76..2fd9772 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -11,10 +11,13 @@ namespace TLAC::Components { + bool Pause::pause = false; bool Pause::isPaused = false; bool Pause::giveUp = false; bool Pause::showUI = true; unsigned int Pause::menuPos = 0; + unsigned int Pause::mainMenuPos = 0; + unsigned int Pause::menuSet = menuset_main; std::chrono::time_point Pause::menuItemSelectTime; std::vector Pause::origAetMovOp; std::vector Pause::origFramespeedOp; @@ -55,12 +58,41 @@ namespace TLAC::Components void Pause::UpdatePostInput() { - if (isPaused) + if (pause) { + // enter pause mode on state transition + if (!isPaused) + { + ((void(*)())DSC_PAUSE_FUNC_ADDRESS)(); + + InjectCode(aetMovPatchAddress, { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 }); + InjectCode(framespeedPatchAddress, { 0x0f, 0x57, 0xc0, 0xc3 }); // XORPS XMM0,XMM0; RET + + uint64_t audioMixerAddr = *(uint64_t*)(AUDIO_MAIN_CLASS_ADDRESS + 0x70); + uint64_t audioStreamsAddress = *(uint64_t*)(audioMixerAddr + 0x18);; + int nAudioStreams = *(uint64_t*)(audioMixerAddr + 0x20); + for (int i = 0; i < nAudioStreams; i++) + { + uint32_t* playstate = (uint32_t*)(audioStreamsAddress + i * 0x50 + 0x18); + if (i < streamPlayStates.size()) + streamPlayStates[i] = *playstate; + else + streamPlayStates.push_back(*playstate); + + *playstate = 0; + } + + menuPos = 0; + menuSet = menuset_main; + showUI = true; + menuItemSelectTime = std::chrono::high_resolution_clock::now(); + isPaused = true; + } + // always exit pause if key is tapped or no longer in game somehow if (isPauseKeyTapped() || *(GameState*)CURRENT_GAME_STATE_ADDRESS != GS_GAME || *(SubGameState*)CURRENT_GAME_SUB_STATE_ADDRESS != SUB_GAME_MAIN) { - setPaused(false); + pause = false; } else { @@ -84,15 +116,39 @@ namespace TLAC::Components menuItemSelectTime = std::chrono::high_resolution_clock::now(); } - menuPos %= menuItems.size(); + if (inputState->Tapped.Buttons & JVS_TRIANGLE) + { + if (menuSet != menuset_main) + { + menuSet = menuset_main; + menuPos = mainMenuPos; + menuItemSelectTime = std::chrono::high_resolution_clock::now(); + } + } + + menuPos %= menuItems[menuSet].size(); + + if (menuSet == menuset_main) + mainMenuPos = menuPos; // use released when unpausing from X so it doesn't trigger input if (inputState->Released.Buttons & JVS_CROSS) - setPaused(false); + pause = false; // use released because this can trigger an unpause too if (inputState->Released.Buttons & JVS_CIRCLE) - menuItems[menuPos].second(); + menuItems[menuSet][menuPos].second(); + + if (menuSet == menuset_sevol) + { + PlayerData* playerdata = (PlayerData*)PLAYER_DATA_ADDRESS; + const char volformat[] = "%d"; + size_t size = snprintf(nullptr, 0, volformat, playerdata->act_vol) + 1; + char* buf = new char[size]; + snprintf(buf, size, volformat, playerdata->act_vol); + menuItems[menuset_sevol][1].first = buf; + delete[] buf; + } } @@ -107,12 +163,33 @@ namespace TLAC::Components } else { + // exit pause mode on state transition + if (isPaused) + { + ((void(*)())DSC_UNPAUSE_FUNC_ADDRESS)(); + + InjectCode(aetMovPatchAddress, origAetMovOp); + InjectCode(framespeedPatchAddress, origFramespeedOp); + + uint64_t audioMixerAddr = *(uint64_t*)(AUDIO_MAIN_CLASS_ADDRESS + 0x70); + uint64_t audioStreamsAddress = *(uint64_t*)(audioMixerAddr + 0x18);; + int nAudioStreams = *(uint64_t*)(audioMixerAddr + 0x20); + for (int i = 0; i < nAudioStreams; i++) + { + uint32_t* playstate = (uint32_t*)(audioStreamsAddress + i * 0x50 + 0x18); + if (i < streamPlayStates.size()) + *playstate = streamPlayStates[i]; + } + + isPaused = false; + } + // only enter pause if in game if (*(GameState*)CURRENT_GAME_STATE_ADDRESS == GS_GAME && *(SubGameState*)CURRENT_GAME_SUB_STATE_ADDRESS == SUB_GAME_MAIN) { if (isPauseKeyTapped()) { - setPaused(true); + pause = true; } } } @@ -159,7 +236,7 @@ namespace TLAC::Components // selection cursor - int selectBoxOrigin = menuY - menuItemHeight * (menuItems.size() / 2.0) - (menuItemHeight - menuTextSize) / 2; + int selectBoxOrigin = menuY - menuItemHeight * (menuItems[menuSet].size() / 2.0) - (menuItemHeight - menuTextSize) / 2; int selectBoxPos = selectBoxOrigin + menuItemHeight * menuPos; const float selectBoxWidth = 200; const float selectBoxHeight = menuItemHeight; @@ -189,11 +266,11 @@ namespace TLAC::Components fontInfo.setSize(menuTextSize, menuTextSize); dtParams.xBegin = menuX; - dtParams.yBegin = menuY - menuItemHeight * (menuItems.size() / 2.0); + dtParams.yBegin = menuY - menuItemHeight * (menuItems[menuSet].size() / 2.0); - for (int i = 0; i < menuItems.size(); i++) + for (int i = 0; i < menuItems[menuSet].size(); i++) { - std::pair &item = menuItems[i]; + std::pair &item = menuItems[menuSet][i]; if (i == menuPos) { @@ -223,18 +300,25 @@ namespace TLAC::Components dtParams.yCurrent = dtParams.yBegin; dtParams.colour = 0xffffffff; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"L/R:Move "); - dtParams.colour = 0xff4040ff; - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"○"); - dtParams.colour = 0xffffffff; - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Select "); - dtParams.colour = 0xffff8000; - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"×"); - dtParams.colour = 0xffffffff; - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Close "); + if (menuSet != menuset_main) + { + dtParams.colour = 0xff40ff40; + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"△"); + dtParams.colour = 0xffffffff; + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Back "); + } dtParams.colour = 0xffc0c0ff; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"□"); dtParams.colour = 0xffffffff; - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Hide Menu"); + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Hide Menu "); + dtParams.colour = 0xffff8020; + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"×"); + dtParams.colour = 0xffffffff; + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Close "); + dtParams.colour = 0xff4040ff; + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"○"); + dtParams.colour = 0xffffffff; + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Select"); } } @@ -243,71 +327,34 @@ namespace TLAC::Components return ((InputState*)(*(uint64_t*)INPUT_STATE_PTR_ADDRESS))->Tapped.Buttons & JVS_START; } - void Pause::setPaused(bool pause) - { - uint64_t audioMixerAddr = *(uint64_t*)(AUDIO_MAIN_CLASS_ADDRESS + 0x70); - uint64_t audioStreamsAddress = *(uint64_t*)(audioMixerAddr + 0x18);; - int nAudioStreams = *(uint64_t*)(audioMixerAddr + 0x20); - - if (pause) - { - ((void(*)())DSC_PAUSE_FUNC_ADDRESS)(); - - InjectCode(aetMovPatchAddress, { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 }); - InjectCode(framespeedPatchAddress, { 0x0f, 0x57, 0xc0, 0xc3 }); // XORPS XMM0,XMM0; RET - - for (int i = 0; i < nAudioStreams; i++) - { - uint32_t* playstate = (uint32_t*)(audioStreamsAddress + i * 0x50 + 0x18); - if (i < streamPlayStates.size()) - streamPlayStates[i] = *playstate; - else - streamPlayStates.push_back(*playstate); - - *playstate = 0; - } - - menuPos = 0; - showUI = true; - menuItemSelectTime = std::chrono::high_resolution_clock::now(); - } - else - { - ((void(*)())DSC_UNPAUSE_FUNC_ADDRESS)(); - - InjectCode(aetMovPatchAddress, origAetMovOp); - InjectCode(framespeedPatchAddress, origFramespeedOp); - - for (int i = 0; i < nAudioStreams; i++) - { - uint32_t* playstate = (uint32_t*)(audioStreamsAddress + i * 0x50 + 0x18); - if (i < streamPlayStates.size()) - *playstate = streamPlayStates[i]; - } - } - - isPaused = pause; - } - bool Pause::hookedGiveUpFunc(void* cls) { if (giveUp) { giveUp = false; - setPaused(false); + pause = false; return true; } else { if (divaGiveUpFunc(cls)) { - setPaused(false); + pause = false; return true; } } return false; } + void Pause::setSEVolume(int amount) + { + PlayerData* playerdata = (PlayerData*)PLAYER_DATA_ADDRESS; + playerdata->act_vol += amount; + if (playerdata->act_vol < 0) playerdata->act_vol = 0; + if (playerdata->act_vol > 100) playerdata->act_vol = 100; + playerdata->act_slide_vol = playerdata->act_vol; + } + void Pause::InjectCode(void* address, const std::vector data) { const size_t byteCount = data.size() * sizeof(uint8_t); diff --git a/source-code/source/plugins/TLAC/Components/Pause.h b/source-code/source/plugins/TLAC/Components/Pause.h index e36aeff..1975e4f 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.h +++ b/source-code/source/plugins/TLAC/Components/Pause.h @@ -1,6 +1,7 @@ #pragma once #include "../Constants.h" #include "EmulatorComponent.h" +#include "PlayerData.h" #include #include @@ -19,15 +20,16 @@ namespace TLAC::Components virtual void UpdatePostInput() override; virtual void UpdateDrawSprites() override; - static bool isPaused; - static bool giveUp; - static void setPaused(bool pause); + static bool pause; // set pause to change pause state + static bool giveUp; // set give up to end current song private: // this is a mess of static so that menuItems can work static bool isPauseKeyTapped(); static std::vector streamPlayStates; static void InjectCode(void* address, const std::vector data); + static bool isPaused; // tracks internal state + static std::vector origAetMovOp; static constexpr uint8_t* aetMovPatchAddress = (uint8_t*)0x1401703b3; @@ -36,6 +38,8 @@ namespace TLAC::Components static bool hookedGiveUpFunc(void* cls); + static void setSEVolume(int amount); + static const int menuX = 640; static const int menuY = 360; static const int menuItemHeight = 36; @@ -43,15 +47,38 @@ namespace TLAC::Components static bool showUI; static unsigned int menuPos; + static unsigned int mainMenuPos; // syncs to menuPos when menuSet == menuset_main (used for restoring on back) + static unsigned int menuSet; static std::chrono::time_point menuItemSelectTime; - static void unpause() { setPaused(false); }; + enum menusets + { + menuset_main = 0, + menuset_sevol = 1, + }; + + static void mainmenu() { menuSet = menuset_main; menuPos = mainMenuPos; menuItemSelectTime = std::chrono::high_resolution_clock::now(); }; + static void unpause() { pause = false; }; static void giveup() { giveUp = true; }; - std::vector> menuItems = { - std::pair(std::string("RESUME"), &unpause), - std::pair(std::string("GIVE UP"), &giveup), + static void sevolmenu() { menuSet = menuset_sevol; menuPos = 1; menuItemSelectTime = std::chrono::high_resolution_clock::now(); }; + static void sevolplus() { setSEVolume(10); }; + static void sevolminus() { setSEVolume(-10); }; + + + // defined as an array now so submenus could be added + std::vector> menuItems[2] = { + { + std::pair(std::string("RESUME"), &unpause), + std::pair(std::string("SE VOLUME"), &sevolmenu), + std::pair(std::string("GIVE UP"), &giveup), + }, + { + std::pair(std::string("+"), &sevolplus), + std::pair(std::string("XX"), &mainmenu), + std::pair(std::string("-"), &sevolminus), + } }; }; } From 487c63a6321e4b99b4815374f6f19c069eb946be Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Mon, 21 Oct 2019 01:33:59 +1100 Subject: [PATCH 07/44] shaderpatch: fix crashing(?) --- source-code/source/plugins/ShaderPatch/src/dllmain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source-code/source/plugins/ShaderPatch/src/dllmain.cpp b/source-code/source/plugins/ShaderPatch/src/dllmain.cpp index e82d648..c5a37f8 100644 --- a/source-code/source/plugins/ShaderPatch/src/dllmain.cpp +++ b/source-code/source/plugins/ShaderPatch/src/dllmain.cpp @@ -213,7 +213,7 @@ void hookedLoadFromFarcThunk(FArchivedFile** ppFile) if (modifiedStr.length() > 0) { - free(file.data); + //free(file.data); file.data = _strdup(modifiedStr.c_str()); file.dataSize = modifiedStr.size(); printf("[ShaderPatch] Patched %s\n", file.fileName.GetCharBuf()); From f7076adcb840bd9117b117bf25aadb5ba0dd5100 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Mon, 21 Oct 2019 01:39:21 +1100 Subject: [PATCH 08/44] pause: add missing string include --- source-code/source/plugins/TLAC/Components/Pause.h | 1 + 1 file changed, 1 insertion(+) diff --git a/source-code/source/plugins/TLAC/Components/Pause.h b/source-code/source/plugins/TLAC/Components/Pause.h index 1975e4f..c99d1fa 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.h +++ b/source-code/source/plugins/TLAC/Components/Pause.h @@ -2,6 +2,7 @@ #include "../Constants.h" #include "EmulatorComponent.h" #include "PlayerData.h" +#include #include #include From 39d2f18c3f91c2f8f00ebabe98b3fa68b1eeef9f Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Mon, 21 Oct 2019 13:46:34 +1100 Subject: [PATCH 09/44] pause: cleanup, remove an unused hook --- .../TLAC/Components/ComponentsManager.cpp | 8 ---- .../TLAC/Components/ComponentsManager.h | 1 - .../TLAC/Components/EmulatorComponent.h | 1 - .../source/plugins/TLAC/Components/Pause.cpp | 48 +++++++++++-------- .../source/plugins/TLAC/Components/Pause.h | 14 ++++-- source-code/source/plugins/TLAC/dllmain.cpp | 17 ------- 6 files changed, 37 insertions(+), 52 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/ComponentsManager.cpp b/source-code/source/plugins/TLAC/Components/ComponentsManager.cpp index 22e099d..a74eb62 100644 --- a/source-code/source/plugins/TLAC/Components/ComponentsManager.cpp +++ b/source-code/source/plugins/TLAC/Components/ComponentsManager.cpp @@ -151,14 +151,6 @@ namespace TLAC::Components } } - void ComponentsManager::UpdatePostDraw() - { - for (auto& component : components) - { - component->UpdatePostDraw(); - } - } - void ComponentsManager::OnFocusGain() { for (auto& component : components) diff --git a/source-code/source/plugins/TLAC/Components/ComponentsManager.h b/source-code/source/plugins/TLAC/Components/ComponentsManager.h index cc1a397..e7269b3 100644 --- a/source-code/source/plugins/TLAC/Components/ComponentsManager.h +++ b/source-code/source/plugins/TLAC/Components/ComponentsManager.h @@ -29,7 +29,6 @@ namespace TLAC::Components void UpdateInput(); void UpdatePostInput(); void UpdateDrawSprites(); - void UpdatePostDraw(); void OnFocusGain(); void OnFocusLost(); void Dispose(); diff --git a/source-code/source/plugins/TLAC/Components/EmulatorComponent.h b/source-code/source/plugins/TLAC/Components/EmulatorComponent.h index 69f63e8..f46b98d 100644 --- a/source-code/source/plugins/TLAC/Components/EmulatorComponent.h +++ b/source-code/source/plugins/TLAC/Components/EmulatorComponent.h @@ -18,7 +18,6 @@ namespace TLAC::Components virtual void UpdateInput() {}; virtual void UpdatePostInput() {}; virtual void UpdateDrawSprites() {}; - virtual void UpdatePostDraw() {}; virtual void OnFocusGain() {}; virtual void OnFocusLost() {}; diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index 2fd9772..c4f18da 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -2,7 +2,6 @@ #include "../Constants.h" #include "GameState.h" #include "Drawing.h" -#include "Input/InputState.h" #include "GL/glut.h" #include "detours.h" #include @@ -17,12 +16,14 @@ namespace TLAC::Components bool Pause::showUI = true; unsigned int Pause::menuPos = 0; unsigned int Pause::mainMenuPos = 0; - unsigned int Pause::menuSet = menuset_main; + unsigned int Pause::menuSet = MENUSET_MAIN; std::chrono::time_point Pause::menuItemSelectTime; std::vector Pause::origAetMovOp; std::vector Pause::origFramespeedOp; std::vector Pause::streamPlayStates; bool(*divaGiveUpFunc)(void*) = (bool(*)(void* cls))GIVEUP_FUNC_ADDRESS; + InputState* Pause::inputState; + PlayerData* Pause::playerData; Pause::Pause() { @@ -37,13 +38,21 @@ namespace TLAC::Components return "pause"; } - void Pause::Initialize(ComponentsManager*) + void Pause::saveOldPatchOps() { origAetMovOp.resize(8); memcpy(&origAetMovOp[0], aetMovPatchAddress, 8); origFramespeedOp.resize(4); memcpy(&origFramespeedOp[0], framespeedPatchAddress, 4); + } + + void Pause::Initialize(ComponentsManager*) + { + inputState = (InputState*)(*(uint64_t*)INPUT_STATE_PTR_ADDRESS); + playerData = (PlayerData*)PLAYER_DATA_ADDRESS; + + saveOldPatchOps(); DetourTransactionBegin(); DetourUpdateThread(GetCurrentThread()); @@ -65,6 +74,7 @@ namespace TLAC::Components { ((void(*)())DSC_PAUSE_FUNC_ADDRESS)(); + saveOldPatchOps(); InjectCode(aetMovPatchAddress, { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 }); InjectCode(framespeedPatchAddress, { 0x0f, 0x57, 0xc0, 0xc3 }); // XORPS XMM0,XMM0; RET @@ -83,7 +93,7 @@ namespace TLAC::Components } menuPos = 0; - menuSet = menuset_main; + menuSet = MENUSET_MAIN; showUI = true; menuItemSelectTime = std::chrono::high_resolution_clock::now(); isPaused = true; @@ -96,8 +106,6 @@ namespace TLAC::Components } else { - InputState* inputState = (InputState*)(*(uint64_t*)INPUT_STATE_PTR_ADDRESS); - if (inputState->Tapped.Buttons & JVS_SQUARE) showUI = !showUI; @@ -118,9 +126,9 @@ namespace TLAC::Components if (inputState->Tapped.Buttons & JVS_TRIANGLE) { - if (menuSet != menuset_main) + if (menuSet != MENUSET_MAIN) { - menuSet = menuset_main; + menuSet = MENUSET_MAIN; menuPos = mainMenuPos; menuItemSelectTime = std::chrono::high_resolution_clock::now(); } @@ -128,7 +136,7 @@ namespace TLAC::Components menuPos %= menuItems[menuSet].size(); - if (menuSet == menuset_main) + if (menuSet == MENUSET_MAIN) mainMenuPos = menuPos; // use released when unpausing from X so it doesn't trigger input @@ -139,14 +147,13 @@ namespace TLAC::Components if (inputState->Released.Buttons & JVS_CIRCLE) menuItems[menuSet][menuPos].second(); - if (menuSet == menuset_sevol) + if (menuSet == MENUSET_SEVOL) { - PlayerData* playerdata = (PlayerData*)PLAYER_DATA_ADDRESS; const char volformat[] = "%d"; - size_t size = snprintf(nullptr, 0, volformat, playerdata->act_vol) + 1; + size_t size = snprintf(nullptr, 0, volformat, playerData->act_vol) + 1; char* buf = new char[size]; - snprintf(buf, size, volformat, playerdata->act_vol); - menuItems[menuset_sevol][1].first = buf; + snprintf(buf, size, volformat, playerData->act_vol); + menuItems[MENUSET_SEVOL][1].first = buf; delete[] buf; } } @@ -300,7 +307,7 @@ namespace TLAC::Components dtParams.yCurrent = dtParams.yBegin; dtParams.colour = 0xffffffff; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"L/R:Move "); - if (menuSet != menuset_main) + if (menuSet != MENUSET_MAIN) { dtParams.colour = 0xff40ff40; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"△"); @@ -324,7 +331,7 @@ namespace TLAC::Components bool Pause::isPauseKeyTapped() { - return ((InputState*)(*(uint64_t*)INPUT_STATE_PTR_ADDRESS))->Tapped.Buttons & JVS_START; + return inputState->Tapped.Buttons & JVS_START; } bool Pause::hookedGiveUpFunc(void* cls) @@ -348,11 +355,10 @@ namespace TLAC::Components void Pause::setSEVolume(int amount) { - PlayerData* playerdata = (PlayerData*)PLAYER_DATA_ADDRESS; - playerdata->act_vol += amount; - if (playerdata->act_vol < 0) playerdata->act_vol = 0; - if (playerdata->act_vol > 100) playerdata->act_vol = 100; - playerdata->act_slide_vol = playerdata->act_vol; + playerData->act_vol += amount; + if (playerData->act_vol < 0) playerData->act_vol = 0; + if (playerData->act_vol > 100) playerData->act_vol = 100; + playerData->act_slide_vol = playerData->act_vol; } void Pause::InjectCode(void* address, const std::vector data) diff --git a/source-code/source/plugins/TLAC/Components/Pause.h b/source-code/source/plugins/TLAC/Components/Pause.h index c99d1fa..b9ddc22 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.h +++ b/source-code/source/plugins/TLAC/Components/Pause.h @@ -2,6 +2,7 @@ #include "../Constants.h" #include "EmulatorComponent.h" #include "PlayerData.h" +#include "Input/InputState.h" #include #include #include @@ -31,6 +32,8 @@ namespace TLAC::Components static bool isPaused; // tracks internal state + static void saveOldPatchOps(); + static std::vector origAetMovOp; static constexpr uint8_t* aetMovPatchAddress = (uint8_t*)0x1401703b3; @@ -41,6 +44,9 @@ namespace TLAC::Components static void setSEVolume(int amount); + static PlayerData* playerData; + static InputState* inputState; + static const int menuX = 640; static const int menuY = 360; static const int menuItemHeight = 36; @@ -55,15 +61,15 @@ namespace TLAC::Components enum menusets { - menuset_main = 0, - menuset_sevol = 1, + MENUSET_MAIN = 0, + MENUSET_SEVOL = 1, }; - static void mainmenu() { menuSet = menuset_main; menuPos = mainMenuPos; menuItemSelectTime = std::chrono::high_resolution_clock::now(); }; + static void mainmenu() { menuSet = MENUSET_MAIN; menuPos = mainMenuPos; menuItemSelectTime = std::chrono::high_resolution_clock::now(); }; static void unpause() { pause = false; }; static void giveup() { giveUp = true; }; - static void sevolmenu() { menuSet = menuset_sevol; menuPos = 1; menuItemSelectTime = std::chrono::high_resolution_clock::now(); }; + static void sevolmenu() { menuSet = MENUSET_SEVOL; menuPos = 1; menuItemSelectTime = std::chrono::high_resolution_clock::now(); }; static void sevolplus() { setSEVolume(10); }; static void sevolminus() { setSEVolume(-10); }; diff --git a/source-code/source/plugins/TLAC/dllmain.cpp b/source-code/source/plugins/TLAC/dllmain.cpp index 6bdf252..36139f3 100644 --- a/source-code/source/plugins/TLAC/dllmain.cpp +++ b/source-code/source/plugins/TLAC/dllmain.cpp @@ -20,7 +20,6 @@ void(__cdecl* divaEngineUpdate)() = (void(__cdecl*)())0x14018CC40; void(__cdecl* divaEngineDrawSprites)(void* addr, int idk) = (void(__cdecl*)(void* addr, int idk))ENGINE_DRAW_SPRITES_ADDRESS; -void(__cdecl* divaEngineFinishDraw)() = (void(__cdecl*)())ENGINE_FINISH_DRAW_ADDRESS; LRESULT CALLBACK MessageWindowProcessCallback(HWND, UINT, WPARAM, LPARAM); DWORD WINAPI WindowMessageDispatcher(LPVOID); @@ -133,11 +132,6 @@ namespace TLAC ComponentsManager.UpdateDrawSprites(); } - void UpdatePostDraw() - { - ComponentsManager.UpdatePostDraw(); - } - void InitializeExtraSettings() { const LPCTSTR RESOLUTION_CONFIG_FILE_NAME = _T(".\\config.ini"); @@ -361,12 +355,6 @@ void hookedEngineDrawSprites(void* addr, int idk) TLAC::UpdateDrawSprites(); } -void hookedEngineFinishDraw() -{ - TLAC::UpdatePostDraw(); - divaEngineFinishDraw(); -} - BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { HWND consoleHandle = GetConsoleWindow(); @@ -393,11 +381,6 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReser DetourAttach(&(PVOID&)divaEngineDrawSprites, hookedEngineDrawSprites); DetourTransactionCommit(); - DetourTransactionBegin(); - DetourUpdateThread(GetCurrentThread()); - DetourAttach(&(PVOID&)divaEngineFinishDraw, hookedEngineFinishDraw); - DetourTransactionCommit(); - TLAC::InitializeExtraSettings(); TLAC::framework::Module = hModule; From 783f76865027b93efd4c8f8e2ae5a96b7ebf3ddf Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Mon, 21 Oct 2019 13:55:25 +1100 Subject: [PATCH 10/44] use proper syntax for accessing vector data --- source-code/source/plugins/TLAC/Components/Pause.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index c4f18da..7372301 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -41,10 +41,10 @@ namespace TLAC::Components void Pause::saveOldPatchOps() { origAetMovOp.resize(8); - memcpy(&origAetMovOp[0], aetMovPatchAddress, 8); + memcpy(origAetMovOp.data(), aetMovPatchAddress, 8); origFramespeedOp.resize(4); - memcpy(&origFramespeedOp[0], framespeedPatchAddress, 4); + memcpy(origFramespeedOp.data(), framespeedPatchAddress, 4); } void Pause::Initialize(ComponentsManager*) From af7140b9e5dcb02af6cc6957158c24bc1f74483b Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Mon, 21 Oct 2019 14:10:40 +1100 Subject: [PATCH 11/44] pause: ? --- source-code/source/plugins/TLAC/Components/Pause.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index 7372301..8388b53 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -18,8 +18,8 @@ namespace TLAC::Components unsigned int Pause::mainMenuPos = 0; unsigned int Pause::menuSet = MENUSET_MAIN; std::chrono::time_point Pause::menuItemSelectTime; - std::vector Pause::origAetMovOp; - std::vector Pause::origFramespeedOp; + std::vector Pause::origAetMovOp = {}; + std::vector Pause::origFramespeedOp = {}; std::vector Pause::streamPlayStates; bool(*divaGiveUpFunc)(void*) = (bool(*)(void* cls))GIVEUP_FUNC_ADDRESS; InputState* Pause::inputState; From b4ee82a6433af28a920268b1bc02bf73105f96ce Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Mon, 21 Oct 2019 14:26:14 +1100 Subject: [PATCH 12/44] pause: okay, I think this should fix appveyor builds --- source-code/source/plugins/TLAC/Components/Pause.cpp | 6 ++++-- source-code/source/plugins/TLAC/Components/Pause.h | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index 8388b53..1774daa 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -18,8 +18,10 @@ namespace TLAC::Components unsigned int Pause::mainMenuPos = 0; unsigned int Pause::menuSet = MENUSET_MAIN; std::chrono::time_point Pause::menuItemSelectTime; - std::vector Pause::origAetMovOp = {}; - std::vector Pause::origFramespeedOp = {}; + std::vector Pause::origAetMovOp; + uint8_t* Pause::aetMovPatchAddress = (uint8_t*)0x1401703b3; + std::vector Pause::origFramespeedOp; + uint8_t* Pause::framespeedPatchAddress = (uint8_t*)0x140192D50; std::vector Pause::streamPlayStates; bool(*divaGiveUpFunc)(void*) = (bool(*)(void* cls))GIVEUP_FUNC_ADDRESS; InputState* Pause::inputState; diff --git a/source-code/source/plugins/TLAC/Components/Pause.h b/source-code/source/plugins/TLAC/Components/Pause.h index b9ddc22..d138192 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.h +++ b/source-code/source/plugins/TLAC/Components/Pause.h @@ -35,10 +35,10 @@ namespace TLAC::Components static void saveOldPatchOps(); static std::vector origAetMovOp; - static constexpr uint8_t* aetMovPatchAddress = (uint8_t*)0x1401703b3; + static uint8_t* aetMovPatchAddress; static std::vector origFramespeedOp; - static constexpr uint8_t* framespeedPatchAddress = (uint8_t*)0x140192D50; + static uint8_t* framespeedPatchAddress; static bool hookedGiveUpFunc(void* cls); From 59c8d164ad9d0772bc24ade0d6efc1c6ed9dd85b Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Mon, 21 Oct 2019 17:24:35 +1100 Subject: [PATCH 13/44] tlac: add three parameter drawRectangle (implemented the same as sega uses) --- .../source/plugins/TLAC/Components/Drawing.h | 29 ++++++++++++++++++- .../source/plugins/TLAC/Components/Pause.cpp | 19 +++--------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Drawing.h b/source-code/source/plugins/TLAC/Components/Drawing.h index 773f5f4..db93d0b 100644 --- a/source-code/source/plugins/TLAC/Components/Drawing.h +++ b/source-code/source/plugins/TLAC/Components/Drawing.h @@ -211,6 +211,33 @@ namespace TLAC::Components float height; }; void(*fillRectangle)(DrawParams* dtParam, RectangleBounds* rect) = (void(*)(DrawParams* dtParam, RectangleBounds* rect))0x140198d80; - void(*drawRectangle)(DrawParams* dtParam, RectangleBounds* rect) = (void(*)(DrawParams* dtParam, RectangleBounds* rect))0x140198320; + + // draws only a border -- use fillRectangle to fill contained pixels + void drawRectangle(DrawParams* dtParam, RectangleBounds* rect) + { + ((void(*)(DrawParams*, RectangleBounds*))0x140198320)(dtParam, rect); + } + + // draws only a border -- use fillRectangle to fill contained pixels + void drawRectangle(DrawParams* dtParam, RectangleBounds* rect, float thickness) + { + uint32_t oldFillColour = dtParam->fillColour; + dtParam->fillColour = dtParam->colour; + + // yes this seems pretty dodgy, but sega does it this way so... I guess it's the only way + RectangleBounds tempRect = { rect->x, rect->y, thickness, rect->height }; // left side + fillRectangle(dtParam, &tempRect); + + tempRect.x = rect->x + rect->width - thickness; // right side + fillRectangle(dtParam, &tempRect); + + tempRect = { rect->x + thickness, rect->y, rect->width - (thickness * 2), thickness }; // top side + fillRectangle(dtParam, &tempRect); + + tempRect.y = rect->y + rect->height - thickness; // left side + fillRectangle(dtParam, &tempRect); + + dtParam->fillColour = oldFillColour; + } #pragma pack(pop) } \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index 1774daa..cfe0d20 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -251,24 +251,13 @@ namespace TLAC::Components const float selectBoxHeight = menuItemHeight; const float selectBoxThickness = 2; - const float selectBoxX1 = menuX - selectBoxWidth / 2; - const float selectBoxX2 = selectBoxX1 + selectBoxWidth - selectBoxThickness; - const float selectBoxY1 = selectBoxPos; - const float selectBoxY2 = selectBoxY1 + selectBoxThickness; - const float selectBoxY3 = selectBoxY1 + selectBoxHeight - selectBoxThickness; - const float selectBoxSideHeight = selectBoxHeight - 2 * selectBoxThickness; + const float selectBoxX = menuX - selectBoxWidth / 2; + const float selectBoxY = selectBoxPos; - // dirty hack using fillRectangle to get thickness (idk how to set it or it isn't possible to with drawRectangle) + rect = { selectBoxX, selectBoxY, selectBoxWidth, selectBoxHeight }; dtParams.colour = 0xc0ffff00; dtParams.fillColour = 0xc0ffff00; - rect = { selectBoxX1, selectBoxY1, selectBoxWidth, selectBoxThickness }; // top - fillRectangle(&dtParams, &rect); - rect = { selectBoxX1, selectBoxY3, selectBoxWidth, selectBoxThickness }; // bottom - fillRectangle(&dtParams, &rect); - rect = { selectBoxX1, selectBoxY2, selectBoxThickness, selectBoxSideHeight }; - fillRectangle(&dtParams, &rect); - rect = { selectBoxX2, selectBoxY2, selectBoxThickness, selectBoxSideHeight }; - fillRectangle(&dtParams, &rect); + drawRectangle(&dtParams, &rect, selectBoxThickness); // menu From b01738258000e7dca46158a02726c867267cc639 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Mon, 21 Oct 2019 18:50:57 +1100 Subject: [PATCH 14/44] tlac: aet drawing funcs --- .../source/plugins/TLAC/Components/Drawing.h | 31 +++++++++++++++++++ .../source/plugins/TLAC/Components/Pause.cpp | 22 +++++++++++++ .../source/plugins/TLAC/Components/Pause.h | 7 +++++ 3 files changed, 60 insertions(+) diff --git a/source-code/source/plugins/TLAC/Components/Drawing.h b/source-code/source/plugins/TLAC/Components/Drawing.h index db93d0b..3bb8301 100644 --- a/source-code/source/plugins/TLAC/Components/Drawing.h +++ b/source-code/source/plugins/TLAC/Components/Drawing.h @@ -239,5 +239,36 @@ namespace TLAC::Components dtParam->fillColour = oldFillColour; } + + struct Point + { + float x; + float y; + }; + + enum createAetFlags : uint32_t + { + CREATEAET_20000 = 0x20000, + }; + + // draw an aet layer (with animation settings) + int createAetLayer(uint32_t drawLayer, createAetFlags flags, char* name, Point* loc, float animationVar1, float animationVar2) + { + return ((int(*)(uint32_t, createAetFlags, char*, Point*, float, float))0x14013c020)(drawLayer, flags, name, loc, animationVar1, animationVar2); + } + // draw an aet layer (with default animation) + int createAetLayer(uint32_t drawLayer, createAetFlags flags, char* name, Point* loc) + { + return createAetLayer(drawLayer, flags, name, loc, -1, -1); + } + + void destroyAetLayer(int &layer) + { + if (layer != 0) + { + ((void(*)(int layer))0x14019d570)(layer); + layer = 0; + } + } #pragma pack(pop) } \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index cfe0d20..f69d292 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -190,6 +190,13 @@ namespace TLAC::Components *playstate = streamPlayStates[i]; } + /* + destroyAetLayer(triangleAet); + destroyAetLayer(squareAet); + destroyAetLayer(crossAet); + destroyAetLayer(circleAet); + */ + isPaused = false; } @@ -317,6 +324,21 @@ namespace TLAC::Components drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"○"); dtParams.colour = 0xffffffff; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Select"); + + /* + destroyAetLayer(triangleAet); + destroyAetLayer(squareAet); + destroyAetLayer(crossAet); + destroyAetLayer(circleAet); + Point spriteLoc = { 64, 64 }; + triangleAet = createAetLayer(0x19, CREATEAET_20000, "button_sankaku", &spriteLoc, 0, 1); + spriteLoc.x += 64; + squareAet = createAetLayer(0x19, CREATEAET_20000, "button_shikaku", &spriteLoc, 0, 1); + spriteLoc.x += 64; + crossAet = createAetLayer(0x19, CREATEAET_20000, "button_batsu", &spriteLoc, 0, 1); + spriteLoc.x += 64; + circleAet = createAetLayer(0x19, CREATEAET_20000, "button_maru", &spriteLoc, 0, 1); + */ } } diff --git a/source-code/source/plugins/TLAC/Components/Pause.h b/source-code/source/plugins/TLAC/Components/Pause.h index d138192..eb7caaf 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.h +++ b/source-code/source/plugins/TLAC/Components/Pause.h @@ -57,6 +57,13 @@ namespace TLAC::Components static unsigned int mainMenuPos; // syncs to menuPos when menuSet == menuset_main (used for restoring on back) static unsigned int menuSet; + /* + int triangleAet; + int squareAet; + int crossAet; + int circleAet; + */ + static std::chrono::time_point menuItemSelectTime; enum menusets From 7c308c1f2448aab9a1b489504ab9c8ba43011126 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Mon, 21 Oct 2019 21:10:39 +1100 Subject: [PATCH 15/44] tlac: (drawing:) use Point struct in more places and add more/better aet funcs, (pause:) use button aets in key legend --- .../source/plugins/TLAC/Components/Drawing.h | 44 ++++++---- .../source/plugins/TLAC/Components/Pause.cpp | 86 +++++++++---------- .../source/plugins/TLAC/Components/Pause.h | 5 +- 3 files changed, 68 insertions(+), 67 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Drawing.h b/source-code/source/plugins/TLAC/Components/Drawing.h index 3bb8301..26fb88e 100644 --- a/source-code/source/plugins/TLAC/Components/Drawing.h +++ b/source-code/source/plugins/TLAC/Components/Drawing.h @@ -5,6 +5,12 @@ namespace TLAC::Components { #pragma pack(push, 1) + struct Point + { + float x; + float y; + }; + struct RawFont { uint32_t sprId; // ? @@ -81,10 +87,8 @@ namespace TLAC::Components uint32_t unk20; uint32_t unk24; uint32_t unk28; - float xBegin; // ? - float yBegin; // ? - float xCurrent; // ? - float yCurrent; // ? + Point originLoc; + Point currentLoc; uint8_t padding3c[0x4]; uint64_t unk40; FontInfo* font; @@ -103,10 +107,8 @@ namespace TLAC::Components unk20 = 0x0; unk24 = 0xd; unk28 = 0; - xBegin = 0; - yBegin = 0; - xCurrent = 0; - yCurrent = 0; + originLoc = { 0, 0 }; + currentLoc = { 0, 0 }; unk40 = 0; font = fi; unk50 = 0x25a1; @@ -240,26 +242,30 @@ namespace TLAC::Components dtParam->fillColour = oldFillColour; } - struct Point - { - float x; - float y; - }; - enum createAetFlags : uint32_t { CREATEAET_20000 = 0x20000, }; - // draw an aet layer (with animation settings) - int createAetLayer(uint32_t drawLayer, createAetFlags flags, char* name, Point* loc, float animationVar1, float animationVar2) + // draw an aet layer (with all settings) + int createAetLayer(int32_t unk1, uint32_t drawLayer, createAetFlags flags, char* name, Point* loc, int32_t unk2, char* animation, char* animation2, float animationInTime, float animationOutTime, Point* scale, int32_t unk5) { - return ((int(*)(uint32_t, createAetFlags, char*, Point*, float, float))0x14013c020)(drawLayer, flags, name, loc, animationVar1, animationVar2); + return ((int(*)(int32_t, uint32_t, createAetFlags, char*, Point*, int32_t, char*, char*, float, float, Point*, int32_t))0x14013be60)(unk1, drawLayer, flags, name, loc, unk2, animation, animation2, animationInTime, animationOutTime, scale, unk5); } - // draw an aet layer (with default animation) + // draw an aet layer (with animation timing override) + int createAetLayer(uint32_t drawLayer, createAetFlags flags, char* name, Point* loc, float animationInTime, float animationOutTime) + { + return createAetLayer(3, drawLayer, flags, name, loc, 0, 0, 0, animationInTime, animationOutTime, 0, 0); + } + // draw an aet layer (with scale) + int createAetLayer(uint32_t drawLayer, createAetFlags flags, char* name, Point* loc, Point* scale) + { + return createAetLayer(3, drawLayer, flags, name, loc, 0, 0, 0, -1, -1, scale, 0); + } + // draw an aet layer int createAetLayer(uint32_t drawLayer, createAetFlags flags, char* name, Point* loc) { - return createAetLayer(drawLayer, flags, name, loc, -1, -1); + return createAetLayer(3, drawLayer, flags, name, loc, 0, 0, 0, -1, -1, 0, 0); } void destroyAetLayer(int &layer) diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index f69d292..52add3b 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -190,12 +190,10 @@ namespace TLAC::Components *playstate = streamPlayStates[i]; } - /* destroyAetLayer(triangleAet); destroyAetLayer(squareAet); destroyAetLayer(crossAet); destroyAetLayer(circleAet); - */ isPaused = false; } @@ -218,7 +216,7 @@ namespace TLAC::Components // setup draw objects FontInfo fontInfo(0x11); DrawParams dtParams(&fontInfo); - dtParams.layer = 0x19; // same as startup screen + dtParams.layer = bgLayer; // bg rect @@ -251,6 +249,8 @@ namespace TLAC::Components */ + dtParams.layer = contentLayer; + // selection cursor int selectBoxOrigin = menuY - menuItemHeight * (menuItems[menuSet].size() / 2.0) - (menuItemHeight - menuTextSize) / 2; int selectBoxPos = selectBoxOrigin + menuItemHeight * menuPos; @@ -270,8 +270,7 @@ namespace TLAC::Components // menu fontInfo.setSize(menuTextSize, menuTextSize); - dtParams.xBegin = menuX; - dtParams.yBegin = menuY - menuItemHeight * (menuItems[menuSet].size() / 2.0); + dtParams.originLoc = { menuX, menuY - menuItemHeight * (menuItems[menuSet].size() / 2.0f) }; for (int i = 0; i < menuItems[menuSet].size(); i++) { @@ -289,56 +288,51 @@ namespace TLAC::Components dtParams.colour = 0xffffffff; } - dtParams.xCurrent = dtParams.xBegin; - dtParams.yCurrent = dtParams.yBegin; + dtParams.currentLoc = dtParams.originLoc; drawText(&dtParams, (drawTextFlags)(DRAWTEXT_ALIGN_CENTRE), item.first); - dtParams.yBegin += menuItemHeight; + dtParams.originLoc.y += menuItemHeight; } // key legend - fontInfo.setSize(18, 18); - - dtParams.xBegin = 32; - dtParams.yBegin = 720 - 40; - dtParams.xCurrent = dtParams.xBegin; - dtParams.yCurrent = dtParams.yBegin; - dtParams.colour = 0xffffffff; - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"L/R:Move "); - if (menuSet != MENUSET_MAIN) - { - dtParams.colour = 0xff40ff40; - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"△"); - dtParams.colour = 0xffffffff; - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Back "); - } - dtParams.colour = 0xffc0c0ff; - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"□"); - dtParams.colour = 0xffffffff; - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Hide Menu "); - dtParams.colour = 0xffff8020; - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"×"); - dtParams.colour = 0xffffffff; - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Close "); - dtParams.colour = 0xff4040ff; - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"○"); - dtParams.colour = 0xffffffff; - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Select"); - - /* destroyAetLayer(triangleAet); destroyAetLayer(squareAet); destroyAetLayer(crossAet); destroyAetLayer(circleAet); - Point spriteLoc = { 64, 64 }; - triangleAet = createAetLayer(0x19, CREATEAET_20000, "button_sankaku", &spriteLoc, 0, 1); - spriteLoc.x += 64; - squareAet = createAetLayer(0x19, CREATEAET_20000, "button_shikaku", &spriteLoc, 0, 1); - spriteLoc.x += 64; - crossAet = createAetLayer(0x19, CREATEAET_20000, "button_batsu", &spriteLoc, 0, 1); - spriteLoc.x += 64; - circleAet = createAetLayer(0x19, CREATEAET_20000, "button_maru", &spriteLoc, 0, 1); - */ + + fontInfo.setSize(18, 18); + dtParams.originLoc = { 32, 720 - 40 }; + dtParams.currentLoc = dtParams.originLoc; + const float spriteSize = 18; + const float halfSpriteSize = spriteSize / 2; + Point spriteLoc = { 0, dtParams.originLoc.y + halfSpriteSize }; + Point spriteScale = { spriteSize / 64, spriteSize / 64 }; // just approximated + + dtParams.colour = 0xffffffff; + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"L/R:Move "); + + if (menuSet != MENUSET_MAIN) + { + spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; + triangleAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_sankaku", &spriteLoc, 0, 0, 0, 0, 0, &spriteScale, 0); + dtParams.originLoc.x += spriteSize; + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Back "); + } + + spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; + squareAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_shikaku", &spriteLoc, 0, 0, 0, 0, 0, &spriteScale, 0); + dtParams.originLoc.x += spriteSize; + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Hide Menu "); + + spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; + crossAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_batsu", &spriteLoc, 0, 0, 0, 0, 0, &spriteScale, 0); + dtParams.originLoc.x += spriteSize; + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Close "); + + spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; + circleAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_maru", &spriteLoc, 0, 0, 0, 0, 0, &spriteScale, 0); + dtParams.originLoc.x += spriteSize; + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Select"); } } diff --git a/source-code/source/plugins/TLAC/Components/Pause.h b/source-code/source/plugins/TLAC/Components/Pause.h index eb7caaf..084be36 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.h +++ b/source-code/source/plugins/TLAC/Components/Pause.h @@ -51,18 +51,19 @@ namespace TLAC::Components static const int menuY = 360; static const int menuItemHeight = 36; static const int menuTextSize = 24; + + static const uint32_t bgLayer = 0x18; + static const uint32_t contentLayer = 0x19; // same as startup screen static bool showUI; static unsigned int menuPos; static unsigned int mainMenuPos; // syncs to menuPos when menuSet == menuset_main (used for restoring on back) static unsigned int menuSet; - /* int triangleAet; int squareAet; int crossAet; int circleAet; - */ static std::chrono::time_point menuItemSelectTime; From 6899c278f4e2402fd0f976826045918805432269 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Mon, 21 Oct 2019 21:39:57 +1100 Subject: [PATCH 16/44] pause: use nullptr instead of 0 in createAetLayer args --- source-code/source/plugins/TLAC/Components/Pause.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index 52add3b..1383b6b 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -314,23 +314,23 @@ namespace TLAC::Components if (menuSet != MENUSET_MAIN) { spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; - triangleAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_sankaku", &spriteLoc, 0, 0, 0, 0, 0, &spriteScale, 0); + triangleAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_sankaku", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, 0); dtParams.originLoc.x += spriteSize; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Back "); } spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; - squareAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_shikaku", &spriteLoc, 0, 0, 0, 0, 0, &spriteScale, 0); + squareAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_shikaku", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, 0); dtParams.originLoc.x += spriteSize; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Hide Menu "); spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; - crossAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_batsu", &spriteLoc, 0, 0, 0, 0, 0, &spriteScale, 0); + crossAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_batsu", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, 0); dtParams.originLoc.x += spriteSize; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Close "); spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; - circleAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_maru", &spriteLoc, 0, 0, 0, 0, 0, &spriteScale, 0); + circleAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_maru", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, 0); dtParams.originLoc.x += spriteSize; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Select"); } From c7d1982dbe051652707ac8cbadb21e2cddfe38a4 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Mon, 21 Oct 2019 21:48:46 +1100 Subject: [PATCH 17/44] pause: floats in createAetLayer calls? --- source-code/source/plugins/TLAC/Components/Pause.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index 1383b6b..59bb432 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -314,23 +314,23 @@ namespace TLAC::Components if (menuSet != MENUSET_MAIN) { spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; - triangleAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_sankaku", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, 0); + triangleAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_sankaku", &spriteLoc, 0, nullptr, nullptr, 0.0f, 0.0f, &spriteScale, 0); dtParams.originLoc.x += spriteSize; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Back "); } spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; - squareAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_shikaku", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, 0); + squareAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_shikaku", &spriteLoc, 0, nullptr, nullptr, 0.0f, 0.0f, &spriteScale, 0); dtParams.originLoc.x += spriteSize; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Hide Menu "); spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; - crossAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_batsu", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, 0); + crossAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_batsu", &spriteLoc, 0, nullptr, nullptr, 0.0f, 0.0f, &spriteScale, 0); dtParams.originLoc.x += spriteSize; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Close "); spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; - circleAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_maru", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, 0); + circleAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_maru", &spriteLoc, 0, nullptr, nullptr, 0.0f, 0.0f, &spriteScale, 0); dtParams.originLoc.x += spriteSize; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Select"); } From a90ae09e114c7e637cc704c737fe6747f0b5cfbd Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Mon, 21 Oct 2019 21:53:26 +1100 Subject: [PATCH 18/44] tlac drawing: lots of const on pointers --- .../source/plugins/TLAC/Components/Drawing.h | 18 +++++++++--------- .../source/plugins/TLAC/Components/Pause.cpp | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Drawing.h b/source-code/source/plugins/TLAC/Components/Drawing.h index 26fb88e..342800c 100644 --- a/source-code/source/plugins/TLAC/Components/Drawing.h +++ b/source-code/source/plugins/TLAC/Components/Drawing.h @@ -212,16 +212,16 @@ namespace TLAC::Components float width; float height; }; - void(*fillRectangle)(DrawParams* dtParam, RectangleBounds* rect) = (void(*)(DrawParams* dtParam, RectangleBounds* rect))0x140198d80; + void(*fillRectangle)(DrawParams* dtParam, const RectangleBounds* rect) = (void(*)(DrawParams* dtParam, const RectangleBounds* rect))0x140198d80; // draws only a border -- use fillRectangle to fill contained pixels - void drawRectangle(DrawParams* dtParam, RectangleBounds* rect) + void drawRectangle(DrawParams* dtParam, const RectangleBounds* rect) { - ((void(*)(DrawParams*, RectangleBounds*))0x140198320)(dtParam, rect); + ((void(*)(DrawParams*, const RectangleBounds*))0x140198320)(dtParam, rect); } // draws only a border -- use fillRectangle to fill contained pixels - void drawRectangle(DrawParams* dtParam, RectangleBounds* rect, float thickness) + void drawRectangle(DrawParams* dtParam, const RectangleBounds* rect, float thickness) { uint32_t oldFillColour = dtParam->fillColour; dtParam->fillColour = dtParam->colour; @@ -248,22 +248,22 @@ namespace TLAC::Components }; // draw an aet layer (with all settings) - int createAetLayer(int32_t unk1, uint32_t drawLayer, createAetFlags flags, char* name, Point* loc, int32_t unk2, char* animation, char* animation2, float animationInTime, float animationOutTime, Point* scale, int32_t unk5) + 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, int32_t unk5) { - return ((int(*)(int32_t, uint32_t, createAetFlags, char*, Point*, int32_t, char*, char*, float, float, Point*, int32_t))0x14013be60)(unk1, drawLayer, flags, name, loc, unk2, animation, animation2, animationInTime, animationOutTime, scale, unk5); + return ((int(*)(int32_t, uint32_t, createAetFlags, const char*, const Point*, int32_t, const char*, const char*, float, float, const Point*, int32_t))0x14013be60)(unk1, drawLayer, flags, name, loc, unk2, animation, animation2, animationInTime, animationOutTime, scale, unk5); } // draw an aet layer (with animation timing override) - int createAetLayer(uint32_t drawLayer, createAetFlags flags, char* name, Point* loc, float animationInTime, float animationOutTime) + int createAetLayer(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); } // draw an aet layer (with scale) - int createAetLayer(uint32_t drawLayer, createAetFlags flags, char* name, Point* loc, Point* scale) + int createAetLayer(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); } // draw an aet layer - int createAetLayer(uint32_t drawLayer, createAetFlags flags, char* name, Point* loc) + int createAetLayer(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); } diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index 59bb432..1383b6b 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -314,23 +314,23 @@ namespace TLAC::Components if (menuSet != MENUSET_MAIN) { spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; - triangleAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_sankaku", &spriteLoc, 0, nullptr, nullptr, 0.0f, 0.0f, &spriteScale, 0); + triangleAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_sankaku", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, 0); dtParams.originLoc.x += spriteSize; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Back "); } spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; - squareAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_shikaku", &spriteLoc, 0, nullptr, nullptr, 0.0f, 0.0f, &spriteScale, 0); + squareAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_shikaku", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, 0); dtParams.originLoc.x += spriteSize; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Hide Menu "); spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; - crossAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_batsu", &spriteLoc, 0, nullptr, nullptr, 0.0f, 0.0f, &spriteScale, 0); + crossAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_batsu", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, 0); dtParams.originLoc.x += spriteSize; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Close "); spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; - circleAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_maru", &spriteLoc, 0, nullptr, nullptr, 0.0f, 0.0f, &spriteScale, 0); + circleAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_maru", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, 0); dtParams.originLoc.x += spriteSize; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Select"); } From 84352bbbfa7bf10fdbe087260a16dbd6f6f1751c Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Tue, 22 Oct 2019 00:56:45 +1100 Subject: [PATCH 19/44] tlac: rename DrawSprites stuff to Draw2D, use a better hook for it --- .../plugins/TLAC/Components/ComponentsManager.cpp | 4 ++-- .../plugins/TLAC/Components/ComponentsManager.h | 2 +- .../plugins/TLAC/Components/EmulatorComponent.h | 2 +- .../source/plugins/TLAC/Components/Pause.cpp | 2 +- .../source/plugins/TLAC/Components/Pause.h | 2 +- source-code/source/plugins/TLAC/Constants.h | 2 +- source-code/source/plugins/TLAC/dllmain.cpp | 15 +++++++-------- 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/ComponentsManager.cpp b/source-code/source/plugins/TLAC/Components/ComponentsManager.cpp index a74eb62..c505d9c 100644 --- a/source-code/source/plugins/TLAC/Components/ComponentsManager.cpp +++ b/source-code/source/plugins/TLAC/Components/ComponentsManager.cpp @@ -143,11 +143,11 @@ namespace TLAC::Components } } - void ComponentsManager::UpdateDrawSprites() + void ComponentsManager::UpdateDraw2D() { for (auto& component : components) { - component->UpdateDrawSprites(); + component->UpdateDraw2D(); } } diff --git a/source-code/source/plugins/TLAC/Components/ComponentsManager.h b/source-code/source/plugins/TLAC/Components/ComponentsManager.h index e7269b3..ce58b37 100644 --- a/source-code/source/plugins/TLAC/Components/ComponentsManager.h +++ b/source-code/source/plugins/TLAC/Components/ComponentsManager.h @@ -28,7 +28,7 @@ namespace TLAC::Components void Update(); void UpdateInput(); void UpdatePostInput(); - void UpdateDrawSprites(); + void UpdateDraw2D(); void OnFocusGain(); void OnFocusLost(); void Dispose(); diff --git a/source-code/source/plugins/TLAC/Components/EmulatorComponent.h b/source-code/source/plugins/TLAC/Components/EmulatorComponent.h index f46b98d..c486283 100644 --- a/source-code/source/plugins/TLAC/Components/EmulatorComponent.h +++ b/source-code/source/plugins/TLAC/Components/EmulatorComponent.h @@ -17,7 +17,7 @@ namespace TLAC::Components virtual void UpdateInput() {}; virtual void UpdatePostInput() {}; - virtual void UpdateDrawSprites() {}; + virtual void UpdateDraw2D() {}; virtual void OnFocusGain() {}; virtual void OnFocusLost() {}; diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index 1383b6b..52337c6 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -209,7 +209,7 @@ namespace TLAC::Components } } - void Pause::UpdateDrawSprites() + void Pause::UpdateDraw2D() { if (isPaused && showUI) { diff --git a/source-code/source/plugins/TLAC/Components/Pause.h b/source-code/source/plugins/TLAC/Components/Pause.h index 084be36..76f5219 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.h +++ b/source-code/source/plugins/TLAC/Components/Pause.h @@ -20,7 +20,7 @@ namespace TLAC::Components virtual void Initialize(ComponentsManager*) override; virtual void Update() override; virtual void UpdatePostInput() override; - virtual void UpdateDrawSprites() override; + virtual void UpdateDraw2D() override; static bool pause; // set pause to change pause state static bool giveUp; // set give up to end current song diff --git a/source-code/source/plugins/TLAC/Constants.h b/source-code/source/plugins/TLAC/Constants.h index cfe2a8e..4cd551d 100644 --- a/source-code/source/plugins/TLAC/Constants.h +++ b/source-code/source/plugins/TLAC/Constants.h @@ -8,7 +8,7 @@ constexpr uint8_t JNE_OPCODE = 0x85; //constexpr uint64_t ENGINE_UPDATE_HOOK_TARGET_ADDRESS = 0x000000014018CC40; constexpr uint64_t ENGINE_UPDATE_INPUT_ADDRESS = 0x000000014018CBB0; -constexpr uint64_t ENGINE_DRAW_SPRITES_ADDRESS = 0x0000000140500EA0; +constexpr uint64_t ENGINE_DRAW_2D_ADDRESS = 0x0000000140501F70; constexpr uint64_t ENGINE_FINISH_DRAW_ADDRESS = 0x0000000140192730; constexpr uint64_t CURRENT_GAME_STATE_ADDRESS = 0x0000000140EDA810; diff --git a/source-code/source/plugins/TLAC/dllmain.cpp b/source-code/source/plugins/TLAC/dllmain.cpp index 36139f3..45979ea 100644 --- a/source-code/source/plugins/TLAC/dllmain.cpp +++ b/source-code/source/plugins/TLAC/dllmain.cpp @@ -19,7 +19,7 @@ #pragma comment(lib, "detours.lib") void(__cdecl* divaEngineUpdate)() = (void(__cdecl*)())0x14018CC40; -void(__cdecl* divaEngineDrawSprites)(void* addr, int idk) = (void(__cdecl*)(void* addr, int idk))ENGINE_DRAW_SPRITES_ADDRESS; +void(__cdecl* divaEngineDraw2D)(void* addr) = (void(__cdecl*)(void* addr))ENGINE_DRAW_2D_ADDRESS; LRESULT CALLBACK MessageWindowProcessCallback(HWND, UINT, WPARAM, LPARAM); DWORD WINAPI WindowMessageDispatcher(LPVOID); @@ -127,9 +127,9 @@ namespace TLAC ComponentsManager.OnFocusLost(); } - void UpdateDrawSprites() + void UpdateDraw2D() { - ComponentsManager.UpdateDrawSprites(); + ComponentsManager.UpdateDraw2D(); } void InitializeExtraSettings() @@ -348,11 +348,10 @@ void hookedEngineUpdate() //divaEngineUpdate(); } -void hookedEngineDrawSprites(void* addr, int idk) +void hookedEngineDraw2D(void* addr) { - divaEngineDrawSprites(addr, idk); - if (idk == 0x0a) - TLAC::UpdateDrawSprites(); + TLAC::UpdateDraw2D(); + divaEngineDraw2D(addr); } BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) @@ -378,7 +377,7 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReser DetourTransactionBegin(); DetourUpdateThread(GetCurrentThread()); - DetourAttach(&(PVOID&)divaEngineDrawSprites, hookedEngineDrawSprites); + DetourAttach(&(PVOID&)divaEngineDraw2D, hookedEngineDraw2D); DetourTransactionCommit(); TLAC::InitializeExtraSettings(); From 68c03689c034b8f1d8cc621294222de21b8655d4 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Tue, 22 Oct 2019 03:50:17 +1100 Subject: [PATCH 20/44] pause: don't click the restart button. I warned you. --- source-code/source/plugins/TLAC/Components/Pause.h | 2 ++ source-code/source/plugins/TLAC/Constants.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/source-code/source/plugins/TLAC/Components/Pause.h b/source-code/source/plugins/TLAC/Components/Pause.h index 76f5219..3b84c0b 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.h +++ b/source-code/source/plugins/TLAC/Components/Pause.h @@ -75,6 +75,7 @@ namespace TLAC::Components static void mainmenu() { menuSet = MENUSET_MAIN; menuPos = mainMenuPos; menuItemSelectTime = std::chrono::high_resolution_clock::now(); }; static void unpause() { pause = false; }; + static void restart() { ((void(*)(uint64_t))0x140675000)(PV_GAME_BASE_ADDRESS); } static void giveup() { giveUp = true; }; static void sevolmenu() { menuSet = MENUSET_SEVOL; menuPos = 1; menuItemSelectTime = std::chrono::high_resolution_clock::now(); }; @@ -86,6 +87,7 @@ namespace TLAC::Components std::vector> menuItems[2] = { { std::pair(std::string("RESUME"), &unpause), + std::pair(std::string("RESTART"), &restart), std::pair(std::string("SE VOLUME"), &sevolmenu), std::pair(std::string("GIVE UP"), &giveup), }, diff --git a/source-code/source/plugins/TLAC/Constants.h b/source-code/source/plugins/TLAC/Constants.h index 4cd551d..e54237c 100644 --- a/source-code/source/plugins/TLAC/Constants.h +++ b/source-code/source/plugins/TLAC/Constants.h @@ -111,7 +111,7 @@ constexpr uint64_t DSC_START_SYS_TIME_ADDRESS_2 = 0x0000000140D0B568; constexpr uint64_t DSC_PAUSE_FUNC_ADDRESS = 0x00000001401295C0; constexpr uint64_t DSC_UNPAUSE_FUNC_ADDRESS = 0x0000000140129590; -constexpr uint64_t PV_GAME_BASE_ADDRESS = 0x0000000140C94380; +constexpr uint64_t PV_GAME_BASE_ADDRESS = 0x000000014CC95270; constexpr uint64_t GIVEUP_FUNC_ADDRESS = 0x000000014010EF00; From 6acaed6f3a4d2ab836849fd296e5ef3166dcf0f4 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Tue, 22 Oct 2019 05:39:37 +1100 Subject: [PATCH 21/44] pause disable broken restart button --- source-code/source/plugins/TLAC/Components/Pause.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Pause.h b/source-code/source/plugins/TLAC/Components/Pause.h index 3b84c0b..bc7a782 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.h +++ b/source-code/source/plugins/TLAC/Components/Pause.h @@ -75,7 +75,7 @@ namespace TLAC::Components static void mainmenu() { menuSet = MENUSET_MAIN; menuPos = mainMenuPos; menuItemSelectTime = std::chrono::high_resolution_clock::now(); }; static void unpause() { pause = false; }; - static void restart() { ((void(*)(uint64_t))0x140675000)(PV_GAME_BASE_ADDRESS); } + //static void restart() { *(uint8_t*)0x140d0b538 = 1; unpause(); } static void giveup() { giveUp = true; }; static void sevolmenu() { menuSet = MENUSET_SEVOL; menuPos = 1; menuItemSelectTime = std::chrono::high_resolution_clock::now(); }; @@ -87,7 +87,7 @@ namespace TLAC::Components std::vector> menuItems[2] = { { std::pair(std::string("RESUME"), &unpause), - std::pair(std::string("RESTART"), &restart), + //std::pair(std::string("RESTART"), &restart), std::pair(std::string("SE VOLUME"), &sevolmenu), std::pair(std::string("GIVE UP"), &giveup), }, From 942de967ced38fac6b694d78dc8bc591d9324ab2 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Tue, 22 Oct 2019 05:42:52 +1100 Subject: [PATCH 22/44] pause: fix button icons remaining when UI is hidden --- source-code/source/plugins/TLAC/Components/Pause.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index 52337c6..ad7eca4 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -109,7 +109,17 @@ namespace TLAC::Components else { if (inputState->Tapped.Buttons & JVS_SQUARE) + { showUI = !showUI; + if (!showUI) + { + // clear these from the screen too + destroyAetLayer(triangleAet); + destroyAetLayer(squareAet); + destroyAetLayer(crossAet); + destroyAetLayer(circleAet); + } + } // only process menu events when UI is visible if (showUI) From d7ca0637f5b321e89d67130350f8b61c016137ae Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Wed, 23 Oct 2019 04:52:39 +1100 Subject: [PATCH 23/44] pause: better input filtering buttons now need to be pressed again after leaving pause to trigger (instead of instantly hitting when unpaused) --- .../source/plugins/TLAC/Components/Pause.cpp | 25 ++++++++++++------- .../source/plugins/TLAC/Components/Pause.h | 3 +++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index ad7eca4..5ef1689 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -26,6 +26,7 @@ namespace TLAC::Components bool(*divaGiveUpFunc)(void*) = (bool(*)(void* cls))GIVEUP_FUNC_ADDRESS; InputState* Pause::inputState; PlayerData* Pause::playerData; + JvsButtons Pause::filteredButtons; Pause::Pause() { @@ -94,6 +95,9 @@ namespace TLAC::Components *playstate = 0; } + // block all buttons from being passed to game + filteredButtons = allButtons; + menuPos = 0; menuSet = MENUSET_MAIN; showUI = true; @@ -169,15 +173,6 @@ namespace TLAC::Components delete[] buf; } } - - - // swallow all button inputs if paused - inputState->Tapped.Buttons = JVS_NONE; - inputState->DoubleTapped.Buttons = JVS_NONE; - inputState->Down.Buttons = JVS_NONE; - inputState->Released.Buttons = JVS_NONE; - inputState->IntervalTapped.Buttons = JVS_NONE; - // todo: slider } } else @@ -208,6 +203,9 @@ namespace TLAC::Components isPaused = false; } + // buttons that have been tapped no longer need to be filtered (doing this with down broke retriggering) + filteredButtons = (JvsButtons)(filteredButtons & ~inputState->Tapped.Buttons); + // only enter pause if in game if (*(GameState*)CURRENT_GAME_STATE_ADDRESS == GS_GAME && *(SubGameState*)CURRENT_GAME_SUB_STATE_ADDRESS == SUB_GAME_MAIN) { @@ -217,6 +215,15 @@ namespace TLAC::Components } } } + + + // swallow filtered button inputs + inputState->Tapped.Buttons = (JvsButtons)(inputState->Tapped.Buttons & ~filteredButtons); + inputState->DoubleTapped.Buttons = (JvsButtons)(inputState->DoubleTapped.Buttons & ~filteredButtons); + inputState->Down.Buttons = (JvsButtons)(inputState->Down.Buttons & ~filteredButtons); + inputState->Released.Buttons = (JvsButtons)(inputState->Released.Buttons & ~filteredButtons); + inputState->IntervalTapped.Buttons = (JvsButtons)(inputState->IntervalTapped.Buttons & ~filteredButtons); + // todo: slider } void Pause::UpdateDraw2D() diff --git a/source-code/source/plugins/TLAC/Components/Pause.h b/source-code/source/plugins/TLAC/Components/Pause.h index bc7a782..4c4253b 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.h +++ b/source-code/source/plugins/TLAC/Components/Pause.h @@ -47,6 +47,9 @@ namespace TLAC::Components static PlayerData* playerData; static InputState* inputState; + static const JvsButtons allButtons = (JvsButtons)(JVS_START | JVS_TRIANGLE | JVS_SQUARE | JVS_CROSS | JVS_CIRCLE | JVS_L | JVS_R); // deliberately only has control panel buttons + static JvsButtons filteredButtons; + static const int menuX = 640; static const int menuY = 360; static const int menuItemHeight = 36; From 98a6fec7acfbc5ea2c6432f1f1c4c65a1f0a4247 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Wed, 23 Oct 2019 05:36:27 +1100 Subject: [PATCH 24/44] pause: menu code cleanup --- .../source/plugins/TLAC/Components/Pause.cpp | 65 ++++++---------- .../source/plugins/TLAC/Components/Pause.h | 78 +++++++++++++++---- 2 files changed, 87 insertions(+), 56 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index 5ef1689..550b552 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -14,10 +14,10 @@ namespace TLAC::Components bool Pause::isPaused = false; bool Pause::giveUp = false; bool Pause::showUI = true; - unsigned int Pause::menuPos = 0; - unsigned int Pause::mainMenuPos = 0; - unsigned int Pause::menuSet = MENUSET_MAIN; - std::chrono::time_point Pause::menuItemSelectTime; + int Pause::curMenuPos = 0; + int Pause::mainMenuPos = 0; + Pause::menusets Pause::curMenuSet = MENUSET_MAIN; + std::chrono::time_point Pause::menuItemMoveTime; std::vector Pause::origAetMovOp; uint8_t* Pause::aetMovPatchAddress = (uint8_t*)0x1401703b3; std::vector Pause::origFramespeedOp; @@ -98,10 +98,8 @@ namespace TLAC::Components // block all buttons from being passed to game filteredButtons = allButtons; - menuPos = 0; - menuSet = MENUSET_MAIN; + setMenuPos(MENUSET_MAIN, 0); showUI = true; - menuItemSelectTime = std::chrono::high_resolution_clock::now(); isPaused = true; } @@ -129,47 +127,32 @@ namespace TLAC::Components if (showUI) { if (inputState->Tapped.Buttons & JVS_L) - { - menuPos -= 1; - menuItemSelectTime = std::chrono::high_resolution_clock::now(); - } + setMenuPos(curMenuSet, curMenuPos - 1); if (inputState->Tapped.Buttons & JVS_R) - { - menuPos += 1; - menuItemSelectTime = std::chrono::high_resolution_clock::now(); - } + setMenuPos(curMenuSet, curMenuPos + 1); if (inputState->Tapped.Buttons & JVS_TRIANGLE) { - if (menuSet != MENUSET_MAIN) + if (curMenuSet != MENUSET_MAIN) { - menuSet = MENUSET_MAIN; - menuPos = mainMenuPos; - menuItemSelectTime = std::chrono::high_resolution_clock::now(); + setMenuPos(MENUSET_MAIN, mainMenuPos); } } - - menuPos %= menuItems[menuSet].size(); - - if (menuSet == MENUSET_MAIN) - mainMenuPos = menuPos; - - // use released when unpausing from X so it doesn't trigger input - if (inputState->Released.Buttons & JVS_CROSS) + + if (inputState->Tapped.Buttons & JVS_CROSS) pause = false; - // use released because this can trigger an unpause too - if (inputState->Released.Buttons & JVS_CIRCLE) - menuItems[menuSet][menuPos].second(); + if (inputState->Tapped.Buttons & JVS_CIRCLE) + menu[curMenuSet].items[curMenuPos].callback(); - if (menuSet == MENUSET_SEVOL) + if (curMenuSet == MENUSET_SEVOL) { const char volformat[] = "%d"; size_t size = snprintf(nullptr, 0, volformat, playerData->act_vol) + 1; char* buf = new char[size]; snprintf(buf, size, volformat, playerData->act_vol); - menuItems[MENUSET_SEVOL][1].first = buf; + menu[MENUSET_SEVOL].items[1].name = buf; delete[] buf; } } @@ -269,8 +252,8 @@ namespace TLAC::Components dtParams.layer = contentLayer; // selection cursor - int selectBoxOrigin = menuY - menuItemHeight * (menuItems[menuSet].size() / 2.0) - (menuItemHeight - menuTextSize) / 2; - int selectBoxPos = selectBoxOrigin + menuItemHeight * menuPos; + int selectBoxOrigin = menuY - menuItemHeight * (menu[curMenuSet].items.size() / 2.0) - (menuItemHeight - menuTextSize) / 2; + int selectBoxPos = selectBoxOrigin + menuItemHeight * curMenuPos; const float selectBoxWidth = 200; const float selectBoxHeight = menuItemHeight; const float selectBoxThickness = 2; @@ -287,16 +270,16 @@ namespace TLAC::Components // menu fontInfo.setSize(menuTextSize, menuTextSize); - dtParams.originLoc = { menuX, menuY - menuItemHeight * (menuItems[menuSet].size() / 2.0f) }; + dtParams.originLoc = { menuX, menuY - menuItemHeight * (menu[curMenuSet].items.size() / 2.0f) }; - for (int i = 0; i < menuItems[menuSet].size(); i++) + for (int i = 0; i < menu[curMenuSet].items.size(); i++) { - std::pair &item = menuItems[menuSet][i]; + menuItem &item = menu[curMenuSet].items[i]; - if (i == menuPos) + if (i == curMenuPos) { const int duration = 1500000000; // 1.5s - std::chrono::nanoseconds cyclePos = (std::chrono::high_resolution_clock::now() - menuItemSelectTime) % std::chrono::nanoseconds(duration); + std::chrono::nanoseconds cyclePos = (std::chrono::high_resolution_clock::now() - menuItemMoveTime) % std::chrono::nanoseconds(duration); uint8_t alpha = (cosf(cyclePos.count() * 6.283185f / duration) * 0.15 + 0.85) * 255; dtParams.colour = 0x00ffff00 | (alpha << 24); } @@ -306,7 +289,7 @@ namespace TLAC::Components } dtParams.currentLoc = dtParams.originLoc; - drawText(&dtParams, (drawTextFlags)(DRAWTEXT_ALIGN_CENTRE), item.first); + drawText(&dtParams, (drawTextFlags)(DRAWTEXT_ALIGN_CENTRE), item.name); dtParams.originLoc.y += menuItemHeight; } @@ -328,7 +311,7 @@ namespace TLAC::Components dtParams.colour = 0xffffffff; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"L/R:Move "); - if (menuSet != MENUSET_MAIN) + if (curMenuSet != MENUSET_MAIN) { spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; triangleAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_sankaku", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, 0); diff --git a/source-code/source/plugins/TLAC/Components/Pause.h b/source-code/source/plugins/TLAC/Components/Pause.h index 4c4253b..30170f1 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.h +++ b/source-code/source/plugins/TLAC/Components/Pause.h @@ -59,16 +59,13 @@ namespace TLAC::Components static const uint32_t contentLayer = 0x19; // same as startup screen static bool showUI; - static unsigned int menuPos; - static unsigned int mainMenuPos; // syncs to menuPos when menuSet == menuset_main (used for restoring on back) - static unsigned int menuSet; int triangleAet; int squareAet; int crossAet; int circleAet; - static std::chrono::time_point menuItemSelectTime; + static std::chrono::time_point menuItemMoveTime; // used for animation enum menusets { @@ -76,29 +73,80 @@ namespace TLAC::Components MENUSET_SEVOL = 1, }; - static void mainmenu() { menuSet = MENUSET_MAIN; menuPos = mainMenuPos; menuItemSelectTime = std::chrono::high_resolution_clock::now(); }; + struct menuItem + { + std::string name; + void(*callback)(); + bool keyRepeat; // unimplemented + + menuItem(std::string _name, void(*_callback)(), bool _keyRepeat) + { + name = _name; + callback = _callback; + keyRepeat = _keyRepeat; + } + }; + + struct menuSet + { + std::string name; + std::vector items; + }; + + static int curMenuPos; + static int mainMenuPos; // syncs to menuPos when menuSet == menuset_main (used for restoring on back) + static menusets curMenuSet; + + static void mainmenu() { curMenuSet = MENUSET_MAIN; curMenuPos = mainMenuPos; menuItemMoveTime = std::chrono::high_resolution_clock::now(); }; static void unpause() { pause = false; }; //static void restart() { *(uint8_t*)0x140d0b538 = 1; unpause(); } static void giveup() { giveUp = true; }; - static void sevolmenu() { menuSet = MENUSET_SEVOL; menuPos = 1; menuItemSelectTime = std::chrono::high_resolution_clock::now(); }; + static void sevolmenu() { curMenuSet = MENUSET_SEVOL; curMenuPos = 1; menuItemMoveTime = std::chrono::high_resolution_clock::now(); }; static void sevolplus() { setSEVolume(10); }; static void sevolminus() { setSEVolume(-10); }; // defined as an array now so submenus could be added - std::vector> menuItems[2] = { + // not sure how to make this static for consistency so whatever + menuSet menu[2] = { { - std::pair(std::string("RESUME"), &unpause), - //std::pair(std::string("RESTART"), &restart), - std::pair(std::string("SE VOLUME"), &sevolmenu), - std::pair(std::string("GIVE UP"), &giveup), + "PAUSED", + { + { "RESUME", unpause, false }, + //{ "RESTART", restart, false }, + { "SE VOLUME", sevolmenu, false }, + { "GIVE UP", giveup, false }, + } }, { - std::pair(std::string("+"), &sevolplus), - std::pair(std::string("XX"), &mainmenu), - std::pair(std::string("-"), &sevolminus), - } + "SE VOLUME", + { + { "+", sevolplus, true }, + { "XX", mainmenu, false }, + { "-", sevolminus, true }, + } + }, }; + + void setMenuPos(menusets set, int pos) + { + if (set >= 0 && set < _countof(menu)) + curMenuSet = set; + else + curMenuSet = MENUSET_MAIN; + + if (pos < 0) + pos = menu[curMenuSet].items.size() - 1; + else if (pos >= menu[curMenuSet].items.size()) + pos = 0; + + curMenuPos = pos; + + if (curMenuSet == MENUSET_MAIN) + mainMenuPos = curMenuPos; + + menuItemMoveTime = std::chrono::high_resolution_clock::now(); + } }; } From 3ae348e9661b984c40ce4fd5ceda482b47e6801a Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Wed, 23 Oct 2019 06:02:34 +1100 Subject: [PATCH 25/44] pause: more cleanup --- .../source/plugins/TLAC/Components/Pause.cpp | 55 ++++++++++++++++-- .../source/plugins/TLAC/Components/Pause.h | 56 ++++--------------- 2 files changed, 61 insertions(+), 50 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index 550b552..5540e44 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -27,6 +27,25 @@ namespace TLAC::Components InputState* Pause::inputState; PlayerData* Pause::playerData; JvsButtons Pause::filteredButtons; + std::vector Pause::menu = { + { + "PAUSED", + { + { "RESUME", unpause, false }, + //{ "RESTART", restart, false }, + { "SE VOLUME", sevolmenu, false }, + { "GIVE UP", giveup, false }, + } + }, + { + "SE VOLUME", + { + { "+", sevolplus, true }, + { "XX", mainmenu, false }, + { "-", sevolminus, true }, + } + }, + }; Pause::Pause() { @@ -113,7 +132,11 @@ namespace TLAC::Components if (inputState->Tapped.Buttons & JVS_SQUARE) { showUI = !showUI; - if (!showUI) + if (showUI) + { + menuItemMoveTime = std::chrono::high_resolution_clock::now(); // restart animations + } + else { // clear these from the screen too destroyAetLayer(triangleAet); @@ -278,9 +301,7 @@ namespace TLAC::Components if (i == curMenuPos) { - const int duration = 1500000000; // 1.5s - std::chrono::nanoseconds cyclePos = (std::chrono::high_resolution_clock::now() - menuItemMoveTime) % std::chrono::nanoseconds(duration); - uint8_t alpha = (cosf(cyclePos.count() * 6.283185f / duration) * 0.15 + 0.85) * 255; + uint8_t alpha = (cosf(getMenuAnimPos() * 6.283185f) * 0.15 + 0.85) * 255; dtParams.colour = 0x00ffff00 | (alpha << 24); } else @@ -368,6 +389,32 @@ namespace TLAC::Components playerData->act_slide_vol = playerData->act_vol; } + void Pause::setMenuPos(menusets set, int pos) + { + if (set >= 0 && set < menu.size()) + curMenuSet = set; + else + curMenuSet = MENUSET_MAIN; + + if (pos < 0) + pos = menu[curMenuSet].items.size() - 1; + else if (pos >= menu[curMenuSet].items.size()) + pos = 0; + + curMenuPos = pos; + + if (curMenuSet == MENUSET_MAIN) + mainMenuPos = curMenuPos; + + menuItemMoveTime = std::chrono::high_resolution_clock::now(); // restart animations + } + + float Pause::getMenuAnimPos() + { + const int duration = 1500000000; // 1.5s + return (float)((std::chrono::high_resolution_clock::now() - menuItemMoveTime) % std::chrono::nanoseconds(duration)).count() / (float)duration; + } + void Pause::InjectCode(void* address, const std::vector data) { const size_t byteCount = data.size() * sizeof(uint8_t); diff --git a/source-code/source/plugins/TLAC/Components/Pause.h b/source-code/source/plugins/TLAC/Components/Pause.h index 30170f1..9649af2 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.h +++ b/source-code/source/plugins/TLAC/Components/Pause.h @@ -64,9 +64,7 @@ namespace TLAC::Components int squareAet; int crossAet; int circleAet; - - static std::chrono::time_point menuItemMoveTime; // used for animation - + enum menusets { MENUSET_MAIN = 0, @@ -94,59 +92,25 @@ namespace TLAC::Components }; static int curMenuPos; - static int mainMenuPos; // syncs to menuPos when menuSet == menuset_main (used for restoring on back) + static int mainMenuPos; // syncs to curMenuPos when curMenuSet == MENUSET_MAIN (used for restoring on back) static menusets curMenuSet; - static void mainmenu() { curMenuSet = MENUSET_MAIN; curMenuPos = mainMenuPos; menuItemMoveTime = std::chrono::high_resolution_clock::now(); }; + static std::chrono::time_point menuItemMoveTime; // used for animation + + static void mainmenu() { setMenuPos(MENUSET_MAIN, mainMenuPos); }; static void unpause() { pause = false; }; //static void restart() { *(uint8_t*)0x140d0b538 = 1; unpause(); } static void giveup() { giveUp = true; }; - static void sevolmenu() { curMenuSet = MENUSET_SEVOL; curMenuPos = 1; menuItemMoveTime = std::chrono::high_resolution_clock::now(); }; + static void sevolmenu() { setMenuPos(MENUSET_SEVOL, 1); }; static void sevolplus() { setSEVolume(10); }; static void sevolminus() { setSEVolume(-10); }; + // contents are in Pause.cpp because they can't be inline here for a static (const) array/vec + static std::vector menu; - // defined as an array now so submenus could be added - // not sure how to make this static for consistency so whatever - menuSet menu[2] = { - { - "PAUSED", - { - { "RESUME", unpause, false }, - //{ "RESTART", restart, false }, - { "SE VOLUME", sevolmenu, false }, - { "GIVE UP", giveup, false }, - } - }, - { - "SE VOLUME", - { - { "+", sevolplus, true }, - { "XX", mainmenu, false }, - { "-", sevolminus, true }, - } - }, - }; + static void setMenuPos(menusets set, int pos); - void setMenuPos(menusets set, int pos) - { - if (set >= 0 && set < _countof(menu)) - curMenuSet = set; - else - curMenuSet = MENUSET_MAIN; - - if (pos < 0) - pos = menu[curMenuSet].items.size() - 1; - else if (pos >= menu[curMenuSet].items.size()) - pos = 0; - - curMenuPos = pos; - - if (curMenuSet == MENUSET_MAIN) - mainMenuPos = curMenuPos; - - menuItemMoveTime = std::chrono::high_resolution_clock::now(); - } + static float getMenuAnimPos(); }; } From 01a089d1f4410089cf5d183671769559039d08c8 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Wed, 23 Oct 2019 07:32:19 +1100 Subject: [PATCH 26/44] pause: add slider input filtering --- .../source/plugins/TLAC/Components/Pause.cpp | 17 ++++++++++------- .../source/plugins/TLAC/Components/Pause.h | 2 ++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index 5540e44..68b4e98 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -24,8 +24,9 @@ namespace TLAC::Components uint8_t* Pause::framespeedPatchAddress = (uint8_t*)0x140192D50; std::vector Pause::streamPlayStates; bool(*divaGiveUpFunc)(void*) = (bool(*)(void* cls))GIVEUP_FUNC_ADDRESS; - InputState* Pause::inputState; PlayerData* Pause::playerData; + InputState* Pause::inputState; + TouchSliderState* Pause::sliderState; JvsButtons Pause::filteredButtons; std::vector Pause::menu = { { @@ -73,6 +74,7 @@ namespace TLAC::Components { inputState = (InputState*)(*(uint64_t*)INPUT_STATE_PTR_ADDRESS); playerData = (PlayerData*)PLAYER_DATA_ADDRESS; + sliderState = (TouchSliderState*)SLIDER_CTRL_TASK_ADDRESS; saveOldPatchOps(); @@ -101,7 +103,7 @@ namespace TLAC::Components InjectCode(framespeedPatchAddress, { 0x0f, 0x57, 0xc0, 0xc3 }); // XORPS XMM0,XMM0; RET uint64_t audioMixerAddr = *(uint64_t*)(AUDIO_MAIN_CLASS_ADDRESS + 0x70); - uint64_t audioStreamsAddress = *(uint64_t*)(audioMixerAddr + 0x18);; + uint64_t audioStreamsAddress = *(uint64_t*)(audioMixerAddr + 0x18); int nAudioStreams = *(uint64_t*)(audioMixerAddr + 0x20); for (int i = 0; i < nAudioStreams; i++) { @@ -180,6 +182,11 @@ namespace TLAC::Components } } } + + // no slider while paused + // this is simpler than buttons because slider doesn't trigger on press, it triggers on movement + // (therefore per-button blocking isn't needed) + sliderState->ResetSensors(); } else { @@ -222,14 +229,12 @@ namespace TLAC::Components } } - // swallow filtered button inputs inputState->Tapped.Buttons = (JvsButtons)(inputState->Tapped.Buttons & ~filteredButtons); inputState->DoubleTapped.Buttons = (JvsButtons)(inputState->DoubleTapped.Buttons & ~filteredButtons); inputState->Down.Buttons = (JvsButtons)(inputState->Down.Buttons & ~filteredButtons); inputState->Released.Buttons = (JvsButtons)(inputState->Released.Buttons & ~filteredButtons); inputState->IntervalTapped.Buttons = (JvsButtons)(inputState->IntervalTapped.Buttons & ~filteredButtons); - // todo: slider } void Pause::UpdateDraw2D() @@ -297,8 +302,6 @@ namespace TLAC::Components for (int i = 0; i < menu[curMenuSet].items.size(); i++) { - menuItem &item = menu[curMenuSet].items[i]; - if (i == curMenuPos) { uint8_t alpha = (cosf(getMenuAnimPos() * 6.283185f) * 0.15 + 0.85) * 255; @@ -310,7 +313,7 @@ namespace TLAC::Components } dtParams.currentLoc = dtParams.originLoc; - drawText(&dtParams, (drawTextFlags)(DRAWTEXT_ALIGN_CENTRE), item.name); + drawText(&dtParams, (drawTextFlags)(DRAWTEXT_ALIGN_CENTRE), menu[curMenuSet].items[i].name); dtParams.originLoc.y += menuItemHeight; } diff --git a/source-code/source/plugins/TLAC/Components/Pause.h b/source-code/source/plugins/TLAC/Components/Pause.h index 9649af2..6f0d9b2 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.h +++ b/source-code/source/plugins/TLAC/Components/Pause.h @@ -3,6 +3,7 @@ #include "EmulatorComponent.h" #include "PlayerData.h" #include "Input/InputState.h" +#include "Input/TouchSliderState.h" #include #include #include @@ -46,6 +47,7 @@ namespace TLAC::Components static PlayerData* playerData; static InputState* inputState; + static TouchSliderState* sliderState; static const JvsButtons allButtons = (JvsButtons)(JVS_START | JVS_TRIANGLE | JVS_SQUARE | JVS_CROSS | JVS_CIRCLE | JVS_L | JVS_R); // deliberately only has control panel buttons static JvsButtons filteredButtons; From 6bbc1fce5f2449b732d2c4e4ed18c2f9eb48eab7 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Wed, 23 Oct 2019 07:47:26 +1100 Subject: [PATCH 27/44] pause: disable aets in key legend -- I've been getting some crashes that seem to be caused by them and I'm not sure why yet might be something as simple as putting const in a few too many places --- .../source/plugins/TLAC/Components/Pause.cpp | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index 68b4e98..74bfa82 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -327,35 +327,47 @@ namespace TLAC::Components fontInfo.setSize(18, 18); dtParams.originLoc = { 32, 720 - 40 }; dtParams.currentLoc = dtParams.originLoc; - const float spriteSize = 18; - const float halfSpriteSize = spriteSize / 2; - Point spriteLoc = { 0, dtParams.originLoc.y + halfSpriteSize }; - Point spriteScale = { spriteSize / 64, spriteSize / 64 }; // just approximated + //const float spriteSize = 18; + //const float halfSpriteSize = spriteSize / 2; + //Point spriteLoc = { 0, dtParams.originLoc.y + halfSpriteSize }; + //Point spriteScale = { spriteSize / 64, spriteSize / 64 }; // just approximated dtParams.colour = 0xffffffff; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"L/R:Move "); if (curMenuSet != MENUSET_MAIN) { - spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; - triangleAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_sankaku", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, 0); - dtParams.originLoc.x += spriteSize; + //spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; + //triangleAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_sankaku", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, 0); + //dtParams.originLoc.x += spriteSize; + dtParams.colour = 0xff80ff40; + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"△"); + dtParams.colour = 0xffffffff; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Back "); } - spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; - squareAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_shikaku", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, 0); - dtParams.originLoc.x += spriteSize; + //spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; + //squareAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_shikaku", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, 0); + //dtParams.originLoc.x += spriteSize; + dtParams.colour = 0xffc080ff; + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"□"); + dtParams.colour = 0xffffffff; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Hide Menu "); - spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; - crossAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_batsu", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, 0); - dtParams.originLoc.x += spriteSize; + //spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; + //crossAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_batsu", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, 0); + //dtParams.originLoc.x += spriteSize; + dtParams.colour = 0xffff8040; + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"×"); + dtParams.colour = 0xffffffff; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Close "); - spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; - circleAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_maru", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, 0); - dtParams.originLoc.x += spriteSize; + //spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; + //circleAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_maru", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, 0); + //dtParams.originLoc.x += spriteSize; + dtParams.colour = 0xff6040ff; + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"○"); + dtParams.colour = 0xffffffff; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Select"); } } From d5b184414a6443e363766fbab49fee7191c0c817 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Wed, 23 Oct 2019 08:26:27 +1100 Subject: [PATCH 28/44] pause: bring back the fancy icons (with a fix for createAetLayer's signature in drawing) --- .../source/plugins/TLAC/Components/Drawing.h | 5 ++- .../source/plugins/TLAC/Components/Pause.cpp | 44 +++++++------------ 2 files changed, 19 insertions(+), 30 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Drawing.h b/source-code/source/plugins/TLAC/Components/Drawing.h index 342800c..d651c3a 100644 --- a/source-code/source/plugins/TLAC/Components/Drawing.h +++ b/source-code/source/plugins/TLAC/Components/Drawing.h @@ -248,9 +248,10 @@ namespace TLAC::Components }; // draw an aet layer (with all settings) - 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, int32_t unk5) + // 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) { - return ((int(*)(int32_t, uint32_t, createAetFlags, const char*, const Point*, int32_t, const char*, const char*, float, float, const Point*, int32_t))0x14013be60)(unk1, drawLayer, flags, name, loc, unk2, animation, animation2, animationInTime, animationOutTime, scale, unk5); + 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); } // 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) diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index 74bfa82..b554b70 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -327,47 +327,35 @@ namespace TLAC::Components fontInfo.setSize(18, 18); dtParams.originLoc = { 32, 720 - 40 }; dtParams.currentLoc = dtParams.originLoc; - //const float spriteSize = 18; - //const float halfSpriteSize = spriteSize / 2; - //Point spriteLoc = { 0, dtParams.originLoc.y + halfSpriteSize }; - //Point spriteScale = { spriteSize / 64, spriteSize / 64 }; // just approximated + const float spriteSize = 18; + const float halfSpriteSize = spriteSize / 2; + Point spriteLoc = { 0, dtParams.originLoc.y + halfSpriteSize }; + const Point spriteScale = { spriteSize / 64, spriteSize / 64 }; // just approximated dtParams.colour = 0xffffffff; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"L/R:Move "); if (curMenuSet != MENUSET_MAIN) { - //spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; - //triangleAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_sankaku", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, 0); - //dtParams.originLoc.x += spriteSize; - dtParams.colour = 0xff80ff40; - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"△"); - dtParams.colour = 0xffffffff; + spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; + triangleAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_sankaku", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, nullptr); + dtParams.originLoc.x += spriteSize; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Back "); } - //spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; - //squareAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_shikaku", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, 0); - //dtParams.originLoc.x += spriteSize; - dtParams.colour = 0xffc080ff; - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"□"); - dtParams.colour = 0xffffffff; + spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; + squareAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_shikaku", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, nullptr); + dtParams.originLoc.x += spriteSize; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Hide Menu "); - //spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; - //crossAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_batsu", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, 0); - //dtParams.originLoc.x += spriteSize; - dtParams.colour = 0xffff8040; - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"×"); - dtParams.colour = 0xffffffff; + spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; + crossAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_batsu", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, nullptr); + dtParams.originLoc.x += spriteSize; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Close "); - //spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; - //circleAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_maru", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, 0); - //dtParams.originLoc.x += spriteSize; - dtParams.colour = 0xff6040ff; - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"○"); - dtParams.colour = 0xffffffff; + spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; + circleAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_maru", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, nullptr); + dtParams.originLoc.x += spriteSize; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Select"); } } From bb20f55e1cdc76de3c9a51266580b18f1bdce0da Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Wed, 23 Oct 2019 11:06:56 +1100 Subject: [PATCH 29/44] tlac: rename some text drawing stuff to be more correct --- .../source/plugins/TLAC/Components/Drawing.h | 13 +++--- .../source/plugins/TLAC/Components/Pause.cpp | 41 ++++++++++--------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Drawing.h b/source-code/source/plugins/TLAC/Components/Drawing.h index d651c3a..1ef1242 100644 --- a/source-code/source/plugins/TLAC/Components/Drawing.h +++ b/source-code/source/plugins/TLAC/Components/Drawing.h @@ -82,13 +82,14 @@ namespace TLAC::Components uint32_t unk14; uint32_t unk18; uint32_t layer; // 8 seems similar to default but higher - // 0x19 is startup screen + // 0x18 is below 0x19 but still seems to be above any game elements + // 0x19 is startup screen (below dwgui) // I noticed some use different scaling uint32_t unk20; uint32_t unk24; uint32_t unk28; - Point originLoc; - Point currentLoc; + Point textCurrentLoc; + Point lineOriginLoc; // must be set for newlines to work as expected uint8_t padding3c[0x4]; uint64_t unk40; FontInfo* font; @@ -107,8 +108,8 @@ namespace TLAC::Components unk20 = 0x0; unk24 = 0xd; unk28 = 0; - originLoc = { 0, 0 }; - currentLoc = { 0, 0 }; + textCurrentLoc = { 0, 0 }; + lineOriginLoc = { 0, 0 }; unk40 = 0; font = fi; unk50 = 0x25a1; @@ -184,7 +185,7 @@ namespace TLAC::Components enum drawTextFlags : uint32_t { - DRAWTEXT_ENABLE_LAYOUT = 1, //? + DRAWTEXT_ENABLE_XADVANCE = 1, DRAWTEXT_ALIGN_RIGHT = 2, DRAWTEXT_ALIGN_CENTRE = 8, DRAWTEXT_STROKE = 0x10000, diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index b554b70..59bc796 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -298,7 +298,8 @@ namespace TLAC::Components // menu fontInfo.setSize(menuTextSize, menuTextSize); - dtParams.originLoc = { menuX, menuY - menuItemHeight * (menu[curMenuSet].items.size() / 2.0f) }; + dtParams.textCurrentLoc = { menuX, menuY - menuItemHeight * (menu[curMenuSet].items.size() / 2.0f) }; + dtParams.lineOriginLoc = dtParams.textCurrentLoc; for (int i = 0; i < menu[curMenuSet].items.size(); i++) { @@ -312,11 +313,11 @@ namespace TLAC::Components dtParams.colour = 0xffffffff; } - dtParams.currentLoc = dtParams.originLoc; drawText(&dtParams, (drawTextFlags)(DRAWTEXT_ALIGN_CENTRE), menu[curMenuSet].items[i].name); - dtParams.originLoc.y += menuItemHeight; + dtParams.textCurrentLoc.y += menuItemHeight; + dtParams.lineOriginLoc = dtParams.textCurrentLoc; } - + // key legend destroyAetLayer(triangleAet); @@ -325,38 +326,38 @@ namespace TLAC::Components destroyAetLayer(circleAet); fontInfo.setSize(18, 18); - dtParams.originLoc = { 32, 720 - 40 }; - dtParams.currentLoc = dtParams.originLoc; + dtParams.textCurrentLoc = { 32, 720 - 40 }; + dtParams.lineOriginLoc = dtParams.textCurrentLoc; const float spriteSize = 18; const float halfSpriteSize = spriteSize / 2; - Point spriteLoc = { 0, dtParams.originLoc.y + halfSpriteSize }; + 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 dtParams.colour = 0xffffffff; - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L"L/R:Move "); + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_XADVANCE), L"L/R:Move "); if (curMenuSet != MENUSET_MAIN) { - spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; + spriteLoc.x = dtParams.textCurrentLoc.x + halfSpriteSize; // the aets are centered on their location, so fudge this a little triangleAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_sankaku", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, nullptr); - dtParams.originLoc.x += spriteSize; - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Back "); + dtParams.textCurrentLoc.x += spriteSize; + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_XADVANCE), L":Back "); } - spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; + spriteLoc.x = dtParams.textCurrentLoc.x + halfSpriteSize; squareAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_shikaku", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, nullptr); - dtParams.originLoc.x += spriteSize; - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Hide Menu "); + dtParams.textCurrentLoc.x += spriteSize; + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_XADVANCE), L":Hide Menu "); - spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; + spriteLoc.x = dtParams.textCurrentLoc.x + halfSpriteSize; crossAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_batsu", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, nullptr); - dtParams.originLoc.x += spriteSize; - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Close "); + dtParams.textCurrentLoc.x += spriteSize; + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_XADVANCE), L":Close "); - spriteLoc.x = dtParams.originLoc.x + halfSpriteSize; + spriteLoc.x = dtParams.textCurrentLoc.x + halfSpriteSize; circleAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_maru", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, nullptr); - dtParams.originLoc.x += spriteSize; - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_LAYOUT), L":Select"); + dtParams.textCurrentLoc.x += spriteSize; + drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_XADVANCE), L":Select"); } } From 0f5745cde10574be32743155729e70b01a92c2b7 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Wed, 23 Oct 2019 11:11:16 +1100 Subject: [PATCH 30/44] pause: use cross to leave sub-menu instead of triangle --- .../source/plugins/TLAC/Components/Pause.cpp | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index 59bc796..593ef69 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -157,16 +157,17 @@ namespace TLAC::Components if (inputState->Tapped.Buttons & JVS_R) setMenuPos(curMenuSet, curMenuPos + 1); - if (inputState->Tapped.Buttons & JVS_TRIANGLE) + if (inputState->Tapped.Buttons & JVS_CROSS) { - if (curMenuSet != MENUSET_MAIN) + if (curMenuSet == MENUSET_MAIN) + { + pause = false; + } + else { setMenuPos(MENUSET_MAIN, mainMenuPos); } } - - if (inputState->Tapped.Buttons & JVS_CROSS) - pause = false; if (inputState->Tapped.Buttons & JVS_CIRCLE) menu[curMenuSet].items[curMenuPos].callback(); @@ -335,15 +336,7 @@ namespace TLAC::Components dtParams.colour = 0xffffffff; drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_XADVANCE), L"L/R:Move "); - - if (curMenuSet != MENUSET_MAIN) - { - spriteLoc.x = dtParams.textCurrentLoc.x + halfSpriteSize; // the aets are centered on their location, so fudge this a little - triangleAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_sankaku", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, nullptr); - dtParams.textCurrentLoc.x += spriteSize; - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_XADVANCE), L":Back "); - } - + spriteLoc.x = dtParams.textCurrentLoc.x + halfSpriteSize; squareAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_shikaku", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, nullptr); dtParams.textCurrentLoc.x += spriteSize; @@ -352,8 +345,11 @@ namespace TLAC::Components spriteLoc.x = dtParams.textCurrentLoc.x + halfSpriteSize; crossAet = createAetLayer(3, 0x19, CREATEAET_20000, "button_batsu", &spriteLoc, 0, nullptr, nullptr, 0, 0, &spriteScale, nullptr); dtParams.textCurrentLoc.x += spriteSize; - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_XADVANCE), L":Close "); - + 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); dtParams.textCurrentLoc.x += spriteSize; From b5b0af0e15c2222a6ddab0fc6177999e4e756c73 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Wed, 23 Oct 2019 11:17:58 +1100 Subject: [PATCH 31/44] pause: pause on focus lost (+ some minor cleanup) --- .../source/plugins/TLAC/Components/Pause.cpp | 19 +++++++++++++++++-- .../source/plugins/TLAC/Components/Pause.h | 10 ++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index 593ef69..a2ede51 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -14,6 +14,10 @@ namespace TLAC::Components bool Pause::isPaused = false; bool Pause::giveUp = false; bool Pause::showUI = true; + int Pause::triangleAet = 0; + int Pause::squareAet = 0; + int Pause::crossAet = 0; + int Pause::circleAet = 0; int Pause::curMenuPos = 0; int Pause::mainMenuPos = 0; Pause::menusets Pause::curMenuSet = MENUSET_MAIN; @@ -125,7 +129,7 @@ namespace TLAC::Components } // always exit pause if key is tapped or no longer in game somehow - if (isPauseKeyTapped() || *(GameState*)CURRENT_GAME_STATE_ADDRESS != GS_GAME || *(SubGameState*)CURRENT_GAME_SUB_STATE_ADDRESS != SUB_GAME_MAIN) + if (isPauseKeyTapped() || !isInGame()) { pause = false; } @@ -221,7 +225,7 @@ namespace TLAC::Components filteredButtons = (JvsButtons)(filteredButtons & ~inputState->Tapped.Buttons); // only enter pause if in game - if (*(GameState*)CURRENT_GAME_STATE_ADDRESS == GS_GAME && *(SubGameState*)CURRENT_GAME_SUB_STATE_ADDRESS == SUB_GAME_MAIN) + if (isInGame()) { if (isPauseKeyTapped()) { @@ -357,11 +361,22 @@ namespace TLAC::Components } } + void Pause::OnFocusLost() + { + if (isInGame()) + pause = true; + } + bool Pause::isPauseKeyTapped() { return inputState->Tapped.Buttons & JVS_START; } + bool Pause::isInGame() + { + return *(GameState*)CURRENT_GAME_STATE_ADDRESS == GS_GAME && *(SubGameState*)CURRENT_GAME_SUB_STATE_ADDRESS == SUB_GAME_MAIN; + } + bool Pause::hookedGiveUpFunc(void* cls) { if (giveUp) diff --git a/source-code/source/plugins/TLAC/Components/Pause.h b/source-code/source/plugins/TLAC/Components/Pause.h index 6f0d9b2..fbe4072 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.h +++ b/source-code/source/plugins/TLAC/Components/Pause.h @@ -22,12 +22,14 @@ namespace TLAC::Components virtual void Update() override; virtual void UpdatePostInput() override; virtual void UpdateDraw2D() override; + virtual void OnFocusLost() override; static bool pause; // set pause to change pause state static bool giveUp; // set give up to end current song private: // this is a mess of static so that menuItems can work static bool isPauseKeyTapped(); + static bool isInGame(); static std::vector streamPlayStates; static void InjectCode(void* address, const std::vector data); @@ -62,10 +64,10 @@ namespace TLAC::Components static bool showUI; - int triangleAet; - int squareAet; - int crossAet; - int circleAet; + static int triangleAet; + static int squareAet; + static int crossAet; + static int circleAet; enum menusets { From 73c3af7bc04a189d4c05ce65d7e54ad361df8230 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Wed, 23 Oct 2019 12:28:29 +1100 Subject: [PATCH 32/44] pause: support all aspect ratios --- .../source/plugins/TLAC/Components/Drawing.h | 5 ++++- .../source/plugins/TLAC/Components/Pause.cpp | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Drawing.h b/source-code/source/plugins/TLAC/Components/Drawing.h index 1ef1242..0c5bd73 100644 --- a/source-code/source/plugins/TLAC/Components/Drawing.h +++ b/source-code/source/plugins/TLAC/Components/Drawing.h @@ -75,7 +75,7 @@ namespace TLAC::Components { uint32_t colour; // RGBA byte array?, so set as 0xAABBGGRR uint32_t fillColour; // ?? RGBA byte array?, so set as 0xAABBGGRR - uint8_t unk08; + uint8_t unk08; // seems to enable DRAWTEXT_MEASURE uint8_t unk09[0x3]; uint32_t unk0c; uint32_t unk10; @@ -188,6 +188,9 @@ namespace TLAC::Components DRAWTEXT_ENABLE_XADVANCE = 1, DRAWTEXT_ALIGN_RIGHT = 2, DRAWTEXT_ALIGN_CENTRE = 8, + DRAWTEXT_MEASURE = 0x200, + DRAWTEXT_SCALING_OPTIMISED = 0x400, // ? -- seems to be set if the requested font size doesn't match the original font, and the internal width/height 1 and 2 match + // maybe it's just required for any scaling though DRAWTEXT_STROKE = 0x10000, }; diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index a2ede51..db817a1 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -251,10 +251,15 @@ namespace TLAC::Components DrawParams dtParams(&fontInfo); dtParams.layer = bgLayer; + // get aspect ratio + float aspect = *(float*)UI_ASPECT_RATIO; + // bg rect + float bgWidth = aspect * 720 + 2; // add a couple of pixels to protect against rounding errors + float bgLeft = -(bgWidth - 1280) / 2; // 0,0 is in the corner of a 720p view.. half of the extra over 1280 wide is the horizontal offset to centre the bg RectangleBounds rect; - rect = { 0, 0, 1280, 720 }; + rect = { bgLeft, 0, bgWidth, 720 }; dtParams.colour = 0xa0000000; dtParams.fillColour = 0xa0000000; fillRectangle(&dtParams, &rect); @@ -330,8 +335,14 @@ namespace TLAC::Components destroyAetLayer(crossAet); destroyAetLayer(circleAet); + float textLeft; + if (aspect > 16.0f / 9.0f) + textLeft = 32; + else + textLeft = (1280 - bgWidth) / 2 + 32; // 0,0 is in the corner of a 720p view.. half of the difference to 1280 wide is the horizontal offset to the window corner + fontInfo.setSize(18, 18); - dtParams.textCurrentLoc = { 32, 720 - 40 }; + dtParams.textCurrentLoc = { textLeft, 720 - 40 }; dtParams.lineOriginLoc = dtParams.textCurrentLoc; const float spriteSize = 18; const float halfSpriteSize = spriteSize / 2; From 9e800103f9dcff489c81d8f3f3420249cf311e3c Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Wed, 23 Oct 2019 22:20:11 +1100 Subject: [PATCH 33/44] pause: add heading text to submenus --- .../source/plugins/TLAC/Components/Pause.cpp | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index db817a1..062cca1 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -290,8 +290,12 @@ namespace TLAC::Components dtParams.layer = contentLayer; // selection cursor - int selectBoxOrigin = menuY - menuItemHeight * (menu[curMenuSet].items.size() / 2.0) - (menuItemHeight - menuTextSize) / 2; - int selectBoxPos = selectBoxOrigin + menuItemHeight * curMenuPos; + int menuOrigin = menuY - menuItemHeight * (menu[curMenuSet].items.size() / 2.0); + if (curMenuSet != MENUSET_MAIN) + { + menuOrigin += menuItemHeight * 0.4; + } + int selectBoxPos = menuOrigin - (menuItemHeight - menuTextSize) / 2 + menuItemHeight * curMenuPos; const float selectBoxWidth = 200; const float selectBoxHeight = menuItemHeight; const float selectBoxThickness = 2; @@ -307,10 +311,20 @@ namespace TLAC::Components // menu fontInfo.setSize(menuTextSize, menuTextSize); - - dtParams.textCurrentLoc = { menuX, menuY - menuItemHeight * (menu[curMenuSet].items.size() / 2.0f) }; + + dtParams.textCurrentLoc = { menuX, (float)menuOrigin }; dtParams.lineOriginLoc = dtParams.textCurrentLoc; + if (curMenuSet != MENUSET_MAIN) + { + dtParams.textCurrentLoc.y -= menuItemHeight * 1.333f; + dtParams.lineOriginLoc.y = dtParams.textCurrentLoc.y; + dtParams.colour = 0xffffffff; + drawText(&dtParams, (drawTextFlags)(DRAWTEXT_ALIGN_CENTRE | DRAWTEXT_STROKE), menu[curMenuSet].name); + dtParams.textCurrentLoc.y += menuItemHeight * 1.333f; + dtParams.lineOriginLoc.y = dtParams.textCurrentLoc.y; + } + for (int i = 0; i < menu[curMenuSet].items.size(); i++) { if (i == curMenuPos) @@ -327,7 +341,7 @@ namespace TLAC::Components dtParams.textCurrentLoc.y += menuItemHeight; dtParams.lineOriginLoc = dtParams.textCurrentLoc; } - + // key legend destroyAetLayer(triangleAet); From 501135cc20501ce70c8bd5eb2edd172fa6ab2a1c Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Wed, 23 Oct 2019 22:21:25 +1100 Subject: [PATCH 34/44] tlac drawing: add drawText functions for strings with formatting/sprite escapes --- .../source/plugins/TLAC/Components/Drawing.h | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Drawing.h b/source-code/source/plugins/TLAC/Components/Drawing.h index 0c5bd73..5c61cc8 100644 --- a/source-code/source/plugins/TLAC/Components/Drawing.h +++ b/source-code/source/plugins/TLAC/Components/Drawing.h @@ -91,7 +91,7 @@ namespace TLAC::Components Point textCurrentLoc; Point lineOriginLoc; // must be set for newlines to work as expected uint8_t padding3c[0x4]; - uint64_t unk40; + uint64_t lineLength; // in characters FontInfo* font; uint16_t unk50; @@ -110,7 +110,7 @@ namespace TLAC::Components unk28 = 0; textCurrentLoc = { 0, 0 }; lineOriginLoc = { 0, 0 }; - unk40 = 0; + lineLength = 0; font = fi; unk50 = 0x25a1; } @@ -187,6 +187,7 @@ namespace TLAC::Components { DRAWTEXT_ENABLE_XADVANCE = 1, DRAWTEXT_ALIGN_RIGHT = 2, + DRAWTEXT_ALIGN_SCREEN_CENTRE = 4, DRAWTEXT_ALIGN_CENTRE = 8, DRAWTEXT_MEASURE = 0x200, DRAWTEXT_SCALING_OPTIMISED = 0x400, // ? -- seems to be set if the requested font size doesn't match the original font, and the internal width/height 1 and 2 match @@ -198,7 +199,6 @@ namespace TLAC::Components { ((void(*)(DrawParams*, uint32_t, const char*, int64_t))0x140198500)(dtParam, flags, str.c_str(), str.length()); } - void drawTextW(DrawParams* dtParam, drawTextFlags flags, std::wstring str) { const wchar_t* ptrs[2]; @@ -207,7 +207,25 @@ namespace TLAC::Components ((void(*)(DrawParams*, uint32_t, const wchar_t**))0x140198380)(dtParam, flags, &ptrs[0]); } - //void(*drawTextW)(DrawParams* dtParam, drawTextFlags flags, MsStringW str) = (void(*)(DrawParams* dtParam, drawTextFlags flags, MsStringW str))0x140198380; + + void drawTextFormattedW(DrawParams* dtParam, drawTextFlags flags, std::wstring str) + { + const wchar_t* ptrs[2]; + ptrs[0] = str.c_str(); + ptrs[1] = (wchar_t*)((uint64_t)ptrs[0] + str.length() * 2); + + ((void(*)(uint32_t, const wchar_t**, DrawParams*))0x1404c2aa0)(flags, &ptrs[0], dtParam); + } + + void drawTextWithSpritesW(DrawParams* dtParam, drawTextFlags flags, std::wstring str) + { + const wchar_t* ptrs[2]; + ptrs[0] = str.c_str(); + ptrs[1] = (wchar_t*)((uint64_t)ptrs[0] + str.length() * 2); + + ((void(*)(uint32_t, const wchar_t**, DrawParams*))0x1404c2cf0)(flags, &ptrs[0], dtParam); + } + struct RectangleBounds { From bb683c22521454285fc56ae1820d6f54e40e6117 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Thu, 24 Oct 2019 17:35:47 +1100 Subject: [PATCH 35/44] tlac drawing: proper support for different aet files --- .../source/plugins/TLAC/Components/Drawing.h | 201 ++++++++++++------ .../source/plugins/TLAC/Components/Pause.cpp | 36 +++- .../source/plugins/TLAC/Components/Pause.h | 4 +- 3 files changed, 162 insertions(+), 79 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Drawing.h b/source-code/source/plugins/TLAC/Components/Drawing.h index 5c61cc8..a8d0a6d 100644 --- a/source-code/source/plugins/TLAC/Components/Drawing.h +++ b/source-code/source/plugins/TLAC/Components/Drawing.h @@ -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) diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index 062cca1..3c2039a 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -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"); } diff --git a/source-code/source/plugins/TLAC/Components/Pause.h b/source-code/source/plugins/TLAC/Components/Pause.h index fbe4072..3bcc855 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.h +++ b/source-code/source/plugins/TLAC/Components/Pause.h @@ -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 @@ -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); }; From 000065ed144e89923b05bb363f92d992c90b5d23 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Thu, 24 Oct 2019 18:58:30 +1100 Subject: [PATCH 36/44] tlac: add some extra drawing stuff, change drawing signatures to allow inline points/rects --- .../source/plugins/TLAC/Components/Drawing.h | 84 +++++++++++-------- .../source/plugins/TLAC/Components/Pause.cpp | 10 +-- 2 files changed, 52 insertions(+), 42 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Drawing.h b/source-code/source/plugins/TLAC/Components/Drawing.h index a8d0a6d..c446540 100644 --- a/source-code/source/plugins/TLAC/Components/Drawing.h +++ b/source-code/source/plugins/TLAC/Components/Drawing.h @@ -1,6 +1,7 @@ #pragma once #include #include +#include namespace TLAC::Components { @@ -10,6 +11,13 @@ namespace TLAC::Components float x; float y; }; + struct RectangleBounds + { + float x; + float y; + float width; + float height; + }; struct RawFont { @@ -75,12 +83,9 @@ namespace TLAC::Components { uint32_t colour; // RGBA byte array?, so set as 0xAABBGGRR uint32_t fillColour; // ?? RGBA byte array?, so set as 0xAABBGGRR - uint8_t unk08; // seems to enable DRAWTEXT_MEASURE + uint8_t clip; uint8_t unk09[0x3]; - uint32_t unk0c; - uint32_t unk10; - uint32_t unk14; - uint32_t unk18; + RectangleBounds clipRect; uint32_t layer; // 8 seems similar to default but higher // 0x18 is below 0x19 but still seems to be above any game elements // 0x19 is startup screen (below dwgui) @@ -99,11 +104,8 @@ namespace TLAC::Components { colour = 0xffffffff; fillColour = 0xff808080; // except it's not? - unk08 = 0; - unk0c = 0; - unk10 = 0; - unk14 = 0; - unk18 = 0; + clip = 0; + clipRect = { 0, 0, 0, 0 }; layer = 0x7; unk20 = 0x0; unk24 = 0xd; @@ -127,7 +129,7 @@ namespace TLAC::Components DRAWTEXT_ALIGN_RIGHT = 2, DRAWTEXT_ALIGN_SCREEN_CENTRE = 4, DRAWTEXT_ALIGN_CENTRE = 8, - DRAWTEXT_MEASURE = 0x200, + DRAWTEXT_ENABLE_CLIP = 0x200, DRAWTEXT_SCALING_OPTIMISED = 0x400, // ? -- seems to be set if the requested font size doesn't match the original font, and the internal width/height 1 and 2 match // maybe it's just required for any scaling though DRAWTEXT_STROKE = 0x10000, @@ -165,43 +167,51 @@ namespace TLAC::Components } - struct RectangleBounds - { - float x; - float y; - float width; - float height; - }; - void(*fillRectangle)(DrawParams* dtParam, const RectangleBounds* rect) = (void(*)(DrawParams* dtParam, const RectangleBounds* rect))0x140198d80; + void(*fillRectangle)(DrawParams* dtParam, const RectangleBounds &rect) = (void(*)(DrawParams* dtParam, const RectangleBounds &rect))0x140198d80; // draws only a border -- use fillRectangle to fill contained pixels - void drawRectangle(DrawParams* dtParam, const RectangleBounds* rect) + void drawRectangle(DrawParams* dtParam, const RectangleBounds &rect) { - ((void(*)(DrawParams*, const RectangleBounds*))0x140198320)(dtParam, rect); + ((void(*)(DrawParams*, const RectangleBounds&))0x140198320)(dtParam, rect); } // draws only a border -- use fillRectangle to fill contained pixels - void drawRectangle(DrawParams* dtParam, const RectangleBounds* rect, float thickness) + void drawRectangle(DrawParams* dtParam, const RectangleBounds &rect, float thickness) { uint32_t oldFillColour = dtParam->fillColour; dtParam->fillColour = dtParam->colour; // yes this seems pretty dodgy, but sega does it this way so... I guess it's the only way - RectangleBounds tempRect = { rect->x, rect->y, thickness, rect->height }; // left side - fillRectangle(dtParam, &tempRect); + RectangleBounds tempRect = { rect.x, rect.y, thickness, rect.height }; // left side + fillRectangle(dtParam, tempRect); - tempRect.x = rect->x + rect->width - thickness; // right side - fillRectangle(dtParam, &tempRect); + tempRect.x = rect.x + rect.width - thickness; // right side + fillRectangle(dtParam, tempRect); - tempRect = { rect->x + thickness, rect->y, rect->width - (thickness * 2), thickness }; // top side - fillRectangle(dtParam, &tempRect); + tempRect = { rect.x + thickness, rect.y, rect.width - (thickness * 2), thickness }; // top side + fillRectangle(dtParam, tempRect); - tempRect.y = rect->y + rect->height - thickness; // left side - fillRectangle(dtParam, &tempRect); + tempRect.y = rect.y + rect.height - thickness; // left side + fillRectangle(dtParam, tempRect); dtParam->fillColour = oldFillColour; } + + void drawLine(DrawParams* dtParam, const Point &p1, const Point &p2) + { + ((void(*)(DrawParams*, const RectangleBounds&))0x140198080)(dtParam, { p1.x, p1.y, p2.x, p2.y }); + } + // draw from the top left corner of rect to the bottom left + void drawLine(DrawParams* dtParam, const RectangleBounds &rect) + { + drawLine(dtParam, { rect.x, rect.y }, { rect.x + rect.width, rect.y + rect.height }); + } + + void drawPolyline(DrawParams* dtParam, const std::vector points) + { + ((void(*)(DrawParams*, const Point*, uint64_t))0x1401980e0)(dtParam, points.data(), points.size()); + } struct MsString { @@ -332,24 +342,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 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) + 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)(fileId, 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(int32_t fileId, 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(fileId, drawLayer, flags, name, loc, 0, 0, 0, animationInTime, animationOutTime, 0, 0); + return createAetLayer(fileId, drawLayer, flags, name, loc, 0, 0, 0, animationInTime, animationOutTime, *(Point*)0, 0); } // draw an aet layer (with scale) - int createAetLayer(int32_t fileId, 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(fileId, drawLayer, flags, name, loc, 0, 0, 0, -1, -1, scale, 0); } // draw an aet layer - int createAetLayer(int32_t fileId, 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(fileId, drawLayer, flags, name, loc, 0, 0, 0, -1, -1, 0, 0); + return createAetLayer(fileId, drawLayer, flags, name, loc, 0, 0, 0, -1, -1, *(Point*)0, 0); } void destroyAetLayer(int &layer) diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index 3c2039a..74d24e9 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -267,7 +267,7 @@ namespace TLAC::Components rect = { bgLeft, 0, bgWidth, 720 }; dtParams.colour = 0xa0000000; dtParams.fillColour = 0xa0000000; - fillRectangle(&dtParams, &rect); + fillRectangle(&dtParams, rect); // pause icon @@ -326,7 +326,7 @@ namespace TLAC::Components rect = { selectBoxX, selectBoxY, selectBoxWidth, selectBoxHeight }; dtParams.colour = 0xc0ffff00; dtParams.fillColour = 0xc0ffff00; - drawRectangle(&dtParams, &rect, selectBoxThickness); + drawRectangle(&dtParams, rect, selectBoxThickness); // menu @@ -387,12 +387,12 @@ namespace TLAC::Components drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_XADVANCE), L"L/R:Move "); aetLoc.x = dtParams.textCurrentLoc.x + halfSpriteSize; - squareAet = createAetLayer(3, dtParams.layer, CREATEAET_20000, "button_shikaku", &aetLoc, 0, nullptr, nullptr, 0, 0, &aetScale, nullptr); + 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 "); aetLoc.x = dtParams.textCurrentLoc.x + halfSpriteSize; - crossAet = createAetLayer(3, dtParams.layer, CREATEAET_20000, "button_batsu", &aetLoc, 0, nullptr, nullptr, 0, 0, &aetScale, nullptr); + 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 "); @@ -400,7 +400,7 @@ namespace TLAC::Components drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_XADVANCE), L":Back "); aetLoc.x = dtParams.textCurrentLoc.x + halfSpriteSize; - circleAet = createAetLayer(3, dtParams.layer, CREATEAET_20000, "button_maru", &aetLoc, 0, nullptr, nullptr, 0, 0, &aetScale, nullptr); + 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"); } From 4da730261f65e70b62433bf3f5daf8fb99703beb Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Thu, 24 Oct 2019 23:06:03 +1100 Subject: [PATCH 37/44] pause: improve layout and add some lines as decoration partial code for a decent looking box is included but commented out because the asset isn't loaded in-game --- .../source/plugins/TLAC/Components/Pause.cpp | 104 ++++++++++++++---- .../source/plugins/TLAC/Components/Pause.h | 7 +- 2 files changed, 90 insertions(+), 21 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index 74d24e9..e624fef 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -14,7 +14,10 @@ namespace TLAC::Components bool Pause::isPaused = false; bool Pause::giveUp = false; bool Pause::showUI = true; - int Pause::keyWinAet = 0; + int Pause::selResultAet1 = 0; + int Pause::selResultAet2 = 0; + int Pause::selResultAet3 = 0; + int Pause::selResultAet4 = 0; int Pause::triangleAet = 0; int Pause::squareAet = 0; int Pause::crossAet = 0; @@ -146,7 +149,12 @@ namespace TLAC::Components else { // clear these from the screen too - destroyAetLayer(keyWinAet); + /* + destroyAetLayer(selResultAet1); + destroyAetLayer(selResultAet2); + destroyAetLayer(selResultAet3); + destroyAetLayer(selResultAet4); + */ destroyAetLayer(triangleAet); destroyAetLayer(squareAet); destroyAetLayer(crossAet); @@ -206,7 +214,7 @@ namespace TLAC::Components InjectCode(framespeedPatchAddress, origFramespeedOp); uint64_t audioMixerAddr = *(uint64_t*)(AUDIO_MAIN_CLASS_ADDRESS + 0x70); - uint64_t audioStreamsAddress = *(uint64_t*)(audioMixerAddr + 0x18);; + uint64_t audioStreamsAddress = *(uint64_t*)(audioMixerAddr + 0x18); int nAudioStreams = *(uint64_t*)(audioMixerAddr + 0x20); for (int i = 0; i < nAudioStreams; i++) { @@ -215,7 +223,12 @@ namespace TLAC::Components *playstate = streamPlayStates[i]; } - destroyAetLayer(keyWinAet); + /* + destroyAetLayer(selResultAet1); + destroyAetLayer(selResultAet2); + destroyAetLayer(selResultAet3); + destroyAetLayer(selResultAet4); + */ destroyAetLayer(triangleAet); destroyAetLayer(squareAet); destroyAetLayer(crossAet); @@ -253,7 +266,7 @@ namespace TLAC::Components FontInfo fontInfo(0x11); DrawParams dtParams(&fontInfo); dtParams.layer = bgLayer; - Point aetScale = { 0.66667, 0.7 }; + Point aetScale = { 0.65, 0.65 }; Point aetLoc = { (1280 - aetScale.x * 1280) / 2, (720 - aetScale.y * 720) / 2 }; // get aspect ratio @@ -265,8 +278,8 @@ namespace TLAC::Components float bgLeft = -(bgWidth - 1280) / 2; // 0,0 is in the corner of a 720p view.. half of the extra over 1280 wide is the horizontal offset to centre the bg RectangleBounds rect; rect = { bgLeft, 0, bgWidth, 720 }; - dtParams.colour = 0xa0000000; - dtParams.fillColour = 0xa0000000; + dtParams.colour = 0xc0000000; + dtParams.fillColour = dtParams.colour; fillRectangle(&dtParams, rect); @@ -296,27 +309,78 @@ namespace TLAC::Components // bg box /* - static int keyWinFile = 0; - if (keyWinFile == 0) + static int selResultFile = 0; + if (selResultFile == 0) { - keyWinFile = findAetFileId("AET_KEY_WIN_MAIN"); + //keyWinFile = findAetFileId("AET_KEY_WIN_MAIN"); + selResultFile = findAetFileId("AET_SEL_RESULT_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); + destroyAetLayer(selResultAet1); + destroyAetLayer(selResultAet2); + destroyAetLayer(selResultAet3); + destroyAetLayer(selResultAet4); + if (selResultFile != -1) + { + //keyWinAet = createAetLayer(keyWinFile, dtParams.layer, CREATEAET_20000, "win_in", aetLoc, 0, nullptr, nullptr, 3.7, 3.7, aetScale, 0); + aetScale = { 0.47f, 0.47f }; + aetLoc = { (1280 - aetScale.x * 1280) / 2, (720 - aetScale.y * 720) / 2 + 72 * aetScale.y }; + float animPos = 7.2; + selResultAet1 = createAetLayer(selResultFile, dtParams.layer, CREATEAET_20000, "window_in", aetLoc, 0, nullptr, nullptr, animPos, animPos, aetScale, 0); + selResultAet2 = createAetLayer(selResultFile, dtParams.layer, CREATEAET_20000, "window_in", aetLoc, 0, nullptr, nullptr, animPos, animPos, aetScale, 0); + selResultAet3 = createAetLayer(selResultFile, dtParams.layer, CREATEAET_20000, "window_in", aetLoc, 0, nullptr, nullptr, animPos, animPos, aetScale, 0); + selResultAet4 = createAetLayer(selResultFile, dtParams.layer, CREATEAET_20000, "window_in", aetLoc, 0, nullptr, nullptr, animPos, animPos, aetScale, 0); + } */ + dtParams.colour = 0xffffff00; + drawPolyline(&dtParams, { + { 537, 255 }, + { 793, 255 }, + { 759, 453 }, + { 744, 465 }, + { 487, 465 }, + { 522, 267 }, + { 537, 255 }, + }); + drawPolyline(&dtParams, { + { 537 - .7f, 255 - 2 }, + { 793 + 2.38f, 255 - 2 }, + { 759 + 2.1f, 453 + 1.15f }, + { 744 + .7f, 465 + 2 }, + { 487 - 2.38f, 465 + 2 }, + { 522 - 2.1f, 267 - 1.15f }, + { 537 - .7f, 255 - 2 }, + }); + drawPolyline(&dtParams, { + { 548, 258 }, + { 768, 258 }, + { 774, 265 }, + { 770, 286 }, + { 764, 286 }, + { 737, 434 }, + { 743, 434 }, + { 739, 455 }, + { 733, 462 }, + { 513, 462 }, + { 507, 455 }, + { 511, 434 }, + { 517, 434 }, + { 544, 286 }, + { 538, 286 }, + { 542, 265 }, + { 548, 258 }, + }); // selection cursor - int menuOrigin = menuY - menuItemHeight * (menu[curMenuSet].items.size() / 2.0); + int menuOrigin = menuY - menuItemTotalHeight * (menu[curMenuSet].items.size() / 2.0) + menuItemTotalHeight / 2 - menuTextSize / 2; if (curMenuSet != MENUSET_MAIN) { - menuOrigin += menuItemHeight * 0.4; + menuOrigin += menuItemTotalHeight * 1.2 / 2; } - int selectBoxPos = menuOrigin - (menuItemHeight - menuTextSize) / 2 + menuItemHeight * curMenuPos; - const float selectBoxWidth = 200; + int selectBoxPos = menuOrigin - (menuItemHeight - menuTextSize) / 2 + menuItemTotalHeight * curMenuPos; + const float selectBoxWidth = 150; const float selectBoxHeight = menuItemHeight; const float selectBoxThickness = 2; @@ -337,11 +401,11 @@ namespace TLAC::Components if (curMenuSet != MENUSET_MAIN) { - dtParams.textCurrentLoc.y -= menuItemHeight * 1.333f; + dtParams.textCurrentLoc.y -= menuItemTotalHeight * 1.2f; dtParams.lineOriginLoc.y = dtParams.textCurrentLoc.y; dtParams.colour = 0xffffffff; drawText(&dtParams, (drawTextFlags)(DRAWTEXT_ALIGN_CENTRE | DRAWTEXT_STROKE), menu[curMenuSet].name); - dtParams.textCurrentLoc.y += menuItemHeight * 1.333f; + dtParams.textCurrentLoc.y += menuItemTotalHeight * 1.2f; dtParams.lineOriginLoc.y = dtParams.textCurrentLoc.y; } @@ -358,7 +422,7 @@ namespace TLAC::Components } drawText(&dtParams, (drawTextFlags)(DRAWTEXT_ALIGN_CENTRE), menu[curMenuSet].items[i].name); - dtParams.textCurrentLoc.y += menuItemHeight; + dtParams.textCurrentLoc.y += menuItemTotalHeight; dtParams.lineOriginLoc = dtParams.textCurrentLoc; } diff --git a/source-code/source/plugins/TLAC/Components/Pause.h b/source-code/source/plugins/TLAC/Components/Pause.h index 3bcc855..90e5f4c 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.h +++ b/source-code/source/plugins/TLAC/Components/Pause.h @@ -58,6 +58,8 @@ namespace TLAC::Components static const int menuX = 640; static const int menuY = 360; static const int menuItemHeight = 36; + static const int menuItemPadding = 12; + static const int menuItemTotalHeight = menuItemHeight + menuItemPadding; static const int menuTextSize = 24; static const uint32_t bgLayer = 0x18; @@ -65,7 +67,10 @@ namespace TLAC::Components static bool showUI; - static int keyWinAet; + static int selResultAet1; + static int selResultAet2; + static int selResultAet3; + static int selResultAet4; static int triangleAet; static int squareAet; static int crossAet; From 02967e7e03b2efde3477e25209497d3296af5d6b Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Fri, 25 Oct 2019 06:47:34 +1100 Subject: [PATCH 38/44] pause: make the cursor and items look nicer (ignore the crackhead math) --- .../source/plugins/TLAC/Components/Pause.cpp | 79 ++++++++++++------- 1 file changed, 49 insertions(+), 30 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index e624fef..115c8ac 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -333,22 +333,23 @@ namespace TLAC::Components selResultAet4 = createAetLayer(selResultFile, dtParams.layer, CREATEAET_20000, "window_in", aetLoc, 0, nullptr, nullptr, animPos, animPos, aetScale, 0); } */ + dtParams.colour = 0xffffff00; drawPolyline(&dtParams, { { 537, 255 }, - { 793, 255 }, - { 759, 453 }, - { 744, 465 }, - { 487, 465 }, + { 794, 255 }, + { 759, 454 }, + { 744, 466 }, + { 487, 466 }, { 522, 267 }, { 537, 255 }, }); drawPolyline(&dtParams, { { 537 - .7f, 255 - 2 }, - { 793 + 2.38f, 255 - 2 }, - { 759 + 2.1f, 453 + 1.15f }, - { 744 + .7f, 465 + 2 }, - { 487 - 2.38f, 465 + 2 }, + { 794 + 2.38f, 255 - 2 }, + { 759 + 2.1f, 454 + 1.15f }, + { 744 + .7f, 466 + 2 }, + { 487 - 2.38f, 466 + 2 }, { 522 - 2.1f, 267 - 1.15f }, { 537 - .7f, 255 - 2 }, }); @@ -358,14 +359,14 @@ namespace TLAC::Components { 774, 265 }, { 770, 286 }, { 764, 286 }, - { 737, 434 }, - { 743, 434 }, - { 739, 455 }, - { 733, 462 }, - { 513, 462 }, - { 507, 455 }, - { 511, 434 }, - { 517, 434 }, + { 737, 435 }, + { 743, 435 }, + { 739, 456 }, + { 733, 463 }, + { 513, 463 }, + { 507, 456 }, + { 511, 435 }, + { 517, 435 }, { 544, 286 }, { 538, 286 }, { 542, 265 }, @@ -373,42 +374,59 @@ namespace TLAC::Components }); + const float slant = 35.0f / 199.0f; // selection cursor - int menuOrigin = menuY - menuItemTotalHeight * (menu[curMenuSet].items.size() / 2.0) + menuItemTotalHeight / 2 - menuTextSize / 2; + int menuOriginY = menuY - menuItemTotalHeight * (menu[curMenuSet].items.size() / 2.0) + menuItemTotalHeight / 2 - menuTextSize / 2; if (curMenuSet != MENUSET_MAIN) { - menuOrigin += menuItemTotalHeight * 1.2 / 2; + menuOriginY += menuItemTotalHeight * 1.2 / 2; } - int selectBoxPos = menuOrigin - (menuItemHeight - menuTextSize) / 2 + menuItemTotalHeight * curMenuPos; + int menuOriginX = menuX + (menuY - menuOriginY + menuTextSize / 2) * slant; const float selectBoxWidth = 150; const float selectBoxHeight = menuItemHeight; const float selectBoxThickness = 2; - const float selectBoxX = menuX - selectBoxWidth / 2; - const float selectBoxY = selectBoxPos; + float selectBoxX = menuOriginX - (menuItemTotalHeight * curMenuPos * slant) - selectBoxWidth / 2; + float selectBoxY = menuOriginY - (menuItemHeight - menuTextSize) / 2 + menuItemTotalHeight * curMenuPos; - rect = { selectBoxX, selectBoxY, selectBoxWidth, selectBoxHeight }; + //rect = { selectBoxX, selectBoxY, selectBoxWidth, selectBoxHeight }; dtParams.colour = 0xc0ffff00; dtParams.fillColour = 0xc0ffff00; - drawRectangle(&dtParams, rect, selectBoxThickness); + //drawRectangle(&dtParams, rect, selectBoxThickness); + drawPolyline(&dtParams, { + { selectBoxX + (selectBoxHeight - 8) * slant + 8 * 15 / 12, selectBoxY }, + { selectBoxX + selectBoxWidth, selectBoxY }, + { selectBoxX + selectBoxWidth - (selectBoxHeight - 8) * slant, selectBoxY + selectBoxHeight - 8 }, + { selectBoxX + selectBoxWidth - (selectBoxHeight - 8) * slant - 8 * 15 / 12, selectBoxY + selectBoxHeight }, + { selectBoxX, selectBoxY + selectBoxHeight }, + { selectBoxX + (selectBoxHeight - 8) * slant, selectBoxY + 8 }, + { selectBoxX + (selectBoxHeight - 8) * slant + 8 * 15 / 12, selectBoxY }, + }); + drawPolyline(&dtParams, { + { selectBoxX + (selectBoxHeight - 8) * slant + 8 * 15 / 12 - .7f, selectBoxY - 2 }, + { selectBoxX + selectBoxWidth + 2.38f, selectBoxY - 2 }, + { selectBoxX + selectBoxWidth - (selectBoxHeight - 8) * slant + 2.1f, selectBoxY + selectBoxHeight - 8 + 1.15f }, + { selectBoxX + selectBoxWidth - (selectBoxHeight - 8) * slant - 8 * 15 / 12 + .7f, selectBoxY + selectBoxHeight + 2 }, + { selectBoxX - 2.38f, selectBoxY + selectBoxHeight + 2 }, + { selectBoxX + (selectBoxHeight - 8) * slant - 2.1f, selectBoxY + 8 - 1.15f }, + { selectBoxX + (selectBoxHeight - 8) * slant + 8 * 15 / 12 - .7f, selectBoxY - 2 }, + }); // menu fontInfo.setSize(menuTextSize, menuTextSize); - - dtParams.textCurrentLoc = { menuX, (float)menuOrigin }; - dtParams.lineOriginLoc = dtParams.textCurrentLoc; if (curMenuSet != MENUSET_MAIN) { - dtParams.textCurrentLoc.y -= menuItemTotalHeight * 1.2f; + dtParams.textCurrentLoc = { menuX + 90 * slant, menuY - 90 }; dtParams.lineOriginLoc.y = dtParams.textCurrentLoc.y; dtParams.colour = 0xffffffff; drawText(&dtParams, (drawTextFlags)(DRAWTEXT_ALIGN_CENTRE | DRAWTEXT_STROKE), menu[curMenuSet].name); - dtParams.textCurrentLoc.y += menuItemTotalHeight * 1.2f; - dtParams.lineOriginLoc.y = dtParams.textCurrentLoc.y; } - + + dtParams.textCurrentLoc = { (float)menuOriginX, (float)menuOriginY }; + dtParams.lineOriginLoc = dtParams.textCurrentLoc; + for (int i = 0; i < menu[curMenuSet].items.size(); i++) { if (i == curMenuPos) @@ -422,6 +440,7 @@ namespace TLAC::Components } drawText(&dtParams, (drawTextFlags)(DRAWTEXT_ALIGN_CENTRE), menu[curMenuSet].items[i].name); + dtParams.textCurrentLoc.x -= (menuItemTotalHeight * slant); dtParams.textCurrentLoc.y += menuItemTotalHeight; dtParams.lineOriginLoc = dtParams.textCurrentLoc; } From ebc5baa13291374613fca59dc5c17e9c6aa0f3e5 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Fri, 25 Oct 2019 23:04:28 +1100 Subject: [PATCH 39/44] tlac: move drawing to utilities as its own class (rather than littering the components namespace), simplify menu coordinates management of pause --- .../source/plugins/TLAC/Components/Drawing.h | 374 ------------------ .../source/plugins/TLAC/Components/Pause.cpp | 157 ++++---- .../source/plugins/TLAC/Components/Pause.h | 3 + source-code/source/plugins/TLAC/Constants.h | 3 + source-code/source/plugins/TLAC/TLAC.vcxproj | 3 +- .../source/plugins/TLAC/TLAC.vcxproj.filters | 5 +- .../source/plugins/TLAC/Utilities/Drawing.cpp | 160 ++++++++ .../source/plugins/TLAC/Utilities/Drawing.h | 269 +++++++++++++ 8 files changed, 526 insertions(+), 448 deletions(-) delete mode 100644 source-code/source/plugins/TLAC/Components/Drawing.h create mode 100644 source-code/source/plugins/TLAC/Utilities/Drawing.cpp create mode 100644 source-code/source/plugins/TLAC/Utilities/Drawing.h diff --git a/source-code/source/plugins/TLAC/Components/Drawing.h b/source-code/source/plugins/TLAC/Components/Drawing.h deleted file mode 100644 index c446540..0000000 --- a/source-code/source/plugins/TLAC/Components/Drawing.h +++ /dev/null @@ -1,374 +0,0 @@ -#pragma once -#include -#include -#include - -namespace TLAC::Components -{ -#pragma pack(push, 1) - struct Point - { - float x; - float y; - }; - struct RectangleBounds - { - float x; - float y; - float width; - float height; - }; - - struct RawFont - { - uint32_t sprId; // ? - uint8_t width1; // glyph? - uint8_t height1; // glyph? - uint8_t width2; // advance? - uint8_t height2; // advance? - uint8_t metric08; // or flag? - uint8_t metric09; // or flag? - uint8_t padding0a[0x06]; - float metric08divby09; - uint64_t _0x10; - int64_t dataBegin; - int64_t dataEnd; - int64_t dataCapacityEnd; - uint8_t padding38[0x8]; - }; - - struct RawFontHolderIdk // ...SeemsPrettyPointlessTbh - { - RawFont* rawfont; - uint16_t width1; - uint16_t height1; - uint16_t zero1; // ? - uint16_t zero2; // ? - uint8_t zero3; // some kind of flag, but seems unused - }; - - struct FontInfo - { - uint32_t fontId; - uint8_t padding04[0x4]; - RawFont* rawfont; - uint16_t flag10; // (zero3 != 0 && padding38[0] != 0) ? 2 : (metric08 != metric09 ? 1 : 0) - uint8_t padding12[0x02]; - float width1; - float height1; - float width2; - float height2; - float userSizeWidth; - float userSizeHeight; - float userSizeWidthMultiplier; // userSizeWidth / width1 - float userSizeHeightMultiplier; // userSizeHeight / width2 - float zero1; // ? - float zero2; // ? - - void setSize(float width, float height) - { - ((void(*)(FontInfo* fi, float width, float height))0x140199e60)(this, width, height); - } - - FontInfo(uint32_t id) - { - ((FontInfo*(*)(FontInfo* fi, uint32_t id))0x140196510)(this, id); - } - }; - - FontInfo*(*getFont)(FontInfo* fi, uint32_t id) = (FontInfo*(*)(FontInfo* fi, uint32_t id))0x140196510; - void(*fontSize)(FontInfo* fi, float width, float height) = (void(*)(FontInfo* fi, float width, float height))0x140199e60; - - struct DrawParams - { - uint32_t colour; // RGBA byte array?, so set as 0xAABBGGRR - uint32_t fillColour; // ?? RGBA byte array?, so set as 0xAABBGGRR - uint8_t clip; - uint8_t unk09[0x3]; - RectangleBounds clipRect; - uint32_t layer; // 8 seems similar to default but higher - // 0x18 is below 0x19 but still seems to be above any game elements - // 0x19 is startup screen (below dwgui) - // I noticed some use different scaling - uint32_t unk20; - uint32_t unk24; - uint32_t unk28; - Point textCurrentLoc; - Point lineOriginLoc; // must be set for newlines to work as expected - uint8_t padding3c[0x4]; - uint64_t lineLength; // in characters - FontInfo* font; - uint16_t unk50; - - DrawParams(FontInfo* fi) - { - colour = 0xffffffff; - fillColour = 0xff808080; // except it's not? - clip = 0; - clipRect = { 0, 0, 0, 0 }; - layer = 0x7; - unk20 = 0x0; - unk24 = 0xd; - unk28 = 0; - textCurrentLoc = { 0, 0 }; - lineOriginLoc = { 0, 0 }; - lineLength = 0; - font = fi; - unk50 = 0x25a1; - } - - DrawParams() - { - DrawParams((FontInfo*)0x140eda860); - } - }; - - enum drawTextFlags : uint32_t - { - DRAWTEXT_ENABLE_XADVANCE = 1, - DRAWTEXT_ALIGN_RIGHT = 2, - DRAWTEXT_ALIGN_SCREEN_CENTRE = 4, - DRAWTEXT_ALIGN_CENTRE = 8, - DRAWTEXT_ENABLE_CLIP = 0x200, - DRAWTEXT_SCALING_OPTIMISED = 0x400, // ? -- seems to be set if the requested font size doesn't match the original font, and the internal width/height 1 and 2 match - // maybe it's just required for any scaling though - DRAWTEXT_STROKE = 0x10000, - }; - - void drawText(DrawParams* dtParam, drawTextFlags flags, std::string str) - { - ((void(*)(DrawParams*, uint32_t, const char*, int64_t))0x140198500)(dtParam, flags, str.c_str(), str.length()); - } - void drawTextW(DrawParams* dtParam, drawTextFlags flags, std::wstring str) - { - const wchar_t* ptrs[2]; - ptrs[0] = str.c_str(); - ptrs[1] = (wchar_t*)((uint64_t)ptrs[0] + str.length() * 2); - - ((void(*)(DrawParams*, uint32_t, const wchar_t**))0x140198380)(dtParam, flags, &ptrs[0]); - } - - void drawTextFormattedW(DrawParams* dtParam, drawTextFlags flags, std::wstring str) - { - const wchar_t* ptrs[2]; - ptrs[0] = str.c_str(); - ptrs[1] = (wchar_t*)((uint64_t)ptrs[0] + str.length() * 2); - - ((void(*)(uint32_t, const wchar_t**, DrawParams*))0x1404c2aa0)(flags, &ptrs[0], dtParam); - } - - void drawTextWithSpritesW(DrawParams* dtParam, drawTextFlags flags, std::wstring str) - { - const wchar_t* ptrs[2]; - ptrs[0] = str.c_str(); - ptrs[1] = (wchar_t*)((uint64_t)ptrs[0] + str.length() * 2); - - ((void(*)(uint32_t, const wchar_t**, DrawParams*))0x1404c2cf0)(flags, &ptrs[0], dtParam); - } - - - void(*fillRectangle)(DrawParams* dtParam, const RectangleBounds &rect) = (void(*)(DrawParams* dtParam, const RectangleBounds &rect))0x140198d80; - - // draws only a border -- use fillRectangle to fill contained pixels - void drawRectangle(DrawParams* dtParam, const RectangleBounds &rect) - { - ((void(*)(DrawParams*, const RectangleBounds&))0x140198320)(dtParam, rect); - } - - // draws only a border -- use fillRectangle to fill contained pixels - void drawRectangle(DrawParams* dtParam, const RectangleBounds &rect, float thickness) - { - uint32_t oldFillColour = dtParam->fillColour; - dtParam->fillColour = dtParam->colour; - - // yes this seems pretty dodgy, but sega does it this way so... I guess it's the only way - RectangleBounds tempRect = { rect.x, rect.y, thickness, rect.height }; // left side - fillRectangle(dtParam, tempRect); - - tempRect.x = rect.x + rect.width - thickness; // right side - fillRectangle(dtParam, tempRect); - - tempRect = { rect.x + thickness, rect.y, rect.width - (thickness * 2), thickness }; // top side - fillRectangle(dtParam, tempRect); - - tempRect.y = rect.y + rect.height - thickness; // left side - fillRectangle(dtParam, tempRect); - - dtParam->fillColour = oldFillColour; - } - - - void drawLine(DrawParams* dtParam, const Point &p1, const Point &p2) - { - ((void(*)(DrawParams*, const RectangleBounds&))0x140198080)(dtParam, { p1.x, p1.y, p2.x, p2.y }); - } - // draw from the top left corner of rect to the bottom left - void drawLine(DrawParams* dtParam, const RectangleBounds &rect) - { - drawLine(dtParam, { rect.x, rect.y }, { rect.x + rect.width, rect.y + rect.height }); - } - - void drawPolyline(DrawParams* dtParam, const std::vector points) - { - ((void(*)(DrawParams*, const Point*, uint64_t))0x1401980e0)(dtParam, points.data(), points.size()); - } - - - 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, - }; - - // 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 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)(fileId, drawLayer, flags, name, loc, unk2, animation, animation2, animationInTime, animationOutTime, scale, aetSpeedCallback); - } - // draw an aet layer (with animation timing override) - int createAetLayer(int32_t fileId, uint32_t drawLayer, createAetFlags flags, const char* name, const Point &loc, float animationInTime, float animationOutTime) - { - return createAetLayer(fileId, drawLayer, flags, name, loc, 0, 0, 0, animationInTime, animationOutTime, *(Point*)0, 0); - } - // draw an aet layer (with scale) - int createAetLayer(int32_t fileId, uint32_t drawLayer, createAetFlags flags, const char* name, const Point &loc, const Point &scale) - { - return createAetLayer(fileId, drawLayer, flags, name, loc, 0, 0, 0, -1, -1, scale, 0); - } - // draw an aet layer - int createAetLayer(int32_t fileId, uint32_t drawLayer, createAetFlags flags, const char* name, const Point &loc) - { - return createAetLayer(fileId, drawLayer, flags, name, loc, 0, 0, 0, -1, -1, *(Point*)0, 0); - } - - void destroyAetLayer(int &layer) - { - if (layer != 0) - { - ((void(*)(int layer))0x14019d570)(layer); - layer = 0; - } - } -#pragma pack(pop) -} \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index 115c8ac..c4c6d51 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -1,7 +1,7 @@ #include "Pause.h" #include "../Constants.h" #include "GameState.h" -#include "Drawing.h" +#include "../Utilities/Drawing.h" #include "GL/glut.h" #include "detours.h" #include @@ -10,6 +10,7 @@ namespace TLAC::Components { + using TLAC::Utilities::Drawing; bool Pause::pause = false; bool Pause::isPaused = false; bool Pause::giveUp = false; @@ -150,15 +151,15 @@ namespace TLAC::Components { // clear these from the screen too /* - destroyAetLayer(selResultAet1); - destroyAetLayer(selResultAet2); - destroyAetLayer(selResultAet3); - destroyAetLayer(selResultAet4); + Drawing::destroyAetLayer(selResultAet1); + Drawing::destroyAetLayer(selResultAet2); + Drawing::destroyAetLayer(selResultAet3); + Drawing::destroyAetLayer(selResultAet4); */ - destroyAetLayer(triangleAet); - destroyAetLayer(squareAet); - destroyAetLayer(crossAet); - destroyAetLayer(circleAet); + Drawing::destroyAetLayer(triangleAet); + Drawing::destroyAetLayer(squareAet); + Drawing::destroyAetLayer(crossAet); + Drawing::destroyAetLayer(circleAet); } } @@ -224,15 +225,15 @@ namespace TLAC::Components } /* - destroyAetLayer(selResultAet1); - destroyAetLayer(selResultAet2); - destroyAetLayer(selResultAet3); - destroyAetLayer(selResultAet4); + Drawing::destroyAetLayer(selResultAet1); + Drawing::destroyAetLayer(selResultAet2); + Drawing::destroyAetLayer(selResultAet3); + Drawing::destroyAetLayer(selResultAet4); */ - destroyAetLayer(triangleAet); - destroyAetLayer(squareAet); - destroyAetLayer(crossAet); - destroyAetLayer(circleAet); + Drawing::destroyAetLayer(triangleAet); + Drawing::destroyAetLayer(squareAet); + Drawing::destroyAetLayer(crossAet); + Drawing::destroyAetLayer(circleAet); isPaused = false; } @@ -258,16 +259,35 @@ namespace TLAC::Components inputState->IntervalTapped.Buttons = (JvsButtons)(inputState->IntervalTapped.Buttons & ~filteredButtons); } + // returns the midpoint of a menu button + Drawing::Point Pause::getMenuItemCoord(menusets set, int pos) + { + const float slant = 35.0f / 199.0f; + + int menuOriginY = menuY - (menuItemTotalHeight * menu[set].items.size() - menuItemPadding) / 2 + menuItemHeight / 2; + if (set != MENUSET_MAIN) + { + menuOriginY += menuItemTotalHeight * 1.2 / 2; + } + int menuOriginX = menuX + (menuY - menuOriginY) * slant; + + Drawing::Point out; + out.x = menuOriginX - (menuItemTotalHeight * pos * slant); + out.y = menuOriginY + menuItemTotalHeight * pos; + + return out; + } + void Pause::UpdateDraw2D() { if (isPaused && showUI) { // setup draw objects - FontInfo fontInfo(0x11); - DrawParams dtParams(&fontInfo); + Drawing::FontInfo fontInfo(0x11); + Drawing::DrawParams dtParams(&fontInfo); dtParams.layer = bgLayer; - Point aetScale = { 0.65, 0.65 }; - Point aetLoc = { (1280 - aetScale.x * 1280) / 2, (720 - aetScale.y * 720) / 2 }; + Drawing::Point aetScale = { 0.65, 0.65 }; + Drawing::Point aetLoc = { (1280 - aetScale.x * 1280) / 2, (720 - aetScale.y * 720) / 2 }; // get aspect ratio float aspect = *(float*)UI_ASPECT_RATIO; @@ -276,11 +296,11 @@ namespace TLAC::Components // bg rect float bgWidth = aspect * 720 + 2; // add a couple of pixels to protect against rounding errors float bgLeft = -(bgWidth - 1280) / 2; // 0,0 is in the corner of a 720p view.. half of the extra over 1280 wide is the horizontal offset to centre the bg - RectangleBounds rect; + Drawing::RectangleBounds rect; rect = { bgLeft, 0, bgWidth, 720 }; dtParams.colour = 0xc0000000; dtParams.fillColour = dtParams.colour; - fillRectangle(&dtParams, rect); + Drawing::fillRectangle(&dtParams, rect); // pause icon @@ -299,9 +319,9 @@ namespace TLAC::Components dtParams.colour = 0x80ffffff; dtParams.fillColour = 0x80ffffff; rect = { pauseX1, pauseY1, pausePartWidth, pauseHeight }; - fillRectangle(&dtParams, &rect); + Drawing::fillRectangle(&dtParams, &rect); rect = { pauseX2, pauseY1, pausePartWidth, pauseHeight }; - fillRectangle(&dtParams, &rect); + Drawing::fillRectangle(&dtParams, &rect); */ @@ -312,30 +332,30 @@ namespace TLAC::Components static int selResultFile = 0; if (selResultFile == 0) { - //keyWinFile = findAetFileId("AET_KEY_WIN_MAIN"); - selResultFile = findAetFileId("AET_SEL_RESULT_MAIN"); + //keyWinFile = Drawing::findAetFileId("AET_KEY_WIN_MAIN"); + selResultFile = Drawing::findAetFileId("AET_SEL_RESULT_MAIN"); //printf("keyWinFile: %d\n", keyWinFile); } - destroyAetLayer(selResultAet1); - destroyAetLayer(selResultAet2); - destroyAetLayer(selResultAet3); - destroyAetLayer(selResultAet4); + Drawing::destroyAetLayer(selResultAet1); + Drawing::destroyAetLayer(selResultAet2); + Drawing::destroyAetLayer(selResultAet3); + Drawing::destroyAetLayer(selResultAet4); if (selResultFile != -1) { - //keyWinAet = createAetLayer(keyWinFile, dtParams.layer, CREATEAET_20000, "win_in", aetLoc, 0, nullptr, nullptr, 3.7, 3.7, aetScale, 0); + //keyWinAet = Drawing::createAetLayer(keyWinFile, dtParams.layer, CREATEAET_20000, "win_in", aetLoc, 0, nullptr, nullptr, 3.7, 3.7, aetScale, 0); aetScale = { 0.47f, 0.47f }; aetLoc = { (1280 - aetScale.x * 1280) / 2, (720 - aetScale.y * 720) / 2 + 72 * aetScale.y }; float animPos = 7.2; - selResultAet1 = createAetLayer(selResultFile, dtParams.layer, CREATEAET_20000, "window_in", aetLoc, 0, nullptr, nullptr, animPos, animPos, aetScale, 0); - selResultAet2 = createAetLayer(selResultFile, dtParams.layer, CREATEAET_20000, "window_in", aetLoc, 0, nullptr, nullptr, animPos, animPos, aetScale, 0); - selResultAet3 = createAetLayer(selResultFile, dtParams.layer, CREATEAET_20000, "window_in", aetLoc, 0, nullptr, nullptr, animPos, animPos, aetScale, 0); - selResultAet4 = createAetLayer(selResultFile, dtParams.layer, CREATEAET_20000, "window_in", aetLoc, 0, nullptr, nullptr, animPos, animPos, aetScale, 0); + selResultAet1 = Drawing::createAetLayer(selResultFile, dtParams.layer, CREATEAET_20000, "window_in", aetLoc, 0, nullptr, nullptr, animPos, animPos, aetScale, 0); + selResultAet2 = Drawing::createAetLayer(selResultFile, dtParams.layer, CREATEAET_20000, "window_in", aetLoc, 0, nullptr, nullptr, animPos, animPos, aetScale, 0); + selResultAet3 = Drawing::createAetLayer(selResultFile, dtParams.layer, CREATEAET_20000, "window_in", aetLoc, 0, nullptr, nullptr, animPos, animPos, aetScale, 0); + selResultAet4 = Drawing::createAetLayer(selResultFile, dtParams.layer, CREATEAET_20000, "window_in", aetLoc, 0, nullptr, nullptr, animPos, animPos, aetScale, 0); } */ dtParams.colour = 0xffffff00; - drawPolyline(&dtParams, { + Drawing::drawPolyline(&dtParams, { { 537, 255 }, { 794, 255 }, { 759, 454 }, @@ -344,7 +364,7 @@ namespace TLAC::Components { 522, 267 }, { 537, 255 }, }); - drawPolyline(&dtParams, { + Drawing::drawPolyline(&dtParams, { { 537 - .7f, 255 - 2 }, { 794 + 2.38f, 255 - 2 }, { 759 + 2.1f, 454 + 1.15f }, @@ -353,7 +373,7 @@ namespace TLAC::Components { 522 - 2.1f, 267 - 1.15f }, { 537 - .7f, 255 - 2 }, }); - drawPolyline(&dtParams, { + Drawing::drawPolyline(&dtParams, { { 548, 258 }, { 768, 258 }, { 774, 265 }, @@ -374,26 +394,22 @@ namespace TLAC::Components }); - const float slant = 35.0f / 199.0f; + Drawing::Point menuCoords = getMenuItemCoord(curMenuSet, curMenuPos); // selection cursor - int menuOriginY = menuY - menuItemTotalHeight * (menu[curMenuSet].items.size() / 2.0) + menuItemTotalHeight / 2 - menuTextSize / 2; - if (curMenuSet != MENUSET_MAIN) - { - menuOriginY += menuItemTotalHeight * 1.2 / 2; - } - int menuOriginX = menuX + (menuY - menuOriginY + menuTextSize / 2) * slant; const float selectBoxWidth = 150; const float selectBoxHeight = menuItemHeight; const float selectBoxThickness = 2; - float selectBoxX = menuOriginX - (menuItemTotalHeight * curMenuPos * slant) - selectBoxWidth / 2; - float selectBoxY = menuOriginY - (menuItemHeight - menuTextSize) / 2 + menuItemTotalHeight * curMenuPos; + float selectBoxX = menuCoords.x - selectBoxWidth / 2; + float selectBoxY = menuCoords.y - menuItemHeight / 2; - //rect = { selectBoxX, selectBoxY, selectBoxWidth, selectBoxHeight }; dtParams.colour = 0xc0ffff00; dtParams.fillColour = 0xc0ffff00; - //drawRectangle(&dtParams, rect, selectBoxThickness); - drawPolyline(&dtParams, { + //rect = { selectBoxX, selectBoxY, selectBoxWidth, selectBoxHeight }; + //Drawing::drawRectangle(&dtParams, rect, selectBoxThickness); + + const float slant = 35.0f / 199.0f; + Drawing::drawPolyline(&dtParams, { { selectBoxX + (selectBoxHeight - 8) * slant + 8 * 15 / 12, selectBoxY }, { selectBoxX + selectBoxWidth, selectBoxY }, { selectBoxX + selectBoxWidth - (selectBoxHeight - 8) * slant, selectBoxY + selectBoxHeight - 8 }, @@ -402,7 +418,7 @@ namespace TLAC::Components { selectBoxX + (selectBoxHeight - 8) * slant, selectBoxY + 8 }, { selectBoxX + (selectBoxHeight - 8) * slant + 8 * 15 / 12, selectBoxY }, }); - drawPolyline(&dtParams, { + Drawing::drawPolyline(&dtParams, { { selectBoxX + (selectBoxHeight - 8) * slant + 8 * 15 / 12 - .7f, selectBoxY - 2 }, { selectBoxX + selectBoxWidth + 2.38f, selectBoxY - 2 }, { selectBoxX + selectBoxWidth - (selectBoxHeight - 8) * slant + 2.1f, selectBoxY + selectBoxHeight - 8 + 1.15f }, @@ -421,14 +437,14 @@ namespace TLAC::Components dtParams.textCurrentLoc = { menuX + 90 * slant, menuY - 90 }; dtParams.lineOriginLoc.y = dtParams.textCurrentLoc.y; dtParams.colour = 0xffffffff; - drawText(&dtParams, (drawTextFlags)(DRAWTEXT_ALIGN_CENTRE | DRAWTEXT_STROKE), menu[curMenuSet].name); + Drawing::drawText(&dtParams, (Drawing::drawTextFlags)(Drawing::DRAWTEXT_ALIGN_CENTRE | Drawing::DRAWTEXT_STROKE), menu[curMenuSet].name); } - dtParams.textCurrentLoc = { (float)menuOriginX, (float)menuOriginY }; - dtParams.lineOriginLoc = dtParams.textCurrentLoc; - for (int i = 0; i < menu[curMenuSet].items.size(); i++) { + menuCoords = getMenuItemCoord(curMenuSet, i); + dtParams.textCurrentLoc = { menuCoords.x, menuCoords.y - menuTextSize / 2 }; + dtParams.lineOriginLoc = dtParams.textCurrentLoc; if (i == curMenuPos) { uint8_t alpha = (cosf(getMenuAnimPos() * 6.283185f) * 0.15 + 0.85) * 255; @@ -439,18 +455,15 @@ namespace TLAC::Components dtParams.colour = 0xffffffff; } - drawText(&dtParams, (drawTextFlags)(DRAWTEXT_ALIGN_CENTRE), menu[curMenuSet].items[i].name); - dtParams.textCurrentLoc.x -= (menuItemTotalHeight * slant); - dtParams.textCurrentLoc.y += menuItemTotalHeight; - dtParams.lineOriginLoc = dtParams.textCurrentLoc; + Drawing::drawText(&dtParams, (Drawing::drawTextFlags)(Drawing::DRAWTEXT_ALIGN_CENTRE), menu[curMenuSet].items[i].name); } // key legend - destroyAetLayer(triangleAet); - destroyAetLayer(squareAet); - destroyAetLayer(crossAet); - destroyAetLayer(circleAet); + Drawing::destroyAetLayer(triangleAet); + Drawing::destroyAetLayer(squareAet); + Drawing::destroyAetLayer(crossAet); + Drawing::destroyAetLayer(circleAet); float textLeft; if (aspect > 16.0f / 9.0f) @@ -467,25 +480,25 @@ namespace TLAC::Components aetScale = { spriteSize / 64, spriteSize / 64 }; // just approximated dtParams.colour = 0xffffffff; - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_XADVANCE), L"L/R:Move "); + Drawing::drawTextW(&dtParams, (Drawing::drawTextFlags)(Drawing::DRAWTEXT_ENABLE_XADVANCE), L"L/R:Move "); aetLoc.x = dtParams.textCurrentLoc.x + halfSpriteSize; - squareAet = createAetLayer(3, dtParams.layer, CREATEAET_20000, "button_shikaku", aetLoc, 0, nullptr, nullptr, 0, 0, aetScale, nullptr); + squareAet = Drawing::createAetLayer(3, dtParams.layer, Drawing::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 "); + Drawing::drawTextW(&dtParams, (Drawing::drawTextFlags)(Drawing::DRAWTEXT_ENABLE_XADVANCE), L":Hide Menu "); aetLoc.x = dtParams.textCurrentLoc.x + halfSpriteSize; - crossAet = createAetLayer(3, dtParams.layer, CREATEAET_20000, "button_batsu", aetLoc, 0, nullptr, nullptr, 0, 0, aetScale, nullptr); + crossAet = Drawing::createAetLayer(3, dtParams.layer, Drawing::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 "); + Drawing::drawTextW(&dtParams, (Drawing::drawTextFlags)(Drawing::DRAWTEXT_ENABLE_XADVANCE), L":Close "); else - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_XADVANCE), L":Back "); + Drawing::drawTextW(&dtParams, (Drawing::drawTextFlags)(Drawing::DRAWTEXT_ENABLE_XADVANCE), L":Back "); aetLoc.x = dtParams.textCurrentLoc.x + halfSpriteSize; - circleAet = createAetLayer(3, dtParams.layer, CREATEAET_20000, "button_maru", aetLoc, 0, nullptr, nullptr, 0, 0, aetScale, nullptr); + circleAet = Drawing::createAetLayer(3, dtParams.layer, Drawing::CREATEAET_20000, "button_maru", aetLoc, 0, nullptr, nullptr, 0, 0, aetScale, nullptr); dtParams.textCurrentLoc.x += spriteSize; - drawTextW(&dtParams, (drawTextFlags)(DRAWTEXT_ENABLE_XADVANCE), L":Select"); + Drawing::drawTextW(&dtParams, (Drawing::drawTextFlags)(Drawing::DRAWTEXT_ENABLE_XADVANCE), L":Select"); } } diff --git a/source-code/source/plugins/TLAC/Components/Pause.h b/source-code/source/plugins/TLAC/Components/Pause.h index 90e5f4c..98287b7 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.h +++ b/source-code/source/plugins/TLAC/Components/Pause.h @@ -3,6 +3,7 @@ #include "EmulatorComponent.h" #include "PlayerData.h" #include "GameState.h" +#include "../Utilities/Drawing.h" #include "Input/InputState.h" #include "Input/TouchSliderState.h" #include @@ -123,5 +124,7 @@ namespace TLAC::Components static void setMenuPos(menusets set, int pos); static float getMenuAnimPos(); + + static TLAC::Utilities::Drawing::Point getMenuItemCoord(menusets set, int pos); }; } diff --git a/source-code/source/plugins/TLAC/Constants.h b/source-code/source/plugins/TLAC/Constants.h index e54237c..91c2c89 100644 --- a/source-code/source/plugins/TLAC/Constants.h +++ b/source-code/source/plugins/TLAC/Constants.h @@ -114,6 +114,9 @@ constexpr uint64_t DSC_UNPAUSE_FUNC_ADDRESS = 0x0000000140129590; constexpr uint64_t PV_GAME_BASE_ADDRESS = 0x000000014CC95270; constexpr uint64_t GIVEUP_FUNC_ADDRESS = 0x000000014010EF00; +constexpr uint64_t AET_DEBUG_ARRAY_POINTER_ADDRESS = 0x0000000140EC5430 + 0x98; +constexpr uint64_t AET_ARRAY_POINTER_ADDRESS = 0x0000000140EC5430 + 0xD8; + #define XINPUT_A 0x00 #define XINPUT_B 0x01 diff --git a/source-code/source/plugins/TLAC/TLAC.vcxproj b/source-code/source/plugins/TLAC/TLAC.vcxproj index 2c61ae9..f8bf08e 100644 --- a/source-code/source/plugins/TLAC/TLAC.vcxproj +++ b/source-code/source/plugins/TLAC/TLAC.vcxproj @@ -111,7 +111,6 @@ - @@ -163,6 +162,7 @@ + @@ -211,6 +211,7 @@ + diff --git a/source-code/source/plugins/TLAC/TLAC.vcxproj.filters b/source-code/source/plugins/TLAC/TLAC.vcxproj.filters index 6ec4726..79143c4 100644 --- a/source-code/source/plugins/TLAC/TLAC.vcxproj.filters +++ b/source-code/source/plugins/TLAC/TLAC.vcxproj.filters @@ -198,7 +198,7 @@ Header Files - + Header Files @@ -338,5 +338,8 @@ Source Files + + Source Files + \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/Utilities/Drawing.cpp b/source-code/source/plugins/TLAC/Utilities/Drawing.cpp new file mode 100644 index 0000000..2df6676 --- /dev/null +++ b/source-code/source/plugins/TLAC/Utilities/Drawing.cpp @@ -0,0 +1,160 @@ +#pragma once +#include +#include +#include +#include "Drawing.h" +#include "../Constants.h" + +namespace TLAC::Utilities +{ +#pragma pack(push, 1) + Drawing::FontInfo*(*Drawing::getFont)(FontInfo* fi, uint32_t id) = (FontInfo*(*)(FontInfo* fi, uint32_t id))0x140196510; + void(*Drawing::fontSize)(FontInfo* fi, float width, float height) = (void(*)(FontInfo* fi, float width, float height))0x140199e60; + + void Drawing::drawText(DrawParams* dtParam, drawTextFlags flags, std::string str) + { + ((void(*)(DrawParams*, uint32_t, const char*, int64_t))0x140198500)(dtParam, flags, str.c_str(), str.length()); + } + void Drawing::drawTextW(DrawParams* dtParam, drawTextFlags flags, std::wstring str) + { + const wchar_t* ptrs[2]; + ptrs[0] = str.c_str(); + ptrs[1] = (wchar_t*)((uint64_t)ptrs[0] + str.length() * 2); + + ((void(*)(DrawParams*, uint32_t, const wchar_t**))0x140198380)(dtParam, flags, &ptrs[0]); + } + + void Drawing::drawTextFormattedW(DrawParams* dtParam, drawTextFlags flags, std::wstring str) + { + const wchar_t* ptrs[2]; + ptrs[0] = str.c_str(); + ptrs[1] = (wchar_t*)((uint64_t)ptrs[0] + str.length() * 2); + + ((void(*)(uint32_t, const wchar_t**, DrawParams*))0x1404c2aa0)(flags, &ptrs[0], dtParam); + } + + void Drawing::drawTextWithSpritesW(DrawParams* dtParam, drawTextFlags flags, std::wstring str) + { + const wchar_t* ptrs[2]; + ptrs[0] = str.c_str(); + ptrs[1] = (wchar_t*)((uint64_t)ptrs[0] + str.length() * 2); + + ((void(*)(uint32_t, const wchar_t**, DrawParams*))0x1404c2cf0)(flags, &ptrs[0], dtParam); + } + + + void(*Drawing::fillRectangle)(DrawParams* dtParam, const RectangleBounds &rect) = (void(*)(DrawParams* dtParam, const RectangleBounds &rect))0x140198d80; + + // draws only a border -- use fillRectangle to fill contained pixels + void Drawing::drawRectangle(DrawParams* dtParam, const RectangleBounds &rect) + { + ((void(*)(DrawParams*, const RectangleBounds&))0x140198320)(dtParam, rect); + } + + // draws only a border -- use fillRectangle to fill contained pixels + void Drawing::drawRectangle(DrawParams* dtParam, const RectangleBounds &rect, float thickness) + { + uint32_t oldFillColour = dtParam->fillColour; + dtParam->fillColour = dtParam->colour; + + // yes this seems pretty dodgy, but sega does it this way so... I guess it's the only way + RectangleBounds tempRect = { rect.x, rect.y, thickness, rect.height }; // left side + fillRectangle(dtParam, tempRect); + + tempRect.x = rect.x + rect.width - thickness; // right side + fillRectangle(dtParam, tempRect); + + tempRect = { rect.x + thickness, rect.y, rect.width - (thickness * 2), thickness }; // top side + fillRectangle(dtParam, tempRect); + + tempRect.y = rect.y + rect.height - thickness; // left side + fillRectangle(dtParam, tempRect); + + dtParam->fillColour = oldFillColour; + } + + + void Drawing::drawLine(DrawParams* dtParam, const Point &p1, const Point &p2) + { + ((void(*)(DrawParams*, const RectangleBounds&))0x140198080)(dtParam, { p1.x, p1.y, p2.x, p2.y }); + } + // draw from the top left corner of rect to the bottom left + void Drawing::drawLine(DrawParams* dtParam, const RectangleBounds &rect) + { + drawLine(dtParam, { rect.x, rect.y }, { rect.x + rect.width, rect.y + rect.height }); + } + + void Drawing::drawPolyline(DrawParams* dtParam, const std::vector points) + { + ((void(*)(DrawParams*, const Point*, uint64_t))0x1401980e0)(dtParam, points.data(), points.size()); + } + + /* + int Drawing::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 Drawing::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; + } + + // 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 Drawing::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)(fileId, drawLayer, flags, name, loc, unk2, animation, animation2, animationInTime, animationOutTime, scale, aetSpeedCallback); + } + // draw an aet layer (with animation timing override) + int Drawing::createAetLayer(int32_t fileId, uint32_t drawLayer, createAetFlags flags, const char* name, const Point &loc, float animationInTime, float animationOutTime) + { + return createAetLayer(fileId, drawLayer, flags, name, loc, 0, 0, 0, animationInTime, animationOutTime, *(Point*)0, 0); + } + // draw an aet layer (with scale) + int Drawing::createAetLayer(int32_t fileId, uint32_t drawLayer, createAetFlags flags, const char* name, const Point &loc, const Point &scale) + { + return createAetLayer(fileId, drawLayer, flags, name, loc, 0, 0, 0, -1, -1, scale, 0); + } + // draw an aet layer + int Drawing::createAetLayer(int32_t fileId, uint32_t drawLayer, createAetFlags flags, const char* name, const Point &loc) + { + return createAetLayer(fileId, drawLayer, flags, name, loc, 0, 0, 0, -1, -1, *(Point*)0, 0); + } + + void Drawing::destroyAetLayer(int &layer) + { + if (layer != 0) + { + ((void(*)(int layer))0x14019d570)(layer); + layer = 0; + } + } +#pragma pack(pop) +} \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/Utilities/Drawing.h b/source-code/source/plugins/TLAC/Utilities/Drawing.h new file mode 100644 index 0000000..4f6b5a5 --- /dev/null +++ b/source-code/source/plugins/TLAC/Utilities/Drawing.h @@ -0,0 +1,269 @@ +#pragma once +#include +#include +#include + +namespace TLAC::Utilities +{ + class Drawing + { + public: +#pragma pack(push, 1) + struct Point + { + float x; + float y; + }; + struct RectangleBounds + { + float x; + float y; + float width; + float height; + }; + + struct RawFont + { + uint32_t sprId; // ? + uint8_t width1; // glyph? + uint8_t height1; // glyph? + uint8_t width2; // advance? + uint8_t height2; // advance? + uint8_t metric08; // or flag? + uint8_t metric09; // or flag? + uint8_t padding0a[0x06]; + float metric08divby09; + uint64_t _0x10; + int64_t dataBegin; + int64_t dataEnd; + int64_t dataCapacityEnd; + uint8_t padding38[0x8]; + }; + + struct RawFontHolderIdk // ...SeemsPrettyPointlessTbh + { + RawFont* rawfont; + uint16_t width1; + uint16_t height1; + uint16_t zero1; // ? + uint16_t zero2; // ? + uint8_t zero3; // some kind of flag, but seems unused + }; + + struct FontInfo + { + uint32_t fontId; + uint8_t padding04[0x4]; + RawFont* rawfont; + uint16_t flag10; // (zero3 != 0 && padding38[0] != 0) ? 2 : (metric08 != metric09 ? 1 : 0) + uint8_t padding12[0x02]; + float width1; + float height1; + float width2; + float height2; + float userSizeWidth; + float userSizeHeight; + float userSizeWidthMultiplier; // userSizeWidth / width1 + float userSizeHeightMultiplier; // userSizeHeight / width2 + float zero1; // ? + float zero2; // ? + + void setSize(float width, float height) + { + ((void(*)(FontInfo* fi, float width, float height))0x140199e60)(this, width, height); + } + + FontInfo(uint32_t id) + { + ((FontInfo*(*)(FontInfo* fi, uint32_t id))0x140196510)(this, id); + } + }; + + static FontInfo*(*getFont)(FontInfo* fi, uint32_t id); + static void(*fontSize)(FontInfo* fi, float width, float height); + + struct DrawParams + { + uint32_t colour; // RGBA byte array?, so set as 0xAABBGGRR + uint32_t fillColour; // ?? RGBA byte array?, so set as 0xAABBGGRR + uint8_t clip; + uint8_t unk09[0x3]; + RectangleBounds clipRect; + uint32_t layer; // 8 seems similar to default but higher + // 0x18 is below 0x19 but still seems to be above any game elements + // 0x19 is startup screen (below dwgui) + // I noticed some use different scaling + uint32_t unk20; + uint32_t unk24; + uint32_t unk28; + Point textCurrentLoc; + Point lineOriginLoc; // must be set for newlines to work as expected + uint8_t padding3c[0x4]; + uint64_t lineLength; // in characters + FontInfo* font; + uint16_t unk50; + + DrawParams(FontInfo* fi) + { + colour = 0xffffffff; + fillColour = 0xff808080; // except it's not? + clip = 0; + clipRect = { 0, 0, 0, 0 }; + layer = 0x7; + unk20 = 0x0; + unk24 = 0xd; + unk28 = 0; + textCurrentLoc = { 0, 0 }; + lineOriginLoc = { 0, 0 }; + lineLength = 0; + font = fi; + unk50 = 0x25a1; + } + + DrawParams() + { + DrawParams((FontInfo*)0x140eda860); + } + }; + + enum drawTextFlags : uint32_t + { + DRAWTEXT_ENABLE_XADVANCE = 1, + DRAWTEXT_ALIGN_RIGHT = 2, + DRAWTEXT_ALIGN_SCREEN_CENTRE = 4, + DRAWTEXT_ALIGN_CENTRE = 8, + DRAWTEXT_ENABLE_CLIP = 0x200, + DRAWTEXT_SCALING_OPTIMISED = 0x400, // ? -- seems to be set if the requested font size doesn't match the original font, and the internal width/height 1 and 2 match + // maybe it's just required for any scaling though + DRAWTEXT_STROKE = 0x10000, + }; + + static void drawText(DrawParams* dtParam, drawTextFlags flags, std::string str); + static void drawTextW(DrawParams* dtParam, drawTextFlags flags, std::wstring str); + static void drawTextFormattedW(DrawParams* dtParam, drawTextFlags flags, std::wstring str); + static void drawTextWithSpritesW(DrawParams* dtParam, drawTextFlags flags, std::wstring str); + + static void(*fillRectangle)(DrawParams* dtParam, const RectangleBounds &rect); + // draws only a border -- use fillRectangle to fill contained pixels + static void drawRectangle(DrawParams* dtParam, const RectangleBounds &rect); + // draws only a border -- use fillRectangle to fill contained pixels + static void drawRectangle(DrawParams* dtParam, const RectangleBounds &rect, float thickness); + + static void drawLine(DrawParams* dtParam, const Point &p1, const Point &p2); + // draw from the top left corner of rect to the bottom left + static void drawLine(DrawParams* dtParam, const RectangleBounds &rect); + + static void drawPolyline(DrawParams* dtParam, const std::vector points); + + + 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); + + // 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 + static int findAetFileId(std::string name); + + enum createAetFlags : uint32_t + { + CREATEAET_20000 = 0x20000, + }; + + // draw an aet layer (with all settings) + // aetSpeedCallback is actually a pointer to a class or struct with the callback address at offset +0x8 + static 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); + // draw an aet layer (with animation timing override) + static int createAetLayer(int32_t fileId, uint32_t drawLayer, createAetFlags flags, const char* name, const Point &loc, float animationInTime, float animationOutTime); + // draw an aet layer (with scale) + static int createAetLayer(int32_t fileId, uint32_t drawLayer, createAetFlags flags, const char* name, const Point &loc, const Point &scale); + // draw an aet layer + static int createAetLayer(int32_t fileId, uint32_t drawLayer, createAetFlags flags, const char* name, const Point &loc); + + static void destroyAetLayer(int &layer); +#pragma pack(pop) + }; +} \ No newline at end of file From 0b8207131a5f2f0d0fc1f1ab94286220305b528c Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Fri, 25 Oct 2019 23:10:26 +1100 Subject: [PATCH 40/44] bad copypaste in project conf --- source-code/source/plugins/TLAC/TLAC.vcxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source-code/source/plugins/TLAC/TLAC.vcxproj b/source-code/source/plugins/TLAC/TLAC.vcxproj index f8bf08e..3fefc80 100644 --- a/source-code/source/plugins/TLAC/TLAC.vcxproj +++ b/source-code/source/plugins/TLAC/TLAC.vcxproj @@ -211,7 +211,7 @@ - + From b15e840e7c4fb775e18f57a9cc226dee4ddf0911 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Sat, 26 Oct 2019 00:16:40 +1100 Subject: [PATCH 41/44] pause: touch panel support --- .../source/plugins/TLAC/Components/Pause.cpp | 43 ++++++++++++++++--- .../source/plugins/TLAC/Components/Pause.h | 7 ++- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index c4c6d51..466cf4e 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -1,6 +1,7 @@ #include "Pause.h" #include "../Constants.h" #include "GameState.h" +#include "ComponentsManager.h" #include "../Utilities/Drawing.h" #include "GL/glut.h" #include "detours.h" @@ -36,7 +37,10 @@ namespace TLAC::Components PlayerData* Pause::playerData; InputState* Pause::inputState; TouchSliderState* Pause::sliderState; + TouchPanelState* Pause::panelState; + ComponentsManager* Pause::componentsManager; JvsButtons Pause::filteredButtons; + int Pause::lastTouchType = 0; std::vector Pause::menu = { { "PAUSED", @@ -79,11 +83,13 @@ namespace TLAC::Components memcpy(origFramespeedOp.data(), framespeedPatchAddress, 4); } - void Pause::Initialize(ComponentsManager*) + void Pause::Initialize(ComponentsManager* manager) { inputState = (InputState*)(*(uint64_t*)INPUT_STATE_PTR_ADDRESS); playerData = (PlayerData*)PLAYER_DATA_ADDRESS; sliderState = (TouchSliderState*)SLIDER_CTRL_TASK_ADDRESS; + panelState = (TouchPanelState*)TASK_TOUCH_ADDRESS; + componentsManager = manager; saveOldPatchOps(); @@ -187,6 +193,31 @@ namespace TLAC::Components if (inputState->Tapped.Buttons & JVS_CIRCLE) menu[curMenuSet].items[curMenuPos].callback(); + if (!componentsManager->IsDwGuiActive()) // not sure if this check is necessary, but it doesn't hurt + { + if (panelState->ContactType == 2 && lastTouchType != 2) // down and was not down before + { + for (int i = 0; i < menu[curMenuSet].items.size(); i++) + { + Drawing::Point itemCoords = getMenuItemCoords(curMenuSet, i); + + Drawing::Point touchCoords = { panelState->XPosition, panelState->YPosition }; + touchCoords.x *= 1280.0f / *(int*)RESOLUTION_WIDTH_ADDRESS; // convert to 720p coords + touchCoords.y *= 720.0f / *(int*)RESOLUTION_HEIGHT_ADDRESS; + + if (touchCoords.x >= itemCoords.x - menuItemWidth / 2 && + touchCoords.x <= itemCoords.x + menuItemWidth / 2 && + touchCoords.y >= itemCoords.y - menuItemHeight / 2 && + touchCoords.y <= itemCoords.y + menuItemHeight / 2) + { + setMenuPos(curMenuSet, i); + menu[curMenuSet].items[i].callback(); + break; + } + } + } + } + if (curMenuSet == MENUSET_SEVOL) { const char volformat[] = "%d"; @@ -257,10 +288,12 @@ namespace TLAC::Components inputState->Down.Buttons = (JvsButtons)(inputState->Down.Buttons & ~filteredButtons); inputState->Released.Buttons = (JvsButtons)(inputState->Released.Buttons & ~filteredButtons); inputState->IntervalTapped.Buttons = (JvsButtons)(inputState->IntervalTapped.Buttons & ~filteredButtons); + + lastTouchType = panelState->ContactType; } // returns the midpoint of a menu button - Drawing::Point Pause::getMenuItemCoord(menusets set, int pos) + Drawing::Point Pause::getMenuItemCoords(menusets set, int pos) { const float slant = 35.0f / 199.0f; @@ -394,9 +427,9 @@ namespace TLAC::Components }); - Drawing::Point menuCoords = getMenuItemCoord(curMenuSet, curMenuPos); + Drawing::Point menuCoords = getMenuItemCoords(curMenuSet, curMenuPos); // selection cursor - const float selectBoxWidth = 150; + const float selectBoxWidth = menuItemWidth; const float selectBoxHeight = menuItemHeight; const float selectBoxThickness = 2; @@ -442,7 +475,7 @@ namespace TLAC::Components for (int i = 0; i < menu[curMenuSet].items.size(); i++) { - menuCoords = getMenuItemCoord(curMenuSet, i); + menuCoords = getMenuItemCoords(curMenuSet, i); dtParams.textCurrentLoc = { menuCoords.x, menuCoords.y - menuTextSize / 2 }; dtParams.lineOriginLoc = dtParams.textCurrentLoc; if (i == curMenuPos) diff --git a/source-code/source/plugins/TLAC/Components/Pause.h b/source-code/source/plugins/TLAC/Components/Pause.h index 98287b7..66afc4f 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.h +++ b/source-code/source/plugins/TLAC/Components/Pause.h @@ -6,6 +6,7 @@ #include "../Utilities/Drawing.h" #include "Input/InputState.h" #include "Input/TouchSliderState.h" +#include "Input/TouchPanelState.h" #include #include #include @@ -52,12 +53,16 @@ namespace TLAC::Components static PlayerData* playerData; static InputState* inputState; static TouchSliderState* sliderState; + static TouchPanelState* panelState; + static ComponentsManager* componentsManager; static const JvsButtons allButtons = (JvsButtons)(JVS_START | JVS_TRIANGLE | JVS_SQUARE | JVS_CROSS | JVS_CIRCLE | JVS_L | JVS_R); // deliberately only has control panel buttons static JvsButtons filteredButtons; + static int lastTouchType; static const int menuX = 640; static const int menuY = 360; + static const int menuItemWidth = 150; static const int menuItemHeight = 36; static const int menuItemPadding = 12; static const int menuItemTotalHeight = menuItemHeight + menuItemPadding; @@ -125,6 +130,6 @@ namespace TLAC::Components static float getMenuAnimPos(); - static TLAC::Utilities::Drawing::Point getMenuItemCoord(menusets set, int pos); + static TLAC::Utilities::Drawing::Point getMenuItemCoords(menusets set, int pos); }; } From a7e50346499f33f0f18416bf1058c87b8f30da5b Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Sat, 26 Oct 2019 00:22:20 +1100 Subject: [PATCH 42/44] pause: add up/down to key legend --- source-code/source/plugins/TLAC/Components/Pause.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index 466cf4e..c897548 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -513,7 +513,7 @@ namespace TLAC::Components aetScale = { spriteSize / 64, spriteSize / 64 }; // just approximated dtParams.colour = 0xffffffff; - Drawing::drawTextW(&dtParams, (Drawing::drawTextFlags)(Drawing::DRAWTEXT_ENABLE_XADVANCE), L"L/R:Move "); + Drawing::drawTextW(&dtParams, (Drawing::drawTextFlags)(Drawing::DRAWTEXT_ENABLE_XADVANCE), L"↑↓/LR:Move "); aetLoc.x = dtParams.textCurrentLoc.x + halfSpriteSize; squareAet = Drawing::createAetLayer(3, dtParams.layer, Drawing::CREATEAET_20000, "button_shikaku", aetLoc, 0, nullptr, nullptr, 0, 0, aetScale, nullptr); From 1c32a16018d769fb8000517fc2ebb5721f1789e4 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Sat, 26 Oct 2019 00:26:16 +1100 Subject: [PATCH 43/44] add pause component to launcher and components.ini --- source-code/data/plugins/components.ini | 3 +++ source-code/source/plugins/Launcher/framework.h | 2 ++ 2 files changed, 5 insertions(+) diff --git a/source-code/data/plugins/components.ini b/source-code/data/plugins/components.ini index 369be77..6c30c94 100644 --- a/source-code/data/plugins/components.ini +++ b/source-code/data/plugins/components.ini @@ -51,3 +51,6 @@ target_inspector = true # saves high scores to plugins/scores.ini score_saver = true + +# adds a pause menu +pause = true diff --git a/source-code/source/plugins/Launcher/framework.h b/source-code/source/plugins/Launcher/framework.h index dce686a..9c13be6 100644 --- a/source-code/source/plugins/Launcher/framework.h +++ b/source-code/source/plugins/Launcher/framework.h @@ -247,6 +247,8 @@ ConfigOptionBase* componentsArray[] = { new BooleanOption(L"target_inspector", COMPONENTS_SECTION, COMPONENTS_FILE, L"Target Inspector", L"Enables hold transfers.", false, true), new BooleanOption(L"score_saver", COMPONENTS_SECTION, COMPONENTS_FILE, L"Score Saver", L"Saves high scores to plugins/scores.ini.", false, true), + + new BooleanOption(L"pause", COMPONENTS_SECTION, COMPONENTS_FILE, L"Pause", L"Adds a pause menu.", false, true), }; bool IsLineInFile(LPCSTR searchLine, LPCWSTR fileName) From 26d6ef0250d414fec8355e4ee62f2c5f510a2abd Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Sat, 26 Oct 2019 10:16:53 +1100 Subject: [PATCH 44/44] add code for skipping through menus (input bit 0x6e set based on any control panel buttons being used) --- .../TLAC/Components/Input/InputEmulator.cpp | 24 +++++++++++++++++++ .../TLAC/Components/Input/InputEmulator.h | 1 + 2 files changed, 25 insertions(+) diff --git a/source-code/source/plugins/TLAC/Components/Input/InputEmulator.cpp b/source-code/source/plugins/TLAC/Components/Input/InputEmulator.cpp index f7d6df1..96af78b 100644 --- a/source-code/source/plugins/TLAC/Components/Input/InputEmulator.cpp +++ b/source-code/source/plugins/TLAC/Components/Input/InputEmulator.cpp @@ -139,6 +139,8 @@ namespace TLAC::Components UpdateSliderLR(); } + SetMetaButtons(); + UpdateHoldState(); heldButtons = GetButtonFromHold(); @@ -371,4 +373,26 @@ namespace TLAC::Components else inputState->Down.Buttons &= ~JVS_R; } + + void InputEmulator::SetMetaButtons() + { + // bit 0x6e is used to skip a bunch of screens + if ((inputState->Down.Buttons & (JVS_L | JVS_R)) == 0) // ask sega okay? idk why this is needed + { + if ((inputState->Tapped.Buttons & (JVS_START | JVS_TRIANGLE | JVS_SQUARE | JVS_CROSS | JVS_CIRCLE)) != 0) + inputState->SetBit(0x6e, true, InputBufferType_Tapped); + else + inputState->SetBit(0x6e, false, InputBufferType_Tapped); + + if ((inputState->Down.Buttons & (JVS_START | JVS_TRIANGLE | JVS_SQUARE | JVS_CROSS | JVS_CIRCLE)) != 0) + inputState->SetBit(0x6e, true, InputBufferType_Down); + else + inputState->SetBit(0x6e, false, InputBufferType_Down); + + if ((inputState->Released.Buttons & (JVS_START | JVS_TRIANGLE | JVS_SQUARE | JVS_CROSS | JVS_CIRCLE)) != 0) + inputState->SetBit(0x6e, true, InputBufferType_Released); + else + inputState->SetBit(0x6e, false, InputBufferType_Released); + } + } } \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/Components/Input/InputEmulator.h b/source-code/source/plugins/TLAC/Components/Input/InputEmulator.h index b795293..309dfd9 100644 --- a/source-code/source/plugins/TLAC/Components/Input/InputEmulator.h +++ b/source-code/source/plugins/TLAC/Components/Input/InputEmulator.h @@ -102,5 +102,6 @@ namespace TLAC::Components void UpdateInputBit(uint32_t bit, uint8_t keycode); void UpdateSliderLR(); + void SetMetaButtons(); }; }