Example #1
0
        public MapRenderer(Mpq mpq, Chk chk)
        {
            this.mpq = mpq;
            this.chk = chk;

            pixel_width = (ushort)(chk.Width * 32);
            pixel_height = (ushort)(chk.Height * 32);

            Stream cv5_fs = (Stream)mpq.GetResource (String.Format ("tileset\\{0}.cv5", Util.TilesetNames[(int)chk.Tileset]));
            cv5 = new byte [cv5_fs.Length];
            cv5_fs.Read (cv5, 0, (int)cv5_fs.Length);
            cv5_fs.Close ();

            Stream vx4_fs = (Stream)mpq.GetResource (String.Format ("tileset\\{0}.vx4", Util.TilesetNames[(int)chk.Tileset]));
            vx4 = new byte [vx4_fs.Length];
            vx4_fs.Read (vx4, 0, (int)vx4_fs.Length);
            vx4_fs.Close ();

            Stream vr4_fs = (Stream)mpq.GetResource (String.Format ("tileset\\{0}.vr4", Util.TilesetNames[(int)chk.Tileset]));
            vr4 = new byte [vr4_fs.Length];
            vr4_fs.Read (vr4, 0, (int)vr4_fs.Length);
            vr4_fs.Close ();

            Stream wpe_fs = (Stream)mpq.GetResource (String.Format ("tileset\\{0}.wpe", Util.TilesetNames[(int)chk.Tileset]));
            wpe = new byte [wpe_fs.Length];
            wpe_fs.Read (wpe, 0, (int)wpe_fs.Length);
            wpe_fs.Close ();
        }
Example #2
0
		public ReadyRoomScreen (Mpq mpq,
					string scenario_prefix,
					int start_element_index,
					int cancel_element_index,
					int skiptutorial_element_index,
					int replay_element_index,
					int transmission_element_index,
					int objectives_element_index,
					int first_portrait_element_index)
			: base (mpq,
				String.Format ("glue\\Ready{0}", Util.RaceChar[(int)Game.Instance.Race]),
				String.Format (Builtins.rez_GluRdyBin, Util.RaceCharLower[(int)Game.Instance.Race]))
		{
			background_path = String.Format ("glue\\PalR{0}\\Backgnd.pcx", Util.RaceCharLower[(int)Game.Instance.Race]);
			fontpal_path = String.Format ("glue\\PalR{0}\\tFont.pcx", Util.RaceCharLower[(int)Game.Instance.Race]);
			effectpal_path = String.Format ("glue\\PalR{0}\\tEffect.pcx", Util.RaceCharLower[(int)Game.Instance.Race]);
			arrowgrp_path = String.Format ("glue\\PalR{0}\\arrow.grp", Util.RaceCharLower[(int)Game.Instance.Race]);

			this.start_element_index = start_element_index;
			this.cancel_element_index = cancel_element_index;
			this.skiptutorial_element_index = skiptutorial_element_index;
			this.replay_element_index = replay_element_index;
			this.transmission_element_index = transmission_element_index;
			this.objectives_element_index = objectives_element_index;
			this.first_portrait_element_index = first_portrait_element_index;

			this.scenario = (Chk)mpq.GetResource (scenario_prefix + "\\staredit\\scenario.chk");
			this.scenario_prefix = scenario_prefix;
		}
Example #3
0
        public Sprite(Mpq mpq, int sprite_entry, byte[] palette, int x, int y)
        {
            this.mpq     = mpq;
            this.palette = palette;

            images_entry = GlobalResources.Instance.SpritesDat.ImagesDatEntries [sprite_entry];
            //			Console.WriteLine ("image_dat_entry == {0}", images_entry);

            uint grp_index = GlobalResources.Instance.ImagesDat.GrpIndexes [images_entry];

            //			Console.WriteLine ("grp_index = {0}", grp_index);
            grp_path = GlobalResources.Instance.ImagesTbl[(int)grp_index - 1];
            //			Console.WriteLine ("grp_path = {0}", grp_path);

            grp = (Grp)mpq.GetResource("unit\\" + grp_path);

            iscript_entry       = GlobalResources.Instance.ImagesDat.IScriptIndexes [images_entry];
            script_entry_offset = GlobalResources.Instance.IScriptBin.GetScriptEntryOffset(iscript_entry);

            Console.WriteLine("new sprite: unit\\{0} @ {1}x{2} (image {3}, iscript id {4}, script_entry_offset {5:X})",
                              grp_path, x, y, images_entry, iscript_entry, script_entry_offset);

            this.buf = GlobalResources.Instance.IScriptBin.Contents;

            /* make sure the offset points to "SCPE" */
            if (Util.ReadDWord(buf, script_entry_offset) != 0x45504353)
            {
                Console.WriteLine("invalid script_entry_offset");
            }

            SetPosition(x, y);
        }
