diff --git a/patches/tModLoader/Terraria/Social/Steam/SteamedWraps.cs b/patches/tModLoader/Terraria/Social/Steam/SteamedWraps.cs index 7ab2b0cc48a..88a7dd45529 100644 --- a/patches/tModLoader/Terraria/Social/Steam/SteamedWraps.cs +++ b/patches/tModLoader/Terraria/Social/Steam/SteamedWraps.cs @@ -340,22 +340,18 @@ public static void BeginPlaytimeTracking() internal static void OnGameExitCleanup() { - // PATH/Steamapps/workshop - string workshopFolder = WorkshopHelper.GetWorkshopFolder(ModLoader.Engine.Steam.TMLAppID_t); - // Steamapps/workshop/appworkshop_1281930.acf - string targetACF = Path.Combine(workshopFolder, $"appworkshop_{ModLoader.Engine.Steam.TMLAppID}.acf"); + if (!SteamAvailable) { + CleanupACF(); + return; + } - if (SteamClient) + if (SteamClient) { SteamAPI.Shutdown(); - else if (SteamAvailable) - GameServer.Shutdown(); - - if (!File.Exists(targetACF)) { - Logging.tML.Error($"Unable to locate tmodloader steam acf. Expected path: {targetACF}"); return; } - File.Delete(targetACF); + GameServer.Shutdown(); + CleanupACF(); } public static uint GetWorkshopItemState(PublishedFileId_t publishId) @@ -400,6 +396,18 @@ public static void UninstallWorkshopItem(PublishedFileId_t publishId, string ins // Remove the files Directory.Delete(installPath, true); + + if (!SteamClient) + // Steam Game Server has to be terminated before the ACF file is modified, so we defer cleanup to end of game likse steam client. + deletedItems.Add(publishId); + } + + private static List deletedItems = new List(); + + private static void CleanupACF() + { + foreach (var item in deletedItems) + UninstallACF(item); } private static void UninstallACF(PublishedFileId_t publishId)