Skip to content

Commit

Permalink
reduce redundant lines
Browse files Browse the repository at this point in the history
  • Loading branch information
DeathChaos25 committed Oct 20, 2024
1 parent bb2ec52 commit 1e3a759
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ public unsafe byte[] ApplyGeneric(List<TblPatch> patches)
using var memoryStream = new ExtendedMemoryStream(result, true);
foreach (var segment in segments)
{
// memoryStream.WriteBigEndianPrimitive(segment.Length);
memoryStream.Write(segment.Span);
// memoryStream.AddPadding(P5RTblSegmentFinder.TblSegmentAlignment);
}

return result;
Expand Down
15 changes: 5 additions & 10 deletions p5rpc.modloader/Merging/Tbl/P3PTblMerger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ await Task.Run(async () =>
}

// Then we merge
byte[] patched;
patched = await PatchAny(extractedTbl.Value.ToArray(), candidates, ResolverSize);
var patched = await PatchAny(extractedTbl.Value.ToArray(), candidates, ResolverSize);

// Then we store in cache.
var item = await _mergedFileCache.AddAsync(cacheKey, sources, patched);
Expand All @@ -196,8 +195,7 @@ private static async Task<byte[]> PatchTable(TblType type, byte[] extractedTable
for (var x = 0; x < candidates.Count; x++)
patches.Add(patcher.GeneratePatch(await File.ReadAllBytesAsync(candidates[x])));

var patched = patcher.Apply(patches, type);
return patched;
return patcher.Apply(patches, type);
}

private async Task<byte[]> PatchMsgTable(byte[] extractedTable, List<string> candidates)
Expand All @@ -216,8 +214,7 @@ private async Task<byte[]> PatchMsgTable(byte[] extractedTable, List<string> can
for (var x = 0; x < candidates.Count; x++)
patches.Add(patcher.GeneratePatch(await File.ReadAllBytesAsync(candidates[x])));

var patched = patcher.Apply(patches, TblType.Message, bmds);
return patched;
return patcher.Apply(patches, TblType.Message, bmds);
}

private async Task<byte[]> PatchAiCalc(byte[] extractedTable, List<string> candidates)
Expand All @@ -240,8 +237,7 @@ private async Task<byte[]> PatchAiCalc(byte[] extractedTable, List<string> candi
for (var x = 0; x < candidates.Count; x++)
patches.Add(patcher.GeneratePatch(await File.ReadAllBytesAsync(candidates[x])));

var patched = patcher.Apply(patches, TblType.AiCalc, bfs);
return patched;
return patcher.Apply(patches, TblType.AiCalc, bfs);
}

private static async Task<byte[]> PatchAny(byte[] extractedTable,
Expand All @@ -252,7 +248,6 @@ private static async Task<byte[]> PatchAny(byte[] extractedTable,
for (var x = 0; x < candidates.Count; x++)
patches.Add(patcher.GeneratePatchGeneric(await File.ReadAllBytesAsync(candidates[x]), ResolverSize));

var patched = patcher.ApplyGeneric(patches);
return patched;
return patcher.ApplyGeneric(patches);
}
}
18 changes: 6 additions & 12 deletions p5rpc.modloader/Merging/Tbl/P4GTblMerger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,7 @@ await Task.Run(async () =>
}

// Then we merge
byte[] patched;
patched = await PatchAny(extractedTbl.Value.ToArray(), candidates, ResolverSize);
var patched = await PatchAny(extractedTbl.Value.ToArray(), candidates, ResolverSize);

// Then we store in cache.
var item = await _mergedFileCache.AddAsync(cacheKey, sources, patched);
Expand All @@ -240,8 +239,7 @@ private async Task<byte[]> PatchTable(TblType type, byte[] extractedTable, List<
for (var x = 0; x < candidates.Count; x++)
patches.Add(patcher.GeneratePatch(await File.ReadAllBytesAsync(candidates[x])));

var patched = patcher.Apply(patches, type);
return patched;
return patcher.Apply(patches, type);
}

