Skip to content

Commit 5678c84

Browse files
committed
Disable publicizer
Disable publicizer until it's a little more stable. Can enabled by adding environmental variable "OXIDE:AllowPublicize"
1 parent c6d73e1 commit 5678c84

13 files changed

Lines changed: 96 additions & 95 deletions

src/Patching/Patcher.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
extern alias References;
1+
extern alias References;
22

33
using Oxide.Core;
44
using Oxide.Core.Logging;
@@ -71,7 +71,7 @@ public static bool Run(AssemblyDefinition module)
7171
for (int n = 0; n < validators.Count; n++)
7272
{
7373
PatchValidationAttribute valid = validators[n];
74-
bool pass = valid.IsValid(module);
74+
bool pass = valid.Validate(module);
7575
// Interface.Oxide.RootLogger.WriteDebug(LogType.Info, Logging.LogEvent.Patch, "Patcher", $"Validation {valid.GetType().Name}: {(pass ? "passed" : "failed")}");
7676
if (!pass)
7777
{
@@ -101,7 +101,7 @@ public static bool Run(AssemblyDefinition module)
101101

102102
return context.TotalPatches > 0;
103103
}
104-
104+
105105
public static byte[] Run(byte[] data, out bool patched)
106106
{
107107
try
@@ -120,7 +120,7 @@ public static byte[] Run(byte[] data, out bool patched)
120120
}
121121
}
122122
}
123-
123+
124124
}
125125
catch (Exception e)
126126
{

src/Patching/Publicizer.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,22 @@
55

66
namespace Oxide.CSharp.Patching
77
{
8-
[InverseNameValidation("0Harmony")]
9-
[InverseNameValidation("System")]
10-
[InverseNameValidation("Microsoft")]
11-
[InverseNameValidation("mscorlib")]
12-
[InverseNameValidation("Unity")]
13-
[InverseNameValidation("Mono")]
14-
[InverseNameValidation("netstandard")]
15-
[InverseNameValidation("Oxide")]
16-
[InverseNameValidation("MySql.Data")]
8+
[HasName("0Harmony", InverseCheck = true)]
9+
[HasName("System", InverseCheck = true)]
10+
[HasName("Microsoft", InverseCheck = true)]
11+
[HasName("mscorlib", InverseCheck = true)]
12+
[HasName("Unity", InverseCheck = true)]
13+
[HasName("Mono", InverseCheck = true)]
14+
[HasName("netstandard", InverseCheck = true)]
15+
[HasName("Oxide", InverseCheck = true)]
16+
[HasName("MySql.Data", InverseCheck = true)]
17+
[HasEnvironmentalVariable("AllowPublicize")]
1718
public class Publicizer : TraversePatch
1819
{
1920
[HasVisability(false)]
20-
[SkipSpecialName]
21-
[DoesNotHaveAttribute("CompilerGeneratedAttribute", StringValidationType.EndsWith)]
22-
[DoesNotHaveAttribute("CompilerServices.ExtensionAttribute", StringValidationType.EndsWith)]
21+
[IsSpecialName(InverseCheck = false)]
22+
[HasAttribute("CompilerGeneratedAttribute", StringValidationType.EndsWith, InverseCheck = true)]
23+
[HasAttribute("CompilerServices.ExtensionAttribute", StringValidationType.EndsWith, InverseCheck = true)]
2324
protected override bool OnMemberDefinition(IMemberDefinition member)
2425
{
2526
return base.OnMemberDefinition(member);

src/Patching/TraversePatch.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,8 @@ protected bool RunValidation(IMemberDefinition member, IEnumerable<PatchValidati
215215

216216
foreach (PatchValidationAttribute valid in validations)
217217
{
218-
if (!valid.IsValid(member))
218+
if (!valid.Validate(member))
219219
{
220-
Type type = valid.GetType();
221220
return false;
222221
}
223222
}

src/Patching/TypeEquality.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
namespace Oxide.CSharp.Patching
1111
{
12-
[NameValidation("mscorlib")]
12+
[HasName("mscorlib")]
1313
public class TypeEquality : TraversePatch
1414
{
15-
[NameValidation("System.Type", StringValidationType.Equals, System.StringComparison.InvariantCulture)]
15+
[HasName("System.Type", StringValidationType.Equals, System.StringComparison.InvariantCulture)]
1616
protected override bool OnTypeDefinition(TypeDefinition type)
1717
{
1818
bool changed = false;

src/Patching/Validation/DoesNotHaveAttributeAttribute.cs

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
extern alias References;
2+
3+
using References::Mono.Cecil;
4+
using References::Mono.Collections.Generic;
5+
using System;
6+
using System.Linq;
7+
8+
namespace Oxide.CSharp.Patching.Validation
9+
{
10+
public class HasAttributeAttribute : HasNameAttribute
11+
{
12+
public HasAttributeAttribute(string rule, StringValidationType type = StringValidationType.StartsWith, StringComparison comparison = StringComparison.InvariantCultureIgnoreCase) : base(rule, type, comparison)
13+
{
14+
}
15+
16+
protected override bool IsValid(object item)
17+
{
18+
if (item is CustomAttribute attribute)
19+
{
20+
return base.IsValid(attribute.AttributeType.FullName);
21+
}
22+
else if (item is Collection<CustomAttribute> attributes)
23+
{
24+
return attributes.Any(a => base.IsValid(a.AttributeType.FullName));
25+
}
26+
else if (item is AssemblyDefinition assem && assem.HasCustomAttributes)
27+
{
28+
return assem.CustomAttributes.Any(a => base.IsValid(a.AttributeType.FullName));
29+
}
30+
else if (item is ModuleDefinition module && module.HasCustomAttributes)
31+
{
32+
return module.CustomAttributes.Any(a => base.IsValid(a.AttributeType.FullName));
33+
}
34+
else if (item is IMemberDefinition member && member.HasCustomAttributes)
35+
{
36+
return member.CustomAttributes.Any(a => base.IsValid(a.AttributeType.FullName));
37+
}
38+
39+
return false;
40+
}
41+
}
42+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using Oxide.Plugins;
3+
4+
namespace Oxide.CSharp.Patching.Validation
5+
{
6+
public class HasEnvironmentalVariableAttribute : PatchValidationAttribute
7+
{
8+
private string VariableName { get; }
9+
10+
public HasEnvironmentalVariableAttribute(string rule)
11+
{
12+
VariableName = rule ?? throw new ArgumentNullException(nameof(rule));
13+
}
14+
15+
protected override bool IsValid(object item) => !string.IsNullOrEmpty(EnvironmentHelper.GetOxideEnvironmentalVariable(VariableName));
16+
}
17+
}

src/Patching/Validation/NameValidationAttribute.cs renamed to src/Patching/Validation/HasNameAttribute.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66

77
namespace Oxide.CSharp.Patching.Validation
88
{
9-
public class NameValidationAttribute : PatchValidationAttribute
9+
public class HasNameAttribute : PatchValidationAttribute
1010
{
1111
public string ValidationRule { get; }
1212

1313
public StringValidationType ValidationType { get; }
1414

1515
public StringComparison ValidationComparison { get; }
1616

17-
public NameValidationAttribute(string rule, StringValidationType type = StringValidationType.StartsWith, StringComparison comparison = StringComparison.InvariantCultureIgnoreCase)
17+
public HasNameAttribute(string rule, StringValidationType type = StringValidationType.StartsWith, StringComparison comparison = StringComparison.InvariantCultureIgnoreCase)
1818
{
1919
ValidationRule = rule;
2020
ValidationType = type;
2121
ValidationComparison = comparison;
2222
}
2323

24-
public override bool IsValid(object item)
24+
protected override bool IsValid(object item)
2525
{
2626
string name = null;
2727

src/Patching/Validation/HasVisabilityAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public HasVisabilityAttribute(bool isPublic)
1717
IsPublic = isPublic;
1818
}
1919

20-
public override bool IsValid(object item)
20+
protected override bool IsValid(object item)
2121
{
2222
if (item is TypeDefinition type)
2323
{

src/Patching/Validation/InverseNameValidationAttribute.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)