Exemple #1
0
 public void ReadArray(Reader reader)
 {
     if (Settings.s.game == Settings.Game.R2Revolution)
     {
         reader.ReadUInt32();
         arrayTypeNumber = reader.ReadByte();
         arrayLength     = reader.ReadByte();
         reader.ReadBytes(2);                 // padding
     }
     else
     {
         arrayTypeNumber = reader.ReadUInt32();
         arrayLength     = reader.ReadByte();
         reader.ReadBytes(3);                 // padding
     }
     arrayType = Settings.s.aiTypes.GetDsgVarType(arrayTypeNumber);
     if (DsgVarInfoEntry.GetDsgVarTypeFromArrayType(type) != arrayType)
     {
         Debug.LogWarning(currentbuf + " - " + type + " - " + arrayTypeNumber + " - " + arrayType + " - " + arrayLength + " - " + Pointer.Current(reader));
     }
     if (valueArray == null || arrayLength != valueArray.Length)
     {
         valueArray = new DsgVarValue[arrayLength];
         for (int i = 0; i < arrayLength; i++)
         {
             valueArray[i] = new DsgVarValue(arrayType);
         }
     }
     for (uint i = 0; i < arrayLength; i++)
     {
         valueArray[i].Read(reader);
     }
 }
Exemple #2
0
 public void WriteArray(Writer writer)
 {
     if (Settings.s.game == Settings.Game.R2Revolution)
     {
         Pointer.Goto(ref writer, Pointer.Current(writer) + 4);
         writer.Write((byte)arrayTypeNumber);
         writer.Write(arrayLength);
         writer.Write((byte)0);
         writer.Write((byte)0);
     }
     else
     {
         writer.Write(arrayTypeNumber);
         writer.Write(arrayLength);
         writer.Write((byte)0);
         writer.Write((byte)0);
         writer.Write((byte)0);
     }
     arrayType = Settings.s.aiTypes.GetDsgVarType(arrayTypeNumber);
     if (DsgVarInfoEntry.GetDsgVarTypeFromArrayType(type) != arrayType)
     {
         Debug.LogWarning(currentbuf + " - " + arrayTypeNumber + " - " + arrayType + " - " + arrayLength + " - " + Pointer.Current(writer));
     }
     if (valueArray != null && arrayLength == valueArray.Length)
     {
         for (uint i = 0; i < arrayLength; i++)
         {
             valueArray[i].Write(writer);
         }
     }
 }
Exemple #3
0
        public object[] ReadArray(Reader reader)
        {
            uint typeNumber;
            byte arraySize;

            if (Settings.s.game == Settings.Game.R2Revolution)
            {
                reader.ReadUInt32();
                typeNumber = reader.ReadByte();
                arraySize  = reader.ReadByte();
                reader.ReadBytes(2);                 // padding
            }
            else
            {
                typeNumber = reader.ReadUInt32();
                arraySize  = reader.ReadByte();
                reader.ReadBytes(3);                 // padding
            }
            DsgVarInfoEntry.DsgVarType itemType = Settings.s.aiTypes.GetDsgVarType(typeNumber);

            object[] resultList = new object[arraySize];

            for (uint i = 0; i < arraySize; i++)
            {
                resultList[i] = ReadValue(reader, itemType);
            }

            return(resultList);
        }
 // Create an empty array
 public Value(DsgVarInfoEntry.DsgVarType type, int length)
 {
     this.type = type;
     AsArray   = new Value[length];
     for (int i = 0; i < AsArray.Length; i++)
     {
         AsArray[i] = null;
     }
 }
            public void InitValue(OpenSpace.ROM.DsgVarValue value)
            {
                this.type = value.dsgVarType;

                if (DsgVarInfoEntry.GetDsgVarTypeFromArrayType(type) != DsgVarInfoEntry.DsgVarType.None)
                {
                    AsArray = new Value[value.ValueArrayLength];
                    for (int i = 0; i < AsArray.Length; i++)
                    {
                        AsArray[i] = null;
                    }
                }
            }
            public void InitValue(DsgVarValue value)
            {
                this.type = value.type;

                if (value.valueArray != null)
                {
                    AsArray = new Value[value.arrayLength];
                    for (int i = 0; i < AsArray.Length; i++)
                    {
                        AsArray[i] = new Value(value.valueArray[i]);
                    }
                }
            }
Exemple #7
0
        public object ReadValueFromBuffer(Reader reader, DsgVarInfoEntry.DsgVarType type, uint offsetInBuffer, Pointer buffer, DsgVarInfoEntry entry = null)
        {
            object returnValue = null;

            Pointer.DoAt(ref reader, buffer + offsetInBuffer, () => {
                if (entry != null)
                {
                    entry.debugValueOffset = Pointer.Current(reader);
                }
                returnValue = ReadValue(reader, type);
            });
            return(returnValue);
        }
