diff --git a/src/StardewModdingAPI/Framework/ModHelper.cs b/src/StardewModdingAPI/Framework/ModHelper.cs
index 09297a65..7810148c 100644
--- a/src/StardewModdingAPI/Framework/ModHelper.cs
+++ b/src/StardewModdingAPI/Framework/ModHelper.cs
@@ -1,6 +1,5 @@
using System;
using System.IO;
-using StardewModdingAPI.Framework.Reflection;
using StardewModdingAPI.Framework.Serialisation;
namespace StardewModdingAPI.Framework
@@ -25,7 +24,7 @@ namespace StardewModdingAPI.Framework
public IContentHelper Content { get; }
/// Simplifies access to private game code.
- public IReflectionHelper Reflection { get; } = new ReflectionHelper();
+ public IReflectionHelper Reflection { get; }
/// Metadata about loaded mods.
public IModRegistry ModRegistry { get; }
@@ -44,9 +43,10 @@ namespace StardewModdingAPI.Framework
/// Metadata about loaded mods.
/// Manages console commands.
/// The content manager which loads content assets.
+ /// Simplifies access to private game code.
/// An argument is null or empty.
/// The path does not exist on disk.
- public ModHelper(IManifest manifest, string modDirectory, JsonHelper jsonHelper, IModRegistry modRegistry, CommandManager commandManager, SContentManager contentManager)
+ public ModHelper(IManifest manifest, string modDirectory, JsonHelper jsonHelper, IModRegistry modRegistry, CommandManager commandManager, SContentManager contentManager, IReflectionHelper reflection)
{
// validate
if (string.IsNullOrWhiteSpace(modDirectory))
@@ -64,6 +64,7 @@ namespace StardewModdingAPI.Framework
this.Content = new ContentHelper(contentManager, modDirectory, manifest.Name);
this.ModRegistry = modRegistry;
this.ConsoleCommands = new CommandHelper(manifest.Name, commandManager);
+ this.Reflection = reflection;
}
/****
diff --git a/src/StardewModdingAPI/Framework/SGame.cs b/src/StardewModdingAPI/Framework/SGame.cs
index d248c3ca..8786010e 100644
--- a/src/StardewModdingAPI/Framework/SGame.cs
+++ b/src/StardewModdingAPI/Framework/SGame.cs
@@ -9,7 +9,6 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using StardewModdingAPI.Events;
-using StardewModdingAPI.Framework.Reflection;
using StardewValley;
using StardewValley.BellsAndWhistles;
using StardewValley.Locations;
@@ -157,9 +156,11 @@ namespace StardewModdingAPI.Framework
/****
** Private wrappers
****/
+ /// Simplifies access to private game code.
+ private static IReflectionHelper Reflection;
+
// ReSharper disable ArrangeStaticMemberQualifier, ArrangeThisQualifier, InconsistentNaming
/// Used to access private fields and methods.
- private static readonly IReflectionHelper Reflection = new ReflectionHelper();
private static List _fpsList => SGame.Reflection.GetPrivateField>(typeof(Game1), nameof(_fpsList)).GetValue();
private static Stopwatch _fpsStopwatch => SGame.Reflection.GetPrivateField(typeof(Game1), nameof(SGame._fpsStopwatch)).GetValue();
private static float _fps
@@ -176,6 +177,7 @@ namespace StardewModdingAPI.Framework
private readonly Action renderScreenBuffer = () => SGame.Reflection.GetPrivateMethod(SGame.Instance, nameof(renderScreenBuffer)).Invoke(new object[0]);
// ReSharper restore ArrangeStaticMemberQualifier, ArrangeThisQualifier, InconsistentNaming
+
/*********
** Accessors
*********/
@@ -188,11 +190,13 @@ namespace StardewModdingAPI.Framework
*********/
/// Construct an instance.
/// Encapsulates monitoring and logging.
- internal SGame(IMonitor monitor)
+ /// Simplifies access to private game code.
+ internal SGame(IMonitor monitor, IReflectionHelper reflection)
{
this.Monitor = monitor;
this.FirstUpdate = true;
SGame.Instance = this;
+ SGame.Reflection = reflection;
Game1.graphics.GraphicsProfile = GraphicsProfile.HiDef; // required by Stardew Valley
}
diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs
index 1913544f..aa78ff41 100644
--- a/src/StardewModdingAPI/Program.cs
+++ b/src/StardewModdingAPI/Program.cs
@@ -15,6 +15,7 @@ using StardewModdingAPI.Events;
using StardewModdingAPI.Framework;
using StardewModdingAPI.Framework.Logging;
using StardewModdingAPI.Framework.Models;
+using StardewModdingAPI.Framework.Reflection;
using StardewModdingAPI.Framework.Serialisation;
using StardewValley;
using Monitor = StardewModdingAPI.Framework.Monitor;
@@ -40,6 +41,9 @@ namespace StardewModdingAPI
/// Tracks whether the game should exit immediately and any pending initialisation should be cancelled.
private readonly CancellationTokenSource CancellationTokenSource = new CancellationTokenSource();
+ /// Simplifies access to private game code.
+ private readonly IReflectionHelper Reflection = new ReflectionHelper();
+
/// The underlying game instance.
private SGame GameInstance;
@@ -141,7 +145,7 @@ namespace StardewModdingAPI
AppDomain.CurrentDomain.UnhandledException += (sender, e) => this.Monitor.Log($"Critical app domain exception: {e.ExceptionObject}", LogLevel.Error);
// override game
- this.GameInstance = new SGame(this.Monitor);
+ this.GameInstance = new SGame(this.Monitor, this.Reflection);
StardewValley.Program.gamePtr = this.GameInstance;
// add exit handler
@@ -599,7 +603,7 @@ namespace StardewModdingAPI
// inject data
// get helper
mod.ModManifest = manifest;
- mod.Helper = new ModHelper(manifest, directory.FullName, jsonHelper, this.ModRegistry, this.CommandManager, (SContentManager)Game1.content);
+ mod.Helper = new ModHelper(manifest, directory.FullName, jsonHelper, this.ModRegistry, this.CommandManager, (SContentManager)Game1.content, this.Reflection);
mod.Monitor = this.GetSecondaryMonitor(manifest.Name);
mod.PathOnDisk = directory.FullName;