Skip to content

Commit

Permalink
Implement Modpack Instance Creation
Browse files Browse the repository at this point in the history
  • Loading branch information
CADIndie committed Apr 28, 2024
1 parent 0441db2 commit 6c63e33
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 9 deletions.
Binary file modified Assets/Plugins/Android/Pojlib-release.aar
Binary file not shown.
61 changes: 54 additions & 7 deletions Assets/Scripts/ModManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using TMPro;
Expand Down Expand Up @@ -145,22 +146,40 @@ public void AddMod()

foreach (MetaInfo metaInfo in modInfos)
{
foreach (var file in metaInfo.files.Where(file => IsValidModFile(file, metaInfo, currentInstanceVer)))
foreach (var file in metaInfo.files.Where(file => IsValidModFile(metaInfo, currentInstanceVer)))
{
ProcessModFile(mp, file, metaInfo, currentInstanceVer);
if (file.url.Contains(".mrpack"))
{
ProcessModpack(mp, file, currentInstanceVer);
} else if (file.url.Contains(".zip"))
{
//ProcessResourcePack();
}
else
{
ProcessModFile(mp, file, metaInfo, currentInstanceVer);
}

return;
}
}
}

private bool IsValidModFile(FileInfo file, MetaInfo metaInfo, string currentInstanceName)
private bool IsValidModFile(MetaInfo metaInfo, string currentInstanceName)
{
return metaInfo.game_versions.Contains(currentInstanceName)
&& metaInfo.loaders.Contains("fabric")
&& !file.url.Contains(".mrpack");
return metaInfo.game_versions.Contains(currentInstanceName)
&& metaInfo.loaders.Contains("fabric");
}

private void ProcessModFile(MetaParser mp, FileInfo file, MetaInfo metaInfo, string currentInstanceVer)
{
AndroidJavaObject instance = LoadInstance();
if (instance == null) return;

DownloadDependenciesAndAddMod(mp, metaInfo, file.url, currentInstanceVer);
}

private void ProcessResourcePack(MetaParser mp, FileInfo file, MetaInfo metaInfo, string currentInstanceVer)
{
Debug.Log($"modName: {mp.title} | modUrl: {file.url} | modVersion: {currentInstanceVer}");

Expand All @@ -169,6 +188,34 @@ private void ProcessModFile(MetaParser mp, FileInfo file, MetaInfo metaInfo, str

DownloadDependenciesAndAddMod(mp, metaInfo, file.url, currentInstanceVer);
}

private async void ProcessModpack(MetaParser mp, FileInfo file, string currentInstanceVer)
{
string path = Path.Combine(Application.persistentDataPath);
path = Path.Combine(path, mp.title + ".mrpack");
Debug.Log($"modName: {mp.title} | modUrl: {file.url} | modVersion: {currentInstanceVer} | modPatch: {path}");

Task DownloadModpackFile()
{
UnityWebRequest modpackFile = new UnityWebRequest(file.url);
modpackFile.method = UnityWebRequest.kHttpVerbGET;
DownloadHandlerFile dh = new DownloadHandlerFile(path);
dh.removeFileOnAbort = true;
modpackFile.downloadHandler = dh;
modpackFile.SendWebRequest();
return Task.CompletedTask;
}

await DownloadModpackFile();

AndroidJavaObject instance = LoadInstance();
if (instance == null) return;

JNIStorage.apiClass.CallStatic<AndroidJavaObject>("createNewInstance", JNIStorage.activity, JNIStorage.instancesObj, mp.title, mp.icon_url, path);
JNIStorage.instance.uiHandler.SetAndShowError(mp.title + " is now being created.");
JNIStorage.instance.UpdateInstances();
File.Delete(path);
}

private AndroidJavaObject LoadInstance()
{
Expand Down
2 changes: 0 additions & 2 deletions ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ PlayerSettings:
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: -1525512396210683227, guid: 7b5da002d83fb8f42ac49c354e6f6d31, type: 2}
- {fileID: 6154349898728414384, guid: d659781fbeb3ee24a850529d00b6529e, type: 2}
metroInputSource: 0
wsaTransparentSwapchain: 0
m_HolographicPauseOnTrackingLoss: 1
Expand Down

0 comments on commit 6c63e33

Please sign in to comment.