Browse Source

Merge branch 'master' of https://git.coder.horse/meidomustard/modifiedMM

habeebweeb 4 years ago
parent
commit
3452a9c59f

+ 13 - 0
MultipleMaids/CM3D2/MultipleMaids/Plugin/MultipleMaids.Config.cs

@@ -87,6 +87,19 @@ namespace CM3D2.MultipleMaids.Plugin
                 }
             }
 
+            IniKey modsOnlyKey = Preferences["config"]["mods_only"];
+            if (modsOnlyKey.Value == "true")
+            {
+                modItemsOnly = true;
+                modItemsToggle = true;
+            }
+            else if (modsOnlyKey.Value != "false")
+            {
+                Preferences["config"]["mods_only"].Value = "false";
+                SaveConfig();
+                modItemsOnly = false;
+            }
+
             if (!int.TryParse(Preferences["config"]["scene_max"].Value, out maxPage))
             {
                 maxPage = 100;

+ 261 - 85
MultipleMaids/CM3D2/MultipleMaids/Plugin/MultipleMaids.Gui.cs

@@ -375,10 +375,24 @@ namespace CM3D2.MultipleMaids.Plugin
                 GUI.enabled = false;
             }
 
-            characterMgr.GetStockMaidCount();
-            float pix = GetPix(45);
+            bool previousGUIState = GUI.enabled;
+            GUI.enabled = !modItemsOnly;
+
+            modItemsToggle = GUI.Toggle(new Rect(GetPix(156),
+                GetPix(115),
+                GetPix(50),
+                GetPix(20)),
+                modItemsToggle,
+                "Mods",
+                style3
+            );
+
+            GUI.enabled = previousGUIState;
+
+            int iconSize = GetPix(45);
             Rect position1;
             Rect viewRect;
+            int bg2ItemCount = (!modItemsOnly && modItemsToggle) ? numberOfModItems : sortList.Count;
             if (sceneLevel != 5)
             {
                 position1 = new Rect(GetPix(7),
@@ -388,7 +402,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(bg2ItemCount / 4f) * iconSize + GetPix(10));
             }
             else
             {
@@ -399,57 +413,89 @@ 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(bg2ItemCount / 4f) * iconSize + GetPix(10));
             }
 
             bg2ScrollPos = GUI.BeginScrollView(position1, bg2ScrollPos, viewRect);
-            for (int index = 0; index < sortList.Count; ++index)
+            int bg2Index = 0;
+            foreach (SortItem sortItem in sortList)
             {
-                Rect position2 = new Rect(index % 4 * GetPix(45),
-                                           index / 4 * GetPix(45),
-                                           GetPix(44),
-                                           GetPix(44));
-                if (GUI.Button(position2, sortList[index].tex))
+                if (modItemsToggle && !sortItem.isMod)
                 {
-                    string menu = sortList[index].menu;
-                    byte[] f_byBuf = null;
+                    continue;
+                }
+                Rect position2 = new Rect(
+                    bg2Index % 4 * iconSize,
+                    bg2Index / 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);
+                bg2Index++;
             }
 
             GUI.EndScrollView();
@@ -578,8 +624,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;
@@ -704,27 +750,41 @@ namespace CM3D2.MultipleMaids.Plugin
                 return;
             }
 
+            numberOfModItems = 0;
             slotIndex = num1;
             sortList.Clear();
             bg2ScrollPos = new Vector2(0.0f, 0.0f);
