def get_objects_in_view_gen(_connection=None): all_objs = [] for manager in services.client_object_managers(): for obj in manager.get_all(): #if issubclass(type(obj), BaseSituation): all_objs.append(type(obj)) ts4mp_log("objs in view", str(all_objs))
def print_leak_chain(obj_address, recursion_depth:int=10, _connection=None): obj = _find_object(obj_address) if obj is None: obj = services.object_manager().get(obj_address) if obj is not None: from sims4.leak_detector import find_object_refs termination_points = set(services._zone_manager) termination_points.update(services.client_object_managers()) find_object_refs(obj, termination_points=termination_points, recursion_depth=recursion_depth)
def print_leak_chain(obj_address:int, recursion_depth:int=10, _connection=None): obj = _find_object(obj_address) if obj is None: obj = services.object_manager().get(obj_address) if obj is not None: from sims4.leak_detector import find_object_refs termination_points = set(services._zone_manager) termination_points.update(services.client_object_managers()) find_object_refs(obj, termination_points=termination_points, recursion_depth=recursion_depth)
def add_client(self, client): for client_distributor in self.client_distributors: if client_distributor.client.id == client.id: raise ValueError('Client is already registered') self.process() logger.info('Adding {0}', client) client_distributor = distributor.system.Distributor() client_distributor.add_client(client) client_distributor._add_ops_for_client_connect(client) all_objs = [] for manager in services.client_object_managers(): for obj in manager.get_all(): # if issubclass(type(obj), BaseSituation): all_objs.append(obj) ts4mp_log("objs in view", str(all_objs)) self.client_distributors.append(client_distributor)
def get_objects_in_view_gen(self): for manager in services.client_object_managers(): for obj in manager.get_all(): yield obj
def stop(self): super().stop() services.client_object_managers().remove(self)
def setup(self, **kwargs): super().setup() services.client_object_managers().add(self)
def print_commodity_census(predicate=lambda x: x, most_common=10, _connection=None): counter = collections.Counter() initial_counter = collections.Counter() commodity_counter = collections.Counter() commodity_initial_counter = collections.Counter() core_commodity_counter = collections.Counter() nonsim_stat_counter = collections.Counter() def compile_tracker(tracker, non_sim): try: for t in tracker: if not predicate(t): continue stat_type = t.stat_type if hasattr(t, 'stat_type') else t counter[stat_type] += 1 if hasattr(t, 'initial_value'): if t.get_value() == t.initial_value: initial_counter[stat_type] += 1 if non_sim: nonsim_stat_counter[stat_type] += 1 except TypeError: pass def compile_obj_state_trackers(obj): if hasattr(obj, 'commodity_tracker'): if obj.commodity_tracker is not None: compile_tracker(obj.commodity_tracker, not obj.is_sim) for commodity in obj.commodity_tracker: if not predicate(commodity): continue commodity_counter[commodity.stat_type] += 1 if hasattr(commodity, 'initial_value'): if commodity.get_value() == commodity.initial_value: commodity_initial_counter[commodity.stat_type] += 1 if commodity.core: core_commodity_counter[commodity.stat_type] += 1 if hasattr(obj, 'statistic_tracker') and obj.statistic_tracker is not None: compile_tracker(obj.statistic_tracker, not obj.is_sim) for sim_info in services.sim_info_manager().values(): for tracker_name in SimInfo.SIM_INFO_TRACKERS: tracker = getattr(sim_info, tracker_name) if tracker is None: continue compile_tracker(tracker, False) compile_obj_state_trackers(sim_info) for mgr in services.client_object_managers(): for obj in mgr.get_all(): if hasattr(obj, 'is_sim') and not obj.is_sim: compile_obj_state_trackers(obj) dump = [] num_statistics = sum(counter.values()) num_statistics_initial = sum(initial_counter.values()) dump.append(('Total count', num_statistics)) dump.append(('Initial count', num_statistics_initial)) dump.append(('Non-initial count', num_statistics - num_statistics_initial)) num_commodities = sum(commodity_counter.values()) num_commodities_initial = sum(commodity_initial_counter.values()) dump.append(('Total commodities count', num_commodities)) dump.append(('Initial commodities count', num_commodities_initial)) dump.append(('Non-initial commodities count', num_commodities - num_commodities_initial)) num_non_sim_commodities = sum(nonsim_stat_counter.values()) dump.append(('Total non-sim commodities count', num_non_sim_commodities)) num_core_commodities = sum(core_commodity_counter.values()) dump.append(('Total core commodities count', num_core_commodities)) output = sims4.commands.CheatOutput(_connection) for (name, value) in dump: output('{:20} : {}'.format(name, value)) output('Most common:') for (commodity, num) in counter.most_common(most_common): name = commodity.__name__ if hasattr(commodity, '__name__') else str(commodity) output('{:40} : {}'.format(name, num)) output('Most common core:') for (commodity, num) in core_commodity_counter.most_common(most_common): name = commodity.__name__ if hasattr(commodity, '__name__') else str(commodity) output('{:40} : {}'.format(name, num)) output('Most common at initial value:') for (commodity, num) in initial_counter.most_common(most_common): name = commodity.__name__ if hasattr(commodity, '__name__') else str(commodity) output('{:40} : {}'.format(name, num))
def get_objects_in_view_gen(self): for manager in services.client_object_managers(): for obj in manager.get_all(): yield obj