Пример #1
0
    def __init__(self):
        self._dc_file = DCFile()
        self._dc_suffix = ""

        self._dclasses_by_name = {}
        self._dclasses_by_number = {}

        self._hash_value = 0
    def __init__(self, root):
        self.root = root
        sys.path.append(root)
        os.chdir(self.root)

        # We haven't loaded this yet:
        self.spellbook = None

        from panda3d.direct import DCFile
        self.dcf = DCFile()
Пример #3
0
    def __init__(self, directory, version=None, language='english'):
        self.directory = directory
        self.version = version or determineVersion(self.directory)
        self.language = language.lower()

        self.dcfiles = [
            os.path.join(directory, 'config/otp.dc'),
            os.path.join(directory, 'config/toon.dc')
        ]
        self.modules = {}
        self.path_overrides = {}

        self.config_file = os.path.join(self.directory,
                                        'config/public_client.prc')

        self.mf = ModuleFinder(sys.path + [self.directory])
        from panda3d.direct import DCFile
        self.dcf = DCFile()
Пример #4
0
    def __init__(self, hasOwnerView):
        self.dcFiles = []
        self._hasOwnerView = hasOwnerView
        self.dcSuffix = ""
        self.dcFile = DCFile()
        self.dclassesByName = None
        self.dclassesByNumber = None
        self.hashVal = 0

        self.doId2do = {}
        if hasOwnerView:
            self.doId2ownerView = {}
Пример #5
0
    def __init__(self, hasOwnerView = False):
        self._hasOwnerView = hasOwnerView
        self.dcFile = DCFile()
        self.dcSuffix = ''

        self.dclassesByName = None
        self.dclassesByNumber = None
        self.hashVal = None

        DoInterestManager.__init__(self)
        DoCollectionManager.__init__(self)

        self.uniqueId = hash(self)
Пример #6
0
    def __init__(self, directory, version=None, language='english'):
        self.directory = directory
        self.version = version or determineVersion(self.directory)
        self.language = language.lower()

        self.dcfiles = [os.path.join(directory, 'config/otp.dc'),
                        os.path.join(directory, 'config/toon.dc')]
        self.modules = {}
        self.path_overrides = {}

        self.config_file = os.path.join(self.directory, 'config/public_client.prc')

        self.mf = ModuleFinder(sys.path+[self.directory])
        from panda3d.direct import DCFile
        self.dcf = DCFile()
Пример #7
0
class NetworkDCLoader(object):
    notify = directNotify.newCategory('NetworkDCLoader')

    def __init__(self):
        self._dc_file = DCFile()
        self._dc_suffix = ""

        self._dclasses_by_name = {}
        self._dclasses_by_number = {}

        self._hash_value = 0

    @property
    def dc_file(self):
        return self._dc_file

    @property
    def dc_suffix(self):
        return self._dc_suffix

    @property
    def dclasses_by_name(self):
        return self._dclasses_by_name

    @property
    def dclasses_by_number(self):
        return self._dclasses_by_number

    @property
    def hash_value(self):
        return self._hash_value

    def read_dc_files(self, dc_file_names=None):
        dc_imports = {}
        if dc_file_names == None:
            read_result = self._dc_file.read_all()
            if not read_result:
                self.notify.error("Could not read dc file.")
        else:
            for dc_fileName in dc_file_names:
                pathname = Filename(dc_fileName)
                read_result = self._dc_file.read(pathname)
                if not read_result:
                    self.notify.error("Could not read dc file: %s" %
                                      (pathname))

        self._hash_value = self._dc_file.get_hash()

        # Now get the class definition for the classes named in the DC
        # file.
        for i in range(self._dc_file.get_num_classes()):
            dclass = self._dc_file.get_class(i)
            number = dclass.get_number()
            class_name = dclass.get_name() + self._dc_suffix

            # Does the class have a definition defined in the newly
            # imported namespace?
            class_def = dc_imports.get(class_name)

            # Also try it without the dc_suffix.
            if class_def == None:
                class_name = dclass.get_name()
                class_def = dc_imports.get(class_name)

            if class_def == None:
                self.notify.debug("No class definition for %s." % (class_name))
            else:
                if inspect.ismodule(class_def):
                    if not hasattr(class_def, class_name):
                        self.notify.error(
                            "Module %s does not define class %s." %
                            (class_name, class_name))

                    class_def = getattr(class_def, class_name)

                if not inspect.isclass(class_def):
                    self.notify.error("Symbol %s is not a class name." %
                                      (class_name))
                else:
                    dclass.set_class_def(class_def)

            self._dclasses_by_name[class_name] = dclass
            if number >= 0:
                self._dclasses_by_number[number] = dclass
Пример #8
0
class ClientBuilder(object):
    MAINMODULE = 'toontown.toonbase.MiraiStart'

    def __init__(self, directory, version=None, language='english'):
        self.directory = directory
        self.version = version or determineVersion(self.directory)
        self.language = language.lower()

        self.dcfiles = [os.path.join(directory, 'config/otp.dc'),
                        os.path.join(directory, 'config/toon.dc')]
        self.modules = {}
        self.path_overrides = {}

        self.config_file = os.path.join(self.directory, 'config/public_client.prc')

        self.mf = ModuleFinder(sys.path+[self.directory])
        from panda3d.direct import DCFile
        self.dcf = DCFile()

    def should_exclude(self, modname):
        # The NonRepeatableRandomSource modules are imported by the dc file explicitly,
        # so we have to allow them.
        if 'NonRepeatableRandomSource' in modname:
            return False

        if modname.endswith('AI'):
            return True
        if modname.endswith('UD'):
            return True
        if modname.endswith('.ServiceStart'):
            return True

    def find_excludes(self):
        for path, dirs, files in os.walk(self.directory):
            for filename in files:
                filepath = os.path.join(path, filename)
                filepath = os.path.relpath(filepath, self.directory)
                if not filepath.endswith('.py'): continue
                filepath = filepath[:-3]
                modname = filepath.replace(os.path.sep, '.')
                if modname.endswith('.__init__'): modname = modname[:-9]
                if self.should_exclude(modname):
                    self.mf.excludes.append(modname)

    def find_dcfiles(self):
        for path, dirs, files in os.walk(self.directory):
            for filename in files:
                filepath = os.path.join(path, filename)
                if filename.endswith('.dc'):
                    self.dcfiles.append(filepath)

    def create_miraidata(self):
        # Create a temporary _miraidata.py and throw it on the path somewhere...

        # First, we need the minified DC file contents:
        from panda3d.core import StringStream
        dcStream = StringStream()
        self.dcf.write(dcStream, True)
        dcData = dcStream.getData()

        # Next we need config files...
        configData = []
        with open(self.config_file) as f:
            fd = f.read()
            fd = fd.replace('SERVER_VERSION_HERE', self.version)
            fd = fd.replace('LANGUAGE_HERE', self.language)
            configData.append(fd)

        md = 'CONFIG = %r\nDC = %r\n' % (configData, dcData)

        # Now we use tempfile to dump md:
        td = tempfile.mkdtemp()
        with open(os.path.join(td, '_miraidata.py'), 'w') as f:
            f.write(md)

        self.mf.path.append(td)

        atexit.register(shutil.rmtree, td)

    def include_dcimports(self):
        for m in xrange(self.dcf.getNumImportModules()):
            modparts = self.dcf.getImportModule(m).split('/')
            mods = [modparts[0]]
            if 'OV' in modparts[1:]:
                mods.append(modparts[0]+'OV')
            for mod in mods:
                self.mf.import_hook(mod)
                for s in xrange(self.dcf.getNumImportSymbols(m)):
                    symparts = self.dcf.getImportSymbol(m,s).split('/')
                    syms = [symparts[0]]
                    if 'OV' in symparts[1:]:
                        syms.append(symparts[0]+'OV')
                    for sym in syms:
                        try:
                            self.mf.import_hook('%s.%s' % (mod,sym))
                        except ImportError:
                            pass

    def build_modules(self):
        for modname, mod in self.mf.modules.items():
            if modname in self.path_overrides:
                modfile = self.path_overrides[modname]
            else:
                modfile = mod.__file__
            if not (modfile and modfile.endswith('.py')): continue
            is_package = modfile.endswith('__init__.py')
            with open(modfile, 'r') as f:
                code = compile(f.read(), modname, 'exec')
            self.modules[modname] = (is_package, code)

    def load_modules(self):
        #self.find_dcfiles()
        self.find_excludes()

        from panda3d.core import Filename
        for dc in self.dcfiles:
            self.dcf.read(Filename.fromOsSpecific(dc))

        self.create_miraidata()

        self.mf.import_hook(self.MAINMODULE)
        for module in EXTRA_MODULES:
            self.mf.import_hook(module)
        if self.language.lower() != "english":
            self.mf.import_hook('otp.otpbase.OTPLocalizer_%s' % self.language.capitalize())
            self.mf.import_hook('otp.otpbase.OTPLocalizer_%sProperty' % self.language.capitalize())
            self.mf.import_hook('toontown.toonbase.TTLocalizer_%s' % self.language.capitalize())
            self.mf.import_hook('toontown.toonbase.TTLocalizer_%s' % self.language.capitalize())
        self.modules['__main__'] = (False, compile('import %s' % self.MAINMODULE,
                                                   '__main__', 'exec'))

        self.include_dcimports()

        self.build_modules()


    def write_zip(self, outfile):
        zip = zipfile.ZipFile(outfile, 'w')
        for modname, (is_package, code) in self.modules.items():
            mcode = imp.get_magic() + '\x00'*4 + marshal.dumps(code)
            name = modname.replace('.','/')
            if is_package:
                name += '/__init__'
            name += '.pyo'
            zip.writestr(name, mcode)
        zip.close()

    def write_list(self, outfile):
        with open(outfile,'w') as out:
            for modname in sorted(self.modules.keys()):
                is_package, code = self.modules[modname]
                out.write('%s%s\n' % (modname, ' [PKG]' if is_package else ''))
