//#define QUARANTINED_FEATURES //#define HOOK_ORDER_ASSERTS //#define ALT_TEXTURE_LOAD using System.Numerics; using System.Text.Json; using ImGuiNET; using SharpPluginLoader.Core; using SharpPluginLoader.Core.MtTypes; using SharpPluginLoader.Core.Entities; using SharpPluginLoader.Core.Memory; using SharpPluginLoader.Core.Rendering; using SharpPluginLoader.Core.Resources; #if ALT_TEXTURE_LOAD using SharpPluginLoader.Core.IO; #endif using WorldTuningTool; namespace PlayerPoser { using static Utility; using static WorldTuningTool.PFuncs; internal static unsafe class Armor { private const string posePath = "nativePC/plugins/CSharp/Poses"; private class BaseMaterial { public int Index = -1; public nint Address = 0x0; public List Parameters = new(); public virtual string Name => "Material"; public virtual int Order => -1; public BaseMaterial() { } public void Update(nint paramsAddr) { Address = paramsAddr; foreach (Parameter param in Parameters) { param.Update(paramsAddr); } } public void Draw(float width) { if (Address != 0x0) { ImGui.PushID(this.GetHashCode()); if (ImGui.CollapsingHeader(Name)) { ImGui.Text($"Address: 0x{Address:X} (index: {Index})"); foreach (Parameter param in Parameters) { int overrideSet = param.Draw(width); // Depends on parameters being set exclusively from the UI. activeMaterialOverrides += overrideSet; } } ImGui.PopID(); } } } private class MhMaterialCommon : BaseMaterial { public override string Name => "MhMaterialCommon"; public override int Order => 0; public MhMaterialCommon() : base() { Parameters.AddRange(new Parameter[]{ P("Bypass", 0x0, ParameterType.BOOL), P("Decal Mask", 0x4, ParameterType.BOOL), P("Emissive", 0x8, ParameterType.BOOL), P("GBuffer ID", 0xC, ParameterType.BYTE, pStep((byte)1)), P("Outline ID", 0x10, ParameterType.BYTE, pStep((byte)1)), }); } } private class BasePLMaterial : BaseMaterial { public override string Name => "PLMaterial"; public override int Order => 1; public BasePLMaterial() : base() { Parameters.AddRange(new Parameter[]{ P("Base Map Factor", 0x0, ParameterType.COLOR_FACTOR, pStep(0.001f)), P("Emissive Factor", 0x10, ParameterType.VECTOR3), P("Metalic", 0x1C, ParameterType.FLOAT, pStep(0.001f)), P("Roughness", 0x20, ParameterType.FLOAT, pStep(0.001f)), P("Specular", 0x24, ParameterType.FLOAT, pStep(0.001f)), P("Sub Surface Blend", 0x28, ParameterType.FLOAT, pStep(0.001f)), P("Sub Surface Profile", 0x2C, ParameterType.INT, pStep(1)), P("Translucency", 0x30, ParameterType.FLOAT, pStep(0.001f)), P("Base Color Emissive", 0x34, ParameterType.BOOL), P("Back Face Normal Flip", 0x38, ParameterType.BOOL), P("Anim Emit Min", 0x3C, ParameterType.FLOAT), P("Anim Emit Speed", 0x40, ParameterType.FLOAT), }); } } private class MhMaterialPLLocal : BasePLMaterial { public override string Name => "MhMaterialPLLocal"; public override int Order => 2; public MhMaterialPLLocal() : base() { Parameters.AddRange(new Parameter[]{ P("Use CMM", 0x44, ParameterType.BOOL), P("Add Color A", 0x50, ParameterType.COLOR_FACTOR, pStep(0.001f)), P("Add Color B", 0x60, ParameterType.COLOR_FACTOR, pStep(0.001f)), P("Add Color C", 0x70, ParameterType.COLOR_FACTOR, pStep(0.001f)), P("Add Color D", 0x80, ParameterType.COLOR_FACTOR, pStep(0.001f)), P("Fur Param", 0x90, ParameterType.VECTOR4), P("Fur Tile", 0xA0, ParameterType.FLOAT), P("Snow Control", 0xB0, ParameterType.VECTOR4), P("Material Snow Blend A", 0xC0, ParameterType.FLOAT), P("Material Snow Blend B", 0xC4, ParameterType.FLOAT), P("Snow Tile", 0xC8, ParameterType.FLOAT), P("Snow Color", 0xD0, ParameterType.COLOR_FACTOR, pStep(0.001f)), P("Snow Mat Control", 0xE0, ParameterType.VECTOR4), P("Snow UV Offset", 0xF0, ParameterType.VECTOR2), P("Anim Emit Wave", 0xF8, ParameterType.FLOAT), P("Use Emit Wave", 0xFC, ParameterType.BOOL), P("Film Thickness", 0x100, ParameterType.FLOAT), P("Film Blend", 0x104, ParameterType.FLOAT), P("Film IOR", 0x108, ParameterType.FLOAT), P("Refract Blend", 0x10C, ParameterType.FLOAT), P("Refraction", 0x110, ParameterType.FLOAT), P("Panorama Tile", 0x114, ParameterType.FLOAT), P("Emissive Blend Color", 0x120, ParameterType.VECTOR3, pStep(0.001f)), P("Emissive Blend Color Blend", 0x12C, ParameterType.FLOAT), P("Emissive Blend Rim Param", 0x130, ParameterType.VECTOR3), P("Detail Normal Blend", 0x13C, ParameterType.FLOAT), P("UV Transform Detail Normal", 0x140, ParameterType.VECTOR4) }); } } private class MhMaterialPLSkinLocal : BasePLMaterial { public override string Name => "MhMaterialPLSkinLocal"; public override int Order => 3; public MhMaterialPLSkinLocal() : base() { Parameters.AddRange(new Parameter[]{ P("Add Color UV", 0x44, ParameterType.VECTOR2, pStep(0.001f)), P("Use CMM", 0x4C, ParameterType.BOOL), P("Add Color A", 0x50, ParameterType.COLOR_FACTOR, pStep(0.001f)), P("Add Color B", 0x60, ParameterType.COLOR_FACTOR, pStep(0.001f)), P("Detail Normal Blend", 0x70, ParameterType.FLOAT), P("UV Transform Detail Normal", 0x80, ParameterType.VECTOR4) }); } } private class MhMaterialPLHairLocal : BasePLMaterial { public override string Name => "MhMaterialPLHairLocal"; public override int Order => 4; public MhMaterialPLHairLocal() : base() { Parameters.AddRange(new Parameter[]{ P("Primary Color", 0x50, ParameterType.COLOR_FACTOR, pStep(0.001f)), P("Secondary Color", 0x60, ParameterType.COLOR_FACTOR, pStep(0.001f)), P("Primary Expo", 0x70, ParameterType.FLOAT), P("Secondary Expo", 0x74, ParameterType.FLOAT), P("Primary Shift", 0x78, ParameterType.FLOAT), P("Secondary Shift", 0x7C, ParameterType.FLOAT), P("Shininess", 0x80, ParameterType.FLOAT), P("Fake Light Direction", 0x84, ParameterType.VECTOR3), P("Fur Height", 0x90, ParameterType.FLOAT), P("Fur Param", 0x94, ParameterType.VECTOR4), P("Fur Tile", 0xA4, ParameterType.FLOAT), P("Vertex AO", 0xA8, ParameterType.VECTOR4), P("V Color Normal Blend", 0xB8, ParameterType.FLOAT), P("Rim Width", 0xBC, ParameterType.FLOAT), P("Rim Normal Blend", 0xC0, ParameterType.FLOAT), P("Use Rim Translucency", 0xC4, ParameterType.BOOL), P("Use Offset", 0xC8, ParameterType.BOOL), P("Inner Offset Scale", 0xCC, ParameterType.FLOAT), P("Detail Normal Blend", 0xD0, ParameterType.FLOAT), P("UV Transform Detail Normal", 0xD4, ParameterType.VECTOR4) }); } } private class MhMaterialPLEditFaceLocal : BasePLMaterial { public override string Name => "MhMaterialPLEditFaceLocal"; public override int Order => 5; public MhMaterialPLEditFaceLocal() : base() { Parameters.AddRange(new Parameter[]{ P("Add Color UV", 0x44, ParameterType.VECTOR2, pStep(0.001f)), P("Add Normal Mask A", 0x50, ParameterType.VECTOR4), P("Add Normal Mask B", 0x60, ParameterType.VECTOR4), P("Add Normal Mask C", 0x70, ParameterType.VECTOR4), P("Add Normal Mask D", 0x80, ParameterType.VECTOR4), P("Paint Map RC", 0x90, ParameterType.VECTOR2), P("Paint Map Num", 0x98, ParameterType.FLOAT), P("Paint Map Offset", 0xA0, ParameterType.VECTOR4), P("Paint Color", 0xB0, ParameterType.COLOR_FACTOR, pStep(0.001f)), P("Paint Roughness", 0xC0, ParameterType.FLOAT), P("Paint Metal", 0xC4, ParameterType.FLOAT), P("Paint Map Num B", 0xC8, ParameterType.FLOAT), P("Paint Map Offset B", 0xD0, ParameterType.VECTOR4), P("Paint Color B", 0xE0, ParameterType.COLOR_FACTOR, pStep(0.001f)), P("Paint Roughness B", 0xF0, ParameterType.FLOAT), P("Paint Metal B", 0xF4, ParameterType.FLOAT), P("Paint Map Num C", 0xF8, ParameterType.FLOAT), P("Paint Map Offset C", 0x100, ParameterType.VECTOR4), P("Paint Color C", 0x110, ParameterType.COLOR_FACTOR, pStep(0.001f)), P("Paint Roughness C", 0x120, ParameterType.FLOAT), P("Paint Metal C", 0x124, ParameterType.FLOAT), P("Face Normal Blend", 0x128, ParameterType.VECTOR2), P("Mayu Map Num", 0x130, ParameterType.FLOAT), P("Mayu Map Offset", 0x134, ParameterType.VECTOR2), P("Mayu Map RC", 0x140, ParameterType.VECTOR2), P("Mayu Color", 0x150, ParameterType.COLOR_FACTOR, pStep(0.001f)), P("Paint Emit", 0x160, ParameterType.BOOL), P("Paint Emit B", 0x164, ParameterType.BOOL), P("Paint Emit C", 0x168, ParameterType.BOOL), P("Paint Emit Intensity", 0x170, ParameterType.VECTOR3), P("Paint Emit Intensity Multiply", 0x17C, ParameterType.FLOAT), P("Paint Normal", 0x180, ParameterType.BOOL), P("Paint Shade", 0x184, ParameterType.BOOL), P("Paint Normal B", 0x188, ParameterType.BOOL), P("Paint Shade B", 0x18C, ParameterType.BOOL), P("Paint Normal C", 0x190, ParameterType.BOOL), P("Paint Shade C", 0x194, ParameterType.BOOL), P("Fake Light Blend", 0x198, ParameterType.FLOAT), P("Fake Light Intensity", 0x19C, ParameterType.FLOAT), P("Fake Face Light Direction", 0x1A0, ParameterType.VECTOR3), P("Fake Shadow Intensity", 0x1AC, ParameterType.FLOAT), P("Fake Shadow Length", 0x1B0, ParameterType.FLOAT), P("Detail Normal Blend", 0x1B4, ParameterType.FLOAT), P("UV Transform Detail Normal", 0x1C0, ParameterType.VECTOR4) }); } } private static class Part { internal const byte Helmet = 0; internal const byte Body = 1; internal const byte Arms = 2; internal const byte Waist = 3; internal const byte Legs = 4; internal const byte Slinger = 5; internal const byte Hair = 6; internal const byte Face = 7; internal const byte EyeLens = 8; } private static class Joint { public const byte Root = 0x0; public const byte Root2 = 0xD; public const byte LowerBack = 0x1; public const byte UpperBack = 0x2; public const byte LowerNeck = 0x3; public const byte LowerNeckNull = 0xFE; public const byte UpperNeck = 0x4; public const byte LeftCollarbone = 0x5; public const byte LeftShoulderNull = 0x46; public const byte LeftShoulder = 0x6; public const byte LeftElbow = 0x7; public const byte LeftWrist = 0x8; public const byte LeftWristNull = 0x1E; public const byte LeftThumbLow = 0x1F; public const byte LeftThumbMid = 0x20; public const byte LeftThumbHigh = 0x21; public const byte LeftIndexLow = 0x22; public const byte LeftIndexMid = 0x23; public const byte LeftIndexHigh = 0x24; public const byte LeftMiddleLow = 0x25; public const byte LeftMiddleMid = 0x26; public const byte LeftMiddleHigh = 0x27; public const byte LeftPalm = 0x28; public const byte LeftRingLow = 0x29; public const byte LeftRingMid = 0x2A; public const byte LeftRingHigh = 0x2B; public const byte LeftPinkyLow = 0x2C; public const byte LeftPinkyMid = 0x2D; public const byte LeftPinkyHigh = 0x2E; public const byte LeftArmUnk1 = 0x51; public const byte LeftArmUnk2 = 0x65; public const byte LeftArmUnk3 = 0x66; public const byte LeftArmUnk4 = 0x67; public const byte LeftArmUnk5 = 0x68; public const byte LeftArmUnk6 = 0x47; public const byte LeftArmUnk7 = 0x50; public const byte RightCollarbone = 0x9; public const byte RightShoulder = 0xA; public const byte RightElbow = 0xB; public const byte RightWrist = 0xC; public const byte RightWristNull = 0x2F; public const byte RightThumbLow = 0x30; public const byte RightThumbMid = 0x31; public const byte RightThumbHigh = 0x32; public const byte RightIndexLow = 0x33; public const byte RightIndexMid = 0x34; public const byte RightIndexHigh = 0x35; public const byte RightMiddleLow = 0x36; public const byte RightMiddleMid = 0x37; public const byte RightMiddleHigh = 0x38; public const byte RightPalm = 0x39; public const byte RightRingLow = 0x3A; public const byte RightRingMid = 0x3B; public const byte RightRingHigh = 0x3C; public const byte RightPinkyLow = 0x3D; public const byte RightPinkyMid = 0x3E; public const byte RightPinkyHigh = 0x3F; public const byte RightArmUnk1 = 0x53; public const byte RightArmUnk2 = 0x49; public const byte RightArmUnk3 = 0x52; public const byte RightArmUnk4 = 0x48; public const byte Unknown1 = 0xF7; public const byte Unknown2 = 0xF8; public const byte LeftHip = 0xE; public const byte LeftKnee = 0xF; public const byte LeftAnkle = 0x10; public const byte LeftToes = 0x11; public const byte LeftAnkleNull = 0x54; public const byte LeftKneeNull = 0x4B; public const byte LeftHipNull = 0x4A; public const byte Unknown3 = 0x40; public const byte Unknown4 = 0x42; public const byte RightHip = 0x12; public const byte RightKnee = 0x13; public const byte RightAnkle = 0x14; public const byte RightToes = 0x15; public const byte RightAnkleNull = 0x55; public const byte RightKneeNull = 0x4D; public const byte RightHipNull = 0x4C; public const byte Unknown5 = 0x43; public const byte Unknown6 = 0x45; public const byte Unknown7 = 0xF9; public const byte Unknown8 = 0xFA; public const byte Unknown9 = 0xFB; public const byte Unknown10 = 0xFC; public const byte Unknown11 = 0xFD; } private static class FaceJoint { public const byte LeftCheek1 = 0x6C; public const byte LeftCheek2 = 0x99; public const byte RightCheek1 = 0x71; public const byte RightCheek2 = 0x9E; public const byte RightCheek3 = 0x70; public const byte LeftCheek3 = 0x6B; public const byte RightCheek4 = 0x6F; public const byte LeftCheek4 = 0x6A; public const byte RightCheek5 = 0x72; public const byte LeftCheek5 = 0x6D; public const byte LeftCheek = 0x6E; public const byte RightCheek = 0x73; public const byte LeftEye = 0x3A; public const byte LeftEye1 = 0x3B; public const byte LeftEye2 = 0x43; public const byte LeftEye3 = 0x42; public const byte LeftEye4 = 0x41; public const byte LeftEye5 = 0x40; public const byte LeftEye6 = 0x3F; public const byte LeftEye7 = 0x46; public const byte LeftEye8 = 0x45; public const byte LeftEye9 = 0x44; public const byte LeftEye10 = 0x3C; public const byte LeftEye11 = 0x3E; public const byte LeftEye12 = 0x3D; public const byte LeftEye13 = 0x68; public const byte RightEye = 0x47; public const byte RightEye1 = 0x48; public const byte RightEye2 = 0x50; public const byte RightEye3 = 0x4F; public const byte RightEye4 = 0x4E; public const byte RightEye5 = 0x4D; public const byte RightEye6 = 0x4C; public const byte RightEye7 = 0x51; public const byte RightEye8 = 0x52; public const byte RightEye9 = 0x53; public const byte RightEye10 = 0x4A; public const byte RightEye11 = 0x4B; public const byte RightEye12 = 0x49; public const byte RightEye13 = 0x69; public const byte Nose = 0x54; public const byte Nose1 = 0x55; public const byte Nose2 = 0x56; public const byte Nose3 = 0x58; public const byte Nose4 = 0x64; public const byte Nose5 = 0x5E; public const byte Nose6 = 0x5F; public const byte Nose7 = 0x65; public const byte Nose8 = 0x5C; public const byte Nose9 = 0x62; public const byte Nose10 = 0x5D; public const byte Nose11 = 0x63; public const byte Nose12 = 0x5B; public const byte Nose13 = 0x61; public const byte Nose14 = 0x5A; public const byte Nose15 = 0x60; public const byte Nose16 = 0x57; public const byte Nose17 = 0x59; public const byte Nose18 = 0x66; public const byte Nose19 = 0x67; public const byte Mouth = 0x75; public const byte Mouth1 = 0x80; public const byte Mouth2 = 0x81; public const byte Mouth3 = 0x86; public const byte Mouth4 = 0x85; public const byte Mouth5 = 0x84; public const byte Mouth6 = 0x83; public const byte Mouth7 = 0x82; public const byte Mouth8 = 0x8B; public const byte Mouth9 = 0x8A; public const byte Mouth10 = 0x89; public const byte Mouth11 = 0x88; public const byte Mouth12 = 0x87; public const byte Mouth13 = 0x8F; public const byte Mouth14 = 0x8E; public const byte Mouth15 = 0x90; public const byte Mouth16 = 0x8D; public const byte Mouth17 = 0x91; public const byte Mouth18 = 0x8C; public const byte Mouth19 = 0x92; public const byte Mouth20 = 0x76; public const byte Mouth21 = 0x77; public const byte Mouth22 = 0x78; public const byte Mouth23 = 0x79; public const byte Mouth24 = 0x7A; public const byte Mouth25 = 0x7F; public const byte Mouth26 = 0x7E; public const byte Mouth27 = 0x7D; public const byte Mouth28 = 0x7C; public const byte Mouth29 = 0x7B; public const byte Mouth30 = 0x74; public const byte ChinMiddle = 0x94; public const byte ChinRight = 0x9C; public const byte ChinLeft = 0x9B; public const byte ChinRightBack = 0x9D; public const byte ChinLeftBack = 0x9A; public const byte NeckMiddle = 0xA0; public const byte Jaw = 0x97; public const byte Jaw1 = 0xEA; public const byte Jaw2 = 0xEB; public const byte JawLeft = 0x98; public const byte JawRight = 0x96; public const byte JawUpLeft = 0x93; public const byte JawUpRight = 0x95; public const byte NeckLeft = 0x9F; public const byte NeckRight = 0xA1; public const byte EyeAgainLeft = 0xF4; public const byte EyeAgainLeft1 = 0xF5; public const byte NoseAgain = 0xF6; public const byte MouthAgain = 0xF7; public const byte Forehead0 = 0xF8; public const byte Forehead = 0xA2; public const byte Forehead1 = 0x36; public const byte Forehead2 = 0x37; public const byte Forehead3 = 0x38; public const byte Forehead4 = 0x35; public const byte Forehead5 = 0x34; public const byte Forehead6 = 0x33; public const byte Forehead7 = 0x32; public const byte Forehead8 = 0x2E; public const byte Forehead9 = 0x2D; public const byte Forehead10 = 0x2F; public const byte Forehead11 = 0x2C; public const byte Forehead12 = 0x30; public const byte Forehead13 = 0x31; public const byte Forehead14 = 0x39; public const byte Base1 = 0xFB; public const byte Base2 = 0xFC; public const byte Base3 = 0xFD; } private static nint[] playerArmor = new nint[9]; private static nint lastBodyArmor = 0x0; private static List playerWeapon = new(); private static nint[] bodyJointMap = new nint[0xFF]; private static nint[] faceJointMap = new nint[0xFF]; private static bool retryArmorRefresh = false; private static bool retryWeaponRefresh = false; private delegate void UpdatePlayerArmor(nint cpPlCombineArmorCtrl, int index, int armorId); private static Hook? updatePlayerArmor; private delegate void ChangeWeapon(nint playerAddr, WeaponType weaponType, int weaponId); private static Hook? changeWeaponHook; private delegate void UpdateModel(nint model); private static Hook? updateModelHook; private static Hook? updateJointRotationHook; private static Hook? updateHairJoints; private static List bodyJoints = new(); private static Dictionary bodyRotations = new(); private static Dictionary bodyPositions = new(); private static Dictionary bodyOffsets = new(); private static List faceJoints = new(); private static Dictionary faceRotations = new(); private static Dictionary facePositions = new(); private static Dictionary faceOffsets = new(); private static List hairJoints = new(); private static Dictionary hairRotations = new(); private static Dictionary hairOffsets = new(); private static Dictionary> jiggleBones = new(); private static bool ikForcedOff = false; private static Patch forceDisableIK; #if QUARANTINED_FEATURES private delegate void UpdateIKPosition(nint ikObject, nint joint, nint obj); private static Hook? updateIKPositionHook; private static List ikJoints = new(); private static Dictionary> ikOffsets = new(); #endif private static NativeFunction getMaterialParams1; private static NativeFunction getMaterialParams2; private static int activeMaterialOverrides = 0; private static List helmetMaterials = new(); private static List bodyMaterials = new(); private static List armsMaterials = new(); private static List waistMaterials = new(); private static List legsMaterials = new(); private static List slingerMaterials = new(); private static List faceMaterials = new(); private static List hairMaterials = new(); private static List> allMaterialLists = new() { helmetMaterials, bodyMaterials, armsMaterials, waistMaterials, legsMaterials, slingerMaterials, faceMaterials, hairMaterials }; private static bool skinToneSet = false; private static Vector2 currentSkinTone = new(); private static Texture? skinAddTexture = null; private static TextureHandle skinAddTextureHandle = TextureHandle.Invalid; private static bool ignoreFullArmorFace = false; private static Patch jmpOverExtFace; private static Patch jmpOverExtHair; private static bool ignoreHideSlinger = false; private static Patch jmpOverHideSlinger; internal static void Initialize() { updatePlayerArmor = Hook.Create(0x1412F0D40, UpdatePlayerArmorHook); changeWeaponHook = Hook.Create(0x141F5A410, ChangeWeaponHook); forceDisableIK = new Patch(0x14031FD40, [0xC6, 0x81, 0x81, 0x01, 0x00, 0x00, 0x00, 0xC3]); updateModelHook = Hook.Create(0x141FBCCD0, UpdateModelHook); updateJointRotationHook = Hook.Create(0x14223BA30, UpdateJointRotationHook); updateHairJoints = Hook.Create(0x1420499A0, UpdateHairJointsHook); #if QUARANTINED_FEATURES updateIKPositionHook = Hook.Create(0x142472C00, UpdateIKPositionHook); #endif getMaterialParams1 = new NativeFunction(0x14222F910); getMaterialParams2 = new NativeFunction(0x14235E400); jmpOverExtFace = new Patch(0x141258654, [0xEB]); jmpOverExtHair = new Patch(0x1412586C2, [0xEB]); jmpOverHideSlinger = new Patch(0x1412EE1D7, [0xEB]); } #if HOOK_ORDER_ASSERTS private static int hookOrder = 1; #endif internal static void OnUpdate() { #if HOOK_ORDER_ASSERTS hookOrder = 0; #endif Player? player = getPlayer(); if (player != null) { if (retryArmorRefresh) { refreshArmorState(player); } if (retryWeaponRefresh) { refreshWeaponState(player); } } } internal static void OnPlayerChange() { Player? player = getPlayer(); if (player != null) { retryArmorRefresh = true; refreshArmorState(player); retryWeaponRefresh = true; refreshWeaponState(player); } } private static void UpdatePlayerArmorHook(nint cpPlCombineArmorCtrl, int index, int armorId) { updatePlayerArmor!.Original(cpPlCombineArmorCtrl, index, armorId); Player? player = null; if (index == Part.Legs && (player = getPlayer()) != null) { retryArmorRefresh = true; refreshArmorState(player); } } private static void ChangeWeaponHook(nint playerAddr, WeaponType weaponType, int weaponId) { changeWeaponHook!.Original(playerAddr, weaponType, weaponId); Player? player = getPlayer(); if (player != null && player.Instance == playerAddr) { retryWeaponRefresh = true; refreshWeaponState(player); } } private static void dropArmorState() { Array.Clear(playerArmor, 0, playerArmor.Length); Array.Clear(bodyJointMap, 0, bodyJointMap.Length); Array.Clear(faceJointMap, 0, faceJointMap.Length); bodyJoints.Clear(); faceJoints.Clear(); hairJoints.Clear(); jiggleBones.Clear(); #if QUARANTINED_FEATURES ikJoints.Clear(); #endif } private static void dropWeaponState() { playerWeapon.Clear(); } private static void dropJointOffsets() { bodyRotations.Clear(); bodyPositions.Clear(); bodyOffsets.Clear(); faceRotations.Clear(); facePositions.Clear(); faceOffsets.Clear(); hairRotations.Clear(); hairOffsets.Clear(); #if QUARANTINED_FEATURES ikOffsets.Clear(); #endif } private static void resetMaterials() { foreach (List partMaterials in allMaterialLists) { foreach (BaseMaterial material in partMaterials) { material.Update(0x0); } } } private static void probeMaterial(nint partAddr, nint paramsAddr, int index, uint code, List partMaterials) where T : BaseMaterial, new() { nint paramsAddr2 = getMaterialParams2.Invoke(paramsAddr, code); if (paramsAddr2 != 0x0) { foreach (BaseMaterial material in partMaterials) { if (material is T && material.Index == index) { material.Update(paramsAddr2); return; } } T newMaterial = new(); partMaterials.Add(newMaterial); newMaterial.Index = index; newMaterial.Update(paramsAddr2); } } private static void probePartForMaterials(nint partAddr, List partMaterials) { if (partAddr == 0x0) { return; } nint paramsAddr; for (int i = 0; ;i++) { paramsAddr = getMaterialParams1.Invoke(partAddr, i); if (paramsAddr == 0x0) break; // Makeup: [2E0]DCDC0 [BFC8B]000 probeMaterial(partAddr, paramsAddr, i, 0xB2732092, partMaterials); probeMaterial(partAddr, paramsAddr, i, 0x120B83B2, partMaterials); probeMaterial(partAddr, paramsAddr, i, 0xBFC8B2E0, partMaterials); probeMaterial(partAddr, paramsAddr, i, 0xCE0DE378, partMaterials); probeMaterial(partAddr, paramsAddr, i, 0xCA04A371, partMaterials); } partMaterials.Sort(delegate(BaseMaterial x, BaseMaterial y) { if (y.Order == x.Order) { if (y.Address != 0x0 && x.Address == 0x0) return 1; else if (x.Address != 0x0 && y.Address == 0x0) return -1; return 0; } return y.Order - x.Order; }); } private static void probeAllPartsForMaterials() { resetMaterials(); probePartForMaterials(playerArmor[Part.Helmet], helmetMaterials); probePartForMaterials(playerArmor[Part.Body], bodyMaterials); probePartForMaterials(playerArmor[Part.Arms], armsMaterials); probePartForMaterials(playerArmor[Part.Waist], waistMaterials); probePartForMaterials(playerArmor[Part.Legs], legsMaterials); probePartForMaterials(playerArmor[Part.Slinger], slingerMaterials); probePartForMaterials(playerArmor[Part.Face], faceMaterials); probePartForMaterials(playerArmor[Part.Hair], hairMaterials); if (skinToneSet) { setSkinToneOverride(); } } private static void refreshArmorState(Player player) { dropArmorState(); if (collectArmorAndJoints(player)) { probeAllPartsForMaterials(); } else { dropJointOffsets(); } } private static void refreshWeaponState(Player player) { dropWeaponState(); collectWeaponParts(player); } private static void collectArmorParts(nint modelAddr, nint resourceAddr) { int part; string fullString = new(GetPtrInline(resourceAddr, 0xC)); string partName = Models.extractPartName(fullString); if (partName == "body") part = Part.Body; else if (partName == "helm") part = Part.Helmet; else if (partName == "arm") part = Part.Arms; else if (partName == "wst") part = Part.Waist; else if (partName == "leg") part = Part.Legs; else if (partName.StartsWith("slg")) part = Part.Slinger; else if (partName.StartsWith("hair")) part = Part.Hair; else if (partName.StartsWith("face")) part = partName.EndsWith("_eyelens") ? Part.EyeLens : Part.Face; else if (fullString.StartsWith("wp\\")) { if (!playerWeapon.Contains(modelAddr)) { playerWeapon.Add(modelAddr); } return; } else return; playerArmor[part] = modelAddr; int jointCount = Get(modelAddr, 0x4A0); nint jointAddr = Get(modelAddr, 0x4A8); for (int i = 0; i < jointCount; i++) { nint childAddr = Get(jointAddr, 0x8); if (childAddr != 0x0 && Get(childAddr) == 0x142F21A90) { childAddr = Get(childAddr, 0x8); if (childAddr != 0x0) { nint childVtable = Get(childAddr); if (childVtable == 0x143524BD8) { childAddr = Get(childAddr, 0x188); if (childAddr != 0x0 && Get(childAddr) == 0x143519530) { nint jiggleData = Get(Get(childAddr, 0xA0)); if (Get(jiggleData) == 0x143519508) { if (!jiggleBones.ContainsKey(jiggleData)) { int jiggleIndex = jiggleBones.Count(); jiggleBones[jiggleData] = new(); } jiggleBones[jiggleData].Add(jointAddr); } } } #if QUARANTINED_FEATURES else if (childVtable == 0x143249170) { childAddr = Get(childAddr, 0x188); if (childAddr != 0x0 && Get(childAddr) == 0x1432492F0) { ikJoints.Add(jointAddr); } } #endif } } switch (part) { case Part.Body: bodyJoints.Add(jointAddr); break; case Part.Face: faceJoints.Add(jointAddr); break; case Part.Hair: hairJoints.Add(jointAddr); break; } jointAddr += 0xC0; } if (part == Part.Body) { for (int i = 0; i < bodyJoints.Count; i++) { jointAddr = bodyJoints[i]; byte id = Get(jointAddr, 0xA0); Assert(bodyJointMap[id] == 0x0); bodyJointMap[id] = jointAddr; } foreach ((nint joint, _) in bodyRotations.Where((e) => !bodyJoints.Contains(e.Key))) bodyRotations.Remove(joint); foreach ((nint joint, _) in bodyPositions.Where((e) => !bodyJoints.Contains(e.Key))) bodyPositions.Remove(joint); foreach ((nint joint, _) in bodyOffsets.Where((e) => !bodyJoints.Contains(e.Key))) bodyOffsets.Remove(joint); #if QUARANTINED_FEATURES foreach ((nint joint, _) in ikOffsets.Where((e) => !bodyJoints.Contains(e.Key))) ikOffsets.Remove(joint); #endif } else if (part == Part.Face) { for (int i = 0; i < faceJoints.Count; i++) { jointAddr = faceJoints[i]; byte id = Get(jointAddr, 0xA0); Assert(faceJointMap[id] == 0x0); faceJointMap[id] = jointAddr; } foreach ((nint joint, _) in faceRotations.Where((e) => !faceJoints.Contains(e.Key))) faceRotations.Remove(joint); foreach ((nint joint, _) in facePositions.Where((e) => !faceJoints.Contains(e.Key))) facePositions.Remove(joint); foreach ((nint joint, _) in faceOffsets.Where((e) => !faceJoints.Contains(e.Key))) faceOffsets.Remove(joint); } else if (part == Part.Hair) { foreach ((nint joint, _) in hairRotations.Where((e) => !hairJoints.Contains(e.Key))) hairRotations.Remove(joint); foreach ((nint joint, _) in hairOffsets.Where((e) => !hairJoints.Contains(e.Key))) hairOffsets.Remove(joint); } } private static void collectWeaponParts(Player player) { nint weaponAddr = player.Get(0x76B0); if (weaponAddr == 0x0) { return; } nint resourceAddr = Get(weaponAddr, 0x2A0); if (resourceAddr == 0x0) { return; } retryWeaponRefresh = false; collectArmorParts(weaponAddr, resourceAddr); nint subAddr = Get(weaponAddr, 0x2208); if (subAddr != 0x0) { resourceAddr = Get(subAddr, 0x2A0); if (resourceAddr != 0x0) { collectArmorParts(subAddr, resourceAddr); } } nint weaponParts = Get(weaponAddr, 0x9C8); if (weaponParts == 0x0) { weaponParts = Get(weaponAddr, 0x21D8); } nint next = weaponParts; nint head = next; nint prev = 0x0; if (weaponParts != 0x0) { prev = Get(weaponParts, 0x38); } for (;next != 0x0;) { weaponParts = next; // If we search backwards (+0x38), we will pick up to-be-freed resources. next = Get(weaponParts, 0x30); nint vTable = Get(weaponParts); if (vTable == 0x1434D1D58) // uWeaponEmblem { if (Get(weaponParts, 0x590) != player.Instance) { continue; } nint parentAddr = Get(weaponParts, 0x5A8); if (parentAddr != 0x0) { vTable = Get(parentAddr); if (vTable == 0x1434D7C88 || vTable == 0x1434D7928) // uWpSubGeneral || uWpQuiver { if (Get(parentAddr, 0x9B0) != player.Instance) { continue; } resourceAddr = Get(parentAddr, 0x2A0); if (resourceAddr != 0x0) { collectArmorParts(parentAddr, resourceAddr); } } } } else if (vTable == 0x1434D7C88) // uWpSubGeneral { if (Get(weaponParts, 0x9B0) != player.Instance) { continue; } } else if (vTable == 0x1434D2400) // uWeaponParts { if (Get(weaponParts, 0x990) != player.Instance) { continue; } } else { continue; } resourceAddr = Get(weaponParts, 0x2A0); if (resourceAddr != 0x0) { collectArmorParts(weaponParts, resourceAddr); } } } private static bool collectArmorAndJoints(Player player) { // MonsterHunterWorld.exe+203E8A2 - mov rax,[rbx+000126C8] // cpPlCombineArmorCtrl + 0x50 + (partIndex * 0x80) nint cpPlCombineArmorCtrl = player.Get(0x126C8); nint bodyArmorResource = player.Get(0x2A0); nint slingerAddr = player.Get(0x8918); if (cpPlCombineArmorCtrl == 0x0 || bodyArmorResource == 0x0 || slingerAddr == 0x0) { return false; } retryArmorRefresh = false; if (bodyArmorResource != lastBodyArmor) { dropJointOffsets(); lastBodyArmor = bodyArmorResource; } collectArmorParts(player.Instance, bodyArmorResource); nint next, resourceAddr; resourceAddr = Get(slingerAddr, 0x2A0); if (resourceAddr != 0x0) { collectArmorParts(slingerAddr, resourceAddr); } cpPlCombineArmorCtrl = Get(cpPlCombineArmorCtrl, 0x70); next = cpPlCombineArmorCtrl; for (;next != 0x0;) { nint armorAddr = next; next = Get(armorAddr, 0x30); nint vTable = Get(armorAddr); if (vTable == 0x1434A7560) // uPlCombineArmor { nint parentAddr = Get(armorAddr, 0x548); if (parentAddr != 0x0) { if (Get(parentAddr) == 0x143451520) // Face. { if (Get(parentAddr, 0x998) != player.Instance) { continue; } if (playerArmor[Part.Face] == 0x0) { resourceAddr = Get(parentAddr, 0x2A0); if (resourceAddr != 0x0) { collectArmorParts(parentAddr, resourceAddr); } nint childAddr = Get(parentAddr, 0x9C8); if (childAddr != 0x0 && Get(childAddr) == 0x143505E98) // Eye lens. { resourceAddr = Get(childAddr, 0x2A0); if (resourceAddr != 0x0) { collectArmorParts(childAddr, resourceAddr); } } } } else if (parentAddr != player.Instance) { continue; } } } else { continue; } resourceAddr = Get(armorAddr, 0x2A0); if (resourceAddr != 0x0) { collectArmorParts(armorAddr, resourceAddr); } if (!playerArmor.Where((p) => p == 0x0).Any()) { break; } } return true; } private static void assertFirstHook(nint model) { #if HOOK_ORDER_ASSERTS Player? player = getPlayer(); if (player != null && model == player.Instance) { if (Monitor.TryEnter(playerArmor)) Monitor.Exit(playerArmor); else Assert(false); Assert(hookOrder == 0); hookOrder = 1; } #endif } private static void assertModelHook(nint model) { #if HOOK_ORDER_ASSERTS Player? player = getPlayer(); if (player != null && model == player.Instance) { if (Monitor.TryEnter(playerArmor)) Monitor.Exit(playerArmor); else Assert(false); Assert(hookOrder == 1); } #endif } private static void UpdateModelHook(nint model) { assertFirstHook(model); bool updateBody = bodyPositions.Count() > 0 || bodyOffsets.Count() > 0; bool updateFace = facePositions.Count() > 0 || faceOffsets.Count() > 0; bool processUpdate = updateBody || updateFace || activeMaterialOverrides > 0 || skinToneSet; updateModelHook!.Original(model); Player? player = null; if (processUpdate && (player = getPlayer()) != null) { getDirectionVectors(player.Rotation, out Vector3 rootForward, out Vector3 rootRight, out Vector3 rootUp); if (model == player.Instance) { if (updateBody) { foreach ((nint addr, Vector3 position) in bodyPositions) { GetRef(addr, 0x50) = player.Position + ((rootForward * position.X) + (rootUp * position.Y) + (rootRight * position.Z)); } foreach ((nint addr, Vector3 offset) in bodyOffsets) { GetRef(addr, 0x50) += (rootForward * offset.X) + (rootUp * offset.Y) + (rootRight * offset.Z); } } foreach (BaseMaterial material in helmetMaterials) { material.Update(material.Address); } foreach (BaseMaterial material in bodyMaterials) { material.Update(material.Address); } foreach (BaseMaterial material in armsMaterials) { material.Update(material.Address); } foreach (BaseMaterial material in waistMaterials) { material.Update(material.Address); } foreach (BaseMaterial material in legsMaterials) { material.Update(material.Address); } foreach (BaseMaterial material in slingerMaterials) { material.Update(material.Address); } } if (model == playerArmor[Part.Face]) { if (updateFace) { foreach ((nint addr, Vector3 position) in facePositions) { GetRef(addr, 0x50) = player.Position + ((rootForward * position.X) + (rootUp * position.Y) + (rootRight * position.Z)); } foreach ((nint addr, Vector3 offset) in faceOffsets) { GetRef(addr, 0x50) += (rootForward * offset.X) + (rootUp * offset.Y) + (rootRight * offset.Z); } } foreach (BaseMaterial material in faceMaterials) { material.Update(material.Address); } } } } private static void UpdateJointRotationHook(nint model) { assertModelHook(model); bool updateBody = bodyRotations.Count() > 0; bool updateFace = faceRotations.Count() > 0; bool processUpdate = updateBody || updateFace; Player? player = null; if (processUpdate && (player = getPlayer()) != null) { if (updateBody && model == player.Instance) { foreach ((nint addr, Vector4 rotation) in bodyRotations) { GetRef(addr, 0x70) = new(rotation.X, rotation.Y, rotation.Z, rotation.W); } } if (updateFace && model == playerArmor[Part.Face]) { foreach ((nint addr, Vector4 rotation) in faceRotations) { GetRef(addr, 0x70) = new(rotation.X, rotation.Y, rotation.Z, rotation.W); } } } updateJointRotationHook!.Original(model); } private static void UpdateHairJointsHook(nint model) { assertModelHook(model); bool updateRotation = hairRotations.Count() > 0; bool updatePosition = hairOffsets.Count() > 0; bool processUpdate = updateRotation || updatePosition || activeMaterialOverrides > 0; updateHairJoints!.Original(model); Player? player = null; if (processUpdate && (player = getPlayer()) != null) { if (model != playerArmor[Part.Hair]) { return; } if (updateRotation) { foreach ((nint addr, Vector4 rotation) in hairRotations) { GetRef(addr, 0x70) = new(rotation.X, rotation.Y, rotation.Z, rotation.W); } } if (updatePosition) { getDirectionVectors(player.Rotation, out Vector3 rootForward, out Vector3 rootRight, out Vector3 rootUp); foreach ((nint addr, Vector3 offset) in hairOffsets) { GetRef(addr, 0x50) += (rootForward * offset.X) + (rootUp * offset.Y) + (rootRight * offset.Z); } } foreach (BaseMaterial material in hairMaterials) { material.Update(material.Address); } } } #if QUARANTINED_FEATURES private static void UpdateIKPositionHook(nint ikObject, nint joint, nint obj) { if (ikOffsets.ContainsKey(joint)) { Vector3 offset = ikOffsets[joint][0]; GetRef(ikObject, 0x1380) += offset; } updateIKPositionHook!.Original(ikObject, joint, obj); } #endif private static void drawJoint(nint jointAddr, Dictionary rotations, Dictionary offsets) { if (jointAddr == 0x0) return; ImGui.PushID(jointAddr); bool hasRotation = rotations.ContainsKey(jointAddr); bool hasOffset = offsets.ContainsKey(jointAddr); #if QUARANTINED_FEATURES bool hasIkOffset = ikOffsets.ContainsKey(jointAddr); #endif ref Vector3 position = ref GetRef(jointAddr, 0x50); ref Vector4 rotation = ref GetRef(jointAddr, 0x70); ImGui.DragFloat4("Rotation", ref rotation, 0.005f); if (hasRotation) { ImGui.PushID("Rotation"); bool doRemove = ImGui.Button("X"); ImGui.SameLine(); if (Models.drawRotate("##Rotate", rotations[jointAddr], out Vector4 result)) { rotations[jointAddr] = result; } if (doRemove) rotations.Remove(jointAddr); ImGui.PopID(); } ImGui.DragFloat3("Position", ref position, 0.005f); if (hasOffset) { ImGui.PushID("Position"); bool doRemove = ImGui.Button("X"); ImGui.SameLine(); if (ImGui.Button("Reset")) { offsets[jointAddr] = default; } ImGui.SameLine(); Vector3 v = offsets[jointAddr]; if (ImGui.DragFloat3($"##Offset", ref v, 0.005f)) { offsets[jointAddr] = v; } if (doRemove) offsets.Remove(jointAddr); ImGui.PopID(); } #if QUARANTINED_FEATURES if (hasIkOffset) { ImGui.PushID("IK"); bool doRemove = ImGui.Button("X"); ImGui.SameLine(); if (ImGui.Button("Reset")) { ikOffsets[jointAddr][0] = default; ikOffsets[jointAddr][1] = default; } ImGui.SameLine(); Vector3 v = ikOffsets[jointAddr][0]; if (ImGui.DragFloat3($"##IK Offset", ref v, 0.025f)) { ikOffsets[jointAddr][0] = v; } if (doRemove) ikOffsets.Remove(jointAddr); ImGui.PopID(); } #endif if (!hasRotation) { if (ImGui.Button("Add Rotation")) { rotations.Add(jointAddr, rotation); } } if (!hasOffset) { if (!hasRotation) { ImGui.SameLine(); } if (ImGui.Button("Add Offset")) { offsets.Add(jointAddr, new Vector3()); } } #if QUARANTINED_FEATURES if (ikJoints.Contains(jointAddr) && !hasIkOffset) { if (!hasOffset) { ImGui.SameLine(); } if (ImGui.Button("Add IK Offset")) { ikOffsets.Add(jointAddr, new List(){ default, default }); } } #endif ImGui.PopID(); } private static void drawBodyJoint(nint jointAddr) { drawJoint(jointAddr, bodyRotations, bodyOffsets); } private static void drawFaceJoint(nint jointAddr) { drawJoint(jointAddr, faceRotations, faceOffsets); } private static void drawJointLeaf(ref List joints, int i, Dictionary rotations, Dictionary offsets) { if (i >= joints.Count) return; nint jointAddr = joints[i]; byte id = Get(jointAddr, 0xA0); ImGui.PushID(jointAddr); if (ImGui.CollapsingHeader($"Joint #{i} (0x{jointAddr:X}, id: 0x{id:X})")) { drawJoint(jointAddr, rotations, offsets); } ImGui.PopID(); drawJointLeaf(ref joints, i + 1, rotations, offsets); } internal static void drawArmorParts(Player player, float width) { if (ImGui.Checkbox("Ignore Full Armor Sets Face/Hair", ref ignoreFullArmorFace)) { if (ignoreFullArmorFace) { jmpOverExtFace.Enable(); jmpOverExtHair.Enable(); } else { jmpOverExtFace.Disable(); jmpOverExtHair.Disable(); } } if (ImGui.Checkbox("Disable Full Armor Sets Hides Slinger", ref ignoreHideSlinger)) { if (ignoreHideSlinger) { jmpOverHideSlinger.Enable(); } else { jmpOverHideSlinger.Disable(); } } bool expand = ImGui.CollapsingHeader("Helmet"); ImGui.SameLine(); int layered = player.Get(0x13754); ImGui.Text($"(id: {player.Get(0x1373C):X}" + ((layered != -1) ? $", layered: {layered:X})" : ")")); if (expand) { Models.drawModelParts(playerArmor[Part.Helmet]); foreach (BaseMaterial material in helmetMaterials) { material.Draw(width); } ImGui.Separator(); } ImGui.PushID("Body"); expand = ImGui.CollapsingHeader("Body"); ImGui.SameLine(); layered = player.Get(0x13758); ImGui.Text($"(id: {player.Get(0x13740):X}" + ((layered != -1) ? $", layered: {layered:X})" : ")")); if (expand) { Models.drawModelParts(playerArmor[Part.Body]); foreach (BaseMaterial material in bodyMaterials) { material.Draw(width); } ImGui.Separator(); } ImGui.PopID(); ImGui.PushID("Arms"); expand = ImGui.CollapsingHeader("Arms"); ImGui.SameLine(); layered = player.Get(0x1375C); ImGui.Text($"(id: {player.Get(0x13744):X}" + ((layered != -1) ? $", layered: {layered:X})" : ")")); if (expand) { Models.drawModelParts(playerArmor[Part.Arms]); foreach (BaseMaterial material in armsMaterials) { material.Draw(width); } ImGui.Separator(); } ImGui.PopID(); expand = ImGui.CollapsingHeader("Waist"); ImGui.SameLine(); layered = player.Get(0x13760); ImGui.Text($"(id: {player.Get(0x13748):X}" + ((layered != -1) ? $", layered: {layered:X})" : ")")); if (expand) { Models.drawModelParts(playerArmor[Part.Waist]); foreach (BaseMaterial material in waistMaterials) { material.Draw(width); } ImGui.Separator(); } ImGui.PushID("Legs"); expand = ImGui.CollapsingHeader("Legs"); ImGui.SameLine(); layered = player.Get(0x13764); ImGui.Text($"(id: {player.Get(0x1374C):X}" + ((layered != -1) ? $", layered: {layered:X})" : ")")); if (expand) { Models.drawModelParts(playerArmor[Part.Legs]); foreach (BaseMaterial material in legsMaterials) { material.Draw(width); } ImGui.Separator(); } ImGui.PopID(); expand = ImGui.CollapsingHeader("Slinger"); ImGui.SameLine(); ImGui.Text($"(id: {player.Get(0x13D8C):X}_{player.Get(0x13D90):X})"); if (expand) { Models.drawModelParts(playerArmor[Part.Slinger]); foreach (BaseMaterial material in slingerMaterials) { material.Draw(width); } ImGui.Separator(); } expand = ImGui.CollapsingHeader("Weapon"); if (expand) { foreach (nint weaponPart in playerWeapon) { Models.drawModelParts(weaponPart); ImGui.Separator(); } } if (ImGui.CollapsingHeader("Hair")) { Models.drawModelParts(playerArmor[Part.Hair]); foreach (BaseMaterial material in hairMaterials) { material.Draw(width); } ImGui.Separator(); } if (ImGui.CollapsingHeader("Face")) { Models.drawModelParts(playerArmor[Part.Face]); foreach (BaseMaterial material in faceMaterials) { material.Draw(width); } ImGui.Separator(); } if (ImGui.CollapsingHeader("Eye Lens")) { Models.drawModelParts(playerArmor[Part.EyeLens]); } } private static void setSkinToneOverride() { skinToneSet = true; foreach (List partMaterials in allMaterialLists) { foreach (BaseMaterial material in partMaterials) { if (material is MhMaterialPLEditFaceLocal || material is MhMaterialPLSkinLocal) { material.Parameters[12].ForceOverrideOn(true); material.Parameters[12].SetOverrideValue(new Vector4(currentSkinTone.X, currentSkinTone.Y, 0.0f, 0.0f), 0); } } } } private static void unsetSkinToneOverride() { skinToneSet = false; foreach (List partMaterials in allMaterialLists) { foreach (BaseMaterial material in partMaterials) { if (material is MhMaterialPLEditFaceLocal || material is MhMaterialPLSkinLocal) { material.Parameters[12].ForceOverrideOff(); } } } } internal static void drawSkinTone(Player player, NativeWrapper playerSettings, float width) { // @TODO: This could be a ColorButton with a popup. if (!skinToneSet) { currentSkinTone = new Vector2( playerSettings.GetRef(0x166) / 255.0f, playerSettings.GetRef(0x167) / 255.0f); } if (skinAddTextureHandle == TextureHandle.Invalid) { if (skinAddTexture != null) { skinAddTextureHandle = skinAddTexture.GetTextureHandle(); } else { #if ALT_TEXTURE_LOAD string path = "native:\\Assets\\default_tex\\skin_BM.tex"; MtFileStream? file = MtFileStream.FromPath(path, OpenMode.Read, false); if (file != null) { skinAddTexture = MtDti.Find("rTexture")!.CreateInstance(); if (skinAddTexture.LoadFrom(file)) { MemoryUtil.WriteBytes(skinAddTexture.Instance + 0xC, StringToCStr(path.Replace("native:\\", "").Replace(".tex", ""))); } else { skinAddTexture = null; } file.Close(); } #else skinAddTexture = ResourceManager.GetResource("Assets\\default_tex\\skin_BM", MtDti.Find("rTexture")!); if (skinAddTexture != null) { skinAddTextureHandle = skinAddTexture.GetTextureHandle(); } #endif } } bool skinToneChanged = false; if (skinAddTextureHandle != TextureHandle.Invalid) { ImGui.PushItemFlag(ImGuiItemFlags.NoNav, true); string fullString = new(GetPtrInline(skinAddTexture!.Instance, 0xC)); ImGui.Text($"{fullString} @ {skinAddTexture.Instance:X}"); Vector2 cursorPos = ImGui.GetCursorPos(); Vector2 mousePos = ImGui.GetMousePos(); Vector2 windowPos = ImGui.GetWindowPos(); windowPos += cursorPos - new Vector2(ImGui.GetScrollX(), ImGui.GetScrollY()); Vector2 size = new Vector2(skinAddTexture.Width, skinAddTexture.Height); ImGui.Image(skinAddTextureHandle, size); ImGui.SetCursorPos(cursorPos); ImGui.InvisibleButton("picker", size); if (ImGui.IsItemActive()) { currentSkinTone = new Vector2( Math.Clamp((mousePos.X - windowPos.X) / size.X, 0.0f, 1.0f), Math.Clamp((mousePos.Y - windowPos.Y) / size.Y, 0.0f, 1.0f)); skinToneChanged = true; } cursorPos = currentSkinTone; cursorPos *= size; cursorPos += windowPos; ImDrawListPtr drawList = ImGui.GetWindowDrawList(); drawList.AddRect(cursorPos - new Vector2(3.0f, 3.0f), cursorPos + new Vector2(3.0f, 3.0f), (uint)0xFFFFFFFF); ImGui.PopItemFlag(); } ImGui.SetNextItemWidth(width * 0.25f); if (ImGui.DragFloat2("##Skin Tone", ref currentSkinTone, 0.001f, 0.0f, 1.0f) || skinToneChanged) { setSkinToneOverride(); } ImGui.SameLine(); if (ImGui.Button("Reset")) { unsetSkinToneOverride(); } ImGui.SameLine(); if (ImGui.Button("Save")) { byte skinToneX = (byte)Math.Round(currentSkinTone.X * 255.0f); byte skinToneY = (byte)Math.Round(currentSkinTone.Y * 255.0f); player.GetRef(0x13716) = skinToneX; player.GetRef(0x13717) = skinToneY; playerSettings.GetRef(0x166) = skinToneX; playerSettings.GetRef(0x167) = skinToneY; } if (ImGui.Button("Unload Texture")) { skinAddTexture = null; skinAddTextureHandle = TextureHandle.Invalid; } } private static bool poseRotationOnly = false; private static string typedPoseName = ""; private static string selectedPoseName = ""; private static bool poseConfirmDelete = false; private static string[] poseList = []; private static bool poseSelectionStarted = false; public static bool overlayJoints = false; private static void savePose(Player player) { string name = typedPoseName; if (name == "") { return; } if (!Directory.Exists(posePath)) { try { Directory.CreateDirectory(posePath); } catch (Exception e) { Log.Error($"Failed create directory: {posePath} ({e.Message})"); return; } } string path = Path.Join(posePath, name + ".json"); FileStream stream; try { stream = File.Open(path, FileMode.Create); } catch (Exception e) { Log.Error($"Failed to open: {path} ({e.Message})"); return; } using (Utf8JsonWriter writer = new Utf8JsonWriter(stream, new JsonWriterOptions { Indented = true })) { Vector3 rootPosition = player.Position; getDirectionVectors(player.Rotation, out Vector3 rootForward, out Vector3 rootRight, out Vector3 rootUp); writer.WriteStartObject(); writer.WriteStartObject("body"); foreach (nint jointAddr in bodyJoints) { byte id = Get(jointAddr, 0xA0); writer.WritePropertyName($"{id}"); writer.WriteStartArray(); writer.WriteStringValue(Vector4ToString(Get(jointAddr, 0x70))); Vector3 positionOffset = default; Vector3 position = Get(jointAddr, 0x50); Vector3 diff = position - rootPosition; positionOffset.Y = diff.Y; diff.Y = 0.0f; positionOffset.X = Vector3.Dot(rootForward, diff); positionOffset.Z = Vector3.Dot(rootRight, diff); writer.WriteStringValue(Vector3ToString(positionOffset)); if (bodyOffsets.ContainsKey(jointAddr)) { writer.WriteStringValue(Vector3ToString(bodyOffsets[jointAddr])); } writer.WriteEndArray(); } writer.WriteEndObject(); writer.WriteStartObject("face"); foreach (nint jointAddr in faceJoints) { byte id = Get(jointAddr, 0xA0); writer.WritePropertyName($"{id}"); writer.WriteStartArray(); writer.WriteStringValue(Vector4ToString(Get(jointAddr, 0x70))); Vector3 positionOffset = default; Vector3 position = Get(jointAddr, 0x50); Vector3 diff = position - rootPosition; positionOffset.Y = diff.Y; diff.Y = 0.0f; positionOffset.X = Vector3.Dot(rootForward, diff); positionOffset.Z = Vector3.Dot(rootRight, diff); writer.WriteStringValue(Vector3ToString(positionOffset)); if (faceOffsets.ContainsKey(jointAddr)) { writer.WriteStringValue(Vector3ToString(faceOffsets[jointAddr])); } writer.WriteEndArray(); } writer.WriteEndObject(); writer.WriteEndObject(); writer.Flush(); } stream.Close(); } private static void setPose(string filePath, string fileName) { dropJointOffsets(); Utf8JsonReader reader; try { reader = new Utf8JsonReader(File.ReadAllBytes(filePath)); } catch (Exception e) { Log.Error($"Failed to open: {filePath} ({e.Message})"); return; } selectedPoseName = fileName; bool isFace = false; byte currentId = 0xFF; int arrayIndex = 0; while (reader.Read()) { switch (reader.TokenType) { case JsonTokenType.PropertyName: string property = reader.GetString()!; if (property == "body") { isFace = false; } else if (property == "face") { isFace = true; } else { try { currentId = Convert.ToByte(property); } catch (FormatException) { currentId = 0xFF; } catch (OverflowException) { currentId = 0xFF; } } break; case JsonTokenType.StartArray: arrayIndex = 0; break; case JsonTokenType.String: if (currentId == 0xFF) break; if (arrayIndex == 0) { if (isFace) { faceRotations[faceJointMap[currentId]] = StringToVector4(reader.GetString()!); } else { bodyRotations[bodyJointMap[currentId]] = StringToVector4(reader.GetString()!); } } else if (arrayIndex == 1 && !poseRotationOnly) { if (isFace) { facePositions[faceJointMap[currentId]] = StringToVector3(reader.GetString()!); } else { bodyPositions[bodyJointMap[currentId]] = StringToVector3(reader.GetString()!); } } arrayIndex++; break; } } } internal static void drawPoser(Player player, float width) { ImGui.PushID("Poser"); ImGui.Text("Poses"); ImGui.PushItemWidth(width * 0.3f); ImGui.InputText("##Pose Name", ref typedPoseName, 99); ImGui.SameLine(); if (ImGui.Button("Save")) { savePose(player); } ImGui.SameLine(); if (ImGui.BeginCombo("##Poses", selectedPoseName, ImGuiComboFlags.HeightLarge)) { if (!poseSelectionStarted) { try { poseList = Directory.GetFiles(posePath); } catch (Exception e) { Log.Error($"Failed read directory: {posePath} ({e.Message})"); } poseSelectionStarted = true; poseConfirmDelete = false; } if (ImGui.Selectable("(None)")) { if (selectedPoseName != "") { dropJointOffsets(); } selectedPoseName = ""; } foreach (string filePath in poseList) { if (Path.GetExtension(filePath) != ".json") { continue; } string fileName = Path.GetFileNameWithoutExtension(filePath); bool isSelected = fileName == selectedPoseName; if (ImGui.Selectable(fileName, isSelected)) { setPose(filePath, fileName); } if (isSelected) ImGui.SetItemDefaultFocus(); } ImGui.EndCombo(); } else { poseSelectionStarted = false; } ImGui.SameLine(); if (poseConfirmDelete) { ImGui.AlignTextToFramePadding(); ImGui.Text("Are you sure?"); ImGui.SameLine(); if (ImGui.Button("No")) { poseConfirmDelete = false; } ImGui.SameLine(); if (ImGui.Button("Yes")) { string path = Path.Join(posePath, selectedPoseName + ".json"); try { File.Delete(path); } catch (Exception e) { Log.Error($"Failed to delete: {path} ({e.Message})"); } selectedPoseName = ""; poseConfirmDelete = false; } } else if (ImGui.Button("Delete")) { if (selectedPoseName != "") { poseConfirmDelete = true; } } ImGui.PopItemWidth(); ImGui.AlignTextToFramePadding(); #if QUARANTINED_FEATURES ImGui.Text($"Rotations: {bodyRotations.Count + faceRotations.Count}, Positions: {bodyPositions.Count + facePositions.Count}, Offsets: {bodyOffsets.Count + faceOffsets.Count + ikOffsets.Count}"); #else ImGui.Text($"Rotations: {bodyRotations.Count + faceRotations.Count}, Positions: {bodyPositions.Count + facePositions.Count}, Offsets: {bodyOffsets.Count + faceOffsets.Count}"); #endif ImGui.SameLine(); if (ImGui.Button("Clear")) { dropJointOffsets(); } ImGui.SameLine(); ImGui.Checkbox("Overlay Joints", ref overlayJoints); if (overlayJoints) { //Renderer.RequestMouseCapture(); } ImGui.Checkbox("Apply Rotations Only", ref poseRotationOnly); ImGui.SameLine(); /* ref byte ikDisabledB = ref GetRef(player.Get(0x990), 0x5C); bool ikDisabled = ikDisabledB == 0x0; if (ImGui.Checkbox("Disable IK", ref ikDisabled)) { ikDisabledB = ByteFlag(!ikDisabled); } if (ImGui.BeginItemTooltip()) { ImGui.Text("Mostly disable inverse kinematics on your player. To rotate ankles, you need to use Force Disable IK."); ImGui.EndTooltip(); } ImGui.SameLine(); */ if (ImGui.Checkbox("Disable IK", ref ikForcedOff)) { if (ikForcedOff) { forceDisableIK.Enable(); } else { forceDisableIK.Disable(); } } if (ImGui.BeginItemTooltip()) { ImGui.Text("Forcefully disable inverse kinematics."); ImGui.EndTooltip(); } ImGui.SameLine(); ref byte lookAtDisabledB = ref GetRef(player.Get(0x9C0), 0x5C); bool lookAtDisabled = lookAtDisabledB == 0x0; if (ImGui.Checkbox("Disable Look At", ref lookAtDisabled)) { lookAtDisabledB = ByteFlag(!lookAtDisabled); } if (ImGui.BeginItemTooltip()) { ImGui.Text("Stop your character from looking at people, animals, and objects they pass."); ImGui.EndTooltip(); } if (ImGui.CollapsingHeader("Joints")) { ImGui.PushItemWidth(width * 0.75f); if (ImGui.TreeNodeEx("Body", ImGuiTreeNodeFlags.Framed)) { drawBodyJoints(); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Face", ImGuiTreeNodeFlags.Framed)) { drawFaceJoints(); ImGui.TreePop(); } if (ImGui.CollapsingHeader("Jiggle Bones")) { for (int i = 0; i < jiggleBones.Count; i++) { nint jiggleData = jiggleBones.Keys.ElementAt(i); ImGui.PushID(jiggleData); List jointAddrs = jiggleBones[jiggleData]; string ids = ""; for (int j = 0; j < jointAddrs.Count; j++) { byte id = Get(jointAddrs[j], 0xA0); ids += $"0x{id:X}" + ((j != jointAddrs.Count - 1) ? ", " : ""); } if (ImGui.CollapsingHeader($"Jiggle Bone #{i} (0x{jiggleData:X}, joint_ids: {ids})")) { ImGui.DragFloat3("Position", ref GetRef(jiggleData, 0xD0), 0.05f); if (ImGui.BeginItemTooltip()) { ImGui.Text("Drag position around to influence the bone."); ImGui.EndTooltip(); } } ImGui.PopID(); } } ImGui.Separator(); if (ImGui.CollapsingHeader("All Body Joints")) { drawJointLeaf(ref bodyJoints, 0, bodyRotations, bodyOffsets); } if (ImGui.CollapsingHeader("All Face Joints")) { drawJointLeaf(ref faceJoints, 0, faceRotations, faceOffsets); } if (ImGui.CollapsingHeader("All Hair Joints")) { drawJointLeaf(ref hairJoints, 0, hairRotations, hairOffsets); } ImGui.PopItemWidth(); } ImGui.PopID(); } private static void drawBodyJoints() { ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags.Framed; bool expand; if (ImGui.TreeNodeEx("Root", flags)) { drawBodyJoint(bodyJointMap[Joint.Root2]); ImGui.TreePop(); } ImGui.PushID("Neck"); if (ImGui.TreeNodeEx("Neck", flags)) { if (ImGui.TreeNodeEx("Upper", flags)) { drawBodyJoint(bodyJointMap[Joint.UpperNeck]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Lower", flags)) { drawBodyJoint(bodyJointMap[Joint.LowerNeck]); ImGui.TreePop(); } ImGui.TreePop(); } ImGui.PopID(); // Neck. ImGui.PushID("Back"); if (ImGui.TreeNodeEx("Back", flags)) { if (ImGui.TreeNodeEx("Upper", flags)) { drawBodyJoint(bodyJointMap[Joint.UpperBack]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Lower", flags)) { drawBodyJoint(bodyJointMap[Joint.LowerBack]); ImGui.TreePop(); } ImGui.TreePop(); } ImGui.PopID(); // Back. ImGui.PushID("Right Arm"); if (ImGui.TreeNodeEx("Right Arm", flags)) { if (ImGui.TreeNodeEx("Collarbone", flags)) { drawBodyJoint(bodyJointMap[Joint.RightCollarbone]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Shoulder", flags)) { drawBodyJoint(bodyJointMap[Joint.RightShoulder]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Elbow", flags)) { drawBodyJoint(bodyJointMap[Joint.RightElbow]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Wrist", flags)) { drawBodyJoint(bodyJointMap[Joint.RightWrist]); ImGui.TreePop(); } ImGui.TreePop(); } ImGui.PopID(); // Right Arm. ImGui.PushID("Right Hand"); if (ImGui.TreeNodeEx("Right Hand", flags)) { ImGui.PushID("Thumb"); if (ImGui.TreeNodeEx("Thumb", flags)) { if (ImGui.TreeNodeEx("Base", flags)) { drawBodyJoint(bodyJointMap[Joint.RightThumbLow]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Middle", flags)) { drawBodyJoint(bodyJointMap[Joint.RightThumbMid]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Tip", flags)) { drawBodyJoint(bodyJointMap[Joint.RightThumbHigh]); ImGui.TreePop(); } ImGui.TreePop(); } ImGui.PopID(); ImGui.PushID("Index"); if (ImGui.TreeNodeEx("Index", flags)) { if (ImGui.TreeNodeEx("Base", flags)) { drawBodyJoint(bodyJointMap[Joint.RightIndexLow]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Middle", flags)) { drawBodyJoint(bodyJointMap[Joint.RightIndexMid]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Tip", flags)) { drawBodyJoint(bodyJointMap[Joint.RightIndexHigh]); ImGui.TreePop(); } ImGui.TreePop(); } ImGui.PopID(); ImGui.PushID("Middle"); if (ImGui.TreeNodeEx("Middle", flags)) { if (ImGui.TreeNodeEx("Base", flags)) { drawBodyJoint(bodyJointMap[Joint.RightMiddleLow]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Middle", flags)) { drawBodyJoint(bodyJointMap[Joint.RightMiddleMid]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Tip", flags)) { drawBodyJoint(bodyJointMap[Joint.RightMiddleHigh]); ImGui.TreePop(); } ImGui.TreePop(); } ImGui.PopID(); ImGui.PushID("Ring"); if (ImGui.TreeNodeEx("Ring", flags)) { if (ImGui.TreeNodeEx("Base", flags)) { drawBodyJoint(bodyJointMap[Joint.RightRingLow]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Middle", flags)) { drawBodyJoint(bodyJointMap[Joint.RightRingMid]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Tip", flags)) { drawBodyJoint(bodyJointMap[Joint.RightRingHigh]); ImGui.TreePop(); } ImGui.TreePop(); } ImGui.PopID(); ImGui.PushID("Pinky"); if (ImGui.TreeNodeEx("Pinky", flags)) { if (ImGui.TreeNodeEx("Base", flags)) { drawBodyJoint(bodyJointMap[Joint.RightPinkyLow]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Middle", flags)) { drawBodyJoint(bodyJointMap[Joint.RightPinkyMid]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Tip", flags)) { drawBodyJoint(bodyJointMap[Joint.RightPinkyHigh]); ImGui.TreePop(); } ImGui.TreePop(); } ImGui.PopID(); expand = ImGui.TreeNodeEx("Palm", flags); if (ImGui.BeginItemTooltip()) { ImGui.Text("Outer Palm/Pinky+Ring"); ImGui.EndTooltip(); } if (expand) { drawBodyJoint(bodyJointMap[Joint.RightPalm]); ImGui.TreePop(); } ImGui.TreePop(); } ImGui.PopID(); // Right Hand. ImGui.PushID("Right Leg"); if (ImGui.TreeNodeEx("Right Leg", flags)) { if (ImGui.TreeNodeEx("Hip", flags)) { drawBodyJoint(bodyJointMap[Joint.RightHip]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Knee", flags)) { drawBodyJoint(bodyJointMap[Joint.RightKnee]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Ankle", flags)) { drawBodyJoint(bodyJointMap[Joint.RightAnkle]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Toes", flags)) { drawBodyJoint(bodyJointMap[Joint.RightToes]); ImGui.TreePop(); } ImGui.TreePop(); } ImGui.PopID(); // Right Leg. ImGui.PushID("Left Arm"); if (ImGui.TreeNodeEx("Left Arm", flags)) { if (ImGui.TreeNodeEx("Collarbone", flags)) { drawBodyJoint(bodyJointMap[Joint.LeftCollarbone]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Shoulder", flags)) { drawBodyJoint(bodyJointMap[Joint.LeftShoulder]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Elbow", flags)) { drawBodyJoint(bodyJointMap[Joint.LeftElbow]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Wrist", flags)) { drawBodyJoint(bodyJointMap[Joint.LeftWrist]); ImGui.TreePop(); } ImGui.TreePop(); } ImGui.PopID(); // Left Arm. ImGui.PushID("Left Hand"); if (ImGui.TreeNodeEx("Left Hand", flags)) { ImGui.PushID("Thumb"); if (ImGui.TreeNodeEx("Thumb", flags)) { if (ImGui.TreeNodeEx("Base", flags)) { drawBodyJoint(bodyJointMap[Joint.LeftThumbLow]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Middle", flags)) { drawBodyJoint(bodyJointMap[Joint.LeftThumbMid]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Tip", flags)) { drawBodyJoint(bodyJointMap[Joint.LeftThumbHigh]); ImGui.TreePop(); } ImGui.TreePop(); } ImGui.PopID(); ImGui.PushID("Index"); if (ImGui.TreeNodeEx("Index", flags)) { if (ImGui.TreeNodeEx("Base", flags)) { drawBodyJoint(bodyJointMap[Joint.LeftIndexLow]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Middle", flags)) { drawBodyJoint(bodyJointMap[Joint.LeftIndexMid]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Tip", flags)) { drawBodyJoint(bodyJointMap[Joint.LeftIndexHigh]); ImGui.TreePop(); } ImGui.TreePop(); } ImGui.PopID(); ImGui.PushID("Middle"); if (ImGui.TreeNodeEx("Middle", flags)) { if (ImGui.TreeNodeEx("Base", flags)) { drawBodyJoint(bodyJointMap[Joint.LeftMiddleLow]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Middle", flags)) { drawBodyJoint(bodyJointMap[Joint.LeftMiddleMid]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Tip", flags)) { drawBodyJoint(bodyJointMap[Joint.LeftMiddleHigh]); ImGui.TreePop(); } ImGui.TreePop(); } ImGui.PopID(); ImGui.PushID("Ring"); if (ImGui.TreeNodeEx("Ring", flags)) { if (ImGui.TreeNodeEx("Base", flags)) { drawBodyJoint(bodyJointMap[Joint.LeftRingLow]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Middle", flags)) { drawBodyJoint(bodyJointMap[Joint.LeftRingMid]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Tip", flags)) { drawBodyJoint(bodyJointMap[Joint.LeftRingHigh]); ImGui.TreePop(); } ImGui.TreePop(); } ImGui.PopID(); ImGui.PushID("Pinky"); if (ImGui.TreeNodeEx("Pinky", flags)) { if (ImGui.TreeNodeEx("Base", flags)) { drawBodyJoint(bodyJointMap[Joint.LeftPinkyLow]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Middle", flags)) { drawBodyJoint(bodyJointMap[Joint.LeftPinkyMid]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Tip", flags)) { drawBodyJoint(bodyJointMap[Joint.LeftPinkyHigh]); ImGui.TreePop(); } ImGui.TreePop(); } ImGui.PopID(); expand = ImGui.TreeNodeEx("Palm", flags); if (ImGui.BeginItemTooltip()) { ImGui.Text("Outer Palm/Pinky+Ring"); ImGui.EndTooltip(); } if (expand) { drawBodyJoint(bodyJointMap[Joint.LeftPalm]); ImGui.TreePop(); } ImGui.TreePop(); } ImGui.PopID(); // Left Hand. ImGui.PushID("Left Leg"); if (ImGui.TreeNodeEx("Left Leg", flags)) { if (ImGui.TreeNodeEx("Hip", flags)) { drawBodyJoint(bodyJointMap[Joint.LeftHip]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Knee", flags)) { drawBodyJoint(bodyJointMap[Joint.LeftKnee]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Ankle", flags)) { drawBodyJoint(bodyJointMap[Joint.LeftAnkle]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Toes", flags)) { drawBodyJoint(bodyJointMap[Joint.LeftToes]); ImGui.TreePop(); } ImGui.TreePop(); } ImGui.PopID(); // Left Leg. } private static void drawFaceJoints() { ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags.Framed; ImGui.PushID("Lips"); if (ImGui.TreeNodeEx("Lips", flags)) { if (ImGui.TreeNodeEx("Right Edge", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth2]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Right Lower 1", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth3]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Right Lower 2", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth4]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Right Upper 1", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth29]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Right Upper 2", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth28]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Left Edge", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth1]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Left Lower 1", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth7]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Left Lower 2", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth6]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Left Upper 1", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth25]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Left Upper 2", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth26]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Middle Lower", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth5]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Middle Upper", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth27]); ImGui.TreePop(); } ImGui.TreePop(); } ImGui.PopID(); // Lips. ImGui.PushID("Mouth"); if (ImGui.TreeNodeEx("Mouth", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth]); if (ImGui.TreeNodeEx("Bottom Teeth", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth30]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Right Lower 1", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth12]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Right Lower 2", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth11]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Right Upper 1", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth24]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Right Upper 2", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth23]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Left Lower 1", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth8]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Left Lower 2", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth9]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Left Upper 1", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth20]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Left Upper 2", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth21]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Middle Lower", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth10]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Middle Upper", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth22]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Right Under", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth15]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Left Under", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth14]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Middle Under", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth13]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Right Cheek 1", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth17]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Right Cheek 2", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth19]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Left Cheek 1", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth16]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Left Cheek 2", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Mouth18]); ImGui.TreePop(); } ImGui.TreePop(); } ImGui.PopID(); // Mouth. ImGui.PushID("Cheeks"); if (ImGui.TreeNodeEx("Cheeks", flags)) { if (ImGui.TreeNodeEx("Right Cheek", flags)) { drawFaceJoint(faceJointMap[FaceJoint.RightCheek]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Right Cheek 1", flags)) { drawFaceJoint(faceJointMap[FaceJoint.RightCheek1]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Right Cheek 2", flags)) { drawFaceJoint(faceJointMap[FaceJoint.RightCheek2]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Right Cheek 3", flags)) { drawFaceJoint(faceJointMap[FaceJoint.RightCheek3]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Right Cheek 4", flags)) { drawFaceJoint(faceJointMap[FaceJoint.RightCheek4]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Right Cheek 5", flags)) { drawFaceJoint(faceJointMap[FaceJoint.RightCheek5]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Left Cheek", flags)) { drawFaceJoint(faceJointMap[FaceJoint.LeftCheek]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Left Cheek 1", flags)) { drawFaceJoint(faceJointMap[FaceJoint.LeftCheek1]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Left Cheek 2", flags)) { drawFaceJoint(faceJointMap[FaceJoint.LeftCheek2]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Left Cheek 3", flags)) { drawFaceJoint(faceJointMap[FaceJoint.LeftCheek3]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Left Cheek 4", flags)) { drawFaceJoint(faceJointMap[FaceJoint.LeftCheek4]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Left Cheek 5", flags)) { drawFaceJoint(faceJointMap[FaceJoint.LeftCheek5]); ImGui.TreePop(); } ImGui.TreePop(); } ImGui.PopID(); // Cheeks. ImGui.PushID("Right Eye"); if (ImGui.TreeNodeEx("Right Eye", flags)) { drawFaceJoint(faceJointMap[FaceJoint.RightEye]); if (ImGui.TreeNodeEx("Eyeball", flags)) { drawFaceJoint(faceJointMap[FaceJoint.RightEye1]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Eyelid Outer", flags)) { drawFaceJoint(faceJointMap[FaceJoint.RightEye2]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Eyelid 1", flags)) { drawFaceJoint(faceJointMap[FaceJoint.RightEye3]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Eyelid 2", flags)) { drawFaceJoint(faceJointMap[FaceJoint.RightEye4]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Eyelid 3", flags)) { drawFaceJoint(faceJointMap[FaceJoint.RightEye5]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Eyelid Inner", flags)) { drawFaceJoint(faceJointMap[FaceJoint.RightEye6]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Eyelid Lower 1", flags)) { drawFaceJoint(faceJointMap[FaceJoint.RightEye7]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Eyelid Lower 2", flags)) { drawFaceJoint(faceJointMap[FaceJoint.RightEye8]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Eyelid Lower 3", flags)) { drawFaceJoint(faceJointMap[FaceJoint.RightEye9]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Eyelid Top 1", flags)) { drawFaceJoint(faceJointMap[FaceJoint.RightEye10]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Eyelid Top 2", flags)) { drawFaceJoint(faceJointMap[FaceJoint.RightEye11]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Eyelid Top 3", flags)) { drawFaceJoint(faceJointMap[FaceJoint.RightEye12]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Under Eye", flags)) { drawFaceJoint(faceJointMap[FaceJoint.RightEye13]); ImGui.TreePop(); } ImGui.TreePop(); } ImGui.PopID(); // Right Eye. ImGui.PushID("Left Eye"); if (ImGui.TreeNodeEx("Left Eye", flags)) { drawFaceJoint(faceJointMap[FaceJoint.LeftEye]); if (ImGui.TreeNodeEx("Eyeball", flags)) { drawFaceJoint(faceJointMap[FaceJoint.LeftEye1]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Eyelid Outer", flags)) { drawFaceJoint(faceJointMap[FaceJoint.LeftEye2]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Eyelid 1", flags)) { drawFaceJoint(faceJointMap[FaceJoint.LeftEye3]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Eyelid 2", flags)) { drawFaceJoint(faceJointMap[FaceJoint.LeftEye4]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Eyelid 3", flags)) { drawFaceJoint(faceJointMap[FaceJoint.LeftEye5]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Eyelid Inner", flags)) { drawFaceJoint(faceJointMap[FaceJoint.LeftEye6]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Eyelid Lower 1", flags)) { drawFaceJoint(faceJointMap[FaceJoint.LeftEye7]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Eyelid Lower 2", flags)) { drawFaceJoint(faceJointMap[FaceJoint.LeftEye8]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Eyelid Lower 3", flags)) { drawFaceJoint(faceJointMap[FaceJoint.LeftEye9]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Eyelid Top 1", flags)) { drawFaceJoint(faceJointMap[FaceJoint.LeftEye10]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Eyelid Top 2", flags)) { drawFaceJoint(faceJointMap[FaceJoint.LeftEye11]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Eyelid Top 3", flags)) { drawFaceJoint(faceJointMap[FaceJoint.LeftEye12]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Under Eye", flags)) { drawFaceJoint(faceJointMap[FaceJoint.LeftEye13]); ImGui.TreePop(); } ImGui.TreePop(); } ImGui.PopID(); // Left Eye. ImGui.PushID("Chin"); if (ImGui.TreeNodeEx("Chin", flags)) { if (ImGui.TreeNodeEx("Chin Right", flags)) { drawFaceJoint(faceJointMap[FaceJoint.ChinRight]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Chin Right Back", flags)) { drawFaceJoint(faceJointMap[FaceJoint.ChinRightBack]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Chin Middle", flags)) { drawFaceJoint(faceJointMap[FaceJoint.ChinMiddle]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Chin Left", flags)) { drawFaceJoint(faceJointMap[FaceJoint.ChinLeft]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Chin Left Back", flags)) { drawFaceJoint(faceJointMap[FaceJoint.ChinLeftBack]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Neck Right", flags)) { drawFaceJoint(faceJointMap[FaceJoint.NeckRight]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Neck Middle", flags)) { drawFaceJoint(faceJointMap[FaceJoint.NeckMiddle]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Neck Left", flags)) { drawFaceJoint(faceJointMap[FaceJoint.NeckLeft]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Jaw", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Jaw]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Jaw Right", flags)) { drawFaceJoint(faceJointMap[FaceJoint.JawRight]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Jaw Up Right", flags)) { drawFaceJoint(faceJointMap[FaceJoint.JawUpRight]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Jaw Left", flags)) { drawFaceJoint(faceJointMap[FaceJoint.JawLeft]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Jaw Up Left", flags)) { drawFaceJoint(faceJointMap[FaceJoint.JawUpLeft]); ImGui.TreePop(); } ImGui.TreePop(); } ImGui.PopID(); // Chin. ImGui.PushID("Brow"); if (ImGui.TreeNodeEx("Brow", flags)) { if (ImGui.TreeNodeEx("Brow 0", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Forehead0]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Brow", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Forehead]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Brow 1", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Forehead1]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Brow 2", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Forehead2]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Brow 3", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Forehead3]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Brow 4", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Forehead4]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Brow 5", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Forehead5]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Brow 6", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Forehead6]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Brow 7", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Forehead7]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Brow 8", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Forehead8]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Brow 9", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Forehead9]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Brow 10", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Forehead10]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Brow 11", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Forehead11]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Brow 12", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Forehead12]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Brow 13", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Forehead13]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Brow 14", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Forehead14]); ImGui.TreePop(); } ImGui.TreePop(); } ImGui.PopID(); // Brow. ImGui.PushID("Nose"); if (ImGui.TreeNodeEx("Nose", flags)) { if (ImGui.TreeNodeEx("Nose", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Nose]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Nose 1", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Nose1]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Nose 2", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Nose2]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Nose 3", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Nose3]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Nose 4", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Nose4]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Nose 5", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Nose5]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Nose 6", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Nose6]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Nose 7", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Nose7]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Nose 8", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Nose8]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Nose 9", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Nose9]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Nose 10", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Nose10]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Nose 11", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Nose11]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Nose 12", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Nose12]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Nose 13", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Nose13]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Nose 14", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Nose14]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Nose 15", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Nose15]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Nose 16", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Nose16]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Nose 17", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Nose17]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Nose 18", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Nose18]); ImGui.TreePop(); } if (ImGui.TreeNodeEx("Nose 19", flags)) { drawFaceJoint(faceJointMap[FaceJoint.Nose19]); ImGui.TreePop(); } ImGui.TreePop(); } ImGui.PopID(); // Nose. } internal static void OnRender() { if (overlayJoints) { for (int i = 0; i < bodyJoints.Count; i++) { Primitives.RenderSphere(Get(bodyJoints[i], 0x50), 0.1f, new MtColor(255, 0, 0, 255)); } for (int i = 0; i < faceJoints.Count; i++) { Primitives.RenderSphere(Get(faceJoints[i], 0x50), 0.1f, new MtColor(255, 0, 0, 255)); } for (int i = 0; i < hairJoints.Count; i++) { Primitives.RenderSphere(Get(hairJoints[i], 0x50), 0.1f, new MtColor(255, 0, 0, 255)); } } } } }