Created
July 1, 2014 13:48
-
-
Save gabstv/999e797a05dddb1b6126 to your computer and use it in GitHub Desktop.
Unofficial Portal 2 patch for mac. It fixes the issue that crashes the game when turrets are firing.
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" | |
"crypto/md5" | |
"encoding/hex" | |
"fmt" | |
"io" | |
"os" | |
"os/user" | |
"path" | |
) | |
func main() { | |
fmt.Println("\n\nPORTAL2 studiorender.dylib unofficial Mac PATCH") | |
fmt.Println("by gabstv") | |
fmt.Println("---------") | |
usr, _ := user.Current() | |
dylp := path.Join(usr.HomeDir, "/Library/Application Support/Steam/SteamApps/common/Portal 2/bin/studiorender.dylib") | |
if _, err := os.Stat(dylp); err != nil { | |
fmt.Println("Could not apply patch!", err.Error()) | |
return | |
} | |
md, _ := MD5(dylp) | |
applied := []byte{224, 0, 65, 149, 230, 133, 81, 175, 33, 138, 18, 229, 20, 46, 236, 163} | |
pattern := []byte{108, 51, 233, 81, 137, 246, 133, 129, 222, 59, 79, 75, 64, 7, 146, 125} | |
if bytes.Compare(applied, md) == 0 { | |
fmt.Println("Patch is already applied!") | |
return | |
} | |
if bytes.Compare(pattern, md) != 0 { | |
fmt.Printf("Could not apply patch! MD5 checksum mismatch: (studiorender.dylib: %s) != %s\n", hex.EncodeToString(md), hex.EncodeToString(pattern)) | |
return | |
} | |
dir, fil := path.Split(dylp) | |
// write a backup | |
ext := path.Ext(fil) | |
backupn := fil[:(len(fil)-len(ext))] + "_backup" + ext | |
backupf, err := os.OpenFile(path.Join(dir, backupn), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666) | |
if err != nil { | |
fmt.Println("Could not apply patch!", err.Error()) | |
return | |
} | |
defer backupf.Close() | |
original, err := os.OpenFile(dylp, os.O_RDWR, 0666) | |
if err != nil { | |
fmt.Println("Could not apply patch!", err.Error()) | |
return | |
} | |
defer original.Close() | |
io.Copy(backupf, original) | |
fmt.Println("studiorender.dylib backup file written") | |
_, err = original.Seek(0x64f0, 0) | |
if err != nil { | |
fmt.Println("Could not apply patch!", err.Error()) | |
return | |
} | |
original.Write([]byte{0xC3}) | |
fmt.Println("PORTAL2 PATCH APPLIED!\n\n") | |
} | |
func MD5(path string) ([]byte, error) { | |
h := md5.New() | |
f, err := os.Open(path) | |
if err != nil { | |
return nil, err | |
} | |
_, err = io.Copy(h, f) | |
if err != nil { | |
return nil, err | |
} | |
return h.Sum(nil), nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment