From c5757aca920ef5d44bb62475e7f3f3828c0e4ee9 Mon Sep 17 00:00:00 2001 From: nghiango1 Date: Mon, 1 Apr 2024 23:54:43 +0700 Subject: [PATCH] Update to match 1.6 patch function getMovementSpeed and movePosition --- .gitignore | 3 + MouseMoveMode.csproj | 2 +- MouseMoveMode/MouseMoveMode.cs | 626 +++++++++++++++++---------------- README.md | 10 +- manifest.json | 2 +- 5 files changed, 338 insertions(+), 305 deletions(-) diff --git a/.gitignore b/.gitignore index 93c154b..64de1a8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# External file +SMAPI/ + # user-specific files *.suo *.user diff --git a/MouseMoveMode.csproj b/MouseMoveMode.csproj index 40a9a7a..98e9dee 100644 --- a/MouseMoveMode.csproj +++ b/MouseMoveMode.csproj @@ -1,7 +1,7 @@ - net5.0 + net6.0 diff --git a/MouseMoveMode/MouseMoveMode.cs b/MouseMoveMode/MouseMoveMode.cs index 9c0d51d..f06bae3 100644 --- a/MouseMoveMode/MouseMoveMode.cs +++ b/MouseMoveMode/MouseMoveMode.cs @@ -30,8 +30,8 @@ public class ModConfig internal sealed class ModEntry : Mod { public static ModConfig config; - public static float hitboxRadius = 64f*2; - public static float baseHitboxRadius = 64f*2; + public static float hitboxRadius = 64f * 2; + public static float baseHitboxRadius = 64f * 2; public static bool isMovingAutomaticaly = false; public static bool isBeingAutoCommand = false; @@ -66,17 +66,17 @@ internal sealed class ModEntry : Mod /// Provides simplified APIs for writing mods. public override void Entry(IModHelper helper) { - Helper.Events.Input.ButtonPressed+=this.MouseMoveMode_InputEvents_ButtonPressed; - Helper.Events.Input.ButtonPressed+=this.ExtendedMode_InputEvents_ButtonPressed; - Helper.Events.Input.CursorMoved+=Input_CursorMoved; - Helper.Events.Input.MouseWheelScrolled+=Input_MouseWheelScrolled; - Helper.Events.Input.ButtonReleased+=this.InputEvents_ButtonReleased; - Helper.Events.GameLoop.UpdateTicked+=this.GameEvents_UpdateTick; - Helper.Events.Player.Warped+=this.PlayerEvents_Warped; + Helper.Events.Input.ButtonPressed += this.MouseMoveMode_InputEvents_ButtonPressed; + Helper.Events.Input.ButtonPressed += this.ExtendedMode_InputEvents_ButtonPressed; + Helper.Events.Input.CursorMoved += Input_CursorMoved; + Helper.Events.Input.MouseWheelScrolled += Input_MouseWheelScrolled; + Helper.Events.Input.ButtonReleased += this.InputEvents_ButtonReleased; + Helper.Events.GameLoop.UpdateTicked += this.GameEvents_UpdateTick; + Helper.Events.Player.Warped += this.PlayerEvents_Warped; StartPatching(); - ModEntry.config=this.Helper.ReadConfig(); + ModEntry.config = this.Helper.ReadConfig(); } private void GameEvents_UpdateTick(object sender, EventArgs e) @@ -88,17 +88,17 @@ private void GameEvents_UpdateTick(object sender, EventArgs e) if (!Context.IsWorldReady) return; - hitboxRadius=baseHitboxRadius; + hitboxRadius = baseHitboxRadius; - if (Game1.player.ActiveObject!=null) + if (Game1.player.ActiveObject != null) { if (Game1.player.ActiveObject.isPlaceable()) { - hitboxRadius=baseHitboxRadius*1.5f; + hitboxRadius = baseHitboxRadius * 1.5f; } } - vector_PlayerToMouse.X=position_MouseOnScreen.X+Game1.viewport.X-Game1.player.GetBoundingBox().Center.X; - vector_PlayerToMouse.Y=position_MouseOnScreen.Y+Game1.viewport.Y-Game1.player.GetBoundingBox().Center.Y; + vector_PlayerToMouse.X = position_MouseOnScreen.X + Game1.viewport.X - Game1.player.GetBoundingBox().Center.X; + vector_PlayerToMouse.Y = position_MouseOnScreen.Y + Game1.viewport.Y - Game1.player.GetBoundingBox().Center.Y; if (!Context.IsPlayerFree) return; @@ -107,53 +107,56 @@ private void GameEvents_UpdateTick(object sender, EventArgs e) switch (mouseState.RightButton) { case ButtonState.Pressed: - if (holdCount=config.HoldTickCount) + if (holdCount >= config.HoldTickCount) { - isHoldingMove=false; - isMovingAutomaticaly=false; + isHoldingMove = false; + isMovingAutomaticaly = false; } - holdCount=0; + holdCount = 0; break; } if (isHoldingMove) { - isMovingAutomaticaly=true; + isMovingAutomaticaly = true; if (isBeingControl) { - if (tickCount==0) + if (tickCount == 0) { - isBeingControl=false; - tickCount=15; - } else + isBeingControl = false; + tickCount = 15; + } + else tickCount--; } - } else + } + else { - if (isTryToDoActionAtClickedTitle==2) + if (isTryToDoActionAtClickedTitle == 2) { - position_Destination=pointedNPC.Position; + position_Destination = pointedNPC.Position; } - vector_PlayerToDestination.X=position_Destination.X-Game1.player.GetBoundingBox().Center.X; - vector_PlayerToDestination.Y=position_Destination.Y-Game1.player.GetBoundingBox().Center.Y; + vector_PlayerToDestination.X = position_Destination.X - Game1.player.GetBoundingBox().Center.X; + vector_PlayerToDestination.Y = position_Destination.Y - Game1.player.GetBoundingBox().Center.Y; } - if (Game1.player.ActiveObject!=null) + if (Game1.player.ActiveObject != null) { - if (isMovingAutomaticaly&&(Game1.player.ActiveObject is StardewValley.Objects.Furniture)) + if (isMovingAutomaticaly && (Game1.player.ActiveObject is StardewValley.Objects.Furniture)) { - isMovingAutomaticaly=false; + isMovingAutomaticaly = false; Game1.player.Halt(); } } @@ -161,16 +164,16 @@ private void GameEvents_UpdateTick(object sender, EventArgs e) private void PlayerEvents_Warped(object sender, WarpedEventArgs e) { - isMovingAutomaticaly=false; + isMovingAutomaticaly = false; // There are location that player's new position (after warp) is too close to new warp // This prevent warp back to back - if (e.OldLocation is StardewValley.Locations.Town&&e.NewLocation is StardewValley.Locations.Mountain) + if (e.OldLocation is StardewValley.Locations.Town && e.NewLocation is StardewValley.Locations.Mountain) { - Game1.player.Position+=new Vector2(0f, -10f); + Game1.player.Position += new Vector2(0f, -10f); } - if (e.OldLocation is StardewValley.Farm&&e.NewLocation.Name=="Backwoods") + if (e.OldLocation is StardewValley.Farm && e.NewLocation.Name == "Backwoods") { - Game1.player.Position+=new Vector2(0f, -10f); + Game1.player.Position += new Vector2(0f, -10f); } } @@ -198,7 +201,7 @@ private void ExtendedMode_InputEvents_ButtonPressed(object sender, ButtonPressed if (config.FullScreenKeybindShortcut.JustPressed()) { - if (Game1.options.isCurrentlyWindowedBorderless()||Game1.options.isCurrentlyFullscreen()) + if (Game1.options.isCurrentlyWindowedBorderless() || Game1.options.isCurrentlyFullscreen()) Game1.options.setWindowedOption("Windowed"); else { @@ -217,52 +220,53 @@ private void MouseMoveMode_InputEvents_ButtonPressed(object sender, ButtonPresse if (config.RightClickMoveModeToggleButton.JustPressed()) { - config.RightClickMoveModeDefault=!config.RightClickMoveModeDefault; + config.RightClickMoveModeDefault = !config.RightClickMoveModeDefault; } if (!config.RightClickMoveModeDefault) return; - if (e.Button==Game1.options.runButton[0].ToSButton()) + if (e.Button == Game1.options.runButton[0].ToSButton()) { - isHoldingRunButton=true; + isHoldingRunButton = true; } - bool mouseRightIsDown = button=="MouseRight"&&Context.IsPlayerFree; - bool isMouseOutsiteHitBox = vector_PlayerToMouse.Length().CompareTo(hitboxRadius)>0; + bool mouseRightIsDown = button == "MouseRight" && Context.IsPlayerFree; + bool isMouseOutsiteHitBox = vector_PlayerToMouse.Length().CompareTo(hitboxRadius) > 0; - if (Game1.player.ActiveObject!=null) + if (Game1.player.ActiveObject != null) { if (Game1.player.ActiveObject is Furniture) { - mouseRightIsDown=false; + mouseRightIsDown = false; } } - if (Game1.player.CurrentTool!=null&&Game1.player.CurrentTool is MeleeWeapon weapon&&!Game1.player.CurrentTool.Name.Contains("Scythe")&&SpecialCooldown(weapon)<=0) + if (Game1.player.CurrentTool != null && Game1.player.CurrentTool is MeleeWeapon weapon && !Game1.player.CurrentTool.Name.Contains("Scythe") && SpecialCooldown(weapon) <= 0) { - if (config.WeaponsSpecticalInteractionType==1) + if (config.WeaponsSpecticalInteractionType == 1) { - mouseRightIsDown=false; - if (isMouseOutsiteHitBox&&button=="MouseRight"&&!Game1.player.isRidingHorse()) + mouseRightIsDown = false; + if (isMouseOutsiteHitBox && button == "MouseRight" && !Game1.player.isRidingHorse()) { weapon.animateSpecialMove(Game1.player); Helper.Input.Suppress(e.Button); } - } else if (config.WeaponsSpecticalInteractionType==2) + } + else if (config.WeaponsSpecticalInteractionType == 2) { - if (button=="MouseRight") + if (button == "MouseRight") { Helper.Input.Suppress(e.Button); - isMouseOutsiteHitBox=true; + isMouseOutsiteHitBox = true; } - if ((button=="MouseMiddle"||button=="MouseX1")&&!Game1.player.isRidingHorse()) + if ((button == "MouseMiddle" || button == "MouseX1") && !Game1.player.isRidingHorse()) { weapon.animateSpecialMove(Game1.player); Helper.Input.Suppress(e.Button); } - if (button=="MouseLeft"&&vector_PlayerToMouse.Length().CompareTo(hitboxRadius)<0&&!Game1.player.isRidingHorse()) + if (button == "MouseLeft" && vector_PlayerToMouse.Length().CompareTo(hitboxRadius) < 0 && !Game1.player.isRidingHorse()) { - if (vector_PlayerToMouse.Y<32f) + if (vector_PlayerToMouse.Y < 32f) { weapon.animateSpecialMove(Game1.player); Helper.Input.Suppress(e.Button); @@ -276,38 +280,42 @@ private void MouseMoveMode_InputEvents_ButtonPressed(object sender, ButtonPresse { if (!config.HoldingMoveOnly) { - position_Destination.X=position_MouseOnScreen.X+Game1.viewport.X; - position_Destination.Y=position_MouseOnScreen.Y+Game1.viewport.Y; + position_Destination.X = position_MouseOnScreen.X + Game1.viewport.X; + position_Destination.Y = position_MouseOnScreen.Y + Game1.viewport.Y; - vector_PlayerToDestination.X=position_Destination.X-Game1.player.GetBoundingBox().Center.X; - vector_PlayerToDestination.Y=position_Destination.Y-Game1.player.GetBoundingBox().Center.Y; - grabTile=new Vector2((float)(position_MouseOnScreen.X+Game1.viewport.X), (float)(position_MouseOnScreen.Y+Game1.viewport.Y))/64f; + vector_PlayerToDestination.X = position_Destination.X - Game1.player.GetBoundingBox().Center.X; + vector_PlayerToDestination.Y = position_Destination.Y - Game1.player.GetBoundingBox().Center.Y; + grabTile = new Vector2((float)(position_MouseOnScreen.X + Game1.viewport.X), (float)(position_MouseOnScreen.Y + Game1.viewport.Y)) / 64f; - isMovingAutomaticaly=true; - isBeingControl=false; + isMovingAutomaticaly = true; + isBeingControl = false; } if (config.ForceMoveButton.IsDown()) { Helper.Input.Suppress(e.Button); - } else if (isMouseOutsiteHitBox) + } + else if (isMouseOutsiteHitBox) { Helper.Input.Suppress(e.Button); - isTryToDoActionAtClickedTitle=GetActionType(ref grabTile); - } else if (!isMouseOutsiteHitBox) + isTryToDoActionAtClickedTitle = GetActionType(ref grabTile); + } + else if (!isMouseOutsiteHitBox) { - isTryToDoActionAtClickedTitle=0; + isTryToDoActionAtClickedTitle = 0; } - } else + } + else { if (e.Button.IsUseToolButton()) { - tickCount=15; - } else - tickCount=0; + tickCount = 15; + } + else + tickCount = 0; if (!config.ForceMoveButton.IsDown()) - isBeingControl=true; + isBeingControl = true; } } @@ -322,59 +330,60 @@ private int GetActionType(ref Vector2 grabTile) // 5 is Unknown, try to grap at pointed place StardewValley.Object pointedObject = Game1.player.currentLocation.getObjectAtTile((int)grabTile.X, (int)grabTile.Y); - if (pointedObject==null&&Game1.player.currentLocation.getObjectAtTile((int)grabTile.X, (int)grabTile.Y+1)!=null) + if (pointedObject == null && Game1.player.currentLocation.getObjectAtTile((int)grabTile.X, (int)grabTile.Y + 1) != null) { - grabTile.Y+=1; - pointedObject=Game1.player.currentLocation.getObjectAtTile((int)grabTile.X, (int)grabTile.Y); + grabTile.Y += 1; + pointedObject = Game1.player.currentLocation.getObjectAtTile((int)grabTile.X, (int)grabTile.Y); } - if (pointedObject!=null&&pointedObject.Type!=null&&(pointedObject.IsSpawnedObject||(pointedObject.Type.Equals("Crafting") - &&pointedObject.Type.Equals("interactive")))) + if (pointedObject != null && pointedObject.Type != null && (pointedObject.IsSpawnedObject || (pointedObject.Type.Equals("Crafting") + && pointedObject.Type.Equals("interactive")))) { return 1; } - pointedNPC=Game1.player.currentLocation.isCharacterAtTile(grabTile); - if (pointedNPC==null) - pointedNPC=Game1.player.currentLocation.isCharacterAtTile(grabTile+new Vector2(0f, 1f)); - if (pointedNPC!=null&&!pointedNPC.IsMonster) + pointedNPC = Game1.player.currentLocation.isCharacterAtTile(grabTile); + if (pointedNPC == null) + pointedNPC = Game1.player.currentLocation.isCharacterAtTile(grabTile + new Vector2(0f, 1f)); + if (pointedNPC != null && !pointedNPC.IsMonster) { - currentToolIndex=Game1.player.CurrentToolIndex; + currentToolIndex = Game1.player.CurrentToolIndex; return 2; } - if (Game1.player.ActiveObject!=null&&Game1.player.ActiveObject.isPlaceable()) + if (Game1.player.ActiveObject != null && Game1.player.ActiveObject.isPlaceable()) { - currentToolIndex=Game1.player.CurrentToolIndex; + currentToolIndex = Game1.player.CurrentToolIndex; return 3; } foreach (var v in Game1.player.currentLocation.terrainFeatures.Pairs) { - if (v.Value.getBoundingBox(v.Key).Intersects(new Rectangle((int)grabTile.X*64, (int)grabTile.Y*64, 64, 64))) + if (v.Value.getBoundingBox().Intersects(new Rectangle((int)grabTile.X * 64, (int)grabTile.Y * 64, 64, 64))) { - if ((v.Value is Grass)||(v.Value is HoeDirt dirt&&!dirt.readyForHarvest())) - { } else + if ((v.Value is Grass) || (v.Value is HoeDirt dirt && !dirt.readyForHarvest())) + { } + else return 4; } } - if (Game1.player.currentLocation.largeTerrainFeatures!=null) + if (Game1.player.currentLocation.largeTerrainFeatures != null) { foreach (var f in Game1.player.currentLocation.largeTerrainFeatures) { - if (f.getBoundingBox().Intersects(new Rectangle((int)grabTile.X*64, (int)grabTile.Y*64, 64, 64))) + if (f.getBoundingBox().Intersects(new Rectangle((int)grabTile.X * 64, (int)grabTile.Y * 64, 64, 64))) { return 4; } } } - if (Game1.isActionAtCurrentCursorTile||Game1.isInspectionAtCurrentCursorTile) + if (Game1.isActionAtCurrentCursorTile || Game1.isInspectionAtCurrentCursorTile) { if (!Game1.currentLocation.isActionableTile((int)grabTile.X, (int)grabTile.Y, Game1.player)) - if (Game1.currentLocation.isActionableTile((int)grabTile.X, (int)grabTile.Y+1, Game1.player)) - grabTile.Y+=1; + if (Game1.currentLocation.isActionableTile((int)grabTile.X, (int)grabTile.Y + 1, Game1.player)) + grabTile.Y += 1; return 1; } @@ -394,25 +403,26 @@ private void Input_MouseWheelScrolled(object sender, MouseWheelScrolledEventArgs // MouseState mouseState = Mouse.GetState(); // mouseState.w - if (this.Helper.Input.IsDown(SButton.LeftControl)||this.Helper.Input.IsDown(SButton.RightControl)) + if (this.Helper.Input.IsDown(SButton.LeftControl) || this.Helper.Input.IsDown(SButton.RightControl)) { - if (e.OldValuee.NewValue) + } + else if (e.OldValue > e.NewValue) { - if (Game1.options.zoomLevel>=config.MouseWhellingMinZoom) - Game1.options.desiredBaseZoomLevel-=0.05f; + if (Game1.options.zoomLevel >= config.MouseWhellingMinZoom) + Game1.options.desiredBaseZoomLevel -= 0.05f; Game1.exitActiveMenu(); - if (!(Game1.player.UsingTool&&(Game1.player.CurrentTool==null||!(Game1.player.CurrentTool is FishingRod fishingRod)||(!fishingRod.isReeling&&!fishingRod.pullingOutOfWater)))) + if (!(Game1.player.UsingTool && (Game1.player.CurrentTool == null || !(Game1.player.CurrentTool is FishingRod fishingRod) || (!fishingRod.isReeling && !fishingRod.pullingOutOfWater)))) { - Game1.player.CurrentToolIndex-=1; + Game1.player.CurrentToolIndex -= 1; } } } @@ -425,8 +435,8 @@ private void Input_CursorMoved(object sender, CursorMovedEventArgs e) if (config.RightClickMoveModeDefault) if (flag) { - position_MouseOnScreen.X=Game1.getMousePosition(Game1.uiMode).X; - position_MouseOnScreen.Y=Game1.getMousePosition(Game1.uiMode).Y; + position_MouseOnScreen.X = Game1.getMousePosition(Game1.uiMode).X; + position_MouseOnScreen.Y = Game1.getMousePosition(Game1.uiMode).Y; } } @@ -436,70 +446,70 @@ private void InputEvents_ButtonReleased(object sender, ButtonReleasedEventArgs e if (config.RightClickMoveModeDefault) { - if (e.Button==Game1.options.runButton[0].ToSButton()) + if (e.Button == Game1.options.runButton[0].ToSButton()) { - isHoldingRunButton=false; + isHoldingRunButton = false; } } } public static void TryToCheckGrapTile() { - if (isTryToDoActionAtClickedTitle==0) + if (isTryToDoActionAtClickedTitle == 0) return; if (Game1.player.isRidingHorse()) { - if ((isTryToDoActionAtClickedTitle==2)&&Utility.tileWithinRadiusOfPlayer(pointedNPC.getTileX(), pointedNPC.getTileY(), 2, Game1.player)) + if ((isTryToDoActionAtClickedTitle == 2) && Utility.tileWithinRadiusOfPlayer(pointedNPC.TilePoint.X, pointedNPC.TilePoint.Y, 2, Game1.player)) Game1.player.mount.dismount(); - else if (isTryToDoActionAtClickedTitle!=0&&isTryToDoActionAtClickedTitle!=5&&Utility.tileWithinRadiusOfPlayer((int)grabTile.X, (int)grabTile.Y, 2, Game1.player)) + else if (isTryToDoActionAtClickedTitle != 0 && isTryToDoActionAtClickedTitle != 5 && Utility.tileWithinRadiusOfPlayer((int)grabTile.X, (int)grabTile.Y, 2, Game1.player)) Game1.player.mount.dismount(); } - if (isTryToDoActionAtClickedTitle==1&&Utility.tileWithinRadiusOfPlayer((int)grabTile.X, (int)grabTile.Y, 1, Game1.player)&&Game1.tryToCheckAt(grabTile, Game1.player)) + if (isTryToDoActionAtClickedTitle == 1 && Utility.tileWithinRadiusOfPlayer((int)grabTile.X, (int)grabTile.Y, 1, Game1.player) && Game1.tryToCheckAt(grabTile, Game1.player)) { - isTryToDoActionAtClickedTitle=0; - isMovingAutomaticaly=false; + isTryToDoActionAtClickedTitle = 0; + isMovingAutomaticaly = false; } - if ((isTryToDoActionAtClickedTitle==2||isTryToDoActionAtClickedTitle==3)&&(Game1.player.CurrentToolIndex!=currentToolIndex)) + if ((isTryToDoActionAtClickedTitle == 2 || isTryToDoActionAtClickedTitle == 3) && (Game1.player.CurrentToolIndex != currentToolIndex)) { - isTryToDoActionAtClickedTitle=0; + isTryToDoActionAtClickedTitle = 0; } - if (isTryToDoActionAtClickedTitle==3&&(Game1.player.ActiveObject==null)) + if (isTryToDoActionAtClickedTitle == 3 && (Game1.player.ActiveObject == null)) { - isTryToDoActionAtClickedTitle=0; + isTryToDoActionAtClickedTitle = 0; } - if (isTryToDoActionAtClickedTitle==2&&Utility.tileWithinRadiusOfPlayer(pointedNPC.getTileX(), pointedNPC.getTileY(), 1, Game1.player)&&Game1.tryToCheckAt(pointedNPC.getTileLocation(), Game1.player)) + if (isTryToDoActionAtClickedTitle == 2 && Utility.tileWithinRadiusOfPlayer(pointedNPC.TilePoint.X, pointedNPC.TilePoint.Y, 1, Game1.player) && Game1.tryToCheckAt(pointedNPC.Tile, Game1.player)) { - isTryToDoActionAtClickedTitle=0; - isMovingAutomaticaly=false; + isTryToDoActionAtClickedTitle = 0; + isMovingAutomaticaly = false; } - if (isTryToDoActionAtClickedTitle==3&&Utility.tileWithinRadiusOfPlayer((int)grabTile.X, (int)grabTile.Y, 1, Game1.player)) + if (isTryToDoActionAtClickedTitle == 3 && Utility.tileWithinRadiusOfPlayer((int)grabTile.X, (int)grabTile.Y, 1, Game1.player)) { int stack = Game1.player.ActiveObject.Stack; - Utility.tryToPlaceItem(Game1.player.currentLocation, Game1.player.ActiveObject, (int)grabTile.X*64+32, (int)grabTile.Y*64+32); - if (Game1.player.ActiveObject==null||Game1.player.ActiveObject.Stack=-5) + if (vector_AutoMove.X <= 5 && vector_AutoMove.X >= -5) { - vector_AutoMove.X=0; - flag2=true; - } else if (vector_AutoMove.X>=5) + vector_AutoMove.X = 0; + flag2 = true; + } + else if (vector_AutoMove.X >= 5) Game1.player.SetMovingRight(true); - else if (vector_AutoMove.X<=-5) + else if (vector_AutoMove.X <= -5) Game1.player.SetMovingLeft(true); - if (vector_AutoMove.Y<=5&&vector_AutoMove.Y>=-5) + if (vector_AutoMove.Y <= 5 && vector_AutoMove.Y >= -5) { - vector_AutoMove.Y=0; - flag3=true; - } else if (vector_AutoMove.Y>=5) + vector_AutoMove.Y = 0; + flag3 = true; + } + else if (vector_AutoMove.Y >= 5) Game1.player.SetMovingDown(true); - else if (vector_AutoMove.Y<=-5) + else if (vector_AutoMove.Y <= -5) Game1.player.SetMovingUp(true); vector_AutoMove.Normalize(); - if (flag2&&flag3) + if (flag2 && flag3) { - isMovingAutomaticaly=false; - isTryToDoActionAtClickedTitle=0; + isMovingAutomaticaly = false; + isTryToDoActionAtClickedTitle = 0; } } } @@ -580,7 +593,7 @@ public static bool PrefixMethod_Farmer_HaltPatch() // true mean base method will exec, false mean the opposite if (config.RightClickMoveModeDefault) { - return !isMovingAutomaticaly||isBeingAutoCommand; + return !isMovingAutomaticaly || isBeingAutoCommand; } return true; } @@ -589,7 +602,7 @@ public static bool PrefixMethod_Farmer_MovePositionPatch() { if (config.RightClickMoveModeDefault) { - if (!isBeingControl&&isMovingAutomaticaly&&Context.IsPlayerFree&&Game1.player.CanMove) + if (!isBeingControl && isMovingAutomaticaly && Context.IsPlayerFree && Game1.player.CanMove) { MovePosition(Game1.currentGameTime, Game1.viewport, Game1.player.currentLocation); return false; @@ -602,24 +615,26 @@ public static void PostfixMethod_Game1_UpdateControlInputPatch() { if (config.RightClickMoveModeDefault) { - if (!isBeingControl&&Context.IsPlayerFree&&Game1.player.CanMove) + if (!isBeingControl && Context.IsPlayerFree && Game1.player.CanMove) { - isBeingAutoCommand=true; + isBeingAutoCommand = true; MoveVectorToCommand(); - if (isHoldingRunButton&&!Game1.player.canOnlyWalk) + if (isHoldingRunButton && !Game1.player.canOnlyWalk) { Game1.player.setRunning(!Game1.options.autoRun, false); Game1.player.setMoving(Game1.player.running ? (byte)16 : (byte)48); - } else if (!isHoldingRunButton&&!Game1.player.canOnlyWalk) + } + else if (!isHoldingRunButton && !Game1.player.canOnlyWalk) { Game1.player.setRunning(Game1.options.autoRun, false); Game1.player.setMoving(Game1.player.running ? (byte)16 : (byte)48); } - isBeingAutoCommand=false; - } else - isBeingAutoCommand=false; + isBeingAutoCommand = false; + } + else + isBeingAutoCommand = false; } } @@ -627,19 +642,36 @@ public static bool PrefixMethod_Farmer_getMovementSpeedPatch(ref float __result) { if (config.RightClickMoveModeDefault) { - if (!isBeingControl&&Context.IsPlayerFree) + if (!isBeingControl && Context.IsPlayerFree) { - - float movementSpeed; - if (Game1.CurrentEvent==null||Game1.CurrentEvent.playerControlSequence) + if (Game1.player.UsingTool && Game1.player.canStrafeForToolUse()) + { + __result = 2f; + return false; + } + if (Game1.CurrentEvent == null || Game1.CurrentEvent.playerControlSequence) { - Game1.player.movementMultiplier=0.066f; - movementSpeed=Math.Max(1f, ((float)Game1.player.speed+(Game1.eventUp ? 0f : ((float)Game1.player.addedSpeed+(Game1.player.isRidingHorse() ? 4.6f : Game1.player.temporarySpeedBuff))))*Game1.player.movementMultiplier*(float)Game1.currentGameTime.ElapsedGameTime.Milliseconds); - } else + Game1.player.movementMultiplier = 0.066f; + float movementSpeed2 = 1f; + movementSpeed2 = ((!Game1.player.isRidingHorse()) ? Math.Max(1f, ((float)Game1.player.speed + (Game1.eventUp ? 0f : (Game1.player.addedSpeed + Game1.player.temporarySpeedBuff))) * Game1.player.movementMultiplier * (float)Game1.currentGameTime.ElapsedGameTime.Milliseconds) : Math.Max(1f, ((float)Game1.player.speed + (Game1.eventUp ? 0f : (Game1.player.addedSpeed + 4.6f + (Game1.player.mount.ateCarrotToday ? 0.4f : 0f) + ((Game1.player.stats.Get("Book_Horse") != 0) ? 0.5f : 0f)))) * Game1.player.movementMultiplier * (float)Game1.currentGameTime.ElapsedGameTime.Milliseconds)); + // This isn't needed + // if (Game1.player.movementDirections.Count > 1) + // { + // movementSpeed2 *= 0.707f; + // } + if (Game1.CurrentEvent == null && Game1.player.hasBuff("19")) + { + movementSpeed2 = 0f; + } + __result = movementSpeed2; + return false; + } + float movementSpeed = Math.Max(1f, (float)Game1.player.speed + (Game1.eventUp ? ((float)Math.Max(0, Game1.CurrentEvent.farmerAddedSpeed - 2)) : (Game1.player.addedSpeed + (Game1.player.isRidingHorse() ? 5f : Game1.player.temporarySpeedBuff)))); + if (Game1.player.movementDirections.Count > 1) { - movementSpeed=Math.Max(1f, (float)Game1.player.speed+(Game1.eventUp ? ((float)Math.Max(0, Game1.CurrentEvent.farmerAddedSpeed-2)) : ((float)Game1.player.addedSpeed+(Game1.player.isRidingHorse() ? 5f : Game1.player.temporarySpeedBuff)))); + movementSpeed = Math.Max(1, (int)Math.Sqrt(2f * (movementSpeed * movementSpeed)) / 2); } - __result=movementSpeed; + __result = movementSpeed; return false; } } @@ -648,145 +680,140 @@ public static bool PrefixMethod_Farmer_getMovementSpeedPatch(ref float __result) public static void MovePosition(GameTime time, xTile.Dimensions.Rectangle viewport, GameLocation currentLocation) { - if (!Game1.player.IsSitting()) + if (Game1.player.IsSitting()) { return; } + + if (Game1.CurrentEvent == null || Game1.CurrentEvent.playerControlSequence) { - TimeSpan elapsedGameTime; - if (Game1.CurrentEvent==null||Game1.CurrentEvent.playerControlSequence) + if (Game1.shouldTimePass() && Game1.player.temporarilyInvincible) { - if (Game1.shouldTimePass(false)&&Game1.player.temporarilyInvincible) + if (Game1.player.temporaryInvincibilityTimer < 0) { - if (Game1.player.temporaryInvincibilityTimer<0) - { - Game1.player.currentTemporaryInvincibilityDuration=1200; - } - int num = Game1.player.temporaryInvincibilityTimer; - elapsedGameTime=time.ElapsedGameTime; - Game1.player.temporaryInvincibilityTimer=num+elapsedGameTime.Milliseconds; - if (Game1.player.temporaryInvincibilityTimer>Game1.player.currentTemporaryInvincibilityDuration) - { - Game1.player.temporarilyInvincible=false; - Game1.player.temporaryInvincibilityTimer=0; - } + Game1.player.currentTemporaryInvincibilityDuration = 1200; + } + Game1.player.temporaryInvincibilityTimer += time.ElapsedGameTime.Milliseconds; + if (Game1.player.temporaryInvincibilityTimer > Game1.player.currentTemporaryInvincibilityDuration) + { + Game1.player.temporarilyInvincible = false; + Game1.player.temporaryInvincibilityTimer = 0; } - } else if (Game1.player.temporarilyInvincible) + } + } + else if (Game1.player.temporarilyInvincible) + { + Game1.player.temporarilyInvincible = false; + Game1.player.temporaryInvincibilityTimer = 0; + } + + if (Game1.activeClickableMenu != null) + { + if (Game1.CurrentEvent == null) + { + return; + } + if (Game1.CurrentEvent.playerControlSequence) + { + return; + } + } + + if (Game1.player.isRafting) + { + Game1.player.moveRaft(currentLocation, time); + return; + } + + if (Game1.player.xVelocity != 0f || Game1.player.yVelocity != 0f) + { + if (double.IsNaN((double)Game1.player.xVelocity) || double.IsNaN((double)Game1.player.yVelocity)) { - Game1.player.temporarilyInvincible=false; - Game1.player.temporaryInvincibilityTimer=0; + Game1.player.xVelocity = 0f; + Game1.player.yVelocity = 0f; } - if (Game1.activeClickableMenu!=null) + + Rectangle bounds = Game1.player.GetBoundingBox(); + Rectangle value = new Microsoft.Xna.Framework.Rectangle(bounds.X + (int)Math.Floor(Game1.player.xVelocity), bounds.Y - (int)Math.Floor(Game1.player.yVelocity), bounds.Width, bounds.Height); + Rectangle nextPositionCeil = new Microsoft.Xna.Framework.Rectangle(bounds.X + (int)Math.Ceiling(Game1.player.xVelocity), bounds.Y - (int)Math.Ceiling(Game1.player.yVelocity), bounds.Width, bounds.Height); + Rectangle nextPosition = Microsoft.Xna.Framework.Rectangle.Union(value, nextPositionCeil); + + if (!currentLocation.isCollidingPosition(nextPosition, viewport, true, -1, false, Game1.player)) { - if (Game1.CurrentEvent==null) + Game1.player.position.X += Game1.player.xVelocity; + Game1.player.position.Y -= Game1.player.yVelocity; + Game1.player.xVelocity -= Game1.player.xVelocity / 16f; + Game1.player.yVelocity -= Game1.player.yVelocity / 16f; + if (Math.Abs(Game1.player.xVelocity) <= 0.05f) { - return; + Game1.player.xVelocity = 0f; } - if (Game1.CurrentEvent.playerControlSequence) + if (Math.Abs(Game1.player.yVelocity) <= 0.05f) { - return; + Game1.player.yVelocity = 0f; } } - if (Game1.player.isRafting) - { - Game1.player.moveRaft(currentLocation, time); - } else + else { - if (Game1.player.xVelocity!=0f||Game1.player.yVelocity!=0f) + Game1.player.xVelocity -= Game1.player.xVelocity / 16f; + Game1.player.yVelocity -= Game1.player.yVelocity / 16f; + if (Math.Abs(Game1.player.xVelocity) <= 0.05f) { - if (double.IsNaN((double)Game1.player.xVelocity)||double.IsNaN((double)Game1.player.yVelocity)) - { - Game1.player.xVelocity=0f; - Game1.player.yVelocity=0f; - } - Rectangle nextPositionFloor = Game1.player.GetBoundingBox(); - nextPositionFloor.X+=(int)Math.Floor((double)Game1.player.xVelocity); - nextPositionFloor.Y-=(int)Math.Floor((double)Game1.player.yVelocity); - Rectangle nextPositionCeil = Game1.player.GetBoundingBox(); - nextPositionCeil.X+=(int)Math.Ceiling((double)Game1.player.xVelocity); - nextPositionCeil.Y-=(int)Math.Ceiling((double)Game1.player.yVelocity); - Rectangle nextPosition = Rectangle.Union(nextPositionFloor, nextPositionCeil); - if (!currentLocation.isCollidingPosition(nextPosition, viewport, true, -1, false, Game1.player)) - { - Game1.player.position.X+=Game1.player.xVelocity; - Game1.player.position.Y-=Game1.player.yVelocity; - Game1.player.xVelocity-=Game1.player.xVelocity/16f; - Game1.player.yVelocity-=Game1.player.yVelocity/16f; - if (Math.Abs(Game1.player.xVelocity)<=0.05f) - { - Game1.player.xVelocity=0f; - } - if (Math.Abs(Game1.player.yVelocity)<=0.05f) - { - Game1.player.yVelocity=0f; - } - } else - { - Game1.player.xVelocity-=Game1.player.xVelocity/16f; - Game1.player.yVelocity-=Game1.player.yVelocity/16f; - if (Math.Abs(Game1.player.xVelocity)<=0.05f) - { - Game1.player.xVelocity=0f; - } - if (Math.Abs(Game1.player.yVelocity)<=0.05f) - { - Game1.player.yVelocity=0f; - } - } + Game1.player.xVelocity = 0f; } - - if (Game1.player.CanMove||Game1.eventUp||Game1.player.controller!=null) + if (Math.Abs(Game1.player.yVelocity) <= 0.05f) { - Game1.player.TemporaryPassableTiles.ClearNonIntersecting(Game1.player.GetBoundingBox()); - - Game1.player.temporarySpeedBuff=0f; + Game1.player.yVelocity = 0f; + } + } + } - if (Game1.player.movementDirections.Contains(0)) - TryMoveDrection(time, viewport, currentLocation, 0); + if (Game1.player.CanMove || Game1.eventUp || Game1.player.controller != null || Game1.player.canStrafeForToolUse()) + { + Game1.player.TemporaryPassableTiles.ClearNonIntersecting(Game1.player.GetBoundingBox()); + float movementSpeed = Game1.player.getMovementSpeed(); + Game1.player.temporarySpeedBuff = 0f; - if (Game1.player.movementDirections.Contains(2)) - TryMoveDrection(time, viewport, currentLocation, 2); + if (Game1.player.movementDirections.Contains(0)) + TryMoveDrection(time, viewport, currentLocation, 0); - if (Game1.player.movementDirections.Contains(1)) - TryMoveDrection(time, viewport, currentLocation, 1); + if (Game1.player.movementDirections.Contains(2)) + TryMoveDrection(time, viewport, currentLocation, 2); - if (Game1.player.movementDirections.Contains(3)) - TryMoveDrection(time, viewport, currentLocation, 3); + if (Game1.player.movementDirections.Contains(1)) + TryMoveDrection(time, viewport, currentLocation, 1); - if (Game1.player.movementDirections.Count==2) - { - if (Math.Abs(vector_AutoMove.Y/vector_AutoMove.X).CompareTo(0.45f)<0) - { - Game1.player.SetMovingDown(false); - Game1.player.SetMovingUp(false); - } else if (Math.Abs(vector_AutoMove.Y)>Math.Sin(Math.PI/3)) - { - Game1.player.SetMovingRight(false); - Game1.player.SetMovingLeft(false); - } - } - } + if (Game1.player.movementDirections.Contains(3)) + TryMoveDrection(time, viewport, currentLocation, 3); - if (Game1.player.movementDirections.Count>0&&!Game1.player.UsingTool) - { - Game1.player.FarmerSprite.intervalModifier=1f-(Game1.player.running ? 0.03f : 0.025f)*(Math.Max(1f, ((float)Game1.player.speed+(Game1.eventUp ? 0f : ((float)Game1.player.addedSpeed+(Game1.player.isRidingHorse() ? 4.6f : 0f))))*Game1.player.movementMultiplier*(float)Game1.currentGameTime.ElapsedGameTime.Milliseconds)*1.25f); - } else + if (Game1.player.movementDirections.Count == 2) + { + if (Math.Abs(vector_AutoMove.Y / vector_AutoMove.X).CompareTo(0.45f) < 0) { - Game1.player.FarmerSprite.intervalModifier=1f; + Game1.player.SetMovingDown(false); + Game1.player.SetMovingUp(false); } - if (Game1.player.temporarilyInvincible) + else if (Math.Abs(vector_AutoMove.Y) > Math.Sin(Math.PI / 3)) { - Game1.player.temporaryInvincibilityTimer+=time.ElapsedGameTime.Milliseconds; - if (Game1.player.temporaryInvincibilityTimer>1200) - { - Game1.player.temporarilyInvincible=false; - Game1.player.temporaryInvincibilityTimer=0; - } - } - if (currentLocation!=null&¤tLocation.isFarmerCollidingWithAnyCharacter()) - { - Game1.player.TemporaryPassableTiles.Add(new Microsoft.Xna.Framework.Rectangle((int)Game1.player.getTileLocation().X*64, (int)Game1.player.getTileLocation().Y*64, 64, 64)); + Game1.player.SetMovingRight(false); + Game1.player.SetMovingLeft(false); } } + return; + } + + if (Game1.player.movementDirections.Count > 0 && !Game1.player.UsingTool) + { + Game1.player.FarmerSprite.intervalModifier = 1f - (Game1.player.running ? 0.0255f : 0.025f) * (Math.Max(1f, ((float)Game1.player.speed + (Game1.eventUp ? 0f : ((float)(int)Game1.player.addedSpeed + (Game1.player.isRidingHorse() ? 4.6f : 0f)))) * Game1.player.movementMultiplier * (float)Game1.currentGameTime.ElapsedGameTime.Milliseconds) * 1.25f); + } + else + { + Game1.player.FarmerSprite.intervalModifier = 1f; + } + + if (currentLocation != null && currentLocation.isFarmerCollidingWithAnyCharacter()) + { + Game1.player.TemporaryPassableTiles.Add(new Microsoft.Xna.Framework.Rectangle(Game1.player.TilePoint.X * 64, Game1.player.TilePoint.Y * 64, 64, 64)); } } + public static int RightDirection(int faceDirection) { switch (faceDirection) @@ -824,7 +851,7 @@ public static int LeftDirection(int faceDirection) public static void TryMoveDrection(GameTime time, xTile.Dimensions.Rectangle viewport, GameLocation currentLocation, int faceDirection) { Warp warp = Game1.currentLocation.isCollidingWithWarp(Game1.player.nextPosition(faceDirection), Game1.player); - if (warp!=null&&Game1.player.IsLocalPlayer) + if (warp != null && Game1.player.IsLocalPlayer) { Game1.player.warpFarmer(warp); return; @@ -836,44 +863,47 @@ public static void TryMoveDrection(GameTime time, xTile.Dimensions.Rectangle vie if (!currentLocation.isCollidingPosition(nextPos, viewport, true, 0, false, Game1.player)) { - if (faceDirection==0||faceDirection==2) - Game1.player.position.Y+=movementSpeed*vector_AutoMove.Y; + if (faceDirection == 0 || faceDirection == 2) + Game1.player.position.Y += movementSpeed * vector_AutoMove.Y; else - Game1.player.position.X+=movementSpeed*vector_AutoMove.X; + Game1.player.position.X += movementSpeed * vector_AutoMove.X; Game1.player.behaviorOnMovement(faceDirection); - } else + } + else { - nextPos=Game1.player.nextPositionHalf(faceDirection); + nextPos = Game1.player.nextPositionHalf(faceDirection); if (!currentLocation.isCollidingPosition(nextPos, viewport, true, 0, false, Game1.player)) { - if (faceDirection==0||faceDirection==2) - Game1.player.position.Y+=movementSpeed*vector_AutoMove.Y/2f; + if (faceDirection == 0 || faceDirection == 2) + Game1.player.position.Y += movementSpeed * vector_AutoMove.Y / 2f; else - Game1.player.position.X+=movementSpeed*vector_AutoMove.X/2f; + Game1.player.position.X += movementSpeed * vector_AutoMove.X / 2f; Game1.player.behaviorOnMovement(faceDirection); - } else if (Game1.player.movementDirections.Count==1) + } + else if (Game1.player.movementDirections.Count == 1) { Rectangle tmp = Game1.player.nextPosition(faceDirection); - tmp.Width/=4; + tmp.Width /= 4; bool leftCorner = currentLocation.isCollidingPosition(tmp, viewport, true, 0, false, Game1.player); - tmp.X+=tmp.Width*3; + tmp.X += tmp.Width * 3; bool rightCorner = currentLocation.isCollidingPosition(tmp, viewport, true, 0, false, Game1.player); - if (leftCorner&&!rightCorner&&!currentLocation.isCollidingPosition(Game1.player.nextPosition(LeftDirection(faceDirection)), viewport, true, 0, false, Game1.player)) + if (leftCorner && !rightCorner && !currentLocation.isCollidingPosition(Game1.player.nextPosition(LeftDirection(faceDirection)), viewport, true, 0, false, Game1.player)) { - if (faceDirection==0||faceDirection==2) - Game1.player.position.X+=(float)Game1.player.speed*((float)time.ElapsedGameTime.Milliseconds/64f); + if (faceDirection == 0 || faceDirection == 2) + Game1.player.position.X += (float)Game1.player.speed * ((float)time.ElapsedGameTime.Milliseconds / 64f); else - Game1.player.position.Y+=(float)Game1.player.speed*((float)time.ElapsedGameTime.Milliseconds/64f); - } else if (rightCorner&&!leftCorner&&!currentLocation.isCollidingPosition(Game1.player.nextPosition(RightDirection(faceDirection)), viewport, true, 0, false, Game1.player)) + Game1.player.position.Y += (float)Game1.player.speed * ((float)time.ElapsedGameTime.Milliseconds / 64f); + } + else if (rightCorner && !leftCorner && !currentLocation.isCollidingPosition(Game1.player.nextPosition(RightDirection(faceDirection)), viewport, true, 0, false, Game1.player)) { - if (faceDirection==0||faceDirection==2) - Game1.player.position.X-=(float)Game1.player.speed*((float)time.ElapsedGameTime.Milliseconds/64f); + if (faceDirection == 0 || faceDirection == 2) + Game1.player.position.X -= (float)Game1.player.speed * ((float)time.ElapsedGameTime.Milliseconds / 64f); else - Game1.player.position.Y-=(float)Game1.player.speed*((float)time.ElapsedGameTime.Milliseconds/64f); + Game1.player.position.Y -= (float)Game1.player.speed * ((float)time.ElapsedGameTime.Milliseconds / 64f); } } } diff --git a/README.md b/README.md index 7b70129..129d366 100644 --- a/README.md +++ b/README.md @@ -28,9 +28,9 @@ Thank you for your the kind words ### Windows Preparing environment -- Install NET 5.0 (Need manual download from https://dotnet.microsoft.com/en-us/download/dotnet/5.0 , as this no logner support version) -- Install Visual Studio 2019 (or VS2019) as your IDE as this is the only Version that support NET 5.0 (It seem that VS2022 can still build from this source, but you can't create a new NET5.0 solution) -- Get source code (it can be done using `git clone` or you can just download it), still you don't know about `git` then it quite hard to make contributing. +- Install NET 6.0 +- Install Visual Studio 2019 (or VS2022) as your IDE +- Get source code (it can be done using `git clone` or you can just download it) - Open the project `MouseMoveMode.sln` file from VS2019 Extra: install Nuget package (the project file already come with it, this should be automated if you using Visual Studio IDE) @@ -52,9 +52,9 @@ If you are using VS2019, the Debug and Build step is pretty straight forward. I It quite impossible even for me to get the debug working, so we can skip it and try relying on `log` that provided by SMAPI. If you know how to then let me know. Preparing environment -- Download Net 5.0 CLI, you can use scripted install and get the version name from https://dotnet.microsoft.com/en-us/download/dotnet/5.0 , here is a example +- Download Net 6.0 CLI, you can use scripted install and get the version name from https://dotnet.microsoft.com/en-us/download/dotnet/6.0 , here is a example ``` - ./dotnet-install.sh --version 5.0.408 + ./dotnet-install.sh --version 6.0.420 ``` - Update your PATH to have the `dotnet` executable avaiable - (Optional) Install Nuget pakage manually using `dotnet` CLI diff --git a/manifest.json b/manifest.json index 3ef1d38..854de71 100644 --- a/manifest.json +++ b/manifest.json @@ -6,5 +6,5 @@ "Name": "MouseMoveMode", "UniqueID": "nghiango1.MouseMoveMode", "UpdateKeys": [ "Nexus:2614", "Github:nghiango1/RightClickMoveMode" ], - "Version": "1.2.8-b" + "Version": "1.2.9" }