private void optionStateChanging(RandomizationOption obj)
 {
     if (obj.MutualExclusiveSet != null && obj.OptionIsSelected)
     {
         var allOptions = RandomizationGroups.SelectMany(x => x.Options).Where(x => x.MutualExclusiveSet == obj.MutualExclusiveSet);
         foreach (var option in allOptions)
         {
             if (option != obj)
             {
                 option.OptionIsSelected = false; // turn off other options
             }
         }
     }
 }
        private async void InternalStartRandomization()
        {
            if (!MERUtilities.IsGameRunning(MERFileSystem.Game))
            {
                ShowProgressPanel = true;
                var randomizer = new Randomizer(this);

                AllowOptionsChanging = false;

                var op = new OptionsPackage()
                {
                    Seed            = int.Parse(SeedTextBox.Text),
                    SelectedOptions = RandomizationGroups.SelectMany(x => x.Options.Where(x => x.OptionIsSelected)).ToList(),
                    UseMultiThread  = UseMultiThreadRNG,
                    Reroll          = PerformReroll
                };
                randomizer.Randomize(op);
            }
            else
            {
                await this.ShowMessageAsync("Mass Effect 2 is running", "Cannot randomize the game while Mass Effect 2 is running. Please close the game and try again.");
            }
        }
Exemplo n.º 3
0
        public void LoadInByFilename(string _Filename)
        {
            try
            {
                using (var ZippedTileset = File.OpenRead(_Filename))
                {
                    using (var ZipFile = new ZipArchive(ZippedTileset, ZipArchiveMode.Read))
                    {
                        ZipArchiveEntry PNG           = ZipFile.GetEntry("texture.png");
                        ZipArchiveEntry JSON          = ZipFile.GetEntry("meta.json");
                        ZipArchiveEntry Collisions    = ZipFile.GetEntry("collisions.chk");
                        ZipArchiveEntry Objects       = ZipFile.GetEntry("objects.unt");
                        ZipArchiveEntry ObjectsHeader = ZipFile.GetEntry("objects.unthd");

                        this.MainPNG = new Bitmap(PNG.Open());

                        #region Loading in the tiles

                        byte[] CollisionArr = null;

                        using (var BR = new BinaryReader(Collisions.Open()))
                            CollisionArr = BR.ReadBytes((int)Collisions.Length);

                        var       Serializer = new DataContractJsonSerializer(typeof(JSONClass));
                        JSONClass JSONObject = (JSONClass)Serializer.ReadObject(JSON.Open());

                        int i = 0;
                        this.Tiles = new List <Tile>();

                        foreach (object[] TileO in JSONObject.tiles)
                        {
                            int    TileID        = Convert.ToInt32(TileO[0]);
                            bool   FlipX         = Convert.ToBoolean(TileO[1]);
                            bool   FlipY         = Convert.ToBoolean(TileO[2]);
                            byte[] CollisionData = new Byte[4];
                            Array.Copy(CollisionArr, i * 4, CollisionData, 0, 4);

                            Bitmap TileBitmap = new Bitmap(16, 16);

                            Graphics g = Graphics.FromImage(TileBitmap);
                            g.DrawImage(this.MainPNG, new Rectangle(new Point(0, 0), new Size(16, 16)), Helpers.GetRectangleForTileID(TileID), GraphicsUnit.Pixel);

                            if (FlipX)
                            {
                                TileBitmap.RotateFlip(RotateFlipType.RotateNoneFlipX);
                            }

                            if (FlipY)
                            {
                                TileBitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
                            }

                            this.Tiles.Add(new Tile(i, TileID, FlipX, FlipY, CollisionData, TileBitmap));

                            i++;
                        }

                        #endregion

                        #region Loading in the Randomization Groups

                        this.RandomizationGroups = new List <List <int> >();

                        foreach (int[] RandomizationGroup in JSONObject.randomization_groups)
                        {
                            List <int> RandomizationGroupO = new List <int>();

                            foreach (object TileID in RandomizationGroup)
                            {
                                RandomizationGroupO.Add(Convert.ToInt32(TileID));
                            }

                            RandomizationGroups.Add(RandomizationGroupO);
                        }

                        #endregion

                        #region Loading in the Texture Formats
                        this.TextureFormats = new List <int>();

                        foreach (int Format in JSONObject.texture_formats)
                        {
                            this.TextureFormats.Add(Format);
                        }

                        #endregion

                        #region Loading in the Texture Names

                        this.Textures = new List <string>();
                        foreach (string TexName in JSONObject.textures)
                        {
                            this.Textures.Add(TexName);
                        }

                        #endregion

                        #region Loading in the Objects

                        byte[] ObjHeader   = null;
                        byte[] ObjectsData = null;

                        using (var BR = new BinaryReader(Objects.Open()))
                            ObjectsData = BR.ReadBytes((int)Objects.Length);

                        using (var BR = new BinaryReader(ObjectsHeader.Open()))
                            ObjHeader = BR.ReadBytes((int)ObjectsHeader.Length);

                        this.Objects = new List <Object>();

                        for (int o = 0; o < 256; o++)
                        {
                            this.Objects.Add(new Object(o, 0, 0, "Object " + i, new List <List <int> >(), new Bitmap(16, 16)));
                        }

                        for (int f = 0; f < ObjHeader.Length; f += 4)
                        {
                            List <List <int> > Tiles  = new List <List <int> >();
                            UInt16             Offset = BitConverter.ToUInt16(ObjHeader, f);
                            Byte TestWidth            = 0;
                            Byte Width  = 1;
                            Byte Height = 0;

                            UInt16 TestOffset = Offset;

                            while (ObjectsData[TestOffset] != 255)
                            {
                                if (ObjectsData[TestOffset] == 0)
                                {
                                    TestOffset += 3;
                                    TestWidth++;
                                }

                                else if (ObjectsData[TestOffset] == 254)
                                {
                                    if (TestWidth > Width)
                                    {
                                        Width = TestWidth;
                                    }

                                    TestWidth   = 0;
                                    TestOffset += 1;
                                    Height++;
                                }
                            }

                            for (int c = 0; c < Height; c++)
                            {
                                Tiles.Add(new List <int>());
                            }

                            for (int r = 0; r < Width; r++)
                            {
                                for (int c = 0; c < Height; c++)
                                {
                                    Tiles[c].Add(0);
                                }
                            }

                            int  Row    = 0;
                            int  Column = 0;
                            bool Pa2    = false;

                            while (ObjectsData[Offset] != 255)
                            {
                                if (ObjectsData[Offset] == 0)
                                {
                                    UInt16 Tile = BitConverter.ToUInt16(ObjectsData, Offset + 1);

                                    if (Tile >= 1024)
                                    {
                                        Pa2 = true;
                                    }

                                    Tiles[Row][Column] = Tile;
                                    Column++;
                                    Offset += 3;
                                }
                                else if (ObjectsData[Offset] == 254)
                                {
                                    Row++;
                                    Column  = 0;
                                    Offset += 1;
                                }
                            }

                            Bitmap PreviewBitmap = new Bitmap(16 * (Width == 0 ? 1 : Width), 16 * (Height == 0 ? 1 : Height));

                            using (Graphics g = Graphics.FromImage(PreviewBitmap))
                            {
                                for (int r = 0; r < Tiles.Count; r++)
                                {
                                    for (int t = 0; t < Tiles[r].Count; t++)
                                    {
                                        int TileID = Tiles[r][t] - (Pa2 ? 1024 : 256);

                                        Tiles[r][t] = TileID;

                                        g.PixelOffsetMode   = System.Drawing.Drawing2D.PixelOffsetMode.Half;
                                        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;

                                        if (TileID >= 0)
                                        {
                                            g.DrawImage(this.Tiles[TileID].TileBitmap, new Rectangle(new Point(16 * t, 16 * r), new Size(16, 16)), new Rectangle(0, 0, 16, 16), GraphicsUnit.Pixel);
                                        }
                                    }
                                }
                            }

                            string ObjectName = "Object " + f / 4;

                            if (JSONObject.object_names.Count() > (f / 4))
                            {
                                if (JSONObject.object_names[f / 4] != null)
                                {
                                    ObjectName = JSONObject.object_names[f / 4];
                                }
                            }

                            Object o = new Object(f / 4, Width, Height, ObjectName, Tiles, PreviewBitmap);
                            this.Objects[f / 4] = o;
                        }

                        #endregion

                        ObjectHash = Helpers.GetObjectHash(this);
                        Filename   = _Filename;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error loading tileset: " + ex.Message + " " + ex.StackTrace);
                return;
            }
        }