コード例 #1
0
        /// <summary>
        /// Filters a set of localized strings and prepares them for display.
        /// </summary>
        /// <param name="unic">The string list.</param>
        /// <param name="stringIds">The string ID cache to use.</param>
        /// <param name="strings">The strings to display.</param>
        /// <param name="language">The language to display strings from.</param>
        /// <param name="filter">The filter to match strings and stringIDs against. Can be <c>null</c> to display everything.</param>
        /// <returns>The strings to print.</returns>
        public static List <DisplayString> PrepareForDisplay(MultilingualUnicodeStringList unic, StringIdCache stringIds, IEnumerable <LocalizedString> strings, GameLanguage language, string filter)
        {
            // Filter the input strings
            var display = new List <DisplayString>();

            foreach (var localizedString in strings)
            {
                var str = unic.GetString(localizedString, language);
                if (str == null)
                {
                    continue;
                }
                var stringId = stringIds.GetString(localizedString.StringID);
                if (filter != null && !str.Contains(filter) && !stringId.Contains(filter))
                {
                    continue;
                }
                display.Add(new DisplayString
                {
                    StringID = stringId,
                    String   = str
                });
            }
            display.Sort((a, b) => String.Compare(a.StringID, b.StringID, StringComparison.Ordinal));
            return(display);
        }
コード例 #2
0
 public GetCommand(OpenTagCache info, TagInstance tag, MultilingualUnicodeStringList unic)
     : base(CommandFlags.Inherit,
            "get",
            "",
            "get <language> <string_id>",
            "")
 {
     Info       = info;
     Tag        = tag;
     Definition = unic;
 }
コード例 #3
0
        public static CommandContext Create(CommandContext parent, FileInfo fileInfo, TagCache cache, HaloTag tag,
                                            MultilingualUnicodeStringList unic, StringIdCache stringIds)
        {
            var context = new CommandContext(parent, string.Format("{0:X8}.unic", tag.Index));

            if (stringIds != null)
            {
                context.AddCommand(new UnicListCommand(unic, stringIds));
                context.AddCommand(new UnicSetCommand(fileInfo, cache, tag, unic, stringIds));
            }
            return(context);
        }
コード例 #4
0
        private void MergeMultilingualUnicodeStringList(Stream cacheStream, Stream blamCacheStream, Dictionary <ResourceLocation, Stream> resourceStreams, CachedTag edTag, CachedTag h3Tag)
        {
            MultilingualUnicodeStringList h3Def = BlamCache.Deserialize <MultilingualUnicodeStringList>(blamCacheStream, h3Tag);
            var edDef = CacheContext.Deserialize <MultilingualUnicodeStringList>(cacheStream, edTag);

            ConvertMultilingualUnicodeStringList(cacheStream, blamCacheStream, resourceStreams, h3Def);

            var mergedStringCount = 0;

            for (var i = 0; i < h3Def.Strings.Count; i++)
            {
                var found = false;

                for (var j = 0; j < edDef.Strings.Count; j++)
                {
                    if (h3Def.Strings[i].StringID == edDef.Strings[j].StringID)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    var localizedStr = new LocalizedString
                    {
                        StringID    = h3Def.Strings[i].StringID,
                        StringIDStr = h3Def.Strings[i].StringIDStr
                    };

                    edDef.Strings.Add(localizedStr);

                    for (var x = 0; x < 12; x++)
                    {
                        edDef.SetString(
                            localizedStr,
                            (GameLanguage)x,
                            h3Def.GetString(
                                h3Def.Strings[i],
                                (GameLanguage)x));
                    }

                    mergedStringCount++;
                }
            }

            if (mergedStringCount > 0)
            {
                Console.WriteLine($"Merged {mergedStringCount} localized strings.");
                CacheContext.Serialize(cacheStream, edTag, edDef);
            }
        }
コード例 #5
0
 public SetCommand(OpenTagCache info, TagInstance tag, MultilingualUnicodeStringList unic)
     : base(CommandFlags.None,
            "set",
            "Set the value of a string",
            "set <language> <stringid> <value>",
            "Sets the string associated with a stringID in a language.\n" +
            "Remember to put the string value in quotes if it contains spaces.\n" +
            "If the string does not exist, it will be added.")
 {
     Info       = info;
     Tag        = tag;
     Definition = unic;
 }
コード例 #6
0
        public RemoveStringCommand(GameCache cache, CachedTag tag, MultilingualUnicodeStringList definition) :
            base(false,

                 "RemoveString",
                 "Removes a string entry from the multilingual_unicode_string_list definition.",

                 "RemoveString <StringID>",

                 "Removes a string entry from the multilingual_unicode_string_list definition.")
        {
            Cache      = cache;
            Tag        = tag;
            Definition = definition;
        }
コード例 #7
0
        public GetStringCommand(HaloOnlineCacheContext cacheContext, CachedTagInstance tag, MultilingualUnicodeStringList unic)
            : base(true,

                   "GetString",
                   "Gets the value of a string.",

                   "GetString <language> <string_id>",

                   "Gets the value of a string.")
        {
            CacheContext = cacheContext;
            Tag          = tag;
            Definition   = unic;
        }
コード例 #8
0
        public RemoveStringCommand(HaloOnlineCacheContext cacheContext, CachedTagInstance tag, MultilingualUnicodeStringList definition) :
            base(false,

                 "RemoveString",
                 "Removes a string entry from the multilingual_unicode_string_list definition.",

                 "RemoveString <StringID>",

                 "Removes a string entry from the multilingual_unicode_string_list definition.")
        {
            CacheContext = cacheContext;
            Tag          = tag;
            Definition   = definition;
        }
コード例 #9
0
ファイル: GetStringCommand.cs プロジェクト: jaron780/TagTool
        public GetStringCommand(GameCache cache, CachedTag tag, MultilingualUnicodeStringList unic)
            : base(true,

                   "GetString",
                   "Gets the value of a string.",

                   "GetString <language> <string_id>",

                   "Gets the value of a string.")
        {
            Cache      = cache;
            Tag        = tag;
            Definition = unic;
        }
コード例 #10
0
        public SetStringCommand(HaloOnlineCacheContext cacheContext, CachedTagInstance tag, MultilingualUnicodeStringList unic)
            : base(false,

                   "SetString",
                   "Set the value of a string",

                   "SetString <language> <stringid> <value>",

                   "Sets the string associated with a stringID in a language.\n" +
                   "Remember to put the string value in quotes if it contains spaces.\n" +
                   "If the string does not exist, it will be added.")
        {
            CacheContext = cacheContext;
            Tag          = tag;
            Definition   = unic;
        }
コード例 #11
0
        public override object Execute(List <string> args)
        {
            if (args.Count != 1)
            {
                return(false);
            }

            var stringID = CacheContext.GetStringId(args[0]);

            var newDefinition = new MultilingualUnicodeStringList
            {
                Data    = new byte[0],
                Strings = new List <LocalizedString>()
            };

            foreach (var oldString in Definition.Strings)
            {
                if (oldString.StringID == stringID)
                {
                    continue;
                }

                var newString = new LocalizedString
                {
                    Offsets     = new int[] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
                    StringID    = oldString.StringID,
                    StringIDStr = oldString.StringIDStr
                };

                for (var i = 0; i < 12; i++)
                {
                    if (oldString.Offsets[i] == -1)
                    {
                        continue;
                    }

                    newDefinition.SetString(newString, (GameLanguage)i, Definition.GetString(oldString, (GameLanguage)i));
                }

                newDefinition.Strings.Add(newString);
            }

            Definition.Data    = newDefinition.Data;
            Definition.Strings = newDefinition.Strings;

            return(true);
        }
コード例 #12
0
ファイル: ListCommand.cs プロジェクト: XeCREATURE/TagTool
 public ListCommand(OpenTagCache info, MultilingualUnicodeStringList definition)
     : base(CommandFlags.Inherit,
            "list",
            "List strings",
            "list <language> [filter]",
            "Lists the strings belonging to a language.\n" +
            "If a filter is specified, only strings containing the filter will be listed.\n" +
            "\n" +
            "Available languages:\n" +
            "\n" +
            "english, japanese, german, french, spanish, mexican, italian, korean,\n" +
            "chinese-trad, chinese-simp, portuguese, russian")
 {
     // TODO: Can we dynamically generate the language list from the dictionary in ArgumentParser?
     Info       = info;
     Definition = definition;
 }
コード例 #13
0
        public UnicSetCommand(FileInfo fileInfo, TagCache cache, HaloTag tag, MultilingualUnicodeStringList unic, StringIdCache stringIds) : base(
                CommandFlags.None,

                "set",
                "Set the value of a string",

                "set <language> <stringid> <value>",

                "Sets the string associated with a stringID in a language.\n" +
                "Remember to put the string value in quotes if it contains spaces.\n" +
                "If the string does not exist, it will be added.")
        {
            _fileInfo  = fileInfo;
            _cache     = cache;
            _tag       = tag;
            _unic      = unic;
            _stringIds = stringIds;
        }
コード例 #14
0
        public ListStringsCommand(GameCache cache, MultilingualUnicodeStringList definition)
            : base(true,
                   "ListStrings",
                   "Lists the unicode strings belonging to a certain language.",

                   "ListStrings <language> [filter]",

                   "Lists the unicode strings belonging to a certain language.\n" +
                   "If a filter is specified, only strings containing the filter will be listed.\n" +
                   "\n" +
                   "Available languages:\n" +
                   "\n" +
                   "english, japanese, german, french, spanish, mexican, italian, korean,\n" +
                   "chinese-trad, chinese-simp, portuguese, russian")
        {
            // TODO: Can we dynamically generate the language list from the dictionary in ArgumentParser?
            Cache      = cache;
            Definition = definition;
        }
コード例 #15
0
        public static CommandContext Create(CommandContext parent, OpenTagCache info, TagInstance tag, MultilingualUnicodeStringList unic)
        {
            var groupName = info.StringIDs.GetString(tag.Group.Name);

            var context = new CommandContext(parent,
                                             string.Format("{0:X8}.{1}", tag.Index, groupName));

            Populate(context, info, tag, unic);

            return(context);
        }
