Example #1
0
        public StoreItem ConvertItem(Entry entry)
        {
            var ret = new StoreItem();

            if (entry.MetaInfo != null)
            {
                foreach (var mi in entry.MetaInfo)
                {
                    switch (mi.Key)
                    {
                    case "EncryptionKey":
                        Index.UseKey(Convert.FromBase64String(mi.Value.Split(':', 3)[1]));
                        break;

                    case "BannerOverride":
                        ret.Banner = mi.Value.ToUpperInvariant();
                        break;
                    }
                }
            }

            var displayAssetPath = entry.DisplayAssetPath ?? "None";
            var _p = GetItemPath(entry.ItemGrants[0].TemplateID, out ret.Type);

            Console.WriteLine("Getting " + _p);
            var exp = Index.GetPackage(_p).GetExport <UObject>();

            foreach (var prop in exp)
            {
                switch (prop.Key)
                {
                case "Rarity":
                    if (ret.Rarity == Rarity.UNCOMMON)
                    {
                        ret.Rarity = GetRarity((EnumProperty)prop.Value);
                    }
                    break;

                case "DisplayName":
                    ret.Name = ((TextProperty)prop.Value).Value;
                    break;

                case "ShortDescription":
                    ret.ShortDescription = ((TextProperty)prop.Value).Value;
                    break;

                case "Description":
                    ret.Description = ((TextProperty)prop.Value).Value;
                    break;

                case "Series":
                    ret.Series = ((ObjectProperty)prop.Value).Value.Resource.ObjectName.String.ToLowerInvariant();
                    break;

                case "DisplayAssetPath":
                    if (displayAssetPath == "None")
                    {
                        displayAssetPath = ((FSoftObjectPath)((StructProperty)prop.Value).Value).AssetPathName.String;
                    }
                    break;

                case "LargePreviewImage":
                    if (ret.StandardIcon == null)
                    {
                        ret.StandardIcon = ((SoftObjectProperty)prop.Value).Value.AssetPathName.String;
                    }
                    break;

                case "HeroDefinition":     // skin
                    foreach (var defProp in Index.GetPackage("/FortniteGame/Content/Athena/Heroes/" + ((ObjectProperty)prop.Value).Value.Resource.ObjectName.String).GetExport <UObject>())
                    {
                        switch (defProp.Key)
                        {
                        case "LargePreviewImage":
                            ret.StandardIcon = ((SoftObjectProperty)defProp.Value).Value.AssetPathName.String;
                            break;
                        }
                    }
                    break;

                case "WeaponDefinition":     // pick
                    var path = "/FortniteGame/Content/Athena/Items/Weapons/" + ((ObjectProperty)prop.Value).Value.Resource.ObjectName.String;
                    Console.WriteLine("getting pickaxe: " + path);
                    var uobj = Index.GetPackage("/FortniteGame/Content/Athena/Items/Weapons/" + ((ObjectProperty)prop.Value).Value.Resource.ObjectName.String).GetExport <UObject>();
                    foreach (var defProp in uobj)
                    {
                        switch (defProp.Key)
                        {
                        case "LargePreviewImage":
                            ret.StandardIcon = ((SoftObjectProperty)defProp.Value).Value.AssetPathName.String;
                            break;
                        }
                    }
                    break;
                }
            }

            if (displayAssetPath != "None")
            {
                exp = Index.GetPackage(ConvertObjectPath(displayAssetPath)).GetExport <UObject>();
                foreach (var prop in exp)
                {
                    switch (prop.Key)
                    {
                    case "DisplayName":
                        ret.Name = ((TextProperty)prop.Value).Value;
                        break;

                    case "ShortDescription":
                        ret.ShortDescription = ((TextProperty)prop.Value).Value;
                        break;

                    case "Description":
                        ret.Description = ((TextProperty)prop.Value).Value;
                        break;

                    case "TileImage":
                    case "DetailsImage":
                        var ind = ((ObjectProperty)((UObject)((StructProperty)prop.Value).Value)["ResourceObject"]).Value;
                        if (string.IsNullOrWhiteSpace(ind.Resource.ObjectName.String))
                        {
                            throw new NotImplementedException("WRAPS NOT ADDED YET");

                            /*/ most likely an item wrap
                             * foreach (var mProp in (await Index.GetPackage("/FortniteGame/Content/UI/Foundation/Textures/Icons/Wraps/FeaturedMaterials/" + packageIndex.import).GetUObjectAsync()).properties)
                             * {
                             *  if (mProp.name == "TextureParameterValues")
                             *  {
                             *      ret.FeaturedIcon = ((FPackageIndex)((FStructFallback)((UScriptStruct)((UScriptArray)mProp.tag_data).data[0]).struct_type).properties[1].tag_data).outer_import;
                             *  }
                             * }*/
                        }
                        else
                        {
                            ret.FeaturedIcon = ind.Resource.OuterIndex.Resource.ObjectName.String;
                            if (ret.FeaturedIcon.Contains("MI_UI"))
                            {
                                // yikes but whatever lol
                                ret.FeaturedIcon = ((ObjectProperty)((UObject)((StructProperty)((ArrayProperty)Index.GetPackage(ConvertObjectPath(ret.FeaturedIcon)).GetExport <UObject>()["TextureParameterValues"]).Value[0]).Value)["ParameterValue"]).Value.Resource.OuterIndex.Resource.ObjectName.String;
                            }
                        }
                        break;
                    }
                }
                if (ret.Type == ItemType.ITEMWRAP)
                {
                    ret.StandardIcon = ret.FeaturedIcon;
                }
                ret.FeaturedIcon = ConvertObjectPath(ret.FeaturedIcon);
            }
            ret.StandardIcon = ConvertObjectPath(ret.StandardIcon);
            if (entry.Categories.Length != 0)
            {
                ret.FeaturedCategory = int.Parse(entry.Categories[0].Split(' ', 2)[1]);
            }
            ret.SortPriority = entry.SortPriority;

            switch (entry.OfferType)
            {
            case "DynamicBundle":
                int basePrice = 0;
                var items     = entry.BundleInfo.BundleItems;
                for (int i = 0; i < items.Length; i++)
                {
                    basePrice += items[i].RegularPrice;
                }
                DiscountedPrice price;
                ret.Price = price = new DiscountedPrice(basePrice + entry.BundleInfo.DiscountedBasePrice, basePrice);
                switch (entry.BundleInfo.DisplayType)
                {
                case "PercentOff":
                    ret.Banner = $"{(1 - ((float)price.Price / price.OriginalPrice)) * 100}% OFF";
                    break;

                case "AmountOff":
                    ret.Banner = $"{price.OriginalPrice - price.Price} V-BUCKS OFF";
                    break;
                }
                ret.Type = ItemType.BUNDLE;
                //ret.ShortDescription.Text.SourceString = $"{items.Length} ITEM BUNDLE"; // TODO: fix this please lmao
                break;

            case "StaticPrice":
            default:
                ret.Price = new StaticPrice(entry.Prices[0].FinalPrice);
                break;
            }
            return(ret);
        }
