private void AddGatheredStrings() { if (mStringsToAdd.Count > 0) { Chunk cur = null; List <Chunk> locChunks = new List <Chunk>(); // rip through the whole thing first. while ((cur = mCoreUucfbFileHelper.RipChunk(false)) != null) { if (cur.Type == "Locl") { locChunks.Add(cur); } } Chunk c = null; // process from back to front so we don't mess up the chunk's knowledge of it's position for (int i = locChunks.Count - 1; i > -1; i--) { c = locChunks[i]; if (mStringsToAdd.ContainsKey(c.Name)) { LocHelper helper = new LocHelper(c.GetAssetData()); helper.AddNewStrings(mStringsToAdd[c.Name].ToString()); mCoreUucfbFileHelper.ReplaceUcfbChunk(c, helper.GetUcfbData(), true); } } } }
private void getStringToolStripMenuItem_Click(object sender, EventArgs e) { string stringId = StringInputDlg.GetString("Enter string id", "It can be a hex number (starting with '0x') or the '.' seperated words like 'cheats.ammo_off'"); if (!String.IsNullOrEmpty(stringId)) { if (mAssetListBox.SelectedIndex > -1) { Chunk c = mAssetListBox.Items[mAssetListBox.SelectedIndex] as Chunk; if (c.Type.ToLower().StartsWith("loc")) { LocHelper lc = new LocHelper(c.GetAssetData()); string result = lc.GetString(stringId); if (!String.IsNullOrEmpty(result)) { mMainTextBox.Text = result; } else { mMainTextBox.Text = String.Format("StringId '{0}', not found", stringId); } } } } }
public List <byte> GetLocBytes() { /* special cases * if (current == '"') * { * sb.Append("\\\""); // escape the quote * cur.Append("\\\""); * } * else if (current == '\\') * { * sb.Append("\\\\"); // escape the escape! * cur.Append("\\\\"); * } */ string string_data = Content.Replace("\\\\", "\\").Replace("\\\"", "\"").Replace("\r\n", "\n").Replace("\n", "\r\n"); if (string_data == "") { string_data = " "; } uint hashId = LocHelper.GetHashId(StringId); UInt16 sz = (UInt16)((string_data.Length * 2) + 2 + 4 + 4); // 2:size info 4:hashId 4 min zero bytes if (sz % 4 != 0) { sz += (UInt16)2; } //if (string_data == "") sz = 0x10; // empty string hack bool sixZeros = false; // TODO: figure out how to tell if we use this. List <byte> mData = new List <byte>(new byte[sz]); //write hashId int stringLoc = 0; BinUtils.WriteNumberAtLocation(stringLoc, hashId, mData); // write the size BinUtils.Write2ByteNumberAtLocation(stringLoc + 4, sz, mData); // lay down string stringLoc += 6; /** MODIFYING 'stringLoc' NOW!! **/ for (int i = 0; i < string_data.Length; i++) { BinUtils.Write2ByteNumberAtLocation(stringLoc, string_data[i], mData); stringLoc += 2; } BinUtils.WriteNumberAtLocation(stringLoc, 0, mData); if (sixZeros) { BinUtils.Write2ByteNumberAtLocation(stringLoc + 4, 0, mData); } return(mData); }
private void createMungedLocFileFromDataToolStripMenuItem_Click(object sender, EventArgs e) { List <string> errors = new List <string>(); List <byte> data = LocHelper.GetBinaryLocData(mMainTextBox.Text, errors); if (data.Count > 0) { LocHelper.MakeUcfb(data, (uint)data.Count); SaveFileDialog dlg = new SaveFileDialog(); dlg.RestoreDirectory = true; int lastSlash = mLVLFileTextBox.Text.LastIndexOf(Path.DirectorySeparatorChar); dlg.InitialDirectory = mLVLFileTextBox.Text.Substring(0, lastSlash); if (dlg.ShowDialog() == DialogResult.OK) { File.WriteAllBytes(dlg.FileName, data.ToArray()); } dlg.Dispose(); } }