Пример #1
0
        public General(HiToTextEntry entry)
        {
            m_format = string.Join("|", entry.Header.Fields);
            m_gamesSupported = string.Join(",", entry.Header.Games);
            foreach(HiToTextEntryHeaderName name in entry.Header.Extensions)
                m_extensionsRequired += name.Value + ",";
            m_extensionsRequired = m_extensionsRequired.TrimEnd(new char[] { ',' });

            tParams = GetTextParameters(entry);

            switchMaps = GetSwitchMaps(entry);

            hiscoreData = new HiscoreData(entry);

            listOfSetMappings = SetupMappings(entry);
        }
Пример #2
0
        public HiscoreData(HiToTextEntry entry)
        {
            _entry = entry;

            foreach (HiToTextEntryMapping mapping in entry.FileStructure)
            {
                int numBlocks = mapping.NumberOfBlocks;
                int start = 1;
                if (mapping.StartSpecified)
                    start = mapping.Start;

                Dictionary<string, int> entries = new Dictionary<string, int>();

                foreach (HiToTextEntryMappingEntry mapEntry in mapping.Entry)
                    entries.Add(mapEntry.Name, mapEntry.Length);

                switch (mapping.Ordering.ToUpper())
                {
                    case "ASCENDING":
                        for (int i = 0; i < numBlocks; i++)
                        {
                            foreach (string s in entries.Keys)
                                dataMap.Add(s + (start + i).ToString(), new byte[entries[s]]);
                        }
                        break;
                    case "DESCENDING":
                        for (int i = numBlocks - 1; i >= 0; i--)
                        {
                            foreach (string s in entries.Keys)
                                dataMap.Add(s + (start + i).ToString(), new byte[entries[s]]);
                        }
                        break;
                    case "NONE":
                        foreach (string s in entries.Keys)
                            dataMap.Add(s, new byte[entries[s]]);
                        break;
                }
            }
        }
Пример #3
0
        private List<SetMapping> SetupMappings(HiToTextEntry entry)
        {
            List<SetMapping> toReturn = new List<SetMapping>();

            foreach (HiToTextEntryFieldName fieldName in entry.SetStructure)
            {
                SetMapping mapping = new SetMapping(fieldName.Name);
                mapping.FieldType = Type.GetType(GetValidFieldType(fieldName.FieldType));
                mapping.ConversionType = fieldName.ConversionType;

                if (fieldName.ConstantSpecified)
                    mapping.Data = fieldName.Constant;
                if (fieldName.ExternalWrapper != null)
                    mapping.ExternalWrapper = GetWrapper(fieldName.ExternalWrapper);

                if (fieldName.ConversionType.ToUpper().Equals("NAME"))
                {
                    if (mapping.ExternalWrapper != null)
                        mapping.ConversionMethod = SetScore.ConvertName(tParams, mapping.ExternalWrapper);
                    else
                        mapping.ConversionMethod = SetScore.ConvertName(tParams);
                }
                else if (fieldName.ConversionType.ToUpper().Equals("SWITCH"))
                    mapping.ConversionMethod = SetScore.ConvertSwitch(switchMaps[fieldName.Name]);

                string[] sPositions = fieldName.Position.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                mapping.Positions = new int[sPositions.Length];
                for (int i = 0; i < sPositions.Length; i++)
                    mapping.Positions[i] = Convert.ToInt32(sPositions[i]);

                SetupSpecialUtilizations(ref mapping, fieldName.SpecialUtilization);

                toReturn.Add(mapping);
            }

            return toReturn;
        }
