Exemplo n.º 1
0
            public DsgVarEditableEntry(int number, DsgVarInfoEntry entry)
            {
                this.number = number;
                this.entry  = entry;
                //print(entry.typeNumber + " - " + entry.type + " - " + entry.debugValueOffset + " - " + entry.value);

                switch (entry.type)
                {
                case DsgVarInfoEntry.DsgVarType.Boolean: this.valueAsBool = (bool)entry.value;  break;

                case DsgVarInfoEntry.DsgVarType.Int:     this.valueAsInt = (int)entry.value;  break;

                case DsgVarInfoEntry.DsgVarType.UInt:    this.valueAsUInt = (uint)entry.value;  break;

                case DsgVarInfoEntry.DsgVarType.Short:   this.valueAsShort = (short)entry.value;  break;

                case DsgVarInfoEntry.DsgVarType.UShort:  this.valueAsUShort = (ushort)entry.value;  break;

                case DsgVarInfoEntry.DsgVarType.Byte:    this.valueAsSByte = (sbyte)entry.value;  break;

                case DsgVarInfoEntry.DsgVarType.UByte:   this.valueAsByte = (byte)entry.value;  break;

                case DsgVarInfoEntry.DsgVarType.Float:   this.valueAsFloat = (float)entry.value;  break;

                case DsgVarInfoEntry.DsgVarType.Vector:  this.valueAsVector = (Vector3)entry.value;  break;

                case DsgVarInfoEntry.DsgVarType.Text:    this.valueAsUInt = (uint)entry.value;  break;

                case DsgVarInfoEntry.DsgVarType.Perso:
                    if (entry.value != null && entry.value is Pointer)
                    {
                        Perso perso = MapLoader.Loader.persos.FirstOrDefault(p => (p.SuperObject != null && p.SuperObject.offset == (Pointer)entry.value));   // find perso that belongs to the superobject
                        if (perso != null)
                        {
                            this.valueAsPersoGao = perso.Gao;
                        }
                    }
                    break;

                case DsgVarInfoEntry.DsgVarType.SuperObject:
                    if (entry.value != null)
                    {
                        SuperObject spo = MapLoader.Loader.superObjects.FirstOrDefault(p => (p.offset != null && p.offset == (Pointer)entry.value));
                        if (spo != null)
                        {
                            this.valueAsSuperObjectGao = spo.Gao;
                        }
                    }
                    break;

                case DsgVarInfoEntry.DsgVarType.Waypoint:

                    if (entry.value != null)
                    {
                        WayPoint wp = null;
                        if (entry.value is Pointer)
                        {
                            wp = WayPoint.FromOffset(entry.value as Pointer);
                            //wp = (WayPoint)entry.value;
                        }

                        if (wp != null)
                        {
                            this.valueAsWaypointGao = wp.Gao;
                        }
                    }
                    break;
                }

                if (entry.initialValue != null)
                {
                    switch (entry.type)
                    {
                    case DsgVarInfoEntry.DsgVarType.Boolean: this.valueAsBool_initial = (bool)entry.initialValue;         break;

                    case DsgVarInfoEntry.DsgVarType.Int:     this.valueAsInt_initial = (int)entry.initialValue;          break;

                    case DsgVarInfoEntry.DsgVarType.UInt:    this.valueAsUInt_initial = (uint)entry.initialValue;         break;

                    case DsgVarInfoEntry.DsgVarType.Short:   this.valueAsShort_initial = (short)entry.initialValue;        break;

                    case DsgVarInfoEntry.DsgVarType.UShort:  this.valueAsUShort_initial = (ushort)entry.initialValue;       break;

                    case DsgVarInfoEntry.DsgVarType.Byte:    this.valueAsSByte_initial = (sbyte)entry.initialValue;        break;

                    case DsgVarInfoEntry.DsgVarType.UByte:   this.valueAsByte_initial = (byte)entry.initialValue;         break;

                    case DsgVarInfoEntry.DsgVarType.Float:   this.valueAsFloat_initial = (float)entry.initialValue;        break;

                    case DsgVarInfoEntry.DsgVarType.Vector:  this.valueAsVector_initial = (Vector3)entry.initialValue;      break;

                    case DsgVarInfoEntry.DsgVarType.Text:    this.valueAsUInt_initial = (uint)entry.initialValue;       break;

                    case DsgVarInfoEntry.DsgVarType.Perso:
                        if (entry.initialValue != null)
                        {
                            Perso perso = MapLoader.Loader.persos.FirstOrDefault(p => p.SuperObject.offset == (Pointer)entry.initialValue);
                            if (perso != null)
                            {
                                this.valueAsPersoGao_initial = perso.Gao;
                            }
                        }
                        break;

                    case DsgVarInfoEntry.DsgVarType.SuperObject:
                        if (entry.initialValue != null)
                        {
                            SuperObject spo = MapLoader.Loader.superObjects.FirstOrDefault(p => p.offset == (Pointer)entry.initialValue);
                            if (spo != null)
                            {
                                this.valueAsSuperObjectGao_initial = spo.Gao;
                            }
                        }
                        break;

                    case DsgVarInfoEntry.DsgVarType.Waypoint:

                        if (entry.initialValue != null)
                        {
                            WayPoint wp = null;
                            if (entry.initialValue is Pointer)
                            {
                                wp = WayPoint.FromOffset(entry.initialValue as Pointer);
                                //wp = (WayPoint)entry.initialValue;
                            }

                            if (wp != null)
                            {
                                this.valueAsWaypointGao_initial = wp.Gao;
                            }
                        }
                        break;
                    }
                }
            }
