Esempio n. 1
0
char* Packet_write(const struct Packet* p, char* buffer, int ascii) {
    //Binary mode
    char* buffPtr;
    if (!ascii) {
        buffer = writeUint8(packet_decoder_binary_header_1, buffer);
        buffer = writeUint8(packet_decoder_binary_header_2, buffer);
    }
    if (p->id == Dummy_Payload_ID) {
        buffPtr = buffer;
        buffer = Dummy_Payload_write(p, buffer, ascii);
    } else if (p->id == Dumb_Payload_ID) {
        buffPtr = buffer;
        buffer = Dumb_Payload_write(p, buffer, ascii);
    } else if (p->id == State_Payload_ID) {
        buffPtr = buffer;
        buffer = State_Payload_write(p, buffer, ascii);
    } else if (p->id == Speed_Payload_ID) {
        buffPtr = buffer;
        buffer = Speed_Payload_write(p, buffer, ascii);
    } else if (p->id == Init_Payload_ID) {
        buffPtr = buffer;
        buffer = Init_Payload_write(p, buffer, ascii);
    }else if (p->id == Heartbeat_Payload_ID) {
        buffPtr = buffer;
        buffer = Heartbeat_Payload_write(p, buffer, ascii);
    }
    //Binary mode, has to compute the checksum
    if (!ascii) {
        uint8_t checksum = Payload_computeChecksum(buffer, buffer - buffPtr);
        buffer = writeUint8(checksum, buffer);
    }
    return buffer;
}
Esempio n. 2
0
 //--------------------------------------------------------------
 void
 DataStream::writeByte(u8 byte, int repeat)
 {
     for (int i = 0; i < repeat; i++)
     {
         writeUint8(byte);
     }
 }
Esempio n. 3
0
//SlimStatePacket
//==============================================================================
//Write
//==============================================================================
char* writeSlimStatePacket(const struct Packet* p, char* buffer, int ascii) {
  //BinaryMode
  if (!ascii) {
    uint8_t lenght = 9;
    //PACKET LENGTH
    buffer = writeUint8(lenght, buffer);
    //PACKET ID
    buffer = writeUint8(SlimStatePacketID, buffer);
    buffer = writeUint32(p->seq, buffer);
    buffer = writeUint16(p->slimState.leftEncoder, buffer);
    buffer = writeUint16(p->slimState.rightEncoder, buffer);
  }//Ascii mode
    else {
        buffer = writeHeaderAscii(buffer);
        buffer = writeUint8Ascii(SlimStatePacketID, buffer);
        buffer = writeUint32Ascii(p->seq, buffer);
        buffer = writeUint16Ascii(p->slimState.leftEncoder, buffer);
        buffer = writeUint16Ascii(p->slimState.rightEncoder, buffer);
        buffer = writeFooterAscii(buffer);
    }
    return buffer;
}
Esempio n. 4
0
void writeString(const char* value, int len, FILE* out) {
	UTF16* utf16String = new UTF16[len];
	const UTF8* sourceStart = (UTF8*) value;
	UTF8* sourceEnd = (UTF8*) value + len;
	UTF16* targetStart = utf16String;
	UTF16* targetEnd = utf16String + len;
	if (ConvertUTF8toUTF16(&sourceStart, sourceEnd, &targetStart, targetEnd, lenientConversion) != conversionOK) {
		fprintf(stderr, "Unable to interpret argument as UTF8 text\n");
		throw ErrBadUTF8;
	}
	uint32_t datalen = (intptr_t) ((uint8_t*)targetStart - (uint8_t*)utf16String);
	writeUint8(datalen, out);
	for (UTF16* ptr = utf16String; ptr < targetStart; ptr++)
		writeUint16(*ptr, out);
	delete [] utf16String;
}
Esempio n. 5
0
void writePercentLength(const char* value, FILE* out) {
	bool percent = strstr(value, "%") != NULL;
	writeUint8(percent ? 1 : 0, out);
	writeFixed(value, out);
}
Esempio n. 6
0
void Settings::save(std::string const& path)
{
	FILE* opt = fopen(path.c_str(), "wb");
	
	writeUint8(opt, maxBonuses);
	writeUint16(opt, loadingTime);
	writeUint16(opt, lives);
	writeUint16(opt, timeToLose);
	writeUint16(opt, flagsToWin);
	
	writeUint8(opt, screenSync);
	writeUint8(opt, map);
	writeUint8(opt, wormSettings[0].controller);
	writeUint8(opt, wormSettings[1].controller);
	writeUint8(opt, randomLevel);
	writeUint16(opt, blood);
	writeUint8(opt, gameMode);
	writeUint8(opt, namesOnBonuses);
	writeUint8(opt, regenerateLevel);
	writeUint8(opt, shadow);
	
	fwrite(weapTable, 1, 40, opt);
	
	for(int i = 0; i < 2; ++i)
	for(int j = 0; j < 3; ++j)
		writeUint8(opt, wormSettings[i].rgb[j]);
		
	for(int i = 0; i < 2; ++i)
	{
		for(int j = 0; j < 5; ++j)
		{
			writeUint8(opt, wormSettings[i].weapons[j]);
		}
	}

	writeUint16(opt, wormSettings[0].health);
	writeUint16(opt, wormSettings[1].health);

	for(int i = 0; i < 2; ++i)
	{
		if(wormSettings[i].randomName)
			writePascalString(opt, "", 21);
		else
			writePascalString(opt, wormSettings[i].name, 21);
	}
	
	//fputc(0, opt); // What's this?
	
	writeUint8(opt, loadChange);
	
	char const lieroStr[] = "\x05LIERO\0\0";
	
	fwrite(lieroStr, 1, sizeof(lieroStr), opt);
	
	//fseek(opt, 0x84, SEEK_SET);
	for(int i = 0; i < 2; ++i)
	{
		for(int j = 0; j < 7; ++j)
		{
			writeUint8(opt, wormSettings[i].controls[j]);
		}
	}
	
	writePascalString(opt, levelFile, 9);
	
	fclose(opt);
}