Browse Source

Add mod_*.mod spawning and tweak bg2 item sort

The item sort sorted the icon's filename rather than the mod's name. The
sort kind of matches up to how com3d2 sorts menus.

ProcModScriptBin and ChangeTex have been "appropriated" to spawn
mod_*.mod files
habeebweeb 4 years ago
parent
commit
fdeecdca32

+ 209 - 81
MultipleMaids/CM3D2/MultipleMaids/Plugin/MultipleMaids.Gui.cs

@@ -660,8 +660,7 @@ namespace CM3D2.MultipleMaids.Plugin
                 GUI.enabled = false;
             }
 
-            characterMgr.GetStockMaidCount();
-            float pix = GetPix(45);
+            int iconSize = GetPix(45);
             Rect position1;
             Rect viewRect;
             if (sceneLevel != 5)
@@ -673,7 +672,7 @@ namespace CM3D2.MultipleMaids.Plugin
                 viewRect = new Rect(0.0f,
                                     0.0f,
                                     position1.width * 0.845f,
-                                    Mathf.Ceil(sortList.Count / 4 + 1) * pix + GetPix(10));
+                                    Mathf.Ceil(sortList.Count / 4f) * iconSize + GetPix(10));
             }
             else
             {
@@ -684,57 +683,84 @@ namespace CM3D2.MultipleMaids.Plugin
                 viewRect = new Rect(0.0f,
                                     0.0f,
                                     position1.width * 0.845f,
-                                    Mathf.Ceil(sortList.Count / 4 + 1) * pix + GetPix(10));
+                                    Mathf.Ceil(sortList.Count / 4f) * iconSize + GetPix(10));
             }
 
             bg2ScrollPos = GUI.BeginScrollView(position1, bg2ScrollPos, viewRect);
             for (int index = 0; index < sortList.Count; ++index)
             {
-                Rect position2 = new Rect(index % 4 * GetPix(45),
-                                           index / 4 * GetPix(45),
-                                           GetPix(44),
-                                           GetPix(44));
-                if (GUI.Button(position2, sortList[index].tex))
-                {
-                    string menu = sortList[index].menu;
-                    byte[] f_byBuf = null;
+                SortItem sortItem = sortList[index];
+                Rect position2 = new Rect(
+                    index % 4 * iconSize,
+                    index / 4 * iconSize,
+                    iconSize,
+                    iconSize
+                );
+                if (GUI.Button(position2, ""))
+                {
+                    string menu = sortItem.menu;
+                    byte[] modBuf = null;
+                    bool ready = true;
+                    if (sortItem.isOfficialMod)
+                    {
+                        menu = sortItem.baseItem;
+
+                        using (FileStream fileStream = new FileStream(sortItem.menu, FileMode.Open))
+                        {
+                            if (fileStream == null)
+                            {
+                                ready = false;
+                            }
+                            else
+                            {
+                                modBuf = new byte[fileStream.Length];
+                                fileStream.Read(modBuf, 0, (int)fileStream.Length);
+                            }
+                        }
+                    }
+                    byte[] menuBuf = null;
                     using (AFileBase afileBase = GameUty.FileOpen(menu, null))
                     {
-                        NDebug.Assert(afileBase.IsValid(), "メニューファイルが存在しません。 :" + menu);
-                        if (f_byBuf == null || f_byBuf.Length < afileBase.GetSize())
+                        if (ready = afileBase.IsValid())
                         {
-                            f_byBuf = new byte[afileBase.GetSize()];
+                            menuBuf = afileBase.ReadAll();
                         }
+                    }
 
-                        afileBase.Read(ref f_byBuf, afileBase.GetSize());
+                    if (ready)
+                    {
+                        string[] meshInfo = ProcScriptBin(menuBuf);
+                        GameObject gameObject = ImportCM2.LoadSkinMesh_R(meshInfo[0], meshInfo, 1);
+                        gameObject.name = menu;
+                        if (sortItem.isOfficialMod)
+                        {
+                            gameObject.name += $"#{Path.GetFileName(sortItem.menu)}";
+                            ProcModScriptBin(modBuf, gameObject);
+                        }
+                        doguBObject.Add(gameObject);
+                        Vector3 zero1 = Vector3.zero;
+                        Vector3 zero2 = Vector3.zero;
+                        zero1.z = 0.4f;
+                        gameObject.transform.localPosition = zero1;
+                        gameObject.transform.localRotation = Quaternion.Euler(zero2);
+                        doguCnt = doguBObject.Count - 1;
+                        gDogu[doguCnt] = GameObject.CreatePrimitive(PrimitiveType.Cube);
+                        gDogu[doguCnt].GetComponent<Renderer>().material = m_material;
+                        gDogu[doguCnt].layer = 8;
+                        gDogu[doguCnt].GetComponent<Renderer>().enabled = false;
+                        gDogu[doguCnt].SetActive(false);
+                        gDogu[doguCnt].transform.position = gameObject.transform.position;
+                        mDogu[doguCnt] = gDogu[doguCnt].AddComponent<MouseDrag6>();
+                        mDogu[doguCnt].isScale = false;
+                        mDogu[doguCnt].obj = gDogu[doguCnt];
+                        mDogu[doguCnt].maid = gameObject;
+                        mDogu[doguCnt].angles = gameObject.transform.eulerAngles;
+                        gDogu[doguCnt].transform.localScale = new Vector3(cubeSize, cubeSize, cubeSize);
+                        mDogu[doguCnt].ido = 1;
                     }
+                }
 
-                    string[] filename2 = ProcScriptBin(maidArray[0], f_byBuf, menu, false);
-                    GameObject gameObject = ImportCM2.LoadSkinMesh_R(filename2[0], filename2, "", maidArray[0].body0.goSlot[8], 1);
-                    doguBObject.Add(gameObject);
-                    gameObject.name = menu;
-                    Vector3 zero1 = Vector3.zero;
-                    Vector3 zero2 = Vector3.zero;
-                    zero1.z = 0.4f;
-                    gameObject.transform.localPosition = zero1;
-                    gameObject.transform.localRotation = Quaternion.Euler(zero2);
-                    doguCnt = doguBObject.Count - 1;
-                    gDogu[doguCnt] = GameObject.CreatePrimitive(PrimitiveType.Cube);
-                    gDogu[doguCnt].GetComponent<Renderer>().material = m_material;
-                    gDogu[doguCnt].layer = 8;
-                    gDogu[doguCnt].GetComponent<Renderer>().enabled = false;
-                    gDogu[doguCnt].SetActive(false);
-                    gDogu[doguCnt].transform.position = gameObject.transform.position;
-                    mDogu[doguCnt] = gDogu[doguCnt].AddComponent<MouseDrag6>();
-                    mDogu[doguCnt].isScale = false;
-                    mDogu[doguCnt].obj = gDogu[doguCnt];
-                    mDogu[doguCnt].maid = gameObject;
-                    mDogu[doguCnt].angles = gameObject.transform.eulerAngles;
-                    gDogu[doguCnt].transform.localScale = new Vector3(cubeSize, cubeSize, cubeSize);
-                    mDogu[doguCnt].ido = 1;
-                }
-
-                GUI.DrawTexture(position2, sortList[index].tex);
+                GUI.DrawTexture(position2, sortItem.tex);
             }
 
             GUI.EndScrollView();
