Exemplo n.º 1
0
                public itemFormat(BinaryReader br)
                {
                    String[] ItemTexts = new String[9];

                    itemHeader = new itemHeaderFormat(br);
                    long data_pos = 0;
                    UInt32 num_strings = 0, offset = 0, flags = 0;

                    // Objects (General Items)  skip 6 bytes
                    if ((itemHeader.ID <= 0x0FFF) && (itemHeader.ID >= 0x0000))
                        br.BaseStream.Position = itemHeader.HeaderSize + 6;

                    // Usable items skip 2 bytes
                    // Usable Items skip 6 bytes as of March 10, 2008 Update (new UINT32)
                    else if ((itemHeader.ID <= 0x1FFF) && (itemHeader.ID >= 0x1000))
                        br.BaseStream.Position = itemHeader.HeaderSize + 6;

                    // Gil skip just 2 bytes
                    else if (itemHeader.ID == 0xFFFF)
                        br.BaseStream.Position = itemHeader.HeaderSize + 2;

                    // Puppet Items, skip 8 bytes
                    else if ((itemHeader.ID <= 0x21FF) && (itemHeader.ID >= 0x2000))//11263 - 8192
                        br.BaseStream.Position = itemHeader.HeaderSize + 10;  // Unknown is 0x04 bytes not 0x02

                    // Armor Specific Info, 22 bytes to skip to get to text
                    // 26 in March 10, 2008 Update (new UINT32)
                    else if ((itemHeader.ID <= 0x3FFF) && (itemHeader.ID >= 0x2800))//16383 - 11264
                        br.BaseStream.Position = itemHeader.HeaderSize + 26;

                    // Weapon Specific Info, 30 bytes to skip
                    // 34 bytes in March 10, 2008 Update (new UINT32)
                    else if ((itemHeader.ID <= 0x6FFF) && (itemHeader.ID >= 0x4000))
                        br.BaseStream.Position = itemHeader.HeaderSize + 34;

                    // Storage Slips, Vouchers, etc.
                    else if ((itemHeader.ID <= 0x7FFF) && (itemHeader.ID >= 0x7000))
                        br.BaseStream.Position = itemHeader.HeaderSize + 70;

                    // Unknown, should not have anything in the way...
                    else
                        br.BaseStream.Position = itemHeader.HeaderSize + 2;

                    data_pos = br.BaseStream.Position;
                    num_strings = br.ReadUInt32();

                    long fallback_pos = 0;
                    for (int i = 0; (i < num_strings); i++)
                    {
                        //                    if (num_strings >= 5)
                        //{ int x = i; }

                        offset = br.ReadUInt32();
                        flags = br.ReadUInt32();
                        fallback_pos = br.BaseStream.Position;
                        // Indicator (UInt32) + UInt32 x 6 Padding before text
                        br.BaseStream.Position = data_pos + offset + 28;
                        byte[] b = new byte[4];
                        int counter = 0;
                        do
                        {
                            if (br.BaseStream.Position >= br.BaseStream.Length)
                                break;
                            if (b == null)
                                b = new byte[4];
                            else if ((counter + 4) > b.Length)
                                Array.Resize(ref b, (int)(counter + 4));
                            b[counter++] = br.ReadByte();
                            b[counter++] = br.ReadByte();
                            b[counter++] = br.ReadByte();
                            b[counter++] = br.ReadByte();
                            if (b[counter - 1] == 0x00)
                                break;
                        } while (true);
                        /*if (i > ItemTexts.Length)
                        {
                            i = i+0;
                            break;
                        }*/
                        ItemTexts[i] = System.Text.Encoding.GetEncoding(932).GetString(b).Trim().Trim("\0\u0001.".ToCharArray());
                        br.BaseStream.Position = fallback_pos;
                    }
                    text = ItemTexts[0];
                    if (num_strings <= 4) // Japanese (no log name, same as shortname)
                        logtext = text;
                    else if (num_strings <= 5) // English (shortname, logname is position 3)
                        logtext = ItemTexts[2];
                    else if (num_strings <= 6) // French (shortname, logname is position 4)
                        logtext = ItemTexts[3];
                    else if (num_strings <= 9)
                        logtext = ItemTexts[4];
                    else
                        logtext = text;
                }
                public itemFormat (BinaryReader br)
                {
                    String[] ItemTexts = new String[9];

                    itemHeader = new itemHeaderFormat(br);
                    long data_pos = 0;
                    UInt32 num_strings = 0, offset = 0, flags = 0;
                                        
                    //Gil
                    if (itemHeader.ID == 0xFFFF)
                        br.BaseStream.Position = itemHeader.HeaderSize + 2;

                    // Standard Items
                    else if (itemHeader.ID < 0x1000)
                        br.BaseStream.Position = itemHeader.HeaderSize + 10;

                    // Usable Items
                    else if (itemHeader.ID < 0x2000)
                        br.BaseStream.Position = itemHeader.HeaderSize + 14;

                    // Puppet Items
                    else if (itemHeader.ID < 0x2200)
                        br.BaseStream.Position = itemHeader.HeaderSize + 10;
                        
                    // Standard Items
                    else if (itemHeader.ID < 0x2800)
                        br.BaseStream.Position = itemHeader.HeaderSize + 10;

                    // Armor
                    else if (itemHeader.ID < 0x4000)
                        br.BaseStream.Position = itemHeader.HeaderSize + 30;

                    // Weapon
                    else if (itemHeader.ID < 0x6000)
                        br.BaseStream.Position = itemHeader.HeaderSize + 42;

                    // Armor
                    else if (itemHeader.ID < 0x7000)
                        br.BaseStream.Position = itemHeader.HeaderSize + 30;

                    // Storage Slips
                    else if (itemHeader.ID <= 0x7400)
                        br.BaseStream.Position = itemHeader.HeaderSize + 70;

                    // Unknown, should not have anything in the way...
                    else
                        br.BaseStream.Position = itemHeader.HeaderSize + 2;

                    data_pos = br.BaseStream.Position;
                    num_strings = br.ReadUInt32();

                    long fallback_pos = 0;
                    for (int i = 0; ( i < num_strings ); i++)
                    {
                        //                    if (num_strings >= 5)
                        //{ int x = i; }

                        offset = br.ReadUInt32();
                        flags = br.ReadUInt32();
                        fallback_pos = br.BaseStream.Position;
                        // Indicator (UInt32) + UInt32 x 6 Padding before text
                        br.BaseStream.Position = data_pos + offset + 28;
                        byte[] b = new byte[4];
                        int counter = 0;
                        do
                        {
                            if (br.BaseStream.Position >= br.BaseStream.Length)
                                break;
                            if (b == null)
                                b = new byte[4];
                            else if (( counter + 4 ) > b.Length)
                                Array.Resize(ref b, (int)( counter + 4 ));
                            b[counter++] = br.ReadByte();
                            b[counter++] = br.ReadByte();
                            b[counter++] = br.ReadByte();
                            b[counter++] = br.ReadByte();
                            if (b[counter - 1] == 0x00)
                                break;
                        } while (true);
                        /*if (i > ItemTexts.Length)
                        {
                            i = i+0;
                            break;
                        }*/
                        ItemTexts[i] = System.Text.Encoding.GetEncoding(932).GetString(b).Trim().Trim("\0\u0001.".ToCharArray());
                        br.BaseStream.Position = fallback_pos;
                    }
                    text = ItemTexts[0];
                    if (num_strings <= 4) // Japanese (no log name, same as shortname)
                        logtext = text;
                    else if (num_strings <= 5) // English (shortname, logname is position 3)
                        logtext = ItemTexts[2];
                    else if (num_strings <= 6) // French (shortname, logname is position 4)
                        logtext = ItemTexts[3];
                    else if (num_strings <= 9)
                        logtext = ItemTexts[4];
                    else
                        logtext = text;
                }