From 6f742d3234eb145a574d032ed87e6cfd52799009 Mon Sep 17 00:00:00 2001 From: GreenComfyTea Date: Thu, 17 Aug 2023 09:48:24 +0300 Subject: [PATCH] Use in-game _DieCount instead of Manual Counting --- .../MHR_Overlay/Damage_Meter/damage_hook.lua | 12 ++-- .../MHR_Overlay/Damage_Meter/players.lua | 55 +++++++++--------- .../MHR_Overlay/Game_Handler/quest_status.lua | 56 ++++++++++++++++++- 3 files changed, 87 insertions(+), 36 deletions(-) diff --git a/reframework/autorun/MHR_Overlay/Damage_Meter/damage_hook.lua b/reframework/autorun/MHR_Overlay/Damage_Meter/damage_hook.lua index 60ad519..7c71564 100644 --- a/reframework/autorun/MHR_Overlay/Damage_Meter/damage_hook.lua +++ b/reframework/autorun/MHR_Overlay/Damage_Meter/damage_hook.lua @@ -264,13 +264,11 @@ function this.cart(dead_player_id, flag_cat_skill_insurance) -- flag_cat_skill_insurance = 0 -- flag_cat_skill_insurance = 1 - local player = players.list[dead_player_id]; - if player == nil then - error_handler.report("damage_hook.cart", "No Dead Player Found"); - return; - end - - player.cart_count = player.cart_count + 1; + --local player = players.list[dead_player_id]; + --if player == nil then + -- error_handler.report("damage_hook.cart", "No Dead Player Found"); + -- return; + --end quest_status.get_cart_count(); end diff --git a/reframework/autorun/MHR_Overlay/Damage_Meter/players.lua b/reframework/autorun/MHR_Overlay/Damage_Meter/players.lua index d64ca8d..dccfe41 100644 --- a/reframework/autorun/MHR_Overlay/Damage_Meter/players.lua +++ b/reframework/autorun/MHR_Overlay/Damage_Meter/players.lua @@ -415,7 +415,7 @@ end function this.init() this.list = {}; this.total = this.new(0, "Total", 0, 0, this.types.total); - this.myself = nil; + this.myself = this.new(-1, "MHROverlayDummy", -1, -1, this.types.myself); end local lobby_manager_type_def = sdk.find_type_definition("snow.LobbyManager"); @@ -448,46 +448,43 @@ local get_master_player_id_method = player_manager_type_def:get_method("getMaste function this.update_players() local is_on_quest = quest_status.flow_state ~= quest_status.flow_states.IN_LOBBY and quest_status.flow_state ~= quest_status.flow_states.IN_TRAINING_AREA; - this.update_player_list(is_on_quest); + if is_on_quest then + this.update_player_list(quest_hunter_info_field); + else + this.update_player_list(hunter_info_field); + end + non_players.update_servant_list(); non_players.update_otomo_list(is_on_quest, quest_status.is_online); this.update_dps(false); - - quest_status.get_cart_count(); end -function this.update_player_list(is_on_quest) - if is_on_quest then - this.update_player_list_(quest_hunter_info_field); - else - this.update_player_list_(hunter_info_field); - end -end - -function this.update_player_list_(hunter_info_field_) +function this.update_player_list(hunter_info_field_) local cached_config = config.current_config.damage_meter_UI; if singletons.lobby_manager == nil then - error_handler.report("players.update_player_list_", "Failed to access Data: lobby_manager"); + error_handler.report("players.update_player_list", "Failed to access Data: lobby_manager"); return; end if singletons.progress_manager == nil then - error_handler.report("players.update_player_list_", "Failed to access Data: progress_manager"); + error_handler.report("players.update_player_list", "Failed to access Data: progress_manager"); return; end + local update_cart_count = false; + -- myself player local myself_player_info = my_hunter_info_field:get_data(singletons.lobby_manager); if myself_player_info == nil then - error_handler.report("players.update_player_list_", "Failed to access Data: myself_player_info"); + error_handler.report("players.update_player_list", "Failed to access Data: myself_player_info"); return; end local myself_player_name = name_field:get_data(myself_player_info); if myself_player_name == nil then - error_handler.report("players.update_player_list_", "Failed to access Data: myself_player_name"); + error_handler.report("players.update_player_list", "Failed to access Data: myself_player_name"); return; end @@ -497,42 +494,40 @@ function this.update_player_list_(hunter_info_field_) local myself_id = get_master_player_id_method:call(singletons.player_manager); if myself_id == nil then - error_handler.report("players.update_player_list_", "Failed to access Data: myself_id"); + error_handler.report("players.update_player_list", "Failed to access Data: myself_id"); return; end if this.myself == nil or myself_id ~= this.myself.id then - if this.myself ~= nil then - this.list[this.myself.id] = nil; - end - + this.list[this.myself.id] = nil; this.myself = this.new(myself_id, myself_player_name, myself_master_rank, myself_hunter_rank, this.types.myself); this.list[myself_id] = this.myself; + update_cart_count = true; end -- other players local player_info_array = hunter_info_field_:get_data(singletons.lobby_manager); if player_info_array == nil then - error_handler.report("players.update_player_list_", "Failed to access Data: player_info_array"); + error_handler.report("players.update_player_list", "Failed to access Data: player_info_array"); return; end local count = get_count_method:call(player_info_array); if count == nil then - error_handler.report("players.update_player_list_", "Failed to access Data: player_info_array -> count"); + error_handler.report("players.update_player_list", "Failed to access Data: player_info_array -> count"); return; end for i = 0, count - 1 do local player_info = get_item_method:call(player_info_array, i); if player_info == nil then - error_handler.report("players.update_player_list_", "Failed to access Data: player_info No. " .. tostring(i)); + error_handler.report("players.update_player_list", "Failed to access Data: player_info No. " .. tostring(i)); goto continue; end local id = member_index_field:get_data(player_info); if id == nil then - error_handler.report("players.update_player_list_", string.format("Failed to access Data: player_info No. %d -> id", i)); + error_handler.report("players.update_player_list", string.format("Failed to access Data: player_info No. %d -> id", i)); goto continue; end @@ -541,7 +536,7 @@ function this.update_player_list_(hunter_info_field_) local name = name_field:get_data(player_info); if name == nil then - error_handler.report("players.update_player_list_", string.format("Failed to access Data: player_info No. %d -> name", i)); + error_handler.report("players.update_player_list", string.format("Failed to access Data: player_info No. %d -> name", i)); goto continue; end @@ -563,14 +558,20 @@ function this.update_player_list_(hunter_info_field_) player = this.new(id, name, master_rank, hunter_rank, this.types.myself); this.myself = player; this.list[id] = player; + update_cart_count = true; else player = this.new(id, name, master_rank, hunter_rank, this.types.other_player); this.list[id] = player; + update_cart_count = true; end end ::continue:: end + + if update_cart_count then + quest_status.get_cart_count(); + end end function this.init_UI(player) diff --git a/reframework/autorun/MHR_Overlay/Game_Handler/quest_status.lua b/reframework/autorun/MHR_Overlay/Game_Handler/quest_status.lua index fd9631b..84eb102 100644 --- a/reframework/autorun/MHR_Overlay/Game_Handler/quest_status.lua +++ b/reframework/autorun/MHR_Overlay/Game_Handler/quest_status.lua @@ -117,6 +117,16 @@ local unique_event_manager_type_def = sdk.find_type_definition("snow.eventcut.Un local play_event_common_method = unique_event_manager_type_def:get_method("playEventCommon"); local event_manager_dispose_method = unique_event_manager_type_def:get_method("dispose"); +local player_manager_type_def = sdk.find_type_definition("snow.player.PlayerManager"); +local get_player_data_method = player_manager_type_def:get_method("get_PlayerData"); + +local player_data_type_def = sdk.find_type_definition("snow.player.PlayerData"); +local die_count_field = player_data_type_def:get_field("_DieCount"); + +local system_array_type_def = sdk.find_type_definition("System.Array"); +local get_length_method = system_array_type_def:get_method("get_Length"); +local get_value_method = system_array_type_def:get_method("GetValue(System.Int32)"); + function this.get_flow_state_name(flow_state, new_line) for key, value in pairs(this.flow_states) do if value == flow_state then @@ -145,11 +155,15 @@ function this.set_flow_state(new_flow_state) small_monster.init_list(); large_monster.init_list(); env_creature.init_list(); + damage_meter_UI.last_displayed_players = {}; + elseif this.flow_state >= this.flow_states.LOADING_QUEST then this.get_cart_count(); this.get_max_cart_count(); end + + players.update_players(); end function this.get_cart_count() @@ -161,9 +175,47 @@ function this.get_cart_count() local death_num = get_death_num_method:call(singletons.quest_manager); if death_num == nil then error_handler.report("quest_status.get_cart_count", "Failed to access Data: death_num"); + else + this.cart_count = death_num; end - - this.cart_count = death_num; + + if singletons.player_manager == nil then + error_handler.report("quest_status.get_cart_count", "Failed to access Data: player_manager"); + return; + end + + local player_data_array = get_player_data_method:call(singletons.player_manager); + if player_data_array == nil then + error_handler.report("quest_status.get_cart_count", "Failed to access Data: player_data_array"); + return; + end + + local player_data_array_length = get_length_method:call(player_data_array); + if player_data_array_length == nil then + error_handler.report("quest_status.get_cart_count", "Failed to access Data: player_data_array_length"); + return; + end + + for i = 0, player_data_array_length - 1 do + local player_data = get_value_method:call(player_data_array, i); + if player_data_array_length == nil then + error_handler.report("quest_status.get_cart_count", string.format("Failed to access Data: player_data No. %d", i)); + goto continue; + end + + local die_count = die_count_field:get_data(player_data); + if die_count == nil then + error_handler.report("quest_status.get_cart_count", string.format("Failed to access Data: die_count No. %d", i)); + goto continue; + end + + local player = players.list[i]; + if player ~= nil then + player.cart_count = die_count; + end + + ::continue:: + end end function this.get_max_cart_count()