private static void InstallPendingSelfUpdates() { var path = Path.Combine(BeatSaber.InstallPath, "IPA.exe"); if (!File.Exists(path)) { return; } var ipaVersion = new Version(FileVersionInfo.GetVersionInfo(path).FileVersion); var selfVersion = Assembly.GetExecutingAssembly().GetName().Version; if (ipaVersion > selfVersion) { Process.Start(new ProcessStartInfo { FileName = path, Arguments = $"\"-nw={Process.GetCurrentProcess().Id},s={string.Join(" ", Environment.GetCommandLineArgs().Skip(1).StrJP()).Replace("\\", "\\\\").Replace(",", "\\,")}\"", UseShellExecute = false }); updater.Info("Updating BSIPA..."); Environment.Exit(0); } }
public override AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters) { LibLoader.SetupAssemblyFilenames(); if (name.Name == CurrentAssemblyName) { return(AssemblyDefinition.ReadAssembly(CurrentAssemblyPath, parameters)); } if (LibLoader.FilenameLocations.TryGetValue($"{name.Name}.dll", out var path)) { if (File.Exists(path)) { return(AssemblyDefinition.ReadAssembly(path, parameters)); } } else if (LibLoader.FilenameLocations.TryGetValue($"{name.Name}.{name.Version}.dll", out path)) { if (File.Exists(path)) { return(AssemblyDefinition.ReadAssembly(path, parameters)); } } return(base.Resolve(name, parameters)); }
internal static Assembly LoadLibrary(AssemblyName asmName) { Log(Logger.Level.Debug, $"Resolving library {asmName}"); SetupAssemblyFilenames(); var testFile = $"{asmName.Name}.{asmName.Version}.dll"; Log(Logger.Level.Debug, $"Looking for file {testFile}"); if (FilenameLocations.TryGetValue(testFile, out var path)) { Log(Logger.Level.Debug, $"Found file {testFile} as {path}"); if (File.Exists(path)) { return(Assembly.LoadFrom(path)); } Log(Logger.Level.Critical, $"but {path} no longer exists!"); } else if (FilenameLocations.TryGetValue(testFile = $"{asmName.Name}.dll", out path)) { Log(Logger.Level.Debug, $"Found file {testFile} as {path}"); if (File.Exists(path)) { return(Assembly.LoadFrom(path)); } Log(Logger.Level.Critical, $"but {path} no longer exists!"); } Log(Logger.Level.Critical, $"No library {asmName} found"); return(null); }
public static bool IsInvalid(string path) { var dataPlugins = Path.Combine(GameVersionEarly.ResolveDataPath(path), "Plugins"); try { var userDir = GetPath(new Guid("374DE290-123F-4565-9164-39C4925E467B"), KnownFolderFlags.AliasOnly | KnownFolderFlags.DontVerify); var userDir2 = GetPath(new Guid("7d83ee9b-2244-4e70-b1f5-5393042af1e4"), KnownFolderFlags.AliasOnly | KnownFolderFlags.DontVerify); var curdir = Environment.CurrentDirectory; if (curdir.IsSubPathOf(userDir) || curdir.IsSubPathOf(userDir2)) { return(false); } } catch { } // To the guys that maintain a fork that removes this code: I would greatly appreciate if we could talk // about this for a little bit. Please message me on Discord at DaNike#6223 return (File.Exists(Path.Combine(path, "IGG-GAMES.COM.url")) || File.Exists(Path.Combine(path, "SmartSteamEmu.ini")) || File.Exists(Path.Combine(path, "GAMESTORRENT.CO.url")) || File.Exists(Path.Combine(dataPlugins, "BSteam crack.dll")) || File.Exists(Path.Combine(dataPlugins, "HUHUVR_steam_api64.dll")) || Directory.GetFiles(dataPlugins, "*.ini", SearchOption.TopDirectoryOnly).Length > 0); }
private static Tuple <IEnumerable <PluginInfo>, IEnumerable <IPlugin> > LoadPluginsFromFile(string file) { List <IPlugin> ipaPlugins = new List <IPlugin>(); if (!File.Exists(file) || !file.EndsWith(".dll", true, null)) { return(new Tuple <IEnumerable <PluginInfo>, IEnumerable <IPlugin> >(null, ipaPlugins)); } T OptionalGetPlugin <T>(Type t) where T : class { // use typeof() to allow for easier renaming (in an ideal world this compiles to a string, but ¯\_(ツ)_/¯) if (t.GetInterface(typeof(T).Name) != null) { try { T pluginInstance = Activator.CreateInstance(t) as T; return(pluginInstance); } catch (Exception e) { Logger.loader.Error($"Could not load plugin {t.FullName} in {Path.GetFileName(file)}! {e}"); } } return(null); } try { Assembly assembly = Assembly.LoadFrom(file); foreach (Type t in assembly.GetTypes()) { IPlugin ipaPlugin = OptionalGetPlugin <IPlugin>(t); if (ipaPlugin != null) { ipaPlugins.Add(ipaPlugin); } } } catch (ReflectionTypeLoadException e) { Logger.loader.Error($"Could not load the following types from {Path.GetFileName(file)}:"); Logger.loader.Error($" {string.Join("\n ", e.LoaderExceptions?.Select(e1 => e1?.Message).StrJP() ?? new string[0])}"); } catch (Exception e) { Logger.loader.Error($"Could not load {Path.GetFileName(file)}!"); Logger.loader.Error(e); } return(new Tuple <IEnumerable <PluginInfo>, IEnumerable <IPlugin> >(null, ipaPlugins)); }
public static bool IsInvalid(string path) { var dataPlugins = Path.Combine(GameVersionEarly.ResolveDataPath(path), "Plugins"); return (File.Exists(Path.Combine(path, "IGG-GAMES.COM.url")) || File.Exists(Path.Combine(path, "SmartSteamEmu.ini")) || File.Exists(Path.Combine(path, "GAMESTORRENT.CO.url")) || File.Exists(Path.Combine(dataPlugins, "BSteam crack.dll")) || File.Exists(Path.Combine(dataPlugins, "HUHUVR_steam_api64.dll")) || Directory.GetFiles(dataPlugins, "*.ini", SearchOption.TopDirectoryOnly).Length > 0); }
private static void InstallPendingSelfUpdates() { var path = Path.Combine(UnityGame.InstallPath, "IPA.exe"); if (!File.Exists(path)) { return; } var ipaVersion = new Version(FileVersionInfo.GetVersionInfo(path).FileVersion); var selfVersion = Assembly.GetExecutingAssembly().GetName().Version; if (ipaVersion > selfVersion) { var scanResult = AntiMalwareEngine.Engine.ScanFile(new FileInfo(path)); if (scanResult == ScanResult.Detected) { Updater.Error("Scan of BSIPA installer found malware; not updating"); return; } if (!SelfConfig.AntiMalware_.RunPartialThreatCode_ && scanResult is not ScanResult.KnownSafe and not ScanResult.NotDetected) { Updater.Error("Scan of BSIPA installer returned partial threat; not updating. To allow this, enable AntiMalware.RunPartialThreatCode in the config."); return; } _ = Process.Start(new ProcessStartInfo { FileName = path, Arguments = $"\"-nw={Process.GetCurrentProcess().Id}," + $"s={string.Join(" ", Environment.GetCommandLineArgs().Skip(1).StrJP()).Replace("\\", "\\\\").Replace(",", "\\,")}\"", UseShellExecute = false }); Updater.Info("Updating BSIPA..."); Environment.Exit(0); } }
private static void InstallPendingModUpdates() { var pendingDir = Path.Combine(BeatSaber.InstallPath, "IPA", "Pending"); if (!Directory.Exists(pendingDir)) { return; } // there are pending updates, install updater.Info("Installing pending updates"); var toDelete = new string[0]; var delFn = Path.Combine(pendingDir, DeleteFileName); if (File.Exists(delFn)) { toDelete = File.ReadAllLines(delFn); File.Delete(delFn); } foreach (var file in toDelete) { try { File.Delete(Path.Combine(BeatSaber.InstallPath, file)); } catch (Exception e) { updater.Error("While trying to install pending updates: Error deleting file marked for deletion"); updater.Error(e); } } #region Self Protection string path; if (Directory.Exists(path = Path.Combine(pendingDir, "IPA"))) { var dirs = new Stack <string>(20); dirs.Push(path); while (dirs.Count > 0) { var currentDir = dirs.Pop(); string[] subDirs; string[] files; try { subDirs = Directory.GetDirectories(currentDir); files = Directory.GetFiles(currentDir); } catch (UnauthorizedAccessException e) { updater.Error(e); continue; } catch (DirectoryNotFoundException e) { updater.Error(e); continue; } foreach (var file in files) { try { if (!Utils.GetRelativePath(file, path).Split(Path.PathSeparator).Contains("Pending")) { File.Delete(file); } } catch (FileNotFoundException e) { updater.Error(e); } } foreach (var str in subDirs) { dirs.Push(str); } } } if (File.Exists(path = Path.Combine(pendingDir, "IPA.exe"))) { File.Delete(path); if (File.Exists(path = Path.Combine(pendingDir, "Mono.Cecil.dll"))) { File.Delete(path); } } #endregion try { Utils.CopyAll(new DirectoryInfo(pendingDir), new DirectoryInfo(BeatSaber.InstallPath), onCopyException: (e, f) => { updater.Error($"Error copying file {Utils.GetRelativePath(f.FullName, pendingDir)} from Pending:"); updater.Error(e); return(true); }); } catch (Exception e) { updater.Error("While trying to install pending updates: Error copying files in"); updater.Error(e); } try { Directory.Delete(pendingDir, true); } catch (Exception e) { updater.Error("Something went wrong performing an operation that should never fail!"); updater.Error(e); } }