Created
July 31, 2015 21:42
-
-
Save diamondo25/4c7813aebd23743f9691 to your computer and use it in GitHub Desktop.
Golang MapleStory ManualPatcher patchfile exporter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"encoding/binary" | |
"encoding/hex" | |
"errors" | |
"flag" | |
"fmt" | |
"io" | |
"io/ioutil" | |
"os" | |
) | |
func main() { | |
var input string | |
flag.StringVar(&input, "input", "", "Input file") | |
flag.Parse() | |
if input == "" { | |
fmt.Println("Try again") | |
return | |
} | |
file, err := os.Open(input) | |
if err != nil { | |
panic(err) | |
} | |
newPos, err := file.Seek(0, os.SEEK_END) | |
if err != nil { | |
panic(err) | |
} | |
newPos -= 12 | |
b := make([]byte, 12) | |
_, err = file.ReadAt(b, newPos) | |
if err != nil && err != io.EOF { | |
panic(err) | |
} | |
fmt.Println(hex.Dump(b)) | |
buf := bytes.NewReader(b) | |
var patchfileSize, noticeSize uint32 | |
if err := binary.Read(buf, binary.LittleEndian, &patchfileSize); err != nil { | |
panic(err) | |
} | |
if err := binary.Read(buf, binary.LittleEndian, ¬iceSize); err != nil { | |
panic(err) | |
} | |
if b[8] != 0xF3 || b[9] != 0xFB || b[10] != 0xF7 || b[11] != 0xF2 { | |
panic(errors.New("Not a valid manualpatcher (incorrect magic value)")) | |
} | |
fmt.Println("Patch notice length: ", noticeSize) | |
fmt.Println("Patch file size: ", patchfileSize) | |
// Read notice | |
b = make([]byte, noticeSize) | |
newPos -= int64(noticeSize) | |
_, err = file.ReadAt(b, newPos) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println("Notice:") | |
fmt.Println("----------------------") | |
fmt.Println(string(b)) | |
fmt.Println("----------------------") | |
// Read patchfile | |
b = make([]byte, patchfileSize) | |
newPos -= int64(patchfileSize) | |
_, err = file.ReadAt(b, newPos) | |
if err != nil { | |
panic(err) | |
} | |
ioutil.WriteFile(input+".patch", b, 0644) | |
fmt.Println("Done.") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment