Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -494,3 +494,4 @@ fabric.properties

### Custom ###
launchSettings.json
.idea/.idea.ShinRyuModManager-CE/.idea/sonarlint.xml
2 changes: 1 addition & 1 deletion ParLibrary.Tests/SllzTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void TestSllz(byte compressionVersion) {
var compressedBinaryFormat = (ParFile)ConvertFormat.With(typeof(Compressor), binaryFormat, parameters);
var decompressedBinaryFormat = (ParFile)ConvertFormat.With(typeof(Decompressor), compressedBinaryFormat);

Assert.IsTrue(compressedBinaryFormat.Stream.Length < decompressedBinaryFormat.Stream.Length);
Assert.IsLessThan(decompressedBinaryFormat.Stream.Length, compressedBinaryFormat.Stream.Length);
Assert.IsTrue(dataStream.Compare(decompressedBinaryFormat.Stream));
}
}
44 changes: 19 additions & 25 deletions ParLibrary/Converter/ParArchiveWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,22 +246,22 @@ private static void WriteNames(DataWriter writer, IEnumerable<Node> nodes) {
}

private static void WriteFolders(DataWriter writer, IEnumerable<Node> folders) {
foreach (var node in folders) {
foreach (var tags in folders.Select(x => x.Tags)) {
var attributes = 0x00000010;

if (node.Tags.TryGetValue("DirectoryInfo", out var directoryInfo)) {
if (tags.TryGetValue("DirectoryInfo", out var directoryInfo)) {
DirectoryInfo info = directoryInfo;
attributes = (int)info.Attributes;
}

if (node.Tags.TryGetValue("Attributes", out var attrs)) {
if (tags.TryGetValue("Attributes", out var attrs)) {
attributes = (int)attrs;
}

writer.Write((int)node.Tags["FolderCount"]);
writer.Write((int)node.Tags["FirstFolderIndex"]);
writer.Write((int)node.Tags["FileCount"]);
writer.Write((int)node.Tags["FirstFileIndex"]);
writer.Write((int)tags["FolderCount"]);
writer.Write((int)tags["FirstFolderIndex"]);
writer.Write((int)tags["FileCount"]);
writer.Write((int)tags["FirstFileIndex"]);
writer.Write(attributes);
writer.Write(0x00000000);
writer.Write(0x00000000);
Expand All @@ -275,39 +275,33 @@ private static void WriteFiles(DataWriter writer, IEnumerable<Node> files, long
foreach (var node in files) {
var parFile = node.GetFormatAs<ParFile>();

if (parFile == null) {
if (parFile == null)
continue;
}

if (node.Stream!.Length > 2048) {
blockSize = 2048 + (-node.Stream.Length % 2048);

var streamLength = node.Stream!.Length;

if (streamLength > 2048 || streamLength >= blockSize) {
blockSize = 2048 + (-streamLength % 2048);
dataPosition = Align(dataPosition, 2048);
} else {
if (node.Stream.Length < blockSize) {
blockSize -= node.Stream.Length;
} else {
blockSize = 2048 + (-node.Stream.Length % 2048);
dataPosition = Align(dataPosition, 2048);
}
blockSize -= streamLength;
}

ulong seconds = 0;
var attributes = parFile.Attributes;

if (!parameters.ResetFileDates) {
var date = parFile.FileDate;
var baseDate = new DateTime(1970, 1, 1);
var baseDate = DateTime.UnixEpoch;

if (node.Tags.TryGetValue("Timestamp", out var timestamp)) {
date = baseDate.AddSeconds(timestamp);
}

if (node.Tags.TryGetValue("FileInfo", out var fileInfo)) {
if (fileInfo is FileInfo info) {
attributes = HandleAttributes(info);

date = info.LastWriteTime;
}
if (node.Tags.TryGetValue("FileInfo", out var fileInfo) && fileInfo is FileInfo info) {
attributes = HandleAttributes(info);

date = info.LastWriteTime;
}

seconds = (ulong)(date - baseDate).TotalSeconds;
Expand Down
35 changes: 9 additions & 26 deletions ParLibrary/ParFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ public class ParFile : BinaryFormat, IConverter<BinaryFormat, ParFile> {
/// Initializes a new instance of the <see cref="ParFile"/> class.
/// </summary>
public ParFile() {
CanBeCompressed = true;
IsCompressed = false;
DecompressedSize = 0;
Attributes = 0x00000020;
FileDate = DateTime.Now;
}

Expand All @@ -29,10 +26,7 @@ public ParFile() {
public ParFile(DataStream stream) : base(stream) {
ArgumentNullException.ThrowIfNull(stream);

CanBeCompressed = true;
IsCompressed = false;
DecompressedSize = (uint)stream.Length;
Attributes = 0x00000020;
FileDate = DateTime.Now;
}

Expand All @@ -43,18 +37,15 @@ public ParFile(DataStream stream) : base(stream) {
/// <param name="offset">Start offset.</param>
/// <param name="length">Data length.</param>
public ParFile(DataStream stream, long offset, long length) : base(stream, offset, length) {
CanBeCompressed = true;
IsCompressed = false;
DecompressedSize = (uint)length;
Attributes = 0x00000020;
FileDate = DateTime.Now;
}

/// <summary>
/// Gets or sets a value indicating whether the file can be compressed.
/// </summary>
public bool CanBeCompressed { get; init; }
public bool CanBeCompressed { get; init; } = true;

/// <summary>
/// Gets or sets a value indicating whether the file is compressed.
/// </summary>
Expand All @@ -64,32 +55,24 @@ public ParFile(DataStream stream, long offset, long length) : base(stream, offse
/// Gets or sets the file size (decompressed).
/// </summary>
public uint DecompressedSize { get; init; }

/// <summary>
/// Gets or sets the file attributes.
/// </summary>
public int Attributes { get; init; }
public int Attributes { get; init; } = 0x00000020;

/// <summary>
/// Gets or sets the file date (as ulong).
/// </summary>
public ulong Timestamp { get; init; }

/// <summary>
/// Gets or sets the file date (as DateTime).
/// </summary>
public DateTime FileDate {
get {
var baseDate = new DateTime(1970, 1, 1);

return baseDate.AddSeconds(Timestamp);
}

private init {
var baseDate = new DateTime(1970, 1, 1);

Timestamp = (ulong)(value - baseDate).TotalSeconds;
}
get => DateTime.UnixEpoch.AddSeconds(Timestamp);

private init => Timestamp = (ulong)(value - DateTime.UnixEpoch).TotalSeconds;
}

/// <inheritdoc/>
Expand Down
34 changes: 14 additions & 20 deletions ParLibrary/Sllz/Compressor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private static DataStream Compress(DataStream inputDataStream, CompressorParamet
break;

case 2 when inputDataStream.Length < 0x1B:
throw new FormatException($"SLLZv2: Input size must more than 0x1A.");
throw new FormatException("SLLZv2: Input size must more than 0x1A.");

case 2:
compressedDataStream = CompressV2(inputDataStream);
Expand Down Expand Up @@ -135,9 +135,7 @@ private static DataStream CompressV1(DataStream inputDataStream) {
outputData[flagPosition] = 0x00;
outputPosition++;

if (outputPosition >= outputSize) {
throw new SllzCompressorException("Compressed size is bigger than original size.");
}
ThrowIfCompressedIsLarger(outputPosition, outputSize);

while (inputPosition < inputData.Length) {
var windowSize = Math.Min(inputPosition, MAX_WINDOW_SIZE);
Expand All @@ -158,18 +156,14 @@ private static DataStream CompressV1(DataStream inputDataStream) {
outputData[flagPosition] = 0x00;
outputPosition++;

if (outputPosition >= outputSize) {
throw new SllzCompressorException("Compressed size is bigger than original size.");
}
ThrowIfCompressedIsLarger(outputPosition, outputSize);
}

outputData[outputPosition] = inputData[inputPosition];
inputPosition++;
outputPosition++;

if (outputPosition >= outputSize) {
throw new SllzCompressorException("Compressed size is bigger than original size.");
}
ThrowIfCompressedIsLarger(outputPosition, outputSize);
} else {
currentFlag |= (byte)(1 << (7 - bitCount));
bitCount++;
Expand All @@ -183,9 +177,7 @@ private static DataStream CompressV1(DataStream inputDataStream) {
outputData[flagPosition] = 0x00;
outputPosition++;

if (outputPosition >= outputSize) {
throw new SllzCompressorException("Compressed size is bigger than original size.");
}
ThrowIfCompressedIsLarger(outputPosition, outputSize);
}

var offset = (short)((match.Item1 - 1) << 4);
Expand All @@ -195,16 +187,12 @@ private static DataStream CompressV1(DataStream inputDataStream) {
outputData[outputPosition] = (byte)tuple;
outputPosition++;

if (outputPosition >= outputSize) {
throw new SllzCompressorException("Compressed size is bigger than original size.");
}
ThrowIfCompressedIsLarger(outputPosition, outputSize);

outputData[outputPosition] = (byte)(tuple >> 8);
outputPosition++;

if (outputPosition >= outputSize) {
throw new SllzCompressorException("Compressed size is bigger than original size.");
}

ThrowIfCompressedIsLarger(outputPosition, outputSize);

inputPosition += match.Item2;
}
Expand Down Expand Up @@ -281,4 +269,10 @@ private static byte[] ZlibCompress(byte[] decompressedData) {

return outputMemoryStream.ToArray();
}

private static void ThrowIfCompressedIsLarger(uint outputPosition, uint outputSize) {
if (outputPosition >= outputSize) {
throw new SllzCompressorException("Compressed size is bigger than original size.");
}
}
}
4 changes: 3 additions & 1 deletion ShinRyuModManager-CE/GameModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ public static void DoY5HActProcedure(MLO mlo) {

try {
new DirectoryInfo(outputFakeDir).Delete(true);
} catch { }
} catch {
// ignore
}
} else {
var outputPath = Path.Combine(parlessDir.FullName, dir.Name + ".par");
Gibbed.Yakuza0.Pack.Program.Main([dir.FullName], outputPath);
Expand Down
2 changes: 2 additions & 0 deletions ShinRyuModManager-CE/LibMeta.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using JetBrains.Annotations;
using ShinRyuModManager.Helpers;

namespace ShinRyuModManager;

[UsedImplicitly]
public class LibMeta {
public Guid GUID { get; set; }
public string Name { get; set; }
Expand Down
8 changes: 4 additions & 4 deletions ShinRyuModManager-CE/ModLoadOrder/MLO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ public class MLO {
private const uint VERSION = 0x020000; // 2.0
private const uint FILESIZE = 0x0; // Remaining faithful to RGG by adding a filesize that's not used

public readonly List<string> Mods;
public readonly List<ParlessFile> Files;
public readonly List<ParlessFolder> ParlessFolders;
public readonly List<CpkFolder> CpkFolders;
public List<string> Mods { get; }
public List<ParlessFile> Files { get; }
public List<ParlessFolder> ParlessFolders { get; }
public List<CpkFolder> CpkFolders { get; }

public MLO(List<int> modIndices, List<string> mods, OrderedSet<string> fileSet, List<ParlessFolder> parlessFolders, Dictionary<string, List<int>> cpkFolders) {
var files = fileSet.ToList();
Expand Down
15 changes: 4 additions & 11 deletions ShinRyuModManager-CE/ModLoadOrder/Mods/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,8 @@ public void AddFiles(string path, string check) {
case "speech":
cpkDataPath = GamePath.RemoveModPath(path);

if (GamePath.CurrentGame == Game.Yakuza5) {
if (GamePath.CurrentGame is Game.Yakuza5 or <= Game.YakuzaKiwami) {
RepackCpKs.Add(cpkDataPath + ".cpk");
//Log.Verbose("Adding CPK folder: {CpkDataPath}", cpkDataPath);
} else {
if (GamePath.CurrentGame <= Game.YakuzaKiwami) {
RepackCpKs.Add(cpkDataPath + ".cpk");
}
}

break;
Expand Down Expand Up @@ -264,10 +259,8 @@ public void AddFiles(string path, string check) {
}

protected static string CheckFolder(string name) {
foreach (var folder in Constants.IncompatiblePars.Where(name.StartsWith)) {
return folder;
}

return "";
var folder = Constants.IncompatiblePars.FirstOrDefault(name.StartsWith);

return folder ?? string.Empty;
}
}
3 changes: 1 addition & 2 deletions ShinRyuModManager-CE/ModLoadOrder/Mods/ModInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

namespace ShinRyuModManager.ModLoadOrder.Mods;

public partial class ModInfo : ObservableObject, IEquatable<ModInfo> {

public sealed partial class ModInfo : ObservableObject, IEquatable<ModInfo> {
[ObservableProperty] private string _name;
[ObservableProperty] private bool _enabled;

Expand Down
2 changes: 1 addition & 1 deletion ShinRyuModManager-CE/ModMeta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class ModMeta {
public string Author { get; internal set; }
public string Version { get; internal set; }
public string Description { get; internal set; }
public string Dependencies { get; internal init; }
public string Dependencies { get; internal set; }

public static ModMeta GetPlaceholder() {
return new ModMeta {
Expand Down
2 changes: 1 addition & 1 deletion ShinRyuModManager-CE/ParRepacker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private static List<string> GetModFiles(string path) {
// Add files in current directory
foreach (var p in Directory.GetFiles(path).Where(f => !f.EndsWith(Constants.VORTEX_MANAGED_FILE)).Select(GamePath.GetDataPathFrom)) {
files.Add(p);
Log.Verbose("Adding file: {file}", p);
Log.Verbose("Adding file: {File}", p);
}

// Get files for all subdirectories
Expand Down
15 changes: 8 additions & 7 deletions ShinRyuModManager-CE/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,13 @@ private static async Task MainCLI(string[] args) {
var list = new List<string>(args);

if (list.Contains("-h") || list.Contains("--help")) {
Log.Information("Usage: run without arguments to generate mod load order.");

Log.Information(" run with \"-s\" or \"--silent\" flag to prevent checking for updates and remove prompts.");
Log.Information("""
Usage: run without arguments to generate mod load order.
-s, --silent prevent checking for updates and remove prompts.
-h, --help show this message and exit.
""");

//Log.Information(" run with \"-r\" or \"--run\" flag to run the game after the program finishes.");
Log.Information(" run with \"-h\" or \"--help\" flag to show this message and exit.");

return;
}
Expand Down Expand Up @@ -270,7 +271,7 @@ internal static List<ModInfo> PreRun() {
_migrated = true;

// Migrate old format to new
Log.Information("Old format load order file (" + Constants.TXT_OLD + ") was found. Importing to the new format...");
Log.Information("Old format load order file ({TxtOld}) was found. Importing to the new format...", Constants.TXT_OLD);

mods.AddRange(ConvertOldToNewModList(ReadModLoadOrderTxt(Constants.TXT_OLD))
.Where(n => !mods.Any(m => EqualModNames(m.Name, n.Name))));
Expand Down Expand Up @@ -402,8 +403,8 @@ private static void PostRun() {

// Calculate the checksum for the game's exe to inform the user if their version might be unsupported
if (LogLevel <= LogEventLevel.Warning && InvalidGameExe()) {
Log.Error("Warning: Game version is unrecognized. Please use the latest Steam version of the game.");
Log.Error("Shin Ryu Mod Manager will still generate the load order, but the game might CRASH or not function properly");
Log.Error("Warning: Game version is unrecognized. Please use the latest Steam version of the game.\n" +
"Shin Ryu Mod Manager will still generate the load order, but the game might CRASH or not function properly");
}

if (!_isSilent) {
Expand Down
Loading