mirror of
https://github.com/GreenComfyTea/MHR-Overlay.git
synced 2026-01-24 04:18:11 -08:00
Merge pull request #19 from praydog/performance-improvements
Major performance improvements
This commit is contained in:
@@ -41,6 +41,8 @@ function large_monster.new(enemy)
|
||||
monster.rage_seconds_left = 0;
|
||||
monster.rage_timer_percentage = 0;
|
||||
|
||||
monster.game_object = nil
|
||||
monster.transform = nil
|
||||
monster.position = Vector3f.new(0, 0, 0);
|
||||
|
||||
monster.name = "Large Monster";
|
||||
@@ -184,52 +186,128 @@ function large_monster.init_dynamic_UI(monster)
|
||||
end
|
||||
end
|
||||
|
||||
local enemy_character_base_type = sdk.find_type_definition("snow.enemy.EnemyCharacterBase")
|
||||
local physical_param_field = enemy_character_base_type:get_field("<PhysicalParam>k__BackingField");
|
||||
local status_param_field = enemy_character_base_type:get_field("<StatusParam>k__BackingField")
|
||||
local stamina_param_field = enemy_character_base_type:get_field("<StaminaParam>k__BackingField")
|
||||
local anger_param_field = enemy_character_base_type:get_field("<AngerParam>k__BackingField")
|
||||
|
||||
local physical_param_type = physical_param_field:get_type()
|
||||
local get_vital_method = physical_param_type:get_method("getVital")
|
||||
local get_capture_hp_vital_method = physical_param_type:get_method("get_CaptureHpVital")
|
||||
local vital_list_field = physical_param_type:get_field("_VitalList")
|
||||
|
||||
local vital_param_type = get_vital_method:get_return_type()
|
||||
local get_current_method = vital_param_type:get_method("get_Current")
|
||||
local get_max_method = vital_param_type:get_method("get_Max")
|
||||
|
||||
local stamina_param_type = stamina_param_field:get_type()
|
||||
local get_stamina_method = stamina_param_type:get_method("getStamina")
|
||||
local get_max_stamina_method = stamina_param_type:get_method("getMaxStamina")
|
||||
|
||||
local anger_param_type = anger_param_field:get_type()
|
||||
local is_anger_method = anger_param_type:get_method("isAnger")
|
||||
local get_anger_point_method = anger_param_type:get_method("get_AngerPoint")
|
||||
local get_limit_anger_method = anger_param_type:get_method("get_LimitAnger")
|
||||
local anger_param_get_timer_method = anger_param_type:get_method("get_Timer")
|
||||
local get_timer_anger_method = anger_param_type:get_method("get_TimerAnger")
|
||||
local get_count_anger_method = anger_param_type:get_method("get_CountAnger")
|
||||
|
||||
local get_gameobject_method = sdk.find_type_definition("via.Component"):get_method("get_GameObject")
|
||||
local get_transform_method = sdk.find_type_definition("via.GameObject"):get_method("get_Transform")
|
||||
local get_position_method = sdk.find_type_definition("via.Transform"):get_method("get_Position")
|
||||
|
||||
function large_monster.update_position(enemy)
|
||||
if not config.current_config.large_monster_UI.dynamic.enabled and
|
||||
not config.current_config.large_monster_UI.static.enabled then
|
||||
return;
|
||||
end
|
||||
|
||||
local monster = large_monster.get_monster(enemy);
|
||||
if not monster then return end
|
||||
|
||||
-- cache off the game object and transform
|
||||
-- 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_gameobject_method:call(enemy)
|
||||
if monster.game_object == nil then
|
||||
customization_menu.status = "No enemy game object";
|
||||
return;
|
||||
end
|
||||
end
|
||||
|
||||
if monster.transform == nil then
|
||||
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)
|
||||
if not position then
|
||||
customization_menu.status = "No enemy position";
|
||||
return;
|
||||
end
|
||||
|
||||
if position ~= nil then
|
||||
monster.position = position;
|
||||
end
|
||||
end
|
||||
|
||||
function large_monster.update(enemy)
|
||||
-- maybe more checks are needed here i'm not fully aware of how the code flows here
|
||||
if not config.current_config.large_monster_UI.dynamic.enabled and
|
||||
not config.current_config.large_monster_UI.static.enabled then
|
||||
return;
|
||||
end
|
||||
|
||||
if enemy == nil then
|
||||
return;
|
||||
end
|
||||
|
||||
local monster = large_monster.get_monster(enemy);
|
||||
|
||||
local physical_param = enemy:get_field("<PhysicalParam>k__BackingField");
|
||||
local physical_param = physical_param_field:get_data(enemy)
|
||||
if physical_param == nil then
|
||||
customization_menu.status = "No physical param";
|
||||
return;
|
||||
end
|
||||
|
||||
local vital_param = physical_param:call("getVital", 0, 0);
|
||||
local vital_param = get_vital_method:call(physical_param, 0, 0);
|
||||
if vital_param == nil then
|
||||
customization_menu.status = "No vital param";
|
||||
return;
|
||||
end
|
||||
|
||||
local health = vital_param:call("get_Current");
|
||||
local max_health = vital_param:call("get_Max");
|
||||
local capture_health = physical_param:call("get_CaptureHpVital");
|
||||
local health = get_current_method:call(vital_param)
|
||||
local max_health = get_max_method:call(vital_param)
|
||||
local capture_health = get_capture_hp_vital_method:call(physical_param)
|
||||
|
||||
local stamina_param = enemy:get_field("<StaminaParam>k__BackingField");
|
||||
local stamina_param = stamina_param_field:get_data(enemy)
|
||||
if stamina_param == nil then
|
||||
customization_menu.status = "No stamina param";
|
||||
return;
|
||||
end
|
||||
|
||||
local stamina = stamina_param:call("getStamina");
|
||||
local max_stamina = stamina_param:call("getMaxStamina");
|
||||
local stamina = get_stamina_method:call(stamina_param)
|
||||
local max_stamina = get_max_stamina_method:call(stamina_param)
|
||||
|
||||
local anger_param = enemy:get_field("<AngerParam>k__BackingField");
|
||||
local anger_param = anger_param_field:get_data(enemy)
|
||||
if anger_param == nil then
|
||||
customization_menu.status = "No anger param";
|
||||
return;
|
||||
end
|
||||
|
||||
local is_in_rage = anger_param:call("isAnger");
|
||||
local rage_point = anger_param:call("get_AngerPoint");
|
||||
local rage_limit = anger_param:call("get_LimitAnger");
|
||||
local rage_timer = anger_param:call("get_Timer");
|
||||
local rage_duration = anger_param:call("get_TimerAnger");
|
||||
local rage_count = anger_param:call("get_CountAnger");
|
||||
local is_in_rage = is_anger_method:call(anger_param)
|
||||
local rage_point = get_anger_point_method:call(anger_param)
|
||||
local rage_limit = get_limit_anger_method:call(anger_param)
|
||||
local rage_timer = anger_param_get_timer_method:call(anger_param)
|
||||
local rage_duration = get_timer_anger_method:call(anger_param)
|
||||
local rage_count = get_count_anger_method:call(anger_param)
|
||||
|
||||
local vital_list = physical_param:get_field("_VitalList");
|
||||
local vital_list = vital_list_field:get_data(physical_param)
|
||||
if vital_list == nil then
|
||||
customization_menu.status = "No vital list";
|
||||
return;
|
||||
@@ -297,23 +375,7 @@ function large_monster.update(enemy)
|
||||
::continue::
|
||||
end
|
||||
|
||||
local enemy_game_object = enemy:call("get_GameObject");
|
||||
if enemy_game_object == nil then
|
||||
customization_menu.status = "No enemy game object";
|
||||
return;
|
||||
end
|
||||
|
||||
local enemy_transform = enemy_game_object:call("get_Transform");
|
||||
if enemy_transform == nil then
|
||||
customization_menu.status = "No enemy transform";
|
||||
return;
|
||||
end
|
||||
|
||||
local position = enemy_transform:call("get_Position");
|
||||
if not position then
|
||||
customization_menu.status = "No enemy position";
|
||||
return;
|
||||
end
|
||||
large_monster.update_position(enemy);
|
||||
|
||||
if health ~= nil then
|
||||
monster.health = health;
|
||||
@@ -334,10 +396,6 @@ function large_monster.update(enemy)
|
||||
end
|
||||
end
|
||||
|
||||
if position ~= nil then
|
||||
monster.position = position;
|
||||
end
|
||||
|
||||
if stamina ~= nil then
|
||||
monster.stamina = stamina;
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user