public static bool Prefix(MethodBase __originalMethod, SectionLayer_Things __instance, ref string __state)
        {
            if (Active)
            {
                __instance.ClearSubMeshes(MeshParts.All);
                Profiler prof = null;
                foreach (IntVec3 intVec in __instance.section.CellRect)
                {
                    List <Thing> list  = __instance.Map.thingGrid.ThingsListAt(intVec);
                    int          count = list.Count;
                    for (int i = 0; i < count; i++)
                    {
                        Thing thing = list[i];

                        __state = "Flag check";
                        prof    = Analyzer.Start(__state, null, null, null, null, __originalMethod);
                        var flag =
                            ((thing.def.seeThroughFog ||
                              !__instance.Map.fogGrid.fogGrid[
                                  CellIndicesUtility.CellToIndex(thing.Position, __instance.Map.Size.x)]) &&
                             thing.def.drawerType != DrawerType.None &&
                             (thing.def.drawerType != DrawerType.RealtimeOnly || !__instance.requireAddToMapMesh) &&
                             (thing.def.hideAtSnowDepth >= 1f || __instance.Map.snowGrid.GetDepth(thing.Position) <=
                              thing.def.hideAtSnowDepth) && thing.Position.x == intVec.x &&
                             thing.Position.z == intVec.z);
                        prof.Stop();

                        if (flag)
                        {
                            __state = thing.def.defName;
                            prof    = Analyzer.Start(__state, null, null, null, null, __originalMethod);
                            __instance.TakePrintFrom(thing);
                            prof.Stop();
                        }
                    }
                }

                __state = "Finalize mesh";
                prof    = Analyzer.Start(__state, null, null, null, null, __originalMethod);
                __instance.FinalizeMesh(MeshParts.All);
                prof.Stop();
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        public static bool Prefix(MethodBase __originalMethod, SectionLayer_Things __instance)
        {
            if (!Active)
            {
                return(true);
            }

            if (ByDef)
            {
                if (!__instance.Visible)
                {
                    return(false);
                }
                int count = __instance.subMeshes.Count;



                for (int i = 0; i < count; i++)
                {
                    LayerSubMesh layerSubMesh = __instance.subMeshes[i];
                    if (layerSubMesh.finalized && !layerSubMesh.disabled)
                    {
                        string Namer()
                        {
                            var n = layerSubMesh.material?.mainTexture?.name ?? layerSubMesh.GetType().Name;

                            return(n);
                        }

                        // todo material.mainTexture is a non trivial lookup
                        var name = layerSubMesh.material?.mainTexture?.name ?? layerSubMesh.GetType().Name;

                        var prof = ProfileController.Start(name, Namer, __originalMethod.GetType(), __originalMethod);
                        Graphics.Internal_DrawMesh_Injected(layerSubMesh.mesh, 0, ref johnmatrix, layerSubMesh.material, 0, null, null, ShadowCastingMode.Off, false, null, LightProbeUsage.Off, null);

                        // Graphics.DrawMesh(layerSubMesh.mesh, Vector3.zeroVector, Quaternion.identityQuaternion, layerSubMesh.material, 0);
                        prof.Stop();
                    }
                }



                return(false);
            }

            {
                if (!__instance.Visible)
                {
                    return(false);
                }

                int count = __instance.subMeshes.Count;



                for (int i = 0; i < count; i++)
                {
                    LayerSubMesh layerSubMesh = __instance.subMeshes[i];
                    if (layerSubMesh.finalized && !layerSubMesh.disabled)
                    {
                        string Namer()
                        {
                            var n = layerSubMesh.material?.mainTexture?.name ?? layerSubMesh.GetType().Name;

                            return(n);
                        }

                        var name = layerSubMesh.material?.mainTexture?.name ?? layerSubMesh.GetType().Name;

                        var prof = ProfileController.Start(name, Namer, __originalMethod.GetType(),
                                                           __originalMethod);
                        Graphics.DrawMesh(layerSubMesh.mesh, Vector3.zero, Quaternion.identity, layerSubMesh.material,
                                          0);
                        prof.Stop();
                    }
                }
            }

            return(false);
        }