efroemling / ballistica

The BombSquad Game Engine
Other
529 stars 107 forks source link

Add set callback function #583

Open TheMade4 opened 1 year ago

TheMade4 commented 1 year ago

Description

Add set callback function

Solution

import _ba

def callback_func(*args):

Code

return

_ba.set_callback(callback_name, callback_func)

Additional context

It is advisable to add a callback for the following functions: _ba.client_info_query_response _hooks.reset_to_main_menu _hooks.set_config_fullscreen_on _hooks.set_config_fullscreen_off _hooks.not_signed_in_screen_message _hooks.connecting_to_party_message _hooks.rejecting_invite_already_in_party_message _hooks.connection_failed_message _hooks.temporarily_unavailable_message _hooks.in_progress_message _hooks.error_message _hooks.purchase_not_valid_error _hooks.purchase_already_in_progress_error _hooks.gear_vr_controller_warning _hooks.orientation_reset_cb_message _hooks.orientation_reset_message _hooks.on_app_resume _apputils.handle_v1_cloud_log _hooks.launch_main_menu_session _hooks.language_test_toggle _hooks.award_in_control_achievement _hooks.award_dual_wielding_achievement _apputils.print_corrupt_file_error _hooks.play_gong_sound _hooks.launch_coop_game _hooks.purchases_restored_message _hooks.dismiss_wii_remotes_window _hooks.unavailable_message _hooks.submit_analytics_counts _hooks.set_last_ad_network _hooks.no_game_circle_message _hooks.google_play_purchases_not_available_message _hooks.google_play_services_not_available_message _hooks.empty_call _hooks.level_icon_press _hooks.trophy_icon_press _hooks.coin_icon_press _hooks.ticket_icon_press _hooks.back_button_press _hooks.friends_button_press _hooks.print_trace _hooks.toggle_fullscreen _hooks.party_icon_activate _hooks.read_config _hooks.ui_remote_press _hooks.quit_window _hooks.remove_in_game_ads_message _hooks.telnet_access_request _hooks.on_app_pause _hooks.do_quit _hooks.shutdown _hooks.gc_disable ba.app.accounts_v1.show_post_purchase_message _hooks.device_menu_press _hooks.show_url_window _hooks.party_invite_revoke _hooks.filter_chat_message _hooks.local_chat_message ba.ShouldShatterMessage ba.ImpactDamageMessage ba.PickedUpMessage ba.DroppedMessage ba.OutOfBoundsMessage ba.PickUpMessage ba.DropMessage _hooks.finish_bootstrapping _input.get_device_value _input.get_last_player_name_from_input_device copy.deepcopy copy.copy ba.Activity ba.Session json.dumps json.loads OnScreenKeyboardWindow _music.do_play_music ba.app.handle_deep_link ba.app.lang.get_resource ba.app.lang.translate ba.Lstr ba.Call _apputils.garbage_collect_session_end ba.ContextError ba.NotFoundError ba.NodeNotFoundError ba.SessionTeamNotFoundError ba.InputDeviceNotFoundError ba.DelegateNotFoundError ba.SessionPlayerNotFoundError ba.WidgetNotFoundError ba.ActivityNotFoundError ba.SessionNotFoundError _dependency.AssetPackage enums.TimeFormat enums.TimeType enums.InputType enums.Permission enums.SpecialChar _player.Player _hooks.get_player_icon _language.Lstr.from_json _hooks.uuid_str _hooks.hash_strings _hooks.have_account_v2_credentials logging.debug logging.info logging.warning logging.error logging.critical _hooks.implicit_sign_in _hooks.implicit_sign_out _hooks.login_adapter_get_sign_in_token_response _apputils.on_too_many_file_descriptors

I got these functions from bombsquad_headless and not everything is functions here because I'm too lazy to sort it, but I think the general principle is clear.

IvanPragma commented 1 year ago

You can do monkey patch for any of this functions.

def function_new(*args, **kwargs) -> None:
    # your code here
    return function_old(*args, **kwargs)

function_old = module.function
module.function = function_new
TheMade4 commented 1 year ago

You can do monkey patch for any of this functions.

def function_new(*args, **kwargs) -> None:
    # your code here
    return function_uld(*args, **kwargs)

function_old = module.function
module.function = new_function

this will not work for the "ba" module from the plugin

TheMade4 commented 1 year ago

And also this functionality is needed on the server

TheMade4 commented 1 year ago

monkey patch will not work for ba._hooks.filter_chat_message from plugin

IvanPragma commented 1 year ago

this will not work for the "ba" module from the plugin

For most functions/methods the monkey patch will work correctly.

IvanPragma commented 1 year ago

monkey patch will not work for ba._hooks.filter_chat_message from plugin

Yes, this is known issue. As far as I know, the C++ layer caches this function on startup. So, you can't monkey patch it from the plugin. To solve this problem you can create .py file at bastd module that will do monkey patch of this function, but don't forget to import this from bastd/__init__.py file.

TheMade4 commented 1 year ago

edit files in folder in ba_data is not an option

Dliwk commented 1 year ago

Yes, known issue, if anyone would come up with some reload_hooks() PR, it would be great.

TheMade4 commented 1 year ago

Yes, known issue, if anyone would come up with some reload_hooks() PR, it would be great.

Yes, that's a good idea