@@ -66,6 +66,7 @@ ReplayManager::ReplayManager() {
66
66
m_offsetJudgingFunc = ref;
67
67
m_tapScoringFunc = ref;
68
68
m_totalWifePointsCalcFunc = ref;
69
+ m_missWindowFunc = ref;
69
70
70
71
LUA->Release (L);
71
72
}
@@ -530,7 +531,7 @@ ReplayManager::CustomTapScoringFunction(float fOffsetSeconds,
530
531
return wife3 (fOffsetSeconds , timingScale);
531
532
};
532
533
533
- if (m_tapScoringFunc.IsNil ()) {
534
+ if (m_tapScoringFunc.IsNil () || !customScoringFunctionsEnabled ) {
534
535
return defaultscoring (fOffsetSeconds , timingScale);
535
536
} else {
536
537
auto output = 0 .F ;
@@ -578,7 +579,7 @@ ReplayManager::CustomHoldNoteScoreScoringFunction(HoldNoteScore hns) -> float
578
579
}
579
580
};
580
581
581
- if (m_holdNoteScoreScoringFunc.IsNil ()) {
582
+ if (m_holdNoteScoreScoringFunc.IsNil () || !customScoringFunctionsEnabled ) {
582
583
return defaultscoring (hns);
583
584
} else {
584
585
auto output = 0 .F ;
@@ -612,7 +613,7 @@ ReplayManager::CustomMineScoringFunction() -> float
612
613
{
613
614
static auto defaultscoring = []() { return wife3_mine_hit_weight; };
614
615
615
- if (m_mineScoringFunc.IsNil ()) {
616
+ if (m_mineScoringFunc.IsNil () || !customScoringFunctionsEnabled ) {
616
617
return defaultscoring ();
617
618
} else {
618
619
auto output = 0 .F ;
@@ -654,7 +655,7 @@ ReplayManager::CustomTotalWifePointsCalculation(TapNoteType tnt) -> float
654
655
}
655
656
};
656
657
657
- if (m_totalWifePointsCalcFunc.IsNil ()) {
658
+ if (m_totalWifePointsCalcFunc.IsNil () || !customScoringFunctionsEnabled ) {
658
659
return defaultscoring (tnt);
659
660
} else {
660
661
auto output = 0 .F ;
@@ -691,7 +692,7 @@ ReplayManager::CustomOffsetJudgingFunction(float fOffsetSeconds, float timingSca
691
692
return GetTapNoteScoreForReplay (fOffsetSeconds , timingScale);
692
693
};
693
694
694
- if (m_offsetJudgingFunc.IsNil ()) {
695
+ if (m_offsetJudgingFunc.IsNil () || !customScoringFunctionsEnabled ) {
695
696
return defaultscoring (fOffsetSeconds , timingScale);
696
697
} else {
697
698
auto output = TNS_None;
@@ -714,6 +715,40 @@ ReplayManager::CustomOffsetJudgingFunction(float fOffsetSeconds, float timingSca
714
715
}
715
716
}
716
717
718
+ auto
719
+ ReplayManager::CustomMissWindowFunction () -> float
720
+ {
721
+ static auto defaultscoring = []() { return MISS_WINDOW_BEGIN_SEC; };
722
+
723
+ if (m_missWindowFunc.IsNil () || !customScoringFunctionsEnabled) {
724
+ return defaultscoring ();
725
+ } else {
726
+ auto output = 0 .F ;
727
+ auto L = LUA->Get ();
728
+ m_missWindowFunc.PushSelf (L);
729
+ static std::string err = " Error running custom miss window function" ;
730
+ if (LuaHelpers::RunScriptOnStack (L, err, 0 , 1 , true )) {
731
+ if (lua_isnumber (L, -1 )) {
732
+ output = std::clamp (static_cast <float >(lua_tonumber (L, -1 )),
733
+ 0 .F ,
734
+ MISS_WINDOW_BEGIN_SEC);
735
+ } else {
736
+ LuaHelpers::ReportScriptError (" You must return a number in the "
737
+ " Custom Miss Window Function." );
738
+ output = defaultscoring ();
739
+ }
740
+ } else {
741
+ output = defaultscoring ();
742
+ Locator::getLogger ()->warn (" Failed to run script on stack for "
743
+ " custom miss window function. "
744
+ " Defaulted to 180ms." );
745
+ }
746
+ lua_settop (L, 0 );
747
+ LUA->Release (L);
748
+ return output;
749
+ }
750
+ }
751
+
717
752
#include " Etterna/Models/Lua/LuaBinding.h"
718
753
class LunaReplayManager : public Luna <ReplayManager>
719
754
{
@@ -748,6 +783,7 @@ class LunaReplayManager : public Luna<ReplayManager>
748
783
p->SetHoldNoteScoringFunction (ref);
749
784
p->SetTapScoringFunction (ref);
750
785
p->SetOffsetJudgingFunction (ref);
786
+ p->SetMissWindowFunction (ref);
751
787
752
788
COMMON_RETURN_SELF;
753
789
}
@@ -868,6 +904,31 @@ class LunaReplayManager : public Luna<ReplayManager>
868
904
COMMON_RETURN_SELF;
869
905
}
870
906
907
+ static int SetMissWindowFunction (T* p, lua_State* L) {
908
+ // pass a lua function
909
+ // that lua function takes no input and returns a number
910
+ // the number is usually [0,1]
911
+ // 0.180 is the default
912
+
913
+ // reset if empty
914
+ if (lua_isnil (L, 1 )) {
915
+ LuaReference ref;
916
+ lua_pushnil (L);
917
+ ref.SetFromStack (L);
918
+ // reset
919
+ p->SetMissWindowFunction (ref);
920
+ } else {
921
+ luaL_checktype (L, 1 , LUA_TFUNCTION);
922
+ LuaReference ref;
923
+ lua_pushvalue (L, 1 );
924
+ ref.SetFromStack (L);
925
+ // set
926
+ p->SetMissWindowFunction (ref);
927
+ }
928
+
929
+ COMMON_RETURN_SELF;
930
+ }
931
+
871
932
static int RunOffsetJudgingFunction (T* p, lua_State* L) {
872
933
873
934
// this offset should be [-1,1] rather than [-1000,1000]
@@ -892,6 +953,7 @@ class LunaReplayManager : public Luna<ReplayManager>
892
953
ADD_METHOD (SetHoldNoteScoreScoringFunction);
893
954
ADD_METHOD (SetTapScoringFunction);
894
955
ADD_METHOD (SetOffsetJudgingFunction);
956
+ ADD_METHOD (SetMissWindowFunction);
895
957
896
958
ADD_METHOD (RunOffsetJudgingFunction);
897
959
}
0 commit comments