Skip to content

Commit 3237af4

Browse files
author
Ellan Jiang
authored
Merge pull request EllanJiang#8 from EllanJiang/dev/v3.0.5
Dev/v3.0.5
2 parents 06816dd + c7bbc8d commit 3237af4

35 files changed

+668
-136
lines changed

GameFramework/Base/GameFrameworkEntry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace GameFramework
1515
/// </summary>
1616
public static class GameFrameworkEntry
1717
{
18-
private const string GameFrameworkVersion = "3.0.4";
18+
private const string GameFrameworkVersion = "3.0.5";
1919
private static readonly LinkedList<GameFrameworkModule> s_GameFrameworkModules = new LinkedList<GameFrameworkModule>();
2020

2121
/// <summary>

GameFramework/Network/NetworkManager.NetworkChannel.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,19 @@ public void Send<T>(T packet, object userData) where T : Packet
591591
}
592592

593593
packetLength = length - m_PacketHeaderLength;
594-
Utility.Converter.GetBytesFromInt(packetLength).CopyTo(packetBuffer, 0);
594+
if (m_PacketHeaderLength == 4)
595+
{
596+
Utility.Converter.GetBytes(packetLength).CopyTo(packetBuffer, 0);
597+
}
598+
else if (m_PacketHeaderLength == 2)
599+
{
600+
Utility.Converter.GetBytes((ushort)packetLength).CopyTo(packetBuffer, 0);
601+
}
602+
else
603+
{
604+
packetBuffer[0] = (byte)packetLength;
605+
}
606+
595607
Send(packetBuffer, 0, length, userData);
596608
}
597609
catch (Exception exception)
@@ -643,9 +655,9 @@ private void Initialize(AddressFamily addressFamily, int packetHeaderLength, int
643655
m_Socket = null;
644656
}
645657

646-
if (packetHeaderLength <= 0)
658+
if (packetHeaderLength != 1 || packetHeaderLength != 2 || packetHeaderLength != 4)
647659
{
648-
throw new GameFrameworkException("Packet header length is invalid.");
660+
throw new GameFrameworkException("Packet header length is invalid, you can only use 1, 2 or 4.");
649661
}
650662

651663
if (maxPacketLength <= 0)
@@ -706,7 +718,7 @@ private bool Process()
706718

707719
if (m_ReceiveState.Length == m_PacketHeaderLength)
708720
{
709-
int packetLength = Utility.Converter.GetIntFromBytes(m_ReceiveState.GetBuffer());
721+
int packetLength = m_PacketHeaderLength == 4 ? Utility.Converter.GetInt32(m_ReceiveState.GetBuffer()) : (m_PacketHeaderLength == 2 ? Utility.Converter.GetUInt16(m_ReceiveState.GetBuffer()) : m_ReceiveState.GetBuffer()[0]);
710722
if (packetLength <= 0)
711723
{
712724
string errorMessage = string.Format("Packet length '{0}' is invalid.", packetLength.ToString());

GameFramework/Resource/ResourceManager.ResourceChecker.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ private void ParseVersionList(string fileUri, byte[] bytes, string errorMessage)
225225
if (listVersion == 0)
226226
{
227227
byte[] encryptBytes = binaryReader.ReadBytes(4);
228-
m_ResourceManager.m_ApplicableGameVersion = Utility.Converter.GetStringFromBytes(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), encryptBytes));
228+
m_ResourceManager.m_ApplicableGameVersion = Utility.Converter.GetString(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), encryptBytes));
229229
m_ResourceManager.m_InternalResourceVersion = binaryReader.ReadInt32();
230230

231231
int resourceCount = binaryReader.ReadInt32();
@@ -235,13 +235,13 @@ private void ParseVersionList(string fileUri, byte[] bytes, string errorMessage)
235235
Dictionary<string, string[]> dependencyAssetNamesCollection = new Dictionary<string, string[]>();
236236
for (int i = 0; i < resourceCount; i++)
237237
{
238-
names[i] = Utility.Converter.GetStringFromBytes(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), encryptBytes));
238+
names[i] = Utility.Converter.GetString(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), encryptBytes));
239239

