Example #1
0
        public SCN0GroupNode GetOrCreateFolder(SCN0GroupNode.GroupType type)
        {
            int typeID = (int)type;

            if (typeID < 0 || typeID >= 5)
            {
                return(null);
            }

            if (_groups[typeID] == null)
            {
                AddChild(_groups[typeID] = new SCN0GroupNode(type));
            }

            return(_groups[typeID]);
        }
Example #2
0
        public SCN0EntryNode CreateResource(SCN0GroupNode.GroupType type, string name)
        {
            SCN0GroupNode group = GetOrCreateFolder(type);

            if (group == null)
            {
                return(null);
            }

            Type          t = SCN0GroupNode._types[(int)type];
            SCN0EntryNode n = Activator.CreateInstance(t) as SCN0EntryNode;

            n.Name = group.FindName(name);
            group.AddChild(n);

            return(n);
        }
Example #3
0
        public SCN0GroupNode GetOrCreateFolder <T>() where T : SCN0EntryNode
        {
            string groupName;

            if (typeof(T) == typeof(SCN0LightSetNode))
            {
                groupName = "LightSet(NW4R)";
            }
            else if (typeof(T) == typeof(SCN0AmbientLightNode))
            {
                groupName = "AmbLights(NW4R)";
            }
            else if (typeof(T) == typeof(SCN0LightNode))
            {
                groupName = "Lights(NW4R)";
            }
            else if (typeof(T) == typeof(SCN0FogNode))
            {
                groupName = "Fogs(NW4R)";
            }
            else if (typeof(T) == typeof(SCN0CameraNode))
            {
                groupName = "Cameras(NW4R)";
            }
            else
            {
                return(null);
            }

            SCN0GroupNode group = null;

            foreach (SCN0GroupNode node in Children)
            {
                if (node.Name == groupName)
                {
                    group = node; break;
                }
            }

            if (group == null)
            {
                AddChild(group = new SCN0GroupNode(groupName));
            }

            return(group);
        }
Example #4
0
        protected override void OnPopulate()
        {
            ResourceGroup *group = Header->Group;
            SCN0GroupNode  g;

            for (int i = 0; i < group->_numEntries; i++)
            {
                string name = group->First[i].GetName();
                (g = new SCN0GroupNode(name)).Initialize(this, new DataSource(group->First[i].DataAddress, 0));
                if (name == "LightSet(NW4R)")
                {
                    for (int x = 0; x < Header->_lightSetCount; x++)
                    {
                        new SCN0LightSetNode().Initialize(g, new DataSource(&Header->LightSets[x], SCN0LightSet.Size));
                    }
                }
                else if (name == "AmbLights(NW4R)")
                {
                    for (int x = 0; x < Header->_ambientCount; x++)
                    {
                        new SCN0AmbientLightNode().Initialize(g, new DataSource(&Header->AmbientLights[x], SCN0AmbientLight.Size));
                    }
                }
                else if (name == "Lights(NW4R)")
                {
                    for (int x = 0; x < Header->_lightCount; x++)
                    {
                        new SCN0LightNode().Initialize(g, new DataSource(&Header->Lights[x], SCN0Light.Size));
                    }
                }
                else if (name == "Fogs(NW4R)")
                {
                    for (int x = 0; x < Header->_fogCount; x++)
                    {
                        new SCN0FogNode().Initialize(g, new DataSource(&Header->Fogs[x], SCN0Fog.Size));
                    }
                }
                else if (name == "Cameras(NW4R)")
                {
                    for (int x = 0; x < Header->_cameraCount; x++)
                    {
                        new SCN0CameraNode().Initialize(g, new DataSource(&Header->Cameras[x], SCN0Camera.Size));
                    }
                }
            }
        }
Example #5
0
        public T CreateResource <T>(string name) where T : SCN0EntryNode
        {
            SCN0GroupNode group = GetOrCreateFolder <T>();

            if (group == null)
            {
                return(null);
            }

            T n = Activator.CreateInstance <T>();

            n.Name = group.FindName(name);
            group.AddChild(n);

            n._realIndex = n.Index;
            n._nodeIndex = group.UsedChildren.IndexOf(n);

            return(n);
        }
        public void AttachNodes()
        {
            SCN0Node      node    = (SCN0Node)Parent.Parent;
            SCN0GroupNode g       = node.GetFolder <SCN0LightNode>();
            bint *        strings = Data->StringOffsets;

            if (g != null && !_replaced)
            {
                for (int i = 0; i < Data->_numLights && i < 8; i++)
                {
                    _lights[i] = g.FindChild(new String((sbyte *)strings + strings[i]), false) as SCN0LightNode;
                }
            }
            g = node.GetFolder <SCN0AmbientLightNode>();
            if (g != null && Data->_ambNameOffset != 0 && !_replaced)
            {
                _ambient = g.FindChild(Data->AmbientString, false) as SCN0AmbientLightNode;
            }
        }
