-
Notifications
You must be signed in to change notification settings - Fork 0
/
AchievementsSocialModule.cs
134 lines (114 loc) · 3.14 KB
/
AchievementsSocialModule.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using System;
using System.Collections.Generic;
using System.Threading;
using Steamworks;
using Terraria.Social.Base;
namespace Terraria.Social.Steam;
public class AchievementsSocialModule : Terraria.Social.Base.AchievementsSocialModule
{
private const string FILE_NAME = "/achievements-steam.dat";
private Callback<UserStatsReceived_t> _userStatsReceived;
private bool _areStatsReceived;
private Dictionary<string, int> _intStatCache = new Dictionary<string, int>();
private Dictionary<string, float> _floatStatCache = new Dictionary<string, float>();
public override void Initialize()
{
_userStatsReceived = Callback<UserStatsReceived_t>.Create((DispatchDelegate<UserStatsReceived_t>)OnUserStatsReceived);
SteamUserStats.RequestCurrentStats();
while (!_areStatsReceived)
{
CoreSocialModule.Pulse();
Thread.Sleep(10);
}
}
public override void Shutdown()
{
_userStatsReceived.Unregister();
StoreStats();
}
public override bool IsAchievementCompleted(string name)
{
bool tile = default(bool);
return SteamUserStats.GetAchievement(name, ref tile) && tile;
}
public override byte[] GetEncryptionKey()
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
byte[] tile = new byte[16];
byte[] bytes = BitConverter.GetBytes(SteamUser.GetSteamID().m_SteamID);
Array.Copy(bytes, tile, 8);
Array.Copy(bytes, 0, tile, 8, 8);
return tile;
}
public override string GetSavePath()
{
return "/achievements-steam.dat";
}
private int GetIntStat(string name)
{
if (_intStatCache.TryGetValue(name, out var value))
{
return value;
}
if (SteamUserStats.GetStat(name, ref value))
{
_intStatCache.Add(name, value);
}
return value;
}
private float GetFloatStat(string name)
{
if (_floatStatCache.TryGetValue(name, out var num))
{
return num;
}
if (SteamUserStats.GetStat(name, ref num))
{
_floatStatCache.Add(name, num);
}
return num;
}
private bool SetFloatStat(string name, float value)
{
_floatStatCache[name] = value;
return SteamUserStats.SetStat(name, value);
}
public override void UpdateIntStat(string name, int value)
{
if (GetIntStat(name) < value)
{
SetIntStat(name, value);
}
}
private bool SetIntStat(string name, int value)
{
_intStatCache[name] = value;
return SteamUserStats.SetStat(name, value);
}
public override void UpdateFloatStat(string name, float value)
{
if (GetFloatStat(name) < value)
{
SetFloatStat(name, value);
}
}
public override void StoreStats()
{
SteamUserStats.StoreStats();
}
public override void CompleteAchievement(string name)
{
SteamUserStats.SetAchievement(name);
}
private void OnUserStatsReceived(UserStatsReceived_t results)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
if (results.m_nGameID == 105600 && results.m_steamIDUser == SteamUser.GetSteamID())
{
_areStatsReceived = true;
}
}
}