add console warning in paranoid mode
This commit is contained in:
parent
4da65cf4c0
commit
0a00c70397
|
@ -20,6 +20,7 @@
|
|||
* For modders:
|
||||
* Added asset propagation for grass textures.
|
||||
* Added asset propagation for `Data\Bundles` changes (for added bundles only).
|
||||
* Added direct `Console` access to paranoid mode warnings.
|
||||
* Improved error messages for `TargetParameterCountException` when using the reflection API.
|
||||
* `helper.Read/WriteSaveData` can now be used while a save is being loaded (e.g. within a `Specialized.LoadStageChanged` event).
|
||||
* Fixed private textures loaded from content packs not having their `Name` field set.
|
||||
|
|
|
@ -27,10 +27,13 @@ namespace StardewModdingAPI.Toolkit.Framework.ModData
|
|||
/// <summary>The mod has no update keys set.</summary>
|
||||
NoUpdateKeys = 32,
|
||||
|
||||
/// <summary>Uses .NET APIs for reading and writing to the console.</summary>
|
||||
AccessesConsole = 64,
|
||||
|
||||
/// <summary>Uses .NET APIs for filesystem access.</summary>
|
||||
AccessesFilesystem = 64,
|
||||
AccessesFilesystem = 128,
|
||||
|
||||
/// <summary>Uses .NET APIs for shell or process access.</summary>
|
||||
AccessesShell = 128
|
||||
AccessesShell = 256
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,8 +42,8 @@ namespace StardewModdingAPI.Framework.Content
|
|||
Texture2D target = this.Data;
|
||||
|
||||
// get areas
|
||||
sourceArea = sourceArea ?? new Rectangle(0, 0, source.Width, source.Height);
|
||||
targetArea = targetArea ?? new Rectangle(0, 0, Math.Min(sourceArea.Value.Width, target.Width), Math.Min(sourceArea.Value.Height, target.Height));
|
||||
sourceArea ??= new Rectangle(0, 0, source.Width, source.Height);
|
||||
targetArea ??= new Rectangle(0, 0, Math.Min(sourceArea.Value.Width, target.Width), Math.Min(sourceArea.Value.Height, target.Height));
|
||||
|
||||
// validate
|
||||
if (sourceArea.Value.X < 0 || sourceArea.Value.Y < 0 || sourceArea.Value.Right > source.Width || sourceArea.Value.Bottom > source.Height)
|
||||
|
|
|
@ -356,6 +356,11 @@ namespace StardewModdingAPI.Framework.ModLoading
|
|||
mod.SetWarning(ModWarning.UsesDynamic);
|
||||
break;
|
||||
|
||||
case InstructionHandleResult.DetectedConsoleAccess:
|
||||
this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Detected direct console access ({handler.NounPhrase}) in assembly {filename}.");
|
||||
mod.SetWarning(ModWarning.AccessesConsole);
|
||||
break;
|
||||
|
||||
case InstructionHandleResult.DetectedFilesystemAccess:
|
||||
this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Detected filesystem access ({handler.NounPhrase}) in assembly {filename}.");
|
||||
mod.SetWarning(ModWarning.AccessesFilesystem);
|
||||
|
|
|
@ -26,6 +26,9 @@ namespace StardewModdingAPI.Framework.ModLoading
|
|||
/// <summary>The instruction is compatible, but references <see cref="ISpecializedEvents.UnvalidatedUpdateTicking"/> or <see cref="ISpecializedEvents.UnvalidatedUpdateTicked"/> which may impact stability.</summary>
|
||||
DetectedUnvalidatedUpdateTick,
|
||||
|
||||
/// <summary>The instruction accesses the SMAPI console directly.</summary>
|
||||
DetectedConsoleAccess,
|
||||
|
||||
/// <summary>The instruction accesses the filesystem directly.</summary>
|
||||
DetectedFilesystemAccess,
|
||||
|
||||
|
|
|
@ -1102,6 +1102,10 @@ namespace StardewModdingAPI.Framework
|
|||
);
|
||||
if (this.Settings.ParanoidWarnings)
|
||||
{
|
||||
LogWarningGroup(ModWarning.AccessesConsole, LogLevel.Warn, "Accesses the console directly",
|
||||
"These mods directly access the SMAPI console, and you enabled paranoid warnings. (Note that this may be",
|
||||
"legitimate and innocent usage; this warning is meaningless without further investigation.)"
|
||||
);
|
||||
LogWarningGroup(ModWarning.AccessesFilesystem, LogLevel.Warn, "Accesses filesystem directly",
|
||||
"These mods directly access the filesystem, and you enabled paranoid warnings. (Note that this may be",
|
||||
"legitimate and innocent usage; this warning is meaningless without further investigation.)"
|
||||
|
|
|
@ -60,6 +60,7 @@ namespace StardewModdingAPI.Metadata
|
|||
if (paranoidMode)
|
||||
{
|
||||
// filesystem access
|
||||
yield return new TypeFinder(typeof(System.Console).FullName, InstructionHandleResult.DetectedConsoleAccess);
|
||||
yield return new TypeFinder(typeof(System.IO.File).FullName, InstructionHandleResult.DetectedFilesystemAccess);
|
||||
yield return new TypeFinder(typeof(System.IO.FileStream).FullName, InstructionHandleResult.DetectedFilesystemAccess);
|
||||
yield return new TypeFinder(typeof(System.IO.FileInfo).FullName, InstructionHandleResult.DetectedFilesystemAccess);
|
||||
|
|
Loading…
Reference in New Issue