Skip to content

Commit

Permalink
Fix null ref exception if a mod somehow sets a recipe to null
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPurple6411 committed Dec 22, 2022
1 parent 4bb0923 commit 46b2d00
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions SMLHelper/Patchers/CraftDataPatcher_Subnautica.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private static void PatchCustomTechData()
ITechData smlTechData = CustomTechData[techType];
bool sameData = false;

if (techExists)
if (techExists && smlTechData != null)
{

sameData = smlTechData.craftAmount == techData.craftAmount &&
Expand Down Expand Up @@ -228,12 +228,12 @@ private static void PatchCustomTechData()
var techDataInstance = new CraftData.TechData
{
_techType = techType,
_craftAmount = smlTechData.craftAmount
_craftAmount = smlTechData?.craftAmount ?? 0
};

var ingredientsList = new CraftData.Ingredients();

if (smlTechData.ingredientCount > 0)
if (smlTechData?.ingredientCount > 0)
{
for (int i = 0; i < smlTechData.ingredientCount; i++)
{
Expand All @@ -245,7 +245,7 @@ private static void PatchCustomTechData()
techDataInstance._ingredients = ingredientsList;
}

if (smlTechData.linkedItemCount > 0)
if (smlTechData?.linkedItemCount > 0)
{
var linkedItems = new List<TechType>();
for (int l = 0; l < smlTechData.linkedItemCount; l++)
Expand All @@ -270,10 +270,10 @@ private static void PatchCustomTechData()
}

if (added > 0)
InternalLogger.Log($"Added {added} new entries to the CraftData.techData dictionary.", LogLevel.Info);
InternalLogger.Log($"Added {added} new entries to the CraftData.techData dictionary.", LogLevel.Debug);

if (replaced > 0)
InternalLogger.Log($"Replaced {replaced} existing entries to the CraftData.techData dictionary.", LogLevel.Info);
InternalLogger.Log($"Replaced {replaced} existing entries to the CraftData.techData dictionary.", LogLevel.Debug);
}


Expand Down

0 comments on commit 46b2d00

Please sign in to comment.