public void writeZone(ByteArrayOutputStream outp) { outp.writeUShort((ushort)X); outp.writeUShort((ushort)Y); outp.writeUShort((ushort)Width); outp.writeUShort((ushort)Height); outp.writeByte((byte)Number); outp.writeByte(0); outp.writeByte(0); outp.writeByte(0); }
public void save(ByteArrayOutputStream outp) { foreach (List <ObjectDefTile> row in tiles) { foreach (ObjectDefTile t in row) { t.write(outp); } outp.writeByte(0xFE); //new line } outp.writeByte(0xFF); //end object }
public void saveObjects() { ByteArrayOutputStream eObjIndexFile = new ByteArrayOutputStream(); ByteArrayOutputStream eObjFile = new ByteArrayOutputStream(); for (int i = 0; i < Objects.Length; i++) { if (Objects[i] == null) { break; } eObjIndexFile.writeUShort((ushort)eObjFile.getPos()); eObjIndexFile.writeByte((byte)Objects[i].width); eObjIndexFile.writeByte((byte)Objects[i].height); Objects[i].save(eObjFile); } ObjFile.replace(eObjFile.getArray(), this); ObjIndexFile.replace(eObjIndexFile.getArray(), this); }
public static byte[] LZ77_Compress(byte[] data, bool header = false) { ByteArrayOutputStream res = new ByteArrayOutputStream(); if (header) //0x37375A4C { res.writeByte(0x4C); res.writeByte(0x5A); res.writeByte(0x37); res.writeByte(0x37); } res.writeInt((data.Length << 8) | 0x10); byte[] tempBuffer = new byte[16]; //Current byte to compress. int current = 0; while (current < data.Length) { int tempBufferCursor = 0; byte blockFlags = 0; for (int i = 0; i < 8; i++) { //Not sure if this is needed. The DS probably ignores this data. if (current >= data.Length) { tempBuffer[tempBufferCursor++] = 0; continue; } int searchPos = 0; int searchLen = 0; LZ77_Compress_Search(data, current, out searchPos, out searchLen); int searchDisp = current - searchPos - 1; if (searchLen > 2) //We found a big match, let's write a compressed block. { blockFlags |= (byte)(1 << (7 - i)); tempBuffer[tempBufferCursor++] = (byte)((((searchLen - 3) & 0xF) << 4) + ((searchDisp >> 8) & 0xF)); tempBuffer[tempBufferCursor++] = (byte)(searchDisp & 0xFF); current += searchLen; } else { tempBuffer[tempBufferCursor++] = data[current++]; } } res.writeByte(blockFlags); for (int i = 0; i < tempBufferCursor; i++) { res.writeByte(tempBuffer[i]); } } return(res.getArray()); }
public void write(ByteArrayOutputStream outp) { if (controlTile) { outp.writeByte(controlByte); } else if (emptyTile) { outp.writeByte(controlByte); outp.writeByte(0); outp.writeByte(0); } else { outp.writeByte(controlByte); outp.writeByte((byte)(tileID % 256)); outp.writeByte((byte)(tileID / 256 + t.ObjectDefTileOffset)); } }
public void write(ByteArrayOutputStream outp, ByteArrayOutputStream cam, int camID) { outp.writeUShort((ushort)X); outp.writeUShort((ushort)Y); outp.writeUShort((ushort)Width); outp.writeUShort((ushort)Height); outp.writeByte((byte)Number); outp.writeByte((byte)camID); outp.writeByte((byte)Music); outp.writeByte((byte)Unknown1); outp.writeByte((byte)Unknown2); outp.writeByte((byte)Unknown3); outp.writeByte((byte)Lighting); outp.writeByte((byte)FlagpoleID); cam.writeInt(CameraTop); cam.writeInt(CameraBottom); cam.writeInt(CameraTopSpin); cam.writeInt(CameraBottomSpin); cam.writeUShort((ushort)camID); cam.writeUShort((ushort)CameraBottomStick); cam.writeUInt(0); //This seems just padding. }
public void write(ByteArrayOutputStream outp) { if (controlTile) outp.writeByte(controlByte); else if(emptyTile) { outp.writeByte(0); outp.writeByte(0); outp.writeByte(0); } else { outp.writeByte(controlByte); outp.writeByte((byte)(tileID % 256)); outp.writeByte((byte)(tileID / 256 + t.ObjectDefTileOffset)); } }
public void save(ByteArrayOutputStream outp) { foreach (List<ObjectDefTile> row in tiles) { foreach (ObjectDefTile t in row) t.write(outp); outp.writeByte(0xFE); //new line } outp.writeByte(0xFF); //end object }
public void saveObjects() { ByteArrayOutputStream eObjIndexFile = new ByteArrayOutputStream(); ByteArrayOutputStream eObjFile = new ByteArrayOutputStream(); for (int i = 0; i < Objects.Length; i++) { if (Objects[i] == null) break; eObjIndexFile.writeUShort((ushort)eObjFile.getPos()); eObjIndexFile.writeByte((byte)Objects[i].width); eObjIndexFile.writeByte((byte)Objects[i].height); Objects[i].save(eObjFile); } ObjFile.replace(eObjFile.getArray(), this); ObjIndexFile.replace(eObjIndexFile.getArray(), this); }
public static byte[] LZ77_Compress(byte[] data, bool header = false) { ByteArrayOutputStream res = new ByteArrayOutputStream(); if (header) //0x37375A4C { res.writeByte(0x4C); res.writeByte(0x5A); res.writeByte(0x37); res.writeByte(0x37); } res.writeInt((data.Length << 8) | 0x10); byte[] tempBuffer = new byte[16]; //Current byte to compress. int current = 0; while (current < data.Length) { int tempBufferCursor = 0; byte blockFlags = 0; for (int i = 0; i < 8; i++) { //Not sure if this is needed. The DS probably ignores this data. if (current >= data.Length) { tempBuffer[tempBufferCursor++] = 0; continue; } int searchPos = 0; int searchLen = 0; LZ77_Compress_Search(data, current, out searchPos, out searchLen); int searchDisp = current - searchPos - 1; if (searchLen > 2) //We found a big match, let's write a compressed block. { blockFlags |= (byte)(1 << (7 - i)); tempBuffer[tempBufferCursor++] = (byte)((((searchLen - 3) & 0xF) << 4) + ((searchDisp >> 8) & 0xF)); tempBuffer[tempBufferCursor++] = (byte)(searchDisp & 0xFF); current += searchLen; } else { tempBuffer[tempBufferCursor++] = data[current++]; } } res.writeByte(blockFlags); for (int i = 0; i < tempBufferCursor; i++) res.writeByte(tempBuffer[i]); } return res.getArray(); }
public void writeZone(ByteArrayOutputStream outp) { outp.writeUShort((ushort)X); outp.writeUShort((ushort)Y); outp.writeUShort((ushort)Width); outp.writeUShort((ushort)Height); outp.writeByte((byte)Number); outp.writeByte(0); outp.writeByte(0); outp.writeByte(0); }
public void write(ByteArrayOutputStream outp, ByteArrayOutputStream cam, int camID) { outp.writeUShort((ushort)X); outp.writeUShort((ushort)Y); outp.writeUShort((ushort)Width); outp.writeUShort((ushort)Height); outp.writeByte((byte)Number); outp.writeByte((byte)camID); outp.writeByte((byte)Music); outp.writeByte((byte)Unknown1); outp.writeByte((byte)Unknown2); outp.writeByte((byte)Unknown3); outp.writeByte((byte)Lighting); outp.writeByte((byte)FlagpoleID); cam.writeInt(CameraTop); cam.writeInt(CameraBottom); cam.writeInt(CameraTopSpin); cam.writeInt(CameraBottomSpin); cam.writeUShort((ushort)camID); cam.writeUShort((ushort)CameraBottomStick); cam.writeUInt(0); //This seems just padding. }