Example #7
0
        public override void OnRebuild(VoidPtr address, int length, bool force)
        {
            //Create data lengths for each group
            //group, lightset, ambient, light, fog, camera
            int[] lengths = new int[6];

            //Create entry counts for each group
            //lightset, ambient, light, fog, camera
            short[] counts = new short[5];

            //Create addresses for all data sections
            //group, entry, key, color, vis
            VoidPtr[] dataAddrs = new VoidPtr[5];

            //Write header and retrieve main resource group
            ResourceGroup *group;

            if (_version == 5)
            {
                SCN0v5 *header = (SCN0v5 *)address;

                header->_origPathOffset = 0;
                header->_frameCount     = (ushort)_numFrames;
                header->_specLightCount = (ushort)_specLights;
                header->_loop           = _loop ? 1 : 0;
                header->_pad            = 0;
                header->_dataOffset     = SCN0v5.Size;

                group = header->Group;
            }
            else
            {
                SCN0v4 *header = (SCN0v4 *)address;

                header->_origPathOffset = 0;
                header->_frameCount     = (ushort)_numFrames;
                header->_specLightCount = (ushort)_specLights;
                header->_loop           = _loop ? 1 : 0;
                header->_pad            = 0;
                header->_dataOffset     = SCN0v4.Size;

                group = header->Group;
            }

            //Create resource group
            *group = new ResourceGroup(Children.Count);
            lengths[0] = group->_totalSize;

            //Get pointer to main resource entry buffer
            ResourceEntry *entry = group->First;

            //Get pointer to resource groups for each child group
            dataAddrs[0] = group->EndAddress;

            //Get pointer to the address for headers
            for (int i = 0; i < 4; i++)
            {
                dataAddrs[i + 1] = dataAddrs[i];
                foreach (SCN0GroupNode g in Children)
                {
                    if (i == 0)
                    {
                        dataAddrs[i + 1] += g._dataLengths[i];
                    }
                    else
                    {
                        foreach (SCN0EntryNode e in g.Children)
                        {
                            dataAddrs[i + 1] += (i == 1 ? e._calcSize : e._dataLengths[i - 2]);
                        }
                    }
                }
            }

            //Use an index array to remap and write groups in proper order.
            int[] indices = new int[] { -1, -1, -1, -1, -1 };

            //Loop through groups and set index, length and count
            foreach (SCN0GroupNode g in Children)
            {
                int i = (int)g._type;
                indices[i]     = g.Index;
                lengths[i + 1] = g._dataLengths[1];
                counts[i]      = (short)g.Children.Count;
            }

            //Now loop through indices to get each group and write it
            for (int i = 0; i < 5; i++)
            {
                //Make sure the group exists
                SCN0GroupNode g = indices[i] >= 0 ? Children[indices[i]] as SCN0GroupNode : null;
                if (g != null)
                {
                    //Set offset to group in main resource group
                    (entry++)->_dataOffset = (int)dataAddrs[0] - (int)group;

                    //Set addresses for rebuild
                    for (int x = 0; x < 4; x++)
                    {
                        g._addrs[x] = dataAddrs[x + 1];
                    }

                    //Rebuild focusing on the resource group
                    g.Rebuild(dataAddrs[0], g._dataLengths[0], true);

                    //Increment addresses
                    lengths[0] += g._dataLengths[0];
                    for (int x = 0; x < 5; x++)
                    {
                        dataAddrs[x] += g._dataLengths[x];
                    }
                }
            }

            //Set header values
            if (_version == 5)
            {
                SCN0v5 *header = (SCN0v5 *)address;
                header->_lightSetCount = counts[0];
                header->_ambientCount  = counts[1];
                header->_lightCount    = counts[2];
                header->_fogCount      = counts[3];
                header->_cameraCount   = counts[4];
                header->Set(lengths[0], lengths[1], lengths[2], lengths[3], lengths[4], lengths[5]);

                if (_userEntries.Count > 0)
                {
                    _userEntries.Write(header->UserData = dataAddrs[4]);
                }
            }
            else
            {
                SCN0v4 *header = (SCN0v4 *)address;
                header->_lightSetCount = counts[0];
                header->_ambientCount  = counts[1];
                header->_lightCount    = counts[2];
                header->_fogCount      = counts[3];
                header->_cameraCount   = counts[4];
                header->Set(lengths[0], lengths[1], lengths[2], lengths[3], lengths[4], lengths[5]);
            }
        }
