public LgbGroup(LgbFile parent, byte[] buffer, int offset)
        {
            this.Parent = parent;
            this.Header = buffer.ToStructure <HeaderData>(offset);
            this.Name   = buffer.ReadString(offset + Header.GroupNameOffset);

            //uint[] Unknown = new uint[100];
            //System.Buffer.BlockCopy(buffer, offset + System.Runtime.InteropServices.Marshal.SizeOf<HeaderData>(), Unknown, 0, 400);


            int entriesOffset = offset + Header.EntriesOffset;

            Entries = new ILgbEntry[Header.EntryCount];
            for (int i = 0; i < Header.EntryCount; ++i)
            {
                int          entryOffset = entriesOffset + BitConverter.ToInt32(buffer, entriesOffset + i * 4);
                LgbEntryType type        = (LgbEntryType)BitConverter.ToInt32(buffer, entryOffset);

                try {
                    switch (type)
                    {
                    case LgbEntryType.Model:
                        Entries[i] = new LgbModelEntry(Parent.File.Pack.Collection, buffer, entryOffset);
                        break;

                    case LgbEntryType.Gimmick:
                    case LgbEntryType.SharedGroup15:
                        Entries[i] = new LgbGimmickEntry(Parent.File.Pack.Collection, buffer, entryOffset);
                        break;

                    case LgbEntryType.EventObject:
                        Entries[i] = new LgbEventObjectEntry(Parent.File.Pack.Collection, buffer, entryOffset);
                        break;

                    case LgbEntryType.Light:
                        Entries[i] = new LgbLightEntry(Parent.File.Pack.Collection, buffer, entryOffset);
                        break;

                    case LgbEntryType.EventNpc:
                        Entries[i] = new LgbENpcEntry(Parent.File.Pack.Collection, buffer, entryOffset);
                        break;

                    case LgbEntryType.Vfx:
                        Entries[i] = new LgbVfxEntry(Parent.File.Pack.Collection, buffer, entryOffset);
                        break;

                    default:
                        // TODO: Work out other parts.
                        //Debug.WriteLine($"{Parent.File.Path} {type} at 0x{entryOffset:X} in {Name}: Can't read type.");
                        break;
                    }
                } catch (Exception ex) {
                    Debug.WriteLine($"{Parent.File.Path} {type} at 0x{entryOffset:X} in {Name} failure: {ex.Message}");
                }
            }
        }
Example #2
0
        public LgbGroup(LgbFile parent, byte[] buffer, int offset)
        {
            this.Parent = parent;
            this.Header = buffer.ToStructure <HeaderData>(offset);
            this.Name   = buffer.ReadString(offset + Header.GroupNameOffset);

            //byte[] Unknown = new byte[100];
            //System.Buffer.BlockCopy(buffer, offset + System.Runtime.InteropServices.Marshal.SizeOf<HeaderData>(), Unknown, 0, 100);

            var entriesOffset = offset + Header.EntriesOffset;

            Entries = new ILgbEntry[Header.EntryCount];
            for (var i = 0; i < Header.EntryCount; ++i)
            {
                var entryOffset = entriesOffset + BitConverter.ToInt32(buffer, entriesOffset + i * 4);

                try {
                    var type = (LgbEntryType)BitConverter.ToInt32(buffer, entryOffset);
                    switch (type)
                    {
                    case LgbEntryType.Model:
                        Entries[i] = new LgbModelEntry(Parent.File.Pack.Collection, buffer, entryOffset);
                        break;

                    case LgbEntryType.Gimmick:
                        Entries[i] = new LgbGimmickEntry(Parent.File.Pack.Collection, buffer, entryOffset);
                        break;

                    case LgbEntryType.EventObject:
                        Entries[i] = new LgbEventObjectEntry(Parent.File.Pack.Collection, buffer, entryOffset);
                        break;

                    case LgbEntryType.Light:
                        Entries[i] = new LgbLightEntry(Parent.File.Pack.Collection, buffer, entryOffset);
                        break;

                    default:
                        System.Diagnostics.Trace.WriteLine(string.Format("{0}: Type {1} at 0x{2:X} in {3}", Parent.File.Path, type, entryOffset, Name));
                        break;
                        // TODO: Work out other parts.
                    }
                } catch (Exception ex) {
                    System.Diagnostics.Debug.WriteLine(ex.ToString());
                }
            }
        }