Exemplo n.º 1
0
        public override void OnApplicationStart()
        {
            Instance = this;

            Directory.CreateDirectory("./UserData/FavCatImport");

            ClassInjector.RegisterTypeInIl2Cpp <CustomPickerList>();
            ClassInjector.RegisterTypeInIl2Cpp <CustomPicker>();

            ApiSnifferPatch.DoPatch();

            FavCatSettings.RegisterSettings();

            MelonLogger.Log("Creating database");
            Database = new LocalStoreDatabase(FavCatSettings.DatabasePath, FavCatSettings.ImageCachePath);

            Database.ImageHandler.TrimCache(FavCatSettings.MaxCacheSizeBytes).NoAwait();

            ExpansionKitApi.RegisterWaitConditionBeforeDecorating(WaitForInitDone());

            foreach (var methodInfo in typeof(AvatarPedestal).GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public).Where(it => it.Name.StartsWith("Method_Private_Void_ApiContainer_") && it.GetParameters().Length == 1))
            {
                Harmony.Patch(methodInfo, new HarmonyMethod(typeof(FavCatMod), nameof(AvatarPedestalPatch)));
            }
        }
Exemplo n.º 2
0
        public override void OnApplicationStart()
        {
            Instance = this;
            if (!CheckWasSuccessful || !MustStayTrue || MustStayFalse)
            {
                return;
            }

            Directory.CreateDirectory("./UserData/FavCatImport");

            ClassInjector.RegisterTypeInIl2Cpp <CustomPickerList>();
            ClassInjector.RegisterTypeInIl2Cpp <CustomPicker>();

            ApiSnifferPatch.DoPatch();

            FavCatSettings.RegisterSettings();

            MelonLogger.Msg("Creating database");
            Database = new LocalStoreDatabase(FavCatSettings.DatabasePath.Value, FavCatSettings.ImageCachePath.Value);

            Database.ImageHandler.TrimCache(FavCatSettings.MaxCacheSizeBytes).NoAwait();

            foreach (var methodInfo in typeof(AvatarPedestal).GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public).Where(it => it.Name.StartsWith("Method_Private_Void_ApiContainer_") && it.GetParameters().Length == 1))
            {
                HarmonyInstance.Patch(methodInfo, new HarmonyMethod(typeof(FavCatMod), nameof(AvatarPedestalPatch)));
            }

            DoAfterUiManagerInit(OnUiManagerInit);
        }
Exemplo n.º 3
0
        public override void OnApplicationStart()
        {
            Instance = this;

            Directory.CreateDirectory("./UserData/FavCatImport");

            ClassInjector.RegisterTypeInIl2Cpp <CustomPickerList>();
            ClassInjector.RegisterTypeInIl2Cpp <CustomPicker>();

            ApiSnifferPatch.DoPatch();

            FavCatSettings.RegisterSettings();

            MelonLogger.Log("Creating database");
            Database = new LocalStoreDatabase(FavCatSettings.DatabasePath, FavCatSettings.ImageCachePath);

            Database.ImageHandler.TrimCache(FavCatSettings.MaxCacheSizeBytes).NoAwait();

            ExpansionKitApi.RegisterWaitConditionBeforeDecorating(WaitForInitDone());
        }
