11#include " Funny.hpp"
22
3- #include < iostream>
43#include " LR2HackBox/LR2HackBox.hpp"
54#include " Misc.hpp"
5+ #include < random>
66
77#include < safetyhook.hpp>
88#include " imgui/imgui.h"
@@ -31,6 +31,41 @@ int Funny::OnProcSinglenote(void* g, int lane, int keypress, int timing, int pla
3131 return result;
3232}
3333
34+ void Funny::OnEndParseBmsFile (SafetyHookContext& regs) {
35+ Funny& funny = *(Funny*)(LR2HackBox::Get ().mFunny .get ());
36+ if (!funny.mIsShuffleKeysounds ) return ;
37+
38+ LR2::gameplay& gameplay = LR2HackBox::Get ().GetGame ()->gameplay ;
39+ std::unordered_map<double , double > randomKeysoundsMapping;
40+ std::vector<double > shuffledKeysounds;
41+ for (int laneIdx = 0 ; laneIdx < 20 ; laneIdx++) {
42+ LR2::LaneStruct& lane = gameplay.bmsobj_note [laneIdx];
43+ if (lane.count == 0 ) continue ;
44+ for (int noteIdx = 0 ; noteIdx < lane.count ; noteIdx++) {
45+ if (randomKeysoundsMapping.contains (lane.notes [noteIdx].val )) continue ;
46+ randomKeysoundsMapping[lane.notes [noteIdx].val ] = 0 ;
47+ shuffledKeysounds.push_back (lane.notes [noteIdx].val );
48+ }
49+ }
50+
51+ std::mt19937 g (gameplay.randomseed );
52+ std::shuffle (shuffledKeysounds.begin (), shuffledKeysounds.end (), g);
53+ int i = 0 ;
54+ for (auto & it : randomKeysoundsMapping) {
55+ it.second = shuffledKeysounds[i];
56+ i++;
57+ }
58+
59+ for (int laneIdx = 0 ; laneIdx < 20 ; laneIdx++) {
60+ LR2::LaneStruct& lane = gameplay.bmsobj_note [laneIdx];
61+ if (lane.count == 0 ) continue ;
62+ for (int noteIdx = 0 ; noteIdx < lane.count ; noteIdx++) {
63+ LR2::NoteStruct& note = lane.notes [noteIdx];
64+ note.val = randomKeysoundsMapping[note.val ];
65+ }
66+ }
67+ }
68+
3469bool Funny::Init (uintptr_t moduleBase) {
3570 Funny::mModuleBase = moduleBase;
3671
@@ -39,7 +74,10 @@ bool Funny::Init(uintptr_t moduleBase) {
3974 FMOD_Channel_SetPan = (decltype (FMOD_Channel_SetPan))GetProcAddress (fmodModule, " FMOD_Channel_SetPan" );
4075
4176 mMidHooks .push_back (safetyhook::create_mid ((void *)(moduleBase + 0x7098 ), OnDrawNote));
77+ #ifdef NDEBUG
4278 oProcSinglenote = safetyhook::create_inline (moduleBase + 0x018850 , OnProcSinglenote);
79+ #endif
80+ mMidHooks .push_back (safetyhook::create_mid (moduleBase + 0x0B64D9 , OnEndParseBmsFile));
4381
4482 return true ;
4583}
@@ -75,4 +113,8 @@ void Funny::Menu() {
75113 ImGui::Checkbox (" Spatial Keysounds" , &mIsSpatialKeysounds );
76114 ImGui::SameLine ();
77115 HelpMarker (" Left ear, right ear, left ear, middle, left ear, right ear" );
116+
117+ ImGui::Checkbox (" Shuffle Keysounds" , &mIsShuffleKeysounds );
118+ ImGui::SameLine ();
119+ HelpMarker (" Randomly shuffles keysounds of a chart. Makes predictable result combined with unrandomizer. Doesn't work in autoplay" );
78120}
0 commit comments