Example #4
0
        public Sprite(Sprite parentSprite, ushort images_entry, byte[] palette)
        {
            this.parent_sprite = parentSprite;
            this.mpq           = parentSprite.mpq;
            this.palette       = palette;
            this.images_entry  = images_entry;

            uint grp_index = GlobalResources.Instance.ImagesDat.GrpIndexes [images_entry];

            grp_path = GlobalResources.Instance.ImagesTbl[(int)grp_index - 1];

            grp = (Grp)mpq.GetResource("unit\\" + grp_path);

            this.buf      = GlobalResources.Instance.IScriptBin.Contents;
            iscript_entry = GlobalResources.Instance.ImagesDat.IScriptIndexes [images_entry];

            script_entry_offset = GlobalResources.Instance.IScriptBin.GetScriptEntryOffset(iscript_entry);

            Console.WriteLine("new dependent sprite: unit\\{0} (image {1}, iscript id {2}, script_entry_offset {3:X})",
                              grp_path, images_entry, iscript_entry, script_entry_offset);

            /* make sure the offset points to "SCEP" */
            if (Util.ReadDWord(buf, script_entry_offset) != 0x45504353)
            {
                Console.WriteLine("invalid script_entry_offset");
            }

            int x, y;

            parentSprite.GetPosition(out x, out y);
            SetPosition(x, y);
        }
Example #5
0
        protected override Surface CreateSurface()
        {
            if (ParentScreen.Background == null && ParentScreen.UseTiles)
            {
                Surface surf = new Surface(Width, Height);
                surf.Fill(new Rectangle(new Point(0, 0), new Size(Width, Height)),
                          Color.FromArgb(0, 0, 0, 0));
                surf.TransparentColor = Color.Black;                 /* XXX */

                Pcx pal = new Pcx();
                pal.ReadFromStream((Stream)Mpq.GetResource("unit\\cmdbtns\\ticon.pcx"),
                                   -1, -1);

                /* tile the top border */
                TileRow(surf, tileGrp, pal.Palette, TILE_TL, TILE_T, TILE_TR, 0);

                /* tile everything down to the bottom border */
                for (int y = tileGrp.Height - 2; y < surf.Height - tileGrp.Height; y += tileGrp.Height - 2)
                {
                    TileRow(surf, tileGrp, pal.Palette, TILE_L, TILE_C, TILE_R, y);
                }

                /* tile the bottom row */
                TileRow(surf, tileGrp, pal.Palette, TILE_BL, TILE_B, TILE_BR, surf.Height - tileGrp.Height);
                return(surf);
            }
            else
            {
                return(null);
            }
        }
Example #6
0
        public ReadyRoomScreen(Mpq mpq,
                               string scenario_prefix,
                               int start_element_index,
                               int cancel_element_index,
                               int skiptutorial_element_index,
                               int replay_element_index,
                               int transmission_element_index,
                               int objectives_element_index,
                               int first_portrait_element_index)
            : base(mpq,
                   String.Format("glue\\Ready{0}", Util.RaceChar[(int)Game.Instance.Race]),
                   String.Format(Builtins.rez_GluRdyBin, Util.RaceCharLower[(int)Game.Instance.Race]))
        {
            background_path = String.Format("glue\\PalR{0}\\Backgnd.pcx", Util.RaceCharLower[(int)Game.Instance.Race]);
            fontpal_path    = String.Format("glue\\PalR{0}\\tFont.pcx", Util.RaceCharLower[(int)Game.Instance.Race]);
            effectpal_path  = String.Format("glue\\PalR{0}\\tEffect.pcx", Util.RaceCharLower[(int)Game.Instance.Race]);
            arrowgrp_path   = String.Format("glue\\PalR{0}\\arrow.grp", Util.RaceCharLower[(int)Game.Instance.Race]);

            this.start_element_index          = start_element_index;
            this.cancel_element_index         = cancel_element_index;
            this.skiptutorial_element_index   = skiptutorial_element_index;
            this.replay_element_index         = replay_element_index;
            this.transmission_element_index   = transmission_element_index;
            this.objectives_element_index     = objectives_element_index;
            this.first_portrait_element_index = first_portrait_element_index;

            this.scenario        = (Chk)mpq.GetResource(scenario_prefix + "\\staredit\\scenario.chk");
            this.scenario_prefix = scenario_prefix;
        }
Example #7
0
        public MovieElement(UIScreen screen, BinElement el, byte[] palette, string resource)
            : base(screen, el, palette)
        {
            Sensitive = false;

            Player = new SmackerPlayer((Stream)Mpq.GetResource(resource), 1);
        }
Example #8
0
        public MapRenderer(Mpq mpq, Chk chk)
        {
            this.mpq = mpq;
            this.chk = chk;

            pixel_width  = (ushort)(chk.Width * 32);
            pixel_height = (ushort)(chk.Height * 32);

            Stream cv5_fs = (Stream)mpq.GetResource(String.Format("tileset\\{0}.cv5", Util.TilesetNames[(int)chk.Tileset]));

            cv5 = new byte [cv5_fs.Length];
            cv5_fs.Read(cv5, 0, (int)cv5_fs.Length);
            cv5_fs.Close();

            Stream vx4_fs = (Stream)mpq.GetResource(String.Format("tileset\\{0}.vx4", Util.TilesetNames[(int)chk.Tileset]));

            vx4 = new byte [vx4_fs.Length];
            vx4_fs.Read(vx4, 0, (int)vx4_fs.Length);
            vx4_fs.Close();

            Stream vr4_fs = (Stream)mpq.GetResource(String.Format("tileset\\{0}.vr4", Util.TilesetNames[(int)chk.Tileset]));

            vr4 = new byte [vr4_fs.Length];
            vr4_fs.Read(vr4, 0, (int)vr4_fs.Length);
            vr4_fs.Close();

            Stream vf4_fs = (Stream)mpq.GetResource(String.Format("tileset\\{0}.vf4", Util.TilesetNames[(int)chk.Tileset]));

            vf4 = new byte [vf4_fs.Length];
            vf4_fs.Read(vf4, 0, (int)vf4_fs.Length);
            vf4_fs.Close();

            Stream wpe_fs = (Stream)mpq.GetResource(String.Format("tileset\\{0}.wpe", Util.TilesetNames[(int)chk.Tileset]));

            wpe = new byte [wpe_fs.Length];
            wpe_fs.Read(wpe, 0, (int)wpe_fs.Length);
            wpe_fs.Close();

            mapLayer             = (CATiledLayer)CATiledLayer.Create();
            mapLayer.TileSize    = new SizeF(32, 32);
            mapLayer.Bounds      = new RectangleF(0, 0, pixel_width, pixel_height);
            mapLayer.AnchorPoint = new PointF(0, 0);
            mapLayerDelegate     = new MapLayerDelegate(this);
            mapLayer.Delegate    = mapLayerDelegate;
            mapLayer.SetNeedsDisplay();
        }
Example #9
0
        public static void PlayMusic(Mpq mpq, string resourcePath, int numLoops)
        {
            Stream stream = (Stream)mpq.GetResource(resourcePath);

            if (stream == null)
            {
                return;
            }
            Sound s = GuiUtil.SoundFromStream(stream);

            s.Play(true);
        }
Example #10
0
        public static void PlaySound(Mpq mpq, string resourcePath)
        {
            Stream stream = (Stream)mpq.GetResource(resourcePath);

            if (stream == null)
            {
                return;
            }
            NSSound s = GuiUtil.SoundFromStream(stream);

            s.Play();
        }
Example #11
0
        void AddMovieElements(int elementIndex, int campaign, int off_x, int off_y)
        {
            MovieElement normalElement, onElement, diskElement;

            if (diskPlayer == null)
            {
                diskPlayer = new SmackerPlayer((Stream)Mpq.GetResource(Game.Instance.PlayingBroodWar ? "glue\\Expcampaign\\disk.smk" : "glue\\campaign\\disk.smk"), 1);
            }

            diskElement = new MovieElement(this,
                                           Elements[elementIndex].BinElement,
                                           Elements[elementIndex].Palette,
                                           diskPlayer);

            diskElement.X1 = (ushort)(Elements[elementIndex].X1 + ((Elements[elementIndex].Width - diskElement.MovieSize.Width) / 2));
            diskElement.Y1 = (ushort)(((ButtonElement)Elements[elementIndex]).TextPosition.Y - diskElement.MovieSize.Height);

            normalElement = new MovieElement(this,
                                             Elements[elementIndex].BinElement,
                                             Elements[elementIndex].Palette,
                                             (Game.Instance.PlayingBroodWar ? BroodwarCampaigns : StarcraftCampaigns)[campaign].normalMovie);

            normalElement.X1 = (ushort)(Elements[elementIndex].X1 + ((Elements[elementIndex].Width - normalElement.MovieSize.Width) / 2) + off_x);
            normalElement.Y1 = (ushort)(((ButtonElement)Elements[elementIndex]).TextPosition.Y - normalElement.MovieSize.Height + off_y);

            onElement = new MovieElement(this,
                                         Elements[elementIndex].BinElement,
                                         Elements[elementIndex].Palette,
                                         (Game.Instance.PlayingBroodWar ? BroodwarCampaigns : StarcraftCampaigns)[campaign].onMovie);

            onElement.X1 = (ushort)(Elements[elementIndex].X1 + ((Elements[elementIndex].Width - onElement.MovieSize.Width) / 2));
            onElement.Y1 = (ushort)(((ButtonElement)Elements[elementIndex]).TextPosition.Y - onElement.MovieSize.Height);

            smkElements.Add(diskElement);
            smkElements.Add(normalElement);
            smkElements.Add(onElement);

            onElement.Visible = false;
            normalElement.Dim(100);

            Elements[elementIndex].MouseEnterEvent +=
                delegate() {
                normalElement.Dim(0);
                onElement.Visible = true;
            };
            Elements[elementIndex].MouseLeaveEvent +=
                delegate() {
                normalElement.Dim(100);
                onElement.Visible = false;
            };
        }
Example #12
0
        public MapRenderer(Mpq mpq, Chk chk)
        {
            this.mpq = mpq;
            this.chk = chk;

            pixel_width  = (ushort)(chk.Width * 32);
            pixel_height = (ushort)(chk.Height * 32);

            Stream cv5_fs = (Stream)mpq.GetResource(String.Format("tileset\\{0}.cv5", Util.TilesetNames[(int)chk.Tileset]));

            cv5 = new byte [cv5_fs.Length];
            cv5_fs.Read(cv5, 0, (int)cv5_fs.Length);
            cv5_fs.Close();

            Stream vx4_fs = (Stream)mpq.GetResource(String.Format("tileset\\{0}.vx4", Util.TilesetNames[(int)chk.Tileset]));

            vx4 = new byte [vx4_fs.Length];
            vx4_fs.Read(vx4, 0, (int)vx4_fs.Length);
            vx4_fs.Close();

            Stream vr4_fs = (Stream)mpq.GetResource(String.Format("tileset\\{0}.vr4", Util.TilesetNames[(int)chk.Tileset]));

            vr4 = new byte [vr4_fs.Length];
            vr4_fs.Read(vr4, 0, (int)vr4_fs.Length);
            vr4_fs.Close();

            Stream vf4_fs = (Stream)mpq.GetResource(String.Format("tileset\\{0}.vf4", Util.TilesetNames[(int)chk.Tileset]));

            vf4 = new byte [vf4_fs.Length];
            vf4_fs.Read(vf4, 0, (int)vf4_fs.Length);
            vf4_fs.Close();

            Stream wpe_fs = (Stream)mpq.GetResource(String.Format("tileset\\{0}.wpe", Util.TilesetNames[(int)chk.Tileset]));

            wpe = new byte [wpe_fs.Length];
            wpe_fs.Read(wpe, 0, (int)wpe_fs.Length);
            wpe_fs.Close();
        }
Example #13
0
		public static Fnt[] GetFonts (Mpq mpq) {
			if (fonts == null) {
				string[] font_list;
				font_list = BroodwarFonts;

				fonts = new Fnt[font_list.Length];

				for (int i = 0; i < fonts.Length; i ++) {
					fonts[i] = (Fnt)mpq.GetResource (font_list[i]);
					Console.WriteLine ("fonts[{0}] = {1}", i, fonts[i] == null ? "null" : "not null");
				}
			}
			return fonts;
		}
Example #14
0
        void FileListSelectionChanged(int selectedIndex)
        {
            string map_path = Path.Combine(curdir, file_listbox.SelectedItem);

            if (selectedScenario != null)
            {
                selectedScenario.Dispose();
            }

            if (selectedIndex < directories.Length)
            {
                selectedScenario = null;
                selectedChk      = null;
            }
            else
            {
                selectedScenario = new MpqArchive(map_path);

                selectedChk = (Chk)selectedScenario.GetResource("staredit\\scenario.chk");
            }

            Elements[MAPTITLE_ELEMENT_INDEX].Text       = selectedChk == null ? "" : selectedChk.Name;
            Elements[MAPDESCRIPTION_ELEMENT_INDEX].Text = selectedChk == null ? "" : selectedChk.Description;

            string mapSizeString = GlobalResources.Instance.GluAllTbl.Strings[MAPSIZE_FORMAT_INDEX];
            //			string mapDimString = GlobalResources.Instance.GluAllTbl.Strings[MAPDIM_FORMAT_INDEX];
            string tileSetString = GlobalResources.Instance.GluAllTbl.Strings[TILESET_FORMAT_INDEX];

            mapSizeString = mapSizeString.Replace("%c", " ");              /* should probably be a tab.. */
            mapSizeString = mapSizeString.Replace("%s",
                                                  (selectedChk == null
                                                                ? ""
                                                                : String.Format("{0}x{1}",
                                                                                selectedChk.Width,
                                                                                selectedChk.Height)));

            tileSetString = tileSetString.Replace("%c", " ");              /* should probably be a tab.. */
            tileSetString = tileSetString.Replace("%s",
                                                  (selectedChk == null
                                                                ? ""
                                                                : String.Format("{0}",
                                                                                selectedChk.Tileset)));

            Elements[MAPSIZE_ELEMENT_INDEX].Text    = mapSizeString;
            Elements[MAPTILESET_ELEMENT_INDEX].Text = tileSetString;

            UpdatePlayersDisplay();
        }
Example #15
0
        public static Fnt[] GetFonts(Mpq mpq)
        {
            if (fonts == null)
            {
                string[] font_list;
                font_list = BroodwarFonts;

                fonts = new Fnt[font_list.Length];

                for (int i = 0; i < fonts.Length; i++)
                {
                    fonts[i] = (Fnt)mpq.GetResource(font_list[i]);
                    Console.WriteLine("fonts[{0}] = {1}", i, fonts[i] == null ? "null" : "not null");
                }
            }
            return(fonts);
        }
Example #16
0
        public void ShowPortrait(int unit, int slot)
        {
            Console.WriteLine("showing portrait {0} (unit {1}, portrait index {2}) in slot {3}",
                              "" /*portrait_resource*/, unit,
                              GlobalResources.Instance.PortDataDat.PortraitIndexes [unit],
                              slot);

            uint portraitIndex = GlobalResources.Instance.UnitsDat.Portraits [unit];

            string portrait_resource = String.Format("portrait\\{0}0.smk",
                                                     GlobalResources.Instance.PortDataTbl[(int)GlobalResources.Instance.PortDataDat.PortraitIndexes [(int)portraitIndex]]);

            portraits[slot].Player = new SmackerPlayer((Stream)Mpq.GetResource(portrait_resource), 1);

            portraits[slot].Dim(100);
            portraits[slot].Play();
            portraits[slot].Visible = true;
            hframes[slot].Visible   = false;
            frames[slot].Visible    = true;
        }
Example #17
0
		public Sprite (Mpq mpq, int sprite_entry, byte[] palette, int x, int y)
		{
			this.mpq = mpq;
			this.palette = palette;

			images_entry = GlobalResources.Instance.SpritesDat.ImagesDatEntries [sprite_entry];
			//			Console.WriteLine ("image_dat_entry == {0}", images_entry);

			uint grp_index = GlobalResources.Instance.ImagesDat.GrpIndexes [images_entry];
			//			Console.WriteLine ("grp_index = {0}", grp_index);
			grp_path = GlobalResources.Instance.ImagesTbl[(int)grp_index-1];
			//			Console.WriteLine ("grp_path = {0}", grp_path);

			grp = (Grp)mpq.GetResource ("unit\\" + grp_path);

			iscript_entry = GlobalResources.Instance.ImagesDat.IScriptIndexes [images_entry];
			script_entry_offset = GlobalResources.Instance.IScriptBin.GetScriptEntryOffset (iscript_entry);

			Console.WriteLine ("new sprite: unit\\{0} @ {1}x{2} (image {3}, iscript id {4}, script_entry_offset {5:X})",
					   grp_path, x, y, images_entry, iscript_entry, script_entry_offset);

			this.buf = GlobalResources.Instance.IScriptBin.Contents;

			/* make sure the offset points to "SCPE" */
			if (Util.ReadDWord (buf, script_entry_offset) != 0x45504353)
				Console.WriteLine ("invalid script_entry_offset");

			SetPosition (x,y);
		}
Example #18
0
 public MovieElement(UIScreen screen, BinElement el, byte[] palette, string resource)
     : base(screen, el, palette)
 {
     Player             = new SmackerPlayer((Stream)Mpq.GetResource(resource), 1);
     Player.FrameReady += NewFrame;
 }
Example #19
0
        void ResourceLoader(object state)
        {
            try {
                starcraftResources.ImagesTbl   = (Tbl)stardatMpq.GetResource(Builtins.ImagesTbl);
                starcraftResources.SfxDataTbl  = (Tbl)stardatMpq.GetResource(Builtins.SfxDataTbl);
                starcraftResources.SpritesTbl  = (Tbl)stardatMpq.GetResource(Builtins.SpritesTbl);
                starcraftResources.GluAllTbl   = (Tbl)stardatMpq.GetResource(Builtins.rez_GluAllTbl);
                starcraftResources.MapDataTbl  = (Tbl)stardatMpq.GetResource(Builtins.MapDataTbl);
                starcraftResources.PortDataTbl = (Tbl)stardatMpq.GetResource(Builtins.PortDataTbl);
                starcraftResources.ImagesDat   = (ImagesDat)stardatMpq.GetResource(Builtins.ImagesDat);
                starcraftResources.SfxDataDat  = (SfxDataDat)stardatMpq.GetResource(Builtins.SfxDataDat);
                starcraftResources.SpritesDat  = (SpritesDat)stardatMpq.GetResource(Builtins.SpritesDat);
                starcraftResources.IscriptBin  = (IScriptBin)stardatMpq.GetResource(Builtins.IScriptBin);
                starcraftResources.UnitsDat    = (UnitsDat)stardatMpq.GetResource(Builtins.UnitsDat);
                starcraftResources.FlingyDat   = (FlingyDat)stardatMpq.GetResource(Builtins.FlingyDat);
                starcraftResources.MapDataDat  = (MapDataDat)stardatMpq.GetResource(Builtins.MapDataDat);
                starcraftResources.PortDataDat = (PortDataDat)stardatMpq.GetResource(Builtins.PortDataDat);

                if (broodatMpq != null)
                {
                    broodwarResources.ImagesTbl   = (Tbl)broodatMpq.GetResource(Builtins.ImagesTbl);
                    broodwarResources.SfxDataTbl  = (Tbl)broodatMpq.GetResource(Builtins.SfxDataTbl);
                    broodwarResources.SpritesTbl  = (Tbl)broodatMpq.GetResource(Builtins.SpritesTbl);
                    broodwarResources.GluAllTbl   = (Tbl)broodatMpq.GetResource(Builtins.rez_GluAllTbl);
                    broodwarResources.MapDataTbl  = (Tbl)broodatMpq.GetResource(Builtins.MapDataTbl);
                    broodwarResources.PortDataTbl = (Tbl)broodatMpq.GetResource(Builtins.PortDataTbl);
                    broodwarResources.ImagesDat   = (ImagesDat)broodatMpq.GetResource(Builtins.ImagesDat);
                    broodwarResources.SfxDataDat  = (SfxDataDat)broodatMpq.GetResource(Builtins.SfxDataDat);
                    broodwarResources.SpritesDat  = (SpritesDat)broodatMpq.GetResource(Builtins.SpritesDat);
                    broodwarResources.IscriptBin  = (IScriptBin)broodatMpq.GetResource(Builtins.IScriptBin);
                    broodwarResources.UnitsDat    = (UnitsDat)broodatMpq.GetResource(Builtins.UnitsDat);
                    broodwarResources.FlingyDat   = (FlingyDat)broodatMpq.GetResource(Builtins.FlingyDat);
                    broodwarResources.MapDataDat  = (MapDataDat)broodatMpq.GetResource(Builtins.MapDataDat);
                    broodwarResources.PortDataDat = (PortDataDat)broodatMpq.GetResource(Builtins.PortDataDat);
                }

                // notify we're ready to roll
                NSApplication.SharedApplication.InvokeOnMainThread(FinishedLoading);
            }
            catch (Exception e) {
                Console.WriteLine("Global Resource loader failed: {0}", e);
#if notyet
                Events.PushUserEvent(new UserEventArgs(new ReadyDelegate(Events.QuitApplication)));
#endif
            }
        }
