Exemplo n.º 1
0
        public static LangMap GetWeaponsOfType(string targetFile, WeaponTypeOnlyWeapons weaponType)
        {
            using var dat = new BinaryReader(new FileStream(targetFile, FileMode.Open, FileAccess.Read));
            dat.BaseStream.Seek(6, SeekOrigin.Begin);
            var count = dat.ReadUInt32();

            dat.BaseStream.Seek(10, SeekOrigin.Begin);

            var weaponClassType = weaponType.ToClassType();

            var weaponTypeName = Path.GetFileNameWithoutExtension(weaponType.ToDatFileName());
            // ReSharper disable once PossibleNullReferenceException
            var structSize = (uint)weaponClassType.GetField(nameof(Armor.StructSize), BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy).GetValue(null);

            var values = new LangMap();

            for (var i = 0; i < count; i++)
            {
                var position = dat.BaseStream.Position;
                var buff     = dat.ReadBytes((int)structSize);

                var weapon = (IWeapon)Activator.CreateInstance(weaponClassType, buff, (ulong)position, "");

                foreach (var lang in Global.LANGUAGES)
                {
                    if (!values.ContainsKey(lang))
                    {
                        values[lang] = new Dictionary <uint, string>();
                    }

                    values[lang][weapon.Id] = DataHelper.weaponData[lang][weaponTypeName ?? throw new InvalidOperationException()][weapon.GMD_Name_Index];
Exemplo n.º 2
0
 public static string ToDatFileName(this WeaponTypeOnlyWeapons weaponType)
 {
     return(((WeaponType)weaponType).ToDatFileName());
 }