Пример #4
0
        private TextParams GetTextParameters(HiToTextEntry entry)
        {
            TextParams tParams = new TextParams();
            if (entry.Header.TextParameters == null)
                return tParams;

            tParams.Format = GetFormat(entry);

            if (entry.Header.TextParameters.ByteSkipAmountSpecified)
                tParams.ByteSkipAmount = entry.Header.TextParameters.ByteSkipAmount;

            if (entry.Header.TextParameters.ByteStartSpecified)
                tParams.ByteStart = entry.Header.TextParameters.ByteStart;

            if (entry.Header.TextParameters.ByteSkipData == null)
                tParams.ByteSkipData = 0x00;
            else
            {
                string sBSD = entry.Header.TextParameters.ByteSkipData;
                if (sBSD.Substring(0, 2).Equals("0x"))
                    sBSD = sBSD.Substring(2);
                if (!sBSD.Equals(string.Empty))
                {
                    try
                    {
                        tParams.ByteSkipData = HiConvert.IntToByteArrayHexAsHex(Convert.ToInt32(sBSD), 1)[0];
                    }
                    catch { }
                }
            }

            if (entry.Header.TextParameters.Offsets != null)
            {
                foreach (HiToTextEntryHeaderTextParametersOffsetsOffset o in entry.Header.TextParameters.Offsets.Offset)
                {
                    Offset.FlagOffsets offsetFlag = GetOffsetFlag(o.Type);

                    string sByte = o.StartByte;
                    if (sByte.Substring(0, 2).Equals("0x"))
                        sByte = sByte.Substring(2);

                    int skipMod = 1;
                    if (o.SkipModifierSpecified)
                        skipMod = Convert.ToInt32(o.SkipModifier);

                    tParams.AddOffset(new Offset(
                        HiConvert.ByteArrayHexAsHexToInt(HiConvert.HexStringToByteArray(sByte)), skipMod, offsetFlag));
                }
            }
            if (entry.Header.TextParameters.SpecialMapping != null)
            {
                foreach (HiToTextEntryHeaderTextParametersSpecialMappingMap map in entry.Header.TextParameters.SpecialMapping.Map)
                {
                    char c = map.Char[0];
                    string sByte = map.Byte;
                    if (sByte.Substring(0, 2).Equals("0x"))
                        sByte = sByte.Substring(2);
                    byte b = HiConvert.HexStringToByteArray(sByte)[0];
                    tParams.AddMapping(c, b);
                }
            }

            return tParams;
        }
Пример #5
0
        private Dictionary<string, OneToManyMap<byte[], string>> GetSwitchMaps(HiToTextEntry entry)
        {
            Dictionary<string, OneToManyMap<byte[], string>> toReturn =
                new Dictionary<string, OneToManyMap<byte[], string>>();

            if (entry.Header.TextParameters == null)
                return toReturn;

            if (entry.Header.TextParameters.SwitchMaps == null)
                return toReturn;

            foreach (HiToTextEntryHeaderTextParametersSwitchMapsSwitchMap sMap in entry.Header.TextParameters.SwitchMaps.SwitchMap)
            {
                string sDefaultOne = sMap.DefaultOne;
                string[] sDefaultOnes =
                    sDefaultOne.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

                for (int i = 0; i < sDefaultOnes.Length; i++)
                {
                    if (sDefaultOnes[i].Substring(0, 2).Equals("0x"))
                        sDefaultOnes[i] = sDefaultOnes[i].Substring(2);
                }

                sDefaultOne = String.Join(string.Empty, sDefaultOnes);
                byte[] defaultOne = HiConvert.HexStringToByteArray(sDefaultOne);

                string defaultMany = sMap.DefaultMany;
                OneToManyMap<byte[], string> map = new OneToManyMap<byte[], string>();
                map.AddDefault(defaultOne, defaultMany);

                foreach (HiToTextEntryHeaderTextParametersSwitchMapsSwitchMapMapping sMapping in sMap.Mapping)
                {
                    string sOne = sMapping.One;
                    string[] sOnes = sOne.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

                    for (int i = 0; i < sOnes.Length; i++)
                    {
                        if (sOnes[i].Substring(0, 2).Equals("0x"))
                            sOnes[i] = sOnes[i].Substring(2);
                    }

                    sOne = String.Join(string.Empty, sOnes);
                    byte[] bOne = HiConvert.HexStringToByteArray(sOne);

                    map.AddMapping(bOne, sMapping.Many);
                }

                toReturn.Add(sMap.Name, map);
            }

            return toReturn;
        }
Пример #6
0
        private StringFormatFlag GetFormat(HiToTextEntry entry)
        {
            if (entry.Header.TextParameters.Formats == null)
                return new StringFormatFlag();

            StringFormatFlag toReturn = new StringFormatFlag();

            HiToTextEntryHeaderTextParametersFormats formats = new HiToTextEntryHeaderTextParametersFormats();
            foreach (string f in entry.Header.TextParameters.Formats.Name)
            {
                switch (f.ToUpper())
                {
                    case "ASCIILOWER":
                        toReturn |= StringFormatFlag.ASCIILower;
                        break;
                    case "ASCIINUMBERS":
                        toReturn |= StringFormatFlag.ASCIINumbers;
                        break;
                    case "ASCIISTANDARD":
                        toReturn |= StringFormatFlag.ASCIIStandard;
                        break;
                    case "ASCIIUPPER":
                        toReturn |= StringFormatFlag.ASCIIUpper;
                        break;
                    case "NEEDSSPECIALMAPPING":
                        toReturn |= StringFormatFlag.NeedsSpecialMapping;
                        break;
                }
            }

            return toReturn;
        }