Example #2
0
        public void WriteToStream(MemoryStream output)
        {
            var converter = new Converter(PakSupplier.Index);

            StoreItem[] weekly = new StoreItem[Store.Weekly.Length];
            for (int i = 0; i < weekly.Length; i++)
            {
                try
                {
                    weekly[i] = converter.ConvertItem(Store.Weekly[i]);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            StoreItem[] daily = new StoreItem[Store.Daily.Length];
            for (int i = 0; i < daily.Length; i++)
            {
                try
                {
                    daily[i] = converter.ConvertItem(Store.Daily[i]);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw e;
                }
            }
            // number of featured categories
            var weeklies = Converter.GetCategorySlots(weekly, out var count, out var sizes, out var size);

            Config.SelectedCategory = count;
            var gc = new GlobalCache(converter.Index);

            // TODO: making it any larger doesn't affect the text or icon resolution :(
            // might have to do with the canvas only writing 1080p pixels on a 4k (e.g) image
            const int w = 1280;
            const int h = 720;

            using var ret    = new SKBitmap(w, h, SKColorType.Rgba8888, SKAlphaType.Opaque);
            using var stream = new VideoOutputStream(ret, 30, 1024 * 1024 * 5, output, true);
            using (var c = new SKCanvas(ret))
            {
                if (!string.IsNullOrWhiteSpace(Background) && File.Exists(Background))
                {
                    try
                    {
                        // TODO: make this permanent or part of drawing the cache (maybe?) just do something
                        using var bmp = SKBitmap.Decode(Background);
                        c.DrawBitmap(bmp, new SKRect(0, 0, w, h), new SKPaint {
                            FilterQuality = SKFilterQuality.High, IsAntialias = true
                        });
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                }
                c.SetMatrix(SKMatrix.MakeScale(w / 1920f, h / 1080f));
                for (int i = 0; i < size; i++)
                {
                    gc.GetSection(DrawType.DAILY).Draw(c, daily);
                    gc.GetSection(DrawType.FEATURED).Draw(c, weeklies[i]);
                    gc.GetSection(DrawType.FEATURED).InitializeCategory(c, weeklies[i], sizes, i + 1, 0);
                    float tickAmt = 1 / 150f;
                    for (int j = 0; j < 150; j++)
                    {
                        gc.GetSection(DrawType.DAILY).DrawBorder(c, daily, j);
                        gc.GetSection(DrawType.FEATURED).DrawBorder(c, weeklies[i], j + i * 150);
                        stream.EncodeFrame();
                        gc.GetSection(DrawType.FEATURED).TickCategory(c, weeklies[i], sizes, j * tickAmt, tickAmt);
                    }
                }
            }

            /*
             * using var bmp = new SKBitmap(1280, 720, SKColorType.Rgba8888, SKAlphaType.Opaque);
             * using var stream = new VideoOutputStream(bmp, 30, 1024 * 1024 * 4, output, true);
             * using var c = new SKCanvas(bmp);
             */
        }