mirror of
https://github.com/revanced/ARSCLib.git
synced 2025-05-01 06:34:26 +02:00
simplify ResConfig language & regions
This commit is contained in:
parent
31eecf0f61
commit
3ee3e2b92f
@ -132,116 +132,81 @@ public class ResConfig extends FixedBlockContainer
|
|||||||
}
|
}
|
||||||
return mValuesContainer.getShortUnsigned(OFFSET_mnc);
|
return mValuesContainer.getShortUnsigned(OFFSET_mnc);
|
||||||
}
|
}
|
||||||
public void setLanguageIn0(byte b){
|
|
||||||
|
public byte[] getLanguageBytes(){
|
||||||
if(getConfigSize()<SIZE_16){
|
if(getConfigSize()<SIZE_16){
|
||||||
if(b==0){
|
return new byte[2];
|
||||||
|
}
|
||||||
|
return mValuesContainer.getByteArray(OFFSET_language, 2);
|
||||||
|
}
|
||||||
|
public void setLanguageBytes(byte[] bytes){
|
||||||
|
if(getConfigSize()<SIZE_16){
|
||||||
|
if(isNull(bytes)){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Can not set languageIn0 for config size="+getConfigSize());
|
throw new IllegalArgumentException("Can not set language bytes for config size="+getConfigSize());
|
||||||
}
|
}
|
||||||
mValuesContainer.put(OFFSET_languageIn0, b);
|
mValuesContainer.putByteArray(OFFSET_language, bytes);
|
||||||
}
|
}
|
||||||
public byte getLanguageIn0(){
|
public char[] getLanguageChars(){
|
||||||
if(getConfigSize()<SIZE_16){
|
byte[] bytes = getLanguageBytes();
|
||||||
return 0;
|
return unPackLanguage(bytes[0], bytes[1]);
|
||||||
}
|
}
|
||||||
return mValuesContainer.get(OFFSET_languageIn0);
|
public void setLanguage(char[] chars){
|
||||||
}
|
setLanguageBytes(packLanguage(chars));
|
||||||
public void setLanguageIn1(byte b){
|
|
||||||
if(getConfigSize()<SIZE_16){
|
|
||||||
if(b==0){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
throw new IllegalArgumentException("Can not set languageIn1 for config size="+getConfigSize());
|
|
||||||
}
|
|
||||||
mValuesContainer.put(OFFSET_languageIn1, b);
|
|
||||||
}
|
|
||||||
public byte getLanguageIn1(){
|
|
||||||
if(getConfigSize()<SIZE_16){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return mValuesContainer.get(OFFSET_languageIn1);
|
|
||||||
}
|
|
||||||
public String getLanguage(){
|
|
||||||
return ResConfigHelper.decodeLanguage(getLanguageChars());
|
|
||||||
}
|
}
|
||||||
public void setLanguage(String language){
|
public void setLanguage(String language){
|
||||||
char[] chs=new char[2];
|
char[] chs = null;
|
||||||
if(language!=null){
|
if(language!=null){
|
||||||
chs=language.toCharArray();
|
chs=language.toCharArray();
|
||||||
}
|
}
|
||||||
setLanguage(chs);
|
setLanguage(chs);
|
||||||
}
|
}
|
||||||
public char[] getLanguageChars(){
|
public String getLanguage(){
|
||||||
byte b0=getLanguageIn0();
|
char[] chars = getLanguageChars();
|
||||||
byte b1=getLanguageIn1();
|
if(isNull(chars)){
|
||||||
return unpackLanguageOrRegion(b0, b1, 'a');
|
return null;
|
||||||
}
|
}
|
||||||
public void setLanguage(char[] chs){
|
return new String(chars);
|
||||||
byte[] bts;
|
|
||||||
if(isNull(chs)){
|
|
||||||
bts=new byte[2];
|
|
||||||
}else {
|
|
||||||
bts=packLanguageOrRegion(chs);
|
|
||||||
}
|
}
|
||||||
setLanguageIn0(bts[0]);
|
|
||||||
setLanguageIn1(bts[1]);
|
public byte[] getRegionBytes(){
|
||||||
}
|
|
||||||
public void setCountryIn0(byte b){
|
|
||||||
if(getConfigSize()<SIZE_16){
|
if(getConfigSize()<SIZE_16){
|
||||||
if(b==0){
|
return new byte[2];
|
||||||
|
}
|
||||||
|
return mValuesContainer.getByteArray(OFFSET_region, 2);
|
||||||
|
}
|
||||||
|
public void setRegionBytes(byte[] bytes){
|
||||||
|
if(getConfigSize()<SIZE_16){
|
||||||
|
if(isNull(bytes)){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Can not set countryIn0 for config size="+getConfigSize());
|
throw new IllegalArgumentException("Can not set region bytes for config size="+getConfigSize());
|
||||||
}
|
}
|
||||||
mValuesContainer.put(OFFSET_countryIn0, b);
|
mValuesContainer.putByteArray(OFFSET_region, bytes);
|
||||||
}
|
|
||||||
public byte getCountryIn0(){
|
|
||||||
if(getConfigSize()<SIZE_16){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return mValuesContainer.get(OFFSET_countryIn0);
|
|
||||||
}
|
|
||||||
public void setCountryIn1(byte b){
|
|
||||||
if(getConfigSize()<SIZE_16){
|
|
||||||
if(b==0){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
throw new IllegalArgumentException("Can not set countryIn1 for config size="+getConfigSize());
|
|
||||||
}
|
|
||||||
mValuesContainer.put(OFFSET_countryIn1, b);
|
|
||||||
}
|
|
||||||
public byte getCountryIn1(){
|
|
||||||
if(getConfigSize()<SIZE_16){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return mValuesContainer.get(OFFSET_countryIn1);
|
|
||||||
}
|
|
||||||
public String getRegion(){
|
|
||||||
return ResConfigHelper.decodeRegion(getRegionChars());
|
|
||||||
}
|
}
|
||||||
public char[] getRegionChars(){
|
public char[] getRegionChars(){
|
||||||
byte b0=getCountryIn0();
|
byte[] bytes = getRegionBytes();
|
||||||
byte b1=getCountryIn1();
|
return unPackRegion(bytes[0], bytes[1]);
|
||||||
return unpackLanguageOrRegion(b0, b1, '0');
|
|
||||||
}
|
}
|
||||||
public void setRegion(char[] chs){
|
public void setRegion(char[] chars){
|
||||||
byte[] bts;
|
setRegionBytes(packRegion(chars));
|
||||||
if(isNull(chs)){
|
|
||||||
bts=new byte[2];
|
|
||||||
}else {
|
|
||||||
bts=packLanguageOrRegion(chs);
|
|
||||||
}
|
|
||||||
setCountryIn0(bts[0]);
|
|
||||||
setCountryIn1(bts[1]);
|
|
||||||
}
|
}
|
||||||
public void setRegion(String region){
|
public void setRegion(String region){
|
||||||
char[] chs=new char[2];
|
char[] chars = null;
|
||||||
if(region!=null){
|
if(region!=null){
|
||||||
chs=region.toCharArray();
|
chars = region.toCharArray();
|
||||||
}
|
}
|
||||||
setRegion(chs);
|
setRegion(chars);
|
||||||
}
|
}
|
||||||
|
public String getRegion(){
|
||||||
|
char[] chars = getRegionChars();
|
||||||
|
if(isNull(chars)){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new String(chars);
|
||||||
|
}
|
||||||
|
|
||||||
public void setOrientation(byte b){
|
public void setOrientation(byte b){
|
||||||
if(getConfigSize()<SIZE_16){
|
if(getConfigSize()<SIZE_16){
|
||||||
if(b==0){
|
if(b==0){
|
||||||
@ -860,61 +825,57 @@ public class ResConfig extends FixedBlockContainer
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static char[] unpackLanguageOrRegion(byte b0, byte b1, char base){
|
private static char[] unPackLanguage(byte in0, byte in1) {
|
||||||
if ((((b0 >> 7) & 1) == 1)) {
|
return unpackLanguageOrRegion(in0, in1, 'a');
|
||||||
int first = b1 & 0x1F;
|
|
||||||
int x=((b1 & 0xE0) >> 5);
|
|
||||||
int y=((b0 & 0x03) << 3);
|
|
||||||
int second = x + y;
|
|
||||||
int third = (b0 & 0x7C) >> 2;
|
|
||||||
|
|
||||||
return new char[] { (char) (first + base), (char) (second + base), (char) (third + base) };
|
|
||||||
}
|
}
|
||||||
return new char[] { (char) b0, (char) b1 };
|
private static char[] unPackRegion(byte in0, byte in1) {
|
||||||
|
return unpackLanguageOrRegion(in0, in1, '0');
|
||||||
}
|
}
|
||||||
private static byte[] packLanguageOrRegion(char[] chs){
|
private static char[] unpackLanguageOrRegion(byte in0, byte in1, char base) {
|
||||||
if(chs==null || chs.length<2){
|
char[] out;
|
||||||
return new byte[2];
|
if ((in0 & 0x80) !=0) {
|
||||||
|
out = new char[3];
|
||||||
|
byte first = (byte) (in1 & 0x1f);
|
||||||
|
byte second = (byte) (((in1 & 0xe0) >> 5) + ((in0 & 0x03) << 3));
|
||||||
|
byte third = (byte) ((in0 & 0x7c) >> 2);
|
||||||
|
|
||||||
|
out[0] = (char) (first + base);
|
||||||
|
out[1] = (char) (second + base);
|
||||||
|
out[2] = (char) (third + base);
|
||||||
|
}else if (in0 != 0) {
|
||||||
|
out = new char[2];
|
||||||
|
out[0] = (char) in0;
|
||||||
|
out[1] = (char) in1;
|
||||||
|
}else {
|
||||||
|
out = new char[2];
|
||||||
}
|
}
|
||||||
if(chs.length==2 || chs.length>3){
|
return out;
|
||||||
byte[] result=new byte[2];
|
|
||||||
result[0]=(byte) chs[0];
|
|
||||||
result[1]=(byte) chs[1];
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
int base=getBase(chs[0]);
|
private static byte[] packLanguage(char[] language) {
|
||||||
int first=chs[0] - base;
|
return packLanguageOrRegion(language, 'a');
|
||||||
int second=chs[1] - base;
|
|
||||||
int third=chs[2] - base;
|
|
||||||
|
|
||||||
int b1Right=first & 0x1F;
|
|
||||||
|
|
||||||
int b0Left=third;
|
|
||||||
b0Left=b0Left << 2;
|
|
||||||
|
|
||||||
int b1Left=second & 7;
|
|
||||||
b1Left=b1Left<<5;
|
|
||||||
|
|
||||||
int b1=(b1Left | b1Right);
|
|
||||||
|
|
||||||
int b0Right=second >> 3;
|
|
||||||
b0Right=b0Right & 0x3;
|
|
||||||
|
|
||||||
int b0=(b0Left | b0Right);
|
|
||||||
return new byte[] { (byte) b0, (byte) b1 };
|
|
||||||
}
|
}
|
||||||
private static int getBase(char ch){
|
private static byte[] packRegion(char[] region) {
|
||||||
int result=ch;
|
return packLanguageOrRegion(region, '0');
|
||||||
if(ch>='0' && ch<='9'){
|
|
||||||
result='0';
|
|
||||||
}else if(ch>='a' && ch<='z'){
|
|
||||||
result='a';
|
|
||||||
}else if(ch>='A' && ch<='Z'){
|
|
||||||
result='A';
|
|
||||||
}
|
}
|
||||||
result=result+32;
|
private static byte[] packLanguageOrRegion(char[] in, char base) {
|
||||||
return result;
|
byte[] out = new byte[2];
|
||||||
|
if(in==null || in.length<2){
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
|
if (in[2] == 0 || in[2] == '-') {
|
||||||
|
out[0] = (byte) in[0];
|
||||||
|
out[1] = (byte) in[1];
|
||||||
|
} else {
|
||||||
|
byte first = (byte) ((in[0] - base) & 0x007f);
|
||||||
|
byte second = (byte) ((in[1] - base) & 0x007f);
|
||||||
|
byte third = (byte) ((in[2] - base) & 0x007f);
|
||||||
|
|
||||||
|
out[0] = (byte) (0x80 | (third << 2) | (second >> 3));
|
||||||
|
out[1] = (byte) ((second << 5) | first);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
private static byte[] toByteArray(char[] chs, int len){
|
private static byte[] toByteArray(char[] chs, int len){
|
||||||
byte[] bts=new byte[len];
|
byte[] bts=new byte[len];
|
||||||
if(chs==null){
|
if(chs==null){
|
||||||
@ -1201,10 +1162,8 @@ public class ResConfig extends FixedBlockContainer
|
|||||||
|
|
||||||
private static final int OFFSET_mcc = 0;
|
private static final int OFFSET_mcc = 0;
|
||||||
private static final int OFFSET_mnc = 2;
|
private static final int OFFSET_mnc = 2;
|
||||||
private static final int OFFSET_languageIn0 = 4;
|
private static final int OFFSET_language = 4;
|
||||||
private static final int OFFSET_languageIn1 = 5;
|
private static final int OFFSET_region = 6;
|
||||||
private static final int OFFSET_countryIn0 = 6;
|
|
||||||
private static final int OFFSET_countryIn1 = 7;
|
|
||||||
private static final int OFFSET_orientation = 8;
|
private static final int OFFSET_orientation = 8;
|
||||||
private static final int OFFSET_touchscreen = 9;
|
private static final int OFFSET_touchscreen = 9;
|
||||||
private static final int OFFSET_density = 10;
|
private static final int OFFSET_density = 10;
|
||||||
|
@ -239,38 +239,18 @@ public class ResConfigHelper {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public static String decodeLanguage(char[] language){
|
|
||||||
StringBuilder builder=new StringBuilder();
|
|
||||||
if(language[0]!=0){
|
|
||||||
builder.append(language[0]).append(language[1]);
|
|
||||||
}
|
|
||||||
if(builder.length()==0){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
public static String decodeRegion(char[] region){
|
|
||||||
StringBuilder builder=new StringBuilder();
|
|
||||||
if(region[0]!=0){
|
|
||||||
builder.append(region[0]).append(region[1]);
|
|
||||||
}
|
|
||||||
if(builder.length()==0){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
public static String decodeLocale(ResConfig resConfig){
|
public static String decodeLocale(ResConfig resConfig){
|
||||||
char[] region=resConfig.getRegionChars();
|
String region = resConfig.getRegion();
|
||||||
char[] language=resConfig.getLanguageChars();
|
String language = resConfig.getLanguage();
|
||||||
StringBuilder builder=new StringBuilder();
|
StringBuilder builder=new StringBuilder();
|
||||||
if(language[0]!=0){
|
if(language!=null){
|
||||||
builder.append(language[0]).append(language[1]);
|
builder.append(language);
|
||||||
}
|
}
|
||||||
if(region[0]!=0){
|
if(region!=null){
|
||||||
if(language[0]!=0){
|
if(language!=null){
|
||||||
builder.append('-');
|
builder.append('-');
|
||||||
}
|
}
|
||||||
builder.append(region[0]).append(region[1]);
|
builder.append(region);
|
||||||
}
|
}
|
||||||
if(builder.length()==0){
|
if(builder.length()==0){
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user