Skip to content

Commit

Permalink
Restore Inventory (#15)
Browse files Browse the repository at this point in the history
* pmdm

* clean up

* clang-format
  • Loading branch information
Pistonight authored Sep 8, 2024
1 parent 4f12886 commit 3dcdd4a
Show file tree
Hide file tree
Showing 44 changed files with 435 additions and 1,806 deletions.
74 changes: 1 addition & 73 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,75 +1,3 @@
---
Language: Cpp
IndentWidth: 4
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 100
CommentPragmas: '^ (IWYU pragma:|NOLINT)'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ForEachMacros: []
IncludeCategories:
- Regex: '^<[Ww]indows\.h>$'
Priority: 1
- Regex: '^<'
Priority: 2
- Regex: '^"'
Priority: 3
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 4
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: c++17
TabWidth: 4
UseTab: Never
WhitespaceSensitiveMacros: ["SEAD_ENUM", "SEAD_ENUM_EX", "SEAD_ENUM_EX_VALUES"]
...
2 changes: 1 addition & 1 deletion .clangd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CompileFlags:
Compiler: /usr/bin/g++
CompilationDatabase: ./target/megaton/none/
CompilationDatabase: ./target/megaton/debug/
Remove: [ -march=*, -mtune=*, -mtp=* ]
Diagnostics:
Suppress:
Expand Down
46 changes: 25 additions & 21 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
# name: Main
#
# on:
# push:
# branches:
# - main
# pull_request:
# branches:
# - main
#
# jobs:
# check:
# name: Check
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - uses: arduino/setup-task@v2
# with:
# version: 3.x
# repo-token: ${{ secrets.GITHUB_TOKEN }}
# - run: task check # installing clang-format 18 is too annoying
name: Main

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
recursive: true
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- uses: DoozyX/[email protected]
with:
source: 'src'
clangFormatVersion: 18
11 changes: 9 additions & 2 deletions Megaton.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@ title-id = 0x01007ef00011e000
entry = "exl_module_init"
sources = [
"src",
"libs/exlaunch/source"
"libs/exlaunch/source",
"libs/botw-symbols/src",
]
includes = [
"src",
"libs/botw/src",
"libs/botw/lib/agl/include",
"libs/botw/lib/gsys/include",
"libs/botw-symbols/src",
"libs/exlaunch/source",
"libs/sead/include",
"libs/nnheaders/include",
]
ldscripts = [
"libs/exlaunch/misc/link.ld",
"libs/botw-symbols/ld/ld160.ld",
"link.ld",
"libs/botw-symbols/ld/toolkit160.ld",
]

[build.flags]
Expand All @@ -48,6 +50,11 @@ cxx = [
"-Wno-invalid-offsetof",
]

[build.profiles.debug.flags]
c = [
"-DBOTWTOOLKIT_TCP_SEND",
]

[check]
ignore = [
".data",
Expand Down
52 changes: 44 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# botw-save-state
A BOTW 1.6.0 Switch save state mod for speedrun practices
![Build Badge](https://img.shields.io/github/check-runs/Pistonight/botw-save-state/main)
![Issue Badge](https://img.shields.io/github/issues/Pistonight/botw-save-state)
![Downloads Badge](https://img.shields.io/github/downloads/Pistonight/botw-save-state/total)

A BOTW 1.6.0 Switch save-state mod for speedrun practices

## Install
**Migration from 1.x - See [here](./migrate-1.x.md)**
Expand Down Expand Up @@ -47,6 +51,8 @@ Restored state from memory
**New in 2.0**: As long as you don't release all the keys, the mod will keep resetting Link's position, allowing for a more accurate restore while in ragdoll state.
For example, with the default restore combo, I typically release the other 3 keys and hold `Plus` for slightly longer until position is fully restored.

If you see errors, please see trouble shooting below.

### Settings
Hold all triggers (`ZL + L + ZR + R`) and the whistle button (`Dpad Down`) for 3 seconds to enter setting mode. You should see the setting menu pop up in the top-right corner.
Use the dpad to navigate the menu and `A` to select. Use `B` to go back a level or exit the settings.
Expand All @@ -65,7 +71,8 @@ Since 2.0, you can now toggle individually what you want to save/restore. Open t

**Recommended (TL;DR)**:
- Keep `Timers` enabled as they don't have negative effects
- If you don't need to track durability during practice (i.e. Any%), you can disable `Overworld Durability` and `Inventory` to avoid accidental durability transfer
- If you don't need to track inventory during practice, you can disable `Inventory` to avoid issues.
- Having it on can still have benefits, for example you don't need to swap equipments after restoring for Any%

**Full List**:
1. `Restore Message`
Expand All @@ -89,13 +96,13 @@ Since 2.0, you can now toggle individually what you want to save/restore. Open t
- Flame Resist
- Shock Resist
- Stealth
3. `Overworld Durability`
- When enabled, the name and durability of equipped Weapon, Bow and Shield will be saved.
- When restoring, the durability of equipped Weapon/Bow/Shield will only be restored if the same item by name is equipped (not necessarily the same one).
- Note that the inventory durability is not restored unless you also enable `Inventory`
4. `Inventory` enables:
- Equipped durability of Weapon, Bow, Shield and Arrow (similar to `Overworld Durability`, only restored if the same item is equipped)
3. `Inventory` enables:
- (Since v2.1) All your items and their states in the inventory, including but not limited to:
- Number of offset slots for IST
- GameData will be synced
- Equipped items in the overworld will be synced if a quick menu is open. If not, they will be synced the next time you open the quick menu.
- Number of offset slots for IST
- (Since v2.1) This is a stored in its own field, so you can edit this value and break slots easily like in

The following will always be enabled, and you cannot turn them off:
- Current Health
Expand All @@ -118,6 +125,35 @@ You can use this [python script](./scripts/ftp.py) to transfer save state files

(This has nothing to do in game, just makes managing the save state files generated by the mod easier)

## Troubleshooting & FAQ

#### Q: The mod is not showing in SimpleModManager
When you download the release `zip`, there are 2 folders `mods` and `botwsavs`. Make sure to
copy these to the **root** of the SD card, and overwrite existing files. Do NOT put them in any subfolders.

#### Q: I installed but it's not working in game
Please check the following:
- The title screen should show the version as `1.6.0-SSx.y` where `x.y` is the version of the mod.
- When you load a save, after walking around for a few seconds, there will be a welcome message displayed on the top-right corner.

If you have these working, then the mod is active, and you likely are not pressing the key combos correctly. Make sure to only
press the keys set. For example, if your binding is `A+B`, then pressing `A+B+Y` will not work.

#### Q: Restore is showing error
Try restarting the game. The mod uses raw memory access to save/restore the state and has protection against invalid memory access.
There is a small chance that when the game boots, the values are not in the usual location.

#### Q: I'm stuck after restoring
Don't restore in water or on a ladder.

#### Q: Crash
Please open an issue and upload the crash report found in `/atmosphere/crash_reports/<timestamp>.log`, where `<timestamp>` is a number.
The greatest number is the most recent crash.

#### Q: Will there be support for TOTK?
Making a mod like this requires an insane amount of research, and I was lucky to have Bloom do most of it
for BOTW. I don't really have the time and energy to think about TOTK right now.

## Developer
**This section is intended for developers**

Expand Down
31 changes: 18 additions & 13 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
version: '3'

env:
CONSOLE_ADDR: 192.168.0.161:5000 # can be overriden in .env
# can be overriden in .env
CONSOLE_ADDR: 192.168.0.161:5000
DEBUG_ADDR: 192.168.0.161:5001
dotenv: [".env"]

includes:
symbols:
aliases: [sym]
taskfile: libs/botw-symbols
dir: libs/botw-symbols

tasks:
build:
aliases: [b]
desc: Build the mod
cmds:
- megaton
- megaton -p debug

check:
desc: Check code for errors
cmds:
- clang-format -n -Werror src/**/*.cpp
- clang-format -n -Werror src/**/*.hpp
- clang-format -n -Werror src/**/*.h
- clang-format -n -Werror $(find src -name '*.cpp' -o -name '*.hpp')

fix:
desc: Fix errors in code
cmds:
- clang-format -i src/**/*.cpp
- clang-format -i src/**/*.hpp
- clang-format -i src/**/*.h
- clang-format -i $(find src -name '*.cpp' -o -name '*.hpp')

package:
desc: Package the build for release
deps: [build]
vars:
VERSION: "SS2.0"
VERSION: "SS2.1"
MOD_DIR: "target/package/mods/The Legend of Zelda - Breath of the Wild/Save State/contents/01007EF00011E000"
cmds:
- megaton -p none
- rm -rf target/package/mods
- mkdir -p "{{.MOD_DIR}}/exefs"
- mkdir -p "{{.MOD_DIR}}/romfs/System"
- cp target/megaton/none/main.npdm "{{.MOD_DIR}}/exefs/main.npdm"
- cp target/megaton/none/make/botwsavs.nso "{{.MOD_DIR}}/exefs/subsdk9"
- cp target/megaton/none/botwsavs.nso "{{.MOD_DIR}}/exefs/subsdk9"
- mkdir -p target/package/botwsavs
- echo "" > target/package/botwsavs/latest.txt
- echo -n "1.6.0-{{.VERSION}}" > "{{.MOD_DIR}}/romfs/System/Version.txt"
Expand All @@ -54,5 +58,6 @@ tasks:
- mkdir -p target/crash_reports/dumps
- lftp $CONSOLE_ADDR < scripts/lftp-download.sh



debug:
cmds:
- python libs/botw-symbols/tcp-client.py $DEBUG_ADDR
2 changes: 1 addition & 1 deletion libs/botw-symbols
Submodule botw-symbols updated 46 files
+3 −0 .clang-format
+21 −0 .github/workflows/check.yml
+1 −4 .gitignore
+25 −33 README.md
+18 −0 Taskfile.yml
+1 −1 badges/150.json
+1 −1 badges/160.json
+2 −0 ld/ld150.ld
+5 −0 ld/ld160.ld
+0 −3 ld/ld160_stubs.ld
+3 −0 ld/toolkit150.ld
+13 −0 ld/toolkit160.ld
+5 −3 listing_160.csv
+102 −0 src/toolkit/equipment.cpp
+21 −0 src/toolkit/equipment.hpp
+67 −0 src/toolkit/io/data_reader.cpp
+106 −0 src/toolkit/io/data_reader.hpp
+64 −0 src/toolkit/io/data_writer.cpp
+108 −0 src/toolkit/io/data_writer.hpp
+114 −0 src/toolkit/io/file.cpp
+43 −0 src/toolkit/io/file.hpp
+53 −0 src/toolkit/mem/internal_ptr.hpp
+18 −0 src/toolkit/mem/mem.cpp
+79 −0 src/toolkit/mem/mem_ptr.hpp
+42 −0 src/toolkit/mem/named_value.hpp
+93 −0 src/toolkit/mem/safe_ptr.hpp
+122 −0 src/toolkit/mem/string.hpp
+27 −0 src/toolkit/mem/unique_ptr.hpp
+66 −0 src/toolkit/msg/info.cpp
+35 −0 src/toolkit/msg/info.hpp
+38 −0 src/toolkit/msg/loader_hook.cpp
+17 −0 src/toolkit/msg/loader_hook.hpp
+140 −0 src/toolkit/msg/widget.cpp
+61 −0 src/toolkit/msg/widget.hpp
+510 −0 src/toolkit/pmdm.cpp
+146 −0 src/toolkit/pmdm.hpp
+27 −0 src/toolkit/scoped_lock.hpp
+20 −0 src/toolkit/sead/list.cpp
+17 −0 src/toolkit/sead/list.hpp
+46 −0 src/toolkit/sead/safe_string.cpp
+158 −0 src/toolkit/tcp.cpp
+57 −0 src/toolkit/tcp.hpp
+26 −0 tcp-client.py
+3 −0 toolkit_150.csv
+13 −0 toolkit_160.csv
+147 −95 update.py
7 changes: 0 additions & 7 deletions link.ld

This file was deleted.

4 changes: 2 additions & 2 deletions scripts/lftp-upload.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mkdir -p -f /atmosphere/contents/01007EF00011E000/exefs
cd /atmosphere/contents/01007EF00011E000/exefs
mput -e target/megaton/none/botwsavs.nso
mput -e target/megaton/none/main.npdm
mput -e target/megaton/debug/botwsavs.nso
mput -e target/megaton/debug/main.npdm
rm -f subsdk9
mv botwsavs.nso subsdk9
Loading

0 comments on commit 3dcdd4a

Please sign in to comment.