internal void LoadStart(BinaryReader theReader, Hsp3Dictionary theDictionary) { if (theReader == null) { throw new ArgumentNullException("readerにnull値を指定できません"); } if (theDictionary == null) { throw new ArgumentNullException("dictionaryにnull値を指定できません"); } seekOrigin = theReader.BaseStream.Position; reader = theReader; dictionary = theDictionary; isStarted = true; }
private void RenameFunctions(Hsp3Dictionary dictionary) { //#funcなどの名前かぶり対策 List <string> functionNames = new List <string>(); List <Function> initializer = new List <Function>(); List <Function> comfuncs = new List <Function>(); List <Function> dllfuncs = new List <Function>(); //ver1.20 標準命令を避けるように functionNames.AddRange(dictionary.GetAllFuncName()); foreach (Function func in functions) { switch (func.Type) { case FunctionType.cfunc: case FunctionType.func: dllfuncs.Add(func); break; case FunctionType.comfunc: comfuncs.Add(func); break; case FunctionType.defcfunc: case FunctionType.deffunc: case FunctionType.module: if (func.ParentModule != null) //(func.DefaultName.Equals("__init", StringComparison.OrdinalIgnoreCase) || func.DefaultName.Equals("__term", StringComparison.OrdinalIgnoreCase)) { initializer.Add(func); } else { func.SetName(func.DefaultName); functionNames.Add(func.DefaultName.ToLower()); } break; } } foreach (Function func in initializer) { string defName = func.DefaultName; if (!functionNames.Contains(defName.ToLower())) { func.SetName(defName); functionNames.Add(defName.ToLower()); continue; } string newName = defName; int index = 1; do { newName = string.Format("{0}_{1}", defName, index); index++; } while (functionNames.Contains(newName)); func.SetName(newName); functionNames.Add(newName.ToLower()); } foreach (Function func in dllfuncs) { string defName = func.DefaultName; string newName = defName; if (newName.StartsWith("_", StringComparison.Ordinal) && (newName.Length > 1)) { newName = newName.Substring(1); } int atIndex = newName.IndexOf("@", StringComparison.Ordinal); if (atIndex > 0) { newName = newName.Substring(0, atIndex); } if (!functionNames.Contains(newName.ToLower())) { func.SetName(newName); functionNames.Add(newName.ToLower()); continue; } int index = 1; do { newName = string.Format("func_{0}", index); index++; } while (functionNames.Contains(newName)); func.SetName(newName); functionNames.Add(newName.ToLower()); } foreach (Function func in comfuncs) { string newName = ""; int index = 1; do { newName = string.Format("comfunc_{0}", index); index++; } while (functionNames.Contains(newName)); //.ToLower() func.SetName(newName); functionNames.Add(newName.ToLower()); } }
internal void ReadPreprocessor(Hsp3Dictionary dictionary) { if (!isStarted) { throw new InvalidOperationException("LoadStartが呼び出されていません"); } if (header == null) { throw new InvalidOperationException("ヘッダーが読み込まれていません"); } if (header.RuntimeStart != 0) { string runtimeName = ReadString((int)header.RuntimeStart, (int)(header.CodeStart - header.RuntimeStart)); if (runtimeName != null) { runtime = new Runtime(runtimeName); } } uint count = header.LabelCount; for (int i = 0; i < count; i++) { long offset = seekOrigin + header.LabelStart + ((int)HeaderDataSize.Label * i); reader.BaseStream.Seek(offset, SeekOrigin.Begin); labels.Add(Label.FromBinaryReader(reader, this, i)); } count = header.DllCount; for (int i = 0; i < count; i++) { long offset = seekOrigin + header.DllStart + ((int)HeaderDataSize.Dll * i); reader.BaseStream.Seek(offset, SeekOrigin.Begin); dlls.Add(Usedll.FromBinaryReader(reader, this, i)); } count = header.ParameterCount; for (int i = 0; i < count; i++) { long offset = seekOrigin + header.ParameterStart + ((int)HeaderDataSize.Parameter * i); reader.BaseStream.Seek(offset, SeekOrigin.Begin); functionParams.Add(Param.FromBinaryReader(reader, this, i)); } count = header.FunctionCount; for (int i = 0; i < count; i++) { long offset = seekOrigin + header.FunctionStart + ((int)HeaderDataSize.Function * i); reader.BaseStream.Seek(offset, SeekOrigin.Begin); functions.Add(Function.FromBinaryReader(reader, this, i)); } count = header.PluginCount; for (int i = 0; i < count; i++) { long offset = seekOrigin + header.PluginStart + ((int)HeaderDataSize.Plugin * i); reader.BaseStream.Seek(offset, SeekOrigin.Begin); plugIns.Add(PlugIn.FromBinaryReader(reader, this, i)); } if ((count != 0) && (header.PluginParameterCount != 0)) { plugIns[0].ExtendedTypeCount = (int)header.PluginParameterCount; } foreach (Param param in functionParams) { param.SetFunction(this); } RenameFunctions(dictionary); ReadDebugInfo(); }