Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
AchievementsSocialModule.cs
Go to the documentation of this file.
1using System;
3using rail;
5
7
9{
10 private const string FILE_NAME = "/achievements-wegame.dat";
11
12 private bool _areStatsReceived;
13
15
16 private RailCallBackHelper _callbackHelper = new RailCallBackHelper();
17
18 private IRailPlayerAchievement _playerAchievement;
19
20 private IRailPlayerStats _playerStats;
21
22 public override void Initialize()
23 {
24 //IL_0012: Unknown result type (might be due to invalid IL or missing references)
25 //IL_001c: Expected O, but got Unknown
26 //IL_002e: Unknown result type (might be due to invalid IL or missing references)
27 //IL_0038: Expected O, but got Unknown
28 //IL_0052: Unknown result type (might be due to invalid IL or missing references)
29 //IL_005e: Unknown result type (might be due to invalid IL or missing references)
30 _callbackHelper.RegisterCallback((RAILEventID)2001, new RailEventCallBackHandler(RailEventCallBack));
31 _callbackHelper.RegisterCallback((RAILEventID)2101, new RailEventCallBackHandler(RailEventCallBack));
32 IRailPlayerStats myPlayerStats = GetMyPlayerStats();
33 IRailPlayerAchievement myPlayerAchievement = GetMyPlayerAchievement();
34 if (myPlayerStats != null && myPlayerAchievement != null)
35 {
36 myPlayerStats.AsyncRequestStats("");
37 myPlayerAchievement.AsyncRequestAchievement("");
39 {
41 Thread.Sleep(10);
42 }
43 }
44 }
45
46 public override void Shutdown()
47 {
48 StoreStats();
49 }
50
51 private IRailPlayerStats GetMyPlayerStats()
52 {
53 //IL_0016: Unknown result type (might be due to invalid IL or missing references)
54 //IL_001c: Expected O, but got Unknown
55 if (_playerStats == null)
56 {
57 IRailStatisticHelper val = rail_api.RailFactory().RailStatisticHelper();
58 if (val != null)
59 {
60 RailID val2 = new RailID();
61 ((RailComparableID)val2).id_ = 0uL;
62 _playerStats = val.CreatePlayerStats(val2);
63 }
64 }
65 return _playerStats;
66 }
67
68 private IRailPlayerAchievement GetMyPlayerAchievement()
69 {
70 //IL_0016: Unknown result type (might be due to invalid IL or missing references)
71 //IL_001c: Expected O, but got Unknown
72 if (_playerAchievement == null)
73 {
74 IRailAchievementHelper val = rail_api.RailFactory().RailAchievementHelper();
75 if (val != null)
76 {
77 RailID val2 = new RailID();
78 ((RailComparableID)val2).id_ = 0uL;
79 _playerAchievement = val.CreatePlayerAchievement(val2);
80 }
81 }
82 return _playerAchievement;
83 }
84
85 public void RailEventCallBack(RAILEventID eventId, EventBase data)
86 {
87 //IL_0000: Unknown result type (might be due to invalid IL or missing references)
88 //IL_0006: Invalid comparison between Unknown and I4
89 //IL_0008: Unknown result type (might be due to invalid IL or missing references)
90 //IL_000e: Invalid comparison between Unknown and I4
91 if ((int)eventId != 2001)
92 {
93 if ((int)eventId == 2101)
94 {
96 }
97 }
98 else
99 {
100 _areStatsReceived = true;
101 }
102 }
103
104 public override bool IsAchievementCompleted(string name)
105 {
106 //IL_0003: Unknown result type (might be due to invalid IL or missing references)
107 //IL_0012: Unknown result type (might be due to invalid IL or missing references)
108 //IL_0017: Unknown result type (might be due to invalid IL or missing references)
109 //IL_001b: Unknown result type (might be due to invalid IL or missing references)
110 //IL_001d: Invalid comparison between Unknown and I4
111 bool flag = false;
112 RailResult val = (RailResult)1;
113 IRailPlayerAchievement myPlayerAchievement = GetMyPlayerAchievement();
114 if (myPlayerAchievement != null)
115 {
116 val = myPlayerAchievement.HasAchieved(name, ref flag);
117 }
118 if (flag)
119 {
120 return (int)val == 0;
121 }
122 return false;
123 }
124
125 public override byte[] GetEncryptionKey()
126 {
127 RailID railID = rail_api.RailFactory().RailPlayer().GetRailID();
128 byte[] array = new byte[16];
129 byte[] bytes = BitConverter.GetBytes(((RailComparableID)railID).id_);
130 Array.Copy(bytes, array, 8);
131 Array.Copy(bytes, 0, array, 8, 8);
132 return array;
133 }
134
135 public override string GetSavePath()
136 {
137 return "/achievements-wegame.dat";
138 }
139
140 private int GetIntStat(string name)
141 {
142 //IL_0010: Unknown result type (might be due to invalid IL or missing references)
143 int result = 0;
144 IRailPlayerStats myPlayerStats = GetMyPlayerStats();
145 if (myPlayerStats != null)
146 {
147 myPlayerStats.GetStatValue(name, ref result);
148 }
149 return result;
150 }
151
152 private float GetFloatStat(string name)
153 {
154 //IL_0018: Unknown result type (might be due to invalid IL or missing references)
155 double num = 0.0;
156 IRailPlayerStats myPlayerStats = GetMyPlayerStats();
157 if (myPlayerStats != null)
158 {
159 myPlayerStats.GetStatValue(name, ref num);
160 }
161 return (float)num;
162 }
163
164 private bool SetFloatStat(string name, float value)
165 {
166 //IL_0008: Unknown result type (might be due to invalid IL or missing references)
167 //IL_0016: Unknown result type (might be due to invalid IL or missing references)
168 //IL_0018: Invalid comparison between Unknown and I4
169 //IL_0010: Unknown result type (might be due to invalid IL or missing references)
170 //IL_0015: Unknown result type (might be due to invalid IL or missing references)
171 IRailPlayerStats myPlayerStats = GetMyPlayerStats();
172 RailResult val = (RailResult)1;
173 if (myPlayerStats != null)
174 {
175 val = myPlayerStats.SetStatValue(name, (double)value);
176 }
177 return (int)val == 0;
178 }
179
180 public override void UpdateIntStat(string name, int value)
181 {
182 //IL_0010: Unknown result type (might be due to invalid IL or missing references)
183 //IL_001e: Unknown result type (might be due to invalid IL or missing references)
184 IRailPlayerStats myPlayerStats = GetMyPlayerStats();
185 if (myPlayerStats != null)
186 {
187 int num = 0;
188 if ((int)myPlayerStats.GetStatValue(name, ref num) == 0 && num < value)
189 {
190 myPlayerStats.SetStatValue(name, value);
191 }
192 }
193 }
194
195 private bool SetIntStat(string name, int value)
196 {
197 //IL_0008: Unknown result type (might be due to invalid IL or missing references)
198 //IL_0015: Unknown result type (might be due to invalid IL or missing references)
199 //IL_0017: Invalid comparison between Unknown and I4
200 //IL_000f: Unknown result type (might be due to invalid IL or missing references)
201 //IL_0014: Unknown result type (might be due to invalid IL or missing references)
202 IRailPlayerStats myPlayerStats = GetMyPlayerStats();
203 RailResult val = (RailResult)1;
204 if (myPlayerStats != null)
205 {
206 val = myPlayerStats.SetStatValue(name, value);
207 }
208 return (int)val == 0;
209 }
210
211 public override void UpdateFloatStat(string name, float value)
212 {
213 //IL_0018: Unknown result type (might be due to invalid IL or missing references)
214 //IL_0028: Unknown result type (might be due to invalid IL or missing references)
215 IRailPlayerStats myPlayerStats = GetMyPlayerStats();
216 if (myPlayerStats != null)
217 {
218 double num = 0.0;
219 if ((int)myPlayerStats.GetStatValue(name, ref num) == 0 && (float)num < value)
220 {
221 myPlayerStats.SetStatValue(name, (double)value);
222 }
223 }
224 }
225
226 public override void StoreStats()
227 {
228 SaveStats();
230 }
231
232 private void SaveStats()
233 {
234 //IL_0010: Unknown result type (might be due to invalid IL or missing references)
235 IRailPlayerStats myPlayerStats = GetMyPlayerStats();
236 if (myPlayerStats != null)
237 {
238 myPlayerStats.AsyncStoreStats("");
239 }
240 }
241
242 private void SaveAchievement()
243 {
244 //IL_0010: Unknown result type (might be due to invalid IL or missing references)
245 IRailPlayerAchievement myPlayerAchievement = GetMyPlayerAchievement();
246 if (myPlayerAchievement != null)
247 {
248 myPlayerAchievement.AsyncStoreAchievement("");
249 }
250 }
251
252 public override void CompleteAchievement(string name)
253 {
254 //IL_000c: Unknown result type (might be due to invalid IL or missing references)
255 IRailPlayerAchievement myPlayerAchievement = GetMyPlayerAchievement();
256 if (myPlayerAchievement != null)
257 {
258 myPlayerAchievement.MakeAchievement(name);
259 }
260 }
261}
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
static byte[] GetBytes(bool value)
static void Sleep(int millisecondsTimeout)
Definition Thread.cs:658
override void UpdateIntStat(string name, int value)
override void UpdateFloatStat(string name, float value)
void RailEventCallBack(RAILEventID eventId, EventBase data)