예제 #1
0
    public static void Main(string[] args)
    {
        MpqContainer mpq = new MpqContainer();

        mpq.Add(new MpqArchive("/home/toshok/src/starcraft/sc-cd/install.exe"));
        mpq.Add(new MpqArchive("/home/toshok/src/starcraft/starcraft/StarDat.mpq"));

        Fnt fnt = (Fnt)mpq.GetResource("files\\font\\font16.fnt");

        Console.WriteLine("loading font palette");
        Stream palStream = (Stream)mpq.GetResource("glue\\Palmm\\tFont.pcx");
        Pcx    pcx1      = new Pcx();

        pcx1.ReadFromStream(palStream, -1, -1);

        Painter.InitializePainter(false, 300);

        Surface textSurf1 = GuiUtil.ComposeText(str1, fnt, pcx1.Palette);
        Surface textSurf2 = GuiUtil.ComposeText(str2, fnt, pcx1.Palette);
        Surface textSurf3 = GuiUtil.ComposeText(str3, fnt, pcx1.Palette);
        Surface textSurf4 = GuiUtil.ComposeText(str4, fnt, pcx1.Palette);

        Surface backgroundSurface = new Surface(Painter.SCREEN_RES_X, Painter.SCREEN_RES_Y);

        backgroundSurface.Fill(new Rectangle(new Point(0, 0), backgroundSurface.Size), Color.Red);

        Painter.Add(Layer.UI,
                    delegate(DateTime now) {
            int y = 0;
            Painter.Blit(textSurf1, new Point(0, y)); y += textSurf1.Height;
            Painter.Blit(textSurf2, new Point(0, y)); y += textSurf2.Height;
            Painter.Blit(textSurf3, new Point(0, y)); y += textSurf3.Height;
            Painter.Blit(textSurf4, new Point(0, y)); y += textSurf4.Height;
        });

        Painter.Add(Layer.Background,
                    delegate(DateTime now) {
            Painter.Blit(backgroundSurface);
        });

        Events.KeyboardUp += delegate(object o, KeyboardEventArgs keyargs) {
            if (keyargs.Key == Key.Escape)
            {
                Events.QuitApplication();
            }
        };

        Events.Run();
    }
