Exemple #1
0
 public static void AddPluginsFromDirectory(this GameDetector gameDetector, string engineDirectory)
 {
     if (ServiceLocator.FileStorage.DirectoryExists(engineDirectory))
     {
         var dlls = ServiceLocator.FileStorage.EnumerateFiles(engineDirectory, "*.dll");
         foreach (var dll in dlls)
         {
             try
             {
                 var asm = Assembly.LoadFile(dll);
                 if (asm != null)
                 {
                     var engines = GetEngines(asm);
                     foreach (var engine in engines)
                     {
                         gameDetector.Add(engine);
                     }
                 }
             }
             catch (BadImageFormatException)
             {
             }
             catch (Exception)
             {
             }
         }
     }
 }
Exemple #2
0
        public static GameStartInfo[] FindGames(GameDetector detector, string folder, bool recursive)
        {
            var games = new List <GameStartInfo>();

            if (Directory.Exists(folder))
            {
                foreach (string subfolder in Directory.GetDirectories(folder))
                {
                    var game = FindGame(detector, new GameFolder(subfolder));
                    if (game != null)
                    {
                        // A game was found, so we do not go any further down that folder
                        games.Add(game);
                    }
                    else if (recursive)
                    {
                        games.AddRange(FindGames(detector, subfolder, true));
                    }
                }

                foreach (string zipFile in Directory.GetFiles(folder, "*.zip"))
                {
                    var game = FindGame(detector, new GameZipArchive(zipFile));
                    if (game != null)
                    {
                        games.Add(game);
                    }
                }
            }

            return(games.ToArray());
        }
        private async void ChooseGamePath_Click(object sender, RoutedEventArgs e)
        {
            MenuFlyoutItem sourceItem  = (MenuFlyoutItem)sender;
            StorageFile    customsFile = null;

            //Open Picker
            if (sourceItem.Tag == null)
            {
                FolderPicker fP = new FolderPicker();
                fP.FileTypeFilter.Add("*");
                fP.SuggestedStartLocation = PickerLocationId.ComputerFolder;

                do
                {
                    StorageFolder gameFolder = null;
                    try {
                        gameFolder = await fP.PickSingleFolderAsync();
                    }
                    catch (Exception) { };
                    if (gameFolder == null)
                    {
                        break;
                    }
                    customsFile = await GameDetector.IsValidGameFolder(gameFolder);

                    if (customsFile == null)
                    {
                        await ShowDialog("Error", "Game location could not be verified. Please choose again.");
                    }
                } while (customsFile == null);
            }
            else
            {
                customsFile = (StorageFile)sourceItem.Tag;
            }

            //Only open if selection valid
            if (customsFile != null)
            {
                string onError = null;
                (uuidStorage, onError) = await Deserializer.DeserializeCustomizationOptionsAsync(customsFile);

                if (uuidStorage == null || onError != null)
                {
                    await ShowDialog("Error", onError);

                    return;
                }

                //Enable Unlockbutton
                if (saveFolder != null && uuidStorage != null)
                {
                    UnlockButton.IsEnabled = true;
                }
                GamePathButton.Content = "Extracted " + this.uuidStorage.Count() / 16 + " outfit options ✔️";
            }
        }
Exemple #4
0
        public GameLibraryViewModel()
        {
            _gameSignatures = new HashSet <string>();
            _games          = new ObservableCollection <GameViewModel>();
            _addCommand     = new DelegateCommand(Scan);

            GameDetector = new GameDetector();
            GameDetector.Add(new ScummMetaEngine());
            GameDetector.Add(new SkyMetaEngine());
            GameDetector.Add(new Sword1.Sword1MetaEngine());

            LoadGameLibrary();
        }
