Skip to content

Commit

Permalink
Fix exceptions when DLC info hasn't loaded yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gwindalmir committed May 12, 2024
1 parent 011444c commit 85e5e34
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
16 changes: 12 additions & 4 deletions WorkshopToolCommon/Extensions/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,19 @@ public static class MyDLCExtensions
public static uint TryGetDLC(this string dlc)
{
#if SE
Sandbox.Game.MyDLCs.MyDLC dlcvalue;
if (Sandbox.Game.MyDLCs.TryGetDLC(dlc, out dlcvalue))
return dlcvalue.AppId;
else
VRage.Game.Definitions.MyDlcDefinition dlcvalue;
try
{
if (Sandbox.Game.MyDLCs.TryGetDLC(dlc, out dlcvalue))
return dlcvalue.AppId;
else
return 0;
}
catch(NullReferenceException)
{
MySandboxGame.Log.WriteLineWarning($"Could not look up DLC with name '{dlc}'. As of SE version 1.204, name lookups are not available. Please use the AppId when specifying DLC instead. Valid AppIds are found in '{Path.Combine(MyModContext.BaseGame.ModPathData, "Game", "DLCs.sbc")}'.");
return 0;
}
#else
return 0;
#endif
Expand Down
11 changes: 9 additions & 2 deletions WorkshopToolCommon/GameBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1039,9 +1039,16 @@ private void ListDLCs()
{
#if SE
MySandboxGame.Log.WriteLineAndConsole("Valid DLC:");
foreach (var dlc in Sandbox.Game.MyDLCs.DLCs.Values)
try
{
foreach (var dlc in Sandbox.Game.MyDLCs.DLCs.Values)
{
MySandboxGame.Log.WriteLineAndConsole($"Name: {dlc.Name}, ID: {dlc.AppId}");
}
}
catch(NullReferenceException)
{
MySandboxGame.Log.WriteLineAndConsole($"Name: {dlc.Name}, ID: {dlc.AppId}");
MySandboxGame.Log.WriteLineWarning($"This option is no longer available as of SE version 1.204.\nValid DLC AppIds are in '{Path.Combine(MyModContext.BaseGame.ModPathData, "Game", "DLCs.sbc")}'.");
}
#endif
}
Expand Down

0 comments on commit 85e5e34

Please sign in to comment.