|
4 | 4 | using MetahookInstallerAvalonia.Lang; |
5 | 5 | using Microsoft.Win32; |
6 | 6 | using ReactiveUI; |
| 7 | +using Gameloop.Vdf; |
| 8 | +using Gameloop.Vdf.Linq; |
7 | 9 | using ShellLink; |
8 | 10 | using System; |
9 | 11 | using System.Collections.Generic; |
@@ -105,6 +107,16 @@ public static bool IsLegitimatePE(string dllPath) |
105 | 107 | return false; |
106 | 108 | } |
107 | 109 | } |
| 110 | + private static string ReadNullTerminatedAscii(BinaryReader reader) |
| 111 | + { |
| 112 | + var bytes = new System.Collections.Generic.List<byte>(); |
| 113 | + byte b; |
| 114 | + while ((b = reader.ReadByte()) != 0) |
| 115 | + { |
| 116 | + bytes.Add(b); |
| 117 | + } |
| 118 | + return System.Text.Encoding.ASCII.GetString(bytes.ToArray()); |
| 119 | + } |
108 | 120 | private static long RvaToFileOffset(BinaryReader stream, int lfanew, uint rva) |
109 | 121 | { |
110 | 122 | try |
@@ -204,7 +216,7 @@ public static bool HasImportedModule(string dllPath, string targetModule) |
204 | 216 | if (nameFileOffset == -1) |
205 | 217 | continue; |
206 | 218 | stream.Position = nameFileOffset; |
207 | | - string moduleName = reader.ReadString().ToLowerInvariant(); |
| 219 | + string moduleName = ReadNullTerminatedAscii(reader).ToLowerInvariant(); |
208 | 220 | if (moduleName == targetModule) |
209 | 221 | return true; |
210 | 222 | } |
@@ -487,31 +499,38 @@ private string[] GetLibraryFolders() |
487 | 499 | var configPath = Path.Combine(_steamPath, "steamapps", "libraryfolders.vdf"); |
488 | 500 | if (File.Exists(configPath)) |
489 | 501 | { |
490 | | - var config = File.ReadAllText(configPath); |
491 | | - var lines = config.Split('\n'); |
492 | | - foreach (var line in lines) |
| 502 | + try |
493 | 503 | { |
494 | | - if (line.Contains("\"path\"")) |
| 504 | + var vdf = VdfConvert.Deserialize(File.ReadAllText(configPath)); |
| 505 | + foreach (var entry in vdf.Value.Children<VProperty>()) |
495 | 506 | { |
496 | | - var path = line.Split('"')[3].Replace("\\\\", "\\"); |
497 | | - libraryFolders.Add(path); |
| 507 | + var pathToken = entry.Value["path"]; |
| 508 | + if (pathToken != null) |
| 509 | + { |
| 510 | + libraryFolders.Add(pathToken.ToString()); |
| 511 | + } |
498 | 512 | } |
499 | 513 | } |
| 514 | + catch |
| 515 | + { |
| 516 | + // Fallback: ignore parse errors, return what we have |
| 517 | + } |
500 | 518 | } |
501 | 519 |
|
502 | 520 | return [.. libraryFolders]; |
503 | 521 | } |
504 | 522 | private static string? GetInstallDirFromManifest(string manifest) |
505 | 523 | { |
506 | | - var lines = manifest.Split('\n'); |
507 | | - foreach (var line in lines) |
| 524 | + try |
508 | 525 | { |
509 | | - if (line.Contains("\"installdir\"")) |
510 | | - { |
511 | | - return line.Split('"')[3]; |
512 | | - } |
| 526 | + var vdf = VdfConvert.Deserialize(manifest); |
| 527 | + var installDir = vdf.Value["installdir"]; |
| 528 | + return installDir?.ToString(); |
| 529 | + } |
| 530 | + catch |
| 531 | + { |
| 532 | + return null; |
513 | 533 | } |
514 | | - return null; |
515 | 534 | } |
516 | 535 | private static string? GetSteamPath() |
517 | 536 | { |
@@ -570,7 +589,7 @@ public bool Equals(PluginInfo? x, PluginInfo? y) |
570 | 589 | } |
571 | 590 | public int GetHashCode(PluginInfo obj) |
572 | 591 | { |
573 | | - return obj?.Name?.GetHashCode() ?? 0; |
| 592 | + return obj?.Name?.ToLowerInvariant().GetHashCode() ?? 0; |
574 | 593 | } |
575 | 594 | } |
576 | 595 | private readonly ObservableCollection<PluginInfo> _plugins = []; |
|
0 commit comments