Elin Decompiled Documentation EA 23.357 Nightly
Loading...
Searching...
No Matches
Steam.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.IO;
5using System.Linq;
6using HeathenEngineering.SteamworksIntegration;
7using HeathenEngineering.SteamworksIntegration.API;
8using Steamworks;
9using UnityEngine;
10
11public class Steam : MonoBehaviour
12{
13 public static Steam Instance;
14
15 public SteamworksBehaviour steamworks;
16
17 public UserGeneratedContentQueryManager ugc;
18
19 public WorkshopItem testData;
20
22
23 private void Awake()
24 {
25 Instance = this;
26 }
27
28 public void Init()
29 {
30 SteamAPI.Init();
31 BaseCore.IsOffline = !App.Client.LoggedOn || SteamSettings.behaviour == null;
32 }
33
34 public void CheckUpdate()
35 {
36 }
37
38 public void CheckDLC()
39 {
40 Debug.Log(HasDLC(ID_DLC.Test));
41 }
42
43 public static bool HasDLC(ID_DLC id)
44 {
45 return id switch
46 {
47 ID_DLC.CursedManor => true,
48 ID_DLC.BackerReward => EClass.core.config.HasBackerRewardCode(),
50 };
51 }
52
53 public static void GetAchievement(ID_Achievement id)
54 {
56 {
57 return;
58 }
59 try
60 {
61 foreach (AchievementObject achievement in Instance.steamworks.settings.achievements)
62 {
63 if (achievement.Id == id.ToString())
64 {
65 if (achievement.IsAchieved)
66 {
67 return;
68 }
69 try
70 {
71 achievement.Unlock();
72 achievement.Store();
73 EClass.ui.Say("sys_acv".lang(achievement.Name), Resources.Load<Sprite>("Media/Graphics/Icon/Achievement/acv_" + id));
74 SE.Play("achievement");
75 return;
76 }
77 catch (Exception ex)
78 {
79 Debug.LogError("Error Achievement 1:" + ex);
80 return;
81 }
82 }
83 }
84 }
85 catch (Exception ex2)
86 {
87 Debug.LogError("Error Achievement 2:" + ex2);
88 }
89 Debug.Log("Achievement not found:" + id);
90 }
91
92 public static void ResetAllAchievement()
93 {
94 foreach (AchievementObject achievement in Instance.steamworks.settings.achievements)
95 {
96 achievement.ClearAchievement();
97 achievement.Store();
98 }
99 }
100
101 public static void ResetAchievement(ID_Achievement id)
102 {
103 AchievementObject achievementObject = Instance.steamworks.settings.achievements.FirstOrDefault((AchievementObject a) => a.Id == id.ToString());
104 if (achievementObject != null)
105 {
106 achievementObject.ClearAchievement();
107 achievementObject.Store();
108 }
109 }
110
111 public void TestHasDLC()
112 {
113 Debug.Log(HasDLC(ID_DLC.Test));
114 Debug.Log(HasDLC(ID_DLC.CursedManor));
115 }
116
118 {
119 LayerProgress.Start("Uploading").onCancel = delegate
120 {
121 };
122 p.UpdateMeta(updateOnly: true);
123 currentPackage = p;
124 QueryAllMyPublished(CreateOrUpdateUserContent, delegate(string error)
125 {
126 LayerProgress.completed = true;
127 Debug.LogError(error);
128 Dialog.Ok("mod_publish_error");
129 });
130 }
131
132 public static void QueryAllMyPublished(Action<List<WorkshopItem>> onComplete, Action<string> onFail = null, float timeout = 10f)
133 {
134 List<WorkshopItem> results = new List<WorkshopItem>();
135 HashSet<PublishedFileId_t> ids = new HashSet<PublishedFileId_t>();
136 uint page = 1u;
137 bool done = false;
138 UgcQuery query = UgcQuery.GetMyPublished();
139 ExecutePage();
140 if (!done && (bool)Instance)
141 {
142 Instance.StartCoroutine(Timeout());
143 }
144 void ExecutePage()
145 {
146 query.SetReturnKeyValueTags(tags: true);
147 query.SetReturnMetadata(metadata: true);
148 if (!query.Execute(HandleResults))
149 {
150 ReportError("UgcQuery.Execute failed at page " + page);
151 }
152 }
153 void HandleResults(UgcQuery q)
154 {
155 if (!done)
156 {
157 results.AddRange(q.ResultsList.Where((WorkshopItem r) => ids.Add(r.FileId)));
158 if (q.ResultsList.Count == 0 || page >= q.pageCount)
159 {
160 done = true;
161 query.Dispose();
162 onComplete?.Invoke(results);
163 }
164 else
165 {
166 query.SetPage(++page);
167 EClass.core.actionsNextFrame.Add(ExecutePage);
168 }
169 }
170 }
171 void ReportError(string error)
172 {
173 if (!done)
174 {
175 done = true;
176 query.Dispose();
177 if (onFail != null)
178 {
179 onFail(error);
180 }
181 else
182 {
183 Debug.LogError(error);
184 }
185 }
186 }
187 IEnumerator Timeout()
188 {
189 uint lastPage = page;
190 float time = Time.realtimeSinceStartup;
191 while (!done)
192 {
193 if (lastPage != page)
194 {
195 lastPage = page;
196 time = Time.realtimeSinceStartup;
197 }
198 if (Time.realtimeSinceStartup - time > timeout)
199 {
200 ReportError("UgcQuery timed out at page " + page + " (" + results.Count + " items fetched)");
201 break;
202 }
203 yield return null;
204 }
205 }
206 }
207
208 private void CreateOrUpdateUserContent(List<WorkshopItem> items)
209 {
210 Debug.Log("Creating Content2");
211 BaseModPackage baseModPackage = currentPackage;
212 Debug.Log(items.Count);
213 foreach (WorkshopItem item in items)
214 {
215 if (item.keyValueTags.IsEmpty())
216 {
217 continue;
218 }
219 StringKeyValuePair[] keyValueTags = item.keyValueTags;
220 for (int i = 0; i < keyValueTags.Length; i++)
221 {
222 StringKeyValuePair stringKeyValuePair = keyValueTags[i];
223 if (stringKeyValuePair.key == "id" && stringKeyValuePair.value == baseModPackage.id && item.Owner.IsMe)
224 {
225 Debug.Log("Updating Content");
226 UpdateUserContent(item.FileId);
227 return;
228 }
229 }
230 }
231 Debug.Log("Creating Content");
232 CreateItemData(baseModPackage).Create(null, null, new WorkshopItemKeyValueTag[1]
233 {
234 new WorkshopItemKeyValueTag
235 {
236 key = "id",
237 value = baseModPackage.id
238 }
239 }, delegate(WorkshopItemDataCreateStatus result)
240 {
241 LayerProgress.completed = true;
242 if (result.hasError)
243 {
244 Dialog.Ok("mod_publish_error");
245 EClass.ui.Say(result.errorMessage);
246 Debug.Log("error:" + result.errorMessage);
247 }
248 else
249 {
250 Dialog.Ok("mod_created");
251 Debug.Log("created");
252 }
253 });
254 }
255
256 public void UpdateUserContent(PublishedFileId_t fileId)
257 {
258 Debug.Log("Updating Content");
260 WorkshopItemData workshopItemData = CreateItemData(p);
261 workshopItemData.publishedFileId = fileId;
262 workshopItemData.Update(delegate(WorkshopItemDataUpdateStatus result)
263 {
264 LayerProgress.completed = true;
265 if (result.hasError)
266 {
267 Dialog.Ok("mod_publish_error");
268 EClass.ui.Say(result.errorMessage);
269 Debug.Log("error:" + result.errorMessage);
270 }
271 else
272 {
273 Dialog.Ok("mod_updated");
274 Debug.Log("updated");
275 }
276 });
277 }
278
279 public WorkshopItemData CreateItemData(BaseModPackage p)
280 {
281 FileInfo fileInfo = new FileInfo(p.dirInfo.FullName + "/preview.jpg");
282 DirectoryInfo directoryInfo = new DirectoryInfo(p.dirInfo.FullName);
283 WorkshopItemData result = new WorkshopItemData
284 {
285 appId = steamworks.settings.applicationId,
286 title = p.title,
287 description = p.description,
288 content = directoryInfo,
289 preview = fileInfo,
290 metadata = (p.id ?? ""),
291 tags = p.tags,
292 visibility = ERemoteStoragePublishedFileVisibility.k_ERemoteStoragePublishedFileVisibilityPublic
293 };
294 switch (p.visibility)
295 {
296 case "Unlisted":
297 result.visibility = ERemoteStoragePublishedFileVisibility.k_ERemoteStoragePublishedFileVisibilityUnlisted;
298 break;
299 case "Private":
300 result.visibility = ERemoteStoragePublishedFileVisibility.k_ERemoteStoragePublishedFileVisibilityPrivate;
301 break;
302 case "FriendsOnly":
303 result.visibility = ERemoteStoragePublishedFileVisibility.k_ERemoteStoragePublishedFileVisibilityFriendsOnly;
304 break;
305 }
306 Debug.Log(App.Client.Owner.id);
307 Debug.Log(result.appId);
308 Debug.Log(p.id);
309 Debug.Log(directoryInfo.Exists + "/" + directoryInfo.FullName);
310 Debug.Log(fileInfo.Exists + "/" + fileInfo.FullName);
311 return result;
312 }
313}
ID_Achievement
ID_DLC
Definition: ID_DLC.cs:2
item3. title
Definition: UIBook.cs:640
static bool IsOffline
Definition: BaseCore.cs:9
List< Action > actionsNextFrame
Definition: BaseCore.cs:31
DirectoryInfo dirInfo
void UpdateMeta(bool updateOnly=false)
bool HasBackerRewardCode()
Definition: CoreConfig.cs:761
CoreConfig config
Definition: Core.cs:70
Definition: Dialog.cs:7
static Dialog Ok(string langDetail, Action action=null)
Definition: Dialog.cs:230
Definition: EClass.cs:6
static Core core
Definition: EClass.cs:7
static UI ui
Definition: EClass.cs:17
static LayerProgress Start(string text, Action onComplete=null)
Definition: Steam.cs:12
void UpdateUserContent(PublishedFileId_t fileId)
Definition: Steam.cs:256
SteamworksBehaviour steamworks
Definition: Steam.cs:15
static void GetAchievement(ID_Achievement id)
Definition: Steam.cs:53
static void ResetAchievement(ID_Achievement id)
Definition: Steam.cs:101
void CheckDLC()
Definition: Steam.cs:38
static void ResetAllAchievement()
Definition: Steam.cs:92
void Awake()
Definition: Steam.cs:23
static Steam Instance
Definition: Steam.cs:13
BaseModPackage currentPackage
Definition: Steam.cs:21
void Init()
Definition: Steam.cs:28
void TestHasDLC()
Definition: Steam.cs:111
static bool HasDLC(ID_DLC id)
Definition: Steam.cs:43
static void QueryAllMyPublished(Action< List< WorkshopItem > > onComplete, Action< string > onFail=null, float timeout=10f)
Definition: Steam.cs:132
WorkshopItemData CreateItemData(BaseModPackage p)
Definition: Steam.cs:279
void CheckUpdate()
Definition: Steam.cs:34
void CreateOrUpdateUserContent(List< WorkshopItem > items)
Definition: Steam.cs:208
UserGeneratedContentQueryManager ugc
Definition: Steam.cs:17
void CreateUserContent(BaseModPackage p)
Definition: Steam.cs:117
WorkshopItem testData
Definition: Steam.cs:19