Skip to content

Commit be49c5a

Browse files
committed
Fix achievement state completion date encoding
1 parent 0cea3f4 commit be49c5a

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/MHServerEmu/Common/Clock.cs

+16
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ static Clock()
3737
/// </summary>
3838
public static TimeSpan GameTime { get => UtcNowPrecise - GameTimeEpoch; }
3939

40+
/// <summary>
41+
/// Returns a <see cref="System.DateTime"/> corresponding to the provided millisecond calendar time timestamp.
42+
/// </summary>
43+
public static DateTime DateTimeMillisecondsToDateTime(long timestamp)
44+
{
45+
return UnixEpoch.AddMilliseconds(timestamp);
46+
}
47+
48+
/// <summary>
49+
/// Returns a <see cref="System.DateTime"/> corresponding to the provided microsecond celandar time timestamp.
50+
/// </summary>
51+
public static DateTime DateTimeMicrosecondsToDateTime(long timestamp)
52+
{
53+
return UnixEpoch.AddTicks(timestamp * 10);
54+
}
55+
4056
/// <summary>
4157
/// Returns a <see cref="System.DateTime"/> corresponding to the provided millisecond game time timestamp.
4258
/// </summary>

src/MHServerEmu/Games/Achievements/AchievementState.cs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
using System.Text;
22
using Google.ProtocolBuffers;
33
using Gazillion;
4+
using MHServerEmu.Common;
5+
using MHServerEmu.Common.Extensions;
46

57
namespace MHServerEmu.Games.Achievements
68
{
79
public class AchievementState
810
{
911
public uint Id { get; set; }
1012
public uint Count { get; set; }
11-
public ulong CompletedDate { get; set; }
13+
public long CompletedDate { get; set; } // DateTime in microseconds
1214

1315
public AchievementState(CodedInputStream stream)
1416
{
1517
Id = stream.ReadRawVarint32();
1618
Count = stream.ReadRawVarint32();
17-
CompletedDate = stream.ReadRawVarint64();
19+
CompletedDate = stream.ReadRawInt64();
1820
}
1921

20-
public AchievementState(uint id, uint count, ulong completedDate)
22+
public AchievementState(uint id, uint count, long completedDate)
2123
{
2224
Id = id;
2325
Count = count;
@@ -28,15 +30,15 @@ public void Encode(CodedOutputStream stream)
2830
{
2931
stream.WriteRawVarint64(Id);
3032
stream.WriteRawVarint64(Count);
31-
stream.WriteRawVarint64(CompletedDate);
33+
stream.WriteRawInt64(CompletedDate);
3234
}
3335

3436
public NetMessageAchievementStateUpdate.Types.AchievementState ToNetStruct()
3537
{
3638
return NetMessageAchievementStateUpdate.Types.AchievementState.CreateBuilder()
3739
.SetId(Id)
3840
.SetCount(Count)
39-
.SetCompleteddate(CompletedDate)
41+
.SetCompleteddate((ulong)CompletedDate)
4042
.Build();
4143
}
4244

@@ -45,7 +47,7 @@ public override string ToString()
4547
StringBuilder sb = new();
4648
sb.AppendLine($"Id: {Id}");
4749
sb.AppendLine($"Count: {Count}");
48-
sb.AppendLine($"CompletionDate: 0x{CompletedDate:X}");
50+
sb.AppendLine($"CompletionDate: {Clock.DateTimeMicrosecondsToDateTime(CompletedDate)}");
4951
return sb.ToString();
5052
}
5153
}

0 commit comments

Comments
 (0)