コード例 #16
0
        public static void Populate(CommandContext context, OpenTagCache info, TagInstance tag, MultilingualUnicodeStringList unic)
        {
            if (info.StringIDs == null)
            {
                return;
            }

            context.AddCommand(new ListCommand(info, unic));
            context.AddCommand(new GetCommand(info, tag, unic));
            context.AddCommand(new SetCommand(info, tag, unic));
        }
コード例 #17
0
        public static CommandContext Create(CommandContext parent, HaloOnlineCacheContext cacheContext, CachedTagInstance tag, MultilingualUnicodeStringList unic)
        {
            var groupName = cacheContext.GetString(tag.Group.Name);

            var context = new CommandContext(parent,
                                             string.Format("{0:X8}.{1}", tag.Index, groupName));

            Populate(context, cacheContext, tag, unic);

            return(context);
        }
コード例 #18
0
        public static void Populate(CommandContext context, HaloOnlineCacheContext cacheContext, CachedTagInstance tag, MultilingualUnicodeStringList unic)
        {
            if (cacheContext.StringIdCache == null)
            {
                return;
            }

            context.AddCommand(new ListStringsCommand(cacheContext, unic));
            context.AddCommand(new GetStringCommand(cacheContext, tag, unic));
            context.AddCommand(new SetStringCommand(cacheContext, tag, unic));
            context.AddCommand(new RemoveStringCommand(cacheContext, tag, unic));
        }
コード例 #19
0
        public static void Populate(CommandContext context, GameCache cache, CachedTag tag, MultilingualUnicodeStringList unic)
        {
            if (cache.StringTable == null)
            {
                return;
            }

            context.AddCommand(new ListStringsCommand(cache, unic));
            context.AddCommand(new GetStringCommand(cache, tag, unic));
            context.AddCommand(new SetStringCommand(cache, tag, unic));
            context.AddCommand(new RemoveStringCommand(cache, tag, unic));
        }
コード例 #20
0
        private MultilingualUnicodeStringList ConvertMultilingualUnicodeStringList(Stream cacheStream, Dictionary <ResourceLocation, Stream> resourceStreams, MultilingualUnicodeStringList unic)
        {
            ushort[] stringIndex = new ushort[12];
            ushort[] stringCount = new ushort[12];

            for (int i = 0; i < 24; i++)
            {
                if (i % 2 == 0)
                {
                    stringIndex[i / 2] = unic.OffsetCounts[i];
                }
                else
                {
                    stringCount[i / 2] = unic.OffsetCounts[i];
                }
            }

            //
            // Convert LocaleTables to a Dictionary
            //

            Dictionary <int, KeyValuePair <int, List <string> > > table = new Dictionary <int, KeyValuePair <int, List <string> > >();

            var localeTable = BlamCache.LocaleTables;

            for (int i = 0; i < localeTable.Count; i++)
            {
                var localizedStringList = localeTable[i];
                for (int j = 0; j < localizedStringList.Count(); j++)
                {
                    var localizedString = localizedStringList[j];
                    var tempPair        = table.ContainsKey(localizedString.Index) ? table[localizedString.Index] : new KeyValuePair <int, List <string> >(localizedString.StringIndex, new List <string> {
                        "", "", "", "", "", "", "", "", "", "", "", ""
                    });
                    tempPair.Value[i]            = localizedString.String;
                    table[localizedString.Index] = tempPair;
                }
            }

            //
            // Determine the max count while ignoring the languages that have 0
            //

            List <ushort> fixedStartIndex = new List <ushort>();
            int           zeroCount       = 0;

            foreach (var startIndex in stringIndex)
            {
                if (startIndex > 0)
                {
                    fixedStartIndex.Add(startIndex);
                }
                else if (startIndex == 0)
                {
                    zeroCount++;
                }
            }
            int begin;

            if (zeroCount == 12)
            {
                begin = 0;
            }
            else
            {
                begin = fixedStartIndex.Max();
            }

            var count = stringCount.Max();

            string data = "";

            unic.Strings = new List <LocalizedString>();

            for (int i = begin; i < begin + count; i++)
            {
                var pair        = table[i];
                var stringBlock = new LocalizedString {
                    StringID    = ConvertStringId(new StringId((uint)pair.Key, BlamCache.Version)),
                    StringIDStr = null,
                };

                var locales = pair.Value;

                for (int j = 0; j < 12; j++)
                {
                    stringBlock.Offsets[j] = Encoding.UTF8.GetBytes(data).Length;

                    if (i < stringIndex[j] || i >= stringIndex[j] + stringCount[j]) // Index is out of bounds for this particular locale
                    {
                        stringBlock.Offsets[j] = -1;
                    }
                    else
                    {
                        data = data + locales[j] + '\0';
                    }
                }
                unic.Strings.Add(stringBlock);
            }

            unic.Data = Encoding.UTF8.GetBytes(data);

            unic.OffsetCounts = new ushort[24];

            return(unic);
        }