Implemented Endemic Life UI.

This commit is contained in:
GreenComfyTea
2022-04-21 17:09:10 +03:00
parent 46a76a6a10
commit b94cffa073
26 changed files with 759 additions and 73 deletions

View File

@@ -61,6 +61,9 @@ function ailments.new(_ailments, ailment_id)
_ailments[ailment_id].duration = 100000;
_ailments[ailment_id].timer_percentage = 0;
_ailments[ailment_id].minutes_left = 0;
_ailments[ailment_id].seconds_left = 0;
_ailments[ailment_id].is_active = false;
_ailments[ailment_id].activate_count = 0;
@@ -205,18 +208,34 @@ function ailments.update_ailments(enemy, monster)
local is_active = get_is_active_method:call(ailment_param);
if is_enable ~= nil then
if is_enable ~= monster.ailments[id].is_enable then
ailments.update_last_change_time(monster, id);
end
monster.ailments[id].is_enable = is_enable;
end
if activate_count ~= nil then
if activate_count ~= monster.ailments[id].activate_count then
ailments.update_last_change_time(monster, id);
end
monster.ailments[id].activate_count = activate_count;
end
if buildup ~= nil then
if buildup ~= monster.ailments[id].total_buildup then
ailments.update_last_change_time(monster, id);
end
monster.ailments[id].total_buildup = buildup;
end
if buildup_limit ~= nil then
if buildup_limit ~= monster.ailments[id].buildup_limit then
ailments.update_last_change_time(monster, id);
end
monster.ailments[id].buildup_limit = buildup_limit;
end
@@ -225,25 +244,64 @@ function ailments.update_ailments(enemy, monster)
end
if timer ~= nil then
if timer ~= monster.ailments[id].timer then
ailments.update_last_change_time(monster, id);
end
monster.ailments[id].timer = timer;
end
if duration ~= nil then
if is_active ~= nil then
if is_active ~= monster.ailments[id].is_active then
ailments.update_last_change_time(monster, id);
end
monster.ailments[id].is_active = is_active;
end
if duration ~= nil and not monster.ailments[id].is_active then
if duration ~= monster.ailments[id].duration then
xy = tostring(monster.ailments[id].is_active) .. " " .. tostring(monster.ailments[id].duration) .. " -> " .. tostring(duration);
ailments.update_last_change_time(monster, id);
end
monster.ailments[id].duration = duration;
end
if timer ~= nil and duration ~= nil then
if duration ~= 0 then
monster.ailments[id].timer_percentage = timer / duration;
if duration ~= 0 then
monster.ailments[id].timer_percentage = timer / monster.ailments[id].duration;
end
if is_active then
if timer < 0 then
timer = 0;
end
local minutes_left = math.floor(timer / 60);
local seconds_left = timer - 60 * minutes_left;
if duration ~= 0 then
monster.ailments[id].timer_percentage = timer / monster.ailments[id].duration;
end
monster.ailments[id].minutes_left = minutes_left;
monster.ailments[id].seconds_left = seconds_left;
end
if is_active ~= nil then
if is_active ~= monster.ailments[id].is_active then
ailments.update_last_change_time(monster, id);
end
monster.ailments[id].is_active = is_active;
end
end
end
function ailments.update_last_change_time(monster, id)
monster.ailments[id].last_change_time = time.total_elapsed_seconds;
end
-- Code by coavins
function ailments.update_poison_blast(enemy, is_large)
if enemy == nil then
@@ -301,11 +359,11 @@ function ailments.draw_dynamic(monster, ailments_position_on_screen, opacity_sca
--sort parts here
local displayed_ailments = {};
for REpart, ailment in pairs(monster.ailments) do
if config.current_config.large_monster_UI.dynamic.ailments.settings.hide_ailments_with_zero_buildup and ailment.total_buildup == 0 and ailment.buildup_limit ~= 0 and ailment.activate_count == 0 then
if config.current_config.large_monster_UI.dynamic.ailments.settings.hide_ailments_with_zero_buildup and ailment.total_buildup == 0 and ailment.buildup_limit ~= 0 and ailment.activate_count == 0 and not ailment.is_active then
goto continue;
end
if config.current_config.large_monster_UI.dynamic.ailments.settings.hide_inactive_ailments_with_no_buildup_support and ailment.buildup_limit == 0 then
if config.current_config.large_monster_UI.dynamic.ailments.settings.hide_inactive_ailments_with_no_buildup_support and ailment.buildup_limit == 0 and not ailment.is_active then
goto continue;
end
@@ -321,7 +379,7 @@ function ailments.draw_dynamic(monster, ailments_position_on_screen, opacity_sca
goto continue;
end
if config.current_config.large_monster_UI.dynamic.ailments.settings.time_limit ~= 0 and time.total_elapsed_seconds - ailment.last_change_time > config.current_config.large_monster_UI.dynamic.ailments.settings.time_limit then
if config.current_config.large_monster_UI.dynamic.ailments.settings.time_limit ~= 0 and time.total_elapsed_seconds - ailment.last_change_time > config.current_config.large_monster_UI.dynamic.ailments.settings.time_limit and not ailment.is_active then
goto continue;
end
@@ -374,14 +432,15 @@ function ailments.draw_dynamic(monster, ailments_position_on_screen, opacity_sca
end
function ailments.draw_static(monster, ailments_position_on_screen, opacity_scale)
--sort parts here
local displayed_ailments = {};
for REpart, ailment in pairs(monster.ailments) do
if config.current_config.large_monster_UI.static.ailments.settings.hide_ailments_with_zero_buildup and ailment.total_buildup == 0 and ailment.buildup_limit ~= 0 and ailment.activate_count == 0 then
if config.current_config.large_monster_UI.static.ailments.settings.hide_ailments_with_zero_buildup and ailment.total_buildup == 0 and ailment.buildup_limit ~= 0 and ailment.activate_count == 0 and not ailment.is_active then
goto continue;
end
if config.current_config.large_monster_UI.static.ailments.settings.hide_inactive_ailments_with_no_buildup_support and ailment.buildup_limit == 0 then
if config.current_config.large_monster_UI.static.ailments.settings.hide_inactive_ailments_with_no_buildup_support and ailment.buildup_limit == 0 and not ailment.is_active then
goto continue;
end
@@ -397,7 +456,7 @@ function ailments.draw_static(monster, ailments_position_on_screen, opacity_scal
goto continue;
end
if config.current_config.large_monster_UI.static.ailments.settings.time_limit ~= 0 and time.total_elapsed_seconds - ailment.last_change_time > config.current_config.large_monster_UI.static.ailments.settings.time_limit then
if config.current_config.large_monster_UI.static.ailments.settings.time_limit ~= 0 and time.total_elapsed_seconds - ailment.last_change_time > config.current_config.large_monster_UI.static.ailments.settings.time_limit and not ailment.is_active then
goto continue;
end
@@ -452,11 +511,11 @@ function ailments.draw_highlighted(monster, ailments_position_on_screen, opacity
--sort parts here
local displayed_ailments = {};
for id, ailment in pairs(monster.ailments) do
if config.current_config.large_monster_UI.highlighted.ailments.settings.hide_ailments_with_zero_buildup and ailment.total_buildup == 0 and ailment.buildup_limit ~= 0 and ailment.activate_count == 0 then
if config.current_config.large_monster_UI.highlighted.ailments.settings.hide_ailments_with_zero_buildup and ailment.total_buildup == 0 and ailment.buildup_limit ~= 0 and ailment.activate_count == 0 and not ailment.is_active then
goto continue;
end
if config.current_config.large_monster_UI.highlighted.ailments.settings.hide_inactive_ailments_with_no_buildup_support and ailment.buildup_limit == 0 then
if config.current_config.large_monster_UI.highlighted.ailments.settings.hide_inactive_ailments_with_no_buildup_support and ailment.buildup_limit == 0 and not ailment.is_active then
goto continue;
end
@@ -472,7 +531,7 @@ function ailments.draw_highlighted(monster, ailments_position_on_screen, opacity
goto continue;
end
if config.current_config.large_monster_UI.highlighted.ailments.settings.time_limit ~= 0 and time.total_elapsed_seconds - ailment.last_change_time > config.current_config.large_monster_UI.highlighted.ailments.settings.time_limit then
if config.current_config.large_monster_UI.highlighted.ailments.settings.time_limit ~= 0 and time.total_elapsed_seconds - ailment.last_change_time > config.current_config.large_monster_UI.highlighted.ailments.settings.time_limit and not ailment.is_active then
goto continue;
end
@@ -526,11 +585,11 @@ function ailments.draw_small(monster, ailments_position_on_screen, opacity_scale
--sort parts here
local displayed_ailments = {};
for REpart, ailment in pairs(monster.ailments) do
if config.current_config.small_monster_UI.ailments.settings.hide_ailments_with_zero_buildup and ailment.total_buildup == 0 and ailment.buildup_limit ~= 0 and ailment.activate_count == 0 then
if config.current_config.small_monster_UI.ailments.settings.hide_ailments_with_zero_buildup and ailment.total_buildup == 0 and ailment.buildup_limit ~= 0 and ailment.activate_count == 0 and not ailment.is_active then
goto continue;
end
if config.current_config.small_monster_UI.ailments.settings.hide_inactive_ailments_with_no_buildup_support and ailment.buildup_limit == 0 then
if config.current_config.small_monster_UI.ailments.settings.hide_inactive_ailments_with_no_buildup_support and ailment.buildup_limit == 0 and not ailment.is_active then
goto continue;
end
@@ -546,7 +605,7 @@ function ailments.draw_small(monster, ailments_position_on_screen, opacity_scale
goto continue;
end
if config.current_config.small_monster_UI.ailments.settings.time_limit ~= 0 and time.total_elapsed_seconds - ailment.last_change_time > config.current_config.small_monster_UI.ailments.settings.time_limit then
if config.current_config.small_monster_UI.ailments.settings.time_limit ~= 0 and time.total_elapsed_seconds - ailment.last_change_time > config.current_config.small_monster_UI.ailments.settings.time_limit and not ailment.is_active then
goto continue;
end

View File

@@ -54,8 +54,8 @@ function large_monster.new(enemy)
monster.rage_seconds_left = 0;
monster.rage_timer_percentage = 0;
monster.game_object = nil
monster.transform = nil
monster.game_object = nil;
monster.transform = nil;
monster.position = Vector3f.new(0, 0, 0);
monster.distance = 0;
@@ -123,6 +123,7 @@ function large_monster.init(monster, enemy)
if enemy_name ~= nil then
monster.name = enemy_name;
end
local set_info = get_set_info_method:call(enemy);
if set_info ~= nil then
local unique_id = get_unique_id_method:call(set_info);
@@ -371,7 +372,7 @@ function large_monster.update_position(enemy)
-- as these are pretty much guaranteed to stay constant
-- as long as the enemy is alive
if monster.game_object == nil then
monster.game_object = get_game_object_method:call(enemy)
monster.game_object = get_game_object_method:call(enemy);
if monster.game_object == nil then
customization_menu.status = "No enemy game object";
return;
@@ -379,14 +380,14 @@ function large_monster.update_position(enemy)
end
if monster.transform == nil then
monster.transform = get_transform_method:call(monster.game_object)
monster.transform = get_transform_method:call(monster.game_object);
if monster.transform == nil then
customization_menu.status = "No enemy transform";
return;
end
end
local position = get_position_method:call(monster.transform)
local position = get_position_method:call(monster.transform);
if not position then
customization_menu.status = "No enemy position";
return;
@@ -688,10 +689,11 @@ function large_monster.draw_dynamic(monster, position_on_screen, opacity_scale)
local last_part_position_on_screen = body_part.draw_dynamic(monster, parts_position_on_screen, opacity_scale);
if config.current_config.large_monster_UI.dynamic.ailments.settings.offset_is_relative_to_parts then
if last_part_position_on_screen == nil then
ailments_position_on_screen = parts_position_on_screen;
else
ailments_position_on_screen.y = last_part_position_on_screen.y + config.current_config.large_monster_UI.dynamic.ailments.offset.y * config.current_config.global_settings.modifiers.global_scale_modifier;
if last_part_position_on_screen ~= nil then
ailments_position_on_screen = {
x = last_part_position_on_screen.x + config.current_config.large_monster_UI.highlighted.ailments.relative_offset.x * config.current_config.global_settings.modifiers.global_scale_modifier,
y = last_part_position_on_screen.y + config.current_config.large_monster_UI.highlighted.ailments.relative_offset.y * config.current_config.global_settings.modifiers.global_scale_modifier
};
end
end
@@ -699,6 +701,7 @@ function large_monster.draw_dynamic(monster, position_on_screen, opacity_scale)
end
function large_monster.draw_static(monster, position_on_screen, opacity_scale)
local monster_name_text = "";
if config.current_config.large_monster_UI.static.monster_name_label.include.monster_name then
monster_name_text = string.format("%s ", monster.name);
@@ -721,6 +724,7 @@ function large_monster.draw_static(monster, position_on_screen, opacity_scale)
else
monster.health_static_UI.bar.colors = config.current_config.large_monster_UI.static.health.bar.normal_colors;
end
drawing.draw_label(monster.static_name_label, position_on_screen, opacity_scale, monster_name_text);
@@ -758,10 +762,11 @@ function large_monster.draw_static(monster, position_on_screen, opacity_scale)
local last_part_position_on_screen = body_part.draw_static(monster, parts_position_on_screen, opacity_scale);
if config.current_config.large_monster_UI.static.ailments.settings.offset_is_relative_to_parts then
if last_part_position_on_screen == nil then
ailments_position_on_screen = parts_position_on_screen;
else
ailments_position_on_screen.y = last_part_position_on_screen.y + config.current_config.large_monster_UI.static.ailments.offset.y * config.current_config.global_settings.modifiers.global_scale_modifier;
if last_part_position_on_screen ~= nil then
ailments_position_on_screen = {
x = last_part_position_on_screen.x + config.current_config.large_monster_UI.highlighted.ailments.relative_offset.x * config.current_config.global_settings.modifiers.global_scale_modifier,
y = last_part_position_on_screen.y + config.current_config.large_monster_UI.highlighted.ailments.relative_offset.y * config.current_config.global_settings.modifiers.global_scale_modifier
};
end
end
@@ -829,15 +834,11 @@ function large_monster.draw_highlighted(monster, position_on_screen, opacity_sca
local last_part_position_on_screen = body_part.draw_highlighted(monster, parts_position_on_screen, opacity_scale);
if config.current_config.large_monster_UI.highlighted.ailments.settings.offset_is_relative_to_parts then
if last_part_position_on_screen == nil then
if last_part_position_on_screen ~= nil then
ailments_position_on_screen = {
x = position_on_screen.x + config.current_config.large_monster_UI.highlighted.ailments.offset.x * config.current_config.global_settings.modifiers.global_scale_modifier,
y = parts_position_on_screen.y + config.current_config.large_monster_UI.highlighted.ailments.offset.y * config.current_config.global_settings.modifiers.global_scale_modifier
x = last_part_position_on_screen.x + config.current_config.large_monster_UI.highlighted.ailments.relative_offset.x * config.current_config.global_settings.modifiers.global_scale_modifier,
y = last_part_position_on_screen.y + config.current_config.large_monster_UI.highlighted.ailments.relative_offset.y * config.current_config.global_settings.modifiers.global_scale_modifier
};
else
ailments_position_on_screen.y = last_part_position_on_screen.y + config.current_config.large_monster_UI.highlighted.ailments.offset.y * config.current_config.global_settings.modifiers.global_scale_modifier;
end
end

View File

@@ -1,16 +1,16 @@
local monster = {};
local monster_hook = {};
local small_monster;
local large_monster;
local config;
local ailments;
local enemy_character_base_type_def = sdk.find_type_definition("snow.enemy.EnemyCharacterBase");
local enemy_character_base_type_def_update_method = enemy_character_base_type_def:get_method("update");
local enemy_character_base_update_method = enemy_character_base_type_def:get_method("update");
local is_boss_enemy_method = sdk.find_type_definition("snow.enemy.EnemyCharacterBase"):get_method("get_isBossEnemy");
sdk.hook(enemy_character_base_type_def_update_method, function(args)
pcall(monster.update_monster, sdk.to_managed_object(args[2]));
sdk.hook(enemy_character_base_update_method, function(args)
pcall(monster_hook.update_monster, sdk.to_managed_object(args[2]));
end, function(retval)
return retval;
end);
@@ -47,7 +47,7 @@ re.on_pre_application_entry("UpdateBehavior", function()
end
end)
function monster.update_monster(enemy)
function monster_hook.update_monster(enemy)
if enemy == nil then
return;
end
@@ -71,13 +71,13 @@ function monster.update_monster(enemy)
ailments.update_poison_blast(enemy, is_large);
if is_large then
monster.update_large_monster(enemy);
monster_hook.update_large_monster(enemy);
else
monster.update_small_monster(enemy);
monster_hook.update_small_monster(enemy);
end
end
function monster.update_large_monster(enemy)
function monster_hook.update_large_monster(enemy)
if not config.current_config.large_monster_UI.dynamic.enabled and
not config.current_config.large_monster_UI.static.enabled and
not config.current_config.large_monster_UI.highlighted.enabled then
@@ -111,7 +111,7 @@ function monster.update_large_monster(enemy)
large_monster.update(enemy);
end
function monster.update_small_monster(enemy)
function monster_hook.update_small_monster(enemy)
if not config.current_config.small_monster_UI.enabled then
return;
end
@@ -141,11 +141,11 @@ function monster.update_small_monster(enemy)
small_monster.update(enemy);
end
function monster.init_module()
function monster_hook.init_module()
small_monster = require("MHR_Overlay.Monsters.small_monster");
large_monster = require("MHR_Overlay.Monsters.large_monster");
config = require("MHR_Overlay.Misc.config");
ailments = require("MHR_Overlay.Monsters.ailments");
end
return monster;
return monster_hook;

View File

@@ -27,8 +27,8 @@ function small_monster.new(enemy)
monster.stamina_percentage = 0;
monster.missing_stamina = 0;
monster.game_object = nil
monster.transform = nil
monster.game_object = nil;
monster.transform = nil;
monster.position = Vector3f.new(0, 0, 0);
monster.distance = 0;
@@ -54,14 +54,22 @@ function small_monster.get_monster(enemy)
return small_monster.list[enemy];
end
local enemy_character_base_type_def = sdk.find_type_definition("snow.enemy.EnemyCharacterBase");
local enemy_type_field = enemy_character_base_type_def:get_field("<EnemyType>k__BackingField");
local message_manager_type_def = sdk.find_type_definition("snow.gui.MessageManager");
local get_enemy_name_message_method = message_manager_type_def:get_method("getEnemyNameMessage");
function small_monster.init(monster, enemy)
local enemy_type = enemy:get_field("<EnemyType>k__BackingField");
local enemy_type = enemy_type_field:get_data(enemy);
if enemy_type == nil then
customization_menu.status = "No enemy type";
return;
end
local enemy_name = singletons.message_manager:call("getEnemyNameMessage", enemy_type);
monster.id = enemy_type;
local enemy_name = get_enemy_name_message_method:call(singletons.message_manager, enemy_type);
if enemy_name ~= nil then
monster.name = enemy_name;
end