240240
variants[i] = null;
241241
byte variantLength = binaryReader.ReadByte();
242242
if (variantLength > 0)
243243
{
244-
variants[i] = Utility.Converter.GetStringFromBytes(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(variantLength), encryptBytes));
244+
variants[i] = Utility.Converter.GetString(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(variantLength), encryptBytes));
245245
}
246246

247247
LoadType loadType = (LoadType)binaryReader.ReadByte();
@@ -254,13 +254,13 @@ private void ParseVersionList(string fileUri, byte[] bytes, string errorMessage)
254254
string[] assetNames = new string[assetNamesCount];
255255
for (int j = 0; j < assetNamesCount; j++)
256256
{
257-
assetNames[j] = Utility.Converter.GetStringFromBytes(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), Utility.Converter.GetBytesFromInt(hashCode)));
257+
assetNames[j] = Utility.Converter.GetString(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), Utility.Converter.GetBytes(hashCode)));
258258

259259
int dependencyAssetNamesCount = binaryReader.ReadInt32();
260260
string[] dependencyAssetNames = new string[dependencyAssetNamesCount];
261261
for (int k = 0; k < dependencyAssetNamesCount; k++)
262262
{
263-
dependencyAssetNames[k] = Utility.Converter.GetStringFromBytes(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), Utility.Converter.GetBytesFromInt(hashCode)));
263+
dependencyAssetNames[k] = Utility.Converter.GetString(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), Utility.Converter.GetBytes(hashCode)));
264264
}
265265

266266
if (variants[i] == null || variants[i] == m_CurrentVariant)
@@ -288,7 +288,7 @@ private void ParseVersionList(string fileUri, byte[] bytes, string errorMessage)
288288
int resourceGroupCount = binaryReader.ReadInt32();
289289
for (int i = 0; i < resourceGroupCount; i++)
290290
{
291-
string groupName = Utility.Converter.GetStringFromBytes(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), encryptBytes));
291+
string groupName = Utility.Converter.GetString(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), encryptBytes));
292292
ResourceGroup resourceGroup = m_ResourceManager.GetResourceGroup(groupName);
293293
int groupResourceCount = binaryReader.ReadInt32();
294294
for (int j = 0; j < groupResourceCount; j++)
@@ -373,13 +373,13 @@ private void ParseReadOnlyList(string fileUri, byte[] bytes, string errorMessage
373373
int resourceCount = binaryReader.ReadInt32();
374374
for (int i = 0; i < resourceCount; i++)
375375
{
376-
string name = Utility.Converter.GetStringFromBytes(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), encryptBytes));
376+
string name = Utility.Converter.GetString(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), encryptBytes));
377377

378378
string variant = null;
379379
byte variantLength = binaryReader.ReadByte();
380380
if (variantLength > 0)
381381
{
382-
variant = Utility.Converter.GetStringFromBytes(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(variantLength), encryptBytes));
382+
variant = Utility.Converter.GetString(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(variantLength), encryptBytes));
383383
}
384384

385385
LoadType loadType = (LoadType)binaryReader.ReadByte();
@@ -459,13 +459,13 @@ private void ParseReadWriteList(string fileUri, byte[] bytes, string errorMessag
459459
int resourceCount = binaryReader.ReadInt32();
460460
for (int i = 0; i < resourceCount; i++)
461461
{
462-
string name = Utility.Converter.GetStringFromBytes(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), encryptBytes));
462+
string name = Utility.Converter.GetString(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), encryptBytes));
463463

464464
string variant = null;
465465
byte variantLength = binaryReader.ReadByte();
466466
if (variantLength > 0)
467467
{
468-
variant = Utility.Converter.GetStringFromBytes(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(variantLength), encryptBytes));
468+
variant = Utility.Converter.GetString(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(variantLength), encryptBytes));
469469
}
470470

471471
LoadType loadType = (LoadType)binaryReader.ReadByte();

GameFramework/Resource/ResourceManager.ResourceIniter.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private void ParsePackageList(string fileUri, byte[] bytes, string errorMessage)
9090
{
9191
byte[] encryptBytes = binaryReader.ReadBytes(4);
9292

93-
m_ResourceManager.m_ApplicableGameVersion = Utility.Converter.GetStringFromBytes(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), encryptBytes));
93+
m_ResourceManager.m_ApplicableGameVersion = Utility.Converter.GetString(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), encryptBytes));
9494
m_ResourceManager.m_InternalResourceVersion = binaryReader.ReadInt32();
9595

