summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-05-09 00:11:39 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-05-09 00:11:39 -0400
commit486ac29796586e09540723dcae8070cf3e60285b (patch)
tree50b9c473ef8e89f17f631af4b183dcb6379acf74 /src
parent85f609dc6c2f02d89b9fccaacfe837f8822d6b7c (diff)
downloadSMAPI-486ac29796586e09540723dcae8070cf3e60285b.tar.gz
SMAPI-486ac29796586e09540723dcae8070cf3e60285b.tar.bz2
SMAPI-486ac29796586e09540723dcae8070cf3e60285b.zip
use shared reflection helper
Diffstat (limited to 'src')
-rw-r--r--src/StardewModdingAPI/Framework/ModHelper.cs7
-rw-r--r--src/StardewModdingAPI/Framework/SGame.cs10
-rw-r--r--src/StardewModdingAPI/Program.cs8
3 files changed, 17 insertions, 8 deletions
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; }
/// <summary>Simplifies access to private game code.</summary>
- public IReflectionHelper Reflection { get; } = new ReflectionHelper();
+ public IReflectionHelper Reflection { get; }
/// <summary>Metadata about loaded mods.</summary>
public IModRegistry ModRegistry { get; }
@@ -44,9 +43,10 @@ namespace StardewModdingAPI.Framework
/// <param name="modRegistry">Metadata about loaded mods.</param>
/// <param name="commandManager">Manages console commands.</param>
/// <param name="contentManager">The content manager which loads content assets.</param>
+ /// <param name="reflection">Simplifies access to private game code.</param>
/// <exception cref="ArgumentNullException">An argument is null or empty.</exception>
/// <exception cref="InvalidOperationException">The <paramref name="modDirectory"/> path does not exist on disk.</exception>
- 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
****/
+ /// <summary>Simplifies access to private game code.</summary>
+ private static IReflectionHelper Reflection;
+
// ReSharper disable ArrangeStaticMemberQualifier, ArrangeThisQualifier, InconsistentNaming
/// <summary>Used to access private fields and methods.</summary>
- private static readonly IReflectionHelper Reflection = new ReflectionHelper();
private static List<float> _fpsList => SGame.Reflection.GetPrivateField<List<float>>(typeof(Game1), nameof(_fpsList)).GetValue();
private static Stopwatch _fpsStopwatch => SGame.Reflection.GetPrivateField<Stopwatch>(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
*********/
/// <summary>Construct an instance.</summary>
/// <param name="monitor">Encapsulates monitoring and logging.</param>
- internal SGame(IMonitor monitor)
+ /// <param name="reflection">Simplifies access to private game code.</param>
+ 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
/// <summary>Tracks whether the game should exit immediately and any pending initialisation should be cancelled.</summary>
private readonly CancellationTokenSource CancellationTokenSource = new CancellationTokenSource();
+ /// <summary>Simplifies access to private game code.</summary>
+ private readonly IReflectionHelper Reflection = new ReflectionHelper();
+
/// <summary>The underlying game instance.</summary>
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;