本文整理汇总了C#中SubRecord.GetReadonlyData方法的典型用法代码示例。如果您正苦于以下问题:C# SubRecord.GetReadonlyData方法的具体用法?C# SubRecord.GetReadonlyData怎么用?C# SubRecord.GetReadonlyData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SubRecord
的用法示例。
在下文中一共展示了SubRecord.GetReadonlyData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MediumLevelRecordEditor
public MediumLevelRecordEditor(SubRecord sr, SubrecordStructure ss, dFormIDLookupS formIDLookup, dFormIDScan formIDScan, dLStringLookup strIDLookup)
{
this.InitializeComponent();
Icon = Resources.tesv_ico;
SuspendLayout();
this.sr = sr;
this.ss = ss;
this.formIDLookup = formIDLookup;
this.formIDScan = formIDScan;
this.strIDLookup = strIDLookup;
int offset = 0;
byte[] data = sr.GetReadonlyData();
this.boxes = new List<TextBox>(ss.elements.Length);
this.valueTypes = new List<ElementValueType>(ss.elements.Length);
this.elements = new List<Panel>();
int groupOffset = 0;
int CurrentGroup = 0;
try
{
for (int i = 0; i < ss.elements.Length; i++)
{
if (ss.elements[i].optional > 0 && offset == data.Length)
{
this.AddElement(ss.elements[i]);
}
else
{
this.AddElement(ss.elements[i], ref offset, data, ref groupOffset, ref CurrentGroup);
if (ss.elements[i].repeat > 0)
{
this.repeatcount++;
if (offset < data.Length)
{
i--;
}
}
}
}
if (ss.elements[ss.elements.Length - 1].repeat > 0 && this.repeatcount > 0)
{
this.AddElement(ss.elements[ss.elements.Length - 1]);
}
}
catch
{
MessageBox.Show("The subrecord doesn't appear to conform to the expected structure.\n" + "Saving is disabled, and the formatted information may be incorrect", "Warning");
this.bSave.Enabled = false;
}
ResumeLayout();
}
示例2: Process
public void Process(FalloutSnip.Data.Subrecord sr, SubRecord subrec)
{
FalloutSnip.Data.SubrecordElement expectedElement = (sr.Elements.Count >= 1) ? sr.Elements[0] : null;
if (expectedElement != null && expectedElement.type == "blob")
return;
byte[] data = subrec.GetReadonlyData();
if (data.Length == 0)
{
if (sr.Elements.Count == 0)
sr.Elements.Add(CreateBlob());
return;
}
if (data.Length == 2) {
// common scenarios
if (expectedElement != null && expectedElement.size == 2)
return;
FalloutSnip.Data.SubrecordElement elem = new FalloutSnip.Data.SubrecordElement();
elem.name = "Unknown";
elem.type = "short";
elem.size = 2;
sr.Elements.Add(elem);
UpdateSize(sr);
return;
}
if (data.Length > 0)
{
bool isAscii = true;
for (int i = 0; i < data.Length - 1 && isAscii; ++i)
isAscii = !Char.IsControl((char)data[i]);
isAscii = (isAscii && data[data.Length - 1] == 0);
if (isAscii)
{
// test if its a string
if (expectedElement == null)
{
FalloutSnip.Data.SubrecordElement elem = new FalloutSnip.Data.SubrecordElement();
elem.name = "Unknown";
elem.type = "string";
sr.Elements.Add(elem);
}
else if (expectedElement.type != "string")
{
sr.Elements.Clear();
sr.Elements.Add(CreateBlob());
}
return;
}
}
for (int offset = 0, elemSize = 4; offset < data.Length; offset += elemSize)
{
if (IsCanceled) return;
int left = data.Length - offset;
if (left >= 4) {
// common scenarios
if (expectedElement != null && expectedElement.size == 4)
continue;
ushort lhs = TypeConverter.h2s(data[offset], data[offset + 1]);
ushort uhs = TypeConverter.h2s(data[offset + 2], data[offset + 3]);
uint ui4 = TypeConverter.h2i(data[offset], data[offset + 1], data[offset + 2], data[offset + 3]);
if (ui4 == 0)
{
if (expectedElement == null)
{
FalloutSnip.Data.SubrecordElement elem = new FalloutSnip.Data.SubrecordElement();
elem.name = "Unknown";
elem.type = "int";
elem.size = 4;
sr.Elements.Add(elem);
UpdateSize(sr);
continue;
}
}
else
{
float flt = TypeConverter.h2f(data[offset], data[offset + 1], data[offset + 2], data[offset + 3]);
if (IsLikelyFloat(flt)) {
// replace element which is int with float
if (expectedElement == null)
{
FalloutSnip.Data.SubrecordElement elem = new FalloutSnip.Data.SubrecordElement();
elem.name = "Unknown";
elem.type = "float";
elem.size = 4;
sr.Elements.Add(elem);
}
else
{
if (expectedElement.type == "int")
expectedElement.type = "float";
}
continue;
}
//.........这里部分代码省略.........
示例3: MatchRecordAddConditionals
private static void MatchRecordAddConditionals(Dictionary<int, Conditional> conditions, SubRecord sr, ElementStructure[] ess)
{
int offset = 0;
byte[] data = sr.GetReadonlyData();
for (int j = 0; j < ess.Length; j++)
{
if (ess[j].CondID != 0)
{
switch (ess[j].type)
{
case ElementValueType.Int:
case ElementValueType.FormID:
conditions[ess[j].CondID] = new Conditional(ElementValueType.Int, TypeConverter.h2si(data[offset], data[offset + 1], data[offset + 2], data[offset + 3]));
offset += 4;
break;
case ElementValueType.UInt:
conditions[ess[j].CondID] = new Conditional(ElementValueType.UInt, (uint)TypeConverter.h2i(data[offset], data[offset + 1], data[offset + 2], data[offset + 3]));
offset += 4;
break;
case ElementValueType.Float:
conditions[ess[j].CondID] = new Conditional(ElementValueType.Float, TypeConverter.h2f(data[offset], data[offset + 1], data[offset + 2], data[offset + 3]));
offset += 4;
break;
case ElementValueType.Short:
conditions[ess[j].CondID] = new Conditional(ElementValueType.Short, (int)TypeConverter.h2ss(data[offset], data[offset + 1]));
offset += 2;
break;
case ElementValueType.UShort:
conditions[ess[j].CondID] = new Conditional(ElementValueType.UShort, TypeConverter.h2s(data[offset], data[offset + 1]));
offset += 2;
break;
case ElementValueType.SByte:
conditions[ess[j].CondID] = new Conditional(ElementValueType.SByte, (sbyte)data[offset]);
offset++;
break;
case ElementValueType.Byte:
conditions[ess[j].CondID] = new Conditional(ElementValueType.Byte, (int)data[offset]);
offset++;
break;
case ElementValueType.String:
{
string s = "";
while (data[offset] != 0) s += (char)data[offset++];
offset++;
conditions[ess[j].CondID] = new Conditional(ElementValueType.String, s);
}
break;
case ElementValueType.fstring:
conditions[ess[j].CondID] = new Conditional(ElementValueType.String, sr.GetStrData());
break;
case ElementValueType.BString:
{
int len = TypeConverter.h2s(data[offset], data[offset + 1]);
string s = System.Text.Encoding.ASCII.GetString(data, offset + 2, len);
offset = offset + (2 + len);
conditions[ess[j].CondID] = new Conditional(ElementValueType.String, s);
} break;
case ElementValueType.LString:
conditions[ess[j].CondID] = new Conditional(ElementValueType.Int, TypeConverter.h2si(data[offset], data[offset + 1], data[offset + 2], data[offset + 3]));
offset += 4;
break;
default:
throw new ApplicationException();
}
}
else
{
switch (ess[j].type)
{
case ElementValueType.Int:
case ElementValueType.UInt:
case ElementValueType.FormID:
case ElementValueType.Float:
offset += 4;
break;
case ElementValueType.UShort:
case ElementValueType.Short:
offset += 2;
break;
case ElementValueType.SByte:
case ElementValueType.Byte:
offset++;
break;
case ElementValueType.String:
while (data[offset] != 0) offset++;
offset++;
break;
case ElementValueType.fstring:
break;
case ElementValueType.LString:
break;
case ElementValueType.BString:
int len = TypeConverter.h2s(data[offset], data[offset + 1]);
offset += 2 + len;
break;
default:
throw new ApplicationException();
}
}
}
//.........这里部分代码省略.........