예제 #2
0
파일: Game.cs 프로젝트: carriercomm/scsharp
		public Game (string starcraftDir, string scCDDir, string bwCDDir)
		{
			instance = this;

			starcraftDir = starcraftDir.Replace ('\\', Path.DirectorySeparatorChar)
						   .Replace ('/', Path.DirectorySeparatorChar);

			scCDDir = scCDDir.Replace ('\\', Path.DirectorySeparatorChar)
					 .Replace ('/', Path.DirectorySeparatorChar);

			bwCDDir = bwCDDir.Replace ('\\', Path.DirectorySeparatorChar)
					 .Replace ('/', Path.DirectorySeparatorChar);

			screens = new UIScreen[(int)UIScreenType.ScreenCount];

			installedMpq = new MpqContainer ();
			playingMpq = new MpqContainer ();

			Mpq scMpq = null, bwMpq = null;

			if (starcraftDir != null) {
				foreach (string path in Directory.GetFileSystemEntries (starcraftDir)) {
					if (Path.GetFileName (path).ToLower() == "broodat.mpq" || Path.GetFileName (path).Equals ("Brood War Data")) {
						if (broodatMpq != null)
							throw new Exception ("You have multiple broodat.mpq files in your starcraft directory.");
						try {
							bwMpq = GetMpq (path);
							Console.WriteLine ("found BrooDat.mpq");
						}
						catch (Exception e) {
							throw new Exception (String.Format ("Could not read mpq archive {0}",
											    path),
									     e);
						}
					}
					else if (Path.GetFileName (path).ToLower() == "stardat.mpq" || Path.GetFileName (path).Equals ("Starcraft Data")) {
						if (stardatMpq != null)
							throw new Exception ("You have multiple stardat.mpq files in your starcraft directory.");
						try {
							scMpq = GetMpq (path);
							Console.WriteLine ("found StarDat.mpq");
						}
						catch (Exception e) {
							throw new Exception (String.Format ("could not read mpq archive {0}",
											    path),
									     e);
						}
					}
					else if (Path.GetFileName (path).ToLower() == "patch_rt.mpq" || Path.GetFileName (path).Equals ("Starcraft Mac Patch")) {
						if (patchRtMpq != null)
							throw new Exception ("You have multiple patch_rt.mpq files in your starcraft directory.");
						try {
							patchRtMpq = GetMpq (path);
							Console.WriteLine ("found patch_rt.mpq");
						}
						catch (Exception e) {
							throw new Exception (String.Format ("could not read mpq archive {0}",
											    path),
									     e);
						}
					}
					else if (Path.GetFileName (path).ToLower() == "starcraft.mpq") {
						try {
							scInstallExe = GetMpq (path);
							Console.WriteLine ("found starcraft.mpq");
						}
						catch (Exception e) {
							throw new Exception (String.Format ("could not read mpq archive {0}",
											    path),
									     e);
						}
					}
					else if (Path.GetFileName (path).ToLower() == "broodwar.mpq") {
						try {
							bwInstallExe = GetMpq (path);
							Console.WriteLine ("found broodwar.mpq");
						}
						catch (Exception e) {
							throw new Exception (String.Format ("could not read mpq archive {0}",
											    path),
									     e);
						}
					}
				}
			}

			if (scMpq == null) {
				throw new Exception ("unable to locate stardat.mpq, please check your StarcraftDirectory configuration setting");
			}

			if (!string.IsNullOrEmpty (scCDDir)) {
				foreach (string path in Directory.GetFileSystemEntries (scCDDir)) {
					if (Path.GetFileName (path).ToLower() == "install.exe" || Path.GetFileName (path).Equals ("Starcraft Archive")) {
						try {
							scInstallExe = GetMpq (path);
							Console.WriteLine ("found SC install.exe");
						}
						catch (Exception e) {
							throw new Exception (String.Format ("could not read mpq archive {0}",
											    path),
									     e);
						}
					}
				}
			}

			if (!string.IsNullOrEmpty (bwCDDir)) {
				foreach (string path in Directory.GetFileSystemEntries (bwCDDir)) {
					if (Path.GetFileName (path).ToLower() == "install.exe" || Path.GetFileName (path).Equals ("Brood War Archive")) {
						try {
							bwInstallExe = GetMpq (path);
							Console.WriteLine ("found BW install.exe");
						}
						catch (Exception e) {
							throw new Exception (String.Format ("could not read mpq archive {0}",
											    path),
									     e);
						}
					}
				}
			}

			if (bwInstallExe == null)
				throw new Exception ("unable to locate broodwar cd's install.exe, please check your BroodwarCDDirectory configuration setting");

			if (bwMpq != null) {
				if (patchRtMpq != null) {
					broodatMpq = new MpqContainer ();
					((MpqContainer)broodatMpq).Add (patchRtMpq);
					((MpqContainer)broodatMpq).Add (bwMpq);
				}
				else
					broodatMpq = bwMpq;
			}

			if (scMpq != null) {
				if (patchRtMpq != null) {
					stardatMpq = new MpqContainer ();
					((MpqContainer)stardatMpq).Add (patchRtMpq);
					((MpqContainer)stardatMpq).Add (scMpq);
				}
				else
					stardatMpq = bwMpq;
			}

			if (broodatMpq != null)
				installedMpq.Add (broodatMpq);
			if (bwInstallExe != null)
				installedMpq.Add (bwInstallExe);
			if (stardatMpq != null)
				installedMpq.Add (stardatMpq);
			if (scInstallExe != null)
				installedMpq.Add (scInstallExe);
			
			PlayingBroodWar = isBroodWar = (broodatMpq != null);
			
			this.rootDir = starcraftDir;
		}
예제 #3
0
        public Game(string starcraftDir, string scCDDir, string bwCDDir)
        {
            instance = this;

            starcraftDir = starcraftDir.Replace('\\', Path.DirectorySeparatorChar)
                           .Replace('/', Path.DirectorySeparatorChar);

            scCDDir = scCDDir.Replace('\\', Path.DirectorySeparatorChar)
                      .Replace('/', Path.DirectorySeparatorChar);

            bwCDDir = bwCDDir.Replace('\\', Path.DirectorySeparatorChar)
                      .Replace('/', Path.DirectorySeparatorChar);

            screens = new UIScreen[(int)UIScreenType.ScreenCount];

            installedMpq = new MpqContainer();
            playingMpq   = new MpqContainer();

            Mpq scMpq = null, bwMpq = null;

            if (starcraftDir != null)
            {
                foreach (string path in Directory.GetFileSystemEntries(starcraftDir))
                {
                    if (Path.GetFileName(path).ToLower() == "broodat.mpq" || Path.GetFileName(path).Equals("Brood War Data"))
                    {
                        if (broodatMpq != null)
                        {
                            throw new Exception("You have multiple broodat.mpq files in your starcraft directory.");
                        }
                        try {
                            bwMpq = GetMpq(path);
                            Console.WriteLine("found BrooDat.mpq");
                        }
                        catch (Exception e) {
                            throw new Exception(String.Format("Could not read mpq archive {0}",
                                                              path),
                                                e);
                        }
                    }
                    else if (Path.GetFileName(path).ToLower() == "stardat.mpq" || Path.GetFileName(path).Equals("Starcraft Data"))
                    {
                        if (stardatMpq != null)
                        {
                            throw new Exception("You have multiple stardat.mpq files in your starcraft directory.");
                        }
                        try {
                            scMpq = GetMpq(path);
                            Console.WriteLine("found StarDat.mpq");
                        }
                        catch (Exception e) {
                            throw new Exception(String.Format("could not read mpq archive {0}",
                                                              path),
                                                e);
                        }
                    }
                    else if (Path.GetFileName(path).ToLower() == "patch_rt.mpq" || Path.GetFileName(path).Equals("Starcraft Mac Patch"))
                    {
                        if (patchRtMpq != null)
                        {
                            throw new Exception("You have multiple patch_rt.mpq files in your starcraft directory.");
                        }
                        try {
                            patchRtMpq = GetMpq(path);
                            Console.WriteLine("found patch_rt.mpq");
                        }
                        catch (Exception e) {
                            throw new Exception(String.Format("could not read mpq archive {0}",
                                                              path),
                                                e);
                        }
                    }
                    else if (Path.GetFileName(path).ToLower() == "starcraft.mpq")
                    {
                        try {
                            scInstallExe = GetMpq(path);
                            Console.WriteLine("found starcraft.mpq");
                        }
                        catch (Exception e) {
                            throw new Exception(String.Format("could not read mpq archive {0}",
                                                              path),
                                                e);
                        }
                    }
                    else if (Path.GetFileName(path).ToLower() == "broodwar.mpq")
                    {
                        try {
                            bwInstallExe = GetMpq(path);
                            Console.WriteLine("found broodwar.mpq");
                        }
                        catch (Exception e) {
                            throw new Exception(String.Format("could not read mpq archive {0}",
                                                              path),
                                                e);
                        }
                    }
                }
            }

            if (scMpq == null)
            {
                throw new Exception("unable to locate stardat.mpq, please check your StarcraftDirectory configuration setting");
            }

            if (!string.IsNullOrEmpty(scCDDir))
            {
                foreach (string path in Directory.GetFileSystemEntries(scCDDir))
                {
                    if (Path.GetFileName(path).ToLower() == "install.exe" || Path.GetFileName(path).Equals("Starcraft Archive"))
                    {
                        try {
                            scInstallExe = GetMpq(path);
                            Console.WriteLine("found SC install.exe");
                        }
                        catch (Exception e) {
                            throw new Exception(String.Format("could not read mpq archive {0}",
                                                              path),
                                                e);
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(bwCDDir))
            {
                foreach (string path in Directory.GetFileSystemEntries(bwCDDir))
                {
                    if (Path.GetFileName(path).ToLower() == "install.exe" || Path.GetFileName(path).Equals("Brood War Archive"))
                    {
                        try {
                            bwInstallExe = GetMpq(path);
                            Console.WriteLine("found BW install.exe");
                        }
                        catch (Exception e) {
                            throw new Exception(String.Format("could not read mpq archive {0}",
                                                              path),
                                                e);
                        }
                    }
                }
            }

            if (bwInstallExe == null)
            {
                throw new Exception("unable to locate broodwar cd's install.exe, please check your BroodwarCDDirectory configuration setting");
            }

            if (bwMpq != null)
            {
                if (patchRtMpq != null)
                {
                    broodatMpq = new MpqContainer();
                    ((MpqContainer)broodatMpq).Add(patchRtMpq);
                    ((MpqContainer)broodatMpq).Add(bwMpq);
                }
                else
                {
                    broodatMpq = bwMpq;
                }
            }

            if (scMpq != null)
            {
                if (patchRtMpq != null)
                {
                    stardatMpq = new MpqContainer();
                    ((MpqContainer)stardatMpq).Add(patchRtMpq);
                    ((MpqContainer)stardatMpq).Add(scMpq);
                }
                else
                {
                    stardatMpq = bwMpq;
                }
            }

            if (broodatMpq != null)
            {
                installedMpq.Add(broodatMpq);
            }
            if (bwInstallExe != null)
            {
                installedMpq.Add(bwInstallExe);
            }
            if (stardatMpq != null)
            {
                installedMpq.Add(stardatMpq);
            }
            if (scInstallExe != null)
            {
                installedMpq.Add(scInstallExe);
            }

            PlayingBroodWar = isBroodWar = (broodatMpq != null);

            this.rootDir = starcraftDir;
        }