Ejemplo n.º 1
0
        private static void LoadPrototypes()
        {
            File prototypeList = Assets.FindFile("/resources/systemgenerated/prototypes.info");

            using (var fs = prototypeList.Open())
                using (var br = new GomBinaryReader(fs, Encoding.UTF8))
                {
                    // Check PINF
                    int magicNum = br.ReadInt32();
                    if (magicNum != 0x464E4950)
                    {
                        throw new InvalidOperationException("prototypes.info does not begin with PINF");
                    }

                    br.ReadInt32(); // Skip 4 bytes

                    int numPrototypes = (int)br.ReadNumber();
                    int protoLoaded   = 0;
                    for (var i = 0; i < numPrototypes; i++)
                    {
                        ulong protId = br.ReadNumber();
                        byte  flag   = br.ReadByte();

                        if (flag == 1)
                        {
                            LoadPrototype(protId);
                            protoLoaded++;
                        }
                    }

                    Console.WriteLine("Loaded {0} prototype files", protoLoaded);
                }
        }
Ejemplo n.º 2
0
        public static GomType Load(GomBinaryReader reader, bool fromGom = true)
        {
            GomTypeId typeId = (GomTypeId)reader.ReadByte();

            GomTypeLoaders.IGomTypeLoader gomTypeLoader;
            if (!gomTypeLoaderMap.TryGetValue(typeId, out gomTypeLoader))
            {
                throw new InvalidOperationException(String.Format("Unknown GomType with Type ID {0}", (byte)typeId));
            }

            return(gomTypeLoader.Load(reader, fromGom));
        }
Ejemplo n.º 3
0
        private static void LoadBucketList()
        {
            File gomFile = Assets.FindFile("/resources/systemgenerated/buckets.info");

            using (var fs = gomFile.Open())
                using (var br = new GomBinaryReader(fs, Encoding.UTF8))
                {
                    br.ReadBytes(8); // Skip 8 header bytes

                    var c9 = br.ReadByte();
                    if (c9 != 0xC9)
                    {
                        throw new InvalidOperationException(String.Format("Unexpected character in buckets.info @ offset 0x8 - expected 0xC9 found {0:X2}", c9));
                    }

                    short numEntries = br.ReadInt16(Endianness.BigEndian);

                    for (var i = 0; i < numEntries; i++)
                    {
                        string fileName = br.ReadLengthPrefixString();
                        BucketFiles.Add(fileName);
                    }
                }
        }
Ejemplo n.º 4
0
        public virtual bool ConfirmType(GomBinaryReader reader)
        {
            byte typeByte = reader.ReadByte();

            return(typeByte == (byte)this.TypeId);
        }
Ejemplo n.º 5
0
        public void Parse(GomBinaryReader reader)
        {
            switch (this.ValueType)
            {
            case TypedValueType.Null:
                this.Value = null;
                break;

            case TypedValueType.Int8:
            case TypedValueType.Int16:
            case TypedValueType.Int24:
            case TypedValueType.Int32:
            case TypedValueType.Int40:
            case TypedValueType.Int48:
            case TypedValueType.Int56:
            case TypedValueType.Int64:
            {
                int numBytesToRead = ((byte)this.ValueType) - 0xB0 + 1;
                this.Value = reader.ReadVariableWidthUInt64(numBytesToRead);
            }
            break;

            case TypedValueType.UnicodeString:
            {
                int strLen = (int)reader.ReadByte();
                if ((strLen >= 0xB0) && (strLen <= 0xB7))
                {
                    strLen = (int)reader.ReadVariableWidthUInt64(strLen - 0xB0 + 1);
                }

                byte[] charData = reader.ReadBytes((int)strLen * 2);
                this.Value = Encoding.Unicode.GetString(charData);
            }
            break;

            case TypedValueType.CString:
            {
                int strLen = (int)reader.ReadByte();
                if ((strLen >= 0xB0) && (strLen <= 0xB7))
                {
                    strLen = (int)reader.ReadVariableWidthUInt64(strLen - 0xB0 + 1);
                }

                byte[] charData = reader.ReadBytes(strLen);
                this.Value = Encoding.UTF8.GetString(charData);
            }
            break;

            case TypedValueType.Array:
            case TypedValueType.Array2:
            {
                int arrayLen = (int)reader.ReadByte();
                if ((arrayLen >= 0xB0) && (arrayLen <= 0xB7))
                {
                    arrayLen = (int)reader.ReadVariableWidthUInt64(arrayLen - 0xB0 + 1);
                }

                List <TypedValue> arrayValues = new List <TypedValue>(arrayLen);
                for (var i = 0; i < arrayLen; i++)
                {
                    var val = reader.ReadTypedValue();
                    arrayValues.Add(val);
                }
                this.Value = arrayValues;

                // Array type 2 has a trailing byte for some reason
                if (this.ValueType == TypedValueType.Array2)
                {
                    reader.ReadByte();
                }
            }
            break;

            case TypedValueType.BizarroFieldType:
            case TypedValueType.FieldType:
            {
                this.Value = reader.ReadGomType();
            }
            break;

            default:
                throw new InvalidOperationException(String.Format("Unexpected TypedValue Type: {0:X}", this.ValueType));
            }
        }