private static List <ItemEntity> LoadEntity(byte[] data, SectionParameters section) { var textEntities = new List <ItemEntity>(); var first = 0; for (int i = section.TextStart; i < section.TextEnd; i++) { if (data[i] == 0) { if (first > 0) { var start = i - first; var text = Encoding.UTF8.GetString(data, start, first); var offset = start - section.TextStart; textEntities.Add(new ItemEntity { Offset = offset, Text = text }); first = 0; } continue; } first++; } return(textEntities); }
private static void Do(string location, byte[] data, string excelName, SectionParameters section) { var excelPath = Path.Combine(location, excelName); var textEntities = LoadEntity(data, section); //CreateWorkbook(excelPath, textEntities); var map = textEntities.ToDictionary(x => x.Offset); ReplaceFromWorkbook(excelPath, map); Update(Path.Combine(location, "EBOOT.BIN"), data, map, section); }
private static void Update(string path, byte[] data, Dictionary <int, ItemEntity> map, SectionParameters section) { var textOffset = (section.TextStart - ADDRESS_OFFSET); var metaList = new List <MetaEntity>(); for (int i = section.MetaStart; i < section.MetaEnd; i += section.MetaOffset) { var meta = new MetaEntity { Offset = i }; metaList.Add(meta); for (int j = 0; j < section.MetaOffset; j += 4) { var value = GetTextReference(data, i + j, section.TextStart, section.TextEnd); if (value != -1) { meta.Values.Add(new Tuple <int, int>(j, value - textOffset)); } } } for (int i = section.TextStart; i < section.TextEnd; i++) { data[i] = 0; } var offset = 0; foreach (var item in map.Values.OrderBy(x => x.Offset)) { var rawText = Encoding.UTF8.GetBytes(item.Text); item.NewOffset = offset; Buffer.BlockCopy(rawText, 0, data, section.TextStart + offset, rawText.Length); data[section.TextStart + offset + rawText.Length] = 0; offset += rawText.Length + 1; if (offset > section.TextEnd) { throw new ArgumentOutOfRangeException(); } } foreach (var item in metaList) { foreach (var pair in item.Values) { var key = pair.Item2; var newValue = map[key].NewOffset + textOffset; Buffer.BlockCopy(BitConverter.GetBytes(newValue), 0, data, item.Offset + pair.Item1, 4); } } File.WriteAllBytes(path, data); }