set shadowLOD as main patching process

This commit is contained in:
aomizu
2025-06-16 23:25:19 +09:00
parent c0daa300bf
commit 084e980adf
5 changed files with 155 additions and 5 deletions

View File

@@ -3,4 +3,4 @@
Name = "TurtleSilicon" Name = "TurtleSilicon"
ID = "com.tairasu.turtlesilicon" ID = "com.tairasu.turtlesilicon"
Version = "1.2.2" Version = "1.2.2"
Build = 57 Build = 58

View File

@@ -19,7 +19,6 @@ var RecommendedSettings = map[string]string{
"gxDepthBits": "24", "gxDepthBits": "24",
"gxMultisampleQuality": "0.000000", "gxMultisampleQuality": "0.000000",
"gxMultisample": "2", "gxMultisample": "2",
"shadowLOD": "0",
} }
// CheckRecommendedSettings reads the Config.wtf file and checks if all recommended settings are applied // CheckRecommendedSettings reads the Config.wtf file and checks if all recommended settings are applied

View File

@@ -8,6 +8,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"regexp"
"strings" "strings"
"turtlesilicon/pkg/debug" "turtlesilicon/pkg/debug"
@@ -211,6 +212,12 @@ func PatchTurtleWoW(myWindow fyne.Window, updateAllStatuses func()) {
} }
} }
// Apply shadowLOD setting to Config.wtf for FPS optimization
if err := applyShadowLODSetting(); err != nil {
debug.Printf("Warning: failed to apply shadowLOD setting to Config.wtf: %v", err)
// Continue with patching even if Config.wtf update fails
}
debug.Println("TurtleWoW patching with bundled resources completed successfully.") debug.Println("TurtleWoW patching with bundled resources completed successfully.")
dialog.ShowInformation("Success", "TurtleWoW patching process completed using bundled resources.", myWindow) dialog.ShowInformation("Success", "TurtleWoW patching process completed using bundled resources.", myWindow)
updateAllStatuses() updateAllStatuses()
@@ -345,6 +352,12 @@ func UnpatchTurtleWoW(myWindow fyne.Window, updateAllStatuses func()) {
} }
} }
// Remove shadowLOD setting from Config.wtf
if err := removeShadowLODSetting(); err != nil {
debug.Printf("Warning: failed to remove shadowLOD setting from Config.wtf: %v", err)
// Continue with unpatching even if Config.wtf update fails
}
debug.Println("TurtleWoW unpatching completed successfully.") debug.Println("TurtleWoW unpatching completed successfully.")
paths.PatchesAppliedTurtleWoW = false paths.PatchesAppliedTurtleWoW = false
dialog.ShowInformation("Success", "TurtleWoW unpatching process completed.", myWindow) dialog.ShowInformation("Success", "TurtleWoW unpatching process completed.", myWindow)
@@ -380,3 +393,139 @@ func UnpatchCrossOver(myWindow fyne.Window, updateAllStatuses func()) {
dialog.ShowInformation("Success", "CrossOver unpatching process completed.", myWindow) dialog.ShowInformation("Success", "CrossOver unpatching process completed.", myWindow)
updateAllStatuses() updateAllStatuses()
} }
// applyShadowLODSetting applies the shadowLOD setting to Config.wtf for FPS optimization
func applyShadowLODSetting() error {
if paths.TurtlewowPath == "" {
return fmt.Errorf("TurtleWoW path not set")
}
configPath := filepath.Join(paths.TurtlewowPath, "WTF", "Config.wtf")
// Create WTF directory if it doesn't exist
wtfDir := filepath.Dir(configPath)
if err := os.MkdirAll(wtfDir, 0755); err != nil {
return fmt.Errorf("failed to create WTF directory: %v", err)
}
var configText string
// Read existing config if it exists
if content, err := os.ReadFile(configPath); err == nil {
configText = string(content)
} else {
debug.Printf("Config.wtf not found, creating new file")
configText = ""
}
// Apply shadowLOD setting
configText = updateOrAddConfigSetting(configText, "shadowLOD", "0")
// Write the updated config back to file
if err := os.WriteFile(configPath, []byte(configText), 0644); err != nil {
return fmt.Errorf("failed to write Config.wtf: %v", err)
}
debug.Printf("Successfully applied shadowLOD setting to Config.wtf")
return nil
}
// updateOrAddConfigSetting updates an existing setting or adds a new one if it doesn't exist
func updateOrAddConfigSetting(configText, setting, value string) string {
// Create regex pattern to match the setting
pattern := fmt.Sprintf(`SET\s+%s\s+"[^"]*"`, regexp.QuoteMeta(setting))
re := regexp.MustCompile(pattern)
newSetting := fmt.Sprintf(`SET %s "%s"`, setting, value)
if re.MatchString(configText) {
// Replace existing setting
configText = re.ReplaceAllString(configText, newSetting)
debug.Printf("Updated setting %s to %s", setting, value)
} else {
// Add new setting
if configText != "" && !strings.HasSuffix(configText, "\n") {
configText += "\n"
}
configText += newSetting + "\n"
debug.Printf("Added new setting %s with value %s", setting, value)
}
return configText
}
// CheckShadowLODSetting checks if the shadowLOD setting is correctly applied in Config.wtf
func CheckShadowLODSetting() bool {
if paths.TurtlewowPath == "" {
return false
}
configPath := filepath.Join(paths.TurtlewowPath, "WTF", "Config.wtf")
if _, err := os.Stat(configPath); os.IsNotExist(err) {
return false
}
content, err := os.ReadFile(configPath)
if err != nil {
return false
}
configText := string(content)
return isConfigSettingCorrect(configText, "shadowLOD", "0")
}
// isConfigSettingCorrect checks if a specific setting has the correct value in the config text
func isConfigSettingCorrect(configText, setting, expectedValue string) bool {
// Create regex pattern to match the setting
pattern := fmt.Sprintf(`SET\s+%s\s+"([^"]*)"`, regexp.QuoteMeta(setting))
re := regexp.MustCompile(pattern)
matches := re.FindStringSubmatch(configText)
if len(matches) < 2 {
return false
}
currentValue := matches[1]
return currentValue == expectedValue
}
// removeShadowLODSetting removes the shadowLOD setting from Config.wtf
func removeShadowLODSetting() error {
if paths.TurtlewowPath == "" {
return fmt.Errorf("TurtleWoW path not set")
}
configPath := filepath.Join(paths.TurtlewowPath, "WTF", "Config.wtf")
if _, err := os.Stat(configPath); os.IsNotExist(err) {
debug.Printf("Config.wtf not found, nothing to remove")
return nil
}
content, err := os.ReadFile(configPath)
if err != nil {
return fmt.Errorf("failed to read Config.wtf: %v", err)
}
configText := string(content)
// Remove shadowLOD setting if it exists
pattern := fmt.Sprintf(`SET\s+%s\s+"[^"]*"[\r\n]*`, regexp.QuoteMeta("shadowLOD"))
re := regexp.MustCompile(pattern)
if re.MatchString(configText) {
configText = re.ReplaceAllString(configText, "")
debug.Printf("Removed shadowLOD setting from Config.wtf")
// Write the updated config back to file
if err := os.WriteFile(configPath, []byte(configText), 0644); err != nil {
return fmt.Errorf("failed to write Config.wtf: %v", err)
}
debug.Printf("Successfully updated Config.wtf")
} else {
debug.Printf("shadowLOD setting not found in Config.wtf, nothing to remove")
}
return nil
}

View File

@@ -419,7 +419,6 @@ func showRecommendedSettingsHelpPopup() {
setting1 := widget.NewLabel("• Terrain Distance (farclip): 177 - Reduces CPU overhead - more fps") setting1 := widget.NewLabel("• Terrain Distance (farclip): 177 - Reduces CPU overhead - more fps")
setting2 := widget.NewLabel("• Vertex Animation Shaders (M2UseShaders): Enabled - Prevents graphic glitches") setting2 := widget.NewLabel("• Vertex Animation Shaders (M2UseShaders): Enabled - Prevents graphic glitches")
setting3 := widget.NewLabel("• Multisampling (gxMultisample): 2x - Makes portraits load properly") setting3 := widget.NewLabel("• Multisampling (gxMultisample): 2x - Makes portraits load properly")
setting4 := widget.NewLabel("• Shadow LOD (shadowLOD): 0 - 10% fps increase")
settingsContainer := container.NewVBox( settingsContainer := container.NewVBox(
settingsTitle, settingsTitle,
@@ -427,7 +426,6 @@ func showRecommendedSettingsHelpPopup() {
setting1, setting1,
setting2, setting2,
setting3, setting3,
setting4,
widget.NewSeparator(), widget.NewSeparator(),
) )

View File

@@ -6,6 +6,7 @@ import (
"strings" "strings"
"time" "time"
"turtlesilicon/pkg/patching"
"turtlesilicon/pkg/paths" "turtlesilicon/pkg/paths"
"turtlesilicon/pkg/service" "turtlesilicon/pkg/service"
"turtlesilicon/pkg/utils" "turtlesilicon/pkg/utils"
@@ -109,11 +110,14 @@ func updateTurtleWoWStatus() {
rosettaX87CorrectSize := utils.CompareFileWithBundledResource(rosettaX87ExePath, "rosettax87/rosettax87") rosettaX87CorrectSize := utils.CompareFileWithBundledResource(rosettaX87ExePath, "rosettax87/rosettax87")
libRuntimeRosettaX87CorrectSize := utils.CompareFileWithBundledResource(libRuntimeRosettaX87Path, "rosettax87/libRuntimeRosettax87") libRuntimeRosettaX87CorrectSize := utils.CompareFileWithBundledResource(libRuntimeRosettaX87Path, "rosettax87/libRuntimeRosettax87")
// Check if shadowLOD setting is applied
shadowLODApplied := patching.CheckShadowLODSetting()
if utils.PathExists(winerosettaDllPath) && utils.PathExists(d3d9DllPath) && utils.PathExists(libSiliconPatchDllPath) && if utils.PathExists(winerosettaDllPath) && utils.PathExists(d3d9DllPath) && utils.PathExists(libSiliconPatchDllPath) &&
utils.DirExists(rosettaX87DirPath) && utils.PathExists(rosettaX87ExePath) && utils.DirExists(rosettaX87DirPath) && utils.PathExists(rosettaX87ExePath) &&
utils.PathExists(libRuntimeRosettaX87Path) && dllsFileValid && utils.PathExists(libRuntimeRosettaX87Path) && dllsFileValid &&
winerosettaDllCorrectSize && d3d9DllCorrectSize && libSiliconPatchCorrectSize && winerosettaDllCorrectSize && d3d9DllCorrectSize && libSiliconPatchCorrectSize &&
rosettaX87CorrectSize && libRuntimeRosettaX87CorrectSize { rosettaX87CorrectSize && libRuntimeRosettaX87CorrectSize && shadowLODApplied {
paths.PatchesAppliedTurtleWoW = true paths.PatchesAppliedTurtleWoW = true
} }
} }