Ejemplo n.º 1
0
        private bool                        DumpAllModsAssemblies()
        {
            var stream = CCL_Log.OpenStream("assembly_dump.txt");

            if (stream == null)
            {
                return(false);
            }

            DumpAssembly(stream, Controller.Data.Assembly_CSharp);

            foreach (var mod in Controller.Data.Mods)
            {
                if (!mod.assemblies.loadedAssemblies.NullOrEmpty())
                {
                    CCL_Log.Write("Mod: " + mod.Identifier);

                    foreach (var assembly in mod.assemblies.loadedAssemblies)
                    {
                        DumpAssembly(stream, assembly);
                    }
                }
            }
            CCL_Log.CloseStream(stream);
            return(true);
        }
        public void Recache()
        {
            _cachedHelpDefs.Clear();
            foreach (var def in (
                         from t in DefDatabase <HelpDef> .AllDefs
                         where t.category == this
                         select t))
            {
                _cachedHelpDefs.Add(def);
            }
            _cachedHelpDefs.Sort();

#if DEVELOPER
            string dump = "Help Category: " + label + " - " + defName + " - " + ModName + "\n";
            foreach (var def in _cachedHelpDefs)
            {
                dump += def.LogDump();
            }
            CCL_Log.Write(dump);
#endif
        }
Ejemplo n.º 3
0
 private void                        DumpAllTypesFieldsPropertiesAndMethods()
 {
     CCL_Log.Write("All Types:");
     foreach (var type in Controller.Data.Assembly_CSharp.GetTypes())
     {
         var str = "\n\t" + type.FullName;
         str += "\n\t\tFields:";
         foreach (var entity in type.GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public))
         {
             str += "\n\t\t\t" + entity.Name;
             if (entity.IsStatic)
             {
                 str += " (Static)";
             }
             else
             {
                 str += " (Instance)";
             }
             if (entity.IsPrivate)
             {
                 str += " (NonPublic)";
             }
             if (entity.IsPublic)
             {
                 str += " (Public)";
             }
         }
         str += "\n\t\tProperties:";
         foreach (var entity in type.GetProperties(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public))
         {
             str += "\n\t\t\t" + entity.Name;
             var method = entity.GetGetMethod();
             if (method != null)
             {
                 str += " (Public Get)";
             }
             else
             {
                 method = entity.GetGetMethod(true);
                 if (method != null)
                 {
                     str += " (NonPublic Get)";
                 }
             }
             method = entity.GetSetMethod();
             if (method != null)
             {
                 str += " (Public Set)";
             }
             else
             {
                 method = entity.GetSetMethod(true);
                 if (method != null)
                 {
                     str += " (NonPublic Set)";
                 }
             }
         }
         str += "\n\t\tMethods:";
         foreach (var entity in type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public))
         {
             str += "\n\t\t\t" + entity.Name;
             if (entity.IsStatic)
             {
                 str += " (Static)";
             }
             else
             {
                 str += " (Instance)";
             }
             if (entity.IsPrivate)
             {
                 str += " (NonPublic)";
             }
             if (entity.IsPublic)
             {
                 str += " (Public)";
             }
             if (entity.GetParameters() != null)
             {
                 str += " Parameters:";
                 foreach (var pi in entity.GetParameters())
                 {
                     str += " " + pi.ParameterType.ToString();
                     if (pi.IsOut)
                     {
                         str += " (out)";
                     }
                     if (pi.IsRetval)
                     {
                         str += " (ret)";
                     }
                 }
             }
         }
         CCL_Log.Write(str);
     }
 }
Ejemplo n.º 4
0
        private void                        DumpAssembly(CCL_Log.LogStream stream, Assembly assembly)
        {
            CCL_Log.IndentStream(stream);
            {
                CCL_Log.Write("Assembly: " + assembly.GetName(), stream);

                CCL_Log.IndentStream(stream);
                {
                    foreach (var type in assembly.GetTypes())
                    {
                        CCL_Log.Write("Type: " + type.FullName, stream);
                        CCL_Log.IndentStream(stream);
                        {
                            #region Fields
                            var fields = type.GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
                            if (!fields.NullOrEmpty())
                            {
                                CCL_Log.Write("Fields:", stream);
                                CCL_Log.IndentStream(stream);
                                {
                                    foreach (var entity in fields)
                                    {
                                        var str = entity.FieldType.Name;
                                        str += " " + entity.Name;
                                        if (entity.IsStatic)
                                        {
                                            str += " (Static)";
                                        }
                                        else
                                        {
                                            str += " (Instance)";
                                        }
                                        if (entity.IsPrivate)
                                        {
                                            str += " (NonPublic)";
                                        }
                                        if (entity.IsPublic)
                                        {
                                            str += " (Public)";
                                        }
                                        CCL_Log.Write(str, stream);
                                    }
                                }
                                CCL_Log.IndentStream(stream, -1);
                            }
                            #endregion
                            #region Properties
                            var properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
                            if (!properties.NullOrEmpty())
                            {
                                CCL_Log.Write("Properties:", stream);
                                CCL_Log.IndentStream(stream);
                                {
                                    foreach (var entity in properties)
                                    {
                                        var str = entity.PropertyType.Name;
                                        str += " " + entity.Name;
                                        var method = entity.GetGetMethod();
                                        if (method != null)
                                        {
                                            str += " (Public Get)";
                                        }
                                        else
                                        {
                                            method = entity.GetGetMethod(true);
                                            if (method != null)
                                            {
                                                str += " (NonPublic Get)";
                                            }
                                        }
                                        method = entity.GetSetMethod();
                                        if (method != null)
                                        {
                                            str += " (Public Set)";
                                        }
                                        else
                                        {
                                            method = entity.GetSetMethod(true);
                                            if (method != null)
                                            {
                                                str += " (NonPublic Set)";
                                            }
                                        }
                                        CCL_Log.Write(str, stream);
                                    }
                                }
                                CCL_Log.IndentStream(stream, -1);
                            }
                            #endregion
                            #region Methods
                            var methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
                            if (!methods.NullOrEmpty())
                            {
                                CCL_Log.Write("Methods:", stream);
                                CCL_Log.IndentStream(stream);
                                {
                                    foreach (var entity in methods)
                                    {
                                        var str = entity.ReturnType.Name;
                                        str += " " + entity.Name;
                                        if (entity.IsStatic)
                                        {
                                            str += " (Static)";
                                        }
                                        else
                                        {
                                            str += " (Instance)";
                                        }
                                        if (entity.IsPrivate)
                                        {
                                            str += " (NonPublic)";
                                        }
                                        if (entity.IsPublic)
                                        {
                                            str += " (Public)";
                                        }
                                        if (!entity.GetParameters().NullOrEmpty())
                                        {
                                            var parameters = entity.GetParameters();
                                            str += " Parameters: (";
                                            for (int i = 0; i < parameters.Length; ++i)
                                            {
                                                var optional = false;
                                                var pi       = parameters[i];
                                                if (pi.IsOut)
                                                {
                                                    str += " (out)";
                                                }
                                                if (pi.IsRetval)
                                                {
                                                    str += " (ret)";
                                                }
                                                if (!pi.GetCustomAttributes(true).NullOrEmpty())
                                                {
                                                    foreach (var attribute in pi.GetCustomAttributes(true))
                                                    {
                                                        optional |= attribute.GetType().Name == "OptionalAttribute";
                                                        str      += " " + attribute.GetType().Name;
                                                    }
                                                }
                                                if (!pi.GetRequiredCustomModifiers().NullOrEmpty())
                                                {
                                                    foreach (var modifier in pi.GetRequiredCustomModifiers())
                                                    {
                                                        str += " " + modifier.Name;
                                                    }
                                                }
                                                if (!pi.GetOptionalCustomModifiers().NullOrEmpty())
                                                {
                                                    foreach (var modifier in pi.GetOptionalCustomModifiers())
                                                    {
                                                        str += " " + modifier.Name;
                                                    }
                                                }
                                                str += " " + pi.ParameterType.ToString();
                                                str += " " + pi.Name;
                                                if (
                                                    (optional) &&
                                                    (pi.DefaultValue != null)
                                                    )
                                                {
                                                    str += " = ";
                                                    if (pi.DefaultValue is string)
                                                    {
                                                        str += "\"";
                                                    }
                                                    str += pi.DefaultValue.ToString();
                                                    if (pi.DefaultValue is string)
                                                    {
                                                        str += "\"";
                                                    }
                                                }
                                                if (i < parameters.Length - 1)
                                                {
                                                    str += ",";
                                                }
                                            }
                                            str += " )";
                                        }
                                        CCL_Log.Write(str, stream);
                                    }
                                }
                                CCL_Log.IndentStream(stream, -1);
                            }
                            #endregion
                        }
                        CCL_Log.IndentStream(stream, -1);
                        CCL_Log.Write("\n", stream);
                    }
                }
                CCL_Log.IndentStream(stream, -1);
            }
            CCL_Log.IndentStream(stream, -1);
            CCL_Log.Write("\n", stream);
        }
        /// <summary>
        /// Get a texture for the def, where defined.
        /// </summary>
        /// <param name="def"></param>
        /// <returns></returns>
        public static Texture2D IconTexture(this Def def)
        {
            // check cache
            if (_cachedDefIcons.ContainsKey(def))
            {
                return(_cachedDefIcons[def]);
            }

            // otherwise try to determine icon
            var bdef = def as BuildableDef;
            var tdef = def as ThingDef;
            var pdef = def as PawnKindDef;
            var rdef = def as RecipeDef;

            // recipes will be passed icon of first product, if defined.
            if (
                (rdef != null) &&
                (!rdef.products.NullOrEmpty())
                )
            {
                _cachedDefIcons.Add(def, rdef.products.First().thingDef.IconTexture());
                return(_cachedDefIcons[def]);
            }

            // animals need special treatment ( this will still only work for animals, pawns are a whole different can o' worms ).
            if (pdef != null)
            {
#if DEVELOPER
                CCL_Log.Write(def.LabelCap + " animal icon ");
#endif
                try
                {
                    _cachedDefIcons.Add(def, (pdef.lifeStages.Last().bodyGraphicData.Graphic.MatFront.mainTexture as Texture2D).Crop());
                    return(_cachedDefIcons[def]);
                }
                catch
                {
#if DEVELOPER
                    CCL_Log.Write("failed");
#endif
                }
            }

            // if not buildable it probably doesn't have an icon.
            if (bdef == null)
            {
#if DEVELOPER
                CCL_Log.Write(def.LabelCap + " not buildable - no icon ");
#endif
                _cachedDefIcons.Add(def, null);
                return(null);
            }

            // if def built != def listed.
            if (
                (tdef != null) &&
                (tdef.entityDefToBuild != null)
                )
            {
#if DEVELOPER
                CCL_Log.Write(def.LabelCap + " getting icon from entityToBuild ");
#endif
                _cachedDefIcons.Add(def, tdef.entityDefToBuild.IconTexture().Crop());
                return(_cachedDefIcons[def]);
            }

#if DEVELOPER
            CCL_Log.Write(def.LabelCap + " uiIcon ");
#endif
            _cachedDefIcons.Add(def, bdef.uiIcon.Crop());
            return(bdef.uiIcon.Crop());
        }