From 72083036f686f8d6e5b7def5db4b401e3f351aba Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Wed, 11 Nov 2026 21:16:07 -0500 Subject: Branch off player related code Signed-off-by: Andrew Opalach --- Animal.cs | 178 +++ Armor.cs | 3111 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Models.cs | 568 ++++++++++ PlayerPoser.csproj | 26 + PlayerPoser.sln | 22 + Plugin.cs | 722 ++++++++++++ README.txt | 3 + Utility.cs | 214 ++++ Zone.cs | 343 ++++++ 9 files changed, 5187 insertions(+) create mode 100644 Animal.cs create mode 100644 Armor.cs create mode 100644 Models.cs create mode 100644 PlayerPoser.csproj create mode 100644 PlayerPoser.sln create mode 100644 Plugin.cs create mode 100644 README.txt create mode 100644 Utility.cs create mode 100644 Zone.cs diff --git a/Animal.cs b/Animal.cs new file mode 100644 index 0000000..f15da23 --- /dev/null +++ b/Animal.cs @@ -0,0 +1,178 @@ +using SharpPluginLoader.Core.Memory; + +namespace SharpPluginLoader.Core.Entities +{ + public class Animal : Entity + { + /// + /// Gets a list of all animals in the game + /// + /// + public static Animal[] GetAllAnimals() + { + lock (_animals) return _animals.ToArray(); + } + + /// + /// Constructs a new Animal from a native pointer + /// + /// The native pointer + public Animal(nint instance) : base(instance) { } + + // @TODO: Map to names. + public int Id => Get(0x1AF8); // +0x294 + public int OtherId => Get(0x1AF0); + + private static nint uGmAnimalCtorHook(nint unknownPtr, int unknownInt) + { + nint animalObject = _uGmAnimalCtor.Original(unknownPtr, unknownInt); + lock (_animals) _animals.Add(new(animalObject)); + return animalObject; + } + + private static nint uGmAnimalDestructorHook(nint animalObject) + { + lock(_animals) + { + for (int i = 0; i < _animals.Count; i++) + { + if (_animals[i].Instance == animalObject) + { + _animals.RemoveAt(i); + break; + } + } + } + return _uGmAnimalDestructor.Original(animalObject); + } + + internal static void Initialize() + { + _uGmAnimalCtor = Hook.Create(0x141D285C0, uGmAnimalCtorHook); + _uGmAnimalDestructor = Hook.Create(0x141D289D0, uGmAnimalDestructorHook); + } + + private delegate nint uGmAnimalCtor(nint unknownPtr, int unknownInt); + private delegate nint uGmAnimalDestructor(nint animalObject); + private static Hook _uGmAnimalCtor = null!; + private static Hook _uGmAnimalDestructor = null!; + private static readonly List _animals = []; + } + + /// + /// Represents an animal id + /// + public enum AnimalType : uint + { + /* + Shepherd Hare = 1, + Pilot Hare = 1, + Woodland Pteryx = 2, + Forest Pteryx = 2, + Cobalt Flutterfly = 3, + Phantom Flutterfly = 3, + Climbing Joyperch = 4, + Forest Gekko = 5, + Wildspire Gekko = 5, + Gloom Gekko = 5, + Moonlight Gekko = 5, + Vaporonid = 6, + Scavantula = 6, + Revolture = 7, + Blissbill = 7, + Stonebill = 7, + Omenfly = 8, + Augurfly = 8, + Scalebat = 9, + Gold Scalebat = 9, + Dung Beetle = 10, + Bomb Beetle = 10, + Rime Beetle = 10, + Pink Parexus = 11, + Great Pink Parexus = 11, + Burst Arowana = 12, + Bomb Arowana = 12, + Great Burst Arowana = 12, + Great Bomb Arowana = 12, + Elegant Coralbird = 13, + Dapper Coralbird = 13, + Andangler = 14, + Downy Crake = 15, + Bristly Crake = 15, + Hopguppy = 16, + Petricanths = 17, + Paratoad = 18, + Sleeptoad = 18, + Nitrotoad = 18, + Wiggler = 19, + Wiggler Queen = 19, + Vigorwasp = 20, + Giant Vigorwasp = 20, + Flying Meduso = 21, + Carrier Ant = 22, + Hercudrome = 23, + Gold Hercudrome = 23, + Prism Hercudrome = 23, + Emperor Hopper = 24, + Tyrant Hopper = 24, + Flashfly = 25, + 羽虫 = 26, + ハエ = 27, + ハチ = 28, + 蛍 = 29, + Grandfather Mantagrell = 30, + Iron Helmcrab = 31, + Soldier Helmcrab = 31, + Emerald Helmcrab = 31, + Gold Helmcrab = 31, + Shiny Gold Helmcrab = 31, + 苦蟲 = 32, + 光蟲 = 32, + 不死蟲 = 32, + 雷光蟲 = 32, + 佳餚蟲 = 32, + Whetfish = 33, + Great Whetfish = 33, + Gastronome Tuna = 34, + Great Gastronome Tuna = 34, + King Marlin = 35, + Great King Marlin = 35, + 楔虫 = 36, + Goldenfish = 37, + Platinumfish = 37, + Great Goldenfish = 37, + Great Platinumfish = 37, + Goldenfry = 38, + Great Goldenfry = 38, + Sushifish = 39, + Great Sushifish = 39, + Gunpowderfish = 40, + Great Gunpowderfish = 40, + Copper Calappa = 41, + Gold Calappa = 41, + Tsuchinoko = 42, + Cactuar = 43, + Cactuar Cutting = 43, + Flowering Cactuar Cutting = 43, + Nekker = 44, + Pearlspring Macaque = 50, + Goldspring Macaque = 50, + Crowned Prawn = 51, + Moon Slug = 52, + Duffel Penguin = 53, + Arrowhead Gekko = 54, + Blue Diva = 55, + Sealord's Crestfish = 56, + Glass Parexus = 57, + Great Glass Parexus = 57, + Wintermoon Nettle = 58, + Moly = 59, + Mossy Moly = 59, + Rocky Moly = 59, + Fluffy Moly = 59, + Spiny Moly = 59, + Rowdy Moly = 59, + Frosty Moly = 59 + */ + } +} diff --git a/Armor.cs b/Armor.cs new file mode 100644 index 0000000..3fef15f --- /dev/null +++ b/Armor.cs @@ -0,0 +1,3111 @@ +//#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)); + } + } + } + } +} diff --git a/Models.cs b/Models.cs new file mode 100644 index 0000000..4073716 --- /dev/null +++ b/Models.cs @@ -0,0 +1,568 @@ +using System.Numerics; +using System.Text.RegularExpressions; + +using ImGuiNET; +using SharpPluginLoader.Core.Entities; +using SharpPluginLoader.Core.Actions; +using SharpPluginLoader.Core.Components; + +namespace PlayerPoser +{ + using static Utility; + + internal static unsafe class Models + { + private static string modelFilter = ""; + private static bool modelFilterIsRegex = false; + private static Regex? modelRegex = null; + internal static bool modelOnlyAddressLod0 = false; + + private static string objectFilter = ""; + private static bool sortObjectsByDistanceToPlayer = false; + + private static int inputLmt = -1; + private static int inputAnimationId = -1; + private static int inputSet = -1; + private static int inputActionId = -1; + + internal static Vector4 rotateVector4(Vector4 rotation, Vector3 offset) + { + Quaternion rotationQ = new(rotation.X, rotation.Y, rotation.Z, rotation.W); + rotationQ *= Quaternion.CreateFromYawPitchRoll(offset.X, offset.Y, offset.Z); + return new(rotationQ.X, rotationQ.Y, rotationQ.Z, rotationQ.W); + } + + internal static bool drawRotate(string label, Vector4 rotation, out Vector4 result) + { + Vector3 offset = default; + if (ImGui.DragFloat3(label, ref offset, 0.0025f)) + { + result = rotateVector4(rotation, offset); + return true; + } + result = new(-1.0f); + return false; + } + + internal static string extractPartName(string fullString) + { + string partName = ""; + if (fullString.StartsWith("pl\\f_equip") || fullString.StartsWith("pl\\m_equip")) + { + partName = fullString.Split('\\')[3]; + } + else if (fullString.StartsWith("wp\\")) + { + string[] split = fullString.Split('\\'); + partName = (split[4] == "mod") ? split[5] : split[4]; + } + else if (fullString.StartsWith("pl\\hair")) + { + partName = fullString.Split('\\')[2]; + } + else if (fullString.StartsWith("pl\\f_face") || fullString.StartsWith("pl\\m_face")) + { + partName = fullString.Split('\\')[4].Substring(2); + } + return partName; + } + + internal static void drawModelParts(nint armorAddr, nint resourceAddr = 0x0, bool hideAll = false, bool showAll = false) + { + if (resourceAddr == 0x0) + { + if (armorAddr == 0x0 || (resourceAddr = Get(armorAddr, 0x2A0)) == 0x0) + { + return; + } + } + ImGui.PushID(resourceAddr); + string fullString = new(GetPtrInline(resourceAddr, 0xC)); + if (armorAddr != 0x0) + { + string partName = extractPartName(fullString); + ImGui.Text($"{partName} (0x{armorAddr:X}, {fullString} @ 0x{resourceAddr:X}):"); + } + else + { + ImGui.Text($"{fullString} @ 0x{resourceAddr:X}:"); + } + // MonsterHunterWorld.exe+222E651 - mov rax,[r8+000000C8] + nint baseLod = Get(resourceAddr, 0xC8); + nint baseOffset = Get(resourceAddr, 0x408 + (0x8 * 0x1)); + int numParts = Get(resourceAddr, 0x548 + (0x4 * 0x1)); + // Setting lodCount to 0 is probably the best way to completely hide a model. + int lodCount = Get(resourceAddr, 0xD0); + const int lodStructSize = 0x50; + const int partsPerLine = 10; + bool allOn = ImGui.Button("Show All") || showAll; + ImGui.SameLine(); + bool allOff = ImGui.Button("Hide All") || hideAll; + for (int i = 0; i < numParts; i++) + { + int lodOffset = Get(baseOffset, i * 0x4); + nint lod0 = baseLod + (lodOffset * lodStructSize); + ushort lod0Visible = Get(lod0); + bool isVisible = lod0Visible != 0; + bool togglePart = ImGui.Checkbox($"##Part #{i}", ref isVisible); + if (ImGui.BeginItemTooltip()) + { + ImGui.Text($"Part #{i} (0x{lod0:X})"); + ImGui.EndTooltip(); + } + int lastLod = (i < numParts - 1) ? Get(baseOffset, (i + 1) * 0x4) : lodCount; + int partLodCount = lastLod - lodOffset; + // This is not a "proper" way to hide a part. It abuses the fact that if the lower + // 16 bits (lodVisible) of these 4 bytes are 0, a check to skip rendering it will + // always pass. Also that +0xA appears to be unused/padding. + // MonsterHunterWorld.exe+222FCE3 - mov eax,[r8] + for (int j = 0; j < partLodCount; j++) + { + if (togglePart || (lod0Visible != 0 && allOff) || (lod0Visible == 0 && allOn)) + { + nint lod = lod0 + (j * lodStructSize); + ref ushort lodVisible = ref GetRef(lod); + ref ushort padSub = ref GetRef(lod, 0xA); + if (lod0Visible != 0) Assert(padSub == 0); + // Check against LOD0 to prevent an inconsistent state. + if ((lodVisible != 0) == (lod0Visible != 0)) + { + (lodVisible, padSub) = (padSub, lodVisible); + } + } + if (modelOnlyAddressLod0) break; + } + if (i != numParts - 1 && i % partsPerLine != partsPerLine - 1) + { + ImGui.SameLine(); + } + } + ImGui.PopID(); + } + + internal static void runAction(ActionController actionController, int actionSet, int actionId) + { + actionController.DoAction(actionSet, actionId); + /* + actionController.GetRef(0xC0) = actionId; + actionController.GetRef(0xBC) = actionSet; + */ + } + + internal static void drawAnimationInfo(Entity entity, float width, bool debug) + { + ActionController actionController = entity.ActionController; + ActionInfo currentActionInfo = actionController.CurrentAction; + SharpPluginLoader.Core.Actions.Action? currentAction = null; + if (currentActionInfo.ActionSet >= 0 && currentActionInfo.ActionSet <= 3) + { + ActionList actionList = actionController.GetActionList(currentActionInfo.ActionSet); + if (currentActionInfo.ActionId >= 0 && currentActionInfo.ActionId < actionList.Count) + { + currentAction = actionList[currentActionInfo.ActionId]; + } + } + if (debug) + { + ImGui.Text($"ActionController: 0x{actionController.Instance:X}"); + ImGui.Text($" Current: {currentAction} {currentActionInfo}"); + if (currentAction != null) + { + + ImGui.Text($" Active Time: {currentAction.ActiveTime}"); + ImGui.Text($" Delta Sec: {currentAction.DeltaSec}"); + } + } + AnimationId currentAnimation = entity.CurrentAnimation; + AnimationLayerComponent? animationLayer = entity.AnimationLayer; + if (animationLayer != null) + { + ImGui.Text(debug ? $"AnimationLayer: 0x{animationLayer.Instance:X}" : "Animation"); + + if (debug) + { + ImGui.Text($" Current: {currentAnimation}"); + ImGui.Text($" Frame: {animationLayer.CurrentFrame:0.000}/{animationLayer.MaxFrame:0.000}"); + } + else + { + ImGui.Text($" Current: {currentAnimation.Lmt}.{currentAnimation.Id}, {(currentAction != null ? currentAction.Name : "None")} ({currentActionInfo.ActionSet}.{currentActionInfo.ActionId})"); + if (ImGui.BeginItemTooltip()) + { + ImGui.Text("{Lmt}.{Id}, {Action} ({Set}.{Id})"); + ImGui.EndTooltip(); + } + ImGui.SetNextItemWidth(width * 0.85f); + ImGui.SliderFloat("Frame", ref animationLayer.CurrentFrame, 0.0f, animationLayer.MaxFrame, "%.3f"); + bool animationPaused = animationLayer.Paused; + if (ImGui.Checkbox("Paused", ref animationPaused)) + { + animationLayer.Paused = animationPaused; + } + ImGui.SameLine(); + float? lockedSpeed = animationLayer.LockedSpeed; + float speed = lockedSpeed ?? animationLayer.Speed; + bool animationLocked = lockedSpeed != null; + if (ImGui.Checkbox("Set", ref animationLocked)) + { + if (animationLocked) + { + animationLayer.LockSpeed(speed); + } + else + { + animationLayer.UnlockSpeed(); + } + } + ImGui.SameLine(); + ImGui.SetNextItemWidth(width * 0.2f); + if (ImGui.DragFloat($"Speed", ref speed, 0.01f, 0.0f, 0.0f, "%.3f")) + { + if (animationLocked) animationLayer.LockSpeed(speed); + } + } + + if (debug) + { + ImGui.PushItemWidth(width * 0.075f); + ImGui.PushID("Animation"); + bool animationValid = inputLmt >= 0 && inputAnimationId >= 0; + if (!animationValid) + { + ImGui.PushItemFlag(ImGuiItemFlags.Disabled, true); + ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * 0.5f); + } + bool doAnimation = ImGui.Button("Do"); + if (!animationValid) + { + ImGui.PopStyleVar(); + ImGui.PopItemFlag(); + } + ImGui.SameLine(); + ImGui.InputInt("Lmt", ref inputLmt, 0); + ImGui.SameLine(); + ImGui.InputInt("Animation Id", ref inputAnimationId, 0); + ImGui.PopID(); + ImGui.PushID("Action"); + bool actionValid = inputSet >= 0 && inputActionId >= 0; + if (!actionValid) + { + ImGui.PushItemFlag(ImGuiItemFlags.Disabled, true); + ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * 0.5f); + } + bool doAction = ImGui.Button("Do"); + if (!actionValid) + { + ImGui.PopStyleVar(); + ImGui.PopItemFlag(); + } + ImGui.SameLine(); + ImGui.InputInt("Set", ref inputSet, 0); + ImGui.SameLine(); + float widthDiff = ImGui.CalcTextSize("Lmt").X - ImGui.CalcTextSize("Set").X; + ImGui.SetCursorPos(ImGui.GetCursorPos() + new Vector2(widthDiff, 0.0f)); + ImGui.InputInt("Action Id", ref inputActionId, 0); + ImGui.PopID(); + if (!(animationValid && actionValid)) + { + ImGui.PushItemFlag(ImGuiItemFlags.Disabled, true); + ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * 0.5f); + } + if (ImGui.Button("Do Both")) + { + doAnimation = true; + doAction = true; + } + if (!(animationValid && actionValid)) + { + ImGui.PopStyleVar(); + ImGui.PopItemFlag(); + } + if (doAction) + { + runAction(actionController, inputSet, inputActionId); + } + if (doAnimation) + { + animationLayer.DoAnimation(new AnimationId((uint)inputLmt, (uint)inputAnimationId)); + } + ImGui.PopItemWidth(); + } + } + } + + private static void iterList(nint baseAddr, Action func) + { + nint next = baseAddr; + nint head = next; + nint prev = Get(next, 0x10); + for (;next != 0x0;) + { + func(next + 0x40); + if (head == prev) + { + next = Get(next, 0x10); + } + else + { + next = Get(next, 0x18); + if (next == 0x0) + { + head = prev; + next = prev; + } + } + } + } + + internal static void drawModelList(float width, nint baseObject) + { + ImGui.PushID("Models"); + ImGui.Text("Filter"); + bool updateRegex = false; + bool invalidRegex = modelFilterIsRegex && modelFilter != "" && modelRegex == null; + if (invalidRegex) + { + ImGui.PushStyleColor(ImGuiCol.Text, 0xFF0000FF); + } + ImGui.SetNextItemWidth(width * 0.55f); + if (ImGui.InputText("##Filter", ref modelFilter, 256)) + { + if (modelFilterIsRegex) + { + updateRegex = true; + } + } + if (invalidRegex) + { + ImGui.PopStyleColor(); + } + ImGui.SameLine(); + if (ImGui.Button("Clear")) + { + modelFilter = ""; + if (modelFilterIsRegex) + { + updateRegex = true; + } + } + ImGui.SameLine(); + if (ImGui.Checkbox("Regex", ref modelFilterIsRegex)) + { + if (modelFilterIsRegex) + { + updateRegex = true; + } + } + if (updateRegex) + { + if (String.IsNullOrEmpty(modelFilter)) + { + modelRegex = null; + } + else + { + try + { + modelRegex = new Regex(modelFilter); + } + catch (ArgumentException) + { + modelRegex = null; + } + } + } + bool hideEverything = ImGui.Button("Hide Everything"); + ImGui.SameLine(); + bool showEverything = ImGui.Button("Show Everything"); + nint baseObjectResource = Get(baseObject, 0x2A0); + if (baseObjectResource != 0x0) + { + iterList(baseObjectResource - 0x40, (partAddr) => + { + ImGui.PushID(partAddr); + nint vTable = Get(partAddr); + if (vTable == 0x143507A18) + { + string fullString = new(GetPtrInline(partAddr, 0xC)); + bool filterMatch = false; + if (modelFilterIsRegex) + { + filterMatch = modelRegex == null || modelRegex.Match(fullString).Success; + } + else + { + filterMatch = String.IsNullOrEmpty(modelFilter) || fullString.StartsWith(modelFilter); + } + if (filterMatch) + { + drawModelParts(0x0, partAddr, hideEverything, showEverything); + } + } + ImGui.PopID(); + }); + } + ImGui.PopID(); + } + + private static void searchUnitList(long addr, List objects) + { + nint baseAddr = Get(addr); + if (baseAddr == 0x0) return; + baseAddr = Get(baseAddr, 0xB8); + if (baseAddr == 0x0) return; + iterList(baseAddr + 0x40, (objectAddr) => + { + nint vTable = Get(objectAddr); + if (vTable == 0x14341F728 || vTable == 0x1434A9720) // Instanced Model || uScrMotionModel + { + objects.Add(objectAddr); + } + }); + } + + internal static void drawObjectList(float width, Player player) + { + List objects = new(); + searchUnitList(0x1450ECA20, objects); + searchUnitList(0x1450EC980, objects); + ImGui.PushID("Objects"); + ImGui.Text("Filter"); + ImGui.SetNextItemWidth(width * 0.55f); + ImGui.InputText("##Filter", ref objectFilter, 256); + ImGui.Checkbox("Sort By Distance To Player", ref sortObjectsByDistanceToPlayer); + IEnumerable enumerator = objects; + if (sortObjectsByDistanceToPlayer) + { + enumerator = Enumerable.OrderBy(objects, (x) => x, Comparer.Create((x, y) => + { + Vector3 pos = player.Position; + Vector3 xPos = default, yPos = default; + nint vTableX = Get(x); + nint vTableY = Get(y); + if (vTableX == 0x1434A9720) + { + xPos = Get(x, 0x160); + } + else if (vTableX == 0x14341F728) + { + bool instanced = (Get(x, 0x2C8) & 0x10) != 0x10; + if (instanced) + { + xPos = Get(x, 0x500); + } + else + { + xPos = Get(x, 0x160); + } + } + if (vTableY == 0x1434A9720) + { + yPos = Get(y, 0x160); + } + else if (vTableY == 0x14341F728) + { + bool instanced = (Get(y, 0x2C8) & 0x10) != 0x10; + if (instanced) + { + yPos = Get(y, 0x500); + } + else + { + yPos = Get(y, 0x160); + } + } + float distX = Vector3.Distance(pos, xPos); + float distY = Vector3.Distance(pos, yPos); + if (distX < distY) return -1; + else if (distX > distY) return 1; + return 0; + })); + } + foreach (nint objectAddr in enumerator) + { + nint resourceAddr = Get(objectAddr, 0x2A0); + string fullString = new(GetPtrInline(resourceAddr, 0xC)); + bool filterMatch = string.IsNullOrEmpty(objectFilter) || (!string.IsNullOrEmpty(fullString) && fullString.StartsWith(objectFilter)); + if (!filterMatch) + { + continue; + } + ImGui.PushID(objectAddr); + if (ImGui.CollapsingHeader($"{fullString} @ 0x{objectAddr:X}")) + { + nint vTable = Get(objectAddr); + if (vTable == 0x1434A9720) + { + ImGui.DragFloat3("Position", ref GetRef(objectAddr, 0x160), 0.5f); + } + else + { + bool update = GetRef(objectAddr, 0x540) == 0x1; + if (ImGui.Checkbox("Update", ref update)) + { + GetRef(objectAddr, 0x540) = ByteFlag(update); + } + ImGui.SameLine(); + bool instanced = (GetRef(objectAddr, 0x2C8) & 0x10) == 0x10; + if (ImGui.Checkbox("Instanced", ref instanced)) + { + if (instanced) + { + GetRef(objectAddr, 0x2C8) |= 0x10; + } + else + { + GetRef(objectAddr, 0x2C8) &= 0xF; + GetRef(objectAddr, 0x160) = GetRef(objectAddr, 0x500); + } + } + if (instanced) + { + ImGui.DragFloat3("Position", ref GetRef(objectAddr, 0x500), 0.5f); + int instanceCount = Get(objectAddr, 0x4C0); + nint instances = Get(objectAddr, 0x4B8); + ImGui.Text($"Instances: {instanceCount} (0x{instances:X})"); + for (int i = 0; i < instanceCount; i++) + { + ImGui.PushID(instances); + ref Vector3 position = ref GetRef(instances, 0xF0); + ref Vector4 rotation = ref GetRef(instances, 0x100); + ref Vector3 scale = ref GetRef(instances, 0x110); + ImGui.DragFloat3("Position", ref position, 0.5f); + ImGui.SliderFloat4("Rotation", ref rotation, -1.0f, 1.0f); + if (drawRotate("Rotate", rotation, out Vector4 result)) + { + rotation = result; + } + ImGui.DragFloat3("Scale", ref scale, 0.025f); + ImGui.Separator(); + ImGui.PopID(); + instances += 0x1D0; + } + } + else + { + ref Vector3 position = ref GetRef(objectAddr, 0x160); + ref Vector4 rotation = ref GetRef(objectAddr, 0x170); + ref Vector3 scale = ref GetRef(objectAddr, 0x180); + ImGui.DragFloat3("Position", ref position, 0.5f); + if (ImGui.Button("Move to Player")) + { + position = new(player.Position.X, player.Position.Y - 150.0f, player.Position.Z); + } + ImGui.SliderFloat4("Rotation", ref rotation, -1.0f, 1.0f); + if (drawRotate("Rotate", rotation, out Vector4 result)) + { + rotation = result; + } + ImGui.DragFloat3("Scale", ref scale, 0.025f); + } + } + } + ImGui.PopID(); + } + ImGui.PopID(); + } + } +} diff --git a/PlayerPoser.csproj b/PlayerPoser.csproj new file mode 100644 index 0000000..0ad9e76 --- /dev/null +++ b/PlayerPoser.csproj @@ -0,0 +1,26 @@ + + + + net8.0 + enable + enable + True + + + + + + + + + ..\SharpPluginLoader-fork\SharpPluginLoader.Bootstrapper\bin\Release\net8.0\SharpPluginLoader.Bootstrapper.dll + + + ..\SharpPluginLoader-fork\SharpPluginLoader.Core\bin\Release\net8.0\SharpPluginLoader.Core.dll + + + ..\WorldTuningTool\bin\Release\net8.0\WorldTuningTool.dll + + + + diff --git a/PlayerPoser.sln b/PlayerPoser.sln new file mode 100644 index 0000000..e6cbbb9 --- /dev/null +++ b/PlayerPoser.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.12.35514.174 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{44C7FB79-D2FA-4610-89FE-8511C1A6BA7C}") = "PlayerPoser", "PlayerPoser.csproj", "{E9DE1105-BC7A-4753-9181-E7DA03727E54}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E9DE1105-BC7A-4753-9181-E7DA03727E54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E9DE1105-BC7A-4753-9181-E7DA03727E54}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E9DE1105-BC7A-4753-9181-E7DA03727E54}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E9DE1105-BC7A-4753-9181-E7DA03727E54}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Plugin.cs b/Plugin.cs new file mode 100644 index 0000000..2173bae --- /dev/null +++ b/Plugin.cs @@ -0,0 +1,722 @@ +using System.Numerics; + +using ImGuiNET; +using SharpPluginLoader.Core; +using SharpPluginLoader.Core.Memory; +using SharpPluginLoader.Core.View; +using SharpPluginLoader.Core.Entities; +using SharpPluginLoader.Core.Rendering; + +namespace PlayerPoser +{ + using static Utility; + + public unsafe class Plugin : IPlugin + { + public string Name => "Player Poser"; + public string Author => "Akon City Software"; + + private const string fontPath = "nativePC/plugins/CSharp/Fonts/Catrinity.otf"; + private bool tryCustomFont = false; + + internal static readonly MtObject sMhArea = SingletonManager.GetSingleton("sMhArea")!; + + internal static readonly MtObject sPlayer = SingletonManager.GetSingleton("sPlayer")!; + internal static readonly MtObject sOtomo = SingletonManager.GetSingleton("sOtomo")!; + + internal static readonly MtObject sUserData = SingletonManager.GetSingleton("sUserData")!; + + private bool hideWeapon = false; + private NativeAction hideWeaponFunc; + private bool hideKnife = false; + private bool hideSlinger = false; + private bool updateHideSlinger = false; + + private static bool overridePlayerWetness = false; + private static float headWetness = 0.0f; + private static float bodyWetness = 0.0f; + private static float waistWetness = 0.0f; + private static float legsWetness = 0.0f; + private Patch noopPlayerWetnessUpdate; + private Patch jmpOverChangeEquipmentWetnessUpdate_1; + private Patch jmpOverChangeEquipmentWetnessUpdate_2; + + private void overridePlayerWetnessEnable() + { + noopPlayerWetnessUpdate.Enable(); + jmpOverChangeEquipmentWetnessUpdate_1.Enable(); + jmpOverChangeEquipmentWetnessUpdate_2.Enable(); + } + + private void overridePlayerWetnessDisable() + { + noopPlayerWetnessUpdate.Disable(); + jmpOverChangeEquipmentWetnessUpdate_1.Disable(); + jmpOverChangeEquipmentWetnessUpdate_2.Disable(); + } + + private float playerOpacityOverride = 1.0f; + private float palicoOpacityOverride = 1.0f; + private delegate void UpdateCharacterParams(nint characterObject, nint unknownPtr); + private Hook? updateCharacterParams; + private delegate void UpdatePalicoFade(nint palicoObject); + private Hook? updatePalicoFade; + + private bool disableCollision = false; + private bool disableExtraCollision = false; + private bool disableGravity = false; + private bool disableExtraGravity = false; + private Patch disableXCollision; + private Patch disableYCollision; + private Patch disableSecondaryYCollision; + private Patch disableZCollision; + private Patch disableExtraYCollision; + private Patch disableGravityYUpdate; + private Patch disableGravityXZUpdate; + private Patch disableGravityEval; + + private void disableCollisionEnable() + { + disableXCollision.Enable(); + disableYCollision.Enable(); + disableSecondaryYCollision.Enable(); + disableZCollision.Enable(); + } + + private void disableCollisionDisable() + { + disableXCollision.Disable(); + disableYCollision.Disable(); + disableSecondaryYCollision.Disable(); + disableZCollision.Disable(); + } + + private void disableExtraCollisionEnable() + { + disableExtraYCollision.Enable(); + } + + private void disableExtraCollisionDisable() + { + disableExtraYCollision.Disable(); + } + + private void disableGravityEnable() + { + disableGravityYUpdate.Enable(); + } + + private void disableGravityDisable() + { + disableGravityYUpdate.Disable(); + } + + private void disableExtraGravityEnable() + { + disableGravityEval.Enable(); + } + + private void disableExtraGravityDisable() + { + disableGravityEval.Disable(); + } + + private bool sortMonsters; + private bool sortAnimals; + + public PluginData Initialize() + { + PluginData data = new PluginData(); + + if (File.Exists(fontPath)) + { + Renderer.RegisterFont("Catrinity", fontPath, 21.0f, GlyphRangeFactory.CreateGlyphRanges([ + (0x0020, 0x00FF), (0x2640, 0x2642) // Gender symbols. + ])); + tryCustomFont = true; + } + + Utility.Initialize(); + Zone.Initialize(); + Armor.Initialize(); + + hideWeaponFunc = new NativeAction(0x141789AB0); + + updateCharacterParams = Hook.Create(0x141F605F0, UpdateCharacterParamsHook); + updatePalicoFade = Hook.Create(0x14201D130, UpdatePalicoFadeHook); + + noopPlayerWetnessUpdate = new Patch(0x14203E893, [0x90, 0x90, 0x90, 0x90, 0x90]); + jmpOverChangeEquipmentWetnessUpdate_1 = new Patch(0x14203E310, [0xEB]); // je -> jmp. + jmpOverChangeEquipmentWetnessUpdate_2 = new Patch(0x14203E397, [0xE9, 0xB9, 0x00, 0x00, 0x00, 0x90]); // je -> jmp. + + // Noop collision checks. + nint addr = PatternScanner.FindFirst(Pattern.FromString("F3 0F 11 06 F3 0F 10 48 04 F3 0F 58 4E 04 F3 0F 11 4E 04 F3 0F 10 40 08 F3 0F 58 46 08 F3 0F 11 46 08 44 8B AF E0 0B 00 00")); + Assert(addr == 0x141C001B5); + disableXCollision = new Patch(addr, [0x90, 0x90, 0x90, 0x90]); + Assert(addr + 0xE == 0x141C001C3); + disableYCollision = new Patch(addr + 0xE, [0x90, 0x90, 0x90, 0x90, 0x90]); + Assert(addr + 0x1D == 0x141C001D2); + disableZCollision = new Patch(addr + 0x1D, [0x90, 0x90, 0x90, 0x90, 0x90]); + + addr = PatternScanner.FindFirst(Pattern.FromString("F3 0F 11 46 04 F3 0F 10 46 08 F3 0F 5C C2 F3 0F 11 46 08 ?? ?? F3 0F")); + Assert(addr == 0x141C000D2); + disableSecondaryYCollision = new Patch(addr, [0x90, 0x90, 0x90, 0x90, 0x90]); + + addr = PatternScanner.FindFirst(Pattern.FromString("F3 0F 11 46 04 F3 0F 10 58 08 F3 0F 58 5E 08 F3 0F 11 5E 08 44 8B 87 D0 0B 00 00 41 F6 C0 03")); + Assert(addr == 0x141BFFF90); + disableExtraYCollision = new Patch(addr, [0x90, 0x90, 0x90, 0x90, 0x90]); + + addr = PatternScanner.FindFirst(Pattern.FromString("F3 0F 11 83 80 00 00 00 F3 0F 11 8B 84 00 00 00 F3 0F 11 93 88 00 00 00 89 B3 8C 00 00 00 8B 83 A4 01 00 00 C1 E8 05 44 0F 29 A4 24 D0 01 00 00 44 0F 29 B4 24 B0 01 00 00 A8 01")); + Assert(addr + 0x8 == 0x1413259ED); + disableGravityYUpdate = new Patch(addr + 0x8, [ + 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, + ]); + disableGravityXZUpdate = new Patch(addr, [ + 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, + 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, // Will already be applied. + 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 + ]); + + addr = PatternScanner.FindFirst(Pattern.FromString("F3 0F 11 97 54 15 00 00 F3 0F 11 8F 58 15 00 00 F3 0F 10 47 68 F3 0F 5E D8 44 89 B7 6C 15 00 00 F3 0F 5E D0 F3 0F 5E C8 F3 0F 11 9F 60 15 00 00 F3 0F 11 97 64 15 00 00 F3 0F 11 8F 68 15 00 00")); + Assert(addr + 0x40 == 0x141BFFF75); + disableGravityEval = new Patch(addr + 0x40, [0x90, 0x90, 0x90, 0x90, 0x90]); // call MonsterHunterWorld.exe+1325810. + + return data; + } + + private void perFrameHideEquipment(Player player) + { + if (hideWeapon) + { + hideWeaponFunc.Invoke(player.Instance, 0); + /* + // MonsterHunterWorld.exe+1789ABA - mov rdi,[rcx+000076B0] + nint weapon = player.Get(0x76B0); + if (weapon != 0x0) + { + GetRef(weapon, 0x1A98) = 0x1; + int weaponParts = Get(weapon, 0x2250); + for (int i = 0; i < weaponParts; i++) + { + nint part = Get(weapon, (i + 0x16B) * 24); + if (part != 0x0) + { + GetRef(part, 0x1A98) = 0x1; + } + } + } + */ + } + + if (hideKnife) + { + // Emulate what Carving and Flourish emote do at + // MonsterHunterWorld.exe+1F68832 - bts eax,06 + // if set, skips + // MonsterHunterWorld.exe+203A0D2 - bts ecx,01 + player.GetRef(0x8938) |= (1 << 6); + player.GetRef(0x8968) |= (1 << 6); + /* + if (playerArmor[Armor.Waist] != 0x0) + { + if (hideKnife) + { + GetRef(playerArmor[Armor.Waist], 0x2D0) &= 0xFD; + } + else + { + GetRef(playerArmor[Armor.Waist], 0x2D0) |= 0x2; + } + } + */ + } + + if (hideSlinger || updateHideSlinger) + { + nint slinger = player.Get(0x8918); + if (slinger != 0) + { + // MonsterHunterWorld.exe+AD9CC6 - cmp [rdi+000019E7],bl + // MonsterHunterWorld.exe+AD8A10 - and [rbx+000002D0],FFFFFE1E + GetRef(slinger, 0x19E7) = ByteFlag(hideSlinger); + updateHideSlinger = false; + } + } + } + + internal static void OnPlayerChange() + { + Armor.OnPlayerChange(); + } + + public void OnUpdate(float deltaTime) + { + Utility.OnUpdate(); + Armor.OnUpdate(); + + Player? player = getPlayer(); + if (player != null) + { + perFrameHideEquipment(player); + } + } + + internal static void OnZoneChange(nint player) + { + if (overridePlayerWetness) + { + nint wetnessAddr = player + 0x13BD0; + GetRef(wetnessAddr) = headWetness; + GetRef(wetnessAddr, 0x28) = bodyWetness; + GetRef(wetnessAddr, 0x50) = waistWetness; + GetRef(wetnessAddr, 0x78) = legsWetness; + } + } + + private void UpdateCharacterParamsHook(nint characterObject, nint unknownPtr) + { + updateCharacterParams!.Original(characterObject, unknownPtr); + + if (playerOpacityOverride != 1.0f) + { + Player? player = getPlayer(); + if (player != null && characterObject == player.Instance) + { + player.GetRef(0x78E0) = playerOpacityOverride; + } + } + } + + public void UpdatePalicoFadeHook(nint palicoObject) + { + updatePalicoFade!.Original(palicoObject); + + if (palicoOpacityOverride != 1.0f) + { + NativeWrapper palico = getPalico(); + if (palico != 0x0 && palicoObject == palico) + { + palico.GetRef(0x314) = palicoOpacityOverride; + } + } + } + + private void drawPlayerName(NativeWrapper playerSettings, bool isFemale) + { + string playerName = new(playerSettings.GetPtrInline(0x50)); + string genderSymbol; + if (tryCustomFont) + { + ImGui.PushFont(Renderer.GetFont("Catrinity")); + genderSymbol = isFemale ? "♀" : "♂"; + } + else + { + genderSymbol = isFemale ? "(F)" : "(M)"; + } + ImGui.Text($"{playerName}"); + ImGui.SameLine(); + if (isFemale) + { + ImGui.PushStyleColor(ImGuiCol.Text, (uint)ColorVectorToInt(ImGui.GetStyle().Colors[(int)ImGuiCol.PlotHistogram])); + } + else + { + ImGui.PushStyleColor(ImGuiCol.Text, (uint)ColorVectorToInt(ImGui.GetStyle().Colors[(int)ImGuiCol.PlotLinesHovered])); + } + ImGui.SetCursorPos(ImGui.GetCursorPos() - new Vector2(4.0f, (tryCustomFont && isFemale) ? -1.0f : 0.0f)); + ImGui.Text($"{genderSymbol}"); + ImGui.PopStyleColor(); + if (tryCustomFont) + { + ImGui.PopFont(); + } + ImGui.SetCursorPos(ImGui.GetCursorPos() + new Vector2(0.0f, 2.0f)); + } + + public void OnRender() + { + Armor.OnRender(); + } + + public void OnImGuiRender() + { + float width = ImGui.GetWindowWidth(); + width /= width / 600.0f; + + Player? player = getPlayer(); + NativeWrapper playerSettings = new(0x0); + if (player == null) + { + ImGui.Text("Player not found"); + goto debug; + } + playerSettings = getPlayerSettings(); + + bool isFemale = player.Get(0x1371C) == 1; + drawPlayerName(playerSettings, isFemale); + + ImGui.Checkbox("Hide Weapon", ref hideWeapon); + ImGui.SameLine(); + ImGui.Checkbox("Hide Knife", ref hideKnife); + ImGui.SameLine(); + if (ImGui.Checkbox("Hide Slinger", ref hideSlinger)) + { + updateHideSlinger = true; + } + + ImGui.AlignTextToFramePadding(); + ImGui.Text("Head Armor Display"); + // MonsterHunterWorld.exe+11A2967 - cmp byte ptr [rax+001403E1],01 + ref byte showHeadArmor = ref playerSettings.GetRef(0x1403E1); + int showHeadArmorInt = showHeadArmor; + ImGui.SameLine(); + if (ImGui.RadioButton("Show", ref showHeadArmorInt, 0)) + { + showHeadArmor = (byte)showHeadArmorInt; + } + ImGui.SameLine(); + if (ImGui.RadioButton("Hide", ref showHeadArmorInt, 1)) + { + showHeadArmor = (byte)showHeadArmorInt; + } + ImGui.SameLine(); + if (ImGui.RadioButton("Hide in Cutscenes", ref showHeadArmorInt, 2)) + { + showHeadArmor = (byte)showHeadArmorInt; + } + + if (ImGui.CollapsingHeader("Armor Parts")) + { + Armor.drawArmorParts(player, width); + } + + ImGui.PushID("Opacity"); + ref float playerOpacity = ref player.GetRef(0x78E0); + if (ImGui.Button("Reset")) + { + playerOpacity = 1.0f; + playerOpacityOverride = 1.0f; + } + ImGui.SameLine(); + ImGui.SetNextItemWidth(width * 0.3f); + if (ImGui.DragFloat("Opacity", ref playerOpacity, 0.01f, 0.0f, Single.MaxValue)) + { + playerOpacityOverride = playerOpacity; + } + NativeWrapper palico = getPalico(); + if (palico != 0x0) + { + ImGui.PushID("Palico"); + ref float palicoOpacity = ref palico.GetRef(0x314); + if (ImGui.Button("Reset")) + { + palicoOpacity = 1.0f; + palicoOpacityOverride = 1.0f; + } + ImGui.SameLine(); + ImGui.SetNextItemWidth(width * 0.3f); + if (ImGui.DragFloat("Palico Opacity", ref palicoOpacity, 0.01f, 0.0f, Single.MaxValue)) + { + palicoOpacityOverride = palicoOpacity; + } + ImGui.PopID(); + } + ImGui.PopID(); + + ImGui.PushID("Wetness"); + if (ImGui.CollapsingHeader("Wetness")) + { + nint wetnessAddr = player.Instance + 0x13BD0; + ref float head = ref GetRef(wetnessAddr); + ref float body = ref GetRef(wetnessAddr, 0x28); + ref float waist = ref GetRef(wetnessAddr, 0x50); + ref float legs = ref GetRef(wetnessAddr, 0x78); + ImGui.PushItemWidth(width * 0.2f); + if (ImGui.DragFloat("Head", ref headWetness, 0.005f)) + { + head = headWetness; + } + ImGui.SameLine(); + ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * disableAlphaFactor); + ImGui.Text($"(Current: {head})"); + ImGui.PopStyleVar(); + if (ImGui.DragFloat("Body", ref bodyWetness, 0.005f)) + { + body = bodyWetness; + } + ImGui.SameLine(); + ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * disableAlphaFactor); + ImGui.Text($"(Current: {body})"); + ImGui.PopStyleVar(); + if (ImGui.DragFloat("Waist", ref waistWetness, 0.005f)) + { + waist = waistWetness; + } + ImGui.SameLine(); + ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * disableAlphaFactor); + ImGui.Text($"(Current: {waist})"); + ImGui.PopStyleVar(); + if (ImGui.DragFloat("Legs", ref legsWetness, 0.005f)) + { + legs = legsWetness; + } + ImGui.SameLine(); + ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * disableAlphaFactor); + ImGui.Text($"(Current: {legs})"); + ImGui.PopStyleVar(); + ImGui.PopItemWidth(); + if (ImGui.Button("Reset")) + { + head = headWetness = 0.0f; + body = bodyWetness = 0.0f; + waist = waistWetness = 0.0f; + legs = legsWetness = 0.0f; + } + ImGui.SameLine(); + if (ImGui.Checkbox("Override Player Wetness", ref overridePlayerWetness)) + { + if (overridePlayerWetness) + { + overridePlayerWetnessEnable(); + head = headWetness; + body = bodyWetness; + waist = waistWetness; + legs = legsWetness; + } + else + { + overridePlayerWetnessDisable(); + } + } + } + ImGui.PopID(); + + if (ImGui.CollapsingHeader("Skin Tone")) + { + Armor.drawSkinTone(player, playerSettings, width); + } + + ImGui.PushID("Position"); + ImGui.PushItemWidth(width * 0.75f); + ImGui.DragFloat3("Position", ref player.Position, 0.5f); + Vector3 forward = new(player.Forward.X, player.Forward.Y, player.Forward.Z); + ImGui.DragFloat3("Forward", ref forward, 0.0f); + Vector4 rotation = new(player.Rotation.X, player.Rotation.Y, player.Rotation.Z, player.Rotation.W); + ImGui.SliderFloat4("Rotation", ref rotation, -1.0f, 1.0f); + if (Models.drawRotate("Rotate", rotation, out Vector4 result)) + { + player.Rotation = new(result.X, result.Y, result.Z, result.W); + } + ImGui.PopItemWidth(); + if (ImGui.Button("Reset")) + { + player.Rotation.X = 0.0f; + player.Rotation.Z = 0.0f; + } + ImGui.PopID(); + + if (ImGui.Checkbox("Disable Some Collision", ref disableCollision)) + { + if (disableCollision) + { + disableCollisionEnable(); + } + else + { + disableCollisionDisable(); + } + } + ImGui.SameLine(); + if (ImGui.Checkbox("Disable Another Y Collision", ref disableExtraCollision)) + { + if (disableExtraCollision) + { + disableExtraCollisionEnable(); + } + else + { + disableExtraCollisionDisable(); + } + } + if (ImGui.BeginItemTooltip()) + { + ImGui.Text("This will make your legs goofy, but is needed to get on top of some things."); + ImGui.EndTooltip(); + } + + if (ImGui.Checkbox("Disable Height Check", ref disableGravity)) + { + if (disableGravity) + { + if (!disableExtraGravity) + { + disableExtraGravityEnable(); + disableExtraGravity = true; + } + disableGravityEnable(); + } + else + { + disableGravityDisable(); + } + } + if (ImGui.BeginItemTooltip()) + { + ImGui.Text("Avoid falling when going too high."); + ImGui.EndTooltip(); + } + ImGui.SameLine(); + float widthDiff = ImGui.CalcTextSize("Disable Some Collision").X - ImGui.CalcTextSize("Disable Height Check").X; + ImGui.SetCursorPos(ImGui.GetCursorPos() + new Vector2(widthDiff, 0.0f)); + if (ImGui.Checkbox("Disable Gravity", ref disableExtraGravity)) + { + if (disableExtraGravity) + { + disableExtraGravityEnable(); + } + else + { + disableExtraGravityDisable(); + } + } + if (ImGui.BeginItemTooltip()) + { + ImGui.Text("Avoid falling when going out of bounds or rotating."); + ImGui.EndTooltip(); + } + + Zone.drawUI(player, getSaveSlotIndex() >= 0, width); + + Models.drawAnimationInfo(player, width, false); + + Armor.drawPoser(player, width); + + debug: + if (ImGui.CollapsingHeader("DEBUG")) + { + drawDebugMenu(player, playerSettings, width); + } + } + + private void drawDebugMenu(Player? player, NativeWrapper playerSettings, float width) + { + ImGui.PushID("Player"); + ImGui.Text("Player"); + ImGui.Text($"sPlayer: 0x{sPlayer.Instance:X}"); + if (player != null) + { + ImGui.Text($"Address: 0x{player.Instance:X}"); + ImGui.Text($"Settings: 0x{playerSettings.Instance:X}"); + + Models.drawAnimationInfo(player, width, true); + + ImGui.Separator(); + } + ImGui.PopID(); + + ImGui.PushID("Palico"); + ImGui.Text("Palico/Otomo"); + ImGui.Text($"sOtomo: 0x{sOtomo.Instance:X}"); + ImGui.PopID(); + + if (ImGui.CollapsingHeader("Monsters")) + { + Monster[] monsters = Monster.GetAllMonsters(); + ImGui.Text($"Count: {monsters.Length}"); + ImGui.Checkbox("Sort by distance from camera", ref sortMonsters); + Viewport vp = CameraSystem.GetViewport(0); + if (sortMonsters && vp.Camera != null) + { + Array.Sort(monsters, delegate(Monster x, Monster y) + { + float distX = Vector3.Distance(vp.Camera.Position, x.Position); + float distY = Vector3.Distance(vp.Camera.Position, y.Position); + if (distX < distY) return 1; + else if (distX > distY) return -1; + return 0; + }); + } + for (int i = monsters.Length - 1; i >= 0; i--) + { + Monster monster = monsters[i]; + ImGui.PushID(monster.Instance); + ImGui.Text($"{monster.Name}:"); + ImGui.Text($" Address: 0x{monster.Instance:X}"); + ImGui.DragFloat3("Position", ref monster.Position, 0.5f); + Vector4 rotation = new(monster.Rotation.X, monster.Rotation.Y, monster.Rotation.Z, monster.Rotation.W); + ImGui.SliderFloat4("Rotation", ref rotation, -1.0f, 1.0f); + if (Models.drawRotate("Rotate", rotation, out Vector4 result)) + { + monster.Rotation = new(result.X, result.Y, result.Z, result.W); + } + Models.drawAnimationInfo(monster, width, true); + ImGui.PopID(); + ImGui.Separator(); + } + } + + if (ImGui.CollapsingHeader("Animals")) + { + Animal[] animals = Animal.GetAllAnimals(); + ImGui.Text($"Count: {animals.Length}"); + ImGui.Checkbox("Sort by distance from camera", ref sortAnimals); + Viewport vp = CameraSystem.GetViewport(0); + if (sortAnimals && vp.Camera != null) + { + Array.Sort(animals, delegate(Animal x, Animal y) + { + float distX = Vector3.Distance(vp.Camera.Position, x.Position); + float distY = Vector3.Distance(vp.Camera.Position, y.Position); + if (distX < distY) return 1; + else if (distX > distY) return -1; + return 0; + }); + } + for (int i = animals.Length - 1; i >= 0; i--) + { + Animal animal = animals[i]; + ImGui.PushID(animal.Instance); + ImGui.Text($"{animal.Id:X} ({animal.OtherId:X}):"); + ImGui.Text($" Address: 0x{animal.Instance:X}"); + ImGui.DragFloat3("Position", ref animal.Position, 0.5f); + Vector4 rotation = new(animal.Rotation.X, animal.Rotation.Y, animal.Rotation.Z, animal.Rotation.W); + ImGui.SliderFloat4("Rotation", ref rotation, -1.0f, 1.0f); + if (Models.drawRotate("Rotate", rotation, out Vector4 result)) + { + animal.Rotation = new(result.X, result.Y, result.Z, result.W); + } + if (ImGui.Button("Remove")) + { + MemoryUtil.GetRef(animal.Instance + 0x928) = 0xFFFFFFFF; + } + ImGui.PopID(); + ImGui.Separator(); + } + } + + ImGui.Checkbox("Only Toggle LOD 0", ref Models.modelOnlyAddressLod0); + if (ImGui.BeginItemTooltip()) + { + ImGui.Text($"This can be used to check if a given model is showing LOD 0 or not.\nApplies when a part is toggled, meaning you should probably toggle all parts on before enabling this."); + ImGui.EndTooltip(); + } + bool expand = ImGui.CollapsingHeader("Loaded Models"); + if (expand && player != null) + { + Models.drawModelList(width, player.Instance); + } + + expand = ImGui.CollapsingHeader("Objects"); + if (ImGui.BeginItemTooltip()) + { + ImGui.Text("This reads from the list of objects to be updated.\nTherefore, at any given moment it could be empty."); + ImGui.EndTooltip(); + } + if (expand && player != null) + { + Models.drawObjectList(width, player); + } + } + } +} diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..2f7d6da --- /dev/null +++ b/README.txt @@ -0,0 +1,3 @@ +== Player Poser + +// vim: set syntax=asciidoc: diff --git a/Utility.cs b/Utility.cs new file mode 100644 index 0000000..6ea08f1 --- /dev/null +++ b/Utility.cs @@ -0,0 +1,214 @@ +#define ENABLE_ASSERTS + +using System.Numerics; +using System.Text; +using System.Globalization; +#if ENABLE_ASSERTS +using System.Diagnostics; +using System.Runtime.CompilerServices; +#endif + +using SharpPluginLoader.Core; +using SharpPluginLoader.Core.MtTypes; +using SharpPluginLoader.Core.Memory; +using SharpPluginLoader.Core.Entities; + +namespace PlayerPoser +{ + using static Plugin; + + internal static unsafe class Utility + { + internal const float disableAlphaFactor = 0.6f; + + private static bool loggedAssertFailed = false; + internal static void Assert(bool condition, [CallerLineNumber] int line = 0) + { + if (!condition && !loggedAssertFailed) + { + Log.Error($"Assert failed on line {line}, further asserts won't be logged."); + loggedAssertFailed = true; + } +#if ENABLE_ASSERTS + Trace.Assert(condition); +#endif + } + + internal static byte ByteFlag(bool f) { return f ? (byte)0x1 : (byte)0x0; } + + internal static T Get(nint addr, nint offset = 0x0) where T : unmanaged + { + return MemoryUtil.Read(addr + offset); + } + + internal static T Get(long addr, nint offset = 0x0) where T : unmanaged + { + return MemoryUtil.Read((nint)addr + offset); + } + + internal static T *GetPtrInline(nint addr, nint offset = 0x0) where T : unmanaged + { + return (T *)(addr + offset); + } + + internal static ref T GetRef(nint addr, nint offset = 0x0) where T : unmanaged + { + return ref MemoryUtil.GetRef(addr + offset); + } + + internal static int ColorVectorToInt(Vector4 v) + { + return ((int)MathF.Round(v.X * 255.0f) | + ((int)MathF.Round(v.Y * 255.0f) << 8) | + ((int)MathF.Round(v.Z * 255.0f) << 16) | + ((int)MathF.Round(v.W * 255.0f) << 24)); + } + + internal static byte[] StringToCStr(string s) + { + return Encoding.ASCII.GetBytes(s + '\0'); + } + + internal static float StringToSingle(string s) { return Convert.ToSingle(s, CultureInfo.InvariantCulture); } + + internal static Vector3 StringToVector3(string s, char delim = ',') + { + if (string.IsNullOrEmpty(s)) throw new FormatException(); + string[] sp = s.Split(delim).Select((v) => v.Trim()).ToArray(); + if (sp.Length != 3) throw new FormatException(); + return new Vector3(StringToSingle(sp[0]), StringToSingle(sp[1]), StringToSingle(sp[2])); + } + + internal static Vector4 StringToVector4(string s, char delim = ',') + { + if (string.IsNullOrEmpty(s)) throw new FormatException(); + string[] sp = s.Split(delim).Select((v) => v.Trim()).ToArray(); + if (sp.Length != 4) throw new FormatException(); + return new Vector4(StringToSingle(sp[0]), StringToSingle(sp[1]), StringToSingle(sp[2]), StringToSingle(sp[3])); + } + + internal static string Vector3ToString(Vector3 v) + { + return string.Format(CultureInfo.InvariantCulture, "{0},{1},{2}", v.X, v.Y, v.Z); + } + + internal static string Vector4ToString(Vector4 v) + { + return string.Format(CultureInfo.InvariantCulture, "{0},{1},{2},{3}", v.X, v.Y, v.Z, v.W); + } + + internal static void getDirectionVectors(MtQuaternion rotation, out Vector3 forward, out Vector3 right, out Vector3 up) + { + Quaternion qRotation = new(rotation.X, rotation.Y, rotation.Z, rotation.W); + forward = Vector3.Transform(new(0.0f, 0.0f, 1.0f), qRotation); + right = Vector3.Transform(new(1.0f, 0.0f, 0.0f), qRotation); + up = Vector3.Transform(new(0.0f, 1.0f, 0.0f), qRotation); + } + + private static Player? lastPlayer = null; + private static int lastSaveSlotIndex = -1; + + private delegate nint DestroyPlayerObject(nint playerObjectInternal, int unknownInt); + private static Hook? destroyPlayerObjectHook; + + private static NativeFunction getSaveSlotGuiAddr; + private static NativeFunction getPlayerSettingsAddr; + + private static NativeFunction getPalicoFunc; + + internal static void OnUpdate() + { + (lastPlayer, lastSaveSlotIndex) = getPlayerWithSaveSlot(); + } + + internal static Player? getPlayer() + { + return lastPlayer; + } + + internal static int getSaveSlotIndex() + { + return lastSaveSlotIndex; + } + + internal static NativeWrapper getPlayerSettings() + { + Assert(lastPlayer != null); + if (lastSaveSlotIndex >= 0) + { + // MonsterHunterWorld.exe+ADC442 - imul rdx,rcx,0026CC00 + nint rax = lastSaveSlotIndex * 0x26CC00; + rax += sUserData.Get(0xA8); + return new(rax); + } + // MonsterHunterWorld.exe+1B8DBB0 - movsxd rax,dword ptr [rcx+000000A0] + return new(getPlayerSettingsAddr.Invoke(sUserData.Instance)); + } + + internal static NativeWrapper getPalico() + { + return new(getPalicoFunc.Invoke(sOtomo!.Instance, 0)); + } + + private static (Player?, int) getPlayerFromSaveSlot() + { + nint guiAddr = getSaveSlotGuiAddr.Invoke(sMhArea.Instance); + if (guiAddr != 0x0) + { + // MonsterHunterWorld.exe+ADC42F - movsxd rcx,dword ptr [rax+00000334] + int saveSlotIndex = Get(guiAddr, 0x334); + if (saveSlotIndex != -1) + { + // MonsterHunterWorld.exe+1B42047 - add r8,00000740 + nint offset = (sPlayer!.Instance + 0x40) + (0x740 * saveSlotIndex); + if (offset != 0x0 && Get(offset) == 0x1433FE588) + { + nint playerAddr = Get(offset, 0x18); + if (playerAddr != 0x0) + { + return (new Player(playerAddr), saveSlotIndex); + } + } + } + } + return (null, -1); + } + + private static (Player?, int) getPlayerWithSaveSlot() + { + Player? player = Player.MainPlayer; + int saveSlotIndex = -1; + if (player == null) + { + (player, saveSlotIndex) = getPlayerFromSaveSlot(); + } + if (player != lastPlayer) + { + lastPlayer = player; + lastSaveSlotIndex = saveSlotIndex; + OnPlayerChange(); + } + return (player, saveSlotIndex); + } + + private static nint DestroyPlayerObjectHook(nint playerObjectInternal, int unknownInt) + { + if (playerObjectInternal == lastPlayer) + { + lastPlayer = null; + lastSaveSlotIndex = -1; + } + return destroyPlayerObjectHook!.Original(playerObjectInternal, unknownInt); + } + + internal static void Initialize() + { + destroyPlayerObjectHook = Hook.Create(0x142033500, DestroyPlayerObjectHook); + + getSaveSlotGuiAddr = new NativeFunction(0x141AC0B60); + getPlayerSettingsAddr = new NativeFunction(0x141B8DBB0); + + getPalicoFunc = new NativeFunction(0x141B32E00); + } + } +} diff --git a/Zone.cs b/Zone.cs new file mode 100644 index 0000000..8fb933a --- /dev/null +++ b/Zone.cs @@ -0,0 +1,343 @@ +#define QUARANTINED_FEATURES + +using System.Numerics; +using System.Runtime.InteropServices; + +using ImGuiNET; +using SharpPluginLoader.Core; +using SharpPluginLoader.Core.Memory; +using SharpPluginLoader.Core.Entities; + +namespace PlayerPoser +{ + using static Utility; + + internal static unsafe class Zone + { + internal enum ZoneState + { + Unknown = 0, + Hub = 1, + Combat = 2 + } + +#if QUARANTINED_FEATURES + private static ZoneState forceZoneState = ZoneState.Unknown; + private static ZoneState lastZoneState = ZoneState.Combat; // Save select default. + private static NativeAction setZoneStateFunc; + private static bool zoneStateManualInvoke = false; + + private static NativeAction setPlayerController1; + private static NativeAction setPlayerController5; + + private static bool forcePassiveInCombatZone = false; + private static Patch zoneStateForcePassive1; + private static Patch zoneStateForcePassive2; + + private static bool forceCombatInPassiveZone = false; + private static Patch zoneStateForceCombat1; + private static Patch zoneStateForceCombat2; +#endif + private delegate void ZoneStateDelegate(nint player, int flags); + private static Hook? setZoneState; + + private static bool enableCrawl = false; + private static nint psuedoObject1; + private static nint psuedoObject2; + private static NativeAction procEnvironmentCollision; + private delegate void CollisionCheckDelegate(nint unknownPtr1, nint unknownPtr2); + private static Hook? collisionCheck; + + private static bool allowHotSpringsAnywhere = false; + private static Patch jmpOverHotSpringsEval; + + private static bool disableHotSpringsSteam = false; + private static Patch jmpOverHotSpringsSteam; + + internal static void Initialize() + { +#if QUARANTINED_FEATURES + // MonsterHunterWorld.exe+20354F7 - call MonsterHunterWorld.exe+1F73850 + setZoneStateFunc = new NativeAction(0x142035020); + + setPlayerController1 = new NativeAction(0x141F73850); + setPlayerController5 = new NativeAction(0x14118DDC0); + + zoneStateForcePassive1 = new Patch(0x140256A3F + 0x6, [0x1]); + zoneStateForcePassive2 = new Patch(0x141AC2865 + 0x6, [0x1]); + + zoneStateForceCombat1 = new Patch(0x141AC2938 + 0x6, [0x0]); + zoneStateForceCombat2 = new Patch(0x141AC28EC + 0x6, [0x0]); +#endif + setZoneState = Hook.Create(0x142035020, SetZoneStateHook); + + psuedoObject1 = (nint)NativeMemory.AllocZeroed(0x7C); + GetRef(psuedoObject1, 0x30) = 0x03; + psuedoObject2 = (nint)NativeMemory.AllocZeroed(0x7C); + GetRef(psuedoObject2, 0x30) = 0x08; + procEnvironmentCollision = new NativeAction(0x141F737D0); + collisionCheck = Hook.Create(0x1411C4E50, CollisionCheckHook); + + // Player + ECCC = How far underwater is the player. + jmpOverHotSpringsEval = new Patch(0x1417C1B03, [0xEB]); + jmpOverHotSpringsSteam = new Patch(0x14203A494, [0xE9, 0x8D, 0x00, 0x00, 0x00, 0x90]); + } + + private static void SetZoneStateHook(nint player, int flags) + { +#if QUARANTINED_FEATURES + ref byte zoneState = ref GetRef(Get(0x1451C42B8), 0xD2EA); + if (zoneStateManualInvoke) + { + zoneStateManualInvoke = false; + } + else + { + lastZoneState = (zoneState == 0x1) ? ZoneState.Hub : ZoneState.Combat; + } + ZoneState overrideZoneState = (forceZoneState == ZoneState.Unknown) ? lastZoneState : forceZoneState; + if (overrideZoneState != ZoneState.Unknown) + { + zoneState = ByteFlag(overrideZoneState == ZoneState.Hub); + } +#endif + + setZoneState!.Original(player, flags); + + Plugin.OnZoneChange(player); + } + + private static void CollisionCheckHook(nint unknownPtr1, nint unknownPtr2) + { + Player? player = null; + if (enableCrawl && (player = getPlayer()) != null) + { + nint controlsAddr = player.Get(0x12608); + bool combatControls = controlsAddr != 0x0 && Get(controlsAddr, 0xB18) == 0x80; + if (combatControls) + { + procEnvironmentCollision.Invoke(player.Instance, psuedoObject1); + procEnvironmentCollision.Invoke(player.Instance, psuedoObject2); + } + else + { + enableCrawl = false; + } + } + + collisionCheck!.Original(unknownPtr1, unknownPtr2); + } + + private static Quaternion getRight(Quaternion q) + { + return q * Quaternion.CreateFromYawPitchRoll(MathF.PI, 0.0f, 0.0f); + } + + internal static void drawUI(Player player, bool saveSlotFallback, float width) + { + ZoneState zoneState = ZoneState.Unknown; + nint zoneStateAddr = Get(0x1451C42B8); + if (zoneStateAddr == 0x0) + { + return; + } + bool expand = ImGui.CollapsingHeader("Zone State"); + ImGui.SameLine(); + ImGui.Text($"(Current: {((GetRef(zoneStateAddr, 0xD2EA) == 0x1) ? "Hub" : "Combat")})"); + if (expand) + { + ref byte passiveFlag1 = ref player.GetRef(0x7626); + ref byte passiveFlag2 = ref GetRef(player.Get(0x7D20), 0x9B8); + bool passive = passiveFlag1 == 0x1 && passiveFlag2 == 0x1; + if (saveSlotFallback) + { + ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * disableAlphaFactor); + } + if (ImGui.Checkbox("Passive", ref passive)) + { + passiveFlag1 = ByteFlag(passive); + passiveFlag2 = ByteFlag(passive); + } + if (saveSlotFallback) + { + ImGui.PopStyleVar(); + } + if (ImGui.BeginItemTooltip()) + { + ImGui.Text("Passive: Calm camera and your hunter looks neutral/smiles.\nCombat: Intense camera and your hunter looks angry.\nIf you have Passive set and Combat Controls on, or vice versa, expect glitchy behavior."); + ImGui.EndTooltip(); + } + nint controlsAddr = player.Get(0x12608); + if (controlsAddr == 0x0) return; + bool combatControls = Get(controlsAddr, 0xB18) == 0x80; + zoneState = combatControls ? ZoneState.Combat : ZoneState.Hub; +#if QUARANTINED_FEATURES + if (ImGui.Checkbox("Combat Controls", ref combatControls)) + { + passiveFlag1 = ByteFlag(!combatControls); + passiveFlag2 = ByteFlag(!combatControls); + setPlayerController1.Invoke(player.Instance); + setPlayerController5.Invoke(controlsAddr); + } + int zoneStateInt = (int)forceZoneState; + ImGui.AlignTextToFramePadding(); + ImGui.Text($"Force:"); + if (ImGui.BeginItemTooltip()) + { + ImGui.Text("This will apply when moving to a different area."); + ImGui.EndTooltip(); + } + ImGui.SameLine(); + ImGui.RadioButton("Off", ref zoneStateInt, 0); + ImGui.SameLine(); + ImGui.RadioButton("Hub", ref zoneStateInt, 1); + ImGui.SameLine(); + ImGui.RadioButton("Combat", ref zoneStateInt, 2); + forceZoneState = (ZoneState)zoneStateInt; + if (ImGui.Button("Run Change Zone State")) + { + zoneStateManualInvoke = true; + setZoneStateFunc.Invoke(player.Instance, 0x000106C0); // or 0x00010780. + } + if (ImGui.BeginItemTooltip()) + { + ImGui.Text("You can use this to apply the value of Force Zone State.\nIf you're out in a map and Force Zone State is set to Off or Combat, this will send you back to camp."); + ImGui.EndTooltip(); + } + if (ImGui.Checkbox("Force Passive in Combat Zones", ref forcePassiveInCombatZone)) + { + if (forcePassiveInCombatZone) + { + zoneStateForcePassive1.Enable(); + zoneStateForcePassive2.Enable(); + } + else + { + zoneStateForcePassive1.Disable(); + zoneStateForcePassive2.Disable(); + } + } + if (ImGui.Checkbox("Force Combat in Passive Zones", ref forceCombatInPassiveZone)) + { + if (forceCombatInPassiveZone) + { + zoneStateForceCombat1.Enable(); + zoneStateForceCombat2.Enable(); + } + else + { + zoneStateForceCombat1.Disable(); + zoneStateForceCombat2.Disable(); + } + } +#endif + if (zoneState != ZoneState.Combat) + { + ImGui.PushItemFlag(ImGuiItemFlags.Disabled, true); + ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * disableAlphaFactor); + } + if (ImGui.Checkbox("Force Crawl", ref enableCrawl)) + { + if (enableCrawl) + { + GetRef(psuedoObject2, 0x70) = player.Position.X + player.Forward.X; + GetRef(psuedoObject2, 0x74) = player.Position.Y + player.Forward.Y; + GetRef(psuedoObject2, 0x78) = player.Position.Z + player.Forward.Z; + + Quaternion playerRotation = new(player.Forward.X, player.Forward.Y, player.Forward.Z, 0.0f); + Quaternion objectRotation = getRight(playerRotation); + + GetRef(psuedoObject2, 0x40) = objectRotation.X; + GetRef(psuedoObject2, 0x44) = objectRotation.Y; + GetRef(psuedoObject2, 0x48) = objectRotation.Z; + GetRef(psuedoObject2, 0x4C) = objectRotation.W; + + GetRef(psuedoObject2, 0x50) = 0.0f; + GetRef(psuedoObject2, 0x54) = 1.0f; + GetRef(psuedoObject2, 0x58) = 0.0f; + GetRef(psuedoObject2, 0x5C) = 0.0f; + + GetRef(psuedoObject2, 0x60) = playerRotation.X; + GetRef(psuedoObject2, 0x64) = playerRotation.Y; + GetRef(psuedoObject2, 0x68) = playerRotation.Z; + GetRef(psuedoObject2, 0x6C) = playerRotation.W; + } + } + if (zoneState != ZoneState.Combat) + { + ImGui.PopStyleVar(); + ImGui.PopItemFlag(); + if (ImGui.BeginItemTooltip()) + { + ImGui.Text("You have to be out in a map to use this."); + ImGui.EndTooltip(); + } + } + else + { + if (ImGui.BeginItemTooltip()) + { + ImGui.Text("Simulate crawling under an object in the direction your character was facing when enabled."); + ImGui.EndTooltip(); + } + } + + if (zoneState != ZoneState.Hub) + { + ImGui.PushItemFlag(ImGuiItemFlags.Disabled, true); + ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * disableAlphaFactor); + } + if (ImGui.Button("Sit in Hot Springs")) + { + // Run sit in hot springs action (top of function). + // MonsterHunterWorld.exe+17601F0 - mov [rsp+08],rbx + Models.runAction(player.ActionController, 0x1, 0x65); + } + if (zoneState != ZoneState.Hub) + { + ImGui.PopStyleVar(); + ImGui.PopItemFlag(); + if (ImGui.BeginItemTooltip()) + { + ImGui.Text("You have to be in a hub area to use this."); + ImGui.EndTooltip(); + } + } + + if (ImGui.Checkbox("Allow Hot Springs Anywhere", ref allowHotSpringsAnywhere)) + { + if (allowHotSpringsAnywhere) + { + jmpOverHotSpringsEval.Enable(); + } + else + { + jmpOverHotSpringsEval.Disable(); + } + } + if (ImGui.BeginItemTooltip()) + { + ImGui.Text("Disable check for being about halfway submerged in water to stay sitting."); + ImGui.EndTooltip(); + } + + if (ImGui.Checkbox("Disable Hot Springs Steam", ref disableHotSpringsSteam)) + { + if (disableHotSpringsSteam) + { + jmpOverHotSpringsSteam.Enable(); + } + else + { + jmpOverHotSpringsSteam.Disable(); + } + } + if (ImGui.BeginItemTooltip()) + { + ImGui.Text("It will take a couple of seconds to fade away."); + ImGui.EndTooltip(); + } + } + } + } +} -- cgit v1.2.3-101-g0448