Skip to content

Commit

Permalink
Merge pull request #17 from NSGolova/main
Browse files Browse the repository at this point in the history
Fixed private methods with `in` arguments
  • Loading branch information
ChecksumDev authored Aug 31, 2023
2 parents e16a249 + 02b0375 commit a4db378
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 34 deletions.
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

0 comments on commit a4db378

Please sign in to comment.