With some exceptions, all asset files have a FileMagic at the start of the file. It can be one of "ubi/b0-l" and "ubi/b0-b", which indicate whether the file is little- or big-endian respectively. However, only "ubi/b0-l", the little-endian variant, has ever been observed in the wild.
BasicString structure
The basic UTF-16 string used all over the place. Sometimes referred to as ubistring.
xx: greatest quat element (0 = x, 1 = y, 2 = z, 3 = w).
aaaaaaaaaa/bbbbbbbbbb/cccccccccc: other three elements.
Compression/decompression:
constfloat32oneOverRootTwo=sqrt(2.0)/2.0;constfloat32scaleRange10Bit=sqrt(2.0)/pow(2.0,10);staticuint32CompressedQuaternionU32::CompressElement(float32elem){returnmin((uint32)((elem+oneOverRootTwo)*(1.0/scaleRange10Bit)+0.000025),0x3FF);}voidCompressedQuaternionU32::Compress(Quaternion*src){uint32a,b,c,x;float32ax,ay,az,aw;Quaternionq;q=*src;q.Normalize();ax=abs(q.x);ay=abs(q.y);az=abs(q.z);aw=abs(q.w);if(ax>ay&&ax>az&&ax>aw){// x is greatest element.if(q.x<0.0)q.Negate();a=CompressElement(q.y);b=CompressElement(q.z);c=CompressElement(q.w);x=0;}elseif(ay>az&&ay>aw){// y is greatest element.if(q.y<0.0)q.Negate();a=CompressElement(q.x);b=CompressElement(q.z);c=CompressElement(q.w);x=1;}elseif(az>aw){// z is greatest element.if(q.z<0.0)q.Negate();a=CompressElement(q.x);b=CompressElement(q.y);c=CompressElement(q.w);x=2;}else{// w is greatest element.if(q.w<0.0)q.Negate();a=CompressElement(q.x);b=CompressElement(q.y);c=CompressElement(q.z);x=3;}this->v=(x<<30)|(a<<20)|(b<<10)|c;return;}voidCompressedQuaternionU32::Decompress(Quaternion*dst){float32a,b,c,s;a=(float32)(this->v>>20&0x3FF)*scaleRange10Bit-oneOverRootTwo;b=(float32)(this->v>>10&0x3FF)*scaleRange10Bit-oneOverRootTwo;c=(float32)(this->v>>0&0x3FF)*scaleRange10Bit-oneOverRootTwo;s=sqrt(((1.0-a*a)-b*b)-c*c);switchthis->v>>30{case0:dst->x=s;dst->y=a;dst->z=b;dst->w=c;break;case1:dst->x=a;dst->y=s;dst->z=b;dst->w=c;break;case2:dst->x=a;dst->y=b;dst->z=s;dst->w=c;break;case3:dst->x=a;dst->y=b;dst->z=c;dst->w=s;break;}return;}