diff --git a/CP77Tools.sln b/CP77Tools.sln index 42ee899449..ece98d52be 100644 --- a/CP77Tools.sln +++ b/CP77Tools.sln @@ -7,20 +7,50 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CP77Tools", "CP77Tools\CP77 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CP77.MSTests", "CP77.MSTests\CP77.MSTests.csproj", "{78302151-8D4B-407B-A2FE-5774C471F8AA}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WolvenKit.Cyberformats", "CP77.CR2W\WolvenKit.Cyberformats.csproj", "{A612A200-90D5-41A7-9ADE-F90AD2274022}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WolvenKit.Common", "WolvenKit.Common\WolvenKit.Common.csproj", "{2B13DF78-8441-49F3-8212-06935A5D7AE0}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {37C3288C-A6D7-4C71-8174-0F2F6D47938E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {37C3288C-A6D7-4C71-8174-0F2F6D47938E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {37C3288C-A6D7-4C71-8174-0F2F6D47938E}.Debug|x64.ActiveCfg = Debug|Any CPU + {37C3288C-A6D7-4C71-8174-0F2F6D47938E}.Debug|x64.Build.0 = Debug|Any CPU {37C3288C-A6D7-4C71-8174-0F2F6D47938E}.Release|Any CPU.ActiveCfg = Release|Any CPU {37C3288C-A6D7-4C71-8174-0F2F6D47938E}.Release|Any CPU.Build.0 = Release|Any CPU + {37C3288C-A6D7-4C71-8174-0F2F6D47938E}.Release|x64.ActiveCfg = Release|Any CPU + {37C3288C-A6D7-4C71-8174-0F2F6D47938E}.Release|x64.Build.0 = Release|Any CPU {78302151-8D4B-407B-A2FE-5774C471F8AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {78302151-8D4B-407B-A2FE-5774C471F8AA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {78302151-8D4B-407B-A2FE-5774C471F8AA}.Debug|x64.ActiveCfg = Debug|Any CPU + {78302151-8D4B-407B-A2FE-5774C471F8AA}.Debug|x64.Build.0 = Debug|Any CPU {78302151-8D4B-407B-A2FE-5774C471F8AA}.Release|Any CPU.ActiveCfg = Release|Any CPU {78302151-8D4B-407B-A2FE-5774C471F8AA}.Release|Any CPU.Build.0 = Release|Any CPU + {78302151-8D4B-407B-A2FE-5774C471F8AA}.Release|x64.ActiveCfg = Release|Any CPU + {78302151-8D4B-407B-A2FE-5774C471F8AA}.Release|x64.Build.0 = Release|Any CPU + {A612A200-90D5-41A7-9ADE-F90AD2274022}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A612A200-90D5-41A7-9ADE-F90AD2274022}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A612A200-90D5-41A7-9ADE-F90AD2274022}.Debug|x64.ActiveCfg = Debug|Any CPU + {A612A200-90D5-41A7-9ADE-F90AD2274022}.Debug|x64.Build.0 = Debug|Any CPU + {A612A200-90D5-41A7-9ADE-F90AD2274022}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A612A200-90D5-41A7-9ADE-F90AD2274022}.Release|Any CPU.Build.0 = Release|Any CPU + {A612A200-90D5-41A7-9ADE-F90AD2274022}.Release|x64.ActiveCfg = Release|Any CPU + {A612A200-90D5-41A7-9ADE-F90AD2274022}.Release|x64.Build.0 = Release|Any CPU + {2B13DF78-8441-49F3-8212-06935A5D7AE0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2B13DF78-8441-49F3-8212-06935A5D7AE0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2B13DF78-8441-49F3-8212-06935A5D7AE0}.Debug|x64.ActiveCfg = Debug|x64 + {2B13DF78-8441-49F3-8212-06935A5D7AE0}.Debug|x64.Build.0 = Debug|x64 + {2B13DF78-8441-49F3-8212-06935A5D7AE0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2B13DF78-8441-49F3-8212-06935A5D7AE0}.Release|Any CPU.Build.0 = Release|Any CPU + {2B13DF78-8441-49F3-8212-06935A5D7AE0}.Release|x64.ActiveCfg = Release|x64 + {2B13DF78-8441-49F3-8212-06935A5D7AE0}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CP77Tools/Program.cs b/CP77Tools/Program.cs index deba99d046..b5b240d098 100644 --- a/CP77Tools/Program.cs +++ b/CP77Tools/Program.cs @@ -4,11 +4,14 @@ using Catel.IoC; using System.CommandLine; using System.ComponentModel; +using System.Configuration; using System.IO; using System.Reflection; using CP77Tools.Commands; using CP77Tools.Extensions; using Luna.ConsoleProgressBar; +using Microsoft.Win32; +using WolvenKit.Common.Oodle; using WolvenKit.Common.Services; namespace CP77Tools @@ -18,16 +21,6 @@ class Program [STAThread] public static async Task Main(string[] args) { - //TODO: check here for linking errors - // try - // { - // Marshal.PrelinkAll(typeof(OozNative)); - // } - // catch (Exception e) - // { - // Console.WriteLine(e); - // } - ServiceLocator.Default.RegisterType(); ServiceLocator.Default.RegisterType(); @@ -75,7 +68,15 @@ public static async Task Main(string[] args) }; //await ConsoleFunctions.UpdateHashesAsync(); - /*await*/ hashService.ReloadLocally(); + hashService.ReloadLocally(); + + // try get oodle dll from game + if (!TryCopyOodleLib()) + { + logger.LogString("Could not automatically find oo2ext_7_win64.dll. " + + "Please manually copy and paste the dll found here Cyberpunk 2077\\bin\\x64\\oo2ext_7_win64.dll into this folder: " + + $"{AppDomain.CurrentDomain.BaseDirectory}."); + } // Run if (args == null || args.Length == 0) @@ -164,5 +165,104 @@ async Task WriteLog() } } + + private delegate void StrDelegate(string value); + + private static string TryGetGameInstallDir() + { + var cp77BinDir = ""; + var cp77exe = ""; + // check for CP77_DIR environment variable first + var CP77_DIR = System.Environment.GetEnvironmentVariable("CP77_DIR", EnvironmentVariableTarget.User); + if (!string.IsNullOrEmpty(CP77_DIR) && new DirectoryInfo(CP77_DIR).Exists) + cp77BinDir = Path.Combine(CP77_DIR, "bin", "x64"); + if (File.Exists(Path.Combine(cp77BinDir, "Cyberpunk2077.exe"))) + return cp77BinDir; + + // else: look for install location + const string uninstallkey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"; + const string uninstallkey2 = "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"; + const string gameName = "Cyberpunk 2077"; + const string exeName = "Cyberpunk2077.exe"; + var exePath = ""; + StrDelegate strDelegate = msg => cp77exe = msg; + + try + { + Parallel.ForEach(Registry.LocalMachine.OpenSubKey(uninstallkey)?.GetSubKeyNames(), item => + { + var programName = Registry.LocalMachine.OpenSubKey(uninstallkey + item) + ?.GetValue("DisplayName"); + var installLocation = Registry.LocalMachine.OpenSubKey(uninstallkey + item) + ?.GetValue("InstallLocation"); + if (programName != null && installLocation != null) + { + if (programName.ToString().Contains(gameName) || + programName.ToString().Contains(gameName)) + { + exePath = Directory.GetFiles(installLocation.ToString(), exeName, + SearchOption.AllDirectories).First(); + } + } + + strDelegate.Invoke(exePath); + }); + Parallel.ForEach(Registry.LocalMachine.OpenSubKey(uninstallkey2)?.GetSubKeyNames(), item => + { + var programName = Registry.LocalMachine.OpenSubKey(uninstallkey2 + item) + ?.GetValue("DisplayName"); + var installLocation = Registry.LocalMachine.OpenSubKey(uninstallkey2 + item) + ?.GetValue("InstallLocation"); + if (programName != null && installLocation != null) + { + if (programName.ToString().Contains(gameName) || + programName.ToString().Contains(gameName)) + { + if (Directory.Exists(installLocation.ToString())) + exePath = Directory.GetFiles(installLocation.ToString(), exeName, + SearchOption.AllDirectories).First(); + } + } + + strDelegate.Invoke(exePath); + }); + + if (File.Exists(cp77exe)) + cp77BinDir = new FileInfo(cp77exe).Directory.FullName; + } + catch (Exception e) + { + + } + + if (string.IsNullOrEmpty(cp77BinDir)) + return null; + if (!File.Exists(Path.Combine(cp77BinDir, "Cyberpunk2077.exe"))) + return null; + + return cp77BinDir; + } + + private static bool TryCopyOodleLib() + { + var ass = AppDomain.CurrentDomain.BaseDirectory; + var destFileName = Path.Combine(ass, "oo2ext_7_win64.dll"); + if (File.Exists(destFileName)) + return true; + + var cp77BinDir = TryGetGameInstallDir(); + if (string.IsNullOrEmpty(cp77BinDir)) + return false; + + // copy oodle dll + var oodleInfo = new FileInfo(Path.Combine(cp77BinDir, "oo2ext_7_win64.dll")); + if (!oodleInfo.Exists) + return false; + + if (!File.Exists(destFileName)) + oodleInfo.CopyTo(destFileName); + + return true; + } } }