Beispiel #1
0
        public static ACT Load(string path)
        {
            FileInfo fi = new FileInfo(path);

            Logger.LogToFile(Logger.LogLevel.Info, "{0}", path);
            ACT act = new ACT();

            using (BEBinaryReader br = new BEBinaryReader(fi.OpenRead(), Encoding.Default))
            {
                if (br.ReadUInt32() != 0x12 ||
                    br.ReadUInt32() != 0x8 ||
                    br.ReadUInt32() != 0x1 ||
                    br.ReadUInt32() != 0x2)
                {
                    Logger.LogToFile(Logger.LogLevel.Error, "{0} isn't a valid ACT file", path);
                    return(null);
                }

                ACTNode a;

                while (br.BaseStream.Position < br.BaseStream.Length)
                {
                    Section tag = (Section)br.ReadUInt32();
                    int     _   = (int)br.ReadUInt32();

                    a = new ACTNode(tag);

                    switch (tag)
                    {
                    case Section.Name:      // 00 00 00 23
                        a.ActorType   = (ActorType)br.ReadByte();
                        a.RenderStyle = (RenderStyle)br.ReadByte();
                        a.Identifier  = br.ReadString();
                        if (a.Identifier.Length == 0)
                        {
                            a.Identifier = "NO_IDENTIFIER";
                        }
                        break;

                    case Section.Model:
                        a.Model = br.ReadString();
                        break;

                    case Section.Section37:     // 00 00 00 25
                        break;

                    case Section.Material:
                        a.Material = br.ReadString();
                        break;

                    case Section.SubLevelBegin:     // 00 00 00 29
                        break;

                    case Section.SubLevelEnd:
                        break;

                    case Section.Matrix:     // 00 00 00 2B
                        a.Transform = new Matrix3D(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                        break;

                    case Section.BoundingBox:     // 00 00 00 32
                        a.Bounds = new MeshExtents(new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()), new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()));
                        break;

                    case Section.EOF:
                        break;

                    default:
                        Console.WriteLine("Unknown ACT tag: {0} ({1} of {2})", tag, br.BaseStream.Position, br.BaseStream.Length);
                        return(null);
                    }

                    act.Sections.Add(a);
                }
            }

            return(act);
        }
Beispiel #2
0
        public static ACT Load(string path)
        {
            FileInfo fi = new FileInfo(path);
            Logger.LogToFile(Logger.LogLevel.Info, "{0}", path);
            ACT act = new ACT();

            using (BEBinaryReader br = new BEBinaryReader(fi.OpenRead(), Encoding.Default))
            {
                if (br.ReadUInt32() != 0x12 ||
                    br.ReadUInt32() != 0x8 ||
                    br.ReadUInt32() != 0x1 ||
                    br.ReadUInt32() != 0x2)
                {
                    Logger.LogToFile(Logger.LogLevel.Error, "{0} isn't a valid ACT file", path);
                    return null;
                }

                ACTNode a;

                while (br.BaseStream.Position < br.BaseStream.Length)
                {
                    Section tag = (Section)br.ReadUInt32();
                    int length = (int)br.ReadUInt32();

                    a = new ACTNode(tag);

                    switch (tag)
                    {
                        case Section.Name:  // 00 00 00 23
                            a.ActorType = (ActorType)br.ReadByte();
                            a.RenderStyle = (RenderStyle)br.ReadByte();
                            a.Identifier = br.ReadString();
                            if (a.Identifier.Length == 0) { a.Identifier = "NO_IDENTIFIER"; }
                            break;

                        case Section.Model:
                            a.Model = br.ReadString();
                            break;

                        case Section.Section37: // 00 00 00 25
                            break;

                        case Section.Material:
                            a.Material = br.ReadString();
                            break;

                        case Section.SubLevelBegin: // 00 00 00 29
                            break;

                        case Section.SubLevelEnd:
                            break;

                        case Section.Matrix: // 00 00 00 2B
                            a.Transform = new Matrix3D(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                            break;

                        case Section.BoundingBox: // 00 00 00 32
                            a.Bounds = new MeshExtents(new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()), new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()));
                            break;

                        case Section.EOF:
                            break;

                        default:
                            Console.WriteLine("Unknown ACT tag: {0} ({1} of {2})", tag, br.BaseStream.Position, br.BaseStream.Length);
                            return null;
                    }

                    act.sections.Add(a);
                }
            }

            return act;
        }