// given a valid XSTR() tag piece of text, extract the string portion, return it in out, nonzero on success int lcl_ext_get_text(const SCP_string &xstr, SCP_string &out) { size_t open_quote_pos, close_quote_pos; // this is some crazy wack-ass code. // look for the open quote open_quote_pos = xstr.find('\"'); if (open_quote_pos == SCP_string::npos) { error_display(0, "Error parsing XSTR() tag %s\n", xstr.c_str()); return 0; } // look for the close quote close_quote_pos = xstr.find('\"', open_quote_pos+1); if (close_quote_pos == SCP_string::npos) { error_display(0, "Error parsing XSTR() tag %s\n", xstr.c_str()); return 0; } // now that we know the boundaries of the actual string in the XSTR() tag, copy it out.assign(xstr, open_quote_pos + 1, close_quote_pos - open_quote_pos - 1); // success return 1; }
bool get_user_sid(SCP_string& outStr) { HANDLE hToken = NULL; if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken) == FALSE) { mprintf(("Failed to get process token! Error Code: %d", GetLastError())); return false; } DWORD dwBufferSize; GetTokenInformation(hToken, TokenUser, NULL, 0, &dwBufferSize); PTOKEN_USER ptkUser = (PTOKEN_USER) new byte[dwBufferSize]; if (GetTokenInformation(hToken, TokenUser, ptkUser, dwBufferSize, &dwBufferSize)) { CloseHandle(hToken); } if (IsValidSid(ptkUser->User.Sid) == FALSE) { mprintf(("Invalid SID structure detected!")); delete[] ptkUser; return false; } LPTSTR sidName = NULL; if (ConvertSidToStringSid(ptkUser->User.Sid, &sidName) == 0) { mprintf(("Failed to convert SID structure to string! Error Code: %d", GetLastError())); delete[] ptkUser; return false; } outStr.assign(sidName); LocalFree(sidName); delete[](byte*) ptkUser; return true; }
/** * Load a shader file from disc or from the builtin defaults in def_files.cpp if none can be found. * This function will also create a list of preprocessor defines for the GLSL compiler based on the shader flags * and the supported GLSL version as reported by the GPU driver. * * @param shader shader_type enum defined with which shader we're loading * @param filename C-string holding the filename (with extension) of the shader file * @param flags integer variable holding a combination of SDR_* flags * @return C-string holding the complete shader source code */ static SCP_string opengl_load_shader(const char* filename) { SCP_string content; if (Enable_external_shaders) { CFILE* cf_shader = cfopen(filename, "rt", CFILE_NORMAL, CF_TYPE_EFFECTS); if (cf_shader != NULL) { int len = cfilelength(cf_shader); content.resize(len); cfread(&content[0], len + 1, 1, cf_shader); cfclose(cf_shader); return content; } } //If we're still here, proceed with internals mprintf((" Loading built-in default shader for: %s\n", filename)); auto def_shader = defaults_get_file(filename); content.assign(reinterpret_cast<const char*>(def_shader.data), def_shader.size); return content; }
bool pilotfile_convert::plr_convert(const char *fname, bool inferno) { Assert( fname != NULL ); SCP_string filename; bool rval = true; if (plr == NULL) { plr = new(std::nothrow) plr_data; } if (plr == NULL) { return false; } filename.reserve(200); cf_create_default_path_string(filename, CF_TYPE_SINGLE_PLAYERS, (inferno) ? const_cast<char*>("inferno") : NULL); if (inferno) { filename.append(DIR_SEPARATOR_STR); } filename.append(fname); filename.append(".pl2"); mprintf((" PL2 => Converting '%s'...\n", filename.c_str())); cfp = cfopen(const_cast<char*>(filename.c_str()), "rb", CFILE_NORMAL); if ( !cfp ) { mprintf((" PL2 => Unable to open for import!\n", fname)); return false; } try { plr_import(); } catch (const char *err) { mprintf(( " PL2 => Import ERROR: %s\n", err)); rval = false; } cfclose(cfp); cfp = NULL; if ( !rval ) { return false; } filename.assign(fname); filename.append(".plr"); cfp = cfopen(const_cast<char*>(filename.c_str()), "wb", CFILE_NORMAL, CF_TYPE_PLAYERS); if ( !cfp ) { mprintf((" PLR => Unable to open for export!\n", fname)); return false; } try { plr_export(); } catch (const char *err) { mprintf((" PLR => Export ERROR: %s\n", err)); rval = false; } cfclose(cfp); cfp = NULL; if (rval) { mprintf((" PLR => Conversion complete!\n")); } return rval; }
bool pilotfile_convert::csg_convert(const char *fname, bool inferno) { Assert( fname != NULL ); Assert( plr != NULL); Assert( csg == NULL ); SCP_string filename; bool rval = true; csg = new(std::nothrow) csg_data; if (csg == NULL) { return false; } filename.reserve(200); cf_create_default_path_string(filename, CF_TYPE_SINGLE_PLAYERS, (inferno) ? "inferno" : nullptr, false, CF_LOCATION_ROOT_USER | CF_LOCATION_ROOT_GAME | CF_LOCATION_TYPE_ROOT); if (inferno) { filename.append(DIR_SEPARATOR_STR); } filename.append(fname); filename.append(".cs2"); mprintf((" CS2 => Converting '%s'...\n", filename.c_str())); cfp = cfopen(filename.c_str(), "rb", CFILE_NORMAL); if ( !cfp ) { mprintf((" CS2 => Unable to open '%s' for import!\n", fname)); delete csg; csg = NULL; return false; } try { csg_import(inferno); } catch (const std::exception& err) { mprintf((" CS2 => Import ERROR: %s\n", err.what())); rval = false; } cfclose(cfp); cfp = NULL; if ( !rval ) { delete csg; csg = NULL; return false; } filename.assign(fname); filename.append(".csg"); cfp = cfopen(filename.c_str(), "wb", CFILE_NORMAL, CF_TYPE_PLAYERS, false, CF_LOCATION_ROOT_USER | CF_LOCATION_ROOT_GAME | CF_LOCATION_TYPE_ROOT); if ( !cfp ) { mprintf((" CSG => Unable to open '%s' for export!\n", fname)); return false; } try { csg_export(); } catch (const char *err) { mprintf((" CSG => Export ERROR: %s\n", err)); rval = false; } cfclose(cfp); cfp = NULL; delete csg; csg = NULL; if (rval) { mprintf((" CSG => Conversion complete!\n")); } return rval; }