public void write(Writer writer) { List <DataInfo> dataInfo = new List <DataInfo>(); // Script Code dataInfo.Clear(); for (int dataPos = 0; dataPos < scriptCodeLength;) { DataInfo info = new DataInfo(); info.data.Clear(); info.readInt = scriptCode[dataPos] < 0 || scriptCode[dataPos] >= 0x100; if (!info.readInt) { for (int i = 0; (scriptCode[dataPos] >= 0 && scriptCode[dataPos] < 0x100) && i < 0x7F; ++i) { info.data.Add(scriptCode[dataPos++]); if (dataPos >= scriptCodeLength) { break; } } dataInfo.Add(info); } else { for (int i = 0; (scriptCode[dataPos] < 0 || scriptCode[dataPos] >= 0x100) && i < 0x7F; ++i) { info.data.Add(scriptCode[dataPos++]); if (dataPos >= scriptCodeLength) { break; } } dataInfo.Add(info); } } int count = dataInfo.Take(dataInfo.Count).Sum(x => x.data.Count); writer.Write(count); for (int i = 0; i < dataInfo.Count; ++i) { DataInfo info = dataInfo[i]; writer.Write((byte)(info.data.Count | ((byte)(info.readInt ? 1 : 0) << 7))); for (int d = 0; d < info.data.Count; ++d) { if (info.readInt) { writer.Write(info.data[d]); } else { writer.Write((byte)info.data[d]); } } } // Jump Table dataInfo.Clear(); for (int dataPos = 0; dataPos < jumpTableLength;) { DataInfo info = new DataInfo(); info.data.Clear(); info.readInt = jumpTable[dataPos] < 0 || jumpTable[dataPos] >= 0x100; if (!info.readInt) { for (int i = 0; (jumpTable[dataPos] >= 0 && jumpTable[dataPos] < 0x100) && i < 0x7F; ++i) { info.data.Add(jumpTable[dataPos++]); if (dataPos >= jumpTableLength) { break; } } dataInfo.Add(info); } else { for (int i = 0; (jumpTable[dataPos] < 0 || jumpTable[dataPos] >= 0x100) && i < 0x7F; ++i) { info.data.Add(jumpTable[dataPos++]); if (dataPos >= jumpTableLength) { break; } } dataInfo.Add(info); } } count = dataInfo.Take(dataInfo.Count).Sum(x => x.data.Count); writer.Write(count); for (int i = 0; i < dataInfo.Count; ++i) { DataInfo info = dataInfo[i]; writer.Write((byte)(info.data.Count | ((byte)(info.readInt ? 1 : 0) << 7))); for (int d = 0; d < info.data.Count; ++d) { if (info.readInt) { writer.Write(info.data[d]); } else { writer.Write((byte)info.data[d]); } } } // Scripts writer.Write((ushort)scripts.Count); foreach (ScriptInfo script in scripts) { writer.Write(script.scriptCodePos_main); writer.Write(script.scriptCodePos_draw); writer.Write(script.scriptCodePos_startup); } foreach (ScriptInfo script in scripts) { writer.Write(script.jumpTablePos_main); writer.Write(script.jumpTablePos_draw); writer.Write(script.jumpTablePos_startup); } // Functions writer.Write((ushort)functionList.Count); foreach (FunctionScript func in functionList) { writer.Write(func.scriptCodePos); } foreach (FunctionScript func in functionList) { writer.Write(func.jumpTablePos); } writer.Close(); }