예제 #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);
                }
        }
예제 #2
0
        public static GomObjectData ReadObject(DomClass domClass, GomBinaryReader reader)
        {
            GomObjectData result = new GomObjectData();
            IDictionary <string, object> resultDict = result.Dictionary;

            if (domClass != null)
            {
                resultDict["Script_Type"] = domClass;
            }
            else
            {
                resultDict["Script_Type"] = null;
            }

            resultDict["Script_TypeId"] = reader.ReadNumber();

            int numFields = (int)reader.ReadNumber();

            resultDict["Script_NumFields"] = numFields;

            ulong fieldId = 0;

            for (var i = 0; i < numFields; i++)
            {
                fieldId += reader.ReadNumber();
                DomField field     = DataObjectModel.Get <DomField>(fieldId);
                GomType  fieldType = null;
                if (field == null)
                {
                    // No idea what kind of field this is, so we'll skip it but we still need to read the data..
                    fieldType = GomTypeLoader.Load(reader, false);
                }
                else
                {
                    fieldType = field.GomType;

                    // Confirm the type matches
                    if (!field.ConfirmType(reader))
                    {
                        throw new InvalidOperationException("Unexpected field type for field " + field.Name);
                    }
                }

                // Read in the data
                object fieldValue = fieldType.ReadData(reader);

                // Save data to resulting script object
                string fieldName = null;
                if ((field != null) && (!String.IsNullOrEmpty(field.Name)))
                {
                    fieldName = field.Name;
                }
                else
                {
                    fieldName = DataObjectModel.GetStoredTypeName(fieldId);
                    if (fieldName == null)
                    {
                        fieldName = String.Format("field_{0:X8}", fieldId);
                    }
                }

                resultDict.Add(fieldName, fieldValue);
            }

            return(result);
        }