Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
build
*.3gx
*.elf
*.kate-swp

.vscode
.cache
compile_commands.json
3gxtool
compile_commands.json
3 changes: 3 additions & 0 deletions include/Megamix/Hooks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ namespace Megamix::Hooks {
void TempoHooks();
void RegionHooks();
void CommandHook();
void ScoringHook();
void DisableAllHooks();

template<typename T> T StubbedFunction();
template<typename T> void StubFunction(u32 address);
}

extern std::vector<float> debugScoreArray;

#endif
7 changes: 6 additions & 1 deletion include/Megamix/Region.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ namespace Megamix {
u32 dataEnd;
u32 bssEnd;

// scoring crap
u32 scoringHookPos;

// game definitions

GameDef* gameTable;
Expand Down Expand Up @@ -151,6 +154,8 @@ namespace Megamix {
inline u32 seqTempo() { return pointers->seqTempoHookPos; }
inline u32 allTempo() { return pointers->allTempoHookPos; }

inline u32 scoring() { return pointers->scoringHookPos; }

inline u32 megamixRegionCode() { return pointers->regionAHookPos; }
inline u32 sdkRegionCode() { return pointers->regionBHookPos; }
}
Expand Down Expand Up @@ -193,4 +198,4 @@ namespace Megamix {
}
}

#endif
#endif
38 changes: 38 additions & 0 deletions include/Megamix/Types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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* mAmtHit;
u32* mAmtBarely;
u32* mAmtMiss;
s32 mAmtPenalties;
s32 field10_0x1c;
u32* mMaxWeight;
u32* field12_0x24;
u32* mScoreWeight;
u32 mPenalty;
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
2 changes: 1 addition & 1 deletion src/Megamix/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
85 changes: 85 additions & 0 deletions src/Megamix/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ using CTRPluginFramework::OSD;

using Megamix::TempoTable;

std::vector<float> debugScoreArray;

// c++ is stupid
namespace GHooks = Megamix::Game::Hooks;

Expand All @@ -27,6 +29,8 @@ 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]);
Expand Down Expand Up @@ -138,6 +142,79 @@ namespace Megamix::Hooks {
return RegionMegamix::UNK;
}

int decideFinalScore(Megamix::CResultManager *arg1) {
u8 amtCategories = arg1->mAmtCategories;
u32* amtHit = arg1->mAmtHit;
u32* amtBarely = arg1->mAmtBarely;
u32* amtMiss = arg1->mAmtMiss;
float catScore10000 = 0.0f;
float totalWeight = 0.0f;
float scoreDivWeight = 0.0f;
float amtInputs = 0.0f;
float result = 0.0f;
int finalResult = 0;
float curScoreWeight = 0.0f;
int validCategories = 0;
float distributedWeight = 0.0f;
float distributedAmtInputs = 0.0f;
float distributedScore = 0.0f;

debugScoreArray.clear();

if (amtCategories != 0) {
for (int g = 0; g < 7; g++) {
amtInputs = (int)(amtHit[g] + amtBarely[g] + amtMiss[g]);
if(amtInputs != 0){
validCategories += 1;
}
}

distributedWeight = (float)(arg1->mScoreWeight[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);
}

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) {
amtInputs = 0;
}
else {
amtInputs += distributedAmtInputs;
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]);
}
}

debugScoreArray.push_back(catScore10000);

curScoreWeight = (float)(arg1->mScoreWeight[i]) + distributedWeight;
totalWeight += curScoreWeight;
scoreDivWeight += curScoreWeight/catScore10000;
}
}
}

if (totalWeight > 0.0f) {
result = totalWeight/scoreDivWeight;
finalResult = (int)(result - (arg1->mAmtPenalties * arg1->mPenalty));
if (finalResult > 10000) {
finalResult = 10000;
}
if (finalResult > 0) {
return finalResult;
}
}
}
return 0;
}

void TickflowHooks() {
rtInitHook(&tickflowHook, GHooks::tickflow(), (u32)getTickflowOffset);
Expand Down Expand Up @@ -171,6 +248,11 @@ namespace Megamix::Hooks {
rtEnableHook(&tickflowCommandsHook);
}

void ScoringHook(){
rtInitHook(&scoringFunctionHook, GHooks::scoring(), (int)decideFinalScore);
rtEnableHook(&scoringFunctionHook);
}

void DisableAllHooks() {
rtDisableHook(&tickflowHook);
rtDisableHook(&gateHook);
Expand All @@ -179,9 +261,12 @@ namespace Megamix::Hooks {
rtDisableHook(&tempoAllHook);
rtDisableHook(&regionFSHook);
rtDisableHook(&regionOtherHook);
rtDisableHook(&scoringFunctionHook);
rtDisableHook(&tickflowCommandsHook);
}



template<typename T>
T StubbedFunction() {
return {};
Expand Down
8 changes: 8 additions & 0 deletions src/Megamix/Region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace Megamix {
.dataEnd= 0x540754,
.bssEnd= 0x5ce1f0,

.scoringHookPos= GameInterface::UNIMPLEMENTED,

.gameTable= (GameDef*)0x522498,
.gateTable= (GateGameDef*)0x525488,
.tickflowHookPos= 0x25a1b4,
Expand Down Expand Up @@ -69,6 +71,8 @@ namespace Megamix {
.dataEnd= 0x54f074,
.bssEnd= 0x5dc2f0,

.scoringHookPos= 0x276264,

.gameTable= (GameDef*)0x52b498,
.gateTable= (GateGameDef*)0x52e488,
.tickflowHookPos= 0x258df4,
Expand Down Expand Up @@ -118,6 +122,8 @@ namespace Megamix {
.dataEnd= 0x54f16c,
.bssEnd= 0x5dc2f0,

.scoringHookPos= GameInterface::UNIMPLEMENTED,

.gameTable= (GameDef*)0x52b498,
.gateTable= (GateGameDef*)0x52e488,
.tickflowHookPos= 0x258df4,
Expand Down Expand Up @@ -162,6 +168,8 @@ namespace Megamix {
.dataEnd= 0x54f16c, //TODO: check
.bssEnd= 0x5dc2f0,

.scoringHookPos= GameInterface::UNIMPLEMENTED,

.gameTable= (GameDef*)0x52b498,
.gateTable= (GateGameDef*)0x52e488,
.tickflowHookPos= 0x258dcc,
Expand Down
13 changes: 13 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ void ctrpf::PatchProcess(ctrpf::FwkSettings&) {

// Start hooks, apply patches
Megamix::Hooks::TickflowHooks();
if(Megamix::isUS()) {
Megamix::Hooks::ScoringHook();
}
Megamix::Hooks::RegionHooks();
Megamix::Patches::PatchRetryRemix();
if (!Megamix::isJP()) {
Expand Down Expand Up @@ -135,6 +138,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))();
});
Expand Down