示例#1
0
        public void SetComponentDrawable(int index, string name, string tex, GameFileCache gfc)
        {
            if (string.IsNullOrEmpty(name))
            {
                DrawableNames[index] = null;
                Drawables[index]     = null;
                Textures[index]      = null;
                Expressions[index]   = null;
                return;
            }

            MetaHash namehash = JenkHash.GenHash(name.ToLowerInvariant());
            Drawable d        = null;

            if (Ydd?.Dict != null)
            {
                Ydd.Dict.TryGetValue(namehash, out d);
            }
            if ((d == null) && (DrawableFilesDict != null))
            {
                RpfFileEntry file = null;
                if (DrawableFilesDict.TryGetValue(namehash, out file))
                {
                    var ydd = gfc.GetFileUncached <YddFile>(file);
                    while ((ydd != null) && (!ydd.Loaded))
                    {
                        Thread.Sleep(1);//kinda hacky
                        gfc.TryLoadEnqueue(ydd);
                    }
                    if (ydd?.Drawables?.Length > 0)
                    {
                        d = ydd.Drawables[0];//should only be one in this dict
                    }
                }
            }

            MetaHash texhash = JenkHash.GenHash(tex.ToLowerInvariant());
            Texture  t       = null;

            if (Ytd?.TextureDict?.Dict != null)
            {
                Ytd.TextureDict.Dict.TryGetValue(texhash, out t);
            }
            if ((t == null) && (TextureFilesDict != null))
            {
                RpfFileEntry file = null;
                if (TextureFilesDict.TryGetValue(texhash, out file))
                {
                    var ytd = gfc.GetFileUncached <YtdFile>(file);
                    while ((ytd != null) && (!ytd.Loaded))
                    {
                        Thread.Sleep(1);//kinda hacky
                        gfc.TryLoadEnqueue(ytd);
                    }
                    if (ytd?.TextureDict?.Textures?.data_items.Length > 0)
                    {
                        t = ytd.TextureDict.Textures.data_items[0];//should only be one in this dict
                    }
                }
            }

            CharacterCloth cc = null;

            if (Yld?.Dict != null)
            {
                Yld.Dict.TryGetValue(namehash, out cc);
            }
            if ((cc == null) && (ClothFilesDict != null))
            {
                RpfFileEntry file = null;
                if (ClothFilesDict.TryGetValue(namehash, out file))
                {
                    var yld = gfc.GetFileUncached <YldFile>(file);
                    while ((yld != null) && (!yld.Loaded))
                    {
                        Thread.Sleep(1);//kinda hacky
                        gfc.TryLoadEnqueue(yld);
                    }
                    if (yld?.ClothDictionary?.Clothes?.data_items?.Length > 0)
                    {
                        cc = yld.ClothDictionary.Clothes.data_items[0];//should only be one in this dict
                    }
                }
            }
            ClothInstance c = null;

            if (cc != null)
            {
                c = new ClothInstance();
                c.Init(cc, Skeleton);
            }

            Expression e = null;

            if (Yed?.ExprMap != null)
            {
                Yed.ExprMap.TryGetValue(namehash, out e);
            }


            if (d != null)
            {
                Drawables[index] = d.ShallowCopy() as Drawable;
            }
            if (t != null)
            {
                Textures[index] = t;
            }
            if (c != null)
            {
                Clothes[index] = c;
            }
            if (e != null)
            {
                Expressions[index] = e;
            }

            DrawableNames[index] = name;
        }
示例#2
0
        public void Init(MetaHash pedhash, GameFileCache gfc)
        {
            Name     = string.Empty;
            NameHash = 0;
            InitData = null;
            Ydd      = null;
            Ytd      = null;
            Yld      = null;
            Ycd      = null;
            Yed      = null;
            Yft      = null;
            Ymt      = null;
            AnimClip = null;
            for (int i = 0; i < 12; i++)
            {
                Drawables[i]   = null;
                Textures[i]    = null;
                Expressions[i] = null;
            }


            CPedModelInfo__InitData initdata = null;

            if (!gfc.PedsInitDict.TryGetValue(pedhash, out initdata))
            {
                return;
            }

            var ycdhash = JenkHash.GenHash(initdata.ClipDictionaryName.ToLowerInvariant());
            var yedhash = JenkHash.GenHash(initdata.ExpressionDictionaryName.ToLowerInvariant());

            //bool pedchange = NameHash != pedhash;
            //Name = pedname;
            NameHash = pedhash;
            InitData = initdata;
            Ydd      = gfc.GetYdd(pedhash);
            Ytd      = gfc.GetYtd(pedhash);
            Ycd      = gfc.GetYcd(ycdhash);
            Yed      = gfc.GetYed(yedhash);
            Yft      = gfc.GetYft(pedhash);

            PedFile pedFile = null;

            gfc.PedVariationsDict?.TryGetValue(pedhash, out pedFile);
            Ymt = pedFile;

            Dictionary <MetaHash, RpfFileEntry> peddict = null;

            gfc.PedDrawableDicts.TryGetValue(NameHash, out peddict);
            DrawableFilesDict = peddict;
            DrawableFiles     = DrawableFilesDict?.Values.ToArray();
            gfc.PedTextureDicts.TryGetValue(NameHash, out peddict);
            TextureFilesDict = peddict;
            TextureFiles     = TextureFilesDict?.Values.ToArray();
            gfc.PedClothDicts.TryGetValue(NameHash, out peddict);
            ClothFilesDict = peddict;
            ClothFiles     = ClothFilesDict?.Values.ToArray();

            RpfFileEntry clothFile = null;

            if (ClothFilesDict?.TryGetValue(pedhash, out clothFile) ?? false)
            {
                Yld = gfc.GetFileUncached <YldFile>(clothFile);
                while ((Yld != null) && (!Yld.Loaded))
                {
                    Thread.Sleep(1);//kinda hacky
                    gfc.TryLoadEnqueue(Yld);
                }
            }



            while ((Ydd != null) && (!Ydd.Loaded))
            {
                Thread.Sleep(1);//kinda hacky
                Ydd = gfc.GetYdd(pedhash);
            }
            while ((Ytd != null) && (!Ytd.Loaded))
            {
                Thread.Sleep(1);//kinda hacky
                Ytd = gfc.GetYtd(pedhash);
            }
            while ((Ycd != null) && (!Ycd.Loaded))
            {
                Thread.Sleep(1);//kinda hacky
                Ycd = gfc.GetYcd(ycdhash);
            }
            while ((Yed != null) && (!Yed.Loaded))
            {
                Thread.Sleep(1);//kinda hacky
                Yed = gfc.GetYed(yedhash);
            }
            while ((Yft != null) && (!Yft.Loaded))
            {
                Thread.Sleep(1);//kinda hacky
                Yft = gfc.GetYft(pedhash);
            }


            Skeleton = Yft?.Fragment?.Drawable?.Skeleton?.Clone();

            MetaHash     cliphash = JenkHash.GenHash("idle");
            ClipMapEntry cme      = null;

            Ycd?.ClipMap?.TryGetValue(cliphash, out cme);
            AnimClip = cme;

            var        exprhash = JenkHash.GenHash(initdata.ExpressionName.ToLowerInvariant());
            Expression expr     = null;

            Yed?.ExprMap?.TryGetValue(exprhash, out expr);
            Expression = expr;


            UpdateEntity();
        }