private async Task<byte[]> PatchMsgTable(byte[] extractedTable, List<string> candidates)
Expand All @@ -260,8 +258,7 @@ private async Task<byte[]> PatchMsgTable(byte[] extractedTable, List<string> can
for (var x = 0; x < candidates.Count; x++)
patches.Add(patcher.GeneratePatch(await File.ReadAllBytesAsync(candidates[x])));

var patched = patcher.Apply(patches, TblType.Message, bmds);
return patched;
return patcher.Apply(patches, TblType.Message, bmds);
}

private async Task<byte[]> PatchAiCalc(byte[] extractedTable, List<string> candidates)
Expand All @@ -284,8 +281,7 @@ private async Task<byte[]> PatchAiCalc(byte[] extractedTable, List<string> candi
for (var x = 0; x < candidates.Count; x++)
patches.Add(patcher.GeneratePatch(await File.ReadAllBytesAsync(candidates[x])));

var patched = patcher.Apply(patches, TblType.AiCalc, bfs);
return patched;
return patcher.Apply(patches, TblType.AiCalc, bfs);
}

private static async Task<byte[]> PatchAny(byte[] extractedTable, List<string> candidates, int ResolverSize)
Expand All @@ -295,8 +291,7 @@ private static async Task<byte[]> PatchAny(byte[] extractedTable, List<string> c
for (var x = 0; x < candidates.Count; x++)
patches.Add(patcher.GeneratePatchGeneric(await File.ReadAllBytesAsync(candidates[x]), ResolverSize));

var patched = patcher.ApplyGeneric(patches);
return patched;
return patcher.ApplyGeneric(patches);
}
private static async Task<byte[]> PatchAny(byte[] extractedTable, List<ICriFsRedirectorApi.BindFileInfo> candidates, int ResolverSize)
{
Expand All @@ -305,7 +300,6 @@ private static async Task<byte[]> PatchAny(byte[] extractedTable, List<ICriFsRed
for (var x = 0; x < candidates.Count; x++)
patches.Add(patcher.GeneratePatchGeneric(await File.ReadAllBytesAsync(candidates[x].FullPath), ResolverSize));

var patched = patcher.ApplyGeneric(patches);
return patched;
return patcher.ApplyGeneric(patches);
}
}
9 changes: 3 additions & 6 deletions p5rpc.modloader/Merging/Tbl/P5RTblMerger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ private static async Task<byte[]> PatchTable(TblType type, ArrayRental extracted
for (var x = 0; x < candidates.Count; x++)
patches.Add(patcher.GeneratePatch(await File.ReadAllBytesAsync(candidates[x].FullPath)));

var patched = patcher.Apply(patches);
return patched;
return patcher.Apply(patches);
}

private async ValueTask PatchAnyFile(Dictionary<string, List<ICriFsRedirectorApi.BindFileInfo>> pathToFileMap,
Expand Down Expand Up @@ -164,8 +163,7 @@ await Task.Run(async () =>
using var extractedTable = reader.ExtractFile(cpkEntry.Files[fileIndex].File);

// Then we merge
byte[] patched;
patched = await PatchAny(extractedTable, candidates, ResolverSize);
var patched = await PatchAny(extractedTable, candidates, ResolverSize);

// Then we store in cache.
var item = await _mergedFileCache.AddAsync(cacheKey, sources, patched);
Expand All @@ -183,7 +181,6 @@ private static async Task<byte[]> PatchAny(ArrayRental extractedTable,
for (var x = 0; x < candidates.Count; x++)
patches.Add(patcher.GeneratePatchGeneric(await File.ReadAllBytesAsync(candidates[x].FullPath), ResolverSize));

var patched = patcher.ApplyGeneric(patches);
return patched;
return patcher.ApplyGeneric(patches);
}
}

0 comments on commit 1e3a759

Please sign in to comment.