This repository was archived by the owner on Dec 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
54 lines (48 loc) · 2.03 KB
/
Program.cs
File metadata and controls
54 lines (48 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using AFSLib;
public class Program
{
static void Main(string[] args)
{
Console.WriteLine("PAFS: Patch AFS - github.com/shadowthehedgehoghacking");
Console.WriteLine("Usage: PAFS <filenames of AFS>");
Console.WriteLine("Example: \"PAFS PJS.afs\" would use PJS.afs and check \"PJS\" directory for file replacement names, resulting in PJS_PATCHED.afs output file");
if (args.Count() < 1 || args.Count() > 1)
{
Console.WriteLine("Invalid arguments");
}
foreach (var arg in args)
{
var file = Path.GetFullPath(arg);
var data = File.ReadAllBytes(file);
AfsArchive target;
if (AfsArchive.TryFromFile(data, out var afsArchive))
{
target = afsArchive;
} else
{
Console.WriteLine(arg.ToString() + " AFS file not found or issue detected.");
continue;
};
var folder = file.Substring(0, file.Length - 4);
if (!Directory.Exists(folder))
{
Console.WriteLine("Directory with replacements not found for " + arg.ToString());
continue;
}
string[] replacementFiles = Directory.GetFiles(folder, "*.adx", SearchOption.TopDirectoryOnly);
foreach (var replacement in replacementFiles) {
var fileName = replacement.Substring(folder.Length + 1);
var fileToPatch = target.Files.FindIndex(x => x.Name == fileName);
target.Files[fileToPatch].Data = File.ReadAllBytes(replacement);
}
try
{
File.WriteAllBytes(folder + "_PATCHED.afs", target.ToBytes());
} catch (IOException e){
Console.WriteLine("Failed to write patched file, stacktrace below for " + folder + "_PATCHED.afs");
Console.WriteLine(e);
}
}
Console.WriteLine("All done!");
}
}