public string GetStringValue(string fieldName) { var elementOffset = table.ElementContent.Until(segment => segment.Name == fieldName).Sum(segment => segment.Length); var valueAddress = table.Start + table.ElementLength * arrayIndex + elementOffset; var seg = table.ElementContent.Single(segment => segment.Name == fieldName); if (seg.Type == ElementContentType.PCS) { return(PCSString.Convert(model, valueAddress, seg.Length)); } else if (seg.Type == ElementContentType.Pointer) { valueAddress = model.ReadPointer(valueAddress); var length = PCSString.ReadString(model, valueAddress, true); return(PCSString.Convert(model, valueAddress, length)); } else { throw new NotImplementedException(); } }
public void SetStringValue(string fieldName, string value) { var elementOffset = table.ElementContent.Until(segment => segment.Name == fieldName).Sum(segment => segment.Length); var valueAddress = table.Start + table.ElementLength * arrayIndex + elementOffset; var seg = table.ElementContent.Single(segment => segment.Name == fieldName); if (seg.Type == ElementContentType.PCS) { var bytes = model.TextConverter.Convert(value, out var _); while (bytes.Count > seg.Length) { bytes.RemoveAt(bytes.Count - 1); } bytes[bytes.Count - 1] = 0xFF; while (bytes.Count < seg.Length) { bytes.Add(0); } token.ChangeData(model, valueAddress, bytes); } else if (seg.Type == ElementContentType.Pointer) { valueAddress = model.ReadPointer(valueAddress); var length = PCSString.ReadString(model, valueAddress, true); var bytes = model.TextConverter.Convert(value, out var _); var pcsRun = (PCSRun)model.GetNextRun(valueAddress); pcsRun = model.RelocateForExpansion(token, pcsRun, bytes.Count); token.ChangeData(model, pcsRun.Start, bytes); for (int i = pcsRun.Length; i < length; i++) { token.ChangeData(model, pcsRun.Start + i, 0xFF); } } else { throw new NotImplementedException(); } }
public string Convert(IReadOnlyList <byte> data, int startIndex, int length) { return(PCSString.Convert(gameCode, data, startIndex, length)); }
public List <byte> Convert(string text, out bool containsBadCharacters) { return(PCSString.Convert(text, gameCode, out containsBadCharacters)); }