Skip to content

Commit 1e46cfc

Browse files
committed
feat: keysounds shuffling in funny
1 parent 18174f3 commit 1e46cfc

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

src/LR2HackBox/Features/Funny.cpp

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
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+
3469
bool 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
}

src/LR2HackBox/Features/Funny.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "BaseModels/ModFeature.hpp"
22

33
#include <safetyhook.hpp>
4+
#include <LR2Mem/LR2Typedefs.hpp>
45

56
#include <stdint.h>
67
class Funny : public ModFeature {
@@ -13,6 +14,7 @@ class Funny : public ModFeature {
1314
private:
1415
static void OnDrawNote(SafetyHookContext& regs);
1516
static int OnProcSinglenote(void* g, int lane, int keypress, int timing, int player);
17+
static void OnEndParseBmsFile(SafetyHookContext& regs);
1618
safetyhook::InlineHook oProcSinglenote;
1719

1820
int(__stdcall* FMOD_Channel_GetPan)(void*, float*) = nullptr;
@@ -23,4 +25,5 @@ class Funny : public ModFeature {
2325
bool mIsInvisibleScratch = false;
2426
bool mIsMetronome = false;
2527
bool mIsSpatialKeysounds = false;
28+
bool mIsShuffleKeysounds = false;
2629
};

0 commit comments

Comments
 (0)