bool FDataTableImporterJSON::ReadRow(const TSharedRef<FJsonObject>& InParsedTableRowObject, const int32 InRowIdx)
{
	// Get row name
	FName RowName = DataTableUtils::MakeValidName(InParsedTableRowObject->GetStringField(TEXT("Name")));

	// Check its not 'none'
	if (RowName.IsNone())
	{
		ImportProblems.Add(FString::Printf(TEXT("Row '%d' missing a name."), InRowIdx));
		return false;
	}

	// Check its not a duplicate
	if (DataTable->RowMap.Find(RowName) != nullptr)
	{
		ImportProblems.Add(FString::Printf(TEXT("Duplicate row name '%s'."), *RowName.ToString()));
		return false;
	}

	// Allocate data to store information, using UScriptStruct to know its size
	uint8* RowData = (uint8*)FMemory::Malloc(DataTable->RowStruct->PropertiesSize);
	DataTable->RowStruct->InitializeStruct(RowData);
	// And be sure to call DestroyScriptStruct later

	if (auto UDStruct = Cast<const UUserDefinedStruct>(DataTable->RowStruct))
	{
		UDStruct->InitializeDefaultValue(RowData);
	}

	// Add to row map
	DataTable->RowMap.Add(RowName, RowData);

	return ReadStruct(InParsedTableRowObject, DataTable->RowStruct, RowName, RowData);
}
Beispiel #2
0
/**************************************************> main <*/
int main (int argc, const char * argv[])
{
	char			command;
	
	gHeadPtr = NULL;
	gTailPtr = NULL;
	
	ReadFile();
	
	while ( (command = GetCommand() ) != 'q' ) {
		switch( command ) {
			case 'n':
				AddToList( ReadStruct() );
				break;
			case 'l':
				ListDVDs();
				break;
		}
	}
	
	WriteFile();
	
	printf( "Goodbye..." );
	
	return 0;
}
Beispiel #3
0
__regargs BOOL OpenIff(IffFileT *iff, const char *filename) {
  iff->fh = Open(filename, MODE_OLDFILE);

  if (ReadStruct(iff->fh, &iff->header) &&
      (iff->header.magic == ID_FORM))
    return 1;

  Close(iff->fh);
  return 0;
}
CapturePlayback::CapturePlayback(PXCSession *session, PXCScheduler *sch,HANDLE file):UtilCaptureImpl(session,sch) {
    this->file=file;
	SetFilePointer(file,0,0,FILE_BEGIN);
	pxcU32 header[32]={0};
	DWORD nbytesRead=0;
	ReadFile(file,&header,sizeof(header),&nbytesRead,0);
	if (nbytesRead>=sizeof(header) && header[0]==PXC_UID('P','X','C','F') && header[27]==PXCCapture::CUID) {
		int sdinfo=header[28];
		PXCCapture::DeviceInfo dinfo;
		ReadStruct(&dinfo,sizeof(dinfo),sdinfo,file);
		dinfo.didx=0;
		devices.push_back(dinfo);
	}
}
Beispiel #5
0
int main (int argc, const char * argv[])
{
	char command;
    
	while ( (command = GetCommand() ) != 'q' ) {
		switch( command ) {
			case 'n':
				AddToList( ReadStruct() );
				break;
			case 'l':
			case 'r':
				ListDVDs( command=='l' );
				break;
		}
        printf( "\n----------\n" );
	}
	
	printf( "Goodbye...\n" );
	
	return 0;
}
Beispiel #6
0
__regargs BOOL ParseChunk(IffFileT *iff) {
  return ReadStruct(iff->fh, &iff->chunk);
}
Beispiel #7
0
//=================================================================================================
void PickServerPanel::Update(float dt)
{
	// update gui
	for(int i=0; i<2; ++i)
	{
		bts[i].mouse_focus = focus;
		bts[i].Update(dt);
	}

	grid.focus = focus;
	grid.Update(dt);

	if(!focus)
		return;

	if(Key.Focus() && Key.PressedRelease(VK_ESCAPE))
	{
		Event((GuiEvent)(GuiEvent_Custom+BUTTON_CANCEL));
		return;
	}

	// ping servers
	ping_timer -= dt;
	if(ping_timer < 0.f)
	{
		ping_timer = 1.f;
		game->peer->Ping("255.255.255.255", (word)game->mp_port, true);
	}

	// listen for packets
	RakNet::Packet* packet;
	for(packet=game->peer->Receive(); packet; game->peer->DeallocatePacket(packet), packet=game->peer->Receive())
	{
		switch(packet->data[0])
		{
		case ID_UNCONNECTED_PONG:
			{
				BitStream s(packet->data+5, packet->length-5, false);
				char sign[2];
				if(!ReadStruct(s, sign))
				{
					WARN(Format("Unknown response from %s: %s.", packet->systemAddress.ToString(), PacketToString(packet)));
					break;
				}

				if(sign[0] != 'C' || sign[1] != 'A')
				{
					WARN(Format("Unknown response from %s, it's not CaRpg server: %s.", packet->systemAddress.ToString(), PacketToString(packet)));
					break;
				}

				uint wersja, build;
				byte gracze, gracze_max, flagi;
				string nazwa;

				if(	!s.Read(wersja) ||
					!s.Read(gracze) ||
					!s.Read(gracze_max) ||
					!s.Read(flagi) ||
					!ReadString1(s, nazwa))
				{
					WARN(Format("Broken response from %s: %s.", packet->systemAddress.ToString(), PacketToString(packet)));
					break;
				}

				if(!s.Read(build))
					build = 0;

				bool valid_version = (wersja == WERSJA && build == g_build);

				// szukaj serwera w bazie
				bool jest = false;
				int index = 0;
				for(vector<ServerData>::iterator it = servers.begin(), end = servers.end(); it != end; ++it, ++index)
				{
					if(it->adr == packet->systemAddress)
					{
						jest = true;
						// aktualizuj
						it->name = nazwa;
						it->players = gracze;
						it->max_players = gracze_max;
						it->flags = flagi;
						it->timer = 0.f;
						it->valid_version = valid_version;

						if(game->pick_autojoin && it->players != it->max_players && it->valid_version)
						{
							bts[0].state = Button::NONE;
							game->pick_autojoin = false;
							grid.selected = index;
							Event(GuiEvent(GuiEvent_Custom+BUTTON_OK));
						}

						break;
					}
				}

				if(!jest)
				{
					// nie ma, dodaj
					ServerData& sd = Add1(servers);
					sd.name = nazwa;
					sd.players = gracze;
					sd.max_players = gracze_max;
					sd.adr = packet->systemAddress;
					sd.flags = flagi;
					sd.timer = 0.f;
					sd.valid_version = valid_version;
					grid.AddItem();

					if(game->pick_autojoin && sd.players != sd.max_players && sd.valid_version)
					{
						bts[0].state = Button::NONE;
						game->pick_autojoin = false;
						grid.selected = servers.size()-1;
						Event(GuiEvent(GuiEvent_Custom+BUTTON_OK));
					}
				}
			}
			break;
		default:
			LOG(Format(txUnknownPacket, packet->data[0], packet->systemAddress.ToString(), PacketToString(packet)));
			break;
		}
	}

	// update servers
	int index = 0;
	for(vector<ServerData>::iterator it = servers.begin(), end = servers.end(); it != end;)
	{
		it->timer += dt;
		if(it->timer >= 2.f)
		{
			grid.RemoveItem(index);
			it = servers.erase(it);
			end = servers.end();
		}
		else
		{
			++it;
			++index;
		}
	}

	if(grid.selected == -1 || !servers[grid.selected].valid_version)
		bts[0].state = Button::DISABLED;
	else if(bts[0].state == Button::DISABLED)
		bts[0].state = Button::NONE;
}
bool FDataTableImporterJSON::ReadArrayEntry(const TSharedRef<FJsonValue>& InParsedPropertyValue, const FName InRowName, const FString& InColumnName, const int32 InArrayEntryIndex, UProperty* InProperty, void* InPropertyData)
{
	const TCHAR* const ParsedPropertyType = JSONTypeToString(InParsedPropertyValue->Type);

	if (UNumericProperty *NumProp = Cast<UNumericProperty>(InProperty))
	{
		FString EnumValue;
		if (NumProp->IsEnum() && InParsedPropertyValue->TryGetString(EnumValue))
		{
			FString Error = DataTableUtils::AssignStringToProperty(EnumValue, InProperty, (uint8*)InPropertyData);
			if (!Error.IsEmpty())
			{
				ImportProblems.Add(FString::Printf(TEXT("Entry %d on property '%s' on row '%s' has invalid enum value: %s."), InArrayEntryIndex, *InColumnName, *InRowName.ToString(), *EnumValue));
				return false;
			}
		}
		else if(NumProp->IsInteger())
		{
			int64 PropertyValue = 0;
			if (!InParsedPropertyValue->TryGetNumber(PropertyValue))
			{
				ImportProblems.Add(FString::Printf(TEXT("Entry %d on property '%s' on row '%s' is the incorrect type. Expected Integer, got %s."), InArrayEntryIndex, *InColumnName, *InRowName.ToString(), ParsedPropertyType));
				return false;
			}

			NumProp->SetIntPropertyValue(InPropertyData, PropertyValue);
		}
		else
		{
			double PropertyValue = 0.0;
			if (!InParsedPropertyValue->TryGetNumber(PropertyValue))
			{
				ImportProblems.Add(FString::Printf(TEXT("Entry %d on property '%s' on row '%s' is the incorrect type. Expected Double, got %s."), InArrayEntryIndex, *InColumnName, *InRowName.ToString(), ParsedPropertyType));
				return false;
			}

			NumProp->SetFloatingPointPropertyValue(InPropertyData, PropertyValue);
		}
	}
	else if (UBoolProperty* BoolProp = Cast<UBoolProperty>(InProperty))
	{
		bool PropertyValue = false;
		if (!InParsedPropertyValue->TryGetBool(PropertyValue))
		{
			ImportProblems.Add(FString::Printf(TEXT("Entry %d on property '%s' on row '%s' is the incorrect type. Expected Boolean, got %s."), InArrayEntryIndex, *InColumnName, *InRowName.ToString(), ParsedPropertyType));
			return false;
		}

		BoolProp->SetPropertyValue(InPropertyData, PropertyValue);
	}
	else if (UArrayProperty* ArrayProp = Cast<UArrayProperty>(InProperty))
	{
		// Cannot nest arrays
		return false;
	}
	else if (UStructProperty* StructProp = Cast<UStructProperty>(InProperty))
	{
		const TSharedPtr<FJsonObject>* PropertyValue = nullptr;
		if (InParsedPropertyValue->TryGetObject(PropertyValue))
		{
			return ReadStruct(PropertyValue->ToSharedRef(), StructProp->Struct, InRowName, InPropertyData);
		}
		else
		{
			// If the JSON does not contain a JSON object for this struct, we try to use the backwards-compatible string deserialization, same as the "else" block below
			FString PropertyValueString;
			if (!InParsedPropertyValue->TryGetString(PropertyValueString))
			{
				ImportProblems.Add(FString::Printf(TEXT("Property '%s' on row '%s' is the incorrect type. Expected String, got %s."), *InColumnName, *InRowName.ToString(), ParsedPropertyType));
				return false;
			}

			const FString Error = DataTableUtils::AssignStringToSingleProperty(PropertyValueString, InProperty, (uint8*)InPropertyData);
			if (Error.Len() > 0)
			{
				ImportProblems.Add(FString::Printf(TEXT("Problem assigning string '%s' to entry %d on property '%s' on row '%s' : %s"), InArrayEntryIndex, *PropertyValueString, *InColumnName, *InRowName.ToString(), *Error));
				return false;
			}

			return true;
		}
	}
	else
	{
		FString PropertyValue;
		if (!InParsedPropertyValue->TryGetString(PropertyValue))
		{
			ImportProblems.Add(FString::Printf(TEXT("Entry %d on property '%s' on row '%s' is the incorrect type. Expected String, got %s."), InArrayEntryIndex, *InColumnName, *InRowName.ToString(), ParsedPropertyType));
			return false;
		}

		const FString Error = DataTableUtils::AssignStringToSingleProperty(PropertyValue, InProperty, (uint8*)InPropertyData);
		if(Error.Len() > 0)
		{
			ImportProblems.Add(FString::Printf(TEXT("Problem assigning string '%s' to entry %d on property '%s' on row '%s' : %s"), InArrayEntryIndex, *PropertyValue, *InColumnName, *InRowName.ToString(), *Error));
			return false;
		}
	}

	return true;
}
CapturePlayback::DevicePlayback::DevicePlayback(CapturePlayback *capture, int didx, HANDLE file):DeviceImpl(capture,didx) {
    this->file=file;
    this->realtime=1;
    this->pause=0;

    SetFilePointer(file,0,0,FILE_BEGIN);
    pxcU32 header[32];
	DWORD nbytesRead;
	ReadFile(file,header,sizeof(header),&nbytesRead,0);
    int sdinfo=header[28];
    int ssinfo=header[29];
    int svpinfo=header[30];
    int sapinfo=header[31];

    PXCCapture::DeviceInfo dinfo;
    ReadStruct(&dinfo,sizeof(dinfo),sdinfo,file);

    int i, nproperties=0;
	ReadFile(file,&nproperties,sizeof(nproperties),&nbytesRead,0);
    for (i=0;i<nproperties;i++) {
        Property pty; pxcF32 value;
		ReadFile(file,&pty,sizeof(pty),&nbytesRead,0);
		ReadFile(file,&value,sizeof(value),&nbytesRead,0);
        properties[pty]=value;
    }

    int nvstreams=0;
	ReadFile(file,&nvstreams,sizeof(nvstreams),&nbytesRead,0);
    for (i=0;i<nvstreams;i++) {
        PXCCapture::Device::StreamInfo sinfo;
        ReadStruct(&sinfo,sizeof(sinfo),ssinfo,file);
        smap[sinfo.sidx]=i;
        sinfo.sidx=i;
        streams.push_back(sinfo);
        PXCCapture::VideoStream::ProfileInfo pinfo;
        ReadStruct(&pinfo,sizeof(pinfo),svpinfo,file);
        vprofiles.push_back(pinfo);
    }

    int nastreams=0;
	ReadFile(file,&nastreams,sizeof(nastreams),&nbytesRead,0);
    for (int j=0;j<nastreams;j++,i++) {
        PXCCapture::Device::StreamInfo sinfo;
        ReadStruct(&sinfo,sizeof(sinfo),ssinfo,file);
        smap[sinfo.sidx]=i;
        sinfo.sidx=i;
        streams.push_back(sinfo);
        PXCCapture::AudioStream::ProfileInfo pinfo;
        ReadStruct(&pinfo,sizeof(pinfo),sapinfo,file);
        aprofiles.push_back(pinfo);
    }

    if (header[26]>0) {
        int nserializables=0;
        ReadFile(file,&nserializables,sizeof(nserializables),&nbytesRead,0);
        if (nserializables>0) {
            int dataSize=0;
            ReadFile(file,&dataSize,sizeof(dataSize),&nbytesRead,0);
            pxcBYTE *dataBuffer=new pxcBYTE[dataSize];
            if (dataBuffer) {
                ReadFile(file,dataBuffer,dataSize,&nbytesRead,0);
                PXCMetadata *md=capture->session->DynamicCast<PXCMetadata>();
                pxcUID uid=md->QueryUID();
                if (uid) {
                    md->AttachBuffer(uid,dataBuffer,dataSize);
                    properties[PROPERTY_PROJECTION_SERIALIZABLE]= *(pxcF32*)&uid;
                }
                delete [] dataBuffer;
            }
        }
    }

    lastframeposition=0;
	LARGE_INTEGER tmp;
	tmp.QuadPart=0;
	SetFilePointerEx(file,tmp,&tmp,FILE_CURRENT);
    firstframeposition=(pxcU64)header[26]>(pxcU64)tmp.QuadPart?(pxcU64)header[26]:(pxcU64)tmp.QuadPart;
    SetFilePointer(file,(LONG)firstframeposition,0,FILE_BEGIN);
    this->currentframe=0;
    this->skipframes=0;
}
Beispiel #10
0
// ReadLines
//------------------------------------------------------------------------------
bool TextReader::ReadLines()
{
    for ( ;; )
    {
        // Skip Leading
        AStackString<> token;
        if ( !GetToken( token ) )
        {
            return true;
        }

        // object?
        if ( token == "object" )
        {
            if ( !ReadObject() )
            {
                return false;
            }
            continue;
        }

        // struct?
        if ( token == "struct" )
        {
            if ( !ReadStruct() )
            {
                return false;
            }
            continue;
        }

        // ref?
        if ( token == "ref" )
        {
            if ( !ReadRef() )
            {
                return false;
            }
            continue;
        }

        // children?
        if ( token == "children" )
        {
            if ( !ReadChildren() )
            {
                return false;
            }
            continue;
        }

        // begin object properties?
        if ( token == "{" )
        {
            continue;
        }

        // end object/struct properties?
        if ( token == "}" )
        {
            m_DeserializationStack.Pop();
            continue;
        }

        // assume property
        PropertyType pt;
        pt = GetPropertyTypeFromString( token );
        if ( pt != PT_NONE )
        {
            if ( !ReadProperty( pt ) )
            {
                return false;
            }
            continue;
        }

        if ( token == "weakRef" )
        {
            if ( !ReadWeakRef() )
            {
                return false;
            }
            continue;
        }

        if ( token == "array<" )
        {
            if ( !ReadArray() )
            {
                return false;
            }
            continue;
        }

        if ( token == "arrayOfStruct<" )
        {
            if ( !ReadArrayOfStruct() )
            {
                return false;
            }
            continue;
        }

        Error( "Unkown token" );
        return false;
    }
}
Beispiel #11
0
int main (int argc, char ** argv)
{
    struct MainLevel demo =
    {
	(BYTE)0x88,       0xFF,
	(WORD)0x8844,     0xFF77,
	(LONG)0x88442211, 0xFF773311,
	1.5, 1.75,
	"Hallo",
	{ (BYTE)0x88, (LONG)0x88442211 },
	/* ... */
    };
    BYTE b = (BYTE)0x88;
    WORD w = (WORD)0x8844;
    LONG l = (LONG)0x88442211;
    FLOAT f = 1.5;
    DOUBLE d = 1.75;
    STRPTR s = "Hallo";
    struct Level1 l1 =
    {
	(BYTE)0x88, (LONG)0x88442211
    };
    BPTR fh;
    struct MainLevel * readback;

    demo.ml_BytePtr = &b;
    demo.ml_WordPtr = &w;
    demo.ml_LongPtr = &l;
    demo.ml_FloatPtr = &f;
    demo.ml_DoublePtr = &d;
    demo.ml_StringPtr = &s;
    demo.ml_Level1Ptr = &l1;

    fh = Open ("writestruct.dat", MODE_NEWFILE);

    if (!fh)
    {
	PrintFault (IoErr(), "Can't open file\n");
	return 10;
    }

    /*
	This writes the following data stream:

	    0000 88			    ml_Byte
	    0001 ff			    ml_Ubyte
	    0002 88 44			    ml_Word
	    0004 ff 77			    ml_UWord
	    0006 88 44 22 11		    ml_Long
	    000a ff 77 33 11		    ml_ULong
	    000e 3f c0 00 00		    ml_Float
	    0012 3f fc 00 00 00 00 00 00    ml_Double
	    001a 01:48 61 6c 6c 6f 00	    ml_String
	    0021 88			    ml_Level1.l1_Byte
	    0022 88 44 22 11		    ml_Level1.l1_Long
	    0026 01:88			    ml_BytePtr
	    0028 01:88 44		    ml_WordPtr
	    002b 01:88 44 22 11 	    ml_LongPtr
	    0030 01:3f c0 00 00 	    ml_FloatPtr
	    0035 01:3f fc 00 00 00 00 00 00 ml_DoublePtr
	    003e 01:01:48 61 6c 6c 6f 00    ml_StringPtr - Note two 01 !
	    0046 01:88 88 44 22 11	    ml_Level1Ptr
    */

    if (!WriteStruct (&dsh, &demo, fh, MainDesc))
    {
	PrintFault (IoErr(), "Failed to write to file\n");
    }

    if (!Close (fh))
    {
	PrintFault (IoErr(), "Failed to close file\n");
    }

    /* Read the structure back */
    fh = Open ("writestruct.dat", MODE_OLDFILE);

    if (!fh)
    {
	PrintFault (IoErr(), "Can't open file for reading\n");
	return 10;
    }

    if (!ReadStruct (&dsh, (APTR *)&readback, fh, MainDesc))
    {
	PrintFault (IoErr(), "Failed to read from file\n");
    }
    else
    {
	UBYTE * ptr;
	int t;

	ptr = (UBYTE *)readback;
	t = 0;

	kprintf ("readback = %p\n", readback);

	kprintf ("%02X (88) %02X (FF)\n"
	    , (UBYTE)readback->ml_Byte
	    , readback->ml_UByte
	);
	kprintf ("%04X (8844) %04X (FF77)\n"
	    , (UWORD)readback->ml_Word
	    , readback->ml_UWord
	);
	kprintf ("%08lX (88442211) %08lX (FF773311)\n"
	    , readback->ml_Long
	    , readback->ml_ULong
	);
	kprintf ("%08lX (3FC00000) %08lX:%08lX (3FFC0000:00000000)\n"
	    , *(ULONG *)&readback->ml_Float
	    , ((ULONG *)&readback->ml_Double)[1]
	    , ((ULONG *)&readback->ml_Double)[0]
	);
	kprintf ("%s (Hallo)\n"
	    , readback->ml_String
	);
	kprintf ("{ %02X %08X } ({ 88 88442211 })\n"
	    , (UBYTE)readback->ml_Level1.l1_Byte
	    , readback->ml_Level1.l1_Long
	);
	kprintf ("%02X (88)\n"
	    , (UBYTE)*readback->ml_BytePtr
	);
	kprintf ("%04X (8844)\n"
	    , (UWORD)*readback->ml_WordPtr
	);
	kprintf ("%08lX (88442211)\n"
	    , *readback->ml_LongPtr
	);
	kprintf ("%08lX (3FC00000) %08lX:%08lX (3FFC0000:00000000)\n"
	    , *(ULONG *)readback->ml_FloatPtr
	    , ((ULONG *)readback->ml_DoublePtr)[1]
	    , ((ULONG *)readback->ml_DoublePtr)[0]
	);
	kprintf ("%s (Hallo)\n"
	    , *readback->ml_StringPtr
	);
	kprintf ("{ %02X %08X } ({ 88 88442211 })\n"
	    , (UBYTE)readback->ml_Level1Ptr->l1_Byte
	    , readback->ml_Level1Ptr->l1_Long
	);

	FreeStruct (readback, MainDesc);
    }

    if (!Close (fh))
    {
	PrintFault (IoErr(), "Failed to close file after reading\n");
    }

    return 0;
} /* main */