Skip to content

Commit

Permalink
v2023.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenlucerne committed Jul 28, 2023
1 parent 15005b0 commit 01ce28d
Show file tree
Hide file tree
Showing 123 changed files with 17,954 additions and 3,712 deletions.
Binary file modified Documentation/Full_Documentation.pdf
Binary file not shown.
36 changes: 36 additions & 0 deletions English.txt
Original file line number Diff line number Diff line change
Expand Up @@ -574,3 +574,39 @@ msgstr "Failed to uninstall the mod '{name}'"

msgid "Uninstall"
msgstr "Uninstall"

msgid "Log in with your smart device"
msgstr "Log in with your smart device"

msgid "Step 1"
msgstr "Step 1"

msgid "Go to "
msgstr "Go to "

msgid "Step 2"
msgstr "Step 2"

msgid "Enter the code below:"
msgstr "Enter the code below:"

msgid "OR"
msgstr "OR"

msgid "On the web"
msgstr "On the web"

msgid "Scan QR code"
msgstr "Scan QR code"

msgid "Scan the code and we'll magically sign you in"
msgstr "Scan the code and we'll magically sign you in"

msgid "could not connect"
msgstr "Could not connect to the Mod.io server"

msgid "Connect with device"
msgstr "Connect with device"

msgid "Failed to connect account"
msgstr "Failed to connect account"
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#if UNITY_EDITOR
using UnityEditor;

#if UNITY_EDITOR