+
             if (itemDataList.Count == 0)
             {
-                foreach (string menuFile in GameUty.MenuFiles)
+                #region menu files
+                HashSet<string> modMenus = null;
+                if (!modItemsOnly)
+                {
+                    modMenus = new HashSet<string>(GameUty.ModOnlysMenuFiles
+                        .Select(file => Path.GetFileName(file).ToLowerInvariant()));
+                }
+
+                string[] menuFiles = modItemsOnly ? GameUty.ModOnlysMenuFiles : GameUty.MenuFiles;
+                foreach (string menuFile in 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,
+                        isMod = modItemsOnly ? true : modMenus.Contains(fileName)
+                    };
+                    BinaryReader binaryReader = new BinaryReader(new MemoryStream(buf), Encoding.UTF8);
                     if (binaryReader.ReadString() != "CM3D2_MENU")
                     {
                         binaryReader.Close();
@@ -735,75 +795,179 @@ 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()
+                    {
+                        isMod = true,
+                        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,
+                        isMod = itemData.isMod,
+                        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 (!modItemsOnly && item.isMod) numberOfModItems++;
+                        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 { }
@@ -8440,7 +8604,7 @@ namespace CM3D2.MultipleMaids.Plugin
             {
                 mFontSize = fontSize;
                 GameObject gameObject = GameObject.Find("__GameMain__/SystemUI Root").transform.Find("MessageWindowPanel").gameObject;
-                MessageClass messageClass = new MessageClass(gameObject, GameMain.Instance.ScriptMgr.adv_kag.MessageWindowMgr);
+                //MessageClass messageClass = new MessageClass(gameObject, GameMain.Instance.ScriptMgr.adv_kag.MessageWindowMgr);
                 SetFieldValue2<UILabel, int>(UTY.GetChildObject(gameObject, "MessageViewer/MsgParent/Message", false)
                                                 .GetComponent<UILabel>(),
                                              "mFontSize",
@@ -8465,11 +8629,23 @@ namespace CM3D2.MultipleMaids.Plugin
                 GameObject gameObject1 = GameObject.Find("__GameMain__/SystemUI Root").transform.Find("MessageWindowPanel").gameObject;
                 MessageWindowMgr messageWindowMgr = GameMain.Instance.ScriptMgr.adv_kag.MessageWindowMgr;
                 messageWindowMgr.OpenMessageWindowPanel();
-                MessageClass inst = new MessageClass(gameObject1, messageWindowMgr);
+
                 UILabel component = UTY.GetChildObject(gameObject1, "MessageViewer/MsgParent/Message", false).GetComponent<UILabel>();
+                UILabel nameComponent = UTY.GetChildObject(gameObject1, "MessageViewer/MsgParent/SpeakerName/Name", false).GetComponent<UILabel>();
+
+                MessageClass inst = new MessageClass(gameObject1, messageWindowMgr);
+                // Fix for ENG version: reconfigure MessageClass to behave as in JP game
+                inst.subtitles_manager_.visible = false;
+                inst.subtitles_manager_ = null;
+                component.gameObject.SetActive(true);
+                nameComponent.gameObject.SetActive(true);
+                UTY.GetChildObject(gameObject1, "MessageViewer/MsgParent/MessageBox", false).SetActive(true);
+                SetFieldValue5<MessageClass, UILabel>(inst, "message_label_", component);
+                SetFieldValue5<MessageClass, UILabel>(inst, "name_label_", nameComponent);
+
                 component.ProcessText();
                 SetFieldValue2<UILabel, int>(component, "mFontSize", fontSize);
-                SetFieldValue5<MessageClass, UILabel>(inst, "message_label_", component);
+
                 inst.SetText(inName, inText, "", 0, AudioSourceMgr.Type.System);
                 inst.FinishChAnime();
             }

+ 157 - 435
MultipleMaids/CM3D2/MultipleMaids/Plugin/MultipleMaids.Init.cs

@@ -92,8 +92,6 @@ namespace CM3D2.MultipleMaids.Plugin
             isDance = false;
             isDanceChu = false;
             isSavePose = false;
-            // bgIndex = 0;
-            // bgIndexB = 0;
             bgIndex = bgCombo2.selectedItemIndex = bgCombo.selectedItemIndex = Array.FindIndex(bgArray, bg => bg == "Theater");
             bg.localScale = new Vector3(1f, 1f, 1f);
             softG = new Vector3(0.0f, -3f / 1000f, 0.0f);
@@ -439,9 +437,6 @@ namespace CM3D2.MultipleMaids.Plugin
             lightComboList[0] = new GUIContent("メイン");
             lightCombo.selectedItemIndex = 0;
             selectLightIndex = 0;
-            // bgCombo.selectedItemIndex = 0;
-            // kankyoCombo.selectedItemIndex = 0;
-            // bgCombo2.selectedItemIndex = 0;
             itemCombo2.selectedItemIndex = 0;
             slotCombo.selectedItemIndex = 0;
             sortList.Clear();
@@ -963,9 +958,6 @@ namespace CM3D2.MultipleMaids.Plugin
             lightComboList[0] = new GUIContent("メイン");
             lightCombo.selectedItemIndex = 0;
             selectLightIndex = 0;
-            // bgCombo.selectedItemIndex = 0;
-            // kankyoCombo.selectedItemIndex = 0;
-            // bgCombo2.selectedItemIndex = 0;
             itemCombo2.selectedItemIndex = 0;
             slotCombo.selectedItemIndex = 0;
             sortList.Clear();
@@ -999,31 +991,15 @@ namespace CM3D2.MultipleMaids.Plugin
             }
 
             doguObject.Clear();
-            string path1 = Path.GetFullPath(".\\") + "Mod\\MultipleMaidsPose";
-            if (!File.Exists(path1))
+            string mmPosePath = Path.GetFullPath(".\\") + "Mod\\MultipleMaidsPose";
+            if (!File.Exists(mmPosePath))
             {
-                Directory.CreateDirectory(path1);
+                Directory.CreateDirectory(mmPosePath);
             }
 
             int countS = this.countS;
-            Action<string, List<string>> action1 = (path, result_list) =>
-                                                            {
-                                                                string[] files = Directory.GetFiles(path);
-                                                                this.countS = 0;
-                                                                for (int index = 0; index < files.Length; ++index)
-                                                                {
-                                                                    if (Path.GetExtension(files[index]) == ".anm")
-                                                                    {
-                                                                        strListS.Add(files[index].Split('\\')[files[index]
-                                                                                                              .Split('\\').Length - 1]
-                                                                                                 .Split('.')[0] + "                    /"
-                                                                                                                + files[index]);
-                                                                        ++this.countS;
-                                                                    }
-                                                                }
-                                                            };
-            List<string> stringList1 = new List<string>();
-            action1(path1, stringList1);
+            this.countS = Directory.GetFiles(mmPosePath).Where(f => Path.GetExtension(f) == ".anm").Count();
+
             if (this.countS != countS)
             {
                 poseArray = null;
@@ -1034,84 +1010,6 @@ namespace CM3D2.MultipleMaids.Plugin
                 return;
             }
 
-            strList2 = new List<string>();
-            strListE = new List<string>();
-            strListE2 = new List<string>();
-            strListS = new List<string>();
-            strListD = new List<string>();
-            strS = "";
-            List<string> stringList2 = new List<string>
-            {
-                string.Empty
-            };
-            stringList2.AddRange(GameUty.PathList);
-            List<string> bgList2 = new List<string>();
-            Action<string> action2 = strFileName =>
-                                              {
-                                                  if (!GameUty.FileSystem.IsExistentFile(strFileName))
-                                                  {
-                                                      return;
-                                                  }
-
-                                                  using (AFileBase file = GameUty.FileSystem.FileOpen(strFileName))
-                                                  {
-                                                      using (CsvParser csvParser = new CsvParser())
-                                                      {
-                                                          csvParser.Open(file);
-                                                          for (int cell_y = 1; cell_y < csvParser.max_cell_y; ++cell_y)
-                                                          {
-                                                              if (csvParser.IsCellToExistData(0, cell_y))
-                                                              {
-                                                                  bgList2.Add(csvParser.GetCellAsString(1, cell_y));
-                                                              }
-                                                          }
-                                                      }
-                                                  }
-                                              };
-            action2("edit_bg.nei");
-            for (int index = 0; index < stringList2.Count; ++index)
-            {
-                action2("edit_bg_" + stringList2[index] + ".nei");
-            }
-
-            List<string> stringList3 = new List<string>();
-            for (int index1 = 0; index1 < bgList2.Count; ++index1)
-            {
-                bool flag = false;
-                for (int index2 = 0; index2 < bgArray21.Length; ++index2)
-                {
-                    if (bgList2[index1] == bgArray21[index2])
-                    {
-                        flag = true;
-                    }
-                }
-
-                if (!flag && bgList2[index1] != "HoneymoonRoom" && bgList2[index1] != "ClassRoom_Play" && bgList2[index1] != "BigSight"
-                    && bgList2[index1] != "PrivateRoom" && bgList2[index1] != "Sea_Night" && bgList2[index1] != "Yashiki")
-                {
-                    stringList3.Add(bgList2[index1]);
-                }
-            }
-
-            if (GameMain.Instance.BgMgr.CreateAssetBundle("SMRoom2") != null)
-            {
-                isVP = true;
-            }
-            if (GameMain.Instance.BgMgr.CreateAssetBundle("Train") != null)
-            {
-                isPP = true;
-            }
-
-            if (GameMain.Instance.BgMgr.CreateAssetBundle("HoneymoonRoom") != null)
-            {
-                isPP2 = true;
-            }
-
-            if (GameMain.Instance.BgMgr.CreateAssetBundle("BigSight") != null)
-            {
-                isPP3 = true;
-            }
-
             if (GameMain.Instance.BgMgr.CreateAssetBundle("rotenburo") != null)
             {
                 isVA = true;
@@ -1129,64 +1027,30 @@ namespace CM3D2.MultipleMaids.Plugin
 
             List<string> stringList4 = new List<string>(350 + poseArray2.Length);
             stringList4.AddRange(poseArray2);
+
             List<string> stringList5 = new List<string>();
-            for (int index = 11; index < 200; ++index)
+
+            // Seems to only produce 'edit_pose_027'
+            for (int poseIndex = 11; poseIndex < 100; poseIndex++)
             {
-                if (index < 100)
+                string pose = $"edit_pose_{poseIndex:000}_f";
+                if (GameUty.FileSystem.IsExistentFile($"{pose}.anm"))
                 {
-                    using (AFileBase afileBase1 = GameUty.FileSystem.FileOpen("edit_pose_0" + index + "_f.anm"))
-                    {
-                        if (afileBase1.IsValid())
-                        {
-                            stringList5.Add("edit_pose_0" + index + "_f");
-                        }
-                        else
-                        {
-                            using (AFileBase afileBase2 = GameUty.FileSystem.FileOpen("edit_pose_" + index + "_f.anm"))
-                            {
-                                if (afileBase2.IsValid())
-                                {
-                                    stringList5.Add("edit_pose_" + index + "_f");
-                                }
-                            }
-                        }
-                    }
+                    stringList5.Add(pose);
                 }
             }
 
-            for (int index1 = 15; index1 < 25; ++index1)
+            // Update when denkigai 2025 releases
+            for (int year = 17; year < 25; year++)
             {
-                for (int index2 = 0; index2 < 2; ++index2)
+                foreach (char sw in "sw")
                 {
-                    string str = "s";
-                    if (index2 == 1)
+                    for (int poseIndex = 1; poseIndex < 10; poseIndex++)
                     {
-                        str = "w";
-                    }
-
-                    for (int index3 = 1; index3 < 20; ++index3)
-                    {
-                        if (index3 < 10)
+                        string pose = $"edit_pose_dg{year}{sw}_{poseIndex:000}_f";
+                        if (GameUty.FileSystem.IsExistentFile($"{pose}.anm"))
                         {
-                            using (AFileBase afileBase3 =
-                                GameUty.FileSystem.FileOpen("edit_pose_dg" + index1 + str + "_00" + index3 + "_f.anm"))
-                            {
-                                if (afileBase3.IsValid())
-                                {
-                                    stringList5.Add("edit_pose_dg" + index1 + str + "_00" + index3 + "_f");
-                                }
-                                else
-                                {
-                                    using (AFileBase afileBase4 =
-                                        GameUty.FileSystem.FileOpen("edit_pose_dg" + index1 + str + "_0" + index3 + "_f.anm"))
-                                    {
-                                        if (afileBase4.IsValid())
-                                        {
-                                            stringList5.Add("edit_pose_dg" + index1 + str + "_0" + index3 + "_f");
-                                        }
-                                    }
-                                }
-                            }
+                            stringList5.Add(pose);
                         }
                     }
                 }
@@ -1194,22 +1058,7 @@ namespace CM3D2.MultipleMaids.Plugin
 
             if (stringList5.Count > 0)
             {
-                stringList4.AddRange(stringList5.ToArray());
-            }
-
-            using (GameUty.FileSystem.FileOpen("dance_cm3d_003_sp2_f1.anm"))
-            {
-                ;
-            }
-
-            using (GameUty.FileSystem.FileOpen("dance_cm3d2_kara_003_ddfl_f1.anm"))
-            {
-                ;
-            }
-
-            using (GameUty.FileSystem.FileOpen("dance_cm3d2_kara02_001_smt_f1.anm"))
-            {
-                ;
+                stringList4.AddRange(stringList5);
             }
 
             stringList4.AddRange(poseArrayVP2);
@@ -1217,85 +1066,70 @@ namespace CM3D2.MultipleMaids.Plugin
             stringList4.AddRange(poseArray4);
             stringList4.AddRange(poseArray5);
             stringList4.AddRange(poseArray6);
-            poseArray = stringList4.ToArray();
-            ((Action<string, List<string>>)((path, result_list) =>
-                                               {
-                                                   string[] files = Directory.GetFiles(path);
-                                                   this.countS = 0;
-                                                   for (int index = 0; index < files.Length; ++index)
-                                                   {
-                                                       if (Path.GetExtension(files[index]) == ".anm")
-                                                       {
-                                                           strListS.Add(files[index].Split('\\')[files[index].Split('\\').Length - 1]
-                                                                                    .Split('.')[0] + "                    /"
-                                                                                                   + files[index]);
-                                                           ++this.countS;
-                                                       }
-                                                   }
-                                               }))(Path.GetFullPath(".\\") + "Mod\\MultipleMaidsPose", new List<string>());
+
+            strList2 = new List<string>();
+            strListE = new List<string>();
+            strListE2 = new List<string>();
+            strListS = new List<string>();
+            HashSet<string> poseSet = new HashSet<string>(stringList4);
+            strS = "";
+            this.countS = 0;
+            foreach (string file in Directory.GetFiles(Path.GetFullPath(".\\") + "Mod\\MultipleMaidsPose"))
+            {
+                if (Path.GetExtension(file) == ".anm")
+                {
+                    string withoutExtension = Path.GetFileNameWithoutExtension(file);
+                    string mmPose = $"{withoutExtension}{twentySpaces}/{file}";
+                    strListS.Add(mmPose);
+                    ++this.countS;
+                }
+            }
             string[] list = GameUty.FileSystem.GetList("motion", AFileSystemBase.ListType.AllFile);
-            int num = 0;
             List<string> stringList6 = new List<string>();
+
             foreach (string path2 in list)
             {
                 string withoutExtension = Path.GetFileNameWithoutExtension(path2);
                 string directoryName = Path.GetDirectoryName(path2);
                 if (!withoutExtension.StartsWith("maid_motion_") && !withoutExtension.StartsWith("work_00")
-                                                                 && !withoutExtension.EndsWith("_3_") && !withoutExtension.EndsWith("_5_")
-                                                                 && !withoutExtension.StartsWith("ck_")
-                                                                 && !withoutExtension.StartsWith("vr_")
-                                                                 && !withoutExtension.StartsWith("dance_mc")
-                                                                 && !withoutExtension.Contains("a01_") && !withoutExtension.StartsWith("j_")
-                                                                 && !withoutExtension.StartsWith("k_") && !withoutExtension.StartsWith("t_")
-                                                                 && !withoutExtension.StartsWith("cbl_")
-                                                                 && !withoutExtension.Contains("b01_") && !withoutExtension.Contains("b02_")
-                                                                 && !withoutExtension.Contains("_kubi_")
-                                                                 && !withoutExtension.EndsWith("_m2") && !withoutExtension.EndsWith("_m3")
-                                                                 && !withoutExtension.Contains("_m2_once")
-                                                                 && !withoutExtension.Contains("_m3_once")
-                                                                 && !withoutExtension.StartsWith("h_")
-                                                                 && !withoutExtension.StartsWith("event_")
-                                                                 && !withoutExtension.StartsWith("man_") && !withoutExtension.EndsWith("_m")
-                                                                 && !withoutExtension.Contains("_m_") && !withoutExtension.Contains("_man")
-                                                                 && !(withoutExtension == "dance_cm3d2_001_zoukin")
-                                                                 && !(withoutExtension == "dance_cm3d2_001_mop")
-                                                                 && !(withoutExtension == "maid_motion")
-                                                                 && !(withoutExtension == "aruki_1_idougo_f")
-                                                                 && !(withoutExtension == "sleep2") && !(withoutExtension == "stand_akire2")
-                                                                 && !(withoutExtension == "ero_scene_001")
-                                                                 && !(withoutExtension == "ero_scenefm_001")
-                                                                 && !(withoutExtension == "training_001")
-                                                                 && !(withoutExtension == "workff_001")
-                                                                 && !(withoutExtension == "workfm_001")
-                                                                 && !(withoutExtension == "dance_cm3d21_005_moe_mset")
-                                                                 && !(withoutExtension == "hinpyoukai_001"))
+                #region huge if condition
+                    && !withoutExtension.EndsWith("_3_") && !withoutExtension.EndsWith("_5_")
+                    && !withoutExtension.StartsWith("ck_")
+                    && !withoutExtension.StartsWith("vr_")
+                    && !withoutExtension.StartsWith("dance_mc")
+                    && !withoutExtension.Contains("a01_") && !withoutExtension.StartsWith("j_")
+                    && !withoutExtension.StartsWith("k_") && !withoutExtension.StartsWith("t_")
+                    && !withoutExtension.StartsWith("cbl_")
+                    && !withoutExtension.Contains("b01_") && !withoutExtension.Contains("b02_")
+                    && !withoutExtension.Contains("_kubi_")
+                    && !withoutExtension.EndsWith("_m2") && !withoutExtension.EndsWith("_m3")
+                    && !withoutExtension.Contains("_m2_once")
+                    && !withoutExtension.Contains("_m3_once")
+                    && !withoutExtension.StartsWith("h_")
+                    && !withoutExtension.StartsWith("event_")
+                    && !withoutExtension.StartsWith("man_") && !withoutExtension.EndsWith("_m")
+                    && !withoutExtension.Contains("_m_") && !withoutExtension.Contains("_man")
+                    && !(withoutExtension == "dance_cm3d2_001_zoukin")
+                    && !(withoutExtension == "dance_cm3d2_001_mop")
+                    && !(withoutExtension == "maid_motion")
+                    && !(withoutExtension == "aruki_1_idougo_f")
+                    && !(withoutExtension == "sleep2") && !(withoutExtension == "stand_akire2")
+                    && !(withoutExtension == "ero_scene_001")
+                    && !(withoutExtension == "ero_scenefm_001")
+                    && !(withoutExtension == "training_001")
+                    && !(withoutExtension == "workff_001")
+                    && !(withoutExtension == "workfm_001")
+                    && !(withoutExtension == "dance_cm3d21_005_moe_mset")
+                    && !(withoutExtension == "hinpyoukai_001"))
+                #endregion
                 {
                     if (!directoryName.Contains("\\sex\\"))
                     {
-                        if (!withoutExtension.StartsWith("sex_"))
+                        if (!withoutExtension.StartsWith("sex_") && !withoutExtension.StartsWith("dance_test"))
                         {
-                            if (withoutExtension.StartsWith("dance_test"))
+                            if (!strListS.Exists(mmPose => withoutExtension == mmPose.Split('/')[0].Replace(twentySpaces, "")))
                             {
-                                strListD.Add(withoutExtension);
-                            }
-                            else
-                            {
-                                bool flag = false;
-                                foreach (string str1 in strListS)
-                                {
-                                    char[] chArray = new char[1] { '/' };
-                                    string str2 = str1.Split(chArray)[0].Replace("                    ", "");
-                                    if (withoutExtension == str2)
-                                    {
-                                        flag = true;
-                                        break;
-                                    }
-                                }
-
-                                if (!flag)
-                                {
-                                    stringList6.Add(withoutExtension);
-                                }
+                                stringList6.Add(withoutExtension);
                             }
                         }
                     }
@@ -1306,85 +1140,23 @@ namespace CM3D2.MultipleMaids.Plugin
                 }
             }
 
-            foreach (string str in stringList6)
-            {
-                bool flag = false;
-                for (int index = 0; index < poseArray.Length; ++index)
-                {
-                    if (str == poseArray[index])
-                    {
-                        flag = true;
-                    }
-                }
-
-                if (!flag && str.StartsWith("edit_"))
-                {
-                    strList2.Add(str);
-                }
-            }
-
-            foreach (string str in stringList6)
-            {
-                bool flag = false;
-                for (int index = 0; index < poseArray.Length; ++index)
-                {
-                    if (str == poseArray[index])
-                    {
-                        flag = true;
-                    }
-                }
-
-                if (!flag && str.StartsWith("pose_"))
-                {
-                    strList2.Add(str);
-                }
-            }
+            strList2.AddRange(stringList6.Where(str => !poseSet.Contains(str) && str.StartsWith("edit_")));
+            strList2.AddRange(stringList6.Where(str => !poseSet.Contains(str) && str.StartsWith("pose_")));
+            strList2.AddRange(stringList6.Where(str => !poseSet.Contains(str) && !str.StartsWith("edit_") && !str.StartsWith("pose_")));
+            strListE2.AddRange(strListE.Where(str => !poseSet.Contains(str)));
 
-            foreach (string str in stringList6)
-            {
-                bool flag = false;
-                for (int index = 0; index < poseArray.Length; ++index)
-                {
-                    if (str == poseArray[index])
-                    {
-                        flag = true;
-                    }
-                }
+            stringList4.AddRange(strList2);
+            stringList4.AddRange(strListE2);
 
-                if (!flag && !str.StartsWith("edit_") && !str.StartsWith("pose_"))
-                {
-                    strList2.Add(str);
-                }
-            }
-
-            foreach (string str in strListE)
-            {
-                bool flag = false;
-                for (int index = 0; index < poseArray.Length; ++index)
-                {
-                    if (str == poseArray[index])
-                    {
-                        flag = true;
-                    }
-                }
-
-                if (!flag)
-                {
-                    strListE2.Add(str);
-                    ++num;
-                }
-            }
-
-            stringList4.AddRange(strList2.ToArray());
-            stringList4.AddRange(strListE2.ToArray());
+            // What is this for?
             existPose = false;
             poseIniStr = "";
             foreach (IniKey key in Preferences["pose"].Keys)
             {
                 IniKey iniKey = Preferences["pose"][key.Key];
-                if (iniKey.Value != null && iniKey.Value != "" && iniKey.Value != "del")
+                if (!string.IsNullOrEmpty(iniKey.Value) && iniKey.Value != "del")
                 {
-                    stringList4.AddRange(new string[1] { key.Key });
+                    stringList4.Add(key.Key);
                     existPose = true;
                     if (poseIniStr == "")
                     {
@@ -1393,7 +1165,7 @@ namespace CM3D2.MultipleMaids.Plugin
                 }
             }
 
-            stringList4.AddRange(strListS.ToArray());
+            stringList4.AddRange(strListS);
             poseArray = stringList4.ToArray();
             List<string> stringList7 = new List<string>(50 + poseGroupArray2.Length);
             stringList7.AddRange(poseGroupArray2);
@@ -1417,37 +1189,22 @@ namespace CM3D2.MultipleMaids.Plugin
 
             poseGroupArray = stringList7.ToArray();
             groupList = new ArrayList();
-            for (int index1 = 0; index1 < poseArray.Length; ++index1)
+            for (int i = 0; i < poseArray.Length; i++)
             {
-                for (int index2 = 0; index2 < poseGroupArray.Length; ++index2)
+                foreach (string poseGroup in poseGroupArray)
                 {
-                    if (poseGroupArray[index2] == poseArray[index1])
+                    if (poseGroup == poseArray[i])
                     {
-                        groupList.Add(index1);
-                        if (poseGroupArray[index2] == strList2[0])
+                        groupList.Add(i);
+                        if (poseGroup == strList2[0])
                         {
-                            sPoseCount = index1;
+                            sPoseCount = i;
                         }
                     }
                 }
             }
 
-            string[] strArray1 = new string[1] { "Salon_Day" };
-            string[] strArray2 = new string[2] { "SMRoom2", "LockerRoom" };
-            string[] strArray3 = new string[4] { "Train", "Toilet", "Oheya", "MyBedRoom_NightOff" };
-            string[] strArray4 = new string[4] { "ClassRoom", "ClassRoom_Play", "HoneymoonRoom", "OutletPark" };
-            string[] strArray5 = new string[9]
-            {
-                    "BigSight", "BigSight_Night", "PrivateRoom", "PrivateRoom_Night", "Sea", "Sea_Night", "Yashiki_Day", "Yashiki",
-                    "Yashiki_Pillow"
-            };
-            string[] strArray6 = new string[8]
-            {
-                    "rotenburo", "rotenburo_night", "villa", "villa_night", "villa_bedroom", "villa_bedroom_night", "villa_farm",
-                    "villa_farm_night"
-            };
-            string[] strArray7 = new string[1] { "karaokeroom" };
-            List<string> stringList8 = new List<string>(50 + poseArray2.Length);
+            List<string> bgList = new List<string>(50 + poseArray2.Length);
 
             PhotoBGData.Create();
             bgDict = new Dictionary<string, string>();
@@ -1464,144 +1221,111 @@ namespace CM3D2.MultipleMaids.Plugin
 
             bgUiNames.ToList().ForEach(x => bgDict[x.Key] = x.Value);
 
-            stringList8.AddRange(neiList);
+            bgList.AddRange(neiList);
 
-            List<string> stringList9 = new List<string>();
+            List<string> myRoomBgList = new List<string>();
             Dictionary<string, string> saveDataDic = CreativeRoomManager.GetSaveDataDic();
             if (saveDataDic != null)
             {
                 foreach (KeyValuePair<string, string> keyValuePair in saveDataDic)
                 {
-                    stringList9.Add(keyValuePair.Key);
+                    myRoomBgList.Add(keyValuePair.Key);
                     bgDict[keyValuePair.Key] = keyValuePair.Value;
                 }
             }
 
-            stringList8.AddRange(stringList9.ToArray());
+            bgList.AddRange(myRoomBgList);
+
             if (isCM3D2)
             {
-                stringList8.AddRange(bgArray21);
-                if (isVP)
-                {
-                    stringList8.AddRange(strArray2);
-                }
-
-                if (isPP)
+                if (GameUty.FileSystemOld.IsExistentFile("phot_bg_list.nei"))
                 {
-                    stringList8.AddRange(strArray3);
+                    List<string> cm3d2BgList = new List<string>(50);
+                    using (AFileBase file = GameUty.FileSystemOld.FileOpen("phot_bg_list.nei"))
+                    {
+                        using (CsvParser csvParser = new CsvParser())
+                        {
+                            csvParser.Open(file);
+                            for (int cell_y = 1; cell_y < csvParser.max_cell_y; ++cell_y)
+                            {
+                                if (csvParser.IsCellToExistData(3, cell_y))
+                                {
+                                    string data = csvParser.GetCellAsString(3, cell_y);
+                                    cm3d2BgList.Add(data);
+                                    // ew
+                                    if (data == "Yashiki") cm3d2BgList.Add("Yashiki_Pillow");
+                                }
+                            }
+                        }
+                    }
+                    bgList.AddRange(cm3d2BgList);
                 }
+            }
 
-                if (isPP2)
-                {
-                    stringList8.AddRange(strArray4);
-                }
+            bgArray = bgList.ToArray();
 
-                if (isPP3)
-                {
-                    stringList8.AddRange(strArray5);
-                }
+            bgIndex = bgCombo2.selectedItemIndex = bgCombo.selectedItemIndex = Array.FindIndex(bgArray, bg => bg == "Theater");
 
-                if (isVA)
-                {
-                    stringList8.AddRange(strArray6);
-                }
+            List<string> bgmList = new List<string>(50) { "bgm008" };
 
-                if (isKA || isKA2)
+            for (int i = 1; i < 33; i++)
+            {
+                if (i == 8) continue;
+                string bgm = $"bgm{i:000}";
+                if (GameUty.FileSystem.IsExistentFile($"{bgm}.ogg"))
                 {
-                    stringList8.AddRange(strArray7);
+                    bgmList.Add(bgm);
                 }
-
-                stringList8.AddRange(strArray1);
             }
 
-            bgArray = stringList8.ToArray();
-            bgIndex = bgCombo2.selectedItemIndex = bgCombo.selectedItemIndex = Array.FindIndex(bgArray, bg => bg == "Theater");
-            string[] strArray8 = new string[3] { "dokidokifallinlove_short_inst", "dokidokifallinlove_short", "entrancetoyou_short" };
-            string[] strArray9 = new string[1] { "scarlet leap_short" };
-            string[] strArray11 = new string[1] { "RhythmixToYou" };
-            string[] strArray15 = new string[5]
-            {
-                    "bloomingdreaming_short", "kiminiaijodelicious_short", "luminousmoment_short", "nightmagicfire_short",
-                    "melodyofempire_short"
-            };
-            List<string> stringList10 = new List<string>(50);
-            stringList10.AddRange(bgmArray2);
-            List<string> stringList11 = new List<string>();
-            for (int index = 18; index < 210; ++index)
+            bgmList.AddRange(new string[]
             {
-                if (index < 100)
+                "bloomingdreaming_short", "canknowtwoclose_short", "dokidokifallinlove_short",
+                "dokidokifallinlove_short_inst", "entrancetoyou_short", "happyhappyscandal_short_nao_kara",
+                "kiminiaijodelicious_short", "luminousmoment_short", "melodyofempire_short",
+                "nightmagicfire_short", "rhythmixtoyou", "scarlet leap_short",
+                "stellarmytears_short_misato_kara", "stellarmytears_short_nao_kara", "stellarmytears_short_sasaki_kara",
+            });
+
+            bgmArray = bgmList.ToArray();
+
+            List<string> stringList12 = new List<string>(50 + parArray2.Length);
+            stringList12.AddRange(parArray2);
+            HashSet<int> enabled_id_list = new HashSet<int>();
+            Action<string> action3 = file_name =>
                 {
-                    using (AFileBase afileBase5 = GameUty.FileSystem.FileOpen("bgm0" + index + ".ogg"))
+                    if (GameUty.FileSystem.IsExistentFile(file_name))
                     {
-                        if (afileBase5.IsValid())
+                        using (AFileBase file = GameUty.FileSystem.FileOpen(file_name))
                         {
-                            stringList11.Add("bgm0" + index);
-                        }
-                        else
-                        {
-                            using (AFileBase afileBase6 = GameUty.FileSystem.FileOpen("bgm" + index + ".ogg"))
+                            using (CsvParser csvParser = new CsvParser())
                             {
-                                if (afileBase6.IsValid())
+                                for (int cell_y = 1; cell_y < csvParser.max_cell_y; ++cell_y)
                                 {
-                                    stringList11.Add("bgm" + index);
+                                    if (csvParser.IsCellToExistData(0, cell_y))
+                                    {
+                                        int cellAsInteger = csvParser.GetCellAsInteger(0, cell_y);
+                                        if (!enabled_id_list.Contains(cellAsInteger))
+                                        {
+                                            enabled_id_list.Add(cellAsInteger);
+                                        }
+                                    }
                                 }
                             }
                         }
                     }
-                }
-            }
+                };
 
-            if (stringList11.Count > 0)
+            action3("desk_item_enabled_id.nei");
+            foreach (string path in GameUty.PathList)
             {
-                stringList10.AddRange(stringList11.ToArray());
-            }
-
-            stringList10.AddRange(strArray8);
-            stringList10.AddRange(strArray9);
-            stringList10.AddRange(strArray11);
-            stringList10.AddRange(strArray15);
-            bgmArray = stringList10.ToArray();
-            List<string> stringList12 = new List<string>(50 + parArray2.Length);
-            stringList12.AddRange(parArray2);
-            HashSet<int> enabled_id_list = new HashSet<int>();
-            Action<string> action3 = file_name =>
-                                              {
-                                                  file_name += ".nei";
-                                                  if (!GameUty.FileSystem.IsExistentFile(file_name))
-                                                  {
-                                                      return;
-                                                  }
-
-                                                  using (AFileBase file = GameUty.FileSystem.FileOpen(file_name))
-                                                  {
-                                                      using (CsvParser csvParser = new CsvParser())
-                                                      {
-                                                          NDebug.Assert(csvParser.Open(file), file_name + "\nopen failed.");
-                                                          for (int cell_y = 1; cell_y < csvParser.max_cell_y; ++cell_y)
-                                                          {
-                                                              if (csvParser.IsCellToExistData(0, cell_y))
-                                                              {
-                                                                  int cellAsInteger = csvParser.GetCellAsInteger(0, cell_y);
-                                                                  if (!enabled_id_list.Contains(cellAsInteger))
-                                                                  {
-                                                                      enabled_id_list.Add(cellAsInteger);
-                                                                  }
-                                                              }
-                                                          }
-                                                      }
-                                                  }
-                                              };
-            action3("desk_item_enabled_id");
-            for (int index = 0; index < GameUty.PathList.Count; ++index)
-            {
-                action3("desk_item_enabled_id_" + GameUty.PathList[index]);
+                action3($"desk_item_enabled_id_{path}.nei");
             }
 
             using (AFileBase file = GameUty.FileSystem.FileOpen("desk_item_detail.nei"))
             {
                 using (CsvParser csv = new CsvParser())
                 {
-                    NDebug.Assert(csv.Open(file), "desk_item_detail.nei\nopen failed.");
                     for (int index = 1; index < csv.max_cell_y; ++index)
                     {
                         if (csv.IsCellToExistData(0, index))
@@ -1612,7 +1336,7 @@ namespace CM3D2.MultipleMaids.Plugin
                                 ItemData2 itemData2 = new ItemData2(csv, index);
                                 if (itemData2.asset_name != "")
                                 {
-                                    stringList12.AddRange(new string[1] { itemData2.name + "                    #" + itemData2.asset_name });
+                                    stringList12.Add($"{itemData2.name}{twentySpaces}#{itemData2.asset_name}");
                                 }
                             }
                         }
@@ -1653,9 +1377,9 @@ namespace CM3D2.MultipleMaids.Plugin
             }
 
             IEnumerable<string> propList1 = filteredList.Where(prpdata => !string.IsNullOrEmpty(prpdata.create_prefab_name))
-                                        .Select(prpdata => prpdata.create_prefab_name);
+                .Select(prpdata => prpdata.create_prefab_name);
             IEnumerable<string> propList2 = filteredList.Where(prpdata => !string.IsNullOrEmpty(prpdata.create_asset_bundle_name))
-                                        .Select(prpdata => prpdata.create_asset_bundle_name);
+                .Select(prpdata => prpdata.create_asset_bundle_name);
             List<string> propList = propList1.ToList();
             propList.AddRange(propList2.ToList());
             stringList13.AddRange(propList);
@@ -1701,8 +1425,6 @@ namespace CM3D2.MultipleMaids.Plugin
             }
 
             itemBArray = stringList14.ToArray();
-
-            //rectWin.y = GetPix(65);
         }
     }
 }

