202 lines
6.7 KiB
C#
202 lines
6.7 KiB
C#
![]() |
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using System;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.Networking;
|
||
|
using UnityEngine.UI;
|
||
|
using System.Text.RegularExpressions;
|
||
|
using ModTool;
|
||
|
|
||
|
public class ModPanal : MonoBehaviour
|
||
|
{
|
||
|
[Header("\tGame Specific Content")]
|
||
|
[SerializeField] private string Key;
|
||
|
[SerializeField] private int GameNumber;
|
||
|
|
||
|
[Header("\tFillables")]
|
||
|
[SerializeField] private OnlineAccountHandler Online;
|
||
|
[SerializeField] private GameObject ModPrefab;
|
||
|
[SerializeField] private GameObject CatPrefab;
|
||
|
[SerializeField] public List<GameObject> CreatedModPrefabs;
|
||
|
[SerializeField] public List<GameObject> CreatedCatPrefabs;
|
||
|
[SerializeField] private Transform ModContainer;
|
||
|
[SerializeField] private Transform CatContainer;
|
||
|
|
||
|
private Dictionary<Mod, ModItem> modItems;
|
||
|
|
||
|
// Start is called before the first frame update
|
||
|
void Start()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
// Update is called once per frame
|
||
|
void Update()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
public void ListMyMods() { // Have to push twice issue.
|
||
|
ModManager.AddSearchDirectory(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments)+@"\My Games\Firstborn\Mods");
|
||
|
ModManager.Refresh();
|
||
|
|
||
|
//Subscribe to ModManager events for keeping track of found mods
|
||
|
//ModManager.ModFound += OnModFound;
|
||
|
//ModManager.ModRemoved += OnModRemoved;
|
||
|
|
||
|
//Subscribe to ModManager events to keep track of loaded mods
|
||
|
//ModManager.ModLoaded += OnModLoaded;
|
||
|
//ModManager.ModUnloaded += OnModUnloaded;
|
||
|
|
||
|
//Refresh and look mods in mod search directories
|
||
|
|
||
|
//Start refreshing ModManager to look for changes every 2 seconds
|
||
|
StartCoroutine(AutoRefresh());
|
||
|
// ModManager.Refresh();
|
||
|
|
||
|
//ListMods();
|
||
|
}
|
||
|
|
||
|
IEnumerator AutoRefresh() {
|
||
|
// while(true) {
|
||
|
yield return new WaitForSeconds(2f);
|
||
|
//}
|
||
|
ListMods();
|
||
|
}
|
||
|
|
||
|
private void ListMods() {
|
||
|
for (int i = 0; i < ModManager.mods.Length; i++)
|
||
|
OnModFound(ModManager.mods[i]);
|
||
|
}
|
||
|
|
||
|
private void OnModFound(Mod mod) {
|
||
|
var NewMod = Instantiate(ModPrefab, ModContainer);
|
||
|
CreatedModPrefabs.Add(NewMod);
|
||
|
ModPrefab Mod = NewMod.GetComponent<ModPrefab>();
|
||
|
|
||
|
Mod.Title.text = mod.modInfo.name;
|
||
|
Mod.Author.text = mod.modInfo.author;
|
||
|
Mod.Description.text = mod.modInfo.description;
|
||
|
Mod.Date.text = mod.modInfo.creationDate;
|
||
|
Debug.Log("Path: "+mod.modInfo.path);
|
||
|
|
||
|
|
||
|
//Mod.Description.text = mod.contentType.ToString();
|
||
|
//ModItem modItem = Instantiate(ModPrefab, ModContainer);
|
||
|
|
||
|
//modItem.Initialize(mod);
|
||
|
//modItem.SetToggleInteractable(!isLoaded);
|
||
|
//modItems.Add(mod, modItem);
|
||
|
}
|
||
|
|
||
|
private void OnModRemoved(Mod mod) {
|
||
|
ModItem modItem;
|
||
|
|
||
|
// if(modItems.TryGetValue(mod, out modItem)) {
|
||
|
// CreatedModPrefabs.Remove(mod);
|
||
|
// Destroy(modItem.gameObject);
|
||
|
// }
|
||
|
}
|
||
|
|
||
|
private void OnModLoaded(Mod mod)
|
||
|
{
|
||
|
Debug.Log("Loaded Mod: " + mod.name);
|
||
|
|
||
|
//load first scene (if present) when a mod is loaded
|
||
|
//ModScene scene = mod.scenes.FirstOrDefault();
|
||
|
|
||
|
//if (scene != null)
|
||
|
// scene.Load();
|
||
|
}
|
||
|
|
||
|
private void OnModUnloaded(Mod mod)
|
||
|
{
|
||
|
Debug.Log("Unloaded Mod: " + mod.name);
|
||
|
}
|
||
|
|
||
|
public void GetCategory(int i) {
|
||
|
for (int j = 0; j < CreatedModPrefabs.Count; j++) {
|
||
|
CreatedModPrefabs[j].SetActive(false);
|
||
|
}
|
||
|
CreatedModPrefabs.Clear();
|
||
|
|
||
|
string url = "https://schaken-mods.com/api/downloads/files?key="+Key+"&categories="+i+"&sortDir=desc&hidden=0&page=1&sortDir=desc&hidden=0";
|
||
|
StartCoroutine(GetCategoryMods(url));
|
||
|
}
|
||
|
|
||
|
IEnumerator GetCategoryMods(string uri) {
|
||
|
UnityWebRequest uwr = UnityWebRequest.Get(uri);
|
||
|
yield return uwr.SendWebRequest();
|
||
|
if (uwr.result == UnityWebRequest.Result.ConnectionError) {
|
||
|
Debug.Log("Error While Sending: " + uwr.error);
|
||
|
} else {
|
||
|
// string FullTXT = uwr.downloadHandler.text.Replace(@"\", string.Empty);
|
||
|
string FullTXT = System.Text.RegularExpressions.Regex.Unescape(uwr.downloadHandler.text);
|
||
|
|
||
|
string BreakingPoints = "hasPendingVersion";
|
||
|
string[] Content = FullTXT.Split(BreakingPoints);
|
||
|
for (int i = 0; i < (Content.Length - 1); i++) {
|
||
|
var NewMod = Instantiate(ModPrefab, ModContainer);
|
||
|
CreatedModPrefabs.Add(NewMod);
|
||
|
ModPrefab Mod = NewMod.GetComponent<ModPrefab>();
|
||
|
|
||
|
string NewScreenshot = "hi";
|
||
|
if (Content[i].Contains("\"primaryScreenshotThumb\": null")) {
|
||
|
NewScreenshot = "https://schaken-mods.com/uploads/monthly_2021_11/NoImage.png.7598ee76366f585b2bb10610b640e551.png";
|
||
|
} else {
|
||
|
NewScreenshot = Content[i].Split (new string[] { "primaryScreenshotThumb" }, StringSplitOptions.None)[1].Split (',')[1].Split (new string[] { "\"url\": \"" }, StringSplitOptions.None)[1].Split ("\"")[0].Trim ();
|
||
|
}
|
||
|
Mod.Title.text = Content[i].Split (new string[] { "\"title\": \"" }, StringSplitOptions.None)[1].Split ("\"")[0].Trim ();
|
||
|
Mod.Date.text = DateTime.Parse(Content[i].Split (new string[] { "\"date\": \"" }, StringSplitOptions.None)[1].Split ("\"")[0].Trim ()).ToString();
|
||
|
Mod.Author.text = Content[i].Split (new string[] { "\"name\": \"" }, StringSplitOptions.None)[2].Split ("\"")[0].Trim ();
|
||
|
Mod.ModID = Content[i].Split (new string[] { "\"id\": " }, StringSplitOptions.None)[1].Split (",")[0].Trim ();
|
||
|
string EndDescription = "\",";
|
||
|
string OrigDescription = Content[i].Split (new string[] { "\"description\": \"" }, StringSplitOptions.None)[1].Split (EndDescription)[0].Trim ();
|
||
|
Mod.Description.text = Regex.Replace(OrigDescription, "<.*?>", String.Empty);
|
||
|
Mod.LoadSS(NewScreenshot);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void GetCategoryList() {
|
||
|
for (int j = 0; j < CreatedCatPrefabs.Count; j++) {
|
||
|
CreatedCatPrefabs[j].SetActive(false);
|
||
|
}
|
||
|
CreatedCatPrefabs.Clear();
|
||
|
|
||
|
string url = "https://schaken-mods.com/api/downloads/categories?key="+Key+"&clubs=0&page=1&perPage=300";
|
||
|
StartCoroutine(GetCategoryMods(url, GameNumber));
|
||
|
}
|
||
|
|
||
|
IEnumerator GetCategoryMods(string uri, int j)
|
||
|
{
|
||
|
UnityWebRequest uwr = UnityWebRequest.Get(uri);
|
||
|
yield return uwr.SendWebRequest();
|
||
|
if (uwr.result == UnityWebRequest.Result.ConnectionError) {
|
||
|
Debug.Log("Error While Sending: " + uwr.error);
|
||
|
} else {
|
||
|
string FullTXT = System.Text.RegularExpressions.Regex.Unescape(uwr.downloadHandler.text);
|
||
|
Debug.Log("Mod Categories Full List: "+FullTXT);
|
||
|
|
||
|
string BreakingPoints = "\"perm_3\"";
|
||
|
string[] Content = FullTXT.Split(BreakingPoints);
|
||
|
Debug.Log("Content Count: "+Content.Length);
|
||
|
for (int i = 0; i < (Content.Length - 1); i++) {
|
||
|
if (Content[i].Contains("\"parentId\": "+j+",")) {
|
||
|
var NewCat = Instantiate(CatPrefab, CatContainer);
|
||
|
CreatedCatPrefabs.Add(NewCat);
|
||
|
CatItem Cat = NewCat.GetComponent<CatItem>();
|
||
|
Cat.CatName.text = Content[i].Split (new string[] { "\"name\": \"" }, StringSplitOptions.None)[1].Split ("\"")[0].Trim ();
|
||
|
Cat.CatID = Content[i].Split (new string[] { "\"id\": " }, StringSplitOptions.None)[1].Split (",")[0].Trim ();
|
||
|
ModPanal TempThis = gameObject.GetComponent<ModPanal>();
|
||
|
Cat.ModMan = TempThis;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|