ZSNES .cht files

General area for talk about ZSNES. The best place to ask for related questions as well as troubleshooting.

Moderator: ZSNES Mods

cracker
New Member
Posts: 3
Joined: Mon Sep 06, 2004 7:20 pm

ZSNES .cht files

Post by cracker »

Is there a program to convert cht files to the originating Pro Action Replay code (raw hex code)? I found a program that claims to do this, but it only displays four digits of hex, whereas PAR codes are eight digits. I have several large cht files that I need to get PAR codes out of, and manually writing them down would take hours.
illegal eagle
Savestate Pimp
Posts: 129
Joined: Thu Jul 29, 2004 2:15 pm
Contact:

Post by illegal eagle »

Do you mean the tool on this page?

Anyway, a cracker should be able to find the values per hex editor and write a tool for converting.
"Other people can give you more suggestions as I just lost all my motivation to respond further to this post."
[i] - Nightcrawler[/i]

[url=http://www.geocities.com/illegal_eagle_2003/]vSNES v2.00[/url]: My SNES savestate viewer.
Noxious Ninja
Dark Wind
Posts: 1271
Joined: Thu Jul 29, 2004 8:58 pm
Location: Texas
Contact:

Post by Noxious Ninja »

I took a quick look at a CHT file, but I don't quite understand it. Have to do some more playing around.
[u][url=http://bash.org/?577451]#577451[/url][/u]
cracker
New Member
Posts: 3
Joined: Mon Sep 06, 2004 7:20 pm

Post by cracker »

That is the tool I have. It only returns a four-digit hex value, not the eight-digit PAR code, or even a six-digit type raw code. If someone can explain what relation the four-digit hex value has to the code, I could convert it to PAR.

And on the second note, I do a lot of N64 code-searching and ROM-hacking, but the .cht files are new to me, and the hex values seem to have no realtion to the entered codes.
jdratlif
Regular
Posts: 317
Joined: Tue Sep 14, 2004 12:48 am
Location: In a small padded white room
Contact:

Re: ZSNES .cht files

Post by jdratlif »

cracker wrote:Is there a program to convert cht files to the originating Pro Action Replay code (raw hex code)? I found a program that claims to do this, but it only displays four digits of hex, whereas PAR codes are eight digits. I have several large cht files that I need to get PAR codes out of, and manually writing them down would take hours.
I tried this program and it didn't work for me either. I don't know why it would only be 4 digits, when it clearly should be 8.

So I decided to do what I always do when faced with a problem. Start coding! I made a Java program which "should" decode the .CHT files. I don't have any, so I had to make some to try it. It worked, but as I said, only on the test file I made for this program.

Maybe an older ZSNES used a different .CHT format, but I don't think so.

You can beta test my program if you like. http://games.technoplaza.net/CHTDecoder/

There is no GUI right now, but it should work in Java 1.1, which means any OS.

I am working on the GUI, but that will take longer than the 25 minutes it took to figure out the .CHT file and code the beta. I would like to know if it works for your codes so I can know if I've decoded it properly.

I'll try and turn it into an application, then an applet so you can use it online also.[/url]
jdratlif
Regular
Posts: 317
Joined: Tue Sep 14, 2004 12:48 am
Location: In a small padded white room
Contact:

CHTDecoder 1.0 finished...

Post by jdratlif »

I have created the GUI part of the program. It also works as an applet, so you can use it from a web browser.

I have only tested it under Windows with AvantBrowser (which is basically a nicer frontend for internet explorer). I will test it later with Linux, Mac OS-X, and Solaris to see how it works on different platforms and browsers, but I have to wait till I can go back to campus for that.
(edit: it works fine on any platform that has a Sun Java Plug-In, but it didn't seem to work on the Netscape 4.7 JVM on Solaris. I think it had something to do with the signing, so you may need Java 1.2 with the Java Plug-In to run it as an applet).

The text mode is still there, and the code has been cleaned up significantly from the hacked together garbage I posted yesterday, but it's basically the same.

Let me know if it doesn't work right, or you want something changed.

You can also download the program and run it from your computer in GUI mode. It just wraps the applet in a frame.

Also, the applet has to access files on your computer. To do this, it uses an applet signed by me. You have to say YES for it to work. But if you worry about trusting me, you can download it and compile the source yourself. GNU GPL.

It should work under any Java. I compiled the jar with Java 1.1.8 and there were no warnings or deprecation problems. But for some reason, my Solaris box didn't have keysigner working. This may mean problems for actual 1.1.8 JVMs, I'm not sure yet. I won't know till I test it on a platform that isn't using Java 1.4

http://games.technoplaza.net

Ciao.
Last edited by jdratlif on Fri Sep 17, 2004 2:43 pm, edited 1 time in total.
http://jdrrant.blogspot.com/ - CODEpendent Blog
http://games.technoplaza.net/ - Emulation Goodies
illegal eagle
Savestate Pimp
Posts: 129
Joined: Thu Jul 29, 2004 2:15 pm
Contact:

Post by illegal eagle »

Hey, nice site jdratlif! :o
cracker wrote:... and the hex values seem to have no realtion to the entered codes.
Mmh, strange. :?
"Other people can give you more suggestions as I just lost all my motivation to respond further to this post."
[i] - Nightcrawler[/i]

[url=http://www.geocities.com/illegal_eagle_2003/]vSNES v2.00[/url]: My SNES savestate viewer.
Aerdan
Winter Knight
Posts: 467
Joined: Mon Aug 16, 2004 10:16 pm
Contact:

Post by Aerdan »

Mmmm...If you don't mind, I'm going to try converting it to Perl for those who *really* hate Java. [Like myself. The language ain't bad, but the implementation soured it.]
jdratlif
Regular
Posts: 317
Joined: Tue Sep 14, 2004 12:48 am
Location: In a small padded white room
Contact:

Post by jdratlif »

Vareni Stargazer wrote:Mmmm...If you don't mind, I'm going to try converting it to Perl for those who *really* hate Java. [Like myself. The language ain't bad, but the implementation soured it.]
It's GPLed, so that is fine with me. I would like to post your version on the site when you finish it if that's cool with you.

I used to hate Java, too. Too slow. But now I love it, thanks to a brillant professor of design, Gregory Rawlins at my university. Unless you need speed (and there are tricks to improve speed if you sacrifice platform independence), I think it's the best language.

Can you create GUIs in perl, or are you just doing text-mode? I don't use perl much anymore since I switched my site to php and learned bourne scripting.

I suppose if you wrote it in perl, you could use HTML forms on a website as a GUI. I hadn't thought about that until now...
http://jdrrant.blogspot.com/ - CODEpendent Blog
http://games.technoplaza.net/ - Emulation Goodies
Noxious Ninja
Dark Wind
Posts: 1271
Joined: Thu Jul 29, 2004 8:58 pm
Location: Texas
Contact:

Post by Noxious Ninja »

jdratlif wrote:I suppose if you wrote it in perl, you could use HTML forms on a website as a GUI. I hadn't thought about that until now...
Hmm... I think I'll try a PHP version, if I have some time.
[u][url=http://bash.org/?577451]#577451[/url][/u]
Aerdan
Winter Knight
Posts: 467
Joined: Mon Aug 16, 2004 10:16 pm
Contact:

Post by Aerdan »

Couple points.
  • PHP is evil.
    PHP is Perl Lite.
Having said that, yes you can create GUIs in Perl. You can use wxPerl, GTK2's Perl interface, GTK1's Perl interface, and *maybe* the Qt interface. It'll be text-mode, though, because I normally don't write GUI'd programs.

As for websites, see PLP. It's embedded Perl, and it's 2-5 times faster than PHP, and it puts a Perl interpreter 'in' Apache, unlike mod_perl and CGI. It only works with Apache1/mod_perl, however; the author's tried interfacing it with mod_perl2, but gave up. Feel free to offer him a patch that lets it work with mod_perl2, though.

EDIT: Perl program completed, but untested. At this point, the text mode only takes one .cht, but it outputs to a plaintext file bearing the same name [with .txt replacing .cht], rather than printing to screen. I felt it more efficient. I decided to release it under three out of fourth Creative Commons licenses [edit it in your favourite editor to see what I mean] rather than the GPL, since the CC licenses are more easily understood by laypeople than the GPL is. It'll be put somewhere viewable shortly.
Kagerato
Lurker
Posts: 153
Joined: Mon Aug 09, 2004 1:40 am
Contact:

Post by Kagerato »

PHP is evil, he says...on a message board written in php.

Well done. Your opinion has conquered the universe. *bows*
Aerdan
Winter Knight
Posts: 467
Joined: Mon Aug 16, 2004 10:16 pm
Contact:

Post by Aerdan »

It's not like there are any alternatives written in PLP, my friend. Having said that, however, I refuse to take the comment back.

Here's the code for the Perl version. As I said, it's in plaintext, so don't expect anything fancy. I may or may not write up a wxPerl frontend, but that depends on whether it'll work with cygwin or not; if it does, I'll try it under the perl I compiled under VC++.

Code: Select all

#!/usr/bin/perl
#
# CHT to TXT
# Copyright (C) 2004, Kiyoshi Aman
#
# This program has been released under some Creative Commons licenses.
#
# Attribution: In order to copy, distribute, display, perform, or produce
# derivative works of this program, you must give credit.
#
# Noncommercial: In order to copy, distribute, display, perform, or produce
# derivative works of this program, you must not use it to gain profit.
#
# Share Alike: In order to produce derivative works of this program, you
# must use these same licenses.

use strict;

sub chtparse {
    my $active,$address,$value,$name;
    my @foo = split //,$cht[$_];

    if ($blah[0] == 0) { # 0 is on, 4 is off.
       $active = "true";
    }

    # The address is backwards on little-endian x86 machines,
    # so this would be a bug on big-endian system.
    for (my $foob = 4; $foob > 1; $foob--) {
        $address <<= 8;
        $address |= (int($foo[$foob]) & 0xFF);
    }
    $value = int $foo[1] & 0xFF;

    for (my $foob = 8; $foob < 26; $foob++) {
        last if ($foob == 0);
        $name .= chr($foo[$foob]);
    }
    return ($active,$address,$value,$name);
}

open CHT, "$_" or die "Cannot open $_: $!";
my @cht = <CHT>;
close CHT;

print "$_ opened.\n";
for (my $i = 0; $i < @cht; $i++) {
    my ($cheat{active},$cheat{address},$cheat{value},$cheat{name}) = chtparse($$

    push @out, %cheat;
}

$_ =~ s/.cht/.txt/;
open FILE, "$_";
for (my $i = 0; $i < @out; $i++) {
    print FILE "Active: $out[$i]{active} Address: $out[$i]{address} Value: $out$
}
close FILE;

print "Codes saved. Please read $_.\n";
jdratlif
Regular
Posts: 317
Joined: Tue Sep 14, 2004 12:48 am
Location: In a small padded white room
Contact:

php or perl...who cares...

Post by jdratlif »

I like both. Although I did recently switch all my websites from perl to PHP, that should not be construed as evidence that I prefer PHP. On the contrary, I simply think it's easier to learn a new language if you do a real project in it.

Though I do prefer the static scoping of PHP, and the fact that you can embed HTML in it. I think that makes it nicer for web pages. But I happily used perl for 5 years on my website and had no problems (at least none caused by perl).

Oops, this wasn't meant as a PHP vs. Perl comment. I meant to say you program doesn't seem to work. I've tried it on Linux with Perl 5.6something and on Windows with ActivePerl 5.8something.

Errors:

perl cht2txt.pl lufia.cht

Global symbol "$address" requires explicit package name at cht2txt.pl line 20.
Global symbol "$value" requires explicit package name at cht2txt.pl line 20.
Global symbol "$name" requires explicit package name at cht2txt.pl line 20.
Global symbol "@cht" requires explicit package name at cht2txt.pl line 21.
Global symbol "@blah" requires explicit package name at cht2txt.pl line 23.
Global symbol "$address" requires explicit package name at cht2txt.pl line 30.
Global symbol "$address" requires explicit package name at cht2txt.pl line 31.
Global symbol "$value" requires explicit package name at cht2txt.pl line 33.
Global symbol "$name" requires explicit package name at cht2txt.pl line 37.
Global symbol "$address" requires explicit package name at cht2txt.pl line 39.
Global symbol "$value" requires explicit package name at cht2txt.pl line 39.
Global symbol "$name" requires explicit package name at cht2txt.pl line 39.
syntax error at cht2txt.pl line 50, near "$$

push"
cht2txt.pl has too many errors.
http://jdrrant.blogspot.com/ - CODEpendent Blog
http://games.technoplaza.net/ - Emulation Goodies
jdratlif
Regular
Posts: 317
Joined: Tue Sep 14, 2004 12:48 am
Location: In a small padded white room
Contact:

version 1.1

Post by jdratlif »

If anyone is interested, I made an update to the CHTDecoder program that pads zeros on the front. (I know, big news, eh?)

So it won't show things like B1F52:B anymore, when it should have displayed 0B1F52:0B.

http://games.technoplaza.net/CHTDecoder/
http://jdrrant.blogspot.com/ - CODEpendent Blog
http://games.technoplaza.net/ - Emulation Goodies
Aerdan
Winter Knight
Posts: 467
Joined: Mon Aug 16, 2004 10:16 pm
Contact:

Post by Aerdan »

5.6.x is old. It's recommended that you update to 5.8.5, the latest stable release. Anyhow, this should fix that issue.

CHT to Text v0.2

[EDIT: Also, PLP is Perl embedded in a similar fashion to PHP, except it doesn't have a memory leak function in the production releases.]
jdratlif
Regular
Posts: 317
Joined: Tue Sep 14, 2004 12:48 am
Location: In a small padded white room
Contact:

Post by jdratlif »

Vareni Stargazer wrote:5.6.x is old. It's recommended that you update to 5.8.5, the latest stable release. Anyhow, this should fix that issue.

CHT to Text v0.2

[EDIT: Also, PLP is Perl embedded in a similar fashion to PHP, except it doesn't have a memory leak function in the production releases.]
The system I ran 5.6 on isn't mine, so I can't update their perl.

Also, this 0.2 version doesn't fix the problem. I tried it on my Windows ActivePerl and the Linux Perl 5.8.4.

>perl chttotext.pl lufia.cht
Bareword found where operator expected at chttotext.pl line 50, near "$%cheat"
(Missing operator before cheat?)
Operator or semicolon missing before %cheat at chttotext.pl line 50.
Ambiguous use of % resolved as operator % at chttotext.pl line 50.
Global symbol "@cht" requires explicit package name at chttotext.pl line 21.
Global symbol "@blah" requires explicit package name at chttotext.pl line 23.
Global symbol "@out" requires explicit package name at chttotext.pl line 50.
syntax error at chttotext.pl line 50, near "$%cheat"
Global symbol "@out" requires explicit package name at chttotext.pl line 55.
Global symbol "@out" requires explicit package name at chttotext.pl line 56.
Global symbol "@out" requires explicit package name at chttotext.pl line 56.
Global symbol "@out" requires explicit package name at chttotext.pl line 56.
Global symbol "@out" requires explicit package name at chttotext.pl line 56.
Execution of chttotext.pl aborted due to compilation errors.

Java's looking pretty good right about now, eh? :-)
http://jdrrant.blogspot.com/ - CODEpendent Blog
http://games.technoplaza.net/ - Emulation Goodies
jdratlif
Regular
Posts: 317
Joined: Tue Sep 14, 2004 12:48 am
Location: In a small padded white room
Contact:

Post by jdratlif »

Noxious Ninja wrote:
jdratlif wrote:I suppose if you wrote it in perl, you could use HTML forms on a website as a GUI. I hadn't thought about that until now...
Hmm... I think I'll try a PHP version, if I have some time.
Have you attempted this?

After lots of googling, I've found that my applet won't run without the Sun Plug-In. Netscape/IE built-in JVM's just don't like the signing method sun chose. This means not everyone can run the applet without installing something special, which is something I'd like to avoid.

If you have done this, I'd like to post it. If not, I think I'll do it myself.

Unrelated to this, but I made a small bug fix. If you hit the cancel button on the file dialogs, it complains about not being able to open the "null" file. This is fixed in version 1.2. I put up a diff along with the full release for those who want to compile it themselves. And of course, the new applet is running.

http://games.technoplaza.net/CHTDecoder/
http://jdrrant.blogspot.com/ - CODEpendent Blog
http://games.technoplaza.net/ - Emulation Goodies
Noxious Ninja
Dark Wind
Posts: 1271
Joined: Thu Jul 29, 2004 8:58 pm
Location: Texas
Contact:

Post by Noxious Ninja »

Bah. I've always messed with text files in PHP, never something where I need raw byte values. I'm having some problems. I'm trying to use the substr function to break the file into 28-byte blocks, but it apparantly screws up some values.

I wish I knew more Python.

EDIT: I was wrong. Casting a character to int doesn't give the byte value, it attempts to covert a string of numbers into a number. ord() gives the byte value of a character.

FINALLY I am getting somewhere. The rest should be easy, I just don't have time to finish it tonight.
[u][url=http://bash.org/?577451]#577451[/url][/u]
jdratlif
Regular
Posts: 317
Joined: Tue Sep 14, 2004 12:48 am
Location: In a small padded white room
Contact:

Post by jdratlif »

I was too impatient to wait for your version, so I wrote my own in PHP.

http://games.technoplaza.net/CHTDecoder/php/

It won't save to a text file, but my main motivation was for people who don't have a Sun Java Plug-In to be able to run it online. This will accomplish that. I might update it for a TXT version later, but I don't feel like it right now.

The source is there also, GPLed of course.
http://jdrrant.blogspot.com/ - CODEpendent Blog
http://games.technoplaza.net/ - Emulation Goodies
Noxious Ninja
Dark Wind
Posts: 1271
Joined: Thu Jul 29, 2004 8:58 pm
Location: Texas
Contact:

Post by Noxious Ninja »

Heh, I just finished mine when I read your post. :D My mom sprained her ankle and I didn't get to work on it earlier. :(

I included HTML, text, and CSV as output options. I spent next to no time on the interface, sorry for the spartan look. It does the job and not much else.

http://thecarpentersshop.com/ninja/chtconvert.php

Source (GPL)

I'm sure there are a few inconsistancies/ineffeciancies in the coding style, since I rearranged several things right before I posted it, and didn't spend much time polishing it up.
[u][url=http://bash.org/?577451]#577451[/url][/u]
Aerdan
Winter Knight
Posts: 467
Joined: Mon Aug 16, 2004 10:16 pm
Contact:

Post by Aerdan »

The one thing I can't do as of yet where chttotext.pl is concerned is output the address and value in hex [but I'm working on that]. Meanwhile, it actually *works* now...that, and the current method makes it easy to do multiple files [just add a do...while loop around the whole code.]

Code: Select all

#!/usr/bin/perl
#
# CHT to TXT
# Copyright (C) 2004, Kiyoshi Aman
#
# This program has been released under some Creative Commons licenses.
#
# Attribution: In order to copy, distribute, display, perform, or produce
# derivative works of this program, you must give credit.
#
# Noncommercial: In order to copy, distribute, display, perform, or produce
# derivative works of this program, you must not use it to gain profit.
#
# Share Alike: In order to produce derivative works of this program, you
# must use these same licenses.

use strict;

my @out;

print "Please enter a filename.\n";
my $in = <STDIN>; chomp $in;

open CHT, "$in" or die "Cannot open $in: $!";
my @cht = <CHT>;
close CHT;

print "$in opened.\n";

$in =~ s/.cht/.txt/;
open FILE, ">$in" or die "Cannot open $in: $!";
for (my $i = 0; $i < @cht; $i++) {
    my %cheat;
    ($cheat{active},$cheat{address},$cheat{val},$cheat{desc}) = chtparse($i);

    print FILE "Active: $cheat{active}\tAddress: $cheat{address}\tValue:$cheat{v
alue}\tName: $cheat{desc}\n";
}
close FILE;

print "Codes saved. Please read $in.\n";

sub chtparse {
    my ($active,$address,$value,$name);
    my @foo = split //,$cht[$_];

    if ($foo[0] == 0) { # 0 is on, 4 is off.
       $active = "on";
    }

    # The address is backwards on little-endian x86 machines,
    # so this would be a bug on big-endian systems.
    for (my $foob = 4; $foob > 1; $foob--) {
        $address <<= 8;
        $address |= (ord($foo[$foob]) & 0xFF);
    }
    $address = $address
    $address = "0".$address if (length($address) < 6);

    $value = ord($foo[1]) & 0xFF;
    $value = "00" if $value == undef;

    for (my $foob = 8; $foob < 26; $foob++) {
        last if ($foob == 0);
        $name .= chr ord($foo[$foob]);
    }
    return ($active,$address,$value,$name);
}
jdratlif
Regular
Posts: 317
Joined: Tue Sep 14, 2004 12:48 am
Location: In a small padded white room
Contact:

Post by jdratlif »

Vareni Stargazer wrote:The one thing I can't do as of yet where chttotext.pl is concerned is output the address and value in hex [but I'm working on that]. Meanwhile, it actually *works* now...that, and the current method makes it easy to do multiple files [just add a do...while loop around the whole code.]
Um, no offense, but do you bother testing before you post stuff?

There are two minor syntax errors in the code you posted which prevent it from running. I fixed those, but that's not what I'm most concerned about. The bigger problem is that it only gives the first code in the cht file I tested. There are supposed to be 4.
http://jdrrant.blogspot.com/ - CODEpendent Blog
http://games.technoplaza.net/ - Emulation Goodies
Aerdan
Winter Knight
Posts: 467
Joined: Mon Aug 16, 2004 10:16 pm
Contact:

Post by Aerdan »

I do test my code.

...I just need to find a .cht with more than one code in it, then.

As for syntax errors, I didn't *see* any, but that doesn't mean there *aren't* any. [And perl didn't think there were any, either, so...]
jdratlif
Regular
Posts: 317
Joined: Tue Sep 14, 2004 12:48 am
Location: In a small padded white room
Contact:

Post by jdratlif »

Noxious Ninja wrote:Heh, I just finished mine when I read your post. :D My mom sprained her ankle and I didn't get to work on it earlier. :(

I included HTML, text, and CSV as output options. I spent next to no time on the interface, sorry for the spartan look. It does the job and not much else.

http://thecarpentersshop.com/ninja/chtconvert.php

Source (GPL)

I'm sure there are a few inconsistancies/ineffeciancies in the coding style, since I rearranged several things right before I posted it, and didn't spend much time polishing it up.
That motivated me to add text mode output, though I don't think I'll be adding CSV. I updated my interface slightly. I think it looks nicer now, too.

http://games.technoplaza.net/CHTDecoder/php/
http://jdrrant.blogspot.com/ - CODEpendent Blog
http://games.technoplaza.net/ - Emulation Goodies
Post Reply