Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Embedded file name: EdgeDetect.py
- __application__ = 'Edge Detect Mod'
- __appShortName__ = 'EdgeDetect'
- __authors__ = ['GPCracker']
- __version__ = '0.0.5'
- __clientVersion__ = '0.9.7'
- __status__ = 'Beta'
- if __name__ == '__main__':
- modInfo = '[{}] {} v{} {} by {} (WOT Client {}).'.format(__appShortName__, __application__, __version__, __status__, ', '.join(__authors__), __clientVersion__)
- print modInfo
- from time import sleep
- sleep(len(modInfo) * (4.0 / 70))
- exit()
- import BigWorld
- import ResMgr
- import Keys
- import Math
- def getClientVersion():
- from Account import _readClientServerVersion
- return _readClientServerVersion()[1].split('_')[1]
- def isCommonTest():
- from Account import _readClientServerVersion
- return _readClientServerVersion()[1].split('_')[0] == 'ct'
- def macrosSubstitution(message, **kwargs):
- import re
- for macros, value in kwargs.items():
- message = re.compile('\\{\\{' + macros + '\\}\\}').sub(str(value), message)
- return message
- class Callback(object):
- def __init__(self, time, function, *args, **kwargs):
- import functools, weakref
- proxiesL = []
- for arg in args:
- try:
- proxiesL.append(weakref.proxy(arg))
- except TypeError:
- proxiesL.append(arg)
- proxiesD = {}
- for key, value in kwargs.iteritems():
- try:
- proxiesD[key] = weakref.proxy(value)
- except TypeError:
- proxiesD[key] = value
- self.__cbID = BigWorld.callback(time, functools.partial(weakref.proxy(function), *proxiesL, **proxiesD))
- return
- def __del__(self):
- try:
- BigWorld.cancelCallback(self.__cbID)
- except ValueError:
- pass
- return None
- class Event(object):
- def __init__(self):
- self.__delegates = []
- return None
- def __iadd__(self, delegate):
- if delegate not in self.__delegates:
- self.__delegates.append(delegate)
- return self
- def __isub__(self, delegate):
- if delegate in self.__delegates:
- self.__delegates.remove(delegate)
- return self
- def __call__(self, *args, **kwargs):
- for delegate in self.__delegates:
- try:
- delegate(*args, **kwargs)
- except:
- import traceback
- traceback.print_exc()
- return
- def __repr__(self):
- return 'Event({}):{}'.format(len(self.__delegates), repr(self.__delegates))
- class Trigger(object):
- def __init__(self, status = False, onActivate = None, onDeactivate = None, onChange = None):
- self.__status = status
- self.onActivate = onActivate if onActivate is not None else Event()
- self.onDeactivate = onDeactivate if onDeactivate is not None else Event()
- self.onChange = onChange if onChange is not None else Event()
- return
- @property
- def status(self):
- return self.__status
- @status.setter
- def status(self, value):
- if value and not self.__status:
- self.onActivate()
- self.onChange(True)
- elif not value and self.__status:
- self.onDeactivate()
- self.onChange(False)
- self.__status = bool(value)
- return None
- def enable(self):
- self.status = True
- return None
- def disable(self):
- self.status = False
- return None
- def __repr__(self):
- return 'Trigger(onActivate = {}, onDeactivate = {}, onChange = {})'.format(repr(self.onActivate), repr(self.onDeactivate), repr(self.onChange))
- class DelayTrigger(Trigger):
- def __init__(self, timestampGetter, dynamicStatus = False, status = False, activateDelay = 0.0, deactivateDelay = 0.0, onActivate = None, onDeactivate = None, onChange = None):
- self.__timestampGetter = timestampGetter
- self.__dynamicStatus = dynamicStatus
- self.__dynamicStatusTimestamp = None
- self.__activateDelay = activateDelay
- self.__deactivateDelay = deactivateDelay
- return super(DelayTrigger, self).__init__(status, onActivate, onDeactivate, onChange)
- def __repr__(self):
- return 'DelayTrigger(onActivate = {}, onDeactivate = {}, onChange = {})'.format(repr(self.onActivate), repr(self.onDeactivate), repr(self.onChange))
- @property
- def dynamicStatus(self):
- return self.__dynamicStatus
- @dynamicStatus.setter
- def dynamicStatus(self, value):
- delay = self.__activateDelay if self.__dynamicStatus else self.__deactivateDelay
- if value != self.__dynamicStatus:
- self.__dynamicStatus = value
- self.__dynamicStatusTimestamp = self.__timestampGetter()
- elif self.__dynamicStatusTimestamp + delay < self.__timestampGetter():
- self.status = self.__dynamicStatus
- return None
- def dynamicEnable(self):
- self.dynamicStatus = True
- return None
- def dynamicDisable(self):
- self.dynamicStatus = False
- return None
- class ThreeStateTrigger(object):
- def __init__(self, status = None, onActivate = None, onDeactivate = None, onReset = None, onChange = None):
- self.__status = status
- self.onActivate = onActivate if onActivate is not None else Event()
- self.onDeactivate = onDeactivate if onDeactivate is not None else Event()
- self.onReset = onReset if onReset is not None else Event()
- self.onChange = onChange if onChange is not None else Event()
- return
- @property
- def status(self):
- return self.__status
- @status.setter
- def status(self, value):
- if value != self.__status:
- if value == True:
- self.onActivate()
- elif value == False:
- self.onDeactivate()
- elif value == None:
- self.onReset()
- else:
- raise TypeError()
- self.onChange(value)
- self.__status = value
- return
- def enable(self):
- self.status = True
- return None
- def disable(self):
- self.status = False
- return None
- def reset(self):
- self.status = None
- return
- def __repr__(self):
- return 'ThreeStateTrigger(onActivate = {}, onDeactivate = {}, onReset = {}, onChange = {}))'.format(repr(self.onActivate), repr(self.onDeactivate), repr(self.onReset), repr(self.onChange))
- class ConfigReader(object):
- BASE_TYPES = ('Binary', 'Blob', 'Bool', 'Float', 'Int', 'Int64', 'Matrix', 'String', 'Vector2', 'Vector3', 'Vector4', 'WideString')
- def readBase(self, typeName, xml, default):
- if xml is not None:
- return getattr(xml, 'as' + typeName)
- else:
- return default
- def readDict(self, xml, default):
- getSectionXML = lambda sectionName: (xml[sectionName] if xml is not None else None)
- return dict([ (sectionName, self.readSection(getSectionXML(sectionName), default[sectionName])) for sectionName in default.keys() ])
- def readExt(self, typeName, xml, default):
- raise typeName in self.__extTypes or AssertionError('No reader for {} type'.format(typeName))
- return self.__extTypes[typeName](xml, default)
- def readList(self, xml, default, itemName = 'item', itemType = 'String', itemDefault = ''):
- if xml is not None:
- return [ self.readSection(xmlSection, (itemType, itemDefault)) for sectionName, xmlSection in xml.items() if sectionName == itemName ]
- else:
- return [ self.readSection(None, (itemType, defaultItem)) for defaultItem in default ]
- def readCustomDict(self, xml, default, itemType = 'String', itemDefault = ''):
- if xml is not None:
- return dict([ (sectionName, self.readSection(xmlSection, (itemType, itemDefault))) for sectionName, xmlSection in xml.items() ])
- else:
- return dict([ (sectionName, self.readSection(None, (itemType, defaultItem))) for sectionName, defaultItem in default.items() ])
- def readSection(self, xmlSection, defSection):
- if isinstance(defSection, (list, tuple)):
- sectionType, sectionDefault = defSection
- if sectionType in self.BASE_TYPES:
- return self.readBase(sectionType, xmlSection, sectionDefault)
- else:
- return self.readExt(sectionType, xmlSection, sectionDefault)
- else:
- if isinstance(defSection, dict):
- return self.readDict(xmlSection, defSection)
- raise IOError('Invalid config parameter type "{}".'.format(type(defSection).__name__))
- return None
- def readConfig(self, xmlPath, defConfig):
- return self.readSection(ResMgr.openSection(xmlPath), defConfig)
- def __init__(self, extTypes = {}):
- self.__extTypes = extTypes
- return None
- @property
- def extTypes(self):
- return self.__extTypes
- @extTypes.setter
- def extTypes(self, value):
- self.__extTypes = value
- return None
- def __del__(self):
- return None
- _config_ = None
- def defaultConfig():
- return {'modEnabled': ('Bool', True),
- 'ignoreClientVersion': ('Bool', False),
- 'hookSetTimeout': ('Float', 3.0),
- 'modLoadedMessage': ('WideString', u'{} loaded.'.format(__application__)),
- 'modUpdateMessage': ('WideString', u'Please update {}!'.format(__application__)),
- 'edgeHighlight': {'color0': ('Vector4', Math.Vector4(127, 127, 127, 255)),
- 'color1': ('Vector4', Math.Vector4(255, 18, 7, 255)),
- 'color2': ('Vector4', Math.Vector4(124, 214, 6, 255)),
- 'color3': ('Vector4', Math.Vector4(255, 255, 255, 255)),
- 'selfColorIndex': ('Int', 0),
- 'selfAllocateInvisiblePartsOnly': ('Bool', True),
- 'enemyColorIndex': ('Int', -1),
- 'enemyAllocateInvisiblePartsOnly': ('Bool', False),
- 'targetEnemyColorIndex': ('Int', 1),
- 'targetEnemyAllocateInvisiblePartsOnly': ('Bool', False),
- 'autoAimEnemyColorIndex': ('Int', -1),
- 'autoAimEnemyAllocateInvisiblePartsOnly': ('Bool', False),
- 'friendColorIndex': ('Int', -1),
- 'friendAllocateInvisiblePartsOnly': ('Bool', False),
- 'targetFriendColorIndex': ('Int', 2),
- 'targetFriendAllocateInvisiblePartsOnly': ('Bool', False)}}
- def readConfig():
- mainSection = ResMgr.openSection(__file__.replace('.pyc', '.xml'))
- if mainSection is None:
- print '[{}] Config loading failed.'.format(__appShortName__)
- else:
- print '[{}] Config successfully loaded.'.format(__appShortName__)
- return ConfigReader().readSection(mainSection, defaultConfig())
- def new_PlayerAvatar_onEnterWorld(self, *args, **kwargs):
- result = old_PlayerAvatar_onEnterWorld(self, *args, **kwargs)
- from helpers import EdgeDetectColorController
- EdgeDetectColorController.g_instance.updateColors()
- return result
- def new_PlayerAvatar_targetFocus(self, entity):
- global _config_
- result = old_PlayerAvatar_targetFocus(self, entity)
- import constants
- import Vehicle
- isGuiVisible = self._PlayerAvatar__isGuiVisible
- isInTutorial = self.arena is not None and self.arena.guiType == constants.ARENA_GUI_TYPE.TUTORIAL
- if (isGuiVisible or isInTutorial) and isinstance(entity, Vehicle.Vehicle) and entity.isStarted and entity.isAlive():
- BigWorld.wgDelEdgeDetectEntity(entity)
- if entity is self.autoAimVehicle:
- colorIndex = _config_['edgeHighlight']['autoAimEnemyColorIndex']
- allocateInvisiblePartsOnly = _config_['edgeHighlight']['autoAimEnemyAllocateInvisiblePartsOnly']
- elif self.team == entity.publicInfo['team']:
- colorIndex = _config_['edgeHighlight']['targetFriendColorIndex']
- allocateInvisiblePartsOnly = _config_['edgeHighlight']['targetFriendAllocateInvisiblePartsOnly']
- else:
- colorIndex = _config_['edgeHighlight']['targetEnemyColorIndex']
- allocateInvisiblePartsOnly = _config_['edgeHighlight']['targetEnemyAllocateInvisiblePartsOnly']
- if colorIndex >= 0:
- BigWorld.wgAddEdgeDetectEntity(entity, colorIndex, allocateInvisiblePartsOnly)
- return result
- def new_PlayerAvatar_targetBlur(self, prevEntity):
- result = old_PlayerAvatar_targetBlur(self, prevEntity)
- import constants
- import Vehicle
- isGuiVisible = self._PlayerAvatar__isGuiVisible
- isInTutorial = self.arena is not None and self.arena.guiType == constants.ARENA_GUI_TYPE.TUTORIAL
- if (isGuiVisible or isInTutorial) and isinstance(prevEntity, Vehicle.Vehicle) and prevEntity.isStarted and prevEntity.isAlive():
- BigWorld.wgDelEdgeDetectEntity(prevEntity)
- if prevEntity is self.autoAimVehicle:
- colorIndex = _config_['edgeHighlight']['autoAimEnemyColorIndex']
- allocateInvisiblePartsOnly = _config_['edgeHighlight']['autoAimEnemyAllocateInvisiblePartsOnly']
- elif self.team == prevEntity.publicInfo['team']:
- colorIndex = _config_['edgeHighlight']['friendColorIndex']
- allocateInvisiblePartsOnly = _config_['edgeHighlight']['friendAllocateInvisiblePartsOnly']
- else:
- colorIndex = _config_['edgeHighlight']['enemyColorIndex']
- allocateInvisiblePartsOnly = _config_['edgeHighlight']['enemyAllocateInvisiblePartsOnly']
- if colorIndex >= 0:
- BigWorld.wgAddEdgeDetectEntity(prevEntity, colorIndex, allocateInvisiblePartsOnly)
- return result
- def new_PlayerAvatar_setVisibleGUI(self, bool):
- result = old_PlayerAvatar_setVisibleGUI(self, bool)
- import Vehicle
- playerVehicle = BigWorld.entity(self.playerVehicleID)
- if isinstance(playerVehicle, Vehicle.Vehicle) and playerVehicle.isStarted and playerVehicle.isAlive() and bool:
- BigWorld.wgDelEdgeDetectEntity(playerVehicle)
- colorIndex = _config_['edgeHighlight']['selfColorIndex']
- allocateInvisiblePartsOnly = _config_['edgeHighlight']['selfAllocateInvisiblePartsOnly']
- BigWorld.wgAddEdgeDetectEntity(playerVehicle, colorIndex, allocateInvisiblePartsOnly)
- return result
- def new_PlayerAvatar_autoAimVehID_getter(self):
- if hasattr(self, '__autoAimVehID'):
- return self.__autoAimVehID
- return 0
- def new_PlayerAvatar_autoAimVehID_setter(self, value):
- import Vehicle
- oldAutoAimVehicle = BigWorld.entity(self.__autoAimVehID) if hasattr(self, '__autoAimVehID') else None
- self.__autoAimVehID = value
- newAutoAimVehicle = BigWorld.entity(self.__autoAimVehID)
- if isinstance(oldAutoAimVehicle, Vehicle.Vehicle) and oldAutoAimVehicle.isStarted and oldAutoAimVehicle.isAlive():
- BigWorld.wgDelEdgeDetectEntity(oldAutoAimVehicle)
- if oldAutoAimVehicle is BigWorld.target():
- if oldAutoAimVehicle.publicInfo['team'] == BigWorld.player().team:
- colorIndex = _config_['edgeHighlight']['targetFriendColorIndex']
- allocateInvisiblePartsOnly = _config_['edgeHighlight']['targetFriendAllocateInvisiblePartsOnly']
- else:
- colorIndex = _config_['edgeHighlight']['targetEnemyColorIndex']
- allocateInvisiblePartsOnly = _config_['edgeHighlight']['targetEnemyAllocateInvisiblePartsOnly']
- elif oldAutoAimVehicle.publicInfo['team'] == BigWorld.player().team:
- colorIndex = _config_['edgeHighlight']['friendColorIndex']
- allocateInvisiblePartsOnly = _config_['edgeHighlight']['friendAllocateInvisiblePartsOnly']
- else:
- colorIndex = _config_['edgeHighlight']['enemyColorIndex']
- allocateInvisiblePartsOnly = _config_['edgeHighlight']['enemyAllocateInvisiblePartsOnly']
- if colorIndex >= 0:
- BigWorld.wgAddEdgeDetectEntity(oldAutoAimVehicle, colorIndex, allocateInvisiblePartsOnly)
- if isinstance(newAutoAimVehicle, Vehicle.Vehicle) and newAutoAimVehicle.isStarted and newAutoAimVehicle.isAlive():
- BigWorld.wgDelEdgeDetectEntity(newAutoAimVehicle)
- colorIndex = _config_['edgeHighlight']['autoAimEnemyColorIndex']
- allocateInvisiblePartsOnly = _config_['edgeHighlight']['autoAimEnemyAllocateInvisiblePartsOnly']
- if colorIndex >= 0:
- BigWorld.wgAddEdgeDetectEntity(newAutoAimVehicle, colorIndex, allocateInvisiblePartsOnly)
- return
- def new_Vehicle_startVisual(self):
- result = old_Vehicle_startVisual(self)
- if self.isStarted and self.isAlive():
- BigWorld.wgDelEdgeDetectEntity(self)
- if self.isPlayer:
- colorIndex = _config_['edgeHighlight']['selfColorIndex']
- allocateInvisiblePartsOnly = _config_['edgeHighlight']['selfAllocateInvisiblePartsOnly']
- elif BigWorld.player().team == self.publicInfo['team']:
- colorIndex = _config_['edgeHighlight']['friendColorIndex']
- allocateInvisiblePartsOnly = _config_['edgeHighlight']['friendAllocateInvisiblePartsOnly']
- else:
- colorIndex = _config_['edgeHighlight']['enemyColorIndex']
- allocateInvisiblePartsOnly = _config_['edgeHighlight']['enemyAllocateInvisiblePartsOnly']
- if colorIndex >= 0:
- BigWorld.wgAddEdgeDetectEntity(self, colorIndex, allocateInvisiblePartsOnly)
- return result
- def new_Vehicle_stopVisual(self):
- if self.isStarted and self.isAlive():
- BigWorld.wgDelEdgeDetectEntity(self)
- return old_Vehicle_stopVisual(self)
- def new_Vehicle_onVehicleDeath(self, *args, **kwargs):
- result = old_Vehicle_onVehicleDeath(self, *args, **kwargs)
- if self.isStarted:
- BigWorld.wgDelEdgeDetectEntity(self)
- return result
- def new_EdgeDetectColorController_changeColor(self, diff):
- from Account import PlayerAccount
- if isinstance(BigWorld.player(), PlayerAccount):
- return old_EdgeDetectColorController_changeColor(self, diff)
- color0 = _config_['edgeHighlight']['color0'].scale(1.0 / 255.0)
- color1 = _config_['edgeHighlight']['color1'].scale(1.0 / 255.0)
- color2 = _config_['edgeHighlight']['color2'].scale(1.0 / 255.0)
- color3 = _config_['edgeHighlight']['color3'].scale(1.0 / 255.0)
- BigWorld.wgSetEdgeDetectColors((color0,
- color1,
- color2,
- color3))
- def injectHooks():
- global old_PlayerAvatar_setVisibleGUI
- global old_Vehicle_stopVisual
- global old_EdgeDetectColorController_changeColor
- global old_PlayerAvatar_onEnterWorld
- global old_PlayerAvatar_targetFocus
- global old_PlayerAvatar_targetBlur
- global old_Vehicle_startVisual
- global old_Vehicle_onVehicleDeath
- from Avatar import PlayerAvatar
- old_PlayerAvatar_onEnterWorld = PlayerAvatar.onEnterWorld
- PlayerAvatar.onEnterWorld = new_PlayerAvatar_onEnterWorld
- old_PlayerAvatar_targetFocus = PlayerAvatar.targetFocus
- PlayerAvatar.targetFocus = new_PlayerAvatar_targetFocus
- old_PlayerAvatar_targetBlur = PlayerAvatar.targetBlur
- PlayerAvatar.targetBlur = new_PlayerAvatar_targetBlur
- old_PlayerAvatar_setVisibleGUI = PlayerAvatar._PlayerAvatar__setVisibleGUI
- PlayerAvatar._PlayerAvatar__setVisibleGUI = new_PlayerAvatar_setVisibleGUI
- PlayerAvatar._PlayerAvatar__autoAimVehID = property(new_PlayerAvatar_autoAimVehID_getter, new_PlayerAvatar_autoAimVehID_setter)
- from Vehicle import Vehicle
- old_Vehicle_startVisual = Vehicle.startVisual
- Vehicle.startVisual = new_Vehicle_startVisual
- old_Vehicle_stopVisual = Vehicle.stopVisual
- Vehicle.stopVisual = new_Vehicle_stopVisual
- old_Vehicle_onVehicleDeath = Vehicle._Vehicle__onVehicleDeath
- Vehicle._Vehicle__onVehicleDeath = new_Vehicle_onVehicleDeath
- from helpers.EdgeDetectColorController import EdgeDetectColorController
- old_EdgeDetectColorController_changeColor = EdgeDetectColorController._EdgeDetectColorController__changeColor
- EdgeDetectColorController._EdgeDetectColorController__changeColor = new_EdgeDetectColorController_changeColor
- return None
- def showStartupMessage(message):
- from gui import SystemMessages
- import functools
- if SystemMessages.g_instance is None:
- BigWorld.callback(1.0, functools.partial(showStartupMessage, message))
- elif message is not None and message != '':
- SystemMessages.pushMessage(message)
- return
- def loadMod():
- global _config_
- _config_ = readConfig()
- if _config_['ignoreClientVersion'] or getClientVersion() == __clientVersion__:
- if _config_['modEnabled']:
- BigWorld.callback(_config_['hookSetTimeout'], injectHooks)
- showStartupMessage(_config_['modLoadedMessage'])
- else:
- showStartupMessage(_config_['modUpdateMessage'])
- print '***** Please update {}! *****'.format(__application__)
- return None
- loadMod()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement