Example #1
0
        private static bool TryParseCard(FileInfo file, out Card card)
        {
            card = null;

            using (var stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
                using (var reader = new BinaryReader(stream))
                {
                    var pngEnd = Utility.SearchForPngEnd(stream);

                    if (pngEnd == -1 || pngEnd >= stream.Length)
                    {
                        return(false);
                    }

                    stream.Position = pngEnd;

                    try
                    {
                        var loadProductNo = reader.ReadInt32();
                        if (loadProductNo > 100)
                        {
                            //return false;
                        }

                        var marker   = reader.ReadString();
                        var gameType = GetGameType(marker);

                        switch (gameType)
                        {
                        case CardType.Koikatu:
                        case CardType.KoikatsuParty:
                        case CardType.KoikatsuPartySpecialPatch:
                            card = EmoCard.ParseKoiChara(file, reader, gameType);
                            break;

                        case CardType.EmotionCreators:
                            card = EmoCard.ParseKoiChara(file, reader, gameType);
                            break;

                        case CardType.AiSyoujyo:
                            card = AiCard.ParseAiChara(file, reader, gameType);
                            break;

                        case CardType.Unknown:
                            card = null;
                            break;

                        default:
                            throw new ArgumentOutOfRangeException(gameType + " is not supported");
                        }
                    }
                    catch (EndOfStreamException)
                    {
                        return(false);
                    }

                    return(card != null);
                }
        }
Example #2
0
        private static bool ParseCard(FileInfo file, out Card card)
        {
            card = null;

            using (var stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
                using (var reader = new BinaryReader(stream))
                {
                    var pngEnd = Utility.SearchForPngEnd(stream);

                    if (pngEnd == -1 || pngEnd >= stream.Length)
                    {
                        return(false);
                    }

                    stream.Position = pngEnd;

                    try
                    {
                        var loadProductNo = reader.ReadInt32();
                        if (loadProductNo > 100)
                        {
                            //return false;
                        }

                        var marker   = reader.ReadString();
                        var gameType = GetGameType(marker);

                        switch (gameType)
                        {
                        case CardType.Koikatu:
                        case CardType.KoikatsuParty:
                        case CardType.KoikatsuPartySpecialPatch:
                            card = KoiCard.ParseKoiChara(file, reader, gameType);
                            break;

                        case CardType.EmotionCreators:
                            card = EmoCard.ParseEmoChara(file, reader, gameType);
                            break;

                        case CardType.AiSyoujyo:
                            card = AiCard.ParseAiChara(file, reader, gameType);
                            break;

                        case CardType.Unknown:
                            card = null;
                            break;

                        default:
                            throw new ArgumentOutOfRangeException($"GameType={gameType} is not supported");
                        }
                    }
                    catch (EndOfStreamException e)
                    {
                        throw new IOException("The card is corrupted or in an unknown format", e);
                    }

                    if (card?.Extended != null)
                    {
                        ExtData.ExtDataParser.Parse(card.Extended);                     // todo cache results or lazy run in background?
                    }
                    // todo check for missing plugins or zipmods, maybe add api to parsers to give links to plugins and zipmods to set as deps, needs a way to specify if they exist or not

                    return(card != null);
                }
        }
Example #3
0
        private static bool ParseCard(FileInfo file, out Card card)
        {
            card = null;

            using (var stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
                using (var reader = new BinaryReader(stream))
                {
                    var pngEnd = Utility.SearchForPngEnd(stream);

                    if (pngEnd == -1 || pngEnd >= stream.Length)
                    {
                        return(false);
                    }

                    stream.Position = pngEnd;

                    try
                    {
                        var loadProductNo = reader.ReadInt32();
                        if (loadProductNo > 100)
                        {
                            //return false;
                        }

                        var marker   = reader.ReadString();
                        var gameType = GetGameType(marker);

                        switch (gameType)
                        {
                        case CardType.Koikatu:
                        case CardType.KoikatsuParty:
                        case CardType.KoikatsuPartySpecialPatch:
                            card = KoiCard.ParseKoiChara(file, reader, gameType);
                            break;

                        case CardType.EmotionCreators:
                            card = EmoCard.ParseEmoChara(file, reader, gameType);
                            break;

                        case CardType.AiSyoujyo:
                            card = AiCard.ParseAiChara(file, reader, gameType);
                            break;

                        case CardType.KoikatsuSunshine:
                            card = KoiSunCard.ParseKoiChara(file, reader, gameType);
                            break;

                        case CardType.Unknown:
                            card = null;
                            break;

                        default:
                            throw new ArgumentOutOfRangeException($"GameType={gameType} is not supported");
                        }
                    }
                    catch (EndOfStreamException e)
                    {
                        throw new IOException("The card is corrupted or in an unknown format", e);
                    }

                    if (card?.Extended != null)
                    {
                        ExtData.ExtDataParser.DeserializeInPlace(card.Extended);
                    }

                    return(card != null);
                }
        }