Skip to content

Commit

Permalink
1.4 workshop fixes & cleanup (tModLoader#2836)
Browse files Browse the repository at this point in the history
* Initial refactor of ModManager.QueryHelper

* Complete re-organization of QueryHelper & ModManager

* Version metadata change to match preview - CI publish TODO

* Cleanup CI Publish. Just testing to do

* Complete expected path testing

* Cleanups from review in Discord - QueryHelper refactor further & misc fixes
  • Loading branch information
Solxanich authored Aug 20, 2022
1 parent 8048f92 commit 8ef29f1
Show file tree
Hide file tree
Showing 20 changed files with 820 additions and 846 deletions.
2 changes: 1 addition & 1 deletion patches/tModLoader/Terraria/IngameOptions.cs.patch
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
if (DrawLeftSide(sb, Lang.inter[35].Value, num10, vector, vector2, leftScale)) {
leftHover = num10;
if (flag4) {
+ Social.Steam.WorkshopHelper.ModManager.StopPlaytimeTracking();
+ Social.Steam.SteamedWraps.StopPlaytimeTracking();
+ SystemLoader.PreSaveAndQuit();
+ // Calls before anything else is
Close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"MenuModUpdatesAvailable": "({0} {^0:Update;Updates} Available!)",
"AudioNotSupported": "No audio hardware found. Disabling all audio.",
"13InfoButton": "How to Access 1.3 tModLoader",
"SteamFamilyShareWarning": "It has been detected you are using Family Share copy of Terraria.\nSteam does not support family-shared tModLoader.\nExperimental Family-Shared tModLoader workaround has been loaded.\nThe following features are not available:\n - Steam Overlay\n - Steam Multiplayer",

// Mods Menu
"ModsModsList": "Mods List",
Expand Down
2 changes: 1 addition & 1 deletion patches/tModLoader/Terraria/Main.cs.patch
Original file line number Diff line number Diff line change
Expand Up @@ -3912,7 +3912,7 @@
private static void TryDisposingEverything() {
ChromaInitializer.DisableAllDeviceGroups();
+
+ WorkshopHelper.OnGameExitCleanup(); // Added by TML.
+ SteamedWraps.OnGameExitCleanup(); // Added by TML.
+ TerrariaSteamClient.Shutdown();
+
CaptureManager.Instance.Dispose();
Expand Down
2 changes: 1 addition & 1 deletion patches/tModLoader/Terraria/ModLoader/Core/ModCompile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ internal static void BuildModCommandLine(string modFolder)
Environment.Exit(1);
}

Social.Steam.WorkshopSocialModule.CiPublish(modFolder);
Social.Steam.WorkshopSocialModule.SteamCMDPublishPreparer(modFolder);

// Mod was built with success, exit code 0 indicates success.
Environment.Exit(0);
Expand Down
5 changes: 2 additions & 3 deletions patches/tModLoader/Terraria/ModLoader/Core/ModOrganizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ internal static IEnumerable<ulong> IdentifyWorkshopDependencies() {
}

// Cull out any dependencies that are already installed.
return dependencies.Where(x => !new WorkshopHelper.ModManager(new Steamworks.PublishedFileId_t(x)).IsInstalled()).ToList();
return dependencies.Where(x => !SteamedWraps.IsWorkshopItemInstalled(new Steamworks.PublishedFileId_t(x))).ToList();
}

internal static string ListDependenciesToDownload(List<ulong> deps) {
Expand Down Expand Up @@ -577,8 +577,7 @@ internal static void DeleteMod(LocalMod tmod) {

if (TryReadManifest(parentDir, out var info)) {
// Is a mod on Steam Workshop
var modManager = new WorkshopHelper.ModManager(new Steamworks.PublishedFileId_t(info.workshopEntryId));
modManager.Uninstall(parentDir);
SteamedWraps.UninstallWorkshopItem(new Steamworks.PublishedFileId_t(info.workshopEntryId));
}
else {
// Is a Mod in Mods Folder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ internal class TerrariaSteamClient

private static string MsgInitFailed = "init_failed";
private static string MsgInitSuccess = "init_success";
private static string MsgFamilyShared = "family_shared";
private static string MsgNotInstalled = "not_installed";
private static string MsgGrant = "grant:";
private static string MsgAck = "acknowledged";
Expand Down Expand Up @@ -78,6 +79,10 @@ internal static LaunchResult Launch() {
if (line == MsgInitSuccess)
break;

// Workaround for #881 family shared
if (line == MsgFamilyShared) {
Social.Steam.SteamedWraps.FamilyShared = true;
}
}

SendCmd(MsgAck);
Expand Down Expand Up @@ -135,7 +140,15 @@ internal static void Run() {
return;
}

// Unfortunately, Valve doesn't support tModLoader for Family-shared Terraria, which has lead to this workaround.
// Does not support Steam Overlay or Steam multiplayer as such.
if (SteamApps.BIsSubscribedFromFamilySharing()) {
Logger.Info("Terraria is installed via Family Share. Re-pathing tModLoader required");
Send(MsgFamilyShared);
}

Send(MsgInitSuccess);

while (Recv() != MsgAck) { }

// message loop
Expand Down
1 change: 1 addition & 0 deletions patches/tModLoader/Terraria/ModLoader/ModLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static class ModLoader
public static bool DownloadedDependenciesOnStartup;
public static bool ShowFirstLaunchWelcomeMessage;
public static bool SeenFirstLaunchModderWelcomeMessage;
public static bool WarnedFamilyShare;
public static Version LastPreviewFreezeNotificationSeen;

public static string versionedName => (BuildInfo.Purpose != BuildInfo.BuildPurpose.Stable) ? BuildInfo.versionedNameDevFriendly : BuildInfo.versionedName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
using System.Diagnostics;
using Terraria.Audio;
using Terraria.ID;
using Terraria.Localization;
using Terraria.UI;

namespace Terraria.ModLoader.UI.DownloadManager
{
internal class UIWorkshopDownload : UIProgress
{
private Stopwatch downloadTimer;

public UIState PreviousUIState { get; set; }

public int PreviousMenuMode { get; set; } = -1;

public UIWorkshopDownload(UIState stateToGoBackTo) {
downloadTimer = new Stopwatch();
PreviousUIState = stateToGoBackTo;
Main.menuMode = 888;
}

public UIWorkshopDownload(int previousMenuMode) {
downloadTimer = new Stopwatch();
PreviousMenuMode = previousMenuMode;
Expand All @@ -31,6 +21,8 @@ public void PrepUIForDownload(string displayName) {
_progressBar.DisplayText = Language.GetTextValue("tModLoader.MBDownloadingMod", displayName);
downloadTimer.Restart();
Main.MenuUI.RefreshState();

_cancelButton.Remove();
}

public void UpdateDownloadProgress(float progress, long bytesReceived, long totalBytesNeeded) {
Expand Down Expand Up @@ -58,7 +50,7 @@ public void Leave(bool refreshBrowser) {
}

public void ReturnToPreviousMenu() {
if (PreviousMenuMode == -1 && PreviousUIState == null) {
if (PreviousMenuMode == -1) {
Main.menuMode = 0;
return;
}
Expand All @@ -67,11 +59,6 @@ public void ReturnToPreviousMenu() {
Main.menuMode = PreviousMenuMode;
}

if (PreviousUIState != null) {
Main.menuMode = 888;
Main.MenuUI.SetState(PreviousUIState);
}

SoundEngine.PlaySound(11);
}
}
Expand Down
13 changes: 10 additions & 3 deletions patches/tModLoader/Terraria/ModLoader/UI/Interface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ internal static void ModLoaderMenus(Main main, int selectedMenu, string[] button
infoMessage.Show(Language.GetTextValue("tModLoader.FirstLaunchWelcomeMessage"), Main.menuMode);
}

if (SteamedWraps.FamilyShared && !ModLoader.WarnedFamilyShare) {
ModLoader.WarnedFamilyShare = true;
infoMessage.Show(Language.GetTextValue("tModLoader.SteamFamilyShareWarning"), Main.menuMode);
}

/*
else if (!ModLoader.AlphaWelcomed) {
ModLoader.AlphaWelcomed = true;
Expand All @@ -122,7 +127,7 @@ internal static void ModLoaderMenus(Main main, int selectedMenu, string[] button
ModLoader.ShowWhatsNew = false;
if (File.Exists("RecentGitHubCommits.txt")) {
bool LastLaunchedShaInRecentGitHubCommits = false;
var messages = new System.Text.StringBuilder();
var messages = new StringBuilder();
var recentcommitsfilecontents = File.ReadLines("RecentGitHubCommits.txt");
foreach (var commitEntry in recentcommitsfilecontents) {
string[] parts = commitEntry.Split(' ', 2);
Expand Down Expand Up @@ -168,8 +173,10 @@ internal static void ModLoaderMenus(Main main, int selectedMenu, string[] button
string cancelButton = promptDepDownloads ? Language.GetTextValue("tModLoader.ContinueAnyway") : null;
string continueButton = promptDepDownloads ? Language.GetTextValue("tModLoader.InstallDependencies") : "";
Action downloadAction = () => {
if (promptDepDownloads)
WorkshopHelper.ModManager.DownloadBatch(deps.Select(x => x.ToString()).ToArray(), Interface.loadModsID);
if (promptDepDownloads) {
//TODO: Would be nice if this used the names of the mods to replace the second x.ToString()
WorkshopHelper.SetupDownload(deps.Select(x => new ModDownloadItem(x.ToString(), x.ToString(), installed:null)).ToList(), previousMenuId:0);
}
};

if (!string.IsNullOrWhiteSpace(message))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,18 @@ public ModDownloadItem(string displayName, string name, string version, string a
ModloaderVersion = modloaderversion;
}

internal ModDownloadItem(string displayName, string publishId, LocalMod installed) {
DisplayName = displayName;
DisplayNameClean = string.Join("", ChatManager.ParseMessage(displayName, Color.White).Where(x => x.GetType() == typeof(TextSnippet)).Select(x => x.Text));
PublishId = publishId;
Installed = installed;
}

internal Task InnerDownloadWithDeps() {
var downloads = new HashSet<ModDownloadItem>() { this };
downloads.Add(this);
GetDependenciesRecursive(this, ref downloads);
return WorkshopHelper.ModManager.Download(downloads.ToList());
return WorkshopHelper.SetupDownload(downloads.ToList(), Interface.modBrowserID);
}

private IEnumerable<ModDownloadItem> GetDependencies() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ internal void DownloadMods(IEnumerable<string> modNames) {
if (downloads.Count <= 0)
return;

WorkshopHelper.ModManager.Download(downloads);
WorkshopHelper.SetupDownload(downloads, Interface.modBrowserID);

if (_missingMods.Count > 0) {
Interface.infoMessage.Show(Language.GetTextValue("tModLoader.MBModsNotFoundOnline", string.Join(",", _missingMods)), Interface.modBrowserID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ public override void MouseOut(UIMouseEvent evt) {
private void DownloadWithDeps(UIMouseEvent evt, UIElement listeningElement) {
SoundEngine.PlaySound(SoundID.MenuTick);
ModDownload.InnerDownloadWithDeps();

//TODO: Some code to add the 'Installed' item to the UIModDownloaditem and redraw?
}

private void ViewModInfo(UIMouseEvent evt, UIElement listeningElement) {
Expand Down
4 changes: 2 additions & 2 deletions patches/tModLoader/Terraria/ModLoader/UI/UIModInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ internal void Show(string modName, string displayName, int gotoMenu, LocalMod lo
}
_url = url;
_loadFromWeb = loadFromWeb;
if (localMod != null && string.IsNullOrEmpty(publishedFileId) && Social.Steam.WorkshopHelper.ModManager.GetPublishIdLocal(localMod.modFile, out ulong publishId))
if (localMod != null && string.IsNullOrEmpty(publishedFileId) && WorkshopHelper.GetPublishIdLocal(localMod.modFile, out ulong publishId))
_publishedFileId = publishId.ToString();
else
_publishedFileId = publishedFileId;
Expand Down Expand Up @@ -203,7 +203,7 @@ private void VisitModSteamPage(UIMouseEvent evt, UIElement listeningElement) {
private void VisitModSteamPageInner() {
string url = $"http://steamcommunity.com/sharedfiles/filedetails/?id={_publishedFileId}";

if (WorkshopHelper.ModManager.SteamUser && Steamworks.SteamUtils.IsOverlayEnabled())
if (SteamedWraps.SteamClient && Steamworks.SteamUtils.IsOverlayEnabled())
Steamworks.SteamFriends.ActivateGameOverlayToWebPage(url, Steamworks.EActivateGameOverlayToWebPageMode.k_EActivateGameOverlayToWebPageMode_Modal);
else
Utils.OpenToURL(url);
Expand Down
77 changes: 4 additions & 73 deletions patches/tModLoader/Terraria/ModLoader/UI/UIModSourceItem.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
using Hjson;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Newtonsoft.Json.Linq;
using ReLogic.Content;
using ReLogic.OS;
using System;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using Terraria.Audio;
using Terraria.GameContent.UI.Elements;
using Terraria.GameContent.UI.States;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader.Core;
using Terraria.ModLoader.UI.ModBrowser;
using Terraria.Social;
using Terraria.Social.Base;
using Terraria.Social.Steam;
using Terraria.UI;
using Terraria.UI.Chat;

namespace Terraria.ModLoader.UI
{
Expand Down Expand Up @@ -260,7 +252,7 @@ private void BuildAndReload(UIMouseEvent evt, UIElement listeningElement) {
private void PublishMod(UIMouseEvent evt, UIElement listeningElement) {
SoundEngine.PlaySound(10);
try {
if (!WorkshopHelper.ModManager.SteamUser) {
if (!SteamedWraps.SteamClient) {
Utils.ShowFancyErrorMessage(Language.GetTextValue("tModLoader.SteamPublishingLimit"), Interface.modSourcesID);
return;
}
Expand All @@ -281,7 +273,7 @@ private void PublishMod(UIMouseEvent evt, UIElement listeningElement) {
if (!File.Exists(icon))
icon = Path.Combine(_mod, "icon.png");

PublishModInner(_builtMod, icon);
WorkshopHelper.PublishMod(_builtMod, icon);
}
catch (WebException e) {
UIModBrowser.LogModBrowserException(e);
Expand All @@ -291,7 +283,7 @@ private void PublishMod(UIMouseEvent evt, UIElement listeningElement) {
private void PublishServerSideMod(UIMouseEvent evt, UIElement listeningElement) {
SoundEngine.PlaySound(10);
try {
if (!WorkshopHelper.ModManager.SteamUser) {
if (!SteamedWraps.SteamClient) {
Utils.ShowFancyErrorMessage(Language.GetTextValue("tModLoader.SteamPublishingLimit"), Interface.modSourcesID);
return;
}
Expand All @@ -309,7 +301,6 @@ private void PublishServerSideMod(UIMouseEvent evt, UIElement listeningElement)
}
}


internal static void PublishModCommandLine(string modName) {
try {
LocalMod localMod;
Expand All @@ -322,7 +313,7 @@ internal static void PublishModCommandLine(string modName) {
if (!File.Exists(icon))
icon = Path.Combine(ModCompile.ModSourcePath, modName, "icon.png");

PublishModInner(localMod, icon);
WorkshopHelper.PublishMod(localMod, icon);
}
catch (Exception e) {
Console.WriteLine("Something went wrong with command line mod publishing.");
Expand All @@ -334,65 +325,5 @@ internal static void PublishModCommandLine(string modName) {
Steamworks.SteamAPI.Shutdown();
Environment.Exit(0);
}

private static void PublishModInner(LocalMod mod, string iconPath) {
var modFile = mod.modFile;
var bp = mod.properties;

if (bp.buildVersion != modFile.TModLoaderVersion)
throw new WebException(Language.GetTextValue("OutdatedModCantPublishError.BetaModCantPublishError"));

var changeLogFile = Path.Combine(ModCompile.ModSourcePath, modFile.Name, "changelog.txt");
string changeLog;
if (File.Exists(changeLogFile))
changeLog = File.ReadAllText(changeLogFile);
else
changeLog = "";

var workshopDescFile = Path.Combine(ModCompile.ModSourcePath, modFile.Name, "description_workshop.txt");
string workshopDesc;
if (File.Exists(workshopDescFile))
workshopDesc = File.ReadAllText(workshopDescFile);
else
workshopDesc = bp.description;

var values = new NameValueCollection
{
{ "displayname", bp.displayName },
{ "displaynameclean", string.Join("", ChatManager.ParseMessage(bp.displayName, Color.White).Where(x => x.GetType() == typeof(TextSnippet)).Select(x => x.Text)) },
{ "name", modFile.Name },
{ "version", $"v{bp.version}" },
{ "author", bp.author },
{ "homepage", bp.homepage },
{ "description", workshopDesc },
{ "iconpath", iconPath },
{ "sourcesfolder", Path.Combine(ModCompile.ModSourcePath, modFile.Name) },
{ "modloaderversion", $"tModLoader v{modFile.TModLoaderVersion}" },
{ "modreferences", string.Join(", ", bp.modReferences.Select(x => x.mod)) },
{ "modside", bp.side.ToFriendlyString() },
{ "changelog" , changeLog }
};

if (string.IsNullOrWhiteSpace(values["author"]))
throw new WebException($"You need to specify an author in build.txt");

if (string.IsNullOrWhiteSpace(values["version"]))
throw new WebException($"You need to specify a version in build.txt");

if (!Main.dedServ) {
Main.MenuUI.SetState(new WorkshopPublishInfoStateForMods(Interface.modSources, modFile, values));
}
else {
SocialAPI.LoadSteam();

var publishSetttings = new WorkshopItemPublishSettings {
Publicity = WorkshopItemPublicSettingId.Public,
UsedTags = Array.Empty<WorkshopTagOption>(),
PreviewImagePath = iconPath
};
WorkshopHelper.ModManager.SteamUser = true;
SocialAPI.Workshop.PublishMod(modFile, values, publishSetttings);
}
}
}
}
2 changes: 1 addition & 1 deletion patches/tModLoader/Terraria/Player.cs.patch
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
Main.ToggleGameplayUpdates(state: true);
+
+ // Added by TML.
+ Social.Steam.WorkshopHelper.ModManager.BeginPlaytimeTracking();
+ Social.Steam.SteamedWraps.BeginPlaytimeTracking();
+ }
}
}
Expand Down
Loading

0 comments on commit 8ef29f1

Please sign in to comment.