From d4c52617d9feb40f8edc2f8edd45e061c2625c30 Mon Sep 17 00:00:00 2001 From: GreenComfyTea Date: Mon, 6 May 2024 19:08:08 +0300 Subject: [PATCH] Add Endemic Life Head Tracking --- .../MHR_Overlay/Endemic_Life/env_creature.lua | 100 ++++++++++++++++-- .../autorun/MHR_Overlay/Misc/config.lua | 1 + .../MHR_Overlay/Monsters/large_monster.lua | 2 + .../MHR_Overlay/Monsters/small_monster.lua | 2 + .../UI/Modules/env_creature_UI.lua | 7 +- .../MHR_Overlay/UI/customization_menu.lua | 5 + 6 files changed, 107 insertions(+), 10 deletions(-) diff --git a/reframework/autorun/MHR_Overlay/Endemic_Life/env_creature.lua b/reframework/autorun/MHR_Overlay/Endemic_Life/env_creature.lua index 2d93419..8163a71 100644 --- a/reframework/autorun/MHR_Overlay/Endemic_Life/env_creature.lua +++ b/reframework/autorun/MHR_Overlay/Endemic_Life/env_creature.lua @@ -53,6 +53,29 @@ this.creature_ids = { gold_wirebug = 63, }; +local environment_creature_base_type_def = sdk.find_type_definition("snow.envCreature.EnvironmentCreatureBase"); +local creature_type_field = environment_creature_base_type_def:get_field("_Type"); +local creature_is_inactive_field = environment_creature_base_type_def:get_field("k__BackingField"); + +local message_manager_type_def = sdk.find_type_definition("snow.gui.MessageManager"); +local get_env_creature_name_message_method = message_manager_type_def:get_method("getEnvCreatureNameMessage"); + +local get_pos_method = environment_creature_base_type_def:get_method("get_Pos"); + +local get_ref_mesh_method = environment_creature_base_type_def:get_method("getMesh"); + +local mesh_type_def = get_ref_mesh_method:get_return_type(); +local get_game_object_method = mesh_type_def:get_method("get_GameObject"); + +local game_object_type_def = get_game_object_method:get_return_type(); +local get_transform_method = game_object_type_def:get_method("get_Transform"); + +local transform_type_def = get_transform_method:get_return_type(); +local get_joint_by_name_method = transform_type_def:get_method("getJointByName"); + +local joint_type_def = get_joint_by_name_method:get_return_type(); +local get_position_method = joint_type_def:get_method("get_Position"); + function this.new(REcreature) local creature = {}; @@ -81,15 +104,6 @@ function this.get_creature(REcreature) return this.list[REcreature]; end -local environment_creature_base_type_def = sdk.find_type_definition("snow.envCreature.EnvironmentCreatureBase"); -local creature_type_field = environment_creature_base_type_def:get_field("_Type"); -local creature_is_inactive_field = environment_creature_base_type_def:get_field("k__BackingField"); - -local message_manager_type_def = sdk.find_type_definition("snow.gui.MessageManager"); -local get_env_creature_name_message_method = message_manager_type_def:get_method("getEnvCreatureNameMessage"); - -local get_pos_method = environment_creature_base_type_def:get_method("get_Pos"); - function this.init(creature, REcreature) local creature_type = creature_type_field:get_data(REcreature); if creature_type == nil then @@ -105,6 +119,8 @@ function this.init(creature, REcreature) creature.name = creature_name; creature.id = creature_type; + + this.update_head_joint(REcreature, creature) end function this.init_UI(creature) @@ -131,6 +147,8 @@ function this.update_position(REcreature, creature) end creature.position = position; + + this.update_head_position(REcreature, creature); end function this.update(REcreature, creature) @@ -150,6 +168,70 @@ function this.update(REcreature, creature) creature.is_inactive = is_inactive; end +function this.update_head_joint(REcreature, creature) + local mesh = get_ref_mesh_method:call(REcreature); + if mesh == nil then + error_handler.report("env_creature.update_head_joint", "Failed to Access Data: Mesh"); + return; + end + + local game_object = get_game_object_method:call(mesh); + if game_object == nil then + error_handler.report("env_creature.update_head_joint", "Failed to Access Data: GameObject"); + return; + end + + local transform = get_transform_method:call(game_object); + if transform == nil then + error_handler.report("env_creature.update_head_joint", "Failed to Access Data: Transform"); + return; + end + + local head_joint = get_joint_by_name_method:call(transform, "Head_00") + or get_joint_by_name_method:call(transform, "Head") + or get_joint_by_name_method:call(transform, "Head_01") + or get_joint_by_name_method:call(transform, "Spine_00") + or get_joint_by_name_method:call(transform, "Body_00") + or get_joint_by_name_method:call(transform, "body_00") + or get_joint_by_name_method:call(transform, "Cog") + or get_joint_by_name_method:call(transform, "Cog_00") + or get_joint_by_name_method:call(transform, "head") + or get_joint_by_name_method:call(transform, "root"); + + if head_joint == nil then + -- local out = ""; + -- local joints = transform:get_Joints(); + + -- for i = 0, joints:get_Length() - 1 do + -- local joint = joints[i]; + -- local joint_name = joint:get_Name(); + + -- out = out .. joint_name .. "\n"; + -- end + + -- error_handler.report(creature.name, out); + + error_handler.report("small_monster.update_head_joint", "Failed to Access Data: HeadJoint"); + return; + end + + creature.head_joint = head_joint; +end + +function this.update_head_position(REcreature, creature) + if creature.head_joint == nil then + return; + end + + local head_position = get_position_method:call(creature.head_joint); + if head_position == nil then + error_handler.report("env_creature.update_head_position", "Failed to Access Data: HeadPosition"); + return; + end + + creature.head_position = head_position; +end + function this.draw(creature, position_on_screen, opacity_scale) if d2d ~= nil and config.current_config.global_settings.renderer.use_d2d_if_available then local text_width, text_height = drawing.font:measure(creature.name); diff --git a/reframework/autorun/MHR_Overlay/Misc/config.lua b/reframework/autorun/MHR_Overlay/Misc/config.lua index f7f484c..44a5b34 100644 --- a/reframework/autorun/MHR_Overlay/Misc/config.lua +++ b/reframework/autorun/MHR_Overlay/Misc/config.lua @@ -7457,6 +7457,7 @@ function this.init_default() enabled = false, settings = { + head_tracking = true, hide_inactive_creatures = true, max_distance = 300, opacity_falloff = true diff --git a/reframework/autorun/MHR_Overlay/Monsters/large_monster.lua b/reframework/autorun/MHR_Overlay/Monsters/large_monster.lua index d79944b..716add1 100644 --- a/reframework/autorun/MHR_Overlay/Monsters/large_monster.lua +++ b/reframework/autorun/MHR_Overlay/Monsters/large_monster.lua @@ -526,7 +526,9 @@ function this.update_head_joint(enemy, monster) local head_joint = get_joint_by_name_method:call(transform, "Head_00") or get_joint_by_name_method:call(transform, "Head") + or get_joint_by_name_method:call(transform, "Head_01") or get_joint_by_name_method:call(transform, "Spine_00") + or get_joint_by_name_method:call(transform, "Cog") or get_joint_by_name_method:call(transform, "head") or get_joint_by_name_method:call(transform, "root"); diff --git a/reframework/autorun/MHR_Overlay/Monsters/small_monster.lua b/reframework/autorun/MHR_Overlay/Monsters/small_monster.lua index ab178fc..bc45c13 100644 --- a/reframework/autorun/MHR_Overlay/Monsters/small_monster.lua +++ b/reframework/autorun/MHR_Overlay/Monsters/small_monster.lua @@ -228,7 +228,9 @@ function this.update_head_joint(enemy, monster) local head_joint = get_joint_by_name_method:call(transform, "Head_00") or get_joint_by_name_method:call(transform, "Head") + or get_joint_by_name_method:call(transform, "Head_01") or get_joint_by_name_method:call(transform, "Spine_00") + or get_joint_by_name_method:call(transform, "Cog") or get_joint_by_name_method:call(transform, "head") or get_joint_by_name_method:call(transform, "root"); diff --git a/reframework/autorun/MHR_Overlay/UI/Modules/env_creature_UI.lua b/reframework/autorun/MHR_Overlay/UI/Modules/env_creature_UI.lua index 637fe56..433d38c 100644 --- a/reframework/autorun/MHR_Overlay/UI/Modules/env_creature_UI.lua +++ b/reframework/autorun/MHR_Overlay/UI/Modules/env_creature_UI.lua @@ -86,7 +86,12 @@ function this.draw() cached_config.world_offset.z ); - local position_on_screen = draw.world_to_screen(creature.position + world_offset); + local position_on_screen; + if cached_config.settings.head_tracking then + position_on_screen = draw.world_to_screen(creature.head_position + world_offset); + else + position_on_screen = draw.world_to_screen(creature.position + world_offset); + end if position_on_screen == nil then goto continue; diff --git a/reframework/autorun/MHR_Overlay/UI/customization_menu.lua b/reframework/autorun/MHR_Overlay/UI/customization_menu.lua index 48490e5..a72b92a 100644 --- a/reframework/autorun/MHR_Overlay/UI/customization_menu.lua +++ b/reframework/autorun/MHR_Overlay/UI/customization_menu.lua @@ -2310,6 +2310,11 @@ function this.draw_endemic_life_UI() config_changed = config_changed or changed; if imgui.tree_node(language.current_language.customization_menu.settings) then + changed, cached_config.settings.head_tracking = imgui.checkbox( + language.current_language.customization_menu.head_tracking, cached_config.settings.head_tracking); + + config_changed = config_changed or changed; + changed, cached_config.settings.hide_inactive_creatures = imgui.checkbox( language.current_language.customization_menu.hide_inactive_creatures, cached_config.settings.hide_inactive_creatures);