Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

Commit

Permalink
Fix issue with writing bytes outside of range
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniruKun committed Jun 29, 2022
1 parent b08b86e commit 414d5ac
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/bin
*.dat
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ This is a small tool to import [HoloCure](https://kay-yu.itch.io/holocure) save

## Download

TODO
Grab a release from [Releases](https://github.com/DaniruKun/tasukeru/releases) and save it anywhere on your PC.
Pick the executable matching your architecture (note: HoloCure currently only runs on Windows).

## Usage

1. Build a release by running `make` or download a release for your platform from Releases
1. Build a release by running `make` or download a release for your platform from [Releases](https://github.com/DaniruKun/tasukeru/releases)
2. Get the save file from the source PC at `Users\[your username]\AppData\Local\HoloCure\save.dat` and move it to the target PC
3. Play HoloCure **at least once** one the target PC
4. On the target PC, drag and drop the `save.dat` onto `tasukeru-*.exe`
Expand Down
20 changes: 15 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

const defaultSaveFileName = "save.dat"
const version = "0.1"
const version = "0.2"

func check(e error) {
if e != nil {
Expand Down Expand Up @@ -46,6 +46,8 @@ func holoCureSaveFilePath() string {
return filepath.Join(dir, "HoloCure", defaultSaveFileName)
}

// generally it seems that the start offset will always be the same
// across machines, but safer to find save block dynamically
func getSettingsStartEnd(srcDec *[]byte) (start, end int) {
for offset, char := range *srcDec {
if char == 0x7B && (*srcDec)[offset+1] == 0x20 {
Expand Down Expand Up @@ -82,8 +84,8 @@ func main() {

start, end = getSettingsStartEnd(&srcDec)

srcSettingsJson := srcDec[start : end+1]
fmt.Println("source save:", string(srcSettingsJson))
srcSaveBlock := srcDec[start : end+1]
fmt.Println("source save:", string(srcSaveBlock))

var targetFilePath string

Expand All @@ -100,8 +102,15 @@ func main() {

start, _ = getSettingsStartEnd(&targetDec)

for i, char := range srcSettingsJson {
targetDec[start+i] = char
// iterate over the source save block and overwrite the dst save block with its data
for i, char := range srcSaveBlock {
targetOffset := start + i

if targetOffset >= len(targetDec) {
targetDec = append(targetDec, char)
} else {
targetDec[targetOffset] = char
}
}

fmt.Println("patched save:", string(targetDec))
Expand All @@ -114,6 +123,7 @@ func main() {
err = os.WriteFile(holoCureSaveFilePath(), []byte(targetEnc), 0644)
check(err)
fmt.Println("save file imported succesfully!")
prompter.YN("Press Enter to quit", true)
}

}

0 comments on commit 414d5ac

Please sign in to comment.