Esempio n. 1
0
        public static Character Read(BinaryReader br, uint dataStart)
        {
            Character result = new Character();

            long startPos = br.BaseStream.Position;

            result.Type      = (CharacterType)br.ReadUInt32();
            result.Signature = br.ReadUInt32();
            result.Unknown1  = br.ReadUInt16();
            result.ID        = br.ReadUInt16();
            result.Unknown2  = br.ReadUInt32();

            switch (result.Type)
            {
            case CharacterType.Shape:
                CharacterShape shape = new CharacterShape();
                shape.Bounds     = br.ReadRectF();
                shape.GeometryID = br.ReadUInt32();
                result.Data      = shape;
                break;

            case CharacterType.EditText:
                CharacterTextEdit textEdit = new CharacterTextEdit();
                textEdit.Bounds     = br.ReadRectF();
                textEdit.FontID     = br.ReadUInt32();
                textEdit.Alignment  = (TextAlignment)br.ReadUInt32();
                textEdit.Color      = br.ReadUInt32();
                textEdit.FontHeight = br.ReadSingle();
                textEdit.ReadOnly   = br.ReadUInt32();
                textEdit.Multiline  = br.ReadUInt32();
                textEdit.Wordwrap   = br.ReadUInt32();
                uint textPtr         = dataStart + br.ReadUInt32();
                uint variableNamePtr = dataStart + br.ReadUInt32();

                long thePos = br.BaseStream.Position;
                br.BaseStream.Position = textPtr;
                textEdit.Text          = br.ReadCStr();
                br.BaseStream.Position = variableNamePtr;
                textEdit.Variable      = br.ReadCStr();
                br.BaseStream.Position = thePos;

                result.Data = textEdit;
                break;

            case CharacterType.Font:
                CharacterFont font    = new CharacterFont();
                uint          namePtr = dataStart + br.ReadUInt32();
                long          cPos    = br.BaseStream.Position;
                br.BaseStream.Position = namePtr;
                font.Name = br.ReadCStr();
                br.BaseStream.Position = cPos;
                uint glyphCount = br.ReadUInt32();
                uint glyphPtr   = br.ReadUInt32();

                cPos = br.BaseStream.Position;
                br.BaseStream.Position = dataStart + glyphPtr;

                font.Glyphs = new Character[glyphCount];
                for (int i = 0; i < font.Glyphs.Length; i++)
                {
                    font.Glyphs[i] = Character.Read(br, dataStart);
                }

                br.BaseStream.Position = cPos;

                result.Data = font;
                break;

            case CharacterType.Button:
                CharacterButton button = new CharacterButton();
                button.MenuButton    = br.ReadUInt32();
                button.Bounds        = br.ReadRectF();
                button.TriangleCount = br.ReadInt32();
                button.VertexCount   = br.ReadInt32();
                button.VertexPtr     = br.ReadUInt32();
                button.TrianglePtr   = br.ReadUInt32();
                button.RecordCount   = br.ReadInt32();
                button.RecordPtr     = br.ReadUInt32();
                button.ActionCount   = br.ReadInt32();
                button.ActionPtr     = br.ReadUInt32();
                button.SoundPtr      = br.ReadUInt32();
                result.Data          = button;
                break;

            case CharacterType.Sprite:
                CharacterSprite sprite      = new CharacterSprite();
                uint            frameCount2 = br.ReadUInt32();
                uint            framePtr2   = br.ReadUInt32();
                sprite.Unknown1 = br.ReadUInt32();

                // TODO: Verify Frames
                br.BaseStream.Position = dataStart + framePtr2;
                sprite.Frames          = new Frame[frameCount2];
                for (int i = 0; i < sprite.Frames.Length; i++)
                {
                    sprite.Frames[i] = ReadFrame(br, dataStart);
                }

                result.Data = sprite;
                break;

            case CharacterType.Sound:
                CharacterSound sound = new CharacterSound();
                // TODO: Sound
                result.Data = sound;
                break;

            case CharacterType.Image:
                CharacterImage image = new CharacterImage();
                image.ImageID = br.ReadUInt32();     // TODO: Verify
                result.Data   = image;
                break;

            case CharacterType.Morph:
                CharacterMorph morph = new CharacterMorph();
                // TODO: Morph
                result.Data = morph;
                break;

            case CharacterType.Movie:
                CharacterMovie movie = new CharacterMovie();

                uint frameCount = br.ReadUInt32();
                uint framePtr   = br.ReadUInt32();
                movie.Unknown1 = br.ReadUInt32();
                uint characterCount = br.ReadUInt32();
                uint characterPtr   = br.ReadUInt32();
                movie.ScreenWidth          = br.ReadInt32();
                movie.ScreenHeight         = br.ReadInt32();
                movie.MillisecondsPerFrame = br.ReadInt32();
                uint importCount = br.ReadUInt32();
                uint importPtr   = br.ReadUInt32();
                uint exportCount = br.ReadUInt32();
                uint exportPtr   = br.ReadUInt32();
                movie.Unknown2 = br.ReadUInt32();

                //MessageBox.Show("Pos: " + br.BaseStream.Position.ToString("X8"));
                //MessageBox.Show("Pos: " + characterPtr.ToString("X8"));

                long myPos = br.BaseStream.Position;


                br.BaseStream.Position = dataStart + framePtr;
                movie.Frames           = new Frame[frameCount];
                for (int i = 0; i < movie.Frames.Length; i++)
                {
                    movie.Frames[i] = ReadFrame(br, dataStart);
                }

                br.BaseStream.Position = dataStart + characterPtr;

                uint[] CharacterPtrs = new uint[characterCount];
                for (int i = 0; i < characterCount; i++)
                {
                    CharacterPtrs[i] = dataStart + br.ReadUInt32();
                }

                movie.Characters = new Character[characterCount];
                for (int i = 0; i < movie.Characters.Length; i++)
                {
                    if (CharacterPtrs[i] == startPos)
                    {
                        movie.Characters[i] = result;
                    }
                    else
                    {
                        br.BaseStream.Position = CharacterPtrs[i];
                        movie.Characters[i]    = Character.Read(br, dataStart);
                    }
                }

                br.BaseStream.Position = dataStart + importPtr;
                movie.Imports          = new Import[importCount];
                for (int i = 0; i < movie.Imports.Length; i++)
                {
                    Import import = new Import();

                    uint importMoviePtr = dataStart + br.ReadUInt32();
                    uint importNamePtr  = dataStart + br.ReadUInt32();
                    import.CharacterID = br.ReadInt32();
                    import.Unknown1    = br.ReadUInt32();

                    long pos = br.BaseStream.Position;

                    br.BaseStream.Position = importMoviePtr;
                    import.ImportMovie     = br.ReadCStr();

                    br.BaseStream.Position = importNamePtr;
                    import.ImportName      = br.ReadCStr();

                    br.BaseStream.Position = pos;

                    movie.Imports[i] = import;
                }

                br.BaseStream.Position = dataStart + exportPtr;
                movie.Exports          = new Export[exportCount];
                for (int i = 0; i < movie.Exports.Length; i++)
                {
                    Export export = new Export();

                    uint exportNamePtr = dataStart + br.ReadUInt32();
                    export.CharacterID = br.ReadInt32();

                    long pos = br.BaseStream.Position;

                    br.BaseStream.Position = exportNamePtr;
                    export.ExportName      = br.ReadCStr();

                    br.BaseStream.Position = pos;

                    movie.Exports[i] = export;
                }

                br.BaseStream.Position = myPos;

                // TODO: Init Arrays

                result.Data = movie;
                break;

            case CharacterType.StaticText:
                CharacterStaticText staticText = new CharacterStaticText();
                // TODO: Static Text
                result.Data = staticText;
                break;

            case CharacterType.None:
                break;

            case CharacterType.Video:
                CharacterVideo video = new CharacterVideo();
                // TODO: Video
                result.Data = video;
                break;

            default:
                MessageBox.Show("Out of range Character Type: " + result.Type);
                break;
            }

            // TODO: Finish Read

            return(result);
        }
Esempio n. 2
0
 public static void clear_char_morph(CharacterMorph morph)
 {
     // tODO
 }