+ 54 - 20
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
 {
@@ -3202,6 +3201,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(',');
@@ -3210,22 +3210,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;
@@ -3300,18 +3339,13 @@ namespace CM3D2.MultipleMaids.Plugin
                                 else if (!str1.StartsWith("mirror") && str1.IndexOf(":") < 0)
                                 {
                                     Object original2;
-                                    if (str1.StartsWith("BG"))
-                                    {
-                                        string name = str1.Replace("BG", "");
-                                        original2 = GameMain.Instance.BgMgr.CreateAssetBundle(name);
-                                        if (original2 == null)
-                                        {
-                                            original2 = Resources.Load("BG/" + name);
-                                        }
-                                    }
-                                    else
+                                    bool isBG = str1.StartsWith("BG");
+                                    string name = isBG ? str1.Replace("BG", "") : str1;
+
+                                    original2 = GameMain.Instance.BgMgr.CreateAssetBundle(name);
+                                    if (original2 == null)
                                     {
-                                        original2 = Resources.Load("Prefab/" + str1);
+                                        original2 = Resources.Load((isBG ? "BG/" : "Prefab/") + name);
                                     }
 
                                     original1 = Instantiate(original2) as GameObject;

+ 160 - 45
MultipleMaids/CM3D2/MultipleMaids/Plugin/MultipleMaids.cs

@@ -569,11 +569,15 @@ namespace CM3D2.MultipleMaids.Plugin
             ["SeaCafe"] = "SeaCafe",
             ["SeaCafe_Night"] = "SeaCafe (Night)",
             ["Sea_Night"] = "海(夜)",
+            ["Sea_VR"] = "海VR",
+            ["Sea_VR_Night"] = "海VR(夜)",
             ["ShinShitsumu"] = "執務室",
             ["ShinShitsumu_ChairRot"] = "執務室(椅子)",
             ["ShinShitsumu_Night"] = "執務室(夜)",
             ["Shitsumu"] = "執務室",
             ["Shitsumu_Night"] = "執務室(夜)",
+            ["Shitsumu_ChairRot"] = "執務室(椅子)",
+            ["Shitsumu_ChairRot_Night"] = "執務室(椅子・夜)",
             ["ShoppingMall"] = "ショッピングモール",
             ["ShoppingMall_Night"] = "ショッピングモール(夜)",
             ["Shukuhakubeya_BedRoom"] = "宿泊-ベッドルーム",
@@ -598,24 +602,16 @@ namespace CM3D2.MultipleMaids.Plugin
             ["Toilet"] = "Toilet",
             ["Town"] = "Town",
             ["Train"] = "電車",
-            ["villa"] = "ヴィラ1F",
-            ["villa_bedroom"] = "ヴィラ2F",
-            ["villa_bedroom_night"] = "ヴィラ2F(夜)",
-            ["villa_farm"] = "畑",
-            ["villa_farm_night"] = "畑(夜)",
-            ["villa_night"] = "ヴィラ1F(夜)",
+            ["Villa"] = "ヴィラ1F",
+            ["Villa_BedRoom"] = "ヴィラ2F",
+            ["Villa_BedRoom_Night"] = "ヴィラ2F(夜)",
+            ["Villa_Farm"] = "畑",
+            ["Villa_Farm_Night"] = "畑(夜)",
+            ["Villa_Night"] = "ヴィラ1F(夜)",
             ["Yashiki"] = "屋敷(夜)",
             ["Yashiki_Day"] = "屋敷",
             ["Yashiki_Pillow"] = "屋敷(夜・枕)",
         };
-
-        private readonly string[] bgArray21 = new string[23]
-        {
-                "Salon", "Syosai", "Syosai_Night", "DressRoom_NoMirror", "MyBedRoom", "MyBedRoom_Night", "Bathroom", "PlayRoom", "Pool",
-                "SMRoom", "PlayRoom2", "Salon_Garden", "LargeBathRoom", "MaidRoom", "OiranRoom", "Penthouse", "Town", "Kitchen",
-                "Kitchen_Night", "Shitsumu", "Shitsumu_Night", "Salon_Entrance", "Bar"
-        };
-
         private readonly ComboBox2 bgCombo = new ComboBox2();
         private readonly ComboBox2 bgCombo2 = new ComboBox2();
         private GUIContent[] bgCombo2List;
@@ -625,13 +621,6 @@ namespace CM3D2.MultipleMaids.Plugin
         private int bgIndex6;
         private int bgIndexB;
         private string[] bgmArray;
-
-        private readonly string[] bgmArray2 = new string[17]
-        {
-                "bgm008", "bgm001", "bgm002", "bgm003", "bgm004", "bgm005", "bgm006", "bgm007", "bgm009", "bgm010", "bgm011", "bgm012",
-                "bgm013", "bgm014", "bgm015", "bgm016", "bgm017"
-        };
-
         private readonly ComboBox2 bgmCombo = new ComboBox2();
         private GUIContent[] bgmComboList;
         private int bgmIndex;
@@ -4207,9 +4196,6 @@ namespace CM3D2.MultipleMaids.Plugin
         private bool isPoseEdit;
         private bool isPoseInit;
         private readonly bool[] isPoseIti = new bool[maxMaidCnt];
-        private bool isPP;
-        private bool isPP2;
-        private bool isPP3;
         private bool isPref;
         private bool isSavePose;
         private bool isSavePose2;
@@ -4253,7 +4239,6 @@ namespace CM3D2.MultipleMaids.Plugin
         private bool isToothoff;
         private bool isVA;
         private bool isWear;
-        private bool isVP;
         private bool isVR;
         private bool isVR2 = true;
         private bool isVRScroll = true;
@@ -4432,6 +4417,9 @@ namespace CM3D2.MultipleMaids.Plugin
         private readonly MouseDrag5[] mMaid2 = new MouseDrag5[maxMaidCnt];
         private readonly MouseDrag2[] mMaidC = new MouseDrag2[maxMaidCnt];
         private readonly MouseDrag3[] mNeck = new MouseDrag3[maxMaidCnt];
+        private bool modItemsOnly = false;
+        private bool modItemsToggle = false;
+        private int numberOfModItems = 0;
         private float moutha;
         private float mouthc;
         private float mouthdw;
@@ -4891,6 +4879,7 @@ namespace CM3D2.MultipleMaids.Plugin
         private Vector3 softG;
         private Vector3 softG2;
         private List<SortItem> sortList = new List<SortItem>();
+        private static readonly string twentySpaces = "                    ";
         private float speed = 1f;
         private Transform Spine;
         private Transform Spine0a;
@@ -5398,10 +5387,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();
@@ -5416,7 +5403,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
             {
@@ -5476,16 +5463,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)
             {
@@ -5497,7 +5474,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,
@@ -5522,20 +5629,28 @@ 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 bool isMod = 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 bool isMod = false;
+            public int priority = -1;
+            public Texture2D tex = null;
 
             public override bool Equals(object obj)
             {
@@ -5545,7 +5660,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()

+ 2 - 1
MultipleMaids/ComboBox2.cs

@@ -32,6 +32,7 @@ public class ComboBox2
                     GUIStyle boxStyle,
                     GUIStyle listStyle)
     {
+        listStyle.onNormal = listStyle.onHover;
         if (forceToUnShow)
         {
             forceToUnShow = false;
@@ -108,4 +109,4 @@ public class ComboBox2
     {
         return (int)((1.0 + (Screen.width / 1280.0 - 1.0) * 0.600000023841858) * i);
     }
-}
+}

+ 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;
     }
-}
+}