예제 #1
0
        private static bool PacketGetUserEventPointProc(ref Packet.State __result, ref PacketGetUserEventPoint __instance)
        {
            Log.Info($"PacketGetUserEventPoint proc");

            GetUserEventPoint query = __instance.query as GetUserEventPoint;

            if (!FileSystem.Configuration.FileExists("UserEventPoint.json"))
            {
                query.response_ = GetUserEventPointResponse.create();
                FileSystem.Configuration.SaveJson("UserEventPoint.json", query.response_);
            }

            query.response_ = FileSystem.Configuration.LoadJson<GetUserEventPointResponse>("UserEventPoint.json");
            return true;
        }
예제 #2
0
        private static bool PacketUpsertUserAllProc(ref Packet.State __result, PacketUpsertUserAll __instance)
        {
            Log.Info($"!!!!! SAVING !!!!!");

            UpsertUserAll query = __instance.query as UpsertUserAll;

            void UpdateUserData(UserData[] array)
            {
                GetUserDataResponse temporary = new GetUserDataResponse();
                temporary.userData = array[0];
                temporary.userId = Singleton<UserManager>.instance.UserId;
                temporary.bpRank = (int)UserUtil.calcBpRank(Singleton<UserManager>.instance.BattlePoint);
                FileSystem.Configuration.SaveJson("UserData.json", temporary);

                GetUserPreviewResponse temporary1 = new GetUserPreviewResponse();
                temporary1.userId = temporary.userId;
                temporary1.isLogin = false;
                temporary1.lastLoginDate = temporary.userData.lastPlayDate;
                temporary1.userName = temporary.userData.userName;
                temporary1.reincarnationNum = temporary.userData.reincarnationNum;
                temporary1.level = temporary.userData.level;
                temporary1.exp = temporary.userData.exp;
                temporary1.playerRating = temporary.userData.playerRating;
                temporary1.lastGameId = temporary.userData.lastGameId;
                temporary1.lastRomVersion = temporary.userData.lastRomVersion;
                temporary1.lastDataVersion = temporary.userData.lastDataVersion;
                temporary1.lastPlayDate = temporary.userData.lastPlayDate;
                temporary1.nameplateId = temporary.userData.nameplateId;
                temporary1.trophyId = temporary.userData.trophyId;
                temporary1.cardId = temporary.userData.cardId;
                temporary1.dispPlayerLv = 1;
                temporary1.dispRating = 1;
                temporary1.dispBP = 1;
                temporary1.headphone = 0;
                FileSystem.Configuration.SaveJson("UserPrev.json", temporary1);
            }

            void UpdateUserOption(MU3.Client.UserOption[] array)
            {
                GetUserOptionResponse temporary = GetUserOptionResponse.create();
                temporary.userOption = array[0];
                temporary.userId = Singleton<UserManager>.instance.UserId;
                FileSystem.Configuration.SaveJson("UserOption.json", temporary);
            }

            void UpdateUserActivity()
            {
                void UpdateForType(string fileName, List<MU3.User.UserActivity> array, UserActivityConst.Kind kind)
                {
                    GetUserActivityResponse temporary = new GetUserActivityResponse();
                    List<MU3.Client.UserActivity> userActivityList = new List<MU3.Client.UserActivity>();
                    foreach (var item in array)
                    {
                        MU3.Client.UserActivity activity = new MU3.Client.UserActivity();
                        item.copyTo(activity);
                        userActivityList.Add(activity);
                    }

                    temporary.userActivityList = userActivityList.ToArray();
                    temporary.length = temporary.userActivityList.Length;
                    temporary.userId = Singleton<UserManager>.instance.UserId;
                    temporary.kind = (int) kind;

                    FileSystem.Configuration.SaveJson(fileName, temporary);
                }

                UserManager instance = Singleton<UserManager>.instance;
                UpdateForType("UserActivityMusic.json", instance.userActivityMusic, UserActivityConst.Kind.Music);
                UpdateForType("UserActivityPlay.json", instance.userActivityPlay, UserActivityConst.Kind.PlayActivity);
            }

            void UpdateUserRecentRating(MU3.Client.UserRecentRating[] array)
            {
                string fileName = "UserRecentRating.json";
                GetUserRecentRatingResponse temporary = new GetUserRecentRatingResponse();

                temporary.userRecentRatingList = array;
                temporary.userId = Singleton<UserManager>.instance.UserId;
                temporary.length = temporary.userRecentRatingList.Length;
                FileSystem.Configuration.SaveJson(fileName, temporary);
            }

            void UpdateUserBpBase(MU3.Client.UserBpBase[] array)
            {
                string fileName = "UserBpBase.json";
                if (!FileSystem.Configuration.FileExists(fileName))
                {
                    GetUserBpBaseResponse bpBase = GetUserBpBaseResponse.create();
                    FileSystem.Configuration.SaveJson(fileName, bpBase);
                }

                GetUserBpBaseResponse temporary = FileSystem.Configuration.LoadJson<GetUserBpBaseResponse>(fileName);
                foreach (var item in array)
                {
                    temporary.userBpBaseList = new[] { item }
                        .Concat(temporary.userBpBaseList)
                        .ToArray();
                }

                temporary.length = temporary.userBpBaseList.Length;
                temporary.userId = Singleton<UserManager>.instance.UserId;
                FileSystem.Configuration.SaveJson("UserBpBase.json", temporary);
            }


            void UpdateUserCharacter(MU3.Client.UserCharacter[] array)
            {
                string fileName = "UserCharacter.json";
                if (!FileSystem.Configuration.FileExists(fileName))
                {
                    GetUserCharacterResponse userCharacter = GetUserCharacterResponse.create();
                    FileSystem.Configuration.SaveJson(fileName, userCharacter);
                }

                GetUserCharacterResponse temporary = FileSystem.Configuration.LoadJson<GetUserCharacterResponse>(fileName);
                foreach (var item in array)
                {
                    temporary.userCharacterList = temporary.userCharacterList
                        .Where(a => a.characterId != item.characterId)
                        .Concat(new[] { item })
                        .ToArray();
                }

                temporary.length = temporary.userCharacterList.Length;
                temporary.nextIndex = 0;
                temporary.userId = Singleton<UserManager>.instance.UserId;
                FileSystem.Configuration.SaveJson(fileName, temporary);
            }

            void UpdateUserCard(MU3.Client.UserCard[] array)
            {
                string fileName = "UserCard.json";
                if (!FileSystem.Configuration.FileExists(fileName))
                {
                    GetUserCardResponse userCard = GetUserCardResponse.create();
                    FileSystem.Configuration.SaveJson(fileName, userCard);
                }

                GetUserCardResponse temporary = FileSystem.Configuration.LoadJson<GetUserCardResponse>(fileName);
                foreach (var item in array)
                {
                    temporary.userCardList = temporary.userCardList
                        .Where(a => a.cardId != item.cardId)
                        .Concat(new[] { item })
                        .ToArray();
                }
                temporary.length = temporary.userCardList.Length;
                temporary.nextIndex = 0;
                temporary.userId = Singleton<UserManager>.instance.UserId;

                FileSystem.Configuration.SaveJson(fileName, temporary);
            }

            void UpdateUserDeck(MU3.Client.UserDeck[] array)
            {
                string fileName = "UserDeckByKey.json";
                if (!FileSystem.Configuration.FileExists(fileName))
                {
                    GetUserDeckByKeyResponse userDeckByKey = GetUserDeckByKeyResponse.create();
                    FileSystem.Configuration.SaveJson(fileName, userDeckByKey);
                }

                GetUserDeckByKeyResponse temporary = FileSystem.Configuration.LoadJson<GetUserDeckByKeyResponse>(fileName);
                foreach (var item in array)
                {
                    temporary.userDeckList = temporary.userDeckList
                        .Where(a => a.deckId != item.deckId)
                        .Concat(new[] { item })
                        .ToArray();
                }
                temporary.length = temporary.userDeckList.Length;
                temporary.userId = Singleton<UserManager>.instance.UserId;

                FileSystem.Configuration.SaveJson(fileName, temporary);
            }

            void UpdateUserTrainingRoom(MU3.Client.UserTrainingRoom[] array)
            {
                string fileName = "UserTrainingRoomByKey.json";
                if (!FileSystem.Configuration.FileExists(fileName))
                {
                    GetUserTrainingRoomByKeyResponse userTrainingRoom = GetUserTrainingRoomByKeyResponse.create();
                    FileSystem.Configuration.SaveJson(fileName, userTrainingRoom);
                }

                GetUserTrainingRoomByKeyResponse temporary = FileSystem.Configuration.LoadJson<GetUserTrainingRoomByKeyResponse>(fileName);
                foreach (var item in array)
                {
                    temporary.userTrainingRoomList = temporary.userTrainingRoomList
                        .Where(a => a.roomId != item.roomId)
                        .Concat(new[] { item })
                        .ToArray();
                }
                temporary.length = temporary.userTrainingRoomList.Length;
                temporary.userId = Singleton<UserManager>.instance.UserId;

                FileSystem.Configuration.SaveJson("UserTrainingRoom.json", temporary);
            }

            void UpdateUserStory(MU3.Client.UserStory[] array)
            {
                string fileName = "UserStory.json";
                if (!FileSystem.Configuration.FileExists(fileName))
                {
                    GetUserStoryResponse userStory = GetUserStoryResponse.create();
                    FileSystem.Configuration.SaveJson(fileName, userStory);
                }

                GetUserStoryResponse temporary = FileSystem.Configuration.LoadJson<GetUserStoryResponse>(fileName);
                foreach (var item in array)
                {
                    temporary.userStoryList = temporary.userStoryList
                        .Where(a => a.storyId != item.storyId)
                        .Concat(new[] { item })
                        .ToArray();
                }
                temporary.length = temporary.userStoryList.Length;
                temporary.userId = Singleton<UserManager>.instance.UserId;

                FileSystem.Configuration.SaveJson(fileName, temporary);
            }

            void UpdateUserChapter(MU3.Client.UserChapter[] array)
            {
                string fileName = "UserChapter.json";
                if (!FileSystem.Configuration.FileExists(fileName))
                {
                    GetUserChapterResponse userChapter = GetUserChapterResponse.create();
                    FileSystem.Configuration.SaveJson(fileName, userChapter);
                }

                GetUserChapterResponse temporary = FileSystem.Configuration.LoadJson<GetUserChapterResponse>(fileName);
                foreach (var item in array)
                {
                    temporary.userChapterList = temporary.userChapterList
                        .Where(a => a.chapterId != item.chapterId)
                        .Concat(new[] { item })
                        .ToArray();
                }
                temporary.length = temporary.userChapterList.Length;
                temporary.userId = Singleton<UserManager>.instance.UserId;

                FileSystem.Configuration.SaveJson(fileName, temporary);
            }

            void UpdateUserItem(UserItem[] array)
            {
                void UpdateForType(string fileName, ItemType itemType)
                {
                    if (!userItemFS.FileExists(fileName))
                    {
                        GetUserItemResponse userItemList = GetUserItemResponse.create();
                        userItemFS.SaveJson(fileName, userItemList);
                    }

                    GetUserItemResponse temporary = userItemFS.LoadJson<GetUserItemResponse>(fileName);
                    foreach (var item in array.Where(a => a.itemKind == (int)itemType))
                    {
                        temporary.userItemList = temporary.userItemList
                            .Where(a => a.itemId != item.itemId)
                            .Concat(new[] { item })
                            .ToArray();
                    }

                    temporary.length = temporary.userItemList.Length;
                    temporary.itemKind = (int)itemType;
                    temporary.nextIndex = 0;
                    temporary.userId = Singleton<UserManager>.instance.UserId;

                    userItemFS.SaveJson(fileName, temporary);
                }

                UpdateForType("Trophy.json", ItemType.Trophy);
                UpdateForType("GachaTicket.json", ItemType.GachaTicket);
                UpdateForType("LimitBreakItem.json", ItemType.LimitBreakItem);
                UpdateForType("NamePlate.json", ItemType.NamePlate);
                UpdateForType("Present.json", ItemType.Present);
                UpdateForType("ProfileVoice.json", ItemType.ProfileVoice);
            }

            void UpdateUserMusicItem(MU3.Client.UserMusicItem[] array)
            {
                string fileName = "UserMusicItem.json";
                if (!FileSystem.Configuration.FileExists(fileName))
                {
                    GetUserMusicItemResponse userMusicItemList = GetUserMusicItemResponse.create();
                    FileSystem.Configuration.SaveJson(fileName, userMusicItemList);
                }

                GetUserMusicItemResponse temporary = FileSystem.Configuration.LoadJson<GetUserMusicItemResponse>(fileName);
                foreach (var item in array)
                {
                    temporary.userMusicItemList = temporary.userMusicItemList
                        .Where(a => a.musicId != item.musicId)
                        .Concat(new[] { item })
                        .ToArray();
                }

                temporary.length = temporary.userMusicItemList.Length;
                temporary.nextIndex = 0;
                temporary.userId = Singleton<UserManager>.instance.UserId;

                FileSystem.Configuration.SaveJson(fileName, temporary);
            }

            void UpdateUserMusic(MU3.Client.UserMusicDetail[] array)
            {
                string fileName = "UserMusic.json";
                if (!FileSystem.Configuration.FileExists(fileName))
                {
                    GetUserMusicResponse userMusicList = GetUserMusicResponse.create();
                    UserMusicDetail userMusicDetail = new UserMusicDetail();
                    userMusicList.length = 0;
                    FileSystem.Configuration.SaveJson(fileName, userMusicList);
                }

                GetUserMusicResponse temporary = FileSystem.Configuration.LoadJson<GetUserMusicResponse>(fileName);
                foreach (var item in array)
                {
                    bool addedItem = false;
                    foreach (var userMusic in temporary.userMusicList) {
                        if (userMusic.length != 0)
                        {
                            if (item.musicId == userMusic.userMusicDetailList[0].musicId)
                            {
                                userMusic.userMusicDetailList = userMusic.userMusicDetailList
                                    .Where(a => a.level != item.level)
                                    .Concat(new[] { item })
                                    .ToArray();
                                userMusic.length = userMusic.userMusicDetailList.Length;
                                addedItem = true;
                                break;
                            }
                        }
                    }

                    if (!addedItem)
                    {
                        MU3.Client.UserMusic userMusic = new MU3.Client.UserMusic();
                        userMusic.userMusicDetailList = userMusic.userMusicDetailList.Add(item).ToArray();
                        userMusic.length = userMusic.userMusicDetailList.Length;
                        temporary.userMusicList = temporary.userMusicList.Add(userMusic).ToArray();
                        temporary.length = temporary.userMusicList.Length;
                    }
                }

                temporary.nextIndex = 0;
                temporary.userId = Singleton<UserManager>.instance.UserId;

                FileSystem.Configuration.SaveJson(fileName, temporary);
            }

            void UpdateUserLoginBonus(MU3.Client.UserLoginBonus[] array)
            {
                string fileName = "UserLoginBonus.json";
                if (!FileSystem.Configuration.FileExists(fileName))
                {
                    GetUserLoginBonusResponse userLoginBonus = GetUserLoginBonusResponse.create();
                    FileSystem.Configuration.SaveJson(fileName, userLoginBonus);
                }

                GetUserLoginBonusResponse temporary = FileSystem.Configuration.LoadJson<GetUserLoginBonusResponse>(fileName);
                foreach (var item in array)
                {
                    temporary.userLoginBonusList = temporary.userLoginBonusList
                        .Where(a => a.bonusId != item.bonusId)
                        .Concat(new[] { item })
                        .ToArray();
                }
                temporary.length = temporary.userLoginBonusList.Length;
                temporary.userId = Singleton<UserManager>.instance.UserId;

                FileSystem.Configuration.SaveJson(fileName, temporary);
            }

            void UpdateUserEventPoint(MU3.Client.UserEventPoint[] array)
            {
                string fileName = "UserEventPoint.json";
                if (!FileSystem.Configuration.FileExists(fileName))
                {
                    GetUserEventPointResponse userEventPoint = GetUserEventPointResponse.create();
                    FileSystem.Configuration.SaveJson(fileName, userEventPoint);
                }

                GetUserEventPointResponse temporary = FileSystem.Configuration.LoadJson<GetUserEventPointResponse>(fileName);
                foreach (var item in array)
                {
                    temporary.userEventPointList = temporary.userEventPointList
                        .Where(a => a.eventId != item.eventId)
                        .Concat(new[] { item })
                        .ToArray();
                }
                temporary.length = temporary.userEventPointList.Length;
                temporary.userId = Singleton<UserManager>.instance.UserId;

                FileSystem.Configuration.SaveJson(fileName, temporary);
            }

            void UpdateUserMissionPoint(MU3.Client.UserMissionPoint[] array)
            {
                string fileName = "UserMissionPoint.json";
                if (!FileSystem.Configuration.FileExists(fileName))
                {
                    GetUserMissionPointResponse userEventPoint = GetUserMissionPointResponse.create();
                    FileSystem.Configuration.SaveJson(fileName, userEventPoint);
                }

                GetUserMissionPointResponse temporary = FileSystem.Configuration.LoadJson<GetUserMissionPointResponse>(fileName);
                foreach (var item in array)
                {
                    temporary.userMissionPointList = temporary.userMissionPointList
                        .Where(a => a.eventId != item.eventId)
                        .Concat(new[] { item })
                        .ToArray();
                }
                temporary.length = temporary.userMissionPointList.Length;
                temporary.userId = Singleton<UserManager>.instance.UserId;

                FileSystem.Configuration.SaveJson(fileName, temporary);
            }

            void UpdateUserRatingLog(MU3.Client.UserRatinglog[] array)
            {
                string fileName = "UserRatingLog.json";
                if (!FileSystem.Configuration.FileExists(fileName))
                {
                    GetUserRatinglogResponse userEventPoint = GetUserRatinglogResponse.create();
                    FileSystem.Configuration.SaveJson(fileName, userEventPoint);
                }

                GetUserRatinglogResponse temporary = FileSystem.Configuration.LoadJson<GetUserRatinglogResponse>(fileName);
                foreach (var item in array)
                {
                    temporary.userRatinglogList = temporary.userRatinglogList
                        .Where(a => a.highestRating != item.highestRating)
                        .Concat(new[] { item })
                        .ToArray();
                }
                temporary.length = temporary.userRatinglogList.Length;
                temporary.userId = Singleton<UserManager>.instance.UserId;

                FileSystem.Configuration.SaveJson(fileName, temporary);
            }


            if (query == null)
            {
                Log.Info("!!!!! No data to save. !!!!!");
                return false;
            }

            var upsert = query.request_.upsertUserAll;

            UpdateUserData(upsert.userData);
            UpdateUserOption(upsert.userOption);
            UpdateUserActivity();
            UpdateUserRecentRating(upsert.userRecentRatingList);
            UpdateUserBpBase(upsert.userBpBaseList);
            if (!string.IsNullOrEmpty(upsert.isNewMusicDetailList)) UpdateUserMusic(upsert.userMusicDetailList);
            if (!string.IsNullOrEmpty(upsert.isNewCharacterList)) UpdateUserCharacter(upsert.userCharacterList);
            if (!string.IsNullOrEmpty(upsert.isNewCardList)) UpdateUserCard(upsert.userCardList);
            if (!string.IsNullOrEmpty(upsert.isNewDeckList)) UpdateUserDeck(upsert.userDeckList);
            if (!string.IsNullOrEmpty(upsert.isNewTrainingRoomList)) UpdateUserTrainingRoom(upsert.userTrainingRoomList);
            if (!string.IsNullOrEmpty(upsert.isNewStoryList)) UpdateUserStory(upsert.userStoryList);
            if (!string.IsNullOrEmpty(upsert.isNewChapterList)) UpdateUserChapter(upsert.userChapterList);
            if (!string.IsNullOrEmpty(upsert.isNewItemList)) UpdateUserItem(upsert.userItemList);
            if (!string.IsNullOrEmpty(upsert.isNewMusicItemList)) UpdateUserMusicItem(upsert.userMusicItemList);
            if (!string.IsNullOrEmpty(upsert.isNewLoginBonusList)) UpdateUserLoginBonus(upsert.userLoginBonusList);
            if (!string.IsNullOrEmpty(upsert.isNewEventPointList)) UpdateUserEventPoint(upsert.userEventPointList);
            if (!string.IsNullOrEmpty(upsert.isNewMissionPointList)) UpdateUserMissionPoint(upsert.userMissionPointList);
            if (!string.IsNullOrEmpty(upsert.isNewRatinglogList)) UpdateUserRatingLog(upsert.userRatinglogList);
            if (UserManager.Exists)
            {
                Singleton<UserManager>.instance.updateLastRemainedGP();
            }
            typeof(PacketUpsertUserAll).GetMethod("clearFlags", (BindingFlags)62).Invoke(__instance, null);

            __result = Packet.State.Done;
            (__instance.query as UpsertUserAll).response_ = new UpsertUserAllResponse()
            {
                returnCode = 1
            };

            return false;
        }