예제 #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            string nif = loaded.SelectedItems[0].Text;

            Objects.NIF obj = null;

            foreach (Objects.NIF n in Objects.NIFs.Values)
            {
                if (n.FileName == nif)
                {
                    obj = n;
                    break;
                }
            }

            if (obj == null)
            {
                return;
            }

            foreach (Objects.Fixture f in Objects.Fixtures)
            {
                if (f.NIF == obj)
                {
                    MessageBox.Show("NIF is currently in use.");
                    return;
                }
            }

            Objects.NIFs.Remove(obj.ID);
            LoadLoaded();

            SelectNIFDialog.reload = true;
        }
예제 #2
0
        private void loaded_SelectedIndexChanged(object sender, EventArgs e)
        {
            button3.Enabled = loaded.SelectedItems.Count > 0;

            if (loaded.SelectedItems.Count > 0)
            {
                Objects.NIF obj = null;
                string      nif = loaded.SelectedItems[0].Text;

                foreach (Objects.NIF n in Objects.NIFs.Values)
                {
                    if (n.FileName == nif)
                    {
                        obj = n;
                        break;
                    }
                }

                grid.SelectedObject = obj;
            }
        }
예제 #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem i in cur.SelectedItems)
            {
                string nif = i.Text;

                //Check if already added
                bool already = false;
                foreach (Objects.NIF n in Objects.NIFs.Values)
                {
                    if (n.FileName == nif)
                    {
                        already = true;
                        break; //already added
                    }
                }

                if (already)
                {
                    continue;
                }

                if (Objects.NIFs.Count >= 200)
                {
                    MessageBox.Show("Maximum NIF Count reached! (200)", "Error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    break;
                }

                //Add
                var nn = new Objects.NIF();
                nn.FileName = nif;
                nn.ID       = ++Objects.NIFS_Max;
                nn.LoadData();
                Objects.NIFs.Add(nn.ID, nn);
                SelectNIFDialog.reload = true;
            }

            LoadLoaded();
        }
예제 #4
0
        public static void GenerateBounding(string file, Objects.NIF n)
        {
            string bb = file + ".bb";

            if (File.Exists(bb))
            {
                Console.WriteLine("--- Reading cached .bb...");
                var rr = new StreamReader(bb);
                n.Position = new Vector3(float.Parse(rr.ReadLine()),
                                         float.Parse(rr.ReadLine()),
                                         float.Parse(rr.ReadLine()));

                n.Scale = new Vector3(float.Parse(rr.ReadLine()),
                                      float.Parse(rr.ReadLine()),
                                      float.Parse(rr.ReadLine()));
                rr.Close();
                return;
            }

            var r = new StreamReader(file);

            float minX = float.MaxValue;
            float minY = float.MaxValue;
            float minZ = float.MaxValue;

            float maxX = float.MinValue;
            float maxY = float.MinValue;
            float maxZ = float.MinValue;

            int v = 0;

            while (!r.EndOfStream)
            {
                string   line  = r.ReadLine().Replace('.', ',');
                string[] split = line.Split(' ');

                if (split.Length == 0)
                {
                    continue;
                }

                switch (split[0])
                {
                case "v": //vertex
                {
                    try {
                        float x = float.Parse(split[1]);
                        float y = float.Parse(split[2]);
                        float z = float.Parse(split[3]);

                        if (x > maxX)
                        {
                            maxX = x;
                        }
                        if (x < minX)
                        {
                            minX = x;
                        }

                        if (y > maxY)
                        {
                            maxY = y;
                        }
                        if (y < minY)
                        {
                            minY = y;
                        }

                        if (z > maxZ)
                        {
                            maxZ = z;
                        }
                        if (z < minZ)
                        {
                            minZ = z;
                        }

                        v++;
                    }
                    catch {
                        Console.WriteLine("invalid node: " + line);
                    }
                }
                break;
                }
            }

            r.Close();

            if (v > 0)
            {
                n.Position = new Vector3(minX,
                                         minY,
                                         minZ);

                n.Scale = new Vector3(maxX - minX,
                                      maxY - minY,
                                      maxZ - minZ);

                var w = new StreamWriter(bb);
                w.WriteLine(n.Position.X);
                w.WriteLine(n.Position.Y);
                w.WriteLine(n.Position.Z);
                w.WriteLine(n.Scale.X);
                w.WriteLine(n.Scale.Y);
                w.WriteLine(n.Scale.Z);
                w.Flush();
                w.Close();
                Console.WriteLine("--- BB saved!");
            }
        }
예제 #5
0
        private static void InternalLoadZone(string path)
        {
            LAST_SAVE = DateTime.UtcNow.Ticks;
            Loading.ShowLoading();

            Polygon.Polygons.Clear();
            var z = new Zone();

            Program.ZONE = z;
            z.PATH       = path;
            z.ZoneID     = int.Parse(Path.GetFileName(path).Remove(0, 4));

            Program.FORM.Text = "DAoC Zone Editor - " + z.ZoneID;

            {
                string p  = string.Format("dat{0}.mpk", z.ZoneID.ToString("D3"));
                string pp = path + "\\" + p;

                Loading.Update("Loading " + p + "...");
                z.LoadSectorDat(path);
                z.LoadHeightmap(path);
                z.LoadBoundings(path);

                #region zonejump.csv

                {
                    Loading.Update(p + "... - Zonejumps");

                    Zonejump.Zonejumps.Clear();
                    var zonejumpcsv = string.Format("{0}\\zonejump.csv", pp);
                    if (File.Exists(zonejumpcsv))
                    {
                        var rs = new StreamReader(zonejumpcsv);

                        while (!rs.EndOfStream)
                        {
                            string   line = rs.ReadLine();
                            string[] s    = line.Split(',');

                            //ID, Name, X, Y, X2, Y2, Z1, Z2, JID

                            var jp = new Zonejump();
                            jp.Name   = s[1];
                            jp.ID     = Parse(s[8]);
                            jp.First  = new Vector3(Parse(s[2]), Parse(s[3]), Parse(s[6]));
                            jp.Second = new Vector3(Parse(s[4]), Parse(s[5]), Parse(s[7]));
                            Zonejump.Zonejumps.Add(jp);
                        }

                        rs.Close();
                    }
                }

                #endregion

                #region lights.csv

                {
                    Loading.Update(p + "... - Lights");
                    Light.Lights.Clear();

                    string f = string.Format("{0}\\lights.csv", pp);
                    if (File.Exists(f))
                    {
                        var rs = new StreamReader(f);

                        while (!rs.EndOfStream)
                        {
                            string   line = rs.ReadLine();
                            string[] s    = line.Split(',');

                            //46473, 54362, 2910, 3
                            //X, Y, Z, Intensity

                            var l = new Light();
                            l.X = Parse(s[0]);
                            l.Y = Parse(s[1]);
                            int zz = Parse(s[2]);
                            int x  = Math.Min((int)Math.Round(l.X / 256f), 255);
                            int y  = Math.Min((int)Math.Round(l.Y / 256f), 255);
                            l.Z       = z.HeightMap[x, y];
                            l.ZOffset = zz - l.Z;
                            int col = Parse(s[3]);
                            l.Intensity = col / 10 + 1;
                            l.Color     = (LightColor)(col % 10);
                            Light.Lights.Add(l);
                        }

                        rs.Close();
                    }
                }

                #endregion

                Loading.Update("Loading patchmaps ...");
                Program.CONFIG.UsePatchmaps = true;

                #region texXXX.mpk

                {
                    string px  = string.Format("tex{0}.mpk", z.ZoneID.ToString("D3"));
                    string ppx = path + "\\" + px;

                    Loading.Update(px + "... - Terrain Texture");

                    //z.TextureSubZones = new Texture[8,8];

                    //Load all textures
                    var Textures = new Image[8, 8];
                    foreach (string file in Directory.GetFiles(ppx, "*.bmp"))
                    {
                        string f    = Path.GetFileName(file);
                        int    num1 = int.Parse(f.Substring(3, 2));
                        int    num2 = int.Parse(f.Substring(6, 2));
                        //tex01-02.bmp
                        Textures[num1, num2] = Image.FromFile(file);
                    }

                    //Merge
                    var      bmp = new Bitmap(2048, 2048);
                    Graphics g   = Graphics.FromImage(bmp);
                    g.Clear(Color.Violet);

                    for (int x = 0; x < 8; x++)
                    {
                        for (int y = 0; y < 8; y++)
                        {
                            Image t = Textures[x, y];

                            if (t == null)
                            {
                                continue;
                            }

                            g.DrawImage(t, x * 256, y * 256, 256, 256);
                        }
                    }

                    g.Save();
                    //bmp.RotateFlip(RotateFlipType.Rotate90FlipX);

                    var ms = new MemoryStream();
                    bmp.Save(ms, ImageFormat.Bmp);
                    ms.Capacity = (int)ms.Length;
                    ms.Position = 0;
                    Texture m = TextureLoader.FromStream(Program.FORM.renderControl1.DEVICE, ms);
                    //Texture m = new Texture(Program.FORM.renderControl1.DEVICE, ms, Usage.None, Pool.SystemMemory);
                    z.TextureMap = m;
                }

                #endregion

                var info = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone();
                info.NumberDecimalSeparator = ".";

                Loading.Update("Loading Sounds..");
                SoundMgr.Load();

                #region nifs.csv

                lock (Objects.NIFs)
                {
                    Objects.NIFs.Clear();
                    Loading.Update(p + "... - NIFs");

                    var rs = new StreamReader(string.Format("{0}\\nifs.csv", pp));

                    int index = 0;

                    while (!rs.EndOfStream)
                    {
                        index++;
                        string line = rs.ReadLine();

                        if (index <= 2)
                        {
                            continue; //header
                        }
                        string[] s = line.Split(',');

                        var nif = new Objects.NIF();
                        nif.ID = Parse(s[0]);
                        //1 = name
                        string name = s[1];
                        int    pos  = name.IndexOf('|');

                        if (pos > 0)
                        {
                            nif.Group = name.Substring(pos + 1);
                        }

                        nif.FileName = s[2];
                        //3 = ambient
                        //4 = merlin
                        //5 = color
                        nif.IsDoor    = s[6] == "1"; //6 = animate
                        nif.Collision = Parse(s[7]); //7 = collide
                        //8 = ground
                        //9 = minangle
                        //10 = maxangle
                        nif.MinScale      = Parse(s[11]);
                        nif.MaxScale      = Parse(s[12]);
                        nif.CollideRadius = Parse(s[13]); //13 = radius
                        Objects.NIFs.Add(nif.ID, nif);

                        if (nif.ID > Objects.NIFS_Max)
                        {
                            Objects.NIFS_Max = nif.ID;
                        }
                    }

                    rs.Close();
                }

                #endregion

                #region fixtures.csv

                lock (Objects.Fixtures)
                {
                    Loading.Update(p + "... - Fixtures");

                    Objects.Fixture_Max = -1;
                    Objects.Fixtures.Clear();

                    var rs = new StreamReader(string.Format("{0}\\fixtures.csv", pp));

                    int index = 0;

                    while (!rs.EndOfStream)
                    {
                        index++;
                        string line = rs.ReadLine();

                        if (index <= 2)
                        {
                            continue; //header
                        }
                        string[] s = line.Split(',');

                        try
                        {
                            var fix = new Objects.Fixture();
                            fix.ID   = Parse(s[0]);
                            fix.NIF  = Objects.NIFs[Parse(s[1])];
                            fix.Name = s[2];
                            fix.X    = float.Parse(s[3], info);
                            fix.Y    = float.Parse(s[4], info);
                            fix.Z    = float.Parse(s[5], info);
                            //6 = A (angle?)
                            fix.Scale = Parse(s[7]);
                            //8 = nif collide
                            //9 = collide radius
                            //10 = animate
                            fix.OnGround = s[11] == "1";
                            //12 = flip
                            //13 = cave
                            //14 = uid
                            if (s.Length > 15)
                            {
                                fix.Rotation = float.Parse(s[15], info);
                                fix.AxisX    = float.Parse(s[16], info);
                                fix.AxisY    = float.Parse(s[17], info);
                                fix.AxisZ    = float.Parse(s[18], info);
                            }

                            Objects.Fixtures.Add(fix);

                            if (fix.ID > Objects.Fixture_Max)
                            {
                                Objects.Fixture_Max = fix.ID;
                            }
                        }
                        catch (ArgumentOutOfRangeException) { }
                        catch (IndexOutOfRangeException) { }
                    }

                    rs.Close();
                }

                #endregion

                {
                    int total = Objects.NIFs.Values.Count;
                    int cur   = 0;
                    var array = new Objects.NIF[Objects.NIFs.Values.Count];
                    Objects.NIFs.Values.CopyTo(array, 0);
                    for (int i = array.Length - 1; i >= 0; i--)
                    {
                        Objects.NIF n = array[i];
                        Loading.Update(p + "... - NIFs (" + (++cur) + "/" + total + "): " + n.FileName);
                        n.LoadData();
                        //Application.DoEvents();
                    }
                }
            }

            LAST_SAVE = DateTime.UtcNow.Ticks;
            Loading.CloseLoading();
        }