From 21b82d3a7bded725f743cd73c3571803eac1ab98 Mon Sep 17 00:00:00 2001 From: MinaciousGrace Date: Sun, 30 Apr 2017 22:19:30 -0400 Subject: [PATCH] pick writereplaydata savedir based on whether its called from load or playerstagestats write out replaydata during fillinhighscore and purge it from the highscore object if successful which it wont be because it doesn't work and i have no idea why --- src/HighScore.cpp | 57 ++++++++++++++++++++++++++++------------------ src/HighScore.h | 5 +++- src/StageStats.cpp | 27 ++++++++++++++++++---- 3 files changed, 61 insertions(+), 28 deletions(-) diff --git a/src/HighScore.cpp b/src/HighScore.cpp index 637af321a0..817bbaba22 100644 --- a/src/HighScore.cpp +++ b/src/HighScore.cpp @@ -57,8 +57,9 @@ struct HighScoreImpl void LoadFromNode( const XNode *pNode ); void LoadFromEttNode(const XNode *pNode); Grade GetWifeGrade() const; + void UnloadReplayData(); - bool WriteReplayData(); + bool WriteReplayData(bool duringload); float RescoreToWifeTS(float ts); @@ -101,6 +102,13 @@ bool HighScoreImpl::operator==( const HighScoreImpl& other ) const return true; } +void HighScoreImpl::UnloadReplayData() { + vector tmpi; + vector tmpf; + vNoteRowVector.swap(tmpi); + vOffsetVector.swap(tmpf); +} + Grade HighScoreImpl::GetWifeGrade() const { if (grade == Grade_Failed) return Grade_Failed; @@ -387,15 +395,11 @@ void HighScoreImpl::LoadFromEttNode(const XNode *pNode) //if (vOffsetVector.size() > 1 && fWifeScore == 0.f) // fWifeScore = RescoreToWifeTS(fJudgeScale); if (vNoteRowVector.size() + vOffsetVector.size() > 2 && (vNoteRowVector.size() == vOffsetVector.size()) && fWifeScore > 0.f) { - bool writesuccess = WriteReplayData(); + bool writesuccess = WriteReplayData(true); // ensure data is written out somewhere else before destroying it - if (writesuccess) { - vector itmp; - vector ftmp; - vNoteRowVector.swap(itmp); - vOffsetVector.swap(ftmp); - } + if (writesuccess) + UnloadReplayData(); } // Validate input. grade = clamp(grade, Grade_Tier01, Grade_Failed); @@ -477,32 +481,34 @@ void HighScoreImpl::LoadFromNode(const XNode *pNode) //if (vOffsetVector.size() > 1 && fWifeScore == 0.f) // fWifeScore = RescoreToWifeTS(fJudgeScale); if (vNoteRowVector.size() + vOffsetVector.size() > 2 && (vNoteRowVector.size() == vOffsetVector.size()) && fWifeScore > 0.f) { - bool writesuccess = WriteReplayData(); + bool writesuccess = WriteReplayData(true); // ensure data is written out somewhere else before destroying it - if (writesuccess) { - vector itmp; - vector ftmp; - vNoteRowVector.swap(itmp); - vOffsetVector.swap(ftmp); - } + if (writesuccess) + UnloadReplayData(); } // Validate input. grade = clamp( grade, Grade_Tier01, Grade_Failed ); } -bool HighScoreImpl::WriteReplayData() { +bool HighScoreImpl::WriteReplayData(bool duringload) { RString append; + RString profiledir; + //open file - RString profiledir = PROFILEMAN->currentlyloadingprofile; - ofstream fileStream(profiledir + "ReplayData/" + ScoreKey, ios::binary); + if (duringload) + profiledir = PROFILEMAN->currentlyloadingprofile; + else + profiledir = PROFILEMAN->GetProfileDir(ProfileSlot_Player1); + + RString path = profiledir + "ReplayData/" + ScoreKey; + ofstream fileStream(path, ios::binary); //check file if (!fileStream) { - LOG->Warn("Failed to create replay file"); + LOG->Warn("Failed to create replay file at %s", path); return false; } - unsigned int idx = vNoteRowVector.size() - 1; //loop for writing both vectors side by side for (unsigned int i = 0; i < idx; i++) { @@ -512,6 +518,8 @@ bool HighScoreImpl::WriteReplayData() { append = to_string(vNoteRowVector[idx]) + " " + to_string(vOffsetVector[idx]); fileStream.write(append.c_str(), append.size()); fileStream.close(); + + LOG->Warn("Created replay file at %s", path); return true; } @@ -635,6 +643,7 @@ void HighScore::SetChordCohesion(bool b) { m_Impl->bNoChordCohesion = b; } void HighScore::SetEtternaValid(bool b) { m_Impl->bEtternaValid = b; } void HighScore::SetOffsetVector(const vector& v) { m_Impl->vOffsetVector = v; } void HighScore::SetNoteRowVector(const vector& v) { m_Impl->vNoteRowVector = v; } +void HighScore::SetScoreKey(RString sk) { m_Impl->ScoreKey = sk; } void HighScore::SetRescoreJudgeVector(const vector& v) { m_Impl->vRescoreJudgeVector = v; } void HighScore::SetAliveSeconds( float f ) { m_Impl->fSurviveSeconds = f; } void HighScore::SetModifiers( const RString &s ) { m_Impl->sModifiers = s; } @@ -649,6 +658,10 @@ void HighScore::SetRadarValues( const RadarValues &rv ) { m_Impl->radarValues = void HighScore::SetLifeRemainingSeconds( float f ) { m_Impl->fLifeRemainingSeconds = f; } void HighScore::SetDisqualified( bool b ) { m_Impl->bDisqualified = b; } +void HighScore::UnloadReplayData() { + m_Impl->UnloadReplayData(); +} + /* We normally don't give direct access to the members. We need this one * for NameToFillIn; use a special accessor so it's easy to find where this * is used. */ @@ -988,8 +1001,8 @@ Grade HighScore::GetWifeGrade() { return m_Impl->GetWifeGrade(); } -bool HighScore::WriteReplayData() { - return m_Impl->WriteReplayData(); +bool HighScore::WriteReplayData(bool duringload) { + return m_Impl->WriteReplayData(duringload); } // Ok I guess we can be more lenient and convert by midwindow values, but we still have to assume j4 - mina diff --git a/src/HighScore.h b/src/HighScore.h index f729941fa4..ac33b1f5dd 100644 --- a/src/HighScore.h +++ b/src/HighScore.h @@ -89,6 +89,7 @@ struct HighScore void SetEtternaValid(bool b); void SetOffsetVector(const vector& v); void SetNoteRowVector(const vector& v); + void SetScoreKey(RString ck); void SetRescoreJudgeVector(const vector& v); void SetAliveSeconds( float f ); void SetMaxCombo( unsigned int i ); @@ -121,7 +122,9 @@ struct HighScore XNode* CreateEttNode() const; void LoadFromNode( const XNode* pNode ); void LoadFromEttNode(const XNode* pNode); - bool WriteReplayData(); + + bool WriteReplayData(bool duringload); + void UnloadReplayData(); RString GetDisplayName() const; diff --git a/src/StageStats.cpp b/src/StageStats.cpp index 8958b194e1..05cacec473 100644 --- a/src/StageStats.cpp +++ b/src/StageStats.cpp @@ -10,6 +10,9 @@ #include "Style.h" #include "Profile.h" #include "ProfileManager.h" +#include +#include +#include "CryptManager.h" /* Arcade: for the current stage (one song). * Nonstop/Oni/Endless: for current course (which usually contains multiple songs) @@ -132,13 +135,10 @@ float StageStats::GetTotalPossibleStepsSeconds() const return fSecs / m_fMusicRate; } -static HighScore FillInHighScore( const PlayerStageStats &pss, const PlayerState &ps, RString sRankingToFillInMarker, RString sPlayerGuid ) +static HighScore FillInHighScore(const PlayerStageStats &pss, const PlayerState &ps, RString sRankingToFillInMarker, RString sPlayerGuid) { HighScore hs; - hs.SetName( sRankingToFillInMarker ); - - hs.SetOffsetVector(pss.GetOffsetVector()); - hs.SetNoteRowVector(pss.GetNoteRowVector()); + hs.SetName(sRankingToFillInMarker); auto chartKey = GAMESTATE->m_pCurSteps[ps.m_PlayerNumber]->GetChartKey(); hs.SetHistoricChartKey(chartKey); @@ -201,6 +201,23 @@ static HighScore FillInHighScore( const PlayerStageStats &pss, const PlayerState hs.SetLifeRemainingSeconds( pss.m_fLifeRemainingSeconds ); hs.SetDisqualified( pss.IsDisqualified() ); + + // should maybe just make the setscorekey function do this internally rather than recalling the datetime object -mina + RString ScoreKey = "S" + BinaryToHex(CryptManager::GetSHA1ForString(hs.GetDateTime().GetString())); + hs.SetScoreKey(ScoreKey); + + // DOES NOT WORK NEEDS FIX -mina + // the vectors stored in pss are what are accessed by evaluation so we can write + // them to the replay file instead of the highscore object (if successful) -mina + // this is kinda messy meh -mina + if (pss.m_fWifeScore > 0.f) { + hs.SetOffsetVector(pss.GetOffsetVector()); + hs.SetNoteRowVector(pss.GetNoteRowVector()); + bool writesuccess = hs.WriteReplayData(false); + if (writesuccess) + hs.UnloadReplayData(); + } + return hs; }