|
-
September 14th, 2009, 10:03 AM
#1
Small problem Reading file
Hello,
I recently started C# coding and I think i've done a pretty good job uptill now but I got stuck when trying to read a filetype called QSD.
It has this in it:
:FOREACH( condition_count )
DWORD length
DWORD command
BYTE[length - 8] data
:ENDFOR
:FOREACH( action_count )
DWORD length
DWORD command
BYTE[length - 8] data
:ENDFOR
I know how to read the Length and command DWORDs but not how to read that BYTE. I don't understand what I need to do with the Length-8 thing.
Can someone please explain?
-
September 14th, 2009, 01:24 PM
#2
Re: Small problem Reading file
Well I am not familiar with the QSD file structure but if you are using the BinaryReader class you can use the ReadBytes method which takes the number of bytes to read, which will be the value you got from length minus 8 because you already got 4 bytes with the length and 4 bytes with the command.
-
September 14th, 2009, 01:53 PM
#3
Re: Small problem Reading file
here this is what I have uptil now:
Code:
<Structure of QSD file>
DWORD file_version
DWORD block_count
SSTR qsd_name
:FOREACH( block_count )
DWORD record_count
SSTR block_name
:FOREACH( record_count )
BYTE check_next
DWORD condition_count
DWORD action_count
SSTR record_name
:FOREACH( condition_count )
DWORD length
DWORD command
BYTE[length - 8] data
:ENDFOR
:FOREACH( action_count )
DWORD length
DWORD command
BYTE[length - 8] data
:ENDFOR
:ENDFOR
:ENDFOR
And this is what I have sofar:
Code:
public class QSDConditions
{
public int length;
public int command;
public byte[] data;
}
public void OpenQSD(string filePath)
{
FilePath = filePath;
BinaryReader fh = new BinaryReader(File.OpenRead(FilePath));
//Basic info. Maybe usefull to display later?
fileversion = fh.ReadInt32();
// This is just the basis info and allows us to start.
BlockCount = fh.ReadInt32();
QSDname = Encoding.GetEncoding("EUC-KR").GetString(fh.ReadBytes(fh.ReadInt16())).Trim("\0");
blocks = new List<QSDBlocks>(BlockCount);
//oke first ForEach
for (int i = 0; i < BlockCount; i++)
{
blocks.Add(new QSDBlocks()
{
record_count = fh.ReadInt32(),
blockname = Encoding.GetEncoding("EUC-KR").GetString(fh.ReadBytes(fh.ReadInt16())).Trim("\0")
});
int recordcount = blocks[i].record_count;
blocks[i].records = new List<QSDRecords>(blocks[i].record_count);
//Records now for each block. Unsure about the LIST<> though.
for (int j = 0; j < recordcount; j++)
{
blocks[i].records.Add(new QSDRecords()
{
check_next = fh.ReadByte(),
condition_count = fh.ReadInt32(),
action_count = fh.ReadInt32(),
record_name = Encoding.GetEncoding("EUC-KR").GetString(fh.ReadBytes(fh.ReadInt16())).Trim("\0")
});
int conditioncount = blocks[i].records[j].condition_count;
int actioncount = blocks[i].records[j].action_count;
blocks[i].records[j].Conditions = new List<QSDConditions>(blocks[i].records[j].condition_count);
//Quest Conditions reader
for (int k = 0; k < conditioncount; k++)
{
blocks[i].records[j].Conditions.Add(new QSDConditions()
{
length = fh.ReadInt32(),
command = fh.ReadInt32(),
data =
});
}
}
}
I havent continued since I ran stuck on the data. I didnt paste evrything but I think I copied all that is important.
-
September 14th, 2009, 04:34 PM
#4
Re: Small problem Reading file
Alright, I found the problem was quite obvious now I looked at it...
[Length - 8]
Length is 32 Bytes.
Length - 8 = 24 bytes.
So i just had to do
ReadBytes(24)
Thanks Someuser didnt think of something that easy actually.
Now I just need to find a way to read OpCodes/Transfer int into OpCodes
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|