Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new "Gecko" Build Type #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

$ IDE stuff
.idea/
.vscode

# Test binary, build with `go test -c`
*.test
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ I feel like it's easiest to lead by example. The `codes.json` file is relatively
```
#### Real example
For a more complex example view the [codes.json file](https://github.com/project-slippi/project-slippi/blob/15533b366d3fad0ec3dae9e9c66794696c1f2624/Gecko%20Codes/codes.json) in my project and the resulting [CodeList.txt file](https://github.com/project-slippi/project-slippi/blob/15533b366d3fad0ec3dae9e9c66794696c1f2624/Gecko%20Codes/CodeList.txt)

#### Even more examples
Look at `build.json` on `./examples` directory, you can execute them from the root of the project by running this on the console:
```
.\gecko build -c .\gecko\buid.json
```

#### Relative paths
I haven't tested this but it should be possible to define relative paths for `sourceFile` and `outputFile` if you have a nested directory structure.
#### File watchers
Expand Down
6 changes: 6 additions & 0 deletions examples/asm/Rumble Off/Rumble Off.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
################################################################################
# Address: 803d4a70
################################################################################

.long 0x00000000

Binary file added examples/bin/FasterMeleeSettings/4Stocks.bin
Binary file not shown.
64 changes: 64 additions & 0 deletions examples/buid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"outputFiles": [
{
"file": "examples/output/codes.gct"
},
{
"file": "examples/output/codes.ini"
},
{
"file": "examples/output/codes.bin"
}
],
"codes": [
{
"name": "ASM Codes",
"authors": [],
"description": [],
"build": [
{
"type": "injectFolder",
"isRecursive": true,
"sourceFolder": "examples/asm",
"annotation": "Rumble Off [UnclePunch]"
}
]
},
{
"name": "Bin Codes",
"authors": [],
"description": [],
"build": [
{
"type": "binary",
"sourceFile": "examples/bin/FasterMeleeSettings/4Stocks.bin",
"annotation": "4 Stocks [Magus]"
}
]
},
{
"name": "GCT Codes",
"authors": [],
"description": [],
"build": [
{
"type": "binary",
"sourceFile": "examples/gct/FreezeGlitchFix.gct",
"annotation": "Prevent freeze glitch [tauKhan]"
}
]
},
{
"name": "Text Codes",
"authors": [],
"description": [],
"build": [
{
"type": "gecko",
"sourceFile": "examples/text/LocalPlayerTag.ini"
}
]
}
]
}

Binary file added examples/gct/FreezeGlitchFix.gct
Binary file not shown.
Binary file added examples/output/codes.bin
Binary file not shown.
Binary file added examples/output/codes.gct
Binary file not shown.
40 changes: 40 additions & 0 deletions examples/output/codes.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
$ASM Codes []
043D4A70 00000000 #examples/asm/Rumble Off/Rumble Off.asm

$Bin Codes []
043D4A4C 04000A00 #4 Stocks [Magus]

$GCT Codes []
00D0C0DE 00D0C0DE #Prevent freeze glitch [tauKhan]
041239A8 60000000
F0000000 00000000

$Text Codes []
$Optional: Force Nametag for Local Player [Fizzi]
*When playing online, nametag YOU will show above your character ---------------------
*Will not cause desyncs when playing online
C20355B4 00000008 #Online/Optional/IndicateLocalPlayer/ForceLocalPlayerTag.asm
3C608048 80639D30
5463443E 2C030208
40820028 806DB61C
88630000 7C03F800
40820018 38600000
3D808003 618C55CC
7D8903A6 4E800420
1C9F0E90 00000000
C22FD1EC 0000000E #Online/Optional/IndicateLocalPlayer/SetLocalPlayerTag.asm
48000010 4E800021
8278826E 82740000
3C608048 80639D30
5463443E 2C030208
40820020 806DB61C
88630000 7C03D800
40820010 4BFFFFD1
7C6802A6 4800002C
7F63DB78 3D808003
618C556C 7D8903A6
4E800421 5463063E
3D808023 618C754C
7D8903A6 4E800421
60000000 00000000

27 changes: 27 additions & 0 deletions examples/text/LocalPlayerTag.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
$Optional: Force Nametag for Local Player [Fizzi]
*When playing online, nametag YOU will show above your character ---------------------
*Will not cause desyncs when playing online
C20355B4 00000008 #Online/Optional/IndicateLocalPlayer/ForceLocalPlayerTag.asm
3C608048 80639D30
5463443E 2C030208
40820028 806DB61C
88630000 7C03F800
40820018 38600000
3D808003 618C55CC
7D8903A6 4E800420
1C9F0E90 00000000
C22FD1EC 0000000E #Online/Optional/IndicateLocalPlayer/SetLocalPlayerTag.asm
48000010 4E800021
8278826E 82740000
3C608048 80639D30
5463443E 2C030208
40820020 806DB61C
88630000 7C03D800
40820010 4BFFFFD1
7C6802A6 4800002C
7F63DB78 3D808003
618C556C 7D8903A6
4E800421 5463063E
3D808023 618C754C
7D8903A6 4E800421
60000000 00000000
37 changes: 34 additions & 3 deletions gecko.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"
"sort"
"strconv"
Expand Down Expand Up @@ -62,6 +63,7 @@ const (
InjectFolder = "injectFolder"
ReplaceBinary = "replaceBinary"
Binary = "binary"
Gecko = "gecko"
)

type assemblerArgConfig struct {
Expand Down Expand Up @@ -264,6 +266,10 @@ func generateCodeLines(desc CodeDescription) []string {
lines := generateBinaryLines(geckoCode.SourceFile)
lines[0] = addLineAnnotation(lines[0], geckoCode.Annotation)
result = append(result, lines...)
case Gecko:
lines := generateGeckoLines(geckoCode.SourceFile, geckoCode.Annotation)
lines[0] = addLineAnnotation(lines[0], geckoCode.Annotation)
result = append(result, lines...)
case Branch:
fallthrough
case BranchAndLink:
Expand Down Expand Up @@ -638,6 +644,31 @@ func generateBinaryLines(file string) []string {
return lines
}

func generateGeckoLines(file string, annotation string) []string {

contents, err := ioutil.ReadFile(file)
if err != nil {
log.Panicf("Failed to read binary file %s\n%s\n", file, err.Error())
}

instructions := contents

if len(instructions) == 0 {
log.Panicf("Binary file must not be empty: %s\n", file)
}

lines := []string{}

if len(annotation) != 0 {
reg := regexp.MustCompile(`/[A-F0-9]{8} [A-F0-9]{8}/g`)
lines = reg.FindAllString(string(contents), -1)
} else {
lines = strings.Split(string(contents), `\n`)
}

return lines
}

func compile(file, addressExp string) ([]byte, string) {
fileExt := filepath.Ext(file)
outputFilePath := file[0:len(file)-len(fileExt)] + ".out"
Expand Down Expand Up @@ -712,14 +743,14 @@ func compile(file, addressExp string) ([]byte, string) {
if aserr != nil || objcopyerr != nil {
// Add $DEVKITPPC/bin to $PATH and try again
if envDEVKITPPC, exists := os.LookupEnv("DEVKITPPC"); exists {
os.Setenv("PATH", envDEVKITPPC + "/bin" + ":" + os.Getenv("PATH"));
os.Setenv("PATH", envDEVKITPPC+"/bin"+":"+os.Getenv("PATH"))
_, err := exec.LookPath(asCmdLinux)
if err != nil {
log.Panicf("%s not available in $PATH. You may need to install devkitPPC", asCmdLinux)
log.Panicf("%s not available in $PATH. You may need to install devkitPPC", asCmdLinux)
}
_, err = exec.LookPath(objcopyCmdLinux)
if err != nil {
log.Panicf("%s not available in $PATH. You may need to install devkitPPC", objcopyCmdLinux)
log.Panicf("%s not available in $PATH. You may need to install devkitPPC", objcopyCmdLinux)
}
} else {
log.Panicf("%s and %s are not available in $PATH, and $DEVKITPPC has not been set. You may need to install devkit-env", asCmdLinux, objcopyCmdLinux)
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module main

go 1.16