@@ -852,8 +878,8 @@ namespace CM3D2.MultipleMaids.Plugin
                     afileBase.Read(ref f_byBuf, afileBase.GetSize());
                 }
 
-                string[] filename2 = ProcScriptBin(maidArray[0], f_byBuf, str, false);
-                GameObject gameObject = ImportCM2.LoadSkinMesh_R(filename2[0], filename2, "", maidArray[0].body0.goSlot[8], 1);
+                string[] filename2 = ProcScriptBin(f_byBuf);
+                GameObject gameObject = ImportCM2.LoadSkinMesh_R(filename2[0], filename2, 1);
                 doguBObject.Add(gameObject);
                 gameObject.name = str;
                 Vector3 zero1 = Vector3.zero;
@@ -1070,24 +1096,25 @@ namespace CM3D2.MultipleMaids.Plugin
             slotIndex = num1;
             sortList.Clear();
             bg2ScrollPos = new Vector2(0.0f, 0.0f);
+
             if (itemDataList.Count == 0)
             {
+                #region menu files
                 foreach (string menuFile in GameUty.MenuFiles)
                 {
                     string fileName = Path.GetFileName(menuFile);
-                    byte[] f_byBuf = null;
-                    using (AFileBase afileBase = GameUty.FileOpen(fileName, null))
+                    byte[] buf;
+                    using (AFileBase aFileBase = GameUty.FileOpen(menuFile))
                     {
-                        NDebug.Assert(afileBase.IsValid(), "メニューファイルが存在しません。 :" + fileName);
-                        if (f_byBuf == null || f_byBuf.Length < afileBase.GetSize())
+                        if (!aFileBase.IsValid())
                         {
-                            f_byBuf = new byte[afileBase.GetSize()];
+                            continue;
                         }
-
-                        afileBase.Read(ref f_byBuf, afileBase.GetSize());
+                        buf = aFileBase.ReadAll();
                     }
 
-                    BinaryReader binaryReader = new BinaryReader(new MemoryStream(f_byBuf), Encoding.UTF8);
+                    ItemData item = new ItemData() { menu = fileName };
+                    BinaryReader binaryReader = new BinaryReader(new MemoryStream(buf), Encoding.UTF8);
                     if (binaryReader.ReadString() != "CM3D2_MENU")
                     {
                         binaryReader.Close();
@@ -1098,75 +1125,176 @@ namespace CM3D2.MultipleMaids.Plugin
                         {
                             binaryReader.ReadInt32();
                             binaryReader.ReadString();
-                            binaryReader.ReadString();
-                            string str1 = binaryReader.ReadString();
-                            string s = "";
+                            item.name = binaryReader.ReadString();
+                            item.category = binaryReader.ReadString();
                             binaryReader.ReadString();
                             binaryReader.ReadInt32();
-                            string str2 = "";
+                            bool run = true;
                             do
                             {
-                                int num2;
+                                int size;
                                 do
                                 {
-                                    num2 = binaryReader.ReadByte();
-                                } while (num2 == 0);
+                                    size = binaryReader.ReadByte();
+                                } while (size == 0);
 
-                                for (int index = 0; index < num2; ++index)
+                                for (int index = 0; index < size; ++index)
                                 {
-                                    string str3 = binaryReader.ReadString();
-                                    if (str3 == "icons" || str3 == "icon")
+                                    string header = binaryReader.ReadString();
+                                    if (header == "icons" || header == "icon")
                                     {
-                                        str2 = binaryReader.ReadString();
+                                        run = false;
+                                        item.icon = binaryReader.ReadString();
                                         break;
                                     }
 
-                                    if (str3 == "priority")
+                                    if (header == "priority")
                                     {
-                                        s = binaryReader.ReadString();
+                                        int.TryParse(binaryReader.ReadString(), out item.priority);
                                         break;
                                     }
                                 }
-                            } while (str2 == "");
+                            } while (run);
 
-                            int.TryParse(s, out int result);
-                            itemDataList.Add(new ItemData() { info = str1, name = str2, menu = fileName, order = result, cd = f_byBuf });
+                            itemDataList.Add(item);
                         }
                         catch { }
 
                         binaryReader.Close();
                     }
                 }
+                #endregion
+
+                #region mod files
+                foreach (string modFile in Menu.GetModFiles())
+                {
+                    byte[] buf = null;
+                    try
+                    {
+                        using (FileStream fileStream = new FileStream(modFile, FileMode.Open))
+                        {
+                            if (fileStream == null)
+                            {
+                                continue;
+                            }
+                            buf = new byte[fileStream.Length];
+                            fileStream.Read(buf, 0, (int)fileStream.Length);
+                        }
+                    }
+                    catch { }
+
+                    if (buf == null)
+                    {
+                        continue;
+                    }
+
+                    ItemData item = new ItemData()
+                    {
+                        isOfficialMod = true,
+                        menu = modFile,
+                        priority = 1000
+                    };
+
+                    BinaryReader binaryReader = new BinaryReader(new MemoryStream(buf), Encoding.UTF8);
+                    if (binaryReader.ReadString() != "CM3D2_MOD")
+                    {
+                        binaryReader.Close();
+                    }
+                    else
+                    {
+                        try
+                        {
+                            binaryReader.ReadInt32();
+                            string iconName = binaryReader.ReadString();
+                            string baseItemPath = binaryReader.ReadString().Replace(":", " ");
+                            item.baseItem = Path.GetFileName(baseItemPath);
+                            item.name = binaryReader.ReadString();
+                            item.category = binaryReader.ReadString();
+                            binaryReader.ReadString();
+                            string mpnValue = binaryReader.ReadString();
+                            MPN mpn = MPN.null_mpn;
+                            try
+                            {
+                                mpn = (MPN)Enum.Parse(typeof(MPN), mpnValue, true);
+                            }
+                            catch
+                            {
+                                binaryReader.Close();
+                                continue;
+                            }
+                            if (mpn != MPN.null_mpn)
+                            {
+                                binaryReader.ReadString();
+                            }
+                            binaryReader.ReadString();
+                            int size = binaryReader.ReadInt32();
+                            for (int i = 0; i < size; i++)
+                            {
+                                string key = binaryReader.ReadString();
+                                int count = binaryReader.ReadInt32();
+                                byte[] data = binaryReader.ReadBytes(count);
+                                if (string.Equals(key, iconName, StringComparison.InvariantCultureIgnoreCase))
+                                {
+                                    Texture2D tex = new Texture2D(1, 1, TextureFormat.RGBA32, false);
+                                    tex.LoadImage(data);
+                                    item.tex = tex;
+                                    break;
+                                }
+                            }
+                            itemDataList.Add(item);
+                        }
+                        catch { }
+                        binaryReader.Close();
+                    }
+                }
+                #endregion
+            }
+
+            if (slotIndex == 0)
+            {
+                return;
             }
 
             foreach (ItemData itemData in itemDataList)
             {
-                if (slotIndex != 0 && itemData.info == slotArray[slotIndex] && itemData.order > 0)
+                if (itemData.category == slotArray[slotIndex] && itemData.priority > 0)
                 {
-                    sortList.Add(new SortItem() { order = itemData.order, name = itemData.name, menu = itemData.menu, tex = itemData.tex });
+                    sortList.Add(new SortItem()
+                    {
+                        category = itemData.category,
+                        priority = itemData.priority,
+                        name = itemData.name,
+                        icon = itemData.icon,
+                        menu = itemData.menu,
+                        tex = itemData.tex,
+                        isOfficialMod = itemData.isOfficialMod,
+                        baseItem = itemData.baseItem
+                    });
                 }
             }
 
