Elin Decompiled Documentation EA 23.345.1 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 if (!query.Execute(HandleResults))
148 {
149 ReportError("UgcQuery.Execute failed at page " + page);
150 }
151 }
152 void HandleResults(UgcQuery q)
153 {
154 if (!done)
155 {
156 results.AddRange(q.ResultsList.Where((WorkshopItem r) => ids.Add(r.FileId)));
157 if (q.ResultsList.Count == 0 || page >= q.pageCount)
158 {
159 done = true;
160 query.Dispose();
161 onComplete?.Invoke(results);
162 }
163 else
164 {
165 query.SetPage(++page);
166 ExecutePage();
167 }
168 }
169 }
170 void ReportError(string error)
171 {
172 if (!done)
173 {
174 done = true;
175 query.Dispose();
176 if (onFail != null)
177 {
178 onFail(error);
179 }
180 else
181 {
182 Debug.LogError(error);
183 }
184 }
185 }
186 IEnumerator Timeout()
187 {
188 uint lastPage = page;
189 float time = Time.realtimeSinceStartup;
190 while (!done)
191 {
192 if (lastPage != page)
193 {
194 lastPage = page;
195 time = Time.realtimeSinceStartup;
196 }
197 if (Time.realtimeSinceStartup - time > timeout)
198 {
199 ReportError("UgcQuery timed out at page " + page + " (" + results.Count + " items fetched)");
200 break;
201 }
202 yield return null;
203 }
204 }
205 }
206
207 private void CreateOrUpdateUserContent(List<WorkshopItem> items)
208 {
209 Debug.Log("Creating Content2");
210 BaseModPackage baseModPackage = currentPackage;
211 Debug.Log(items.Count);
212 foreach (WorkshopItem item in items)
213 {
214 if (item.keyValueTags.IsEmpty())
215 {
216 continue;
217 }
218 StringKeyValuePair[] keyValueTags = item.keyValueTags;
219 for (int i = 0; i < keyValueTags.Length; i++)
220 {
221 StringKeyValuePair stringKeyValuePair = keyValueTags[i];
222 if (stringKeyValuePair.key == "id" && stringKeyValuePair.value == baseModPackage.id && item.Owner.IsMe)
223 {
224 Debug.Log("Updating Content");
225 UpdateUserContent(item.FileId);
226 return;
227 }
228 }
229 }
230 Debug.Log("Creating Content");
231 CreateItemData(baseModPackage).Create(null, null, new WorkshopItemKeyValueTag[1]
232 {
233 new WorkshopItemKeyValueTag
234 {
235 key = "id",
236 value = baseModPackage.id
237 }
238 }, delegate(WorkshopItemDataCreateStatus result)
239 {
240 LayerProgress.completed = true;
241 if (result.hasError)
242 {
243 Dialog.Ok("mod_publish_error");
244 EClass.ui.Say(result.errorMessage);
245 Debug.Log("error:" + result.errorMessage);
246 }
247 else
248 {
249 Dialog.Ok("mod_created");
250 Debug.Log("created");
251 }
252 });
253 }
254
255 public void UpdateUserContent(PublishedFileId_t fileId)
256 {
257 Debug.Log("Updating Content");
259 WorkshopItemData workshopItemData = CreateItemData(p);
260 workshopItemData.publishedFileId = fileId;
261 workshopItemData.Update(delegate(WorkshopItemDataUpdateStatus result)
262 {
263 LayerProgress.completed = true;
264 if (result.hasError)
265 {
266 Dialog.Ok("mod_publish_error");
267 EClass.ui.Say(result.errorMessage);
268 Debug.Log("error:" + result.errorMessage);
269 }
270 else
271 {
272 Dialog.Ok("mod_updated");
273 Debug.Log("updated");
274 }
275 });
276 }
277
278 public WorkshopItemData CreateItemData(BaseModPackage p)
279 {
280 FileInfo fileInfo = new FileInfo(p.dirInfo.FullName + "/preview.jpg");
281 DirectoryInfo directoryInfo = new DirectoryInfo(p.dirInfo.FullName);
282 WorkshopItemData result = new WorkshopItemData
283 {
284 appId = steamworks.settings.applicationId,
285 title = p.title,
286 description = p.description,
287 content = directoryInfo,
288 preview = fileInfo,
289 metadata = (p.id ?? ""),
290 tags = p.tags,
291 visibility = ERemoteStoragePublishedFileVisibility.k_ERemoteStoragePublishedFileVisibilityPublic
292 };
293 switch (p.visibility)
294 {
295 case "Unlisted":
296 result.visibility = ERemoteStoragePublishedFileVisibility.k_ERemoteStoragePublishedFileVisibilityUnlisted;
297 break;
298 case "Private":
299 result.visibility = ERemoteStoragePublishedFileVisibility.k_ERemoteStoragePublishedFileVisibilityPrivate;
300 break;
301 case "FriendsOnly":
302 result.visibility = ERemoteStoragePublishedFileVisibility.k_ERemoteStoragePublishedFileVisibilityFriendsOnly;
303 break;
304 }
305 Debug.Log(App.Client.Owner.id);
306 Debug.Log(result.appId);
307 Debug.Log(p.id);
308 Debug.Log(directoryInfo.Exists + "/" + directoryInfo.FullName);
309 Debug.Log(fileInfo.Exists + "/" + fileInfo.FullName);
310 return result;
311 }
312}
ID_Achievement
ID_DLC
Definition: ID_DLC.cs:2
item3. title
Definition: UIBook.cs:640
static bool IsOffline
Definition: BaseCore.cs:9
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:255
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:278
void CheckUpdate()
Definition: Steam.cs:34
void CreateOrUpdateUserContent(List< WorkshopItem > items)
Definition: Steam.cs:207
UserGeneratedContentQueryManager ugc
Definition: Steam.cs:17
void CreateUserContent(BaseModPackage p)
Definition: Steam.cs:117
WorkshopItem testData
Definition: Steam.cs:19