9696
int resourceCount = binaryReader.ReadInt32();
@@ -100,13 +100,13 @@ private void ParsePackageList(string fileUri, byte[] bytes, string errorMessage)
100100
Dictionary<string, string[]> dependencyAssetNamesCollection = new Dictionary<string, string[]>();
101101
for (int i = 0; i < resourceCount; i++)
102102
{
103-
names[i] = Utility.Converter.GetStringFromBytes(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), encryptBytes));
103+
names[i] = Utility.Converter.GetString(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), encryptBytes));
104104

105105
variants[i] = null;
106106
byte variantLength = binaryReader.ReadByte();
107107
if (variantLength > 0)
108108
{
109-
variants[i] = Utility.Converter.GetStringFromBytes(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(variantLength), encryptBytes));
109+
variants[i] = Utility.Converter.GetString(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(variantLength), encryptBytes));
110110
}
111111

112112
LoadType loadType = (LoadType)binaryReader.ReadByte();
@@ -117,13 +117,13 @@ private void ParsePackageList(string fileUri, byte[] bytes, string errorMessage)
117117
string[] assetNames = new string[assetNamesCount];
118118
for (int j = 0; j < assetNamesCount; j++)
119119
{
120-
assetNames[j] = Utility.Converter.GetStringFromBytes(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), Utility.Converter.GetBytesFromInt(hashCode)));
120+
assetNames[j] = Utility.Converter.GetString(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), Utility.Converter.GetBytes(hashCode)));
121121

122122
int dependencyAssetNamesCount = binaryReader.ReadInt32();
123123
string[] dependencyAssetNames = new string[dependencyAssetNamesCount];
124124
for (int k = 0; k < dependencyAssetNamesCount; k++)
125125
{
126-
dependencyAssetNames[k] = Utility.Converter.GetStringFromBytes(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), Utility.Converter.GetBytesFromInt(hashCode)));
126+
dependencyAssetNames[k] = Utility.Converter.GetString(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), Utility.Converter.GetBytes(hashCode)));
127127
}
128128

129129
if (variants[i] == null || variants[i] == m_CurrentVariant)
@@ -151,7 +151,7 @@ private void ParsePackageList(string fileUri, byte[] bytes, string errorMessage)
151151
int resourceGroupCount = binaryReader.ReadInt32();
152152
for (int i = 0; i < resourceGroupCount; i++)
153153
{
154-
string groupName = Utility.Converter.GetStringFromBytes(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), encryptBytes));
154+
string groupName = Utility.Converter.GetString(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), encryptBytes));
155155
ResourceGroup resourceGroup = m_ResourceManager.GetResourceGroup(groupName);
156156
int groupResourceCount = binaryReader.ReadInt32();
157157
for (int j = 0; j < groupResourceCount; j++)

