Skip to content

Commit

Permalink
Merge branch 'DoggettCK-AddMillisecondsToAchievementTimestamps'
Browse files Browse the repository at this point in the history
  • Loading branch information
hetelek committed May 13, 2014
2 parents 6e968cb + c7dc6d0 commit 34b5121
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 7 deletions.
1 change: 1 addition & 0 deletions Velocity/achievementcreationwizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ void AchievementCreationWizard::onFinished(int result)
achievement->gamerscore = ui->spnGamerscore->value();
achievement->flags = (ui->cmbxType->currentIndex() + 1) | (ui->cmbxSecret->currentIndex() << 3);
achievement->unlockTime = 0;
achievement->unlockTimeMilliseconds = 0;
achievement->structSize = 0x1C;

// set the thumbnail image
Expand Down
9 changes: 6 additions & 3 deletions Velocity/profileeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ void ProfileEditor::loadAchievementInfo(int gameIndex, unsigned int chievIndex)
ui->dteAchTimestamp->setEnabled(false);
}

ui->dteAchTimestamp->setDateTime(QDateTime::fromTime_t(entry.unlockTime));
ui->dteAchTimestamp->setDateTime(QDateTime::fromTime_t(entry.unlockTime).addMSecs(entry.unlockTimeMilliseconds));

// set the thumbnail
ImageEntry img;
Expand Down Expand Up @@ -966,7 +966,7 @@ void ProfileEditor::loadAvatarAwardInfo(int gameIndex, unsigned int awardIndex)
ui->dteAwTimestamp->setEnabled(false);
}

ui->dteAwTimestamp->setDateTime(QDateTime::fromTime_t(award->unlockTime));
ui->dteAwTimestamp->setDateTime(QDateTime::fromTime_t(award->unlockTime).addMSecs(award->unlockTimeMilliseconds));

// download the thumbnail
string tmp = AvatarAwardGpd::GetLargeAwardImageURL(award);
Expand Down Expand Up @@ -1692,7 +1692,9 @@ void ProfileEditor::on_dteAchTimestamp_dateTimeChanged(const QDateTime &date)
games.at(ui->gamesList->currentIndex().row()).gpd->StartWriting();

entry->unlockTime = date.toTime_t();
ui->dteAchTimestamp->setDateTime(QDateTime::fromTime_t(entry->unlockTime));
entry->unlockTimeMilliseconds = date.time().msec();

ui->dteAchTimestamp->setDateTime(QDateTime::fromTime_t(entry->unlockTime).addMSecs(entry->unlockTimeMilliseconds));
games.at(ui->gamesList->currentIndex().row()).gpd->WriteAchievementEntry(entry);
games.at(ui->gamesList->currentIndex().row()).updated = true;

Expand All @@ -1714,6 +1716,7 @@ void ProfileEditor::on_dteAwTimestamp_dateTimeChanged(const QDateTime &date)
return;

entry->unlockTime = date.toTime_t();
entry->unlockTimeMilliseconds = date.time().msec();
aaGames.at(ui->aaGamelist->currentIndex().row()).gpd->WriteAvatarAward(entry);
aaGames.at(ui->aaGamelist->currentIndex().row()).updated = true;

Expand Down
24 changes: 22 additions & 2 deletions Velocity/profileeditor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,17 @@ p, li { white-space: pre-wrap; }
</property>
<layout class="QVBoxLayout" name="verticalLayout_16">
<item>
<widget class="QDateTimeEdit" name="dteAchTimestamp"/>
<widget class="QDateTimeEdit" name="dteAchTimestamp">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="displayFormat">
<string>yyyy-MM-dd hh:mm:ss.zzz AP</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cmbxAchState">
Expand Down Expand Up @@ -1482,7 +1492,17 @@ p, li { white-space: pre-wrap; }
</property>
<layout class="QVBoxLayout" name="verticalLayout_10">
<item>
<widget class="QDateTimeEdit" name="dteAwTimestamp"/>
<widget class="QDateTimeEdit" name="dteAwTimestamp">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="displayFormat">
<string>yyyy-MM-dd hh:mm:ss.zzz AP</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cmbxAwState">
Expand Down
3 changes: 2 additions & 1 deletion XboxInternals/Gpd/AvatarAwardGpd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct AvatarAward AvatarAwardGpd::readAvatarAwardEntry(XdbfEntry entry)
// read the unlock time
WINFILETIME time = { io->ReadDword(), io->ReadDword() };
award.unlockTime = XdbfHelpers::FILETIMEtoTimeT(time);
award.unlockTimeMilliseconds = XdbfHelpers::FILETIMEtoMilliseconds(time);

// read the rest of the entry
award.subcategory = (AssetSubcategory)io->ReadDword();
Expand Down Expand Up @@ -143,7 +144,7 @@ void AvatarAwardGpd::WriteAvatarAward(struct AvatarAward *award)
io->Write(award->flags);

