Ejemplo n.º 1
0
        public void DrawEquipmentAiming(Thing eq, Vector3 drawLoc, float aimAngle)
        {
            float num = aimAngle - 90f;
            Mesh  mesh;

            if (aimAngle > 20f && aimAngle < 160f)
            {
                mesh = MeshPool.plane10;
                num += eq.def.equippedAngleOffset;
            }
            else if (aimAngle > 200f && aimAngle < 340f)
            {
                mesh = MeshPool.plane10Flip;
                num -= 180f;
                num -= eq.def.equippedAngleOffset;
            }
            else
            {
                mesh = MeshPool.plane10;
                num += eq.def.equippedAngleOffset;
            }
            num %= 360f;
            Graphic_StackCount graphic_StackCount = eq.Graphic as Graphic_StackCount;
            Material           matSingle;

            if (graphic_StackCount != null)
            {
                matSingle = graphic_StackCount.SubGraphicForStackCount(1, eq.def).MatSingle;
            }
            else
            {
                matSingle = eq.Graphic.MatSingle;
            }
            Graphics.DrawMesh(mesh, drawLoc, Quaternion.AngleAxis(num, Vector3.up), matSingle, 0);
        }
        static void renderStaticEquipment(Pawn pawn, /*Mesh mesh,*/ Rot4 bodyFacing, Vector3 vector, Quaternion quaternion, bool portrait)
        {
            if (!Settings.corpse_display_equipment || portrait || !pawn.Dead || pawn.Spawned || pawn.equipment == null || pawn.equipment.Primary == null)
            {
                return;
            }
            var eq     = pawn.equipment.Primary;
            var offset = eq.def.equippedAngleOffset % 360f;
            Graphic_StackCount graphic_StackCount = eq.Graphic as Graphic_StackCount;
            Material           matSingle;

            if (graphic_StackCount == null)
            {
                matSingle = eq.Graphic.MatSingle;
            }
            else
            {
                matSingle = graphic_StackCount.SubGraphicForStackCount(1, eq.def).MatSingle;
            }

            float   an = 0;
            Vector3 ax = Vector3.up;

            quaternion.ToAngleAxis(out an, out ax);
            Graphics.DrawMesh(MeshPool.plane10, vector + quaternion * new Vector3(0, 0, -0.22f) + new Vector3(0f, 0.0367346928f, 0f), Quaternion.AngleAxis(-45f - (an - 180f) * 0.2f + offset, Vector3.up), matSingle, 0);
        }
        public void DrawEquipmentAiming(Thing eq, Vector3 drawLoc, float aimAngle)
        {
            Mesh  mesh = null;
            float num  = aimAngle - 90f;

            if (aimAngle > 20f && aimAngle < 160f)
            {
                mesh = MeshPool.plane10;
                num += eq.def.equippedAngleOffset;
            }
            else if (aimAngle > 200f && aimAngle < 340f)
            {
                mesh = MeshPool.plane10Flip;
                num -= 180f;
                num -= eq.def.equippedAngleOffset;
            }
            else
            {
                mesh = MeshPool.plane10;
                num += eq.def.equippedAngleOffset;
            }
            num %= 360f;
            CompEquippable compEquippable = eq.TryGetComp <CompEquippable>();

            if (compEquippable != null)
            {
                EquipmentUtility.Recoil(eq.def, EquipmentUtility.GetRecoilVerb(compEquippable.AllVerbs), out var drawOffset, out var angleOffset, aimAngle);
                drawLoc += drawOffset;
                num     += angleOffset;
            }
            Material           material           = null;
            Graphic_StackCount graphic_StackCount = eq.Graphic as Graphic_StackCount;

            Graphics.DrawMesh(material: (graphic_StackCount == null) ? eq.Graphic.MatSingle : graphic_StackCount.SubGraphicForStackCount(1, eq.def).MatSingle, mesh: mesh, position: drawLoc, rotation: Quaternion.AngleAxis(num, Vector3.up), layer: 0);
        }
Ejemplo n.º 4
0
        public static bool DrawEquipmentAimingModded(Thing eq, Vector3 drawLoc, float aimAngle)
        {
            Pawn pawn;

            float num = aimAngle - 90f;
            Mesh  mesh;

            if (aimAngle > 20f && aimAngle < 160f)
            {
                mesh = MeshPool.plane10;
                num += eq.def.equippedAngleOffset;
            }
            else if (aimAngle > 200f && aimAngle < 340f)
            {
                mesh = MeshPool.plane10Flip;
                num -= 180f;
                num -= eq.def.equippedAngleOffset;
            }
            else
            {
                mesh = MeshPool.plane10;
                num += eq.def.equippedAngleOffset;
            }
            num %= 360f;
            Graphic_StackCount graphic_StackCount = eq.Graphic as Graphic_StackCount;
            Material           matSingle;

            if (graphic_StackCount != null)
            {
                matSingle = graphic_StackCount.SubGraphicForStackCount(1, eq.def).MatSingle;
            }
            else
            {
                matSingle = eq.Graphic.MatSingle;
            }

            if (eq.GetType() == typeof(FactionItem))
            {
                FactionItemDef facdef    = eq.def as FactionItemDef;
                float          scalePawn = 1f;
                Vector3        scale     = facdef.ItemMeshSize * scalePawn;
                Material       Mat       = eq.Graphic.MatAt(eq.Rotation);
                Matrix4x4      matrix    = default(Matrix4x4);
                matrix.SetTRS(drawLoc, Quaternion.AngleAxis(num, Vector3.up), scale * 1.2f);
                Graphics.DrawMesh(mesh, matrix, matSingle, 0);

                //                Matrix4x4 matrix = default(Matrix4x4);
                //                matrix.SetTRS(drawLoc, Quaternion.AngleAxis(num, Vector3.up), facdef.ItemMeshSize);
                //                Graphics.DrawMesh(mesh, matrix, matSingle, 0);
                //               Graphics.DrawMesh()
            }

            else
            {
                Graphics.DrawMesh(mesh, drawLoc, Quaternion.AngleAxis(num, Vector3.up), matSingle, 0);
            }

            return(false);
        }
        static bool Prefix(Pawn ___pawn, Thing eq, Vector3 drawLoc, float aimAngle)
        {
            var comp = eq.TryGetCompOversizedWeapon();

            if (comp == null)
            {
                return(true);
            }

            // Ultimately I think it is better to do this than try to use a transpiler.
            // In any solution I will have to check for the comp (which adds the overhead)
            // and beyond that there is no advantage of using a transpiler vs replacing the original
            // like this.

            float num = aimAngle - 90f;
            Mesh  mesh;

            if (aimAngle > 20f && aimAngle < 160f)
            {
                mesh = MeshPool.plane10;
                num += eq.def.equippedAngleOffset;
            }
            else if (aimAngle > 200f && aimAngle < 340f)
            {
                mesh = MeshPool.plane10Flip;
                num -= 180f;
                num -= eq.def.equippedAngleOffset;
            }
            else
            {
                mesh = MeshPool.plane10;
                num += eq.def.equippedAngleOffset;
            }
            num %= 360f;
            Graphic_StackCount graphic_StackCount = eq.Graphic as Graphic_StackCount;
            Material           matSingle;

            if (graphic_StackCount != null)
            {
                matSingle = graphic_StackCount.SubGraphicForStackCount(1, eq.def).MatSingle;
            }
            else
            {
                matSingle = eq.Graphic.MatSingle;
            }

            // CHANGED
            Vector3 scale     = new Vector3(eq.Graphic.drawSize.x, 1f, eq.Graphic.drawSize.y);
            var     curOffset = comp.Props != null?OffsetFromRotation(___pawn.Rotation, comp.Props) : Vector3.zero;

            Graphics.DrawMesh(mesh, Matrix4x4.TRS(drawLoc + curOffset, Quaternion.AngleAxis(num, Vector3.up), scale), matSingle, 0);
            return(false);
        }
        public static void Postfix(PawnRenderer __instance, Thing eq, Vector3 drawLoc, float aimAngle)
        {
            if (replaced)
            {
                if (!(pawn.stances.curStance is Stance_Busy && ((Stance_Busy)pawn.stances.curStance).focusTarg.IsValid))
                {
                    aimAngle = machine.turretAngle;
                }

                if (pawn.Rotation == Rot4.South)
                {
                    drawLoc -= south;
                }
                else if (pawn.Rotation == Rot4.North)
                {
                    drawLoc -= north;
                }
                else if (pawn.Rotation == Rot4.East)
                {
                    drawLoc -= east;
                }
                else if (pawn.Rotation == Rot4.West)
                {
                    drawLoc -= west;
                }

                Mesh  mesh = null;
                float num  = aimAngle - 90f;
                if (aimAngle > 20f && aimAngle < 160f)
                {
                    mesh = MeshPool.plane20;
                    num += eq.def.equippedAngleOffset;
                }
                else if (aimAngle > 200f && aimAngle < 340f)
                {
                    mesh = StaticConstructorClass.plane20Flip;
                    num -= 180f;
                    num -= eq.def.equippedAngleOffset;
                }
                else
                {
                    mesh = MeshPool.plane20;
                    num += eq.def.equippedAngleOffset;
                }
                num %= 360f;
                Graphic_StackCount graphic_StackCount = eq.Graphic as Graphic_StackCount;
                Graphics.DrawMesh(material: (graphic_StackCount == null) ? eq.Graphic.MatSingle : graphic_StackCount.SubGraphicForStackCount(1, eq.def).MatSingle, mesh: mesh, position: drawLoc, rotation: Quaternion.AngleAxis(num, Vector3.up), layer: 0);
            }
            replaced = false;
        }
Ejemplo n.º 7
0
        //=================================== COMPDEFLECTOR

        //public static void SpecialDisplayStatsPostFix(Thing __instance, ref IEnumerable<StatDrawEntry> __result)
        //{
        //    ////Log.Message("3");
        //    ThingWithComps thingWithComps = __instance as ThingWithComps;
        //    if (thingWithComps != null)
        //    {
        //        CompDeflector compDeflector = thingWithComps.GetComp<CompDeflector>();
        //        if (compDeflector != null)
        //        {
        //            List<StatDrawEntry> origin = new List<StatDrawEntry>();
        //            foreach (StatDrawEntry entry in __result)
        //            {
        //                //Log.Message("Entry");
        //                origin.Add(entry);
        //            }

        //            List<StatDrawEntry> entries = new List<StatDrawEntry>();
        //            foreach (StatDrawEntry entry in compDeflector.PostSpecialDisplayStats())
        //            {
        //                //Log.Message("Hey!");
        //                entries.Add(entry);
        //            }

        //            origin.Concat(entries);

        //            __result = origin;
        //        }
        //    }
        //}

        public static void DrawEquipmentAimingPostFix(PawnRenderer __instance, Thing eq, Vector3 drawLoc, float aimAngle)
        {
            Pawn pawn = (Pawn)AccessTools.Field(typeof(PawnRenderer), "pawn").GetValue(__instance);

            if (pawn != null)
            {
                ////Log.Message("1");
                Pawn_EquipmentTracker pawn_EquipmentTracker = pawn.equipment;
                if (pawn_EquipmentTracker != null)
                {
                    ////Log.Message("2");
                    foreach (ThingWithComps thingWithComps in pawn_EquipmentTracker.AllEquipmentListForReading)
                    {
                        ////Log.Message("3");
                        if (thingWithComps != null)
                        {
                            ////Log.Message("4");
                            ////Log.Message("3");
                            CompDeflector compDeflector = thingWithComps.GetComp <CompDeflector>();
                            if (compDeflector != null)
                            {
                                ////Log.Message("5");
                                if (compDeflector.IsAnimatingNow)
                                {
                                    bool flip = false;
                                    if (!Find.TickManager.Paused && compDeflector.IsAnimatingNow)
                                    {
                                        compDeflector.AnimationDeflectionTicks -= 20;
                                    }
                                    float offset = eq.def.equippedAngleOffset;
                                    float num    = aimAngle - 90f;
                                    if (aimAngle > 20f && aimAngle < 160f)
                                    {
                                        //mesh = MeshPool.plane10;
                                        num += offset;
                                        if (compDeflector.IsAnimatingNow)
                                        {
                                            num += ((compDeflector.AnimationDeflectionTicks + 1) / 2);
                                        }
                                    }
                                    else if (aimAngle > 200f && aimAngle < 340f)
                                    {
                                        //mesh = MeshPool.plane10Flip;
                                        flip = true;
                                        num -= 180f;
                                        num -= offset;
                                        if (compDeflector.IsAnimatingNow)
                                        {
                                            num -= ((compDeflector.AnimationDeflectionTicks + 1) / 2);
                                        }
                                    }
                                    else
                                    {
                                        //mesh = MeshPool.plane10;
                                        num += offset;
                                        if (compDeflector.IsAnimatingNow)
                                        {
                                            num += ((compDeflector.AnimationDeflectionTicks + 1) / 2);
                                        }
                                    }
                                    num %= 360f;
                                    Graphic_StackCount graphic_StackCount = eq.Graphic as Graphic_StackCount;
                                    Material           matSingle;
                                    if (graphic_StackCount != null)
                                    {
                                        matSingle = graphic_StackCount.SubGraphicForStackCount(1, eq.def).MatSingle;
                                    }
                                    else
                                    {
                                        matSingle = eq.Graphic.MatSingle;
                                    }
                                    //mesh = MeshPool.GridPlane(thingWithComps.def.graphicData.drawSize);
                                    //Graphics.DrawMesh(mesh, drawLoc, Quaternion.AngleAxis(num, Vector3.up), matSingle, 0);

                                    Vector3   s      = new Vector3(eq.def.graphicData.drawSize.x, 1f, eq.def.graphicData.drawSize.y);
                                    Matrix4x4 matrix = default(Matrix4x4);
                                    matrix.SetTRS(drawLoc, Quaternion.AngleAxis(num, Vector3.up), s);
                                    if (!flip)
                                    {
                                        Graphics.DrawMesh(MeshPool.plane10, matrix, matSingle, 0);
                                    }
                                    else
                                    {
                                        Graphics.DrawMesh(MeshPool.plane10Flip, matrix, matSingle, 0);
                                    }

                                    ////Log.Message("DeflectDraw");
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public void DrawEquipmentAiming(Thing eq, Vector3 drawLoc, float aimAngle, int curLevel, int baseLevel)
        {
            float num = aimAngle - 90f;
            Mesh  mesh;

            if (aimAngle > 20f && aimAngle < 160f)
            {
                mesh = MeshPool.plane10;
                num += eq.def.equippedAngleOffset;
            }
            else if (aimAngle > 200f && aimAngle < 340f)
            {
                mesh = MeshPool.plane10Flip;
                num -= 180f;
                num -= eq.def.equippedAngleOffset;
            }
            else
            {
                mesh = MeshPool.plane10;
                num += eq.def.equippedAngleOffset;
            }
            num %= 360f;
            Graphic_StackCount graphic_StackCount = eq.Graphic as Graphic_StackCount;
            Material           matSingle;
            var matrix = default(Matrix4x4);

            if (graphic_StackCount != null)
            {
                matSingle = graphic_StackCount.SubGraphicForStackCount(1, eq.def).MatSingle;
            }
            else
            {
                if (!cachedGraphics.TryGetValue(eq, out var graphics))
                {
                    graphics           = new Dictionary <int, Graphic>();
                    cachedGraphics[eq] = graphics;
                }
                if (!graphics.TryGetValue(curLevel, out var graphic))
                {
                    if (eq.Graphic is Graphic_RandomRotated graphicRandomRotated)
                    {
                        Vector2 drawSize = graphicRandomRotated.subGraphic.drawSize;
                        drawSize.x *= 1f - ((curLevel - baseLevel) / DrawDynamicThings.pawnDrawScale);
                        drawSize.y *= 1f - ((curLevel - baseLevel) / DrawDynamicThings.pawnDrawScale);
                        Log.Message("Get copy 1 from " + graphicRandomRotated.subGraphic);
                        graphic = graphicRandomRotated.subGraphic.GetCopy(drawSize);
                    }
                    else
                    {
                        Vector2 drawSize = eq.Graphic.drawSize;
                        drawSize.x *= 1f - ((curLevel - baseLevel) / DrawDynamicThings.pawnDrawScale);
                        drawSize.y *= 1f - ((curLevel - baseLevel) / DrawDynamicThings.pawnDrawScale);
                        Log.Message("Get copy 2 from " + eq.Graphic);
                        graphic = eq.Graphic.GetCopy(drawSize);
                    }
                    graphics[curLevel] = graphic;
                }

                matrix.SetTRS(drawLoc, Quaternion.AngleAxis(num, Vector3.up), new Vector3(graphic.drawSize.x, 1f, graphic.drawSize.y));
                matSingle = graphic.MatSingle;
            }
            Graphics.DrawMesh(mesh, matrix, matSingle, 0);
        }
        public static void DrawEquipmentAimingOverride(Mesh mesh, Thing eq, Vector3 drawLoc, float aimAngle, CompOversizedWeapon compOversized, CompEquippable equippable, Pawn pawn, bool offhand = false)
        {
            float num = aimAngle - 90f;

            if (aimAngle > 20f && aimAngle < 160f)
            {
                mesh = MeshPool.plane10;
                num += eq.def.equippedAngleOffset;
            }
            else
            {
                if (aimAngle > 200f && aimAngle < 340f)
                {
                    mesh = offhand ? (mesh == MeshPool.plane10 ? MeshPool.plane10Flip : MeshPool.plane10) : MeshPool.plane10Flip;
                    num -= 180f;
                    num -= eq.def.equippedAngleOffset;
                }
                else
                {
                    mesh = MeshPool.plane10;
                    num += eq.def.equippedAngleOffset;
                }
            }
            num %= 360f;
            Vector3 s;

            if (pawn.RaceProps.Humanlike)
            {
                if (HarmonyPatches_OversizedWeapon.enabled_AlienRaces)
                {
                    Vector2 v = AlienRaceUtility.AlienRacesPatch(pawn, eq);
                    float   f = Mathf.Max(v.x, v.y);
                    s = new Vector3(eq.def.graphicData.drawSize.x * f, 1f, eq.def.graphicData.drawSize.y * f);
                }
                else
                {
                    s = new Vector3(eq.def.graphicData.drawSize.x, 1f, eq.def.graphicData.drawSize.y);
                }
            }
            else
            {
                Vector2 v = pawn.ageTracker.CurKindLifeStage.bodyGraphicData.drawSize;
                s = new Vector3(eq.def.graphicData.drawSize.x + v.x / 10, 1f, eq.def.graphicData.drawSize.y + v.y / 10);
            }
            Matrix4x4  matrix   = default(Matrix4x4);
            Quaternion rotation = Quaternion.AngleAxis(num, Vector3.up);

            matrix.SetTRS(drawLoc, rotation, s);
            Graphic_StackCount graphic_StackCount = eq.Graphic as Graphic_StackCount;
            bool     flag3 = graphic_StackCount != null;
            Material matSingle;

            if (flag3)
            {
                matSingle = graphic_StackCount.SubGraphicForStackCount(1, eq.def).MatSingle;
            }
            else
            {
                matSingle = eq.Graphic.MatSingle;
            }
            OversizedUtil.Draw(mesh, matrix, matSingle, 0, eq, pawn, drawLoc, rotation);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Adds another "layer" to the equipment aiming if they have a
        /// weapon with a CompActivatableEffect.
        /// </summary>
        /// <param name="__instance"></param>
        /// <param name="eq"></param>
        /// <param name="drawLoc"></param>
        /// <param name="aimAngle"></param>
        public static bool DrawEquipmentAimingPreFix(PawnRenderer __instance, Thing eq, Vector3 drawLoc, float aimAngle)
        {
                ThingWithComps thingWithComps = eq as ThingWithComps;
                if (thingWithComps != null)
                {

                //If the deflector is active, it's already using this code.
                var deflector = thingWithComps.AllComps.FirstOrDefault<ThingComp>((ThingComp y) => y.GetType().ToString() == "CompDeflector.CompDeflector" || y.GetType().BaseType.ToString() == "CompDeflector.CompDeflector");
                    if (deflector != null)
                    {
                        bool isAnimatingNow = Traverse.Create(deflector).Property("IsAnimatingNow").GetValue<bool>();
                        if (isAnimatingNow)
                        {
                            return false;
                        }

                    }

                    CompOversizedWeapon compOversizedWeapon = thingWithComps.TryGetComp<CompOversizedWeapon>();
                    if (compOversizedWeapon != null)
                    {
                    bool flip = false;
                    float num = aimAngle - 90f;
                    Mesh mesh;
                    if (aimAngle > 20f && aimAngle < 160f)
                    {
                        mesh = MeshPool.plane10;
                        num += eq.def.equippedAngleOffset;
                    }
                    else if (aimAngle > 200f && aimAngle < 340f)
                    {
                        mesh = MeshPool.plane10Flip;
                        flip = true;
                        num -= 180f;
                        num -= eq.def.equippedAngleOffset;
                    }
                    else
                    {
                        mesh = MeshPool.plane10;
                        num += eq.def.equippedAngleOffset;
                    }
                    num %= 360f;
                    Graphic_StackCount graphic_StackCount = eq.Graphic as Graphic_StackCount;
                    Material matSingle;
                    if (graphic_StackCount != null)
                    {
                        matSingle = graphic_StackCount.SubGraphicForStackCount(1, eq.def).MatSingle;
                    }
                    else
                    {
                        matSingle = eq.Graphic.MatSingle;
                    }

                    Vector3 s = new Vector3(eq.def.graphicData.drawSize.x, 1f, eq.def.graphicData.drawSize.y);
                    Matrix4x4 matrix = default(Matrix4x4);
                    matrix.SetTRS(drawLoc, Quaternion.AngleAxis(num, Vector3.up), s);
                    if (!flip) Graphics.DrawMesh(MeshPool.plane10, matrix, matSingle, 0);
                    else Graphics.DrawMesh(MeshPool.plane10Flip, matrix, matSingle, 0);
                    return false;
                }
            }
            //}
            return true;
        }
Ejemplo n.º 11
0
        static bool Prefix(ref Thing eq, ref Vector3 drawLoc, ref float aimAngle, PawnRenderer __instance)
        {
            if (!Gunplay.settings.enableWeaponAnimations)
            {
                return(true);
            }

            CompGun comp = eq.TryGetComp <CompGun>();

            if (comp == null)
            {
                return(true);
            }

            Pawn pawn = pawnField.GetValue(__instance) as Pawn;

            if (pawn == null)
            {
                return(true);
            }

            Stance_Busy stance_Busy = pawn.stances.curStance as Stance_Busy;

            if (stance_Busy != null && !stance_Busy.neverAimWeapon && stance_Busy.focusTarg.IsValid)
            {
                drawLoc -= equipmentDir.RotatedBy(aimAngle);
                aimAngle = (aimAngle + comp.RotationOffset) % 360;
                drawLoc += equipmentDir.RotatedBy(aimAngle);
            }

            GunPropDef prop = GunplaySetup.GunProp(eq);

            if (prop == null)
            {
                return(true);
            }

            float num = aimAngle - 90f;
            Mesh  mesh;

            if (aimAngle > 20f && aimAngle < 160f)
            {
                mesh = MeshPool.plane10;
                num += eq.def.equippedAngleOffset;
            }
            else if (aimAngle > 200f && aimAngle < 340f)
            {
                mesh = MeshPool.plane10Flip;
                num -= 180f;
                num -= eq.def.equippedAngleOffset;
            }
            else
            {
                mesh = MeshPool.plane10;
                num += eq.def.equippedAngleOffset;
            }
            num %= 360f;

            drawingScale.x = drawingScale.z = prop.drawScale;
            CompPrimer primer = eq.TryGetComp <CompPrimer>();

            if (primer != null)
            {
                primer.Draw(mesh, drawLoc, num, drawingScale);
                return(false);
            }

            if (prop.drawScale == 1f)
            {
                return(true);
            }

            Material mat;

            Graphic_StackCount graphic_StackCount = eq.Graphic as Graphic_StackCount;

            if (graphic_StackCount != null)
            {
                mat = graphic_StackCount.SubGraphicForStackCount(1, eq.def).MatSingle;
            }
            else
            {
                mat = eq.Graphic.MatSingle;
            }

            drawingMatrix.SetTRS(drawLoc, Quaternion.AngleAxis(num, Vector3.up), drawingScale);
            Graphics.DrawMesh(mesh, drawingMatrix, mat, 0);

            return(false);
        }
Ejemplo n.º 12
0
        public static bool DrawEquipmentAimingModded(Thing eq, Vector3 drawLoc, float aimAngle)
        {
            Pawn pawn;
            ThingDef_AlienRace alienRaceDef = HarmonyPatches.AlienDefFor(eq, out pawn);

            if (alienRaceDef != null)
            {
                switch (pawn.Rotation.AsInt)
                {
                case 1:
                {
                    drawLoc.x += (alienRaceDef.alienRace.generalSettings.alienPartGenerator.CustomDrawSize.x - 1);
                    break;
                }

                case 2:
                {
                    drawLoc.z -= (alienRaceDef.alienRace.generalSettings.alienPartGenerator.CustomDrawSize.x - 1);
                    break;
                }

                case 3:
                {
                    drawLoc.x -= (alienRaceDef.alienRace.generalSettings.alienPartGenerator.CustomDrawSize.x - 1);
                    break;
                }
                }
            }

            float num = aimAngle - 90f;
            Mesh  mesh;

            if (aimAngle > 20f && aimAngle < 160f)
            {
                mesh = MeshPool.plane10;
                num += eq.def.equippedAngleOffset;
            }
            else if (aimAngle > 200f && aimAngle < 340f)
            {
                mesh = MeshPool.plane10Flip;
                num -= 180f;
                num -= eq.def.equippedAngleOffset;
            }
            else
            {
                mesh = MeshPool.plane10;
                num += eq.def.equippedAngleOffset;
            }
            num %= 360f;
            Graphic_StackCount graphic_StackCount = eq.Graphic as Graphic_StackCount;
            Material           matSingle;

            if (graphic_StackCount != null)
            {
                matSingle = graphic_StackCount.SubGraphicForStackCount(1, eq.def).MatSingle;
            }
            else
            {
                matSingle = eq.Graphic.MatSingle;
            }

            if (eq.GetType() == typeof(FactionItem))
            {
                FactionItemDef facdef    = eq.def as FactionItemDef;
                float          scalePawn = alienRaceDef != null ? alienRaceDef.alienRace.generalSettings.alienPartGenerator.CustomDrawSize.x : 1f;
                Vector3        scale     = facdef.ItemMeshSize * scalePawn;
                Material       Mat       = eq.Graphic.MatAt(eq.Rotation);
                Matrix4x4      matrix    = default(Matrix4x4);
                matrix.SetTRS(drawLoc, Quaternion.AngleAxis(num, Vector3.up), scale * 1.2f);
                Graphics.DrawMesh(mesh, matrix, matSingle, 0);

                //                Matrix4x4 matrix = default(Matrix4x4);
                //                matrix.SetTRS(drawLoc, Quaternion.AngleAxis(num, Vector3.up), facdef.ItemMeshSize);
                //                Graphics.DrawMesh(mesh, matrix, matSingle, 0);
                //               Graphics.DrawMesh()
            }

            else
            {
                Graphics.DrawMesh(mesh, drawLoc, Quaternion.AngleAxis(num, Vector3.up), matSingle, 0);
            }

            return(false);
        }
Ejemplo n.º 13
0
        // draws hands on equipment and adjusts aiming angle position, if corresponding Comp is specified
        public new void DrawEquipmentAiming(Thing equipment, Vector3 weaponDrawLoc, float aimAngle)
        {
            CompWeaponExtensions compWeaponExtensions = pawn.equipment.Primary.TryGetComp <CompWeaponExtensions>();

            float   weaponAngle;
            Vector3 weaponPositionOffset = Vector3.zero;

            Mesh weaponMesh;
            bool flipped;
            bool aiming = Aiming();

            if (aimAngle > 110 && aimAngle < 250)
            {
                flipped = true;

                // flip weapon texture
                weaponMesh = MeshPool.GridPlaneFlip(equipment.Graphic.drawSize);

                if (!aiming && compWeaponExtensions != null)
                {
                    weaponPositionOffset += compWeaponExtensions.WeaponPositionOffset;
                    // flip x position offset
                    weaponPositionOffset.x = -weaponPositionOffset.x;
                }

                weaponAngle  = aimAngle - 180f;
                weaponAngle -= !aiming
                    ? equipment.def.equippedAngleOffset
                    : (compWeaponExtensions?.AttackAngleOffset ?? 0);
            }
            else
            {
                flipped = false;

                weaponMesh = MeshPool.GridPlane(equipment.Graphic.drawSize);

                if (!aiming && compWeaponExtensions != null)
                {
                    weaponPositionOffset += compWeaponExtensions.WeaponPositionOffset;
                }

                weaponAngle  = aimAngle;
                weaponAngle += !aiming
                    ? equipment.def.equippedAngleOffset
                    : (compWeaponExtensions?.AttackAngleOffset ?? 0);
            }

            if (pawn.Rotation == Rot4.West || pawn.Rotation == Rot4.North)
            {
                // draw weapon beneath the pawn
                weaponPositionOffset += new Vector3(0, -0.5f, 0);
            }

            // weapon angle and position offsets based on current attack animation sequence
            DoAttackAnimationOffsets(ref weaponAngle, ref weaponPositionOffset, flipped);

            Graphic_StackCount graphic_StackCount = equipment.Graphic as Graphic_StackCount;
            Material           weaponMat          = graphic_StackCount != null
                ? graphic_StackCount.SubGraphicForStackCount(1, equipment.def).MatSingle
                : equipment.Graphic.MatSingle;

            // draw weapon
            Graphics.DrawMesh(weaponMesh, weaponDrawLoc + weaponPositionOffset,
                              Quaternion.AngleAxis(weaponAngle, Vector3.up),
                              weaponMat, 0);

            // draw hands on equipment, if CompWeaponExtensions defines them
            if (compWeaponExtensions != null)
            {
                DrawHands(weaponAngle, weaponDrawLoc + weaponPositionOffset, compWeaponExtensions, flipped);
            }
        }
Ejemplo n.º 14
0
        public static bool Prefix(PawnRenderer __instance, Thing eq, Vector3 drawLoc, float aimAngle)
        {
            Traverse traverse = Traverse.Create(__instance);
            Pawn     pp       = traverse.Field("pawn").GetValue <Pawn>();

            if (pp.kindDef.defName.EqualsIgnoreCase("ra2_rhinotank") || pp.kindDef.defName.EqualsIgnoreCase("ra2_grizzlytank") || pp.kindDef.defName.EqualsIgnoreCase("ra2_apotank"))
            {
                Stance_Busy stance_Busy = pp.stances.curStance as Stance_Busy;
                if (stance_Busy != null && !stance_Busy.neverAimWeapon && stance_Busy.focusTarg.IsValid)
                {
                    drawLoc -= new Vector3(0f, 0f, 0.4f).RotatedBy(aimAngle);
                }
                else
                {
                    if (pp.Rotation == Rot4.South)
                    {
                        drawLoc -= new Vector3(0f, 0f, -0.22f);
                    }
                    else if (pp.Rotation == Rot4.North)
                    {
                        drawLoc -= new Vector3(0f, 0f, -0.11f);
                    }
                    else if (pp.Rotation == Rot4.East)
                    {
                        drawLoc -= new Vector3(0.2f, 0f, -0.22f);
                    }
                    else if (pp.Rotation == Rot4.West)
                    {
                        drawLoc -= new Vector3(-0.2f, 0f, -0.22f);
                    }
                }

                float num = aimAngle - 90f;



                Mesh mesh;
                if (aimAngle > 20f && aimAngle < 160f)
                {
                    mesh = MeshPool.plane10;
                    num += eq.def.equippedAngleOffset;
                }
                else if (aimAngle > 200f && aimAngle < 340f)
                {
                    mesh = MeshPool.plane10Flip;
                    num -= 180f;
                    num -= eq.def.equippedAngleOffset;
                }
                else
                {
                    mesh = MeshPool.plane10;
                    num += eq.def.equippedAngleOffset;
                }

                num %= 360f;
                if (!pp.TargetCurrentlyAimingAt.IsValid)
                {
                    //Log.Warning(pp.Rotation+"/");
                    switch (pp.Rotation.AsInt)
                    {
                    case 0:
                        num = -90f;
                        break;

                    case 1:
                        num = 0f;
                        break;

                    case 2:
                        num = 90f;
                        break;

                    case 3:
                        num = 0f;
                        break;

                    default:
                        num = 0;
                        break;
                    }


                    // num =pp.Rotation.AsAngle- 90f;
                }
                Graphic_StackCount graphic_StackCount = eq.Graphic as Graphic_StackCount;
                Material           matSingle;
                if (graphic_StackCount != null)
                {
                    matSingle = graphic_StackCount.SubGraphicForStackCount(1, eq.def).MatSingle;
                }
                else
                {
                    matSingle = eq.Graphic.MatSingle;
                }
                Matrix4x4 matrix = new Matrix4x4();
                Vector3   s      = new Vector3(pp.kindDef.lifeStages[0].bodyGraphicData.drawSize.x, 1, pp.kindDef.lifeStages[0].bodyGraphicData.drawSize.y); //new Vector3(5,1,5);
                matrix.SetTRS(drawLoc + new Vector3(0, 1, 0), num.ToQuat(), s);
                // Graphics.DrawMesh(mesh, drawLoc, Quaternion.AngleAxis(num, Vector3.up), matSingle, 0);
                Graphics.DrawMesh(mesh, matrix, matSingle, 0);
                return(false);
            }



            return(true);
        }
        // Token: 0x0600000A RID: 10 RVA: 0x000022B0 File Offset: 0x000004B0
        public static bool DrawEquipmentAimingPreFix(PawnRenderer __instance, Thing eq, Vector3 drawLoc, float aimAngle)
        {
            ThingWithComps thingWithComps = eq as ThingWithComps;
            bool           flag           = thingWithComps != null;

            if (flag)
            {
                ThingComp thingComp = thingWithComps.AllComps.FirstOrDefault((ThingComp y) => y.GetType().ToString() == "CompDeflector.CompDeflector" || y.GetType().BaseType.ToString() == "CompDeflector.CompDeflector");
                bool      flag2     = thingComp != null;
                if (flag2)
                {
                    bool value = Traverse.Create(thingComp).Property("IsAnimatingNow", null).GetValue <bool>();
                    bool flag3 = value;
                    if (flag3)
                    {
                        return(false);
                    }
                }
                CompOversizedWeapon compOversizedWeapon = thingWithComps.TryGetComp <CompOversizedWeapon>();
                bool flag4 = compOversizedWeapon != null;
                if (flag4)
                {
                    bool  flag5  = false;
                    float num    = aimAngle - 90f;
                    Pawn  value2 = Traverse.Create(__instance).Field("pawn").GetValue <Pawn>();
                    bool  flag6  = value2 == null;
                    if (flag6)
                    {
                        return(true);
                    }
                    bool flag7 = aimAngle > 20f && aimAngle < 160f;
                    if (flag7)
                    {
                        Mesh mesh = MeshPool.plane10;
                        num += eq.def.equippedAngleOffset;
                    }
                    else
                    {
                        bool flag8 = aimAngle > 200f && aimAngle < 340f;
                        if (flag8)
                        {
                            Mesh mesh = MeshPool.plane10Flip;
                            flag5 = true;
                            num  -= 180f;
                            num  -= eq.def.equippedAngleOffset;
                        }
                        else
                        {
                            num = HarmonyCompOversizedWeapon.AdjustOffsetAtPeace(eq, value2, compOversizedWeapon, num);
                        }
                    }
                    bool flag9 = compOversizedWeapon.Props != null && !value2.IsFighting() && compOversizedWeapon.Props.verticalFlipNorth && value2.Rotation == Rot4.North;
                    if (flag9)
                    {
                        num += 180f;
                    }
                    bool flag10 = !value2.IsFighting();
                    if (flag10)
                    {
                        num = HarmonyCompOversizedWeapon.AdjustNonCombatRotation(value2, num, compOversizedWeapon);
                    }
                    num %= 360f;
                    Graphic_StackCount graphic_StackCount = eq.Graphic as Graphic_StackCount;
                    bool     flag11 = graphic_StackCount != null;
                    Material matSingle;
                    if (flag11)
                    {
                        matSingle = graphic_StackCount.SubGraphicForStackCount(1, eq.def).MatSingle;
                    }
                    else
                    {
                        matSingle = eq.Graphic.MatSingle;
                    }
                    Vector3   vector   = new Vector3(eq.def.graphicData.drawSize.x, 1f, eq.def.graphicData.drawSize.y);
                    Matrix4x4 matrix4x = default(Matrix4x4);
                    Vector3   vector2  = HarmonyCompOversizedWeapon.AdjustRenderOffsetFromDir(value2, compOversizedWeapon);
                    matrix4x.SetTRS(drawLoc + vector2, Quaternion.AngleAxis(num, Vector3.up), vector);
                    Graphics.DrawMesh((!flag5) ? MeshPool.plane10 : MeshPool.plane10Flip, matrix4x, matSingle, 0);
                    bool flag12 = compOversizedWeapon.Props != null && compOversizedWeapon.Props.isDualWeapon;
                    if (flag12)
                    {
                        vector2 = new Vector3(-1f * vector2.x, vector2.y, vector2.z);
                        bool flag13 = value2.Rotation == Rot4.North || value2.Rotation == Rot4.South;
                        Mesh mesh2;
                        if (flag13)
                        {
                            num  += 135f;
                            num  %= 360f;
                            mesh2 = ((!flag5) ? MeshPool.plane10Flip : MeshPool.plane10);
                        }
                        else
                        {
                            vector2 = new Vector3(vector2.x, vector2.y - 0.1f, vector2.z + 0.15f);
                            mesh2   = ((!flag5) ? MeshPool.plane10 : MeshPool.plane10Flip);
                        }
                        matrix4x.SetTRS(drawLoc + vector2, Quaternion.AngleAxis(num, Vector3.up), vector);
                        Graphics.DrawMesh(mesh2, matrix4x, matSingle, 0);
                    }
                    return(false);
                }
            }
            return(true);
        }
        //public static void DrawEquipmentAimingPostFix(PawnRenderer __instance, Thing eq, Vector3 drawLoc, float aimAngle)
        //{
        //    Pawn pawn = (Pawn)AccessTools.Field(typeof(PawnRenderer), "pawn").GetValue(__instance);

        //    Pawn_EquipmentTracker pawn_EquipmentTracker = pawn.equipment;
        //    if (pawn_EquipmentTracker != null)
        //    {
        //        ThingWithComps thingWithComps = (ThingWithComps)AccessTools.Field(typeof(Pawn_EquipmentTracker), "primaryInt").GetValue(pawn_EquipmentTracker);
        //        if (thingWithComps != null)
        //        {
        //            CompOversizedWeapon compOversizedWeapon = thingWithComps.TryGetComp<CompOversizedWeapon>();
        //            if (compOversizedWeapon != null)
        //            {
        //                bool flip = false;
        //                float num = aimAngle - 90f;
        //                Mesh mesh;
        //                if (aimAngle > 20f && aimAngle < 160f)
        //                {
        //                    mesh = MeshPool.plane10;
        //                    num += eq.def.equippedAngleOffset;
        //                }
        //                else if (aimAngle > 200f && aimAngle < 340f)
        //                {
        //                    mesh = MeshPool.plane10Flip;
        //                    flip = true;
        //                    num -= 180f;
        //                    num -= eq.def.equippedAngleOffset;
        //                }
        //                else
        //                {
        //                    mesh = MeshPool.plane10;
        //                    num += eq.def.equippedAngleOffset;
        //                }
        //                num %= 360f;
        //                Graphic_StackCount graphic_StackCount = eq.Graphic as Graphic_StackCount;
        //                Material matSingle;
        //                if (graphic_StackCount != null)
        //                {
        //                    matSingle = graphic_StackCount.SubGraphicForStackCount(1, eq.def).MatSingle;
        //                }
        //                else
        //                {
        //                    matSingle = eq.Graphic.MatSingle;
        //                }
        //                //mesh = MeshPool.GridPlane(thingWithComps.def.graphicData.drawSize);
        //                //Graphics.DrawMesh(mesh, drawLoc, Quaternion.AngleAxis(num, Vector3.up), matSingle, 0);
        //                //Log.Message("Oversized Draw");

        //                //Vector3 s = new Vector3(eq.def.graphicData.drawSize.x, 1f, eq.def.graphicData.drawSize.y);
        //                //Matrix4x4 matrix = default(Matrix4x4);
        //                //matrix.SetTRS(drawLoc, Quaternion.AngleAxis(num, Vector3.up), s);
        //                //if (!flip) Graphics.DrawMesh(MeshPool.plane10, matrix, matSingle, 0);
        //                //else Graphics.DrawMesh(MeshPool.plane10Flip, matrix, matSingle, 0);
        //                //Log.Message("Oversized Called");

        //            }
        //        }
        //    }
        //}
        /// <summary>
        /// Adds another "layer" to the equipment aiming if they have a
        /// weapon with a CompActivatableEffect.
        /// </summary>
        /// <param name="__instance"></param>
        /// <param name="eq"></param>
        /// <param name="drawLoc"></param>
        /// <param name="aimAngle"></param>
        public static bool DrawEquipmentAimingPreFix(PawnRenderer __instance, Thing eq, Vector3 drawLoc, float aimAngle)
        {
            Pawn pawn = (Pawn)AccessTools.Field(typeof(PawnRenderer), "pawn").GetValue(__instance);

            Pawn_EquipmentTracker pawn_EquipmentTracker = pawn.equipment;

            if (pawn_EquipmentTracker != null)
            {
                ThingWithComps thingWithComps = (ThingWithComps)AccessTools.Field(typeof(Pawn_EquipmentTracker), "primaryInt").GetValue(pawn_EquipmentTracker);
                if (thingWithComps != null)
                {
                    //If the deflector is active, it's already using this code.
                    ThingComp deflector = thingWithComps.AllComps.FirstOrDefault <ThingComp>((ThingComp y) => y.GetType().ToString().Contains("Deflect"));
                    if (deflector != null)
                    {
                        //Log.Message("Prefix");
                        bool isAnimatingNow = (bool)AccessTools.Property(deflector.GetType(), "IsAnimatingNow").GetValue(deflector, null);
                        if (isAnimatingNow)
                        {
                            return(false);
                        }
                    }
                }
                CompOversizedWeapon compOversizedWeapon = thingWithComps.TryGetComp <CompOversizedWeapon>();
                if (compOversizedWeapon != null)
                {
                    bool  flip = false;
                    float num  = aimAngle - 90f;
                    Mesh  mesh;
                    if (aimAngle > 20f && aimAngle < 160f)
                    {
                        mesh = MeshPool.plane10;
                        num += eq.def.equippedAngleOffset;
                    }
                    else if (aimAngle > 200f && aimAngle < 340f)
                    {
                        mesh = MeshPool.plane10Flip;
                        flip = true;
                        num -= 180f;
                        num -= eq.def.equippedAngleOffset;
                    }
                    else
                    {
                        mesh = MeshPool.plane10;
                        num += eq.def.equippedAngleOffset;
                    }
                    num %= 360f;
                    Graphic_StackCount graphic_StackCount = eq.Graphic as Graphic_StackCount;
                    Material           matSingle;
                    if (graphic_StackCount != null)
                    {
                        matSingle = graphic_StackCount.SubGraphicForStackCount(1, eq.def).MatSingle;
                    }
                    else
                    {
                        matSingle = eq.Graphic.MatSingle;
                    }
                    //mesh = MeshPool.GridPlane(thingWithComps.def.graphicData.drawSize);
                    //Graphics.DrawMesh(mesh, drawLoc, Quaternion.AngleAxis(num, Vector3.up), matSingle, 0);
                    //Log.Message("Oversized Draw");

                    Vector3   s      = new Vector3(eq.def.graphicData.drawSize.x, 1f, eq.def.graphicData.drawSize.y);
                    Matrix4x4 matrix = default(Matrix4x4);
                    matrix.SetTRS(drawLoc, Quaternion.AngleAxis(num, Vector3.up), s);
                    if (!flip)
                    {
                        Graphics.DrawMesh(MeshPool.plane10, matrix, matSingle, 0);
                    }
                    else
                    {
                        Graphics.DrawMesh(MeshPool.plane10Flip, matrix, matSingle, 0);
                    }
                    return(false);
                    //Log.Message("Oversized Called");
                }
            }
            return(true);
        }