-
Notifications
You must be signed in to change notification settings - Fork 68
/
patch.go
47 lines (39 loc) · 1.1 KB
/
patch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Package patch allows softpatching ROMs based on the presence of a patch file
// next to the ROM. This is useful to apply fan translations without altering
// No-Intro ROMs. Softpatching only works for cores where NeedFullPath is false.
package patch
import (
"io/ioutil"
"os"
"path/filepath"
"strings"
)
// Try to apply different patches located next to the game
// Currently only .ups is supported
func Try(gamePath string, bytes []byte) (*[]byte, error) {
upsFile := strings.TrimSuffix(gamePath, filepath.Ext(gamePath)) + ".ups"
if _, err := os.Stat(upsFile); !os.IsNotExist(err) {
pbytes, err := ioutil.ReadFile(upsFile)
if err != nil {
return nil, err
}
patched, err := applyUPS(pbytes, bytes)
if err != nil {
return nil, err
}
return patched, nil
}
ipsFile := strings.TrimSuffix(gamePath, filepath.Ext(gamePath)) + ".ips"
if _, err := os.Stat(ipsFile); !os.IsNotExist(err) {
pbytes, err := ioutil.ReadFile(ipsFile)
if err != nil {
return nil, err
}
patched, err := applyIPS(pbytes, bytes)
if err != nil {
return nil, err
}
return patched, nil
}
return nil, nil
}