Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed private methods with in arguments #17

Merged
merged 2 commits into from
Aug 31, 2023
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
26 changes: 1 addition & 25 deletions GenericStripper/Modules/BeatSaber/BSAssemblyModule.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Runtime.InteropServices;
using Mono.Cecil;
using Mono.Cecil.Rocks;

namespace GenericStripper.Modules.BeatSaber;

Expand All @@ -10,8 +8,6 @@ public class BsAssemblyModule
private readonly FileInfo _file;
private readonly ModuleDefinition _module;

private TypeReference? _inasmref;

public BsAssemblyModule(string gamePath, string fileName, params string[] resolverDirs)
{
_bslibLoader = new BsLibLoader(gamePath);
Expand Down Expand Up @@ -63,27 +59,7 @@ private void VirtualizeType(TypeDefinition type)
IsConstructor: false, IsSpecialName: false, IsGenericInstance: false, HasOverrides: false
}))
{
foreach (var p in m.Parameters.Where(p => p.IsIn))
{
_inasmref ??= _module.ImportReference(typeof(InAttribute));
List<TypeReference> opt = new();
List<TypeReference> req = new();
while (_inasmref is IModifierType modType)
{
if (_inasmref.IsOptionalModifier) opt.Add(modType.ModifierType);
else req.Add(modType.ModifierType);
_inasmref = modType.ElementType;
}

if (!req.Contains(_inasmref)) req.Add(_inasmref);
foreach (var typeReference in req) _inasmref = _inasmref.MakeRequiredModifierType(typeReference);

foreach (var typeReference in opt) _inasmref = _inasmref.MakeOptionalModifierType(typeReference);

p.ParameterType = _inasmref;
}

m.IsVirtual = true;
m.IsVirtual = !m.IsPrivate || m.Parameters.FirstOrDefault(p => p.IsIn) == null;
m.IsPublic = true;
m.IsPrivate = false;
m.IsNewSlot = true;
Expand Down
6 changes: 3 additions & 3 deletions GenericStripper/Modules/BeatSaber/BeatSaber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void StripDll(string file, string outDir, params string[] resolveDirs)
var outAssembly = Path.Combine(outDir, relativePath);
if (!Directory.Exists(Path.GetDirectoryName(outAssembly)))
Directory.CreateDirectory(Path.GetDirectoryName(outAssembly) ?? string.Empty);

bsAssemblyModule.Write(outAssembly);
}

Expand All @@ -44,7 +44,7 @@ public async Task StripAllDlls(string outDir)
await InstallBsipa();

if (!Directory.Exists(outDir)) Directory.CreateDirectory(outDir);

var bsLibsDir = Path.Combine(GamePath, "Libs");
var bsManagedDir = Path.Combine(GamePath, "Beat Saber_Data", "Managed");

Expand All @@ -70,7 +70,7 @@ public async Task StripAllDlls(string outDir)
AnsiConsole.MarkupLine($"[gray]Skipped {assemblyInf.Name}[/]");
continue;
}

StripDll(assembly, outDir, bsLibsDir, bsManagedDir);
task.Increment(1);
AnsiConsole.MarkupLine($"[teal]Stripped {assemblyInf.Name}[/]");
Expand Down
9 changes: 3 additions & 6 deletions GenericStripper/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ public static int Main(string[] args)
config.SetApplicationName("GenericStripper");
config.AddCommand<StripCommand>("strip")
.WithDescription("Strips assemblies of their metadata and virtualizes them.")
.WithExample(new[]
{
"strip", "-m", "beatsaber", "-p", "C:\\Program Files (x86)\\Steam\\steamapps\\common\\Beat Saber",
"-o", "stripped"
});
.WithExample("strip", "-m", "beatsaber", "-p",
"C:\\Program Files (x86)\\Steam\\steamapps\\common\\Beat Saber", "-o", "stripped");
});

return app.Run(args);
}

Expand Down