Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
WorkshopHelper.cs
Go to the documentation of this file.
1using System;
3using System.IO;
4using Steamworks;
5using Terraria.IO;
8
10
11public class WorkshopHelper
12{
13 public class UGCBased
14 {
15 public struct SteamWorkshopItem
16 {
17 public string ContentFolderPath;
18
19 public string Description;
20
21 public string PreviewImagePath;
22
23 public string[] Tags;
24
25 public string Title;
26
28 }
29
30 public class Downloader
31 {
32 public List<string> ResourcePackPaths { get; private set; }
33
34 public List<string> WorldPaths { get; private set; }
35
36 public Downloader()
37 {
40 }
41
42 public static Downloader Create()
43 {
44 return new Downloader();
45 }
46
48 {
49 //IL_0030: Unknown result type (might be due to invalid IL or missing references)
50 PublishedFileId_t[] array = new PublishedFileId_t[SteamUGC.GetNumSubscribedItems()];
51 SteamUGC.GetSubscribedItems((PublishedFileId_t[])(object)array, (uint)array.Length);
52 ulong num = 0uL;
53 string empty = string.Empty;
54 uint num2 = 0u;
56 PublishedFileId_t[] array2 = (PublishedFileId_t[])(object)array;
57 for (int i = 0; i < array2.Length; i++)
58 {
59 if (SteamUGC.GetItemInstallInfo(array2[i], ref num, ref empty, 1024u, ref num2))
60 {
61 list.Add(empty);
62 }
63 }
64 return list;
65 }
66
71
73 {
77 {
78 if (listOfSubscribedItemsPath == null)
79 {
80 continue;
81 }
82 try
83 {
84 string path = listOfSubscribedItemsPath + Path.DirectorySeparatorChar + "workshop.json";
85 if (!File.Exists(path))
86 {
87 continue;
88 }
90 if (!(text == "World"))
91 {
92 if (text == "ResourcePack")
93 {
95 }
96 }
97 else
98 {
100 }
101 }
102 catch (Exception exception)
103 {
104 issueReporter.ReportDownloadProblem("Workshop.ReportIssue_FailedToLoadSubscribedFile", listOfSubscribedItemsPath, exception);
105 return false;
106 }
107 }
108 return true;
109 }
110 }
111
113 {
115
116 private UGCQueryHandle_t m_UGCQueryHandle;
117
119
121
122 public bool HasItemOfId(ulong id)
123 {
124 return _items.ContainsKey(id);
125 }
126
133
139
140 public void Prepare()
141 {
142 Refresh();
143 }
144
145 public void Refresh()
146 {
147 //IL_0001: Unknown result type (might be due to invalid IL or missing references)
148 //IL_0006: Unknown result type (might be due to invalid IL or missing references)
149 //IL_0009: Unknown result type (might be due to invalid IL or missing references)
150 //IL_0011: Unknown result type (might be due to invalid IL or missing references)
151 //IL_0016: Unknown result type (might be due to invalid IL or missing references)
152 //IL_001c: Unknown result type (might be due to invalid IL or missing references)
153 //IL_0021: Unknown result type (might be due to invalid IL or missing references)
154 //IL_002d: Unknown result type (might be due to invalid IL or missing references)
155 //IL_0032: Unknown result type (might be due to invalid IL or missing references)
156 //IL_0037: Unknown result type (might be due to invalid IL or missing references)
157 //IL_003e: Unknown result type (might be due to invalid IL or missing references)
158 CSteamID steamID = SteamUser.GetSteamID();
159 m_UGCQueryHandle = SteamUGC.CreateQueryUserUGCRequest(((CSteamID)(ref steamID)).GetAccountID(), (EUserUGCList)0, (EUGCMatchingUGCType)(-1), (EUserUGCListSortOrder)0, SteamUtils.GetAppID(), SteamUtils.GetAppID(), 1u);
161 SteamAPICall_t val = SteamUGC.SendQueryUGCRequest(m_UGCQueryHandle);
164 }
165
167 {
168 //IL_000e: Unknown result type (might be due to invalid IL or missing references)
169 //IL_000f: Unknown result type (might be due to invalid IL or missing references)
170 //IL_0015: Invalid comparison between Unknown and I4
171 //IL_0020: Unknown result type (might be due to invalid IL or missing references)
172 //IL_0084: Unknown result type (might be due to invalid IL or missing references)
173 //IL_0031: Unknown result type (might be due to invalid IL or missing references)
174 //IL_003f: Unknown result type (might be due to invalid IL or missing references)
175 //IL_0040: Unknown result type (might be due to invalid IL or missing references)
176 //IL_008d: Unknown result type (might be due to invalid IL or missing references)
177 _items.Clear();
178 if (bIOFailure || (int)pCallback.m_eResult != 1)
179 {
180 SteamUGC.ReleaseQueryUGCRequest(m_UGCQueryHandle);
181 return;
182 }
184 for (uint num = 0u; num < pCallback.m_unNumResultsReturned; num++)
185 {
186 SteamUGC.GetQueryUGCResult(m_UGCQueryHandle, num, ref val);
187 ulong publishedFileId = val.m_nPublishedFileId.m_PublishedFileId;
189 steamWorkshopItem.Title = ((SteamUGCDetails_t)(ref val)).m_rgchTitle;
190 steamWorkshopItem.Description = ((SteamUGCDetails_t)(ref val)).m_rgchDescription;
193 }
194 SteamUGC.ReleaseQueryUGCRequest(m_UGCQueryHandle);
195 }
196
200 }
201
202 public abstract class APublisherInstance
203 {
205
207
209
210 protected PublishedFileId_t _publishedFileID;
211
212 private UGCUpdateHandle_t _updateHandle;
213
215
217
218 private FinishedPublishingAction _endAction;
219
221
222 public void PublishContent(PublishedItemsFinder finder, WorkshopIssueReporter issueReporter, FinishedPublishingAction endAction, string itemTitle, string itemDescription, string contentFolderPath, string previewImagePath, WorkshopItemPublicSettingId publicity, string[] tags)
223 {
224 //IL_003f: Unknown result type (might be due to invalid IL or missing references)
225 //IL_0044: Unknown result type (might be due to invalid IL or missing references)
226 //IL_007d: Unknown result type (might be due to invalid IL or missing references)
227 //IL_00e9: Unknown result type (might be due to invalid IL or missing references)
228 //IL_00ee: Unknown result type (might be due to invalid IL or missing references)
235 {
236 Title = itemTitle,
237 Description = itemDescription,
238 ContentFolderPath = contentFolderPath,
239 Tags = tags,
240 PreviewImagePath = previewImagePath,
241 Visibility = visibility
242 };
243 ulong? num = null;
245 {
246 num = info.workshopEntryId;
247 }
248 if (num.HasValue && finder.HasItemOfId(num.Value))
249 {
250 _publishedFileID = new PublishedFileId_t(num.Value);
252 UpdateItem();
253 }
254 else
255 {
256 CreateItem();
257 }
258 }
259
261 {
262 _entryData.Title = null;
263 _entryData.Description = null;
264 }
265
267 {
269 {
270 WorkshopItemPublicSettingId.FriendsOnly => 1,
271 WorkshopItemPublicSettingId.Public => 0,
272 _ => 2,
273 });
274 }
275
276 private void CreateItem()
277 {
278 //IL_0006: Unknown result type (might be due to invalid IL or missing references)
279 //IL_000c: Unknown result type (might be due to invalid IL or missing references)
280 //IL_0011: Unknown result type (might be due to invalid IL or missing references)
281 //IL_0018: Unknown result type (might be due to invalid IL or missing references)
283 SteamAPICall_t val = SteamUGC.CreateItem(SteamUtils.GetAppID(), (EWorkshopFileType)0);
286 }
287
289 {
290 //IL_0000: Unknown result type (might be due to invalid IL or missing references)
291 //IL_0025: Unknown result type (might be due to invalid IL or missing references)
292 //IL_0026: Unknown result type (might be due to invalid IL or missing references)
293 //IL_002c: Invalid comparison between Unknown and I4
294 //IL_002f: Unknown result type (might be due to invalid IL or missing references)
295 //IL_0030: Unknown result type (might be due to invalid IL or missing references)
296 //IL_0035: Unknown result type (might be due to invalid IL or missing references)
297 if (param.m_bUserNeedsToAcceptWorkshopLegalAgreement)
298 {
299 _issueReporter.ReportDelayedUploadProblem("Workshop.ReportIssue_FailedToPublish_UserDidNotAcceptWorkshopTermsOfService");
300 _endAction(this);
301 }
302 else if ((int)param.m_eResult == 1)
303 {
304 _publishedFileID = param.m_nPublishedFileId;
305 UpdateItem();
306 }
307 else
308 {
309 _issueReporter.ReportDelayedUploadProblemWithoutKnownReason("Workshop.ReportIssue_FailedToPublish_WithoutKnownReason", ((object)(EResult)(ref param.m_eResult)).ToString());
310 _endAction(this);
311 }
312 }
313
314 protected abstract string GetHeaderText();
315
316 protected abstract void PrepareContentForUpdate();
317
318 private void UpdateItem()
319 {
320 //IL_002e: Unknown result type (might be due to invalid IL or missing references)
321 //IL_0034: Unknown result type (might be due to invalid IL or missing references)
322 //IL_0039: Unknown result type (might be due to invalid IL or missing references)
323 //IL_003e: Unknown result type (might be due to invalid IL or missing references)
324 //IL_004c: Unknown result type (might be due to invalid IL or missing references)
325 //IL_007d: Unknown result type (might be due to invalid IL or missing references)
326 //IL_008f: Unknown result type (might be due to invalid IL or missing references)
327 //IL_006b: Unknown result type (might be due to invalid IL or missing references)
328 //IL_00ae: Unknown result type (might be due to invalid IL or missing references)
329 //IL_00ef: Unknown result type (might be due to invalid IL or missing references)
330 //IL_00f5: Unknown result type (might be due to invalid IL or missing references)
331 //IL_00fa: Unknown result type (might be due to invalid IL or missing references)
332 //IL_00fc: Unknown result type (might be due to invalid IL or missing references)
333 //IL_00fd: Unknown result type (might be due to invalid IL or missing references)
334 //IL_0108: Unknown result type (might be due to invalid IL or missing references)
335 //IL_00d2: Unknown result type (might be due to invalid IL or missing references)
336 //IL_00de: Unknown result type (might be due to invalid IL or missing references)
337 string headerText = GetHeaderText();
339 {
340 _endAction(this);
341 return;
342 }
344 UGCUpdateHandle_t val = SteamUGC.StartItemUpdate(SteamUtils.GetAppID(), _publishedFileID);
345 if (_entryData.Title != null)
346 {
347 SteamUGC.SetItemTitle(val, _entryData.Title);
348 }
349 if (_entryData.Description != null)
350 {
351 SteamUGC.SetItemDescription(val, _entryData.Description);
352 }
353 SteamUGC.SetItemContent(val, _entryData.ContentFolderPath);
354 SteamUGC.SetItemTags(val, (IList<string>)_entryData.Tags);
355 if (_entryData.PreviewImagePath != null)
356 {
357 SteamUGC.SetItemPreview(val, _entryData.PreviewImagePath);
358 }
359 if (_entryData.Visibility.HasValue)
360 {
361 SteamUGC.SetItemVisibility(val, _entryData.Visibility.Value);
362 }
364 SteamAPICall_t val2 = SteamUGC.SubmitItemUpdate(val, "");
365 _updateHandle = val;
368 }
369
371 {
372 //IL_0000: Unknown result type (might be due to invalid IL or missing references)
373 //IL_0025: Unknown result type (might be due to invalid IL or missing references)
374 //IL_0026: Unknown result type (might be due to invalid IL or missing references)
375 //IL_002b: Unknown result type (might be due to invalid IL or missing references)
376 //IL_002c: Unknown result type (might be due to invalid IL or missing references)
377 //IL_002f: Invalid comparison between Unknown and I4
378 //IL_0043: Unknown result type (might be due to invalid IL or missing references)
379 //IL_0046: Invalid comparison between Unknown and I4
380 //IL_0031: Unknown result type (might be due to invalid IL or missing references)
381 //IL_0033: Invalid comparison between Unknown and I4
382 //IL_0048: Unknown result type (might be due to invalid IL or missing references)
383 //IL_004b: Invalid comparison between Unknown and I4
384 //IL_0035: Unknown result type (might be due to invalid IL or missing references)
385 //IL_0037: Invalid comparison between Unknown and I4
386 //IL_0050: Unknown result type (might be due to invalid IL or missing references)
387 //IL_0053: Invalid comparison between Unknown and I4
388 //IL_0039: Unknown result type (might be due to invalid IL or missing references)
389 //IL_003c: Invalid comparison between Unknown and I4
390 if (param.m_bUserNeedsToAcceptWorkshopLegalAgreement)
391 {
392 _issueReporter.ReportDelayedUploadProblem("Workshop.ReportIssue_FailedToPublish_UserDidNotAcceptWorkshopTermsOfService");
393 _endAction(this);
394 return;
395 }
396 EResult eResult = param.m_eResult;
397 if ((int)eResult <= 9)
398 {
399 if ((int)eResult != 1)
400 {
401 if ((int)eResult != 8)
402 {
403 if ((int)eResult != 9)
404 {
405 goto IL_0079;
406 }
407 _issueReporter.ReportDelayedUploadProblem("Workshop.ReportIssue_FailedToPublish_CouldNotFindFolderToUpload");
408 }
409 else
410 {
411 _issueReporter.ReportDelayedUploadProblem("Workshop.ReportIssue_FailedToPublish_InvalidParametersForPublishing");
412 }
413 }
414 else
415 {
416 SteamFriends.ActivateGameOverlayToWebPage("steam://url/CommunityFilePage/" + _publishedFileID.m_PublishedFileId, (EActivateGameOverlayToWebPageMode)0);
417 }
418 }
419 else if ((int)eResult != 15)
420 {
421 if ((int)eResult != 25)
422 {
423 if ((int)eResult != 33)
424 {
425 goto IL_0079;
426 }
427 _issueReporter.ReportDelayedUploadProblem("Workshop.ReportIssue_FailedToPublish_SteamFileLockFailed");
428 }
429 else
430 {
431 _issueReporter.ReportDelayedUploadProblem("Workshop.ReportIssue_FailedToPublish_LimitExceeded");
432 }
433 }
434 else
435 {
436 _issueReporter.ReportDelayedUploadProblem("Workshop.ReportIssue_FailedToPublish_AccessDeniedBecauseUserDoesntOwnLicenseForApp");
437 }
438 goto IL_00f5;
439 IL_00f5:
440 _endAction(this);
441 return;
442 IL_0079:
443 _issueReporter.ReportDelayedUploadProblemWithoutKnownReason("Workshop.ReportIssue_FailedToPublish_WithoutKnownReason", ((object)(EResult)(ref param.m_eResult)).ToString());
444 goto IL_00f5;
445 }
446
448 {
449 string path = folderPath + Path.DirectorySeparatorChar + "workshop.json";
450 bool result = true;
451 try
452 {
454 }
455 catch (Exception exception)
456 {
457 _issueReporter.ReportManifestCreationProblem("Workshop.ReportIssue_CouldNotCreateResourcePackManifestFile", exception);
458 result = false;
459 }
460 return result;
461 }
462
463 public bool TryGetProgress(out float progress)
464 {
465 //IL_0008: Unknown result type (might be due to invalid IL or missing references)
466 //IL_000f: Unknown result type (might be due to invalid IL or missing references)
467 //IL_0015: Unknown result type (might be due to invalid IL or missing references)
468 //IL_0020: Unknown result type (might be due to invalid IL or missing references)
469 //IL_0029: Unknown result type (might be due to invalid IL or missing references)
470 progress = 0f;
471 if (_updateHandle == default(UGCUpdateHandle_t))
472 {
473 return false;
474 }
475 ulong num = default(ulong);
476 ulong num2 = default(ulong);
477 SteamUGC.GetItemUpdateProgress(_updateHandle, ref num, ref num2);
478 if (num2 == 0L)
479 {
480 return false;
481 }
482 progress = (float)((double)num / (double)num2);
483 return true;
484 }
485 }
486
505
507 {
509
511 {
512 _world = world;
513 }
514
515 protected override string GetHeaderText()
516 {
518 }
519
520 protected override void PrepareContentForUpdate()
521 {
523 {
525 }
526 else
527 {
529 }
530 }
531 }
532
533 public const string ManifestFileName = "workshop.json";
534 }
535}
void Add(TKey key, TValue value)
static bool Exists([NotNullWhen(true)] string? path)
Definition File.cs:97
static void WriteAllText(string path, string? contents)
Definition File.cs:282
static string ReadAllText(string path)
Definition File.cs:246
static readonly char DirectorySeparatorChar
Definition Path.cs:71
static bool TryReadingManifest(string filePath, out FoundWorkshopEntryInfo info)
static string ReadHeader(string jsonText)
static string GetHeaderTextFor(ResourcePack resourcePack, ulong workshopEntryId, string[] tags, WorkshopItemPublicSettingId publicity, string previewImagePath)
void ReportManifestCreationProblem(string textKey, Exception exception)
void ReportDelayedUploadProblemWithoutKnownReason(string textKey, string reasonValue)
static string GetHeaderTextFor(WorldFileData world, ulong workshopEntryId, string[] tags, WorkshopItemPublicSettingId publicity, string previewImagePath)
static void SetSkipPulsing(bool shouldSkipPausing)
void UpdateItemResult(SubmitItemUpdateResult_t param, bool bIOFailure)
delegate void FinishedPublishingAction(APublisherInstance instance)
void CreateItemResult(CreateItemResult_t param, bool bIOFailure)
void PublishContent(PublishedItemsFinder finder, WorkshopIssueReporter issueReporter, FinishedPublishingAction endAction, string itemTitle, string itemDescription, string contentFolderPath, string previewImagePath, WorkshopItemPublicSettingId publicity, string[] tags)
bool TryWritingManifestToFolder(string folderPath, string manifestText)
ERemoteStoragePublishedFileVisibility GetVisibility(WorkshopItemPublicSettingId publicityId)
bool Refresh(WorkshopIssueReporter issueReporter)
bool Prepare(WorkshopIssueReporter issueReporter)
void OnSteamUGCRequestUGCDetailsResult(SteamUGCRequestUGCDetailsResult_t pCallback, bool bIOFailure)
void OnSteamUGCQueryCompleted(SteamUGCQueryCompleted_t pCallback, bool bIOFailure)
CallResult< SteamUGCQueryCompleted_t > OnSteamUGCQueryCompletedCallResult
CallResult< SteamUGCRequestUGCDetailsResult_t > OnSteamUGCRequestUGCDetailsResultCallResult
static void Copy(string source, string destination, bool cloud, bool overwrite=true)
static bool CopyToLocal(string cloudPath, string localPath)