コード例 #1
0
        public static Placeable Create(GFFStruct templateRoot)
        {
            GameObject gameObject;

            //get the resource reference for this object, which we'll use as it's in-engine name
            string name = templateRoot["TemplateResRef"].GetValue <string>();

            //get the appearance row number in placeables.2da
            int appearance = (int)templateRoot["Appearance"].GetValue <uint>();

            //get the model name for this appearance id
            string modelRef = Resources.Load2DA("placeables")[appearance, "modelname"];

            if (modelRef == "PLC_Invis")
            {
                gameObject = new GameObject(name);
            }
            else
            {
                gameObject      = Resources.LoadModel(modelRef);
                gameObject.name = name;
            }

            //add the template component to the new object
            Placeable placeable = gameObject.AddComponent <Placeable>();

            placeable.templateRoot = templateRoot;

            return(placeable);
        }
コード例 #2
0
        private Module(string name)
        {
            rim  = new RIMObject(Resources.ModuleDirectory + "\\" + name + ".rim");
            srim = new RIMObject(Resources.ModuleDirectory + "\\" + name + "_s.rim");

            ifo = new GFFLoader(rim.GetResource("module", ResourceType.IFO)).GetRoot();
            string areaName = ifo["Mod_Entry_Area"].GetValue <string>();

            entryPosition = new Vector3(ifo["Mod_Entry_X"].GetValue <float>(), ifo["Mod_Entry_Z"].GetValue <float>(), ifo["Mod_Entry_Y"].GetValue <float>());

            are = new GFFLoader(rim.GetResource(areaName, ResourceType.ARE)).GetRoot();
            git = new GFFLoader(rim.GetResource(areaName, ResourceType.GIT)).GetRoot();

            Dictionary <string, Vector3> layout = Resources.LoadLayout(areaName);

            daddy = new GameObject(name);
            charsH.transform.parent  = daddy.transform;
            doorsH.transform.parent  = daddy.transform;
            placesH.transform.parent = daddy.transform;
            foreach (var value in layout)
            {
                string resref = value.Key.ToLower();

                GameObject room = Resources.LoadModel(resref);
                room.transform.position = value.Value;
                room.transform.parent   = daddy.transform;
            }

            int    musicId       = git["AreaProperties"]["MusicDay"].GetValue <int>();
            string musicResource = Resources.Load2DA("ambientmusic")[musicId, "resource"];

            ambientMusic = Resources.LoadAudio(musicResource);
        }
コード例 #3
0
        private GFFStruct[] ReadList(long offset)
        {
            long pos = file.Position;

            file.Position = lioffset + offset;

            //read the size of the list
            byte[] buffer = new byte[DWORD_SIZE];
            file.Read(buffer, 0, buffer.Length);
            uint count = BitConverter.ToUInt32(buffer, 0);

            //read the elements of the list (each being 1 uint index into the struct array)
            buffer = new byte[DWORD_SIZE * count];
            file.Read(buffer, 0, buffer.Length);

            file.Position = pos;

            GFFStruct[] structs = new GFFStruct[count];
            for (int i = 0, j = 0; i < count; i++, j += DWORD_SIZE)
            {
                structs[i] = new GFFStruct(null, GFFStruct.FieldType.Struct, ReadStruct(BitConverter.ToUInt32(buffer, j)));
            }

            return(structs);
        }
コード例 #4
0
        public static Character Create(GFFStruct templateRoot)
        {
            GameObject gameObject;

            //get the resource reference for this object, which we'll use as it's in-engine name
            string name = templateRoot["TemplateResRef"].GetValue <string>();

            //get the appearance row number in appearance.2da
            int appearance = templateRoot["Appearance_Type"].GetValue <ushort>();

            //get the model name for this appearance id
            string modelRef = Resources.Load2DA("appearance")[appearance, "modela"];

            if (modelRef == null)
            {
                modelRef = Resources.Load2DA("appearance")[appearance, "race"];
            }
            string texRef = Resources.Load2DA("appearance")[appearance, "texa"];

            //create a new game object and load the model into the scene
            gameObject      = Resources.LoadModel(modelRef);
            gameObject.name = name;

            //add the templateRoot component to the new object
            Character character = gameObject.AddComponent <Character>();

            character.templateRoot = templateRoot;

            return(character);
        }
