STB Editor in C#

This forum is for main questions (format files, STB / STL and so on).

Moderators: osRose dev team, ospRose dev team, osiRose dev team, Moderators

Forum rules
Client Editing is a delicate subject. osRose and osiRose will not support or use any Client Editing tool or results as a standard. So you are free to experiment, test, and develop there on Client Editing, but at your own risk :)

STB Editor in C#

Postby Stark on Mon Nov 26, 2012 4:07 pm

Dear OsRose community,

Recently I became interested in trying to make editors for files inside the Rose client. Of course there's already a bunch of editors so for the most part there is no real purpose in trying to create and editor besides wanting to learn how to make such tools in general for fun, in my case.

I usually program in C# and I wanted to start with an STB editor because it seemed the most straightforward to me. Using the following topics I got as far as the code at the bottom shows you:
- viewtopic.php?f=34&t=4498&p=48621
- viewtopic.php?f=34&t=4498&p=48638

Although the topics were a little vague, they were still quite helpfull. Everything untill rowheight seems to be fine. I manually checked if the offset was correct using a hex editor and it was fine. But after this it only returns me negative numbers, which seems to me is incorrect as it makes the program crash and it doesn't make any sense in the first place. Some searching brought me to the subject of endianness which seems to hold the key to my fix, but I'm a little over my head here, so I was hoping one of you could help me solve the problem. I'm not an expert programmer, but I'm willing to learn.

  1.        public string FormatCode;
  2.         public Int32 data_offset;
  3.         public Int32 rowcount;
  4.         public Int32 columncount;
  5.  
  6.         public void Load(string filePath)
  7.         {
  8.             Encoding koreanEncoding = Encoding.GetEncoding("EUC-KR");
  9.  
  10.             FileStream fileStream = File.OpenRead(filePath);
  11.             BinaryReader fh = new BinaryReader(fileStream, koreanEncoding);
  12.  
  13.             this.FormatCode = koreanEncoding.GetString(fh.ReadBytes(4));
  14.  
  15.             this.data_offset = fh.ReadInt32();
  16.             this.rowcount = fh.ReadInt32();
  17.             this.columncount = fh.ReadInt32();
  18.             fh.BaseStream.Seek(data_offset, SeekOrigin.Begin);
  19.  
  20.             Int32 rowheight = fh.ReadInt32();
  21.             for (int x = 0; x <= columncount; x++)
  22.             {
  23.                 Int16 columnwidth = fh.ReadInt16();
  24.             }
  25.  
  26.             for (int x = 0; x < columncount; x++)
  27.             {
  28.                 Int16 columntitlelength = fh.ReadInt16();
  29.                 char[] columntitle = fh.ReadChars(columntitlelength);
  30.             }
  31.  
  32.             Int16 idcolumnnamelength = fh.ReadInt16();
  33.             char[] idcolumnname = fh.ReadChars(idcolumnnamelength);
  34.             for (int x = 1; x < (rowcount - 1); x++)
  35.             {
  36.                 Int16 rowdatalength = fh.ReadInt16();
  37.                 char[] rowdata = fh.ReadChars(rowdatalength);
  38.             }
  39.  
  40.             for (int x = 1; x < rowcount; x++)
  41.             {
  42.                 for (int i = 1; x < columncount; i++)
  43.                 {
  44.                     Int16 celldatalength = fh.ReadInt16();
  45.                     char[] celldata = fh.ReadChars(celldatalength);
  46.                 }
  47.             }
  48.         }


Edit: I forgot to mention that I'm using Xadet3's STB file format pseudocode.
Stark
Little soul
Little soul
 
Posts: 2
Joined: Thu Nov 22, 2012 1:51 pm

Re: STB Editor in C#

Postby PurpleYouko on Tue Nov 27, 2012 6:30 pm

looks to me like this is your problem
  1. for (int x = 1; x < rowcount; x++)
  2.             {
  3.                 for (int i = 1; x < columncount; i++)
  4.                 {
  5.                     Int16 celldatalength = fh.ReadInt16();
  6.                     char[] celldata = fh.ReadChars(celldatalength);
  7.                 }
  8.             }

That X should be an i
the way you have it now you will be stuck in that for statement until you run out of memory for your variable lol
Need to lookup information on NARose items, skills, quests?
Now featuring a newly completed skill tree for all classes
Formatting fixed for different resolutions
Image

"A Gazelle is nothing but a giraffe plotted logarithmicaly"
User avatar
PurpleYouko
Rose Guru
Rose Guru
 
Posts: 4733
Joined: Fri Aug 10, 2007 2:05 pm

Re: STB Editor in C#

Postby Circa on Tue Nov 27, 2012 7:14 pm

hahah, i hate when I do that lol. dam dem loops!
Circa
Clown
Clown
 
Posts: 404
Joined: Sun Aug 23, 2009 5:52 am
Location: CA

Re: STB Editor in C#

Postby Stark on Tue Nov 27, 2012 7:19 pm

Oh, haha, guess I missed that. But like I said, it's already going wrong after rowHeight, so that can't be the problem, right?

Thank you for the help so far though.
Stark
Little soul
Little soul
 
Posts: 2
Joined: Thu Nov 22, 2012 1:51 pm

Re: STB Editor in C#

Postby xadet3 on Fri Nov 30, 2012 4:05 pm

  1. fh.BaseStream.Seek(data_offset, SeekOrigin.Begin);

Remove this as it seeks to below the column widths, column names and row names.

  1. Int32 rowheight = fh.ReadInt32();

This needs to be reading a 16-bit integer.

  1. for (int x = 0; x <= columncount; x++)

This means you're reading the number of columns + 1, it needs to be < instead of <=.

  1. for (int x = 1; x < (rowcount - 1); x++)

Is reading 1 less row than it should be, so either change the x = 1 to x = 0, or rowcount - 1 to rowcount.

One small point to make is use koreanEncoding.GetString(fh.ReadBytes(x)) instead of ReadChars, as you are with the header.
xadet3
Pero pero
Pero pero
 
Posts: 727
Joined: Tue Jan 08, 2008 11:51 pm
Location: Norwich, England.


Return to Client Editing Question Zone

Who is online

Users browsing this forum: Majestic-12 [Bot] and 4 guests

cron