Skip to content

Commit b08e6c8

Browse files
Implemented changes from 4.7.7 (#30)
1 parent 643a562 commit b08e6c8

File tree

7 files changed

+63
-26
lines changed

7 files changed

+63
-26
lines changed

ShinRyuModManager-CE/GameModel.cs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -403,14 +403,16 @@ public static void DoUBIKProcedure(MLO mlo) {
403403
}
404404

405405
public static void DoYK3HActProcedure(MLO mlo, string codename) {
406-
var hactDir = new DirectoryInfo(GamePath.DataPath).EnumerateDirectories().FirstOrDefault(x => x.Name.StartsWith("hact_"))?.FullName;
407-
408-
if (string.IsNullOrEmpty(hactDir))
406+
var haveHAct = mlo.Files.Any(x => x.Name.Contains("/hact_"));
407+
408+
if (!haveHAct)
409409
return;
410-
411-
var haveTalk = mlo.Files.Any(x => x.Name.Contains("/hact_"));
412410

413-
if (!haveTalk)
411+
var hactDir = new DirectoryInfo(GamePath.DataPath)
412+
.EnumerateDirectories()
413+
.FirstOrDefault(x => x.Name.StartsWith("hact_"))?.FullName;
414+
415+
if (string.IsNullOrEmpty(hactDir))
414416
return;
415417

416418
var rootHActDir = Path.Combine(GamePath.ParlessDir, "hact_" + codename);
@@ -433,6 +435,7 @@ public static void DoYK3HActProcedure(MLO mlo, string codename) {
433435
if (string.IsNullOrEmpty(hActDirPath))
434436
continue;
435437

438+
436439
var hActDir = new DirectoryInfo(hActDirPath);
437440

438441
foreach (var dir in hActDir.EnumerateDirectories()) {
@@ -448,15 +451,17 @@ public static void DoYK3HActProcedure(MLO mlo, string codename) {
448451
}
449452

450453
public static void DoTalkProcedureYK3(MLO mlo, string codename) {
451-
var hactDir = new DirectoryInfo(GamePath.DataPath).GetDirectories().FirstOrDefault(x => x.Name.StartsWith("hact_"))?.FullName;
452-
453-
if (string.IsNullOrEmpty(hactDir))
454-
return;
455-
456454
var haveTalk = mlo.Files.Any(x => x.Name.Contains("/talk_"));
457455

458456
if (!haveTalk)
459457
return;
458+
459+
var hactDir = new DirectoryInfo(GamePath.DataPath)
460+
.EnumerateDirectories()
461+
.FirstOrDefault(x => x.Name.StartsWith("hact_"))?.FullName;
462+
463+
if (string.IsNullOrEmpty(hactDir))
464+
return;
460465

461466
var rootTalkDir = Path.Combine(GamePath.ParlessDir, "talk_" + codename);
462467

ShinRyuModManager-CE/ModLoadOrder/Generator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static async Task<MLO> GenerateModeLoadOrder(List<ModInfo> mods, bool loo
7878
// Check for folders which do not exist in the data path in the mod's root
7979
List<string> foldersNotFound = [];
8080

81-
foreach (var subPath in Directory.GetDirectories(modPath)) {
81+
foreach (var subPath in Directory.EnumerateDirectories(modPath)) {
8282
var subPathName = new DirectoryInfo(subPath).Name;
8383

8484
if (GamePath.DirectoryExistsInData(subPathName) || GamePath.FileExistsInData($"{subPathName}.par"))

ShinRyuModManager-CE/ModLoadOrder/Mods/Mod.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,14 @@ public void AddFiles(string path, string check) {
211211
continue;
212212

213213
var fileName = Path.GetFileName(p);
214-
var fileNameNoExt = Path.GetFileNameWithoutExtension(p);
215-
var gmtHashName = fileNameNoExt.Length <= 30 ? fileNameNoExt : fileNameNoExt[..30];
216-
var gmtPath = Path.Combine(gmtFolderPath, fileName);
214+
var fileNameNoExt = Path.GetFileNameWithoutExtension(p).ToLowerInvariant();
215+
216+
var hash = new PXDHash();
217+
hash.Set(fileNameNoExt);
217218

218-
var checksum = ComputePirateYakuzaChecksum(gmtHashName);
219+
var gmtPath = Path.Combine(gmtFolderPath, fileName);
220+
221+
var checksum = string.Concat("00", hash.Checksum.ToString("x4").AsSpan(2, 2));
219222
var destinationDirectory = Path.Combine(baseParlessPath, checksum);
220223

221224
if (!Directory.Exists(destinationDirectory))
@@ -268,10 +271,4 @@ protected static string CheckFolder(string name) {
268271

269272
return folder ?? string.Empty;
270273
}
271-
272-
private static string ComputePirateYakuzaChecksum(string input) {
273-
var sum = Encoding.UTF8.GetBytes(input).Sum(b => b) % 256;
274-
275-
return sum.ToString("x4");
276-
}
277274
}

ShinRyuModManager-CE/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,11 @@ internal static List<ModInfo> PreRun(Profile? profile = null) {
257257
if (File.Exists(Constants.TXT_OLD)) {
258258
mods.AddRange(ModListSerializer.Read(Constants.TXT_OLD, profile));
259259

260-
File.Move(Constants.TXT_OLD, $"{Constants.TXT_OLD}.bak");
260+
File.Move(Constants.TXT_OLD, $"{Constants.TXT_OLD}.bak", true);
261261
} else if (File.Exists(Constants.TXT)) {
262262
mods.AddRange(ModListSerializer.Read(Constants.TXT, profile));
263263

264-
File.Move(Constants.TXT, $"{Constants.TXT}.bak");
264+
File.Move(Constants.TXT, $"{Constants.TXT}.bak", true);
265265
} else if (File.Exists(Constants.MOD_LIST)) {
266266
mods.AddRange(ModListSerializer.Read(Constants.MOD_LIST, profile));
267267
} else {

ShinRyuModManager-CE/ShinRyuModManager-CE.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
1515

1616
<!-- Versioning -->
17-
<AssemblyVersion>1.4.2</AssemblyVersion>
17+
<AssemblyVersion>1.4.3</AssemblyVersion>
1818
<VersionPrefix>$(AssemblyVersion)</VersionPrefix>
1919
<AssemblyTitle>ShinRyuModManager-CE</AssemblyTitle>
2020
<Company>SRMM Studio</Company>

ShinRyuModManager-CE/UserInterface/Assets/changelog.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
> ### **%{color:gold} Version 1.4.2 %** ###
1+
> ### **%{color:gold} Version 1.4.3 %** ###
2+
* Implemented improved PYIH and newer hashing from SRMM 4.7.7
3+
4+
---
5+
6+
> ### **%{color:orange} Version 1.4.2 %** ###
27
* Implemented **experimental** Talk and HAct repack methods from SRMM 4.7.6
38

49
---

Utils/PXDHash.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Runtime.InteropServices;
2+
3+
namespace Utils;
4+
5+
[StructLayout(LayoutKind.Sequential, Size = 32)]
6+
public struct PXDHash {
7+
public ushort Checksum { get; set; }
8+
9+
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 30)]
10+
private char[] str; // 0x0002
11+
12+
public void Set(string val) {
13+
Checksum = 0;
14+
15+
if (str == null || str.Length <= 0)
16+
str = new char[30];
17+
18+
var valChar = val.ToCharArray();
19+
var len = valChar.Length <= 30 ? valChar.Length : 30;
20+
21+
for (var i = 0; i < len; i++) {
22+
Checksum += (byte)valChar[i];
23+
str[i] = valChar[i];
24+
}
25+
}
26+
27+
public override string ToString() {
28+
return new string(str);
29+
}
30+
}

0 commit comments

Comments
 (0)