コード例 #5
0
        public static Item Create(GFFStruct templateRoot)
        {
            GameObject gameObject;

            //get the resource reference for this object, which we'll use as it's in-engine name
            string name = templateRoot["TemplateResRef"].GetValue <string>();

            //get the appearance row number in baseitems.2da
            int appearance = templateRoot["BaseItem"].GetValue <int>();
            int modelVar   = templateRoot["ModelVariation"].GetValue <byte>();

            //get the model name for this appearance id
            string modelRef = Resources.Load2DA("baseitems")[appearance, "defaultmodel"];

            //update the model name with the correct variant
            modelRef = modelRef.Replace("001", modelVar.ToString().PadLeft(3, '0'));

            //create a new game object and load the model into the scene
            gameObject      = Resources.LoadModel(modelRef);
            gameObject.name = name;

            //add the template component to the new object
            Item item = gameObject.AddComponent <Item>();

            item.templateRoot = templateRoot;

            //get the icon texture
            string iconRef = "i" + modelRef;

            Texture2D iconTex = Resources.LoadTexture2D(iconRef);

            item.icon = Sprite.Create(iconTex, new Rect(0, 0, iconTex.width, iconTex.height), new Vector2(iconTex.width / 2, iconTex.height / 2));

            int slots = 0;

            if (int.TryParse(Resources.Load2DA("baseitems")[appearance, "equipableslots"].Remove(0, 2), NumberStyles.HexNumber, new CultureInfo("en-US"), out slots))
            {
                item.equipableSlots = slots;
            }

            return(item);
        }
コード例 #6
0
        public GFFLoader(Stream file)
        {
            this.file = file;

            //read the file type and version
            byte[] buffer = new byte[DWORD_SIZE * 14];
            file.Read(buffer, 0, DWORD_SIZE * 14);

            string filetype = Encoding.ASCII.GetString(buffer, 0, 4);
            string filever  = Encoding.ASCII.GetString(buffer, 4, 4);

            //get the offset to and number of structs in the file
            structoffset = BitConverter.ToUInt32(buffer, 8);
            structcount  = BitConverter.ToInt32(buffer, 12);

            //get the offset to and number of fields in the file
            fieldoffset = BitConverter.ToUInt32(buffer, 16);
            fieldcount  = BitConverter.ToInt32(buffer, 20);

            //get the offset to and number of labels in the file
            labeloffset = BitConverter.ToUInt32(buffer, 24);
            labelcount  = BitConverter.ToInt32(buffer, 28);

            //get the offset to and number of field data in the file
            fdoffset = BitConverter.ToUInt32(buffer, 32);
            fdcount  = BitConverter.ToInt32(buffer, 36);

            //get the offset to and number of field indices in the file
            fioffset = BitConverter.ToUInt32(buffer, 40);
            ficount  = BitConverter.ToInt32(buffer, 44);

            //get the offset to and number of list indices in the file
            lioffset = BitConverter.ToUInt32(buffer, 48);
            licount  = BitConverter.ToInt32(buffer, 52);

            //read the top level struct, recursively reading the file
            TopStruct = new GFFStruct(null, GFFStruct.FieldType.Struct, ReadStruct(0));
        }
コード例 #7
0
        public static Door Create(GFFStruct templateRoot)
        {
            GameObject gameObject;

            //get the resource reference for this object, which we'll use as it's in-engine name
            string name = templateRoot["TemplateResRef"].GetValue <string>();

            //get the appearance row number in genericdoors.2da
            int appearance = templateRoot["GenericType"].GetValue <byte>();

            //get the model name for this door id
            string modelRef = Resources.Load2DA("genericdoors")[appearance, "modelname"];

            //create a new game object and load the model into the scene
            gameObject      = Resources.LoadModel(modelRef);
            gameObject.name = name;

            //add the template component to the new object
            Door door = gameObject.AddComponent <Door>();

            door.templateRoot = templateRoot;

            return(door);
        }