protected override IEnumerable<string> GetOptions()
		{
				
			using (var unitSync = new UnitSync(Settings.Default.SpringPath))
			{
				return unitSync.GetModNames();
			}
		}
Пример #2
0
        /// <summary>
        /// Returns an SM2 map texuture
        /// </summary>
        public BitmapSource GetTexture(Map map, int detail, UnitSync unitSync)
        {
            UnitSync.NativeMethods.RemoveAllArchives();
            UnitSync.NativeMethods.AddAllArchives(map.ArchiveName);
            ProgressChanged(this, new ProgressChangedEventArgs(0, "Extracting map"));
            var mapName     = map.Name + ".smf";
            var smfFileData = unitSync.ReadVfsFile("maps\\" + mapName);
            var reader      = new BinaryReader(new MemoryStream(smfFileData));
            var smfHeader   = reader.ReadStruct <SMFHeader>();

            smfHeader.SelfCheck();
            var mapWidth  = smfHeader.mapx;
            var mapHeight = smfHeader.mapy;

            reader.BaseStream.Position = smfHeader.tilesPtr;
            var mapTileHeader = reader.ReadStruct <MapTileHeader>();

            // get the tile files and the number of tiles they contain
            var tileFiles = new Dictionary <byte[], int>();

            for (var i = 0; i < mapTileHeader.numTileFiles; i++)
            {
                var numTiles     = reader.ReadInt32();
                var tileFileData = unitSync.ReadVfsFile("maps\\" + reader.ReadCString());
                tileFiles.Add(tileFileData, numTiles);
            }

            // get the position of the tiles
            var mapUnitInTiles = Tiles.TileMipLevel1Size / smfHeader.texelPerSquare;
            var tilesX         = smfHeader.mapx / mapUnitInTiles;
            var tilesY         = smfHeader.mapy / mapUnitInTiles;
            var tileIndices    = new int[tilesX * tilesY];

            for (var i = 0; i < tileIndices.Length; i++)
            {
                tileIndices[i] = reader.ReadInt32();
            }

            Tiles.ProgressChanged += (s, e) => ProgressChanged(this, e);

            UnitSync.NativeMethods.RemoveAllArchives();
            // load the tiles
            return(Tiles.LoadTiles(tileFiles, tileIndices, tilesX, tilesY, detail));
        }
