示例#1
0
        public static void Postfix(PawnGraphicSet __instance, ref List <Material> __result)
        {
            Pawn pawn = __instance.pawn;

            if (!pawn.RaceProps.Humanlike)
            {
                return;
            }
            if (pawn.apparel.AnyApparel)
            {
                if (pawn.apparel.WornApparel.Any(x => x.TryGetComp <CompExosuitDrawer>() != null))
                {
                    foreach (var item in pawn.apparel.WornApparel)
                    {
                        CompExosuitDrawer extraDrawer = item.TryGetComp <CompExosuitDrawer>();
                        if (extraDrawer != null && extraDrawer.hidesBody)
                        {
                            for (int i = 0; i < __result.Count; i++)
                            {
                                __result[i] = Constants.InvisibleGraphics(pawn).nakedGraphic.MatSingle;
                            }
                            return;
                        }
                    }
                }
            }
        }
        //static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
        //{
        //
        //    List<CodeInstruction> instructionList = instructions.ToList();
        //
        //    for (int i = 0; i < instructionList.Count; i++)
        //    {
        //        CodeInstruction instruction = instructionList[index: i];
        //        if (i > 1 && instructionList[index: i - 1].OperandIs(AccessTools.Method(type: typeof(Graphics), name: nameof(Graphics.DrawMesh), parameters: new[] { typeof(Mesh), typeof(Vector3), typeof(Quaternion), typeof(Material), typeof(Int32) })) && (i + 1) < instructionList.Count /* && instructionList[index: i + 1].opcode == OpCodes.Brtrue_S*/)
        //        {
        //            yield return instruction; // portrait
        //            yield return new CodeInstruction(opcode: OpCodes.Ldarg_1);
        //            yield return new CodeInstruction(opcode: OpCodes.Ldarg_0);
        //            yield return new CodeInstruction(opcode: OpCodes.Ldfld, operand: AccessTools.Field(type: typeof(PawnRenderer), name: "pawn"));
        //            yield return new CodeInstruction(opcode: OpCodes.Ldloc_0);             // quat
        //            yield return new CodeInstruction(opcode: OpCodes.Ldarg_S, operand: 4); // bodyfacing
        //            yield return new CodeInstruction(opcode: OpCodes.Ldarg_S, operand: 9); //invisible
        //            yield return new CodeInstruction(opcode: OpCodes.Ldloc_1);             // Mesh
        //            yield return new CodeInstruction(opcode: OpCodes.Ldarg_S, operand: 5); // bodyfacing
        //            yield return new CodeInstruction(opcode: OpCodes.Call, operand: typeof(PawnRenderer_RenderPawnInternal_DrawExosuit_Transpiler).GetMethod("DrawAddons"));
        //
        //            instruction = new CodeInstruction(opcode: OpCodes.Ldarg_S, operand: 7);
        //        }
        //
        //        yield return instruction;
        //    }
        //}

        public static void DrawAddons(bool portrait, Vector3 vector, Pawn pawn, Quaternion quat, Rot4 bodyFacing, bool invisible, Mesh mesh, Rot4 headfacing)
        {
            if (invisible)
            {
                return;
            }
            Vector2 size = mesh?.bounds.size ?? (portrait ? MeshPool.humanlikeBodySet.MeshAt(bodyFacing).bounds.size : pawn.Drawer.renderer.graphics.nakedGraphic.MeshAt(bodyFacing).bounds.size);

            if (pawn.apparel != null && pawn.apparel.WornApparelCount > 0)
            {
                foreach (var apparel in pawn.apparel.WornApparel)
                {
                    CompExosuitDrawer ExtraDrawer = apparel.TryGetComp <CompExosuitDrawer>();
                    if (ExtraDrawer != null)
                    {
                        foreach (CompExosuitDrawer Extas in apparel.AllComps.Where(x => x.GetType() == typeof(CompExosuitDrawer)))
                        {
                            Vector3 drawAt = vector;
                            if (!Extas.Props.ExtrasEntries.NullOrEmpty())
                            {
                                if (Extas.ShouldDrawExtra(pawn, apparel, bodyFacing, out Material extraMat))
                                {
                                    if (Extas.onHead)
                                    {
                                        drawAt = vector + quat * pawn.Drawer.renderer.BaseHeadOffsetAt(headfacing);
                                    }
                                    drawAt += quat * Extas.GetAltitudeOffset(bodyFacing, Extas.ExtraPartEntry);
                                    Matrix4x4 matrix = default(Matrix4x4);
                                    matrix.SetTRS(drawAt, quat, new Vector3(Extas.ExtraPartEntry.drawSize.x, 0, Extas.ExtraPartEntry.drawSize.y));
                                    Graphics.DrawMesh(mesh, matrix, extraMat, 1);
                                    //    vector.y += CompApparelExtaDrawer.MinClippingDistance;
                                }
                            }
                        }
                    }

                    /*
                     * Comp_TurretGun OgsOld_CompTurret = apparel.TryGetComp<Comp_TurretGun>();
                     * if (OgsOld_CompTurret != null)
                     * {
                     *  foreach (Comp_TurretGun Extas in apparel.AllComps.Where(x => x.GetType() == typeof(Comp_TurretGun)))
                     *  {
                     *      Extas.PostDraw();
                     *  }
                     * }
                     */
                }
            }
        }
        public static void Postfix(PawnGraphicSet __instance, bool portrait, ref Material __result)
        {
            Pawn pawn = __instance.pawn;

            if (pawn.apparel.AnyApparel && !portrait)
            {
                if (pawn.apparel.WornApparel.Any(x => x.TryGetComp <CompExosuitDrawer>() != null))
                {
                    foreach (var item in pawn.apparel.WornApparel)
                    {
                        CompExosuitDrawer extraDrawer = item.TryGetComp <CompExosuitDrawer>();
                        if (extraDrawer != null && extraDrawer.hidesHair)
                        {
                            __result = Constants.InvisibleGraphics(pawn).hairGraphic.MatSingle;
                            return;
                        }
                    }
                }
            }
        }