Ejemplo n.º 1
0
 public void SetYbn(YbnFile ybn)
 {
     Ybn = ybn;
     Tag = ybn;
     UpdateFormTitle();
     UpdateUI();
     waschanged = ybn?.HasChanged ?? false;
 }
Ejemplo n.º 2
0
 public bool ContainsYbn(YbnFile ybn)
 {
     foreach (var f in YbnFiles)
     {
         if (f == ybn)
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 3
0
        public void LoadModel(YbnFile ybn)
        {
            if (ybn == null)
            {
                return;
            }

            FileName = ybn.Name;
            Ybn      = ybn;

            UpdateBoundsUI(ybn.Bounds);
        }
Ejemplo n.º 4
0
        public YbnFile AddYbnFile(string filename)
        {
            YbnFile ybn = new YbnFile();

            ybn.RpfFileEntry      = new RpfResourceFileEntry();
            ybn.RpfFileEntry.Name = Path.GetFileName(filename);
            ybn.FilePath          = GetFullFilePath(filename);
            ybn.Name = ybn.RpfFileEntry.Name;
            if (!AddYbnFile(ybn))
            {
                return(null);
            }
            return(ybn);
        }
Ejemplo n.º 5
0
        public void RemoveYbnFile(YbnFile ybn)
        {
            if (ybn == null)
            {
                return;
            }
            var relpath = GetRelativePath(ybn.FilePath);

            if (string.IsNullOrEmpty(relpath))
            {
                relpath = ybn.Name;
            }
            YbnFiles.Remove(ybn);
            YbnFilenames.Remove(relpath);
            HasChanged = true;
        }
Ejemplo n.º 6
0
        public bool AddYbnFile(YbnFile ybn)
        {
            string relpath = GetRelativePath(ybn.FilePath);

            if (string.IsNullOrEmpty(relpath))
            {
                relpath = ybn.Name;
            }
            if (YndFilenames.Contains(relpath))
            {
                return(false);
            }
            YbnFilenames.Add(relpath);
            YbnFiles.Add(ybn);
            return(true);
        }
Ejemplo n.º 7
0
        private void SelectFile(RpfEntry entry, int offset, int length)
        {
            SelectedEntry  = entry;
            SelectedOffset = offset;
            SelectedLength = length;

            RpfFileEntry rfe = entry as RpfFileEntry;

            if (rfe == null)
            {
                RpfDirectoryEntry rde = entry as RpfDirectoryEntry;
                if (rde != null)
                {
                    FileInfoLabel.Text = rde.Path + " (Directory)";
                    DataTextBox.Text   = "[Please select a data file]";
                }
                else
                {
                    FileInfoLabel.Text = "[Nothing selected]";
                    DataTextBox.Text   = "[Please select a data file]";
                }
                ShowTextures(null);
                return;
            }


            Cursor = Cursors.WaitCursor;

            string typestr = "Resource";

            if (rfe is RpfBinaryFileEntry)
            {
                typestr = "Binary";
            }

            byte[] data = rfe.File.ExtractFile(rfe);

            int datalen = (data != null) ? data.Length : 0;

            FileInfoLabel.Text = rfe.Path + " (" + typestr + " file)  -  " + TextUtil.GetBytesReadable(datalen);


            if (ShowLargeFileContentsCheckBox.Checked || (datalen < 524287)) //512K
            {
                DisplayFileContentsText(rfe, data, length, offset);
            }
            else
            {
                DataTextBox.Text = "[Filesize >512KB. Select the Show large files option to view its contents]";
            }



            bool istexdict = false;


            if (rfe.NameLower.EndsWith(".ymap"))
            {
                YmapFile ymap = new YmapFile(rfe);
                ymap.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = ymap;
            }
            else if (rfe.NameLower.EndsWith(".ytyp"))
            {
                YtypFile ytyp = new YtypFile();
                ytyp.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = ytyp;
            }
            else if (rfe.NameLower.EndsWith(".ymf"))
            {
                YmfFile ymf = new YmfFile();
                ymf.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = ymf;
            }
            else if (rfe.NameLower.EndsWith(".ymt"))
            {
                YmtFile ymt = new YmtFile();
                ymt.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = ymt;
            }
            else if (rfe.NameLower.EndsWith(".ybn"))
            {
                YbnFile ybn = new YbnFile();
                ybn.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = ybn;
            }
            else if (rfe.NameLower.EndsWith(".fxc"))
            {
                FxcFile fxc = new FxcFile();
                fxc.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = fxc;
            }
            else if (rfe.NameLower.EndsWith(".yft"))
            {
                YftFile yft = new YftFile();
                yft.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = yft;

                if ((yft.Fragment != null) && (yft.Fragment.Drawable != null) && (yft.Fragment.Drawable.ShaderGroup != null) && (yft.Fragment.Drawable.ShaderGroup.TextureDictionary != null))
                {
                    ShowTextures(yft.Fragment.Drawable.ShaderGroup.TextureDictionary);
                    istexdict = true;
                }
            }
            else if (rfe.NameLower.EndsWith(".ydr"))
            {
                YdrFile ydr = new YdrFile();
                ydr.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = ydr;

                if ((ydr.Drawable != null) && (ydr.Drawable.ShaderGroup != null) && (ydr.Drawable.ShaderGroup.TextureDictionary != null))
                {
                    ShowTextures(ydr.Drawable.ShaderGroup.TextureDictionary);
                    istexdict = true;
                }
            }
            else if (rfe.NameLower.EndsWith(".ydd"))
            {
                YddFile ydd = new YddFile();
                ydd.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = ydd;
                //todo: show embedded texdicts in ydd's? is this possible?
            }
            else if (rfe.NameLower.EndsWith(".ytd"))
            {
                YtdFile ytd = new YtdFile();
                ytd.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = ytd;
                ShowTextures(ytd.TextureDict);
                istexdict = true;
            }
            else if (rfe.NameLower.EndsWith(".ycd"))
            {
                YcdFile ycd = new YcdFile();
                ycd.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = ycd;
            }
            else if (rfe.NameLower.EndsWith(".ynd"))
            {
                YndFile ynd = new YndFile();
                ynd.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = ynd;
            }
            else if (rfe.NameLower.EndsWith(".ynv"))
            {
                YnvFile ynv = new YnvFile();
                ynv.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = ynv;
            }
            else if (rfe.NameLower.EndsWith("_cache_y.dat"))
            {
                CacheDatFile cdf = new CacheDatFile();
                cdf.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = cdf;
            }
            else if (rfe.NameLower.EndsWith(".rel"))
            {
                RelFile rel = new RelFile(rfe);
                rel.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = rel;
            }
            else if (rfe.NameLower.EndsWith(".gxt2"))
            {
                Gxt2File gxt2 = new Gxt2File();
                gxt2.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = gxt2;
            }
            else if (rfe.NameLower.EndsWith(".pso"))
            {
                JPsoFile pso = new JPsoFile();
                pso.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = pso;
            }
            else
            {
                DetailsPropertyGrid.SelectedObject = null;
            }


            if (!istexdict)
            {
                ShowTextures(null);
            }


            Cursor = Cursors.Default;
        }
Ejemplo n.º 8
0
        private void startButton_Click(object sender, EventArgs e)
        {
            var watch = Stopwatch.StartNew();

            TimeLabel.Text       = "Time Elapsed: 0ms";
            cancelButton.Enabled = true;
            var errorFiles = new List <string>()
            {
            };

            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;
                for (var j = 0; j < CurrentList.Items.Count; j++)
                {
                    if (CancelLoop)
                    {
                        FilesAddedLabel.Text = "Cancelled";
                        CancelLoop           = false;
                        return;
                    }
                    string filename      = CurrentList.Items[j].ToString();
                    FilesAddedLabel.Text = "Processing " + Path.GetFileName(filename) + " (" + (j + 1) + " of " + CurrentList.Items.Count + ")";

                    if (filename.EndsWith(".ybn"))
                    {
                        YbnFile ybn = new YbnFile();
                        RpfDirectoryEntry RPFFilesDirectory;
                        byte[] oldData;
                        if (filename.Contains(".rpf"))
                        {
                            string fileDirectory = StringFunctions.TopMostRPF(filename);
                            if (File.Exists(filename))
                            {
                                RPFFilesDirectory = null;
                                oldData           = File.ReadAllBytes(filename);
                            }
                            else
                            {
                                RpfFile TopRPF = new RpfFile(fileDirectory, fileDirectory);
                                TopRPF.ScanStructure(null, null);
                                (RPFFilesDirectory, oldData) = RPFFunctions.GetFileData(TopRPF, Path.GetFileName(filename));
                            }
                        }
                        else
                        {
                            RPFFilesDirectory = null;
                            oldData           = File.ReadAllBytes(filename);
                        }
                        try
                        {
                            ybn.Load(oldData);
                            byte[] newData = ybn.Save();
                            if (filename.Contains(".rpf"))
                            {
                                if (File.Exists(filename))
                                {
                                    RPFFilesDirectory = null;
                                    oldData           = File.ReadAllBytes(filename);
                                }
                                else
                                {
                                    RPFFunctions.AddFileBackToRPF(RPFFilesDirectory, filename, newData);
                                }
                            }
                            else
                            {
                                File.WriteAllBytes(filename, newData);
                            }
                            var elapsedMss = watch.ElapsedMilliseconds;
                            TimeLabel.Text = "Time Elapsed: " + StringFunctions.ConvertMillisecondsToSeconds(elapsedMss).ToString();
                        }
                        catch (Exception)
                        {
                            errorFiles.Add(filename);
                        }
                    }
                    else if (filename.EndsWith(".ydr"))
                    {
                        YdrFile ydr = new YdrFile();
                        RpfDirectoryEntry RPFFilesDirectory;
                        byte[] oldData;
                        if (filename.Contains(".rpf"))
                        {
                            string fileDirectory = StringFunctions.TopMostRPF(filename);
                            if (File.Exists(filename))
                            {
                                RPFFilesDirectory = null;
                                oldData           = File.ReadAllBytes(filename);
                            }
                            else
                            {
                                RpfFile TopRPF = new RpfFile(fileDirectory, fileDirectory);
                                TopRPF.ScanStructure(null, null);
                                (RPFFilesDirectory, oldData) = RPFFunctions.GetFileData(TopRPF, Path.GetFileName(filename));
                            }
                        }
                        else
                        {
                            RPFFilesDirectory = null;
                            oldData           = File.ReadAllBytes(filename);
                        }
                        try
                        {
                            RpfFile.LoadResourceFile(ydr, oldData, 165);
                            byte[] newData = ydr.Save();
                            if (filename.Contains(".rpf"))
                            {
                                if (File.Exists(filename))
                                {
                                    RPFFilesDirectory = null;
                                    oldData           = File.ReadAllBytes(filename);
                                }
                                else
                                {
                                    RPFFunctions.AddFileBackToRPF(RPFFilesDirectory, filename, newData);
                                }
                            }
                            else
                            {
                                File.WriteAllBytes(filename, newData);
                            }
                            var elapsedMss = watch.ElapsedMilliseconds;
                            TimeLabel.Text = "Time Elapsed: " + StringFunctions.ConvertMillisecondsToSeconds(elapsedMss).ToString();
                        }
                        catch (Exception)
                        {
                            errorFiles.Add(filename);
                        }
                    }
                    else if (filename.EndsWith(".ydd"))
                    {
                        YddFile ydd = new YddFile();
                        RpfDirectoryEntry RPFFilesDirectory;
                        byte[] oldData;
                        if (filename.Contains(".rpf"))
                        {
                            string fileDirectory = StringFunctions.TopMostRPF(filename);
                            if (File.Exists(filename))
                            {
                                RPFFilesDirectory = null;
                                oldData           = File.ReadAllBytes(filename);
                            }
                            else
                            {
                                RpfFile TopRPF = new RpfFile(fileDirectory, fileDirectory);
                                TopRPF.ScanStructure(null, null);
                                (RPFFilesDirectory, oldData) = RPFFunctions.GetFileData(TopRPF, Path.GetFileName(filename));
                            }
                        }
                        else
                        {
                            RPFFilesDirectory = null;
                            oldData           = File.ReadAllBytes(filename);
                        }
                        try
                        {
                            RpfFile.LoadResourceFile(ydd, oldData, 165);
                            byte[] newData = ydd.Save();
                            if (filename.Contains(".rpf"))
                            {
                                if (File.Exists(filename))
                                {
                                    RPFFilesDirectory = null;
                                    oldData           = File.ReadAllBytes(filename);
                                }
                                else
                                {
                                    RPFFunctions.AddFileBackToRPF(RPFFilesDirectory, filename, newData);
                                }
                            }
                            else
                            {
                                File.WriteAllBytes(filename, newData);
                            }
                            var elapsedMss = watch.ElapsedMilliseconds;
                            TimeLabel.Text = "Time Elapsed: " + StringFunctions.ConvertMillisecondsToSeconds(elapsedMss).ToString();
                        }
                        catch (Exception)
                        {
                            errorFiles.Add(filename);
                        }
                    }
                    else if (filename.EndsWith(".yft"))
                    {
                        YftFile yft = new YftFile();
                        RpfDirectoryEntry RPFFilesDirectory;
                        byte[] oldData;
                        if (filename.Contains(".rpf"))
                        {
                            string fileDirectory = StringFunctions.TopMostRPF(filename);
                            if (File.Exists(filename))
                            {
                                RPFFilesDirectory = null;
                                oldData           = File.ReadAllBytes(filename);
                            }
                            else
                            {
                                RpfFile TopRPF = new RpfFile(fileDirectory, fileDirectory);
                                TopRPF.ScanStructure(null, null);
                                (RPFFilesDirectory, oldData) = RPFFunctions.GetFileData(TopRPF, Path.GetFileName(filename));
                            }
                        }
                        else
                        {
                            RPFFilesDirectory = null;
                            oldData           = File.ReadAllBytes(filename);
                        }
                        try
                        {
                            RpfFile.LoadResourceFile(yft, oldData, 162);
                            byte[] newData = yft.Save();
                            if (filename.Contains(".rpf"))
                            {
                                if (File.Exists(filename))
                                {
                                    RPFFilesDirectory = null;
                                    oldData           = File.ReadAllBytes(filename);
                                }
                                else
                                {
                                    RPFFunctions.AddFileBackToRPF(RPFFilesDirectory, filename, newData);
                                }
                            }
                            else
                            {
                                File.WriteAllBytes(filename, newData);
                            }
                            var elapsedMss = watch.ElapsedMilliseconds;
                            TimeLabel.Text = "Time Elapsed: " + StringFunctions.ConvertMillisecondsToSeconds(elapsedMss).ToString();
                        }
                        catch (Exception)
                        {
                            errorFiles.Add(filename);
                        }
                    }
                }
                if (errorFiles.Count != 0)
                {
                    string message = "The following file(s) were corrupted and were not edited.\n\n";
                    foreach (string item in errorFiles)
                    {
                        message = message + item + "\n";
                    }
                    MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                FilesAddedLabel.Text = "Complete";
                var elapsedMs        = watch.ElapsedMilliseconds;
                TimeLabel.Text       = "Time Elapsed: " + StringFunctions.ConvertMillisecondsToSeconds(elapsedMs).ToString();
                cancelButton.Enabled = false;
            }).Start();
        }
Ejemplo n.º 9
0
        private void startButton_Click(object sender, EventArgs e)
        {
            timerTime            = DateTime.Now;
            watch                = new System.Threading.Timer(Tick, null, 0, 10);
            cancelButton.Enabled = true;
            var errorFiles = new List <string>()
            {
            };

            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;
                //while (cancelLoop)
                //{
                for (var j = 0; j < CurrentList.Items.Count; j++)
                {
                    string filename      = CurrentList.Items[j].ToString();
                    FilesAddedLabel.Text = "Processing " + Path.GetFileName(filename) + " (" + (j + 1) + " of " + CurrentList.Items.Count + ")";

                    Vector3 moveVec = new Vector3(float.Parse(xMove.Text), float.Parse(yMove.Text), float.Parse(zMove.Text));
                    //Quaternion rotVec = Quaternion.RotationYawPitchRoll(float.Parse(xRotate.Text), float.Parse(yRotate.Text), float.Parse(zRotate.Text));

                    if (backupFilesToolStripMenuItem.Checked)
                    {
                        if (!filename.Contains(".rpf"))
                        {
                            File.Copy(filename, $"{filename}.old", true);
                        }
                        else
                        {
                            string fileDirectory = StringFunctions.TopMostRPF(filename);
                            File.Copy(fileDirectory, Path.Combine(fileDirectory, ".old"));
                        }
                    }

                    if (filename.EndsWith(".ybn"))
                    {
                        YbnFile ybn = new YbnFile();
                        RpfDirectoryEntry RPFFilesDirectory;
                        byte[] oldData;
                        if (filename.Contains(".rpf"))
                        {
                            string fileDirectory = StringFunctions.TopMostRPF(filename);
                            if (File.Exists(filename))
                            {
                                RPFFilesDirectory = null;
                                oldData           = File.ReadAllBytes(filename);
                            }
                            else
                            {
                                RpfFile TopRPF = new RpfFile(fileDirectory, fileDirectory);
                                TopRPF.ScanStructure(null, null);
                                (RPFFilesDirectory, oldData) = RPFFunctions.GetFileData(TopRPF, Path.GetFileName(filename));
                            }
                        }
                        else
                        {
                            RPFFilesDirectory = null;
                            oldData           = File.ReadAllBytes(filename);
                        }

                        try
                        {
                            ybn.Load(oldData);

                            if (ybn.Bounds != null)
                            {
                                ybn.Bounds.BoxCenter    += moveVec;
                                ybn.Bounds.BoxMax       += moveVec;
                                ybn.Bounds.BoxMin       += moveVec;
                                ybn.Bounds.SphereCenter += moveVec;

                                BoundComposite boundcomp = ybn.Bounds as BoundComposite;
                                var compchilds           = boundcomp?.Children?.data_items;
                                if (boundcomp.BVH != null)
                                {
                                    Vector3 boundcompBBC            = MathFunctions.ConvertToVec3(boundcomp.BVH.BoundingBoxCenter);
                                    Vector3 boundcompBBMax          = MathFunctions.ConvertToVec3(boundcomp.BVH.BoundingBoxMax);
                                    Vector3 boundcompBBMin          = MathFunctions.ConvertToVec3(boundcomp.BVH.BoundingBoxMin);
                                    boundcomp.BVH.BoundingBoxCenter = new Vector4(boundcompBBC + moveVec, boundcomp.BVH.BoundingBoxCenter.W);
                                    boundcomp.BVH.BoundingBoxMax    = new Vector4(boundcompBBMax + moveVec, boundcomp.BVH.BoundingBoxMax.W);
                                    boundcomp.BVH.BoundingBoxMin    = new Vector4(boundcompBBMin + moveVec, boundcomp.BVH.BoundingBoxMin.W);
                                }
                                if (compchilds != null)
                                {
                                    for (int i = 0; i < compchilds.Length; i++)
                                    {
                                        compchilds[i].BoxCenter    += moveVec;
                                        compchilds[i].BoxMax       += moveVec;
                                        compchilds[i].BoxMin       += moveVec;
                                        compchilds[i].SphereCenter += moveVec;
                                        BoundBVH bgeom              = compchilds[i] as BoundBVH;
                                        if (bgeom != null)
                                        {
                                            if (bgeom.BVH != null)
                                            {
                                                Vector3 bgeomBBC            = MathFunctions.ConvertToVec3(bgeom.BVH.BoundingBoxCenter);
                                                Vector3 bgeomBBMax          = MathFunctions.ConvertToVec3(bgeom.BVH.BoundingBoxMax);
                                                Vector3 bgeomBBMin          = MathFunctions.ConvertToVec3(bgeom.BVH.BoundingBoxMin);
                                                bgeom.BVH.BoundingBoxCenter = new Vector4(bgeomBBC + moveVec, bgeom.BVH.BoundingBoxCenter.W);
                                                bgeom.BVH.BoundingBoxMax    = new Vector4(bgeomBBMax + moveVec, bgeom.BVH.BoundingBoxMax.W);
                                                bgeom.BVH.BoundingBoxMin    = new Vector4(bgeomBBMin + moveVec, bgeom.BVH.BoundingBoxMin.W);
                                            }
                                            bgeom.CenterGeom = bgeom.CenterGeom + moveVec;
                                        }
                                    }
                                }
                            }
                            byte[] newData = ybn.Save();
                            if (filename.Contains(".rpf"))
                            {
                                if (File.Exists(filename))
                                {
                                    RPFFilesDirectory = null;
                                    oldData           = File.ReadAllBytes(filename);
                                }
                                else
                                {
                                    RPFFunctions.AddFileBackToRPF(RPFFilesDirectory, filename, newData);
                                }
                            }
                            else
                            {
                                File.WriteAllBytes(filename, newData);
                            }
                        }
                        catch (Exception)
                        {
                            errorFiles.Add(filename);
                        }
                    }
                    else if (filename.EndsWith(".ymap"))
                    {
                        YmapFile ymap = new YmapFile();
                        RpfDirectoryEntry RPFFilesDirectory;
                        byte[] oldData;
                        if (filename.Contains(".rpf"))
                        {
                            string fileDirectory = StringFunctions.TopMostRPF(filename);
                            if (File.Exists(filename))
                            {
                                RPFFilesDirectory = null;
                                oldData           = File.ReadAllBytes(filename);
                            }
                            else
                            {
                                RpfFile TopRPF = new RpfFile(fileDirectory, fileDirectory);
                                TopRPF.ScanStructure(null, null);
                                (RPFFilesDirectory, oldData) = RPFFunctions.GetFileData(TopRPF, Path.GetFileName(filename));
                            }
                        }
                        else
                        {
                            RPFFilesDirectory = null;
                            oldData           = File.ReadAllBytes(filename);
                        }

                        try
                        {
                            ymap.Load(oldData);
                            if (ymap.CarGenerators != null)
                            {
                                foreach (YmapCarGen yEnts in ymap.CarGenerators)
                                {
                                    yEnts.SetPosition(yEnts.Position + moveVec);
                                    //yEnts.Orientation = Quaternion.Add(yEnts.Orientation, rotVec);
                                }
                            }
                            if (ymap.AllEntities != null)
                            {
                                foreach (YmapEntityDef yEnts in ymap.AllEntities)
                                {
                                    yEnts.SetPosition(yEnts.Position + moveVec);
                                    //yEnts.Orientation = Quaternion.Add(yEnts.Orientation, rotVec);
                                }
                            }
                            if (ymap.DistantLODLights != null)
                            {
                                int lightCount = ymap._CMapData.DistantLODLightsSOA.position.Count1;
                                for (int i = 0; i < lightCount; i++)
                                {
                                    Vector3 vector3     = ymap.DistantLODLights.positions[i].ToVector3() + moveVec;
                                    MetaVECTOR3 metaVec = new MetaVECTOR3 {
                                        x = vector3.X, y = vector3.Y, z = vector3.Z
                                    };
                                    ymap.DistantLODLights.positions[i] = metaVec;
                                }
                            }
                            if (ymap.GrassInstanceBatches != null)
                            {
                                foreach (YmapGrassInstanceBatch yEnts in ymap.GrassInstanceBatches)
                                {
                                    yEnts.Position += moveVec;
                                    yEnts.AABBMin  += moveVec;
                                    yEnts.AABBMax  += moveVec;
                                }
                            }

                            ymap._CMapData.streamingExtentsMax = ymap.CMapData.streamingExtentsMax + moveVec;
                            ymap._CMapData.streamingExtentsMin = ymap.CMapData.streamingExtentsMin + moveVec;
                            ymap._CMapData.entitiesExtentsMax  = ymap.CMapData.entitiesExtentsMax + moveVec;
                            ymap._CMapData.entitiesExtentsMin  = ymap.CMapData.entitiesExtentsMin + moveVec;

                            byte[] newData = ymap.Save();
                            if (filename.Contains(".rpf"))
                            {
                                if (File.Exists(filename))
                                {
                                    RPFFilesDirectory = null;
                                    oldData           = File.ReadAllBytes(filename);
                                }
                                else
                                {
                                    RPFFunctions.AddFileBackToRPF(RPFFilesDirectory, filename, newData);
                                }
                            }
                            else
                            {
                                File.WriteAllBytes(filename, newData);
                            }
                        }
                        catch (Exception)
                        {
                            errorFiles.Add(filename);
                        }
                    }
                }
                if (errorFiles.Count != 0)
                {
                    string message = "The following file(s) were corrupted and were not edited.\n\n";
                    foreach (string item in errorFiles)
                    {
                        message = message + item + "\n";
                    }

                    MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                FilesAddedLabel.Text = "Complete";
                cancelButton.Enabled = false;
                watch.Dispose();
                //}
            }).Start();
        }
Ejemplo n.º 10
0
        static void HandleGenColOptions(string[] args)
        {
            CommandLine.Parse <GenColOptions>(args, (opts, gOpts) =>
            {
                if (opts.InputFile == null)
                {
                    Console.WriteLine("Please provide input file with -i --input");
                    return;
                }

                if (opts.OutputFile == null)
                {
                    Console.WriteLine("Please provide output file with -o --output");
                    return;
                }

                var inputFileInfos  = new FileInfo(opts.InputFile);
                var outputFileInfos = new FileInfo(opts.OutputFile);

                if (!inputFileInfos.Exists)
                {
                    Console.WriteLine("Input file does not exists");
                    return;
                }

                if (inputFileInfos.Extension == ".ydr")
                {
                    var ydr = new YdrFile();

                    ydr.Load(inputFileInfos.FullName);

                    var modelData  = GenCol_GetModelData(ydr.Drawable.DrawableModelsX);
                    var bComposite = GenCol_CreateBoundComposite(modelData);

                    DMesh3 mesh;

                    if (opts.Mode == "copy")
                    {
                        mesh = new DMesh3();

                        var triangles = new List <DefaultConvexFace <VertexVector3> >();

                        for (int g = 0; g < modelData.Geometries.Count; g++)
                        {
                            var mGeometry = modelData.Geometries[g];

                            for (int i = 0; i < mGeometry.Indices.Count - 2; i += 3)
                            {
                                var vert1 = mGeometry.Vertices[mGeometry.Indices[i + 0]];
                                var vert2 = mGeometry.Vertices[mGeometry.Indices[i + 1]];
                                var vert3 = mGeometry.Vertices[mGeometry.Indices[i + 2]];

                                var triangle = new DefaultConvexFace <VertexVector3>()
                                {
                                    Vertices = new VertexVector3[]
                                    {
                                        vert1,
                                        vert2,
                                        vert3,
                                    }
                                };

                                triangles.Add(triangle);
                            }
                        }

                        mesh = GenCol_CreateMesh(triangles);
                    }
                    else
                    {
                        var hull          = ConvexHull.Create(modelData.Vertices);
                        var hullTriangles = hull.Result.Faces.ToList();

                        mesh = GenCol_CreateMesh(hullTriangles);
                    }

                    GenCol_Reshape(mesh, opts.Smooth, opts.TriangleCount);

                    mesh = GenCol_CleanVertices(mesh);

                    var quantum = (modelData.BbMax - modelData.BbMin) / (2 ^ opts.Qantum);

                    var bGeometry = new BoundGeometry
                    {
                        Type                   = 4,
                        Vertices               = new ResourceSimpleArray <BoundVertex>(),
                        BoundingBoxCenter      = (RAGE_Vector3)modelData.BsCenter,
                        BoundingSphereRadius   = modelData.BsRadius,
                        BoundingBoxMin         = (RAGE_Vector3)modelData.BbMin,
                        BoundingBoxMax         = (RAGE_Vector3)modelData.BbMax,
                        CenterGravity          = new RAGE_Vector3(0.0f, 0.0f, 0.0f),
                        CenterGeometry         = new RAGE_Vector3(0.0f, 0.0f, 0.0f),
                        Margin                 = 0.04f,
                        Quantum                = new RAGE_Vector3(quantum.X, quantum.Y, quantum.Z),
                        Polygons               = new ResourceSimpleArray <BoundPolygon>(),
                        Materials              = new ResourceSimpleArray <BoundMaterial>(),
                        MaterialColours        = new ResourceSimpleArray <uint_r>(),
                        PolygonMaterialIndices = new ResourceSimpleArray <byte_r>(),
                        Unknown_78h_Data       = new ResourceSimpleArray <BoundVertex>(),
                    };

                    var material = new BoundMaterial();

                    bGeometry.Materials.Add(material);

                    var matColour = new uint_r {
                        Value = 0
                    };

                    bGeometry.MaterialColours.Add(matColour);

                    var meshVertices = mesh.Vertices().ToList();

                    for (int i = 0; i < meshVertices.Count; i++)
                    {
                        var vertex  = meshVertices[i];
                        var bVertex = new BoundVertex
                        {
                            X = Convert.ToInt16(vertex.x / quantum.X),
                            Y = Convert.ToInt16(vertex.y / quantum.Y),
                            Z = Convert.ToInt16(vertex.z / quantum.Z),
                        };

                        bGeometry.Vertices.Add(bVertex);
                        bGeometry.Unknown_78h_Data.Add(bVertex);
                    }

                    var meshTriangles = mesh.Triangles().ToList();

                    for (int i = 0; i < meshTriangles.Count; i++)
                    {
                        var polygon  = new BoundPolygon();
                        var triangle = new BoundPolygonTriangle();

                        triangle.TriArea = 0.0f;

                        int vidx1 = meshTriangles[i].a;
                        int vidx2 = meshTriangles[i].b;
                        int vidx3 = meshTriangles[i].c;

                        if (vidx1 == -1 || vidx2 == -1 || vidx3 == -1)
                        {
                            continue;
                        }

                        triangle.TriIndex1 = (ushort)((triangle.TriIndex1 & ~0x7FFF) | (vidx1 & 0x7FFF));
                        triangle.TriIndex2 = (ushort)((triangle.TriIndex2 & ~0x7FFF) | (vidx2 & 0x7FFF));
                        triangle.TriIndex3 = (ushort)((triangle.TriIndex3 & ~0x7FFF) | (vidx3 & 0x7FFF));

                        triangle.EdgeIndex1 = 0;
                        triangle.EdgeIndex2 = 1;
                        triangle.EdgeIndex3 = 2;

                        polygon.data = new byte[16];

                        int offset = 0;

                        byte[] bytes = BitConverter.GetBytes(triangle.TriArea);
                        Buffer.BlockCopy(bytes, 0, polygon.data, offset, bytes.Length);
                        offset += bytes.Length;

                        bytes = BitConverter.GetBytes(triangle.TriIndex1);
                        Buffer.BlockCopy(bytes, 0, polygon.data, offset, bytes.Length);
                        offset += bytes.Length;

                        bytes = BitConverter.GetBytes(triangle.TriIndex2);
                        Buffer.BlockCopy(bytes, 0, polygon.data, offset, bytes.Length);
                        offset += bytes.Length;

                        bytes = BitConverter.GetBytes(triangle.TriIndex3);
                        Buffer.BlockCopy(bytes, 0, polygon.data, offset, bytes.Length);
                        offset += bytes.Length;

                        bytes = BitConverter.GetBytes(triangle.EdgeIndex1);
                        Buffer.BlockCopy(bytes, 0, polygon.data, offset, bytes.Length);
                        offset += bytes.Length;

                        bytes = BitConverter.GetBytes(triangle.EdgeIndex2);
                        Buffer.BlockCopy(bytes, 0, polygon.data, offset, bytes.Length);
                        offset += bytes.Length;

                        bytes = BitConverter.GetBytes(triangle.EdgeIndex3);
                        Buffer.BlockCopy(bytes, 0, polygon.data, offset, bytes.Length);
                        offset += bytes.Length;

                        bGeometry.Polygons.Add(polygon);

                        var matIndex = new byte_r {
                            Value = 0
                        };

                        bGeometry.PolygonMaterialIndices.Add(matIndex);
                    }

                    bComposite.Children.Add(bGeometry);

                    if (outputFileInfos.Extension == ".ybn")
                    {
                        var ybn = new YbnFile
                        {
                            Bound = bComposite
                        };

                        ybn.Save(opts.OutputFile);
                    }
                    else if (outputFileInfos.Extension == ".ydr")
                    {
                        ydr.Drawable.Bound = bComposite;
                        ydr.Save(opts.OutputFile);
                    }
                    else
                    {
                        Console.WriteLine("Output file type not valid");
                    }
                }
                else
                {
                    Console.WriteLine("Input file type not valid");
                }
            });
        }