Example #8
0
        public override void OnRebuild(VoidPtr address, int length, bool force)
        {
            int GroupLen = 0, LightSetLen = 0, AmbLightSetLen = 0, LightLen = 0, FogLen = 0, CameraLen = 0;

            _header = address;

            ResourceGroup *group;

            if (_version == 5)
            {
                SCN0v5 *header = (SCN0v5 *)address;

                header->_origPathOffset = _origPathOffset;
                header->_frameCount     = (short)_frameCount;
                header->_specLightCount = (short)_specLights;
                header->_loop           = _loop;
                header->_pad            = 0;
                header->_dataOffset     = SCN0v5.Size;

                group = header->Group;
            }
            else
            {
                SCN0v4 *header = (SCN0v4 *)address;

                header->_origPathOffset = _origPathOffset;
                header->_frameCount     = (short)_frameCount;
                header->_specLightCount = (short)_specLights;
                header->_loop           = _loop;
                header->_pad            = 0;
                header->_dataOffset     = SCN0v4.Size;

                group = header->Group;
            }

            *group = new ResourceGroup(Children.Count);
            GroupLen = group->_totalSize;

            ResourceEntry *entry        = group->First;
            VoidPtr        groupAddress = group->EndAddress;
            VoidPtr        entryAddress = groupAddress;

            foreach (SCN0GroupNode g in Children)
            {
                entryAddress += g._groupLen;
            }

            VoidPtr keyframeAddress = entryAddress;

            foreach (SCN0GroupNode g in Children)
            {
                foreach (SCN0EntryNode e in g.Children)
                {
                    keyframeAddress += e._length;
                }
            }

            VoidPtr lightArrayAddress = keyframeAddress;

            foreach (SCN0GroupNode g in Children)
            {
                foreach (SCN0EntryNode e in g.Children)
                {
                    lightArrayAddress += e._keyLen;
                }
            }

            VoidPtr visibilityAddress = lightArrayAddress;

            foreach (SCN0GroupNode g in Children)
            {
                foreach (SCN0EntryNode e in g.Children)
                {
                    visibilityAddress += e._lightLen;
                }
            }

            short _lightSetCount = 0, _ambientCount = 0, _lightCount = 0, _fogCount = 0, _cameraCount = 0;

            int[] indices = new int[] { -1, -1, -1, -1, -1 };
            foreach (SCN0GroupNode g in Children)
            {
                if (g._name == "LightSet(NW4R)")
                {
                    indices[0]     = g.Index;
                    LightSetLen    = g._entryLen;
                    _lightSetCount = (short)g.Children.Count;
                }
                else if (g._name == "AmbLights(NW4R)")
                {
                    indices[1]     = g.Index;
                    AmbLightSetLen = g._entryLen;
                    _ambientCount  = (short)g.Children.Count;
                }
                else if (g._name == "Lights(NW4R)")
                {
                    indices[2]  = g.Index;
                    LightLen    = g._entryLen;
                    _lightCount = (short)g.Children.Count;
                }
                else if (g._name == "Fogs(NW4R)")
                {
                    indices[3] = g.Index;
                    FogLen     = g._entryLen;
                    _fogCount  = (short)g.Children.Count;
                }
                else if (g._name == "Cameras(NW4R)")
                {
                    indices[4]   = g.Index;
                    CameraLen    = g._entryLen;
                    _cameraCount = (short)g.Children.Count;
                }
            }

            for (int i = 0; i < 5; i++)
            {
                SCN0GroupNode g = indices[i] >= 0 ? Children[indices[i]] as SCN0GroupNode : null;
                if (g != null)
                {
                    (entry++)->_dataOffset = (int)groupAddress - (int)group;

                    g._dataAddr         = entryAddress;
                    g.keyframeAddress   = keyframeAddress;
                    g.lightArrayAddress = lightArrayAddress;
                    g.visibilityAddress = visibilityAddress;

                    g.Rebuild(groupAddress, g._groupLen, true);

                    groupAddress      += g._groupLen;
                    GroupLen          += g._groupLen;
                    entryAddress      += g._entryLen;
                    keyframeAddress   += g.keyLen;
                    lightArrayAddress += g.lightLen;
                    visibilityAddress += g.visLen;
                }
            }
            if (_version == 5)
            {
                SCN0v5 *header = (SCN0v5 *)address;
                header->_lightSetCount = _lightSetCount;
                header->_ambientCount  = _ambientCount;
                header->_lightCount    = _lightCount;
                header->_fogCount      = _fogCount;
                header->_cameraCount   = _cameraCount;
                header->Set(GroupLen, LightSetLen, AmbLightSetLen, LightLen, FogLen, CameraLen);

                if (_userEntries.Count > 0)
                {
                    _userEntries.Write(header->UserData = lightArrayAddress);
                }
            }
            else
            {
                SCN0v4 *header = (SCN0v4 *)address;
                header->_lightSetCount = _lightSetCount;
                header->_ambientCount  = _ambientCount;
                header->_lightCount    = _lightCount;
                header->_fogCount      = _fogCount;
                header->_cameraCount   = _cameraCount;
                header->Set(GroupLen, LightSetLen, AmbLightSetLen, LightLen, FogLen, CameraLen);
            }
        }
