(feat) Disable Mod rewrites if requested
This commit is contained in:
parent
8a475b3579
commit
f945349ed4
|
@ -286,12 +286,15 @@ namespace StardewModdingAPI.Framework.Logging
|
|||
/// <summary>Log details for settings that don't match the default.</summary>
|
||||
/// <param name="isDeveloperMode">Whether to enable full console output for developers.</param>
|
||||
/// <param name="checkForUpdates">Whether to check for newer versions of SMAPI and mods on startup.</param>
|
||||
public void LogSettingsHeader(bool isDeveloperMode, bool checkForUpdates)
|
||||
/// ///<param name="rewriteMods">Whether to rewrite mods, might need to be false to hook up to the Visual Studio Debugger.</param>
|
||||
public void LogSettingsHeader(bool isDeveloperMode, bool checkForUpdates, bool rewriteMods)
|
||||
{
|
||||
if (isDeveloperMode)
|
||||
this.Monitor.Log($"You have SMAPI for developers, so the console will be much more verbose. You can disable developer mode by installing the non-developer version of SMAPI, or by editing {Constants.ApiConfigPath}.", LogLevel.Info);
|
||||
if (!checkForUpdates)
|
||||
this.Monitor.Log($"You configured SMAPI to not check for updates. Running an old version of SMAPI is not recommended. You can enable update checks by reinstalling SMAPI or editing {Constants.ApiConfigPath}.", LogLevel.Warn);
|
||||
if (!rewriteMods)
|
||||
this.Monitor.Log($"You configured SMAPI to not rewrite potentially broken mods. This is not reccomended except in certain circumstances such as attaching to the Visual Studio debugger. You can enable mod rewrites by reinstalling SMAPI or editing {Constants.ApiConfigPath}.", LogLevel.Warn);
|
||||
if (!this.Monitor.WriteToConsole)
|
||||
this.Monitor.Log("Writing to the terminal is disabled because the --no-terminal argument was received. This usually means launching the terminal failed.", LogLevel.Warn);
|
||||
this.Monitor.VerboseLog("Verbose logging enabled.");
|
||||
|
|
|
@ -37,6 +37,9 @@ namespace StardewModdingAPI.Framework.ModLoading
|
|||
/// <summary>The objects to dispose as part of this instance.</summary>
|
||||
private readonly HashSet<IDisposable> Disposables = new HashSet<IDisposable>();
|
||||
|
||||
/// <summary>Whether mods should be re-writen for compatibility.</summary>
|
||||
private readonly bool RewriteMods;
|
||||
|
||||
|
||||
/*********
|
||||
** Public methods
|
||||
|
@ -45,10 +48,12 @@ namespace StardewModdingAPI.Framework.ModLoading
|
|||
/// <param name="targetPlatform">The current game platform.</param>
|
||||
/// <param name="monitor">Encapsulates monitoring and logging.</param>
|
||||
/// <param name="paranoidMode">Whether to detect paranoid mode issues.</param>
|
||||
public AssemblyLoader(Platform targetPlatform, IMonitor monitor, bool paranoidMode)
|
||||
/// <param name="rewriteMods">Whether to rewrite potentially broken mods or not.</param>
|
||||
public AssemblyLoader(Platform targetPlatform, IMonitor monitor, bool paranoidMode, bool rewriteMods)
|
||||
{
|
||||
this.Monitor = monitor;
|
||||
this.ParanoidMode = paranoidMode;
|
||||
this.RewriteMods = rewriteMods;
|
||||
this.AssemblyMap = this.TrackForDisposal(Constants.GetAssemblyMap(targetPlatform));
|
||||
|
||||
// init resolver
|
||||
|
@ -308,7 +313,7 @@ namespace StardewModdingAPI.Framework.ModLoading
|
|||
}
|
||||
|
||||
// find or rewrite code
|
||||
IInstructionHandler[] handlers = new InstructionMetadata().GetHandlers(this.ParanoidMode, platformChanged).ToArray();
|
||||
IInstructionHandler[] handlers = new InstructionMetadata().GetHandlers(this.ParanoidMode, platformChanged, this.RewriteMods).ToArray();
|
||||
RecursiveRewriter rewriter = new RecursiveRewriter(
|
||||
module: module,
|
||||
rewriteType: (type, replaceWith) =>
|
||||
|
|
|
@ -20,7 +20,8 @@ namespace StardewModdingAPI.Framework.Models
|
|||
[nameof(GitHubProjectName)] = "Pathoschild/SMAPI",
|
||||
[nameof(WebApiBaseUrl)] = "https://smapi.io/api/",
|
||||
[nameof(VerboseLogging)] = false,
|
||||
[nameof(LogNetworkTraffic)] = false
|
||||
[nameof(LogNetworkTraffic)] = false,
|
||||
[nameof(RewriteMods)] = true
|
||||
};
|
||||
|
||||
/// <summary>The default values for <see cref="SuppressUpdateChecks"/>, to log changes if different.</summary>
|
||||
|
@ -64,6 +65,9 @@ namespace StardewModdingAPI.Framework.Models
|
|||
/// <summary>The mod IDs SMAPI should ignore when performing update checks or validating update keys.</summary>
|
||||
public string[] SuppressUpdateChecks { get; set; }
|
||||
|
||||
/// <summary>Whether to rewrite mods for compatibility. Should only be set to false to facilitate joining to the Visual Studio Debugger.</summary>
|
||||
public bool RewriteMods { get; set; } = (bool)SConfig.DefaultValues[nameof(SConfig.RewriteMods)];
|
||||
|
||||
|
||||
/********
|
||||
** Public methods
|
||||
|
|
|
@ -276,7 +276,7 @@ namespace StardewModdingAPI.Framework
|
|||
|
||||
// log basic info
|
||||
this.LogManager.HandleMarkerFiles();
|
||||
this.LogManager.LogSettingsHeader(this.Settings.DeveloperMode, this.Settings.CheckForUpdates);
|
||||
this.LogManager.LogSettingsHeader(this.Settings.DeveloperMode, this.Settings.CheckForUpdates, this.Settings.RewriteMods);
|
||||
|
||||
// set window titles
|
||||
this.SetWindowTitles(
|
||||
|
@ -1389,7 +1389,7 @@ namespace StardewModdingAPI.Framework
|
|||
|
||||
// load mods
|
||||
IList<IModMetadata> skippedMods = new List<IModMetadata>();
|
||||
using (AssemblyLoader modAssemblyLoader = new AssemblyLoader(Constants.Platform, this.Monitor, this.Settings.ParanoidWarnings))
|
||||
using (AssemblyLoader modAssemblyLoader = new AssemblyLoader(Constants.Platform, this.Monitor, this.Settings.ParanoidWarnings, this.Settings.RewriteMods))
|
||||
{
|
||||
// init
|
||||
HashSet<string> suppressUpdateChecks = new HashSet<string>(this.Settings.SuppressUpdateChecks, StringComparer.OrdinalIgnoreCase);
|
||||
|
|
|
@ -27,29 +27,32 @@ namespace StardewModdingAPI.Metadata
|
|||
/// <summary>Get rewriters which detect or fix incompatible CIL instructions in mod assemblies.</summary>
|
||||
/// <param name="paranoidMode">Whether to detect paranoid mode issues.</param>
|
||||
/// <param name="platformChanged">Whether the assembly was rewritten for crossplatform compatibility.</param>
|
||||
public IEnumerable<IInstructionHandler> GetHandlers(bool paranoidMode, bool platformChanged)
|
||||
/// <param name="rewriteMods">Whether to return Rewriters</param>
|
||||
public IEnumerable<IInstructionHandler> GetHandlers(bool paranoidMode, bool platformChanged, bool rewriteMods)
|
||||
{
|
||||
/****
|
||||
** rewrite CIL to fix incompatible code
|
||||
****/
|
||||
// rewrite for crossplatform compatibility
|
||||
if (platformChanged)
|
||||
yield return new MethodParentRewriter(typeof(SpriteBatch), typeof(SpriteBatchFacade));
|
||||
if (rewriteMods)
|
||||
{
|
||||
if (platformChanged)
|
||||
yield return new MethodParentRewriter(typeof(SpriteBatch), typeof(SpriteBatchFacade));
|
||||
|
||||
// rewrite for Stardew Valley 1.5
|
||||
yield return new FieldReplaceRewriter(typeof(DecoratableLocation), "furniture", typeof(GameLocation), nameof(GameLocation.furniture));
|
||||
yield return new FieldReplaceRewriter(typeof(Farm), "resourceClumps", typeof(GameLocation), nameof(GameLocation.resourceClumps));
|
||||
yield return new FieldReplaceRewriter(typeof(MineShaft), "resourceClumps", typeof(GameLocation), nameof(GameLocation.resourceClumps));
|
||||
// rewrite for Stardew Valley 1.5
|
||||
yield return new FieldReplaceRewriter(typeof(DecoratableLocation), "furniture", typeof(GameLocation), nameof(GameLocation.furniture));
|
||||
yield return new FieldReplaceRewriter(typeof(Farm), "resourceClumps", typeof(GameLocation), nameof(GameLocation.resourceClumps));
|
||||
yield return new FieldReplaceRewriter(typeof(MineShaft), "resourceClumps", typeof(GameLocation), nameof(GameLocation.resourceClumps));
|
||||
|
||||
// heuristic rewrites
|
||||
yield return new HeuristicFieldRewriter(this.ValidateReferencesToAssemblies);
|
||||
yield return new HeuristicMethodRewriter(this.ValidateReferencesToAssemblies);
|
||||
// heuristic rewrites
|
||||
yield return new HeuristicFieldRewriter(this.ValidateReferencesToAssemblies);
|
||||
yield return new HeuristicMethodRewriter(this.ValidateReferencesToAssemblies);
|
||||
|
||||
#if HARMONY_2
|
||||
// rewrite for SMAPI 3.6 (Harmony 1.x => 2.0 update)
|
||||
yield return new Harmony1AssemblyRewriter();
|
||||
#endif
|
||||
|
||||
}
|
||||
/****
|
||||
** detect mod issues
|
||||
****/
|
||||
|
|
|
@ -68,6 +68,12 @@ copy all the settings, or you may cause bugs due to overridden changes in future
|
|||
*/
|
||||
"LogNetworkTraffic": false,
|
||||
|
||||
/**
|
||||
* Whether SMAPI should rewrite mods for compatibility.
|
||||
* Note: This is best left to true unless you are attempting to hook into the Visual Studio Debugger
|
||||
*/
|
||||
"RewriteMods": true,
|
||||
|
||||
/**
|
||||
* The colors to use for text written to the SMAPI console.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue