Пример #1
0
        private static void RemoveUnnecessaryColors(ISerializableFile file)
        {
            return;

            for (int section = 0; section < file.NumberOfSections; section++)
            {
                for (int entry = 0; entry < file.SectionLengths[section]; entry++)
                {
                    string     mystring        = file[section, entry];
                    var        allIndices      = IndexOfEvery(mystring, "{Color ");
                    List <int> indicesToRemove = new List <int>();
                    for (int i = 0; i < allIndices.Count - 1; i++)
                    {
                        string firstByte  = mystring.Substring(allIndices[i] + 7, 2);
                        string secondByte = mystring.Substring(allIndices[i + 1] + 7, 2);
                        if (firstByte == secondByte)
                        {
                            indicesToRemove.Add(allIndices[i + 1]);
                        }
                    }

                    indicesToRemove.Reverse();
                    foreach (int i in indicesToRemove)
                    {
                        mystring = mystring.Remove(i, 10);
                    }

                    file[section, entry] = mystring;
                }
            }
        }
Пример #2
0
        public QuickEdit(PatcherLib.Datatypes.Context context, IDictionary <Guid, ISerializableFile> files, IDictionary <SectionType, IList <QuickEditEntry> > sections)
        {
            Context    = context;
            this.files = new Dictionary <Guid, ISerializableFile>(files);
            lookup     = new Dictionary <SectionType, IList <QuickEditEntry> >(sections);

            List <IList <string> > sections2      = new List <IList <string> >(sections.Count);
            List <IList <string> > entryNames     = new List <IList <string> >(sections.Count);
            List <SectionType>     sectionTypes   = new List <SectionType>(sections.Count);
            List <int>             sectionLengths = new List <int>(sections.Count);
            List <string>          sectionNames   = new List <string>();

            HiddenEntries = new bool[sections.Count].AsReadOnly();

            foreach (KeyValuePair <SectionType, IList <QuickEditEntry> > kvp in sections)
            {
                CharMap = CharMap ?? files[kvp.Value[0].Guid].CharMap;

                IList <QuickEditEntry> entries   = kvp.Value;
                QuickEditEntry         mainEntry = entries.FindAll(e => e.Main)[0];

                //ISerializableFile mainFile = files[mainEntry.Guid];
                ISerializableFile mainFile = null;
                files.TryGetValue(mainEntry.Guid, out mainFile);
                if (mainFile == null)
                {
                    continue;
                }

                int           entryCount = mainEntry.Length;
                List <string> names      = new List <string>(entryCount);
                List <string> values     = new List <string>(entryCount);
                for (int i = mainEntry.Offset; i < (mainEntry.Offset + entryCount); i++)
                {
                    names.Add(mainFile.EntryNames[mainEntry.Section][i]);
                    values.Add(mainFile[mainEntry.Section, i]);
                }
                entryNames.Add(names.AsReadOnly());
                sections2.Add(values.ToArray());
                sectionLengths.Add(entryCount);
                sectionTypes.Add(kvp.Key);
                sectionNames.Add(FormatName(kvp.Key.ToString()));
            }

            this.sections       = sections2.AsReadOnly();
            EntryNames          = entryNames.AsReadOnly();
            NumberOfSections    = sections.Count;
            this.sectionTypes   = sectionTypes.AsReadOnly();
            this.SectionNames   = sectionNames.AsReadOnly();
            this.SectionLengths = sectionLengths.AsReadOnly();
        }
Пример #3
0
        public QuickEdit(IDictionary <Guid, ISerializableFile> files, IDictionary <SectionType, IList <QuickEditEntry> > sections)
        {
            this.files = new Dictionary <Guid, ISerializableFile>(files);
            lookup     = new Dictionary <SectionType, IList <QuickEditEntry> >(sections);

            List <IList <string> > sections2      = new List <IList <string> >(sections.Count);
            List <IList <string> > entryNames     = new List <IList <string> >(sections.Count);
            List <SectionType>     sectionTypes   = new List <SectionType>(sections.Count);
            List <int>             sectionLengths = new List <int>(sections.Count);
            List <string>          sectionNames   = new List <string>();

            foreach (KeyValuePair <SectionType, IList <QuickEditEntry> > kvp in sections)
            {
                CharMap = CharMap ?? files[kvp.Value[0].Guid].CharMap;

                IList <QuickEditEntry> entries   = kvp.Value;
                QuickEditEntry         mainEntry = entries.FindAll(e => e.Main)[0];
                ISerializableFile      mainFile  = files[mainEntry.Guid];
                int           entryCount         = mainEntry.Length;
                List <string> names  = new List <string>(entryCount);
                List <string> values = new List <string>(entryCount);
                for (int i = mainEntry.Offset; i < (mainEntry.Offset + entryCount); i++)
                {
                    names.Add(mainFile.EntryNames[mainEntry.Section][i]);
                    values.Add(mainFile[mainEntry.Section, i]);
                }
                entryNames.Add(names.AsReadOnly());
                sections2.Add(values.ToArray());
                sectionLengths.Add(entryCount);
                sectionTypes.Add(kvp.Key);
                sectionNames.Add(kvp.Key.ToString());
            }

            this.sections       = sections2.AsReadOnly();
            EntryNames          = entryNames.AsReadOnly();
            NumberOfSections    = sections.Count;
            this.sectionTypes   = sectionTypes.AsReadOnly();
            this.SectionNames   = sectionNames.AsReadOnly();
            this.SectionLengths = sectionLengths.AsReadOnly();
        }
Пример #4
0
        private static void WriteFileXml(ISerializableFile file, XmlWriter writer)
        {
            writer.WriteStartElement("File");
            writer.WriteElementString("Guid", file.Layout.Guid.ToString("B").ToUpper());
            writer.WriteStartElement("Sections");
            int numSections = file.NumberOfSections;

            for (int i = 0; i < numSections; i++)
            {
                writer.WriteStartElement("Section");
                int length = file.SectionLengths[i];
                for (int j = 0; j < length; j++)
                {
                    writer.WriteElementString("Entry", file[i, j]);
                }

                writer.WriteEndElement(); // Section
            }

            writer.WriteEndElement(); // Sections
            writer.WriteEndElement(); // File
        }
Пример #5
0
        private static void WriteFileXml(ISerializableFile file, XmlWriter writer)
        {
            writer.WriteStartElement("File");
            writer.WriteComment("DisplayName: " + file.DisplayName);
            writer.WriteElementString("Guid", file.Layout.Guid.ToString("B").ToUpper());
            if (!string.IsNullOrEmpty(file.FileComments))
            {
                writer.WriteElementString("Comment", file.FileComments);
            }

            writer.WriteStartElement("Sections");
            int numSections = file.NumberOfSections;

            for (int i = 0; i < numSections; i++)
            {
                writer.WriteStartElement("Section");
                if (!string.IsNullOrEmpty(file.SectionNames[i]))
                {
                    writer.WriteComment(file.SectionNames[i]);
                }
                if (file.SectionComments != null && file.SectionComments.Count > i && !string.IsNullOrEmpty(file.SectionComments[i]))
                {
                    writer.WriteElementString("Comment", file.SectionComments[i]);
                }

                int length = file.SectionLengths[i];
                for (int j = 0; j < length; j++)
                {
                    writer.WriteElementString("Entry", file[i, j]);
                }

                writer.WriteEndElement(); // Section
            }

            writer.WriteEndElement(); // Sections
            writer.WriteEndElement(); // File
        }
Пример #6
0
        private static void WriteFileXml( ISerializableFile file, XmlWriter writer )
        {
            writer.WriteStartElement( "File" );
            writer.WriteElementString( "Guid", file.Layout.Guid.ToString( "B" ).ToUpper() );
            writer.WriteStartElement( "Sections" );
            int numSections = file.NumberOfSections;
            for ( int i = 0; i < numSections; i++ )
            {
                writer.WriteStartElement( "Section" );
                int length = file.SectionLengths[i];
                for ( int j = 0; j < length; j++ )
                {
                    writer.WriteElementString( "Entry", file[i, j] );
                }

                writer.WriteEndElement(); // Section
            }

            writer.WriteEndElement(); // Sections
            writer.WriteEndElement(); // File
        }
Пример #7
0
        private static void WriteFileXml( ISerializableFile file, XmlWriter writer )
        {
            writer.WriteStartElement( "File" );
            writer.WriteComment( "DisplayName: " + file.DisplayName );
            writer.WriteElementString( "Guid", file.Layout.Guid.ToString( "B" ).ToUpper() );
            if (!string.IsNullOrEmpty(file.FileComments))
                writer.WriteElementString( "Comment", file.FileComments );

            writer.WriteStartElement( "Sections" );
            int numSections = file.NumberOfSections;
            for (int i = 0; i < numSections; i++)
            {
                writer.WriteStartElement( "Section" );
                if (!string.IsNullOrEmpty( file.SectionNames[i] )) writer.WriteComment( file.SectionNames[i] );
                if (file.SectionComments != null && file.SectionComments.Count > i && !string.IsNullOrEmpty( file.SectionComments[i] ))
                    writer.WriteElementString( "Comment", file.SectionComments[i] );

                int length = file.SectionLengths[i];
                for (int j = 0; j < length; j++)
                {
                    writer.WriteElementString( "Entry", file[i, j] );
                }

                writer.WriteEndElement(); // Section
            }

            writer.WriteEndElement(); // Sections
            writer.WriteEndElement(); // File
        }
Пример #8
0
        private static void RemoveUnnecessaryColors( ISerializableFile file )
        {
            return;
            for (int section = 0; section < file.NumberOfSections; section++)
            {
                for (int entry = 0; entry < file.SectionLengths[section]; entry++)
                {
                    string mystring = file[section, entry];
                    var allIndices = IndexOfEvery( mystring, "{Color " );
                    List<int> indicesToRemove = new List<int>();
                    for (int i = 0; i < allIndices.Count - 1; i++)
                    {
                        string firstByte = mystring.Substring( allIndices[i] + 7, 2 );
                        string secondByte = mystring.Substring( allIndices[i+1] + 7, 2 );
                        if (firstByte == secondByte)
                        {
                            indicesToRemove.Add( allIndices[i + 1] );
                        }
                    }

                    indicesToRemove.Reverse();
                    foreach (int i in indicesToRemove)
                    {
                        mystring = mystring.Remove( i, 10 );
                    }

                    file[section, entry] = mystring;
                }
            }
        }