Exemplo n.º 2
0
        public static List <SuperObject> Read(EndianBinaryReader reader, Pointer off_so, bool parseSiblings = true, bool parseChildren = true, SuperObject parent = null)
        {
            MapLoader          l            = MapLoader.Loader;
            List <SuperObject> superObjects = new List <SuperObject>();

            if (IsParsed(off_so))
            {
                return(null);
            }
            bool isFirstNode    = true;
            bool hasNextBrother = false;
            bool isValidNode    = true;

            while (isFirstNode || (hasNextBrother && parseSiblings))
            {
                SuperObject so = new SuperObject(off_so);
                superObjects.Add(so);   // Local list of superobjects (only this & siblings)
                l.superObjects.Add(so); // Global list of superobjects (all)
                if (parent != null)
                {
                    parent.children.Add(so);
                    so.parent = parent;
                }
                hasNextBrother      = false;
                so.type             = reader.ReadUInt32();
                so.off_data         = Pointer.Read(reader);
                so.off_child_first  = Pointer.Read(reader);
                so.off_child_last   = Pointer.Read(reader);
                so.num_children     = reader.ReadUInt32();
                so.off_brother_next = Pointer.Read(reader);
                so.off_brother_prev = Pointer.Read(reader);
                so.off_parent       = Pointer.Read(reader);
                so.off_matrix       = Pointer.Read(reader);
                //R3Pointer.Read(reader); // a copy of the matrix right after, at least in R3GC
                Vector3    pos   = Vector3.zero;
                Vector3    scale = Vector3.one;
                Quaternion rot   = Quaternion.identity;
                if (so.off_matrix != null)
                {
                    Pointer curPos = Pointer.Goto(ref reader, so.off_matrix);
                    so.matrix = Matrix.Read(reader, so.off_matrix);
                    pos       = so.matrix.GetPosition(convertAxes: true);
                    rot       = so.matrix.GetRotation(convertAxes: true);
                    scale     = so.matrix.GetScale(convertAxes: true);
                    Pointer.Goto(ref reader, curPos);
                }
                switch (so.type)
                {
                case 0x20:     // IPO
                    Pointer.Goto(ref reader, so.off_data);
                    so.data = IPO.Read(reader, so.off_data, so);
                    break;

                case 0x40:     // IPO
                    l.print("IPO with code 0x40 at offset " + String.Format("0x{0:X}", so.offset.offset));
                    Pointer.Goto(ref reader, so.off_data);
                    so.data = IPO.Read(reader, so.off_data, so);
                    break;

                case 0x02:     // e.o.
                    Pointer.Goto(ref reader, so.off_data);
                    so.data = Perso.Read(reader, so.off_data, so);
                    break;

                case 0x01:     // world superobject
                    so.data = World.New(so);
                    //print("parsing world superobject with " + num_children + " children");
                    break;

                case 0x04:     // sector
                    Pointer.Goto(ref reader, so.off_data);
                    so.data = Sector.Read(reader, so.off_data, so);
                    break;

                default:
                    l.print("Unknown SO type " + so.type + " at offset " + String.Format("0x{0:X}", so.offset.offset));
                    isValidNode = false;
                    break;
                }
                if (so.Gao != null)
                {
                    if (parent != null)
                    {
                        so.Gao.transform.parent = parent.Gao.transform;
                    }
                    so.Gao.transform.localPosition = pos;
                    so.Gao.transform.localRotation = rot;
                    so.Gao.transform.localScale    = scale;
                }
                isFirstNode = false;
                if (isValidNode)
                {
                    if (parseChildren && so.num_children > 0 && so.off_child_first != null)
                    {
                        //if (type == 0x01) print("parsing children now");
                        Pointer off_current = Pointer.Goto(ref reader, so.off_child_first);
                        SuperObject.Read(reader, so.off_child_first, true, true, so);
                        //R3Pointer.Goto(ref reader, off_current);
                    }
                    if (so.off_brother_next != null && !IsParsed(so.off_brother_next))
                    {
                        hasNextBrother = true;
                        Pointer.Goto(ref reader, so.off_brother_next);
                        off_so = so.off_brother_next;
                    }
                }
            }
            return(superObjects);
        }