// Write the unlock time
WINFILETIME time = XdbfHelpers::TimeTtoFILETIME(award->unlockTime);
WINFILETIME time = XdbfHelpers::TimeTtoFILETIME(award->unlockTime, award->unlockTimeMilliseconds);
io->Write(time.dwHighDateTime);
io->Write(time.dwLowDateTime);

Expand Down
8 changes: 7 additions & 1 deletion XboxInternals/Gpd/GameGpd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ AchievementEntry GameGpd::readAchievementEntry(XdbfEntry entry)

WINFILETIME timeStamp = { io->ReadDword(), io->ReadDword() };
toReturn.unlockTime = XdbfHelpers::FILETIMEtoTimeT(timeStamp);
toReturn.unlockTimeMilliseconds = XdbfHelpers::FILETIMEtoMilliseconds(timeStamp);

toReturn.name = io->ReadWString();
toReturn.unlockedDescription = io->ReadWString();
Expand Down Expand Up @@ -80,10 +81,15 @@ void GameGpd::WriteAchievementEntry(AchievementEntry *entry)
if (entry->flags & UnlockedOnline)
{
if (entry->unlockTime == 0)
/*
Not worrying about whether the milliseconds are 0,
because a timestamp of 0000-00-00 00:00:00.123
surely wouldn't be suspicious.
*/
io->Write((UINT64)0);
else
{
WINFILETIME time = XdbfHelpers::TimeTtoFILETIME(entry->unlockTime);
WINFILETIME time = XdbfHelpers::TimeTtoFILETIME(entry->unlockTime, entry->unlockTimeMilliseconds);
io->Write(time.dwHighDateTime);
io->Write(time.dwLowDateTime);
}
Expand Down
2 changes: 2 additions & 0 deletions XboxInternals/Gpd/XdbfDefininitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ struct AchievementEntry
DWORD gamerscore;
DWORD flags;
unsigned int unlockTime;
unsigned int unlockTimeMilliseconds;
wstring name;
wstring lockedDescription;
wstring unlockedDescription;
Expand Down Expand Up @@ -427,6 +428,7 @@ struct AvatarAward
DWORD imageID;
DWORD flags;
unsigned int unlockTime;
unsigned int unlockTimeMilliseconds;
AssetSubcategory subcategory;
DWORD colorizable;
wstring name;
Expand Down
25 changes: 25 additions & 0 deletions XboxInternals/Gpd/XdbfHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ time_t XdbfHelpers::FILETIMEtoTimeT(WINFILETIME time)
return (time_t)((i64 - 116444736000000000) / 10000000);
}

unsigned int XdbfHelpers::FILETIMEtoMilliseconds(WINFILETIME time)
{
/* Effectively the same as FILETIMEtoTimeT, but we're leaving
the milliseconds on, and stripping them out with a modulus.
TODO: Maybe just make this void with two reference parameters
to fill a time_t and unsigned int.
*/
INT64 i64 = (((INT64)(time.dwHighDateTime)) << 32) + time.dwLowDateTime;
return (unsigned int)(((i64 - 116444736000000000) / 10000) % 1000);
}

WINFILETIME XdbfHelpers::TimeTtoFILETIME(time_t time)
{
WINFILETIME toReturn;
Expand All @@ -46,6 +58,19 @@ WINFILETIME XdbfHelpers::TimeTtoFILETIME(time_t time)
return toReturn;
}

WINFILETIME XdbfHelpers::TimeTtoFILETIME(time_t time, unsigned int millis)
{
// TODO: Can just have the old function call this with 0ms
millis = millis % 1000; // make sure 0-999 ms

WINFILETIME toReturn;

UINT64 ll = ((UINT64)(time * (UINT64)10000000)) + ((UINT64)(millis * (UINT64)10000)) + 116444736000000000;
toReturn.dwLowDateTime = (DWORD)ll;
toReturn.dwHighDateTime = ll >> 32;
return toReturn;
}

string XdbfHelpers::GetAchievementState(AchievementEntry *entry)
{
if (entry->flags & UnlockedOnline)
Expand Down
4 changes: 4 additions & 0 deletions XboxInternals/Gpd/XdbfHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ class XBOXINTERNALSSHARED_EXPORT XdbfHelpers

static time_t FILETIMEtoTimeT(WINFILETIME time);

static unsigned int FILETIMEtoMilliseconds(WINFILETIME time);

static WINFILETIME TimeTtoFILETIME(time_t time);

static WINFILETIME TimeTtoFILETIME(time_t time, unsigned int milliseconds);

static string AchievementTypeToString(AchievementFlags type);

static string RegionIDtoString(XboxLiveCountry id);
Expand Down

0 comments on commit 34b5121

Please sign in to comment.