コード例 #1
0
CCL_NAMESPACE_BEGIN

BlenderObjectCulling::BlenderObjectCulling(Scene *scene, BL::Scene& b_scene)
        : use_scene_camera_cull_(false),
          use_camera_cull_(false),
          camera_cull_margin_(0.0f),
          use_scene_distance_cull_(false),
          use_distance_cull_(false),
          distance_cull_margin_(0.0f)
{
	if(b_scene.render().use_simplify()) {
		PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");

		use_scene_camera_cull_ = scene->camera->type != CAMERA_PANORAMA &&
		                         !b_scene.render().use_multiview() &&
		                         get_boolean(cscene, "use_camera_cull");
		use_scene_distance_cull_ = scene->camera->type != CAMERA_PANORAMA &&
		                           !b_scene.render().use_multiview() &&
		                           get_boolean(cscene, "use_distance_cull");

		camera_cull_margin_ = get_float(cscene, "camera_cull_margin");
		distance_cull_margin_ = get_float(cscene, "distance_cull_margin");

		if(distance_cull_margin_ == 0.0f) {
			use_scene_distance_cull_ = false;
		}
	}
}
コード例 #2
0
ファイル: blender_object.cpp プロジェクト: nttputus/blensor
static uint object_ray_visibility(BL::Object b_ob)
{
	PointerRNA cvisibility = RNA_pointer_get(&b_ob.ptr, "cycles_visibility");
	uint flag = 0;

	flag |= get_boolean(cvisibility, "camera")? PATH_RAY_CAMERA: 0;
	flag |= get_boolean(cvisibility, "diffuse")? PATH_RAY_DIFFUSE: 0;
	flag |= get_boolean(cvisibility, "glossy")? PATH_RAY_GLOSSY: 0;
	flag |= get_boolean(cvisibility, "transmission")? PATH_RAY_TRANSMIT: 0;
	flag |= get_boolean(cvisibility, "shadow")? PATH_RAY_SHADOW: 0;

	return flag;
}
コード例 #3
0
VoutParameters* AmConfigVout::get_cvbs_config()
{
  if (!mVoutParamsCvbs) {
    mVoutParamsCvbs = new VoutParameters;
  }
  if (mVoutParamsCvbs) {
    memset(mVoutParamsCvbs, 0, sizeof(*mVoutParamsCvbs));
    mVoutParamsCvbs->is_video_csc_enabled =
    get_boolean("COMMON:VideoColorConversion", true);
    mVoutParamsCvbs->tailored_info =
    (amba_vout_tailored_info)(get_boolean("COMMON:QtSupport", true)
    ? (AMBA_VOUT_OSD_NO_CSC | AMBA_VOUT_OSD_AUTO_COPY) : 0);
    mVoutParamsCvbs->video_mode =
    str_to_video_mode(get_string("CVBS:Resolution", "576i"));
    mVoutParamsCvbs->vout_video_size.specified =
    (uint32_t)get_int("CVBS:VoutSize", 0);
    mVoutParamsCvbs->vout_video_size.vout_width =
    (uint16_t)get_int("CVBS:VoutSize/VoutWidth", 0);
    mVoutParamsCvbs->vout_video_size.vout_height =
    (uint16_t)get_int("CVBS:VoutSize/VoutHeight", 0);
    mVoutParamsCvbs->vout_video_size.video_width =
    (uint16_t)get_int("CVBS:VoutSize/VideoWidth", 0);
    mVoutParamsCvbs->vout_video_size.video_height =
    (uint16_t)get_int("CVBS:VoutSize/VideoHeight", 0);
    mVoutParamsCvbs->video_rotate =
    int_to_rotate_info(get_int("CVBS:CvbsRotateVideo", 0));
    mVoutParamsCvbs->is_video_enabled = get_int("CVBS:EnableVideo", 1);
    mVoutParamsCvbs->video_flip =
    str_to_flip_info(get_string("CVBS:CvbsFlipVideo", "normal"));
    mVoutParamsCvbs->framebuffer_id = get_int("CVBS:FramebufferID", -1);
    mVoutParamsCvbs->video_offset.specified =
    (uint32_t)get_int("CVBS:VideoOffset", 0);
    mVoutParamsCvbs->video_offset.offset_x =
    (int16_t)get_int("CVBS:VideoOffset/OffsetX", 0);
    mVoutParamsCvbs->video_offset.offset_y =
    (int16_t)get_int("CVBS:VideoOffset/OffsetY", 0);
    mVoutParamsCvbs->osd_rescale.enable =
    (uint32_t)get_int("CVBS:OsdRescale", 0);
    mVoutParamsCvbs->osd_rescale.width =
    (uint16_t)get_int("CVBS:OsdRescale/Width", 0);
    mVoutParamsCvbs->osd_rescale.height =
    (uint16_t)get_int("CVBS:OsdRescale/Height", 0);
    mVoutParamsCvbs->osd_offset.specified =
    (uint32_t)get_int("CVBS:OsdOffset", 0);
    mVoutParamsCvbs->osd_offset.offset_x =
    (int16_t)get_int("CVBS:OsdOffset/OffsetX", 0);
    mVoutParamsCvbs->osd_offset.offset_y =
    (int16_t)get_int("CVBS:OsdOffset/OffsetY", 0);
  }
  return mVoutParamsCvbs;
}
コード例 #4
0
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Get Octane common settings
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SessionParams BlenderSync::get_session_params(BL::UserPreferences b_userpref, BL::Scene b_scene, ::OctaneEngine::OctaneClient::SceneExportTypes::SceneExportTypesEnum export_type, bool interactive) {
    SessionParams params;
    PointerRNA oct_scene = RNA_pointer_get(&b_scene.ptr, "octane");

    // Interactive
    params.interactive = interactive;

    // Samples
    ::Octane::RenderPassId cur_pass_type = Passes::pass_type_translator[RNA_enum_get(&oct_scene, "cur_pass_type")];
    if(cur_pass_type == ::Octane::RenderPassId::RENDER_PASS_BEAUTY) {
        if(!interactive) {
            params.samples = get_int(oct_scene, "max_samples");
        }
        else {
            params.samples = get_int(oct_scene, "max_preview_samples");
            if(params.samples == 0) params.samples = 16000;
        }
    }
    else if(cur_pass_type == ::Octane::RenderPassId::RENDER_PASS_AMBIENT_OCCLUSION) {
        params.samples = get_int(oct_scene, "pass_ao_max_samples");
    }
    else {
        params.samples = get_int(oct_scene, "pass_max_samples");
    }

    params.anim_mode            = static_cast<AnimationMode>(RNA_enum_get(&oct_scene, "anim_mode"));
    params.export_type         = interactive ? ::OctaneEngine::OctaneClient::SceneExportTypes::NONE : export_type;

    params.deep_image           = get_boolean(oct_scene, "deep_image");
    params.use_passes           = get_boolean(oct_scene, "use_passes");
    params.meshes_type          = static_cast<Mesh::MeshType>(RNA_enum_get(&oct_scene, "meshes_type"));
    if(params.export_type != ::OctaneEngine::OctaneClient::SceneExportTypes::NONE && params.meshes_type == Mesh::GLOBAL)
        params.meshes_type = Mesh::RESHAPABLE_PROXY;
    params.use_viewport_hide    = get_boolean(oct_scene, "viewport_hide");
    
    params.fps = (float)b_scene.render().fps() / b_scene.render().fps_base();

    params.hdr_tonemapped = get_boolean(oct_scene, "hdr_tonemap_enable");
    params.out_of_core_enabled = get_boolean(oct_scene, "out_of_core_enable");
    params.out_of_core_mem_limit = get_int(oct_scene, "out_of_core_limit");
    params.out_of_core_gpu_headroom = get_int(oct_scene, "out_of_core_gpu_headroom");

    PointerRNA render_settings = RNA_pointer_get(&b_scene.ptr, "render");
    params.output_path = get_string(render_settings, "filepath");
    const char *cur_path = params.output_path.c_str();
    size_t len = params.output_path.length();
    if(len > 0 && cur_path[len - 1] != '/' && cur_path[len - 1] != '\\')
        params.output_path += "/";

    return params;
} //get_session_params()
コード例 #5
0
ファイル: dbus-session.c プロジェクト: vgeddes/lightum
int
get_session_active (DBusGProxy * proxy_session)
{
    gboolean is_active;
    gboolean is_local;

    get_boolean (proxy_session, "IsActive", &is_active);
    get_boolean (proxy_session, "IsLocal", &is_local);

    if (is_active && is_local)
        return 1;
    else
        return 0;

}
コード例 #6
0
ファイル: blender_object.cpp プロジェクト: nttputus/blensor
void BlenderSync::sync_background_light()
{
	BL::World b_world = b_scene.world();

	if(b_world) {
		PointerRNA cworld = RNA_pointer_get(&b_world.ptr, "cycles");
		bool sample_as_light = get_boolean(cworld, "sample_as_light");

		if(sample_as_light) {
			/* test if we need to sync */
			Light *light;
			ObjectKey key(b_world, 0, b_world);

			if(light_map.sync(&light, b_world, b_world, key) ||
			   world_recalc ||
			   b_world.ptr.data != world_map)
			{
				light->type = LIGHT_BACKGROUND;
				light->map_resolution  = get_int(cworld, "sample_map_resolution");
				light->shader = scene->default_background;

				light->tag_update(scene);
				light_map.set_recalc(b_world);
			}
		}
	}

	world_map = b_world.ptr.data;
	world_recalc = false;
}
コード例 #7
0
void BlenderObjectCulling::init_object(Scene *scene, BL::Object& b_ob)
{
	if(!use_scene_camera_cull_ && !use_scene_distance_cull_) {
		return;
	}

	PointerRNA cobject = RNA_pointer_get(&b_ob.ptr, "cycles");

	use_camera_cull_ = use_scene_camera_cull_ && get_boolean(cobject, "use_camera_cull");
	use_distance_cull_ = use_scene_distance_cull_ && get_boolean(cobject, "use_distance_cull");

	if(use_camera_cull_ || use_distance_cull_) {
		/* Need to have proper projection matrix. */
		scene->camera->update(scene);
	}
}
コード例 #8
0
ファイル: EntityData.cpp プロジェクト: christopho/solarus
/**
 * \brief Returns whether a field is unset.
 *
 * A field can only be unset if it is optional.
 *
 * \param key Key of the field to check.
 * \return \c true if the field exists, is optional and is equal to its
 * default value.
 */
bool EntityData::is_field_unset(const std::string& key) const {

    const EntityTypeDescription& type_description = entity_type_descriptions.at(type);
    for (const EntityFieldDescription& field_description : type_description) {
        if (field_description.key != key) {
            continue;
        }

        if (field_description.optional != OptionalFlag::OPTIONAL) {
            // Mandatory field: always set.
            return false;
        }

        const FieldValue& default_value = field_description.default_value;
        switch (default_value.value_type) {

        case EntityFieldType::STRING:
            return get_string(key) == default_value.string_value;

        case EntityFieldType::INTEGER:
            return get_integer(key) == default_value.int_value;

        case EntityFieldType::BOOLEAN:
            return get_boolean(key) == (default_value.int_value != 0);

        case EntityFieldType::NIL:
            Debug::die("Nil entity field");
            break;
        }
    }

    // The field does not exist.
    return false;
}
コード例 #9
0
static Itdb_ArtworkFormat *g_value_to_image_format (GValue *value)
{
    GHashTable *dict;
    Itdb_ArtworkFormat *img_spec;

    g_return_val_if_fail (G_VALUE_HOLDS (value, G_TYPE_HASH_TABLE), NULL);
    dict = g_value_get_boxed (value);
    g_return_val_if_fail (dict != NULL, NULL);

    img_spec = g_new0 (Itdb_ArtworkFormat, 1);
    if (img_spec == NULL) {
        return NULL;
    }

    if (!set_pixel_format (img_spec, dict)) {
        g_free (img_spec);
        return NULL;
    }
    set_back_color (img_spec, dict);

    dict_to_struct (dict, sysinfo_image_format_fields_mapping, img_spec);

    if (get_boolean (dict, "AlignRowBytes")
            && (img_spec->row_bytes_alignment == 0)) {
        /* at least the nano3g has the AlignRowBytes key with no
         * RowBytesAlignment key.
         */
        img_spec->row_bytes_alignment = 4;
    }

    return img_spec;
}
コード例 #10
0
ファイル: command.c プロジェクト: daaang/mpc
static int
bool_cmd(int argc, char **argv, struct mpd_connection *conn,
	 bool (*get_mode)(const struct mpd_status *status),
	 bool (*run_set_mode)(struct mpd_connection *conn, bool mode))
{
	bool mode;

	if (argc == 1) {
		int mode_i = get_boolean(argv[0]);
		if (mode_i < 0)
			return -1;

		mode = (bool)mode_i;
	} else {
		struct mpd_status *status;
		status = getStatus(conn);
		mode = !get_mode(status);
		mpd_status_free(status);
	}

	if (!run_set_mode(conn, mode))
		printErrorAndExit(conn);

	return 1;
}
コード例 #11
0
static ssize_t bcm43xx_attr_preamble_store(struct device *dev,
        struct device_attribute *attr,
        const char *buf, size_t count)
{
    struct bcm43xx_private *bcm = dev_to_bcm(dev);
    unsigned long flags;
    int err;
    int value;

    if (!capable(CAP_NET_ADMIN))
        return -EPERM;

    value = get_boolean(buf, count);
    if (value < 0)
        return value;
    bcm43xx_lock(bcm, flags);
    assert(bcm->initialized);

    bcm->short_preamble = !!value;

    err = 0;
    bcm43xx_unlock(bcm, flags);

    return err ? err : count;
}
コード例 #12
0
ファイル: blender_shader.cpp プロジェクト: baysmith/blender
void BlenderSync::sync_world(bool update_all)
{
	Background *background = scene->background;
	Background prevbackground = *background;

	BL::World b_world = b_scene.world();

	if(world_recalc || update_all || b_world.ptr.data != world_map) {
		Shader *shader = scene->shaders[scene->default_background];
		ShaderGraph *graph = new ShaderGraph();

		/* create nodes */
		if(b_world && b_world.use_nodes() && b_world.node_tree()) {
			BL::ShaderNodeTree b_ntree(b_world.node_tree());

			add_nodes(scene, b_data, b_scene, graph, b_ntree);
		}
		else if(b_world) {
			ShaderNode *closure, *out;

			closure = graph->add(new BackgroundNode());
			closure->input("Color")->value = get_float3(b_world.horizon_color());
			out = graph->output();

			graph->connect(closure->output("Background"), out->input("Surface"));
		}

		/* AO */
		if(b_world) {
			BL::WorldLighting b_light = b_world.light_settings();

			if(b_light.use_ambient_occlusion())
				background->ao_factor = b_light.ao_factor();
			else
				background->ao_factor = 0.0f;

			background->ao_distance = b_light.distance();
		}

		shader->set_graph(graph);
		shader->tag_update(scene);
	}

	PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");

	/* when doing preview render check for BI's transparency settings,
	 * this is so because bledner's preview render routines are not able
	 * to tweak all cycles's settings depending on different circumstances
	 */
	if(b_engine.is_preview() == false)
		background->transparent = get_boolean(cscene, "film_transparent");
	else
		background->transparent = b_scene.render().alpha_mode() == BL::RenderSettings::alpha_mode_TRANSPARENT;

	background->use = render_layer.use_background;

	if(background->modified(prevbackground))
		background->tag_update(scene);
}
コード例 #13
0
ファイル: lua_cpp.cpp プロジェクト: dataliven/nscp
bool lua::lua_wrapper::pop_boolean() {
	int pos = lua_gettop(L);
	if (pos == 0)
		return false;
	NSCAPI::nagiosReturn ret = get_boolean(pos);
	lua_pop(L, 1);
	return ret;
}
コード例 #14
0
void BlenderSync::sync_materials(bool update_all)
{
	shader_map.set_default(scene->shaders[scene->default_surface]);

	/* material loop */
	BL::BlendData::materials_iterator b_mat;

	for(b_data.materials.begin(b_mat); b_mat != b_data.materials.end(); ++b_mat) {
		Shader *shader;

		/* test if we need to sync */
		if(shader_map.sync(&shader, *b_mat) || update_all) {
			ShaderGraph *graph = new ShaderGraph();

			shader->name = b_mat->name().c_str();
			shader->pass_id = b_mat->pass_index();

			/* create nodes */
			if(b_mat->use_nodes() && b_mat->node_tree()) {
				BL::ShaderNodeTree b_ntree(b_mat->node_tree());

				add_nodes(scene, b_engine, b_data, b_scene, !preview, graph, b_ntree);
			}
			else {
				ShaderNode *closure, *out;

				closure = graph->add(new DiffuseBsdfNode());
				closure->input("Color")->value = get_float3(b_mat->diffuse_color());
				out = graph->output();

				graph->connect(closure->output("BSDF"), out->input("Surface"));
			}

			/* settings */
			PointerRNA cmat = RNA_pointer_get(&b_mat->ptr, "cycles");
			shader->use_mis = get_boolean(cmat, "sample_as_light");
			shader->use_transparent_shadow = get_boolean(cmat, "use_transparent_shadow");
			shader->heterogeneous_volume = !get_boolean(cmat, "homogeneous_volume");
			shader->volume_sampling_method = (VolumeSampling)RNA_enum_get(&cmat, "volume_sampling");
			shader->volume_interpolation_method = (VolumeInterpolation)RNA_enum_get(&cmat, "volume_interpolation");

			shader->set_graph(graph);
			shader->tag_update(scene);
		}
	}
}
コード例 #15
0
ファイル: eval.c プロジェクト: ingramj/bs
static inline object *if_alternate(object *exp)
{
    object *alt = cdr(cdr(cdr(exp)));
    if (is_empty_list(alt)) {
        return get_boolean(0);
    } else {
        return car(alt);
    }
}
コード例 #16
0
ファイル: config.c プロジェクト: fshemsing/iiag
static void load_config(const char * file)
{
	int i;
	FILE * f;
	char * name;
	const struct field * fld;

	if (!strcmp(file, "-")) {
		f = stdin;
	} else {
		f = fopen(file, "r");
		if (f == NULL) {
			warning("Could not open config file '%s'", file);
			return;
		}
	}

	while (igspaces(f) != EOF) {
		fld = NULL;
		name = get_string(f);

		for (i = 0; i < sizeof(cfg_fields) / sizeof(*cfg_fields); i++) {
			if (!strcmp(cfg_fields[i].name, name)) {
				fld = cfg_fields + i;
				break;
			}
		}

		igspaces(f);
		expect('=', f, file);

		if (fld == NULL) {
			warning("%s: Unknown field '%s'", file, name);
			free(get_string(f));
		} else {
			switch (fld->type) {
			case STRING:
				// FIXME potential memory leak
				*(char **)fld->ptr = get_string(f);
				break;
			case BOOLEAN:
				*(int *)fld->ptr = get_boolean(f, file);
				break;
			case CONTROL:
				*(int *)fld->ptr = get_control(f);
				break;
			case INTEGER:
				*(int *)fld->ptr = get_integer(f);
				break;
			}
		}

		free(name);
	}

	if (f != stdin) fclose(f);
}
コード例 #17
0
void BlenderSync::sync_world(bool update_all)
{
	Background *background = scene->background;
	Background prevbackground = *background;

	BL::World b_world = b_scene.world();

	if(world_recalc || update_all || b_world.ptr.data != world_map) {
		Shader *shader = scene->shaders[scene->default_background];
		ShaderGraph *graph = new ShaderGraph();

		/* create nodes */
		if(b_world && b_world.use_nodes() && b_world.node_tree()) {
			PtrSockMap sock_to_node;
			BL::ShaderNodeTree b_ntree(b_world.node_tree());

			add_nodes(scene, b_data, b_scene, graph, b_ntree, sock_to_node);
		}
		else if(b_world) {
			ShaderNode *closure, *out;

			closure = graph->add(new BackgroundNode());
			closure->input("Color")->value = get_float3(b_world.horizon_color());
			out = graph->output();

			graph->connect(closure->output("Background"), out->input("Surface"));
		}

		/* AO */
		if(b_world) {
			BL::WorldLighting b_light = b_world.light_settings();

			if(b_light.use_ambient_occlusion())
				background->ao_factor = b_light.ao_factor();
			else
				background->ao_factor = 0.0f;

			background->ao_distance = b_light.distance();
		}

		shader->set_graph(graph);
		shader->tag_update(scene);
	}

	PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
	background->transparent = get_boolean(cscene, "film_transparent");
	background->use = render_layer.use_background;

	if(background->modified(prevbackground))
		background->tag_update(scene);
}
MODRET set_lmd_ignore_memcached_down(cmd_rec *cmd) {
  int ignore = -1;

  CHECK_ARGS(cmd, 1);
  CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL);

  ignore = get_boolean(cmd, 1);
  if (ignore == -1)
    CONF_ERROR(cmd, "expected Boolean parameter");

  if(ignore == TRUE) {
      ignore_memcached_down = true;
  }

  return PR_HANDLED(cmd);
}
コード例 #19
0
static void dict_to_struct (GHashTable *dict,
                            const DictFieldMapping *mapping,
                            void *struct_ptr)
{
    const DictFieldMapping *it = mapping;
    g_return_if_fail (it != NULL);
    while (it->name != NULL) {
        switch (it->type) {
            case G_TYPE_INT64: {
                gint *field;
                field = G_STRUCT_MEMBER_P (struct_ptr, it->offset);
                *field = get_int64 (dict, it->name);
                break;
            }

            case G_TYPE_BOOLEAN: {
                gboolean *field;
                field = G_STRUCT_MEMBER_P (struct_ptr, it->offset);
                *field = get_boolean (dict, it->name);
                break;
            }

            case G_TYPE_STRING: {
                gchar **field;
                field = G_STRUCT_MEMBER_P (struct_ptr, it->offset);
                *field = get_string (dict, it->name);
                break;
            }

            case G_TYPE_DOUBLE: {
                gdouble *field;
                field = G_STRUCT_MEMBER_P (struct_ptr, it->offset);
                *field = get_double (dict, it->name);
                break;
            }
        }
        g_hash_table_remove (dict, it->name);
        ++it;
    }
#ifdef DEBUG_PARSING
    if (g_hash_table_size (dict) != 0) {
        g_print ("Unused keys:\n");
        g_hash_table_foreach (dict, dump_key_name, NULL);
        g_print ("\n");
    }
#endif
}
コード例 #20
0
ファイル: blender_object.cpp プロジェクト: sobotka/blender
void BlenderSync::sync_background_light(bool use_portal)
{
  BL::World b_world = b_scene.world();

  if (b_world) {
    PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
    PointerRNA cworld = RNA_pointer_get(&b_world.ptr, "cycles");

    enum SamplingMethod { SAMPLING_NONE = 0, SAMPLING_AUTOMATIC, SAMPLING_MANUAL, SAMPLING_NUM };
    int sampling_method = get_enum(cworld, "sampling_method", SAMPLING_NUM, SAMPLING_AUTOMATIC);
    bool sample_as_light = (sampling_method != SAMPLING_NONE);

    if (sample_as_light || use_portal) {
      /* test if we need to sync */
      Light *light;
      ObjectKey key(b_world, 0, b_world);

      if (light_map.sync(&light, b_world, b_world, key) || world_recalc ||
          b_world.ptr.data != world_map) {
        light->type = LIGHT_BACKGROUND;
        if (sampling_method == SAMPLING_MANUAL) {
          light->map_resolution = get_int(cworld, "sample_map_resolution");
        }
        else {
          light->map_resolution = 0;
        }
        light->shader = scene->default_background;
        light->use_mis = sample_as_light;
        light->max_bounces = get_int(cworld, "max_bounces");

        int samples = get_int(cworld, "samples");
        if (get_boolean(cscene, "use_square_samples"))
          light->samples = samples * samples;
        else
          light->samples = samples;

        light->tag_update(scene);
        light_map.set_recalc(b_world);
      }
    }
  }

  world_map = b_world.ptr.data;
  world_recalc = false;
}
コード例 #21
0
ファイル: mod_copy.c プロジェクト: laoflch/proftpd
/* usage: CopyEngine on|off */
MODRET set_copyengine(cmd_rec *cmd) {
  int engine = -1;
  config_rec *c;

  CHECK_ARGS(cmd, 1);
  CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL);

  engine = get_boolean(cmd, 1);
  if (engine == -1) {
    CONF_ERROR(cmd, "expected Boolean parameter");
  }

  c = add_config_param(cmd->argv[0], 1, NULL);
  c->argv[0] = palloc(c->pool, sizeof(int));
  *((int *) c->argv[0]) = engine;

  return PR_HANDLED(cmd);
}
コード例 #22
0
ファイル: eval.c プロジェクト: ingramj/bs
static object *expand_clauses(object *clauses)
{
    if (is_empty_list(clauses)) {
        return get_boolean(0);
    } else {
        object *first = car(clauses);
        object *rest = cdr(clauses);
        if (cond_predicate(first) == lookup_symbol("else")) {
            if (is_empty_list(rest)) {
                return sequence_to_exp(cond_actions(first));
            } else {
                error("else clause must be last in cond expression");
            }
        } else {
            return make_if(cond_predicate(first),
                    sequence_to_exp(cond_actions(first)),
                    expand_clauses(rest));
        }
    }
}
コード例 #23
0
int cmd_consume ( int argc, char ** argv, mpd_Connection * conn )
{
	int mode;

	if(argc==1) {
		mode = get_boolean(argv[0]);
		if (mode < 0)
			return -1;
	}
	else {
		mpd_Status * status;
		status = getStatus(conn);
		mode = !status->consume;
		mpd_freeStatus(status);
	}

	mpd_sendConsumeCommand(conn,mode);
	my_finishCommand(conn);

	return 1;
}
コード例 #24
0
ファイル: sysfs.c プロジェクト: 119-org/hi3518-osdrv
static ssize_t b43legacy_attr_preamble_store(struct device *dev,
					     struct device_attribute *attr,
					     const char *buf, size_t count)
{
	struct b43legacy_wldev *wldev = dev_to_b43legacy_wldev(dev);
	unsigned long flags;
	int value;

	if (!capable(CAP_NET_ADMIN))
		return -EPERM;

	value = get_boolean(buf, count);
	if (value < 0)
		return value;
	mutex_lock(&wldev->wl->mutex);
	spin_lock_irqsave(&wldev->wl->irq_lock, flags);

	wldev->short_preamble = !!value;

	spin_unlock_irqrestore(&wldev->wl->irq_lock, flags);
	mutex_unlock(&wldev->wl->mutex);

	return count;
}
コード例 #25
0
int cmd_repeat ( int argc, char ** argv, mpd_Connection * conn )
{
	int mode;

	if(argc==1) {
		mode = get_boolean(argv[0]);
		if (mode < 0)
			return -1;
	}
	else {
		mpd_Status * status;
		status = getStatus(conn);
		mode = !status->repeat;
		mpd_freeStatus(status);
	}


	mpd_sendRepeatCommand(conn,mode);
	printErrorAndExit(conn);
	my_finishCommand(conn);
	printErrorAndExit(conn);

	return 1;
}
コード例 #26
0
ファイル: init_ctx.c プロジェクト: PADL/krb5
krb5_error_code KRB5_CALLCONV
krb5_init_context_profile(profile_t profile, krb5_flags flags,
                          krb5_context *context_out)
{
    krb5_context ctx = 0;
    krb5_error_code retval;
    struct {
        krb5_timestamp now;
        krb5_int32 now_usec;
        long pid;
    } seed_data;
    krb5_data seed;
    int tmp;
    char *plugin_dir = NULL;

    /* Verify some assumptions.  If the assumptions hold and the
       compiler is optimizing, this should result in no code being
       executed.  If we're guessing "unsigned long long" instead
       of using uint64_t, the possibility does exist that we're
       wrong.  */
    {
        uint64_t i64;
        assert(sizeof(i64) == 8);
        i64 = 0, i64--, i64 >>= 62;
        assert(i64 == 3);
        i64 = 1, i64 <<= 31, i64 <<= 31, i64 <<= 1;
        assert(i64 != 0);
        i64 <<= 1;
        assert(i64 == 0);
    }

    retval = krb5int_initialize_library();
    if (retval)
        return retval;

#if (defined(_WIN32))
    /*
     * Load the krbcc32.dll if necessary.  We do this here so that
     * we know to use API: later on during initialization.
     * The context being NULL is ok.
     */
    krb5_win_ccdll_load(ctx);

    /*
     * krb5_vercheck() is defined in win_glue.c, and this is
     * where we handle the timebomb and version server checks.
     */
    retval = krb5_vercheck();
    if (retval)
        return retval;
#endif

    *context_out = NULL;

    ctx = calloc(1, sizeof(struct _krb5_context));
    if (!ctx)
        return ENOMEM;
    ctx->magic = KV5M_CONTEXT;

    ctx->profile_secure = (flags & KRB5_INIT_CONTEXT_SECURE) != 0;

    retval = k5_os_init_context(ctx, profile, flags);
    if (retval)
        goto cleanup;

    ctx->trace_callback = NULL;
#ifndef DISABLE_TRACING
    if (!ctx->profile_secure)
        k5_init_trace(ctx);
#endif

    retval = get_boolean(ctx, KRB5_CONF_ALLOW_WEAK_CRYPTO, 0, &tmp);
    if (retval)
        goto cleanup;
    ctx->allow_weak_crypto = tmp;

    retval = get_boolean(ctx, KRB5_CONF_IGNORE_ACCEPTOR_HOSTNAME, 0, &tmp);
    if (retval)
        goto cleanup;
    ctx->ignore_acceptor_hostname = tmp;

    retval = get_tristate(ctx, KRB5_CONF_DNS_CANONICALIZE_HOSTNAME, "fallback",
                          CANONHOST_FALLBACK, 1, &tmp);
    if (retval)
        goto cleanup;
    ctx->dns_canonicalize_hostname = tmp;

    /* initialize the prng (not well, but passable) */
    if ((retval = krb5_c_random_os_entropy( ctx, 0, NULL)) !=0)
        goto cleanup;
    if ((retval = krb5_crypto_us_timeofday(&seed_data.now, &seed_data.now_usec)))
        goto cleanup;
    seed_data.pid = getpid ();
    seed.length = sizeof(seed_data);
    seed.data = (char *) &seed_data;
    if ((retval = krb5_c_random_add_entropy(ctx, KRB5_C_RANDSOURCE_TIMING, &seed)))
        goto cleanup;

    ctx->default_realm = 0;
    get_integer(ctx, KRB5_CONF_CLOCKSKEW, DEFAULT_CLOCKSKEW, &tmp);
    ctx->clockskew = tmp;

    /* DCE 1.1 and below only support CKSUMTYPE_RSA_MD4 (2)  */
    /* DCE add kdc_req_checksum_type = 2 to krb5.conf */
    get_integer(ctx, KRB5_CONF_KDC_REQ_CHECKSUM_TYPE, CKSUMTYPE_RSA_MD5,
                &tmp);
    ctx->kdc_req_sumtype = tmp;

    get_integer(ctx, KRB5_CONF_AP_REQ_CHECKSUM_TYPE, 0, &tmp);
    ctx->default_ap_req_sumtype = tmp;

    get_integer(ctx, KRB5_CONF_SAFE_CHECKSUM_TYPE, CKSUMTYPE_RSA_MD5_DES,
                &tmp);
    ctx->default_safe_sumtype = tmp;

    get_integer(ctx, KRB5_CONF_KDC_DEFAULT_OPTIONS, KDC_OPT_RENEWABLE_OK,
                &tmp);
    ctx->kdc_default_options = tmp;
#define DEFAULT_KDC_TIMESYNC 1
    get_integer(ctx, KRB5_CONF_KDC_TIMESYNC, DEFAULT_KDC_TIMESYNC, &tmp);
    ctx->library_options = tmp ? KRB5_LIBOPT_SYNC_KDCTIME : 0;

    retval = profile_get_string(ctx->profile, KRB5_CONF_LIBDEFAULTS,
                                KRB5_CONF_PLUGIN_BASE_DIR, 0,
                                DEFAULT_PLUGIN_BASE_DIR, &plugin_dir);
    if (!retval)
        retval = k5_expand_path_tokens(ctx, plugin_dir, &ctx->plugin_base_dir);
    if (retval) {
        TRACE_PROFILE_ERR(ctx, KRB5_CONF_PLUGIN_BASE_DIR,
                          KRB5_CONF_LIBDEFAULTS, retval);
        goto cleanup;
    }

    /*
     * We use a default file credentials cache of 3.  See
     * lib/krb5/krb/ccache/file/fcc.h for a description of the
     * credentials cache types.
     *
     * Note: DCE 1.0.3a only supports a cache type of 1
     *      DCE 1.1 supports a cache type of 2.
     */
#define DEFAULT_CCACHE_TYPE 4
    get_integer(ctx, KRB5_CONF_CCACHE_TYPE, DEFAULT_CCACHE_TYPE, &tmp);
    ctx->fcc_default_format = tmp + 0x0500;
    ctx->prompt_types = 0;
    ctx->use_conf_ktypes = 0;
    ctx->udp_pref_limit = -1;

    /* It's OK if this fails */
    (void)profile_get_string(ctx->profile, KRB5_CONF_LIBDEFAULTS,
                             KRB5_CONF_ERR_FMT, NULL, NULL, &ctx->err_fmt);
    *context_out = ctx;
    ctx = NULL;

cleanup:
    profile_release_string(plugin_dir);
    krb5_free_context(ctx);
    return retval;
}
コード例 #27
0
ファイル: scripting.c プロジェクト: MigNov/CDVWS
int _script_builtin_function(char *var, char *fn, char *args)
{
	int ret = 0;
	struct timespec ts;
	struct timespec tse;

	if (_perf_measure)
		ts = utils_get_time( TIME_CURRENT );

	if (strcmp(fn, "set_all_variables_overwritable") == 0) {
		if (args != NULL) {
			int var = get_boolean(args);

			if ((var == 0) || (var == 1))
				variable_allow_overwrite(NULL, var);
			else
				desc_printf(gIO, gFd, "Invalid value for %s(): %s\n",
					fn, args);
		}
	}
	else
	if (strcmp(fn, "get_all_variables_overwritable") == 0) {
		if (var != NULL) {
			char tmp[4] = { 0 };
			snprintf(tmp, sizeof(tmp), "%d", variable_get_overwrite(NULL));
			variable_add(var, tmp, TYPE_QSCRIPT, -1, TYPE_INT);
		}
		else
			desc_printf(gIO, gFd, "All variables overwritable: %s\n",
				(variable_get_overwrite(NULL) == 1) ? "true" : "false");
	}
	else
	if (strcmp(fn, "set_variable_overwritable") == 0) {
		tTokenizer t;

		t = tokenize(args, ",");
		if (t.numTokens == 2)
			variable_allow_overwrite(trim(t.tokens[0]), get_boolean(t.tokens[1]));
		else
			desc_printf(gIO, gFd, "Syntax: set_variable_overwritable(variable, true|false)\n");

		free_tokens(t);
	}
	else
	if (strcmp(fn, "get_variable_overwritable") == 0) {
		char tmp[4] = { 0 };

		if ((args != NULL) && (strlen(args) > 0))
		{
			snprintf(tmp, sizeof(tmp), "%d", variable_get_overwrite(args));

			if (var != NULL)
				variable_add(var, tmp, TYPE_QSCRIPT, -1, TYPE_INT);
			else
				desc_printf(gIO, gFd, "Variable %s overwritable: %s\n",
					args, (strcmp(tmp, "1") == 0) ? "true" :
					((strcmp(tmp, "0") == 0) ? "false" : "not found"));
		}
		else
			desc_printf(gIO, gFd, "Variable name is missing\n");
	}
	else
	if (strcmp(fn, "enable_perf") == 0) {
		int enable = get_boolean(args);

		if ((enable == 0) || (enable == 1)) {
			DPRINTF("%sabling performance measuring\n", enable ? "En" : "Dis");

			_perf_measure = enable;
		}
		else
			DPRINTF("Incorrect setting for performace measuring: %d\n", enable);

		if (_perf_measure)
			ts = utils_get_time( TIME_CURRENT );
	}
	else
	if (strcmp(fn, "del") == 0) {
		variable_set_deleted(args, 1);
	}
	else
	if (strcmp(fn, "get") == 0) {
		char *val = variable_get_element_as_string(args, "get");

		if (val != NULL) {
			DPRINTF("%s: Processing internal 'get' function for arguments: %s\n", __FUNCTION__, args);
			DPRINTF("%s: Variable %s processed to %s\n", __FUNCTION__, var, val);

			if (var != NULL)
				variable_add(var, val, TYPE_QSCRIPT, -1, gettype(val));
		}
	}
	else
	if (strcmp(fn, "dumpvars") == NULL) {
		desc_variable_dump(gIO, gFd, args);
	}
	else
	if (strcmp(fn, "post") == 0) {
		char *val = variable_get_element_as_string(args, "post");

		if (val != NULL) {
			DPRINTF("%s: Processing internal 'post' function for arguments: %s\n", __FUNCTION__, args);
			DPRINTF("%s: Variable %s processed to %s\n", __FUNCTION__, var, val);

			if (var != NULL)
				variable_add(var, val, TYPE_QSCRIPT, -1, gettype(val));
		}
	}
	else
	if (strcmp(fn, "cookie") == 0) {
		char *val = variable_get_element_as_string(args, "cookie");

		if (val != NULL) {
			DPRINTF("%s: Processing internal 'cookie' function for arguments: %s\n", __FUNCTION__, args);
			DPRINTF("%s: Variable %s processed to %s\n", __FUNCTION__, var, val);

			if (var != NULL)
				variable_add(var, val, TYPE_QSCRIPT, -1, gettype(val));
		}
	}
	else
	if (strcmp(fn, "sleep") == 0) {
		int num = atoi(args);

		DPRINTF("%s: Sleeping for %d seconds...\n", __FUNCTION__, num);
		sleep(num);
	}
	else
	if (strcmp(fn, "dumptype") == 0) {
		char *str = variable_get_type_string(args, "any");

		desc_printf(gIO, gFd, "%s\n", str ? str : "<null>");
		str = utils_free("scripting.dumptype.str", str);
	}
	else
	if (strcmp(fn, "print") == 0) {
		if (args != NULL) {
			if ((args[0] == '"') || (args[0] == '\'')) {
				*args++;
				args[strlen(args) - 1] = 0;

				args = replace(args, "\\n", "\n");
				desc_printf(gIO, gFd, "%s", args);
			}
			else {
				char *var = variable_get_element_as_string(args, NULL);
				desc_printf(gIO, gFd, "%s", var ? var : "");
				var = utils_free("scripting.print.var", var);
			}
		}
	}
	else
	if (strcmp(fn, "printf") == 0) {
		if ((args != NULL) && (strlen(args) > 0)) {
			int i;
			tTokenizer t;

			*args++;

			t = tokenize(args, "\"");
			if (t.numTokens == 1) {
				char *instr = NULL;

				instr = strdup(t.tokens[0]);
				while (strstr(instr, "\\n") != NULL)
					instr = replace(instr, "\\n", "\n");

				desc_printf(gIO, gFd, "%s", instr);
				instr = utils_free("scripting.printf.instr", instr);
			}
			else
			if (t.numTokens == 2) {
				tTokenizer t2;
				char *instr = NULL;
				char *vars = NULL;

				instr = strdup( t.tokens[0] );
				vars = strdup( t.tokens[1] + 1 );

				t2 = tokenize(vars, ",");
				for (i = 0; i < t2.numTokens; i++) {
					DPRINTF("%s: Replacing variable %s\n", __FUNCTION__, trim(t2.tokens[i]));
					char *tmp = variable_get_element_as_string(trim(t2.tokens[i]), NULL);

					if (tmp != NULL)
						instr = replace(instr, "%s", tmp);
					else {
						instr = replace(instr, "%s", "NULL");
						DPRINTF("%s: Variable \"%s\" not found\n", __FUNCTION__, trim(t2.tokens[i]));
					}
				}

				while (strstr(instr, "\\n") != NULL)
					instr = replace(instr, "\\n", "\n");

				desc_printf(gIO, gFd, "%s", instr);
				free_tokens(t2);
			}
			else {
				free_tokens(t);
				ret = -EINVAL;
				goto cleanup;
			}

			free_tokens(t);
		}
		else {
			desc_printf(gIO, gFd, "Invalid syntax for printf()\n");
			ret = -EINVAL;
			goto cleanup;
		}
	}
	else
	if (strcmp(fn, "idb_dump_query_set") == 0) {
		idb_results_show( gIO, gFd, idb_get_last_select_data() );
	}
	else
	if (strcmp(fn, "idb_query") == 0) {
		char *filename = NULL;
		char *query = NULL;
		tTokenizer t;
		int i;

		t = tokenize(args, "\"");
		if (t.numTokens > 1) {
			int num = 0;
			for (i = 0; i < t.numTokens; i++) {
				if (strcmp(trim(t.tokens[i]), ",") != 0) {
					if (num == 0)
						filename = strdup(t.tokens[i]);
					else
					if (num == 1)
						query = strdup(t.tokens[i]);
					num++;
				}
			}
		}
		free_tokens(t);

		if (((filename == NULL) || (query == NULL)) && (args[0] == '@')) {
			*args++;

			DPRINTF("Reading query file '%s'\n", args);
			if (access(args, R_OK) == 0) {
				FILE *fp = NULL;
				char buf[BUFSIZE];

				fp = fopen(args, "r");
				if (fp != NULL) {
					int num = 0;

					while (!feof(fp)) {
						memset(buf, 0, sizeof(buf));

						fgets(buf, sizeof(buf), fp);
						if ((strlen(buf) > 0)
							&& (buf[strlen(buf) - 1] == '\n'))
							buf[strlen(buf) - 1] = 0;

						if (strlen(buf) > 0) {
							num++;
							int ret = idb_query(buf);
							desc_printf(gIO, gFd, "Query '%s' returned with code %d\n",
								buf, ret);
						}
					}

					desc_printf(gIO, gFd, "%d queries processed\n", num);
					fclose(fp);
				}
				else
					desc_printf(gIO, gFd, "Error: Cannot open file %s for reading\n",
						args);
			}
			else
				desc_printf(gIO, gFd, "Error: Cannot access file %s\n", t.tokens[1]);
		}
		else
		if ((filename != NULL) && (query != NULL)) {
			char tmp[4096] = { 0 };
			snprintf(tmp, sizeof(tmp), "INIT %s", filename);

			ret = 0;
			if (idb_query(tmp) != 0) {
				DPRINTF("Error while trying to initialize file '%s'\n", filename);
				ret = -EIO;
			}
			if (idb_query(query) != 0) {
				DPRINTF("Error while running query '%s'\n", query);
				ret = -EIO;
			}
			else
			if ((strncmp(query, "SELECT", 6) == 0) || (strcmp(query, "SHOW TABLES") == 0))
				idb_results_show( gIO, gFd, idb_get_last_select_data() );

			idb_query("COMMIT");
			idb_query("CLOSE");
		}
	}
	else {
		ret = -EINVAL;
		goto cleanup;
	}

cleanup:
	if (_perf_measure) {
		tse = utils_get_time( TIME_CURRENT );
		desc_printf(gIO, gFd, "\nPERF: Function %s() was running for %.3f microseconds (%.3f ms)\n",
			fn, get_time_float_us( tse, ts ), get_time_float_us(tse, ts) / 1000.);
	}

	return ret;
}
コード例 #28
0
ファイル: icn.c プロジェクト: EmmetCooper/ctr_toolkit
int icn_settings_proccess(ICN_CONTEXT icn)
{
	/** Creating Buffer **/	
	u8 buff[100];
	
	/** Processing Bitmask Flags **/
	//Creating Identity Arrays
	u8 bit_flag_key_0[MAX_BIT_NUM][20] = {"Visable", "AutoBoot", "Flag3DEffect", "RequireAcceptEULA", "AutoSaveOnExit", "UseExtendedBanner", "UseAgeRestrictions", "UseSaveData"};
	u8 bit_flag_key_1[MAX_BIT_NUM][20] = {"IconDatabase", "", "", "", "", "", "", ""};
	u8 bit_flag_value[MAX_BIT_NUM] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
	
	//Creating bit flag 0 counter
	u8 bit_flag[MAX_BIT_NUM];
	//memset(bit_flag, 0, MAX_BIT_NUM);
	
	//Region Age Rating flag
	int use_age_ratings = FALSE;
	
	fseek(icn.bsf, 0x00, SEEK_SET);
	if(key_search("Options", icn.bsf) == FOUND){
		if(key_search("Flags", icn.bsf) == FOUND){
			long int pos0 = ftell(icn.bsf);
			for(int i = 0; i < MAX_BIT_NUM; i++){
				fseek(icn.bsf, pos0, SEEK_SET);
				if (get_boolean(bit_flag_key_0[i], icn.bsf) == TRUE){
					if(icn.verbose_bool)
						printf("[+] %s was True\n",bit_flag_key_0[i]);
					icn.settings.byte_flag[0] += bit_flag_value[i];
					if(i == 6)
						use_age_ratings = TRUE;
				}
				else if(icn.verbose_bool)
						printf("[+] %s was False\n",bit_flag_key_0[i]);
					
			}
		}
		else{
			key_find_fail("Flags");
			return FLAG_FAIL;
		}
	}
	else{
		key_find_fail("Options");
		return FLAG_FAIL;
	}
	
	fseek(icn.bsf, 0x00, SEEK_SET);
	if(key_search("Options", icn.bsf) == FOUND){
		if(key_search("Flags", icn.bsf) == FOUND){
			long int pos0 = ftell(icn.bsf);
			for(int i = 0; i < 1; i++){
				fseek(icn.bsf, pos0, SEEK_SET);
				if (get_boolean(bit_flag_key_1[i], icn.bsf) == TRUE){
					if(icn.verbose_bool)
						printf("[+] %s was True\n",bit_flag_key_1[i]);
					icn.settings.byte_flag[1] += bit_flag_value[i];
					if(i == 6)
						use_age_ratings = TRUE;
				}
				else if(icn.verbose_bool)
						printf("[+] %s was False\n",bit_flag_key_1[i]);
					
			}
		}
		else{
			key_find_fail("Flags");
			return FLAG_FAIL;
		}
	}
	else{
		key_find_fail("Options");
		return FLAG_FAIL;
	}
	
	/** Processing Age Ratings **/
		/*** Seting Up Region Key Array and Input Array***/
	u8 region_rating_key[MAX_RATING_NUM][12] = {"Japan", "USA", "German", "Europe", "Portugual", "England", "Australia"};
	u8 region_rating_struct_index[MAX_RATING_NUM] = {0,1,3,4,6,7,8};
	u8 region_rating_string[2];
	//memset(region_rating_string, 0x00, sizeof(region_rating_string));
	
		/*** Setting Up Age Restriction Rules ***/
	u8 region_age[MAX_RATING_NUM][10];
	int region_age_num[MAX_RATING_NUM] = {5,5,5,5,5,8,5};
	memcpy(region_age[RATING_JPN], (u8[]) {0,12,15,17,18}, region_age_num[RATING_JPN]);
	memcpy(region_age[RATING_USA], (u8[]) {3,6,10,13,17}, region_age_num[RATING_USA]);
	memcpy(region_age[RATING_GER], (u8[]) {0,6,12,16,17}, region_age_num[RATING_GER]);
	memcpy(region_age[RATING_EUR], (u8[]) {3,7,12,16,18}, region_age_num[RATING_EUR]);
	memcpy(region_age[RATING_PRT], (u8[]) {4,6,12,16,18}, region_age_num[RATING_PRT]);
	memcpy(region_age[RATING_ENG], (u8[]) {3,4,7,8,12,15,16,18}, region_age_num[RATING_ENG]);
	memcpy(region_age[RATING_AUS], (u8[]) {0,7,14,15,18}, region_age_num[RATING_AUS]);
	
		
		/*** Iterating Through Input File for Age Restrictions ***/
	if(use_age_ratings == TRUE){//Checking If Age Restictions Are To be used
		fseek(icn.bsf, 0x00, SEEK_SET);
		if(key_search("RegionRatings", icn.bsf) == FOUND){
			long int pos0 = ftell(icn.bsf);
			u8 region_rating;
			for(int i = 0; i < MAX_RATING_NUM; i++){
				fseek(icn.bsf, pos0, SEEK_SET);
				u8 rating_index = region_rating_struct_index[i];
				if(get_value(region_rating_string,2,region_rating_key[i],icn.bsf) == FOUND){
					char_to_int_array(&region_rating, region_rating_string, 1, BIG_ENDIAN, DEC);
					int rating_type = INVALID_RATING;
					for(int j = 0; j < region_age_num[i]; j++){						
						if(region_age[i][j] == region_rating){
							rating_type = VALID_RATING;
							break;
						}
					}
					if(rating_type == VALID_RATING){
						region_rating += 0x80; //Active Rating bitflag
						icn.settings.ratings.rating[rating_index] = region_rating;
						if(icn.verbose_bool)
							printf("[+] Age Restriction for %s was set to %d\n",region_rating_key[i], (region_rating - 0x80));
					}
					else{
						printf("[!] Age Restriction for %s %d, is Invalid.\n",region_rating_key[i], region_rating);
						icn.settings.ratings.rating[rating_index] = 0x00;
					}
				}
				else{
					value_find_fail(region_rating_key[i]);
					icn.settings.ratings.rating[rating_index] = 0x00;
				}
			}
		}
	}
	else{//If Age Restrictions are not to be used
		for(int i = 0; i < MAX_RATING_NUM; i++){
			u8 rating_index = region_rating_struct_index[i];
			icn.settings.ratings.rating[rating_index] = 0x00;
			}
	}
		
	/** Processing Region Lock **/
	u8 region_lock_list[MAX_REGION_LOCK_NUM][15] = {"Japan", "America", "Europe", "Australia", "China", "Korea", "Taiwan"};
	u8 region_bit_flag_value[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
	fseek(icn.bsf, 0x00, SEEK_SET);
	if(key_search("Options", icn.bsf) == FOUND){
		if(key_search("RegionLockout", icn.bsf) == FOUND){
			long int pos0 = ftell(icn.bsf);
			for(int i = 0; i < MAX_REGION_LOCK_NUM; i++){
				fseek(icn.bsf, pos0, SEEK_SET);
				if (get_boolean(region_lock_list[i], icn.bsf) == TRUE){
					if(icn.verbose_bool)
						printf("[+] Region Lock was set to include %s\n",region_lock_list[i]);
					icn.settings.region_lock[0] += region_bit_flag_value[i];
				}
				else if(icn.verbose_bool)
						printf("[+] Region Lock was set to exclude %s\n",region_lock_list[i]);
					
			}
		}
		else{
			key_find_fail("RegionLockout");
			return REGION_LOCKOUT_FAIL;
		}
	}
	else{
		key_find_fail("Options");
		return REGION_LOCKOUT_FAIL;
	}
	/**
	// This may need to be more complex
	u8 region_lock_list_1[MAX_REGION_LOCK_NUM][15] = {"Region_Free", "Japan", "America", "Europe", "Australia", "China", "Korea", "Taiwan"};
	u8 region_lock_list_2[MAX_REGION_LOCK_NUM][5] = {"All", "JPN", "USA", "EUR", "AUS", "CHN", "KOR", "TWN"};
	u8 region_lock_hex[MAX_REGION_LOCK_NUM][8] = {"7FFFFFFF", "00000001", "00000002", "00000004", "00000008", "0000010", "00000020", "00000040"};
	fseek(icn.bsf, 0x00, SEEK_SET);
	if(key_search("Options", icn.bsf) == FOUND){
		if (get_value(buff,15,"RegionLockout", icn.bsf) == FOUND){
			for(int i = 0; i < MAX_REGION_LOCK_NUM; i++){
				if(strcmp(buff, region_lock_list_1[i]) == 0 || strcmp(buff, region_lock_list_2[i]) == 0){
					if(icn.verbose_bool)
						printf("[+] Region Lock was set to %s\n",region_lock_list_1[i]);
					char_to_int_array(icn.settings.region_lock, region_lock_hex[i], 4, LITTLE_ENDIAN, HEX);
					break;
				}
				else if( i == (MAX_REGION_LOCK_NUM - 1)){
					printf("[!] Invalid Region-Lockout Code: '%s'\n", buff);
					return REGION_LOCKOUT_FAIL;
				}
			}
		}
		else{
			printf("[!] No Region-Lockout Code was Specified\n");
			return REGION_LOCKOUT_FAIL;
		}
	}
	else{
		key_find_fail("Options");
		return REGION_LOCKOUT_FAIL;
	}
	**/
	
	/** Processing EULA Version **/
	fseek(icn.bsf, 0x00, SEEK_SET);
	if(key_search("Options", icn.bsf) == FOUND){
		long int pos0 = ftell(icn.bsf);
		if (get_value(buff,2,"EulaMajorVersion",icn.bsf) == FOUND){
			char_to_int_array(&icn.settings.eula_major, buff, 1, BIG_ENDIAN, HEX);
		}
		else{
			printf("[!] EulaMajorVersion was not specified\n");
			return EULA_VER_FAIL;
		}
		fseek(icn.bsf, pos0, SEEK_SET);
		if (get_value(buff,2,"EulaMinorVersion",icn.bsf) == FOUND){
			char_to_int_array(&icn.settings.eula_minor, buff, 1, BIG_ENDIAN, HEX);
		}
		else{
			printf("[!] EulaMinorVersion was not specified\n");
			return EULA_VER_FAIL;
		}
		if(icn.verbose_bool){
			printf("[+] EULA Version was set to %02x.%02x\n",icn.settings.eula_major,icn.settings.eula_minor);
		}
	}
	else{
		key_find_fail("Options");
		return REGION_LOCKOUT_FAIL;
	}
	
	/** Processing Default Banner Frame **/
	u8 default_frame[MAX_READ_LEN];
	fseek(icn.bsf, 0x00, SEEK_SET);
	if(key_search("Options", icn.bsf) == FOUND){
		if (get_value(default_frame,100,"OptimalBNRFrame",icn.bsf) == FOUND){
			//if(icn.verbose_bool)
			//	printf("[+] OptimalBNRFrame was set to %f\n",default_frame); //Doesn't work
			union
			{
				float          f;
				unsigned char  b[sizeof(float)];
			} v = { atof(default_frame) };
			u8 default_frame_hex[8];
			sprintf(default_frame_hex, "%02X%02X%02X%02X\0",v.b[3],v.b[2],v.b[1],v.b[0]);
			char_to_int_array(icn.settings.optimal_bnr_frame, default_frame_hex, 4, LITTLE_ENDIAN, HEX);
		}
		else{
			value_find_fail("Default BNR Frame");
			return OPTM_BNR_FAIL;
		}
	}
	else{
		key_find_fail("Options");
		return OPTM_BNR_FAIL;
	}
    
	
	/** Processing IDs **/
	fseek(icn.bsf, 0x00, SEEK_SET);
	if(key_search("IDs", icn.bsf) == FOUND){
		long int pos0 = ftell(icn.bsf);
		//MatchMaker ID
		if(get_value(buff,0x8,"MatchMakerID",icn.bsf) == FOUND){
			char_to_int_array(icn.settings.match_maker_id, buff, sizeof(icn.settings.match_maker_id), LITTLE_ENDIAN, HEX);
			printf("Not MMID\n");
		}
		else{
			value_find_fail("MatchMakerID");
			return ID_FAIL;
		}
		//MatchMakerBIT ID
		fseek(icn.bsf, pos0, SEEK_SET);
		if(get_value(buff,0x10,"MatchMakerBITID",icn.bsf) == FOUND){
			printf("Is MMBID\n");
			char_to_int_array(icn.settings.match_maker_bit_id, buff, sizeof(icn.settings.match_maker_bit_id), LITTLE_ENDIAN, HEX);
			printf("Not MMBID\n");
		}
		else{
			value_find_fail("MatchMakerBITID");
			return ID_FAIL;
		}
		//CEC ID
		fseek(icn.bsf, pos0, SEEK_SET);
		if(get_value(buff,0x8,"CECID",icn.bsf) == FOUND){
			char_to_int_array(icn.settings.cec_id, buff, sizeof(icn.settings.cec_id), LITTLE_ENDIAN, HEX);
			printf("Not CECID\n");
		}
		else{
			value_find_fail("CECID");
			return ID_FAIL;
		}
	}
	else{
		key_find_fail("IDs");
		return ID_FAIL;
	}
	
	
	
    /** Writing To File **/
    fseek(icn.output, FLAG_OFFSET, SEEK_SET);
    fwrite(&icn.settings, sizeof(icn.settings), 1, icn.output);

    /** Return, all is good **/
    return 0;
}
コード例 #29
0
/**
 * \brief Converts this savegame v1 into a savegame v2.
 * \param savegame_v2 The savegame to fill.
 */
void SavegameConverterV1::convert_to_v2(Savegame& savegame_v2) {

  // 1. Built-in values.
  savegame_v2.set_string(Savegame::KEY_STARTING_POINT, get_string(STARTING_POINT));
  if (!get_string(STARTING_MAP).empty()) {
    savegame_v2.set_string(Savegame::KEY_STARTING_MAP, get_string(STARTING_MAP));
  }
  else {
    // Older v1 savegames used integers to identify maps.
    std::ostringstream oss;
    oss << get_integer(STARTING_MAP_INT);
    savegame_v2.set_string(Savegame::KEY_STARTING_MAP, oss.str());
  }
  savegame_v2.set_integer(Savegame::KEY_CURRENT_LIFE, get_integer(CURRENT_LIFE));
  savegame_v2.set_integer(Savegame::KEY_CURRENT_MONEY, get_integer(CURRENT_MONEY));
  savegame_v2.set_integer(Savegame::KEY_CURRENT_MAGIC, get_integer(CURRENT_MAGIC));
  savegame_v2.set_integer(Savegame::KEY_MAX_LIFE, get_integer(MAX_LIFE));
  savegame_v2.set_integer(Savegame::KEY_MAX_MONEY, get_integer(MAX_MONEY));
  savegame_v2.set_integer(Savegame::KEY_MAX_MAGIC, get_integer(MAX_MAGIC));
  savegame_v2.set_string(Savegame::KEY_ITEM_SLOT_1, get_string(ITEM_SLOT_0));
  savegame_v2.set_string(Savegame::KEY_ITEM_SLOT_2, get_string(ITEM_SLOT_1));

  savegame_v2.set_string(Savegame::KEY_KEYBOARD_ACTION, InputEvent::get_keyboard_key_name(
      InputEvent::KeyboardKey(get_integer(KEYBOARD_ACTION_KEY))));
  savegame_v2.set_string(Savegame::KEY_KEYBOARD_ATTACK, InputEvent::get_keyboard_key_name(
      InputEvent::KeyboardKey(get_integer(KEYBOARD_SWORD_KEY))));
  savegame_v2.set_string(Savegame::KEY_KEYBOARD_ITEM_1, InputEvent::get_keyboard_key_name(
      InputEvent::KeyboardKey(get_integer(KEYBOARD_ITEM_1_KEY))));
  savegame_v2.set_string(Savegame::KEY_KEYBOARD_ITEM_2, InputEvent::get_keyboard_key_name(
      InputEvent::KeyboardKey(get_integer(KEYBOARD_ITEM_2_KEY))));
  savegame_v2.set_string(Savegame::KEY_KEYBOARD_PAUSE, InputEvent::get_keyboard_key_name(
      InputEvent::KeyboardKey(get_integer(KEYBOARD_PAUSE_KEY))));
  savegame_v2.set_string(Savegame::KEY_KEYBOARD_RIGHT, InputEvent::get_keyboard_key_name(
      InputEvent::KeyboardKey(get_integer(KEYBOARD_RIGHT_KEY))));
  savegame_v2.set_string(Savegame::KEY_KEYBOARD_UP, InputEvent::get_keyboard_key_name(
      InputEvent::KeyboardKey(get_integer(KEYBOARD_UP_KEY))));
  savegame_v2.set_string(Savegame::KEY_KEYBOARD_LEFT, InputEvent::get_keyboard_key_name(
      InputEvent::KeyboardKey(get_integer(KEYBOARD_LEFT_KEY))));
  savegame_v2.set_string(Savegame::KEY_KEYBOARD_DOWN, InputEvent::get_keyboard_key_name(
      InputEvent::KeyboardKey(get_integer(KEYBOARD_DOWN_KEY))));
  savegame_v2.set_string(Savegame::KEY_JOYPAD_ACTION, get_string(JOYPAD_ACTION_KEY));
  savegame_v2.set_string(Savegame::KEY_JOYPAD_ATTACK, get_string(JOYPAD_SWORD_KEY));
  savegame_v2.set_string(Savegame::KEY_JOYPAD_ITEM_1, get_string(JOYPAD_ITEM_1_KEY));
  savegame_v2.set_string(Savegame::KEY_JOYPAD_ITEM_2, get_string(JOYPAD_ITEM_2_KEY));
  savegame_v2.set_string(Savegame::KEY_JOYPAD_PAUSE, get_string(JOYPAD_PAUSE_KEY));
  savegame_v2.set_string(Savegame::KEY_JOYPAD_RIGHT, get_string(JOYPAD_RIGHT_KEY));
  savegame_v2.set_string(Savegame::KEY_JOYPAD_UP, get_string(JOYPAD_UP_KEY));
  savegame_v2.set_string(Savegame::KEY_JOYPAD_LEFT, get_string(JOYPAD_LEFT_KEY));
  savegame_v2.set_string(Savegame::KEY_JOYPAD_DOWN, get_string(JOYPAD_DOWN_KEY));
  savegame_v2.set_integer(Savegame::KEY_ABILITY_RESISTANCE, get_integer(ABILITY_TUNIC));
  savegame_v2.set_integer(Savegame::KEY_ABILITY_SWORD, get_integer(ABILITY_SWORD));
  savegame_v2.set_integer(Savegame::KEY_ABILITY_SHIELD, get_integer(ABILITY_SHIELD));
  savegame_v2.set_integer(Savegame::KEY_ABILITY_LIFT, get_integer(ABILITY_LIFT));
  savegame_v2.set_integer(Savegame::KEY_ABILITY_SWIM, get_integer(ABILITY_SWIM));
  savegame_v2.set_integer(Savegame::KEY_ABILITY_SWORD_KNOWLEDGE, get_integer(ABILITY_SWORD_KNOWLEDGE));
  savegame_v2.set_integer(Savegame::KEY_ABILITY_DETECT_WEAK_WALLS, get_integer(ABILITY_DETECT_WEAK_WALLS));
  savegame_v2.set_integer(Savegame::KEY_ABILITY_GET_BACK_FROM_DEATH, get_integer(ABILITY_GET_BACK_FROM_DEATH));
  savegame_v2.set_integer(Savegame::KEY_ABILITY_RUN, get_integer(ABILITY_RUN));

  // 2. Values that used to be built-in in v1 and become pure data in v2.
  savegame_v2.set_string("player_name", get_string(PLAYER_NAME));
  savegame_v2.set_integer("pause_last_submenu", get_integer(PAUSE_LAST_SUBMENU) + 1);
  savegame_v2.set_integer("pause_inventory_last_item_index", get_integer(INVENTORY_LAST_ITEM_INDEX) + 1);

  for (int i = 0; i < 40; i++) {
    int index = 200 + i * 10;

    std::ostringstream oss;
    oss << "dungeon_" << (i + 1);
    const std::string& dungeon_number = oss.str();

    // Dungeon finished (integer replaced by a boolean).
    if (get_integer(index) > 0) {
      savegame_v2.set_boolean(dungeon_number + "_finished", true);
    }

    // Got the map? (integer replaced by a boolean).
    ++index;
    if (get_integer(index) > 0) {
      savegame_v2.set_boolean(dungeon_number + "_map", true);
    }

    // Got the compass? (integer replaced by a boolean).
    ++index;
    if (get_integer(index) > 0) {
      savegame_v2.set_boolean(dungeon_number + "_compass", true);
    }

    // Got the big key? (integer replaced by a boolean).
    ++index;
    if (get_integer(index) > 0) {
      savegame_v2.set_boolean(dungeon_number + "_big_key", true);
    }

    // Got the boss key? (integer replaced by a boolean).
    ++index;
    if (get_integer(index) > 0) {
      savegame_v2.set_boolean(dungeon_number + "_boss_key", true);
    }

    // Number of small keys.
    ++index;
    int nb_small_keys = get_integer(index);
    if (nb_small_keys > 0) {
      savegame_v2.set_integer(dungeon_number + "_small_keys", nb_small_keys);
    }
  }

  // 3. Custom values.
  int i;
  for (i = 32; i < 64; i++) {
    const std::string& value = get_string(i);
    if (!value.empty()) {
      std::ostringstream oss;
      oss << "s" << i;
      savegame_v2.set_string(oss.str(), value);
    }
  }

  for (i = 1024; i < 2048; i++) {
    int value = get_integer(i);
    if (value != 0) {
      std::ostringstream oss;
      oss << "i" << i;
      savegame_v2.set_integer(oss.str(), value);
    }
  }

  for (i = 0; i < 32768; i++) {
    bool value = get_boolean(i);
    if (value) {
      std::ostringstream oss;
      oss << "b" << i;
      savegame_v2.set_boolean(oss.str(), value);
    }
  }
}
コード例 #30
0
ファイル: EntityData.cpp プロジェクト: christopho/solarus
/**
 * \copydoc LuaData::export_to_lua
 */
bool EntityData::export_to_lua(std::ostream& out) const {

    // Entity type.
    out << get_type_name() << "{\n";

    // Name.
    if (has_name()) {
        out << "  name = \"" << escape_string(get_name()) << "\",\n";
    }

    // Position on the map.
    out << "  layer = " << get_layer() << ",\n"
        << "  x = " << get_xy().x << ",\n"
        << "  y = " << get_xy().y << ",\n";

    // Properties specific to a type of entity.
    const EntityTypeDescription& type_description = entity_type_descriptions.at(get_type());

    for (const EntityFieldDescription& field_description : type_description) {

        const std::string& key = field_description.key;
        const bool optional = field_description.optional == OptionalFlag::OPTIONAL;
        switch (field_description.default_value.value_type) {

        case EntityFieldType::STRING:
        {
            const std::string& value = get_string(key);
            const std::string& default_value = field_description.default_value.string_value;
            if (optional && value == default_value) {
                // No need to write the value.
                continue;
            }
            out << "  " << key << " = \"" << escape_string(value) << "\",\n";
            break;
        }

        case EntityFieldType::INTEGER:
        {
            int value = get_integer(key);
            int default_value = field_description.default_value.int_value;
            if (optional && value == default_value) {
                // No need to write the value.
                continue;
            }
            out << "  " << key << " = " << value << ",\n";
            break;
        }

        case EntityFieldType::BOOLEAN:
        {
            bool value = get_boolean(key);
            bool default_value = field_description.default_value.int_value != 0;
            if (optional && value == default_value) {
                // No need to write the value.
                continue;
            }
            out << "  " << key << " = " << (value ? "true" : "false") << ",\n";

            break;
        }

        case EntityFieldType::NIL:
            Debug::die("Nil entity field");
            break;
        }
    }
    out << "}\n\n";

    return true;
}