I have structure for file I want to create simple GUI program for reading file but this structure codded in c++ how can I use this with c# ? ı want to read file with strcut and then convert output to json file.
I tried something like this,
public class _StlEntry
{
public String string1;
public String string2;
public String string3;
public String string4;
}
public class StlEntry
{
public int[] unknown1;
public int string1offset;
public int string1size;
//--
public int[] unknown2;
public int string2offset;
public int string2size;
//--
public int[] unknown3;
public int string3offset;
public int string3size;
//--
public int[] unknown4;
public int string4offset;
public int string4size;
//--
public int unknown5;
public int[] unknown6;
OpenFileDialog dialog = new OpenFileDialog();
DialogResult result = dialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
string filename = dialog.FileName;
byte[] data = File.ReadAllBytes(filename);
struct Item // sizeof 0x5F0
{
0x000 DWord unknown1; // always 0x00000000
0x000 DWord itemName[256]; // non-NLS key name of the item
0x104 DWord actorId; // Actor MPQ Id
0x108 DWord itemTypeHash; // hash of the ItemType
0x114 DWord iLevel; // item level
0x120 DWord numRandomAffixes; // number of random affixes
0x124 DWord numSockets; // number of sockets the item can have
0x128 DWord stackSize; // stack size
0x12C DWord goldPrice; // gold buy price (sell price is 15% of buy)
} ```
Try following :
public class _StlEntry
{
public uint unknown1; // always 0x00000000
public uint[] itemName;
public uint actorId; // Actor MPQ Id
public uint itemTypeHash; // hash of the ItemType
public uint iLevel; // item level
public uint numRandomAffixes; // number of random affixes
public uint numSockets; // number of sockets the item can have
public uint stackSize; // stack size
public uint goldPrice; // gold buy price (sell price is 15% of buy)
public _StlEntry()
{
OpenFileDialog dialog = new OpenFileDialog();
DialogResult result = dialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
string filename = dialog.FileName;
FileStream stream = File.OpenRead(filename);
BinaryReader reader = new BinaryReader(stream);
unknown1 = reader.ReadUInt32();
itemName = Enumerable.Range(0, 64).Select(x => reader.ReadUInt32()).ToArray();
actorId = reader.ReadUInt32();
itemTypeHash = reader.ReadUInt32();
iLevel = reader.ReadUInt32();
numRandomAffixes = reader.ReadUInt32();
numSockets = reader.ReadUInt32();
stackSize = reader.ReadUInt32();
goldPrice = reader.ReadUInt32();
}
}
}
User contributions licensed under CC BY-SA 3.0