Пример #1
0
        private void GameInformation_Load(object sender, EventArgs e)
        {
            this.Localize();

            var record = GameRegistrar.GetGameRecordById(this.GameSource.GetGameId());

            this.GameNameTextBox.Text           = record == null ? " - " : record.Name;
            this.GameNameTextBox.SelectionStart = 0;

            this.GameIdTextBox.Text           = this.GameSource.GetGameId();
            this.GameIdTextBox.SelectionStart = 0;

            this.ReleaseYearTextBox.Text           = record == null ? " - " : record.ReleaseYear;
            this.ReleaseYearTextBox.SelectionStart = 0;

            this.PublisherTextBox.Text           = record == null ? " - " : record.Publisher;
            this.PublisherTextBox.SelectionStart = 0;

            this.RegionsTextBox.Text           = record == null ? " - " : record.Regions;
            this.RegionsTextBox.SelectionStart = 0;

            if (record == null && (this.GameSource is GameSourceBase))
            {
                // This will read sectors, but oh well.
                this.ChecksumTextBox.Text = GameRegistrar.CalculateGameChecksum((GameSourceBase)this.GameSource);
            }
            else
            {
                // This will read sectors, but oh well.
                this.ChecksumTextBox.Text = record == null ? " - " : record.CheckSum;
            }
            this.ChecksumTextBox.SelectionStart = 0;
        }
Пример #2
0
        public void TestInstallLocalUpdateToInstalledGame()
        {
            //lets pretend that this game is already installed.
            FileSystem.Current.GetDirectory("c:\\program files\\MGDF\\game").Create();
            FileSystem.Current.GetFile("c:\\program files\\MGDF\\game\\game.json").WriteText(ReadTextFile("console.json"));
            FileSystem.Current.GetDirectory("c:\\program files\\MGDF\\game\\content").Create();
            FileSystem.Current.GetFile("c:\\program files\\MGDF\\game\\content\\test.json").WriteText("blah");
            Registry.Current.CreateSubKey(BaseRegistryKey.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MGDF1_Console");

            MockArchiveFile archive = new MockArchiveFile(null, "C:\\Documents and Settings\\user\\desktop\\game.zip");

            new MockArchiveFile(archive, "game.json", @"{
  ""gameUid"":""Console"",
  ""gameName"":""Lua Console"",
  ""description"":""A Lua command console for interacting with the MGDF system"",
  ""version"":""1.0.0.0"",
  ""interfaceVersion"":""1"",
  ""developerUid"":""no-8"",
  ""developerName"":""no8 interactive"",
  ""homepage"":""http://www.junkship.org"",
  ""gamesourceService"":""http://games.junkship.org/gamesource.asmx"",
  ""statisticsService"":""http://statistics.junkship.org/statisticsservice.asmx"",
  ""statisticsPrivacyPolicy"":""We wont use ur informationz"",
  ""supportEmail"":""*****@*****.**""
}");
            new MockArchiveFile(archive, "update.json", ReadTextFile("update.json"));
            new MockArchiveFile(archive, "content");
            new MockArchiveFile(archive, "bin");
            ((MockArchiveFactory)ArchiveFactory.Current).VirtualArchives.Add("C:\\Documents and Settings\\user\\desktop\\game.zip", archive);

            GameInstall install = new GameInstall("C:\\Documents and Settings\\user\\desktop\\game.zip");

            Assert.IsTrue(install.IsValid);

            GameUpdater updater = new GameUpdater(install);

            updater.Start();

            //check that all the games content was copied across
            Assert.IsTrue(FileSystem.Current.GetDirectory("c:\\program files\\MGDF\\game").Exists);
            Assert.IsTrue(FileSystem.Current.GetFile("c:\\program files\\MGDF\\game\\game.json").Exists);
            Assert.IsTrue(FileSystem.Current.GetDirectory("c:\\program files\\MGDF\\game\\content").Exists);
            Assert.IsTrue(FileSystem.Current.GetDirectory("c:\\program files\\MGDF\\game\\bin").Exists);
            //did the update remove the file specified
            Assert.IsFalse(FileSystem.Current.GetFile("c:\\program files\\MGDF\\game\\content\\test.json").Exists);

            Game game = new Game("c:\\program files\\MGDF\\game\\game.json");

            Assert.IsTrue(game.IsValid);

            GameRegistrar registrar = new GameRegistrar(true, game);

            registrar.Start();

            //assert the shortcuts are in the right place
            var key = Registry.Current.OpenSubKey(BaseRegistryKey.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MGDF1_Console");

            Assert.IsNotNull(key);
            Assert.AreEqual("c:\\program files\\MGDF\\resources\\gamesystemicon.ico", key.GetValue("DisplayIcon"));
            Assert.AreEqual("Lua Console", key.GetValue("DisplayName"));
            Assert.AreEqual("http://www.junkship.org", key.GetValue("URLInfoAbout"));
            Assert.AreEqual(1, key.GetDwordValue("NoModify"));
            Assert.AreEqual(1, key.GetDwordValue("NoRepair"));
            Assert.AreEqual("no8 interactive", key.GetValue("Publisher"));
            Assert.AreEqual("c:\\program files\\MGDF\\game", key.GetValue("InstallLocation"));
            Assert.AreEqual("1.0.0.0", key.GetValue("DisplayVersion"));

            //assert the shortcuts are in the right place
            Assert.IsTrue(FileSystem.Current.GetFile("c:\\Documents and Settings\\user\\desktop\\Lua Console.lnk").Exists);
            Assert.IsTrue(FileSystem.Current.GetDirectory("c:\\Documents and Settings\\user\\start menu\\no8 interactive").Exists);
            Assert.IsTrue(FileSystem.Current.GetFile("c:\\Documents and Settings\\user\\start menu\\no8 interactive\\Lua Console.lnk").Exists);

            registrar = new GameRegistrar(false, game);
            registrar.Start();

            //assert the registry key has been removed
            key = Registry.Current.OpenSubKey(BaseRegistryKey.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MGDF1_Console");
            Assert.IsNull(key);

            //shortcuts should have been removed
            Assert.IsFalse(FileSystem.Current.GetFile("c:\\Documents and Settings\\user\\desktop\\Lua Console.lnk").Exists);
            Assert.IsFalse(FileSystem.Current.GetFile("c:\\Documents and Settings\\user\\start menu\\no8 interactive\\Lua Console.lnk").Exists);
        }
Пример #3
0
        public void TestUpdateLocalGameWithFullInstaller(bool includeGdfDll)
        {
            MockArchiveFile archive = new MockArchiveFile(null, "C:\\Documents and Settings\\user\\desktop\\game.zip");

            new MockArchiveFile(archive, "game.json", ReadTextFile("console.json"));
            new MockArchiveFile(archive, "preferences.json", ReadTextFile("preferences.json"));
            if (includeGdfDll)
            {
                new MockArchiveFile(archive, "gdf.dll", "GAMES_EXPLORER_DEFINITION");
            }
            new MockArchiveFile(archive, "content");
            new MockArchiveFile(archive, "bin");
            ((MockArchiveFactory)ArchiveFactory.Current).VirtualArchives.Add("C:\\Documents and Settings\\user\\desktop\\game.zip", archive);

            var gameInstall = new GameInstall("C:\\Documents and Settings\\user\\desktop\\game.zip");

            Assert.IsTrue(gameInstall.IsValid);

            GameUpdater updater = new GameUpdater(gameInstall);

            updater.Start();

            //check that all the games content was copied across
            Assert.IsTrue(FileSystem.Current.GetDirectory("c:\\program files\\MGDF\\game").Exists);
            Assert.IsTrue(FileSystem.Current.GetFile("c:\\program files\\MGDF\\game\\game.json").Exists);
            Assert.IsTrue(FileSystem.Current.GetFile("c:\\program files\\MGDF\\game\\preferences.json").Exists);
            Assert.IsTrue(FileSystem.Current.GetDirectory("c:\\program files\\MGDF\\game\\content").Exists);
            Assert.IsTrue(FileSystem.Current.GetDirectory("c:\\program files\\MGDF\\game\\bin").Exists);

            Game game = new Game("c:\\program files\\MGDF\\game\\game.json");

            Assert.IsTrue(game.IsValid);

            var key = Registry.Current.CreateSubKey(BaseRegistryKey.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MGDF1_Console");

            GameRegistrar registrar = new GameRegistrar(true, game);

            registrar.Start();

            //assert the shortcuts are in the right place
            key = Registry.Current.OpenSubKey(BaseRegistryKey.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MGDF1_Console");
            Assert.IsNotNull(key);
            Assert.AreEqual("c:\\program files\\MGDF\\resources\\gamesystemicon.ico", key.GetValue("DisplayIcon"));
            Assert.AreEqual("Lua Console", key.GetValue("DisplayName"));
            Assert.AreEqual("http://www.junkship.org", key.GetValue("URLInfoAbout"));
            Assert.AreEqual(1, key.GetDwordValue("NoModify"));
            Assert.AreEqual(1, key.GetDwordValue("NoRepair"));
            Assert.AreEqual("no8 interactive", key.GetValue("Publisher"));
            Assert.AreEqual("c:\\program files\\MGDF\\game", key.GetValue("InstallLocation"));
            Assert.AreEqual("0.1", key.GetValue("DisplayVersion"));

            //assert the shortcuts are in the right place
            Assert.IsTrue(FileSystem.Current.GetFile("c:\\Documents and Settings\\user\\desktop\\Lua Console.lnk").Exists);
            Assert.IsTrue(FileSystem.Current.GetDirectory("c:\\Documents and Settings\\user\\start menu\\no8 interactive").Exists);
            Assert.IsTrue(FileSystem.Current.GetFile("c:\\Documents and Settings\\user\\start menu\\no8 interactive\\Lua Console.lnk").Exists);

            //assert the the game has been added to the games explorer
            Assert.AreEqual(includeGdfDll, GameExplorer.Current.IsInstalled("c:\\program files\\MGDF\\game\\gdf.dll"));

            //deregister the game
            registrar = new GameRegistrar(false, game);
            registrar.Start();

            //assert the shortcut has been removed
            key = Registry.Current.OpenSubKey(BaseRegistryKey.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MGDF1_Console");
            Assert.IsNull(key);

            //shortcuts should have been removed
            Assert.IsFalse(FileSystem.Current.GetFile("c:\\Documents and Settings\\user\\desktop\\Lua Console.lnk").Exists);
            Assert.IsFalse(FileSystem.Current.GetFile("c:\\Documents and Settings\\user\\start menu\\no8 interactive\\Lua Console.lnk").Exists);

            if (includeGdfDll)
            {
                //assert the the game has been removed from the games explorer
                Assert.IsTrue(!GameExplorer.Current.IsInstalled("c:\\program files\\MGDF\\game\\gdf.dll"));
            }
        }
Пример #4
0
        static int RunMain()
        {
            CommandLineParser commandLine;

            if (FileSystem.Current.FileExists(Resources.ParamsOverrideFile))
            {
                using (var stream = FileSystem.Current.GetFile(Resources.ParamsOverrideFile).OpenStream(FileMode.Open))
                {
                    using (var reader = new StreamReader(stream))
                    {
                        commandLine = new CommandLineParser(reader.ReadToEnd().Split(), false);
                    }
                }
            }
            else
            {
                commandLine = new CommandLineParser(Environment.GetCommandLineArgs());
            }

            Resources.InitGameDirectory(commandLine[Resources.GamesManagerArguments.GameDirOverrideArgument]);

            Application.ThreadException += Application_ThreadException;
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Game game = new Game(FileSystem.Combine(Resources.GameBaseDir, Resources.GameConfig));

            if (game.ErrorCollection.Count > 0)
            {
                ViewFactory.Current.CreateView <IMessage>().Show("Game configuration invalid " + game.ErrorCollection[0], "Game configuration invalid");
                return(-1);
            }
            Game.Current = game;

            Resources.InitUserDirectory(Game.Current.Uid, commandLine[Resources.GamesManagerArguments.UserDirOverrideArgument] != null);
            Logger.Current = new Logger(Path.Combine(Resources.GameUserDir, "GamesManagerLog.txt"));


            if (commandLine[Resources.GamesManagerArguments.RegisterArgument] != null)
            {
                Logger.Current.Write(LogInfoLevel.Info, "Registering game...");
                if (!UACControl.IsAdmin())
                {
                    Logger.Current.Write(LogInfoLevel.Error, "Registering requires administrator access");
                    ViewFactory.Current.CreateView <IMessage>().Show("Registering requires administrator access", "Administrator access required");
                    return(-1);
                }

                var installer = new GameRegistrar(true, Game.Current);
                return(installer.Start() == LongRunningTaskResult.Completed ? 0: -1);
            }
            else if (commandLine[Resources.GamesManagerArguments.DeregisterArgument] != null)
            {
                Logger.Current.Write(LogInfoLevel.Info, "Deregistering game...");
                if (!UACControl.IsAdmin())
                {
                    Logger.Current.Write(LogInfoLevel.Error, "Deregistering requires administrator access");
                    ViewFactory.Current.CreateView <IMessage>().Show("Deregistering requires administrator access", "Administrator access required");
                    return(-1);
                }

                var uninstaller = new GameRegistrar(false, Game.Current);
                return(uninstaller.Start() == LongRunningTaskResult.Completed ? 0 : -1);
            }
            else if (commandLine[Resources.GamesManagerArguments.UpdateFrameworkArgument] != null || commandLine[Resources.GamesManagerArguments.UpdateGameArgument] != null)
            {
                Logger.Current.Write(LogInfoLevel.Info, "Updating game/framework...");

                if (commandLine[Resources.GamesManagerArguments.UpdateFrameworkArgument] != null &&
                    commandLine[Resources.GamesManagerArguments.FrameworkUpdateHashArgument] == null)
                {
                    Logger.Current.Write(LogInfoLevel.Error, "Framework update MD5 hash argument missing");
                    ViewFactory.Current.CreateView <IMessage>().Show("Framework update MD5 hash argument missing", "Missing argument");
                    return(-1);
                }

                if (commandLine[Resources.GamesManagerArguments.UpdateGameArgument] != null &&
                    commandLine[Resources.GamesManagerArguments.GameUpdateHashArgument] == null)
                {
                    Logger.Current.Write(LogInfoLevel.Error, "Game update MD5 hash argument missing");
                    ViewFactory.Current.CreateView <IMessage>().Show("Game update MD5 hash argument missing", "Missing argument");
                    return(-1);
                }

                if (!UACControl.IsAdmin())
                {
                    Logger.Current.Write(LogInfoLevel.Error, "Updating requires administrator access");
                    ViewFactory.Current.CreateView <IMessage>().Show("Updating requires administrator access", "Administrator access required");
                    return(-1);
                }

                var presenter = new UpdateGamePresenter(
                    commandLine[Resources.GamesManagerArguments.UpdateGameArgument],
                    commandLine[Resources.GamesManagerArguments.GameUpdateHashArgument],
                    commandLine[Resources.GamesManagerArguments.UpdateFrameworkArgument],
                    commandLine[Resources.GamesManagerArguments.FrameworkUpdateHashArgument]);
                presenter.ShowView();
                Application.Run(presenter.View as Form);

                Process.Start(Resources.FrameworkUpdaterExecutable, Resources.GamesManagerBootArguments(string.Empty, string.Empty, string.Empty, string.Empty));
            }
            else
            {
                Logger.Current.Write(LogInfoLevel.Info, "Launching game...");
                var presenter = new LaunchGamePresenter(commandLine[Resources.GamesManagerArguments.NoUpdateCheckArgument] == null);
                presenter.ShowView();
                Application.Run(presenter.View as Form);
            }

            return(0);
        }
Пример #5
0
        public void Start(string biosRom1FileName, string biosRom2FileName, IGameSource gameSource, string nvramFileName)
        {
            int fixMode = 0;

            ///////////
            // If they haven't initialized us properly, complain!

            if (!this.maxLagTicks.HasValue)
            {
                throw new InvalidOperationException("Audio buffer not set!");
            }

            if (!this.cpuClockHertz.HasValue)
            {
                throw new InvalidOperationException("CPU Clock speed not set!");
            }

            if (!this.renderHighResolution.HasValue)
            {
                throw new InvalidOperationException("High resolution setting not set!");
            }

            // Are we already started?
            if (this.workerThread != null)
            {
                return;
            }

            this.GameSource = gameSource;

            //////////////
            // Attempt to load Bios #1.
            try
            {
                this.biosRom1Copy = System.IO.File.ReadAllBytes(biosRom1FileName);
            }
            catch
            {
                throw new BadBiosRom1Exception();
            }

            // Also get outta here if it's not the right length.
            if (this.biosRom1Copy.Length != ROM1_SIZE)
            {
                throw new BadBiosRom1Exception();
            }
            if (this.biosRom1Copy[28] == 234)
            {
                FreeDOCore.SetAnvilFix(30);
            }                                                                 //bios anvil
            //////////////
            // Attempt to load Bios #2.

            // If we don't load Bios #2, we'll just use all zeroes.
            this.biosRom2Copy = new byte[ROM2_SIZE];             // Allocate full size to get all 0's

            // Load from file, if a file was chosen
            byte[] biosRom2Bytes = null;
            if (!string.IsNullOrWhiteSpace(biosRom2FileName))
            {
                try
                {
                    biosRom2Bytes = System.IO.File.ReadAllBytes(biosRom2FileName);
                }
                catch
                {
                    throw new BadBiosRom2Exception();
                }

                // Bios #2 is allowed to be less than or equal to the right size.
                // The only example file I know of is less than (912KB) the actual size on the hardware (1MB).
                if (biosRom2Bytes.Length > ROM2_SIZE || biosRom2Bytes.Length == 0)
                {
                    throw new BadBiosRom2Exception();
                }



                // Copy to the member variable.
                biosRom2Bytes.CopyTo(this.biosRom2Copy, 0);
            }

            //////////////
            // Load a copy of the nvram.
            try
            {
                // If we previously had a game open, and they have now loaded
                // a new game, we want to make sure the game that was previously
                // open does not accidentally save.
                lock (nvramCopySemaphore)
                {
                    // Note that we copy to the OLD nvram file name, just in case.
                    if (this.nvramTimer.Enabled == true)
                    {
                        Memory.WriteMemoryDump(this.nvramFileName, this.nvramCopyPtr, NVRAM_SIZE);
                    }

                    this.nvramTimer.Enabled = false;

                    // Read the new NVRAM into memory.
                    Memory.ReadMemoryDump(this.nvramCopy, nvramFileName, NVRAM_SIZE);
                }
            }
            catch
            {
                throw new BadNvramFileException();
            }

            // Freak out if the nvram isn't the right size.
            if (this.nvramCopy.Length != NVRAM_SIZE)
            {
                throw new BadNvramFileException();
            }

            // Remember the file name.
            this.nvramFileName = nvramFileName;

            //////////////
            // Attempt to start up the game source (it is allowed to throw errors).
            try
            {
                this.GameSource.Open();
            }
            catch
            {
                throw new BadGameRomException();
            }

            FreeDOCore.SetFixMode(fixMode);

            /////////////////
            // Initialize the core
            FreeDOCore.Initialize();

            ////////////////
            // Set fix mode
            GameRecord record = GameRegistrar.GetGameRecordById(this.GameSource.GetGameId());

            if (record != null)
            {
                if (
                    record.Id == "F3AF1B13" || // Crash 'n Burn (JP)
                    record.Id == "217344B0"    // Crash 'n Burn (US)

                    )
                {
                    fixMode = fixMode | (int)FixMode.FIX_BIT_TIMING_1;
                }

                if (record.Id == "DBB419FA" || // Street Figthter 2, for intro sync
                    record.Id == "07C32F10" ||// Street Figthter 2, for intro sync
                    record.Id == "5282889F" ||// Street Figthter 2, for intro sync
                    record.Id == "7340307E"   // Street Figthter 2, for intro sync
                    )
                {
                    fixMode = fixMode | (int)FixMode.FIX_BIT_TIMING_2;
                }

                if (record.Id == "CB8EE795" // Dinopark Tycoon
                    )
                {
                    fixMode = fixMode | (int)FixMode.FIX_BIT_TIMING_3;
                }

                if (record.Id == "1A370EBA" || // Microcosm
                    record.Id == "B35C911D"// Microcosm
                    )
                {
                    fixMode = fixMode | (int)FixMode.FIX_BIT_TIMING_5;
                }

                if (record.Id == "0511D3D2" || // Alone in the Dark
                    record.Id == "9F7D72BC" ||// Alone in the Dark
                    record.Id == "E843C635"// Alone in the Dark
                    )
                {
                    fixMode = fixMode | (int)FixMode.FIX_BIT_TIMING_6;
                }

                if (record.Id == "2AABA5B9" || // Samurai Shodown (EU-US)
                    record.Id == "BF61BB32"    // Samurai Shodown (JP)
                    )
                {
                    fixMode = fixMode | (int)FixMode.FIX_BIT_GRAPHICS_STEP_Y;
                }
            }
            FreeDOCore.SetFixMode(fixMode);
            /////////////////
            // Start the core thread
            this.InternalResume(false);
        }