예제 #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            Ultima.Tile mytile = new Ultima.Tile();

            //mytile = tm.GetLandTile(2563, 489);
            int mytileid = (mytile.ID & 0x3FFF);

            // uonet.display(""+mytileid);


            Ultima.Tile       mytile2 = new Ultima.Tile();
            Ultima.TileMatrix tm      = new TileMatrix(0, 0, 6144, 4096);
            HuedTile[]        htile   = tm.GetStaticTiles(2563, 489);
            int mytileid2             = (htile[0].ID & 0x3FFF); // need a check, exception if ID is 0

            //uonet.display("" + htile[0].ID + "___" + htile[1].ID);

            //mytile2 =



            mytile = tm.GetLandTile(273, 1216);
            //txtOutput.Text = txtOutput.Text + StringList.Table[1076267];
            //txtOutput.Text = txtOutput.Text +
        }
예제 #2
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);

            TileMatrix matrix = Parameters.CurrentMap.Tiles;

            bool tilesHighlite = false;

            pe.Graphics.Clear(Color.Black);
            MapCoordinates = new Hashtable();

            for (int x = 0; x < _TileWidth; x++)
            {
                for (int y = 0; y < _TileWidth; y++)
                {
                    int upperX = x * ScaledSize;
                    int upperY = y * ScaledSize;

                    Bitmap bmp = Cache.GetTile(matrix.GetLandTile(_Upper_Coordinate.X + x, _Upper_Coordinate.Y + y).ID, (int)MapScale);

                    if (bmp == null)
                    {
                        bmp = new Bitmap(ScaledSize, ScaledSize);
                        Graphics g = Graphics.FromImage(bmp);
                        g.Clear(Color.Black);
                        g.Dispose();
                    }

                    Rectangle area = new Rectangle(upperX, upperY, ScaledSize, ScaledSize);

                    if (_HighlightedArea.Contains(_Upper_Coordinate.X + x, _Upper_Coordinate.Y + y))
                    {
                        tilesHighlite = true;
                    }
                    else
                    {
                        tilesHighlite = false;
                    }

                    pe.Graphics.DrawImage(bmp, upperX, upperY);

                    if (MapScale >= Scaling.Scale10)
                    {
                        pe.Graphics.DrawRectangle(new Pen(Color.FromArgb(150, Color.Black)), area);
                    }
                    else
                    {
                        pe.Graphics.DrawRectangle(new Pen(Color.FromArgb(100, Color.Black)), area);
                    }

                    if (tilesHighlite)
                    {
                        pe.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(100, Color.Yellow)), area);
                    }

                    MapCoordinates[area] = new Point(_Upper_Coordinate.X + x, _Upper_Coordinate.Y + y);
                }
            }
        }
예제 #3
0
        protected override unsafe TransformedColoredTextured[] GetMesh(LandTile tile, Texture tex)
        {
            int *  pInput  = stackalloc int[16];
            float *numPtr1 = stackalloc float[this._meshProvider.Size];
            // ISSUE: untyped stack allocation
            IntPtr     num     = new IntPtr(checked (unchecked ((uint)_meshProvider.Size) * sizeof(Point3D)));
            TileMatrix matrix  = Map.GetMatrix(Engine.m_World);
            int *      numPtr2 = pInput;

            for (int index1 = -1; index1 < 3; ++index1)
            {
                for (int index2 = -1; index2 < 3; ++index2)
                {
                    *numPtr2++ = (int)matrix.GetLandTile(tile.ax + index2, tile.ay + index1).z;
                }
            }
            this._meshProvider.Sample(pInput, numPtr1);
            this._foldLeftRight = tile.m_FoldLeftRight;
            this.ComputeMesh(numPtr1);
            this.ComputeNormals(numPtr1);
            return(this._mesh);
        }
        private void ShowMapButton_Click(object sender, EventArgs e)
        {
            try { Application.OpenForms["MapViewer"].Close(); }
            catch { }

            MapViewer DWM = new MapViewer();

            if (RenderedMaps[facetList.SelectedIndex] == null)
            {
                TileMatrix matrix = Parameters.CurrentMap.Tiles;

                Bitmap bmp = new Bitmap(Parameters.CurrentMap.Width, Parameters.CurrentMap.Height);

                renderProgress.Visible = true;
                renderProgress.Value   = 0;
                renderProgress.Maximum = bmp.Width;

                for (int x = 0; x < Parameters.CurrentMap.Width; x++)
                {
                    for (int y = 0; y < Parameters.CurrentMap.Height; y++)
                    {
                        bmp.SetPixel(x, y, Cache.GetColor(matrix.GetLandTile(x, y).ID));
                    }

                    renderProgress.Increment(1);
                }

                renderProgress.Visible = false;

                bmp.Save(String.Format("Map{0}.bmp", facetList.SelectedIndex));
                RenderedMaps[facetList.SelectedIndex] = bmp;
            }

            if (RenderedMaps[facetList.SelectedIndex] != null)
            {
                DWM.Editor = this;

                System.Drawing.Size size = new System.Drawing.Size(RenderedMaps[facetList.SelectedIndex].Width, RenderedMaps[facetList.SelectedIndex].Height);

                int reductionPercentage = 100;

                while ((size.Width > Screen.GetWorkingArea(DWM).Width - 100 || size.Height > Screen.GetWorkingArea(DWM).Height - 100) && reductionPercentage > 0)
                {
                    double reduction = (double)reductionPercentage * 0.01;

                    size.Width  = (int)((double)RenderedMaps[facetList.SelectedIndex].Width * reduction);
                    size.Height = (int)((double)RenderedMaps[facetList.SelectedIndex].Height * reduction);

                    reductionPercentage -= 1;
                }

                size.Width  += 6;
                size.Height += 51;

                DWM.Location = new Point((Screen.PrimaryScreen.WorkingArea.Width - size.Width) / 2, (Screen.PrimaryScreen.WorkingArea.Height - size.Height) / 2);
                DWM.Size     = size;

                Bitmap   newBMP = new Bitmap(DWM.mapImage.Width, DWM.mapImage.Height);
                Graphics g      = Graphics.FromImage(newBMP);
                g.DrawImage(RenderedMaps[facetList.SelectedIndex], 0, 0, DWM.mapImage.Width, DWM.mapImage.Height);
                g.Dispose();

                DWM.mapImage.Image = newBMP;
                DWM.Show();
                DWM.Focus();
                DWM.Select();
            }
        }
예제 #5
0
        //-----------------//
        //--PATCH MUL MAP--//
        //-----------------//



        //-------------------------//
        //--GENERATE DICTIONARIES--//
        //-------------------------//

        public static void GenerateDictionary_CC_EC(MainForm form)
        {
            //Dictionary population is achieved by reading ALL the standard map tiles from SA Classic Client (MAPx.MUL, not facetx.uop), finding the land graphic and searching the correspective
            // at the same coordinates in the SA Enhanced Client uncompressed map block files, obtained by unpacking facetX.uop (here i will use only facet0)
            //This obviously works only if both maps are identical (and this is the case of the two CC and EC map files, at the same patch version), or differs only for the tiles you want
            // to convert (read above), in the case we have a snowy CC map and a normal EC map.
            //
            //Only differing tiles will be saved in the dictionary.
            //
            //It doesn't use map diffs, for now!

            form.Invoke(new DelegateString(form.AppendToLog), "Setting up for dictionary generation..\n");

            SortedDictionary <short, short> LandtileDictionary = new SortedDictionary <short, short>();

            //directory of the unpacked facet0.uop (use Mythic Package Editor to do that), where the binaries are, not where the directory tree is (build/sectors/facet0/)
            string       sa_dir    = "C:\\Users\\claudio\\ultima\\unpack\\build\\sectors\\facet_00\\";
            FileStream   sa_stream = null;
            BinaryReader sa        = null;

            int        prog = 0;
            short      buffer, count;
            string     sa_filename;
            TileMatrix tileMatrix = new TileMatrix("C:\\UO_cc\\", 0, 0, 7168, 4096);   //pre-KR map, ML dimensions //0,0 = fileindex, mapid
            Tile       tile       = tileMatrix.GetLandTile(0, 0);

            try
            {
                form.Invoke(new DelegateString(form.AppendToLog), "Dictionary population started!\n");
                //start of blocks iteration - cycle between SA map blocks
                for (short blocksX = 0; blocksX < (tileMatrix.Width / 64); blocksX++)
                {
                    for (short blocksY = 0; blocksY < (tileMatrix.Height / 64); blocksY++)
                    {
                        sa_filename = string.Format("{0:D8}.bin", prog);
                        form.Invoke(new DelegateString(form.AppendToLog), String.Format("Reading SA block {0}\n", sa_filename));
                        form.Invoke(new StatusBarDelegate(form.ProgressbarIncrease));
                        sa_stream = new FileStream(sa_dir + sa_filename, FileMode.Open);
                        sa        = new BinaryReader(sa_stream);
                        sa.BaseStream.Seek(1 + 2, SeekOrigin.Begin);                                                //skip file header (BYTE facetid, WORD fileid)

                        for (int x = 0 + blocksX * 64; x < blocksX * 64 + 64; x++)                                  //coordinates of the tile in the map, not in the block
                        {
                            for (int y = 0 + blocksY * 64; y < blocksY * 64 + 64; y++)
                            {
                                tile = tileMatrix.GetLandTile(x, y);

                                // start of the tile definition
                                sa.BaseStream.Seek(1, SeekOrigin.Current);                                          //skip the z BYTE
                                buffer = (short)sa.ReadInt16();                                                     //read landtilegraphic WORD
                                if ((short)tile.ID != buffer)
                                {
                                    if (!LandtileDictionary.ContainsKey((short)tile.ID))
                                    {
                                        LandtileDictionary.Add((short)tile.ID, buffer);                                 //add a voice to the dictionary, if not present
                                        form.Invoke(new DelegateString(form.AppendToLog), string.Format("At {0},{1} found 0x{2:X} to convert in 0x{3:X}\n", x, y, tile.ID, buffer));
                                    }
                                }

                                buffer = (short)sa.ReadByte();                                                      //read delimitercount (BYTE)
                                if (buffer > 0)                                                                     // if there are delimiters, skip some things..
                                {
                                    for (count = 0; count < buffer; count++)
                                    {
                                        if ((short)sa.ReadByte() <= 7)                                              //ensures there is a valid direction (BYTE)
                                        {
                                            sa.BaseStream.Seek(1 + 4, SeekOrigin.Current);                          //skip z (BYTE) and landtilegraphic (DWORD)
                                        }
                                    }
                                }
                                buffer = (short)sa.ReadByte();                                                      //read staticscount (BYTE)
                                if (buffer > 0)
                                {
                                    for (count = 0; count < buffer; count++)
                                    {
                                        sa.BaseStream.Seek(4 + 1 + 4, SeekOrigin.Current);                          //skip static graphic (DWORD), z (BYTE), color (DWORD)
                                    }
                                }
                                //end of the tile definition
                            }
                        }

                        sa.Close();
                        prog++;
                    }
                }
                //end of blocks iteration
            }
            catch (ObjectDisposedException)
            {
                form.Invoke(new DelegateString(form.AppendToLog), "\nError reading the file, maybe it's corrupted or the format is not valid..");
            }


            // Now that the dictionary is populated, we can write it into a file
            //
            //DICTIONARY FILE STRUCTURE:
            //(from the head until EOF, for each id)
            //- WORD pre-KR landtilegraphic id
            //- WORD stygian abyss enhanced client landtilegraphic id
            form.Invoke(new DelegateString(form.AppendToLog), "Dictionary generated in local memory, writing into file..\n");

            FileStream   dict_stream = new FileStream("c:\\out\\landtileDict.bin", FileMode.Create);
            BinaryWriter writer      = new BinaryWriter(dict_stream);

            foreach (var p in LandtileDictionary)
            {
                writer.Write(p.Key);
                writer.Write(p.Value);
            }

            writer.Close();
            form.Invoke(new DelegateString(form.AppendToLog), "Dictionary generation completed!\n");
            form.Invoke(new SuccessDelegate(form.Success));
        }
예제 #6
0
        public static void GenerateDictionary_CC_CC(MainForm form)
        {
            // Dictionary population is achieved by reading ALL the map tiles from a MAPx.MUL, finding the land graphic and searching the correspective
            // at the same coordinates in the second MAPx.MUL.
            //This obviously works only if both maps are identical, or differs only for the tiles you want
            // to convert (read above), in the case we have a snowy map and a normal map.
            //
            //Only differing tiles will be saved in the dictionary.

            form.Invoke(new DelegateString(form.AppendToLog), "Setting up for dictionary generation..\n");

            SortedDictionary <short, short> LandtileDictionary = new SortedDictionary <short, short>();

            //tiles from file 1 (e.g. normal map) will be substituted
            TileMatrix tileMatrix_1 = new TileMatrix("C:\\out\\1\\", 0, 0, 7168, 4096);   //pre-KR map, ML dimensions //0,0 = fileindex, mapid
            Tile       tile_1       = tileMatrix_1.GetLandTile(0, 0);
            // with the same tile (if different) from file 2 (e.g. snowy map)
            TileMatrix tileMatrix_2 = new TileMatrix("C:\\out\\2\\", 0, 0, 7168, 4096);   //pre-KR map, ML dimensions //0,0 = fileindex, mapid
            Tile       tile_2       = tileMatrix_2.GetLandTile(0, 0);

            try
            {
                form.Invoke(new DelegateString(form.AppendToLog), "Dictionary population started! Reading...\n");

                for (int x = 0; x < tileMatrix_1.Width; x++)
                {
                    for (int y = 0; y < tileMatrix_1.Height; y++)
                    {
                        tile_1 = tileMatrix_1.GetLandTile(x, y);
                        tile_2 = tileMatrix_2.GetLandTile(x, y);

                        if (tile_1.ID != tile_2.ID)
                        {
                            if (!LandtileDictionary.ContainsKey((short)tile_1.ID))
                            {
                                LandtileDictionary.Add((short)tile_1.ID, (short)tile_2.ID); //add a voice to the dictionary, if not present
                                form.Invoke(new DelegateString(form.AppendToLog), string.Format("At {0},{1} found 0x{2:X} to convert in 0x{3:X}\n", x, y, tile_1.ID, tile_2.ID));
                            }
                        }
                    }
                    form.Invoke(new StatusBarDelegate(form.ProgressbarIncrease));
                }
            }
            catch (ObjectDisposedException)
            {
                form.Invoke(new DelegateString(form.AppendToLog), "\nError reading the file, maybe it's corrupted or the format is not valid..");
            }


            // Now that the dictionary is populated, we can write it into a file
            //
            //DICTIONARY FILE STRUCTURE:
            //(from the head until EOF, for each id)
            //- WORD id to be substituted
            //- WORD substitute previous id with this one
            form.Invoke(new DelegateString(form.AppendToLog), "Dictionary generated in local memory, writing into file..\n");

            FileStream   dict_stream = new FileStream("c:\\out\\landtileDict.bin", FileMode.Create);
            BinaryWriter writer      = new BinaryWriter(dict_stream);

            foreach (var p in LandtileDictionary)
            {
                writer.Write(p.Key);
                writer.Write(p.Value);
                //form.Invoke(new DelegateString(form.AppendToLog), string.Format("Writing 0x{0:X} to 0x{1:X}\n", p.Key, p.Value));
            }

            writer.Close();
            form.Invoke(new DelegateString(form.AppendToLog), "Dictionary generation completed!\n");
            form.Invoke(new SuccessDelegate(form.Success));
        }
예제 #7
0
        private void button3_Click(object sender, EventArgs e)
        {
            string newPath = Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf('\\'));

            newPath += @"\Created\";

            if (!Directory.Exists(newPath))
            {
                Directory.CreateDirectory(newPath);
            }
            TileMatrix tm = new TileMatrix(0, 0, 6144, 4096);
            TransTable tt = new TransTable();

            for (int BlockX = 0; BlockX < 96; BlockX++)
            {
                for (int BlockY = 0; BlockY < 64; BlockY++)
                {
                    int BlockID  = BlockX * 64 + BlockY + 1;
                    int firstID  = BlockID / 100;
                    int secondID = BlockID - firstID * 100;
                    BlockID--;
                    String       filename = newPath + "facet0_" + firstID + "_" + secondID + ".dat";
                    BinaryWriter bw       = new BinaryWriter(File.Create(filename));
                    Tile         t;
                    HuedTile[]   ht;
                    bool         overlap = false;
                    for (int X = BlockX * 64; X < (BlockX + 1) * 64; X++)
                    {
                        for (int Y = BlockY * 64; Y < (BlockY + 1) * 64; Y++)
                        {
                            t = tm.GetLandTile(X, Y);
                            if (!overlap)
                            {
                                bw.Write((byte)0);
                            }
                            else
                            {
                                overlap = false;
                            }
                            if (bw.BaseStream.Position == 1)
                            {
                                bw.Write((UInt16)BlockID);
                            }
                            else
                            {
                                bw.Write((UInt16)0);
                            }
                            bw.Write((SByte)t.Z);
                            bw.Write((UInt16)tt[t.ID]);
                            bw.Write(UopParser.Flip((UInt16)t.ID));
                            AddDelimiters(bw, BlockX, BlockY, X, Y);
                            ht = tm.GetStaticTiles(X, Y);
                            if (ht != null)
                            {
                                for (int i = 0; i < ht.Length; i++)
                                {
                                    if (!overlap)
                                    {
                                        bw.Write((byte)0);
                                    }
                                    else
                                    {
                                        overlap = false;
                                    }
                                    bw.Write((byte)0);
                                    if (i == 0)
                                    {
                                        bw.Write((byte)ht.Length);
                                    }
                                    else
                                    {
                                        bw.Write((byte)0);
                                    }
                                    bw.Write((UInt16)ht[i].ID);
                                    bw.Write((UInt16)0);
                                    bw.Write((sbyte)ht[i].Z);
                                    bw.Write((UInt16)ht[i].Hue);
                                    overlap = true;
                                }
                            }
                        }
                    }
                    bw.Write(new byte[] { 0, 0, 0 });
                    bw.Close();
                }
            }
        }
예제 #8
0
파일: Converter.cs 프로젝트: cbnolok/UOEMC
        private void WriteLandTile(BinaryWriter writer, int x, int y)
        {
            Tile tile = tileMatrix.GetLandTile(x, y);

            writer.Write(GetZ((sbyte)tile.Z));                         //BYTE  -> tile Z
            writer.Write(GetLandTileID(tile.ID));                      //WORD -> LANDTILEgraphic
        }