Example #9
0
        public override void OnPopulate()
        {
            if (Header->_version == 5)
            {
                ResourceGroup *group = Header5->Group;
                SCN0GroupNode  g;
                for (int i = 0; i < group->_numEntries; i++)
                {
                    string name = group->First[i].GetName();
                    (g = new SCN0GroupNode(name)).Initialize(this, new DataSource(group->First[i].DataAddress, 0));
                    if (name == "LightSet(NW4R)")
                    {
                        for (int x = 0; x < Header5->_lightSetCount; x++)
                        {
                            new SCN0LightSetNode().Initialize(g, new DataSource(&Header5->LightSets[x], SCN0LightSet.Size));
                        }
                    }
                    else if (name == "AmbLights(NW4R)")
                    {
                        for (int x = 0; x < Header5->_ambientCount; x++)
                        {
                            new SCN0AmbientLightNode().Initialize(g, new DataSource(&Header5->AmbientLights[x], SCN0AmbientLight.Size));
                        }
                    }
                    else if (name == "Lights(NW4R)")
                    {
                        for (int x = 0; x < Header5->_lightCount; x++)
                        {
                            new SCN0LightNode().Initialize(g, new DataSource(&Header5->Lights[x], SCN0Light.Size));
                        }
                    }
                    else if (name == "Fogs(NW4R)")
                    {
                        for (int x = 0; x < Header5->_fogCount; x++)
                        {
                            new SCN0FogNode().Initialize(g, new DataSource(&Header5->Fogs[x], SCN0Fog.Size));
                        }
                    }
                    else if (name == "Cameras(NW4R)")
                    {
                        for (int x = 0; x < Header5->_cameraCount; x++)
                        {
                            new SCN0CameraNode().Initialize(g, new DataSource(&Header5->Cameras[x], SCN0Camera.Size));
                        }
                    }
                }
            }
            else
            {
                ResourceGroup *group = Header4->Group;
                SCN0GroupNode  g, lightsets = null;
                for (int i = 0; i < group->_numEntries; i++)
                {
                    string name = group->First[i].GetName();
                    (g = new SCN0GroupNode(name)).Initialize(this, new DataSource(group->First[i].DataAddress, 0));
                    if (name == "LightSet(NW4R)")
                    {
                        for (int x = 0; x < Header4->_lightSetCount; x++)
                        {
                            new SCN0LightSetNode().Initialize(lightsets = g, new DataSource(&Header4->LightSets[x], SCN0LightSet.Size));
                        }
                    }
                    else if (name == "AmbLights(NW4R)")
                    {
                        for (int x = 0; x < Header4->_ambientCount; x++)
                        {
                            new SCN0AmbientLightNode().Initialize(g, new DataSource(&Header4->AmbientLights[x], SCN0AmbientLight.Size));
                        }
                    }
                    else if (name == "Lights(NW4R)")
                    {
                        for (int x = 0; x < Header4->_lightCount; x++)
                        {
                            new SCN0LightNode().Initialize(g, new DataSource(&Header4->Lights[x], SCN0Light.Size));
                        }
                    }
                    else if (name == "Fogs(NW4R)")
                    {
                        for (int x = 0; x < Header4->_fogCount; x++)
                        {
                            new SCN0FogNode().Initialize(g, new DataSource(&Header4->Fogs[x], SCN0Fog.Size));
                        }
                    }
                    else if (name == "Cameras(NW4R)")
                    {
                        for (int x = 0; x < Header4->_cameraCount; x++)
                        {
                            new SCN0CameraNode().Initialize(g, new DataSource(&Header4->Cameras[x], SCN0Camera.Size));
                        }
                    }
                }
                foreach (SCN0LightSetNode t in lightsets.Children)
                {
                    t.AttachNodes();
                }
            }

            //for (int i = 0; i < strings.Count; i++)
            //    Console.WriteLine(strings.Keys.ElementAt(i) + " " + strings.Values.ElementAt(i));
        }