def save_zone(self, save_slot_data=None): zone_data_msg = self._get_zone_proto() zone_data_msg.ClearField('gameplay_zone_data') gameplay_zone_data = zone_data_msg.gameplay_zone_data gameplay_zone_data.lot_owner_household_id_on_save = self.lot.owner_household_id gameplay_zone_data.venue_type_id_on_save = self.venue_service.venue.guid64 if self.venue_service.venue is not None else 0 gameplay_zone_data.active_household_id_on_save = services.active_household_id( ) self.lot.save(gameplay_zone_data) if self.lot.front_door_id: zone_data_msg.front_door_id = self.lot.front_door_id num_spawn_points = len(self._spawner_data) spawn_point_ids = [0] * num_spawn_points for (spawn_point_id, spawn_point) in self._spawner_data.items(): spawn_point_ids[spawn_point.spawn_point_index] = spawn_point_id zone_data_msg.ClearField('spawn_point_ids') zone_data_msg.spawn_point_ids.extend(spawn_point_ids) zone_objects_message = serialization.ZoneObjectData() object_list = serialization.ObjectList() zone_objects_message.zone_id = self.id persistence_service = services.get_persistence_service() open_street_data = persistence_service.get_open_street_proto_buff( self.open_street_id) if open_street_data is not None: open_street_data.Clear() add_proto_to_persistence = False else: open_street_data = serialization.OpenStreetsData() add_proto_to_persistence = True open_street_data.world_id = self.open_street_id open_street_data.nbh_id = self.neighborhood_id open_street_data.sim_time_on_save = services.time_service( ).sim_timeline.now.absolute_ticks() open_street_data.active_household_id_on_save = services.active_household_id( ) open_street_data.active_zone_id_on_save = self.id self.service_manager.save_all_services( persistence_service, persistence_error_types.ErrorCodes.ZONE_SERVICES_SAVE_FAILED, object_list=object_list, zone_data=zone_data_msg, open_street_data=open_street_data, save_slot_data=save_slot_data) zone_objects_message.objects = object_list if add_proto_to_persistence: services.get_persistence_service().add_open_street_proto_buff( open_street_data) persistence_module.run_persistence_operation( persistence_module.PersistenceOpType.kPersistenceOpSaveZoneObjects, zone_objects_message, 0, None)
def load_zone(_connection=None): try: zone = services.current_zone() name = str(hex(zone.id)).replace("0x", "") zone_objects_pb = serialization.ZoneObjectData() zone_objects_message = open(get_file_matching_name(name)[0], "rb").read() output("msg", dir(zone_objects_pb)) zone_objects_pb.ParseFromString(zone_objects_message) output("msg", zone_objects_pb) output("msg", zone_objects_message) persistence_module.run_persistence_operation( persistence_module.PersistenceOpType.kPersistenceOpLoadZoneObjects, zone_objects_pb, 0, None) except Exception as e: output("er", e)
def save_current_houshold(slot_id:int=0, slot_name='Unnamed', _connection=None): output = sims4.commands.Output(_connection) try: sim_info.save_active_household_command_start() save_slot_data_msg = services.get_persistence_service().get_save_slot_proto_buff() save_slot_data_msg.slot_id = slot_id active_household = services.active_household() if active_household is not None: save_slot_data_msg.active_household_id = active_household.id sims4.core_services.service_manager.save_all_services(None, persistence_error_types.ErrorCodes.CORE_SERICES_SAVE_FAILED, save_slot_data=save_slot_data_msg) save_game_buffer = services.get_persistence_service().get_save_game_data_proto() persistence_module.run_persistence_operation(persistence_module.PersistenceOpType.kPersistenceOpSaveHousehold, save_game_buffer, 0, None) except Exception as e: output('Exception thrown while executing command persistence.save_active_household.\n{}'.format(e)) output('No household file generated. Please address all the exceptions.') raise finally: sim_info.save_active_household_command_stop() output('Exported active household to T:\\InGame\\Households\\{}.household'.format(active_household.name)) return 1
def generate(template:TunableInstanceParam(sims4.resources.Types.SIM_TEMPLATE), _connection=None): output = sims4.commands.Output(_connection) if template.template_type != SimTemplateType.PREMADE_HOUSEHOLD: output('{} has invalid template type. Expected PREMADE_HOUSEHOLD, got {}'.format(template, template.template_type)) return try: distributor = Distributor.instance() distributor.enabled = False household = template.create_premade_household() if household is None: output('Failed to create household from template {}'.format(template)) return for sim_info in household.sim_info_gen(): tracker = sim_info.occult_tracker if tracker is None: continue if tracker.has_any_occult_or_part_occult_trait(): template_manager = services.get_instance_manager(sims4.resources.Types.SIM_TEMPLATE) sim_template = template_manager.get(sim_info.premade_sim_template_id) if sim_template is not None: if sim_template.occult is not None: output('Household template {} contains a premade sim (sim template id: {}) who has occult trait but also has occult tuned at sim template. This is unexpected. Please check sim template tuning and .siminfo file.'.format(template, sim_info.premade_sim_template_id)) save_active_household_command_start() save_slot_data_msg = services.get_persistence_service().get_save_slot_proto_buff() save_slot_data_msg.slot_id = 0 save_slot_data_msg.active_household_id = household.id sims4.core_services.service_manager.save_all_services(None, save_slot_data=save_slot_data_msg) save_game_buffer = services.get_persistence_service().get_save_game_data_proto() persistence_module.run_persistence_operation(persistence_module.PersistenceOpType.kPersistenceOpSaveHousehold, save_game_buffer, 0, None) except Exception as e: output('Exception thrown while executing command premade_household.generate.\n{}'.format(e)) output('No household file generated. Please address all the exceptions.') raise finally: save_active_household_command_stop() distributor.enabled = True output('Exported active household to T:\\InGame\\Households\\{}.household'.format(household.name)) for sim_info in tuple(household): sim_info.remove_permanently()
def _fill_and_send_save_game_protobufs_gen(self, timeline, slot_id, slot_name, auto_save_slot_id=None): self.save_error_code = persistence_error_types.ErrorCodes.SETTING_SAVE_SLOT_DATA_FAILED save_slot_data_msg = self.get_save_slot_proto_buff() save_slot_data_msg.slot_id = slot_id save_slot_data_msg.slot_name = slot_name if services.active_household_id() is not None: save_slot_data_msg.active_household_id = services.active_household_id() sims4.core_services.service_manager.save_all_services(self, persistence_error_types.ErrorCodes.CORE_SERICES_SAVE_FAILED, save_slot_data=save_slot_data_msg) self.save_error_code = persistence_error_types.ErrorCodes.SAVE_CAMERA_DATA_FAILED camera.serialize(save_slot_data=save_slot_data_msg) def on_save_complete(slot_id, success): wakeable_element.trigger_soft_stop() self.save_error_code = persistence_error_types.ErrorCodes.SAVE_TO_SLOT_FAILED wakeable_element = element_utils.soft_sleep_forever() persistence_module.run_persistence_operation(persistence_module.PersistenceOpType.kPersistenceOpSave, self._save_game_data_proto, slot_id, on_save_complete) yield element_utils.run_child(timeline, wakeable_element) if auto_save_slot_id is not None: self.save_error_code = persistence_error_types.ErrorCodes.AUTOSAVE_TO_SLOT_FAILED wakeable_element = element_utils.soft_sleep_forever() persistence_module.run_persistence_operation(persistence_module.PersistenceOpType.kPersistenceOpSave, self._save_game_data_proto, auto_save_slot_id, on_save_complete) yield element_utils.run_child(timeline, wakeable_element) self.save_error_code = persistence_error_types.ErrorCodes.NO_ERROR