コード例 #1
0
ファイル: file_access.cpp プロジェクト: dataxerik/godot
String FileAccess::get_pascal_string() {

	uint32_t sl = get_32();
	CharString cs;
	cs.resize(sl + 1);
	get_buffer((uint8_t *)cs.ptr(), sl);
	cs[sl] = 0;

	String ret;
	ret.parse_utf8(cs.ptr());

	return ret;
};
コード例 #2
0
StringName PHashTranslation::get_message(const StringName& p_src_text) const {

	int htsize = hash_table.size();

	if (htsize==0)
		return StringName();

	CharString str = p_src_text.operator String().utf8();
	uint32_t h = hash(0,str.get_data());


	DVector<int>::Read htr =  hash_table.read();
	const uint32_t *htptr = (const uint32_t*)&htr[0];
	DVector<int>::Read btr =  bucket_table.read();
	const uint32_t *btptr = (const uint32_t*)&btr[0];
	DVector<uint8_t>::Read sr = strings.read();
	const char *sptr= (const char*)&sr[0];

	uint32_t p = htptr[ h % htsize];

	//print_line("String: "+p_src_text.operator String());
	//print_line("Hash: "+itos(p));

	if (p==0xFFFFFFFF) {
//		print_line("GETMSG: Nothing!");
		return StringName(); //nothing
	}

	const Bucket &bucket = *(const Bucket*)&btptr[p];

	h = hash(bucket.func,str.get_data());

	int idx=-1;

	for(int i=0;i<bucket.size;i++) {

		if (bucket.elem[i].key==h) {

			idx=i;
			break;
		}

	}

	//print_line("bucket pos: "+itos(idx));
	if (idx==-1) {
//		print_line("GETMSG: Not in Bucket!");
		return StringName();
	}

	if (bucket.elem[idx].comp_size == bucket.elem[idx].uncomp_size) {

		String rstr;
		rstr.parse_utf8(&sptr[ bucket.elem[idx].str_offset ], bucket.elem[idx].uncomp_size );
//		print_line("Uncompressed, size: "+itos(bucket.elem[idx].comp_size));
//		print_line("Return: "+rstr);

		return rstr;
	} else {

		CharString uncomp;
		uncomp.resize( bucket.elem[idx].uncomp_size+1 );
		smaz_decompress(&sptr[ bucket.elem[idx].str_offset ], bucket.elem[idx].comp_size,uncomp.ptr(),bucket.elem[idx].uncomp_size );
		String rstr;
		rstr.parse_utf8(uncomp.get_data());
//		print_line("Compressed, size: "+itos(bucket.elem[idx].comp_size));
//		print_line("Return: "+rstr);
		return rstr;
	}

}
コード例 #3
0
bool PackedSourcePCK::try_open_pack(const String& p_path) {

	FileAccess *f = FileAccess::open(p_path,FileAccess::READ);
	if (!f)
		return false;

	uint32_t magic= f->get_32();

	if (magic != 0x4b435047) {
		//maybe at he end.... self contained exe
		f->seek_end();
		f->seek( f->get_pos() -4 );
		magic = f->get_32();
		if (magic != 0x4b435047) {

			memdelete(f);
			return false;
		}
		f->seek( f->get_pos() -12 );


		uint64_t ds = f->get_64();
		f->seek( f->get_pos() -ds-8 );

		magic = f->get_32();
		if (magic != 0x4b435047) {

			memdelete(f);
			return false;
		}

	}

	uint32_t ver_major = f->get_32();
	uint32_t ver_minor = f->get_32();
	uint32_t ver_rev = f->get_32();

	ERR_EXPLAIN("Pack created with a newer version of the engine: "+itos(ver_major)+"."+itos(ver_minor)+"."+itos(ver_rev));
	ERR_FAIL_COND_V( ver_major > VERSION_MAJOR || (ver_major == VERSION_MAJOR && ver_minor > VERSION_MINOR), ERR_INVALID_DATA);

	for(int i=0;i<16;i++) {
		//reserved
		f->get_32();
	}

	int file_count = f->get_32();

	for(int i=0;i<file_count;i++) {

		uint32_t sl = f->get_32();
		CharString cs;
		cs.resize(sl+1);
		f->get_buffer((uint8_t*)cs.ptr(),sl);
		cs[sl]=0;

		String path;
		path.parse_utf8(cs.ptr());

		uint64_t ofs = f->get_64();
		uint64_t size = f->get_64();
		uint8_t md5[16];
		f->get_buffer(md5,16);

		PackedData::get_singleton()->add_path(p_path, path, ofs, size, md5,this);
	};

	return true;
};