Skip to content

Commit fc0baff

Browse files
v4.0.6 GDK support and other fixes
1 parent 97c0569 commit fc0baff

File tree

90 files changed

+8303
-4298
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+8303
-4298
lines changed

Runtime/ModIO.Implementation/Classes/ModIOUnityImplementation.cs

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,6 +1395,9 @@ public static Result RemoveUserData()
13951395
// remove the user's auth token and credentials, clear the session
13961396
UserData.instance?.ClearUser();
13971397

1398+
// clear the UserProfile from the cache as it is no longer valid
1399+
ResponseCache.ClearUserFromCache();
1400+
13981401
ModManagement.WakeUp();
13991402

14001403
bool userExists = ModCollectionManager.DoesUserExist();
@@ -1422,43 +1425,55 @@ public static async Task<ResultAnd<Texture2D>> DownloadTexture(DownloadReference
14221425
Texture2D texture = null;
14231426
//-------------------------------------------------------------------------------------
14241427

1425-
if(IsInitialized(out result) && AreCredentialsValid(false, out result))
1428+
if(downloadReference.IsValid())
14261429
{
1427-
// Check cache asynchronously for texture in temp folder
1428-
Task<ResultAnd<Texture2D>> cacheTask =
1429-
ResponseCache.GetTextureFromCache(downloadReference);
1430-
1431-
openCallbacks[callbackConfirmation] = cacheTask;
1432-
ResultAnd<Texture2D> cacheResponse = await cacheTask;
1433-
openCallbacks[callbackConfirmation] = null;
1434-
1435-
if(cacheResponse.result.Succeeded())
1436-
{
1437-
// CACHE SUCCEEDED
1438-
1439-
result = cacheResponse.result;
1440-
texture = cacheResponse.value;
1441-
}
1442-
else
1430+
if(IsInitialized(out result) && AreCredentialsValid(false, out result))
14431431
{
1444-
// MAKE RESTAPI REQUEST
1445-
Task<ResultAnd<Texture2D>> task =
1446-
RESTAPI.Request<Texture2D>(downloadReference.url, DownloadImage.Template);
1432+
// Check cache asynchronously for texture in temp folder
1433+
Task<ResultAnd<Texture2D>> cacheTask =
1434+
ResponseCache.GetTextureFromCache(downloadReference);
14471435

1448-
openCallbacks[callbackConfirmation] = task;
1449-
ResultAnd<Texture2D> response = await task;
1436+
openCallbacks[callbackConfirmation] = cacheTask;
1437+
ResultAnd<Texture2D> cacheResponse = await cacheTask;
14501438
openCallbacks[callbackConfirmation] = null;
14511439

1452-
result = response.result;
1440+
if(cacheResponse.result.Succeeded())
1441+
{
1442+
// CACHE SUCCEEDED
14531443

1454-
if(response.result.Succeeded())
1444+
result = cacheResponse.result;
1445+
texture = cacheResponse.value;
1446+
}
1447+
else
14551448
{
1456-
texture = response.value;
1449+
// MAKE RESTAPI REQUEST
1450+
Task<ResultAnd<Texture2D>> task =
1451+
RESTAPI.Request<Texture2D>(downloadReference.url, DownloadImage.Template);
1452+
1453+
openCallbacks[callbackConfirmation] = task;
1454+
ResultAnd<Texture2D> response = await task;
1455+
openCallbacks[callbackConfirmation] = null;
1456+
1457+
result = response.result;
14571458

1458-
await ResponseCache.AddTextureToCache(downloadReference, response.value);
1459+
if(response.result.Succeeded())
1460+
{
1461+
texture = response.value;
1462+
1463+
await ResponseCache.AddTextureToCache(downloadReference, response.value);
1464+
}
14591465
}
1466+
// continue to invoke at the end of this method
14601467
}
1461-
// continue to invoke at the end of this method
1468+
}
1469+
else
1470+
{
1471+
Logger.Log(
1472+
LogLevel.Warning,
1473+
"The DownloadReference provided for the DownloadTexture method was not"
1474+
+ " valid. Consider using the DownloadReference.IsValid() method to check if the"
1475+
+ "DownloadReference has an existing URL before using this method.");
1476+
result = ResultBuilder.Create(ResultCode.InvalidParameter_DownloadReferenceIsntValid);
14621477
}
14631478

14641479
callbackConfirmation.SetResult(true);

Runtime/ModIO.Implementation/Classes/ResultCode.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ internal static class ResultCode
5050
public const uint InvalidParameter_ModLogoTooLarge = 20212;
5151
public const uint InvalidParameter_CantBeNull = 20213;
5252
public const uint InvalidParameter_MissingModId = 20214;
53+
54+
public const uint InvalidParameter_DownloadReferenceIsntValid = 20220;
5355

5456
// - API handling errors -
5557
public const uint API_FailedToDeserializeResponse = 20300;

Runtime/ModIO.Implementation/Implementation.API/Classes/RESTAPI.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,9 @@ static async Task<ResultAnd<T>> PerformRequest<T>(
576576
//--------------------------------------------------------------------------------//
577577
case ResponseCodeType.NetworkError:
578578
logTitle =
579-
"NETWORK ERROR\nA Network error occurred. Check your Internet connection and/or Firewall settings.\n\n";
579+
$"NETWORK ERROR\nA Network error occurred. Check your Internet "
580+
+ $"connection and/or Firewall settings.\n URL: {webRequest.url}\n "
581+
+ $"ERROR: {webRequest.error}";
580582

581583
internalResponse.result =
582584
ResultBuilder.Create(ResultCode.API_FailedToConnect);

Runtime/ModIO.Implementation/Implementation.API/Classes/ResponseCache.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,14 @@ static async void ClearModsFromCacheAfterDelay(List<ModId> modIds)
387387
} while(modIds.Count > 0);
388388
}
389389

