summaryrefslogtreecommitdiff
path: root/StardewModdingAPI/Inheritance
diff options
context:
space:
mode:
Diffstat (limited to 'StardewModdingAPI/Inheritance')
-rw-r--r--StardewModdingAPI/Inheritance/SGame.cs360
1 files changed, 348 insertions, 12 deletions
diff --git a/StardewModdingAPI/Inheritance/SGame.cs b/StardewModdingAPI/Inheritance/SGame.cs
index f5e11114..5b05f2e2 100644
--- a/StardewModdingAPI/Inheritance/SGame.cs
+++ b/StardewModdingAPI/Inheritance/SGame.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using Microsoft.Xna.Framework;
@@ -199,6 +198,15 @@ namespace StardewModdingAPI.Inheritance
}
/// <summary>
+ ///
+ /// </summary>
+ public int ThumbstickMotionMargin
+ {
+ get { return (int)typeof(Game1).GetBaseFieldValue<object>(Program.gamePtr, "thumbstickMotionMargin"); }
+ set { typeof(Game1).SetBaseFieldValue<object>(this, "thumbstickMotionMargin", value); }
+ }
+
+ /// <summary>
/// The current Colour in Game1 (Private field, uses reflection)
/// </summary>
public Color BgColour
@@ -414,21 +422,331 @@ namespace StardewModdingAPI.Inheritance
/// <param name="gameTime"></param>
protected override void Update(GameTime gameTime)
{
+ QueueDebugMessage("FPS: " + FramesPerSecond);
UpdateEventCalls();
+ if (ZoomLevelIsOne)
+ options.zoomLevel = 0.99f;
+
if (FramePressedKeys.Contains(Keys.F3))
{
Debug = !Debug;
}
- try
+ if (FramePressedKeys.Contains(Keys.F2))
{
- base.Update(gameTime);
+ //Built-in debug mode
+ debugMode = !debugMode;
}
- catch (Exception ex)
+
+ if (Constants.EnableCompletelyOverridingBaseCalls)
{
- Log.AsyncR("An error occured in the base update loop: " + ex);
- Console.ReadKey();
+ #region Overridden Update Call
+
+ if (Program.BuildType == 0)
+ SteamHelper.update();
+ if ((paused /*|| !this.IsActive*/) && (options == null || options.pauseWhenOutOfFocus || paused))
+ return;
+ if (quit)
+ Exit();
+ currentGameTime = gameTime;
+ if (gameMode != 11)
+ {
+ if (IsMultiplayer && gameMode == 3)
+ {
+ if (multiplayerMode == 2)
+ server.receiveMessages();
+ else
+ client.receiveMessages();
+ }
+ if (IsActive)
+ InvokeBasePrivateInstancedMethod("checkForEscapeKeys");
+ //this.checkForEscapeKeys();
+ updateMusic();
+ updateRaindropPosition();
+ if (bloom != null)
+ bloom.tick(gameTime);
+ if (globalFade)
+ {
+ if (!dialogueUp)
+ {
+ if (fadeIn)
+ {
+ fadeToBlackAlpha = Math.Max(0.0f, fadeToBlackAlpha - globalFadeSpeed);
+ if (fadeToBlackAlpha <= 0.0)
+ {
+ globalFade = false;
+ if (afterFade != null)
+ {
+ afterFadeFunction afterFadeFunction = afterFade;
+ afterFade();
+ if (afterFade != null && afterFade.Equals(afterFadeFunction))
+ afterFade = null;
+ if (nonWarpFade)
+ fadeToBlack = false;
+ }
+ }
+ }
+ else
+ {
+ fadeToBlackAlpha = Math.Min(1f, fadeToBlackAlpha + globalFadeSpeed);
+ if (fadeToBlackAlpha >= 1.0)
+ {
+ globalFade = false;
+ if (afterFade != null)
+ {
+ afterFadeFunction afterFadeFunction = afterFade;
+ afterFade();
+ if (afterFade != null && afterFade.Equals(afterFadeFunction))
+ afterFade = null;
+ if (nonWarpFade)
+ fadeToBlack = false;
+ }
+ }
+ }
+ }
+ else
+ InvokeBasePrivateInstancedMethod("UpdateControlInput", gameTime);
+ //this.UpdateControlInput(gameTime);
+ }
+ else if (pauseThenDoFunctionTimer > 0)
+ {
+ freezeControls = true;
+ pauseThenDoFunctionTimer -= gameTime.ElapsedGameTime.Milliseconds;
+ if (pauseThenDoFunctionTimer <= 0)
+ {
+ freezeControls = false;
+ if (afterPause != null)
+ afterPause();
+ }
+ }
+ if (gameMode == 3 || gameMode == 2)
+ {
+ player.millisecondsPlayed += (uint)gameTime.ElapsedGameTime.Milliseconds;
+ bool flag = true;
+ if (currentMinigame != null)
+ {
+ if (pauseTime > 0.0)
+ updatePause(gameTime);
+ if (fadeToBlack)
+ {
+ updateScreenFade(gameTime);
+ if (fadeToBlackAlpha >= 1.0)
+ fadeToBlack = false;
+ }
+ else
+ {
+ if (ThumbstickMotionMargin > 0)
+ ThumbstickMotionMargin -= gameTime.ElapsedGameTime.Milliseconds;
+ if (IsActive)
+ {
+ KeyboardState state1 = Keyboard.GetState();
+ MouseState state2 = Mouse.GetState();
+ GamePadState state3 = GamePad.GetState(PlayerIndex.One);
+ foreach (Keys keys in state1.GetPressedKeys())
+ {
+ if (!oldKBState.IsKeyDown(keys))
+ currentMinigame.receiveKeyPress(keys);
+ }
+ if (options.gamepadControls)
+ {
+ if (currentMinigame == null)
+ {
+ oldMouseState = state2;
+ oldKBState = state1;
+ oldPadState = state3;
+ return;
+ }
+ foreach (Buttons b in Utility.getPressedButtons(state3, oldPadState))
+ currentMinigame.receiveKeyPress(Utility.mapGamePadButtonToKey(b));
+ if (currentMinigame == null)
+ {
+ oldMouseState = state2;
+ oldKBState = state1;
+ oldPadState = state3;
+ return;
+ }
+ if (state3.ThumbSticks.Right.Y < -0.200000002980232 && oldPadState.ThumbSticks.Right.Y >= -0.200000002980232)
+ currentMinigame.receiveKeyPress(Keys.Down);
+ if (state3.ThumbSticks.Right.Y > 0.200000002980232 && oldPadState.ThumbSticks.Right.Y <= 0.200000002980232)
+ currentMinigame.receiveKeyPress(Keys.Up);
+ if (state3.ThumbSticks.Right.X < -0.200000002980232 && oldPadState.ThumbSticks.Right.X >= -0.200000002980232)
+ currentMinigame.receiveKeyPress(Keys.Left);
+ if (state3.ThumbSticks.Right.X > 0.200000002980232 && oldPadState.ThumbSticks.Right.X <= 0.200000002980232)
+ currentMinigame.receiveKeyPress(Keys.Right);
+ if (oldPadState.ThumbSticks.Right.Y < -0.200000002980232 && state3.ThumbSticks.Right.Y >= -0.200000002980232)
+ currentMinigame.receiveKeyRelease(Keys.Down);
+ if (oldPadState.ThumbSticks.Right.Y > 0.200000002980232 && state3.ThumbSticks.Right.Y <= 0.200000002980232)
+ currentMinigame.receiveKeyRelease(Keys.Up);
+ if (oldPadState.ThumbSticks.Right.X < -0.200000002980232 && state3.ThumbSticks.Right.X >= -0.200000002980232)
+ currentMinigame.receiveKeyRelease(Keys.Left);
+ if (oldPadState.ThumbSticks.Right.X > 0.200000002980232 && state3.ThumbSticks.Right.X <= 0.200000002980232)
+ currentMinigame.receiveKeyRelease(Keys.Right);
+ if (isGamePadThumbstickInMotion())
+ {
+ setMousePosition(getMouseX() + (int)(state3.ThumbSticks.Left.X * 16.0), getMouseY() - (int)(state3.ThumbSticks.Left.Y * 16.0));
+ lastCursorMotionWasMouse = false;
+ }
+ else if (getMousePosition().X != getOldMouseX() || getMousePosition().Y != getOldMouseY())
+ lastCursorMotionWasMouse = true;
+ }
+ foreach (Keys keys in oldKBState.GetPressedKeys())
+ {
+ if (!state1.IsKeyDown(keys))
+ currentMinigame.receiveKeyRelease(keys);
+ }
+ if (options.gamepadControls)
+ {
+ if (currentMinigame == null)
+ {
+ oldMouseState = state2;
+ oldKBState = state1;
+ oldPadState = state3;
+ return;
+ }
+ if (state3.IsConnected && state3.IsButtonDown(Buttons.X) && !oldPadState.IsButtonDown(Buttons.X))
+ currentMinigame.receiveRightClick(getMouseX(), getMouseY(), true);
+ else if (state3.IsConnected && state3.IsButtonDown(Buttons.A) && !oldPadState.IsButtonDown(Buttons.A))
+ currentMinigame.receiveLeftClick(getMouseX(), getMouseY(), true);
+ else if (state3.IsConnected && !state3.IsButtonDown(Buttons.X) && oldPadState.IsButtonDown(Buttons.X))
+ currentMinigame.releaseRightClick(getMouseX(), getMouseY());
+ else if (state3.IsConnected && !state3.IsButtonDown(Buttons.A) && oldPadState.IsButtonDown(Buttons.A))
+ currentMinigame.releaseLeftClick(getMouseX(), getMouseY());
+ foreach (Buttons b in Utility.getPressedButtons(oldPadState, state3))
+ currentMinigame.receiveKeyRelease(Utility.mapGamePadButtonToKey(b));
+ if (state3.IsConnected && state3.IsButtonDown(Buttons.A) && currentMinigame != null)
+ currentMinigame.leftClickHeld(0, 0);
+ }
+ if (currentMinigame == null)
+ {
+ oldMouseState = state2;
+ oldKBState = state1;
+ oldPadState = state3;
+ return;
+ }
+ if (state2.LeftButton == ButtonState.Pressed && oldMouseState.LeftButton != ButtonState.Pressed)
+ currentMinigame.receiveLeftClick(getMouseX(), getMouseY(), true);
+ if (state2.RightButton == ButtonState.Pressed && oldMouseState.RightButton != ButtonState.Pressed)
+ currentMinigame.receiveRightClick(getMouseX(), getMouseY(), true);
+ if (state2.LeftButton == ButtonState.Released && oldMouseState.LeftButton == ButtonState.Pressed)
+ currentMinigame.releaseLeftClick(getMouseX(), getMouseY());
+ if (state2.RightButton == ButtonState.Released && oldMouseState.RightButton == ButtonState.Pressed)
+ currentMinigame.releaseLeftClick(getMouseX(), getMouseY());
+ if (state2.LeftButton == ButtonState.Pressed && oldMouseState.LeftButton == ButtonState.Pressed)
+ currentMinigame.leftClickHeld(getMouseX(), getMouseY());
+ oldMouseState = state2;
+ oldKBState = state1;
+ oldPadState = state3;
+ }
+ if (currentMinigame != null && currentMinigame.tick(gameTime))
+ {
+ currentMinigame.unload();
+ currentMinigame = null;
+ fadeIn = true;
+ fadeToBlackAlpha = 1f;
+ return;
+ }
+ }
+ flag = IsMultiplayer;
+ }
+ else if (farmEvent != null && farmEvent.tickUpdate(gameTime))
+ {
+ farmEvent.makeChangesToLocation();
+ timeOfDay = 600;
+ UpdateOther(gameTime);
+ displayHUD = true;
+ farmEvent = null;
+ currentLocation = getLocationFromName("FarmHouse");
+ player.position = Utility.PointToVector2(Utility.getHomeOfFarmer(player).getBedSpot()) * tileSize;
+ player.position.X -= tileSize;
+ changeMusicTrack("none");
+ currentLocation.resetForPlayerEntry();
+ player.forceCanMove();
+ freezeControls = false;
+ displayFarmer = true;
+ outdoorLight = Color.White;
+ viewportFreeze = false;
+ fadeToBlackAlpha = 0.0f;
+ fadeToBlack = false;
+ globalFadeToClear(null, 0.02f);
+ player.mailForTomorrow.Clear();
+ showEndOfNightStuff();
+ }
+ if (flag)
+ {
+ if (endOfNightMenus.Count() > 0 && activeClickableMenu == null)
+ activeClickableMenu = endOfNightMenus.Pop();
+ if (activeClickableMenu != null)
+ {
+ updateActiveMenu(gameTime);
+ }
+ else
+ {
+ if (pauseTime > 0.0)
+ updatePause(gameTime);
+ if (!globalFade && !freezeControls && (activeClickableMenu == null && IsActive))
+ InvokeBasePrivateInstancedMethod("UpdateControlInput", gameTime);
+ //this.UpdateControlInput(gameTime);
+ }
+ if (showingEndOfNightStuff && endOfNightMenus.Count() == 0 && activeClickableMenu == null)
+ {
+ showingEndOfNightStuff = false;
+ globalFadeToClear(playMorningSong, 0.02f);
+ }
+ if (!showingEndOfNightStuff)
+ {
+ if (IsMultiplayer || activeClickableMenu == null && currentMinigame == null)
+ UpdateGameClock(gameTime);
+ //this.UpdateCharacters(gameTime);
+ //this.UpdateLocations(gameTime);
+ InvokeBasePrivateInstancedMethod("UpdateCharacters", gameTime);
+ InvokeBasePrivateInstancedMethod("UpdateLocations", gameTime);
+ UpdateViewPort(false, (Point)InvokeBasePrivateInstancedMethod("getViewportCenter"));
+ }
+ UpdateOther(gameTime);
+ if (messagePause)
+ {
+ KeyboardState state1 = Keyboard.GetState();
+ MouseState state2 = Mouse.GetState();
+ GamePadState state3 = GamePad.GetState(PlayerIndex.One);
+ if (isOneOfTheseKeysDown(state1, options.actionButton) && !isOneOfTheseKeysDown(oldKBState, options.actionButton))
+ pressActionButton(state1, state2, state3);
+ oldKBState = state1;
+ oldPadState = state3;
+ }
+ }
+ }
+ else
+ {
+ InvokeBasePrivateInstancedMethod("UpdateTitleScreen", gameTime);
+ //this.UpdateTitleScreen(gameTime);
+ if (activeClickableMenu != null)
+ updateActiveMenu(gameTime);
+ if (gameMode == 10)
+ UpdateOther(gameTime);
+ }
+ if (audioEngine != null)
+ audioEngine.Update();
+ if (multiplayerMode == 2 && gameMode == 3)
+ server.sendMessages(gameTime);
+ }
+
+ //typeof (Game).GetMethod("Update", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(this, new object[] {gameTime});
+ //base.Update(gameTime);
+
+ #endregion
+ }
+ else
+ {
+ try
+ {
+ base.Update(gameTime);
+ }
+ catch (Exception ex)
+ {
+ Log.AsyncR("An error occured in the base update loop: " + ex);
+ Console.ReadKey();
+ }
}
GameEvents.InvokeUpdateTick();
@@ -477,11 +795,10 @@ namespace StardewModdingAPI.Inheritance
{
FramesPerSecond = 1 / (float) gameTime.ElapsedGameTime.TotalSeconds;
- if (Constants.EnableCompletelyOverridingBaseDrawCall)
+ if (Constants.EnableCompletelyOverridingBaseCalls)
{
#region Overridden Draw
- // StardewValley.Game1
if (!ZoomLevelIsOne)
{
GraphicsDevice.SetRenderTarget(Screen);
@@ -901,7 +1218,7 @@ namespace StardewModdingAPI.Inheritance
{
spriteBatch.DrawString(smallFont, string.Concat(new object[]
{
- panMode ? ((getOldMouseX() + viewport.X) / tileSize + "," + (getOldMouseY() + viewport.Y) / tileSize) : string.Concat("player: ", player.getStandingX() / tileSize, ", ", player.getStandingY() / tileSize),
+ panMode ? ((getOldMouseX() + viewport.X) / tileSize + "," + (getOldMouseY() + viewport.Y) / tileSize) : string.Concat("aplayer: ", player.getStandingX() / tileSize, ", ", player.getStandingY() / tileSize),
Environment.NewLine,
"debugOutput: ",
debugOutput
@@ -1000,16 +1317,16 @@ namespace StardewModdingAPI.Inheritance
if (Debug)
{
spriteBatch.Begin();
- spriteBatch.DrawString(smoothFont, "FPS: " + FramesPerSecond, Vector2.Zero, Color.CornflowerBlue);
- int i = 1;
+ int i = 0;
while (DebugMessageQueue.Any())
{
string s = DebugMessageQueue.Dequeue();
- spriteBatch.DrawString(smoothFont, s, new Vector2(0, i * 12), Color.CornflowerBlue);
+ spriteBatch.DrawString(smoothFont, s, new Vector2(0, i * 14), Color.CornflowerBlue);
i++;
}
GraphicsEvents.InvokeDrawDebug(null, EventArgs.Empty);
+
spriteBatch.End();
}
else
@@ -1265,6 +1582,25 @@ namespace StardewModdingAPI.Inheritance
}
/// <summary>
+ /// Invokes a private, non-static method in Game1 via Reflection
+ /// </summary>
+ /// <param name="name">The name of the method</param>
+ /// <param name="parameters">Any parameters needed</param>
+ /// <returns>Whatever the method normally returns. Null if void.</returns>
+ public static object InvokeBasePrivateInstancedMethod(string name, params object[] parameters)
+ {
+ try
+ {
+ return typeof (Game1).GetMethod(name, BindingFlags.NonPublic | BindingFlags.Instance).Invoke(Program.gamePtr, parameters);
+ }
+ catch
+ {
+ Log.AsyncR("Failed to call base method: " + name);
+ return null;
+ }
+ }
+
+ /// <summary>
/// Queue's a message to be drawn in Debug mode (F3)
/// </summary>
/// <returns></returns>