Exemplo n.º 1
0
        private ITagGroup ResourceManager_ResolveResource(string resourceName)
        {
            //Prepare
            IndexEntry entry    = mapFile.IndexEntries[resourceLookup[resourceName]];
            Group      tagGroup = TagLookup.CreateTagGroup(entry.Root);

            //Read
            using (BinaryReader reader = entry.Data.GetVirtualStream().CreateReader())
            {
                //Read
                reader.BaseStream.Seek(entry.Address, SeekOrigin.Begin);
                tagGroup.Read(reader);
            }

            //Return
            return(Convert.ToGuerilla(tagGroup, soundCacheFileGestalt, entry, mapFile));
        }
Exemplo n.º 2
0
        private void decompileButton_Click(object sender, EventArgs e)
        {
            //Loop
            foreach (TagId id in checkedTagIds)
            {
                //Get index entry
                IndexEntry entry = mapFile.IndexEntries[id];

                //Check
                if (entry != null)
                {
                    //Read
                    Group tagGroup = TagLookup.CreateTagGroup(entry.Root);
                    using (var stream = entry.Data.GetVirtualStream())
                        using (var reader = stream.CreateReader())
                        {
                            reader.BaseStream.Seek(entry.Address, SeekOrigin.Begin);
                            tagGroup.Read(reader);
                        }

                    //Collect references
                    AbideTagGroupFile tagGroupFile = new AbideTagGroupFile()
                    {
                        TagGroup = Convert.ToGuerilla(tagGroup, soundCacheFileGestalt, entry, mapFile)
                    };
                    resourceManager.CollectResources(tagGroupFile.TagGroup);

                    //Get file name
                    string fileName = Path.Combine(RegistrySettings.WorkspaceDirectory, "tags", $"{entry.Filename}.{tagGroup.GroupName}");

                    //Create directory?
                    if (!Directory.Exists(Path.GetDirectoryName(fileName)))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(fileName));
                    }

                    //Save tag file
                    tagGroupFile.Save(fileName);
                }
            }

            //Decompile resources
            foreach (string resourceString in resourceManager.GetResources())
            {
                //Find entry
                IndexEntry entry = mapFile.IndexEntries[cacheResources.FindIndex(resourceString)];

                //Check
                if (entry != null)
                {
                    //Read
                    Group tagGroup = TagLookup.CreateTagGroup(entry.Root);
                    using (var stream = entry.Data.GetVirtualStream())
                        using (var reader = stream.CreateReader())
                        {
                            reader.BaseStream.Seek(entry.Address, SeekOrigin.Begin);
                            tagGroup.Read(reader);
                        }

                    //Collect references
                    AbideTagGroupFile tagGroupFile = new AbideTagGroupFile()
                    {
                        TagGroup = Convert.ToGuerilla(tagGroup, soundCacheFileGestalt, entry, mapFile)
                    };

                    //Get file name
                    string fileName = Path.Combine(RegistrySettings.WorkspaceDirectory, "tags", $"{entry.Filename}.{tagGroup.GroupName}");

                    //Create directory?
                    if (!Directory.Exists(Path.GetDirectoryName(fileName)))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(fileName));
                    }

                    //Save tag file
                    tagGroupFile.Save(fileName);
                }
            }
        }
Exemplo n.º 3
0
        private void Map_Decompile(object state)
        {
            Console.WriteLine($"Decompiling {map.Name}...");
            Group      globalsGroup;
            Group      soundGestaltGroup = null;
            IndexEntry soundGestalt      = null;
            IndexEntry globals           = map.Globals;

            try
            {
                using (var tagReader = globals.Data.GetVirtualStream().CreateReader())
                {
                    tagReader.BaseStream.Seek(globals.Address, SeekOrigin.Begin);
                    globalsGroup = TagLookup.CreateTagGroup(globals.Root);
                    globalsGroup.Read(tagReader);

                    BlockField soundGlobalsTagBlock = (BlockField)globalsGroup.TagBlocks[0].Fields[4];
                    if (soundGlobalsTagBlock.BlockList.Count > 0)
                    {
                        TagId soundGestaltId = (TagId)soundGlobalsTagBlock.BlockList[0].Fields[4].Value;
                        soundGestalt = map.IndexEntries[soundGestaltId];
                        soundGlobalsTagBlock.BlockList[0].Fields[4].Value = (int)TagId.Null;
                    }
                }

                if (soundGestalt != null)
                {
                    using (BinaryReader reader = soundGestalt.Data.GetVirtualStream().CreateReader())
                    {
                        soundGestaltGroup = TagLookup.CreateTagGroup(soundGestalt.Root);
                        reader.BaseStream.Seek(soundGestalt.Address, SeekOrigin.Begin);
                        soundGestaltGroup.Read(reader);
                    }
                }

                int   num    = 0;
                float total  = map.IndexEntries.Count;
                var   result = Parallel.ForEach(map.IndexEntries, entry =>
                {
                    num++;
                    Group guerillaTagGroup;
                    var tagGroup = TagLookup.CreateTagGroup(entry.Root);
                    var reader   = entry.Data.GetVirtualStream().CreateReader();
                    reader.BaseStream.Seek(entry.Address, SeekOrigin.Begin);
                    try { tagGroup.Read(reader); }
                    finally { guerillaTagGroup = Convert.ToGuerilla(tagGroup, soundGestaltGroup, entry, map); }

                    string localFileName    = Path.Combine($"{entry.Filename}.{guerillaTagGroup.GroupName}");
                    string tagGroupFileName = Path.Combine(OutputDirectory, localFileName);

                    if (!Directory.Exists(Path.GetDirectoryName(tagGroupFileName)))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(tagGroupFileName));
                    }

                    TagGroupHeader header = new TagGroupHeader();
                    using (FileStream fs = new FileStream(tagGroupFileName, FileMode.Create, FileAccess.ReadWrite, FileShare.Read))
                        using (BinaryReader fileReader = new BinaryReader(fs))
                            using (BinaryWriter fileWriter = new BinaryWriter(fs))
                            {
                                fs.Seek(TagGroupHeader.Size, SeekOrigin.Begin);
                                guerillaTagGroup.Write(fileWriter);

                                switch (guerillaTagGroup.GroupTag)
                                {
                                case "snd!":
                                    SoundTagGroup_CreateResources(guerillaTagGroup, soundGestalt, fileWriter, ref header);
                                    break;

                                case "mode":
                                    RenderModelTagGroup_CreateResources(guerillaTagGroup, entry, fileWriter, ref header);
                                    break;

                                case "sbsp":
                                    ScenarioStructureBspTagGroup_CreateResources(guerillaTagGroup, entry, fileWriter, ref header);
                                    break;

                                case "ltmp":
                                    ScenarioStructureLightmapTagGroup_CreateResources(guerillaTagGroup, entry, fileWriter, ref header);
                                    break;

                                case "weat":
                                    WeatherSystemTagGroup_CreateResources(guerillaTagGroup, entry, fileWriter, ref header);
                                    break;

                                case "DECR":
                                    DecoratorSetTagGroup_CreateResources(guerillaTagGroup, entry, fileWriter, ref header);
                                    break;

                                case "PRTM":
                                    ParticleModelTagGroup_CreateResources(guerillaTagGroup, entry, fileWriter, ref header);
                                    break;

                                case "jmad":
                                    AnimationTagGroup_CreateResources(guerillaTagGroup, entry, fileWriter, ref header);
                                    break;

                                case "bitm":
                                    BitmapTagGroup_CreateResources(guerillaTagGroup, entry, fileWriter, ref header);
                                    break;
                                }

                                header.Checksum = (uint)TagGroup_CalculateChecksum(guerillaTagGroup);
                                header.GroupTag = guerillaTagGroup.GroupTag.FourCc;
                                header.Id       = entry.Id.Dword;
                                header.AbideTag = "atag";

                                fs.Seek(0, SeekOrigin.Begin);
                                fileWriter.Write(header);
                                Host.Report(num / total);
                            }
                });
            }
            catch
            {
#if DEBUG
                throw;
#endif
            }
            finally
            {
                GC.Collect();
            }

            Host.Report(1);
            Thread.Sleep(500);
            Host.Complete();
        }