Ejemplo n.º 1
0
        private int TagGroup_CalculateChecksum(ITagGroup tagGroup)
        {
            int checksum = 0;

            using (VirtualStream tagStream = new VirtualStream(TagGroupHeader.Size))
                using (BinaryWriter writer = new BinaryWriter(tagStream))
                {
                    tagGroup.Write(writer);
                    tagStream.Align(4);

                    if (tagStream.Length == 0)
                    {
                        return(0);
                    }

                    byte[] tagGroupBuffer = tagStream.ToArray();
                    checksum = BitConverter.ToInt32(tagGroupBuffer, 0);
                    for (int i = 1; i < tagGroupBuffer.Length / 4; i++)
                    {
                        checksum ^= BitConverter.ToInt32(tagGroupBuffer, i * 4);
                    }
                }

            return(checksum);
        }
Ejemplo n.º 2
0
        private void FixSystemLinkButton_Click(object sender, EventArgs e)
        {
            /*
             * Heh I guess Entity is good for something :P
             */

            //Prepare
            ITagGroup         tagGroup = null;
            ITagGroup         scenario = new Scenario();
            ITagBlock         scenarioBlock = null, simulationDefinitionTableElementBlock = null;
            BlockField        simulationDefinitionTableField = null;
            List <IndexEntry> simulationDefinitionEntries = new List <IndexEntry>();
            bool success = false;

            //Build table
            foreach (IndexEntry entry in Map.IndexEntries)
            {
                switch (entry.Root)
                {
                case "bipd":
                case "bloc":
                case "ctrl":
                case "jpt!":
                case "mach":
                case "scen":
                case "ssce":
                case "vehi":
                    simulationDefinitionEntries.Add(entry);
                    break;

                case "eqip":
                case "garb":
                case "proj":
                    simulationDefinitionEntries.Add(entry);
                    simulationDefinitionEntries.Add(entry);
                    break;

                case "weap":
                    simulationDefinitionEntries.Add(entry);
                    simulationDefinitionEntries.Add(entry);
                    simulationDefinitionEntries.Add(entry);
                    break;
                }
            }

            //Read scenario
            using (BinaryReader reader = Map.Scenario.TagData.CreateReader())
            {
                reader.BaseStream.Seek((uint)Map.Scenario.PostProcessedOffset, SeekOrigin.Begin);
                scenario.Read(reader);
            }

            //Re-create simulation definition table
            scenarioBlock = scenario[0];
            simulationDefinitionTableField = (BlockField)scenarioBlock[143];
            simulationDefinitionTableField.BlockList.Clear();
            foreach (IndexEntry entry in simulationDefinitionEntries)
            {
                //Attempt to add tag block
                simulationDefinitionTableElementBlock = simulationDefinitionTableField.Add(out success);
                if (success)
                {
                    simulationDefinitionTableElementBlock[0].Value = entry.Id;
                }
            }

            //Rebuild map
            using (VirtualStream tagDataStream = new VirtualStream(Map.TagDataStream.MemoryAddress))
                using (BinaryWriter writer = tagDataStream.CreateWriter())
                    using (BinaryReader reader = Map.TagDataStream.CreateReader())
                    {
                        //Loop
                        foreach (IndexEntry entry in Map.IndexEntries.Where(ie => ie.Offset > 0 && ie.Size > 0))
                        {
                            //Read (unless it's our modified scenario)
                            if (entry != Map.Scenario)
                            {
                                tagGroup = TagLookup.CreateTagGroup(entry.Root);
                                reader.BaseStream.Seek(entry.Offset, SeekOrigin.Begin);
                                tagGroup.Read(reader);
                            }
                            else
                            {
                                tagGroup = scenario;
                            }

                            //Create buffer
                            using (VirtualStream stream = new VirtualStream(tagDataStream.Position))
                                using (BinaryWriter tagWriter = stream.CreateWriter())
                                    using (BinaryReader tagReader = stream.CreateReader())
                                    {
                                        //Write
                                        tagGroup.Write(tagWriter);

                                        //Recalculate raw addresses
                                        Helper.RecalculateRawAddresses(entry.Raws, entry.Root, stream, tagReader, tagWriter);

                                        //Setup tag
                                        entry.Offset = (uint)stream.MemoryAddress;
                                        entry.Size   = (int)stream.Length;

                                        //Write to tag data stream
                                        writer.Write(stream.ToArray());
                                    }
                        }

                        //Align
                        tagDataStream.Align(4096);

                        //Swap
                        Map.SwapTagBuffer(tagDataStream.ToArray(), tagDataStream.MemoryAddress);
                    }
        }
Ejemplo n.º 3
0
        private void copyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Prepare
            TagClipboardHeader header = new TagClipboardHeader();

            //Initialize IO
            using (MemoryStream ms = new MemoryStream())
                using (BinaryWriter writer = new BinaryWriter(ms))
                {
                    //Check
                    if (tagStructureTreeView.SelectedNode.Tag is ITagBlock tagBlock)
                    {
                        //Setup header
                        header = new TagClipboardHeader
                        {
                            BlockCount = 1,
                            BlockName  = tagBlock.BlockName
                        };

                        //Write header
                        writer.Write(header);

                        //Write block
                        using (VirtualStream tagStream = new VirtualStream(ms.Position))
                            using (BinaryWriter tagWriter = new BinaryWriter(tagStream))
                            {
                                //Write
                                tagBlock.Write(tagWriter);

                                //Post write
                                tagBlock.PostWrite(tagWriter);

                                //Write tag buffer
                                writer.Write(tagStream.ToArray());
                            }

                        //Set
                        Clipboard.SetData(AbideClipboardTag, ms);
                    }
                    else if (tagStructureTreeView.SelectedNode.Tag is StructField structField && structField.Value is ITagBlock structBlock)
                    {
                        //Setup header
                        header = new TagClipboardHeader
                        {
                            BlockCount = 1,
                            BlockName  = structBlock.BlockName
                        };

                        //Write header
                        writer.Write(header);

                        //Write struct
                        using (VirtualStream tagStream = new VirtualStream(ms.Position))
                            using (BinaryWriter tagWriter = new BinaryWriter(tagStream))
                            {
                                //Write
                                structBlock.Write(tagWriter);

                                //Post write
                                structBlock.PostWrite(tagWriter);

                                //Write tag buffer
                                writer.Write(tagStream.ToArray());
                            }

                        //Set
                        Clipboard.SetData(AbideClipboardTag, ms);
                    }