public void Setup(ZAnimationInfo info) { numFrames = info.numFrames; Globals.Assert(numFrames <= (int)Enum.kMaxTexturesInAnim); float gapTotal = 0; for (int i = 0; i < numFrames; i++) { gapTotal += info.frameTime[i]; texture[i] = info.texture[i]; subTextureId[i] = info.subTextureId[i]; frameTime[i] = gapTotal; } state = AnimationState.kAnimNotStarted; gapType = info.gapType; currentFrame = 0; }
private long writeFile(ref long nullsPos, Stream dest, long dstPos, ref bool firstFile, Stream srcStream, FstFile lastFile, FstFile file, List <JunkRedumpPatch> patches, NStream nstream, long junkStart, bool isJunkFile) { //Debug.WriteLine(string.Format(@"{0} : {1} : {2} : {3}/{4}", file.DataOffset.ToString("X8"), (file.DataOffset + file.Length).ToString("X8"), /*(nextFile.DataOffset - lastEnd).ToString("X8"),*/ file.Length.ToString("X8"), file.Path, file.Name)); //file found long gap = writeDestGap(nullsPos, dest, dstPos, file.DataOffset - dstPos, firstFile, patches, junkStart, nstream); firstFile = false; bool missing = false; if (file.Length == 0) { // missing = true; } else if (isJunkFile) { missing = true; MemorySection ms = MemorySection.Read(srcStream, 8); long size = ms.ReadUInt32B(0); GapType gt = (GapType)(size & 0b11); size &= 0xFFFFFFFC; //set nullsPos value if zerobyte file without junk if (gt == GapType.JunkFile) { nullsPos = Math.Min(nullsPos - (dstPos + gap), 0); //reset the nulls long nulls = (size & 0xFC) >> 2; long junkFileLen = ms.ReadUInt32B(4); if (junkFileLen != file.Length) { throw new HandledException(string.Format("NKit Junk file restoration length mismatch {0}: {1}", file.DataOffset.ToString("X8"), file.Name)); } ByteStream.Zeros.Copy(dest, nulls); nstream.JunkStream.Position = (dstPos + gap) + nulls; nstream.JunkStream.Copy(dest, junkFileLen - nulls); _log?.LogDetail(string.Format("Generated file content with Junk {0}: {1}", file.DataOffset.ToString("X8"), file.Name)); } else { throw new HandledException(string.Format("NKit Junk file restoration bytes invalid {0}: {1}", file.DataOffset.ToString("X8"), file.Name)); } } else { byte[] f = new byte[Math.Min(0x30, file.Length)]; srcStream.Read(f, 0, f.Length); //then read while junk is created if (lastFile.DataOffset == file.DataOffset && lastFile.Length == 0) //null file overlapped this file so set nullsPos to have a gap (XGIII) needs fst sorting by offset then size { nullsPos = dstPos + 0x1CL; //will already be aligned } int nulls = (int)(nullsPos - (dstPos + gap)); nstream.JunkStream.Position = file.DataOffset; //async junk gen int countNulls = 0; for (int i = 0; i < f.Length && f[i] == 0; i++) { countNulls++; } if (f.Length > nulls && countNulls < f.Length) //don't test all nulls { missing = nstream.JunkStream.Compare(f, 0, f.Length, Math.Max(0, nulls)) == f.Length; } if (missing) { _log?.LogDetail(string.Format("File content is Junk {0}: {1}", file.DataOffset.ToString("X8"), file.Name)); } dest.Write(f, 0, f.Length); srcStream.Copy(dest, file.Length - f.Length); //copy file } if (!missing) //reset the gap when no junk { nullsPos = dstPos + gap + file.Length + 0x1c; if (nullsPos % 4 != 0) { nullsPos += 4 - (nullsPos % 4); } } return(gap + file.Length); }
private void UpdateAllowedSlippages(double newSlippage, GapType gap) { double[] arr = new double[] {newSlippage, EffectiveMinAllowedSlippage, EffectiveMaxAllowedSlippage}; double minSlip = arr.Min(); double maxSlip = arr.Max(); LoggingUtility.WriteDebug(LoggingConfig, string.Format( "An opening gap of '{0}' caused changes to allowed slippages. [Before - Min: {1}. Max {2}] [After - Min: {3}. Max: {4}]", gap, EffectiveMinAllowedSlippage, EffectiveMaxAllowedSlippage, minSlip, maxSlip)); EffectiveMaxAllowedSlippage = maxSlip; EffectiveMinAllowedSlippage = minSlip; }
public ScoringEntity() { Console.WriteLine("scoring entity created"); gapType = GapType.None; }
} ///@property(readwrite,assign) AnimationState state; public void SetGapType(GapType inThing) { gapType = inThing; } ///@property(readwrite,assign) GapType gapType;
private long writeGap(ConvertFile file, ref long nullsPos, ref long srcPos, long dstPos, NStream inStream, Stream target, bool firstOrLastFile) { if (file.GapLength == 0) { if (file.FstFile.Length == 0) { nullsPos = dstPos + 0x1c; } return(0); } MemorySection ms = MemorySection.Read(inStream, 4); srcPos += 4; long size = ms.ReadUInt32B(0); GapType gt = (GapType)(size & 0b11); size &= 0xFFFFFFFC; if (size == 0xFFFFFFFC) //for wii only. not a thing for GC { srcPos += 4; inStream.Read(ms.Data, 0, 4); size = 0xFFFFFFFCL + (long)ms.ReadUInt32B(0); //cater for files > 0xFFFFFFFF } long nulls; long junkFileLen = 0; //set nullsPos value if zerobyte file without junk if (gt == GapType.JunkFile) { nullsPos = Math.Min(nullsPos - dstPos, 0); nulls = (size & 0xFC) >> 2; inStream.Read(ms.Data, 0, 4); srcPos += 4; junkFileLen = ms.ReadUInt32B(0); file.FstFile.Length = junkFileLen; junkFileLen += junkFileLen % 4 == 0 ? 0 : 4 - (junkFileLen % 4); ByteStream.Zeros.Copy(target, nulls); inStream.JunkStream.Position = dstPos + nulls; inStream.JunkStream.Copy(target, junkFileLen - nulls); dstPos += junkFileLen; if (file.GapLength <= 8) { return(junkFileLen); } else { //read gap inStream.Read(ms.Data, 0, 4); srcPos += 4; size = ms.ReadUInt32B(0); gt = (GapType)(size & 0b11); size &= 0xFFFFFFFC; } } else if (file.FstFile.Length == 0) //last zero byte file was legit { nullsPos = dstPos + 0x1c; } long maxNulls = Math.Max(0, nullsPos - dstPos); //0x1cL if (size < maxNulls) //need to test this commented if { nulls = size; } else { nulls = size >= 0x40000 && !firstOrLastFile ? 0 : maxNulls; } if (gt == GapType.AllJunk) { ByteStream.Zeros.Copy(target, nulls); inStream.JunkStream.Position = dstPos + nulls; inStream.JunkStream.Copy(target, size - nulls); dstPos += size; } else if (gt == GapType.AllScrubbed) { ByteStream.Zeros.Copy(target, size); dstPos += size; } else { long prg = size; byte btByte = 0x00; GapBlockType bt = GapBlockType.Junk; //should never be used while (prg > 0) { inStream.Read(ms.Data, 0, 4); srcPos += 4; long bytes; long blk = ms.ReadUInt32B(0); GapBlockType btType = (GapBlockType)(blk >> 30); bool btRepeat = btType == GapBlockType.Repeat; if (!btRepeat) { bt = btType; } long cnt = 0x3FFFFFFF & blk; if (bt == GapBlockType.NonJunk) { bytes = Math.Min(cnt * Gap.BlockSize, prg); inStream.Copy(target, bytes); srcPos += bytes; } else if (bt == GapBlockType.ByteFill) { if (!btRepeat) { btByte = (byte)(0xFF & cnt); //last 8 bits when not repeating are the byte cnt >>= 8; } bytes = Math.Min(cnt * Gap.BlockSize, prg); Stream bs; switch (btByte) { case 0x00: bs = ByteStream.Zeros; break; case 0x55: bs = ByteStream.Fives; break; case 0xff: bs = ByteStream.FFs; break; default: bs = new ByteStream(btByte); break; } bs.Copy(target, bytes); } else //if (bt == GapBlockType.Junk) { bytes = Math.Min(cnt * Gap.BlockSize, prg); maxNulls = Math.Max(0, nullsPos - dstPos); //0x1cL if (prg < maxNulls) { nulls = bytes; } else { nulls = bytes >= 0x40000 && !firstOrLastFile ? 0 : maxNulls; } ByteStream.Zeros.Copy(target, nulls); inStream.JunkStream.Position = dstPos + nulls; inStream.JunkStream.Copy(target, bytes - nulls); } prg -= bytes; dstPos += bytes; } } return(size + junkFileLen); }
private long writeGap(ref long fileLength, LongRef gapLength, ref long nullsPos, ref long srcPos, long dstPos, Stream inStream, Stream target, JunkStream junk, bool firstOrLastFile, ScrubManager scrub) { if (gapLength.Value == 0) { if (fileLength == 0) { nullsPos = dstPos + 0x1c; } return(0); } long srcLen = gapLength.Value; //fix added for (padding between junk files) - Zumba Fitness (Europe) (En,Fr,De,Es,It) MemorySection ms = MemorySection.Read(inStream, 4); srcPos += 4; long size = ms.ReadUInt32B(0); GapType gt = (GapType)(size & 0b11); size &= 0xFFFFFFFC; if (size == 0xFFFFFFFC) //for wii only. not a thing for GC { srcPos += 4; inStream.Read(ms.Data, 0, 4); size = 0xFFFFFFFCL + (long)ms.ReadUInt32B(0); //cater for files > 0xFFFFFFFF } gapLength.Value = size; scrub.AddGap(fileLength, dstPos, size); //keep track of trailing nulls when restoring scrubbed images long nulls; long junkFileLen = 0; //set nullsPos value if zerobyte file without junk if (gt == GapType.JunkFile) { nullsPos = Math.Min(nullsPos - dstPos, 0); nulls = (size & 0xFC) >> 2; inStream.Read(ms.Data, 0, 4); srcPos += 4; junkFileLen = ms.ReadUInt32B(0); fileLength = junkFileLen; junkFileLen += junkFileLen % 4 == 0 ? 0 : 4 - (junkFileLen % 4); ByteStream.Zeros.Copy(target, nulls); junk.Position = dstPos + nulls; junk.Copy(target, junkFileLen - nulls); dstPos += junkFileLen; if (srcLen <= 8) { return(junkFileLen); } else { //read gap inStream.Read(ms.Data, 0, 4); srcPos += 4; size = ms.ReadUInt32B(0); gt = (GapType)(size & 0b11); size &= 0xFFFFFFFC; gapLength.Value = size; } } else if (fileLength == 0) //last zero byte file was legit { nullsPos = dstPos + 0x1c; } long maxNulls = Math.Max(0, nullsPos - dstPos); //0x1cL if (size < maxNulls) //need to test this commented if { nulls = size; } else { nulls = size >= 0x40000 && !firstOrLastFile ? 0 : maxNulls; } nullsPos = dstPos + nulls; //belt and braces if (gt == GapType.AllJunk) { ByteStream.Zeros.Copy(target, nulls); junk.Position = dstPos + nulls; junk.Copy(target, size - nulls); dstPos += size; } else if (gt == GapType.AllScrubbed) { scrub.Scrub(target, dstPos, size, 0); dstPos += size; } else { long prg = size; byte btByte = 0x00; GapBlockType bt = GapBlockType.Junk; //should never be used while (prg > 0) { inStream.Read(ms.Data, 0, 4); srcPos += 4; long bytes; long blk = ms.ReadUInt32B(0); GapBlockType btType = (GapBlockType)(blk >> 30); bool btRepeat = btType == GapBlockType.Repeat; if (!btRepeat) { bt = btType; } long cnt = 0x3FFFFFFF & blk; if (bt == GapBlockType.NonJunk) { bytes = Math.Min(cnt * Gap.BlockSize, prg); inStream.Copy(target, bytes); srcPos += bytes; } else if (bt == GapBlockType.ByteFill) { if (!btRepeat) { btByte = (byte)(0xFF & cnt); //last 8 bits when not repeating are the byte cnt >>= 8; } bytes = Math.Min(cnt * Gap.BlockSize, prg); scrub.Scrub(target, dstPos, bytes, btByte); } else //if (bt == GapBlockType.Junk) { bytes = Math.Min(cnt * Gap.BlockSize, prg); maxNulls = Math.Max(0, nullsPos - dstPos); //0x1cL if (prg < maxNulls) { nulls = bytes; } else { nulls = bytes >= 0x40000 && !firstOrLastFile ? 0 : maxNulls; } ByteStream.Zeros.Copy(target, nulls); junk.Position = dstPos + nulls; junk.Copy(target, bytes - nulls); } prg -= bytes; dstPos += bytes; } } return(gapLength.Value + junkFileLen); }