390+
/// <summary>
391+
/// If the user has logged out we need to clear the cache for the user data.
392+
/// </summary>
393+
public static void ClearUserFromCache()
394+
{
395+
currentUser = null;
396+
}
397+
390398
/// <summary>
391399
/// Clears the entire cache, used when performing a shutdown operation.
392400
/// </summary>
@@ -397,7 +405,7 @@ public static void ClearCache()
397405
termsHash = default;
398406
termsOfUse = null;
399407
gameTags = null;
400-
currentUser = null;
408+
ClearUserFromCache();
401409
}
402410
#endregion // Clearing Cache entries
403411

Runtime/ModIO.Implementation/Implementation.API/Classes/ResponseTranslator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ public static UserProfile ConvertUserObjectToUserProfile(UserObject userObject)
253253
user.avatar_100x100 = CreateDownloadReference(
254254
userObject.avatar.filename, userObject.avatar.thumb_100x100, (ModId)0);
255255
user.username = userObject.username;
256+
user.portal_username = userObject.display_name_portal;
256257
user.language = userObject.language;
257258
user.timezone = userObject.timezone;
258259
return user;
Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,50 @@
1-
using ModIO.Implementation.API.Objects;
1+
using System;
2+
using System.Collections.Generic;
3+
using ModIO.Implementation.API.Objects;
24
using Newtonsoft.Json.Utilities;
35
using UnityEngine;
46

