public string toString() { MobFileSection cur = this; var encoding = Encoding.GetEncoding(1251); MobFileSectionInfo info = cur.info; int delta = 0; string result = ""; switch (info.Type) { case SectionType.ST_STRING: case SectionType.ST_SCRIPT: delta = BitConverter.ToInt32(cur.Data, 4) - 8; result = encoding.GetString(cur.Data, 8, delta); break; case SectionType.ST_SCRIPT_ENC: delta = BitConverter.ToInt32(cur.Data, 4) - 12; CryptScript(cur.Data); result = encoding.GetString(cur.Data, 12, delta); CryptScript(cur.Data); break; } return(result); }
public void setId(SectionId id) { MobFileSection sec = this; sec.info.Id = id; BitConverter.GetBytes(Convert.ToUInt32(id)).CopyTo(sec.Data, 0); }
public void ReturnSection() { if (CurrentSection.Owner != null) { CurrentSection = CurrentSection.Owner; } }
public void setString(string text) { MobFileSection cur = this; var encoding = Encoding.GetEncoding(1251); MobFileSectionInfo info = cur.info; byte[] temp; int delta = BitConverter.ToInt32(cur.Data, 4) - 8; switch (info.Type) { case SectionType.ST_STRING: case SectionType.ST_SCRIPT: temp = new byte[text.Length + 8]; Array.Copy(cur.Data, temp, 8); encoding.GetBytes(text).CopyTo(temp, 8); break; case SectionType.ST_SCRIPT_ENC: delta -= 4; temp = new byte[text.Length + 12]; Array.Copy(cur.Data, temp, 12); encoding.GetBytes(text).CopyTo(temp, 12); CryptScript(temp); break; default: return; } cur.Data = temp; delta = text.Length - delta; FixSize(delta); }
public int SaveMobFile(string filename) { System.IO.FileStream fs = new System.IO.FileStream(filename, System.IO.FileMode.Create); Stack <MobFileSection> stack = new Stack <MobFileSection>(); MobFileSection cur = MainSection; stack.Push(null); do { if (cur.Items != null) { for (int i = cur.Items.Count - 1; i >= 0; --i) { stack.Push(cur.Items[i]); } } if (cur.Data != null) { fs.Write(cur.Data, 0, cur.Data.Length); } } while ((cur = stack.Pop()) != null); fs.Close(); Changed = false; return(0); }
public ErrorCodes OpenMobFile(string filename) { Filename = filename; System.IO.FileStream mob_file; try { mob_file = System.IO.File.Open(filename, System.IO.FileMode.Open); } catch { return(ErrorCodes.CannotOpen); } //main_section.data_size = (uint)mob_file.Length; MainSection.Data = new byte[(uint)mob_file.Length]; //main_section.data_offset = 0; mob_file.Read(MainSection.Data, 0, MainSection.Data.Length); mob_file.Close(); CurrentSection = MainSection; ErrorCodes result = MainSection.ReadSubsections(); if (result != 0) { CurrentSection = MainSection = new MobFileSection(null); } return(result); }
public object UserValue; // Адовый костыль. Здесь будут храниться всякие ГУИшные данные public MobFileSection(MobFileSection owner = null) { this.Owner = owner; Data = null; //data_size = 0; info = null; Items = null; Readed = false; }
public MobFileSection Clone(MobFileSection owner) { MobFileSection new_sect = new MobFileSection(owner); Stack <MobFileSection> stack1 = new Stack <MobFileSection>(); Stack <MobFileSection> stack2 = new Stack <MobFileSection>(); MobFileSection cur = this, cur_new = new_sect; stack1.Push(null); stack2.Push(null); do { if (cur.Items != null && cur.Items.Count > 0) { cur_new.Items = new List <MobFileSection>(cur.Items.Count); for (int i = 0; i < cur.Items.Count; ++i) { stack1.Push(cur.Items[i]); cur_new.Items.Add(new MobFileSection(cur_new)); stack2.Push(cur_new.Items[i]); } } else { cur_new.Items = null; } if (cur.Data != null) { cur_new.Data = (byte[])cur.Data.Clone(); // WARNING } else { cur_new.Data = null; } cur_new.info = cur.info; cur_new.Readed = cur.Readed; cur = stack1.Pop(); cur_new = stack2.Pop(); } while (cur != null && cur_new != null); return(new_sect); }
public double toNumber() { MobFileSection sec = this; switch (sec.info.Type) { case SectionType.ST_BYTE: return(sec.Data[8]); case SectionType.ST_DWORD: return(BitConverter.ToUInt32(sec.Data, 8)); case SectionType.ST_FLOAT: return(BitConverter.ToSingle(sec.Data, 8)); } return(double.NaN); }
public void setNumber(double value) { MobFileSection sec = this; switch (sec.info.Type) { case SectionType.ST_BYTE: sec.Data[8] = Convert.ToByte(value); break; case SectionType.ST_DWORD: BitConverter.GetBytes(Convert.ToUInt32(value)).CopyTo(sec.Data, 8); break; case SectionType.ST_FLOAT: BitConverter.GetBytes(Convert.ToSingle(value)).CopyTo(sec.Data, 8); break; } }
public int FixSize(int delta) // delta = newSize - oldSize { MobFileSection cur = this; int size; while (cur != null) { if (cur.Data != null) { if (cur.Data.Length >= 8) { size = BitConverter.ToInt32(cur.Data, 4); size += delta; BitConverter.GetBytes(size).CopyTo(cur.Data, 4); } else { return(1); } } cur = cur.Owner; } return(0); }
public MobFile(string filename) { MainSection = new MobFileSection(null); OpenMobFile(filename); Changed = false; }
public MobFile() { MainSection = new MobFileSection(null); Changed = false; }