From ed3bf29600d3e8e7cb88629bfe6da9db6339c6a8 Mon Sep 17 00:00:00 2001 From: ClxS Date: Fri, 4 Mar 2016 22:21:16 +0000 Subject: [PATCH] A few small clean ups and removed a lot of the readme until I think of what to put there --- README.md | 114 +-------------------- StardewModdingAPI/Inheritance/SGame.cs | 13 ++- StardewModdingAPI/StardewModdingAPI.csproj | 37 ++++++- 3 files changed, 41 insertions(+), 123 deletions(-) diff --git a/README.md b/README.md index 140c15fa..286bd089 100644 --- a/README.md +++ b/README.md @@ -2,116 +2,4 @@ A Modding API For Stardew Valley See: https://github.com/Zoryn4163/SMAPI-Mods -NOTICE: THIS PROJECT IS STILL IN ALPHA - -Mod directories: %appdata%\StardewValley\Mods\ and .\Mods\ <- That means next to StardewModdingApi.exe in the Mods folder! - -To install a mod, put a DLL in one of those directories. If you are not on the latest version, do not post any errors, issues, etc. - - - -NOTICE: THIS PART AND ONWARD REQUIRE VISUAL STUDIOS AND KNOWLEDGE OF C# PROGRAMMING - -You can create a mod by making a direct reference to the ModdingApi.exe - -From there, you need to inherit from StardewModdingAPI.Mod - -The first class that inherits from that class will be loaded into the game at runtime, and once the game fully initializes the mod, the method Entry() will be called once. - -It is recommended to subscribe to an event (from Events.cs) to be able to interface with the game rather than directly make changes from the Entry() method. - - - TestMod.cs: - - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - using Microsoft.Xna.Framework.Input; - using StardewModdingAPI; - - namespace StardewTestMod - { - public class TestMod : Mod - { - public override string Name - { - get { return "Test Mod"; } - } - - public override string Authour - { - get { return "Zoryn Aaron"; } - } - - public override string Version - { - get { return "0.0.1Test"; } - } - - public override string Description - { - get { return "A Test Mod"; } - } - - public override void Entry() - { - Console.WriteLine("Test Mod Has Loaded"); - Program.LogError("Test Mod can call to Program.cs in the API"); - Program.LogColour(ConsoleColor.Magenta, "Test Mod is just a tiny DLL file in AppData/Roaming/StardewValley/Mods"); - - //Subscribe to an event from the modding API - Events.KeyPressed += Events_KeyPressed; - } - - void Events_KeyPressed(Keys key) - { - Console.WriteLine("TestMod sees that the following key was pressed: " + key); - } - } - } - - -Break Fishing (WARNING: SOFTLOCKS YOUR GAME): - - public override void Entry() - { - Events.UpdateTick += Events_UpdateTick; - Events.Initialize += Events_Initialize; - } - - private FieldInfo cmg; - private bool gotGame; - private SBobberBar sb; - void Events_Initialize() - { - cmg = SGame.StaticFields.First(x => x.Name == "activeClickableMenu"); - } - - void Events_UpdateTick() - { - if (cmg != null && cmg.GetValue(null) != null) - { - if (cmg.GetValue(null).GetType() == typeof(BobberBar)) - { - if (!gotGame) - { - gotGame = true; - BobberBar b = (BobberBar)cmg.GetValue(null); - sb = SBobberBar.ConstructFromBaseClass(b); - } - else - { - sb.bobberPosition = Extensions.Random.Next(0, 750); - sb.treasure = true; - sb.distanceFromCatching = 0.5f; - } - } - else - { - gotGame = false; - sb = null; - } - } - } \ No newline at end of file +## NOTICE: THIS PROJECT IS STILL IN ALPHA diff --git a/StardewModdingAPI/Inheritance/SGame.cs b/StardewModdingAPI/Inheritance/SGame.cs index 36f905f7..69439209 100644 --- a/StardewModdingAPI/Inheritance/SGame.cs +++ b/StardewModdingAPI/Inheritance/SGame.cs @@ -66,8 +66,15 @@ namespace StardewModdingAPI.Inheritance public Farmer PreviousFarmer { get; private set; } + private static SGame instance; + public static SGame Instance { get { return instance; } } + + public Farmer CurrentFarmer { get { return player; } } + public SGame() { + instance = this; + if (Program.debug) { SaveGame.serializer = new XmlSerializer(typeof (SaveGame), new Type[28] @@ -195,11 +202,7 @@ namespace StardewModdingAPI.Inheritance 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; + return ModLocations.FirstOrDefault(n => n.name == name); } public static SGameLocation LoadOrCreateSGameLocationFromName(String name) diff --git a/StardewModdingAPI/StardewModdingAPI.csproj b/StardewModdingAPI/StardewModdingAPI.csproj index a223f6c2..d6a3d01c 100644 --- a/StardewModdingAPI/StardewModdingAPI.csproj +++ b/StardewModdingAPI/StardewModdingAPI.csproj @@ -19,9 +19,24 @@ + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true - AnyCPU + x86 true full false @@ -57,9 +72,9 @@ False - D:\Games\steamapps\common\Stardew Valley\Stardew Valley.exe + ..\..\..\..\Games\SteamLibrary\steamapps\common\Stardew Valley\Stardew Valley.exe False - False + True @@ -72,8 +87,8 @@ False - D:\Games\steamapps\common\Stardew Valley\xTile.dll - False + ..\..\..\..\Games\SteamLibrary\steamapps\common\Stardew Valley\xTile.dll + True @@ -108,6 +123,18 @@ + + + False + Microsoft .NET Framework 4.5 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + +