String OS_Unix::get_executable_path() const { #ifdef __linux__ //fix for running from a symlink char buf[256]; memset(buf, 0, 256); ssize_t len = readlink("/proc/self/exe", buf, sizeof(buf)); String b; if (len > 0) { b.parse_utf8(buf, len); } if (b == "") { WARN_PRINT("Couldn't get executable path from /proc/self/exe, using argv[0]"); return OS::get_executable_path(); } return b; #elif defined(__OpenBSD__) char resolved_path[MAXPATHLEN]; realpath(OS::get_executable_path().utf8().get_data(), resolved_path); return String(resolved_path); #elif defined(__FreeBSD__) int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; char buf[MAXPATHLEN]; size_t len = sizeof(buf); if (sysctl(mib, 4, buf, &len, NULL, 0) != 0) { WARN_PRINT("Couldn't get executable path from sysctl"); return OS::get_executable_path(); } String b; b.parse_utf8(buf); return b; #elif defined(__APPLE__) char temp_path[1]; uint32_t buff_size = 1; _NSGetExecutablePath(temp_path, &buff_size); char *resolved_path = new char[buff_size + 1]; if (_NSGetExecutablePath(resolved_path, &buff_size) == 1) WARN_PRINT("MAXPATHLEN is too small"); String path(resolved_path); delete[] resolved_path; return path; #else ERR_PRINT("Warning, don't know how to obtain executable path on this OS! Please override this function properly."); return OS::get_executable_path(); #endif }
static void _fix_html(Vector<uint8_t>& html,const String& name,int max_memory) { String str; String strnew; str.parse_utf8((const char*)html.ptr(),html.size()); Vector<String> lines=str.split("\n"); for(int i=0;i<lines.size();i++) { if (lines[i].find("godot.js")!=-1) { strnew+="<script type=\"text/javascript\" src=\""+name+"_filesystem.js\"></script>\n"; strnew+="<script async type=\"text/javascript\" src=\""+name+".js\"></script>\n"; } else if (lines[i].find("var Module")!=-1) { strnew+=lines[i]; strnew+="TOTAL_MEMORY:"+itos(max_memory*1024*1024)+","; } else { strnew+=lines[i]+"\n"; } } CharString cs = strnew.utf8(); html.resize(cs.size()); for(int i=9;i<cs.size();i++) { html[i]=cs[i]; } }
bool rel_path_to_abs(const String &p_existing_path, String &r_abs_path) { #ifdef WINDOWS_ENABLED CharType ret[_MAX_PATH]; if (::_wfullpath(ret, p_existing_path.c_str(), _MAX_PATH)) { String abspath = String(ret).replace("\\", "/"); int pos = abspath.find(":/"); if (pos != -1) { r_abs_path = abspath.substr(pos - 1, abspath.length()); } else { r_abs_path = abspath; } return true; } #else char *resolved_path = ::realpath(p_existing_path.utf8().get_data(), NULL); if (resolved_path) { String retstr; bool success = !retstr.parse_utf8(resolved_path); ::free(resolved_path); if (success) { r_abs_path = retstr; return true; } } #endif return false; }
static void _fix_html(Vector<uint8_t>& html,const String& name,int max_memory) { String str; String strnew; str.parse_utf8((const char*)html.ptr(),html.size()); Vector<String> lines=str.split("\n"); for(int i=0; i<lines.size(); i++) { if (lines[i].find("$GODOTTMEM")!=-1) { strnew+=lines[i].replace("$GODOTTMEM",itos(max_memory*1024*1024))+"\n"; } else if (lines[i].find("$GODOTFS")!=-1) { strnew+=lines[i].replace("$GODOTFS",name+"fs.js")+"\n"; } else if (lines[i].find("$GODOTMEM")!=-1) { strnew+=lines[i].replace("$GODOTMEM",name+".mem")+"\n"; } else if (lines[i].find("$GODOTJS")!=-1) { strnew+=lines[i].replace("$GODOTJS",name+".js")+"\n"; } else { strnew+=lines[i]+"\n"; } } CharString cs = strnew.utf8(); html.resize(cs.size()); for(int i=9; i<cs.size(); i++) { html[i]=cs[i]; } }
void EditorExportPlatformJavaScript::_fix_html(Vector<uint8_t>& p_html, const String& p_name, bool p_debug) { String str; String strnew; str.parse_utf8((const char*)p_html.ptr(),p_html.size()); Vector<String> lines=str.split("\n"); for(int i=0;i<lines.size();i++) { String current_line = lines[i]; current_line = current_line.replace("$GODOT_TMEM",itos((1<<(max_memory+5))*1024*1024)); current_line = current_line.replace("$GODOT_FS",p_name+"fs.js"); current_line = current_line.replace("$GODOT_MEM",p_name+".mem"); current_line = current_line.replace("$GODOT_JS",p_name+".js"); current_line = current_line.replace("$GODOT_CANVAS_WIDTH",Globals::get_singleton()->get("display/width")); current_line = current_line.replace("$GODOT_CANVAS_HEIGHT",Globals::get_singleton()->get("display/height")); current_line = current_line.replace("$GODOT_HEAD_TITLE",!html_title.empty()?html_title:(String) Globals::get_singleton()->get("application/name")); current_line = current_line.replace("$GODOT_HEAD_INCLUDE",html_head_include); current_line = current_line.replace("$GODOT_STYLE_FONT_FAMILY",html_font_family); current_line = current_line.replace("$GODOT_STYLE_INCLUDE",html_style_include); current_line = current_line.replace("$GODOT_CONTROLS_ENABLED",html_controls_enabled?"true":"false"); current_line = current_line.replace("$GODOT_DEBUG_ENABLED",p_debug?"true":"false"); strnew += current_line+"\n"; } CharString cs = strnew.utf8(); p_html.resize(cs.length()); for(int i=9;i<cs.length();i++) { p_html[i]=cs[i]; } }
String OS_Unix::get_executable_path() const { #ifdef __linux__ //fix for running from a symlink char buf[256]; memset(buf,0,256); readlink("/proc/self/exe", buf, sizeof(buf)); //print_line("Exec path is:"+String(buf)); String b; b.parse_utf8(buf); if (b=="") { WARN_PRINT("Couldn't get executable path from /proc/self/exe, using argv[0]"); return OS::get_executable_path(); } return b; #elif defined(__FreeBSD__) char resolved_path[MAXPATHLEN]; realpath(OS::get_executable_path().utf8().get_data(), resolved_path); return String(resolved_path); #else ERR_PRINT("Warning, don't know how to obtain executable path on this OS! Please override this function properly."); return OS::get_executable_path(); #endif }
static Error _decode_string(const uint8_t *&buf, int &len, int *r_len, String &r_string) { ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); uint32_t strlen = decode_uint32(buf); buf += 4; len -= 4; ERR_FAIL_COND_V((int)strlen > len, ERR_FILE_EOF); String str; str.parse_utf8((const char *)buf, strlen); r_string = str; //handle padding if (strlen % 4) { strlen += 4 - strlen % 4; } buf += strlen; len -= strlen; if (r_len) { (*r_len) += 4 + strlen; } return OK; }
void MultiplayerAPI::_process_simplify_path(int p_from, const uint8_t *p_packet, int p_packet_len) { ERR_EXPLAIN("Invalid packet received. Size too small."); ERR_FAIL_COND(p_packet_len < 5); int id = decode_uint32(&p_packet[1]); String paths; paths.parse_utf8((const char *)&p_packet[5], p_packet_len - 5); NodePath path = paths; if (!path_get_cache.has(p_from)) { path_get_cache[p_from] = PathGetCache(); } PathGetCache::NodeInfo ni; ni.path = path; ni.instance = 0; path_get_cache[p_from].nodes[id] = ni; // Encode path to send ack. CharString pname = String(path).utf8(); int len = encode_cstring(pname.get_data(), NULL); Vector<uint8_t> packet; packet.resize(1 + len); packet.write[0] = NETWORK_COMMAND_CONFIRM_PATH; encode_cstring(pname.get_data(), &packet.write[1]); network_peer->set_transfer_mode(NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE); network_peer->set_target_peer(p_from); network_peer->put_packet(packet.ptr(), packet.size()); }
static String _get_clipboard(Atom p_source, Window x11_window, ::Display* x11_display, String p_internal_clipboard) { String ret; Atom type; Atom selection = XA_PRIMARY; int format, result; unsigned long len, bytes_left, dummy; unsigned char *data; Window Sown = XGetSelectionOwner (x11_display, p_source); if (Sown == x11_window) { printf("returning internal clipboard\n"); return p_internal_clipboard; }; if (Sown != None) { XConvertSelection (x11_display, p_source, XA_STRING, selection, x11_window, CurrentTime); XFlush (x11_display); while (true) { XEvent event; XNextEvent(x11_display, &event); if (event.type == SelectionNotify && event.xselection.requestor == x11_window) { break; }; }; // // Do not get any data, see how much data is there // XGetWindowProperty (x11_display, x11_window, selection, // Tricky.. 0, 0, // offset - len 0, // Delete 0==FALSE AnyPropertyType, //flag &type, // return type &format, // return format &len, &bytes_left, //that &data); // DATA is There if (bytes_left > 0) { result = XGetWindowProperty (x11_display, x11_window, selection, 0,bytes_left,0, AnyPropertyType, &type,&format, &len, &dummy, &data); if (result == Success) { ret.parse_utf8((const char*)data); } else printf ("FAIL\n"); XFree (data); } } return ret; };
String ResourceInteractiveLoaderBinary::get_unicode_string() { int len = f->get_32(); if (len>str_buf.size()) { str_buf.resize(len); } f->get_buffer((uint8_t*)&str_buf[0],len); String s; s.parse_utf8(&str_buf[0]); return s; }
String StreamPeer::get_utf8_string(int p_bytes) { ERR_FAIL_COND_V(p_bytes < 0, String()); Vector<uint8_t> buf; buf.resize(p_bytes); get_data(buf.ptr(), p_bytes); String ret; ret.parse_utf8((const char *)buf.ptr(), buf.size()); return ret; }
String DirAccessAndroid::get_next(){ const char* fn= AAssetDir_getNextFileName(aad); if (!fn) return ""; String s; s.parse_utf8(fn); current=s; return s; }
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; };
bool test_13() { OS::get_singleton()->print("\n\nTest 13: UTF8\n"); /* how can i embed UTF in here? */ static const CharType ustr[] = { 0x304A, 0x360F, 0x3088, 0x3046, 0 }; //static const wchar_t ustr[] = { 'P', 0xCE, 'p',0xD3, 0 }; String s = ustr; OS::get_singleton()->print("\tUnicode: %ls\n", ustr); s.parse_utf8(s.utf8().get_data()); OS::get_singleton()->print("\tConvert/Parse UTF8: %ls\n", s.c_str()); return (s == ustr); }
void MultiplayerAPI::_process_confirm_path(int p_from, const uint8_t *p_packet, int p_packet_len) { ERR_FAIL_COND(p_packet_len < 2); String paths; paths.parse_utf8((const char *)&p_packet[1], p_packet_len - 1); NodePath path = paths; PathSentCache *psc = path_send_cache.getptr(path); ERR_FAIL_COND(!psc); Map<int, bool>::Element *E = psc->confirmed_peers.find(p_from); ERR_FAIL_COND(!E); E->get() = true; }
StringName ResourceInteractiveLoaderBinary::_get_string() { uint32_t id = f->get_32(); if (id & 0x80000000) { uint32_t len = id & 0x7FFFFFFF; if ((int)len > str_buf.size()) { str_buf.resize(len); } if (len == 0) return StringName(); f->get_buffer((uint8_t *)&str_buf[0], len); String s; s.parse_utf8(&str_buf[0]); return s; } return string_map[id]; }
void RichTextEditor::_file_selected(const String& p_path) { CharString cs; FileAccess *fa = FileAccess::open(p_path,FileAccess::READ); if (!fa) { ERR_FAIL(); } while(!fa->eof_reached()) cs.push_back(fa->get_8()); cs.push_back(0); memdelete(fa); String bbcode; bbcode.parse_utf8(&cs[0]); node->parse_bbcode(bbcode); }
Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, int p_packet_len) { uint32_t target = decode_uint32(&p_packet[1]); Node *node = NULL; if (target & 0x80000000) { // Use full path (not cached yet). int ofs = target & 0x7FFFFFFF; ERR_EXPLAIN("Invalid packet received. Size smaller than declared."); ERR_FAIL_COND_V(ofs >= p_packet_len, NULL); String paths; paths.parse_utf8((const char *)&p_packet[ofs], p_packet_len - ofs); NodePath np = paths; node = root_node->get_node(np); if (!node) ERR_PRINTS("Failed to get path from RPC: " + String(np)); } else { // Use cached path. int id = target; Map<int, PathGetCache>::Element *E = path_get_cache.find(p_from); ERR_EXPLAIN("Invalid packet received. Requests invalid peer cache."); ERR_FAIL_COND_V(!E, NULL); Map<int, PathGetCache::NodeInfo>::Element *F = E->get().nodes.find(id); ERR_EXPLAIN("Invalid packet received. Unabled to find requested cached node."); ERR_FAIL_COND_V(!F, NULL); PathGetCache::NodeInfo *ni = &F->get(); // Do proper caching later. node = root_node->get_node(ni->path); if (!node) ERR_PRINTS("Failed to get cached path from RPC: " + String(ni->path)); } return node; }
void MultiplayerAPI::_process_confirm_path(int p_from, const uint8_t *p_packet, int p_packet_len) { ERR_EXPLAIN("Invalid packet received. Size too small."); ERR_FAIL_COND(p_packet_len < 2); String paths; paths.parse_utf8((const char *)&p_packet[1], p_packet_len - 1); NodePath path = paths; PathSentCache *psc = path_send_cache.getptr(path); ERR_EXPLAIN("Invalid packet received. Tries to confirm a path which was not found in cache."); ERR_FAIL_COND(!psc); Map<int, bool>::Element *E = psc->confirmed_peers.find(p_from); ERR_EXPLAIN("Invalid packet received. Source peer was not found in cache for the given path."); ERR_FAIL_COND(!E); E->get() = true; }
Error EditorSceneImporterFBXConv::_parse_json(State& state, const String &p_path) { //not the happiest.... Vector<uint8_t> data = FileAccess::get_file_as_array(p_path); ERR_FAIL_COND_V(!data.size(),ERR_FILE_CANT_OPEN); String str; bool utferr = str.parse_utf8((const char*)data.ptr(),data.size()); ERR_FAIL_COND_V(utferr,ERR_PARSE_ERROR); Dictionary dict; Error err = dict.parse_json(str); str=String(); //free mem immediately ERR_FAIL_COND_V(err,err); if (dict.has("meshes")) state.meshes=dict["meshes"]; if (dict.has("materials")) state.materials=dict["materials"]; if (dict.has("nodes")) state.nodes=dict["nodes"]; if (dict.has("animations")) state.animations=dict["animations"]; state.scene = memnew( Spatial ); _detect_bones(state); _parse_surfaces(state); _parse_materials(state); err = _parse_nodes(state,state.nodes,state.scene); if (err) return err; if (state.import_animations) { err = _parse_animations(state); if (err) return err; } print_line("JSON PARSED O-K!"); return OK; }
String OS_Unix::get_executable_path() const { #ifdef __linux__ //fix for running from a symlink char buf[256]; memset(buf,0,256); readlink("/proc/self/exe", buf, sizeof(buf)); String b; b.parse_utf8(buf); if (b=="") { WARN_PRINT("Couldn't get executable path from /proc/self/exe, using argv[0]"); return OS::get_executable_path(); } return b; #elif defined(__FreeBSD__) char resolved_path[MAXPATHLEN]; realpath(OS::get_executable_path().utf8().get_data(), resolved_path); return String(resolved_path); #elif defined(__APPLE__) char temp_path[1]; uint32_t buff_size=1; _NSGetExecutablePath(temp_path, &buff_size); char* resolved_path = new char[buff_size + 1]; if (_NSGetExecutablePath(resolved_path, &buff_size) == 1) WARN_PRINT("MAXPATHLEN is too small"); String path(resolved_path); delete[] resolved_path; return path; #elif defined(EMSCRIPTEN) // We return nothing return String(); #else ERR_PRINT("Warning, don't know how to obtain executable path on this OS! Please override this function properly."); return OS::get_executable_path(); #endif }
String DirAccessFlash::get_next() { if (!dir_stream) return ""; dirent *entry; entry=readdir(dir_stream); if (entry==NULL) { list_dir_end(); return ""; } //typedef struct stat Stat; struct stat flags; String fname; if (fname.parse_utf8(entry->d_name)) fname=entry->d_name; //no utf8, maybe latin? String f=current_dir+"/"+fname; if (stat(f.utf8().get_data(),&flags)==0) { if (S_ISDIR(flags.st_mode)) { _cisdir=true; } else { _cisdir=false; } } else { _cisdir=false; } return fname; };
RES ResourceFormatLoaderShader::load(const String &p_path, const String &p_original_path, Error *r_error) { if (r_error) *r_error = ERR_FILE_CANT_OPEN; Ref<Shader> shader; shader.instance(); Vector<uint8_t> buffer = FileAccess::get_file_as_array(p_path); String str; str.parse_utf8((const char *)buffer.ptr(), buffer.size()); shader->set_code(str); if (r_error) *r_error = OK; return shader; }
static void _fix_files(Vector<uint8_t>& html,uint64_t p_data_size) { String str; String strnew; str.parse_utf8((const char*)html.ptr(),html.size()); Vector<String> lines=str.split("\n"); for(int i=0;i<lines.size();i++) { if (lines[i].find("$DPLEN")!=-1) { strnew+=lines[i].replace("$DPLEN",itos(p_data_size)); } else { strnew+=lines[i]+"\n"; } } CharString cs = strnew.utf8(); html.resize(cs.size()); for(int i=9;i<cs.size();i++) { html[i]=cs[i]; } }
Error read_all_file_utf8(const String &p_path, String &r_content) { PoolVector<uint8_t> sourcef; Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); ERR_FAIL_COND_V(err != OK, err); int len = f->get_len(); sourcef.resize(len + 1); PoolVector<uint8_t>::Write w = sourcef.write(); int r = f->get_buffer(w.ptr(), len); f->close(); memdelete(f); ERR_FAIL_COND_V(r != len, ERR_CANT_OPEN); w[len] = 0; String source; if (source.parse_utf8((const char *)w.ptr())) { ERR_FAIL_V(ERR_INVALID_DATA); } r_content = source; return OK; }
static String _parse_string(const uint8_t *p_bytes,bool p_utf8) { uint32_t offset=0; uint32_t len = decode_uint16(&p_bytes[offset]); if (p_utf8) { //don't know how to read extended utf8, this will have to be for now len>>=8; } offset+=2; //printf("len %i, unicode: %i\n",len,int(p_utf8)); if (p_utf8) { Vector<uint8_t> str8; str8.resize(len+1); for(int i=0;i<len;i++) { str8[i]=p_bytes[offset+i]; } str8[len]=0; String str; str.parse_utf8((const char*)str8.ptr()); return str; } else { String str; for(int i=0;i<len;i++) { CharType c = decode_uint16(&p_bytes[offset+i*2]); if (c==0) break; str += String::chr(c); } return str; } }
void EditorExportPlatformOSX::_fix_plist(Vector<uint8_t>& plist,const String& p_binary) { String str; String strnew; str.parse_utf8((const char*)plist.ptr(),plist.size()); Vector<String> lines=str.split("\n"); for(int i=0;i<lines.size();i++) { if (lines[i].find("$binary")!=-1) { strnew+=lines[i].replace("$binary",p_binary)+"\n"; } else if (lines[i].find("$name")!=-1) { strnew+=lines[i].replace("$name",p_binary)+"\n"; } else if (lines[i].find("$info")!=-1) { strnew+=lines[i].replace("$info",info)+"\n"; } else if (lines[i].find("$identifier")!=-1) { strnew+=lines[i].replace("$identifier",identifier)+"\n"; } else if (lines[i].find("$short_version")!=-1) { strnew+=lines[i].replace("$short_version",short_version)+"\n"; } else if (lines[i].find("$version")!=-1) { strnew+=lines[i].replace("$version",version)+"\n"; } else if (lines[i].find("$signature")!=-1) { strnew+=lines[i].replace("$signature",signature)+"\n"; } else if (lines[i].find("$copyright")!=-1) { strnew+=lines[i].replace("$copyright",copyright)+"\n"; } else if (lines[i].find("$highres")!=-1) { strnew+=lines[i].replace("$highres",high_resolution?"<true/>":"<false/>")+"\n"; } else { strnew+=lines[i]+"\n"; } } CharString cs = strnew.utf8(); plist.resize(cs.size()); for(int i=9;i<cs.size();i++) { plist[i]=cs[i]; } }
void EditorExportPlatformOSX::_fix_plist(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist, const String &p_binary) { String str; String strnew; str.parse_utf8((const char *)plist.ptr(), plist.size()); Vector<String> lines = str.split("\n"); for (int i = 0; i < lines.size(); i++) { if (lines[i].find("$binary") != -1) { strnew += lines[i].replace("$binary", p_binary) + "\n"; } else if (lines[i].find("$name") != -1) { strnew += lines[i].replace("$name", p_binary) + "\n"; } else if (lines[i].find("$info") != -1) { strnew += lines[i].replace("$info", p_preset->get("application/info")) + "\n"; } else if (lines[i].find("$identifier") != -1) { strnew += lines[i].replace("$identifier", p_preset->get("application/identifier")) + "\n"; } else if (lines[i].find("$short_version") != -1) { strnew += lines[i].replace("$short_version", p_preset->get("application/short_version")) + "\n"; } else if (lines[i].find("$version") != -1) { strnew += lines[i].replace("$version", p_preset->get("application/version")) + "\n"; } else if (lines[i].find("$signature") != -1) { strnew += lines[i].replace("$signature", p_preset->get("application/signature")) + "\n"; } else if (lines[i].find("$copyright") != -1) { strnew += lines[i].replace("$copyright", p_preset->get("application/copyright")) + "\n"; } else if (lines[i].find("$highres") != -1) { strnew += lines[i].replace("$highres", p_preset->get("display/high_res") ? "<true/>" : "<false/>") + "\n"; } else { strnew += lines[i] + "\n"; } } CharString cs = strnew.utf8(); plist.resize(cs.size() - 1); for (int i = 0; i < cs.size() - 1; i++) { plist[i] = cs[i]; } }
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; } }
Error GDTokenizerBuffer::set_code_buffer(const Vector<uint8_t> & p_buffer) { const uint8_t *buf=p_buffer.ptr(); int total_len=p_buffer.size(); ERR_FAIL_COND_V( p_buffer.size()<24 || p_buffer[0]!='G' || p_buffer[1]!='D' || p_buffer[2]!='S' || p_buffer[3]!='C',ERR_INVALID_DATA); int version = decode_uint32(&buf[4]); if (version>BYTECODE_VERSION) { ERR_EXPLAIN("Bytecode is too New! Please use a newer engine version."); ERR_FAIL_COND_V(version>BYTECODE_VERSION,ERR_INVALID_DATA); } int identifier_count = decode_uint32(&buf[8]); int constant_count = decode_uint32(&buf[12]); int line_count = decode_uint32(&buf[16]); int token_count = decode_uint32(&buf[20]); const uint8_t *b=buf; b=&buf[24]; total_len-=24; identifiers.resize(identifier_count); for(int i=0;i<identifier_count;i++) { int len = decode_uint32(b); ERR_FAIL_COND_V(len>total_len,ERR_INVALID_DATA); b+=4; Vector<uint8_t> cs; cs.resize(len); for(int j=0;j<len;j++) { cs[j]=b[j]^0xb6; } cs[cs.size()-1]=0; String s; s.parse_utf8((const char*)cs.ptr()); b+=len; total_len-=len+4; identifiers[i]=s; } constants.resize(constant_count); for(int i=0;i<constant_count;i++) { Variant v; int len; Error err = decode_variant(v,b,total_len,&len); if (err) return err; b+=len; total_len-=len; constants[i]=v; } ERR_FAIL_COND_V(line_count*8>total_len,ERR_INVALID_DATA); for(int i=0;i<line_count;i++) { uint32_t token=decode_uint32(b); b+=4; uint32_t linecol=decode_uint32(b); b+=4; lines.insert(token,linecol); total_len-=8; } tokens.resize(token_count); for(int i=0;i<token_count;i++) { ERR_FAIL_COND_V( total_len < 1, ERR_INVALID_DATA); if ((*b)&TOKEN_BYTE_MASK) { //little endian always ERR_FAIL_COND_V( total_len < 4, ERR_INVALID_DATA); tokens[i]=decode_uint32(b)&~TOKEN_BYTE_MASK; b+=4; } else { tokens[i]=*b; b+=1; total_len--; } } token=0; return OK; }