- Joined
- Aug 14, 2009
- Messages
- 2,304
- Reaction score
- 1,189
In this tutorial, I will show everybody how to partially read SCB Files in C#. But you can convert my code into any language you want.
First what's the SCB file? It's basically a SCO file but in binary format. So instead of saving everything as text, it saves it as binary values.
So first the structure of the SCB format.
So first create a FileStream using System.IO:
Now you can create a BinaryReader we use them to read the actual binary file.
So now for the actual reading:
As I said earlier, the File Version is a unsigned int. In C# it's uint. Because it's an uint not an ushort, we have to use ReadUInt32. Not 16.
The File Flags are an unsigned long. In C# it's ulong. Because in 32-Bit C++ a unsigned long is 4 bytes we have to use ReadUInt32 again. Not 64.
Now for reading the name length & name. We can't use the method ReadString from BinaryReader because of null terminators. So we have to read the length and then all chars.
Finally we come to the tricky part. Because Eternity / SCB files use r3dPoint3D to save we have to figure out how big r3dPoint3D is. In this case it's 12 bytes. Because X, Y, Z (3) multiplied by 4 (4 bytes for each float / int). We can easily read 12 bytes then split them up, or we could read 4 bytes at a time.
I'll read 12 bytes and then cut the bytes to 4 individual pieces.
We read 12 bytes:
now we create a new variable that is a byte array with 4 bytes:
and copy the first 4 bytes to our buffer
Now the same thing for our 4 next bytes:
And again for the last 4 bytes:
Now we have our x, y, z pivot. We can now convert the byte pivot coordinates using the BitConverter ToSingle method:
If you like this Tutorial click the like button . If I should do the rest of the file just lemme know!
First what's the SCB file? It's basically a SCO file but in binary format. So instead of saving everything as text, it saves it as binary values.
So first the structure of the SCB format.
Version - unsigned int
Flags - unsigned long
Name Length - int
Name - /\ char sizeof name length
Pivot - 12 bytes (3 float numbers)
So first create a FileStream using System.IO:
Code:
FileStream fs = File.Open("C:\\Models\\Target_01.scb", FileMode.Open);
Now you can create a BinaryReader we use them to read the actual binary file.
Code:
BinaryReader br = new BinaryReader(fs);
So now for the actual reading:
As I said earlier, the File Version is a unsigned int. In C# it's uint. Because it's an uint not an ushort, we have to use ReadUInt32. Not 16.
Code:
uint fileVersion = br.ReadUInt32();
The File Flags are an unsigned long. In C# it's ulong. Because in 32-Bit C++ a unsigned long is 4 bytes we have to use ReadUInt32 again. Not 64.
Code:
ulong fileFlags = br.ReadUInt32();
Now for reading the name length & name. We can't use the method ReadString from BinaryReader because of null terminators. So we have to read the length and then all chars.
Code:
// Read the name length
int nameLength = br.ReadInt32();
// Read namelength chars
string name = new string(br.ReadChars(nameLength));
Finally we come to the tricky part. Because Eternity / SCB files use r3dPoint3D to save we have to figure out how big r3dPoint3D is. In this case it's 12 bytes. Because X, Y, Z (3) multiplied by 4 (4 bytes for each float / int). We can easily read 12 bytes then split them up, or we could read 4 bytes at a time.
I'll read 12 bytes and then cut the bytes to 4 individual pieces.
We read 12 bytes:
Code:
byte[] buffer = br.ReadBytes(12);
now we create a new variable that is a byte array with 4 bytes:
Code:
var x = new byte[4];
and copy the first 4 bytes to our buffer
Code:
Array.Copy(buffer, 0, x, 0, 4);
Now the same thing for our 4 next bytes:
Code:
var y = new byte[4];
Array.Copy(buffer, 4, y, 0, 4);
And again for the last 4 bytes:
Code:
var z = new byte[4];
Array.Copy(buffer, 8, z, 0, 4);
Now we have our x, y, z pivot. We can now convert the byte pivot coordinates using the BitConverter ToSingle method:
Code:
System.BitConverter.ToSingle(x, 0)
If you like this Tutorial click the like button . If I should do the rest of the file just lemme know!
Last edited: