Exemple #1
0
bool CircularNanoparticle::saveState(std::ofstream & stream)
{
	/* Format:
	*  
	*  <parent_data><mRadius><boundary>
	*/

	//call parent so it can sort out saving its part
	if(! Nanoparticle::saveState(stream) )
	{
		return false;
	}

	
	if(!stream.good())
	{
		cerr << "Error: Cannot save CircularNanoparticle. Stream not good" << endl;
		return false;
	}

	stream.write( (char*) &mRadius, sizeof(int));

	if(!stream.good())
	{
		cerr << "Error: Cannot save CircularNanoparticle. Failed writing mRadius" << endl;
		return false;
	}

	stream.write( (char*) &mBoundary, sizeof(enum boundary));

	if(!stream.good())
	{
		cerr << "Error: Cannot save CircularNanoparticle. Failed writing mBoundary" << endl;
		return false;
	}

	return true;
}
Exemple #2
0
bool ProjectileRecord::saveToStream(std::ofstream& outStream) const
{
  if (!outStream.good())
  {
    DuskLog() << "ProjectileRecord::saveToStream: ERROR: stream contains errors!\n";
    return false;
  }

  uint32_t len = 0;

  //header "Proj"
  outStream.write((const char*) &cHeaderProj, sizeof(uint32_t));
  //ID
  len = ID.length();
  outStream.write((const char*) &len, sizeof(uint32_t));
  outStream.write(ID.c_str(), len);
  //Mesh
  len = Mesh.length();
  outStream.write((const char*) &len, sizeof(uint32_t));
  outStream.write(Mesh.c_str(), len);
  //TTL
  outStream.write((const char*) &DefaultTTL, sizeof(float));
  //velocity
  outStream.write((const char*) &DefaultVelocity, sizeof(float));
  //times
  outStream.write((const char*) &times, sizeof(uint8_t));
  //dice
  outStream.write((const char*) &dice, sizeof(uint8_t));
  //check
  if (!outStream.good())
  {
    DuskLog() << "ProjectileRecord::saveToStream: Error while writing data to "
              << "stream. Current projectile is \""<<ID<<"\".\n";
    return false;
  }

  return outStream.good();
}
bool PerkRecord::saveToStream(std::ofstream& output) const
{
  output.write((const char*) &cPERK, 4);
  if (!saveSizeAndUnknownValues(output, getWriteSize())) return false;

  //write EDID
  output.write((const char*) &cEDID, 4);
  //EDID's length
  uint16_t subLength = editorID.length()+1;
  output.write((const char*) &subLength, 2);
  //write editor ID
  output.write(editorID.c_str(), subLength);

  if (unknownVMAD.isPresent())
  {
    //write VMAD
    if (!unknownVMAD.saveToStream(output, cVMAD))
    {
      std::cout << "Error while writing subrecord VMAD of PERK!\n";
      return false;
    }
  }//if VMAD

  if (name.isPresent())
  {
    //write FULL
    if (!name.saveToStream(output, cFULL))
      return false;
  }//if has FULL

  //write DESC
  if (!description.saveToStream(output, cDESC))
    return false;

  if (!subBlocks.empty())
  {
    unsigned int i;
    for (i=0; i<subBlocks.size(); ++i)
    {
      if (!subBlocks[i].subData.saveToStream(output, subBlocks[i].subType))
      {
        std::cout << "Error while writing (binary) subrecord "
                  << IntTo4Char(subBlocks[i].subType)<<" of PERK!\n";
        return false;
      }//if
    }//for
  }//if subBlocks

  return output.good();
}
bool ArtObjectRecord::saveToStream(std::ofstream& output) const
{
  output.write((const char*) &cARTO, 4);
  if (!saveSizeAndUnknownValues(output, getWriteSize())) return false;

  //write EDID
  output.write((const char*) &cEDID, 4);
  //EDID's length
  uint16_t subLength = editorID.length()+1;
  output.write((const char*) &subLength, 2);
  //write editor ID
  output.write(editorID.c_str(), subLength);

  //write OBND
  output.write((const char*) &cOBND, 4);
  //OBND's length
  subLength = 12;
  output.write((const char*) &subLength, 2);
  //write OBND
  output.write((const char*) unknownOBND, 12);

  //write MODL
  output.write((const char*) &cMODL, 4);
  //MODL's length
  subLength = modelPath.length()+1;
  output.write((const char*) &subLength, 2);
  //write model path
  output.write(modelPath.c_str(), subLength);

  if (unknownMODT.isPresent())
  {
    //write MODT
    if (!unknownMODT.saveToStream(output, cMODT))
    {
      std::cout << "Error while writing subrecord MODT of ARTO!\n";
      return false;
    }
  }//if MODT

  //write DNAM
  output.write((const char*) &cDNAM, 4);
  //DNAM's length
  subLength = 4; //fixed size
  output.write((const char*) &subLength, 2);
  //write DNAM
  output.write((const char*) &unknownDNAM, 4);

  return output.good();
}
void PerfdataWriter::RotateFile(std::ofstream& output, const String& temp_path, const String& perfdata_path)
{
	ObjectLock olock(this);

	if (output.good()) {
		output.close();

		if (Utility::PathExists(temp_path)) {
			String finalFile = perfdata_path + "." + Convert::ToString((long)Utility::GetTime());
			if (rename(temp_path.CStr(), finalFile.CStr()) < 0) {
				BOOST_THROW_EXCEPTION(posix_error()
				    << boost::errinfo_api_function("rename")
				    << boost::errinfo_errno(errno)
				    << boost::errinfo_file_name(temp_path));
			}
		}
	}

	output.open(temp_path.CStr());

	if (!output.good())
		Log(LogWarning, "PerfdataWriter")
		    << "Could not open perfdata file '" << temp_path << "' for writing. Perfdata will be lost.";
}
Exemple #6
0
void __cdecl sdlog(const char *fmt, ...) {
	if(ofile.good()) {
		if(!fmt) { return; }

		va_list va_alist;
		char logbuf[9999] = {0};

		va_start (va_alist, fmt);
		_vsnprintf_s(logbuf+strlen(logbuf), sizeof(logbuf) - strlen(logbuf), _TRUNCATE, fmt, va_alist);
		va_end (va_alist);

		ofile << logbuf;
		ofile.flush();
	}
}
bool NavMeshRecord::saveToStream(std::ofstream& output) const
{
  output.write((const char*) &cNAVM, 4);
  if (!saveSizeAndUnknownValues(output, getWriteSize())) return false;
  if (isDeleted()) return true;

  if (unknownNVNM.isPresent())
  {
    //write NVNM
    if (!unknownNVNM.saveToStream(output, cNVNM))
    {
      std::cout << "Error while writing subrecord NVNM of NAVM!\n";
      return false;
    }
  }//if NVNM

  if (unknownONAM.isPresent())
  {
    //write ONAM
    if (!unknownONAM.saveToStream(output, cONAM))
    {
      std::cout << "Error while writing subrecord ONAM of NAVM!\n";
      return false;
    }
  }//if ONAM

  if (unknownNNAM.isPresent())
  {
    //write NNAM
    if (!unknownNNAM.saveToStream(output, cNNAM))
    {
      std::cout << "Error while writing subrecord NNAM of NAVM!\n";
      return false;
    }
  }//if NNAM

  if (unknownPNAM.isPresent())
  {
    //write PNAM
    if (!unknownPNAM.saveToStream(output, cPNAM))
    {
      std::cout << "Error while writing subrecord PNAM of NAVM!\n";
      return false;
    }
  }//if PNAM

  return output.good();
}
bool ActionRecord::saveToStream(std::ofstream& output) const
{
  output.write((const char*) &cAACT, 4);
  if (!saveSizeAndUnknownValues(output, getWriteSize())) return false;
  if (isDeleted()) return true;

  //write EDID
  output.write((const char*) &cEDID, 4);
  //EDID's length
  uint16_t subLength = editorID.length()+1;
  output.write((const char*) &subLength, 2);
  //write editor ID
  output.write(editorID.c_str(), subLength);

  return output.good();
}
Exemple #9
0
void
PeakClusterSelect::myUpdate(MarControlPtr sender)
{
  (void) sender;  //suppress warning of unused parameter(s)
  MRSDIAG("PeakClusterSelect.cpp - PeakClusterSelect:myUpdate");

  ctrl_onObservations_->setValue(1, NOUPDATE);
  ctrl_onSamples_->setValue(ctrl_inSamples_, NOUPDATE);
  ctrl_osrate_->setValue(ctrl_israte_, NOUPDATE);
  ctrl_onObsNames_->setValue("peakLabels", NOUPDATE);

#ifdef DBG_FILE_OUT
  if (!outTextFile.good () || ! outTextFile.is_open ())
    outTextFile.open(outFileName.c_str ());
#endif
}
Exemple #10
0
void Wiimote::SpeakerData(wm_speaker_data* sd)
{
    // TODO consider using static max size instead of new
    s16 *samples = new s16[sd->length * 2];

    if (m_reg_speaker.format == 0x40)
    {
        // 8 bit PCM
        for (int i = 0; i < sd->length; ++i)
        {
            samples[i] = (s16)(s8)sd->data[i];
        }
    }
    else if (m_reg_speaker.format == 0x00)
    {
        // 4 bit Yamaha ADPCM (same as dreamcast)
        for (int i = 0; i < sd->length; ++i)
        {
            samples[i * 2] = adpcm_yamaha_expand_nibble(m_adpcm_state, (sd->data[i] >> 4) & 0xf);
            samples[i * 2 + 1] = adpcm_yamaha_expand_nibble(m_adpcm_state, sd->data[i] & 0xf);
        }
    }

#ifdef WIIMOTE_SPEAKER_DUMP
    static int num = 0;

    if (num == 0)
    {
        File::Delete("rmtdump.wav");
        File::Delete("rmtdump.bin");
        atexit(stopdamnwav);
        OpenFStream(ofile, "rmtdump.bin", ofile.binary | ofile.out);
        wav.Start("rmtdump.wav", 6000/*Common::swap16(m_reg_speaker.sample_rate)*/);
    }
    wav.AddMonoSamples(samples, sd->length*2);
    if (ofile.good())
    {
        for (int i = 0; i < sd->length; i++)
        {
            ofile << sd->data[i];
        }
    }
    num++;
#endif

    delete[] samples;
}
int main(int argc, char * argv[])
{
    PIN_Init(argc, argv);

    Out.open(KnobOutfile.Value().c_str());
    if (!Out.good())
    {
        std::cerr << "Unable to open '" << KnobOutfile.Value() << "'" << std::endl;
        return 1;
    }

    INS_AddInstrumentFunction(InstrumentIndirects, 0);
    PIN_AddFiniFunction(Fini, 0);

    PIN_StartProgram();
    return 0;
}
/**
 * @brief Called once at engine initialization to set the timer
 */
void profile_init()
{
    start_profile_time = timer_get_microseconds();

    if (Cmdline_profile_write_file)
    {
        profiling_file.open("profiling.csv");

        if (!profiling_file.good())
        {
            mprintf(("Failed to open profiling output file 'profiling.csv'!"));
        }
    }

    if (Cmdline_json_profiling) {
        _mkdir("tracing");
    }
}
Exemple #13
0
bool GroupData::saveToStream(std::ofstream& output) const
{
  output.write((const char*) &cGRUP, 4);
  //write size
  output.write((const char*) &m_GroupSize, 4);
  //write label
  output.write((const char*) &m_GroupLabel, 4);
  //write type
  output.write((const char*) &m_GroupType, 4);
  //write unknown data
  unsigned int i;
  for (i=0; i<2; ++i)
  {
    output.write((const char*) &(UnknownGroupDataTwo[i]), 4);
  }//for

  return output.good();
}
Exemple #14
0
///////////////////////////////////////////////////////////////////////
// Name: OpenLog()
// Desc: open global log file
///////////////////////////////////////////////////////////////////////
bool OpenLog ( const char* filename )
{
    String time( GetFormattedTime() );

    // open debug file
    debug_file.open ( filename, std::ios::out ); //ios::ate );
    if ( ! debug_file.good() )
      return false;

    debug_file << "<html><head><title>Savage Wheels Log File</title></head><body><h1>Savage Wheels V" << VER_MAJ << "." << VER_MIN << " - Log File</h1>";
    debug_file << "<hr/><pre>";
    debug_file <<  time << "Build: " << APP_NAME << " <br/>";
    debug_file <<  time << "Copyright &copy; 2003-2013 KenamicK Entertainment <br />";
    debug_file <<  time << "Opened on: " << __DATE__ << "<br />";
    debug_file <<  time << "Opened at: " << __TIME__ << "<br />";
    debug_file <<  time << LOG_DASH << "<br />";

    return true;
}
Exemple #15
0
void Log::logStandardOutputs( boost::shared_ptr< sbf::pkg::Module > module )
{
	namespace bfs = boost::filesystem;
 	namespace bpx = boost::posix_time;

	// Resets previous redirection (if any)
	outRedirection.reset();
 	errRedirection.reset();
 	logRedirection.reset();

	// Creates log directory
	g_logDirectory = module->getPathSafe(sbf::pkg::VarPath) / "log";
	try 
	{
		boost::filesystem::create_directory(g_logDirectory);
	}
	catch(const std::exception& e) 
	{
		std::cerr << e.what( ) << std::endl;

	}

	// log-ulis2-0-2010-11-16_15h25m48s.txt
	g_logFilePrefix = std::string("log_") + module->getName() + module->getVersion() + "_";
	g_logFileSuffix = ".txt";

	std::stringstream ss;
	bpx::time_facet * outputFacet = new bpx::time_facet(); 
	ss.imbue( std::locale(std::locale::classic(), outputFacet) );
	// Monday-29-02-2009_14h30m12s
	outputFacet->format("%Y-%m-%d_%Hh%Mm%Ss");
	ss << g_logFilePrefix << bpx::second_clock::local_time() << g_logFileSuffix;
	g_currentLogFile = ss.str();

	static std::ofstream logFile( (g_logDirectory / g_currentLogFile ).string().c_str() );
	if(logFile.good())
	{
		outRedirection.reset(new vgDebug::StreamTee(&std::cout, &logFile));
		errRedirection.reset(new vgDebug::StreamTee(&std::cerr, &logFile));
		logRedirection.reset(new vgDebug::StreamTee(&std::clog, &logFile));
	}
}
Exemple #16
0
void parse_template(template_files_vector::iterator i, std::ifstream &input, std::ofstream &output, const symbol_map &symbols)
{
    std::string line;
    parser_vector parsers;
    parsers.push_back(parser_object_ptr(new symbol_parser(symbols, parsers, input, output)));

    input.open(i->first.c_str(), std::ios::in);
    string_pair &out_file = i->second;
    output.open(std::string(out_file.first + symbols.find("NAME_LOWER")->second + out_file.second).c_str(),
        std::ios::out | std::ios::trunc);

    if( !input.is_open() )
        throw std::runtime_error("Failed to open template file");
    if( !output.is_open() )
        throw std::runtime_error("Failed to open output file");

    std::string buff;

    // read and write line by line
    while(true)
    {
        symbol_parser::m_should_output = true;

        std::getline(input, line);
        buff = line;

        if( input.eof() )
            break;

        if( !input.good() || !output.good() )
            throw std::runtime_error("Input or Output error!");

        for( parser_vector::reverse_iterator i = parsers.rbegin(), end = parsers.rend(); i != end; ++i )
            if( (**i)(buff) )
                break;
    }

    input.close();
    output.close();
    input.clear();
    output.clear();
}
Exemple #17
0
void	holBooking::printToFile( std::ofstream& out )
{
	if( out.good() )
	{
		out << holName << std::endl;
		node *tmp = first;
		if( first != NULL )
		{
			out << tmp->name << "  " << tmp->holiday << std::endl;
			
			while(tmp->next != NULL )
			{
				tmp = tmp->next;
				out << tmp->name << "  " << tmp->holiday << std::endl;
			}
				
		}
		out << "BREAK BREAK" << std::endl;
	}
}
bool DestructionData::saveToStream(std::ofstream& output) const
{
  if (!isPresent) return true;
  //write DEST
  output.write((const char*) &cDEST, 4);
  //DEST's length
  const uint16_t subLength = 8;
  output.write((const char*) &subLength, 2);
  //write DEST
  output.write((const char*) &health, 4);
  output.write((const char*) &stageCount, 1);
  output.write((const char*) &unknownTwo, 1);
  output.write((const char*) &unknownThreeFour, 2);
  unsigned int i;
  for (i=0; i<stages.size(); ++i)
  {
    if (!stages[i].saveToStream(output))
      return false;
  }//for
  return output.good();
}
Exemple #19
0
void print_alert(libtorrent::alert const* a, std::ostream& os)
{
	using namespace libtorrent;

#ifdef ANSI_TERMINAL_COLORS
	if (a->category() & alert::error_notification)
	{
		os << esc("31");
	}
	else if (a->category() & (alert::peer_notification | alert::storage_notification))
	{
		os << esc("33");
	}
#endif
	os << "[" << time_now_string() << "] " << a->message();
#ifdef ANSI_TERMINAL_COLORS
	os << esc("0");
#endif

	if (g_log_file.good())
		g_log_file << "[" << time_now_string() << "] " << a->message() << std::endl;
}
Exemple #20
0
bool FileSystem::rawopen
	(
	std::ofstream& out,			// Output stream to open.
	const string &fname,			// May be converted to upper-case.
	bool is_text				// Should the file be opened in text mode
	)
{
	string name = fname;
	if (!rewrite_virtual_path(name)) {
		con.Print_err(MM_MAJOR_WARN, "Illegal file access\n");
		return false;
	}

#if defined(MACOS) || (__GNUG__ > 2)
	std::ios_base::openmode mode = std::ios::out | std::ios::trunc;
	if (!is_text) mode |= std::ios::binary;
#elif defined(UNIX)
	int mode = std::ios::out | std::ios::trunc;
#else
	int mode = std::ios::out | std::ios::trunc;
	if (!is_text) mode |= std::ios::binary;
#endif
	switch_slashes(name);

	// We first "clear" the stream object. This is done to prevent
	// problems when re-using stream objects
	out.clear();

	int uppercasecount = 0;
	do {
		out.open(name.c_str(), mode);		// Try to open
		if (out.good()) return true;		// found it!
		out.clear();						// Forget ye not
	} while (base_to_uppercase(name, ++uppercasecount));

	// file not found.
	return false;
}
bool EquipmentSlotRecord::saveToStream(std::ofstream& output) const
{
  output.write((const char*) &cEQUP, 4);
  if (!saveSizeAndUnknownValues(output, getWriteSize())) return false;

  //write EDID
  output.write((const char*) &cEDID, 4);
  //EDID's length
  uint16_t subLength = editorID.length()+1;
  output.write((const char*) &subLength, 2);
  //write editor ID
  output.write(editorID.c_str(), subLength);

  if (!parentSlots.empty())
  {
    //write PNAM
    output.write((const char*) &cPNAM, 4);
    //PNAM's length
    subLength = 4*parentSlots.size();
    output.write((const char*) &subLength, 2);
    unsigned int i;
    for (i=0; i<parentSlots.size(); ++i)
    {
      //write PNAM's data
      output.write((const char*) &(parentSlots[i]), 4);
    }//for
  }//if has PNAM

  //write DATA
  output.write((const char*) &cDATA, 4);
  //DATA's length
  subLength = 4;
  output.write((const char*) &subLength, 2);
  //write DATA's data
  output.write((const char*) &flags, 4);

  return output.good();
}
bool MovementTypeRecord::saveToStream(std::ofstream& output) const
{
  output.write((const char*) &cMOVT, 4);
  if (!saveSizeAndUnknownValues(output, getWriteSize())) return false;

  //write EDID
  output.write((const char*) &cEDID, 4);
  //EDID's length
  uint16_t subLength = editorID.length()+1;
  output.write((const char*) &subLength, 2);
  //write editor ID
  output.write(editorID.c_str(), subLength);

  //write NNAM
  output.write((const char*) &cNNAM, 4);
  //NNAM's length
  subLength = nameString.length()+1;
  output.write((const char*) &subLength, 2);
  //write name string
  output.write(nameString.c_str(), subLength);

  //write SPED
  if (!unknownSPED.saveToStream(output, cSPED))
  {
    std::cout << "Error while writing subrecord SPED of MOVT!\n";
    return false;
  }

  //write INAM
  if (!unknownINAM.saveToStream(output, cINAM))
  {
    std::cout << "Error while writing subrecord INAM of MOVT!\n";
    return false;
  }

  return output.good();
}
Exemple #23
0
  Copier(CopyDescriptor desc,	 
	 unsigned block_size)
    : _desc(desc),
      _src(_desc.src.c_str()),
      _dest(_desc.dest.c_str()),
      _block_size(block_size)
  {
    _done = false;
  
    // get length of the source file
    _src.seekg (0, std::ios::end);
    _src_length = _src.tellg();
    _src.seekg (0, std::ios::beg);    
    _src_offset = 0;

    if(_src_length == 0)
      _done = true;

    if(!_src.good())
      throw "Unable to open source file!";

    if(!_dest.good())
      throw "Unable to open dest file!";
  }
