updates
This commit is contained in:
parent
868789770d
commit
cbf741d5ac
|
@ -3,7 +3,8 @@ A Modding API For Stardew Valley
|
|||
|
||||
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 method Entry() will be called once.
|
||||
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:
|
||||
|
||||
|
|
Binary file not shown.
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
|
||||
namespace StardewModdingAPI
|
||||
{
|
||||
|
@ -11,22 +12,51 @@ namespace StardewModdingAPI
|
|||
public delegate void BlankEventHandler();
|
||||
|
||||
public static event BlankEventHandler GameLoaded = delegate { };
|
||||
public static event BlankEventHandler UpdateInitialized = delegate { };
|
||||
public static event BlankEventHandler Initialize = delegate { };
|
||||
public static event BlankEventHandler LoadContent = delegate { };
|
||||
public static event BlankEventHandler UpdateTick = delegate { };
|
||||
public static event BlankEventHandler DrawTick = delegate { };
|
||||
|
||||
public delegate void StateChanged(KeyboardState newState);
|
||||
public static event StateChanged KeyboardChanged = delegate { };
|
||||
|
||||
public delegate void KeyStateChanged(Keys key);
|
||||
public static event KeyStateChanged KeyPressed = delegate { };
|
||||
|
||||
|
||||
public static void InvokeGameLoaded()
|
||||
{
|
||||
GameLoaded.Invoke();
|
||||
}
|
||||
|
||||
public static void InvokeUpdateInitialized()
|
||||
public static void InvokeInitialize()
|
||||
{
|
||||
UpdateInitialized.Invoke();
|
||||
Initialize.Invoke();
|
||||
}
|
||||
|
||||
public static void InvokeLoadContent()
|
||||
{
|
||||
LoadContent.Invoke();
|
||||
}
|
||||
|
||||
public static void InvokeUpdateTick()
|
||||
{
|
||||
UpdateTick.Invoke();
|
||||
}
|
||||
|
||||
public static void InvokeDrawTick()
|
||||
{
|
||||
DrawTick.Invoke();
|
||||
}
|
||||
|
||||
public static void InvokeKeyboardChanged(KeyboardState newState)
|
||||
{
|
||||
KeyboardChanged.Invoke(newState);
|
||||
}
|
||||
|
||||
public static void InvokeKeyPressed(Keys key)
|
||||
{
|
||||
KeyPressed.Invoke(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ using Microsoft.Xna.Framework.Graphics;
|
|||
using Microsoft.Xna.Framework.Input;
|
||||
using StardewValley;
|
||||
using StardewValley.Menus;
|
||||
using StardewValley.Minigames;
|
||||
using StardewValley.Network;
|
||||
using Keys = Microsoft.Xna.Framework.Input.Keys;
|
||||
|
||||
|
@ -23,7 +24,7 @@ namespace StardewModdingAPI
|
|||
public static string DataPath = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley"));
|
||||
public static string ModPath = Path.Combine(Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley")), "Mods");
|
||||
|
||||
public static Game1 gamePtr;
|
||||
public static SGame gamePtr;
|
||||
public static bool ready;
|
||||
|
||||
public static Assembly StardewAssembly;
|
||||
|
@ -32,7 +33,6 @@ namespace StardewModdingAPI
|
|||
public static Form StardewForm;
|
||||
|
||||
public static Thread gameThread;
|
||||
public static Thread updateThread;
|
||||
public static Thread consoleInputThread;
|
||||
|
||||
public static int frozenTime;
|
||||
|
@ -73,9 +73,7 @@ namespace StardewModdingAPI
|
|||
LogInfo("Initializing Console Input Thread...");
|
||||
consoleInputThread.Start();
|
||||
|
||||
updateThread = new Thread(UpdateThread);
|
||||
LogInfo("Starting Update Thread...");
|
||||
updateThread.Start();
|
||||
Events.KeyPressed += Events_KeyPressed;
|
||||
Events.UpdateTick += Events_UpdateTick;
|
||||
|
||||
LogInfo("Applying Final SDV Tweaks...");
|
||||
|
@ -98,15 +96,13 @@ namespace StardewModdingAPI
|
|||
{
|
||||
try
|
||||
{
|
||||
gamePtr = new Game1();
|
||||
gamePtr = new SGame();
|
||||
Game1.graphics.GraphicsProfile = GraphicsProfile.HiDef;
|
||||
LoadMods();
|
||||
|
||||
StardewForm = Control.FromHandle(Program.gamePtr.Window.Handle).FindForm();
|
||||
StardewGameInfo.SetValue(StardewProgramType, gamePtr);
|
||||
|
||||
KeyboardInput.KeyDown += KeyboardInput_KeyDown;
|
||||
|
||||
ready = true;
|
||||
|
||||
gamePtr.Run();
|
||||
|
@ -116,8 +112,6 @@ namespace StardewModdingAPI
|
|||
LogError("Game failed to start: " + ex);
|
||||
}
|
||||
ready = false;
|
||||
if (updateThread != null && updateThread.ThreadState == ThreadState.Running)
|
||||
updateThread.Abort();
|
||||
if (consoleInputThread != null && consoleInputThread.ThreadState == ThreadState.Running)
|
||||
consoleInputThread.Abort();
|
||||
Log("Game Execution Finished");
|
||||
|
@ -160,14 +154,9 @@ namespace StardewModdingAPI
|
|||
}
|
||||
}
|
||||
|
||||
public static void UpdateThread()
|
||||
static void Events_KeyPressed(Keys key)
|
||||
{
|
||||
Events.InvokeUpdateInitialized();
|
||||
while (ready)
|
||||
{
|
||||
Events.InvokeUpdateTick();
|
||||
Thread.Sleep(1000 / 60);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void Events_UpdateTick()
|
||||
|
@ -190,19 +179,6 @@ namespace StardewModdingAPI
|
|||
}
|
||||
}
|
||||
|
||||
static void KeyboardInput_KeyDown(object sender, StardewValley.KeyEventArgs e)
|
||||
{
|
||||
switch (e.KeyCode)
|
||||
{
|
||||
case Keys.B:
|
||||
Game1.player.hairstyleColor = Extensions.RandomColour();
|
||||
break;
|
||||
case Keys.OemPlus:
|
||||
Game1.player.Money += 5000;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void StardewInvoke(Action a)
|
||||
{
|
||||
StardewForm.Invoke(a);
|
||||
|
@ -231,8 +207,8 @@ namespace StardewModdingAPI
|
|||
|
||||
Command.RegisterCommand("player_setname", "Sets the player's name | player_setname <object> <value>", new[] { "(player, pet, farm)<object> (String)<value> The target name" }).CommandFired += player_setName;
|
||||
Command.RegisterCommand("player_setmoney", "Sets the player's money | player_setmoney <value>|inf", new[] { "(Int32)<value> The target money" }).CommandFired += player_setMoney;
|
||||
Command.RegisterCommand("player_setenergy", "Sets the player's energy | player_setenergy <value>|inf", new[] { "(Int32)<value> The target energy" }).CommandFired += player_setStamina;
|
||||
Command.RegisterCommand("player_setmaxenergy", "Sets the player's max energy | player_setmaxenergy <value>", new[] { "(Int32)<value> The target max energy" }).CommandFired += player_setMaxStamina;
|
||||
Command.RegisterCommand("player_setstamina", "Sets the player's stamina | player_setstamina <value>|inf", new[] { "(Int32)<value> The target stamina" }).CommandFired += player_setStamina;
|
||||
Command.RegisterCommand("player_setmaxstamina", "Sets the player's max stamina | player_setmaxstamina <value>", new[] { "(Int32)<value> The target max stamina" }).CommandFired += player_setMaxStamina;
|
||||
Command.RegisterCommand("player_sethealth", "Sets the player's health | player_sethealth <value>|inf", new[] { "(Int32)<value> The target health" }).CommandFired += player_setHealth;
|
||||
Command.RegisterCommand("player_setmaxhealth", "Sets the player's max health | player_setmaxhealth <value>", new[] { "(Int32)<value> The target max health" }).CommandFired += player_setMaxHealth;
|
||||
Command.RegisterCommand("player_setimmunity", "Sets the player's immunity | player_setimmunity <value>", new[] { "(Int32)<value> The target immunity" }).CommandFired += player_setImmunity;
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using StardewValley;
|
||||
|
||||
namespace StardewModdingAPI
|
||||
{
|
||||
public class SGame : Game1
|
||||
{
|
||||
public KeyboardState KStateNow { get; private set; }
|
||||
public KeyboardState KStatePrior { 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(); }
|
||||
}
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
Program.Log("XNA Initialize");
|
||||
Events.InvokeInitialize();
|
||||
base.Initialize();
|
||||
}
|
||||
|
||||
protected override void LoadContent()
|
||||
{
|
||||
Program.Log("XNA LoadContent");
|
||||
Events.InvokeLoadContent();
|
||||
base.LoadContent();
|
||||
}
|
||||
|
||||
protected override void Update(GameTime gameTime)
|
||||
{
|
||||
KStateNow = Keyboard.GetState();
|
||||
CurrentlyPressedKeys = KStateNow.GetPressedKeys();
|
||||
|
||||
foreach (Keys k in FramePressedKeys)
|
||||
Events.InvokeKeyPressed(k);
|
||||
|
||||
if (KStateNow != KStatePrior)
|
||||
{
|
||||
Events.InvokeKeyboardChanged(KStateNow);
|
||||
}
|
||||
|
||||
Events.InvokeUpdateTick();
|
||||
base.Update(gameTime);
|
||||
|
||||
KStatePrior = KStateNow;
|
||||
PreviouslyPressedKeys = CurrentlyPressedKeys;
|
||||
}
|
||||
|
||||
protected override void Draw(GameTime gameTime)
|
||||
{
|
||||
Events.InvokeDrawTick();
|
||||
base.Draw(gameTime);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -72,6 +72,7 @@
|
|||
<Compile Include="ModItem.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SGame.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
|
|
|
@ -32,3 +32,4 @@ C:\TFSource\Master-Collection\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\
|
|||
C:\TFSource\Master-Collection\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\Steamworks.NET.dll
|
||||
C:\TFSource\Master-Collection\StardewModdingAPI\StardewModdingAPI\obj\x86\Debug\StardewModdingAPI.exe
|
||||
C:\TFSource\Master-Collection\StardewModdingAPI\StardewModdingAPI\obj\x86\Debug\StardewModdingAPI.pdb
|
||||
C:\TFSource\Master-Collection\StardewModdingAPI\StardewModdingAPI\obj\x86\Debug\StardewModdingAPI.csprojResolveAssemblyReference.cache
|
||||
|
|
Loading…
Reference in New Issue