Skip to content

Commit 2146655

Browse files
make new trimmed etterna save functions for highscores
1 parent e627277 commit 2146655

File tree

2 files changed

+145
-0
lines changed

2 files changed

+145
-0
lines changed

src/HighScore.cpp

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,14 @@ struct HighScoreImpl
4949
RadarValues radarValues;
5050
float fLifeRemainingSeconds;
5151
bool bDisqualified;
52+
RString ValidationKey;
5253

5354
HighScoreImpl();
5455
XNode *CreateNode() const;
56+
XNode *CreateEttNode() const;
5557
void LoadFromNode( const XNode *pNode );
58+
void LoadFromEttNode(const XNode *pNode);
59+
Grade GetWifeGrade() const;
5660

5761
bool WriteReplayData();
5862

@@ -97,6 +101,25 @@ bool HighScoreImpl::operator==( const HighScoreImpl& other ) const
97101
return true;
98102
}
99103

104+
Grade HighScoreImpl::GetWifeGrade() const {
105+
if (grade == Grade_Failed)
106+
return Grade_Failed;
107+
108+
if (fWifeScore >= 0.9998f)
109+
return Grade_Tier01;
110+
if (fWifeScore >= 0.9975f)
111+
return Grade_Tier02;
112+
if (fWifeScore >= 0.93f)
113+
return Grade_Tier03;
114+
if (fWifeScore >= 0.8f)
115+
return Grade_Tier04;
116+
if (fWifeScore >= 0.7f)
117+
return Grade_Tier05;
118+
if (fWifeScore >= 0.6f)
119+
return Grade_Tier06;
120+
return Grade_Tier07;
121+
}
122+
100123
RString HighScoreImpl::OffsetsToString(vector<float> v) const{
101124
RString o = "";
102125
if (v.empty())
@@ -202,6 +225,7 @@ HighScoreImpl::HighScoreImpl()
202225
ZERO( fSkillsetSSRs );
203226
radarValues.MakeUnknown();
204227
fLifeRemainingSeconds = 0;
228+
RString ValidationKey = "";
205229
}
206230

207231
XNode *HighScoreImpl::CreateNode() const
@@ -263,6 +287,120 @@ XNode *HighScoreImpl::CreateNode() const
263287
return pNode;
264288
}
265289

290+
XNode *HighScoreImpl::CreateEttNode() const
291+
{
292+
XNode *pNode = new XNode("HighScore");
293+
pNode->AppendChild("HistoricChartKey", sHistoricChartKey);
294+
pNode->AppendChild("ScoreKey", ScoreKey);
295+
pNode->AppendChild("SSRCalcVersion", SSRCalcVersion);
296+
pNode->AppendChild("Grade", GradeToString(GetWifeGrade()));
297+
pNode->AppendChild("WifeScore", fWifeScore);
298+
pNode->AppendChild("SSRNormPercent", fSSRNormPercent);
299+
pNode->AppendChild("Rate", fMusicRate);
300+
pNode->AppendChild("JudgeScale", fJudgeScale);
301+
pNode->AppendChild("NoChordCohesion", bNoChordCohesion);
302+
pNode->AppendChild("EtternaValid", bEtternaValid);
303+
304+
if (vOffsetVector.size() > 1) {
305+
pNode->AppendChild("Offsets", OffsetsToString(vOffsetVector));
306+
pNode->AppendChild("NoteRows", NoteRowsToString(vNoteRowVector));
307+
}
308+
309+
pNode->AppendChild("SurviveSeconds", fSurviveSeconds);
310+
pNode->AppendChild("MaxCombo", iMaxCombo);
311+
pNode->AppendChild("Modifiers", sModifiers);
312+
pNode->AppendChild("DateTime", dateTime.GetString());
313+
pNode->AppendChild("ProductID", iProductID);
314+
315+
XNode* pTapNoteScores = pNode->AppendChild("TapNoteScores");
316+
FOREACH_ENUM(TapNoteScore, tns)
317+
if (tns != TNS_None) // HACK: don't save meaningless "none" count
318+
pTapNoteScores->AppendChild(TapNoteScoreToString(tns), iTapNoteScores[tns]);
319+
320+
XNode* pHoldNoteScores = pNode->AppendChild("HoldNoteScores");
321+
FOREACH_ENUM(HoldNoteScore, hns)
322+
if (hns != HNS_None) // HACK: don't save meaningless "none" count
323+
pHoldNoteScores->AppendChild(HoldNoteScoreToString(hns), iHoldNoteScores[hns]);
324+
325+
// dont bother writing skillset ssrs for non-applicable scores
326+
if (fWifeScore > 0.f) {
327+
XNode* pSkillsetSSRs = pNode->AppendChild("SkillsetSSRs");
328+
FOREACH_ENUM(Skillset, ss)
329+
pSkillsetSSRs->AppendChild(SkillsetToString(ss), fSkillsetSSRs[ss]);
330+
}
331+
332+
pNode->AppendChild("Disqualified", bDisqualified);
333+
pNode->AppendChild("ValidationKey", ValidationKey);
334+
return pNode;
335+
}
336+
337+
void HighScoreImpl::LoadFromEttNode(const XNode *pNode)
338+
{
339+
ASSERT(pNode->GetName() == "HighScore");
340+
341+
RString s;
342+
343+
pNode->GetChildValue("HistoricChartKey", sHistoricChartKey);
344+
pNode->GetChildValue("SSRCalcVersion", SSRCalcVersion);
345+
pNode->GetChildValue("Grade", s);
346+
grade = StringToGrade(s);
347+
pNode->GetChildValue("WifeScore", fWifeScore);
348+
pNode->GetChildValue("SSRNormPercent", fSSRNormPercent);
349+
pNode->GetChildValue("Rate", fMusicRate);
350+
pNode->GetChildValue("JudgeScale", fJudgeScale);
351+
pNode->GetChildValue("NoChordCohesion", bNoChordCohesion);
352+
pNode->GetChildValue("EtternaValid", bEtternaValid);
353+
pNode->GetChildValue("Offsets", s); vOffsetVector = OffsetsToVector(s);
354+
pNode->GetChildValue("NoteRows", s); vNoteRowVector = NoteRowsToVector(s);
355+
pNode->GetChildValue("SurviveSeconds", fSurviveSeconds);
356+
pNode->GetChildValue("MaxCombo", iMaxCombo);
357+
pNode->GetChildValue("Modifiers", sModifiers);
358+
pNode->GetChildValue("DateTime", s); dateTime.FromString(s);
359+
pNode->GetChildValue("ScoreKey", ScoreKey);
360+
361+
if (fWifeScore > 0.f)
362+
ScoreKey = "S" + BinaryToHex(CryptManager::GetSHA1ForString(dateTime.GetString()));
363+
else
364+
ScoreKey = "";
365+
366+
const XNode* pTapNoteScores = pNode->GetChild("TapNoteScores");
367+
if (pTapNoteScores)
368+
FOREACH_ENUM(TapNoteScore, tns)
369+
pTapNoteScores->GetChildValue(TapNoteScoreToString(tns), iTapNoteScores[tns]);
370+
371+
const XNode* pHoldNoteScores = pNode->GetChild("HoldNoteScores");
372+
if (pHoldNoteScores)
373+
FOREACH_ENUM(HoldNoteScore, hns)
374+
pHoldNoteScores->GetChildValue(HoldNoteScoreToString(hns), iHoldNoteScores[hns]);
375+
376+
if (fWifeScore > 0.f) {
377+
const XNode* pSkillsetSSRs = pNode->GetChild("SkillsetSSRs");
378+
if (pSkillsetSSRs)
379+
FOREACH_ENUM(Skillset, ss)
380+
pSkillsetSSRs->GetChildValue(SkillsetToString(ss), fSkillsetSSRs[ss]);
381+
}
382+
383+
pNode->GetChildValue("Disqualified", bDisqualified);
384+
pNode->GetChildValue("ValidationKey", ValidationKey);
385+
386+
// special test case stuff - mina
387+
//if (vOffsetVector.size() > 1 && fWifeScore == 0.f)
388+
// fWifeScore = RescoreToWifeTS(fJudgeScale);
389+
if (vNoteRowVector.size() + vOffsetVector.size() > 2 && (vNoteRowVector.size() == vOffsetVector.size()) && fWifeScore > 0.f) {
390+
bool writesuccess = WriteReplayData();
391+
392+
// ensure data is written out somewhere else before destroying it
393+
if (writesuccess) {
394+
vector<int> itmp;
395+
vector<float> ftmp;
396+
vNoteRowVector.swap(itmp);
397+
vOffsetVector.swap(ftmp);
398+
}
399+
}
400+
// Validate input.
401+
grade = clamp(grade, Grade_Tier01, Grade_Failed);
402+
}
403+
266404
void HighScoreImpl::LoadFromNode(const XNode *pNode)
267405
{
268406
ASSERT(pNode->GetName() == "HighScore");
@@ -551,6 +689,11 @@ XNode* HighScore::CreateNode() const
551689
return m_Impl->CreateNode();
552690
}
553691

692+
XNode* HighScore::CreateEttNode() const
693+
{
694+
return m_Impl->CreateEttNode();
695+
}
696+
554697
void HighScore::LoadFromNode( const XNode* pNode )
555698
{
556699
m_Impl->LoadFromNode( pNode );

src/HighScore.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ struct HighScore
118118
bool operator!=(HighScore const& other) const;
119119

120120
XNode* CreateNode() const;
121+
XNode* CreateEttNode() const;
121122
void LoadFromNode( const XNode* pNode );
123+
void LoadEttNode(const XNode* pNode);
122124

123125
RString GetDisplayName() const;
124126

0 commit comments

Comments
 (0)