GameFramework/Resource/ResourceManager.ResourceLoader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,9 @@ private byte[] DefaultDecryptResourceCallback(string name, string variant, int l
452452
switch ((LoadType)loadType)
453453
{
454454
case LoadType.LoadFromMemoryAndQuickDecrypt:
455-
return Utility.Encryption.GetQuickXorBytes(bytes, Utility.Converter.GetBytesFromInt(hashCode));
455+
return Utility.Encryption.GetQuickXorBytes(bytes, Utility.Converter.GetBytes(hashCode));
456456
case LoadType.LoadFromMemoryAndDecrypt:
457-
return Utility.Encryption.GetXorBytes(bytes, Utility.Converter.GetBytesFromInt(hashCode));
457+
return Utility.Encryption.GetXorBytes(bytes, Utility.Converter.GetBytes(hashCode));
458458
default:
459459
return bytes;
460460
}

GameFramework/Resource/ResourceManager.ResourceUpdater.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ private void GenerateReadWriteList()
238238
binaryWriter.Write(m_ResourceManager.m_ReadWriteResourceInfos.Count);
239239
foreach (KeyValuePair<ResourceName, ReadWriteResourceInfo> i in m_ResourceManager.m_ReadWriteResourceInfos)
240240
{
241-
byte[] nameBytes = Utility.Encryption.GetXorBytes(Utility.Converter.GetBytesFromString(i.Key.Name), encryptCode);
241+
byte[] nameBytes = Utility.Encryption.GetXorBytes(Utility.Converter.GetBytes(i.Key.Name), encryptCode);
242242
binaryWriter.Write((byte)nameBytes.Length);
243243
binaryWriter.Write(nameBytes);
244244

@@ -248,7 +248,7 @@ private void GenerateReadWriteList()
248248
}
249249
else
250250
{
251-
byte[] variantBytes = Utility.Encryption.GetXorBytes(Utility.Converter.GetBytesFromString(i.Key.Variant), encryptCode);
251+
byte[] variantBytes = Utility.Encryption.GetXorBytes(Utility.Converter.GetBytes(i.Key.Variant), encryptCode);
252252
binaryWriter.Write((byte)variantBytes.Length);
253253
binaryWriter.Write(variantBytes);
254254
}
@@ -290,7 +290,7 @@ private void GenerateReadWriteList()
290290

291291
private void OnDownloadStart(object sender, DownloadStartEventArgs e)
292292
{
293-
UpdateInfo updateInfo = (UpdateInfo)e.UserData;
293+
UpdateInfo updateInfo = e.UserData as UpdateInfo;
294294
if (updateInfo == null)
295295
{
296296
return;
@@ -323,7 +323,7 @@ private void OnDownloadStart(object sender, DownloadStartEventArgs e)
323323

324324
private void OnDownloadUpdate(object sender, DownloadUpdateEventArgs e)
325325
{
326-
UpdateInfo updateInfo = (UpdateInfo)e.UserData;
326+
UpdateInfo updateInfo = e.UserData as UpdateInfo;
327327
if (updateInfo == null)
328328
{
329329
return;
@@ -356,7 +356,7 @@ private void OnDownloadUpdate(object sender, DownloadUpdateEventArgs e)
356356

357357
private void OnDownloadSuccess(object sender, DownloadSuccessEventArgs e)
358358
{
359-
UpdateInfo updateInfo = (UpdateInfo)e.UserData;
359+
UpdateInfo updateInfo = e.UserData as UpdateInfo;
360360
if (updateInfo == null)
361361
{
362362
return;
@@ -374,7 +374,7 @@ private void OnDownloadSuccess(object sender, DownloadSuccessEventArgs e)
374374

375375
if (!zip)
376376
{
377-
byte[] hashBytes = Utility.Converter.GetBytesFromInt(updateInfo.HashCode);
377+
byte[] hashBytes = Utility.Converter.GetBytes(updateInfo.HashCode);
378378
if (updateInfo.LoadType == LoadType.LoadFromMemoryAndQuickDecrypt)
379379
{
380380
bytes = Utility.Encryption.GetQuickXorBytes(bytes, hashBytes);
@@ -385,7 +385,7 @@ private void OnDownloadSuccess(object sender, DownloadSuccessEventArgs e)
385385
}
386386
}
387387

388-
int hashCode = Utility.Converter.GetIntFromBytes(Utility.Verifier.GetCrc32(bytes));
388+
int hashCode = Utility.Converter.GetInt32(Utility.Verifier.GetCrc32(bytes));
389389
if (updateInfo.ZipHashCode != hashCode)
390390
{
391391
string errorMessage = string.Format("Zip hash code error, need '{0}', downloaded '{1}'.", updateInfo.ZipHashCode.ToString("X8"), hashCode.ToString("X8"));
@@ -449,7 +449,7 @@ private void OnDownloadSuccess(object sender, DownloadSuccessEventArgs e)
449449

450450
private void OnDownloadFailure(object sender, DownloadFailureEventArgs e)
451451
{
452-
UpdateInfo updateInfo = (UpdateInfo)e.UserData;
452+
UpdateInfo updateInfo = e.UserData as UpdateInfo;
453453
if (updateInfo == null)
454454
{
455455
return;

0 commit comments

Comments
 (0)