Big commit

- Add missing Tired Timer to Stamina UI;
- Replace per-tick updates of HP, Stamina and Rage to per-event;
-- Stamina UI on Small Monsters is now deprecated;
-
This commit is contained in:
GreenComfyTea
2022-07-10 20:00:56 +03:00
parent 9c1ba9ac4c
commit 06a29637bd
8 changed files with 662 additions and 470 deletions

View File

@@ -4,11 +4,24 @@ local large_monster;
local config;
local ailments;
local character_base_type_def = sdk.find_type_definition("snow.CharacterBase");
local character_base_start_method = character_base_type_def:get_method("start");
local enemy_character_base_type_def = sdk.find_type_definition("snow.enemy.EnemyCharacterBase");
local enemy_character_base_update_method = enemy_character_base_type_def:get_method("update");
local is_boss_enemy_method = enemy_character_base_type_def:get_method("get_isBossEnemy");
local enemy_damage_check_type_def = sdk.find_type_definition("snow.enemy.EnemyDamageCheck");
local damage_check_update_param_update_method = enemy_damage_check_type_def:get_method("updateParam");
local anger_param_type_def = sdk.find_type_definition("snow.enemy.EnemyAngerParam");
local anger_add_method = anger_param_type_def:get_method("add");
local anger_update_method = anger_param_type_def:get_method("updateNormal");
local stamina_param_type_def = sdk.find_type_definition("snow.enemy.EnemyStaminaParam");
local stamina_sub_method = stamina_param_type_def:get_method("sub");
local stamina_update_method = stamina_param_type_def:get_method("updateParam");
local tick_count = 0;
local last_update_tick = 0;
local recorded_monsters = {};
@@ -41,6 +54,67 @@ re.on_pre_application_entry("UpdateBehavior", function()
end
end)
--snow.enemy.EnemyDamageStockParam
function monster_hook.update_health(enemy_damage_stock_param)
local enemy = enemy_damage_stock_param:call("get_RefEnemy");
if enemy == nil then
return;
end
local is_large = is_boss_enemy_method:call(enemy);
if is_large == nil then
return;
end
if is_large then
local monster = large_monster.get_monster(enemy);
local physical_param = large_monster.update_health(enemy, monster);
large_monster.update_parts(enemy, monster, physical_param);
else
local monster = small_monster.get_monster(enemy);
small_monster.update_health(enemy, monster);
end
end
function monster_hook.update_stamina(stamina_param, stamina_sub)
if stamina_sub == 0 then
return;
end
local enemy = stamina_param:call("get_Em");
if enemy == nil then
return;
end
local monster = large_monster.get_monster(enemy);
large_monster.update_stamina(enemy, monster, stamina_param);
-- stamina sub gets called periodically at low rate for large monsters even without damage
large_monster.update(enemy, monster);
end
function monster_hook.update_stamina_timer(stamina_param, enemy)
local monster = large_monster.get_monster(enemy);
large_monster.update_stamina(enemy, monster, stamina_param);
end
function monster_hook.update_rage(anger_param, anger_add, enemy)
if anger_add == 0 then
return;
end
local monster = large_monster.get_monster(enemy);
large_monster.update_rage(enemy, monster, anger_param);
end
function monster_hook.update_rage_timer(anger_param, enemy)
local monster = large_monster.get_monster(enemy);
large_monster.update_rage_timer(enemy, monster, anger_param);
end
function monster_hook.update_monster(enemy)
if enemy == nil then
return;
@@ -72,37 +146,16 @@ end
function monster_hook.update_large_monster(enemy)
local cached_config = config.current_config.large_monster_UI;
if not cached_config.dynamic.enabled and
not cached_config.static.enabled and
not cached_config.highlighted.enabled then
if not cached_config.dynamic.enabled then
return;
end
local monster = large_monster.get_monster(enemy);
-- this is the VERY LEAST thing we should do all the time
-- so the position doesn't lag all over the place
-- due to how infrequently we update the monster(s).
large_monster.update_position(enemy);
if not config.current_config.global_settings.performance.prioritize_large_monsters and updated_monsters[enemy] then
return;
end
-- is it old tick?
-- is update limit reached?
if tick_count == last_update_tick and updates_this_tick >= config.current_config.global_settings.performance.max_monster_updates_per_tick then
return;
end
-- actually update the enemy now. we don't do this very often
-- due to how much CPU time it takes to update each monster.
if not config.current_config.global_settings.performance.prioritize_large_monsters then
updates_this_tick = updates_this_tick + 1;
last_update_tick = tick_count;
num_updated_monsters = num_updated_monsters + 1;
updated_monsters[enemy] = true;
end
large_monster.update(enemy);
large_monster.update_position(enemy, monster);
end
function monster_hook.update_small_monster(enemy)
@@ -110,10 +163,12 @@ function monster_hook.update_small_monster(enemy)
return;
end
local monster = small_monster.get_monster(enemy);
-- this is the VERY LEAST thing we should do all the time
-- so the position doesn't lag all over the place
-- due to how infrequently we update the monster(s).
small_monster.update_position(enemy);
small_monster.update_position(enemy, monster);
if updated_monsters[enemy] then
return;
@@ -132,20 +187,51 @@ function monster_hook.update_small_monster(enemy)
num_updated_monsters = num_updated_monsters + 1;
updated_monsters[enemy] = true;
small_monster.update(enemy);
small_monster.update(enemy, monster);
end
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");
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);
sdk.hook(damage_check_update_param_update_method, function(args)
pcall(monster_hook.update_health, sdk.to_managed_object(args[2]));
end, function(retval)
return retval;
end);
sdk.hook(stamina_sub_method, function(args)
pcall(monster_hook.update_stamina, sdk.to_managed_object(args[2]), sdk.to_float(args[3]));
end, function(retval)
return retval;
end);
sdk.hook(stamina_update_method, function(args)
pcall(monster_hook.update_stamina, sdk.to_managed_object(args[2]), -1, sdk.to_managed_object(args[3]));
end, function(retval)
return retval;
end);
sdk.hook(anger_add_method, function(args)
pcall(monster_hook.update_rage, sdk.to_managed_object(args[2]), sdk.to_float(args[3]), sdk.to_managed_object(args[4]));
end, function(retval)
return retval;
end);
sdk.hook(anger_update_method, function(args)
pcall(monster_hook.update_rage_timer, sdk.to_managed_object(args[2]), sdk.to_managed_object(args[3]));
end, function(retval)
return retval;
end);
end
return monster_hook;