Skip to content

Commit

Permalink
Merge pull request #44 from mika-f/integrations/unity
Browse files Browse the repository at this point in the history
  • Loading branch information
mika-f committed Mar 7, 2024
2 parents edaf890 + d3d6bda commit 78170ca
Show file tree
Hide file tree
Showing 150 changed files with 4,691 additions and 92 deletions.
7 changes: 5 additions & 2 deletions src/Plana.CLI/Commands/ObfuscateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private async Task<List<IPlanaPlugin>> ParseExtraArguments(InvocationContext con
foreach (var (plugin, attr) in container.Items)
{
var enabler = new Option<bool>($"--{attr.Id}", () => false, $"enable {plugin.Name} plugin");
allPluginOptions.Add(new PlanaPluginOption(attr.Id, $"enable {plugin.Name} plugin", false));
allPluginOptions.Add(new PlanaPluginOption(attr.Id, plugin.Name, $"enable {plugin.Name} plugin", false));

try
{
Expand Down Expand Up @@ -170,7 +170,10 @@ private async Task<List<IPlanaPlugin>> ParseExtraArguments(InvocationContext con
if (context.ParseResult.GetValueForOption(GlobalCommandLineOptions.RetrieveArgs))
{
foreach (var o in allPluginOptions)
Console.WriteLine($"Id={o.Name}, Name={o.FriendlyName}, Type={o.ValueType.FullName}, Required={false}, Description={o.Description}");
if (o.Description == $"enable {o.FriendlyName} plugin")

Check warning on line 173 in src/Plana.CLI/Commands/ObfuscateCommand.cs

View workflow job for this annotation

GitHub Actions / build

Convert into method call with '?:' expression inside
Console.WriteLine($"Id={o.Name}, Name={o.FriendlyName}, Type={o.ValueType.FullName}, Required={false}, Description=SEPARATOR");
else
Console.WriteLine($"Id={o.Name}, Name={o.FriendlyName}, Type={o.ValueType.FullName}, Required={false}, Description={o.Description}");

throw new ControlledGlobalExitException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public async Task CanInstantiateWithDefaults()

Assert.NotNull(instance);
Assert.Equal("Rename Symbols", instance.Name);
Assert.Equal(8, instance.Options.Count);
Assert.Equal(7, instance.Options.Count);

Assert.False(instance.IsEnableClassNameRenaming);
Assert.False(instance.IsEnableFieldsRenaming);
Expand All @@ -26,6 +26,5 @@ public async Task CanInstantiateWithDefaults()
Assert.False(instance.IsEnablePropertiesRenaming);
Assert.False(instance.IsEnableVariablesRenaming);
Assert.False(instance.KeepOriginalNameInInspector);
Assert.False(instance.KeepOriginalNameWithSendCustomEvent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public async Task RenameFields_ExternalReference()
var implementation = await container.GetSourceByPathAsync("Plana.Composition.RenameSymbols/RenameSymbolsPlugin.cs");
var reference = await container.GetSourceByPathAsync("Plana.Composition.RenameSymbols.Tests/RenameSymbolsPluginTest.cs");

// IsEnableClassNameRenaming -> _0x4b78aef3
const string identifier = "_0x4b78aef3";
// IsEnableClassNameRenaming -> _0x935f5b12
const string identifier = "_0x935f5b12";

var declaration = await implementation.GetFirstSyntax<FieldDeclarationSyntax>(w => w.HasModifier(SyntaxKind.InternalKeyword));
Assert.Equal(identifier, declaration.Declaration.Variables[0].Identifier.ToString());
Expand Down Expand Up @@ -56,8 +56,8 @@ public async Task RenameFields_InternalReference()

var implementation = await container.GetSourceByTypeAsync(typeof(MeaningEqualitySymbolComparator));

// SymbolDisplayFormat -> _0xd5e5660c
const string identifier = "_0xd5e5660c";
// SymbolDisplayFormat -> _0xcb375677
const string identifier = "_0xcb375677";

var declaration = await implementation.GetFirstSyntax<FieldDeclarationSyntax>(w => w.HasModifiers(SyntaxKind.PrivateKeyword, SyntaxKind.StaticKeyword, SyntaxKind.ReadOnlyKeyword));
Assert.Equal(identifier, declaration.Declaration.Variables[0].Identifier.ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public async Task RenameVariables_ForEachStatement()

var implementation = await container.GetSourceByTypeAsync(typeof(Obfuscator));

// instance -> _0xcdfa050c
const string identifier = "_0xcdfa050c";
// instance -> _0x3a050ac8
const string identifier = "_0x3a050ac8";

var @foreach = await implementation.GetFirstSyntax<ForEachStatementSyntax>();
Assert.Equal(identifier, @foreach.Identifier.ToFullString());
Expand All @@ -38,8 +38,8 @@ public async Task RenameVariables_PrimaryConstructor()

var implementation = await container.GetSourceByTypeAsync(typeof(AnnotationComment));

// AnnotationComment.Annotation -> _0x5038b7aa
const string identifier = "_0x5038b7aa";
// AnnotationComment.Annotation -> _0xd660581b
const string identifier = "_0xd660581b";

var declaration = await implementation.GetFirstSyntax<RecordDeclarationSyntax>();
var constructor = declaration.ParameterList!.Parameters[0];
Expand Down
2 changes: 1 addition & 1 deletion src/Plana.Composition.RenameSymbols/CSharpSymbolsWalker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Plana.Composition.RenameSymbols;

internal class CSharpSymbolsWalker(IDocument document, IPlanaSecureRandom random, bool isRenameNamespaces, bool isRenameClasses, bool isRenameProperties, bool isRenameFields, bool isRenameMethods, bool isRenameMethodsWithEvents, bool isRenameVariables, Dictionary<ISymbol, string> dict)
internal class CSharpSymbolsWalker(IDocument document, IPlanaSecureRandom random, bool isRenameNamespaces, bool isRenameClasses, bool isRenameProperties, bool isRenameFields, bool isRenameMethods, bool isRenameVariables, Dictionary<ISymbol, string> dict)
: CSharpSyntaxWalker
{
private static readonly List<string> Messages =
Expand Down
14 changes: 5 additions & 9 deletions src/Plana.Composition.RenameSymbols/RenameSymbolsPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ public class RenameSymbolsPlugin : IPlanaPlugin2
private static readonly PlanaPluginOption Namespace = new("rename-namespaces", "Rename Namespaces", "rename namespaces, not supports file-scoped namespaces", false);
private static readonly PlanaPluginOption ClassName = new("rename-classes", "Rename Classes", "rename classes", false);
private static readonly PlanaPluginOption Properties = new("rename-properties", "Rename Properties", "rename properties", false);
private static readonly PlanaPluginOption Fields = new("rename-fields", "rename fields", false);
private static readonly PlanaPluginOption Methods = new("rename-methods", "rename methods", false);
private static readonly PlanaPluginOption WithSendCustomEvent = new("with-send-custom-event", "rename all methods", false);
private static readonly PlanaPluginOption Variables = new("rename-variables", "rename local variables", false);
private static readonly PlanaPluginOption KeepNameOnInspector = new("enum-attributes", "add UnityEngine.InspectorName to enum members, without already specified", false);
private static readonly PlanaPluginOption Fields = new("rename-fields", "Rename Fields", "rename fields", false);
private static readonly PlanaPluginOption Methods = new("rename-methods", "Rename Methods", "rename methods", false);
private static readonly PlanaPluginOption Variables = new("rename-variables", "Rename Variables", "rename local variables", false);
private static readonly PlanaPluginOption KeepNameOnInspector = new("enum-attributes", "Keep Inspector Name of Enums", "add UnityEngine.InspectorName to enum members, without already specified", false);

private readonly Dictionary<ISymbol, string> _dict = new(MeaningEqualitySymbolComparator.Default);

Expand All @@ -37,9 +36,8 @@ public class RenameSymbolsPlugin : IPlanaPlugin2
internal bool IsEnablePropertiesRenaming;
internal bool IsEnableVariablesRenaming;
internal bool KeepOriginalNameInInspector;
internal bool KeepOriginalNameWithSendCustomEvent;

public IReadOnlyCollection<IPlanaPluginOption> Options => new List<IPlanaPluginOption> { Namespace, ClassName, Properties, Fields, Methods, WithSendCustomEvent, Variables, KeepNameOnInspector }.AsReadOnly();
public IReadOnlyCollection<IPlanaPluginOption> Options => new List<IPlanaPluginOption> { Namespace, ClassName, Properties, Fields, Methods, Variables, KeepNameOnInspector }.AsReadOnly();

public string Name => "Rename Symbols";

Expand All @@ -50,7 +48,6 @@ public void BindParameters(IPlanaPluginParameterBinder binder)
IsEnablePropertiesRenaming = binder.GetValue(Properties);
IsEnableFieldsRenaming = binder.GetValue(Fields);
IsEnableMethodsRenaming = binder.GetValue(Methods);
KeepOriginalNameWithSendCustomEvent = binder.GetValue(WithSendCustomEvent);
IsEnableVariablesRenaming = binder.GetValue(Variables);
KeepOriginalNameInInspector = binder.GetValue(KeepNameOnInspector);
}
Expand All @@ -67,7 +64,6 @@ public async Task ObfuscateAsync(IPlanaPluginRunContext context)
IsEnablePropertiesRenaming,
IsEnableFieldsRenaming,
IsEnableMethodsRenaming,
KeepOriginalNameWithSendCustomEvent,
IsEnableVariablesRenaming,
_dict
);
Expand Down
4 changes: 2 additions & 2 deletions src/Plana.Integrations.Unity/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ crashlytics-build.properties
/UIElementsSchema/

# externals
/[Aa]ssets/NatsunekoLaboratory/Plana/Plugins/*
!/[Aa]ssets/NatsunekoLaboratory/Plana/Plugins/*.meta
/[Aa]ssets/NatsunekoLaboratory/Plana/Plugins/**/*.*
!/[Aa]ssets/NatsunekoLaboratory/Plana/Plugins/**/*.meta
/[Aa]ssets/NatsunekoLaboratory/UStyled.meta
/[Aa]ssets/NatsunekoLaboratory/UStyled/*
/[Aa]ssets/ObfuscateTest.meta
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace NatsunekoLaboratory.Plana.Models.Abstractions
{
internal class CommandBase
{
private const string Guid = "300a45c7c5134854a88ad90d52d3a119";
private const string Guid = "185d3059c6896f043bb50e0eb319fa67";
private static readonly string Path;

static CommandBase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public ObfuscateCommand(FileSystemInfo workspace, DirectoryInfo plugins, bool is
var friendlyName = property.Value.FriendlyName;
var description = property.Value.Description;

if ($"enable {arg} plugin" == description)
if (description == "SEPARATOR")
cur = arg;

if (string.IsNullOrWhiteSpace(cur))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,10 @@ private FileInfo GetProjectScopeWorkspace(FileInfo fi)
return GetCSharpProjectWorkspace(filename);
}

private FileInfo GetCSharpProjectWorkspace(string name)
private FileInfo GetCSharpProjectWorkspace(string project)
{
var path = Application.dataPath;
return new FileInfo(Path.GetFullPath(Path.Combine(path, "..", $"{name}.csproj")));
return new FileInfo(Path.GetFullPath(Path.Combine(path, "..", $"{project}.csproj")));
}

private void UpdateObfuscateButton()
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 78170ca

Please sign in to comment.