summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/SMAPI.Toolkit/Framework/LowLevelEnvironmentUtility.cs2
-rw-r--r--src/SMAPI.Toolkit/ModToolkit.cs2
-rw-r--r--src/SMAPI.Toolkit/Serialization/Converters/SemanticVersionConverter.cs7
-rw-r--r--src/SMAPI.Toolkit/Serialization/Converters/SimpleReadOnlyConverter.cs7
-rw-r--r--src/SMAPI/Framework/ModHelpers/ModHelper.cs1
-rw-r--r--src/SMAPI/Framework/Models/SConfig.cs2
-rw-r--r--src/SMAPI/Framework/SCore.cs2
-rw-r--r--src/SMAPI/Framework/Serialization/KeybindConverter.cs5
-rw-r--r--src/SMAPI/Utilities/SDate.cs4
9 files changed, 23 insertions, 9 deletions
diff --git a/src/SMAPI.Toolkit/Framework/LowLevelEnvironmentUtility.cs b/src/SMAPI.Toolkit/Framework/LowLevelEnvironmentUtility.cs
index 118b71b2..f464f4bb 100644
--- a/src/SMAPI.Toolkit/Framework/LowLevelEnvironmentUtility.cs
+++ b/src/SMAPI.Toolkit/Framework/LowLevelEnvironmentUtility.cs
@@ -22,7 +22,7 @@ namespace StardewModdingAPI.Toolkit.Framework
/// <param name="buffer">The buffer to fill with the resulting string.</param>
[DllImport("libc")]
[SuppressMessage("ReSharper", "IdentifierTypo", Justification = "This is the actual external command name.")]
- static extern int uname(IntPtr buffer);
+ private static extern int uname(IntPtr buffer);
/*********
diff --git a/src/SMAPI.Toolkit/ModToolkit.cs b/src/SMAPI.Toolkit/ModToolkit.cs
index 0df75a31..55b9bdd8 100644
--- a/src/SMAPI.Toolkit/ModToolkit.cs
+++ b/src/SMAPI.Toolkit/ModToolkit.cs
@@ -65,7 +65,7 @@ namespace StardewModdingAPI.Toolkit
/// <param name="metadataPath">The file path for the SMAPI metadata file.</param>
public ModDatabase GetModDatabase(string metadataPath)
{
- MetadataModel metadata = JsonConvert.DeserializeObject<MetadataModel>(File.ReadAllText(metadataPath));
+ MetadataModel metadata = JsonConvert.DeserializeObject<MetadataModel>(File.ReadAllText(metadataPath)) ?? new MetadataModel();
ModDataRecord[] records = metadata.ModData.Select(pair => new ModDataRecord(pair.Key, pair.Value)).ToArray();
return new ModDatabase(records, this.GetUpdateUrl);
}
diff --git a/src/SMAPI.Toolkit/Serialization/Converters/SemanticVersionConverter.cs b/src/SMAPI.Toolkit/Serialization/Converters/SemanticVersionConverter.cs
index c32c3185..913d54e0 100644
--- a/src/SMAPI.Toolkit/Serialization/Converters/SemanticVersionConverter.cs
+++ b/src/SMAPI.Toolkit/Serialization/Converters/SemanticVersionConverter.cs
@@ -48,7 +48,12 @@ namespace StardewModdingAPI.Toolkit.Serialization.Converters
return this.ReadObject(JObject.Load(reader));
case JsonToken.String:
- return this.ReadString(JToken.Load(reader).Value<string>(), path);
+ {
+ string? value = JToken.Load(reader).Value<string>();
+ return value is not null
+ ? this.ReadString(value, path)
+ : null;
+ }
default:
throw new SParseException($"Can't parse {nameof(ISemanticVersion)} from {reader.TokenType} node (path: {reader.Path}).");
diff --git a/src/SMAPI.Toolkit/Serialization/Converters/SimpleReadOnlyConverter.cs b/src/SMAPI.Toolkit/Serialization/Converters/SimpleReadOnlyConverter.cs
index 1c59f5e7..cdf2ed77 100644
--- a/src/SMAPI.Toolkit/Serialization/Converters/SimpleReadOnlyConverter.cs
+++ b/src/SMAPI.Toolkit/Serialization/Converters/SimpleReadOnlyConverter.cs
@@ -42,7 +42,12 @@ namespace StardewModdingAPI.Toolkit.Serialization.Converters
return this.ReadObject(JObject.Load(reader), path);
case JsonToken.String:
- return this.ReadString(JToken.Load(reader).Value<string>(), path);
+ {
+ string? value = JToken.Load(reader).Value<string>();
+ return value is not null
+ ? this.ReadString(value, path)
+ : null;
+ }
default:
throw new SParseException($"Can't parse {typeof(T).Name} from {reader.TokenType} node (path: {reader.Path}).");
diff --git a/src/SMAPI/Framework/ModHelpers/ModHelper.cs b/src/SMAPI/Framework/ModHelpers/ModHelper.cs
index 9ac3b6f7..caa66bad 100644
--- a/src/SMAPI/Framework/ModHelpers/ModHelper.cs
+++ b/src/SMAPI/Framework/ModHelpers/ModHelper.cs
@@ -88,6 +88,7 @@ namespace StardewModdingAPI.Framework.ModHelpers
/// <param name="modDirectory">The full path to the mod's folder.</param>
/// <param name="currentInputState">Manages the game's input state for the current player instance. That may not be the main player in split-screen mode.</param>
/// <param name="events">Manages access to events raised by SMAPI.</param>
+ /// <param name="contentHelper">An API for loading content assets.</param>
/// <param name="gameContentHelper">An API for loading content assets from the game's <c>Content</c> folder or via <see cref="IModEvents.Content"/>.</param>
/// <param name="modContentHelper">An API for loading content assets from your mod's files.</param>
/// <param name="contentPackHelper">An API for managing content packs.</param>
diff --git a/src/SMAPI/Framework/Models/SConfig.cs b/src/SMAPI/Framework/Models/SConfig.cs
index 62b15405..9444c046 100644
--- a/src/SMAPI/Framework/Models/SConfig.cs
+++ b/src/SMAPI/Framework/Models/SConfig.cs
@@ -100,7 +100,7 @@ namespace StardewModdingAPI.Framework.Models
/// <param name="logNetworkTraffic">Whether SMAPI should log network traffic.</param>
/// <param name="consoleColors">The colors to use for text written to the SMAPI console.</param>
/// <param name="suppressUpdateChecks">The mod IDs SMAPI should ignore when performing update checks or validating update keys.</param>
- public SConfig(bool developerMode, bool? checkForUpdates, bool? paranoidWarnings, bool? useBetaChannel, string gitHubProjectName, string webApiBaseUrl, string[]? verboseLogging, bool? rewriteMods, bool? usePintail, bool? useRawImageLoading, bool? useCaseInsensitivePaths, bool? logNetworkTraffic, ColorSchemeConfig consoleColors, string[]? suppressUpdateChecks)
+ public SConfig(bool developerMode, bool? checkForUpdates, bool? paranoidWarnings, bool? useBetaChannel, string gitHubProjectName, string webApiBaseUrl, string[]? verboseLogging, bool? rewriteMods, bool? useRawImageLoading, bool? useCaseInsensitivePaths, bool? logNetworkTraffic, ColorSchemeConfig consoleColors, string[]? suppressUpdateChecks)
{
this.DeveloperMode = developerMode;
this.CheckForUpdates = checkForUpdates ?? (bool)SConfig.DefaultValues[nameof(this.CheckForUpdates)];
diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs
index d9969d4d..46d65f6a 100644
--- a/src/SMAPI/Framework/SCore.cs
+++ b/src/SMAPI/Framework/SCore.cs
@@ -191,7 +191,7 @@ namespace StardewModdingAPI.Framework
string logPath = this.GetLogPath();
// init basics
- this.Settings = JsonConvert.DeserializeObject<SConfig>(File.ReadAllText(Constants.ApiConfigPath));
+ this.Settings = JsonConvert.DeserializeObject<SConfig>(File.ReadAllText(Constants.ApiConfigPath)) ?? throw new InvalidOperationException("The 'smapi-internal/config.json' file is missing or invalid. You can reinstall SMAPI to fix this.");
if (File.Exists(Constants.ApiUserConfigPath))
JsonConvert.PopulateObject(File.ReadAllText(Constants.ApiUserConfigPath), this.Settings);
if (developerMode.HasValue)
diff --git a/src/SMAPI/Framework/Serialization/KeybindConverter.cs b/src/SMAPI/Framework/Serialization/KeybindConverter.cs
index 539f1291..f7b8e67e 100644
--- a/src/SMAPI/Framework/Serialization/KeybindConverter.cs
+++ b/src/SMAPI/Framework/Serialization/KeybindConverter.cs
@@ -49,7 +49,10 @@ namespace StardewModdingAPI.Framework.Serialization
case JsonToken.String:
{
- string str = JToken.Load(reader).Value<string>();
+ string? str = JToken.Load(reader).Value<string>();
+
+ if (str is null)
+ return new Keybind(Array.Empty<SButton>());
if (objectType == typeof(Keybind))
{
diff --git a/src/SMAPI/Utilities/SDate.cs b/src/SMAPI/Utilities/SDate.cs
index c7ad41bd..06ee8b91 100644
--- a/src/SMAPI/Utilities/SDate.cs
+++ b/src/SMAPI/Utilities/SDate.cs
@@ -278,11 +278,11 @@ namespace StardewModdingAPI.Utilities
/// <summary>Get whether a date represents 0 spring Y1, which is the date during the in-game intro.</summary>
/// <param name="day">The day of month.</param>
- /// <param name="season">The season name.</param>
+ /// <param name="season">The normalized season name.</param>
/// <param name="year">The year.</param>
private bool IsDayZero(int day, string season, int year)
{
- return day == 0 && season?.Trim().ToLower() == "spring" && year == 1;
+ return day == 0 && season == "spring" && year == 1;
}
/// <summary>Get the day of week for a given date.</summary>