Exemple #24
0
void setLoggingDestination(Destination dest)
{
    switch (dest) {
    case Destination::COUT:
    {
        _logger = _coutLogger;
        break;
    }
    case Destination::CERR:
    {
        _logger = _cerrLogger;
        break;
    }
    case Destination::FILE:
    {
        if(_fileOutput.good())
        {
            _logger = _fileLogger;
        }
        else
        {
            std::cerr << "ERROR: Invalid output stream - cannot log to file";
        }
        break;
    }
    case Destination::SYSLOG:
    {
        std::cerr << "WARNING: Not implemented logger output used" << std::endl;
        _logger = _syslogLogger;
        break;
    }
    default:
        std::cerr << "Not supported logging output" << std::endl;
        break;
    }
}
bool ScriptRecord::saveToStream(std::ofstream& output) const
{
  output.write((const char*) &cSCPT, 4);
  uint32_t Size;
  Size = 4 /* SCHD */ +4 /* 4 bytes for length */ +52 /* fixed length is 52 bytes */
        +4 /* SCDT */ +4 /* 4 bytes for length */ +ScriptDataSize
        +4 /* SCTX */ +4 /* 4 bytes for length */
        +ScriptText.length() /* length of text (no NUL termination) */;
  if (!LocalVars.empty())
  {
    Size = Size + 4 /* SCVR */ +4 /* 4 bytes for length */;
    unsigned int i;
    for (i=0; i<LocalVars.size(); ++i)
    {
      Size = Size + LocalVars.at(i).length()+1;/*length of string +1 for NUL termination*/
    }
  }
  output.write((const char*) &Size, 4);
  output.write((const char*) &HeaderOne, 4);
  output.write((const char*) &HeaderFlags, 4);

  /*Script:
    SCHD = Script Header (52 bytes)
        char Name[32]
        long NumShorts
        long NumLongs
        long NumFloats
        long ScriptDataSize
        long LocalVarSize
    SCVR = List of all the local script variables seperated by '\0' NULL characters.
    SCDT = The compiled script data
    SCTX = Script text
      Note (thoronador): SCVR may not be present at all, if there are no local
          vars. Moreover, SCVR, SCDT and SCTX can occur in any order.*/

  //write SCHD
  output.write((const char*) &cSCHD, 4);
  uint32_t SubLength = 52; /* length is fixed at 52 bytes */
  //write SCHD's length
  output.write((const char*) &SubLength, 4);
  //write script header
  // ---- write ID
  uint_fast32_t ID_len = recordID.length()+1;
  if (ID_len>32) ID_len = 32;
  output.write(recordID.c_str(), ID_len);
  //Do we need to fill the rest to reach 32 characters?
  if (ID_len<32)
  {
    output.write(NULof32, 32 - ID_len);
  }
  // ---- write local var counts
  output.write((const char*) &NumShorts, 4);
  output.write((const char*) &NumLongs, 4);
  output.write((const char*) &NumFloats, 4);
  // ---- write sizes
  output.write((const char*) &ScriptDataSize, 4);
  output.write((const char*) &LocalVarSize, 4);

  if (!LocalVars.empty())
  {
    //write SCVR
    output.write((const char*) &cSCVR, 4);
    //length is sum of lengths of individual strings
    SubLength = 0;
    unsigned int i;
    for (i=0; i<LocalVars.size(); ++i)
    {
      SubLength += LocalVars.at(i).length()+1;/*length of string +1 for NUL termination*/
    }
    //write SCVR's length
    output.write((const char*) &SubLength, 4);
    //write script's variable list
    for (i=0; i<LocalVars.size(); ++i)
    {
      output.write(LocalVars.at(i).c_str(), LocalVars.at(i).length()+1);/*length of string +1 for NUL termination*/
    }
  }

  //check if data is present
  if ((ScriptDataSize!=0) and (ScriptData==NULL))
  {
    std::cout << "Error while writing script record: script data is NULL, "
              << "but size is not zero.\n";
    return false;
  }

  //write SCDT
  output.write((const char*) &cSCDT, 4);
  SubLength = ScriptDataSize;
  //write SCDT's length
  output.write((const char*) &SubLength, 4);
  //write script compiled data
  output.write(ScriptData, SubLength);

  //write SCTX
  output.write((const char*) &cSCTX, 4);
  SubLength = ScriptText.length(); /* length of text, no NUL-termination */
  //write SCTX's length
  output.write((const char*) &SubLength, 4);
  //write script compiled data
  output.write(ScriptText.c_str(), SubLength);

  return output.good();
}
bool CombatStyleRecord::saveToStream(std::ofstream& output) const
{
  output.write((const char*) &cCSTY, 4);
  if (!saveSizeAndUnknownValues(output, getWriteSize())) return false;

  //write EDID
  output.write((const char*) &cEDID, 4);
  //EDID's length
  uint16_t subLength = editorID.length()+1;
  output.write((const char*) &subLength, 2);
  //write editor ID
  output.write(editorID.c_str(), subLength);

  //write CSGD
  output.write((const char*) &cCSGD, 4);
  //CSGD's length
  if (csgdLen==gdl40Bytes)
  {
    subLength = 40; //fixed
  }
  else if (csgdLen==gdl32Bytes)
  {
    subLength = 32; //fixed
  }
  else
  {
    subLength = 8; //fixed
  }
  output.write((const char*) &subLength, 2);
  //write CSGD's stuff
  output.write((const char*) &offensiveMult, 4);
  output.write((const char*) &defensiveMult, 4);
  if (csgdLen>gdl8Bytes)
  {
    output.write((const char*) &groupOffensiveMult, 4);
    output.write((const char*) &melee, 4);
    output.write((const char*) &magic, 4);
    output.write((const char*) &ranged, 4);
    output.write((const char*) &shout, 4);
    output.write((const char*) &unarmed, 4);
  }
  if (csgdLen==gdl40Bytes)
  {
    output.write((const char*) &staff, 4);
    output.write((const char*) &avoidThreatChance, 4);
  }

  if (hasCSMD)
  {
    //write CSMD
    output.write((const char*) &cCSMD, 4);
    //CSMD's length
    subLength = 8;
    output.write((const char*) &subLength, 2);
    //write CSMD's stuff
    output.write((const char*) &unknownCSMDOne, 4);
    output.write((const char*) &unknownCSMDTwo, 4);
  }//if CSMD

  unsigned int i;
  if (!unknownCSME.empty())
  {
    //write CSME
    output.write((const char*) &cCSME, 4);
    //CSME's length
    subLength = 4*unknownCSME.size();
    output.write((const char*) &subLength, 2);
    //write CSME's stuff
    for (i=0; i<unknownCSME.size(); ++i)
    {
      output.write((const char*) &unknownCSME[i], 4);
    }//for
  }//if CSME

  if (cscrLen!=crl0Bytes)
  {
    //write CSCR
    output.write((const char*) &cCSCR, 4);
    //CSCR's length
    if (cscrLen==crl16Bytes)
    {
      subLength = 16; //fixed
    }
    else
    {
      subLength = 8; //fixed
    }
    output.write((const char*) &subLength, 2);
    //write CSCR's stuff
    output.write((const char*) &circleMult, 4);
    output.write((const char*) &fallbackMult, 4);
    if (cscrLen==crl16Bytes)
    {
      output.write((const char*) &flankDistance, 4);
      output.write((const char*) &stalkTime, 4);
    }
  }//if CSCR present

  if (hasCSLR)
  {
    //write CSLR
    output.write((const char*) &cCSLR, 4);
    //CSLR's length
    subLength = 4; //fixed
    output.write((const char*) &subLength, 2);
    //write CSLR's stuff
    output.write((const char*) &longRangeStrafeMult, 4);
  }//if has CSLR

  if (!unknownCSFL.empty())
  {
    //write CSFL
    output.write((const char*) &cCSFL, 4);
    //CSFL's length
    subLength = 4*unknownCSFL.size();
    output.write((const char*) &subLength, 2);
    //write CSFL's stuff
    for (i=0; i<unknownCSFL.size(); ++i)
    {
      output.write((const char*) &unknownCSFL[i], 4);
    }//for
  }//if has CSFL

  if (hasDATA)
  {
    //write DATA
    output.write((const char*) &cDATA, 4);
    //DATA's length
    subLength = 4; //fixed
    output.write((const char*) &subLength, 2);
    //write DATA's stuff
    output.write((const char*) &unknownDATA, 4);
  }//if has DATA

  return output.good();
}
bool LandscapeRecord::saveToStream(std::ofstream& output) const
{
  output.write((const char*) &cLAND, 4);
  uint32_t Size;
  Size = 4 /* INTV */ +4 /* 4 bytes for length */ +8 /* size of INTV */
        +4 /* DATA */ +4 /* 4 bytes for length */ +4 /* size of DATA */;
  if (hasHeightSubrecord)
  {
    Size = Size +4 /* VHGT */ +4 /* 4 bytes for length */ +4232 /* size of VHGT */;
  }
  if (hasWNAMSubrecord)
  {
    Size = Size +4 /* WNAM */ +4 /* 4 bytes for length */ +81 /* size of WNAM */;
  }
  if (hasNormals)
  {
    Size = Size + 4 /* VNML */ +4 /* 4 bytes for length */ +12675 /* size of VNML */;
  }

  if (hasVertexColour)
  {
    Size = Size + 4 /* VCLR */ +4 /* 4 bytes for length */ +12675 /* size of VCLR */;
  }
  if (hasVertexTextures)
  {
    Size = Size + 4 /* VTEX */ +4 /* 4 bytes for length */ +512 /* size of VTEX */;
  }
  output.write((const char*) &Size, 4);
  output.write((const char*) &HeaderOne, 4);
  output.write((const char*) &HeaderFlags, 4);
  /*Landscape:
    INTV (8 bytes)
        long CellX }
        long CellY } The cell coordinates of the cell.
    DATA (4 bytes)
        long Unknown (default of 0x09)
    VNML (12675 bytes)
        struct {
          signed byte X
          signed byte Y
          signed byte Z
        } normals[65][65];
            A RGB color map 65x65 pixels in size representing the land normal vectors.
            The signed value of the 'color' represents the vector's component. Blue
            is vertical (Z), Red the X direction and Green the Y direction. Note that
            the y-direction of the data is from the bottom up.
    VHGT (4232 bytes)
        float HeightOffset
            A height offset for the entire cell. Decreasing this value will shift the
            entire cell land down.
        byte Unknown1 (0x00)
        signed byte  HeightData[65][65]
            Contains the height data for the cell in the form of a 65x65 pixel array. The
            height data is not absolute values but uses differences between adjacent pixels.
            Thus a pixel value of 0 means it has the same height as the last pixel. Note that
            the y-direction of the data is from the bottom up.
        short Unknown2 (0x0000)
    WNAM (81 bytes)
        byte Data[9][9] (Unknown byte data.)
    VCLR (12675 bytes) optional
        Vertex color array, looks like another RBG image 65x65 pixels in size.
    VTEX (512 bytes) optional
        A 16x16 array of short texture indices (from a LTEX record I think). */

  //write INTV
  output.write((const char*) &cINTV, 4);
  uint32_t SubLength = 8; /* fixed size is eight bytes*/
  //write INTV's length
  output.write((const char*) &SubLength, 4);
  //write cell offsets
  output.write((const char*) &CellX, 4);
  output.write((const char*) &CellY, 4);

  //write DATA
  output.write((const char*) &cDATA, 4);
  SubLength = 4; //always four bytes
  //write DATA's length
  output.write((const char*) &SubLength, 4);
  //write unknown data
  output.write((const char*) &UnknownData, 4);

  if (hasNormals)
  {
    //write VNML
    output.write((const char*) &cVNML, 4);
    SubLength = 12675; //always 12675 bytes
    //write VNML's length
    output.write((const char*) &SubLength, 4);
    //write normals
    output.write((const char*) &(Normals[0][0][0]), 65*65*3);
  }

  if (hasHeightSubrecord)
  {
    //write VHGT
    output.write((const char*) &cVHGT, 4);
    SubLength = 4232; //always 4232 bytes
    //write VHGT's length
    output.write((const char*) &SubLength, 4);
    //write height data
    // --- offset
    output.write((const char*) &HeightOffset, 4);
    // --- unknown byte
    output.write((const char*) &UnknownByte, 1);
    // --- the actual height data
    output.write((const char*) &(HeightData[0][0]), 65*65);
    // --- unknown short
    output.write((const char*) &UnknownShort, 2);
  }

  if (hasWNAMSubrecord)
  {
    //write WNAM
    output.write((const char*) &cWNAM, 4);
    SubLength = 81; //always 81 bytes
    //write WNAM's length
    output.write((const char*) &SubLength, 4);
    //write WNAM
    output.write(Data, 81);
  }

  if (hasVertexColour)
  {
    //write VCLR
    output.write((const char*) &cVCLR, 4);
    SubLength = 12675; //always 12675 bytes
    //write VNML's length
    output.write((const char*) &SubLength, 4);
    //write vertex colour
    output.write((const char*) &(VertexColour[0][0][0]), 65*65*3);
  }

  if (hasVertexTextures)
  {
    //write VTEX
    output.write((const char*) &cVTEX, 4);
    SubLength = 512; //always 512 bytes
    //write VTEX's length
    output.write((const char*) &SubLength, 4);
    //write vertex textures
    output.write((const char*) &(VertexTextures[0][0]), 16*16*2);
  }

  return output.good();
}
Exemple #28
0
		inline bool is_good() { return mFile.good(); }
