@@ -96,22 +96,28 @@ int BattleFixes::OnAddDrawingBuffer_PlayArea(LR2::DrawingBuf* drb, LR2::SRCstruc
9696 }
9797}
9898
99- int BattleFixes::OnProcSinglenote (LR2::game* g, int lane, int keypress, int timing, int player) {
99+ void BattleFixes::OnBeginProcNote (SafetyHookContext& regs) {
100+ BattleFixes& battleFixes = *(BattleFixes*)(LR2HackBox::Get ().mBattleFixes .get ());
101+ LR2::game& game = *LR2HackBox::Get ().GetGame ();
102+ if (!battleFixes.mIsEnabled || game.config .play .battle != 1 ) return ;
103+ battleFixes.autoadjust_lastPlayer = *(int *)(regs.esp + 0x14 );
104+ battleFixes.autoadjust_lastMidCount = game.gameplay .autojudge_midcount ;
105+ battleFixes.autoadjust_lastMidSum = game.gameplay .autojudge_midsum ;
106+ }
107+
108+ void BattleFixes::OnEndProcNote (SafetyHookContext& regs) {
100109 BattleFixes& battleFixes = *(BattleFixes*)(LR2HackBox::Get ().mBattleFixes .get ());
101110 GameOptions& options = *(GameOptions*)(LR2HackBox::Get ().mGameOptions .get ());
102- if (!battleFixes.mIsEnabled ) return battleFixes.oProcSinglenote .ccall <int >(g, lane, keypress, timing, player);
103- int oldMidCount = g->gameplay .autojudge_midcount ;
104- int oldMidSum = g->gameplay .autojudge_midsum ;
105- int retVal = battleFixes.oProcSinglenote .ccall <int >(g, lane, keypress, timing, player);
106- if (player == 1 ) {
107- if (oldMidCount != g->gameplay .autojudge_midcount ) {
111+ LR2::game& game = *LR2HackBox::Get ().GetGame ();
112+ if (!battleFixes.mIsEnabled || game.config .play .battle != 1 ) return ;
113+ if (battleFixes.autoadjust_lastPlayer == 1 ) {
114+ if (battleFixes.autoadjust_lastMidCount != game.gameplay .autojudge_midcount ) {
108115 battleFixes.autoadjust_midcountP2 ++;
109- battleFixes.autoadjust_midsumP2 += g-> gameplay .autojudge_midsum - oldMidSum ;
110- g-> gameplay .autojudge_midcount = oldMidCount ;
111- g-> gameplay .autojudge_midsum = oldMidSum ;
116+ battleFixes.autoadjust_midsumP2 += game. gameplay .autojudge_midsum - battleFixes. autoadjust_lastMidSum ;
117+ game. gameplay .autojudge_midcount = battleFixes. autoadjust_lastMidCount ;
118+ game. gameplay .autojudge_midsum = battleFixes. autoadjust_lastMidSum ;
112119 }
113120 }
114- return retVal;
115121}
116122
117123void BattleFixes::OnCheckAutoadjustCondition (SafetyHookContext& regs) {
@@ -152,18 +158,12 @@ void BattleFixes::OnCheckMousewheelLanecover(SafetyHookContext& regs) {
152158 }
153159}
154160
155- void BattleFixes::OnGameStart (SafetyHookContext& regs) {
161+ void BattleFixes::OnShuffleNotesLoop (SafetyHookContext& regs) {
162+ BattleFixes& battleFixes = *(BattleFixes*)(LR2HackBox::Get ().mBattleFixes .get ());
156163 LR2::game& game = *LR2HackBox::Get ().GetGame ();
157-
158- int totalnotes[2 ];
159- memset (totalnotes, 0 , sizeof (totalnotes));
160- for (int lane = 0 ; lane < 20 ; lane++) {
161- int laneCount = game.gameplay .bmsobj_note [lane].count ;
162- int player = lane < 10 ? 0 : 1 ;
163- totalnotes[player] += laneCount;
164- }
165- game.gameplay .player [0 ].totalnotes = totalnotes[0 ];
166- game.gameplay .player [1 ].totalnotes = totalnotes[1 ];
164+ if (!battleFixes.mIsEnabled ) return ;
165+ unsigned int & isBattle = *(unsigned int *)(regs.esp + 0x48 );
166+ isBattle = 0 ;
167167}
168168
169169void BattleFixes::SceneInit () {
@@ -172,6 +172,9 @@ void BattleFixes::SceneInit() {
172172 lastLineBmstime = -1 .;
173173 autoadjust_midcountP2 = 0 ;
174174 autoadjust_midsumP2 = 0 ;
175+ autoadjust_lastPlayer = 0 ;
176+ autoadjust_lastMidCount = 0 ;
177+ autoadjust_lastMidSum = 0 ;
175178}
176179
177180static void ApplyP2ShutterFix (bool enable) {
@@ -214,12 +217,14 @@ bool BattleFixes::Init(uintptr_t moduleBase) {
214217 mMidHooks .push_back (safetyhook::create_mid (0x42BC62 , OnSetBpmChangedBmstime));
215218 oAddDrawingBuffer_PlayArea = safetyhook::create_inline (0x49D630 , OnAddDrawingBuffer_PlayArea);
216219
217- oProcSinglenote = safetyhook::create_inline (moduleBase + 0x018850 , OnProcSinglenote);
220+ mMidHooks .push_back (safetyhook::create_mid (0x419320 , OnBeginProcNote));
221+ mMidHooks .push_back (safetyhook::create_mid (0x419410 , OnEndProcNote));
222+ mMidHooks .push_back (safetyhook::create_mid (0x419432 , OnEndProcNote));
218223 mMidHooks .push_back (safetyhook::create_mid (0x42C832 , OnCheckAutoadjustCondition));
219224
220225 mMidHooks .push_back (safetyhook::create_mid (0x427779 , OnCheckMousewheelLanecover));
221226
222- mMidHooks .push_back (safetyhook::create_mid (0x42CD2C , OnGameStart ));
227+ mMidHooks .push_back (safetyhook::create_mid (0x4B4A30 , OnShuffleNotesLoop ));
223228
224229 ApplyP2ShutterFix (mIsEnabled );
225230
0 commit comments