Config file

Configurable file path, language.
This commit is contained in:
katboi01
2022-12-28 14:29:18 +01:00
parent 3e57846c0e
commit 662ee9f865
10 changed files with 88 additions and 41 deletions
+1
View File
@@ -64,3 +64,4 @@ crashlytics-build.properties
/Assets/Plugins/RootMotion/PuppetMaster/_Integration /Assets/Plugins/RootMotion/PuppetMaster/_Integration
/VMDRecords /VMDRecords
/umamusume /umamusume
Config.json
@@ -15,8 +15,8 @@ public class LoadSound : ScriptableObject
public UmaSoundInfo getSoundPath(string name) { public UmaSoundInfo getSoundPath(string name) {
UmaSoundInfo info; UmaSoundInfo info;
info.acbPath = UmaDatabaseController.GetABPath(Main.AbSounds.FirstOrDefault(a => a.Name.Contains(name) && a.Name.EndsWith("acb"))); info.acbPath = Main.AbSounds.FirstOrDefault(a => a.Name.Contains(name) && a.Name.EndsWith("acb")).FilePath;
info.awbPath = UmaDatabaseController.GetABPath(Main.AbSounds.FirstOrDefault(a => a.Name.Contains(name) && a.Name.EndsWith("awb"))); info.awbPath = Main.AbSounds.FirstOrDefault(a => a.Name.Contains(name) && a.Name.EndsWith("awb")).FilePath;
return info; return info;
} }
+48
View File
@@ -0,0 +1,48 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
public class Config
{
public static Config Instance;
public string Version = "";
public string LanguageTip = "Affects Uma names on the list. Language options: 0 - En, 1 - Jp";
public Language Language = Language.En;
public string MainPathTip = "Path to game folder, eg. D:\\Backup\\Cygames\\umamusume or D:/Backup/Cygames/umamusume";
public string MainPath = "";
public Config()
{
//TODO: Updating config file
Version = Application.version;
string configPath = Application.dataPath + "/../Config.json";
MainPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "Low"}\Cygames\umamusume";
if (!File.Exists(configPath))
{
File.WriteAllText(configPath, JsonUtility.ToJson(this, true));
}
else
{
try
{
JsonUtility.FromJsonOverwrite(File.ReadAllText(configPath), this);
}
catch (Exception ex)
{
UmaViewerUI.Instance.LyricsText.text = "Config load error. Using default path. " + ex.Message;
MainPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "Low"}\Cygames\umamusume";
}
}
Instance = this;
}
}
public enum Language
{
En,
Jp
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: be06b6cd776f04146a28ef529c501dc7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+1 -1
View File
@@ -17,7 +17,7 @@ public class ManifestDB
public ManifestDB() public ManifestDB()
{ {
string DBPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "Low"}\\Cygames\\umamusume\\meta"; string DBPath = $"{Config.Instance.MainPath}\\meta";
ManifestDB.DBPath = DBPath; ManifestDB.DBPath = DBPath;
if (File.Exists(DBPath)) if (File.Exists(DBPath))
{ {
@@ -11,6 +11,7 @@ public class UmaDatabaseEntry
public string Url; public string Url;
public string Checksum; public string Checksum;
public string Prerequisites; public string Prerequisites;
public string FilePath => $"{Config.Instance.MainPath}\\dat\\{Url.Substring(0, 2)}\\{Url}";
} }
public class UmaCharaData public class UmaCharaData
@@ -53,8 +53,8 @@ public class UmaDatabaseController
{ {
try try
{ {
metaDb = new SqliteConnection($@"Data Source={Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "Low"}\Cygames\umamusume\meta;"); metaDb = new SqliteConnection($@"Data Source={Config.Instance.MainPath}\meta;");
masterDb = new SqliteConnection($@"Data Source={Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "Low"}\Cygames\umamusume\master\master.mdb;"); masterDb = new SqliteConnection($@"Data Source={Config.Instance.MainPath}\master\master.mdb;");
metaDb.Open(); metaDb.Open();
MetaEntries = ReadMeta(metaDb); MetaEntries = ReadMeta(metaDb);
@@ -66,7 +66,7 @@ public class UmaDatabaseController
} }
catch catch
{ {
UmaViewerUI.Instance.LyricsText.text = $"Database not found: \n{GetGameRootPath()}/meta\n{GetGameRootPath()}/master/master.mdb"; UmaViewerUI.Instance.LyricsText.text = $"Database not found: \n{Config.Instance.MainPath}/meta\n{Config.Instance.MainPath}/master/master.mdb";
UmaViewerUI.Instance.LyricsText.color = Color.red; UmaViewerUI.Instance.LyricsText.color = Color.red;
} }
} }
@@ -158,23 +158,4 @@ public class UmaDatabaseController
DataRow row = result.Rows[0]; DataRow row = result.Rows[0];
return row; return row;
} }
public static string GetABPath(UmaDatabaseEntry entry)
{
if (Application.platform == RuntimePlatform.Android)
{
return $"{GetGameRootPath()}/dat/{entry.Url.Substring(0, 2)}/{entry.Url}";
}
return $"{GetGameRootPath()}\\dat\\{entry.Url.Substring(0, 2)}\\{entry.Url}";
}
public static string GetGameRootPath()
{
if (Application.platform == RuntimePlatform.Android)
{
return Application.persistentDataPath;
}
return $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "Low"}\\Cygames\\umamusume";
}
} }
+6 -6
View File
@@ -275,7 +275,7 @@ public class UmaViewerBuilder : MonoBehaviour
if (CurrentUMAContainer.Head) if (CurrentUMAContainer.Head)
{ {
var locatorEntry = Main.AbList.FirstOrDefault(a => a.Name.EndsWith("3d/animator/drivenkeylocator")); var locatorEntry = Main.AbList.FirstOrDefault(a => a.Name.EndsWith("3d/animator/drivenkeylocator"));
var bundle = AssetBundle.LoadFromFile(UmaDatabaseController.GetABPath(locatorEntry)); var bundle = AssetBundle.LoadFromFile(locatorEntry.FilePath);
Main.LoadedBundles.Add(locatorEntry.Name, bundle); Main.LoadedBundles.Add(locatorEntry.Name, bundle);
var locator = Instantiate(bundle.LoadAsset("DrivenKeyLocator"), CurrentUMAContainer.transform) as GameObject; var locator = Instantiate(bundle.LoadAsset("DrivenKeyLocator"), CurrentUMAContainer.transform) as GameObject;
locator.name = "DrivenKeyLocator"; locator.name = "DrivenKeyLocator";
@@ -288,7 +288,7 @@ public class UmaViewerBuilder : MonoBehaviour
var mangaObjects = new List<GameObject>(); var mangaObjects = new List<GameObject>();
mangaEntry.ForEach(entry => mangaEntry.ForEach(entry =>
{ {
AssetBundle ab = AssetBundle.LoadFromFile(UmaDatabaseController.GetABPath(entry)); AssetBundle ab = AssetBundle.LoadFromFile(entry.FilePath);
Main.LoadedBundles.Add(entry.Name, ab); Main.LoadedBundles.Add(entry.Name, ab);
var obj = ab.LoadAsset(Path.GetFileNameWithoutExtension(entry.Name)) as GameObject; var obj = ab.LoadAsset(Path.GetFileNameWithoutExtension(entry.Name)) as GameObject;
obj.SetActive(false); obj.SetActive(false);
@@ -561,7 +561,7 @@ public class UmaViewerBuilder : MonoBehaviour
{ {
List<AudioClip> clips = new List<AudioClip>(); List<AudioClip> clips = new List<AudioClip>();
UmaViewerUI.Instance.LoadedAssetsAdd(awb); UmaViewerUI.Instance.LoadedAssetsAdd(awb);
string awbPath = UmaDatabaseController.GetABPath(awb); ; string awbPath = awb.FilePath;
if (!File.Exists(awbPath)) return clips; if (!File.Exists(awbPath)) return clips;
FileStream awbFile = File.OpenRead(awbPath); FileStream awbFile = File.OpenRead(awbPath);
@@ -599,7 +599,7 @@ public class UmaViewerBuilder : MonoBehaviour
UmaDatabaseEntry lyricsAsset = Main.AbList.FirstOrDefault(a => a.Name.Contains(lyricsVar)); UmaDatabaseEntry lyricsAsset = Main.AbList.FirstOrDefault(a => a.Name.Contains(lyricsVar));
if (lyricsAsset != null) if (lyricsAsset != null)
{ {
string filePath = UmaDatabaseController.GetABPath(lyricsAsset); string filePath = lyricsAsset.FilePath;
if (File.Exists(filePath)) if (File.Exists(filePath))
{ {
AssetBundle bundle; AssetBundle bundle;
@@ -664,7 +664,7 @@ public class UmaViewerBuilder : MonoBehaviour
Debug.Log("Loading " + entry.Name); Debug.Log("Loading " + entry.Name);
if (Main.LoadedBundles.ContainsKey(entry.Name)) return; if (Main.LoadedBundles.ContainsKey(entry.Name)) return;
string filePath = UmaDatabaseController.GetABPath(entry); string filePath = entry.FilePath;
if (File.Exists(filePath)) if (File.Exists(filePath))
{ {
AssetBundle bundle = AssetBundle.LoadFromFile(filePath); AssetBundle bundle = AssetBundle.LoadFromFile(filePath);
@@ -1250,7 +1250,7 @@ public class UmaViewerBuilder : MonoBehaviour
{ {
string value = $"chara/chr{id}/chr_icon_{id}"; string value = $"chara/chr{id}/chr_icon_{id}";
var entry = UmaViewerMain.Instance.AbList.FirstOrDefault(a => a.Name.Equals(value)); var entry = UmaViewerMain.Instance.AbList.FirstOrDefault(a => a.Name.Equals(value));
string path = UmaDatabaseController.GetABPath(entry); string path = entry.FilePath;
if (File.Exists(path)) if (File.Exists(path))
{ {
AssetBundle assetBundle = AssetBundle.LoadFromFile(path); AssetBundle assetBundle = AssetBundle.LoadFromFile(path);
+14 -9
View File
@@ -30,6 +30,7 @@ public class UmaViewerMain : MonoBehaviour
private void Awake() private void Awake()
{ {
Instance = this; Instance = this;
new Config();
Application.targetFrameRate = -1; Application.targetFrameRate = -1;
AbList = UmaDatabaseController.Instance.MetaEntries.ToList(); AbList = UmaDatabaseController.Instance.MetaEntries.ToList();
AbChara = AbList.Where(ab => ab.Name.StartsWith(UmaDatabaseController.CharaPath)).ToList(); AbChara = AbList.Where(ab => ab.Name.StartsWith(UmaDatabaseController.CharaPath)).ToList();
@@ -41,18 +42,22 @@ public class UmaViewerMain : MonoBehaviour
private IEnumerator Start() private IEnumerator Start()
{ {
Dictionary<int, string> enNames = new Dictionary<int, string>(); Dictionary<int, string> enNames = new Dictionary<int, string>();
yield return UmaViewerDownload.DownloadText("https://www.tracenacademy.com/api/BasicCharaDataInfo", txt =>
if(Config.Instance.Language == Language.En)
{ {
if (string.IsNullOrEmpty(txt)) return; yield return UmaViewerDownload.DownloadText("https://www.tracenacademy.com/api/BasicCharaDataInfo", txt =>
var umaData = JArray.Parse(txt);
foreach (var item in umaData)
{ {
if (!enNames.ContainsKey((int)item["charaId"])) if (string.IsNullOrEmpty(txt)) return;
var umaData = JArray.Parse(txt);
foreach (var item in umaData)
{ {
enNames.Add((int)item["charaId"], item["charaNameEnglish"].ToString()); if (!enNames.ContainsKey((int)item["charaId"]))
{
enNames.Add((int)item["charaId"], item["charaNameEnglish"].ToString());
}
} }
} });
}); }
var UmaCharaData = UmaDatabaseController.Instance.CharaData; var UmaCharaData = UmaDatabaseController.Instance.CharaData;
foreach (var item in UmaCharaData) foreach (var item in UmaCharaData)
@@ -79,7 +84,7 @@ public class UmaViewerMain : MonoBehaviour
var asset = AbList.FirstOrDefault(a => a.Name.Equals("livesettings")); var asset = AbList.FirstOrDefault(a => a.Name.Equals("livesettings"));
if (asset != null) if (asset != null)
{ {
string filePath = UmaDatabaseController.GetABPath(asset); string filePath = asset.FilePath;
if (File.Exists(filePath)) if (File.Exists(filePath))
{ {
AssetBundle bundle = AssetBundle.LoadFromFile(filePath); AssetBundle bundle = AssetBundle.LoadFromFile(filePath);
+1 -1
View File
@@ -148,7 +148,7 @@ public class UmaViewerUI : MonoBehaviour
public void LoadedAssetsAdd(UmaDatabaseEntry entry) public void LoadedAssetsAdd(UmaDatabaseEntry entry)
{ {
LoadedAssetCount++; LoadedAssetCount++;
string filePath = UmaDatabaseController.GetABPath(entry); string filePath = entry.FilePath;
var container = Instantiate(UmaContainerAssetsPrefab, LoadedAssetsPanel).GetComponent<UmaUIContainer>(); var container = Instantiate(UmaContainerAssetsPrefab, LoadedAssetsPanel).GetComponent<UmaUIContainer>();
container.Name = Path.GetFileName(entry.Name) + "\n" + entry.Url; container.Name = Path.GetFileName(entry.Name) + "\n" + entry.Url;
container.Button.onClick.AddListener(() => {Process.Start("explorer.exe", "/select," + filePath);}); container.Button.onClick.AddListener(() => {Process.Start("explorer.exe", "/select," + filePath);});