Skip to content

Commit

Permalink
Fix OOB errors in InitScoreStates
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicAglialoro committed May 25, 2022
1 parent 673ddb8 commit 46711e9
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace SRXDScoreMod;

[BepInDependency("com.pink.spinrhythm.moddingutils", "1.0.6")]
[BepInPlugin("SRXD.ScoreMod", "ScoreMod", "1.2.1.3")]
[BepInPlugin("SRXD.ScoreMod", "ScoreMod", "1.2.1.4")]
internal class Plugin : BaseUnityPlugin {
public static Plugin Instance { get; private set; }
public new static ManualLogSource Logger { get; private set; }
Expand Down
77 changes: 51 additions & 26 deletions ScoreSystems/CustomScoreSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -494,82 +494,107 @@ private void InitScoreStates() {
int availableStreak = 0;

switch (note.NoteType) {
case NoteType.Match:
case NoteType.Match: {
availablePoints = matchPointValue;
availableStreak = 1;

break;
case NoteType.DrumStart:
}
case NoteType.DrumStart: {
availablePoints = maxBeatValue;
availableSecondaryScore = 1;
availableStreak = 1;

if (note.length > 0f)
availableSustainPoints = Mathf.FloorToInt(beatHoldTickRate * note.length);

break;
}
case NoteType.SpinRightStart:
case NoteType.SpinLeftStart:
var spinnerSection = trackData.SpinnerSections[trackData.SpinnerSectionIndexForNoteIndex[i]];
case NoteType.SpinLeftStart: {
int index = trackData.SpinnerSectionIndexForNoteIndex[i];

if (index < 0 || index >= trackData.SpinnerSections.Count)
break;

var spinnerSection = trackData.SpinnerSections[index];

availablePoints = spinStartPointValue;
availableSustainPoints = Mathf.FloorToInt(spinTickRate * (spinnerSection.endsAtTime - spinnerSection.startsAtTime));
availableStreak = 1;

break;
case NoteType.HoldStart:
var freestyleSection0 = trackData.FreestyleSections[trackData.FreestyleSectionIndexForNoteIndex[i]];
}
case NoteType.HoldStart: {
int index = trackData.FreestyleSectionIndexForNoteIndex[i];

if (index < 0 || index >= trackData.FreestyleSections.Count)
break;

var freestyleSection = trackData.FreestyleSections[index];

availablePoints = maxTapValue;
availableSustainPoints = Mathf.FloorToInt(holdTickRate * (freestyleSection0.EndTime - freestyleSection0.Time));
availableSustainPoints = Mathf.FloorToInt(holdTickRate * (freestyleSection.EndTime - freestyleSection.Time));
availableSecondaryScore = 1;
availableStreak = 1;

break;
case NoteType.SectionContinuationOrEnd:
if (note.FreestyleEndType != FreestyleSection.EndType.Release)
}
case NoteType.SectionContinuationOrEnd: {
int index = trackData.FreestyleSectionIndexForNoteIndex[i];

if (index < 0 || index >= trackData.FreestyleSections.Count)
break;

var freestyleSection1 = trackData.FreestyleSections[trackData.FreestyleSectionIndexForNoteIndex[i]];

if (freestyleSection1.endNoteIndex != i)
var freestyleSection = trackData.FreestyleSections[index];

if (freestyleSection.endNoteIndex != i)
break;

availablePoints = maxLiftoffValue;
availableSecondaryScore = 1;
availableStreak = 1;

break;
case NoteType.Tap:
}
case NoteType.Tap: {
availablePoints = maxTapValue;
availableSecondaryScore = 1;
availableStreak = 1;

break;
case NoteType.DrumEnd:
}
case NoteType.DrumEnd: {
if (note.DrumEndType != DrumSection.EndType.Release)
break;

var startNote = trackData.GetNote(trackData.DrumIndexForNoteIndex[i]);
if (startNote.endNoteIndex != i)
int index = trackData.DrumIndexForNoteIndex[i];

if (index < 0 || index >= trackData.NoteCount || trackData.GetNote(index).endNoteIndex != i)
break;

availablePoints = maxBeatReleaseValue;
availableSecondaryScore = 1;
availableStreak = 1;

break;
case NoteType.ScratchStart:
var scratchSection = trackData.ScratchSections[trackData.ScratchSectionIndexForNoteIndex[i]];
}
case NoteType.ScratchStart: {
int index = trackData.ScratchSectionIndexForNoteIndex[i];

if (index < 0 || index >= trackData.ScratchSections.Count)
break;

var scratchSection = trackData.ScratchSections[index];

if (scratchSection.IsEmpty)
break;

availableSustainPoints = Mathf.FloorToInt(scratchTickRate * (scratchSection.endsAtTime - scratchSection.startsAtTime));
availableStreak = 1;

break;
}
}

maxPossibleScore += maxMultiplier * (availablePoints + availableSustainPoints);
Expand Down

0 comments on commit 46711e9

Please sign in to comment.