namespace ModIO.Implementation.Platform
{
Expand All @@ -7,13 +9,13 @@ internal static partial class PlatformConfiguration
{
#if UNITY_EDITOR_WIN
/// <summary>Holds the value for the platform header value to use in requests.</summary>
public static string RESTAPI_HEADER = "windows";
public static string RESTAPI_HEADER = RestApiPlatform.Windows.ToString();
#elif UNITY_EDITOR_OSX
/// <summary>Holds the value for the platform header value to use in requests.</summary>
public static string RESTAPI_HEADER = "mac";
public static string RESTAPI_HEADER = RestApiPlatform.Mac.ToString();
#elif UNITY_EDITOR_LINUX
/// <summary>Holds the value for the platform header value to use in requests.</summary>
public static string RESTAPI_HEADER = "linux";
public static string RESTAPI_HEADER = RestApiPlatform.Linux.ToString();
#endif
public const bool SynchronizedDataJobs = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,23 @@ internal static partial class PlatformConfiguration
{
#if UNITY_STANDALONE_WIN
/// <summary>Holds the value for the platform header value to use in requests.</summary>
public static string RESTAPI_HEADER = "windows";
public static string RESTAPI_HEADER = RestApiPlatform.Windows.ToString();
#elif UNITY_WSA
/// <summary>Holds the value for the platform header value to use in requests.</summary>
public static string RESTAPI_HEADER = "UWP";
/// UWP is not currently supported on the backend
public static string RESTAPI_HEADER = RestApiPlatform.Windows.ToString();
#elif UNITY_STANDALONE_OSX
/// <summary>Holds the value for the platform header value to use in requests.</summary>
public static string RESTAPI_HEADER = "mac";
public static string RESTAPI_HEADER = RestApiPlatform.Mac.ToString();
#elif UNITY_STANDALONE_LINUX
/// <summary>Holds the value for the platform header value to use in requests.</summary>
public static string RESTAPI_HEADER = "linux";
public static string RESTAPI_HEADER = RestApiPlatform.Linux.ToString();
#elif UNITY_ANDROID
/// <summary>Holds the value for the platform header value to use in requests.</summary>
public static string RESTAPI_HEADER = "android";
public static string RESTAPI_HEADER = RestApiPlatform.Android.ToString();
#elif UNITY_IOS
/// <summary>Holds the value for the platform header value to use in requests.</summary>
public static string RESTAPI_HEADER = "ios";
public static string RESTAPI_HEADER = RestApiPlatform.Ios.ToString();
#endif
public const bool SynchronizedDataJobs = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ namespace ModIO.Implementation.Platform
internal class SystemIODataService : IUserDataService, IPersistentDataService, ITempDataService
{
#region Directories
#if UNITY_ANDROID

private string persistentDataPath;
public SystemIODataService()
{
persistentDataPath = Application.persistentDataPath;
}

~SystemIODataService()
{
AndroidJNI.DetachCurrentThread();
}
#endif

#if UNITY_STANDALONE_WIN

/// <summary>Root directory for persistent data.</summary>
Expand Down Expand Up @@ -41,7 +55,7 @@ internal class SystemIODataService : IUserDataService, IPersistentDataService, I
public static readonly string GlobalSettingsFilePath =
$"{UserRootDirectory}/globalsettings.json";

#endregion
#endregion

#region Data
/// <summary>Global Settings data structure.</summary>
Expand Down Expand Up @@ -240,10 +254,26 @@ public bool TryCreateParentDirectory(string path)

public async Task<bool> IsThereEnoughDiskSpaceFor(long bytes)
{
FileInfo f = new FileInfo(UserRootDirectory);
string drive = Path.GetPathRoot(f.FullName);
var d = new DriveInfo(drive);
return bytes < d.AvailableFreeSpace;
try
{
#if UNITY_ANDROID
//DriveInfo is not supported on iLcpp
AndroidJNI.AttachCurrentThread();
var statFs = new AndroidJavaObject("android.os.StatFs", persistentDataPath);
var freeBytes = statFs.Call<long>("getFreeBytes");
return bytes < freeBytes;
#else
FileInfo f = new FileInfo(PersistentDataRootDirectory);
string drive = Path.GetPathRoot(f.FullName);
var d = new DriveInfo(drive);
return bytes < d.AvailableFreeSpace;
#endif
}
catch(Exception e)
{
Console.WriteLine(e);
throw;
}
}

#endregion // Operations
Expand Down
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<a href="https://mod.io"><img src="https://mod.io/images/branding/modio-logo-bluedark.svg" alt="mod.io" width="360" align="right"/></a>
# mod.io Unity Plugin v2023.6.1
# mod.io Unity Plugin v2023.7.1
[![License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/modio/modio-unity/blob/master/LICENSE)
[![Discord](https://img.shields.io/discord/389039439487434752.svg?label=Discord&logo=discord&color=7289DA&labelColor=2C2F33)](https://discord.mod.io)
[![Master docs](https://img.shields.io/badge/docs-master-green.svg)](https://go.mod.io/unity-docs)
[![Unity 3D](https://img.shields.io/badge/Unity-2019.4+-lightgrey.svg)](https://unity3d.com)
[![Unity 3D](https://img.shields.io/badge/Unity-2020.3+-lightgrey.svg)](https://unity3d.com)

Welcome to the mod.io Unity Engine plugin repository. It allows game developers to host and automatically install user-created mods in their games which use **Unity 2019.4** or newer. It provides a UI for mod discovery, installation and collection management, and a C# interface which connects to the [mod.io REST API](https://docs.mod.io).
Welcome to the mod.io Unity Engine plugin repository. It allows game developers to host and automatically install user-created mods in their games which use **Unity 2020.3** or newer. It provides a UI for mod discovery, installation and collection management, and a C# interface which connects to the [mod.io REST API](https://docs.mod.io).

## Watch the video tutorial
<a href="https://www.youtube.com/watch?v=pmECrkdzHzQ"><img src="https://i.ytimg.com/vi/pmECrkdzHzQ/maxresdefault.jpg" alt="mod.io" width="560"/></a>
Expand All @@ -32,11 +32,12 @@ Alternatively, you can download an archive of the code using GitHub's download f

1. Set up your [game profile on mod.io](https://mod.io/g/add) (or our [private test environment](https://test.mod.io/g/add)) to get your game ID and API key.
2. Add the plugin to your project using the installation instructions above.
3. Ensure you dont have any conflicting libraries by going to Assets/Plugins/mod.io/ThirdParty to remove any libraries you may already have in your project (such as JsonNet).
4. Restart unity to ensure it recognises the new assembly definitions.
5. Go to Tools > mod.io > Edit Settings to locate the config file.
6. Select the config file and use the inspector to assign your game ID and API key in server settings (Make sure to deselect the config file before using playmode in the editor. A known unity bug can cause the editor to crash in 2019-2021).
7. Setup complete! Join us [on Discord](https://discord.mod.io) if you have any questions or need help.
3. Ensure you dont have any conflicting libraries by going to Assets/Plugins/mod.io/ThirdParty to remove any libraries you may already have in your project.
4. If you dont have Newtonsoft in your project, add it from the Package Manager by clicking the "Add package from git URL" option and enter "com.unity.newtonsoft-json" to add the Newtonsoft package
5. Restart unity to ensure it recognises the new assembly definitions.
6. Go to Tools > mod.io > Edit Settings to locate the config file.
7. Select the config file and use the inspector to assign your game ID and API key in server settings (Make sure to deselect the config file before using playmode in the editor. A known unity bug can cause the editor to crash in 2019-2021).
8. Setup complete! Join us [on Discord](https://discord.mod.io) if you have any questions or need help.

## Setting up the Browser UI

Expand Down
2 changes: 2 additions & 0 deletions Runtime/Classes/ModProfileDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ public class ModProfileDetails
internal byte[] GetLogo()
{
#if UNITY_2019_4_OR_NEWER
// If a Texture2D type is not set to 'Sprite (2D or UI)' it will get flagged
// by cloudflare as suspicious and be rejected. This will return a 403
return logo.EncodeToPNG();
#else
return logo;
Expand Down
28 changes: 28 additions & 0 deletions Runtime/ModIO.Implementation/Classes/ModIOUnityImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using UnityEngine;
using System.Linq;
using ModIO.Implementation.API.Requests;
using ModIO.Implementation.Wss;

namespace ModIO.Implementation
{
Expand Down Expand Up @@ -369,6 +370,7 @@ static async Task ShutdownTask()
{
await WebRequestManager.Shutdown();
await ModManagement.ShutdownOperations();
await WssHandler.Shutdown();

isInitialized = false;
UserData.instance = null;
Expand Down Expand Up @@ -708,6 +710,28 @@ public static async void AuthenticateUser(
callback?.Invoke(result);
}

public static async void BeginWssAuthentication(Action<ResultAnd<ExternalAuthenticationToken>> callback)
{
if(callback == null)
{
Logger.Log(
LogLevel.Warning,
"No callback was given to the BeginWssAuthentication method, any response "
+ "returned from the server wont be used. This operation has been cancelled.");
return;
}

var response = await BeginWssAuthentication();
callback?.Invoke(response);
}

public static async Task<ResultAnd<ExternalAuthenticationToken>> BeginWssAuthentication()
{
var callbackConfirmation = openCallbacks.New();
var result = await openCallbacks.Run(callbackConfirmation, Wss.Wss.BeginAuthenticationProcess());
openCallbacks.Complete(callbackConfirmation);
return result;
}

#endregion // Authentication

Expand Down Expand Up @@ -2144,6 +2168,10 @@ public static async Task<Result> DeleteModComment(ModId modId, long commentId)
var config = API.Requests.DeleteModComment.Request(modId, commentId);
var taskResult = await openCallbacks.Run(callbackConfirmation, WebRequestManager.Request<ModCommentObject>(config));
result = taskResult.result;
if(result.Succeeded())
{
ResponseCache.RemoveModCommentFromCache(commentId);
}
}
openCallbacks.Complete(callbackConfirmation);

Expand Down
4 changes: 2 additions & 2 deletions Runtime/ModIO.Implementation/Classes/ModIOVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ internal struct ModIOVersion : System.IComparable<ModIOVersion>
{
// ---------[ Singleton ]---------
/// <summary>Singleton instance for current version.</summary>
public static readonly ModIOVersion Current = new ModIOVersion(2023, 6, 1, "beta");
public static readonly ModIOVersion Current = new ModIOVersion(2023, 7, 1, "beta");

// ---------[ Fields ]---------
/// <summary>Main Version number.</summary>
Expand Down Expand Up @@ -97,7 +97,7 @@ public int CompareTo(ModIOVersion other)
#region Utility

/// <summary>Creates the request header representation of the version.</summary>
public string ToHeaderString() => $"modioUnityPlugin-{year.ToString()}.{month.ToString()}.{patch.ToString()}-{suffix}";
public string ToHeaderString() => $"modio-{year.ToString()}.{month.ToString()}.{patch.ToString()}-{suffix}";


#endregion // Utility
Expand Down
6 changes: 6 additions & 0 deletions Runtime/ModIO.Implementation/Classes/ResultCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ internal static class ResultCode
public const uint Internal_FileHashMismatch = 20505;
public const uint Internal_OperationCancelled = 20506;
public const uint Internal_InvalidParameter = 20507;

// - WSS handling errors -
public const uint WSS_NotConnected = 20600;
public const uint WSS_FailedToSend = 20601;
public const uint WSS_MessageTimeout = 20602;
public const uint WSS_UnexpectedMessage = 20603;

// - REST API Errors -
// 10000 mod.io is currently experiencing an outage. (rare)
Expand Down
11 changes: 11 additions & 0 deletions Runtime/ModIO.Implementation/Classes/UserData.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using ModIO.Implementation.API;
using ModIO.Implementation.API.Objects;
using ModIO.Implementation.Wss.Messages.Objects;

namespace ModIO.Implementation
{
Expand Down Expand Up @@ -64,6 +66,15 @@ public void SetOAuthToken(AccessTokenObject newToken)
DataStorage.SaveUserData();
}

/// <summary>Convenience wrapper that sets OAuthToken and clears rejected flag.</summary>
public void SetOAuthToken(WssLoginSuccess newToken)
{
oAuthToken = newToken.access_token;
oAuthExpiryDate = newToken.date_expires;
oAuthTokenWasRejected = false;
DataStorage.SaveUserData();
}

public void SetOAuthTokenAsRejected()
{
oAuthTokenWasRejected = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ public static void AddModsToCache(string url, int offset, ModPage modPage)

if(!mods.ContainsKey(mod.id))
{
CachedModProfile cachedMod = new CachedModProfile();
cachedMod.profile = mod;
CachedModProfile cachedMod = new CachedModProfile { profile = mod };
mods.Add(mod.id, cachedMod);
modIdsToClearAfterLifeTimeCheck.Add(mod.id);
}
Expand All @@ -151,6 +150,26 @@ public static void AddModCommentsToCache(string url, CommentPage commentPage)
}
}

public static void RemoveModCommentFromCache(long id)
{
List<string> urls = new List<string>();
foreach(var kvp in commentObjectsCache)
{
foreach(var commentObject in kvp.Value.CommentObjects)
{
if(commentObject.id == id)
{
urls.Add(kvp.Key);
}
}
}

foreach(var url in urls)
{
commentObjectsCache.Remove(url);
}
}

public static void AddModToCache(ModProfile mod)
{
if(mods.ContainsKey(mod.id))
Expand Down Expand Up @@ -538,6 +557,7 @@ public static void ClearCache()
termsHash = default;
termsOfUse = null;
gameTags = null;
commentObjectsCache.Clear();
modsDependencies?.Clear();
currentUserRatings?.Clear();
currentRatingsCached = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public static Rating[] ConvertModRatingsObjectToRatings(RatingObject[] ratingObj
int index = 0;
foreach(var ratingObj in ratingObjects)
{
ratings[index] = new Rating
ratings[index++] = new Rating
{
modId = new ModId(ratingObj.mod_id),
rating = (ModRating)ratingObj.rating,
Expand Down Expand Up @@ -207,7 +207,9 @@ public static ModComment ConvertModCommentObjectsToModComment(ModCommentObject m
resourceId = modCommentObjects.resource_id,
submittedBy = modCommentObjects.submitted_by,
threadPosition = modCommentObjects.thread_position,
commentDetails = new CommentDetails(modCommentObjects.reply_id, modCommentObjects.content)
commentDetails = new CommentDetails(modCommentObjects.reply_id, modCommentObjects.content),
userProfile = ConvertUserObjectToUserProfile(modCommentObjects.user)

};

}
Expand Down Expand Up @@ -241,6 +243,7 @@ public static ModProfile ConvertModObjectToModProfile(ModObject modObject)
profile.name = modObject.name ?? "";
profile.summary = modObject.summary ?? "";
profile.homePageUrl = modObject.homepage_url;
profile.profilePageUrl = modObject.profile_url;
profile.status = (ModStatus)modObject.status;
profile.visible = modObject.visible == 1;
profile.contentWarnings = (ContentWarnings)modObject.maturity_option;
Expand All @@ -262,9 +265,12 @@ public static ModProfile ConvertModObjectToModProfile(ModObject modObject)

// set tags
List<string> tags = new List<string>();
foreach(ModTagObject tag in modObject.tags)
if (modObject.tags != null)
{
tags.Add(tag.name);
foreach(ModTagObject tag in modObject.tags)
{
tags.Add(tag.name);
}
}
profile.tags = tags.ToArray();

Expand Down
Loading

0 comments on commit 01ce28d

Please sign in to comment.