Author Topic: VB.NET  (Read 6684 times)

LeeHiOoO

  • *
  • Posts: 128
    • View Profile
VB.NET
« on: 2009-08-14 05:25:38 »
Hey guys, I'm trying to write a program (FF related - I'm not getting into details) and I've been trying so many ways to decode FF texts to ASC. I had success in decoding FF text to ASC but I can't seem to decode ASC back to FF text. There are so many issues... I'm wondering if someone can enlighten this.
Here's basically what my code does:

This one works FF to ASC ...
Code: [Select]
'tmpbytes() as byte array that already read through the file

For i = 0 To tmpbytes.Length - 1
                sTmp &= FF2ASC(tmpbytes(i))
            Next

Private Function FF2ASC(ByVal b As Byte) As String

        Select Case Hex(b)
            Case "0"
                Return Environment.NewLine & "[END DIALOG]" & Environment.NewLine
            Case "1"
                Return Environment.NewLine & "[NEW WINDOW]" & Environment.NewLine
            Case "2"
                Return Environment.NewLine
            Case "20"
                Return " "
            Case "21"
                Return "0"
            Case "22"
                Return "1"
            Case ....

but i haven't come with a way to encode back to FF'ish' text

Tried this one recently but didn't worked:

Code: [Select]
'These tables are type string() defined at form load
        ....
        FF_table(65) = "21"
        FF_table(66) = "22"
        FF_table(67) = "23"
        FF_table(68) = "24"
        FF_table(69) = "25"
        FF_table(70) = "26"
        FF_table(71) = "27"
....
ASC_table(65) = "0"
        ASC_table(66) = "1"
        ASC_table(67) = "2"
        ASC_table(68) = "3"
        ASC_table(69) = "4"
        ASC_table(70) = "5"
        ASC_table(71) = "6"
        ....

'then it comes the function

Private Function Encoding(ByVal str As String, ByVal Method As String) As String

        Select Case Method
            Case "FF"
                For i = 0 To FF_table.Length - 1
                    str = str.Replace(ASC_table(i), FF_table(i))
                Next
                Return str
            Case "ASC"
                For i = 0 To FF_table.Length - 1
                    str = str.Replace(FF_table(i), ASC_table(i))
                Next
                Return str
        End Select

    End Function

 :-( Can someone explain the method that u guys did in ur progs?
« Last Edit: 2009-08-18 16:36:06 by LeeHiOoO »

nfitc1

  • *
  • Posts: 3011
  • I just don't know what went wrong.
    • View Profile
    • WM/PrC Blog
Re: Help Coding? VB.NET
« Reply #1 on: 2009-08-15 16:33:59 »
Your second method is likely going to backfire on you.

You're trying to pass through it as long as the replace table is, but that's bad. Consider the first run:

Whatever Asc_table(i) is, the replace will look for all instances of it and change it to whatever it is in the FF_table, right?

For the sake of argument, let's say Asc_table(0) = "0" and FF_Table(0) = "a". I know this is not the case, but let's pretend, shall we?

Now the string we're trying to convert is "0123456789". After the first pass, it will see the "0" at the beginning and it will become "a123456789".

Here's the catch, when the loop gets to the index where Asc_table(i) = "a", it will see the "a" in the "a123456789" and change that with something else, say "x".

So now, instead of the "a123456789" that we thought we were going to get, we have "x123456789".

Your error is in looping through the entire table like that and multiple characters are getting re-written multiple times. Do the loop per character in the string you're trying to translate and you'll get the results you want.

LeeHiOoO

  • *
  • Posts: 128
    • View Profile
Re: Help Coding? VB.NET
« Reply #2 on: 2009-08-15 21:04:38 »
How u did it dealing with kernel items descriptions and stuff? I don't want the code. i just want the 'logic'.

nvm managed to do it...
« Last Edit: 2009-08-16 02:32:56 by LeeHiOoO »

LeeHiOoO

  • *
  • Posts: 128
    • View Profile
Re: VB.NET
« Reply #3 on: 2009-08-18 16:39:40 »
@ Fleet Command:

LGP Update 3

Updates:

- check if ff7's datapath exists in registry for openfiledialog
- Added status bar
- Loading of TOC complete
- Opening file progress while calculates and show TOC (too slow atm)

Know issues:

- If you click anything while it's loading a file, the program stop responding, even so it's still calculating, if you wait it'll complete the task. But for user interface purposes this needs to be fixed.
- Loading file is too slow atm, ie. load battle.lgp and you'll understand what I mean.
- No close method before opens another file, exit program, etc. (to be implemented)
« Last Edit: 2009-08-19 04:11:09 by LeeHiOoO »

Fleet Command

  • *
  • Posts: 135
    • View Profile
Re: VB.NET
« Reply #4 on: 2009-08-20 08:05:03 »
Just downloaded it. I don't have my Visual Basic Express with me here but I'll be analyzing it soon.

Currently, I'm taking a not very deep look at the code. Your work is excellent, always remember that.  :-) But like any programmer (including me and Bill Gates) you work has some errors. I spotted some in the first look.

First, I told you to separate the I/O logic from User Interface but you didn't do it completely. Your User-interface code (frmMain.vb) opens registry keys and file streams. It shouldn't. You User Interface code should do none of these. It is the duty of LGP Stream class or DeLGP class. (Hey, I don't see a DeLGP class yet.) The only duty is be an interface between user and LGP Stream/DeLGP classes. Be warned: If you deviate from this rule, you'll end up being entangled with bugs that you cannot easily find its source. (Besides, you won't be able to easily extend your program to support drag-and-drop, command-line parameters and shortcuts. But this not as important as strange bugs.)

Second, you must not use any form of Unicode in your file I/O, not even UTF-7 and UTF-8. The reason is: a single Unicode character can occupy more than one byte. You are developing a software for a game that is created in 1995-1998, so you should only use ASCII encoding in file I/O. Windows 1252 can also be a temporary encoding solution. Meanwhile, your user interface must use Unicode format to work well on all computers will all languages all over the world. You need to constantly convert between ASCII and UFT-8 but that's easy and convenient.

Third, do not cause unnecessary inconvenience for your users. For example, your Open dialog box should always remember that last folder. Try opening mulltiple LGP files outside Final Fantasy VII folder in a row and you'll know what I mean. If you wish, you can add a shortcut to Final Fantasy VII folder in the Open dialog box (in its shortcut bar) but always remember the last folder that is opened.

I'll start analyzing the code soon. I'll test your code with all the LGP files in FF7 and then I'll report in.

EDIT: In the mean time, you'd better take a look at this:
http://www.joelonsoftware.com/articles/Unicode.html

Fleet Command

  • *
  • Posts: 135
    • View Profile
Re: VB.NET
« Reply #5 on: 2009-08-24 07:25:01 »
Sorry for the delay, but my tests aren't finished yet. Some of your offsets are wrong and I'm looking for the reason.

LeeHiOoO

  • *
  • Posts: 128
    • View Profile
Re: VB.NET
« Reply #6 on: 2009-08-25 00:07:34 »
No problem, I've been busy with some other things too.
Next week I'm going into surgery for my gallbladder, so I'm into a battery of pre-surgery exams.
As I'll be away from my work during recovery time, I may focus on that code, if I'll be able to.

Fleet Command

  • *
  • Posts: 135
    • View Profile
Re: VB.NET
« Reply #7 on: 2009-08-28 21:29:06 »
FINALLY! I'm free! :-D I broke free from the tangle of the code, LeeHiOoO. I feel I'm out of jail! (Although I don't know how it feels being in a jail. Anyway...) :lol:

Now, I know what is wrong with the code and why offsets are wrong. But no time for the lecture now. I have to go. I'll upload the new code after 24 hours (or so I hope) along with two pages of notes. You should have no problem running it.