Example #20
0
		protected virtual void ResourceLoader ()
		{
			Stream s;

			fontpal = null;
			effectpal = null;

			if (fontpal_path != null) {
				Console.WriteLine ("loading font palette");
				s = (Stream)mpq.GetResource (fontpal_path);
				if (s != null) {
					fontpal = new Pcx ();
					fontpal.ReadFromStream (s, -1, -1);
				}
			}
			if (effectpal_path != null) {
				Console.WriteLine ("loading cursor palette");
				s = (Stream)mpq.GetResource (effectpal_path);
				if (s != null) {
					effectpal = new Pcx ();
					effectpal.ReadFromStream (s, -1, -1);
				}
				if (effectpal != null && arrowgrp_path != null) {
					Console.WriteLine ("loading arrow cursor");
					Grp arrowgrp = (Grp)mpq.GetResource (arrowgrp_path);
					if (arrowgrp != null) {
						Cursor = new CursorAnimator (arrowgrp, effectpal.Palette);
						Cursor.SetHotSpot (64, 64);
					}
				}
			}

			if (background_path != null) {
				Console.WriteLine ("loading background");
				background = GuiUtil.SurfaceFromStream ((Stream)mpq.GetResource (background_path),
									background_translucent, background_transparent);
			}

			Elements = new List<UIElement> ();
			if (binFile != null) {
				Console.WriteLine ("loading ui elements");
				Bin = (Bin)mpq.GetResource (binFile);

				if (Bin == null)
					throw new Exception (String.Format ("specified file '{0}' does not exist",
									    binFile));

				/* convert all the BinElements to UIElements for our subclasses to use */
				foreach (BinElement el in Bin.Elements) {
					//					Console.WriteLine ("{0}: {1}", el.text, el.flags);

					UIElement ui_el = null;
					switch (el.type) {
					case ElementType.DialogBox:
						ui_el = new DialogBoxElement (this, el, fontpal.RgbData);
						break;
					case ElementType.Image:
						ui_el = new ImageElement (this, el, fontpal.RgbData, translucentIndex);
						break;
					case ElementType.TextBox:
						ui_el = new TextBoxElement (this, el, fontpal.RgbData);
						break;
					case ElementType.ListBox:
						ui_el = new ListBoxElement (this, el, fontpal.RgbData);
						break;
					case ElementType.ComboBox:
						ui_el = new ComboBoxElement (this, el, fontpal.RgbData);
						break;
					case ElementType.LabelLeftAlign:
					case ElementType.LabelCenterAlign:
					case ElementType.LabelRightAlign:
						ui_el = new LabelElement (this, el, fontpal.RgbData);
						break;
					case ElementType.Button:
					case ElementType.DefaultButton:
					case ElementType.ButtonWithoutBorder:
						ui_el = new ButtonElement(this, el, fontpal.RgbData);
						break;
					case ElementType.Slider:
					case ElementType.OptionButton:
					case ElementType.CheckBox:
						ui_el = new UIElement (this, el, fontpal.RgbData);
						break;
					default:
						Console.WriteLine ("unhandled case {0}", el.type);
						ui_el = new UIElement (this, el, fontpal.RgbData);
						break;
					}

					Elements.Add (ui_el);
				}
			}

			UIPainter = new UIPainter (Elements);
		}
