public override bool OnInitialize()
        {
            MDL0Material* header = Header;

            _initVersion = header->_pad != 0 && _replaced ? header->_pad : Model._version;

            if ((_name == null) && (header->_stringOffset != 0))
                _name = header->ResourceString;

            XFCmds.Clear();

            //Get XF Commands
            byte* pData = (byte*)header->DisplayLists(Model._version) + 0xE0;
            Top:
            if (*pData++ == 0x10)
            {
                XFData dat = new XFData();
                int count = (ushort)*(bushort*)pData; pData += 2;
                dat.addr = (XFMemoryAddr)(ushort)*(bushort*)pData; pData += 2;
                dat.values = new List<uint>();
                for (int i = 0; i < count + 1; i++)
                {
                    dat.values.Add(*(buint*)pData);
                    pData += 4;
                }
                XFCmds.Add(dat);
                goto Top;
            }

            _mdl0Offset = header->_mdl0Offset;
            _stringOffset = header->_stringOffset;
            _userDataOffset = header->UserDataOffset(_initVersion);
            _shaderOffset = header->_shaderOffset;
            _dlOffset = header->DisplayListOffset(_initVersion);
            _furDataOffset = header->FurDataOffset(_initVersion);
            _matRefOffset = header->_matRefOffset;
            _pad = header->_pad;

            _dataLen = header->_dataLen;
            _numTextures = header->_numTexGens;
            _numLights = header->_numLightChans;
            _usageFlags = new Bin32(header->_usageFlags);

            _indirectMethod1 = header->_indirectMethod1;
            _indirectMethod2 = header->_indirectMethod2;
            _indirectMethod3 = header->_indirectMethod3;
            _indirectMethod4 = header->_indirectMethod4;

            _normMapRefLight1 = header->_normMapRefLight1;
            _normMapRefLight2 = header->_normMapRefLight2;
            _normMapRefLight3 = header->_normMapRefLight3;
            _normMapRefLight4 = header->_normMapRefLight4;

            _ssc = header->_activeTEVStages;
            _clip = header->_numIndTexStages;
            _transp = header->_enableAlphaTest;

            _lSet = header->_lightSet;
            _fSet = header->_fogSet;

            _cull = (CullMode)(int)header->_cull;

            if ((-header->_mdl0Offset + (int)header->DisplayListOffset(_initVersion)) % 0x20 != 0)
            {
                Model._errors.Add("Material " + Index + " has an improper align offset.");
                SignalPropertyChange();
            }

            mode = header->DisplayLists(_initVersion);
            _alphaFunc = mode->AlphaFunction;
            _zMode = mode->ZMode;
            _blendMode = mode->BlendMode;
            _constantAlpha = mode->ConstantAlpha;

            _tevColorBlock = *header->TevColorBlock(_initVersion);
            _tevKonstBlock = *header->TevKonstBlock(_initVersion);
            _indMtx = *header->IndMtxBlock(_initVersion);

            MDL0TexSRTData* TexMatrices = header->TexMatrices(_initVersion);

            _layerFlags = TexMatrices->_layerFlags;
            _texMtxFlags = TexMatrices->_mtxFlags;

            MDL0MaterialLighting* Light = header->Light(_initVersion);

            (_chan1 = Light->Channel1)._parent = this;
            (_chan2 = Light->Channel2)._parent = this;

            c1 = CReg2Color;
            c2 = CReg2Color;
            c3 = CReg2Color;

            k1 = KReg0Color;
            k2 = KReg1Color;
            k3 = KReg2Color;
            k3 = KReg3Color;

            clr1 = C1MaterialColor;
            clr2 = C2MaterialColor;

            amb1 = C1AmbientColor;
            amb2 = C2AmbientColor;

            (_userEntries = new UserDataCollection()).Read(header->UserData(_initVersion));

            return true;
        }
 internal void ApplyCLR0(CLR0Node node, int index)
 {
     if (node == null) return;
     CLR0MaterialNode mat = node.FindChild(Name, false) as CLR0MaterialNode;
     if (mat != null)
         foreach (CLR0MaterialEntryNode e in mat.Children)
         {
             ARGBPixel p = e.Colors.Count > index ? e.Colors[index] : new ARGBPixel();
             switch (e.Target)
             {
                 case EntryTarget.Ambient0: amb1 = (RGBAPixel)p; break;
                 case EntryTarget.Ambient1: amb2 = (RGBAPixel)p; break;
                 case EntryTarget.Color0: clr1 = (RGBAPixel)p; break;
                 case EntryTarget.Color1: clr2 = (RGBAPixel)p; break;
                 case EntryTarget.TevColorReg0: c1 = (GXColorS10)p; break;
                 case EntryTarget.TevColorReg1: c2 = (GXColorS10)p; break;
                 case EntryTarget.TevColorReg2: c3 = (GXColorS10)p; break;
                 case EntryTarget.TevKonstReg0: k1 = (GXColorS10)p; break;
                 case EntryTarget.TevKonstReg1: k2 = (GXColorS10)p; break;
                 case EntryTarget.TevKonstReg2: k3 = (GXColorS10)p; break;
                 case EntryTarget.TevKonstReg3: k4 = (GXColorS10)p; break;
             }
         }
 }
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            GXColorS10 p = new GXColorS10();

            string s = value.ToString();
            string[] arr = s.Split(delims, StringSplitOptions.RemoveEmptyEntries);

            if (arr.Length == 4)
            {
                short.TryParse(arr[0], out p.R);
                short.TryParse(arr[1], out p.G);
                short.TryParse(arr[2], out p.B);
                short.TryParse(arr[3], out p.A);
            }

            return p;
        }