Пример #3
0
		/// <summary>
		/// Returns an SM2 map texuture
		/// </summary>
		public BitmapSource GetTexture(Map map, int detail, UnitSync unitSync)
		{
			UnitSync.NativeMethods.RemoveAllArchives();
			UnitSync.NativeMethods.AddAllArchives(map.ArchiveName);
			ProgressChanged(this, new ProgressChangedEventArgs(0, "Extracting map"));
			var mapName = map.Name + ".smf";
			var smfFileData = unitSync.ReadVfsFile("maps\\" + mapName);
			var reader = new BinaryReader(new MemoryStream(smfFileData));
			var smfHeader = reader.ReadStruct<SMFHeader>();
			smfHeader.SelfCheck();
			var mapWidth = smfHeader.mapx;
			var mapHeight = smfHeader.mapy;

			reader.BaseStream.Position = smfHeader.tilesPtr;
			var mapTileHeader = reader.ReadStruct<MapTileHeader>();

			// get the tile files and the number of tiles they contain
			var tileFiles = new Dictionary<byte[], int>();
			for (var i = 0; i < mapTileHeader.numTileFiles; i++)
			{
				var numTiles = reader.ReadInt32();
				var tileFileData = unitSync.ReadVfsFile("maps\\" + reader.ReadCString());
				tileFiles.Add(tileFileData, numTiles);
			}

			// get the position of the tiles
			var mapUnitInTiles = Tiles.TileMipLevel1Size/smfHeader.texelPerSquare;
			var tilesX = smfHeader.mapx/mapUnitInTiles;
			var tilesY = smfHeader.mapy/mapUnitInTiles;
			var tileIndices = new int[tilesX*tilesY];
			for (var i = 0; i < tileIndices.Length; i++)
			{
				tileIndices[i] = reader.ReadInt32();
			}

			Tiles.ProgressChanged += (s, e) => ProgressChanged(this, e);

			UnitSync.NativeMethods.RemoveAllArchives();
			// load the tiles
			return Tiles.LoadTiles(tileFiles, tileIndices, tilesX, tilesY, detail);
		}
		/// <summary>
		/// create testmission.sdz, the script.txt, run spring, capture output
		/// </summary>
		void TestMission()
		{
			var springPath = Settings.Default.SpringPath;
			var unitSync = new UnitSync(Settings.Default.SpringPath);
			var springExe = springPath + "\\spring.exe";
			var realName = Mission.Name;
			string scriptFile = null;
			try
			{
				var missionFile = "testmission.sdz";
                var writeablePath = unitSync.WritableDataDirectory;
				var missionPath = writeablePath + "\\games\\" + missionFile;
				scriptFile = writeablePath + "\\script.txt";
				Mission.Name = Mission.Name + " Test";
				File.WriteAllText(scriptFile, Mission.GetScript());
				Mission.CreateArchive(missionPath, true);
			}
			catch(Exception e)
			{
				if (Debugger.IsAttached) throw;
				MessageBox.Show(e.Message);
                return;
			}
			finally
			{
				unitSync.Dispose();
				Mission.Name = realName;
			}
			var startInfo = new ProcessStartInfo
			                {
			                	FileName = springExe,
			                	Arguments = String.Format("\"{0}\"", scriptFile),
                                RedirectStandardError = Debugger.IsAttached,
                                RedirectStandardOutput = Debugger.IsAttached,
			                	UseShellExecute = false
			                };
			var springProcess = new Process { StartInfo = startInfo };
            if (Debugger.IsAttached)
            {
                Utils.InvokeInNewThread(delegate
                    {
                        if (!springProcess.Start()) throw new Exception("Failed to start Spring");

                        System.Action readOut = async () =>
                            {
                                string line;
                                while((line = await springProcess.StandardOutput.ReadLineAsync()) != null)
                                    if (!String.IsNullOrEmpty(line)) Console.WriteLine(line);
                            };
                        readOut();

                        System.Action readErr = async () =>
                        {
                            string line;
                            while ((line = await springProcess.StandardError.ReadLineAsync()) != null)
                                if (!String.IsNullOrEmpty(line)) Console.WriteLine(line);
                        };
                        readErr();
                    });
            }
            else
            {
                springProcess.Start();
            }
		}
Пример #5
0
		/// <summary>
		/// Returns an SM2 map texuture
		/// </summary>
		public BitmapSource GetTexture(Map map, int detail, UnitSync unitSync)
		{
			UnitSync.NativeMethods.RemoveAllArchives();
			UnitSync.NativeMethods.AddAllArchives(map.ArchiveName);
			ProgressChanged(this, new ProgressChangedEventArgs(0, "Extracting map"));

			var mapDir = UnitSync.NativeMethods.GetMapFileName(UnitSync.NativeMethods.GetMapIndex(map.Name));
			var smfFileData = unitSync.ReadVfsFile(mapDir);
			BinaryReader reader;
			try {
				reader = new BinaryReader(new MemoryStream(smfFileData));
			} catch (System.ArgumentNullException nullEx)
			{
				throw new System.ArgumentNullException("smfFileData", "Unable to read SMF: " + mapDir);
			}
			var smfHeader = reader.ReadStruct<SMFHeader>();
			smfHeader.SelfCheck();
			var mapWidth = smfHeader.mapx;
			var mapHeight = smfHeader.mapy;

			reader.BaseStream.Position = smfHeader.tilesPtr;
			var mapTileHeader = reader.ReadStruct<MapTileHeader>();

			// get the tile files and the number of tiles they contain
			var tileFiles = new Dictionary<byte[], int>();
			for (var i = 0; i < mapTileHeader.numTileFiles; i++)
			{
				var numTiles = reader.ReadInt32();
				var tileFileData = unitSync.ReadVfsFile("maps\\" + reader.ReadCString());
				tileFiles.Add(tileFileData, numTiles);
			}

			// get the position of the tiles
			var mapUnitInTiles = Tiles.TileMipLevel1Size/smfHeader.texelPerSquare;
			var tilesX = smfHeader.mapx/mapUnitInTiles;
			var tilesY = smfHeader.mapy/mapUnitInTiles;
			var tileIndices = new int[tilesX*tilesY];
			for (var i = 0; i < tileIndices.Length; i++)
			{
				tileIndices[i] = reader.ReadInt32();
			}

			Tiles.ProgressChanged += (s, e) => ProgressChanged(this, e);

			UnitSync.NativeMethods.RemoveAllArchives();
			// load the tiles

			WriteableBitmap ret;
			try {
				ret = (WriteableBitmap)Tiles.LoadTiles(tileFiles, tileIndices, tilesX, tilesY, detail);
			} catch (System.Exception ex)
			{
				// some maps (e.g. Glacies) fail to load the tiles properly; use minimap as a fallback 

				//if (map.Texture == null) throw new System.Exception("Unable to load map texture");
				//var newBitmap = new Bitmap(GetBitmap(map.Texture), new Size(map.Texture.PixelWidth / 8, map.Texture.PixelHeight / 8));

				map.Minimap = unitSync.GetMinimap(map);
				ret = new WriteableBitmap(ConvertBitmap(map.Minimap));
				ret.Freeze();
				//ret.Unlock();
			}

			return ret;
		}
		protected override object GetItem(string itemName)
		{
			using (var unitSync = new UnitSync(Settings.Default.SpringPath))
			{
				return WelcomeDialog.LoadMod(unitSync, itemName);
			}
		}
Пример #7
0
        /// <summary>
        /// Returns an SM2 map texuture
        /// </summary>
        public BitmapSource GetTexture(Map map, int detail, UnitSync unitSync)
        {
            UnitSync.NativeMethods.RemoveAllArchives();
            UnitSync.NativeMethods.AddAllArchives(map.ArchiveName);
            ProgressChanged(this, new ProgressChangedEventArgs(0, "Extracting map"));

            var          mapDir      = UnitSync.NativeMethods.GetMapFileName(UnitSync.NativeMethods.GetMapIndex(map.Name));
            var          smfFileData = unitSync.ReadVfsFile(mapDir);
            BinaryReader reader;

            try {
                reader = new BinaryReader(new MemoryStream(smfFileData));
            } catch (System.ArgumentNullException nullEx)
            {
                throw new System.ArgumentNullException("smfFileData", "Unable to read SMF: " + mapDir);
            }
            var smfHeader = reader.ReadStruct <SMFHeader>();

            smfHeader.SelfCheck();
            var mapWidth  = smfHeader.mapx;
            var mapHeight = smfHeader.mapy;

            reader.BaseStream.Position = smfHeader.tilesPtr;
            var mapTileHeader = reader.ReadStruct <MapTileHeader>();

            // get the tile files and the number of tiles they contain
            var tileFiles = new Dictionary <byte[], int>();

            for (var i = 0; i < mapTileHeader.numTileFiles; i++)
            {
                var numTiles     = reader.ReadInt32();
                var tileFileData = unitSync.ReadVfsFile("maps\\" + reader.ReadCString());
                tileFiles.Add(tileFileData, numTiles);
            }

            // get the position of the tiles
            var mapUnitInTiles = Tiles.TileMipLevel1Size / smfHeader.texelPerSquare;
            var tilesX         = smfHeader.mapx / mapUnitInTiles;
            var tilesY         = smfHeader.mapy / mapUnitInTiles;
            var tileIndices    = new int[tilesX * tilesY];

            for (var i = 0; i < tileIndices.Length; i++)
            {
                tileIndices[i] = reader.ReadInt32();
            }

            Tiles.ProgressChanged += (s, e) => ProgressChanged(this, e);

            UnitSync.NativeMethods.RemoveAllArchives();
            // load the tiles

            WriteableBitmap ret;

            try {
                ret = (WriteableBitmap)Tiles.LoadTiles(tileFiles, tileIndices, tilesX, tilesY, detail);
            } catch (System.Exception ex)
            {
                // some maps (e.g. Glacies) fail to load the tiles properly; use minimap as a fallback

                //if (map.Texture == null) throw new System.Exception("Unable to load map texture");
                //var newBitmap = new Bitmap(GetBitmap(map.Texture), new Size(map.Texture.PixelWidth / 8, map.Texture.PixelHeight / 8));

                map.Minimap = unitSync.GetMinimap(map);
                ret         = new WriteableBitmap(ConvertBitmap(map.Minimap));
                ret.Freeze();
                //ret.Unlock();
            }

            return(ret);
        }