From 34878ad4d03e003964c151add26e266e1446b098 Mon Sep 17 00:00:00 2001 From: vivian cherry <97123273+viviancherry9@users.noreply.github.com> Date: Mon, 6 Apr 2026 15:10:35 -0400 Subject: [PATCH 1/7] code changes --- include/Megamix/Hooks.hpp | 1 + include/Megamix/Region.hpp | 7 ++- include/Megamix/Types.hpp | 38 ++++++++++++++++ src/Megamix/Commands.cpp | 2 +- src/Megamix/Hooks.cpp | 90 ++++++++++++++++++++++++++++++++++++++ src/Megamix/Region.cpp | 8 ++++ src/main.cpp | 1 + 7 files changed, 145 insertions(+), 2 deletions(-) diff --git a/include/Megamix/Hooks.hpp b/include/Megamix/Hooks.hpp index e8c8c62..7332e70 100644 --- a/include/Megamix/Hooks.hpp +++ b/include/Megamix/Hooks.hpp @@ -8,6 +8,7 @@ namespace Megamix::Hooks { void TempoHooks(); void RegionHooks(); void CommandHook(); + void ScoringHook(); void DisableAllHooks(); template T StubbedFunction(); diff --git a/include/Megamix/Region.hpp b/include/Megamix/Region.hpp index f2fc9f3..e9fcb77 100644 --- a/include/Megamix/Region.hpp +++ b/include/Megamix/Region.hpp @@ -27,6 +27,9 @@ namespace Megamix { u32 dataEnd; u32 bssEnd; + // scoring crap + u32 scoringFunctionPos; + // game definitions GameDef* gameTable; @@ -151,6 +154,8 @@ namespace Megamix { inline u32 seqTempo() { return pointers->seqTempoHookPos; } inline u32 allTempo() { return pointers->allTempoHookPos; } + inline u32 scoring() { return pointers->scoringFunctionPos; } + inline u32 megamixRegionCode() { return pointers->regionAHookPos; } inline u32 sdkRegionCode() { return pointers->regionBHookPos; } } @@ -193,4 +198,4 @@ namespace Megamix { } } -#endif \ No newline at end of file +#endif diff --git a/include/Megamix/Types.hpp b/include/Megamix/Types.hpp index ced1826..e0e2ac4 100644 --- a/include/Megamix/Types.hpp +++ b/include/Megamix/Types.hpp @@ -560,6 +560,44 @@ namespace Megamix { TextBox* textBox; }; + struct CResultManager{ + int* _vtable; + u8 mAmtCategories; + u8 field_0x5; + u8 mCommentTargetLowPrio; + u8 field_0x7; + s32 mCommentTargetHighPrio; + u32* field6_0xc; + u32* field7_0x10; + u32* field8_0x14; + s32 field9_0x18; + s32 field10_0x1c; + u32* mMaxWeight; + u32* field12_0x24; + u32* mScoreWeight; + u32 field14_0x2c; + u32* field15_0x30; + u32* field16_0x34; + u32 mOkThreshold; + u32 mHiThereshold; + u32* points; + u32* field20_0x44; + u32* mCommentMsbtFile; + char** mCommentHiEntry; + char** mCommentNgEntry; + s32 mSafeComment; + char* mSafeHiEntry; + char* mSafeOkEntry; + char* mSafeNgEntry; + s32 mMsbtFile; + char* mResultCaptionString; + u8 field_0x6c; + u8 field_0x6d; + u8 field_0x6e; + u8 field_0x64; + u32 mSkillStarInputNum; + }; + } // namespace Megamix #endif diff --git a/src/Megamix/Commands.cpp b/src/Megamix/Commands.cpp index 0c2a0fc..8891038 100644 --- a/src/Megamix/Commands.cpp +++ b/src/Megamix/Commands.cpp @@ -16,7 +16,7 @@ namespace Megamix { ); } - extern "C" __attribute__((used)) + extern "C" __attribute__((used)) int tickflowCommandsHook(CTickflow* self, u32 cmd_num, u32 arg0, u32* args){ switch(cmd_num){ // Necessary, as our hook overrides case 0. diff --git a/src/Megamix/Hooks.cpp b/src/Megamix/Hooks.cpp index fb9e78b..ebc90d5 100644 --- a/src/Megamix/Hooks.cpp +++ b/src/Megamix/Hooks.cpp @@ -27,6 +27,9 @@ namespace Megamix::Hooks { RT_HOOK tickflowCommandsHook; + RT_HOOK scoringFunctionHook; + + void* getTickflowOffset(int index) { if (config->tickflows.contains(index)) { int result = Megamix::btks.LoadFile(config->tickflows[index]); @@ -138,6 +141,85 @@ namespace Megamix::Hooks { return RegionMegamix::UNK; } + int decideFinalScore(Megamix::CResultManager *arg1){ + //pointers + u8 amtCategories = arg1->mAmtCategories; + OSD::Notify("amtCategories = " + std::to_string(amtCategories)); + u32* field6 = arg1->field6_0xc; + u32* field7 = arg1->field7_0x10; + u32* field8 = arg1->field8_0x14; + long long catScore10000 = 0LL; + float catScore10000float = 0.0f; + float totalWeight = 0.0f; + float scoreDivWeight = 0.0f; + int maxCatScore = 0; + float result = 0.0f; + int finalResult = 0; + float curScoreWeight = 0.0f; + int i = 0; + int g = 0; + int validCategories = 0; + float distributedWeight = 0.0f; + + if (0 != amtCategories){ + //OSD::Notify("amt categories loop entered!"); + do{ + maxCatScore = (int)(field6[g] + field7[g] + field8[g]); + if(maxCatScore != 0){ + validCategories += 1; + } + g += 1; + }while (g < 7); + distributedWeight = (float)(arg1->mScoreWeight[7]) / (float)(validCategories); + do{ + maxCatScore = (int)(field6[i] + field7[i] + field8[i]); + //OSD::Notify("cat score = " + std::to_string(maxCatScore)); + + if (0 < maxCatScore) { + if((int)(field6[i] + field7[i] + field8[i]) < 1){ + maxCatScore = 0; + } + else{ + if(arg1->points[i] < 1){ + catScore10000 = ((arg1->points[i]+1) * 10000) / (maxCatScore * arg1->mMaxWeight[i]); + //OSD::Notify("points = " + std::to_string(arg1->points[i])); + } else { + catScore10000 = (arg1->points[i] * 10000) / (maxCatScore * arg1->mMaxWeight[i]); + //OSD::Notify("catScore10000 = " + std::to_string(catScore10000)); + } + //OSD::Notify("points = " + std::to_string(arg1->points[i])); + + //OSD::Notify("mMaxWeight = " + std::to_string(arg1->mMaxWeight[i])); + catScore10000float = (float)catScore10000; + //OSD::Notify("catScore10000float = " + std::to_string(catScore10000float)); + } + if(i != 7){ + curScoreWeight = (float)(arg1->mScoreWeight[i]) + distributedWeight; + OSD::Notify("curScoreWeight = " + std::to_string(curScoreWeight)); + totalWeight += curScoreWeight; + OSD::Notify("totalWeight = " + std::to_string(totalWeight)); + scoreDivWeight += curScoreWeight/catScore10000float; + //OSD::Notify("scoreDivWeight= " + std::to_string(scoreDivWeight)); + } + } + i += 1; + } while (i < amtCategories); + if (0.0f < totalWeight){ + result = totalWeight/scoreDivWeight; + //OSD::Notify("result = " + std::to_string(result)); + finalResult = (int)(result - (arg1->field9_0x18 * arg1->field14_0x2c)); + if(10000 < finalResult){ + finalResult = 10000; + } + //OSD::Notify("finalResult = " + std::to_string(finalResult)); + if (0 < finalResult){ + return finalResult; + } + } + } + //OSD::Notify("finalResult = " + std::to_string(finalResult)); + return 0; + } void TickflowHooks() { rtInitHook(&tickflowHook, GHooks::tickflow(), (u32)getTickflowOffset); @@ -171,6 +253,11 @@ namespace Megamix::Hooks { rtEnableHook(&tickflowCommandsHook); } + void ScoringHook(){ + rtInitHook(&scoringFunctionHook, GHooks::scoring(), (int)decideFinalScore); + rtEnableHook(&scoringFunctionHook); + } + void DisableAllHooks() { rtDisableHook(&tickflowHook); rtDisableHook(&gateHook); @@ -179,9 +266,12 @@ namespace Megamix::Hooks { rtDisableHook(&tempoAllHook); rtDisableHook(®ionFSHook); rtDisableHook(®ionOtherHook); + rtDisableHook(&scoringFunctionHook); rtDisableHook(&tickflowCommandsHook); } + + template T StubbedFunction() { return {}; diff --git a/src/Megamix/Region.cpp b/src/Megamix/Region.cpp index c2a7781..e82c15f 100644 --- a/src/Megamix/Region.cpp +++ b/src/Megamix/Region.cpp @@ -22,6 +22,8 @@ namespace Megamix { .dataEnd= 0x540754, .bssEnd= 0x5ce1f0, + .scoringFunctionPos= GameInterface::NO_PTR, + .gameTable= (GameDef*)0x522498, .gateTable= (GateGameDef*)0x525488, .tickflowHookPos= 0x25a1b4, @@ -69,6 +71,8 @@ namespace Megamix { .dataEnd= 0x54f074, .bssEnd= 0x5dc2f0, + .scoringFunctionPos= 0x276264, + .gameTable= (GameDef*)0x52b498, .gateTable= (GateGameDef*)0x52e488, .tickflowHookPos= 0x258df4, @@ -118,6 +122,8 @@ namespace Megamix { .dataEnd= 0x54f16c, .bssEnd= 0x5dc2f0, + .scoringFunctionPos= GameInterface::NO_PTR, + .gameTable= (GameDef*)0x52b498, .gateTable= (GateGameDef*)0x52e488, .tickflowHookPos= 0x258df4, @@ -162,6 +168,8 @@ namespace Megamix { .dataEnd= 0x54f16c, //TODO: check .bssEnd= 0x5dc2f0, + .scoringFunctionPos= GameInterface::NO_PTR, + .gameTable= (GameDef*)0x52b498, .gateTable= (GateGameDef*)0x52e488, .tickflowHookPos= 0x258dcc, diff --git a/src/main.cpp b/src/main.cpp index 19d6d32..223d6aa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -103,6 +103,7 @@ void ctrpf::PatchProcess(ctrpf::FwkSettings&) { // Start hooks, apply patches Megamix::Hooks::TickflowHooks(); + Megamix::Hooks::ScoringHook(); Megamix::Hooks::RegionHooks(); Megamix::Patches::PatchRetryRemix(); if (!Megamix::isJP()) { From 9a9269db9a17b5265ff5258ae43a8e071c92b0b2 Mon Sep 17 00:00:00 2001 From: viviancherry9 Date: Mon, 6 Apr 2026 21:11:58 -0400 Subject: [PATCH 2/7] skillstar point distribution + removing debug text the skillstar category now distributes its points and amtInputs amongst the other categories --- .gitignore | 4 ++- src/Megamix/Hooks.cpp | 67 ++++++++++++++++++++++++++----------------- 2 files changed, 44 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index be2a5c8..a37f717 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,9 @@ build *.3gx *.elf +*.kate-swp .vscode .cache -compile_commands.json \ No newline at end of file +3gxtool +compile_commands.json diff --git a/src/Megamix/Hooks.cpp b/src/Megamix/Hooks.cpp index ebc90d5..67d222e 100644 --- a/src/Megamix/Hooks.cpp +++ b/src/Megamix/Hooks.cpp @@ -144,7 +144,7 @@ namespace Megamix::Hooks { int decideFinalScore(Megamix::CResultManager *arg1){ //pointers u8 amtCategories = arg1->mAmtCategories; - OSD::Notify("amtCategories = " + std::to_string(amtCategories)); + //OSD::Notify("amtCategories = " + std::to_string(amtCategories)); u32* field6 = arg1->field6_0xc; u32* field7 = arg1->field7_0x10; u32* field8 = arg1->field8_0x14; @@ -152,7 +152,7 @@ namespace Megamix::Hooks { float catScore10000float = 0.0f; float totalWeight = 0.0f; float scoreDivWeight = 0.0f; - int maxCatScore = 0; + float amtInputs = 0.0f; float result = 0.0f; int finalResult = 0; float curScoreWeight = 0.0f; @@ -160,48 +160,63 @@ namespace Megamix::Hooks { int g = 0; int validCategories = 0; float distributedWeight = 0.0f; + float distributedAmtInputs = 0.0f; + float distributedScore = 0.0f; if (0 != amtCategories){ //OSD::Notify("amt categories loop entered!"); do{ - maxCatScore = (int)(field6[g] + field7[g] + field8[g]); - if(maxCatScore != 0){ + amtInputs = (int)(field6[g] + field7[g] + field8[g]); + if(amtInputs != 0){ validCategories += 1; } g += 1; }while (g < 7); + distributedWeight = (float)(arg1->mScoreWeight[7]) / (float)(validCategories); + distributedAmtInputs = (float)(field6[7] + field7[7] + field8[7]) / (float)(validCategories); + if(arg1->points[7] < 1){ + distributedScore = (float)(arg1->points[7] + 1) / (float)(validCategories); + } else { + distributedScore = (float)(arg1->points[7]) / (float)(validCategories); + } + + //OSD::Notify("distributedWeight = " + std::to_string(distributedWeight)); + //OSD::Notify("distributedAmtInputs = " + std::to_string(distributedAmtInputs)); + //OSD::Notify("distributedScore = " + std::to_string(distributedScore)); + do{ - maxCatScore = (int)(field6[i] + field7[i] + field8[i]); - //OSD::Notify("cat score = " + std::to_string(maxCatScore)); + if(i != 7){ + amtInputs = (float)(field6[i] + field7[i] + field8[i]); - if (0 < maxCatScore) { - if((int)(field6[i] + field7[i] + field8[i]) < 1){ - maxCatScore = 0; - } - else{ - if(arg1->points[i] < 1){ - catScore10000 = ((arg1->points[i]+1) * 10000) / (maxCatScore * arg1->mMaxWeight[i]); - //OSD::Notify("points = " + std::to_string(arg1->points[i])); - } else { - catScore10000 = (arg1->points[i] * 10000) / (maxCatScore * arg1->mMaxWeight[i]); - //OSD::Notify("catScore10000 = " + std::to_string(catScore10000)); + if (0 < amtInputs) { + if((float)(field6[i] + field7[i] + field8[i]) < 1){ + amtInputs = 0; } - //OSD::Notify("points = " + std::to_string(arg1->points[i])); + else{ + amtInputs += distributedAmtInputs; + //OSD::Notify("cat score = " + std::to_string(amtInputs)); + if(arg1->points[i] < 1){ + catScore10000 = ((arg1->points[i] + distributedScore + 1) * 10000) / (amtInputs * arg1->mMaxWeight[i]); + //OSD::Notify("points = " + std::to_string(arg1->points[i])); + } else { + catScore10000 = ((arg1->points[i] + distributedScore) * 10000) / (amtInputs * arg1->mMaxWeight[i]); + //OSD::Notify("catScore10000 = " + std::to_string(catScore10000)); + } + //OSD::Notify("points = " + std::to_string(arg1->points[i])); - //OSD::Notify("mMaxWeight = " + std::to_string(arg1->mMaxWeight[i])); - catScore10000float = (float)catScore10000; - //OSD::Notify("catScore10000float = " + std::to_string(catScore10000float)); - } - if(i != 7){ + //OSD::Notify("mMaxWeight = " + std::to_string(arg1->mMaxWeight[i])); + catScore10000float = (float)catScore10000; + //OSD::Notify("catScore10000float = " + std::to_string(catScore10000float)); + } curScoreWeight = (float)(arg1->mScoreWeight[i]) + distributedWeight; - OSD::Notify("curScoreWeight = " + std::to_string(curScoreWeight)); + //OSD::Notify("curScoreWeight = " + std::to_string(curScoreWeight)); totalWeight += curScoreWeight; - OSD::Notify("totalWeight = " + std::to_string(totalWeight)); + //OSD::Notify("totalWeight = " + std::to_string(totalWeight)); scoreDivWeight += curScoreWeight/catScore10000float; //OSD::Notify("scoreDivWeight= " + std::to_string(scoreDivWeight)); } - } + } i += 1; } while (i < amtCategories); if (0.0f < totalWeight){ From d269fedbde4898a2cb7d71a374b69f7a0b93c52b Mon Sep 17 00:00:00 2001 From: viviancherry9 Date: Thu, 9 Apr 2026 16:17:07 -0400 Subject: [PATCH 3/7] hopefully(?) fixed skillstar score distribution --- src/Megamix/Hooks.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Megamix/Hooks.cpp b/src/Megamix/Hooks.cpp index 67d222e..b13f6ee 100644 --- a/src/Megamix/Hooks.cpp +++ b/src/Megamix/Hooks.cpp @@ -142,14 +142,13 @@ namespace Megamix::Hooks { } int decideFinalScore(Megamix::CResultManager *arg1){ - //pointers u8 amtCategories = arg1->mAmtCategories; //OSD::Notify("amtCategories = " + std::to_string(amtCategories)); u32* field6 = arg1->field6_0xc; u32* field7 = arg1->field7_0x10; u32* field8 = arg1->field8_0x14; - long long catScore10000 = 0LL; - float catScore10000float = 0.0f; + //long long catScore10000 = 0LL; + float catScore10000 = 0.0f; float totalWeight = 0.0f; float scoreDivWeight = 0.0f; float amtInputs = 0.0f; @@ -206,14 +205,14 @@ namespace Megamix::Hooks { //OSD::Notify("points = " + std::to_string(arg1->points[i])); //OSD::Notify("mMaxWeight = " + std::to_string(arg1->mMaxWeight[i])); - catScore10000float = (float)catScore10000; + //catScore10000float = (float)catScore10000; //OSD::Notify("catScore10000float = " + std::to_string(catScore10000float)); } curScoreWeight = (float)(arg1->mScoreWeight[i]) + distributedWeight; //OSD::Notify("curScoreWeight = " + std::to_string(curScoreWeight)); totalWeight += curScoreWeight; //OSD::Notify("totalWeight = " + std::to_string(totalWeight)); - scoreDivWeight += curScoreWeight/catScore10000float; + scoreDivWeight += curScoreWeight/catScore10000; //OSD::Notify("scoreDivWeight= " + std::to_string(scoreDivWeight)); } } From 7d1be684b0ba23c12f15359734c9be23f4f38b06 Mon Sep 17 00:00:00 2001 From: viviancherry9 Date: Thu, 9 Apr 2026 20:41:28 -0400 Subject: [PATCH 4/7] the category scores can now be accessed through the CTRplugin menu! --- include/Megamix/Hooks.hpp | 2 ++ src/Megamix/Hooks.cpp | 10 ++++++++++ src/main.cpp | 10 ++++++++++ 3 files changed, 22 insertions(+) diff --git a/include/Megamix/Hooks.hpp b/include/Megamix/Hooks.hpp index 7332e70..77f4546 100644 --- a/include/Megamix/Hooks.hpp +++ b/include/Megamix/Hooks.hpp @@ -15,4 +15,6 @@ namespace Megamix::Hooks { template void StubFunction(u32 address); } +extern std::vector debugScoreArray; + #endif diff --git a/src/Megamix/Hooks.cpp b/src/Megamix/Hooks.cpp index b13f6ee..a74ac60 100644 --- a/src/Megamix/Hooks.cpp +++ b/src/Megamix/Hooks.cpp @@ -6,6 +6,8 @@ #include "Megamix.hpp" #include "Config.hpp" +std::vector debugScoreArray; + using CTRPluginFramework::OSD; using Megamix::TempoTable; @@ -162,6 +164,8 @@ namespace Megamix::Hooks { float distributedAmtInputs = 0.0f; float distributedScore = 0.0f; + debugScoreArray.clear(); + if (0 != amtCategories){ //OSD::Notify("amt categories loop entered!"); do{ @@ -171,6 +175,7 @@ namespace Megamix::Hooks { } g += 1; }while (g < 7); + //OSD::Notify("validCategories = " + std::to_string(validCategories)); distributedWeight = (float)(arg1->mScoreWeight[7]) / (float)(validCategories); distributedAmtInputs = (float)(field6[7] + field7[7] + field8[7]) / (float)(validCategories); @@ -208,6 +213,11 @@ namespace Megamix::Hooks { //catScore10000float = (float)catScore10000; //OSD::Notify("catScore10000float = " + std::to_string(catScore10000float)); } + // do{ + debugScoreArray.push_back(catScore10000); + // } while ((int)(debugScoreArray.size()) <= (int)(validCategories)); + + curScoreWeight = (float)(arg1->mScoreWeight[i]) + distributedWeight; //OSD::Notify("curScoreWeight = " + std::to_string(curScoreWeight)); totalWeight += curScoreWeight; diff --git a/src/main.cpp b/src/main.cpp index 223d6aa..f7a17fe 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -136,6 +136,16 @@ void InitMenu(ctrpf::PluginMenu &menu) { ))(); }); + menu += new ctrpf::MenuEntry("Category Scores", nullptr, [](ctrpf::MenuEntry*) { + std::string debugScoreOutput = ""; + + for(float i : debugScoreArray) { + debugScoreOutput += std::to_string(i) + "\n"; + } + + ctrpf::MessageBox("Category Scores", debugScoreOutput)(); + }); + menu += new ctrpf::MenuEntry("Tickflow contents", nullptr, [](ctrpf::MenuEntry*) { ctrpf::MessageBox("Map shit", Stuff::FileMapToString(config->tickflows))(); }); From 1e092e556843944976d717f31bddf2900e18d127 Mon Sep 17 00:00:00 2001 From: viviancherry9 Date: Thu, 21 May 2026 14:40:16 -0400 Subject: [PATCH 5/7] rename some unnamed variables, remove debug comments, standardize if statements --- include/Megamix/Types.hpp | 6 ++--- src/Megamix/Hooks.cpp | 55 +++++++++++---------------------------- 2 files changed, 18 insertions(+), 43 deletions(-) diff --git a/include/Megamix/Types.hpp b/include/Megamix/Types.hpp index e0e2ac4..3c80c2c 100644 --- a/include/Megamix/Types.hpp +++ b/include/Megamix/Types.hpp @@ -567,9 +567,9 @@ namespace Megamix { u8 mCommentTargetLowPrio; u8 field_0x7; s32 mCommentTargetHighPrio; - u32* field6_0xc; - u32* field7_0x10; - u32* field8_0x14; + u32* mAmtHit; + u32* mAmtBarely; + u32* mAmtMiss; s32 field9_0x18; s32 field10_0x1c; u32* mMaxWeight; diff --git a/src/Megamix/Hooks.cpp b/src/Megamix/Hooks.cpp index a74ac60..0eee892 100644 --- a/src/Megamix/Hooks.cpp +++ b/src/Megamix/Hooks.cpp @@ -31,7 +31,6 @@ namespace Megamix::Hooks { RT_HOOK scoringFunctionHook; - void* getTickflowOffset(int index) { if (config->tickflows.contains(index)) { int result = Megamix::btks.LoadFile(config->tickflows[index]); @@ -145,11 +144,9 @@ namespace Megamix::Hooks { int decideFinalScore(Megamix::CResultManager *arg1){ u8 amtCategories = arg1->mAmtCategories; - //OSD::Notify("amtCategories = " + std::to_string(amtCategories)); - u32* field6 = arg1->field6_0xc; - u32* field7 = arg1->field7_0x10; - u32* field8 = arg1->field8_0x14; - //long long catScore10000 = 0LL; + u32* amtHit = arg1->mAmtHit; + u32* amtBarely = arg1->mAmtBarely; + u32* amtMiss = arg1->mAmtMiss; float catScore10000 = 0.0f; float totalWeight = 0.0f; float scoreDivWeight = 0.0f; @@ -166,82 +163,60 @@ namespace Megamix::Hooks { debugScoreArray.clear(); - if (0 != amtCategories){ - //OSD::Notify("amt categories loop entered!"); + if (amtCategories != 0){ do{ - amtInputs = (int)(field6[g] + field7[g] + field8[g]); + amtInputs = (int)(amtHit[g] + amtBarely[g] + amtMiss[g]); if(amtInputs != 0){ validCategories += 1; } g += 1; }while (g < 7); - //OSD::Notify("validCategories = " + std::to_string(validCategories)); distributedWeight = (float)(arg1->mScoreWeight[7]) / (float)(validCategories); - distributedAmtInputs = (float)(field6[7] + field7[7] + field8[7]) / (float)(validCategories); + distributedAmtInputs = (float)(amtHit[7] + amtBarely[7] + amtMiss[7]) / (float)(validCategories); if(arg1->points[7] < 1){ distributedScore = (float)(arg1->points[7] + 1) / (float)(validCategories); } else { distributedScore = (float)(arg1->points[7]) / (float)(validCategories); } - //OSD::Notify("distributedWeight = " + std::to_string(distributedWeight)); - //OSD::Notify("distributedAmtInputs = " + std::to_string(distributedAmtInputs)); - //OSD::Notify("distributedScore = " + std::to_string(distributedScore)); - do{ if(i != 7){ - amtInputs = (float)(field6[i] + field7[i] + field8[i]); - - if (0 < amtInputs) { - if((float)(field6[i] + field7[i] + field8[i]) < 1){ + amtInputs = (float)(amtHit[i] + amtBarely[i] + amtMiss[i]); + if (amtInputs > 0) { + if((float)(amtHit[i] + amtBarely[i] + amtMiss[i]) < 1){ amtInputs = 0; } else{ amtInputs += distributedAmtInputs; - //OSD::Notify("cat score = " + std::to_string(amtInputs)); if(arg1->points[i] < 1){ catScore10000 = ((arg1->points[i] + distributedScore + 1) * 10000) / (amtInputs * arg1->mMaxWeight[i]); - //OSD::Notify("points = " + std::to_string(arg1->points[i])); } else { catScore10000 = ((arg1->points[i] + distributedScore) * 10000) / (amtInputs * arg1->mMaxWeight[i]); - //OSD::Notify("catScore10000 = " + std::to_string(catScore10000)); } - //OSD::Notify("points = " + std::to_string(arg1->points[i])); - - //OSD::Notify("mMaxWeight = " + std::to_string(arg1->mMaxWeight[i])); - //catScore10000float = (float)catScore10000; - //OSD::Notify("catScore10000float = " + std::to_string(catScore10000float)); } - // do{ - debugScoreArray.push_back(catScore10000); - // } while ((int)(debugScoreArray.size()) <= (int)(validCategories)); + debugScoreArray.push_back(catScore10000); curScoreWeight = (float)(arg1->mScoreWeight[i]) + distributedWeight; - //OSD::Notify("curScoreWeight = " + std::to_string(curScoreWeight)); totalWeight += curScoreWeight; - //OSD::Notify("totalWeight = " + std::to_string(totalWeight)); scoreDivWeight += curScoreWeight/catScore10000; - //OSD::Notify("scoreDivWeight= " + std::to_string(scoreDivWeight)); } } i += 1; - } while (i < amtCategories); - if (0.0f < totalWeight){ + } while (amtCategories > i); + + if (totalWeight > 0.0f){ result = totalWeight/scoreDivWeight; - //OSD::Notify("result = " + std::to_string(result)); finalResult = (int)(result - (arg1->field9_0x18 * arg1->field14_0x2c)); - if(10000 < finalResult){ + if(finalResult > 10000){ finalResult = 10000; } - //OSD::Notify("finalResult = " + std::to_string(finalResult)); - if (0 < finalResult){ + if (finalResult > 0){ return finalResult; } } } - //OSD::Notify("finalResult = " + std::to_string(finalResult)); return 0; } From fdfae14bc0b985854dc3fda90ce780b2c427d5e6 Mon Sep 17 00:00:00 2001 From: viviancherry9 Date: Thu, 21 May 2026 15:06:07 -0400 Subject: [PATCH 6/7] more code cleanup renamed scoringFunctionPos to scoringHookPos, changed do while loops to for loops replaced NO_PTR with UNIMPLEMENTED --- include/Megamix/Region.hpp | 4 ++-- src/Megamix/Hooks.cpp | 32 ++++++++++++++------------------ src/Megamix/Region.cpp | 8 ++++---- src/main.cpp | 4 +++- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/include/Megamix/Region.hpp b/include/Megamix/Region.hpp index e9fcb77..acc5770 100644 --- a/include/Megamix/Region.hpp +++ b/include/Megamix/Region.hpp @@ -28,7 +28,7 @@ namespace Megamix { u32 bssEnd; // scoring crap - u32 scoringFunctionPos; + u32 scoringHookPos; // game definitions @@ -154,7 +154,7 @@ namespace Megamix { inline u32 seqTempo() { return pointers->seqTempoHookPos; } inline u32 allTempo() { return pointers->allTempoHookPos; } - inline u32 scoring() { return pointers->scoringFunctionPos; } + inline u32 scoring() { return pointers->scoringHookPos; } inline u32 megamixRegionCode() { return pointers->regionAHookPos; } inline u32 sdkRegionCode() { return pointers->regionBHookPos; } diff --git a/src/Megamix/Hooks.cpp b/src/Megamix/Hooks.cpp index 0eee892..84cfea7 100644 --- a/src/Megamix/Hooks.cpp +++ b/src/Megamix/Hooks.cpp @@ -142,7 +142,7 @@ namespace Megamix::Hooks { return RegionMegamix::UNK; } - int decideFinalScore(Megamix::CResultManager *arg1){ + int decideFinalScore(Megamix::CResultManager *arg1) { u8 amtCategories = arg1->mAmtCategories; u32* amtHit = arg1->mAmtHit; u32* amtBarely = arg1->mAmtBarely; @@ -154,8 +154,6 @@ namespace Megamix::Hooks { float result = 0.0f; int finalResult = 0; float curScoreWeight = 0.0f; - int i = 0; - int g = 0; int validCategories = 0; float distributedWeight = 0.0f; float distributedAmtInputs = 0.0f; @@ -163,33 +161,32 @@ namespace Megamix::Hooks { debugScoreArray.clear(); - if (amtCategories != 0){ - do{ + if (amtCategories != 0) { + for (int g = 0; g < 7; g++) { amtInputs = (int)(amtHit[g] + amtBarely[g] + amtMiss[g]); if(amtInputs != 0){ validCategories += 1; } - g += 1; - }while (g < 7); + } distributedWeight = (float)(arg1->mScoreWeight[7]) / (float)(validCategories); distributedAmtInputs = (float)(amtHit[7] + amtBarely[7] + amtMiss[7]) / (float)(validCategories); - if(arg1->points[7] < 1){ + if (arg1->points[7] < 1) { distributedScore = (float)(arg1->points[7] + 1) / (float)(validCategories); } else { distributedScore = (float)(arg1->points[7]) / (float)(validCategories); } - do{ - if(i != 7){ + for (int i = 0; amtCategories > i; i++) { + if (i != 7) { amtInputs = (float)(amtHit[i] + amtBarely[i] + amtMiss[i]); if (amtInputs > 0) { - if((float)(amtHit[i] + amtBarely[i] + amtMiss[i]) < 1){ + if ((float)(amtHit[i] + amtBarely[i] + amtMiss[i]) < 1) { amtInputs = 0; } - else{ + else { amtInputs += distributedAmtInputs; - if(arg1->points[i] < 1){ + if (arg1->points[i] < 1) { catScore10000 = ((arg1->points[i] + distributedScore + 1) * 10000) / (amtInputs * arg1->mMaxWeight[i]); } else { catScore10000 = ((arg1->points[i] + distributedScore) * 10000) / (amtInputs * arg1->mMaxWeight[i]); @@ -203,16 +200,15 @@ namespace Megamix::Hooks { scoreDivWeight += curScoreWeight/catScore10000; } } - i += 1; - } while (amtCategories > i); + } - if (totalWeight > 0.0f){ + if (totalWeight > 0.0f) { result = totalWeight/scoreDivWeight; finalResult = (int)(result - (arg1->field9_0x18 * arg1->field14_0x2c)); - if(finalResult > 10000){ + if (finalResult > 10000) { finalResult = 10000; } - if (finalResult > 0){ + if (finalResult > 0) { return finalResult; } } diff --git a/src/Megamix/Region.cpp b/src/Megamix/Region.cpp index e82c15f..0dc284e 100644 --- a/src/Megamix/Region.cpp +++ b/src/Megamix/Region.cpp @@ -22,7 +22,7 @@ namespace Megamix { .dataEnd= 0x540754, .bssEnd= 0x5ce1f0, - .scoringFunctionPos= GameInterface::NO_PTR, + .scoringHookPos= GameInterface::UNIMPLEMENTED, .gameTable= (GameDef*)0x522498, .gateTable= (GateGameDef*)0x525488, @@ -71,7 +71,7 @@ namespace Megamix { .dataEnd= 0x54f074, .bssEnd= 0x5dc2f0, - .scoringFunctionPos= 0x276264, + .scoringHookPos= 0x276264, .gameTable= (GameDef*)0x52b498, .gateTable= (GateGameDef*)0x52e488, @@ -122,7 +122,7 @@ namespace Megamix { .dataEnd= 0x54f16c, .bssEnd= 0x5dc2f0, - .scoringFunctionPos= GameInterface::NO_PTR, + .scoringHookPos= GameInterface::UNIMPLEMENTED, .gameTable= (GameDef*)0x52b498, .gateTable= (GateGameDef*)0x52e488, @@ -168,7 +168,7 @@ namespace Megamix { .dataEnd= 0x54f16c, //TODO: check .bssEnd= 0x5dc2f0, - .scoringFunctionPos= GameInterface::NO_PTR, + .scoringHookPos= GameInterface::UNIMPLEMENTED, .gameTable= (GameDef*)0x52b498, .gateTable= (GateGameDef*)0x52e488, diff --git a/src/main.cpp b/src/main.cpp index f7a17fe..f1c1d36 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -103,7 +103,9 @@ void ctrpf::PatchProcess(ctrpf::FwkSettings&) { // Start hooks, apply patches Megamix::Hooks::TickflowHooks(); - Megamix::Hooks::ScoringHook(); + if(Megamix::isUS()) { + Megamix::Hooks::ScoringHook(); + } Megamix::Hooks::RegionHooks(); Megamix::Patches::PatchRetryRemix(); if (!Megamix::isJP()) { From 82bb78a5c6de5933407d201618d4e06d39565ce3 Mon Sep 17 00:00:00 2001 From: viviancherry9 Date: Thu, 21 May 2026 16:30:32 -0400 Subject: [PATCH 7/7] rename unnamed variables + move variable declaration --- include/Megamix/Types.hpp | 4 ++-- src/Megamix/Hooks.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/Megamix/Types.hpp b/include/Megamix/Types.hpp index 3c80c2c..3e0d0f5 100644 --- a/include/Megamix/Types.hpp +++ b/include/Megamix/Types.hpp @@ -570,12 +570,12 @@ namespace Megamix { u32* mAmtHit; u32* mAmtBarely; u32* mAmtMiss; - s32 field9_0x18; + s32 mAmtPenalties; s32 field10_0x1c; u32* mMaxWeight; u32* field12_0x24; u32* mScoreWeight; - u32 field14_0x2c; + u32 mPenalty; u32* field15_0x30; u32* field16_0x34; u32 mOkThreshold; diff --git a/src/Megamix/Hooks.cpp b/src/Megamix/Hooks.cpp index 84cfea7..a30a911 100644 --- a/src/Megamix/Hooks.cpp +++ b/src/Megamix/Hooks.cpp @@ -6,12 +6,12 @@ #include "Megamix.hpp" #include "Config.hpp" -std::vector debugScoreArray; - using CTRPluginFramework::OSD; using Megamix::TempoTable; +std::vector debugScoreArray; + // c++ is stupid namespace GHooks = Megamix::Game::Hooks; @@ -204,7 +204,7 @@ namespace Megamix::Hooks { if (totalWeight > 0.0f) { result = totalWeight/scoreDivWeight; - finalResult = (int)(result - (arg1->field9_0x18 * arg1->field14_0x2c)); + finalResult = (int)(result - (arg1->mAmtPenalties * arg1->mPenalty)); if (finalResult > 10000) { finalResult = 10000; }