Exemple #5
0
        private static GameStartInfo FindGame(GameDetector detector, IGameContainer container)
        {
            GameStartInfo startInfo = null;

            var result = detector.Detect(container);

            if (result.Detected)
            {
                string id = ResourceLoader.GetGameId(container);

                startInfo = new GameStartInfo(container, id, result.Platform, result.Interpreter, result.Name, result.Version);
            }

            return(startInfo);
        }
        private async void FillGamePathList()
        {
            List <(string path, StorageFile customsFile)> gameInstallations = await GameDetector.TryFindGameFolders();

            foreach ((string path, StorageFile customsFile) in gameInstallations)
            {
                MenuFlyoutItem flyout = new MenuFlyoutItem {
                    Tag  = customsFile,
                    Text = path
                };
                flyout.Click += ChooseGamePath_Click;
                GamePathListMenu.Items.Add(flyout);
            }

            //Manual Game Path Selection
            MenuFlyoutItem lastFlyout = new MenuFlyoutItem();

            lastFlyout.Text   = "Choose other";
            lastFlyout.Click += ChooseGamePath_Click;
            GamePathListMenu.Items.Add(lastFlyout);
        }
        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);

            if (Settings.Default.AutoShowOverlay)
            {
                ShowOverlay();
            }

            _ = lightsManager.SwitchToDefaultColor();

            if (GameDetector.IsGameRunning())
            {
                var dialog = new RoleDialog();
                dialog.ShowDialog(this);
                AdjustForCurrentRole(dialog.SelectedRole);
            }
            else if (Settings.Default.AutoStartGame)
            {
                GameDetector.LauchGame();
            }
        }
        private void OpenItem_OnClick(object sender, RoutedEventArgs e)
        {
            var ofd = new OpenFileDialog()
            {
                Filter           = "Bundle Files|*.BUN;*.BIN|All Files|*.*",
                Multiselect      = true,
                RestoreDirectory = true,
                CheckFileExists  = true,
                CheckPathExists  = true
            };

            if (ofd.ShowDialog() == true)
            {
                _game = GameDetector.Game.Unknown;
                var canContinue = true;
                var fileList    = ofd.FileNames.ToList();

                Title = $"NFS Viewer v{Assembly.GetExecutingAssembly().GetName().Version}";

                foreach (var fileName in fileList.ToList())
                {
                    var fullDirectory = Path.GetDirectoryName(fileName);

                    if (fullDirectory == null)
                    {
                        throw new NullReferenceException("fullDirectory == null");
                    }

                    var parentDirectory = Directory.GetParent(fullDirectory);

                    if (string.Equals("CARS", parentDirectory.Name, StringComparison.CurrentCultureIgnoreCase))
                    {
                        var texPath = Path.Combine(parentDirectory.FullName, "TEXTURES.BIN");
                        if (!fileList.Contains(texPath))
                        {
                            fileList.Add(texPath);
                        }
                        parentDirectory = Directory.GetParent(parentDirectory.FullName);
                    }
                    else if (string.Equals("FRONTEND", parentDirectory.Name, StringComparison.CurrentCultureIgnoreCase))
                    {
                        parentDirectory = Directory.GetParent(parentDirectory.FullName);
                    }
                    else if (string.Equals("TRACKS", parentDirectory.Name, StringComparison.CurrentCultureIgnoreCase))
                    {
                        parentDirectory = Directory.GetParent(parentDirectory.FullName);
                    }

                    var detectedGame = GameDetector.DetectGame(parentDirectory.FullName);

                    if (detectedGame != GameDetector.Game.World &&
                        detectedGame != GameDetector.Game.MostWanted &&
                        detectedGame != GameDetector.Game.Carbon &&
                        detectedGame != GameDetector.Game.ProStreet &&
                        detectedGame != GameDetector.Game.Underground &&
                        detectedGame != GameDetector.Game.Underground2 &&
                        detectedGame != GameDetector.Game.Undercover)
                    {
                        MessageUtil.ShowError("Unsupported game!");
                        canContinue = false;
                        break;
                    }

                    if (_game != GameDetector.Game.Unknown && _game != detectedGame)
                    {
                        MessageUtil.ShowError("Don't mess with me like this");
                        canContinue = false;
                        break;
                    }

                    _game = detectedGame;
                }

                if (!canContinue)
                {
                    MessageUtil.ShowError("Cannot open files.");
                    return;
                }

                Log.PushSimple(LogModel.LogLevel.Info, $"Loading {fileList.Count} file(s) in {_game} mode");

                // Data cleanup
                Containers.Clear();
                RenderManager.Reset();
                // RenderManager.Instance.Reset();
                AssetRegistry.Instance.Reset();

                foreach (var file in fileList)
                {
                    var stopwatch = new Stopwatch();
                    var cm        = new ChunkManager(_game);

                    stopwatch.Start();
                    cm.Read(file);
                    stopwatch.Stop();

                    Log.PushSimple(LogModel.LogLevel.Info, $"Loaded [{file}] in {stopwatch.ElapsedMilliseconds}ms");

                    var resources = cm.Chunks.Where(c => c.Resource != null).Select(c => c.Resource).ToList();

                    var container = new FileContainer
                    {
                        FileName   = Path.GetFileName(file),
                        InnerFiles = new ObservableCollection <FileAssetContainer>(),
                        Assets     = new ObservableCollection <FileAssetContainer>(resources.Select(r =>
                        {
                            FileAssetContainer fac = new NullAsset();

                            switch (r)
                            {
                            case TexturePack tpk:
                                fac = new TexturePackAsset
                                {
                                    Resource  = tpk,
                                    SubAssets = new ObservableCollection <FileAssetContainer>()
                                };

                                foreach (var texture in tpk.Textures.OrderBy(t => t.Name))
                                {
                                    fac.SubAssets.Add(new TextureAsset
                                    {
                                        Resource   = texture,
                                        IsSelected = false
                                    });
                                }

                                break;

                            case SolidList solidList:
                                fac = new SolidListAsset
                                {
                                    Resource  = solidList,
                                    SubAssets = new ObservableCollection <FileAssetContainer>()
                                };

                                foreach (var solidObject in solidList.Objects.OrderBy(o => o.Name))
                                {
                                    fac.SubAssets.Add(new SolidObjectAsset
                                    {
                                        Resource   = solidObject,
                                        IsSelected = false
                                    });
                                }


                                break;
                            }

                            return(fac);
                        }))
                    };

                    Containers.Add(container);
                }
            }
        }
        private void OpenMapItem_OnClick(object sender, RoutedEventArgs e)
        {
            var openFolder = new OpenFileDialog()
            {
                Filter           = "Bundle Files|*.BUN;*.BIN|All Files|*.*",
                RestoreDirectory = true,
                CheckFileExists  = true,
                CheckPathExists  = true
            };

            if (openFolder.ShowDialog() == true)
            {
                var fileName      = openFolder.FileName;
                var fullDirectory = new DirectoryInfo(fileName).Parent;

                if (fullDirectory?.Name.ToLower() != "tracks" &&
                    fullDirectory?.Name.ToLower() != "trackshigh")
                {
                    MessageUtil.ShowError("Looks like you're using the wrong menu command...");
                    return;
                }

                var parentDirectory = fullDirectory.Parent;

                if (parentDirectory != null)
                {
                    var game = _game = GameDetector.DetectGame(parentDirectory.FullName);

                    if (game == GameDetector.Game.Unknown)
                    {
                        MessageUtil.ShowError("Cannot determine installed game.");
                        return;
                    }

                    Log.PushSimple(LogModel.LogLevel.Info, $"Loading [{fileName}] in {game} mode");

                    GameBundleManager gbm;

                    switch (game)
                    {
                    case GameDetector.Game.MostWanted:
                    {
                        gbm = new MostWantedManager();
                        break;
                    }

                    case GameDetector.Game.Carbon:
                    {
                        gbm = new CarbonManager();
                        break;
                    }

                    case GameDetector.Game.ProStreet:
                    case GameDetector.Game.ProStreetTest:
                    {
                        gbm = new ProStreetManager();
                        break;
                    }

                    case GameDetector.Game.Undercover:
                    {
                        gbm = new UndercoverManager();
                        break;
                    }

                    case GameDetector.Game.World:
                    {
                        gbm = new World15Manager();
                        break;
                    }

                    default:
                        throw new ArgumentOutOfRangeException(nameof(game), game, "Invalid game!");
                    }

                    Containers.Clear();
                    //MainVisual.Children.Clear();
                    // RenderManager.Instance.Reset();
                    AssetRegistry.Instance.Reset();

                    LocationBundle bundle;

                    try
                    {
                        bundle = gbm.ReadLocationBundle(fileName);
                    }
                    catch (Exception)
                    {
                        MessageUtil.ShowError("This is not a map file.");
                        return;
                    }

                    //var bundle = gbm.ReadLocationBundle(fileName);
                    var rootContainer = new FileContainer
                    {
                        FileName = fileName,
                        Assets   = new ObservableCollection <FileAssetContainer>()
                    };

                    BinaryReader masterStream = null;

                    if (game != GameDetector.Game.World)
                    {
                        masterStream = new BinaryReader(
                            File.OpenRead(
                                Path.Combine(fullDirectory.FullName, $"STREAM{bundle.Name}.BUN")));
                    }

                    if (game == GameDetector.Game.ProStreet &&
                        (string.Equals(bundle.Name.ToLower(), "l6r_lodtest") ||
                         string.Equals(bundle.Name.ToLower(), "l6r_lighting") ||
                         string.Equals(bundle.Name.ToLower(), "l6r_nis") ||
                         string.Equals(bundle.Name.ToLower(), "l6r_testtrack")))
                    {
                        game = GameDetector.Game.ProStreetTest;
                    }

                    var stopwatch = new Stopwatch();
                    var cm        = new ChunkManager(game);
                    stopwatch.Start();

                    foreach (var section in bundle.Sections.OrderBy(s => s.Number))
                    {
                        cm.Reset();

                        var sectionContainer = new SectionContainer
                        {
                            Section   = section,
                            SubAssets = new ObservableCollection <FileAssetContainer>()
                        };

                        // NFS:World loading requires creation of independent file streams
                        if (section is WorldStreamSection wss)
                        {
                            var computedPath = Path.Combine(fullDirectory.FullName,
                                                            wss.FragmentFileId == 0
                                    ? $"STREAM{bundle.Name}_{wss.Number}.BUN"
                                    : $"STREAM{bundle.Name}_0x{wss.FragmentFileId:X8}.BUN");
                            cm.Read(computedPath);
                        }
                        else
                        {
                            if (masterStream != null)
                            {
                                masterStream.BaseStream.Position = section.Offset;

                                var sectionData = masterStream.ReadBytes((int)section.Size);

                                using (var br = new BinaryReader(new MemoryStream(sectionData)))
                                {
                                    cm.Read(br);
                                }
                            }
                        }

                        var resources = cm.Chunks.Where(c => c.Resource != null).Select(c => c.Resource).ToList();

                        sectionContainer.SubAssets = new ObservableCollection <FileAssetContainer>(resources.Select(r =>
                        {
                            FileAssetContainer fac = new NullAsset();

                            switch (r)
                            {
                            case TexturePack tpk:
                                fac = new TexturePackAsset
                                {
                                    Resource  = tpk,
                                    SubAssets = new ObservableCollection <FileAssetContainer>()
                                };

                                foreach (var texture in tpk.Textures.OrderBy(t => t.Name))
                                {
                                    fac.SubAssets.Add(new TextureAsset
                                    {
                                        Resource   = texture,
                                        IsSelected = false
                                    });
                                }

                                break;

                            case SolidList solidList:
                                fac = new SolidListAsset
                                {
                                    Resource  = solidList,
                                    SubAssets = new ObservableCollection <FileAssetContainer>()
                                };

                                foreach (var solidObj in solidList.Objects.OrderBy(o => o.Name))
                                {
                                    fac.SubAssets.Add(new SolidObjectAsset
                                    {
                                        Resource   = solidObj,
                                        IsSelected = false
                                    });
                                }

                                break;
                            }

                            return(fac);
                        }));

                        rootContainer.Assets.Add(sectionContainer);
                    }

                    stopwatch.Stop();

                    Log.PushSimple(LogModel.LogLevel.Info, $"Loaded {fileName} [{stopwatch.ElapsedMilliseconds}ms]");

                    Containers.Add(rootContainer);

                    masterStream?.Dispose();

                    Title = $"NFS Viewer v{Assembly.GetExecutingAssembly().GetName().Version} - [{fileName} ({game})]";

                    RenderManager.Reset();
                }
            }
        }