Exemple #8
0
 public DsgVarValue(DsgVarInfoEntry.DsgVarType type)
 {
     this.type = type;
 }
Exemple #9
0
 public DsgVarValue(DsgVarInfoEntry.DsgVarType type, DsgMem dsgMem)
 {
     this.type   = type;
     this.dsgMem = dsgMem;
 }
Exemple #10
0
        private object ReadValue(Reader reader, DsgVarInfoEntry.DsgVarType type)
        {
            object returnValue = null;
            float  x, y, z;

            try {
                switch (type)
                {
                case DsgVarInfoEntry.DsgVarType.Boolean:
                    returnValue = reader.ReadBoolean(); break;

                case DsgVarInfoEntry.DsgVarType.Byte:
                    returnValue = reader.ReadSByte(); break;

                case DsgVarInfoEntry.DsgVarType.UByte:
                    returnValue = reader.ReadByte(); break;

                case DsgVarInfoEntry.DsgVarType.Float:
                    returnValue = reader.ReadSingle(); break;

                case DsgVarInfoEntry.DsgVarType.Int:
                    returnValue = reader.ReadInt32(); break;

                case DsgVarInfoEntry.DsgVarType.UInt:
                    returnValue = reader.ReadUInt32(); break;

                case DsgVarInfoEntry.DsgVarType.Short:
                    returnValue = reader.ReadInt16(); break;

                case DsgVarInfoEntry.DsgVarType.UShort:
                    returnValue = reader.ReadUInt16(); break;

                case DsgVarInfoEntry.DsgVarType.Vector:
                    x           = reader.ReadSingle();
                    y           = reader.ReadSingle();
                    z           = reader.ReadSingle();
                    returnValue = new Vector3(x, y, z);
                    break;

                case DsgVarInfoEntry.DsgVarType.Text:
                    uint textInd = reader.ReadUInt32();
                    returnValue = textInd;                             // MapLoader.Loader.fontStruct.GetTextForHandleAndLanguageID((int)textInd, 0);
                    break;

                case DsgVarInfoEntry.DsgVarType.Graph:
                    Pointer off_graph = Pointer.Read(reader);
                    Graph   graph     = Graph.FromOffsetOrRead(off_graph, reader);

                    returnValue = off_graph;                             //"Graph " + off_graph;

                    break;

                case DsgVarInfoEntry.DsgVarType.Waypoint:
                    Pointer off_waypoint = Pointer.Read(reader);
                    if (off_waypoint != null)
                    {
                        WayPoint wayPoint = WayPoint.FromOffsetOrRead(off_waypoint, reader);
                        returnValue = off_waypoint;
                        //returnValue = wayPoint;
                    }

                    break;

                case DsgVarInfoEntry.DsgVarType.Perso:
                case DsgVarInfoEntry.DsgVarType.GameMaterial:
                case DsgVarInfoEntry.DsgVarType.VisualMaterial:
                case DsgVarInfoEntry.DsgVarType.ObjectList:
                    returnValue = Pointer.Read(reader);

                    break;

                case DsgVarInfoEntry.DsgVarType.SuperObject:

                    returnValue = Pointer.Read(reader);

                    break;

                case DsgVarInfoEntry.DsgVarType.Array11:
                case DsgVarInfoEntry.DsgVarType.Array9:
                case DsgVarInfoEntry.DsgVarType.Array6:
                    MapLoader.Loader.print(type);
                    returnValue = reader.ReadInt32(); break;

                case DsgVarInfoEntry.DsgVarType.ActionArray:
                case DsgVarInfoEntry.DsgVarType.FloatArray:
                case DsgVarInfoEntry.DsgVarType.IntegerArray:
                case DsgVarInfoEntry.DsgVarType.PersoArray:
                case DsgVarInfoEntry.DsgVarType.SoundEventArray:
                case DsgVarInfoEntry.DsgVarType.SuperObjectArray:
                case DsgVarInfoEntry.DsgVarType.TextArray:
                case DsgVarInfoEntry.DsgVarType.TextRefArray:
                case DsgVarInfoEntry.DsgVarType.VectorArray:
                case DsgVarInfoEntry.DsgVarType.WayPointArray:
                    returnValue = ReadArray(reader);

                    break;

                default:
                    returnValue = reader.ReadInt32(); break;
                }
            } catch (Exception e) {
                returnValue = "Exception: " + e.Message;
                //returnValue = "Exception: " + e.Message + "\nBuffer: " + buffer + " - InfoEntry.Offset: " + infoEntry.offsetInBuffer + " - typeNumber: " + infoEntry.typeNumber + "\n" + e.StackTrace;
            }
            return(returnValue);
        }