Esempio n. 1
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            if (AllList.SelectedItem == null)
            {
                return;
            }
            string name = (string)AllList.SelectedItem;

            var fwav = new FWAV();

            fwav.Name           = name;
            fwav.ChunkParent    = SourceIff;
            fwav.ChunkProcessed = true;

            Content.Content.Get().Changes.BlockingResMod(new ResAction(() =>
            {
                ushort resultID = 0;
                for (ushort i = 1; i < ushort.MaxValue; i++)
                {
                    if (!FWAVTable.Any(x => x.ChunkID == i))
                    {
                        resultID = i;
                        break;
                    }
                }
                fwav.ChunkID    = resultID;
                fwav.ChunkLabel = "";

                SourceIff.AddChunk(fwav);
                fwav.AddedByPatch = true;
                fwav.RuntimeInfo  = ChunkRuntimeState.Modified;
            }, fwav));
            RefreshAnimTable();
        }
Esempio n. 2
0
        public void Save()
        {
            //save the house first
            var iff = new IffFile();

            vm.TS1State.UpdateSIMI(vm);
            var marshal = vm.Save();
            var fsov    = new FSOV();

            fsov.ChunkLabel     = "Simitone Lot Data";
            fsov.ChunkID        = 1;
            fsov.ChunkProcessed = true;
            fsov.ChunkType      = "FSOV";
            fsov.AddedByPatch   = true;

            using (var stream = new MemoryStream())
            {
                marshal.SerializeInto(new BinaryWriter(stream));
                fsov.Data = stream.ToArray();
            }

            iff.AddChunk(fsov);

            var simi = vm.TS1State.SimulationInfo;

            simi.ChunkProcessed = true;
            simi.AddedByPatch   = true;
            iff.AddChunk(simi);

            Texture2D roofless = null;
            var       thumb    = World.GetLotThumb(GameFacade.GraphicsDevice, (tex) => roofless = FSO.Common.Utils.TextureUtils.Decimate(tex, GameFacade.GraphicsDevice, 2, false));

            thumb = FSO.Common.Utils.TextureUtils.Decimate(thumb, GameFacade.GraphicsDevice, 2, false);

            var tPNG = GeneratePNG(thumb);

            tPNG.ChunkID = 513;
            iff.AddChunk(tPNG);

            var rPNG = GeneratePNG(roofless);

            rPNG.ChunkID = 512;
            iff.AddChunk(rPNG);

            Content.Get().Neighborhood.SaveHouse(vm.GetGlobalValue(10), iff);
            Content.Get().Neighborhood.SaveNeighbourhood(true);
        }
Esempio n. 3
0
        private void OKButton_Click(object sender, EventArgs e)
        {
            var  name  = ChunkLabelEntry.Text;
            var  guidT = GUIDEntry.Text;
            uint guid;
            var  objProvider = Content.Content.Get().WorldObjects;

            if (name == "")
            {
                MessageBox.Show("Name cannot be empty!", "Invalid Object Name");
            }
            else if (guidT == "")
            {
                MessageBox.Show("GUID cannot be empty!", "Invalid GUID");
            }
            else if (!uint.TryParse(guidT, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out guid))
            {
                MessageBox.Show("GUID is invalid! Make sure it is a hex string of size 8. (eg. 6789ABCD)", "Invalid GUID");
            }
            else
            {
                lock (objProvider.Entries)
                {
                    if (objProvider.Entries.ContainsKey(guid))
                    {
                        MessageBox.Show("This GUID is already being used!", "GUID is Taken!");
                        return;
                    }

                    //OK, it's valid. Now to add it to the objects system...
                    //This is a little tricky because we want to add an object that does not exist yet.
                    //There's a special function just for this! But first, we need an OBJD...

                    var obj = new OBJD()
                    {
                        GUID             = guid,
                        ObjectType       = OBJDType.Normal,
                        ChunkLabel       = name,
                        ChunkID          = 1,
                        ChunkProcessed   = true,
                        ChunkType        = "OBJD",
                        ChunkParent      = TargetIff,
                        AnimationTableID = 128,
                        AddedByPatch     = true
                    };

                    Content.Content.Get().Changes.BlockingResMod(new ResAction(() =>
                    {
                        //find a free space to place the object
                        ushort id = 16807; //todo: why???
                        var list  = TargetIff.List <OBJD>();
                        if (list != null)
                        {
                            foreach (var chk in list.OrderBy(x => x.ChunkID))
                            {
                                if (chk.ChunkID == id)
                                {
                                    id++;
                                }
                            }
                        }
                        obj.ChunkID = id;
                        //add it to the iff file
                        TargetIff.AddChunk(obj);
                    }, obj));

                    if (IsNew)
                    {
                        //add a default animation table, for quality of life reasons

                        var anim = new STR()
                        {
                            ChunkLabel     = name,
                            ChunkID        = 128,
                            ChunkProcessed = true,
                            ChunkType      = "STR#",
                            ChunkParent    = TargetIff,
                        };

                        anim.InsertString(0, new STRItem {
                            Value = "", Comment = ""
                        });
                        TargetIff.AddChunk(anim);

                        var filename = TargetIff.RuntimeInfo.Path;
                        Directory.CreateDirectory(Path.GetDirectoryName(filename));
                        using (var stream = new FileStream(filename, FileMode.Create))
                            TargetIff.Write(stream);
                    }

                    //add it to the provider
                    objProvider.AddObject(TargetIff, obj);

                    DialogResult = DialogResult.OK;
                    ResultGUID   = guid;
                    Close();
                }
            }
        }
        public static IffFile GeneratePiff(IffFile iff, HashSet <Type> allowedTypes, HashSet <Type> disallowedTypes)
        {
            var piffFile = new IffFile();

            var piff = new PIFF();

            piff.SourceIff = iff.Filename;
            var entries = new List <PIFFEntry>();
            var chunks  = iff.ListAll();

            //write removals first
            foreach (var c in iff.RemovedOriginal)
            {
                lock (c)
                {
                    if ((allowedTypes == null || allowedTypes.Contains(c.GetType())) &&
                        (disallowedTypes == null || !disallowedTypes.Contains(c.GetType())))
                    {
                        entries.Add(new PIFFEntry {
                            Type       = c.ChunkType, ChunkID = c.OriginalID, Delete = true,
                            ChunkLabel = c.ChunkLabel, ChunkFlags = c.ChunkFlags
                        });
                    }
                }
            }

            foreach (var c in chunks)
            {
                lock (c)
                {
                    if ((allowedTypes == null || allowedTypes.Contains(c.GetType())) &&
                        (disallowedTypes == null || !disallowedTypes.Contains(c.GetType())))
                    {
                        if (c.AddedByPatch)
                        {
                            //this chunk has been newly added.
                            var oldParent = c.ChunkParent;
                            piffFile.AddChunk(c);
                            c.ChunkParent = oldParent;
                        }
                        else if ((c.RuntimeInfo == ChunkRuntimeState.Modified || c.RuntimeInfo == ChunkRuntimeState.Patched))
                        {
                            var chunkD = MakeChunkDiff(c);
                            if (chunkD != null && (chunkD.Patches.Length > 0 || c.OriginalLabel != c.ChunkLabel || c.OriginalID != c.ChunkID))
                            {
                                entries.Add(chunkD);
                            }
                            c.RuntimeInfo = ChunkRuntimeState.Patched;
                        }
                    }
                }
            }
            if (entries.Count == 0)
            {
                return(null);                    //no patch data...
            }
            piff.Entries        = entries.ToArray();
            piff.ChunkID        = 256;
            piff.ChunkLabel     = (piff.SourceIff + " patch");
            piff.ChunkProcessed = true;

            piffFile.AddChunk(piff);
            piffFile.Filename = piff.SourceIff.Substring(0, piff.SourceIff.Length - 4) + ".piff";
            return(piffFile);
        }
Esempio n. 5
0
        public static IffFile GeneratePiff(IffFile iff, HashSet<Type> allowedTypes, HashSet<Type> disallowedTypes)
        {
            var piffFile = new IffFile();

            var piff = new PIFF();
            piff.SourceIff = iff.Filename;
            var entries = new List<PIFFEntry>();
            var chunks = iff.ListAll();

            //write removals first
            foreach (var c in iff.RemovedOriginal)
            {
                lock (c)
                {
                    if ((allowedTypes == null || allowedTypes.Contains(c.GetType()))
                        && (disallowedTypes == null || !disallowedTypes.Contains(c.GetType())))
                    {
                        entries.Add(new PIFFEntry {
                            Type = c.ChunkType, ChunkID = c.OriginalID, Delete = true,
                            ChunkLabel = c.ChunkLabel, ChunkFlags = c.ChunkFlags
                        });
                    }
                }
            }

            foreach (var c in chunks)
            {
                lock (c)
                {
                    if ((allowedTypes == null || allowedTypes.Contains(c.GetType()))
                        && (disallowedTypes == null || !disallowedTypes.Contains(c.GetType())))
                    {
                        if (c.AddedByPatch)
                        {
                            //this chunk has been newly added.
                            var oldParent = c.ChunkParent;
                            piffFile.AddChunk(c);
                            c.ChunkParent = oldParent;
                        }
                        else if ((c.RuntimeInfo == ChunkRuntimeState.Modified || c.RuntimeInfo == ChunkRuntimeState.Patched))
                        {
                            var chunkD = MakeChunkDiff(c);
                            if (chunkD != null && (chunkD.Patches.Length > 0 || c.OriginalLabel != c.ChunkLabel || c.OriginalID != c.ChunkID))
                            {
                                entries.Add(chunkD);
                            }
                            c.RuntimeInfo = ChunkRuntimeState.Patched;
                        }
                    }
                }
            }
            if (entries.Count == 0) return null; //no patch data...
            piff.Entries = entries.ToArray();
            piff.ChunkID = 256;
            piff.ChunkLabel = (piff.SourceIff + " patch");
            piff.ChunkProcessed = true;

            piffFile.AddChunk(piff);
            piffFile.Filename = piff.SourceIff.Substring(0, piff.SourceIff.Length - 4)+".piff";
            return piffFile;
        }
Esempio n. 6
0
        public static IffFile GeneratePiff(IffFile iff, HashSet <Type> allowedTypes, HashSet <Type> disallowedTypes, PIFF oldPIFF)
        {
            var piffFile = new IffFile();

            var piff = new PIFF();

            piff.SourceIff = iff.Filename;
            if (oldPIFF != null)
            {
                piff.Comment = oldPIFF.Comment;
            }
            var entries = new List <PIFFEntry>();
            var chunks  = iff.ListAll();

            //write removals first
            foreach (var c in iff.RemovedOriginal)
            {
                lock (c)
                {
                    if ((allowedTypes == null || allowedTypes.Contains(c.GetType())) &&
                        (disallowedTypes == null || !disallowedTypes.Contains(c.GetType())))
                    {
                        entries.Add(new PIFFEntry {
                            Type       = c.ChunkType, ChunkID = c.OriginalID, EntryType = PIFFEntryType.Remove,
                            ChunkLabel = c.ChunkLabel, ChunkFlags = c.ChunkFlags, Comment = FindComment(c, oldPIFF)
                        });
                    }
                }
            }

            bool anyAdded = false;

            foreach (var c in chunks)
            {
                //find a comment for this chunk
                lock (c)
                {
                    if ((allowedTypes == null || allowedTypes.Contains(c.GetType())) &&
                        (disallowedTypes == null || !disallowedTypes.Contains(c.GetType())))
                    {
                        if (c.AddedByPatch)
                        {
                            //this chunk has been newly added.
                            var oldParent = c.ChunkParent;
                            anyAdded = true;
                            piffFile.AddChunk(c);
                            c.ChunkParent = oldParent;

                            //make an entry for it!
                            entries.Add(new PIFFEntry()
                            {
                                ChunkID     = c.ChunkID,
                                ChunkLabel  = c.ChunkLabel,
                                ChunkFlags  = c.ChunkFlags,
                                EntryType   = PIFFEntryType.Add,
                                NewDataSize = (uint)(c.ChunkData?.Length ?? 0),
                                Type        = c.ChunkType,
                                Comment     = FindComment(c, oldPIFF)
                            });
                        }
                        else if ((c.RuntimeInfo == ChunkRuntimeState.Modified || c.RuntimeInfo == ChunkRuntimeState.Patched))
                        {
                            var chunkD = MakeChunkDiff(c);
                            if (chunkD != null && (chunkD.Patches.Length > 0 || c.OriginalLabel != c.ChunkLabel || c.OriginalID != c.ChunkID))
                            {
                                chunkD.Comment = FindComment(c, oldPIFF);
                                entries.Add(chunkD);
                            }
                            c.RuntimeInfo = ChunkRuntimeState.Patched;
                        }
                    }
                }
            }
            if (entries.Count == 0 && !anyAdded)
            {
                return(null);                                 //no patch data...
            }
            piff.Entries        = entries.ToArray();
            piff.ChunkID        = 256;
            piff.ChunkLabel     = (piff.SourceIff + " patch");
            piff.ChunkProcessed = true;

            piffFile.AddChunk(piff);
            piffFile.Filename = (oldPIFF != null) ? oldPIFF.ChunkParent.Filename : null; // (piff.SourceIff.Substring(0, piff.SourceIff.Length - 4)+".piff")
            return(piffFile);
        }