57
namespace ModIO.Implementation.API
68
{
79
/// <summary>
810
/// You do not need to use this class. This is used to ensure specific types in API request
9-
/// objects get AOT code generated when using IL2CPP compilation.
11+
/// objects and anything we serialize for the registry gets AOT code generated when using IL2CPP
12+
/// compilation.
1013
/// </summary>
1114
internal class AotTypeEnforcer : MonoBehaviour
1215
{
1316
public void Awake()
1417
{
18+
AotHelper.EnsureList<ModId>();
19+
AotHelper.EnsureList<ModObject>();
20+
AotHelper.EnsureList<LogoObject>();
21+
AotHelper.EnsureList<UserObject>();
1522
AotHelper.EnsureList<ImageObject>();
1623
AotHelper.EnsureList<MetadataKVPObject>();
24+
AotHelper.EnsureList<ModMediaObject>();
25+
AotHelper.EnsureList<ModfileObject>();
26+
AotHelper.EnsureList<ModStatsObject>();
27+
AotHelper.EnsureList<GameTagOptionObject>();
1728
AotHelper.EnsureList<ModTagObject>();
18-
AotHelper.EnsureList<ModObject>();
29+
AotHelper.EnsureList<TermsObject>();
30+
AotHelper.EnsureList<TermsButtonObject>();
31+
AotHelper.EnsureList<TermsLinksObject>();
32+
AotHelper.EnsureList<DownloadObject>();
33+
AotHelper.EnsureList<FilehashObject>();
34+
AotHelper.EnsureList<UserEventObject>();
35+
AotHelper.EnsureList<ModEventObject>();
36+
AotHelper.EnsureList<AvatarObject>();
37+
AotHelper.EnsureList<AccessTokenObject>();
38+
AotHelper.EnsureList<ErrorObject>();
39+
AotHelper.EnsureList<Error>();
40+
AotHelper.EnsureList<ModCollectionRegistry>();
41+
AotHelper.EnsureList<UserModCollectionData>();
42+
AotHelper.EnsureList<ModCollectionEntry>();
43+
AotHelper.EnsureList<ModProfile>();
44+
AotHelper.EnsureList<DownloadReference>();
45+
AotHelper.EnsureList<KeyValuePair<string, string>>();
46+
AotHelper.EnsureList<ModStats>();
47+
AotHelper.EnsureList<DateTime>();
1948
}
2049
}
2150
}

Runtime/ModIO.Implementation/Implementation.API/Implementation.API.Objects/DownloadObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
namespace ModIO.Implementation.API.Objects
33
{
44
[System.Serializable]
5-
internal class DownloadObject
5+
internal struct DownloadObject
66
{
77
public string binary_url;
88
public long date_expires;

Runtime/ModIO.Implementation/Implementation.API/Implementation.API.Objects/FilehashObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
namespace ModIO.Implementation.API.Objects
33
{
44
[System.Serializable]
5-
internal class FilehashObject
5+
internal struct FilehashObject
66
{
77
public string md5;
88
}

Runtime/ModIO.Implementation/Implementation.API/Implementation.API.Objects/ImageObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace ModIO
22
{
33
[System.Serializable]
4-
internal class ImageObject
4+
internal struct ImageObject
55
{
66
public string filename;
77
public string original;

Runtime/ModIO.Implementation/Implementation.API/Implementation.API.Objects/ModfileObject.cs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,5 @@ internal struct ModfileObject
1919
public string changelog;
2020
public string metadata_blob;
2121
public DownloadObject download;
22-
23-
//public static bool operator == (ModfileObject a, ModfileObject b) => Equals(a, b);
24-
//public static bool operator !=(ModfileObject a, ModfileObject b) => !Equals(a, b);
25-
26-
//public override bool Equals(object other) => GetHashCode() == other.GetHashCode();
27-
28-
//public bool Equals(ModfileObject other) =>
29-
// (id, mod_id, date_added, virus_status, virus_positive,
30-
// virustotal_hash, filesize, filehash, filename, version,
31-
// changelog, metadata_blob)
32-
// ==
33-
// (other.id, other.mod_id, other.date_added, other.virus_status,
34-
// other.virus_positive, other.virustotal_hash, other.filesize, other.filehash,
35-
// other.filename, other.version, other.changelog, other.metadata_blob);
36-
37-
//public override int GetHashCode() =>
38-
// (id, mod_id, date_added, virus_status, virus_positive,
39-
// virustotal_hash, filesize, filehash, filename, version,
40-
// changelog, metadata_blob).GetHashCode();
4122
}
4223
}

0 commit comments

Comments
 (0)