コード例 #1
0
ファイル: XmlPso.cs プロジェクト: SlOneRPC/RPF-Converter
        private static void TraverseStringRaw(string str, PsoBuilder pb, PsoStructureEntryInfo entry, byte[] data)
        {
            switch (entry.Unk_5h)
            {
            default:
                break;

            case 0:
                var str0len = (int)((entry.ReferenceKey >> 16) & 0xFFFF);
                if (!string.IsNullOrEmpty(str))
                {
                    byte[] strdata = Encoding.ASCII.GetBytes(str);
                    Buffer.BlockCopy(strdata, 0, data, entry.DataOffset, strdata.Length);
                    if (strdata.Length > str0len)
                    {
                    }
                }
                break;

            case 1:
            case 2:
                if (!string.IsNullOrEmpty(str))
                {
                    var bptr = pb.AddString(str);
                    var ptr  = new PsoPOINTER(bptr.BlockID, bptr.Offset);
                    ptr.SwapEnd();
                    var val = MetaTypes.ConvertToBytes(ptr);
                    Buffer.BlockCopy(val, 0, data, entry.DataOffset, val.Length);
                }
                break;

            case 3:
                if (!string.IsNullOrEmpty(str))
                {
                    var bptr = pb.AddString(str);
                    var ptr  = new CharPointer(bptr.Pointer, str.Length);
                    ptr.SwapEnd();
                    var val = MetaTypes.ConvertToBytes(ptr);
                    Buffer.BlockCopy(val, 0, data, entry.DataOffset, val.Length);
                }
                break;

            case 7:    //hash only?
            case 8:    //hash with STRF entry?

                var hashVal = string.IsNullOrEmpty(str) ? 0 : GetHash(str);
                Write(hashVal, data, entry.DataOffset);

                if (entry.Unk_5h == 8)
                {
                    pb.AddStringToSTRF(str);
                }
                break;
            }
        }
コード例 #2
0
        public static string GetString(PsoFile pso, CharPointer ptr)
        {
            if (ptr.Count1 == 0)
            {
                return(null);
            }

            var blocki = (int)ptr.PointerDataId;     // (ptr.Pointer & 0xFFF) - 1;
            var offset = (int)ptr.PointerDataOffset; // (ptr.Pointer >> 12) & 0xFFFFF;

            var block = pso.GetBlock(blocki);

            if (block == null)
            {
                return(null);
            }

            var length   = ptr.Count1;
            var lastbyte = offset + length;

            if (lastbyte >= block.Length)
            {
                return(null);
            }

            var data = pso.DataSection?.Data;

            if (data == null)
            {
                return(null);
            }

            var doffset = block.Offset + offset;

            string s = Encoding.ASCII.GetString(data, doffset, length);

            //if (meta.Strings == null) return null;
            //if (offset < 0) return null;
            //if (offset >= meta.Strings.Length) return null;
            //string s = meta.Strings[offset];

            return(s);
        }