public Text_4(Narc files, CharTable charTable) { Version = 3; TextList.Clear(); TextList.Add(new List <List <string> >()); foreach (byte[] bytes in files.Files) { BinaryReader br = new BinaryReader(new MemoryStream(bytes)); List <string> s4 = new List <string>(); bool flag2 = false; int stringCount = br.ReadUInt16(), originalKey = br.ReadUInt16(); OriginalKeys.Add(originalKey); int num = (originalKey * 0x2fd) & 0xffff; int[] numArray = new int[stringCount]; int[] numArray2 = new int[stringCount]; for (int i = 0; i < stringCount; i++) { int num2 = (num * (i + 1)) & 0xffff; int num3 = num2 | (num2 << 16); numArray[i] = br.ReadInt32(); numArray[i] = numArray[i] ^ num3; numArray2[i] = br.ReadInt32(); numArray2[i] = numArray2[i] ^ num3; } for (int j = 0; j < stringCount; j++) { int control = 0; num = (0x91bd3 * (j + 1)) & 0xffff; string text = ""; for (int k = 0; k < numArray2[j]; k++) { int num4 = br.ReadUInt16(); num4 ^= num; switch (control) { case 0: switch (num4) { case 0xE000: text += "\\n"; break; case 0x25BC: if (Version > 2) { text += "\\f"; } else { text += "\\r"; } break; case 0x25BD: if (Version > 2) { text += "\\r"; } else { text += "\\f"; } break; case 0xF100: flag2 = true; break; case 0xFFFE: text += "["; control = 1; break; case 0xFFFF: break; default: if (flag2) { int num5 = 0; int num6 = 0; string str = null; while (true) { if (num5 >= 15) { num5 -= 15; if (num5 > 0) { int num8 = num6 | (num4 << 9 - num5 & 511); if ((num8 & 255) == 255) { break; } if (num8 != 0 && num8 != 1) { char str2 = charTable.GetCharacter(num8); if (str2 == '\0') { text += "\\x" + num8.ToString("X4"); } else { text += str2; } } } } else { int num8 = num4 >> num5 & 511; if ((num8 & 255) == 255) { break; } if (num8 != 0 && num8 != 1) { char str3 = charTable.GetCharacter(num8); if (str3 == '\0') { text += "\\x" + num8.ToString("X4"); } else { text += str3; } } num5 += 9; if (num5 < 15) { num6 = num4 >> num5 & 511; num5 += 9; } num += 18749; num &= 65535; num4 = br.ReadUInt16(); num4 ^= num; k++; } } text += str; } else { char str3 = charTable.GetCharacter(num4); if (str3 == '\0') { text += "\\x" + num4.ToString("X4"); } else { text += str3; } } break; } break; case 1: text += num4.ToString("X4"); if (num4 == 0x0129) // 不知道为何,很奇怪的控制符 { control = 3; } else { control = 2; } break; case 2: control = -num4; if (control == 0) { text += "]"; } break; case 3: control = -num4 + 1; if (control == 0) { text += "]"; } break; default: text += "," + num4.ToString("X4"); control++; if (control == 0) { text += "]"; } break; } num += 18749; num &= 65535; } s4.Add(text); } TextList[0].Add(s4); } }
public byte[] Save(CharTable charTable, StyleType style = StyleType.BOTTOM_RIGHT, FontType font = FontType.SONG_TI) { switch (Gen) { case Generation.Gen.Gen4: while (Table.Items.Length <= charTable.maxCharCode) { Table.AddNewItem(); } for (ushort i = 1; i <= charTable.maxCharCode; i++) { char c = charTable.GetCharacter(i); if (ChinesePunctuation.Contains(c)) { Table.Items[i - 1].Item = DrawChar.CharToValues(c, style, FontType.MS_GOTHIC, posX: -2 + ("?!".Contains(c) ? -3 : 0), posY: 2); Table.Items[i - 1].Width = 13; } else if (i >= ChineseCharStart) { Table.Items[i - 1].Item = DrawChar.CharToValues(c, style, font); Table.Items[i - 1].Width = 13; } } break; case Generation.Gen.Gen5: NFTRNitroFile tempTable = (NFTRNitroFile)Table; /* * foreach (char c in ChinesePunctuation) * { * ushort code = tempTable[c]; * if (code > 0 && code < tempTable.Items.Length) * { * CGLPFrame.Character item = (CGLPFrame.Character)tempTable.Items[code]; * switch (font) * { * case FontType.PIXEL_9: * item.Width = (byte)(((style == StyleType.BOTTOM_RIGHT_5) ? 9 : 10) - item.SpaceWidth); * break; * default: * item.Width = (byte)(12 - item.SpaceWidth); * break; * } * } * }*/ CMAPFrame lastFrame = (CMAPFrame)tempTable.Frames[tempTable.FramesCount - 1]; char[] originalChars = lastFrame.Keys, newChars = charTable.Values; ushort[] originalValues = lastFrame.Values, newValues = charTable.Keys; for (ushort i = 0, j = 0; i < originalChars.Length && j < newChars.Length; i++) { if (originalChars[i] >= 0x4E00 && originalChars[i] < 0xE000) { while (j < newChars.Length && (newChars[j] < 0x4E00 || newChars[j] >= 0xE000)) { j++; } if (j < newChars.Length) { lastFrame[originalValues[i]] = newChars[j]; CGLPFrame.Character item = (CGLPFrame.Character)tempTable.Items[originalValues[i]]; switch (font) { case FontType.PIXEL_9: item.Item = DrawChar.CharToValues(newChars[j], style, font, posX: -1, posY: -1); item.Width = (byte)((style == StyleType.BOTTOM_RIGHT_5) ? 9 : 10); break; default: item.Item = DrawChar.CharToValues(newChars[j], style, font); item.Width = 12; break; } item.SpaceWidth = 0; j++; } } } break; default: return(new byte[0]); } MemoryStream ms = new MemoryStream(); BinaryWriter bw = new BinaryWriter(ms); Table.WriteTo(bw); byte[] bytes = new byte[ms.Length]; ms.Position = 0; ms.Read(bytes, 0, bytes.Length); bw.Close(); return(bytes); }