123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Text;
- using UnityEngine;
- public class EditMod : MonoBehaviour
- {
- private void Awake()
- {
- }
- private void OnGUI()
- {
- if (this.m_eModMode == EditMod.MOD_MODE.MOD_TEX)
- {
- GUI.TextField(new Rect(10f, 10f, 100f, 20f), this.m_mpn.ToString(), 255);
- if (GUI.Button(new Rect(120f, 10f, 100f, 20f), "ExportBase"))
- {
- this.ModExportBase();
- }
- this.strModPath = GUI.TextField(new Rect(240f, 10f, 400f, 20f), this.strModPath, 255);
- if (GUI.Button(new Rect(650f, 10f, 100f, 20f), "Compile"))
- {
- this.ModCompileDir(this.strModPath);
- }
- }
- else if (this.m_eModMode == EditMod.MOD_MODE.MOD_MQO)
- {
- this.strModPath = GUI.TextField(new Rect(390f, 10f, 400f, 20f), this.strModPath, 255);
- if (GUI.Button(new Rect(800f, 10f, 100f, 20f), "Compile"))
- {
- this.ModCompileDirMqo(this.strModPath);
- }
- }
- }
- private void ModExportBase()
- {
- Maid maid = GameMain.Instance.CharacterMgr.GetMaid(0);
- maid.ExportModBaseMenu(this.m_mpn);
- }
- private void ModExportMqo(string f_strOutFileName)
- {
- Maid maid = GameMain.Instance.CharacterMgr.GetMaid(0);
- maid.ExportModBaseMqo(this.m_mpn, f_strOutFileName);
- NDebug.MessageBox("MOD Export Complete", "MODの元ファイルを出力しました。");
- }
- private void ModCompileDir(string f_strModPath)
- {
- if (!Directory.Exists(f_strModPath))
- {
- NUty.WinMessageBox(NUty.GetWindowHandle(), "コンパイル対象のパスが見つかりません。", "MOD Compile Error", 0);
- return;
- }
- string[] files = Directory.GetFiles(f_strModPath, "mod_*.txt", SearchOption.TopDirectoryOnly);
- foreach (string f_strModMenu in files)
- {
- this.ModCompileMenu(f_strModMenu);
- }
- }
- private void ModCompileDirMqo(string f_strModPath)
- {
- if (!Directory.Exists(f_strModPath))
- {
- NUty.WinMessageBox(NUty.GetWindowHandle(), "コンパイル対象のパスが見つかりません。", "MQO Compile Error", 0);
- return;
- }
- string[] files = Directory.GetFiles(f_strModPath, "*.*", SearchOption.TopDirectoryOnly);
- foreach (string text in files)
- {
- if (text.Contains(".menu.txt"))
- {
- ModCompile.CompileMenuScript(text);
- }
- else if (text.Contains(".mqo"))
- {
- ModCompile.ConvMqoToModel(text);
- }
- else if (text.Contains(".png"))
- {
- ModCompile.ExportTexture(text);
- }
- else if (text.Contains(".mate.txt"))
- {
- ModCompile.ExportMaterial(text);
- }
- }
- NDebug.MessageBox("MOD Compile Complete", "MODファイルのコンパイルが終了しました。");
- }
- private bool ModCompileMenu(string f_strModMenu)
- {
- byte[] array = null;
- try
- {
- using (FileStream fileStream = new FileStream(f_strModMenu, FileMode.Open))
- {
- if (fileStream == null)
- {
- NUty.WinMessageBox(NUty.GetWindowHandle(), "コンパイル対象のメニューがありません。\n" + f_strModMenu, "MOD Compile Error", 0);
- return false;
- }
- array = new byte[fileStream.Length];
- fileStream.Read(array, 0, (int)fileStream.Length);
- }
- }
- catch (Exception ex)
- {
- NUty.WinMessageBox(NUty.GetWindowHandle(), "ModCompileMenu MODアイテムメニューファイルが読み込めませんでした。\n " + f_strModMenu + "\n" + ex.Message, "MOD Compile Error", 0);
- return false;
- }
- string text = string.Empty;
- string value = string.Empty;
- string text2 = string.Empty;
- string value2 = string.Empty;
- string value3 = string.Empty;
- string value4 = string.Empty;
- string value5 = string.Empty;
- string text3 = string.Empty;
- Dictionary<string, EditMod.TexSet> dictionary = new Dictionary<string, EditMod.TexSet>();
- string @string = Encoding.UTF8.GetString(array);
- using (StringReader stringReader = new StringReader(@string))
- {
- string text4;
- while ((text4 = stringReader.ReadLine()) != null)
- {
- string[] array2 = text4.Split(new char[]
- {
- '\t',
- ' '
- }, StringSplitOptions.RemoveEmptyEntries);
- if (array2.Length != 0)
- {
- if (array2[0].IndexOf("/") != 0)
- {
- if (array2[0] == "基本アイテム")
- {
- text2 = array2[1];
- }
- else if (array2[0] == "アイテム名")
- {
- value2 = array2[1];
- }
- else if (array2[0] == "カテゴリ名")
- {
- value4 = array2[1];
- }
- else if (array2[0] == "説明")
- {
- value3 = array2[1];
- }
- else if (array2[0] == "アイコン")
- {
- array2[1] = array2[1].ToLower();
- value = array2[1];
- string text5 = Path.GetDirectoryName(f_strModMenu) + "\\";
- text5 += array2[1];
- try
- {
- FileStream fileStream2 = new FileStream(text5, FileMode.Open);
- if (fileStream2 == null)
- {
- NUty.WinMessageBox(NUty.GetWindowHandle(), "アイコンファイルが開けません。\n" + text5, "MOD Compile Error", 0);
- return false;
- }
- byte[] array3 = new byte[fileStream2.Length];
- fileStream2.Read(array3, 0, (int)fileStream2.Length);
- if (!dictionary.ContainsKey(array2[1].ToLower()))
- {
- dictionary.Add(array2[1].ToLower(), new EditMod.TexSet
- {
- nSize = (int)fileStream2.Length,
- byData = array3
- });
- }
- fileStream2.Close();
- fileStream2.Dispose();
- }
- catch (Exception ex2)
- {
- NDebug.MessageBox("指定のアイコンファイルが見つかりませんでした。\n" + array2[1], "MOD Compile Error");
- return false;
- }
- }
- else if (array2[0] == "色セット")
- {
- value5 = array2[1];
- if (array2.Length >= 3)
- {
- text3 = array2[2];
- }
- }
- else if (array2[0] == "テクスチャ設定")
- {
- array2[2] = array2[2].ToLower();
- string text6 = Path.GetDirectoryName(f_strModMenu) + "\\";
- text6 += array2[2];
- try
- {
- FileStream fileStream3 = new FileStream(text6, FileMode.Open);
- if (fileStream3 == null)
- {
- NUty.WinMessageBox(NUty.GetWindowHandle(), "テクスチャが開けません。\n" + text6, "MOD Compile Error", 0);
- return false;
- }
- byte[] array4 = new byte[fileStream3.Length];
- fileStream3.Read(array4, 0, (int)fileStream3.Length);
- if (!dictionary.ContainsKey(array2[2].ToLower()))
- {
- dictionary.Add(array2[2].ToLower(), new EditMod.TexSet
- {
- nSize = (int)fileStream3.Length,
- byData = array4
- });
- }
- fileStream3.Close();
- fileStream3.Dispose();
- }
- catch (Exception ex3)
- {
- array2[2] = Path.ChangeExtension(array2[2], ".tex");
- string text7 = array2[2].ToLower();
- if (!dictionary.ContainsKey(text7))
- {
- dictionary.Add(text7, new EditMod.TexSet
- {
- nSize = EditMod.dummyImg.Length,
- byData = EditMod.dummyImg
- });
- Debug.Log("画像ファイルが付近に見つからなかったので、内部のファイルシステムから呼び出すことにします。" + text7);
- }
- }
- }
- else if (array2[0] == "テクスチャ変更")
- {
- string text8 = array2[4].ToLower();
- string text9 = Path.GetDirectoryName(f_strModMenu) + "\\";
- string[] array5;
- if (text8.Contains("*"))
- {
- array5 = Directory.GetFiles(text9, text8, SearchOption.AllDirectories);
- }
- else
- {
- array5 = new string[]
- {
- text9 + text8
- };
- }
- foreach (string text10 in array5)
- {
- try
- {
- FileStream fileStream4 = new FileStream(text10, FileMode.Open);
- if (fileStream4 == null)
- {
- NUty.WinMessageBox(NUty.GetWindowHandle(), "テクスチャが開けません。\n" + text10, "MOD Compile Error", 0);
- return false;
- }
- byte[] array7 = new byte[fileStream4.Length];
- fileStream4.Read(array7, 0, (int)fileStream4.Length);
- if (!dictionary.ContainsKey(Path.GetFileName(text10).ToLower()))
- {
- dictionary.Add(Path.GetFileName(text10).ToLower(), new EditMod.TexSet
- {
- nSize = (int)fileStream4.Length,
- byData = array7
- });
- }
- fileStream4.Close();
- fileStream4.Dispose();
- }
- catch (Exception ex4)
- {
- string path = Path.GetFileName(text10);
- path = Path.ChangeExtension(path, ".tex");
- string text11 = text8.ToLower();
- if (!dictionary.ContainsKey(text11))
- {
- dictionary.Add(text11, new EditMod.TexSet
- {
- nSize = EditMod.dummyImg.Length,
- byData = EditMod.dummyImg
- });
- Debug.Log("画像ファイルが付近に見つからなかったので、内部のファイルシステムから呼び出すことにします。" + text11);
- }
- }
- }
- }
- foreach (string str in array2)
- {
- text = text + str + "\t";
- }
- text += "\n";
- }
- }
- }
- }
- MemoryStream memoryStream = new MemoryStream();
- BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
- binaryWriter.Write("CM3D2_MOD");
- binaryWriter.Write(1270);
- binaryWriter.Write(value);
- binaryWriter.Write(text2.ToLower());
- binaryWriter.Write(value2);
- binaryWriter.Write(value4);
- binaryWriter.Write(value3);
- if (string.IsNullOrEmpty(value5))
- {
- binaryWriter.Write(MPN.null_mpn.ToString());
- }
- else
- {
- binaryWriter.Write(value5);
- binaryWriter.Write(text3.ToLower());
- }
- binaryWriter.Write(text);
- binaryWriter.Write(dictionary.Count);
- foreach (KeyValuePair<string, EditMod.TexSet> keyValuePair in dictionary)
- {
- binaryWriter.Write(keyValuePair.Key);
- binaryWriter.Write(keyValuePair.Value.byData.Length);
- binaryWriter.Write(keyValuePair.Value.byData);
- }
- string text12 = Path.GetDirectoryName(f_strModMenu) + "\\_compiled\\";
- Directory.CreateDirectory(text12);
- text12 += Path.GetFileNameWithoutExtension(f_strModMenu);
- text12 += ".mod";
- File.WriteAllBytes(text12, memoryStream.ToArray());
- memoryStream.Close();
- memoryStream.Dispose();
- memoryStream = null;
- NUty.WinMessageBox(NUty.GetWindowHandle(), "MODコンパイル完了\n" + text12, "MOD Compile Completed", 0);
- return true;
- }
- private void Update()
- {
- if (!this.bPush && Input.GetKey(KeyCode.M) && Input.GetKey(KeyCode.O) && Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.Q))
- {
- if (this.m_eModMode != EditMod.MOD_MODE.MOD_TEX)
- {
- this.m_eModMode = EditMod.MOD_MODE.MOD_TEX;
- }
- else
- {
- this.m_eModMode = EditMod.MOD_MODE.MOD_NON;
- }
- this.bPush = true;
- }
- else if (!this.bPush && Input.GetKey(KeyCode.M) && Input.GetKey(KeyCode.O) && Input.GetKey(KeyCode.D) && Input.GetKey(KeyCode.Q))
- {
- if (this.m_eModMode != EditMod.MOD_MODE.MOD_MQO)
- {
- this.m_eModMode = EditMod.MOD_MODE.MOD_MQO;
- }
- else
- {
- this.m_eModMode = EditMod.MOD_MODE.MOD_NON;
- }
- this.bPush = true;
- }
- else if (!Input.GetKey(KeyCode.M) && !Input.GetKey(KeyCode.O) && !Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.Q))
- {
- this.bPush = false;
- }
- }
- private string strModPath = string.Empty;
- private EditMod.MOD_MODE m_eModMode;
- public MPN m_mpn;
- private string m_strOutFileName = string.Empty;
- public static readonly byte[] dummyImg = new byte[]
- {
- 137,
- 80,
- 78,
- 71,
- 13,
- 10,
- 26,
- 10,
- 0,
- 0,
- 0,
- 13,
- 73,
- 72,
- 68,
- 82,
- 0,
- 0,
- 0,
- 1,
- 0,
- 0,
- 0,
- 1,
- 8,
- 2,
- 0,
- 0,
- 0,
- 144,
- 119,
- 83,
- 222,
- 0,
- 0,
- 0,
- 12,
- 73,
- 68,
- 65,
- 84,
- 8,
- 153,
- 99,
- 248,
- byte.MaxValue,
- byte.MaxValue,
- 63,
- 0,
- 5,
- 254,
- 2,
- 254,
- 88,
- 242,
- 107,
- 14,
- 0,
- 0,
- 0,
- 0,
- 73,
- 69,
- 78,
- 68,
- 174,
- 66,
- 96,
- 130,
- 110,
- 101,
- 105
- };
- private bool bPush;
- private enum MOD_MODE
- {
- MOD_NON,
- MOD_TEX,
- MOD_MQO
- }
- private class TexSet
- {
- public int nSize;
- public byte[] byData;
- }
- }
|