Example #1
0
        public bool TryParse(FileInfo file)
        {
            string fileName = file.FullName;

            using (BinaryReader reader = new BinaryReader(file.OpenRead()))
            {
                long pngSize = 0L;
                if (!CheckPngData(reader.BaseStream, ref pngSize, true))
                {
                    return(false);
                }

                if (reader.BaseStream.Length - reader.BaseStream.Position == 0L)
                {
                    return(false);
                }

                try
                {
                    int loadProductNo = reader.ReadInt32();
                    if (loadProductNo != 100)
                    {
                        CardTypes sceneCardType = CheckIfSceneCard(reader);
                        if (sceneCardType != CardTypes.Unknown) // Scene Card
                        {
                            return(ReadSceneCard(fileName, sceneCardType, reader, pngSize));
                        }

                        reader.Seek(pngSize, SeekOrigin.Begin);
                    }

                    ICharaCard card = null;

                    string    marker   = reader.ReadString();
                    CardTypes cardType = CardTypeFinder.IsMarkerOf(marker);

                    switch (cardType)
                    {
                    case CardTypes.KoiKatuChara:
                    case CardTypes.KoiKatuCharaS:
                    case CardTypes.KoiKatuCharaSP:
                        card = new KKCharaCard(fileName, loadProductNo, marker);
                        break;

                    case CardTypes.AIS_Chara:
                        card = new AISCharaCard(fileName, loadProductNo, marker);
                        break;

                    case CardTypes.HoneySelectCharaMale:
                        card = new HSCharaCard(fileName, marker, 0);
                        break;

                    case CardTypes.HoneySelectCharaFemale:
                        card = new HSCharaCard(fileName, marker, 1);
                        break;

                    case CardTypes.PlayHome_Male:
                        card = new PHCharaCard(fileName, marker, 0);
                        break;

                    case CardTypes.PlayHome_Female:
                        card = new PHCharaCard(fileName, marker, 1);
                        break;

                    case CardTypes.PremiumResortCharaMale:
                        card = new SBPRCharaCard(fileName, marker, 0);
                        break;

                    case CardTypes.PremiumResortCharaFemale:
                        card = new SBPRCharaCard(fileName, marker, 1);
                        break;

                    default:
                        break;
                    }

                    if (card != null && card.Parse(reader, pngSize))
                    {
                        Cards.Add(card);
                        return(true);
                    }
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Message);
                }
            }
            return(false);
        }
        protected virtual void ReadOICharInfo(BinaryReader reader, Version version)
        {
            ReadObjectInfo(reader, version, true);

            var sex = reader.ReadInt32();

            PHCharaCard charaCard = new PHCharaCard(this.SourceFileName, "", (short)sex);

            charaCard.Parse(reader, 0L);

            string name = string.Empty;

            ReadCharFileStatus(reader, version, ref name);

            charaCard.Name = name;
            this.CharaCards.Add(charaCard);

            // bones
            int countBones = reader.ReadInt32();

            for (int i = 0; i < countBones; i++)
            {
                reader.ReadBytes(4); // key
                ReadObjectInfo(reader, version, false);
            }

            // IkTarget
            int countIkTarget = reader.ReadInt32();

            for (int i = 0; i < countIkTarget; i++)
            {
                reader.ReadBytes(4); // key
                ReadObjectInfo(reader, version, false);
            }

            // child
            int countChild = reader.ReadInt32();

            for (int i = 0; i < countChild; i++)
            {
                reader.ReadBytes(4); // key
                ReadChild(reader, version);
            }

            // kinematicMode, animeInfo.group, animeInfo.category, animeInfo.no
            // handPtnL, handPtnR, skinRate, nipple, siru
            reader.ReadBytes(37);

            if (version >= VersionOf(0, 1, 2))
            {
                reader.ReadBytes(4); // faceOption
            }

            // mouthOpen, lipSync
            reader.ReadBytes(5);

            ReadObjectInfo(reader, version, false); // lookAtTarget

            // enableIK, activeIK, enableFK, activeFK
            // expression, animeSpeed
            reader.ReadBytes(22);

            if (version < VersionOf(0, 1, 2))
            {
                // animePattern[0]
                reader.ReadBytes(4);
            }
            else
            {
                // animePattern[0], animePattern[1]
                reader.ReadBytes(8);
            }

            // animeOptionVisible, isAnimeForceLoop
            reader.ReadBytes(2);

            int voiceCount = reader.ReadInt32();

            for (int i = 0; i < voiceCount; i++)
            {
                // group, category, no
                reader.ReadBytes(12);
            }
            reader.ReadBytes(4); // repeat

            if (sex == 0)
            {
                reader.ReadBoolean(); // visibleSimple
                reader.ReadString();  // simpleColor
                // visibleSon, animeOptionParam[0], animeOptionParam[1]
                reader.ReadBytes(9);
            }

            int countNeckByte = reader.ReadInt32();

            reader.ReadBytes(countNeckByte);

            int countEyesByte = reader.ReadInt32();

            reader.ReadBytes(countEyesByte);

            reader.ReadBytes(4); // animeNormalizedTime

            int countAccessGroup = reader.ReadInt32();

            for (int i = 0; i < countAccessGroup; i++)
            {
                // key, TreeState
                reader.ReadBytes(8);
            }

            int countAccessNo = reader.ReadInt32();

            for (int i = 0; i < countAccessNo; i++)
            {
                // key, TreeState
                reader.ReadBytes(8);
            }
        }