-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
174 lines (143 loc) · 5.56 KB
/
main.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package main
import (
"bufio"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"time"
)
func main() {
var mcLocation string
var found bool
var srcCount int
var srcList, destList []string
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
fmt.Println("[RITO SHADERS INIT]: Failed to determine the script directory:", err)
return
}
placeholderFile := filepath.Join(dir, "materials", "putMaterialsHere")
if _, err := os.Stat(placeholderFile); err == nil {
os.Remove(placeholderFile)
}
displayIntro()
if !confirm("[RITO SHADERS INIT]: Is IObit Unlocker installed on your system? (Y=Yes, N=No)") {
fmt.Println("[RITO SHADERS INIT]: Redirecting you to the IObit Unlocker download page...")
exec.Command("rundll32", "url.dll,FileProtocolHandler", "https://www.iobit.com/en/iobit-unlocker.php").Start()
time.Sleep(3 * time.Second)
return
}
if !confirm("[RITO SHADERS INIT]: Have you unlocked the WindowsApps folder? (Y=Yes, N=No)") {
if !confirm("[RITO SHADERS INIT]: Unlocking the WindowsApps folder might take a while depending on your system. Proceed? (Y=Yes, N=No)") {
fmt.Println("[RITO SHADERS INIT]: Shader injection requires the WindowsApps folder to be unlocked.")
return
}
unlockWindowsApps(dir)
}
mcLocation, found = findMinecraftLocation()
if !found {
fmt.Println("[RITO SHADERS INIT]: Minecraft installation not found in 'C:\\Program Files\\WindowsApps'. Please ensure Minecraft is installed.")
return
}
if confirm("[RITO SHADERS INIT]: Would you like to back up the original materials? (Y=Yes, N=No)") {
backupMaterials(mcLocation, dir)
}
srcList, destList, srcCount = findBinFiles(dir, mcLocation)
if srcCount == 0 {
fmt.Println("[RITO SHADERS INIT]: No .bin files detected. Please add .bin files to the /materials folder.")
return
}
displayMaterialList(srcList, mcLocation)
if !confirm("[RITO SHADERS INIT]: Ready to inject the new materials? (Y=Yes, N=No)") {
fmt.Println("[RITO SHADERS INIT]: Operation canceled.")
return
}
deleteVanillaMaterials(destList)
moveSourceMaterials(srcList, mcLocation)
fmt.Println("[RITO SHADERS INIT]: Injection completed successfully!")
}
func displayIntro() {
fmt.Println("\n[RITO SHADERS INIT]:\nThis tool injects `.material.bin` files into Minecraft Bedrock Edition.")
time.Sleep(3 * time.Second)
}
func confirm(prompt string) bool {
fmt.Println(prompt)
reader := bufio.NewReader(os.Stdin)
response, _ := reader.ReadString('\n')
response = strings.TrimSpace(strings.ToLower(response))
return response == "y"
}
func unlockWindowsApps(dir string) {
for {
fmt.Println("[RITO SHADERS INIT]: Attempting to unlock WindowsApps folder...")
cmd := exec.Command("powershell", "-command", "start-process", "-file", "claimedOwnership.bat", "-verb", "runas", "-Wait")
cmd.Dir = dir
cmd.Run()
if _, err := os.Stat(filepath.Join(dir, "claimedOwnership.bat")); err == nil {
break
} else {
fmt.Println("[RITO SHADERS INIT]: UAC prompt not accepted. Retrying...")
}
}
fmt.Println("[RITO SHADERS INIT]: WindowsApps folder unlocked successfully!")
time.Sleep(2 * time.Second)
}
func findMinecraftLocation() (string, bool) {
programFiles := os.Getenv("ProgramFiles")
mcPattern := filepath.Join(programFiles, "WindowsApps", "Microsoft.MinecraftUWP_*")
matches, err := filepath.Glob(mcPattern)
if err != nil || len(matches) == 0 {
return "", false
}
return matches[0], true
}
func backupMaterials(mcLocation, dir string) {
src := filepath.Join(mcLocation, "data", "renderer", "materials")
dest := filepath.Join(dir, "materials.backup")
fmt.Println("[RITO SHADERS INIT]: Backing up original materials...")
exec.Command("xcopy", src, dest, "/E", "/I", "/H", "/Y").Run()
fmt.Println("[RITO SHADERS INIT]: Backup completed!")
time.Sleep(2 * time.Second)
}
func findBinFiles(dir, mcLocation string) ([]string, []string, int) {
var srcList, destList []string
materialsDir := filepath.Join(dir, "materials")
files, err := os.ReadDir(materialsDir)
if err != nil {
fmt.Println("[RITO SHADERS INIT]: Failed to read the materials directory:", err)
return nil, nil, 0
}
for _, file := range files {
if !file.IsDir() && strings.HasSuffix(file.Name(), ".bin") {
srcFile := filepath.Join(materialsDir, file.Name())
destFile := filepath.Join(mcLocation, "data", "renderer", file.Name())
srcList = append(srcList, srcFile)
destList = append(destList, destFile)
}
}
return srcList, destList, len(srcList)
}
func displayMaterialList(srcList []string, mcLocation string) {
fmt.Printf("[RITO SHADERS INIT]: %d .bin file(s) detected in the materials folder.\n", len(srcList))
fmt.Println("[RITO SHADERS INIT]: Minecraft installation found at:", mcLocation)
fmt.Println("[RITO SHADERS INIT]: -------- Materials to Inject --------")
for _, src := range srcList {
fmt.Println(filepath.Base(src))
}
fmt.Println("[RITO SHADERS INIT]: -------------------------------------")
}
func deleteVanillaMaterials(destList []string) {
fmt.Println("[RITO SHADERS INIT]: Removing original materials...")
for _, dest := range destList {
exec.Command("IObitUnlocker", "/advanced", "/delete", dest).Run()
}
}
func moveSourceMaterials(srcList []string, mcLocation string) {
fmt.Println("[RITO SHADERS INIT]: Injecting new materials...")
for _, src := range srcList {
dest := filepath.Join(mcLocation, "data", "renderer", "materials", filepath.Base(src))
exec.Command("IObitUnlocker", "/advanced", "/move", src, dest).Run()
}
}