Exemplo n.º 4
0
        public static async Task ReFetchFavorites()
        {
            ImportRunning     = true;
            ImportStatusOuter = "Re-fetch running...";

            var database = FavCatMod.Database;

            ImportStatusOuter = "Fetching worlds...";
            var worldFavs = database.WorldFavorites.myStoredFavorites.FindAll().ToList();

            for (var i = 0; i < worldFavs.Count; i++)
            {
                ImportStatusInner = i + "/" + worldFavs.Count;

                var storedFavorite = worldFavs[i];
                if (database.myStoredWorlds.FindById(storedFavorite.ObjectId) != null)
                {
                    continue;
                }

                await FavCatMod.YieldToMainThread();

                new ApiWorld {
                    id = storedFavorite.ObjectId
                }.Fetch(null, new Action <ApiContainer>(c =>
                {
                    if (c.Code == 404)
                    {
                        database.CompletelyDeleteWorld(storedFavorite.ObjectId);
                    }
                }));

                await Task.Delay(TimeSpan.FromSeconds(5f + Random.Range(0f, 5f))).ConfigureAwait(false);
            }

            var canShowFavorites = DateTime.Now < FavCatMod.NoMoreVisibleAvatarFavoritesAfter;

            if (canShowFavorites)
            {
                ImportStatusOuter = "Fetching avatars...";
                var avatarFavs = database.AvatarFavorites.myStoredFavorites.FindAll().ToList();
                for (var i = 0; i < avatarFavs.Count; i++)
                {
                    ImportStatusInner = i + "/" + avatarFavs.Count;

                    var storedFavorite = avatarFavs[i];
                    if (database.myStoredAvatars.FindById(storedFavorite.ObjectId) != null)
                    {
                        continue;
                    }

                    await FavCatMod.YieldToMainThread();

                    new ApiAvatar {
                        id = storedFavorite.ObjectId
                    }.Fetch(null, new Action <ApiContainer>(c =>
                    {
                        if (c.Code == 404)
                        {
                            database.CompletelyDeleteAvatar(storedFavorite.ObjectId);
                        }
                    }));

                    await Task.Delay(TimeSpan.FromSeconds(5f + Random.Range(0f, 5f))).ConfigureAwait(false);
                }
            }

            ImportStatusOuter = "Fetching players...";
            var playerFavs = database.PlayerFavorites.myStoredFavorites.FindAll().ToList();

            for (var i = 0; i < playerFavs.Count; i++)
            {
                ImportStatusInner = i + "/" + playerFavs.Count;

                var storedFavorite = playerFavs[i];
                if (database.myStoredPlayers.FindById(storedFavorite.ObjectId) != null)
                {
                    continue;
                }

                await FavCatMod.YieldToMainThread();

                new APIUser {
                    id = storedFavorite.ObjectId
                }.Fetch(new Action <ApiContainer>(c =>
                {
                    if (c.Code == 404)
                    {
                        database.CompletelyDeletePlayer(storedFavorite.ObjectId);
                    }
                }));

                await Task.Delay(TimeSpan.FromSeconds(5f + Random.Range(0f, 5f))).ConfigureAwait(false);
            }

            ImportRunning = false;
        }
Exemplo n.º 5
0
        internal static async Task ProcessTextFile(string filePath)
        {
            var fileName = Path.GetFileName(filePath);

            MelonLogger.Log($"Started avatar import process for file {fileName}");

            var toAdd = new List <string>();

            { // file access block
                using var file   = new FileStream(filePath, FileMode.Open, FileAccess.Read);
                using var reader = new StreamReader(file);
                string line;

                while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
                {
                    var matches = AvatarIdRegex.Matches(line);
                    foreach (Match match in matches)
                    {
                        var avatarId = match.Value;
                        toAdd.Add(avatarId);
                    }
                }
            }

            for (var i = 0; i < toAdd.Count; i++)
            {
                ImportStatusInner = $"Fetching avatar {i + 1}/{toAdd.Count}";
                var avatarId = toAdd[i];
                if (FavCatMod.Database.myStoredAvatars.FindById(avatarId) == null)
                {
                    await FavCatMod.YieldToMainThread();

                    new ApiAvatar {
                        id = avatarId
                    }.Fetch();                             // it will get intercepted and stored
                    await Task.Delay(TimeSpan.FromSeconds(5f + Random.Range(0f, 5f))).ConfigureAwait(false);
                }
            }

            ImportStatusInner = "Creating favorites list";
            await FavCatMod.YieldToMainThread();

            var userId           = APIUser.CurrentUser.id;
            var categoryName     = $"Imported from {fileName}";
            var existingCategory = FavCatMod.Database.AvatarFavorites.GetCategory(categoryName);

            foreach (var avatarId in toAdd)
            {
                if (FavCatMod.Database.AvatarFavorites.IsFavorite(avatarId, categoryName))
                {
                    continue;
                }

                var storedAvatar = FavCatMod.Database.myStoredAvatars.FindById(avatarId);
                if (storedAvatar == null || storedAvatar.ReleaseStatus != "public" && storedAvatar.AuthorId != userId)
                {
                    continue;
                }

                FavCatMod.Database.AvatarFavorites.AddFavorite(avatarId, categoryName);
            }

            if (existingCategory == null)
            {
                existingCategory = new StoredCategory {
                    CategoryName = categoryName, SortType = "!added"
                };
                FavCatMod.Database.AvatarFavorites.UpdateCategory(existingCategory);

                var avatarModule = FavCatMod.Instance.AvatarModule !;
                avatarModule.CreateList(existingCategory);
                avatarModule.ReorderLists();
                avatarModule.RefreshFavButtons();
            }

            MelonLogger.Log($"Done importing {fileName}");
            File.Delete(filePath);
        }