private static IList<tag_field> ExtractFields(IEnumerable<tag_group> h2Tags, BinaryReader reader, tag_group tag)
 {
     reader.BaseStream.Position = tag.definition_address - Guerilla.BaseAddress;
     var definition = reader.ReadFieldDefinition<tag_block_definition>();
     tag_field_set field_set;
     return reader.ReadFieldSet(ref definition, out field_set);
 }
        private void ProcessTag(IEnumerable<tag_group> h2Tags, string folder, BinaryReader reader, XmlWriter writer, tag_group tag)
        {
            const int @null = -1;
            List<tag_field> fields = null;
            if (tag.parent_group_tag != @null)
            {
                fields = new List<tag_field>();
                var parent = h2Tags.Where(x => x.group_tag == tag.parent_group_tag).Single();
                if (parent.parent_group_tag != @null)
                {
                    var @base = h2Tags.Where(x => x.group_tag == parent.parent_group_tag).Single();
                    fields.AddRange(ExtractFields(h2Tags, reader, @base));
                }
                fields.AddRange(ExtractFields(h2Tags, reader, parent));
                fields.AddRange(ExtractFields(h2Tags, reader, tag));
            }

            // Process the tag_group definition.
            var fieldOffset = 0;
            ProcessTagBlockDefinition(tag.Definition, writer, tag.definition_address, ref fieldOffset, tag.Class.ToString(), "", root, false, fields);
            root = root ? false : false;

            writer.Flush();

            //File.WriteAllText(string.Format("{0}\\{1}.cs", folder, readTag.Name), writer.ToString());
            return;
        }
        private static string GetEntityCompatibleName(tag_group tag)
        {
            var outputName = tag.Class.ToString().Trim();

            Regex r = new Regex("[^a-zA-Z0-9!+++<> -]");
            outputName = r.Replace(outputName, "");
            outputName = outputName.Replace('<', '_');
            outputName = outputName.Replace('>', '_');
            outputName.Trim();
            return outputName;
        }
Exemplo n.º 4
0
        private static string GetEntityCompatibleName(tag_group tag)
        {
            var outputName = tag.Class.ToString().Trim();

            Regex r = new Regex("[^a-zA-Z0-9!+++<> -]");

            outputName = r.Replace(outputName, "");
            outputName = outputName.Replace('<', '_');
            outputName = outputName.Replace('>', '_');
            outputName.Trim();
            return(outputName);
        }
Exemplo n.º 5
0
        protected Guerilla(string guerillaExecutablePath)
        {
            // Open the guerilla executable.
            using (BinaryReader reader = new BinaryReader(new VirtualMemoryStream(guerillaExecutablePath, Guerilla.BaseAddress)))
            {
                Guerilla.h2Tags = new List <tag_group>(Guerilla.NumberOfTagLayouts);

                // Loop through all the tag layouts and extract each one.
                for (int i = 0; i < Guerilla.NumberOfTagLayouts; i++)
                {
                    // Go to the tag layout table.
                    reader.BaseStream.Position = Guerilla.TagLayoutTableAddress + (i * 4);

                    // Read the tag layout pointer.
                    int layoutAddress = reader.ReadInt32();

                    // Go to the tag layout and read it.
                    reader.BaseStream.Position = layoutAddress;
                    tag_group tag = new tag_group(reader);
                    h2Tags.Add(tag);
                }
            }
        }
Exemplo n.º 6
0
 public void Read(IntPtr h2LangLib, BinaryReader reader)
 {
     this = new tag_group(reader);
 }
Exemplo n.º 7
0
        public string Validate(tag_group validateTag, IEnumerable <tag_group> tagPool)
        {
            PointersList = new List <Tuple <BlamPointer, ElementArray> >();
            StreamWriter stringWriter = File.CreateText(string.Format(@"C:\Users\stem\Documents\h2pc to h2xbox\analysis\{0}.txt", validateTag.Class.ToSafeString()));

            WriteMessage = new Log(stringWriter.WriteLine);

            int          offset       = 0;
            ElementArray elementArray = null;

            if (validateTag.ParentClass != TagClass.Null)
            {
                var parentClass = tagPool.Where(x => x.Class == validateTag.ParentClass).Single();
                if (parentClass.ParentClass != TagClass.Null)
                {
                    var baseClass = tagPool.Where(x => x.Class == parentClass.ParentClass).Single();
                    elementArray = ProcessTagBlockDefinition(baseClass.Definition, ref offset, true);
                    elementArray.Append(ProcessTagBlockDefinition(parentClass.Definition, ref offset, true));
                    elementArray.Append(ProcessTagBlockDefinition(validateTag.Definition, ref offset, true));
                }
                else
                {
                    elementArray = ProcessTagBlockDefinition(parentClass.Definition, ref offset, true);
                    elementArray.Append(ProcessTagBlockDefinition(validateTag.Definition, ref offset, true));
                }
            }
            else
            {
                elementArray = ProcessTagBlockDefinition(validateTag.Definition, ref offset, true);
            }

            elementArray.Count = 1;

            var mapFiles = Directory.GetFiles(@"C:\Users\stem\Documents\modding\singleplayer", "*.map", SearchOption.TopDirectoryOnly)
                           .Concat(Directory.GetFiles(@"C:\Users\stem\Documents\modding\multiplayer", "*.map", SearchOption.TopDirectoryOnly))
                           .Concat(Directory.GetFiles(@"C:\Users\stem\Documents\modding\resource", "*.map", SearchOption.TopDirectoryOnly));

            foreach (var file in mapFiles)
            {
                using (var map = new MapStream(file))
                {
                    var binaryReader = new BinaryReader(map);

                    OnWriteMessage(string.Format("Begin ({0})", map.MapName));

                    foreach (var tag in map.Tags)
                    {
                        if (!(tag.Type == validateTag.Class))
                        {
                            continue;
                        }
                        else
                        {
                            VirtualMappedAddress metaTableMemory = new VirtualMappedAddress()
                            {
                                Address = map.Tags[0].VirtualAddress, Length = map.TagCacheLength
                            };
                            isValidDelegate = new Func <BlamPointer, bool>(metaTableMemory.Contains);
                            VirtualMappedAddress virtualTagMemory = new VirtualMappedAddress()
                            {
                                Address = tag.VirtualAddress, Length = tag.Length
                            };
                            IsPointerOwnedByTagDelegate = new Func <BlamPointer, bool>(virtualTagMemory.Contains);
                            OnWriteMessage(string.Format("Tag ({0})", tag.Path));
                            map[tag.Identifier].Seek();
                            offset = (int)map.Position;
                            elementArray.VirtualAddress = map[tag.Identifier].Meta.VirtualAddress;
                            PointersList = new List <Tuple <BlamPointer, ElementArray> >();
                            ValidateTagBlock(elementArray, elementArray.ToFixedArrayPointer(), binaryReader, ref offset);
                            AnalyzePointers(PointersList);
                            stringWriter.Flush();
                        }
                    }
                    Console.WriteLine(string.Format("Parsed ({0})", map.MapName));
                    //OnWriteMessage(string.Format("End ({0})", map.MapName));
                }
            }
            stringWriter.Close();
            return("");
        }
Exemplo n.º 8
0
        protected Guerilla(string guerillaExecutablePath)
        {
            // Open the guerilla executable.
            using (BinaryReader reader = new BinaryReader(new VirtualMemoryStream(guerillaExecutablePath, Guerilla.BaseAddress)))
            {
                Guerilla.h2Tags = new List<tag_group>(Guerilla.NumberOfTagLayouts);

                // Loop through all the tag layouts and extract each one.
                for (int i = 0; i < Guerilla.NumberOfTagLayouts; i++)
                {
                    // Go to the tag layout table.
                    reader.BaseStream.Position = Guerilla.TagLayoutTableAddress + (i * 4);

                    // Read the tag layout pointer.
                    int layoutAddress = reader.ReadInt32();

                    // Go to the tag layout and read it.
                    reader.BaseStream.Position = layoutAddress;
                    tag_group tag = new tag_group(reader);
                    h2Tags.Add(tag);
                }
            }
        }
Exemplo n.º 9
0
        public string Validate(tag_group validateTag, IEnumerable<tag_group> tagPool)
        {
            PointersList = new List<Tuple<BlamPointer, ElementArray>>();
            StreamWriter stringWriter = File.CreateText(string.Format(@"C:\Users\stem\Documents\h2pc to h2xbox\analysis\{0}.txt", validateTag.Class.ToSafeString()));
            WriteMessage = new Log(stringWriter.WriteLine);

            int offset = 0; 
            ElementArray elementArray = null;
            if (validateTag.ParentClass != TagClass.Null)
            {
                var parentClass = tagPool.Where(x => x.Class == validateTag.ParentClass).Single();
                if (parentClass.ParentClass != TagClass.Null)
                {
                    var baseClass = tagPool.Where(x => x.Class == parentClass.ParentClass).Single();
                    elementArray = ProcessTagBlockDefinition(baseClass.Definition, ref offset, true);
                    elementArray.Append(ProcessTagBlockDefinition(parentClass.Definition, ref offset, true));
                    elementArray.Append(ProcessTagBlockDefinition(validateTag.Definition, ref offset, true));
                }
                else
                {
                    elementArray = ProcessTagBlockDefinition(parentClass.Definition, ref offset, true);
                    elementArray.Append(ProcessTagBlockDefinition(validateTag.Definition, ref offset, true));
                }
            }
            else
            {
                elementArray = ProcessTagBlockDefinition(validateTag.Definition, ref offset, true);
            }

            elementArray.Count = 1;

            var mapFiles = Directory.GetFiles(@"C:\Users\stem\Documents\modding\singleplayer", "*.map", SearchOption.TopDirectoryOnly)
                .Concat(Directory.GetFiles(@"C:\Users\stem\Documents\modding\multiplayer", "*.map", SearchOption.TopDirectoryOnly))
                .Concat(Directory.GetFiles(@"C:\Users\stem\Documents\modding\resource", "*.map", SearchOption.TopDirectoryOnly));
            foreach (var file in mapFiles)
            {
                using (var map = new MapStream(file))
                {
                    var binaryReader = new BinaryReader(map);

                    OnWriteMessage(string.Format("Begin ({0})", map.MapName));

                    foreach (var tag in map.Tags)
                    {
                        if (!(tag.Type == validateTag.Class)) continue;
                        else
                        {
                            VirtualMappedAddress metaTableMemory = new VirtualMappedAddress() { Address = map.Tags[0].VirtualAddress, Length = map.TagCacheLength };
                            isValidDelegate = new Func<BlamPointer, bool>(metaTableMemory.Contains);
                            VirtualMappedAddress virtualTagMemory = new VirtualMappedAddress() { Address = tag.VirtualAddress, Length = tag.Length };
                            IsPointerOwnedByTagDelegate = new Func<BlamPointer, bool>(virtualTagMemory.Contains);
                            OnWriteMessage(string.Format("Tag ({0})", tag.Path));
                            map[tag.Identifier].Seek();
                            offset = (int)map.Position;
                            elementArray.VirtualAddress = map[tag.Identifier].Meta.VirtualAddress;
                            PointersList = new List<Tuple<BlamPointer, ElementArray>>();
                            ValidateTagBlock(elementArray, elementArray.ToFixedArrayPointer(), binaryReader, ref offset);
                            AnalyzePointers(PointersList);
                            stringWriter.Flush();
                        }
                    }
                    Console.WriteLine(string.Format("Parsed ({0})", map.MapName));
                    //OnWriteMessage(string.Format("End ({0})", map.MapName));
                }
            }
            stringWriter.Close();
            return "";
        }
Exemplo n.º 10
0
 public void Read(IntPtr h2LangLib, BinaryReader reader)
 {
     this = new tag_group(reader);
 }
Exemplo n.º 11
0
        private static IList <tag_field> ExtractFields(IEnumerable <tag_group> h2Tags, BinaryReader reader, tag_group tag)
        {
            var definition = ( TagBlockDefinition)tag.Definition;

            return(definition.LatestFieldSet.Fields);
        }
Exemplo n.º 12
0
        private void ProcessTag(IEnumerable <tag_group> h2Tags, string folder, BinaryReader reader, XmlWriter writer, tag_group tag)
        {
            const int        @null  = -1;
            List <tag_field> fields = null;

            if (tag.parent_group_tag != @null)
            {
                fields = new List <tag_field>();
                var parent = h2Tags.Where(x => x.group_tag == tag.parent_group_tag).Single();
                if (parent.parent_group_tag != @null)
                {
                    var @base = h2Tags.Where(x => x.group_tag == parent.parent_group_tag).Single();
                    fields.AddRange(ExtractFields(h2Tags, reader, @base));
                }
                fields.AddRange(ExtractFields(h2Tags, reader, parent));
                fields.AddRange(ExtractFields(h2Tags, reader, tag));
            }

            // Process the tag_group definition.
            var fieldOffset = 0;

            ProcessTagBlockDefinition(tag.Definition, writer, tag.definition_address, ref fieldOffset, tag.Class.ToString(), "", root, false, fields);
            root = root ? false : false;

            writer.Flush();

            //File.WriteAllText(string.Format("{0}\\{1}.cs", folder, readTag.Name), writer.ToString());
            return;
        }