summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--StardewModdingAPI/Events/EventArgs.cs9
-rw-r--r--StardewModdingAPI/Events/Player.cs6
-rw-r--r--StardewModdingAPI/Inheritance/SGame.cs570
-rw-r--r--TrainerMod/TrainerMod.csproj4
4 files changed, 305 insertions, 284 deletions
diff --git a/StardewModdingAPI/Events/EventArgs.cs b/StardewModdingAPI/Events/EventArgs.cs
index c9055f84..f856f477 100644
--- a/StardewModdingAPI/Events/EventArgs.cs
+++ b/StardewModdingAPI/Events/EventArgs.cs
@@ -92,6 +92,15 @@ namespace StardewModdingAPI.Events
public Farmer PriorFarmer { get; private set; }
}
+ public class EventArgsInventory : EventArgs
+ {
+ public EventArgsInventory(List<Item> inventory)
+ {
+ Inventory = inventory;
+ }
+ public List<Item> Inventory { get; private set; }
+ }
+
public class EventArgsIntChanged : EventArgs
{
public EventArgsIntChanged(Int32 priorInt, Int32 newInt)
diff --git a/StardewModdingAPI/Events/Player.cs b/StardewModdingAPI/Events/Player.cs
index 3fa5c806..169da863 100644
--- a/StardewModdingAPI/Events/Player.cs
+++ b/StardewModdingAPI/Events/Player.cs
@@ -10,10 +10,16 @@ namespace StardewModdingAPI.Events
public static class PlayerEvents
{
public static event EventHandler<EventArgsFarmerChanged> FarmerChanged = delegate { };
+ public static event EventHandler<EventArgsInventory> InventoryChanged = delegate { };
public static void InvokeFarmerChanged(Farmer priorFarmer, Farmer newFarmer)
{
FarmerChanged.Invoke(null, new EventArgsFarmerChanged(priorFarmer, newFarmer));
}
+
+ public static void InvokeInventoryChanged(List<Item> inventory)
+ {
+ FarmerChanged.Invoke(null, new InventoryChanged(inventory));
+ }
}
}
diff --git a/StardewModdingAPI/Inheritance/SGame.cs b/StardewModdingAPI/Inheritance/SGame.cs
index f9b2f60c..c19dadf2 100644
--- a/StardewModdingAPI/Inheritance/SGame.cs
+++ b/StardewModdingAPI/Inheritance/SGame.cs
@@ -1,297 +1,303 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using System.Xml.Serialization;
-using Microsoft.Xna.Framework;
-using Microsoft.Xna.Framework.Graphics;
-using Microsoft.Xna.Framework.Input;
-using StardewValley;
-using StardewValley.Characters;
-using StardewValley.Menus;
-using StardewValley.Monsters;
-using StardewValley.Quests;
-using StardewValley.TerrainFeatures;
-
-namespace StardewModdingAPI.Inheritance
-{
- public class SGame : Game1
- {
- public static List<SGameLocation> ModLocations = new List<SGameLocation>();
- public static SGameLocation CurrentLocation { get; internal set; }
- public static Dictionary<Int32, SObject> ModItems { get; private set; }
- public const Int32 LowestModItemID = 1000;
-
- public static FieldInfo[] StaticFields { get { return GetStaticFields(); } }
-
- public static FieldInfo[] GetStaticFields()
- {
- return typeof(Game1).GetFields();
- }
-
- public KeyboardState KStateNow { get; private set; }
- public KeyboardState KStatePrior { get; private set; }
-
- public MouseState MStateNow { get; private set; }
- public MouseState MStatePrior { get; private set; }
-
- public Keys[] CurrentlyPressedKeys { get; private set; }
- public Keys[] PreviouslyPressedKeys { get; private set; }
-
- public Keys[] FramePressedKeys
- {
- get { return CurrentlyPressedKeys.Where(x => !PreviouslyPressedKeys.Contains(x)).ToArray(); }
- }
-
- public int PreviousGameLocations { get; private set; }
- public int PreviousLocationObjects { get; private set; }
-
- public GameLocation PreviousGameLocation { get; private set; }
- public IClickableMenu PreviousActiveMenu { get; private set; }
-
- public Int32 PreviousTimeOfDay { get; private set; }
- public Int32 PreviousDayOfMonth { get; private set; }
- public String PreviousSeasonOfYear { get; private set; }
- public Int32 PreviousYearOfGame { get; private set; }
-
- public Farmer PreviousFarmer { get; private set; }
-
- public SGame()
- {
- if (Program.debug)
- {
- SaveGame.serializer = new XmlSerializer(typeof (SaveGame), new Type[28]
- {
- typeof (Tool),
- typeof (GameLocation),
- typeof (Crow),
- typeof (Duggy),
- typeof (Bug),
- typeof (BigSlime),
- typeof (Fireball),
- typeof (Ghost),
- typeof (Child),
- typeof (Pet),
- typeof (Dog),
- typeof (StardewValley.Characters.Cat),
- typeof (Horse),
- typeof (GreenSlime),
- typeof (LavaCrab),
- typeof (RockCrab),
- typeof (ShadowGuy),
- typeof (SkeletonMage),
- typeof (SquidKid),
- typeof (Grub),
- typeof (Fly),
- typeof (DustSpirit),
- typeof (Quest),
- typeof (MetalHead),
- typeof (ShadowGirl),
- typeof (Monster),
- typeof (TerrainFeature),
- typeof (SObject)
- });
- }
- }
-
- protected override void Initialize()
- {
- Program.Log("XNA Initialize");
- ModItems = new Dictionary<Int32, SObject>();
- PreviouslyPressedKeys = new Keys[0];
- base.Initialize();
- Events.GameEvents.InvokeInitialize();
- }
-
- protected override void LoadContent()
- {
- Program.Log("XNA LoadContent");
- base.LoadContent();
- Events.GameEvents.InvokeLoadContent();
- }
-
- protected override void Update(GameTime gameTime)
- {
- UpdateEventCalls();
-
- try
- {
- base.Update(gameTime);
- }
- catch (Exception ex)
- {
- Program.LogError("An error occured in the base update loop: " + ex);
- Console.ReadKey();
- }
-
- Events.GameEvents.InvokeUpdateTick();
-
- PreviouslyPressedKeys = CurrentlyPressedKeys;
- }
-
- protected override void Draw(GameTime gameTime)
- {
- base.Draw(gameTime);
- Events.GraphicsEvents.InvokeDrawTick();
-
- if (false)
- {
- spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
-
- if (CurrentLocation != null)
- CurrentLocation.draw(spriteBatch);
-
- if (player != null && player.position != null)
- spriteBatch.DrawString(dialogueFont, player.position.ToString(), new Vector2(0, 180), Color.Orange);
-
- spriteBatch.End();
- }
- }
-
- public static Int32 RegisterModItem(SObject modItem)
- {
- if (modItem.HasBeenRegistered)
- {
- Program.LogError("The item {0} has already been registered with ID {1}", modItem.Name, modItem.RegisteredId);
- return modItem.RegisteredId;
- }
- Int32 newId = LowestModItemID;
- if (ModItems.Count > 0)
- newId = Math.Max(LowestModItemID, ModItems.OrderBy(x => x.Key).First().Key + 1);
- ModItems.Add(newId, modItem);
- modItem.HasBeenRegistered = true;
- modItem.RegisteredId = newId;
- return newId;
- }
-
- public static SObject PullModItemFromDict(Int32 id, bool isIndex)
- {
- if (isIndex)
- {
- if (ModItems.ElementAtOrDefault(id).Value != null)
- {
- return ModItems.ElementAt(id).Value.Clone();
- }
- Program.LogError("ModItem Dictionary does not contain index: " + id.ToString());
- return null;
- }
- if (ModItems.ContainsKey(id))
- {
- return ModItems[id].Clone();
- }
- Program.LogError("ModItem Dictionary does not contain ID: " + id.ToString());
- return null;
- }
-
- public static SGameLocation GetLocationFromName(String name)
- {
- if (ModLocations.Any(x => x.name == name))
- {
- return ModLocations[ModLocations.IndexOf(ModLocations.First(x => x.name == name))];
- }
- return null;
- }
-
- public static SGameLocation LoadOrCreateSGameLocationFromName(String name)
- {
- if (GetLocationFromName(name) != null)
- return GetLocationFromName(name);
- GameLocation gl = locations.FirstOrDefault(x => x.name == name);
- if (gl != null)
- {
- Program.LogDebug("A custom location was created for the new name: " + name);
- SGameLocation s = SGameLocation.ConstructFromBaseClass(gl);
- ModLocations.Add(s);
- return s;
- }
- if (currentLocation != null && currentLocation.name == name)
- {
- gl = currentLocation;
- Program.LogDebug("A custom location was created from the current location for the new name: " + name);
- SGameLocation s = SGameLocation.ConstructFromBaseClass(gl);
- ModLocations.Add(s);
- return s;
- }
-
- Program.LogDebug("A custom location could not be created for: " + name);
- return null;
- }
-
-
- public void UpdateEventCalls()
- {
- KStateNow = Keyboard.GetState();
- CurrentlyPressedKeys = KStateNow.GetPressedKeys();
- MStateNow = Mouse.GetState();
-
- foreach (Keys k in FramePressedKeys)
- Events.ControlEvents.InvokeKeyPressed(k);
-
- if (KStateNow != KStatePrior)
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Xml.Serialization;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+using Microsoft.Xna.Framework.Input;
+using StardewValley;
+using StardewValley.Characters;
+using StardewValley.Menus;
+using StardewValley.Monsters;
+using StardewValley.Quests;
+using StardewValley.TerrainFeatures;
+
+namespace StardewModdingAPI.Inheritance
+{
+ public class SGame : Game1
+ {
+ public static List<SGameLocation> ModLocations = new List<SGameLocation>();
+ public static SGameLocation CurrentLocation { get; internal set; }
+ public static Dictionary<Int32, SObject> ModItems { get; private set; }
+ public const Int32 LowestModItemID = 1000;
+
+ public static FieldInfo[] StaticFields { get { return GetStaticFields(); } }
+
+ public static FieldInfo[] GetStaticFields()
+ {
+ return typeof(Game1).GetFields();
+ }
+
+ public KeyboardState KStateNow { get; private set; }
+ public KeyboardState KStatePrior { get; private set; }
+
+ public MouseState MStateNow { get; private set; }
+ public MouseState MStatePrior { get; private set; }
+
+ public Keys[] CurrentlyPressedKeys { get; private set; }
+ public Keys[] PreviouslyPressedKeys { get; private set; }
+
+ public Keys[] FramePressedKeys
+ {
+ get { return CurrentlyPressedKeys.Where(x => !PreviouslyPressedKeys.Contains(x)).ToArray(); }
+ }
+
+ public int PreviousGameLocations { get; private set; }
+ public int PreviousLocationObjects { get; private set; }
+ public int PreviousItems { get; private set; }
+
+ public GameLocation PreviousGameLocation { get; private set; }
+ public IClickableMenu PreviousActiveMenu { get; private set; }
+
+ public Int32 PreviousTimeOfDay { get; private set; }
+ public Int32 PreviousDayOfMonth { get; private set; }
+ public String PreviousSeasonOfYear { get; private set; }
+ public Int32 PreviousYearOfGame { get; private set; }
+
+ public Farmer PreviousFarmer { get; private set; }
+
+ public SGame()
+ {
+ if (Program.debug)
{
- Events.ControlEvents.InvokeKeyboardChanged(KStatePrior, KStateNow);
- KStatePrior = KStateNow;
- }
-
- if (MStateNow != MStatePrior)
+ SaveGame.serializer = new XmlSerializer(typeof (SaveGame), new Type[28]
+ {
+ typeof (Tool),
+ typeof (GameLocation),
+ typeof (Crow),
+ typeof (Duggy),
+ typeof (Bug),
+ typeof (BigSlime),
+ typeof (Fireball),
+ typeof (Ghost),
+ typeof (Child),
+ typeof (Pet),
+ typeof (Dog),
+ typeof (StardewValley.Characters.Cat),
+ typeof (Horse),
+ typeof (GreenSlime),
+ typeof (LavaCrab),
+ typeof (RockCrab),
+ typeof (ShadowGuy),
+ typeof (SkeletonMage),
+ typeof (SquidKid),
+ typeof (Grub),
+ typeof (Fly),
+ typeof (DustSpirit),
+ typeof (Quest),
+ typeof (MetalHead),
+ typeof (ShadowGirl),
+ typeof (Monster),
+ typeof (TerrainFeature),
+ typeof (SObject)
+ });
+ }
+ }
+
+ protected override void Initialize()
+ {
+ Program.Log("XNA Initialize");
+ ModItems = new Dictionary<Int32, SObject>();
+ PreviouslyPressedKeys = new Keys[0];
+ base.Initialize();
+ Events.GameEvents.InvokeInitialize();
+ }
+
+ protected override void LoadContent()
+ {
+ Program.Log("XNA LoadContent");
+ base.LoadContent();
+ Events.GameEvents.InvokeLoadContent();
+ }
+
+ protected override void Update(GameTime gameTime)
+ {
+ UpdateEventCalls();
+
+ try
{
- Events.ControlEvents.InvokeMouseChanged(MStatePrior, MStateNow);
- MStatePrior = MStateNow;
- }
-
- if (activeClickableMenu != null && activeClickableMenu != PreviousActiveMenu)
+ base.Update(gameTime);
+ }
+ catch (Exception ex)
{
- Events.MenuEvents.InvokeMenuChanged(PreviousActiveMenu, activeClickableMenu);
- PreviousActiveMenu = activeClickableMenu;
- }
-
- if (locations.GetHash() != PreviousGameLocations)
+ Program.LogError("An error occured in the base update loop: " + ex);
+ Console.ReadKey();
+ }
+
+ Events.GameEvents.InvokeUpdateTick();
+
+ PreviouslyPressedKeys = CurrentlyPressedKeys;
+ }
+
+ protected override void Draw(GameTime gameTime)
+ {
+ base.Draw(gameTime);
+ Events.GraphicsEvents.InvokeDrawTick();
+
+ if (false)
{
- Events.LocationEvents.InvokeLocationsChanged(locations);
- PreviousGameLocations = locations.GetHash();
- }
-
- if (currentLocation != PreviousGameLocation)
+ spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
+
+ if (CurrentLocation != null)
+ CurrentLocation.draw(spriteBatch);
+
+ if (player != null && player.position != null)
+ spriteBatch.DrawString(dialogueFont, player.position.ToString(), new Vector2(0, 180), Color.Orange);
+
+ spriteBatch.End();
+ }
+ }
+
+ public static Int32 RegisterModItem(SObject modItem)
+ {
+ if (modItem.HasBeenRegistered)
{
- Events.LocationEvents.InvokeCurrentLocationChanged(PreviousGameLocation, currentLocation);
- PreviousGameLocation = currentLocation;
- }
-
- if (player != null && player != PreviousFarmer)
+ Program.LogError("The item {0} has already been registered with ID {1}", modItem.Name, modItem.RegisteredId);
+ return modItem.RegisteredId;
+ }
+ Int32 newId = LowestModItemID;
+ if (ModItems.Count > 0)
+ newId = Math.Max(LowestModItemID, ModItems.OrderBy(x => x.Key).First().Key + 1);
+ ModItems.Add(newId, modItem);
+ modItem.HasBeenRegistered = true;
+ modItem.RegisteredId = newId;
+ return newId;
+ }
+
+ public static SObject PullModItemFromDict(Int32 id, bool isIndex)
+ {
+ if (isIndex)
{
- Events.PlayerEvents.InvokeFarmerChanged(PreviousFarmer, player);
- PreviousFarmer = player;
- }
-
+ if (ModItems.ElementAtOrDefault(id).Value != null)
+ {
+ return ModItems.ElementAt(id).Value.Clone();
+ }
+ Program.LogError("ModItem Dictionary does not contain index: " + id.ToString());
+ return null;
+ }
+ if (ModItems.ContainsKey(id))
+ {
+ return ModItems[id].Clone();
+ }
+ Program.LogError("ModItem Dictionary does not contain ID: " + id.ToString());
+ return null;
+ }
+
+ public static SGameLocation GetLocationFromName(String name)
+ {
+ if (ModLocations.Any(x => x.name == name))
+ {
+ return ModLocations[ModLocations.IndexOf(ModLocations.First(x => x.name == name))];
+ }
+ return null;
+ }
+
+ public static SGameLocation LoadOrCreateSGameLocationFromName(String name)
+ {
+ if (GetLocationFromName(name) != null)
+ return GetLocationFromName(name);
+ GameLocation gl = locations.FirstOrDefault(x => x.name == name);
+ if (gl != null)
+ {
+ Program.LogDebug("A custom location was created for the new name: " + name);
+ SGameLocation s = SGameLocation.ConstructFromBaseClass(gl);
+ ModLocations.Add(s);
+ return s;
+ }
+ if (currentLocation != null && currentLocation.name == name)
+ {
+ gl = currentLocation;
+ Program.LogDebug("A custom location was created from the current location for the new name: " + name);
+ SGameLocation s = SGameLocation.ConstructFromBaseClass(gl);
+ ModLocations.Add(s);
+ return s;
+ }
+
+ Program.LogDebug("A custom location could not be created for: " + name);
+ return null;
+ }
+
+
+ public void UpdateEventCalls()
+ {
+ KStateNow = Keyboard.GetState();
+ CurrentlyPressedKeys = KStateNow.GetPressedKeys();
+ MStateNow = Mouse.GetState();
+
+ foreach (Keys k in FramePressedKeys)
+ Events.ControlEvents.InvokeKeyPressed(k);
+
+ if (KStateNow != KStatePrior)
+ {
+ Events.ControlEvents.InvokeKeyboardChanged(KStatePrior, KStateNow);
+ KStatePrior = KStateNow;
+ }
+
+ if (MStateNow != MStatePrior)
+ {
+ Events.ControlEvents.InvokeMouseChanged(MStatePrior, MStateNow);
+ MStatePrior = MStateNow;
+ }
+
+ if (activeClickableMenu != null && activeClickableMenu != PreviousActiveMenu)
+ {
+ Events.MenuEvents.InvokeMenuChanged(PreviousActiveMenu, activeClickableMenu);
+ PreviousActiveMenu = activeClickableMenu;
+ }
+
+ if (locations.GetHash() != PreviousGameLocations)
+ {
+ Events.LocationEvents.InvokeLocationsChanged(locations);
+ PreviousGameLocations = locations.GetHash();
+ }
+
+ if (currentLocation != PreviousGameLocation)
+ {
+ Events.LocationEvents.InvokeCurrentLocationChanged(PreviousGameLocation, currentLocation);
+ PreviousGameLocation = currentLocation;
+ }
+
+ if (player != null && player != PreviousFarmer)
+ {
+ Events.PlayerEvents.InvokeFarmerChanged(PreviousFarmer, player);
+ PreviousFarmer = player;
+ }
+
+ if(player != null && PreviousItems != player.items.GetHash())
+ {
+ Events.PlayerEvents.InvokeInventoryChanged(player.items);
+ }
+
if(currentLocation != null && PreviousLocationObjects != currentLocation.objects.GetHash())
{
Events.LocationEvents.InvokeOnNewLocationObject(currentLocation.objects);
PreviousLocationObjects = currentLocation.objects.GetHash();
- }
-
- if (timeOfDay != PreviousTimeOfDay)
+ }
+
+ if (timeOfDay != PreviousTimeOfDay)
{
- Events.TimeEvents.InvokeTimeOfDayChanged(PreviousTimeOfDay, timeOfDay);
- PreviousTimeOfDay = timeOfDay;
- }
-
- if (dayOfMonth != PreviousDayOfMonth)
+ Events.TimeEvents.InvokeTimeOfDayChanged(PreviousTimeOfDay, timeOfDay);
+ PreviousTimeOfDay = timeOfDay;
+ }
+
+ if (dayOfMonth != PreviousDayOfMonth)
{
- Events.TimeEvents.InvokeDayOfMonthChanged(PreviousDayOfMonth, dayOfMonth);
- PreviousDayOfMonth = dayOfMonth;
- }
-
- if (currentSeason != PreviousSeasonOfYear)
+ Events.TimeEvents.InvokeDayOfMonthChanged(PreviousDayOfMonth, dayOfMonth);
+ PreviousDayOfMonth = dayOfMonth;
+ }
+
+ if (currentSeason != PreviousSeasonOfYear)
{
- Events.TimeEvents.InvokeSeasonOfYearChanged(PreviousSeasonOfYear, currentSeason);
- PreviousSeasonOfYear = currentSeason;
- }
-
- if (year != PreviousYearOfGame)
+ Events.TimeEvents.InvokeSeasonOfYearChanged(PreviousSeasonOfYear, currentSeason);
+ PreviousSeasonOfYear = currentSeason;
+ }
+
+ if (year != PreviousYearOfGame)
{
- Events.TimeEvents.InvokeYearOfGameChanged(PreviousYearOfGame, year);
- PreviousYearOfGame = year;
- }
- }
- }
+ Events.TimeEvents.InvokeYearOfGameChanged(PreviousYearOfGame, year);
+ PreviousYearOfGame = year;
+ }
+ }
+ }
} \ No newline at end of file
diff --git a/TrainerMod/TrainerMod.csproj b/TrainerMod/TrainerMod.csproj
index 213b3210..61cb0829 100644
--- a/TrainerMod/TrainerMod.csproj
+++ b/TrainerMod/TrainerMod.csproj
@@ -38,7 +38,7 @@
<Private>False</Private>
</Reference>
<Reference Include="Stardew Valley">
- <HintPath>D:\Games\steamapps\common\Stardew Valley\Stardew Valley.exe</HintPath>
+ <HintPath>..\..\..\..\Games\SteamLibrary\steamapps\common\Stardew Valley\Stardew Valley.exe</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
@@ -49,7 +49,7 @@
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="xTile">
- <HintPath>D:\Games\steamapps\common\Stardew Valley\xTile.dll</HintPath>
+ <HintPath>..\..\..\..\Games\SteamLibrary\steamapps\common\Stardew Valley\xTile.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>