public void setSegment(uint index, uint segmentStart, uint segmentEnd, bool isMIO0, bool fakeMIO0, uint uncompressedOffset) { if (segmentStart > segmentEnd) { return; } if (!isMIO0) { segStart[index] = segmentStart; segIsMIO0[index] = false; uint size = segmentEnd - segmentStart; segData[index] = new byte[size]; for (uint i = 0; i < size; i++) { segData[index][i] = bytes[segmentStart + i]; } } else { if (fakeMIO0) { segStart[index] = segmentStart + uncompressedOffset; segIsMIO0[index] = false; } else { segIsMIO0[index] = true; } segData[index] = MIO0.mio0_decode(getSubArray(bytes, segmentStart, segmentEnd - segmentStart)); } }
public void setSegment(uint index, uint segmentStart, uint segmentEnd, bool isMIO0, bool fakeMIO0, uint uncompressedOffset, byte?areaID) { if (segmentStart > segmentEnd) { return; } SegBank seg = new SegBank(); seg.SegID = (byte)index; if (!isMIO0) { seg.SegStart = segmentStart; seg.IsMIO0 = false; uint size = segmentEnd - segmentStart; seg.Data = new byte[size]; for (uint i = 0; i < size; i++) { seg.Data[i] = bytes[segmentStart + i]; } } else { if (fakeMIO0) { seg.SegStart = segmentStart + uncompressedOffset; seg.IsMIO0 = false; } else { seg.IsMIO0 = true; } seg.Data = MIO0.mio0_decode(getSubArray_safe(bytes, segmentStart, segmentEnd - segmentStart)); } setSegment(index, seg, areaID); }
private int parseLevelScriptTemporarlyForSegments(byte[][] segments, uint[] segmentStarts, bool[] segmentsAreMIO0, byte seg, uint off) { ROM rom = ROM.Instance; byte[] data = segments[seg]; bool end = false; int endCmd = 0; byte l_seg; uint l_start, l_end, l_off; while (!end) { byte cmdLen = data[off + 1]; byte[] cmd = rom.getSubArray_safe(data, off, cmdLen); //rom.printArray(cmd, cmdLen); switch (cmd[0]) { case 0x00: case 0x01: { l_seg = cmd[3]; l_start = bytesToInt(cmd, 4, 4); l_end = bytesToInt(cmd, 8, 4); l_off = bytesToInt(cmd, 13, 3); segmentStarts[l_seg] = l_start; segments[l_seg] = rom.getROMSection(l_start, l_end); int end_r = parseLevelScriptTemporarlyForSegments(segments, segmentStarts, segmentsAreMIO0, l_seg, l_off); if (end_r == 0x02) { end = true; endCmd = 2; } } break; case 0x02: endCmd = 2; end = true; break; case 0x05: l_seg = cmd[4]; l_off = bytesToInt(cmd, 5, 3); if (l_seg == seg) { if ((long)l_off - (long)off == -4) { //Console.WriteLine("Infinite loop detected!"); return(0x02); } } endCmd = parseLevelScriptTemporarlyForSegments(segments, segmentStarts, segmentsAreMIO0, l_seg, l_off); end = true; break; case 0x06: l_seg = cmd[4]; l_off = bytesToInt(cmd, 5, 3); int end_ret = parseLevelScriptTemporarlyForSegments(segments, segmentStarts, segmentsAreMIO0, l_seg, l_off); if (end_ret == 0x02) { end = true; endCmd = 2; } break; case 0x07: end = true; endCmd = 0x07; break; case 0x17: l_seg = cmd[3]; l_start = bytesToInt(cmd, 4, 4); l_end = bytesToInt(cmd, 8, 4); if (l_start < l_end) { segmentStarts[l_seg] = l_start; segments[l_seg] = rom.getROMSection(l_start, l_end); } //rom.setSegment(seg, start, end, false); break; case 0x18: case 0x1A: l_seg = cmd[3]; l_start = bytesToInt(cmd, 4, 4); l_end = bytesToInt(cmd, 8, 4); if (l_start < l_end) { byte[] MIO0_header = rom.getSubArray_safe(rom.Bytes, l_start, 0x10); if (bytesToInt(MIO0_header, 0, 4) == 0x4D494F30) // Check MIO0 signature { int compressedOffset = (int)bytesToInt(MIO0_header, 0x8, 4); int uncompressedOffset = (int)bytesToInt(MIO0_header, 0xC, 4); bool isFakeMIO0 = rom.testIfMIO0IsFake(l_start, compressedOffset, uncompressedOffset); segmentsAreMIO0[l_seg] = !isFakeMIO0; if (isFakeMIO0) { segmentStarts[l_seg] = l_start + (uint)uncompressedOffset; } segments[l_seg] = MIO0.mio0_decode(rom.getROMSection(l_start, l_end)); } } break; case 0x1D: end = true; endCmd = 0x02; break; } off += cmdLen; } return(endCmd); }