class SpellbookLoader(object):
    """Loads all client and/or AI modules in order to get the spellbook
    initialized.
    """

    DC_FILES = ['config/toontown.dc']

    def __init__(self, root):
        self.root = root
        sys.path.append(root)
        os.chdir(self.root)

        # We haven't loaded this yet:
        self.spellbook = None

        from panda3d.direct import DCFile
        self.dcf = DCFile()

    def load_modules(self, client=True, ai=True):
        self.start_headless()
        self.load_dc()
        self.load_spellbook()

        if client:
            self.load_suffix('')
        if ai:
            self.load_suffix('AI')

    def start_headless(self):
        # Start a headless Panda3D base.
        from direct.showbase.ShowBase import ShowBase
        base = ShowBase(windowType='none')
        base.wantKarts = False
        base.wantPets = False

        import __builtin__

        class game:
            name = 'uberDog'
            process = 'server'

        __builtin__.game = game
        __builtin__.simbase = base
        __builtin__.__dev__ = False

        from panda3d.core import loadPrcFileData
        loadPrcFileData('',
                        'model-path resources\ndefault-model-extension .bam')

    def load_dc(self):
        # Load and parse toon.dc and otp.dc...
        from panda3d.core import Filename
        for dc in self.DC_FILES:
            full_path = os.path.join(self.root, dc)
            self.dcf.read(Filename.fromOsSpecific(full_path))

    def load_spellbook(self):
        from otp.ai.MagicWordGlobal import spellbook
        self.spellbook = spellbook

    def load_suffix(self, suffix):
        for m in xrange(self.dcf.getNumImportModules()):
            modparts = self.dcf.getImportModule(m).split('/')
            if not suffix or suffix in modparts[1:]:
                mod = modparts[0] + suffix
            else:
                mod = modparts[0]
            __import__(mod)
            for s in xrange(self.dcf.getNumImportSymbols(m)):
                symparts = self.dcf.getImportSymbol(m, s).split('/')
                syms = [symparts[0]]
                if not suffix or suffix in symparts[1:]:
                    sym = symparts[0] + suffix
                else:
                    continue
                try:
                    __import__('%s.%s' % (mod, sym))
                except ImportError:
                    pass