Example #21
0
		public Sprite (Sprite parentSprite, ushort images_entry, byte[] palette)
		{
			this.parent_sprite = parentSprite;
			this.mpq = parentSprite.mpq;
			this.palette = palette;
			this.images_entry = images_entry;

			uint grp_index = GlobalResources.Instance.ImagesDat.GrpIndexes [images_entry];

			grp_path = GlobalResources.Instance.ImagesTbl[(int)grp_index-1];

			grp = (Grp)mpq.GetResource ("unit\\" + grp_path);

			this.buf = GlobalResources.Instance.IScriptBin.Contents;
			iscript_entry = GlobalResources.Instance.ImagesDat.IScriptIndexes [images_entry];

			script_entry_offset = GlobalResources.Instance.IScriptBin.GetScriptEntryOffset (iscript_entry);

			Console.WriteLine ("new dependent sprite: unit\\{0} (image {1}, iscript id {2}, script_entry_offset {3:X})",
					   grp_path, images_entry, iscript_entry, script_entry_offset);

			/* make sure the offset points to "SCEP" */
			if (Util.ReadDWord (buf, script_entry_offset) != 0x45504353)
				Console.WriteLine ("invalid script_entry_offset");

			int x, y;
			parentSprite.GetPosition (out x, out y);
			SetPosition (x,y);
		}
Example #22
0
 public DialogBoxElement(UIScreen screen, BinElement el, byte[] palette)
     : base(screen, el, palette)
 {
     tileGrp = (Grp)Mpq.GetResource("dlgs\\tile.grp");
 }
Example #23
0
 public static void PlaySound(Mpq mpq, string resourcePath)
 {
     Stream stream = (Stream)mpq.GetResource (resourcePath);
     if (stream == null)
         return;
     Sound s = GuiUtil.SoundFromStream (stream);
     s.Play();
 }
Example #24
0
 public static void PlayMusic(Mpq mpq, string resourcePath, int numLoops)
 {
     Stream stream = (Stream)mpq.GetResource (resourcePath);
     if (stream == null)
         return;
     Sound s = GuiUtil.SoundFromStream (stream);
     s.Play (true);
 }
Example #25
0
        void FileListSelectionChanged(int selectedIndex)
        {
            string map_path = Path.Combine (curdir, file_listbox.SelectedItem);

            if (selectedScenario !=null)
                selectedScenario.Dispose ();

            if (selectedIndex < directories.Length) {
                selectedScenario = null;
                selectedChk = null;
            }
            else {
                selectedScenario = new MpqArchive (map_path);

                selectedChk = (Chk)selectedScenario.GetResource ("staredit\\scenario.chk");
            }

            Elements[MAPTITLE_ELEMENT_INDEX].Text = selectedChk == null ? "" : selectedChk.Name;
            Elements[MAPDESCRIPTION_ELEMENT_INDEX].Text = selectedChk == null ? "" : selectedChk.Description;

            string mapSizeString = GlobalResources.Instance.GluAllTbl.Strings[MAPSIZE_FORMAT_INDEX];
            //			string mapDimString = GlobalResources.Instance.GluAllTbl.Strings[MAPDIM_FORMAT_INDEX];
            string tileSetString = GlobalResources.Instance.GluAllTbl.Strings[TILESET_FORMAT_INDEX];

            mapSizeString = mapSizeString.Replace ("%c", " "); /* should probably be a tab.. */
            mapSizeString = mapSizeString.Replace ("%s",
                                   (selectedChk == null
                                ? ""
                                : String.Format ("{0}x{1}",
                                         selectedChk.Width,
                                         selectedChk.Height)));

            tileSetString = tileSetString.Replace ("%c", " "); /* should probably be a tab.. */
            tileSetString = tileSetString.Replace ("%s",
                                   (selectedChk == null
                                ? ""
                                : String.Format ("{0}",
                                         selectedChk.Tileset)));

            Elements[MAPSIZE_ELEMENT_INDEX].Text = mapSizeString;
            Elements[MAPTILESET_ELEMENT_INDEX].Text = tileSetString;

            UpdatePlayersDisplay ();
        }
Example #26
0
    public static void Main(string[] args)
    {
        string mpqpath = args[0];
        string mappath = args[1];

        Console.WriteLine("Map name {0}", mappath);

        Mpq mpq = GetMPQ(mpqpath);
        Mpq map = GetMPQ(mappath);

        Chk chk = (Chk)map.GetResource("staredit\\scenario.chk");

        ushort[,] mapTiles = chk.MapTiles;

        byte[] image = new byte[chk.Width * 32 * chk.Height * 32 * 3];

        /*
         * 00 - Badlands
         * 01 - Space Platform
         * 02 - Installation
         * 03 - Ashworld
         * 04 - Jungle World
         * 05 - Desert World
         * 06 - Arctic World
         * 07 - Twilight World
         */

        string[] tileset_names = new string[] {
            "badlands",
            "platform",
            "install",
            "ashworld",
            "jungle",
            "desert",
            "ice",
            "twilight"
        };

        Stream cv5_fs = (Stream)mpq.GetResource(String.Format("tileset\\{0}.cv5", tileset_names[(int)chk.Tileset]));
        Stream vx4_fs = (Stream)mpq.GetResource(String.Format("tileset\\{0}.vx4", tileset_names[(int)chk.Tileset]));
        Stream vr4_fs = (Stream)mpq.GetResource(String.Format("tileset\\{0}.vr4", tileset_names[(int)chk.Tileset]));
        Stream wpe_fs = (Stream)mpq.GetResource(String.Format("tileset\\{0}.wpe", tileset_names[(int)chk.Tileset]));

        byte[] cv5 = new byte [cv5_fs.Length];
        cv5_fs.Read(cv5, 0, (int)cv5_fs.Length);

        byte[] vx4 = new byte [vx4_fs.Length];
        vx4_fs.Read(vx4, 0, (int)vx4_fs.Length);

        byte[] vr4 = new byte [vr4_fs.Length];
        vr4_fs.Read(vr4, 0, (int)vr4_fs.Length);

        byte[] wpe = new byte [wpe_fs.Length];
        wpe_fs.Read(wpe, 0, (int)wpe_fs.Length);

        for (int map_y = 0; map_y < chk.Height; map_y++)
        {
            for (int map_x = 0; map_x < chk.Width; map_x++)
            {
                int mapTile = mapTiles[map_x, map_y];

                bool odd = (mapTile & 0x10) == 0x10;

                int tile_group  = mapTile >> 4;                /* the tile's group in the cv5 file */
                int tile_number = mapTile & 0x0F;              /* the megatile within the tile group */

                int megatile_id = Util.ReadWord(cv5, (tile_group * 26 + 10 + tile_number) * 2);

                if (map_y == 0)
                {
                    Console.Write("[{0}.{1}:0x{2:x}]", tile_group, tile_number, megatile_id);
                    if (map_x == chk.Width - 1)
                    {
                        Console.WriteLine();
                    }
                }

                int minitile_x, minitile_y;

                //				Console.WriteLine ("[{0},{1}] = {2} ({3:x} = {4:x}:{5:x})", map_x, map_y, megatile_id, mapTile, tile_group, tile_number);

                for (minitile_y = 0; minitile_y < 4; minitile_y++)
                {
                    for (minitile_x = 0; minitile_x < 4; minitile_x++)
                    {
                        ushort minitile_id = Util.ReadWord(vx4, megatile_id * 32 + minitile_y * 8 + minitile_x * 2);
                        bool   flipped     = (minitile_id & 0x01) == 0x01;
                        minitile_id >>= 1;

                        //						Console.WriteLine ("minitile [{0},{1}] = {2}", minitile_x, minitile_y, minitile_id);

                        int pixel_x, pixel_y;
                        if (flipped)
                        {
                            for (pixel_y = 0; pixel_y < 8; pixel_y++)
                            {
                                for (pixel_x = 0; pixel_x < 8; pixel_x++)
                                {
                                    int x = map_x * 32 + (minitile_x + 1) * 8 - pixel_x - 1;
                                    int y = (map_y * 32 + minitile_y * 8) * chk.Width * 32 + pixel_y * chk.Width * 32;

                                    byte palette_entry = vr4[minitile_id * 64 + pixel_y * 8 + pixel_x];

                                    image[0 + 3 * (x + y)] = wpe[palette_entry * 4 + 2];
                                    image[1 + 3 * (x + y)] = wpe[palette_entry * 4 + 1];
                                    image[2 + 3 * (x + y)] = wpe[palette_entry * 4 + 0];
                                }
                            }
                        }
                        else
                        {
                            for (pixel_y = 0; pixel_y < 8; pixel_y++)
                            {
                                for (pixel_x = 0; pixel_x < 8; pixel_x++)
                                {
                                    int x = map_x * 32 + minitile_x * 8 + pixel_x;
                                    int y = (map_y * 32 + minitile_y * 8) * chk.Width * 32 + pixel_y * chk.Width * 32;

                                    byte palette_entry = vr4[minitile_id * 64 + pixel_y * 8 + pixel_x];

                                    image[0 + 3 * (x + y)] = wpe[palette_entry * 4 + 2];
                                    image[1 + 3 * (x + y)] = wpe[palette_entry * 4 + 1];
                                    image[2 + 3 * (x + y)] = wpe[palette_entry * 4 + 0];
                                }
                            }
                        }
                    }
                }
            }
        }

        TGA.WriteTGA("map.tga",
                     image, (uint)chk.Width * 32, (uint)chk.Height * 32);
    }