C
C#•3y ago
Core Dream

BinaryReader Question

Trying to read the values AS bytes, but reader reads them as decimals, is there a trick to making it bytes?
private void ReadArenaDefs(string arenaSlotNumber)
{
string fileName = @$"{AppDomain.CurrentDomain.BaseDirectory}\ArenaDefinition_00505.jsfb";

byte[] bytesCrowdType = new byte[8];
int offset = 288;

if (File.Exists(fileName))
{
using (BinaryReader reader = new BinaryReader(new FileStream(fileName, FileMode.Open)))
{
reader.BaseStream.Seek(offset, SeekOrigin.Begin);
reader.Read(bytesCrowdType, 0, 8);
}
}
}
private void ReadArenaDefs(string arenaSlotNumber)
{
string fileName = @$"{AppDomain.CurrentDomain.BaseDirectory}\ArenaDefinition_00505.jsfb";

byte[] bytesCrowdType = new byte[8];
int offset = 288;

if (File.Exists(fileName))
{
using (BinaryReader reader = new BinaryReader(new FileStream(fileName, FileMode.Open)))
{
reader.BaseStream.Seek(offset, SeekOrigin.Begin);
reader.Read(bytesCrowdType, 0, 8);
}
}
}
18 Replies
reacher
reacher•3y ago
Just read the bytes directly from Stream You don't need BinaryReader, that's for reading bytes as other types
Core Dream
Core DreamOP•3y ago
hmm but the issue i have is it comes back as decimals
Core Dream
Core DreamOP•3y ago
Core Dream
Core DreamOP•3y ago
is there a way to convert it to bytes in the bytes[] array or it has to be .ToString("X") for that?
reacher
reacher•3y ago
It is bytes It's just displayed as base 10 Everything is bytes internally That's just how the debugger is configured to display them
Core Dream
Core DreamOP•3y ago
ah Is there a way to turn them into this? 732B2BDED5BB0FCA which is those in hex
reacher
reacher•3y ago
Probably, google "visual studio debugger hex"
Core Dream
Core DreamOP•3y ago
ty wait, so if i put it to "RELEASE" it will show hex? in my form
reacher
reacher•3y ago
Why would release have anything to do with anything?
Core Dream
Core DreamOP•3y ago
DebugOutputContent.Text = fs.Read(bytesCrowdType, 0, bytesCrowdType.Length).ToString("X"); Because I want the USER to see hex no one makes games or mods or does stuff in base 10 🙂 even in Unity I just suck at this I guess 😦
reacher
reacher•3y ago
Release doesn't have anything to do with how you format things to display to the user But yes if you want to display a hex string to the user you have to convert the bytes to a hex string like that
Core Dream
Core DreamOP•3y ago
foreach (byte b in bytesCrowdType) { DebugOutputContent.Text += b.ToString("X"); } got it 🙂 Thank you for putting up with my dumb question I appreciate your time and help Also the new help post system is amazing 🙂
reacher
reacher•3y ago
Yeah I kinda like it lol It's nice
Core Dream
Core DreamOP•3y ago
Yeah Discord did g ood on that front 🙂 Last question based on 'writing' bytes (fs i guess) don't worry if its not hex then right? it will convert to hex in file?
reacher
reacher•3y ago
If you want to write bytes you write bytes from a byte array Make sure you don't write a string
Core Dream
Core DreamOP•3y ago
private void WriteArenaDefs(string arenaSlotNumber)
{
string fileName = @$"{AppDomain.CurrentDomain.BaseDirectory}\ArenaDefinition_00505.jsfb";

byte[] bytesCrowdType = new byte[8];

int offset = 288;

if (File.Exists(fileName))
{
using (FileStream fs = File.OpenWrite(fileName))
{
for (int i = 0x120; i <= 0x127; i++)
{
fs.Position = offset;
fs.Write(bytesCrowdType);
}

fs.Close();

}
}
}
private void WriteArenaDefs(string arenaSlotNumber)
{
string fileName = @$"{AppDomain.CurrentDomain.BaseDirectory}\ArenaDefinition_00505.jsfb";

byte[] bytesCrowdType = new byte[8];

int offset = 288;

if (File.Exists(fileName))
{
using (FileStream fs = File.OpenWrite(fileName))
{
for (int i = 0x120; i <= 0x127; i++)
{
fs.Position = offset;
fs.Write(bytesCrowdType);
}

fs.Close();

}
}
}
so like this someone told me you needed to loop through each byte in the array too
reacher
reacher•3y ago
Why are you seeking and writing one byte at a time? Just seek once and write the whole array?
Core Dream
Core DreamOP•3y ago
I am not sure how to do that with writing fs.Position = offset; fs.Write(bytesCrowdType); ah think i got it
Want results from more Discord servers?
Add your server