Ejemplo n.º 1
0
        public static MapInfo GetMap(ulong key)
        {
            STUMap map = GetInstance <STUMap>(key);

            if (map == null)
            {
                return(null);
            }

            string nameA = GetString(map.DisplayName);
            string nameB = GetString(map.VariantName);

            string descA   = GetString(map.DescriptionA);
            string descB   = GetString(map.DescriptionB);
            string subline = GetString(map.SublineString);

            string stateA = GetString(map.StateStringA);
            string stateB = GetString(map.StateStringB);

            List <GamemodeInfo> gamemodes = null;

            if (map.Gamemodes != null)
            {
                gamemodes = new List <GamemodeInfo>();
                foreach (Common.STUGUID guid in map.Gamemodes)
                {
                    STUGamemode gamemode = GetInstance <STUGamemode>(guid);
                    if (gamemode == null)
                    {
                        continue;
                    }

                    gamemodes.Add(new GamemodeInfo {
                        Name = GetString(gamemode.DisplayName),
                        GUID = guid
                    });
                }
            }

            if (!string.IsNullOrEmpty(nameA) && !string.IsNullOrEmpty(nameB) && nameB.Equals(nameA))
            {
                nameB = null;
            }

            if (!string.IsNullOrEmpty(descA) && !string.IsNullOrEmpty(descB) && descB.Equals(descA))
            {
                descB = null;
            }

            string uniqueName;

            if (nameA == null)
            {
                uniqueName = $"Title Screen:{GUID.Index(key):X}";
            }
            else
            {
                uniqueName = nameA + $":{GUID.Index(key):X}";
            }
            return(new MapInfo(uniqueName, key, nameA, nameB, descA, descB, subline, stateA, stateB,
                               map.MapDataResource1, map.MapDataResource2, gamemodes));
        }
Ejemplo n.º 2
0
        public void SaveMaps(ICLIFlags toolFlags)
        {
            string basePath;

            if (toolFlags is ExtractMapEnvFlags flags)
            {
                basePath = flags.OutputPath;
            }
            else
            {
                throw new Exception("no output path");
            }

            basePath = Path.Combine(basePath, "Environments");

            if (!Directory.Exists(basePath))
            {
                Directory.CreateDirectory(basePath);
            }

            if (!flags.SkipMapEnvironmentLUT && File.Exists(Path.Combine(basePath, "SPILUT", "config.ocio")))
            {
                File.Delete(Path.Combine(basePath, "SPILUT", "config.ocio"));
            }

            HashSet <KeyValuePair <ulong, string> > done = new HashSet <KeyValuePair <ulong, string> >();

            foreach (ulong metaKey in TrackedFiles[0x9F])
            {
                STUMap map = GetInstance <STUMap>(metaKey);
                if (map == null)
                {
                    continue;
                }

                MapInfo mapInfo = GetMap(metaKey);
                mapInfo.Name  = mapInfo.Name ?? "Title Screen";
                mapInfo.NameB = mapInfo.NameB ?? mapInfo.Name;

                ulong dataKey = map.MapDataResource1;

                using (Stream data = OpenFile(dataKey))
                {
                    if (data == null)
                    {
                        continue;
                    }

                    using (BinaryReader dataReader = new BinaryReader(data))
                    {
                        MapEnvironment env = dataReader.Read <MapEnvironment>();

                        string fname = $"ow_map_{GetValidFilename($"{mapInfo.NameB}_{GUID.Index(mapInfo.MetadataGUID):X}")}";

                        if (!flags.SkipMapEnvironmentSound && done.Add(new KeyValuePair <ulong, string>(env.MapEnvironmentSound, mapInfo.Name)))
                        {
                            SaveSound(flags, basePath, Path.Combine("Sound", GetValidFilename($"{mapInfo.NameB}_{GUID.Index(mapInfo.MetadataGUID):X}")), env.MapEnvironmentSound);
                        }
                        if (!flags.SkipMapEnvironmentLUT && done.Add(new KeyValuePair <ulong, string>(env.LUT, mapInfo.Name)))
                        {
                            SaveTex(flags, basePath, "LUT", fname, env.LUT);
                            SaveLUT(flags, basePath, "SPILUT", fname, env.LUT, Path.Combine(basePath, "SPILUT", "config.ocio"), mapInfo);
                        }
                        if (!flags.SkipMapEnvironmentBlendCubemap && done.Add(new KeyValuePair <ulong, string>(env.BlendEnvironmentCubemap, mapInfo.Name)))
                        {
                            SaveTex(flags, basePath, "BlendCubemap", fname, env.BlendEnvironmentCubemap);
                        }
                        if (!flags.SkipMapEnvironmentGroundCubemap && done.Add(new KeyValuePair <ulong, string>(env.GroundEnvironmentCubemap, mapInfo.Name)))
                        {
                            SaveTex(flags, basePath, "GroundCubemap", fname, env.GroundEnvironmentCubemap);
                        }
                        if (!flags.SkipMapEnvironmentSkyCubemap && done.Add(new KeyValuePair <ulong, string>(env.SkyEnvironmentCubemap, mapInfo.Name)))
                        {
                            SaveTex(flags, basePath, "SkyCubemap", fname, env.SkyEnvironmentCubemap);
                        }
                        if (!flags.SkipMapEnvironmentSkybox && done.Add(new KeyValuePair <ulong, string>(env.SkyboxModel ^ env.SkyboxModelLook, mapInfo.Name)))
                        {
                            SaveMdl(flags, basePath, Path.Combine("Skybox", GetValidFilename($"{mapInfo.NameB}_{GUID.Index(mapInfo.MetadataGUID):X}")), env.SkyboxModel, env.SkyboxModelLook);
                        }
                        if (!flags.SkipMapEnvironmentEntity && done.Add(new KeyValuePair <ulong, string>(env.EntityDefinition, mapInfo.Name)))
                        {
                            SaveEntity(flags, basePath, Path.Combine("Entity", GetValidFilename($"{mapInfo.NameB}_{GUID.Index(mapInfo.MetadataGUID):X}")), env.EntityDefinition);
                        }

                        InfoLog("Saved Environment data for {0}", mapInfo.NameB);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void Parse(Dictionary <ushort, List <ulong> > track, Dictionary <ulong, Record> map, CASCHandler handler, bool quiet, OverToolFlags flags)
        {
            List <ulong> masters = track[0x9F];

            foreach (ulong key in masters)
            {
                if (!map.ContainsKey(key))
                {
                    continue;
                }
                ISTU stu = ISTU.NewInstance(Util.OpenFile(map[key], handler), uint.MaxValue);
                if (stu.Instances == null)
                {
                    continue;
                }
                STUMap mapSTU = stu.Instances.First() as STUMap;
                if (map == null)
                {
                    continue;
                }
//                Console.Out.WriteLine($"{key}");
//
//                if (mapSTU.StringDescriptionA != null) {
//                    Console.Out.WriteLine($"\tStringDescriptionA: {Util.GetString(mapSTU.StringDescriptionA, map, handler)}");
//                }
//                if (mapSTU.StringStateA != null) {
//                    Console.Out.WriteLine($"\tStringStateA: {Util.GetString(mapSTU.StringStateA, map, handler)}");
//                }
//                if (mapSTU.StringName != null) {
//                    Console.Out.WriteLine($"\tStringName: {Util.GetString(mapSTU.StringName, map, handler)}");
//                }
//                if (mapSTU.StringStateB != null) {
//                    Console.Out.WriteLine($"StringStateB: {Util.GetString(mapSTU.StringStateB, map, handler)}");
//                }
//                if (mapSTU.StringDescriptionB != null) {
//                    Console.Out.WriteLine($"\tStringDescriptionB: {Util.GetString(mapSTU.StringDescriptionB, map, handler)}");
//                }
//                if (mapSTU.StringSubline != null) {
//                    Console.Out.WriteLine($"\tStringSubline: {Util.GetString(mapSTU.StringSubline, map, handler)}");
//                }
//                if (mapSTU.StringNameB != null) {
//                    Console.Out.WriteLine($"\tStringNameB: {Util.GetString(mapSTU.StringNameB, map, handler)}");
//                }

                //string name = Util.GetString(map.Header.name.key, map, handler);
                //if (string.IsNullOrWhiteSpace(name)) {
                //    name = $"Unknown{GUID.Index(masterKey):X}";
                //}
                //Console.Out.WriteLine(name);
                //Console.Out.WriteLine("\tID: {0:X8}", GUID.Index(masterKey));

                //string subline = Util.GetString(map.Header.subline.key, map, handler);
                //if (subline == null) {
                //    subline = "";
                //}
                //if (map.Header.subline.key != map.Header.subline2.key && map.Header.subline2.key != 0) {
                //    subline += " " + Util.GetString(map.Header.subline2.key, map, handler);
                //}
                //subline = subline.Trim();
                //if (subline.Length > 0) {
                //    Console.Out.WriteLine("\tSubline: {0}", subline);
                //}

                //TryString("State", Util.GetString(map.Header.stateA.key, map, handler));
                //TryString("State", Util.GetString(map.Header.stateB.key, map, handler));

                //string description = Util.GetString(map.Header.description1.key, map, handler);
                //if (description == null) {
                //    description = "";
                //}
                //if (map.Header.description1.key != map.Header.description2.key && map.Header.description2.key != 0) {
                //    description += " " + Util.GetString(map.Header.description2.key, map, handler);
                //}
                //description = description.Trim();
                //if (description.Length > 0) {
                //    Console.Out.WriteLine("\tDescription: {0}", description);
                //}
            }
        }
Ejemplo n.º 4
0
        public static void Save(ICLIFlags flags, STUMap map, ulong key, string basePath)
        {
            string name = GetValidFilename(GetString(map.DisplayName)) ?? "Title Screen";

            if (GetString(map.VariantName) != null)
            {
                name = GetValidFilename(GetString(map.VariantName));
            }

            LoudLog($"Extracting map {name}\\{GUID.Index(key):X}");

            // if (map.Gamemodes != null) {
            //     foreach (Common.STUGUID gamemodeGUID in map.Gamemodes) {
            //         STUGamemode gamemode = GetInstance<STUGamemode>(gamemodeGUID);
            //     }
            // }

            // TODO: MAP11 HAS CHANGED
            // TODO: MAP10 TOO?

            string mapPath = Path.Combine(basePath, "Maps", name, GUID.Index(key).ToString("X")) + Path.DirectorySeparatorChar;

            CreateDirectoryFromFile(mapPath);

            // if (map.UnknownArray != null) {
            //     Dictionary<ulong, List<TextureInfo>> textures = new Dictionary<ulong, List<TextureInfo>>();
            //     foreach (STUMap.STU_7D6D8405 stu_7D6D8405 in map?.UnknownArray) {
            //         ISTU overrideStu = OpenSTUSafe(stu_7D6D8405.Override);
            //         STUSkinOverride @override = GetInstance<STUSkinOverride>(stu_7D6D8405.Override);
            //         textures = FindLogic.Texture.FindTextures(textures, @override.SkinImage);
            //     }
            //     SaveLogic.Texture.Save(flags, Path.Combine(mapPath, "override"), textures);
            // }

            OWMDLWriter   modelWriter = new OWMDLWriter();
            OWMap14Writer owmap       = new OWMap14Writer();

            FindLogic.Combo.ComboInfo info = new FindLogic.Combo.ComboInfo();
            LoudLog("\tFinding");
            FindLogic.Combo.Find(info, map.MapDataResource1);

            MapEnvironment?env = null;

            using (Stream data = OpenFile(map.MapDataResource1)) {
                if (data != null)
                {
                    using (BinaryReader dataReader = new BinaryReader(data)) {
                        env = dataReader.Read <MapEnvironment>();
                    }
                }
            }

            using (Stream mapStream = OpenFile(map.GetDataKey(1))) {
                STULib.Types.Map.Map mapData = new STULib.Types.Map.Map(mapStream, BuildVersion);

                using (Stream map2Stream = OpenFile(map.GetDataKey(2))) {
                    if (map2Stream == null)
                    {
                        return;
                    }
                    STULib.Types.Map.Map map2Data = new STULib.Types.Map.Map(map2Stream, BuildVersion);
                    using (Stream map8Stream = OpenFile(map.GetDataKey(8))) {
                        STULib.Types.Map.Map map8Data = new STULib.Types.Map.Map(map8Stream, BuildVersion);
                        using (Stream mapEntitiesStream = OpenFile(map.GetDataKey(0xB))) {
                            STULib.Types.Map.Map mapEntities =
                                new STULib.Types.Map.Map(mapEntitiesStream, BuildVersion, true);

                            mapEntitiesStream.Position = (long)(Math.Ceiling(mapEntitiesStream.Position / 16.0f) * 16);  // Future proofing (?)

                            for (int i = 0; i < mapEntities.Records.Length; ++i)
                            {
                                if (mapEntities.Records[i] != null && mapEntities.Records[i].GetType() != typeof(MapEntity))
                                {
                                    continue;
                                }
                                MapEntity mapEntity = (MapEntity)mapEntities.Records[i];

                                if (mapEntity == null)
                                {
                                    continue;
                                }
                                FindLogic.Combo.Find(info, mapEntity.Header.Entity);
                                STUModelComponent component =
                                    GetInstance <STUModelComponent>(mapEntity.Header.Entity);

                                if (component == null)
                                {
                                    continue;
                                }
                                mapEntity.ModelLook    = component.Look;
                                mapEntity.Model        = component.Model;
                                mapEntities.Records[i] = mapEntity;
                            }

                            using (Stream mapLStream = OpenFile(map.GetDataKey(9))) {
                                STULib.Types.Map.Map mapLData = new STULib.Types.Map.Map(mapLStream, BuildVersion);
                                using (Stream outputStream = File.Open(Path.Combine(mapPath, $"{name}.owmap"),
                                                                       FileMode.Create, FileAccess.Write)) {
                                    owmap.Write(outputStream, mapData, map2Data, map8Data, mapEntities, mapLData, name,
                                                modelWriter, info);
                                }
                            }
                        }
                    }
                }
            }

            FindLogic.Combo.Find(info, map.EffectAnnouncer);
            info.SetEffectName(map.EffectAnnouncer, "LoadAnnouncer");
            FindLogic.Combo.Find(info, map.EffectMusic);
            info.SetEffectName(map.EffectMusic, "LoadMusic");

            if (map.VoiceSet != null)
            {
                FindLogic.Combo.Find(info, map.VoiceSet);
            }

            if (env != null)
            {
                FindLogic.Combo.Find(info, env.Value.EntityDefinition);
                STUVoiceSetComponent voiceSetComponent = GetInstance <STUVoiceSetComponent>(env.Value.EntityDefinition);
                if (voiceSetComponent != null)
                {
                    FindLogic.Combo.Find(info, voiceSetComponent.VoiceSet);
                    info.SetEffectVoiceSet(map.EffectAnnouncer, voiceSetComponent.VoiceSet);
                    info.SetEffectVoiceSet(map.EffectMusic, voiceSetComponent.VoiceSet);
                }
            }

            LoudLog("\tSaving");
            Combo.Save(flags, mapPath, info);

            string soundPath       = Path.Combine(mapPath, "Sound");
            string voiceSetsPath   = Path.Combine(soundPath, "VoiceSets");
            string otherSoundsPath = Path.Combine(soundPath, "SFX");

            Combo.SaveVoiceSets(flags, voiceSetsPath, info);
            foreach (KeyValuePair <ulong, FindLogic.Combo.SoundFileInfo> sound in info.SoundFiles)
            {
                Combo.SaveSoundFile(flags, otherSoundsPath, info, sound.Key, false);
            }

            LoudLog("\tDone");
        }
Ejemplo n.º 5
0
        public void SaveMaps(ICLIFlags toolFlags)
        {
            string basePath;

            if (toolFlags is ExtractFlags flags)
            {
                basePath = flags.OutputPath;
            }
            else
            {
                throw new Exception("no output path");
            }

            Dictionary <string, Dictionary <string, ParsedArg> > parsedTypes = ParseQuery(flags, QueryTypes, QueryNameOverrides);

            if (parsedTypes == null)
            {
                QueryHelp(QueryTypes); return;
            }
            foreach (ulong key in TrackedFiles[0x9F])
            {
                STUMap map = GetInstance <STUMap>(key);
                if (map == null)
                {
                    continue;
                }
                ListMaps.MapInfo mapInfo = ListMaps.GetMap(key);
                mapInfo.Name = mapInfo.Name ?? "Title Screen";

                Dictionary <string, ParsedArg> config = new Dictionary <string, ParsedArg>();
                foreach (string name in new [] { mapInfo.Name, mapInfo.NameB, mapInfo.UniqueName, GUID.Index(map.MapDataResource1).ToString("X"), "*" })
                {
                    if (name == null)
                    {
                        continue;
                    }
                    string theName = name.ToLowerInvariant();
                    if (!parsedTypes.ContainsKey(theName))
                    {
                        continue;
                    }
                    foreach (KeyValuePair <string, ParsedArg> parsedArg in parsedTypes[theName])
                    {
                        if (config.ContainsKey(parsedArg.Key))
                        {
                            config[parsedArg.Key] = config[parsedArg.Key].Combine(parsedArg.Value);
                        }
                        else
                        {
                            config[parsedArg.Key] = parsedArg.Value.Combine(null); // clone for safety
                        }
                    }
                }

                if (config.Count == 0)
                {
                    continue;
                }

                Map.Save(flags, map, key, basePath);
            }
        }
Ejemplo n.º 6
0
        protected string GetMapName(ulong key)
        {
            STUMap map = GetInstance <STUMap>(key);

            return(GetString(map.DisplayName));
        }