Easy Save 2 + Prime31 GooglePlayServices Cloud Save

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
Locked
chud575
Posts: 12
Joined: Sat Feb 15, 2014 7:02 pm

Easy Save 2 + Prime31 GooglePlayServices Cloud Save

Post by chud575 »

Hey there,

Did a little reading in the forum about converting to raw bytes when saving to the cloud, but I'm still having problems. Specifically i'm using Prime31's GPGS Cloud Saving interface, which means i can only pass/receive strings. Here's what I'm doing:

On Save:

Code: Select all

var saveGameByteArray : byte[] = ES2.LoadRaw( "UserEasySave.txt" );
var byteStringArray : String = System.Text.Encoding.UTF8.GetString(saveGameByteArray);
PlayGameServices.setStateData( byteStringArray, 0 );
On Load:

Code: Select all

PlayGameServices.loadCloudDataForKey( 0, true );

void loadCloudDataForKeySucceededEvent( int key, string data )
{
	Debug.Log( "loadCloudDataForKeySucceededEvent:" + data );
	var byteArray = System.Text.Encoding.UTF8.GetBytes(data);
	ES2.SaveRaw( byteArray, "UserEasySave.txt");
}
When I try to load the "UserEasySave.txt" that I overwrote locally from the byteArray, I get "EndOfStreamEexception: Failed to read past end of stream"
I've also tried converting the streams to "ToBase64", same results.

thoughts?
chud575
Posts: 12
Joined: Sat Feb 15, 2014 7:02 pm

Re: Easy Save 2 + Prime31 GooglePlayServices Cloud Save

Post by chud575 »

suppose i spoke too soon. Had corrupt data in there, and setStateData() doesn't create a new save. I needed to delete the old save.
User avatar
Joel
Moodkie Staff
Posts: 4873
Joined: Wed Nov 07, 2012 10:32 pm

Re: Easy Save 2 + Prime31 GooglePlayServices Cloud Save

Post by Joel »

Glad you managed to find the problem!

If you find that you get an EndOfStreamException again, it may be that Prime31 is re-encoding the string, so the bytes will be different when you load them back. To fix this, you may have to use System.Convert.ToBase64String(byte[]) and System.Convert.FromBase64String(String) instead of System.Text.Encoding.UTF8.GetString and System.Text.Encoding.UTF8.GetBytes.

All the best,
Joel
Locked