View Full Version : need some guidance on write function packageio. Reading is fine
Keylan
09-27-2013, 04:26 AM
I am wondering if anyone can help me. I have been racking my brain most of today trying to figure this out. I am creating a save editor with C#. I made one before in vb, but I am switching languages, and not fully understanding what I am doing wrong.
I am using packageio, and I am using the following code to read:
reader.Position = PosEXP;
EXP = reader.ReadInt32();
reader.Position = PosLV;
LV = reader.ReadByte();
reader.Position = PosHP
HP = reader.ReadInt16();
This code works fine for reading the offsets. However, when I go to code the writing part, I am having issues. This first part works fine:
writer.Position = PosEXP;
writer.WriteInt32(EXP, Endian.Little);
But when I try to write wither the LV or HP, I get an error when trying to WriteByte and WriteInt16:
writer.Position = PosLV;
writer.WriteByte(LV);
writer.Position = HP;
writer.WriteInt16(HP);
I have tried Int16 with the Endian.Little part as well, and I keep getting errors. Does anyone know what my problem is? I had the same issue in my vb editor, and ended up using StreamWriter for those types of bytes, but I would like to stick with packageio this time around.
Thanks in advance for any assistance that can be given.
Emerald Lance
09-27-2013, 04:55 AM
WriteByte is writing a value between 0 and 255, right? And you're making sure to accomodate for the differences between a signed and unsigned integer (not trying to write 65355 unless the integer is specified)? Also, does your program have a GUI or is it text based? If GUI, are you making sure to specify which tool you're using within the GUI (textbox, combobox, numericupdown, etc)? If text, are you making sure everything is defined and called correctly?
Those are all common mistakes that everybody makes sometimes, so it's always good to double check. At any rate, everything looks fine for a text-style editor based on the snippets of code you posted. I don't think it will work as is for a GUI-style editor though (not unless you do some extra coding). Specifically, what error are you getting?
Keylan
09-28-2013, 03:51 AM
WriteByte is writing a value between 0 and 255, right? And you're making sure to accomodate for the differences between a signed and unsigned integer (not trying to write 65355 unless the integer is specified)? Also, does your program have a GUI or is it text based? If GUI, are you making sure to specify which tool you're using within the GUI (textbox, combobox, numericupdown, etc)? If text, are you making sure everything is defined and called correctly?
Those are all common mistakes that everybody makes sometimes, so it's always good to double check. At any rate, everything looks fine for a text-style editor based on the snippets of code you posted. I don't think it will work as is for a GUI-style editor though (not unless you do some extra coding). Specifically, what error are you getting?
Thanks for the reply.
I am using Visual Studio 2012, and using a GUI. I have it writing the data to textboxes. The textboxes are set to only allow for one number (for the Byte) and two numbers (for the Int16). I even tried to change the LV to tbLV.Text, but it is giving errors saying:
"The best overload method match for 'PackageIO.Writer.WriteByte(byte)' has some invalid arguments."
and
"The best overload method match for 'PackageIO.Writer.WriteInt16(short)' has some invalid arguments."
EDIT:
I apparently had all of my variables listed as int. I changed the single one to byte, and the 16 to short, and it seems to have made the red error line go away and let me compile. Hopefully it works.
Now I just need to figure out how to make it update the variables to match the textboxes. Going to try to use textbox_changed and see if it will work, but I have had issues with that in the past.
Sephiroth
09-28-2013, 04:48 AM
Thanks for the reply.
I am using Visual Studio 2012, and using a GUI. I have it writing the data to textboxes. The textboxes are set to only allow for one number (for the Byte) and two numbers (for the Int16). I even tried to change the LV to tbLV.Text, but it is giving errors saying:
"The best overload method match for 'PackageIO.Writer.WriteByte(byte)' has some invalid arguments."
and
"The best overload method match for 'PackageIO.Writer.WriteInt16(short)' has some invalid arguments."
EDIT:
I apparently had all of my variables listed as int. I changed the single one to byte, and the 16 to short, and it seems to have made the red error line go away and let me compile. Hopefully it works.
Now I just need to figure out how to make it update the variables to match the textboxes. Going to try to use textbox_changed and see if it will work, but I have had issues with that in the past.
Reader
VB - byte
Reader.Position = lv
Textbox1.Text = Reader.ReadByte
C# - byte
Reader.Position = lv;
Textbox1.Text = Reader.ReadByte;
VB - int8
Reader.Position = lv
Textbox1.Text = Reader.Readint8
C# - int8
Reader.Position = lv;
Textbox1.Text = Reader.Readint8;
VB - int16
Reader.Position = lv
Textbox1.Text = Reader.Readint16
C# - int16
Reader.Position = lv;
Textbox1.Text = Reader.Readint16;
VB - int24
Reader.Position = lv
Textbox1.Text = Reader.Readint24
C# - int24
Reader.Position = lv;
Textbox1.Text = Reader.Readint24;
VB - int32
Reader.Position = lv
Textbox1.Text = Reader.Readint32
C# - int32
Reader.Position = lv;
Textbox1.Text = Reader.Readint32;
Writer
VB - byte
Writer.Position = lv
Writer.WriteByte(CByte(Textbox1.Text))
C# - byte
Writer.Position = lv;
Writer.WriteByte(Convert.ToByte(Textbox1.Text));
VB - int8
Writer.Position = lv
Writer.Writeint8(CInt(Textbox1.Text))
C# - int8
Writer.Position = lv;
Writer.Writeint8(Convert.ToInt8(Textbox1.Text));
VB - int16
Writer.Position = lv
Writer.Writeint16(CInt(Textbox1.Text))
C# - int16
Writer.Position = lv;
Writer.Writeint16(Convert.ToInt16(Textbox1.Text));
VB - int24
Writer.Position = lv
Writer.Writeint24(CInt(Textbox1.Text))
C# - int24
Writer.Position = lv;
Writer.Writeint24(Convert.ToInt24(Textbox1.Text));
VB - int32
Writer.Position = lv
Writer.Writeint32(CInt(Textbox1.Text))
C# - int32
Writer.Position = lv;
Writer.Writeint32(Convert.ToInt32(Textbox1.Text));
Keylan
09-28-2013, 05:24 PM
Thank you so much. I had to make a few changes to what you posted, as it said for c# code to use WriteInt16(Convert.ToInt32()); and that have me errors. Just changed the 32 to 16 and it worked fine.
Sent from my Verizon Galaxy Note 2 using Xparent Skyblue Tapatalk 2
Emerald Lance
09-28-2013, 06:30 PM
That's good, I'm glad you got it working. Also, for the future, might I suggest numeric up down boxes for numbers? They're like text boxes that are specifically for numbers, and sometimes text boxes have a hard time transitioning from strings to integers (instead of Textbox1.Text, you'd use NumericUpDown.Value, which can only correspond to integers). At any rate, good luck with your editor. ^-^
Sephiroth
09-28-2013, 06:43 PM
Thank you so much. I had to make a few changes to what you posted, as it said for c# code to use WriteInt16(Convert.ToInt32()); and that have me errors. Just changed the 32 to 16 and it worked fine.
Sent from my Verizon Galaxy Note 2 using Xparent Skyblue Tapatalk 2
Oops my bad lol
vBulletin Solutions, Inc. All rights reserved.