Exemple #10
0
        static int Main(string[] args)
        {
            var    musicDriver      = "adlib";
            var    showVersion      = false;
            var    showHelp         = false;
            var    listAudioDevices = false;
            var    bootParam        = 0;
            var    copyProtection   = false;
            string switches         = null;
            var    options          = new OptionSet
            {
                { "v|version", "Display NScumm version information and exit", v => showVersion = v != null },
                { "h|help", "Display a brief help text and exit", h => showHelp = h != null },
                { "e|music-driver=", "Select music driver", d => musicDriver = d },
                { "list-audio-devices", "List all available audio devices", b => listAudioDevices = b != null },
                { "b|boot-param=", "Pass number to the boot script (boot param)", (int b) => bootParam = b },
                { "debugflags=", "Enable engine specific debug flags (separated by commas)", d => switches = d },
                { "copy_protection", "Enable copy protection in SCUMM games, when NScumm disables it by default.", b => copyProtection = b != null }
            };

            try
            {
                var extras = options.Parse(args);
                Initialize(switches);
                if (showVersion)
                {
                    ShowVersion();
                }
                else if (showHelp)
                {
                    Usage(options);
                }
                else if (listAudioDevices)
                {
                    ListAudioDevices();
                }
                else if (extras.Count == 1)
                {
                    var path = ScummHelper.NormalizePath(extras[0]);
                    if (File.Exists(path))
                    {
                        var pluginsdDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "plugins");
                        var gd = new GameDetector();
                        gd.AddPluginsFromDirectory(pluginsdDirectory);
                        var info = gd.DetectGame(path);
                        if (info == null)
                        {
                            Console.Error.WriteLine("This game is not supported, sorry please contact me if you want to support this game.");
                        }
                        else
                        {
                            ((AudioManager)ServiceLocator.AudioManager).Directory = Path.GetDirectoryName(info.Game.Path);
                            var settings = new GameSettings(info.Game, info.Engine)
                            {
                                AudioDevice = musicDriver, CopyProtection = copyProtection, BootParam = bootParam
                            };
                            var game = new ScummGame(settings);
                            game.Services.AddService <IMenuService>(new MenuService(game));
                            game.Run();
                        }
                    }
                    else
                    {
                        Console.Error.WriteLine("The file {0} does not exist.", path);
                    }
                }
                else
                {
                    Usage(options);
                    return(1);
                }
            }
            catch (ArgumentException)
            {
                Usage(options);
                return(1);
            }
            catch (OptionException)
            {
                Usage(options);
                return(1);
            }
            return(0);
        }
Exemple #11
0
 private void StartGame_Click(object sender, EventArgs e)
 {
     GameDetector.LauchGame();
 }
 /// <summary>
 /// Cancels the search for installed games.
 /// </summary>
 public void Cancel()
 {
     GameDetector.Cancel();
 }