Skip to content

Commit

Permalink
Fix filtering of onPlayerSpeaking event not working in WoT 1.6.0.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhakonen committed Aug 25, 2019
1 parent e554b8a commit 637a915
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
32 changes: 11 additions & 21 deletions src/mod_tessumod.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def init():

g_messengerEvents.users.onUsersListReceived += on_users_list_received

add_onPlayerSpeaking_filter(g_messengerEvents.voip.onPlayerSpeaking)
g_messengerEvents.voip.onPlayerSpeaking = wrap_onPlayerSpeaking(g_messengerEvents.voip.onPlayerSpeaking)

notifications.add_event_handler(notifications.TSPLUGIN_DOWNLOAD, on_tsplugin_download)
notifications.add_event_handler(notifications.TSPLUGIN_IGNORED, on_tsplugin_ignore_toggled)
Expand All @@ -141,7 +141,7 @@ def fini():
g_playerEvents.onAvatarReady -= g_positional_audio.enable
g_playerEvents.onAvatarBecomeNonPlayer -= g_positional_audio.disable

remove_onPlayerSpeaking_filter(g_messengerEvents.voip.onPlayerSpeaking)
g_messengerEvents.voip.onPlayerSpeaking = g_messengerEvents.voip.onPlayerSpeaking.get_original_event()

g_authentication_error = None
g_keyvaluestorage = None
Expand Down Expand Up @@ -503,25 +503,15 @@ def wrapper(*args, **kwargs):
return orig_method(*args, **kwargs)
return wrapper

def add_onPlayerSpeaking_filter(obj):
class FilterEvent(type(obj)):
def __call__(self, dbid, talking):
if talking:
self.unfiltered_call(dbid, talking)
elif has_speak_feedback(dbid):
pass
else:
self.unfiltered_call(dbid, talking)

def unfiltered_call(self, *args, **kwargs):
self.original_class.__call__(self, *args, **kwargs)

obj.original_class = obj.__class__
obj.__class__ = FilterEvent

def remove_onPlayerSpeaking_filter(obj):
obj.__class__ = obj.original_class
del obj.original_class
def wrap_onPlayerSpeaking(obj):
def filter_func(self, orig_func, dbid, talking):
if talking:
orig_func(dbid, talking)
elif has_speak_feedback(dbid):
pass
else:
orig_func(dbid, talking)
return utils.EventFilter(obj, filter_func)

def on_users_list_received(tags):
'''This function populates user cache with friends and clan members from
Expand Down
25 changes: 25 additions & 0 deletions src/tessumod/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,31 @@ def id(self):
def __repr__(self):
return "Player(name={0}, id={1})".format(self._name, self._id)

class EventFilter(object):
def __init__(self, orig_event, filter_func):
self._orig_event = orig_event
self._filter_func = filter_func

def __call__(self, *args, **kwargs):
return self._filter_func(self, self.unfiltered_call, *args, **kwargs)

def __iadd__(self, delegate):
self._orig_event.__iadd__(delegate)
return self

def __isub__(self, delegate):
self._orig_event.__isub__(delegate)
return self

def clear(self):
self._orig_event.clear()

def unfiltered_call(self, *args, **kwargs):
return self._orig_event.__call__(*args, **kwargs)

def get_original_event(self):
return self._orig_event

class MinimapMarkersController(object):
'''MinimapMarkersController class repeatably starts given marker 'action' every
'interval' seconds in minimap over given 'vehicle_id', effectively creating
Expand Down

0 comments on commit 637a915

Please sign in to comment.