Skip to content

Commit f44895b

Browse files
committed
Fix attribute naming and improve validation logic
- Renamed `HasVisabilityAttribute` to `HasVisibilityAttribute`. - Corrected spelling in the `Publicizer` class. - Enhanced validation logic for properties, methods, and fields based on visibility and static status.
1 parent 4f1b206 commit f44895b

2 files changed

Lines changed: 35 additions & 6 deletions

File tree

src/Patching/Publicizer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace Oxide.CSharp.Patching
1919
[HasEnvironmentalVariable("AllowPublicize")]
2020
public class Publicizer : TraversePatch
2121
{
22-
[HasVisability(false)]
22+
[HasVisibility(false)]
2323
// [IsSpecialName(InverseCheck = false)]
2424
[HasAttribute("CompilerGeneratedAttribute", StringValidationType.EndsWith, InverseCheck = true)]
2525
[HasAttribute("CompilerServices.ExtensionAttribute", StringValidationType.EndsWith, InverseCheck = true)]

src/Patching/Validation/HasVisabilityAttribute.cs renamed to src/Patching/Validation/HasVisibilityAttribute.cs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
extern alias References;
22

33
using References::Mono.Cecil;
4-
using System;
5-
using System.Reflection;
64

75
namespace Oxide.CSharp.Patching.Validation
86
{
9-
public class HasVisabilityAttribute : PatchValidationAttribute
7+
public class HasVisibilityAttribute : PatchValidationAttribute
108
{
119
public bool IsPublic { get; }
1210

1311
public bool? IsStatic { get; set; }
1412

15-
public HasVisabilityAttribute(bool isPublic)
13+
public HasVisibilityAttribute(bool isPublic)
1614
{
1715
IsPublic = isPublic;
1816
}
@@ -50,12 +48,43 @@ protected override bool IsValid(object item)
5048
}
5149
else if (item is PropertyDefinition prop)
5250
{
53-
return prop.SetMethod != null ? IsValid(prop.GetMethod) && IsValid(prop.SetMethod) : IsValid(prop.GetMethod);
51+
if (IsPublic)
52+
{
53+
return prop.SetMethod != null ? IsValid(prop.GetMethod) && IsValid(prop.SetMethod) : IsValid(prop.GetMethod);
54+
}
55+
else
56+
{
57+
return prop.SetMethod != null ? IsValid(prop.GetMethod) || IsValid(prop.SetMethod) : IsValid(prop.GetMethod);
58+
}
5459
}
5560
else if (item is EventDefinition @event)
5661
{
5762
return @event.AddMethod != null && IsValid(@event.AddMethod);
5863
}
64+
else if (item is MethodDefinition method)
65+
{
66+
if (IsStatic.HasValue)
67+
{
68+
if (method.IsStatic != IsStatic.Value)
69+
{
70+
return false;
71+
}
72+
}
73+
74+
return method.IsPublic == IsPublic;
75+
}
76+
else if (item is FieldDefinition field)
77+
{
78+
if (IsStatic.HasValue)
79+
{
80+
if (field.IsStatic != IsStatic.Value)
81+
{
82+
return false;
83+
}
84+
}
85+
86+
return field.IsPublic == IsPublic;
87+
}
5988
else if (item is IMemberDefinition)
6089
{
6190
bool? isPub = GetPropertyValue<bool?>(item, "IsPublic");

0 commit comments

Comments
 (0)