Advertisement
cm3d2-01

CM3D2.AddModsSlider.Plugin.0.0.0.0

Aug 20th, 2015
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 15.80 KB | None | 0 0
  1. // CM3D2.AddModsSlider.Plugin.0.0.0.0 : フリーコメント欄の各modパラメータをスライドバーで操作する UnityInjector 用プラグイン
  2.  
  3. // メイドエディット画面中にF5で表示トグル。
  4. // コメント欄で操作する数値をスライドバーで調整する事が可能。
  5. // "EYEBALL", "TEST_EYE_RATIO", "TEST_EYE_ANG"
  6. // "TEST_PELSCL", "TEST_THISCL", "TEST_THIPOS", "SPISCL", "S0ASCL", "S1_SCL", "S1ASCL"
  7. // に対応。フリーコメント欄にそのmodの有効な書式が在れば、該当するスライドバーが表示される。
  8.  
  9.  
  10. using System;
  11. using System.Collections.Generic;
  12. using System.IO;
  13. using System.Text;
  14. using System.Text.RegularExpressions;
  15. using UnityEngine;
  16. using UnityInjector.Attributes;
  17.  
  18. namespace CM3D2.AddModsSlider.Plugin
  19. {
  20.     [PluginFilter("CM3D2x64"),
  21.     PluginFilter("CM3D2x86"),
  22.     PluginFilter("CM3D2VRx64"),
  23.     PluginName("CM3D2 AddModsSlider"),
  24.     PluginVersion("0.0.0.0")]
  25.     public class AddModsSlider : UnityInjector.PluginBase
  26.     {
  27.         private int sceneLevel;
  28.         private bool visible = false;
  29.         private ModsParam mp;
  30.         private float scbarValue = 0f;
  31.  
  32.         public class ModsParam
  33.         {
  34.             public static string[] sKey = {
  35.                                         "EYEBALL"
  36.                                         , "TEST_EYE_RATIO", "TEST_EYE_ANG"
  37.                                         , "TEST_PELSCL", "TEST_THISCL", "TEST_THIPOS"
  38.                                         , "SPISCL", "S0ASCL", "S1_SCL", "S1ASCL"
  39.                                         };
  40.             public static int Count { get{return ModsParam.sKey.Length; } }
  41.  
  42.             public Dictionary<string, float[]> fValue = new Dictionary<string, float[]>();
  43.             public Dictionary<string, float[]> fVmin = new Dictionary<string, float[]>();
  44.             public Dictionary<string, float[]> fVmax = new Dictionary<string, float[]>();
  45.             public Dictionary<string, string[]> sLabel = new Dictionary<string, string[]>();
  46.             public Dictionary<string, string> sMatchPattern = new Dictionary<string, string>();
  47.             public Dictionary<string, bool> bEnabled = new Dictionary<string, bool>();
  48.             public Dictionary<string, bool> bScale = new Dictionary<string, bool>();
  49.            
  50.             public ModsParam()
  51.             {
  52.                 this.fValue[ModsParam.sKey[0]] = new float[2] {1.0f,1.0f};
  53.  
  54.                 this.fValue[ModsParam.sKey[1]] = new float[1] {1.0f};
  55.                 this.fValue[ModsParam.sKey[2]] = new float[3] {0.0f, 0.0f, 0.0f};
  56.  
  57.                 this.fValue[ModsParam.sKey[3]] = new float[3] {1.0f, 1.0f, 1.0f};
  58.                 this.fValue[ModsParam.sKey[4]] = new float[2] {1.0f, 1.0f};
  59.                 this.fValue[ModsParam.sKey[5]] = new float[2] {0.0f, 0.0f};
  60.  
  61.                 this.fValue[ModsParam.sKey[6]] = new float[3] {1.0f, 1.0f, 1.0f};
  62.                 this.fValue[ModsParam.sKey[7]] = new float[3] {1.0f, 1.0f, 1.0f};
  63.                 this.fValue[ModsParam.sKey[8]] = new float[3] {1.0f, 1.0f, 1.0f};
  64.                 this.fValue[ModsParam.sKey[9]] = new float[3] {1.0f, 1.0f, 1.0f};
  65.  
  66.  
  67.                 this.fVmin[ModsParam.sKey[0]] = new float[2] {0.1f,0.1f};
  68.  
  69.                 this.fVmin[ModsParam.sKey[1]] = new float[1] {0.1f};
  70.                 this.fVmin[ModsParam.sKey[2]] = new float[3] {-60.0f, -100.0f, -100.0f};
  71.  
  72.                 this.fVmin[ModsParam.sKey[3]] = new float[3] {0.1f, 0.1f, 0.1f};
  73.                 this.fVmin[ModsParam.sKey[4]] = new float[2] {0.1f, 0.1f};
  74.                 this.fVmin[ModsParam.sKey[5]] = new float[2] {-100.0f, -100.0f};
  75.  
  76.                 this.fVmin[ModsParam.sKey[6]] = new float[3] {0.1f, 0.1f, 0.1f};
  77.                 this.fVmin[ModsParam.sKey[7]] = new float[3] {0.1f, 0.1f, 0.1f};
  78.                 this.fVmin[ModsParam.sKey[8]] = new float[3] {0.1f, 0.1f, 0.1f};
  79.                 this.fVmin[ModsParam.sKey[9]] = new float[3] {0.1f, 0.1f, 0.1f};
  80.  
  81.  
  82.                 this.fVmax[ModsParam.sKey[0]] = new float[2] {2.0f,2.0f};
  83.  
  84.                 this.fVmax[ModsParam.sKey[1]] = new float[1] {2.0f};
  85.                 this.fVmax[ModsParam.sKey[2]] = new float[3] {60.0f, 100.0f, 100.0f};
  86.  
  87.                 this.fVmax[ModsParam.sKey[3]] = new float[3] {2.0f, 2.0f, 2.0f};
  88.                 this.fVmax[ModsParam.sKey[4]] = new float[2] {2.0f, 2.0f};
  89.                 this.fVmax[ModsParam.sKey[5]] = new float[2] {100.0f, 100.0f};
  90.  
  91.                 this.fVmax[ModsParam.sKey[6]] = new float[3] {2.0f, 2.0f, 2.0f};
  92.                 this.fVmax[ModsParam.sKey[7]] = new float[3] {2.0f, 2.0f, 2.0f};
  93.                 this.fVmax[ModsParam.sKey[8]] = new float[3] {2.0f, 2.0f, 2.0f};
  94.                 this.fVmax[ModsParam.sKey[9]] = new float[3] {2.0f, 2.0f, 2.0f};
  95.  
  96.  
  97.                 this.sLabel[ModsParam.sKey[0]] = new string[2] {"瞳の大きさ(縦): ", "瞳の大きさ(横): "};
  98.  
  99.                 this.sLabel[ModsParam.sKey[1]] = new string[1] {"目の縦横比率 : "};
  100.                 this.sLabel[ModsParam.sKey[2]] = new string[3] {"目の角度 : ", "目の横位置 : ", "目の縦位置 : "};
  101.  
  102.                 this.sLabel[ModsParam.sKey[3]] = new string[3] {"骨盤の横幅 : ", "骨盤の奥行き : ", "骨盤の高さ : "};
  103.                 this.sLabel[ModsParam.sKey[4]] = new string[2] {"足の横幅 : ", "足の奥行き : "};
  104.                 this.sLabel[ModsParam.sKey[5]] = new string[2] {"足の横位置 : ", "足の前後位置 : "};
  105.  
  106.                 this.sLabel[ModsParam.sKey[6]] = new string[3] {"胴(下腹部)の横幅 : ", "胴(下腹部)の奥行き : ", "胴(下腹部)の高さ : "};
  107.                 this.sLabel[ModsParam.sKey[7]] = new string[3] {"胴(腹部)の横幅 : ", "胴(腹部)の奥行き : ", "胴(腹部)の高さ : "};
  108.                 this.sLabel[ModsParam.sKey[8]] = new string[3] {"胴(みぞおち)の横幅 : ", "胴(みぞおち)の奥行き : ", "胴(みぞおち)の高さ : "};
  109.                 this.sLabel[ModsParam.sKey[9]] = new string[3] {"胴(首・肋骨)の横幅 : ", "胴(首・肋骨)の奥行き : ", "胴(首・肋骨)の高さ : "};
  110.  
  111.  
  112.                 this.sMatchPattern[ModsParam.sKey[0]] = @"#" + ModsParam.sKey[0] + @"=([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+)#";
  113.  
  114.                 this.sMatchPattern[ModsParam.sKey[1]] = @"#" + ModsParam.sKey[1] + @"=([-+]?[0-9]*\.?[0-9]+)#";
  115.                 this.sMatchPattern[ModsParam.sKey[2]] = @"#" + ModsParam.sKey[2] + @"=([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+)#";
  116.                
  117.                 this.sMatchPattern[ModsParam.sKey[3]] = @"#" + ModsParam.sKey[3] + @"=([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+)#";
  118.                 this.sMatchPattern[ModsParam.sKey[4]] = @"#" + ModsParam.sKey[4] + @"=([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+)#";
  119.                 this.sMatchPattern[ModsParam.sKey[5]] = @"#" + ModsParam.sKey[5] + @"=([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+)#";
  120.  
  121.                 this.sMatchPattern[ModsParam.sKey[6]] = @"#" + ModsParam.sKey[6] + @"=([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+)#";
  122.                 this.sMatchPattern[ModsParam.sKey[7]] = @"#" + ModsParam.sKey[7] + @"=([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+)#";
  123.                 this.sMatchPattern[ModsParam.sKey[8]] = @"#" + ModsParam.sKey[8] + @"=([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+)#";
  124.                 this.sMatchPattern[ModsParam.sKey[9]] = @"#" + ModsParam.sKey[9] + @"=([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+)#";
  125.  
  126.  
  127.                 for (int i=0; i<ModsParam.Count; i++)
  128.                 {
  129.                     string key = ModsParam.sKey[i];
  130.                    
  131.                     this.bEnabled[key] = false;
  132.                     for (int j=0; j<ModsParam.Count; j++)
  133.                     {
  134.                         if (key == "TEST_EYE_ANG" || key == "TEST_THIPOS")
  135.                         {
  136.                             this.bScale[key] = false;
  137.                         }
  138.                         else
  139.                         {
  140.                             this.bScale[key] = true;
  141.                         }
  142.                     }
  143.                 }
  144.             }
  145.         }
  146.  
  147.  
  148. //----
  149.  
  150.         public void Awake()
  151.         {
  152.         }
  153.  
  154.         void OnLevelWasLoaded(int level)
  155.         {
  156.             sceneLevel = level;
  157.             if (sceneLevel == 5)
  158.             {
  159.                 this.mp = new ModsParam();
  160.             }
  161.             else
  162.             {
  163.                 visible = false;
  164.             }
  165.            
  166.         }
  167.  
  168.         void Update()
  169.         {
  170.             if (Input.GetKeyDown(KeyCode.F5))
  171.             {
  172.                 visible = !visible;
  173.             }
  174.            
  175.         }
  176.  
  177.         void OnGUI()
  178.         {
  179.             if (!visible) return;
  180.             if (sceneLevel != 5) return;
  181.  
  182.             string freeComment = null;
  183.             CharacterMgr cm = GameMain.Instance.CharacterMgr;
  184.  
  185.             Maid maid = cm.GetMaid(0);
  186.             if (maid == null) return;
  187.  
  188.             if (maid.Param != null && maid.Param.status != null && maid.Param.status.free_comment != null)
  189.             {
  190.                freeComment = maid.Param.status.free_comment;
  191.             }
  192.             if (freeComment == null) return;
  193.  
  194.             CheckModbEnabled(this.mp, freeComment);
  195.             AddSlider(this.mp);
  196.             UpdateFreeComment(maid, this.mp);
  197.          }
  198.  
  199. //----
  200.  
  201.         private void CheckModbEnabled(ModsParam mp, string freeComment)
  202.         {
  203.  
  204.             for(int i=0; i<ModsParam.Count; i++)
  205.             {
  206.                 string key = ModsParam.sKey[i];
  207.                 int vnum = mp.fValue[key].Length;
  208.                 Match match = Regex.Match(freeComment, mp.sMatchPattern[ModsParam.sKey[i]]);
  209.            
  210.                 if (match.Groups.Count > vnum)
  211.                 {
  212.                     bool tpf = true;
  213.  
  214.                     for(int j=0; j<vnum; j++)
  215.                     {
  216.                         mp.bEnabled[key] = true;
  217.                         tpf &= Single.TryParse(match.Groups[j + 1].Value, out mp.fValue[key][j]);
  218.                     }
  219.                     if(!tpf) mp.bEnabled[key] = false;
  220.                 }
  221.             }
  222.         }
  223.  
  224.  
  225.         private void AddSlider(ModsParam mp)
  226.          {
  227.             int mods_n = ModsParam.Count;
  228.             int margin = 10;
  229.             int menuHeight = 43;
  230.             int okButtonHeight = 90;
  231.             int winTop = margin + menuHeight;
  232.             int winLeft = margin + (int)((Screen.width - margin * 2) * 0.75);
  233.             int winWidth = (int)((Screen.width - margin * 2) * 0.25);
  234.             int winHeight = (int)(Screen.height- winTop - margin - okButtonHeight);
  235.             int conTop = winTop + margin + 30;
  236.             int conWidth = winWidth - margin * 4 ;
  237.             int conHeight = 0;
  238.             int lineH = 22;
  239.             int lineH2 = 24;
  240.             int lineP = conTop;
  241.             int overHeight = 0;
  242.             int outconLine = 0;
  243.             int thrcon = 0;
  244.             bool scrlf = false;
  245.  
  246.             // 下地のボックス
  247.             GUIStyle bstyle = "box";
  248.             bstyle.fontSize = 18;
  249.             bstyle.alignment = TextAnchor.UpperLeft;
  250.             Rect outRect = new Rect(winLeft, winTop, winWidth, winHeight);
  251.             GUI.Box(outRect, "Mods Slider", bstyle);
  252.  
  253.  
  254.             // スクロールバー
  255.             for (int i=0; i<mods_n; i++)
  256.             {
  257.                 string key = ModsParam.sKey[i];
  258.                 if (!mp.bEnabled[key]) continue;
  259.  
  260.                 int value_n = mp.fValue[key].Length;
  261.  
  262.                 conHeight += lineH2;
  263.                 for (int j=0; j<value_n; j++) conHeight += lineH * 2;
  264.                 conHeight += (int)(margin*2);
  265.             }
  266.            
  267.             overHeight = conHeight - (winHeight - conTop - margin);
  268.  
  269.             if (overHeight > 0)
  270.             {
  271.                 outRect.Set(winLeft+winWidth-margin*2, lineP, margin, winHeight-lineP+winTop-margin);
  272.                 scbarValue = GUI.VerticalScrollbar(outRect, scbarValue, 20f, 0f, 120f);
  273.  
  274.                 scrlf = true;
  275.                 outconLine = (int)(overHeight * scbarValue/100f);
  276.             }
  277.  
  278.    
  279.             // ラベルとスライダーバー
  280.             GUIStyle lstyle = "label";
  281.  
  282.             for (int i=0; i<mods_n; i++)
  283.             {
  284.                 if (lineP > winTop + winHeight - lineH * 2) break;
  285.  
  286.                 string key = ModsParam.sKey[i];
  287.                 if (!mp.bEnabled[key]) continue;
  288.  
  289.                 int value_n = mp.fValue[key].Length;
  290.  
  291.                 for (int j=0; j<value_n; j++)
  292.                 {
  293.                     if (scrlf)
  294.                     {
  295.                         if (thrcon < outconLine)
  296.                         {
  297.                             thrcon += lineH * 2;
  298.                             continue;    
  299.                         }
  300.                        
  301.                         if (lineP > winTop + winHeight - lineH * 2) break;
  302.                     }
  303.  
  304.                     if (j == 0)
  305.                     {
  306.                         lstyle.fontSize = 16;
  307.                         outRect.Set(winLeft+10, lineP, conWidth, lineH2);
  308.                         GUI.Label(outRect, key, lstyle);
  309.                         lineP += lineH2;
  310.                     }
  311.  
  312.                     lstyle.fontSize = 14;
  313.  
  314.                     string label = mp.sLabel[key][j];
  315.                     float value = mp.fValue[key][j];
  316.                     float vmin = mp.fVmin[key][j];
  317.                     float vmax = mp.fVmax[key][j];
  318.                     bool isScale = mp.bScale[key];
  319.  
  320.                     outRect.Set(winLeft+10, lineP, conWidth, lineH);
  321.                     GUI.Label(outRect, label+value.ToString("F"), lstyle);
  322.                     lineP += lineH;
  323.                     outRect.Set(winLeft+10, lineP, conWidth, lineH);
  324.                     if (isScale)
  325.                     {
  326.                         float tmp = value - 1f;
  327.                         tmp = GUI.HorizontalSlider(outRect, tmp, -vmax+1f, vmax-1f);
  328.                         mp.fValue[key][j] = 1f + tmp;
  329.                     }
  330.                     else
  331.                     {
  332.                         mp.fValue[key][j] = GUI.HorizontalSlider(outRect, value, vmin, vmax);
  333.                     }
  334.                     lineP += lineH;
  335.                 }
  336.  
  337.                 if (scrlf)
  338.                 {
  339.                     if (thrcon < outconLine)
  340.                     {
  341.                         thrcon += (int)(margin*2);
  342.                         continue;    
  343.                     }
  344.                     if (lineP > winTop + winHeight - lineH * 2) break;
  345.                 }
  346.                 lineP += (int)(margin*2);
  347.             }
  348.         }
  349.  
  350.         private void UpdateFreeComment(Maid maid, ModsParam mp)
  351.         {
  352.             string freeComment = maid.Param.status.free_comment;
  353.  
  354.             for(int i=0; i<ModsParam.Count; i++)
  355.             {
  356.                 string key = ModsParam.sKey[i];
  357.                 int vnum = mp.fValue[key].Length;
  358.  
  359.                 if (mp.bEnabled[key])
  360.                 {
  361.                     freeComment = Regex.Replace(freeComment, mp.sMatchPattern[ModsParam.sKey[i]], "");
  362.                     string ws = @"#" + ModsParam.sKey[i];
  363.  
  364.                     for(int j=0; j<vnum; j++)
  365.                     {
  366.                         ws +=  (j == 0) ? "=" : ",";
  367.                         ws += mp.fValue[key][j].ToString("F2");
  368.                     }
  369.  
  370.                     ws += "#";
  371.                    
  372.                     freeComment += ws;
  373.                 }
  374.             }
  375.  
  376.             maid.Param.SetFreeComment(freeComment);
  377.         }
  378.  
  379.         private float conRV(float vf)
  380.         {
  381.             return (vf < 0) ? 1f/vf : vf;
  382.         }
  383.         private float decRV(float vf)
  384.         {
  385.             return (vf < 1) ? -1f/vf : vf;
  386.         }
  387.     }
  388. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement