public static void CheckThisType(TypeDefinition td, out mttup state) { state.ishk = false; state.ispt = false; state.isbeppl = false; if (td.BaseType != null && td.BaseType.Name == "PartialityMod") { state.ishk = true; } if (td.HasCustomAttributes) { foreach (CustomAttribute catr in td.CustomAttributes) { if (catr.AttributeType.Name == "MonoModPatch") { state.ispt = true; } if (catr.AttributeType.Namespace == "BepInEx") { state.isbeppl = true; } } } if (td.HasNestedTypes) { foreach (TypeDefinition ntd in td.NestedTypes) { mttup nestate; CheckThisType(ntd, out nestate); state.ishk = (nestate.ishk) ? true : state.ishk; state.ispt = (nestate.ispt) ? true : state.ispt; state.isbeppl = (nestate.isbeppl) ? true : state.isbeppl; } } }
public static ModType GetModType(string path) { mttup ultstate = new mttup(false, false, false); try { using (ModuleDefinition md = ModuleDefinition.ReadModule(path)) { foreach (TypeDefinition t in md.Types) { mttup tstate = new mttup(false, false, false); CheckThisType(t, out tstate); ultstate.ishk = (tstate.ishk) ? true : ultstate.ishk; ultstate.ispt = (tstate.ispt) ? true : ultstate.ispt; ultstate.isbeppl = (tstate.isbeppl) ? true : ultstate.isbeppl; } } } catch (IOException ioe) { Wood.WriteLine("ERROR CHECKING ASSEMBLY TYPE: IOException occured"); Wood.Indent(); Wood.WriteLine(ioe); Wood.Unindent(); } int ftc = 0; if (ultstate.ishk) { ftc++; } if (ultstate.ispt) { ftc++; } if (ultstate.isbeppl) { ftc++; } switch (ftc) { case 0: return(ModType.Unknown); case 3: return(ModType.Invalid); case 2: return((ultstate.ispt) ? ModType.Invalid : ModType.Unknown); case 1: if (ultstate.ishk) { return(ModType.Partmod); } else if (ultstate.ispt) { return(ModType.Patch); } else { return(ModType.BepPlugin); } default: return(ModType.Unknown); } }