Add support for exporting prop, compatible with the new version, add the EnableRootMotion option (#143)

* update BillboardBuilder

* add a new enum value

* Add the EnableRootMotion option to support scenarios where the character is not within the camera view

* Add support for exporting prop

* update

* compatible with the new version 2

* update

---------

Co-authored-by: 左右看 <1918891542@qq.com>
This commit is contained in:
CroakFang
2025-09-28 18:10:18 +08:00
committed by GitHub
parent 2f2f06eadc
commit d66991c2ef
33 changed files with 6620 additions and 390 deletions
@@ -45,6 +45,11 @@ public class UmaDatabaseController
public List<DataRow> LiveData;
public List<DataRow> DressData;
//修改(载入通用服装ColorSet相关)
public List<DataRow> CharaDressColor;
/// <summary> Meta Database Connection </summary>
public SqliteConnection metaDb;
/// <summary> Master Database Connection </summary>
@@ -67,8 +72,25 @@ public class UmaDatabaseController
masterDb = new SqliteConnection($@"Data Source={Config.Instance.MainPath}/master/master.mdb;");
}
metaDb.Open();
MetaEntries = ReadMeta(metaDb);
try
{
metaDb.Open();
MetaEntries = ReadMeta(metaDb);
}
catch (Exception e)
{
try
{
var dbPath = $@"{Config.Instance.MainPath}/meta";
var key = GenFinalKey(Config.Instance.DBKey);
MetaEntries = ReadMetaFromEncryptedDb(dbPath, key, 3);
}
catch (Exception)
{
throw;
}
}
masterDb.Open();
CharaData = ReadCharaMaster(masterDb);
@@ -76,6 +98,12 @@ public class UmaDatabaseController
FaceTypeData = ReadFaceTypeData(masterDb);
LiveData = ReadAllLiveData(masterDb);
DressData = ReadAllDressData(masterDb);
//修改(载入通用服装ColorSet相关)
CharaDressColor = ReadAllCharaDressColor(masterDb);
#if UNITY_STANDALONE_WIN
if (!Config.Instance.RegionDetectionPassed)
{
@@ -100,16 +128,26 @@ public class UmaDatabaseController
}
else
{
msg += "\nPlease install the dmm game client";
msg += "\nPlease install the dmm game client or check the key settings.";
}
UmaViewerUI.Instance.ShowMessage(msg, UIMessageType.Error);
}
}
//修改(载入通用服装ColorSet相关)
static List<DataRow> ReadAllCharaDressColor(SqliteConnection conn)
{
return ReadMaster(conn, "SELECT * FROM chara_dress_color_set");
}
static Dictionary<string,UmaDatabaseEntry> ReadMeta(SqliteConnection conn)
{
SqliteCommand sqlite_cmd = conn.CreateCommand();
sqlite_cmd.CommandText = "SELECT m,n,h,d FROM a WHERE d IS NOT NULL";
sqlite_cmd.CommandText = "SELECT m,n,h,d FROM a WHERE d IS NOT NULL"; //filter out manifest entries, whitch have null prerequisites
SqliteDataReader sqlite_datareader = sqlite_cmd.ExecuteReader();
Dictionary<string, UmaDatabaseEntry> meta = new Dictionary<string, UmaDatabaseEntry>();
while (sqlite_datareader.Read())
@@ -143,8 +181,8 @@ public class UmaDatabaseController
}
}
catch(Exception e)
{
Debug.LogError($"Error caught while reading Entry : \n {e}");
{
Debug.LogError($"Error caught while reading Entry : \n {e}");
}
if (entry != null && !meta.ContainsKey(entry.Name)) {
@@ -155,6 +193,108 @@ public class UmaDatabaseController
return meta;
}
public static Dictionary<string, UmaDatabaseEntry> ReadMetaFromEncryptedDb(string dbPath, byte[] keyBytes, int cipherIndex = -1)
{
var meta = new Dictionary<string, UmaDatabaseEntry>(StringComparer.Ordinal);
IntPtr db = IntPtr.Zero;
try
{
db = Sqlite3MC.Open(dbPath);
if (cipherIndex >= 0)
{
try
{
int cfgRc = Sqlite3MC.MC_Config(db, "cipher", cipherIndex);
}
catch (Exception e)
{
Debug.LogError($"MC_Config thrown: {e}");
}
}
int rcKey = Sqlite3MC.Key_SetBytes(db, keyBytes);
if (rcKey != Sqlite3MC.SQLITE_OK)
{
string em = Sqlite3MC.GetErrMsg(db);
throw new InvalidOperationException($"sqlite3_key returned rc={rcKey}, errmsg={em}");
}
if (!Sqlite3MC.ValidateReadable(db, out string validateErr))
{
Debug.LogError($"DB validation after key failed: {validateErr}");
throw new InvalidOperationException("DB validation after key failed: " + validateErr);
}
string sql = "SELECT m,n,h,c,d,e FROM a";
Sqlite3MC.ForEachRow(sql, db, (stmt) =>
{
try
{
string m = Sqlite3MC.ColumnText(stmt, 0);
string n = Sqlite3MC.ColumnText(stmt, 1);
string h = Sqlite3MC.ColumnText(stmt, 2);
string c = Sqlite3MC.ColumnText(stmt, 3);
string d = Sqlite3MC.ColumnText(stmt, 4);
string e = Sqlite3MC.ColumnText(stmt, 5);
if (string.IsNullOrEmpty(m))
{
Debug.LogWarning("Skipping row: empty type string (m).");
return;
}
if (!Enum.TryParse<UmaFileType>(m, /*ignoreCase*/ false, out UmaFileType type))
{
Debug.LogWarning($"Unrecognized EntryType Enum Value :{m}");
return;
}
if (string.IsNullOrEmpty(n))
{
Debug.LogError($"Invalid entry name '{n}' or URL '{h}'. Skipping row.");
return;
}
var entry = new UmaDatabaseEntry
{
Type = type,
Name = n,
Url = h,
Checksum = c,
Prerequisites = d,
Key = e
};
if (!meta.ContainsKey(entry.Name))
{
meta.Add(entry.Name, entry);
}
}
catch (Exception exRow)
{
Debug.LogError("Error caught while reading row: " + exRow);
}
});
}
catch (Exception ex)
{
Debug.LogError("ReadMetaFromEncryptedDb failed: " + ex);
throw;
}
finally
{
if (db != IntPtr.Zero)
{
try { Sqlite3MC.Close(db); }
catch (Exception e) { Debug.LogError("Closing DB failed: " + e); }
}
}
return meta;
}
static void SetDefaultGameRegion(SqliteConnection conn)
{
var str = ReadMaster(conn, "SELECT text FROM text_data LIMIT 1");
@@ -307,4 +447,15 @@ public class UmaDatabaseController
GC.WaitForPendingFinalizers();
}
public byte[] GenFinalKey(byte[] key)
{
var baseKey = Config.Instance.DBBaseKey;
if (baseKey.Length < 13)
throw new Exception("Invalid Base Key length");
for (int i = 0; i < key.Length; i++)
{
key[i] = (byte)(key[i] ^ baseKey[i % 13]);
}
return key;
}
}