Example #1
0
        public ActorDefinition CreateActorDefinition(ActorEntry entry)
        {
            ActorDefinition definition = new ActorDefinition();

            definition.Name          = entry.DefinitionName;
            definition.FrameNameHash = entry.FrameNameHash;
            Definitions.Add(definition);
            return(definition);
        }
Example #2
0
        public void ReadFromFile(BinaryReader reader)
        {
            int poolLength = reader.ReadInt32();

            pool = new string(reader.ReadChars(poolLength));

            int hashesLength = reader.ReadInt32();

            definitions = new List <ActorDefinition>();

            for (int i = 0; i != hashesLength; i++)
            {
                ActorDefinition definition = new ActorDefinition(reader);
                int             pos        = definition.NamePos;
                definition.Name = pool.Substring(pos, pool.IndexOf('\0', pos) - pos);
                definitions.Add(definition);
            }

            // Offset is required for reading cutscene names later.
            long actorDataOffset = reader.BaseStream.Position + 4;

            filesize = reader.ReadInt32();
            const6   = reader.ReadInt16();
            const2   = reader.ReadInt16();
            const16  = reader.ReadInt32();
            size     = reader.ReadInt32(); //size of sector end.
            unk12    = reader.ReadInt32();
            unk13    = reader.ReadInt32();

            //if (const2 != 2)
            //    throw new Exception("const_6 is not 6");

            //if (const6 != 6)
            //    throw new Exception("const_2 is not 2");

            //if (const16 != 16)
            //    throw new Exception("const_16 is not 16");

            unk14 = reader.ReadInt32();

            if (const2 == 2)
            {
                int newpos = (unk14 / 4 - 2) * 4;
                if (unk14 - 8 != newpos)
                {
                    throw new FormatException("unk14-8 != newpos");
                }

                int count = (unk14 - 8) / sizeof(int);
                reader.BaseStream.Seek(unk14 - 12, SeekOrigin.Current);
                extraData = new List <ActorExtraData>();
                for (int i = 0; i < count; i++)
                {
                    extraData.Add(new ActorExtraData(reader));
                }
            }
            else
            {
                unk02 = reader.ReadBytes(size - unk14);
            }

            int itemCount = reader.ReadInt32();

            reader.BaseStream.Seek(itemCount * 4, SeekOrigin.Current);

            items = new List <ActorEntry>();
            for (int i = 0; i != itemCount; i++)
            {
                ActorEntry item = new ActorEntry(reader);
                item.Data = ExtraData[item.DataID];
                items.Add(item);
            }

            // Read how many cutscenes and check if we actually need to do anything.
            int numCutscenes = reader.ReadInt32();

            if (numCutscenes > 0)
            {
                long endPosition = 0;
                for (int i = 0; i < numCutscenes; i++)
                {
                    // Get the offset, then save the position so we can return.
                    uint offset          = reader.ReadUInt32();
                    long currentPosition = reader.BaseStream.Position;

                    // Seek to the offset and read cutscene name
                    reader.BaseStream.Seek(actorDataOffset + offset, SeekOrigin.Begin);
                    string cutsceneName   = StringHelpers.ReadString(reader);
                    ushort cutscene_unk01 = reader.ReadUInt16();

                    // End position so we can make sure we have reached the end of file.
                    endPosition = reader.BaseStream.Position;

                    // Return to our offset.
                    reader.BaseStream.Seek(currentPosition, SeekOrigin.Begin);
                }

                // Seek back to our end point and assert if we have not reached the end of file.
                reader.BaseStream.Position = endPosition;
            }

            Debug.Assert(reader.BaseStream.Position == reader.BaseStream.Length, "This is not the end of the file. Message Greavesy with this message and the name of the SDS you tried to read.");
        }
Example #3
0
        public void ReadFromFile(BinaryReader reader)
        {
            int poolLength = reader.ReadInt32();

            pool = new string(reader.ReadChars(poolLength));

            int hashesLength = reader.ReadInt32();

            definitions = new List <ActorDefinition>();

            for (int i = 0; i != hashesLength; i++)
            {
                ActorDefinition definition = new ActorDefinition(reader);
                int             pos        = definition.NamePos;
                definition.Name = pool.Substring(pos, pool.IndexOf('\0', pos) - pos);
                definitions.Add(definition);
            }

            filesize = reader.ReadInt32();
            const6   = reader.ReadInt16();
            const2   = reader.ReadInt16();
            const16  = reader.ReadInt32();
            size     = reader.ReadInt32(); //size of sector end.
            unk12    = reader.ReadInt32();
            unk13    = reader.ReadInt32();

            //if (const2 != 2)
            //    throw new Exception("const_6 is not 6");

            //if (const6 != 6)
            //    throw new Exception("const_2 is not 2");

            //if (const16 != 16)
            //    throw new Exception("const_16 is not 16");

            unk14 = reader.ReadInt32();

            if (const2 == 2)
            {
                int newpos = (unk14 / 4 - 2) * 4;
                if (unk14 - 8 != newpos)
                {
                    throw new FormatException("unk14-8 != newpos");
                }

                int count = (unk14 - 8) / sizeof(int);
                reader.BaseStream.Seek(unk14 - 12, SeekOrigin.Current);
                extraData = new List <ActorExtraData>();
                for (int i = 0; i < count; i++)
                {
                    extraData.Add(new ActorExtraData(reader));
                }
            }
            else
            {
                unk02 = reader.ReadBytes(size - unk14);
            }

            int itemCount = reader.ReadInt32();

            reader.BaseStream.Seek(itemCount * 4, SeekOrigin.Current);

            items = new List <ActorEntry>();
            for (int i = 0; i != itemCount; i++)
            {
                ActorEntry item = new ActorEntry(reader);
                item.Data = ExtraData[item.DataID];
                items.Add(item);
            }

            unk16 = reader.ReadInt32();

            //if (unk16 != 0)
            //    throw new Exception("UNK16 is not 0. Message Greavesy with this message and the name of the SDS you tried to read");
        }