byte[] convert_unHuffman_code_to_binary(byte[] sjisstr) { PatchUtil.PRIORITY_CODE priorityCode = PatchUtil.SearchPriorityCode(); PatchUtil.TextEngineRework_enum textEngineRework = PatchUtil.SearchTextEngineReworkPatch(); List <byte> ret = new List <byte>(); for (int i = 0; i < sjisstr.Length;) { if (sjisstr[i] == '@') { uint code1 = at_code_to_binary(sjisstr, i, out i); //unHuffman patchでは可変長デコードらしい. //@0009 -> 0x09 //@0080@000d -> 0x80 0x0d //@0010@0102 -> 0x10 0x02 0x01 または、0x10 0x02 0x01 0xFF(昔のルーチン?) // //0x10だけ別処理が必要. //0x10の後、+2バイト後に 終端0xFFがあることがある. if (code1 == 0x80) { uint code2 = 0x1C; if (i < sjisstr.Length && sjisstr[i] == '@') { code2 = at_code_to_binary(sjisstr, i, out i); } else { //一番無害な、 0x1C 目を開ける で補正しよう Log.Error("@0080の後に、@命令が続いていません。@001Cで補正します。"); } ret.Add((byte)(code1)); //@0080 ret.Add((byte)(code2)); //@0000 if (textEngineRework == PatchUtil.TextEngineRework_enum.TeqTextEngineRework) { i += TeqTextEngineRework(ret, code2, sjisstr, i); } } else if (code1 == 0x10) { uint code2 = 0x0101; if (i < sjisstr.Length && sjisstr[i] == '@') { code2 = at_code_to_binary(sjisstr, i, out i); if (code2 < 0x100) {//@0010 の次のコードが 0x0003 みたいに 0x100以下 R.Debug("@0010の次のコードが 0x100以下です。危険なので、+0x100補正します。 code2:{0}", code2); code2 += 0x100; } } else { //一番 無害な 0x0101で補正. R.Debug("@0010の後に、@命令が続いていません。@0010@0101@0001で補正します。"); } uint code3 = 0x0; if (i < sjisstr.Length && sjisstr[i] == '@') { code3 = at_code_to_binary(sjisstr, i, out i); } else {//@0010@0101??? R.Debug("@0010命令が途中で終わってしまいました。"); } ret.Add((byte)(code1)); //@0010 ret.Add((byte)(code2 & 0xFF)); //@0000 //@0102 みたいなのは、リトルエンディアン化する必要がある ret.Add((byte)((code2 >> 8) & 0xFF)); //@0000 if (code3 > 0) { ret.Add((byte)(code3)); //@0010終端に謎のコード 大昔は 0xFFでも入れていたのかなあ・・・? } } else {//@0080 と @0010 以外は1バイトで格納 ret.Add((byte)(code1 & 0xFF)); } continue; } if (i + 1 >= sjisstr.Length) {//もう余白がないので1バイト文字列 ret.Add(sjisstr[i]); i++; } else { byte code1 = sjisstr[i]; byte code2 = sjisstr[i + 1]; if (priorityCode == PatchUtil.PRIORITY_CODE.UTF8 && code1 >= 0xC0 && code1 >= 0x80) { i += U.AppendUTF8(ret, sjisstr, i); } else if (priorityCode == PatchUtil.PRIORITY_CODE.SJIS && U.isSJIS1stCode(code1) && U.isSJIS2ndCode(code2)) { ret.Add(sjisstr[i]); i++; ret.Add(sjisstr[i]); i++; } else {//1バイト ret.Add(sjisstr[i]); i++; } } } //0終端 ret.Add(0); ret.Add(0); //終端が2つないとダメ?らしい. return(ret.ToArray()); }
public String UnHffmanPatchDecodeLow(byte[] srcdata) { PatchUtil.TextEngineRework_enum textEngineRework = PatchUtil.SearchTextEngineReworkPatch(); List <byte> str = new List <byte>(); int length = srcdata.Length; int i = 0; while (i < length) { byte code = srcdata[i]; if (length > i + 1) { byte code2 = srcdata[i + 1]; if (this.PriorityCode == PatchUtil.PRIORITY_CODE.UTF8) { if (U.IsUTF8_LAT1SpecialFont(code, code2)) { //LAT1の特殊コードのエリア AppendAtmarkCode(str, code); //@00C0 AppendAtmarkCode(str, code2); //@0081 i += 2; continue; } else if (U.isUTF8PreCode(code, code2)) { i += U.AppendUTF8(str, srcdata, i); continue; } } if (U.isSJIS1stCode(code) && U.isSJIS2ndCode(code2)) {//SJISコード 2バイト読み飛ばす. i += AppendSJIS(str, code, code2); continue; } //unHuffman patchでは可変長デコードらしい. //@0009 -> 0x09 //@0080@000d -> 0x80 0x0d //@0010@0102 -> 0x10 0x02 0x01 0x01 または、0x10 0x02 0x01 0xFF // //0x10だけ別処理が必要. //0x10の後、+2バイト後に 終端0x01 か 0xFFがある if (code == 0x80) { //code2 = srcdata[i + 1]; AppendAtmarkCode(str, code); //@0080 AppendAtmarkCode(str, code2); //@000d i += 2; if (textEngineRework == PatchUtil.TextEngineRework_enum.TeqTextEngineRework) { i += TeqTextEngineRework(str, code2, srcdata, i); } continue; } if (code == 0x10) { if (length <= i + 2) {//もう文字列の容量がないので、 @0010@0102 じゃないと思う. 謎のコード. str.Add(code); str.Add(code2); i += 2; continue; } code2 = srcdata[i + 1]; byte code3 = srcdata[i + 2]; uint code23 = ((uint)code3 << 8) | (((uint)code2) & 0xFF); AppendAtmarkCode(str, code); //@0010 AppendAtmarkCode(str, code23); //@0102 i += 3; continue; } } if (code < 0x20 || code == 0x40) { AppendAtmarkCode(str, code); //@000Fとかのコード i += 1; continue; } //特殊Unicode if (this.PriorityCode == PatchUtil.PRIORITY_CODE.LAT1 && U.IsEnglishSPCode(code)) { //英語版FEにはUnicodeの1バイトだけ表記があるらしい. AppendAtmarkCode(str, code); //@000Fとかのコード i += 1; continue; } //アルファベット等だと思われる. str.Add(code); i += 1; } return(listbyte_to_string_low(str.ToArray(), str.Count)); }