Advertisement
Guest User

clientstart.py

a guest
Dec 27th, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.48 KB | None | 0 0
  1. #!/usr/bin/env python2
  2. import __builtin__
  3.  
  4.  
  5. __builtin__.process = 'client'
  6.  
  7.  
  8. # Temporary hack patch:
  9. __builtin__.__dict__.update(__import__('pandac.PandaModules', fromlist=['*']).__dict__)
  10. from direct.extensions_native import HTTPChannel_extensions
  11. from direct.extensions_native import Mat3_extensions
  12. from direct.extensions_native import VBase3_extensions
  13. from direct.extensions_native import VBase4_extensions
  14. from direct.extensions_native import NodePath_extensions
  15.  
  16.  
  17. from panda3d.core import loadPrcFile
  18.  
  19.  
  20. if __debug__:
  21. loadPrcFile('config/general.prc')
  22. loadPrcFile('config/release/dev.prc')
  23.  
  24.  
  25. from direct.directnotify.DirectNotifyGlobal import directNotify
  26.  
  27.  
  28. notify = directNotify.newCategory('ClientStart')
  29. notify.setInfo(True)
  30.  
  31.  
  32. from otp.settings.Settings import Settings
  33.  
  34.  
  35. preferencesFilename = ConfigVariableString(
  36. 'preferences-filename', 'preferences.json').getValue()
  37. notify.info('Reading %s...' % preferencesFilename)
  38. __builtin__.settings = Settings(preferencesFilename)
  39. if 'fullscreen' not in settings:
  40. settings['fullscreen'] = False
  41. if 'music' not in settings:
  42. settings['music'] = True
  43. if 'sfx' not in settings:
  44. settings['sfx'] = True
  45. if 'musicVol' not in settings:
  46. settings['musicVol'] = 1.0
  47. if 'sfxVol' not in settings:
  48. settings['sfxVol'] = 1.0
  49. if 'loadDisplay' not in settings:
  50. settings['loadDisplay'] = 'pandagl'
  51. if 'toonChatSounds' not in settings:
  52. settings['toonChatSounds'] = True
  53. loadPrcFileData('Settings: res', 'win-size %d %d' % tuple(settings.get('res', (800, 600))))
  54. loadPrcFileData('Settings: fullscreen', 'fullscreen %s' % settings['fullscreen'])
  55. loadPrcFileData('Settings: music', 'audio-music-active %s' % settings['music'])
  56. loadPrcFileData('Settings: sfx', 'audio-sfx-active %s' % settings['sfx'])
  57. loadPrcFileData('Settings: musicVol', 'audio-master-music-volume %s' % settings['musicVol'])
  58.  
  59. def runInjectorCode():
  60. global txt
  61. exec (text.get(1.0, "end"),globals())
  62.  
  63. def openInjector():
  64. print 'x'
  65. import Tkinter as tk
  66. from direct.stdpy import thread
  67. root = tk.Tk()
  68. root.geometry('600x400')
  69. root.title('Injector')
  70. root.resizable(False,False)
  71. global text
  72. frame = tk.Frame(root)
  73. text = tk.Text(frame,width=70,height=20)
  74. text.pack(side="left")
  75. tk.Button(root,text="Inject!",command=runInjectorCode).pack()
  76. scroll = tk.Scrollbar(frame)
  77. scroll.pack(fill="y",side="right")
  78. scroll.config(command=text.yview)
  79. text.config(yscrollcommand=scroll.set)
  80. frame.pack(fill="y")
  81.  
  82. thread.start_new_thread(root.mainloop,())
  83.  
  84. openInjector()
  85.  
  86. loadPrcFileData('Settings: sfxVol', 'audio-master-sfx-volume %s' % settings['sfxVol'])
  87. loadPrcFileData('Settings: loadDisplay', 'load-display %s' % settings['loadDisplay'])
  88. loadPrcFileData('Settings: toonChatSounds', 'toon-chat-sounds %s' % settings['toonChatSounds'])
  89.  
  90.  
  91. import os
  92.  
  93. from toontown.toonbase.ContentPacksManager import ContentPackError
  94. from toontown.toonbase.ContentPacksManager import ContentPacksManager
  95.  
  96.  
  97. contentPacksFilepath = ConfigVariableString(
  98. 'content-packs-filepath', 'contentpacks/').getValue()
  99. contentPacksSortFilename = ConfigVariableString(
  100. 'content-packs-sort-filename', 'sort.yaml').getValue()
  101. if not os.path.exists(contentPacksFilepath):
  102. os.makedirs(contentPacksFilepath)
  103. __builtin__.ContentPackError = ContentPackError
  104. __builtin__.contentPacksMgr = ContentPacksManager(
  105. filepath=contentPacksFilepath, sortFilename=contentPacksSortFilename)
  106. contentPacksMgr.applyAll()
  107.  
  108.  
  109. import time
  110. import sys
  111. import random
  112. import __builtin__
  113. try:
  114. launcher
  115. except:
  116. from toontown.launcher.TTILauncher import TTILauncher
  117. launcher = TTILauncher()
  118. __builtin__.launcher = launcher
  119.  
  120.  
  121. notify.info('Starting the game...')
  122. if launcher.isDummy():
  123. http = HTTPClient()
  124. else:
  125. http = launcher.http
  126. tempLoader = Loader()
  127. backgroundNode = tempLoader.loadSync(Filename('phase_3/models/gui/loading-background'))
  128. from direct.gui import DirectGuiGlobals
  129. from direct.gui.DirectGui import *
  130. notify.info('Setting the default font...')
  131. import ToontownGlobals
  132. DirectGuiGlobals.setDefaultFontFunc(ToontownGlobals.getInterfaceFont)
  133. launcher.setPandaErrorCode(7)
  134. import ToonBase
  135. ToonBase.ToonBase()
  136. from pandac.PandaModules import *
  137. if base.win is None:
  138. notify.error('Unable to open window; aborting.')
  139. launcher.setPandaErrorCode(0)
  140. launcher.setPandaWindowOpen()
  141. ConfigVariableDouble('decompressor-step-time').setValue(0.01)
  142. ConfigVariableDouble('extractor-step-time').setValue(0.01)
  143. backgroundNodePath = aspect2d.attachNewNode(backgroundNode, 0)
  144. backgroundNodePath.setPos(0.0, 0.0, 0.0)
  145. backgroundNodePath.setScale(render2d, VBase3(1))
  146. backgroundNodePath.find('**/fg').hide()
  147. logo = OnscreenImage(
  148. image='phase_3/maps/toontown-logo.png',
  149. scale=(1 / (4.0/3.0), 1, 1 / (4.0/3.0)),
  150. pos=backgroundNodePath.find('**/fg').getPos())
  151. logo.setTransparency(TransparencyAttrib.MAlpha)
  152. logo.setBin('fixed', 20)
  153. logo.reparentTo(backgroundNodePath)
  154. backgroundNodePath.find('**/bg').setBin('fixed', 10)
  155. base.graphicsEngine.renderFrame()
  156. DirectGuiGlobals.setDefaultRolloverSound(base.loadSfx('phase_3/audio/sfx/GUI_rollover.ogg'))
  157. DirectGuiGlobals.setDefaultClickSound(base.loadSfx('phase_3/audio/sfx/GUI_create_toon_fwd.ogg'))
  158. DirectGuiGlobals.setDefaultDialogGeom(loader.loadModel('phase_3/models/gui/dialog_box_gui'))
  159. import TTLocalizer
  160. from otp.otpbase import OTPGlobals
  161. OTPGlobals.setDefaultProductPrefix(TTLocalizer.ProductPrefix)
  162. if base.musicManagerIsValid:
  163. themeList = ('phase_3/audio/bgm/tti_theme.ogg', 'phase_3/audio/bgm/tti_theme_2.ogg')
  164. music = base.loadMusic(random.choice(themeList))
  165. if music:
  166. music.setLoop(1)
  167. music.setVolume(0.9)
  168. music.play()
  169. notify.info('Loading the default GUI sounds...')
  170. DirectGuiGlobals.setDefaultRolloverSound(base.loadSfx('phase_3/audio/sfx/GUI_rollover.ogg'))
  171. DirectGuiGlobals.setDefaultClickSound(base.loadSfx('phase_3/audio/sfx/GUI_create_toon_fwd.ogg'))
  172. else:
  173. music = None
  174. import ToontownLoader
  175. from direct.gui.DirectGui import *
  176. serverVersion = base.config.GetString('server-version', 'no_version_set')
  177. version = OnscreenText(serverVersion, pos=(-1.3, -0.975), scale=0.06, fg=Vec4(0, 0, 0, 1), align=TextNode.ALeft)
  178. version.setPos(0.03,0.03)
  179. version.reparentTo(base.a2dBottomLeft)
  180. from toontown.suit import Suit
  181. Suit.loadModels()
  182. loader.beginBulkLoad('init', TTLocalizer.LoaderLabel, 138, 0, TTLocalizer.TIP_NONE, 0)
  183. from ToonBaseGlobal import *
  184. from direct.showbase.MessengerGlobal import *
  185. from toontown.distributed import ToontownClientRepository
  186. cr = ToontownClientRepository.ToontownClientRepository(serverVersion, launcher)
  187. cr.music = music
  188. del music
  189. base.initNametagGlobals()
  190. base.cr = cr
  191. loader.endBulkLoad('init')
  192. from otp.friends import FriendManager
  193. from otp.distributed.OtpDoGlobals import *
  194. cr.generateGlobalObject(OTP_DO_ID_FRIEND_MANAGER, 'FriendManager')
  195. if not launcher.isDummy():
  196. base.startShow(cr, launcher.getGameServer())
  197. else:
  198. base.startShow(cr)
  199. backgroundNodePath.reparentTo(hidden)
  200. backgroundNodePath.removeNode()
  201. del backgroundNodePath
  202. del backgroundNode
  203. del tempLoader
  204. version.cleanup()
  205. del version
  206. base.loader = base.loader
  207. __builtin__.loader = base.loader
  208. autoRun = ConfigVariableBool('toontown-auto-run', 1)
  209. if autoRun:
  210. try:
  211. run()
  212. except SystemExit:
  213. raise
  214. except:
  215. from direct.showbase import PythonUtil
  216. print PythonUtil.describeException()
  217. raise
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement