Esempio n. 1
0
 private static void RegisterConVars(Assembly assembly)
 {
     try
     {
         var customVars = new List <BaseConVar>();
         foreach (var type in assembly.GetTypes())
         {
             foreach (var field in type.GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
             {
                 if (field.FieldType.IsSubclassOf(typeof(BaseConVar)))
                 {
                     if (field.IsStatic)
                     {
                         _console.RegisterConVarInternal((BaseConVar)field.GetValue(null));
                         customVars.Add((BaseConVar)field.GetValue(null));
                     }
                     else if (type.GetCustomAttribute <CompilerGeneratedAttribute>() == null)
                     {
                         LogCore.LogE(
                             $"ConVar defined as {type.Name} in {assembly.FullName}. {field.Name} could not be registered. ConVars must be static fields.");
                     }
                 }
             }
         }
         foreach (var baseConVar in customVars)
         {
             if ((baseConVar.flags & ConVarFlags.Engine) != ConVarFlags.None)
             {
                 baseConVar.defaultValue = baseConVar.GetString();
             }
             else if (baseConVar.defaultValue != null)
             {
                 baseConVar.SetString(baseConVar.defaultValue);
             }
         }
     }
     catch (Exception e)
     {
         LogCore.LogE($"{nameof(CommandHelper)} failed to scan the assembly called {assembly.FullName}. Exception : {e}");
     }
 }