예제 #1
0
        private void SetHandlesValue(GenericUnknownStruct data)
        {
            data.Handles = _handles;

            var usedIndexes = new HashSet <uint>();

            foreach (var handle in _handles)
            {
                var id = handle.Id;
                handle.SetValue(data.ClassList[id]);
                usedIndexes.Add(id);
            }

            foreach (var index in usedIndexes)
            {
                data.ClassList[index] = null;
            }

            var newClassList = new List <GenericUnknownStruct.BaseClassEntry>();

            foreach (var classEntry in data.ClassList)
            {
                if (classEntry != null)
                {
                    newClassList.Add(classEntry);
                }
            }

            data.ClassList = newClassList.ToArray();
        }
예제 #2
0
        public ItemEditorControl(object data, SaveFile saveFile)
        {
            if (!(data is ItemData))
            {
                throw new Exception("Unexpected data type");
            }
            InitializeComponent();

            cbAttachmentSlot.DisplayMember = "NameWithoutGroup";
            cbMod.DisplayMember            = "ItemGameNameDescription";

            _saveFile = saveFile;
            _itemData = (ItemData)data;

            lblGameName.Text       = NameResolver.GetGameName(_itemData.ItemTdbId);
            lblItemName.Text       = NameResolver.GetName(_itemData.ItemTdbId);
            cbQuestItem.Checked    = _itemData.Flags.IsQuestItem;
            cbUnequippable.Checked = _itemData.Flags.IsNotUnequippable;
            nudQuantity.Maximum    = uint.MaxValue;

            if (_itemData.Data is ItemData.SimpleItemData sid)
            {
                nudQuantity.Enabled = true;
                nudQuantity.Value   = sid.Quantity;
            }
            else if (_itemData.Data is ItemData.ModableItemWithQuantityData miwqd)
            {
                nudQuantity.Enabled = true;
                nudQuantity.Value   = miwqd.Quantity;
            }

            if (_itemData.Data is ItemData.ModableItemData mid)
            {
                partListBox.Enabled      = true;
                statsSelect.Enabled      = true;
                addStatButton.Enabled    = true;
                btnDeleteMod.Enabled     = true;
                btnAddMod.Enabled        = true;
                cbAttachmentSlot.Enabled = true;
                cbModListSelect.Enabled  = true;
                cbMod.Enabled            = true;

                FillPartsList(mid);

                SelectedPartSeed      = _itemData.Header.Seed;
                SelectedPartTweakDbId = _itemData.ItemTdbId;

                var statsNode = _saveFile.Nodes.FirstOrDefault(n => n.Name == Constants.NodeNames.STATS_SYSTEM);
                if (statsNode == null)
                {
                    return;
                }
                _rootData = (GenericUnknownStruct)statsNode.Value;
                var mapStructure = _rootData.ClassList[0];
                _mapStructure = mapStructure as GameStatsStateMapStructure ?? throw new Exception("Unexpected Structure");

                FillStatsList();
            }
        }
예제 #3
0
        private GenericUnknownStruct.BaseClassEntry[] SetHandlesIndex(GenericUnknownStruct data)
        {
            var newClassList = new List <GenericUnknownStruct.BaseClassEntry>();

            foreach (var classEntry in data.ClassList)
            {
                if (classEntry == null)
                {
                    continue;
                }

                newClassList.Add(classEntry);
            }

            if (data.Handles.Count > 0)
            {
                var handles = data.Handles.OrderBy(h => h.Id).ToList();

                var lastOrgIdx = (uint)0;
                var idx        = (uint)newClassList.Count - 1;
                for (int i = 0; i < handles.Count; i++)
                {
                    var handleId = handles[i].Id;

                    if (lastOrgIdx == handleId)
                    {
                        handles[i].Id = idx;
                    }
                    else
                    {
                        lastOrgIdx    = handleId;
                        handles[i].Id = ++idx;
                    }
                }

                var usedIds = new HashSet <uint>();
                foreach (var handle in handles)
                {
                    if (usedIds.Contains(handle.Id))
                    {
                        continue;
                    }

                    newClassList.Add(handle.GetValue());
                    usedIds.Add(handle.Id);
                }
            }

            return(newClassList.ToArray());
        }
예제 #4
0
        private object InternalRead(NodeEntry node, BinaryReader reader)
        {
            var result = new GenericUnknownStruct();

            reader.Skip(4); //skip Id

            int readSize   = node.Size - ((int)reader.BaseStream.Position - node.Offset);
            var dataBuffer = reader.ReadBytes(readSize);

            using (var ms = new MemoryStream(dataBuffer))
            {
                using (var br = new BinaryReader(ms))
                {
                    result.TotalLength = br.ReadUInt32();
                    result.Unknown1    = br.ReadBytes(4);
                    result.Unknown2    = br.ReadUInt32();
                    result.Unknown3    = br.ReadBytes(4);

                    var stringListOffset    = br.ReadUInt32();
                    var dataIndexListOffset = br.ReadUInt32();
                    var dataListOffset      = br.ReadUInt32();

                    if (result.Unknown2 > 1)
                    {
                        var count1 = br.ReadInt32();

                        result.CNameHashes1 = new ulong[count1];
                        for (int i = 0; i < count1; i++)
                        {
                            result.CNameHashes1[i] = br.ReadUInt64();
                        }
                    }

                    var stringIndexListPosition = br.BaseStream.Position;
                    var stringListPosition      = stringIndexListPosition + stringListOffset;
                    var dataIndexListPosition   = stringIndexListPosition + dataIndexListOffset;
                    var dataListPosition        = stringIndexListPosition + dataListOffset;

                    // start of stringIndexList
                    var stringInfoList = new List <KeyValuePair <int, byte> >();
                    for (int i = 0; i < (stringListPosition - stringIndexListPosition) / 4; i++)
                    {
                        stringInfoList.Add(new KeyValuePair <int, byte>(br.ReadInt24(), br.ReadByte()));
                    }

                    // start of stringList
                    Debug.Assert(br.BaseStream.Position == stringListPosition);

                    _stringList = new List <string>();
                    foreach (var pair in stringInfoList)
                    {
                        Debug.Assert(br.BaseStream.Position == stringIndexListPosition + pair.Key);
                        _stringList.Add(br.ReadString(pair.Value - 1));
                        br.Skip(1); // null terminator
                    }

                    // start of dataIndexList
                    Debug.Assert(br.BaseStream.Position == dataIndexListPosition);

                    var pointerList = new List <KeyValuePair <uint, uint> >();
                    for (int i = 0; i < (dataListPosition - dataIndexListPosition) / 8; i++)
                    {
                        pointerList.Add(new KeyValuePair <uint, uint>(br.ReadUInt32(), br.ReadUInt32()));
                    }

                    // start of dataList
                    Debug.Assert(br.BaseStream.Position == dataListPosition);

                    var bufferDict = new Dictionary <int, byte[]>();
                    result.ClassList = new GenericUnknownStruct.BaseClassEntry[pointerList.Count];
                    for (int i = 0; i < result.ClassList.Length; i++)
                    {
                        Debug.Assert(br.BaseStream.Position == stringIndexListPosition + pointerList[i].Value);

                        long length;
                        if (i < result.ClassList.Length - 1)
                        {
                            length = pointerList[i + 1].Value - pointerList[i].Value;
                        }
                        else
                        {
                            length = result.TotalLength - br.BaseStream.Position + 4;
                        }

                        GenericUnknownStruct.BaseClassEntry classEntry;
                        if (_doMapping)
                        {
                            classEntry = GetInstanceFromName(_stringList[(int)pointerList[i].Key]);
                        }
                        else
                        {
                            classEntry = new GenericUnknownStruct.ClassEntry();
                            ((GenericUnknownStruct.ClassEntry)classEntry).Name = _stringList[(int)pointerList[i].Key];
                        }

                        bufferDict.Add(i, br.ReadBytes((int)length));

                        result.ClassList[i] = classEntry;
                    }

                    _handles = new List <IHandle>();

                    Parallel.ForEach(bufferDict, (pair) =>
                    {
                        using (var ms2 = new MemoryStream(pair.Value))
                        {
                            using (var br2 = new BinaryReader(ms2))
                            {
                                if (_doMapping)
                                {
                                    ReadMappedFields(br2, result.ClassList[pair.Key]);
                                }
                                else
                                {
                                    ((GenericUnknownStruct.ClassEntry)result.ClassList[pair.Key]).Fields = ReadUnmappedFields(br2);
                                }
                            }
                        }
                    });

                    if (_doMapping)
                    {
                        SetHandlesValue(result);
                    }
                    _handles = null;

                    // end of mainData
                    Debug.Assert((br.BaseStream.Position - 4) == result.TotalLength);

                    readSize = (int)(br.BaseStream.Length - br.BaseStream.Position);
                    if (readSize > 0)
                    {
                        var count1 = br.ReadInt32();

                        result.CNameHashes2 = new ulong[count1];
                        for (int i = 0; i < count1; i++)
                        {
                            result.CNameHashes2[i] = br.ReadUInt64();
                        }
                    }
                }
            }

            readSize = node.Size - ((int)reader.BaseStream.Position - node.Offset);
            Debug.Assert(readSize == 0);

            _stringList = null;

            result.Node = node;

            return(result);
        }