|
@@ -124,44 +124,41 @@ public static class ModelUtility
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- if (ProcScriptBin(modelBuffer, out var modelInfo))
|
|
|
+ if (!ProcScriptBin(modelBuffer, out var modelInfo) || !InstantiateModel(modelInfo.ModelFile, out var finalModel))
|
|
|
{
|
|
|
- if (InstantiateModel(modelInfo.ModelFile, out var finalModel))
|
|
|
- {
|
|
|
- IEnumerable<Renderer> renderers = GetRenderers(finalModel).ToList();
|
|
|
+ Utility.LogMessage($"Could not load menu model '{modItem.MenuFile}'");
|
|
|
|
|
|
- foreach (var matChange in modelInfo.MaterialChanges)
|
|
|
- foreach (var renderer in renderers)
|
|
|
- if (matChange.MaterialIndex < renderer.materials.Length)
|
|
|
- renderer.materials[matChange.MaterialIndex] = ImportCM.LoadMaterial(
|
|
|
- matChange.MaterialFile, null, renderer.materials[matChange.MaterialIndex]
|
|
|
- );
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
- if (!modItem.IsOfficialMod)
|
|
|
- return finalModel;
|
|
|
+ IEnumerable<Renderer> renderers = GetRenderers(finalModel).ToList();
|
|
|
|
|
|
- try
|
|
|
- {
|
|
|
- modelBuffer = ReadOfficialMod(modItem.MenuFile);
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- Utility.LogError(
|
|
|
- $"Could not read mod menu file '{modItem.MenuFile}' because {e.Message}\n{e.StackTrace}"
|
|
|
+ foreach (var matChange in modelInfo.MaterialChanges)
|
|
|
+ foreach (var renderer in renderers)
|
|
|
+ if (matChange.MaterialIndex < renderer.materials.Length)
|
|
|
+ renderer.materials[matChange.MaterialIndex] = ImportCM.LoadMaterial(
|
|
|
+ matChange.MaterialFile, null, renderer.materials[matChange.MaterialIndex]
|
|
|
);
|
|
|
|
|
|
- return null;
|
|
|
- }
|
|
|
+ if (!modItem.IsOfficialMod)
|
|
|
+ return finalModel;
|
|
|
|
|
|
- ProcModScriptBin(modelBuffer, finalModel);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ modelBuffer = ReadOfficialMod(modItem.MenuFile);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ Utility.LogError(
|
|
|
+ $"Could not read mod menu file '{modItem.MenuFile}' because {e.Message}\n{e.StackTrace}"
|
|
|
+ );
|
|
|
|
|
|
- return finalModel;
|
|
|
- }
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
- Utility.LogMessage($"Could not load menu model '{modItem.MenuFile}'");
|
|
|
+ ProcModScriptBin(modelBuffer, finalModel);
|
|
|
|
|
|
- return null;
|
|
|
+ return finalModel;
|
|
|
}
|
|
|
|
|
|
private static GameObject GetDeploymentObject()
|
|
@@ -238,6 +235,7 @@ public static class ModelUtility
|
|
|
if (binaryReader.ReadByte() is not 0)
|
|
|
{
|
|
|
var otherBone = CreateSeed();
|
|
|
+
|
|
|
otherBone.name = bone.name + "_SCL_";
|
|
|
otherBone.transform.parent = bone.transform;
|
|
|
boneDict[bone.name + "$_SCL_"] = otherBone;
|
|
@@ -421,37 +419,29 @@ public static class ModelUtility
|
|
|
var numberOfProps = binaryReader.ReadByte();
|
|
|
var menuPropString = string.Empty;
|
|
|
|
|
|
- if (numberOfProps is not 0)
|
|
|
- {
|
|
|
- for (var i = 0; i < numberOfProps; i++)
|
|
|
- menuPropString = $"{menuPropString}\"{binaryReader.ReadString()}\"";
|
|
|
-
|
|
|
- if (menuPropString != string.Empty)
|
|
|
- {
|
|
|
- var header = UTY.GetStringCom(menuPropString);
|
|
|
- var menuProps = UTY.GetStringList(menuPropString);
|
|
|
+ if (numberOfProps is 0)
|
|
|
+ break;
|
|
|
|
|
|
- if (header is "end")
|
|
|
- break;
|
|
|
+ for (var i = 0; i < numberOfProps; i++)
|
|
|
+ menuPropString = $"{menuPropString}\"{binaryReader.ReadString()}\"";
|
|
|
|
|
|
- switch (header)
|
|
|
- {
|
|
|
- case "マテリアル変更":
|
|
|
- var matNo = int.Parse(menuProps[2]);
|
|
|
- var materialFile = menuProps[3];
|
|
|
+ if (menuPropString == string.Empty)
|
|
|
+ continue;
|
|
|
|
|
|
- modelInfo.MaterialChanges.Add(new MaterialChange(matNo, materialFile));
|
|
|
+ var header = UTY.GetStringCom(menuPropString);
|
|
|
+ var menuProps = UTY.GetStringList(menuPropString);
|
|
|
|
|
|
- break;
|
|
|
- case "additem":
|
|
|
- modelInfo.ModelFile = menuProps[1];
|
|
|
+ if (header is "end")
|
|
|
+ break;
|
|
|
+ else if (header is "マテリアル変更")
|
|
|
+ {
|
|
|
+ var matNo = int.Parse(menuProps[2]);
|
|
|
+ var materialFile = menuProps[3];
|
|
|
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
+ modelInfo.MaterialChanges.Add(new MaterialChange(matNo, materialFile));
|
|
|
}
|
|
|
- else
|
|
|
- break;
|
|
|
+ else if (header is "additem")
|
|
|
+ modelInfo.ModelFile = menuProps[1];
|
|
|
}
|
|
|
}
|
|
|
catch
|
|
@@ -479,12 +469,12 @@ public static class ModelUtility
|
|
|
binaryReader.ReadString();
|
|
|
binaryReader.ReadString();
|
|
|
|
|
|
- var mpnValue = binaryReader.ReadString();
|
|
|
+ var serializedMpn = binaryReader.ReadString();
|
|
|
var mpn = MPN.null_mpn;
|
|
|
|
|
|
try
|
|
|
{
|
|
|
- mpn = (MPN)Enum.Parse(typeof(MPN), mpnValue, true);
|
|
|
+ mpn = (MPN)Enum.Parse(typeof(MPN), serializedMpn, true);
|
|
|
}
|
|
|
catch { /* ignored */ }
|
|
|
|
|
@@ -521,76 +511,58 @@ public static class ModelUtility
|
|
|
{
|
|
|
var data = line.Split(new[] { '\t', ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
|
- switch (data[0])
|
|
|
+ var header = data[0];
|
|
|
+
|
|
|
+ if (header is "アイテム変更" or "マテリアル変更")
|
|
|
+ mode = IMode.ItemChange;
|
|
|
+ else if (header is "テクスチャ変更")
|
|
|
+ mode = IMode.TexChange;
|
|
|
+
|
|
|
+ if (mode is IMode.ItemChange)
|
|
|
{
|
|
|
- case "アイテム変更":
|
|
|
- case "マテリアル変更":
|
|
|
- mode = IMode.ItemChange;
|
|
|
+ if (header is "スロット名")
|
|
|
+ materialChange = true;
|
|
|
|
|
|
- break;
|
|
|
- case "テクスチャ変更":
|
|
|
- mode = IMode.TexChange;
|
|
|
+ if (!materialChange)
|
|
|
+ continue;
|
|
|
|
|
|
- break;
|
|
|
- }
|
|
|
+ if (header is "マテリアル番号")
|
|
|
+ {
|
|
|
+ materialIndex = int.Parse(data[1]);
|
|
|
|
|
|
- switch (mode)
|
|
|
- {
|
|
|
- case IMode.ItemChange:
|
|
|
- if (data[0] is "スロット名")
|
|
|
- materialChange = true;
|
|
|
-
|
|
|
- if (materialChange)
|
|
|
- {
|
|
|
- if (data[0] is "マテリアル番号")
|
|
|
- {
|
|
|
- materialIndex = int.Parse(data[1]);
|
|
|
-
|
|
|
- renderers ??= GetRenderers(go).ToList();
|
|
|
-
|
|
|
- foreach (var renderer in renderers)
|
|
|
- if (materialIndex < renderer.materials.Length)
|
|
|
- material = renderer.materials[materialIndex];
|
|
|
- }
|
|
|
-
|
|
|
- if (!material)
|
|
|
- continue;
|
|
|
-
|
|
|
- switch (data[0])
|
|
|
- {
|
|
|
- case "テクスチャ設定":
|
|
|
- ChangeTex(materialIndex, data[1], data[2].ToLower());
|
|
|
-
|
|
|
- break;
|
|
|
- case "色設定":
|
|
|
- material.SetColor(
|
|
|
- data[1],
|
|
|
- new(
|
|
|
- float.Parse(data[2]) / 255f, float.Parse(data[3]) / 255f,
|
|
|
- float.Parse(data[4]) / 255f, float.Parse(data[5]) / 255f
|
|
|
- )
|
|
|
- );
|
|
|
-
|
|
|
- break;
|
|
|
- case "数値設定":
|
|
|
- material.SetFloat(data[1], float.Parse(data[2]));
|
|
|
-
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
+ renderers ??= GetRenderers(go).ToList();
|
|
|
|
|
|
- break;
|
|
|
- case IMode.TexChange:
|
|
|
- var matno = int.Parse(data[2]);
|
|
|
+ foreach (var renderer in renderers)
|
|
|
+ if (materialIndex < renderer.materials.Length)
|
|
|
+ material = renderer.materials[materialIndex];
|
|
|
+ }
|
|
|
|
|
|
- ChangeTex(matno, data[3], data[4].ToLower());
|
|
|
+ if (!material)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ if (header is "テクスチャ設定")
|
|
|
+ ChangeTex(materialIndex, data[1], data[2].ToLower());
|
|
|
+ else if (header is "色設定")
|
|
|
+ material.SetColor(
|
|
|
+ data[1],
|
|
|
+ new(
|
|
|
+ float.Parse(data[2]) / 255f, float.Parse(data[3]) / 255f, float.Parse(data[4]) / 255f,
|
|
|
+ float.Parse(data[5]) / 255f
|
|
|
+ )
|
|
|
+ );
|
|
|
+ else if (header is "数値設定")
|
|
|
+ material.SetFloat(data[1], float.Parse(data[2]));
|
|
|
+ }
|
|
|
+ else if (mode is IMode.TexChange)
|
|
|
+ {
|
|
|
+ var matno = int.Parse(data[2]);
|
|
|
|
|
|
- break;
|
|
|
- case IMode.None:
|
|
|
- break;
|
|
|
- default:
|
|
|
- throw new ArgumentOutOfRangeException();
|
|
|
+ ChangeTex(matno, data[3], data[4].ToLower());
|
|
|
}
|
|
|
+ else if (mode is IMode.None)
|
|
|
+ continue;
|
|
|
+ else
|
|
|
+ throw new ArgumentOutOfRangeException(nameof(mode));
|
|
|
}
|
|
|
|
|
|
void ChangeTex(int matno, string prop, string filename)
|