Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
IlliaYalovoi committed Jul 15, 2023
1 parent 64b44d7 commit f2ccac2
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 20 deletions.
35 changes: 29 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,37 @@ import (
"github.com/manifoldco/promptui"
)

var debugMode = false

func main() {

prompt := promptui.Select{
Label: "Select game to patch",
Items: []string{"Europa Universalis IV", "Hearts of Iron IV"},
OS := runtime.GOOS

if debugMode {

promptOSChoice := promptui.Select{
Label: fmt.Sprintf("Choose desired OS"),
Items: []string{"Windows", "Linux", "Darwin"},
HideHelp: true,
}
_, desiredOS, _ := promptOSChoice.Run()

switch desiredOS {
case "windows":
OS = "windows"
case "linux":
OS = "linux"
case "darwin":
OS = "darwin"
}
}
promptGame := promptui.Select{
Label: "Select game to patch",
Items: []string{"Europa Universalis IV", "Hearts of Iron IV"},
HideHelp: true,
}

_, result, err := prompt.Run()
_, result, err := promptGame.Run()

if err != nil {
fmt.Printf("Prompt failed %v\n", err)
Expand All @@ -23,9 +46,9 @@ func main() {

switch result {
case "Europa Universalis IV":
err = applyPatch(false, "eu4", runtime.GOOS)
err = applyPatch(debugMode, "eu4", OS)
case "Hearts of Iron IV":
err = applyPatch(false, "hoi4", runtime.GOOS)
err = applyPatch(debugMode, "hoi4", OS)
}

if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func applyPatch(test bool, originalFileName, OS string) error {
hexWantedEU4Windows := []string{"48", "8D", "0D", "??", "??", "??", "01", "E8", "??", "??", "??", "01", "31", "C0", "0F", "94", "C3", "E8"}
hexExistsEU4Linux := []string{"E8", "65", "95", "E5", "FF", "89", "C3", "E8", "38", "08", "EC", "FF", "31", "F6", "85", "DB", "40", "0F", "94", "C6", "48", "89", "C7"}
hexWantedEU4Linux := []string{"E8", "65", "95", "E5", "FF", "89", "C3", "E8", "38", "08", "EC", "FF", "31", "F6", "31", "DB", "40", "0F", "94", "C6", "48", "89", "C7"}
hexExistsEU4Darwin := []string{"E8", "7A", "C5", "76", "01", "89", "01", "89", "C3", "E8", "93", "A6", "EC", "FF", "31", "F6", "85", "DB", "40", "0F", "94", "C6", "48", "89", "C7"}
hexWantedEU4Darwin := []string{"E8", "7A", "C5", "76", "01", "89", "01", "89", "C3", "E8", "93", "A6", "EC", "FF", "31", "F6", "31", "DB", "40", "0F", "94", "C6", "48", "89", "C7"}
hexExistsEU4Darwin := []string{"E8", "7A", "C5", "76", "01", "89", "C3", "E8", "93", "A6", "EC", "FF", "31", "F6", "85", "DB", "40", "0F", "94", "C6", "48", "89", "C7"}
hexWantedEU4Darwin := []string{"E8", "7A", "C5", "76", "01", "89", "C3", "E8", "93", "A6", "EC", "FF", "31", "F6", "31", "DB", "40", "0F", "94", "C6", "48", "89", "C7"}
// HOI4
hexExistsHOI4Windows := []string{"48", "8D", "0D", "77", "B6", "C9", "01", "E8", "CA", "86", "B3", "01", "85", "C0", "0F", "94", "C3", "E8", "90"}
hexWantedHOI4Windows := []string{"48", "8D", "0D", "77", "B6", "C9", "01", "E8", "CA", "86", "B3", "01", "31", "C0", "0F", "94", "C3", "E8", "90"}
Expand Down
44 changes: 32 additions & 12 deletions test_eu4_patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,65 @@ import (
)

func TestApplyPatchEU4Windows(t *testing.T) {
err := backupFile("./test_files/eu4/eu4_original.exe", "./test_files/eu4/eu4_test.exe")
err := backupFile("./test_files/eu4/eu4_windows_original.exe", "./test_files/eu4/eu4_windows_test.exe")

if err != nil {
t.Error(err)
}
err = applyPatch(true, "./test_files/eu4/eu4_test", "windows")
err = applyPatch(true, "./test_files/eu4/eu4_windows_test", "windows")

if err != nil {
t.Error(err)
}

if !compareExes("./test_files/eu4/eu4_patched.exe", "./test_files/eu4/eu4_test.exe") {
if !compareExes("./test_files/eu4/eu4_windows_patched.exe", "./test_files/eu4/eu4_windows_test.exe") {
if err != nil {
t.Error("Executables doesnt match")
}
}
os.Remove("./test_files/eu4/eu4_test.exe")
os.Remove("./test_files/eu4/eu4_test_backup.exe")
os.Remove("./test_files/eu4/eu4.exe")
os.Remove("./test_files/eu4/eu4_windows_test.exe")
os.Remove("./test_files/eu4/eu4_windows_test_backup.exe")
os.Remove("./test_files/eu4/eu4_windows.exe")
}

func TestApplyPatchEU4Linux(t *testing.T) {
err := backupFile("./test_files/eu4/eu4_original", "./test_files/eu4/eu4_test")
err := backupFile("./test_files/eu4/eu4_linux_original", "./test_files/eu4/eu4_linux_test")

if err != nil {
t.Error(err)
}
err = applyPatch(true, "./test_files/eu4/eu4_test", "linux")
err = applyPatch(true, "./test_files/eu4/eu4_linux_test", "linux")
if err != nil {
t.Error(err)
}

if !compareExes("./test_files/eu4/eu4_patched", "./test_files/eu4/eu4_test") {
if !compareExes("./test_files/eu4/eu4_linux_patched", "./test_files/eu4/eu4_linux_test") {
if err != nil {
t.Error("Executables doesnt match")
}
}
os.Remove("./test_files/eu4/eu4_test")
os.Remove("./test_files/eu4/eu4_test_backup")
os.Remove("./test_files/eu4/eu4")
os.Remove("./test_files/eu4/eu4_linux_test")
os.Remove("./test_files/eu4/eu4_linux_test_backup")
os.Remove("./test_files/eu4/eu4_linux")
}

func TestApplyPatchEU4Darwin(t *testing.T) {
err := backupFile("./test_files/eu4/eu4_darwin_original", "./test_files/eu4/eu4_darwin_test")

if err != nil {
t.Error(err)
}
err = applyPatch(true, "./test_files/eu4/eu4_darwin_test", "darwin")
if err != nil {
t.Error(err)
}

if !compareExes("./test_files/eu4/eu4_darwin_patched", "./test_files/eu4/eu4_darwin_test") {
if err != nil {
t.Error("Executables doesnt match")
}
}
os.Remove("./test_files/eu4/eu4_darwin_test")
os.Remove("./test_files/eu4/eu4_darwin_test_backup")
os.Remove("./test_files/eu4/eu4_darwin")
}

0 comments on commit f2ccac2

Please sign in to comment.