From 084e980adfb61a3bd93d729081c0516e377b9583 Mon Sep 17 00:00:00 2001 From: aomizu Date: Mon, 16 Jun 2025 23:25:19 +0900 Subject: [PATCH] set shadowLOD as main patching process --- FyneApp.toml | 2 +- pkg/launcher/recommended.go | 1 - pkg/patching/patching.go | 149 ++++++++++++++++++++++++++++++++++++ pkg/ui/components.go | 2 - pkg/ui/status.go | 6 +- 5 files changed, 155 insertions(+), 5 deletions(-) diff --git a/FyneApp.toml b/FyneApp.toml index e2d03c8..165bee1 100644 --- a/FyneApp.toml +++ b/FyneApp.toml @@ -3,4 +3,4 @@ Name = "TurtleSilicon" ID = "com.tairasu.turtlesilicon" Version = "1.2.2" - Build = 57 + Build = 58 diff --git a/pkg/launcher/recommended.go b/pkg/launcher/recommended.go index 728075e..2e1c0c5 100644 --- a/pkg/launcher/recommended.go +++ b/pkg/launcher/recommended.go @@ -19,7 +19,6 @@ var RecommendedSettings = map[string]string{ "gxDepthBits": "24", "gxMultisampleQuality": "0.000000", "gxMultisample": "2", - "shadowLOD": "0", } // CheckRecommendedSettings reads the Config.wtf file and checks if all recommended settings are applied diff --git a/pkg/patching/patching.go b/pkg/patching/patching.go index 6d241be..2899db4 100644 --- a/pkg/patching/patching.go +++ b/pkg/patching/patching.go @@ -8,6 +8,7 @@ import ( "os" "os/exec" "path/filepath" + "regexp" "strings" "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.") dialog.ShowInformation("Success", "TurtleWoW patching process completed using bundled resources.", myWindow) 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.") paths.PatchesAppliedTurtleWoW = false 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) 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 +} diff --git a/pkg/ui/components.go b/pkg/ui/components.go index 6862fac..9151de2 100644 --- a/pkg/ui/components.go +++ b/pkg/ui/components.go @@ -419,7 +419,6 @@ func showRecommendedSettingsHelpPopup() { setting1 := widget.NewLabel("• Terrain Distance (farclip): 177 - Reduces CPU overhead - more fps") setting2 := widget.NewLabel("• Vertex Animation Shaders (M2UseShaders): Enabled - Prevents graphic glitches") setting3 := widget.NewLabel("• Multisampling (gxMultisample): 2x - Makes portraits load properly") - setting4 := widget.NewLabel("• Shadow LOD (shadowLOD): 0 - 10% fps increase") settingsContainer := container.NewVBox( settingsTitle, @@ -427,7 +426,6 @@ func showRecommendedSettingsHelpPopup() { setting1, setting2, setting3, - setting4, widget.NewSeparator(), ) diff --git a/pkg/ui/status.go b/pkg/ui/status.go index 91cf6ae..65a139a 100644 --- a/pkg/ui/status.go +++ b/pkg/ui/status.go @@ -6,6 +6,7 @@ import ( "strings" "time" + "turtlesilicon/pkg/patching" "turtlesilicon/pkg/paths" "turtlesilicon/pkg/service" "turtlesilicon/pkg/utils" @@ -109,11 +110,14 @@ func updateTurtleWoWStatus() { rosettaX87CorrectSize := utils.CompareFileWithBundledResource(rosettaX87ExePath, "rosettax87/rosettax87") 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) && utils.DirExists(rosettaX87DirPath) && utils.PathExists(rosettaX87ExePath) && utils.PathExists(libRuntimeRosettaX87Path) && dllsFileValid && winerosettaDllCorrectSize && d3d9DllCorrectSize && libSiliconPatchCorrectSize && - rosettaX87CorrectSize && libRuntimeRosettaX87CorrectSize { + rosettaX87CorrectSize && libRuntimeRosettaX87CorrectSize && shadowLODApplied { paths.PatchesAppliedTurtleWoW = true } }