-            IOrderedEnumerable<SortItem> orderedEnumerable = sortList
-                                                             .OrderBy(p => p.order)
-                                                             .ThenBy(p => p.name);
+            IOrderedEnumerable<SortItem> sortedItemList = sortList
+                .OrderBy(item => item.priority)
+                .ThenBy(item => item.name);
+
             List<SortItem> sortItemList = new List<SortItem>();
-            string str4 = "";
-            foreach (SortItem sortItem in orderedEnumerable)
+
+            string previousMenu = "";
+            foreach (SortItem item in sortedItemList)
             {
                 try
                 {
-                    if (!(sortItem.menu == str4))
+                    if (item.menu != previousMenu)
                     {
-                        if (sortItem.tex == null)
+                        if (item.tex == null)
                         {
-                            byte[] data = ImportCM.LoadTexture(GameUty.FileSystem, sortItem.name, false).data;
+                            byte[] data = ImportCM.LoadTexture(GameUty.FileSystem, item.icon, false).data;
                             Texture2D texture2D = new Texture2D(50, 50, TextureFormat.RGB565, false);
                             texture2D.LoadImage(data);
-                            sortItem.tex = texture2D;
+                            item.tex = texture2D;
                         }
-                        str4 = sortItem.menu;
-                        sortItemList.Add(sortItem);
+                        previousMenu = item.menu;
+                        sortItemList.Add(item);
                     }
                 }
                 catch { }

+ 48 - 9
MultipleMaids/CM3D2/MultipleMaids/Plugin/MultipleMaids.Update.cs

@@ -8,7 +8,6 @@ using UnityEngine;
 using UnityEngine.PostProcessing;
 using UnityEngine.Rendering;
 using Object = UnityEngine.Object;
-using Util;
 
 namespace CM3D2.MultipleMaids.Plugin
 {
@@ -4733,6 +4732,7 @@ namespace CM3D2.MultipleMaids.Plugin
                     }
 
                     doguBObject = new List<GameObject>();
+                    Dictionary<string, string> modFiles = null;
                     for (int index1 = 0; index1 < strArray6.Length - 1; ++index1)
                     {
                         string[] strArray8 = strArray6[index1].Split(',');
@@ -4741,22 +4741,61 @@ namespace CM3D2.MultipleMaids.Plugin
                         bool flag1 = true;
                         if (str1.Contains(".menu"))
                         {
-                            string str2 = str1;
-                            byte[] f_byBuf = null;
-                            using (AFileBase afileBase = GameUty.FileOpen(str2, null))
+                            string mainMenu = str1;
+                            string modMenu = null;
+                            int modMenuPos = str1.IndexOf("#");
+                            if (modMenuPos >= 0)
+                            {
+                                if (modFiles == null)
+                                {
+                                    modFiles = new Dictionary<string, string>();
+                                    foreach (string filePath in Menu.GetModFiles())
+                                    {
+                                        string filename = Path.GetFileName(filePath).ToLowerInvariant();
+                                        if (!modFiles.ContainsKey(filename)) modFiles.Add(filename, filePath);
+                                    }
+                                }
+                                string modFilename = strArray8[0].Substring(modMenuPos + 1).Replace(" ", "_").ToLowerInvariant();
+                                modMenu = modFiles[modFilename];
+                                mainMenu = str1.Substring(0, modMenuPos);
+                            }
+                            byte[] modBuf = null;
+
+                            if (!string.IsNullOrEmpty(modMenu))
+                            {
+                                using (FileStream fileStream = new FileStream(modMenu, FileMode.Open))
+                                {
+                                    if (fileStream != null)
+                                    {
+                                        modBuf = new byte[fileStream.Length];
+                                        fileStream.Read(modBuf, 0, (int)fileStream.Length);
+                                    }
+                                    else
+                                    {
+                                        flag1 = false;
+                                    }
+                                }
+                            }
+
+                            byte[] menuBuf = null;
+                            using (AFileBase afileBase = GameUty.FileOpen(mainMenu, null))
                             {
                                 if (flag1 = afileBase.IsValid())
                                 {
-                                    f_byBuf = new byte[afileBase.GetSize()];
-                                    afileBase.Read(ref f_byBuf, afileBase.GetSize());
+                                    menuBuf = afileBase.ReadAll();
                                 }
                             }
                             if (flag1)
                             {
-                                string[] filename2 = ProcScriptBin(maidArray[0], f_byBuf, str2, false);
-                                original1 = ImportCM2.LoadSkinMesh_R(filename2[0], filename2, "", maidArray[0].body0.goSlot[8], 1);
+                                string[] meshInfo = ProcScriptBin(menuBuf);
+                                original1 = ImportCM2.LoadSkinMesh_R(meshInfo[0], meshInfo, 1);
+                                original1.name = mainMenu;
+                                if (modBuf != null)
+                                {
+                                    original1.name += $"#{Path.GetFileName(modMenu)}";
+                                    ProcModScriptBin(modBuf, original1);
+                                }
                                 doguBObject.Add(original1);
-                                original1.name = str2;
                                 Vector3 zero1 = Vector3.zero;
                                 Vector3 zero2 = Vector3.zero;
                                 zero1.z = 0.4f;

+ 144 - 20
MultipleMaids/CM3D2/MultipleMaids/Plugin/MultipleMaids.cs

@@ -5397,10 +5397,8 @@ namespace CM3D2.MultipleMaids.Plugin
             return texture2D;
         }
 
-        private static string[] ProcScriptBin(Maid maid, byte[] cd, string filename, bool f_bTemp)
+        private static string[] ProcScriptBin(byte[] cd)
         {
-            f_bTemp = false;
-            TBody body0 = maid.body0;
             List<LastParam> lastParamList = new List<LastParam>();
             BinaryReader binaryReader = new BinaryReader(new MemoryStream(cd), Encoding.UTF8);
             string str1 = binaryReader.ReadString();
@@ -5415,7 +5413,7 @@ namespace CM3D2.MultipleMaids.Plugin
             string str2 = string.Empty;
             string empty1 = string.Empty;
             string empty2 = string.Empty;
-            string[] strArray = new string[maxMaidCnt];
+            string[] strArray = new string[100];
             int num2 = 0;
             try
             {
@@ -5475,16 +5473,6 @@ namespace CM3D2.MultipleMaids.Plugin
                         break;
                     }
                 }
-
-                lastParamList.Sort((a, b) => a.nOrder - a.nOrder);
-                for (int index = 0; index < lastParamList.Count; ++index)
-                {
-                    LastParam lastParam = lastParamList[index];
-                    if (lastParam.strComm == "アイテムパラメータ")
-                    {
-                        body0.GetSlot(lastParam.aryArgs[0]).SetParam(lastParam.aryArgs[1], lastParam.aryArgs[2]);
-                    }
-                }
             }
             catch (Exception ex)
             {
@@ -5496,7 +5484,137 @@ namespace CM3D2.MultipleMaids.Plugin
             return strArray;
         }
 
+        private static void ChangeTex(int matno, string prop, string filename, Dictionary<string, byte[]> matDict, GameObject go)
+        {
+            TextureResource textureResource = null;
+            byte[] buf = matDict[filename.ToLowerInvariant()];
+            textureResource = new TextureResource(2, 2, TextureFormat.ARGB32, null, buf);
+            List<Renderer> list = new List<Renderer>(3);
+            go.transform.GetComponentsInChildren<Renderer>(true, list);
+            foreach (Renderer r in list)
+            {
+                if (r != null && r.material != null)
+                {
+                    if (matno < r.materials.Length)
+                    {
+                        r.materials[matno].SetTexture(prop, null);
+                        Texture2D texture2D = textureResource.CreateTexture2D();
+                        texture2D.name = filename;
+                        r.materials[matno].SetTexture(prop, texture2D);
+                    }
+                }
+            }
+        }
+
+        private static void ProcModScriptBin(byte[] cd, GameObject go)
+        {
+            BinaryReader binaryReader = new BinaryReader(new MemoryStream(cd), Encoding.UTF8);
+            string str1 = binaryReader.ReadString();
+            NDebug.Assert(str1 == "CM3D2_MOD", "ProcModScriptBin 例外 : ヘッダーファイルが不正です。" + str1);
+            binaryReader.ReadInt32();
+            binaryReader.ReadString();
+            binaryReader.ReadString();
+            binaryReader.ReadString();
+            binaryReader.ReadString();
+            binaryReader.ReadString();
+            string mpnValue = binaryReader.ReadString();
+            MPN mpn = MPN.null_mpn;
+            try
+            {
+                mpn = (MPN)Enum.Parse(typeof(MPN), mpnValue);
+            }
+            catch { }
+            if (mpn != MPN.null_mpn)
+            {
+                binaryReader.ReadString();
+            }
+            string s = binaryReader.ReadString();
+            int num2 = binaryReader.ReadInt32();
+            Dictionary<string, byte[]> dictionary = new Dictionary<string, byte[]>();
+            for (int i = 0; i < num2; i++)
+            {
+                string key = binaryReader.ReadString();
+                int count = binaryReader.ReadInt32();
+                byte[] value = binaryReader.ReadBytes(count);
+                dictionary.Add(key, value);
+            }
+            binaryReader.Close();
+
+            using (StringReader stringReader = new StringReader(s))
+            {
+                string mode = "";
+                string slotname = String.Empty;
+                Material material = null;
+                int num3 = 0;
+                string line;
+                bool change = false;
+                while ((line = stringReader.ReadLine()) != null)
+                {
+                    string[] array = line.Split(new char[] { '\t', ' ' },
+                        StringSplitOptions.RemoveEmptyEntries);
 
+                    if (array[0] == "アイテム変更" || array[0] == "マテリアル変更")
+                    {
+                        mode = "ItemChange";
+                    }
+                    else if (array[0] == "テクスチャ変更")
+                    {
+                        mode = "TexChange";
+                    }
+                    if (mode == "ItemChange")
+                    {
+                        if (array[0] == "スロット名")
+                        {
+                            slotname = array[1];
+                            change = true;
+                        }
+                        if (change)
+                        {
+                            if (array[0] == "マテリアル番号")
+                            {
+                                num3 = int.Parse(array[1]);
+                                foreach (Transform transform in go.GetComponentsInChildren<Transform>(true))
+                                {
+                                    Renderer component = transform.GetComponent<Renderer>();
+                                    if (component != null && component.materials != null)
+                                    {
+                                        Material[] materials = component.materials;
+                                        for (int k = 0; k < materials.Length; k++)
+                                        {
+                                            if (k == num3)
+                                            {
+                                                material = materials[k];
+                                                break;
+                                            }
+                                        }
+                                    }
+                                }
+                            }
+                            if (material != null)
+                            {
+                                if (array[0] == "テクスチャ設定")
+                                {
+                                    ChangeTex(num3, array[1], array[2].ToLower(), dictionary, go);
+                                }
+                                else if (array[0] == "色設定")
+                                {
+                                    material.SetColor(array[1], new Color(float.Parse(array[2]) / 255f, float.Parse(array[3]) / 255f, float.Parse(array[4]) / 255f, float.Parse(array[5]) / 255f));
+                                }
+                                else if (array[0] == "数値設定")
+                                {
+                                    material.SetFloat(array[1], float.Parse(array[2]));
+                                }
+                            }
+                        }
+                    }
+                    else if (mode == "TexChange")
+                    {
+                        int matno = int.Parse(array[2]);
+                        ChangeTex(matno, array[3], array[4].ToLower(), dictionary, go);
+                    }
+                }
+            }
+        }
         private enum modKey
         {
             Shift,
@@ -5521,20 +5639,26 @@ namespace CM3D2.MultipleMaids.Plugin
 
         private class SortItem
         {
+            public string category = String.Empty;
             public string menu = string.Empty;
             public string name = string.Empty;
-            public int order;
+            public string icon = string.Empty;
+            public bool isOfficialMod = false;
+            public string baseItem = string.Empty;
+            public int priority;
             public Texture2D tex;
         }
 
         private class ItemData
         {
-            public byte[] cd;
-            public string info = string.Empty;
+            public string category = string.Empty;
             public string menu = string.Empty;
             public string name = string.Empty;
-            public int order;
-            public readonly Texture2D tex = null;
+            public string icon = string.Empty;
+            public string baseItem = string.Empty;
+            public bool isOfficialMod = false;
+            public int priority = -1;
+            public Texture2D tex = null;
 
             public override bool Equals(object obj)
             {
@@ -5544,7 +5668,7 @@ namespace CM3D2.MultipleMaids.Plugin
                     return false;
                 }
 
-                return name == itemData.name && menu == itemData.menu;
+                return icon == itemData.icon && menu == itemData.menu;
             }
 
             public override int GetHashCode()

+ 21 - 38
MultipleMaids/ImportCM2.cs

@@ -19,7 +19,7 @@ public class ImportCM2 : MonoBehaviour
             "m_LocalPosition.z"
     };
 
-    public static GameObject LoadSkinMesh_R(string filename, string[] filename2, string slotname, TBodySkin bodyskin, int layer)
+    public static GameObject LoadSkinMesh_R(string filename, string[] filename2, int layer)
     {
         try
         {
@@ -38,10 +38,10 @@ public class ImportCM2 : MonoBehaviour
         }
 
         var r = new BinaryReader(new MemoryStream(m_skinTempFile), Encoding.UTF8);
-        TBodySkin.OriVert oriVert = bodyskin.m_OriVert;
+        TBodySkin.OriVert oriVert = new TBodySkin.OriVert();
         var gameObject1 = Instantiate(Resources.Load("seed")) as GameObject;
         gameObject1.layer = layer;
-        var gameObject2 = (GameObject) null;
+        var gameObject2 = (GameObject)null;
         var hashtable = new Hashtable();
         string str1 = r.ReadString();
         if (str1 != "CM3D2_MESH")
@@ -113,8 +113,8 @@ public class ImportCM2 : MonoBehaviour
             if (hashtable.ContainsKey(str4))
             {
                 GameObject gameObject3 = !hashtable.ContainsKey(str4 + "&_SCL_")
-                                                 ? (GameObject) hashtable[str4]
-                                                 : (GameObject) hashtable[str4 + "&_SCL_"];
+                                                 ? (GameObject)hashtable[str4]
+                                                 : (GameObject)hashtable[str4 + "&_SCL_"];
                 transformArray[index] = gameObject3.transform;
             }
         }
@@ -125,8 +125,8 @@ public class ImportCM2 : MonoBehaviour
         Mesh mesh2 = mesh1;
         var matrix4x4Array = new Matrix4x4[length3];
         for (int index1 = 0; index1 < length3; ++index1)
-        for (int index2 = 0; index2 < 16; ++index2)
-            matrix4x4Array[index1][index2] = r.ReadSingle();
+            for (int index2 = 0; index2 < 16; ++index2)
+                matrix4x4Array[index1][index2] = r.ReadSingle();
         mesh2.bindposes = matrix4x4Array;
         var vector3Array1 = new Vector3[length1];
         var vector3Array2 = new Vector3[length1];
@@ -199,7 +199,7 @@ public class ImportCM2 : MonoBehaviour
         var materialArray = new Material[length6];
         for (int index = 0; index < length6; ++index)
         {
-            Material material = ReadMaterial(r, bodyskin, null, filename2[1 + index]);
+            Material material = ReadMaterial(r, filename2[1 + index]);
             materialArray[index] = material;
         }
 
@@ -208,10 +208,8 @@ public class ImportCM2 : MonoBehaviour
         return gameObject1;
     }
 
-    public static Material ReadMaterial(BinaryReader r, TBodySkin bodyskin, Material existmat, string filename)
+    public static Material ReadMaterial(BinaryReader r, string filename)
     {
-        bodyskin = null;
-        existmat = null;
         if (m_hashPriorityMaterials == null)
         {
             m_hashPriorityMaterials = new Dictionary<int, KeyValuePair<string, float>>();
@@ -242,18 +240,11 @@ public class ImportCM2 : MonoBehaviour
         string str2 = r.ReadString();
         string path1 = "DefMaterial/" + r.ReadString();
         Material material;
-        if (existmat == null)
-        {
-            var original = Resources.Load(path1, typeof(Material)) as Material;
-            if (original == null)
-                return original;
-            material = Instantiate(original);
-        }
-        else
-        {
-            material = existmat;
-            NDebug.Assert(material.shader.name == str2, "マテリアル入れ替えエラー。違うシェーダーに入れようとしました。 " + str2 + " -> " + material.shader.name);
-        }
+
+        var original = Resources.Load(path1, typeof(Material)) as Material;
+        if (original == null)
+            return original;
+        material = Instantiate(original);
 
         material.name = str1;
         int hashCode1 = material.name.GetHashCode();
@@ -263,7 +254,7 @@ public class ImportCM2 : MonoBehaviour
             if (priorityMaterial.Key == material.name)
             {
                 material.SetFloat("_SetManualRenderQueue", priorityMaterial.Value);
-                material.renderQueue = (int) priorityMaterial.Value;
+                material.renderQueue = (int)priorityMaterial.Value;
             }
         }
 
@@ -372,18 +363,10 @@ public class ImportCM2 : MonoBehaviour
             string str7 = r.ReadString();
             string str8 = r.ReadString();
             string path2 = "DefMaterial/" + r.ReadString();
-            if (existmat == null)
-            {
-                var original = Resources.Load(path2, typeof(Material)) as Material;
-                if (original == null)
-                    return original;
-                material = Instantiate(original);
-            }
-            else
-            {
-                material = existmat;
-                NDebug.Assert(material.shader.name == str8, "マテリアル入れ替えエラー。違うシェーダーに入れようとしました。 " + str8 + " -> " + material.shader.name);
-            }
+            var original2 = Resources.Load(path2, typeof(Material)) as Material;
+            if (original2 == null)
+                return original2;
+            material = Instantiate(original2);
 
             material.name = str7;
             int hashCode2 = material.name.GetHashCode();
@@ -393,7 +376,7 @@ public class ImportCM2 : MonoBehaviour
                 if (priorityMaterial.Key == material.name)
                 {
                     material.SetFloat("_SetManualRenderQueue", priorityMaterial.Value);
-                    material.renderQueue = (int) priorityMaterial.Value;
+                    material.renderQueue = (int)priorityMaterial.Value;
                 }
             }
 
@@ -471,4 +454,4 @@ public class ImportCM2 : MonoBehaviour
 
         return material;
     }
-}
+}