From e7a13282a158d0b521ed0b1e01cd7c9149017256 Mon Sep 17 00:00:00 2001 From: MaxDorob Date: Tue, 11 Jun 2024 18:51:50 +0600 Subject: [PATCH 01/13] Visual recoil --- .../Harmony/Harmony_PawnRenderer.cs | 80 ++++++++----------- 1 file changed, 33 insertions(+), 47 deletions(-) diff --git a/Source/CombatExtended/Harmony/Harmony_PawnRenderer.cs b/Source/CombatExtended/Harmony/Harmony_PawnRenderer.cs index b245ab1495..71f299635b 100644 --- a/Source/CombatExtended/Harmony/Harmony_PawnRenderer.cs +++ b/Source/CombatExtended/Harmony/Harmony_PawnRenderer.cs @@ -468,55 +468,41 @@ private static void DrawMesh(Mesh mesh, Matrix4x4 matrix, Material mat, int laye */ internal static IEnumerable Transpiler(IEnumerable instructions) { - foreach (var c in instructions) + var codes = instructions.ToList(); + var recoil_opcodes = new CodeInstruction[] { - yield return c; + new CodeInstruction(OpCodes.Ldarg_0), + new CodeInstruction(OpCodes.Ldarg_1), + new CodeInstruction(OpCodes.Ldarg_2), + new CodeInstruction(OpCodes.Ldloc_1), + new CodeInstruction(OpCodes.Ldloc_2), + new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Harmony_PawnRenderer_DrawEquipmentAiming), nameof(RecoilCE))) + }; + bool foundRecoil = false; + int index = 0; + for (int i = 0; i < codes.Count; i++) + { + CodeInstruction code = codes[i]; + if (foundRecoil && code.opcode == OpCodes.Stloc_1) + { + index = i + 1; + break; + } + else if (code.opcode == OpCodes.Call && ReferenceEquals(code.operand, typeof(EquipmentUtility).GetMethod(nameof(EquipmentUtility.Recoil)))) + { + foundRecoil = true; + } } - // var codes = instructions.ToList(); - // var recoil_opcodes = new CodeInstruction[] - // { - // new CodeInstruction(OpCodes.Ldarg_1), - // new CodeInstruction(OpCodes.Ldarg_2), - // new CodeInstruction(OpCodes.Ldarg_3), - // new CodeInstruction(OpCodes.Ldloc_1), - // new CodeInstruction(OpCodes.Ldloc_2), - // new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Harmony_PawnRenderer_DrawEquipmentAiming), nameof(RecoilCE))) - // }; - // bool foundRecoil = false; - // int index = 0; - // for (int i = 0; i < codes.Count; i++) - // { - // CodeInstruction code = codes[i]; - // if (foundRecoil && code.opcode == OpCodes.Stloc_1) - // { - // index = i + 1; - // break; - // } - // else if (code.opcode == OpCodes.Call && ReferenceEquals(code.operand, typeof(EquipmentUtility).GetMethod(nameof(EquipmentUtility.Recoil)))) - // { - // foundRecoil = true; - // } - // } - // codes.InsertRange(index, recoil_opcodes); - // codes[codes.Count - 2].operand = - // AccessTools.Method(typeof(Harmony_PawnRenderer_DrawEquipmentAiming), nameof(DrawMesh)); - // codes.InsertRange(codes.Count - 2, new[] - // { - // new CodeInstruction(OpCodes.Ldarg_1), - // new CodeInstruction(OpCodes.Ldarg_2), - // new CodeInstruction(OpCodes.Ldarg_3) - // }); - // return codes; - } - - internal static void Prefix(ref Vector3 drawLoc) - { - return; - //TODO 1.5 - // if (___pawn.Rotation == south) - // { - // drawLoc.y++; - // } + codes.InsertRange(index, recoil_opcodes); + codes[codes.Count - 2].operand = + AccessTools.Method(typeof(Harmony_PawnRenderer_DrawEquipmentAiming), nameof(DrawMesh)); + codes.InsertRange(codes.Count - 2, new[] + { + new CodeInstruction(OpCodes.Ldarg_0), + new CodeInstruction(OpCodes.Ldarg_1), + new CodeInstruction(OpCodes.Ldarg_2) + }); + return codes; } } } From 979272e3c96c8e9b78f1c9f2104f7bf363623975 Mon Sep 17 00:00:00 2001 From: MaxDorob Date: Tue, 11 Jun 2024 23:14:35 +0600 Subject: [PATCH 02/13] Removed obsolete code --- .../CombatExtended/Defs/ShieldDefExtension.cs | 1 - .../CombatExtended/Things/Apparel_Shield.cs | 70 ------------------- 2 files changed, 71 deletions(-) diff --git a/Source/CombatExtended/CombatExtended/Defs/ShieldDefExtension.cs b/Source/CombatExtended/CombatExtended/Defs/ShieldDefExtension.cs index 0e22f414f8..65ef6e06e0 100644 --- a/Source/CombatExtended/CombatExtended/Defs/ShieldDefExtension.cs +++ b/Source/CombatExtended/CombatExtended/Defs/ShieldDefExtension.cs @@ -12,7 +12,6 @@ public class ShieldDefExtension : DefModExtension { public List shieldCoverage = new List(); public List crouchCoverage = new List(); - public bool drawAsTall = false; public bool PartIsCoveredByShield(BodyPartRecord part, Pawn pawn) { diff --git a/Source/CombatExtended/CombatExtended/Things/Apparel_Shield.cs b/Source/CombatExtended/CombatExtended/Things/Apparel_Shield.cs index 97f66dd40e..8ad14495d0 100644 --- a/Source/CombatExtended/CombatExtended/Things/Apparel_Shield.cs +++ b/Source/CombatExtended/CombatExtended/Things/Apparel_Shield.cs @@ -10,82 +10,12 @@ namespace CombatExtended { public class Apparel_Shield : Apparel { - // From PawnRenderer - private const float YOffsetBehind = 0.00390625f; - private const float YOffsetPostHead = 0.03515625f; - private const float YOffsetPrimaryEquipmentUnder = 0f; - private const float YOffsetPrimaryEquipmentOver = 0.0390625f; - private const float YOffsetIntervalClothes = 0.00390625f; - private const float YOffsetStatus = 0.04296875f; - public const string OneHandedTag = "CE_OneHandedWeapon"; - private bool drawShield => Wearer.Drafted || (Wearer.CurJob?.def.alwaysShowWeapon ?? false) || (Wearer.mindState.duty?.def.alwaysShowWeapon ?? false); // Copied from PawnRenderer.CarryWeaponOpenly(), we show the shield whenever weapons are drawn - private bool IsTall => def.GetModExtension()?.drawAsTall ?? false; - public override bool AllowVerbCast(Verb verb) { ThingWithComps primary = Wearer.equipment?.Primary; return primary == null || (primary.def.weaponTags?.Contains(OneHandedTag) ?? false); } - - public override void DrawWornExtras() - { - if (Wearer == null || !Wearer.Spawned) - { - return; - } - if (!drawShield) - { - return; - } - - float num = 0f; - Vector3 vector = this.Wearer.Drawer.DrawPos; - vector.y = Wearer.Rotation == Rot4.West || Wearer.Rotation == Rot4.South ? AltitudeLayer.PawnUnused.AltitudeFor() : AltitudeLayer.Pawn.AltitudeFor(); - - Vector3 s = new Vector3(1f, 1f, 1f); - if (this.Wearer.Rotation == Rot4.North) - { - vector.x -= 0.1f; - vector.z -= IsTall ? -0.1f : 0.2f; - } - else - { - if (this.Wearer.Rotation == Rot4.South) - { - vector.x += 0.1f; - vector.z -= IsTall ? -0.05f : 0.2f; - } - else - { - if (this.Wearer.Rotation == Rot4.East) - { - if (IsTall) - { - vector.x += 0.1f; - } - vector.z -= IsTall ? -0.05f : 0.2f; - num = 22.5f; - } - else - { - if (this.Wearer.Rotation == Rot4.West) - { - if (IsTall) - { - vector.x -= 0.1f; - } - vector.z -= IsTall ? -0.05f : 0.2f; - num = 337.5f; - } - } - } - } - Material mat = Graphic.GetColoredVersion(ShaderDatabase.CutoutComplex, DrawColor, DrawColorTwo).MatSingle; - Matrix4x4 matrix = default(Matrix4x4); - matrix.SetTRS(vector, Quaternion.AngleAxis(num, Vector3.up), s); - Graphics.DrawMesh(MeshPool.plane10, matrix, mat, 0); - } } } From dbfad6c35f278bd3408ae8690ed8d50da6977e53 Mon Sep 17 00:00:00 2001 From: MaxDorob Date: Tue, 11 Jun 2024 23:20:50 +0600 Subject: [PATCH 03/13] Reference assembly version 1.5.4104 (contains changes of render system) --- Source/BetterTurretsCompat/BetterTurretsCompat.csproj | 2 +- Source/CombatExtended/CombatExtended.csproj | 2 +- Source/MiscTurretsCompat/MiscTurretsCompat.csproj | 2 +- Source/MultiplayerCompat/MultiplayerCompat.csproj | 2 +- Source/SRTSCompat/SRTSCompat.csproj | 2 +- Source/VehiclesCompat/VehiclesCompat.csproj | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/BetterTurretsCompat/BetterTurretsCompat.csproj b/Source/BetterTurretsCompat/BetterTurretsCompat.csproj index 5a94488bc6..b37cab8275 100644 --- a/Source/BetterTurretsCompat/BetterTurretsCompat.csproj +++ b/Source/BetterTurretsCompat/BetterTurretsCompat.csproj @@ -54,7 +54,7 @@ - + diff --git a/Source/CombatExtended/CombatExtended.csproj b/Source/CombatExtended/CombatExtended.csproj index 48af98c638..06d24c20c2 100644 --- a/Source/CombatExtended/CombatExtended.csproj +++ b/Source/CombatExtended/CombatExtended.csproj @@ -128,7 +128,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/Source/MiscTurretsCompat/MiscTurretsCompat.csproj b/Source/MiscTurretsCompat/MiscTurretsCompat.csproj index c22e3f86a5..12f309f64b 100644 --- a/Source/MiscTurretsCompat/MiscTurretsCompat.csproj +++ b/Source/MiscTurretsCompat/MiscTurretsCompat.csproj @@ -54,7 +54,7 @@ - + diff --git a/Source/MultiplayerCompat/MultiplayerCompat.csproj b/Source/MultiplayerCompat/MultiplayerCompat.csproj index 9aab2f9dda..c32381cb51 100644 --- a/Source/MultiplayerCompat/MultiplayerCompat.csproj +++ b/Source/MultiplayerCompat/MultiplayerCompat.csproj @@ -46,7 +46,7 @@ - + diff --git a/Source/SRTSCompat/SRTSCompat.csproj b/Source/SRTSCompat/SRTSCompat.csproj index e1adde4fe8..5abb8ba699 100644 --- a/Source/SRTSCompat/SRTSCompat.csproj +++ b/Source/SRTSCompat/SRTSCompat.csproj @@ -52,7 +52,7 @@ - + diff --git a/Source/VehiclesCompat/VehiclesCompat.csproj b/Source/VehiclesCompat/VehiclesCompat.csproj index 56267a494b..79be0719b7 100644 --- a/Source/VehiclesCompat/VehiclesCompat.csproj +++ b/Source/VehiclesCompat/VehiclesCompat.csproj @@ -61,7 +61,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + From 40b62beea1af7a5215cd2628db86a17469551241 Mon Sep 17 00:00:00 2001 From: MaxDorob Date: Tue, 11 Jun 2024 23:21:38 +0600 Subject: [PATCH 04/13] Custom renderNodes --- .../Render/PawnRenderNodeWorker_Drafted.cs | 19 +++++++++++ .../Render/PawnRenderNode_Apparel.cs | 33 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 Source/CombatExtended/CombatExtended/Render/PawnRenderNodeWorker_Drafted.cs create mode 100644 Source/CombatExtended/CombatExtended/Render/PawnRenderNode_Apparel.cs diff --git a/Source/CombatExtended/CombatExtended/Render/PawnRenderNodeWorker_Drafted.cs b/Source/CombatExtended/CombatExtended/Render/PawnRenderNodeWorker_Drafted.cs new file mode 100644 index 0000000000..1094110676 --- /dev/null +++ b/Source/CombatExtended/CombatExtended/Render/PawnRenderNodeWorker_Drafted.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Remoting.Messaging; +using System.Text; +using System.Threading.Tasks; +using Verse; + +namespace CombatExtended +{ + public class PawnRenderNodeWorker_Drafted : PawnRenderNodeWorker + { + public override bool CanDrawNow(PawnRenderNode node, PawnDrawParms parms) + { + var pawn = node.tree.pawn; + return (pawn.Drafted || (pawn.CurJob?.def.alwaysShowWeapon ?? false) || (pawn.mindState.duty?.def.alwaysShowWeapon ?? false)) && base.CanDrawNow(node, parms); + } + } +} diff --git a/Source/CombatExtended/CombatExtended/Render/PawnRenderNode_Apparel.cs b/Source/CombatExtended/CombatExtended/Render/PawnRenderNode_Apparel.cs new file mode 100644 index 0000000000..c5ef5fd4f6 --- /dev/null +++ b/Source/CombatExtended/CombatExtended/Render/PawnRenderNode_Apparel.cs @@ -0,0 +1,33 @@ +using RimWorld; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; +using Verse; + +namespace CombatExtended +{ + public class PawnRenderNode_Apparel : Verse.PawnRenderNode_Apparel + { + public PawnRenderNode_Apparel(Pawn pawn, PawnRenderNodeProperties props, PawnRenderTree tree) : base(pawn, props, tree) + { + } + public PawnRenderNode_Apparel(Pawn pawn, PawnRenderNodeProperties props, PawnRenderTree tree, Apparel apparel) : base(pawn, props, tree) + { + } + public PawnRenderNode_Apparel(Pawn pawn, PawnRenderNodeProperties props, PawnRenderTree tree, Apparel apparel, bool useHeadMesh) : base(pawn, props, tree) + { + } + public override IEnumerable GraphicsFor(Pawn pawn) + { + yield return GraphicDatabase.Get((apparel.def.graphicData?.graphicClass ?? typeof(Graphic_Multi)), TexPathFor(pawn), ShaderFor(pawn), apparel.def.graphicData.drawSize, apparel.DrawColor, apparel.DrawColorTwo); + } + public override string ToString() + { + return apparel?.ToString() ?? base.ToString(); + } + } +} From e549b8abdab301a151c4706234758ebcc9dbefbc Mon Sep 17 00:00:00 2001 From: MaxDorob Date: Tue, 11 Jun 2024 23:22:15 +0600 Subject: [PATCH 05/13] Melee shield changes --- Defs/ThingDefs_Misc/Apparel_Shield.xml | 27 +++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Defs/ThingDefs_Misc/Apparel_Shield.xml b/Defs/ThingDefs_Misc/Apparel_Shield.xml index f595ce9c49..49c7616d57 100644 --- a/Defs/ThingDefs_Misc/Apparel_Shield.xml +++ b/Defs/ThingDefs_Misc/Apparel_Shield.xml @@ -64,10 +64,35 @@ 1.0 - Child, Adult + Child, Adult
  • TribalShield
  • + +
  • + CombatExtended.PawnRenderNode_Apparel + CombatExtended.PawnRenderNodeWorker_Drafted + Things/Apparel/Shield/CE_Shield + CutoutComplex + + 0.8 + + 91 + + + -5 + + + -5 + (.15, 0, -.1) + + + (.3, 0, -.2) + + +
  • +
    + false
  • From 4a800597ee9a8b2810554b0593f197a1d857b10f Mon Sep 17 00:00:00 2001 From: MaxDorob Date: Tue, 11 Jun 2024 23:31:28 +0600 Subject: [PATCH 06/13] Removed obsolete commented code --- .../Harmony/Harmony_PawnRenderer.cs | 519 +++--------------- 1 file changed, 66 insertions(+), 453 deletions(-) diff --git a/Source/CombatExtended/Harmony/Harmony_PawnRenderer.cs b/Source/CombatExtended/Harmony/Harmony_PawnRenderer.cs index 71f299635b..3ba9f318b4 100644 --- a/Source/CombatExtended/Harmony/Harmony_PawnRenderer.cs +++ b/Source/CombatExtended/Harmony/Harmony_PawnRenderer.cs @@ -14,496 +14,109 @@ namespace CombatExtended.HarmonyCE { - internal static class Harmony_PawnRenderer + [HarmonyPatch(typeof(PawnRenderUtility), nameof(PawnRenderUtility.DrawEquipmentAiming))] + internal static class Harmony_PawnRenderer_DrawEquipmentAiming { - /* - * - * Please remember to: - * - SYNC these with vanilla PawnRenderer constants - * - CHECK if any names changed. - */ - - private const float YOffsetBehind = 0.0028957527f; + public static Rot4 south = Rot4.South; - private const float YOffsetHead = 0.023166021f; + private static Thing equipment; - private const float YOffsetOnHead = 0.03185328f; + private static Vector3 recoilOffset = new Vector3(); - private const float YOffsetPostHead = 0.03367347f; - - private const float YOffsetIntervalClothes = 0.0028957527f; - - private static Vector3 Vec2ToVec3(Vector2 vector) - { - return new Vector3(vector.x, 0, vector.y); - } + private static float muzzleJump = 0; - /* - * Compatiblity stuff IMPORTANT - * - * These are patched by compatibility patches so we can have custom drawsize, drawoffsets for mods like Alien races - * IF YOU ARE A MODDER PLEASE READ THIS... - * - * In order to make compatiblity with CE easier, we've implemented several empty functions that return a default value. - * These are to be patched by either other mods or by CE it self inorder to make the process of changing simple things in CE a bit simpler. - * - * <==================================== Example of adding support for customHeadDrawSize form HAR in CE ====================================> - */ + private static Vector3 casingDrawPos; - // dubwise apparel tweak loaded check - private static bool quickFast_Loaded = AccessTools.Method("QuickFast.bs:hairScale_Changed") != null; + private static readonly Matrix4x4 TBot5 = Matrix4x4.Translate(new Vector3(0, -0.006f, 0)); - /// - /// Intended to allow an easy point that allow other mods or CE to patch the rendering in runtime - /// - [MethodImpl(MethodImplOptions.NoInlining)] - public static GraphicMeshSet GetHumanlikeHeadSetForPawnHelper(float lifeStageFactor, Pawn pawn) - { - return null; - } + private static readonly Matrix4x4 TBot3 = Matrix4x4.Translate(new Vector3(0, -0.004f, 0)); - /// - /// Intended to allow an easy point that allow other mods or CE to patch the rendering in runtime - /// - [MethodImpl(MethodImplOptions.NoInlining)] - public static Vector2 GetHeadCustomSize(ThingDef def) + public static void Prefix(Thing eq, Vector3 drawLoc) { - return Vector2.one; + equipment = eq; + casingDrawPos = drawLoc; } - /// - /// Intended to allow an easy point that allow other mods or CE to patch the rendering in runtime - /// - [MethodImpl(MethodImplOptions.NoInlining)] - public static Vector2 GetHeadCustomOffset(ThingDef def) + private static void RecoilCE(Thing eq, Vector3 position, float aimAngle, float num, CompEquippable compEquippable) { - return Vector2.zero; + if (Controller.settings.RecoilAnim && compEquippable.PrimaryVerb.verbProps is VerbPropertiesCE) + { + CE_Utility.Recoil(eq.def, compEquippable.PrimaryVerb, out var drawOffset, out var angleOffset, aimAngle, true); + recoilOffset = drawOffset; + muzzleJump = angleOffset; + } } - /* - * - * Check this patch if: - * - Apparel is rendered slightly off from the pawn sprite (update YOffset constants based on PawnRenderer values - * - * - * If all apparel worn on pawns is the drop image of that apparel, - * CHECK Harmony_ApparelGraphicRecordGetter.cs - * INSTEAD! - * - * - Patch Harmony_PawnRenderer_DrawBodyApparel - * - * This patch is used to enable rendering of backpacks and tac vest and similar items. - * - * - Patch Harmony_PawnRenderer_DrawHeadHair - * - * Should render just after vanilla tattoos. Used to render headgrear with the CE apparel extension - * - * - Patch Harmony_PawnRenderer_ShellFullyCoversHead - * - * Should Allow headgear to render since most CE gear has full head coverage. - */ - //TODO: 1.5 - // [HarmonyPatch(typeof(PawnRenderer), nameof(PawnRenderer.DrawBodyApparel))] - // public static class Harmony_PawnRenderer_DrawBodyApparel - // { - // private static MethodBase mDrawMeshNowOrLater = AccessTools.Method(typeof(GenDraw), nameof(GenDraw.DrawMeshNowOrLater), parameters: new[] { typeof(Mesh), typeof(Vector3), typeof(Quaternion), typeof(Material), typeof(bool) }); - // - // private static FieldInfo fShell = AccessTools.Field(typeof(ApparelLayerDefOf), nameof(ApparelLayerDefOf.Shell)); - // - // public static bool IsVisibleLayer(ApparelLayerDef def) - // { - // // If it's invisible skip everything - // if (!def.IsVisibleLayer()) - // { - // return false; - // } - // // Moved to since backpacks use - // if (def == CE_ApparelLayerDefOf.Backpack) - // { - // return false; - // } - // // Enable toggling webbing rendering - // if (def == CE_ApparelLayerDefOf.Webbing && !Controller.settings.ShowTacticalVests) - // { - // return false; - // } - // return true; - // } - // - // public static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) - // { - // List codes = instructions.ToList(); - // Label l1 = generator.DefineLabel(); - // Label l2 = generator.DefineLabel(); - // for (int i = 0; i < codes.Count; i++) - // { - // CodeInstruction code = codes[i]; - // /* - // * Replace ApparelLayerDef::lastLayer != ApparelLayerDefOf::Shell with IsPreShellLayer(ApparelLayerDef::lastLayer) - // * by poping the first part and replacin the second part and changing != to brtrue - // */ - // if (code.opcode == OpCodes.Ldsfld && code.OperandIs(fShell)) - // { - // yield return new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Harmony_PawnRenderer_DrawBodyApparel), nameof(Harmony_PawnRenderer_DrawBodyApparel.IsVisibleLayer), parameters: new[] { typeof(ApparelLayerDef) })); - // i++; - // yield return new CodeInstruction(OpCodes.Brfalse_S, codes[i].operand); - // continue; - // } - // /* - // * Add the offset to loc before calling mDrawMeshNowOrLater - // */ - // if (code.opcode == OpCodes.Call && code.OperandIs(mDrawMeshNowOrLater)) - // { - // yield return new CodeInstruction(OpCodes.Ldloca_S, 5) - // { - // labels = code.labels - // }; - // yield return new CodeInstruction(OpCodes.Dup); - // yield return new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(Vector3), nameof(Vector3.y))); - // yield return new CodeInstruction(OpCodes.Ldarg_0); - // yield return new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Harmony_PawnRenderer_DrawBodyApparel), nameof(GetPostShellOffset))); - // yield return new CodeInstruction(OpCodes.Add); - // yield return new CodeInstruction(OpCodes.Stfld, AccessTools.Field(typeof(Vector3), nameof(Vector3.y))); - // code.labels = new List
  • - false
  • From 3630c6450e2977128fd1364f76345f6a2bd3f567 Mon Sep 17 00:00:00 2001 From: MaxDorob Date: Mon, 17 Jun 2024 01:22:08 +0600 Subject: [PATCH 08/13] Revert "Removed obsolete code" This reverts commit 979272e3c96c8e9b78f1c9f2104f7bf363623975. --- .../CombatExtended/Defs/ShieldDefExtension.cs | 1 + .../CombatExtended/Things/Apparel_Shield.cs | 70 +++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/Source/CombatExtended/CombatExtended/Defs/ShieldDefExtension.cs b/Source/CombatExtended/CombatExtended/Defs/ShieldDefExtension.cs index 65ef6e06e0..0e22f414f8 100644 --- a/Source/CombatExtended/CombatExtended/Defs/ShieldDefExtension.cs +++ b/Source/CombatExtended/CombatExtended/Defs/ShieldDefExtension.cs @@ -12,6 +12,7 @@ public class ShieldDefExtension : DefModExtension { public List shieldCoverage = new List(); public List crouchCoverage = new List(); + public bool drawAsTall = false; public bool PartIsCoveredByShield(BodyPartRecord part, Pawn pawn) { diff --git a/Source/CombatExtended/CombatExtended/Things/Apparel_Shield.cs b/Source/CombatExtended/CombatExtended/Things/Apparel_Shield.cs index 8ad14495d0..97f66dd40e 100644 --- a/Source/CombatExtended/CombatExtended/Things/Apparel_Shield.cs +++ b/Source/CombatExtended/CombatExtended/Things/Apparel_Shield.cs @@ -10,12 +10,82 @@ namespace CombatExtended { public class Apparel_Shield : Apparel { + // From PawnRenderer + private const float YOffsetBehind = 0.00390625f; + private const float YOffsetPostHead = 0.03515625f; + private const float YOffsetPrimaryEquipmentUnder = 0f; + private const float YOffsetPrimaryEquipmentOver = 0.0390625f; + private const float YOffsetIntervalClothes = 0.00390625f; + private const float YOffsetStatus = 0.04296875f; + public const string OneHandedTag = "CE_OneHandedWeapon"; + private bool drawShield => Wearer.Drafted || (Wearer.CurJob?.def.alwaysShowWeapon ?? false) || (Wearer.mindState.duty?.def.alwaysShowWeapon ?? false); // Copied from PawnRenderer.CarryWeaponOpenly(), we show the shield whenever weapons are drawn + private bool IsTall => def.GetModExtension()?.drawAsTall ?? false; + public override bool AllowVerbCast(Verb verb) { ThingWithComps primary = Wearer.equipment?.Primary; return primary == null || (primary.def.weaponTags?.Contains(OneHandedTag) ?? false); } + + public override void DrawWornExtras() + { + if (Wearer == null || !Wearer.Spawned) + { + return; + } + if (!drawShield) + { + return; + } + + float num = 0f; + Vector3 vector = this.Wearer.Drawer.DrawPos; + vector.y = Wearer.Rotation == Rot4.West || Wearer.Rotation == Rot4.South ? AltitudeLayer.PawnUnused.AltitudeFor() : AltitudeLayer.Pawn.AltitudeFor(); + + Vector3 s = new Vector3(1f, 1f, 1f); + if (this.Wearer.Rotation == Rot4.North) + { + vector.x -= 0.1f; + vector.z -= IsTall ? -0.1f : 0.2f; + } + else + { + if (this.Wearer.Rotation == Rot4.South) + { + vector.x += 0.1f; + vector.z -= IsTall ? -0.05f : 0.2f; + } + else + { + if (this.Wearer.Rotation == Rot4.East) + { + if (IsTall) + { + vector.x += 0.1f; + } + vector.z -= IsTall ? -0.05f : 0.2f; + num = 22.5f; + } + else + { + if (this.Wearer.Rotation == Rot4.West) + { + if (IsTall) + { + vector.x -= 0.1f; + } + vector.z -= IsTall ? -0.05f : 0.2f; + num = 337.5f; + } + } + } + } + Material mat = Graphic.GetColoredVersion(ShaderDatabase.CutoutComplex, DrawColor, DrawColorTwo).MatSingle; + Matrix4x4 matrix = default(Matrix4x4); + matrix.SetTRS(vector, Quaternion.AngleAxis(num, Vector3.up), s); + Graphics.DrawMesh(MeshPool.plane10, matrix, mat, 0); + } } } From 3fef723450c1ca7203ee1432538f4e9cb6917fda Mon Sep 17 00:00:00 2001 From: MaxDorob Date: Mon, 17 Jun 2024 02:04:42 +0600 Subject: [PATCH 09/13] Warning about obsolete render --- .../CombatExtended/Things/Apparel_Shield.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Source/CombatExtended/CombatExtended/Things/Apparel_Shield.cs b/Source/CombatExtended/CombatExtended/Things/Apparel_Shield.cs index 97f66dd40e..2aede24fc1 100644 --- a/Source/CombatExtended/CombatExtended/Things/Apparel_Shield.cs +++ b/Source/CombatExtended/CombatExtended/Things/Apparel_Shield.cs @@ -19,9 +19,17 @@ public class Apparel_Shield : Apparel private const float YOffsetStatus = 0.04296875f; public const string OneHandedTag = "CE_OneHandedWeapon"; - private bool drawShield => Wearer.Drafted || (Wearer.CurJob?.def.alwaysShowWeapon ?? false) || (Wearer.mindState.duty?.def.alwaysShowWeapon ?? false); // Copied from PawnRenderer.CarryWeaponOpenly(), we show the shield whenever weapons are drawn + private bool drawShield => this.def.apparel.renderNodeProperties.NullOrEmpty() && (Wearer.Drafted || (Wearer.CurJob?.def.alwaysShowWeapon ?? false) || (Wearer.mindState.duty?.def.alwaysShowWeapon ?? false)); // Copied from PawnRenderer.CarryWeaponOpenly(), we show the shield whenever weapons are drawn private bool IsTall => def.GetModExtension()?.drawAsTall ?? false; + public override void PostMake() + { + base.PostMake(); + if (this.def.apparel.renderNodeProperties.NullOrEmpty()) + { + Log.WarningOnce($"{def.defName} using obsolete render system", def.defName.GetHashCodeSafe()); + } + } public override bool AllowVerbCast(Verb verb) { From fe4c47c4bcb2540efb14e6b8096f0de3106f460b Mon Sep 17 00:00:00 2001 From: MaxDorob Date: Tue, 18 Jun 2024 19:34:38 +0600 Subject: [PATCH 10/13] Parent of renderNode --- Defs/ThingDefs_Misc/Apparel_Shield.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/Defs/ThingDefs_Misc/Apparel_Shield.xml b/Defs/ThingDefs_Misc/Apparel_Shield.xml index e5cde73e9c..c1e4c6bbb6 100644 --- a/Defs/ThingDefs_Misc/Apparel_Shield.xml +++ b/Defs/ThingDefs_Misc/Apparel_Shield.xml @@ -74,6 +74,7 @@ CombatExtended.PawnRenderNodeWorker_Drafted Things/Apparel/Shield/CE_Shield CutoutComplex + ApparelBody 0.8 From ca098d5cd4d9aa99ce4064380d60c581702d8d81 Mon Sep 17 00:00:00 2001 From: MaxDorob Date: Tue, 18 Jun 2024 20:43:50 +0600 Subject: [PATCH 11/13] NRE fix --- .../CombatExtended/Render/PawnRenderNodeWorker_Drafted.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/CombatExtended/CombatExtended/Render/PawnRenderNodeWorker_Drafted.cs b/Source/CombatExtended/CombatExtended/Render/PawnRenderNodeWorker_Drafted.cs index 1094110676..d964a924c4 100644 --- a/Source/CombatExtended/CombatExtended/Render/PawnRenderNodeWorker_Drafted.cs +++ b/Source/CombatExtended/CombatExtended/Render/PawnRenderNodeWorker_Drafted.cs @@ -13,7 +13,7 @@ public class PawnRenderNodeWorker_Drafted : PawnRenderNodeWorker public override bool CanDrawNow(PawnRenderNode node, PawnDrawParms parms) { var pawn = node.tree.pawn; - return (pawn.Drafted || (pawn.CurJob?.def.alwaysShowWeapon ?? false) || (pawn.mindState.duty?.def.alwaysShowWeapon ?? false)) && base.CanDrawNow(node, parms); + return pawn != null && pawn.Spawned && (pawn.Drafted || (pawn.CurJob?.def.alwaysShowWeapon ?? false) || (pawn.mindState?.duty?.def.alwaysShowWeapon ?? false)) && base.CanDrawNow(node, parms); } } } From df5c4c290cd6d3c323aa0cc8366236c3a1f36320 Mon Sep 17 00:00:00 2001 From: n7huntsman Date: Fri, 21 Jun 2024 22:17:00 -0400 Subject: [PATCH 12/13] Housekeeping, adjust shield east offset --- Defs/ThingDefs_Misc/Apparel_Shield.xml | 53 +++++++++++++------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/Defs/ThingDefs_Misc/Apparel_Shield.xml b/Defs/ThingDefs_Misc/Apparel_Shield.xml index c1e4c6bbb6..b5a5318238 100644 --- a/Defs/ThingDefs_Misc/Apparel_Shield.xml +++ b/Defs/ThingDefs_Misc/Apparel_Shield.xml @@ -64,35 +64,36 @@ 1.0 - Child, Adult + Child, Adult
  • TribalShield
  • - -
  • - CombatExtended.PawnRenderNode_Apparel - CombatExtended.PawnRenderNodeWorker_Drafted - Things/Apparel/Shield/CE_Shield - CutoutComplex - ApparelBody - - 0.8 - - 91 - - - -5 - - - -5 - (.15, 0, -.1) - - - (.3, 0, -.2) - - -
  • -
    + +
  • + CombatExtended.PawnRenderNode_Apparel + CombatExtended.PawnRenderNodeWorker_Drafted + Things/Apparel/Shield/CE_Shield + CutoutComplex + ApparelBody + + 0.8 + + 91 + + + -5 + (0, 0, -0.1) + + + -5 + (0.15, 0, -0.1) + + + (0.3, 0, -0.2) + + +
  • +
  • From d0bec37de05472396bf4945e078d1d9e235dc95a Mon Sep 17 00:00:00 2001 From: n7huntsman Date: Fri, 21 Jun 2024 22:52:46 -0400 Subject: [PATCH 13/13] Update ballistic shield rendering --- Defs/ThingDefs_Misc/Apparel_Shield.xml | 27 +++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Defs/ThingDefs_Misc/Apparel_Shield.xml b/Defs/ThingDefs_Misc/Apparel_Shield.xml index b5a5318238..1af192a7f0 100644 --- a/Defs/ThingDefs_Misc/Apparel_Shield.xml +++ b/Defs/ThingDefs_Misc/Apparel_Shield.xml @@ -156,6 +156,32 @@
  • OutlanderShield
  • + +
  • + CombatExtended.PawnRenderNode_Apparel + CombatExtended.PawnRenderNodeWorker_Drafted + Things/Apparel/BallisticShield/CE_BallisticShield + CutoutComplex + ApparelBody + + 0.8 + + 91 + + + -5 + (0, 0, -0.1) + + + -5 + (0.15, 0, -0.1) + + + (0.15, 0, -0.1) + + +
  • +
  • @@ -170,7 +196,6 @@
  • Legs
  • - true