예제 #1
0
 public sceHeader(StreamFunctionAdd sfa)
 {
     this.offsetScript  = !(sfa.ReadAnsiStringSize(8) != "TOD1RSCE") ? sfa.ReadUInt32() : throw new Exception("Error #1: Bad Magic");
     this.offsetStrings = sfa.ReadUInt32();
     this.str           = new List <sceStrings>();
     this.sizes         = new List <int>();
     sfa.PositionStream = (long)this.offsetScript;
     while (sfa.PositionStream < (long)this.offsetStrings)
     {
         if (sfa.ReadByte() == 0x47)
         {
             byte num = sfa.ReadByte();
             if ((int)num >> 4 == 1 && sfa.ReadByte() == (byte)0)
             {
                 this.str.Add(new sceStrings((uint)sfa.PositionStream - 1, this.offsetStrings)
                 {
                     offset     = ((uint)num & 0xF) + this.offsetStrings,
                     typeOffset = (byte)1
                 });
             }
             if ((int)num >> 4 == 5)
             {
                 sceStrings sceStrings = new sceStrings((uint)sfa.PositionStream, this.offsetStrings);
                 sceStrings.offset     = (uint)(((int)num & 0xF) << 8) + (uint)sfa.ReadByte() + this.offsetStrings;
                 sceStrings.typeOffset = (byte)2;
                 if (sfa.ReadByte() == (byte)0)
                 {
                     this.str.Add(sceStrings);
                 }
             }
             if (num == 0x90)
             {
                 sceStrings sceStrings = new sceStrings((uint)sfa.PositionStream, this.offsetStrings);
                 sceStrings.offset     = (uint)sfa.ReadUInt16() + this.offsetStrings;
                 sceStrings.typeOffset = (byte)3;
                 if (sfa.ReadByte() == (byte)0)
                 {
                     this.str.Add(sceStrings);
                 }
             }
         }
     }
     this.str.Sort((Comparison <sceStrings>)((s1, s2) => s1.offset.CompareTo(s2.offset)));
     for (int index = 0; index < this.str.Count; ++index)
     {
         if (index < this.str.Count - 1)
         {
             this.sizes.Add((int)this.str[index + 1].offset - (int)this.str[index].offset);
         }
         else
         {
             this.sizes.Add((int)(uint)sfa.LengthStream - (int)this.str[index].offset);
         }
     }
     for (int index = 0; index < this.str.Count; ++index)
     {
         this.str[index].ReadData(sfa, this.sizes[index]);
     }
 }
예제 #2
0
        public sceHeader(StreamFunctionAdd sfa)
        {
            if (sfa.ReadAnsiStringSize(8) != "TOD1RSCE")
            {
                throw new Exception("Error #1: Bad Magic");
            }
            offsetScript       = sfa.ReadUInt32();
            offsetStrings      = sfa.ReadUInt32();
            fileStrings        = new List <sceStrings>();
            sizes              = new List <int>();
            sfa.PositionStream = offsetScript;
            while (sfa.PositionStream < offsetStrings)
            {
                //The file is composed by some bytecode above and strings below
                //then the game gets the offset to a string whith the opcode 0x47
                //so we loop until then, it can get some false positives though
                if (sfa.ReadByte() == 0x47)
                {
                    byte num = sfa.ReadByte();
                    if (num >> 4 == 1)
                    {
                        if (sfa.ReadByte() == 0x0)
                        {
                            fileStrings.Add(new sceStrings((uint)sfa.PositionStream - 1, offsetStrings)
                            {
                                offset     = ((uint)num & 0xF) + offsetStrings,
                                typeOffset = sceStrings.OffsetType.ShortOffset
                            });
                        }
                        else
                        {
                            sfa.PositionStream--;
                        }
                    }
                    if (num >> 4 == 5)
                    {
                        sceStrings sceStrings = new sceStrings((uint)sfa.PositionStream, offsetStrings);
                        sceStrings.offset     = (uint)((num & 0xF) << 8) + sfa.ReadByte() + offsetStrings;
                        sceStrings.typeOffset = sceStrings.OffsetType.MediumOffset;
                        if (sfa.ReadByte() == 0)
                        {
                            fileStrings.Add(sceStrings);
                        }
                    }
                    if (num == 0x90)
                    {
                        sceStrings sceStrings = new sceStrings((uint)sfa.PositionStream, offsetStrings);
                        sceStrings.offset     = sfa.ReadUInt16() + offsetStrings;
                        sceStrings.typeOffset = sceStrings.OffsetType.LargeOffset;
                        if (sfa.ReadByte() == 0)
                        {
                            fileStrings.Add(sceStrings);
                        }
                    }
                }
            }

            //order the offsets by string position
            fileStrings.Sort((s1, s2) => s1.offset.CompareTo(s2.offset));

            //Get sizes
            for (int index = 0; index < fileStrings.Count; ++index)
            {
                if (index < fileStrings.Count - 1)
                {
                    sizes.Add((int)fileStrings[index + 1].offset - (int)fileStrings[index].offset);
                }
                else
                {
                    sizes.Add((int)(uint)sfa.LengthStream - (int)fileStrings[index].offset);
                }
            }
            for (int index = 0; index < fileStrings.Count; ++index)
            {
                fileStrings[index].ReadData(sfa, sizes[index]);
            }
        }