bool AlchemyPotionRecord::saveToStream(std::ofstream& output) const
{
  output.write((const char*) &cALCH, 4);
  if (!saveSizeAndUnknownValues(output, getWriteSize())) return false;
  if (isDeleted()) return true;

  //write EDID
  output.write((const char*) &cEDID, 4);
  //EDID's length
  uint16_t subLength = editorID.length()+1;
  output.write((const char*) &subLength, 2);
  //write editor ID
  output.write(editorID.c_str(), subLength);

  //write OBND
  output.write((const char*) &cOBND, 4);
  //OBND's length
  subLength = 12; //fixed
  output.write((const char*) &subLength, 2);
  //write OBND
  output.write((const char*) unknownOBND, 12);

  if (name.isPresent())
  {
    //write FULL
    if (!name.saveToStream(output, cFULL))
      return false;
  }//if has FULL

  uint32_t i;
  if (!keywordArray.empty())
  {
    //write KSIZ
    output.write((const char*) &cKSIZ, 4);
    //KSIZ's length
    subLength = 4; //fixed
    output.write((const char*) &subLength, 2);
    //write KSIZ's data
    const uint32_t k_Size = keywordArray.size();
    output.write((const char*) &k_Size, 4);

    //write KWDA
    output.write((const char*) &cKWDA, 4);
    //KWDA's length
    subLength = 4*k_Size; //fixed
    output.write((const char*) &subLength, 2);
    //write KWDA's data
    for (i=0; i<k_Size; ++i)
    {
      output.write((const char*) &(keywordArray.at(i)), 4);
    }//for
  }//if keyword array

  //write MODL
  output.write((const char*) &cMODL, 4);
  //MODL's length
  subLength = modelPath.length()+1;
  output.write((const char*) &subLength, 2);
  //write model path
  output.write(modelPath.c_str(), subLength);

  if (unknownMODT.isPresent())
  {
    //write MODT
    if (!unknownMODT.saveToStream(output, cMODT))
    {
      std::cout << "Error while writing MODT of ALCH!";
      return false;
    }
  }//if MODT

  if (unknownMODS.isPresent())
  {
    //write MODS
    if (!unknownMODS.saveToStream(output, cMODS))
    {
      std::cout << "Error while writing MODS of ALCH!";
      return false;
    }
  }//if MODS

  if (pickupSoundFormID!=0)
  {
    //write YNAM
    output.write((const char*) &cYNAM, 4);
    //YNAM's length
    subLength = 4; //fixed
    output.write((const char*) &subLength, 2);
    //write pickup sound form ID
    output.write((const char*) &pickupSoundFormID, 4);
  }//if has YNAM

  if (putdownSoundFormID!=0)
  {
    //write ZNAM
    output.write((const char*) &cZNAM, 4);
    //ZNAM's length
    subLength = 4; //fixed
    output.write((const char*) &subLength, 2);
    //write putdown sound form ID
    output.write((const char*) &putdownSoundFormID, 4);
  }//if has ZNAM

  if (equipTypeFormID!=0)
  {
    //write ETYP
    output.write((const char*) &cETYP, 4);
    //ETYP's length
    subLength = 4; //fixed
    output.write((const char*) &subLength, 2);
    //write equip type form ID
    output.write((const char*) &equipTypeFormID, 4);
  }//if has ETYP

  //write DATA
  output.write((const char*) &cDATA, 4);
  //DATA's length
  subLength = 4; //fixed
  output.write((const char*) &subLength, 2);
  //write DATA
  output.write((const char*) &weight, 4);

  //write ENIT
  output.write((const char*) &cENIT, 4);
  //ENIT's length
  subLength = 20; //fixed
  output.write((const char*) &subLength, 2);
  //write ENIT
  output.write((const char*) &value, 4);
  output.write((const char*) &flags, 4);
  output.write((const char*) &unknownThirdENIT, 4);
  output.write((const char*) &addictionChance, 4);
  output.write((const char*) &useSoundFormID, 4);

  for (i=0; i<effects.size(); ++i)
  {
    if (!effects[i].saveToStream(output))
    {
      std::cout << "Error while writing effect blocks of ALCH!\n";
      return false;
    }
  }//for

  return  output.good();
}
bool SGFACESET::WriteCache( std::ofstream& aFile, SGNODE* parentNode )
{
    if( NULL == parentNode )
    {
        if( NULL == m_Parent )
        {
            #ifdef DEBUG
            std::ostringstream ostr;
            ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
            ostr << " * [BUG] corrupt data; m_aParent is NULL";
            wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
            #endif

            return false;
        }

        SGNODE* np = m_Parent;

        while( NULL != np->GetParent() )
            np = np->GetParent();

        if( np->WriteCache( aFile, NULL ) )
        {
            m_written = true;
            return true;
        }

        return false;
    }

    if( parentNode != m_Parent )
    {
        #ifdef DEBUG
        std::ostringstream ostr;
        ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
        ostr << " * [BUG] corrupt data; parentNode != m_aParent";
        wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
        #endif

        return false;
    }

    if( !aFile.good() )
    {
        #ifdef DEBUG
        std::ostringstream ostr;
        ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
        ostr << " * [INFO] bad stream";
        wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
        #endif

        return false;
    }

    // check if any references are unwritten and swap parents if so
    if( NULL != m_RCoords && !m_RCoords->isWritten() )
        m_RCoords->SwapParent( this );

    if( NULL != m_RNormals && !m_RNormals->isWritten() )
        m_RNormals->SwapParent( this );

    if( NULL != m_RColors && !m_RColors->isWritten() )
        m_RColors->SwapParent( this );

    aFile << "[" << GetName() << "]";
    #define NITEMS 7
    bool items[NITEMS];
    int i;

    for( i = 0; i < NITEMS; ++i )
        items[i] = 0;

    i = 0;
    if( NULL != m_Coords )
        items[i] = true;

    ++i;
    if( NULL != m_RCoords )
        items[i] = true;

    ++i;
    if( NULL != m_CoordIndices )
        items[i] = true;

    ++i;
    if( NULL != m_Normals )
        items[i] = true;

    ++i;
    if( NULL != m_RNormals )
        items[i] = true;

    ++i;
    if( NULL != m_Colors )
        items[i] = true;

    ++i;
    if( NULL != m_RColors )
        items[i] = true;

    for( int i = 0; i < NITEMS; ++i )
        aFile.write( (char*)&items[i], sizeof(bool) );

    if( items[0] )
        m_Coords->WriteCache( aFile, this );

    if( items[1] )
        aFile << "[" << m_RCoords->GetName() << "]";

    if( items[2] )
        m_CoordIndices->WriteCache( aFile, this );

    if( items[3] )
        m_Normals->WriteCache( aFile, this );

    if( items[4] )
        aFile << "[" << m_RNormals->GetName() << "]";

    if( items[5] )
        m_Colors->WriteCache( aFile, this );

    if( items[6] )
        aFile << "[" << m_RColors->GetName() << "]";

    if( aFile.fail() )
        return false;

    m_written = true;
    return true;
}