mirror of
https://github.com/libretro/ludo.git
synced 2026-11-07 17:27:59 -10:00
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
// 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 (
|
|
"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 := os.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 := os.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
|
|
}
|