diff --git a/UnitystationLauncher/ContentScanning/Scanners/MemberReferenceScanner.cs b/UnitystationLauncher/ContentScanning/Scanners/MemberReferenceScanner.cs index 6ae9a86..fda3e62 100644 --- a/UnitystationLauncher/ContentScanning/Scanners/MemberReferenceScanner.cs +++ b/UnitystationLauncher/ContentScanning/Scanners/MemberReferenceScanner.cs @@ -55,47 +55,53 @@ when typeCfg.FieldsParsed.Any(field => field.Name == mMemberRefField.Name errors.Add(new($"Access to field not allowed: {mMemberRefField}")); return; case MMemberRefMethod mMemberRefMethod: + bool safe = IsMMemberRefMethodSafe(mMemberRefMethod, typeCfg); + if (!safe) { - foreach (WhitelistMethodDefine parsed in typeCfg.MethodsParsed) - { - bool paramMismatch = false; - - if (parsed.Name != mMemberRefMethod.Name || - !mMemberRefMethod.ReturnType.WhitelistEquals(parsed.ReturnType) || - mMemberRefMethod.ParameterTypes.Length != parsed.ParameterTypes.Count || - mMemberRefMethod.GenericParameterCount != parsed.GenericParameterCount) - { - continue; - } - - for (int i = 0; i < mMemberRefMethod.ParameterTypes.Length; i++) - { - MType a = mMemberRefMethod.ParameterTypes[i]; - MType b = parsed.ParameterTypes[i]; - - if (a.WhitelistEquals(b)) - { - continue; - } - - paramMismatch = true; - break; - } - - if (!paramMismatch) - { - return; // Found - } - } - errors.Add(new($"Access to method not allowed: {mMemberRefMethod}")); - return; } + + return; default: throw new ArgumentException($"Invalid memberRef type: {memberRef.GetType()}", nameof(memberRef)); } } + private static bool IsMMemberRefMethodSafe(MMemberRefMethod mMemberRefMethod, TypeConfig typeCfg) + { + foreach (WhitelistMethodDefine parsed in typeCfg.MethodsParsed) + { + bool paramMismatch = false; + if (parsed.Name != mMemberRefMethod.Name || + !mMemberRefMethod.ReturnType.WhitelistEquals(parsed.ReturnType) || + mMemberRefMethod.ParameterTypes.Length != parsed.ParameterTypes.Count || + mMemberRefMethod.GenericParameterCount != parsed.GenericParameterCount) + { + continue; + } + + for (int i = 0; i < mMemberRefMethod.ParameterTypes.Length; i++) + { + MType a = mMemberRefMethod.ParameterTypes[i]; + MType b = parsed.ParameterTypes[i]; + + if (a.WhitelistEquals(b)) + { + continue; + } + + paramMismatch = true; + break; + } + if (!paramMismatch) + { + return true; // Found + } + } + + return false; + } + private static MTypeReferenced? GetBaseMTypeReferenced(MMemberRef memberRef) {