NOTE: Use of this mod will create a folder StardewTAS
in your Documents
folder. This folder will contain your save states, scripts, screenshots, etc.
Basic Framework for a TAS Mod, includes
- frame advance (press
q
ordownarrow
for 1 frame, holdspace
for real time) - reset (press
|
for normal speed, ']' for fast speed) - save (press
.
, writes to tmp.json) - load (press
,
, reads from tmp.json) - AC keybind (hold
r
to simulate ac keys) - Console (Ctrl+`) or (⌘+`) to open/close the console (` is above tab on US keyboards, may function as
~
if using another keyboard layout...)- you cannot manually input while the console is up
Hold the keys you want and then advance a frame to store those inputs (simulate AC with r
)
Slowly copying over/making sure things work in the new system.
Console supports scrolling, selection, normal copy and paste (or it should, LET ME KNOW because it works on mac fine). Console font has no support for non-ascii, so will print ?
.
Scripting in this TAS is done with Lua! By typing lua
onto the console you'll enter into a Lua REPL (read-eval-print-loop), which will allow you to run arbitrary lua code. Documentation for the core lua engine functions can be found by navigating locally to docs/ldoc/index.html or you can browse the TASMod/Assets/lua
folder where the lua files are stored.
There is an example init.lua
file in the lua-examples
folder. The TASMod will look for a file called init.lua
in the StardewTAS/Scripts/
folder and will run that file when first launching into the lua console. This allows you to define custom functions and aliases that you can use in the console. For example, you can define a function called myfunc
in init.lua
and then call it from the lua console with myfunc()
. You can also do things like auto-load into a specific save state or configure the engine state by toggling overlays/logic etc (or loading a particular engine state).
If you are using Visual Studio Code for editing files in your local StardewTAS/Scripts
folder, I recommend installing the Lua language server extension to get type annotations and autocomplete for Lua. To include all the base engine lua files, open the workspace settings (Shift + Command + P (Mac) / Ctrl + Shift + P (Windows/Linux) to open the command palette) and search for lua.workspace.library
, click Add Item, and then paste the path to the lua
folder from the mod install.
Default Steam install paths (if you are on linux let me know the path!):
- Mac:
~/Library/Application Support/Steam/steamapps/common/Stardew Valley/Contents/MacOS/Mods/TASMod/assets/lua/
- Windows:
C:\Program Files (x86)\Steam\steamapps\common\Stardew Valley\Mods\TASMod\assets\lua\
You don't need to do this (the mod will correctly link the files), but it will give you intellisense for the base engine code.
advance({keyboard={keys to press}, mouse={X=int, Y=int, left=bool, right=bool}})
- advance a frame with the given keyboard/mouse inputs. This should then pause while any existing automation is running. Example for holding down and right and clicking the mouse:
advance({keyboard={Keys.S, Keys.D}, mouse={X=100, Y=100, left=true}})
- Global frame stack
current_frame()
- returns the current frame actual framepush(f)
- pushes a frame onto the frame stackpush()
orgcf()
- pushes the current frame onto the frame stackf = pop()
- pops a frame off the frame stackrw()
- rewinds to the frame on the top of the frame stackbrw()
- blocking rewind to the frame on the top of the frame stackframe_stack_clear()
- clears the frame stackpgcf()
- print the global frame stack
- reset functions (blocking forces lua to wait until the reset is complete, others can occur async)
reset()
- reset to the current framefreset()
- fast reset to the current framereset(f)
- reset to the given framefreset(f)
- fast reset to the given framebreset()
- blocking reset to the current framebreset(f)
- blocking reset to the given framebfreset()
- blocking fast reset to the current framebfreset(f)
- blocking fast reset to the given frame
- save state functions
save()
- save the current state to filesaveas(f)
orsave(f)
- save the current state to a new fileload(f)
- load a save state and advance to final framefload(f)
- load a save state and fast advance to final frameview()
- swap between view modesexec("...")
- execute a command on the base console (e.g.exec("overlay off Layers")
)
There's a ton more but there's a whole generated set of docs for the lua engine that you can find in the docs folder.
Any function that is callable through this top level console has some help text associated with its use, and you can discover different tools through the list command.
help
- allows you to check command description/usagelist
- lists available overlays/logics/commands, to find available optionsoverlay
- print or modify the status of TAS overlayslogic
- print or modify the status of TAS automation logicclr
- clear the current console screenexit
- exit the game
Tries to mimic basic linux command line methods
ls
- list save states (allows for wildcard search)cp
- copy save state to new filerm
- delete a save state filemv
- rename a save state file
Basic functions for manipulating the save state including loading, saving, and resetting.
frame
- print the current framestateinfo
- print some details about the current save statereset
- reset to the desired framefreset
- fast reset to the desired frameload
- load a save state and advance to final framefload
- load a save state and fast advance to final framesave
- save the current state to filesaveas
- save the current state to a new filenewgame
- setup a new save state file and fill in detailsswapseed
- swap the seed of the current save state
Engine state is the current state of overlays/logics. You can save different configurations if you find that you often want to switch between different setups.
saveengine
- save the current engine state to fileloadengine
- load engine state from filealias
- allows you to define custom commands based on other commandsalias set ss=screenshot
will setss
to call thescreenshot
function
genpath
- generates a nav path to a tilewalkpath
- walk the current nav path (activates theWalkPath
logic)
forage
- print current details about forage (defaults to current location, define specificforage loc
orforage all
)friendship
- prints current friendship detailsplayer
- prints details on player including xp/friendship/pos/etctrashcans
- prints current trash can drops
sethayday
- sets the date for theWheatHay
overlayblankscreen
- turns the screen blackscreenshot
- screenshot the current game screen (stored in the StardewTAS folder)takestep
- take N steps in a direction (activates theTakeStep
logic)
Tools for automated frame advance through common actions
AcceptSleep
- auto advance when the frame for the sleep menu is popping up and approve the sleep questionAdvanceFrozen
- advance when character is frozen/picking up an artifact/sleeping emotingAnimationCancel
- advance through frames after swing up to the first cancel frameDialogueBox
- advance to the frame where you can click a dialogue boxDialogueBoxTransition
- advance through frames where a dialogue box is transitioning on/off the screenGhostCancel
- walk like a ghost (without taking a step)LevelUpMenu
- advance through level up menu (does not advance profession select)SaveGame
- advance through the save game menuScreenFade
- advance through frames where the screen is fading in and out of blackShippingMenu
- holds the mouse and advances through shipping menuSkipEvent
- skips events or advances through pause frames up during an event/requires dialogue interactionSwipePickup
- swing cancel pickup an item if melee weapon in inventory (will swap tools suboptimally)TakeStep
- walk N steps in a directionWalkPath
- attempt to walk the current nav path automatically (will be suboptimal vs manual, may panic out)
To implement a new Automation, create a new class that inherits from IAutomatedLogic
. All classes that inherit from IAutomatedLogic
will be automatically loaded and available in Controller.Logics
.
Additional info layers to draw on top of the game
Clay
- draw the clay tilling mapClickableMenuRects
- show outlines of clickable screen elements in menusCropQuality
- draw first gold quality day for a tileDrawPath
- draw the current nav pathFishing
- draw a simplified view of the fishing minigame including where the fish wants to goGrid
- draw the tile grid outlinesHitbox
- draw hitboxes for all charactersInfoPanel
- draw a bunch of random game state detailsLayers
- highlight all of the unwalkable tilesMinesLadder
- draw rock break counts and path to nearest ladderMixedSeed
- overlay the seed you'll get if you plant a mixed seed on the next frameMonsterDrop
- displays items a monster will dropMouse
- draw your actual mouse onto the screenMouseData
- draws tile, steps, ticks at mouse positionObjectDrop
- draw what items an object will dropObjectTiles
- draw boundaries around objectsSleep
- draw sleep details given current step countTileHighlight
- draw highlighted tilesTimerPanel
- draw a timer panel in the top left cornerWeaponGuide
- draw a guide for weapon hitboxesWheatHay
- draw tiles where wheat will give hay if harvested on a specific day
To implement a new Overlay, create a new class that inherits from IOverlay
. All classes that inherit from IOverlay
will be automatically loaded and available in Controller.Overlays
.
A ton of harmony patches (including patching SMAPI inputs and base System.DateTime and System.Random) to rewrap functionality and control all parts of the update/draw loop. Added some additional fields to System.Random to trace random calls for debugging purposes.
If you have Stardew installed at a non-standard location, you'll need to modify the StardewModConfig build config which can be found at:
C:\Users\<User>\.nuget\packages\pathoschild.stardew.modbuildconfig\4.1.0\build\find-game-folder.targets
NOTE: you may need to try building and failing once before this file will exist.
At the bottom of the file you can add
<GamePath Condition="!Exists('$(GamePath)')">Path-To-Stardew-Directory</GamePath>
(Thanks to @PianoAddict for finding these details!)
This project uses LDoc to generate documentation for the lua files. To generate the docs, run the following command from the root directory of the project:
ldoc .
You'll need Lua/LuaRocks installed to run this command, which will vary by system. On Mac you can install Lua/LuaRocks with the following command:
brew install lua luarocks
luarocks install penlight
luarocks install ldoc
Looking for someone on windows to give guidance on how to install Lua/LuaRocks :).