Пример #10
0
class ClientBuilder(object):
    MAINMODULE = 'toontown.toonbase.MiraiStart'

    def __init__(self, directory, version=None, language='english'):
        self.directory = directory
        self.version = version or determineVersion(self.directory)
        self.language = language.lower()

        self.dcfiles = [
            os.path.join(directory, 'config/otp.dc'),
            os.path.join(directory, 'config/toon.dc')
        ]
        self.modules = {}
        self.path_overrides = {}

        self.config_file = os.path.join(self.directory,
                                        'config/public_client.prc')

        self.mf = ModuleFinder(sys.path + [self.directory])
        from panda3d.direct import DCFile
        self.dcf = DCFile()

    def should_exclude(self, modname):
        # The NonRepeatableRandomSource modules are imported by the dc file explicitly,
        # so we have to allow them.
        if 'NonRepeatableRandomSource' in modname:
            return False

        if modname.endswith('AI'):
            return True
        if modname.endswith('UD'):
            return True
        if modname.endswith('.ServiceStart'):
            return True

    def find_excludes(self):
        for path, dirs, files in os.walk(self.directory):
            for filename in files:
                filepath = os.path.join(path, filename)
                filepath = os.path.relpath(filepath, self.directory)
                if not filepath.endswith('.py'): continue
                filepath = filepath[:-3]
                modname = filepath.replace(os.path.sep, '.')
                if modname.endswith('.__init__'): modname = modname[:-9]
                if self.should_exclude(modname):
                    self.mf.excludes.append(modname)

    def find_dcfiles(self):
        for path, dirs, files in os.walk(self.directory):
            for filename in files:
                filepath = os.path.join(path, filename)
                if filename.endswith('.dc'):
                    self.dcfiles.append(filepath)

    def create_miraidata(self):
        # Create a temporary _miraidata.py and throw it on the path somewhere...

        # First, we need the minified DC file contents:
        from panda3d.core import StringStream
        dcStream = StringStream()
        self.dcf.write(dcStream, True)
        dcData = dcStream.getData()

        # Next we need config files...
        configData = []
        with open(self.config_file) as f:
            fd = f.read()
            fd = fd.replace('SERVER_VERSION_HERE', self.version)
            fd = fd.replace('LANGUAGE_HERE', self.language)
            configData.append(fd)

        md = 'CONFIG = %r\nDC = %r\n' % (configData, dcData)

        # Now we use tempfile to dump md:
        td = tempfile.mkdtemp()
        with open(os.path.join(td, '_miraidata.py'), 'w') as f:
            f.write(md)

        self.mf.path.append(td)

        atexit.register(shutil.rmtree, td)

    def include_dcimports(self):
        for m in xrange(self.dcf.getNumImportModules()):
            modparts = self.dcf.getImportModule(m).split('/')
            mods = [modparts[0]]
            if 'OV' in modparts[1:]:
                mods.append(modparts[0] + 'OV')
            for mod in mods:
                self.mf.import_hook(mod)
                for s in xrange(self.dcf.getNumImportSymbols(m)):
                    symparts = self.dcf.getImportSymbol(m, s).split('/')
                    syms = [symparts[0]]
                    if 'OV' in symparts[1:]:
                        syms.append(symparts[0] + 'OV')
                    for sym in syms:
                        try:
                            self.mf.import_hook('%s.%s' % (mod, sym))
                        except ImportError:
                            pass

    def build_modules(self):
        for modname, mod in self.mf.modules.items():
            if modname in self.path_overrides:
                modfile = self.path_overrides[modname]
            else:
                modfile = mod.__file__
            if not (modfile and modfile.endswith('.py')): continue
            is_package = modfile.endswith('__init__.py')
            with open(modfile, 'r') as f:
                code = compile(f.read(), modname, 'exec')
            self.modules[modname] = (is_package, code)

    def load_modules(self):
        #self.find_dcfiles()
        self.find_excludes()

        from panda3d.core import Filename
        for dc in self.dcfiles:
            self.dcf.read(Filename.fromOsSpecific(dc))

        self.create_miraidata()

        self.mf.import_hook(self.MAINMODULE)
        for module in EXTRA_MODULES:
            self.mf.import_hook(module)
        if self.language.lower() != "english":
            self.mf.import_hook('otp.otpbase.OTPLocalizer_%s' %
                                self.language.capitalize())
            self.mf.import_hook('otp.otpbase.OTPLocalizer_%sProperty' %
                                self.language.capitalize())
            self.mf.import_hook('toontown.toonbase.TTLocalizer_%s' %
                                self.language.capitalize())
            self.mf.import_hook('toontown.toonbase.TTLocalizer_%s' %
                                self.language.capitalize())
        self.modules['__main__'] = (False,
                                    compile('import %s' % self.MAINMODULE,
                                            '__main__', 'exec'))

        self.include_dcimports()

        self.build_modules()

    def write_zip(self, outfile):
        zip = zipfile.ZipFile(outfile, 'w')
        for modname, (is_package, code) in self.modules.items():
            mcode = imp.get_magic() + '\x00' * 4 + marshal.dumps(code)
            name = modname.replace('.', '/')
            if is_package:
                name += '/__init__'
            name += '.pyo'
            zip.writestr(name, mcode)
        zip.close()

    def write_list(self, outfile):
        with open(outfile, 'w') as out:
            for modname in sorted(self.modules.keys()):
                is_package, code = self.modules[modname]
                out.write('%s%s\n' % (modname, ' [PKG]' if is_package else ''))