Codes
WiiRd forum
March 29, 2024, 12:31:23 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Welcome on the new server

Update 4.3 - do NOT update!
Gecko 1.9.3.1
Should I get a USB Gecko, I wanna hack?
How do I use my USB Gecko
Where can I get WiiRd?
 
   Home   CODE DATABASE GAMEHACKING Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Cross-platform GCT Creator  (Read 6218 times)
sli
Newbie
*

Karma: 0
Posts: 5

signedlongint
« on: October 28, 2008, 02:44:57 AM »

UPDATE #2: Whoops, messed up a list access, and was unhexlifying the codes twice when using cli mode. Fixed that.

UPDATE: Removed a couple limitations. The script will now detect non-hex digits and report the problem line when used in file mode (cli mode will just report an error). Any line without 16 total characters excluding the space will be treated as a comment.

I guess this would be the correct section... Anyway, I whipped up a little Python script to create GCT files from a couple sources. I was tired of using CodeMgr in Wine. Tongue It should run on any computer with Python installed, both Linux and OS X (usually) come with Python installed. It will ignore any line that is not pure hex and 16 characters long, so commenting on codes lists is possible by just putting them on their own lines.

Here's the usage text. As you can see it works kind of like an archiver.
Code:
Usage: python gct.py <command> <data>
Commands:
f Read codes from a file.
c Read codes from command line.
Example: python gct.py c 04337f18 05f5e0ff

And here's the source:
Code:
import sys, binascii

if len(sys.argv) < 3 or sys.argv[1] not in ['f','c']:
    print 'Usage: python gct.py <command> <data>'
    print 'Commands:'
    print '\tf\tRead codes from a file.'
    print '\tc\tRead codes from command line.'
    print '\t\tExample: python gct.py c 04337f18 05f5e0ff'
    sys.exit(1)

if sys.argv[1] == 'f':
    raw = open(sys.argv[2]).read().split('\n')
    codes = ''
    for c in raw:
        c = c.replace(' ','')
        if len(c) == 16:
            try:
                binascii.unhexlify(c)
                codes += c
            except:
                print 'Error: Non-hex digit found in "%s %s"' % (c[:8], c[8:])
                sys.exit(1)
elif sys.argv[1] == 'c':
    try: codes = ''.join(sys.argv[2:])
    except:
        print 'Error: Non-hex digit found.'
        sys.exit(1)
else:
    print 'How did you get this far?'
    sys.exit(1)

data = '\x00\xd0\xc0\xde\x00\xd0\xc0\xde'
data += binascii.unhexlify(codes)
data += '\xf0\x00\x00\x00\x00\x00\x00\x00'

while 1:
    title = raw_input('Enter game ID: ')
    if len(title) < 6: print 'Game ID too short!'
    else: break

open('%s.gct' % title,'w').write(data)

print '%s.gct created.' % title
« Last Edit: November 02, 2008, 06:27:34 AM by sli » Logged
christian.remboldt
Newbie
*

Karma: 0
Posts: 12


« Reply #1 on: November 01, 2008, 02:36:04 AM »

This is awesome. Have you tried wiipy? It is a port of python to the wii. This is a link to the wiibrew page.

http://wiibrew.org/wiki/WiiPy

The download from here is version 2alpha this is pretty much useless but the page gives some good info about the program.

Version 3alpha can be downloaded from the google codes page.

http://code.google.com/p/wiipy/

This version allows a script to be run named run.py from a folder named wiipy on the root of the SD card. I tried starting your script with this version but it gives a code dump. If you want I can post the dump. This seem like the best version the sample run.py script has wiimote support.

Finally this is the link to version 4

http://www.cs.utexas.edu/~tehpola/PyOGC.cgi

This version comes with a script named demo.pyx complied into the boot.elf. This is the newest version so it seem to be the most full featured. The demo has sound playback but only uses the GC controller.

It would be cool if you could configure your script to run on the wii so If a user had a txt file with all the codes saved to the sd card they could select the codes to run. This would mean either figureing a way to get it to run on version3 with out the code dump or compling a revision of version4. The version 4 download comes with source and can be easily complied with devkitpro.

The major additions that would need to be made to the script are a way to select which txt file is to be used and which codes are to be implimented. I have no ideas about the first part of this but for the second the code selection my idea is this. Use the run.py script from version3 it has button support for both the A and B wiimote buttons. If your script looked for a blank line then printed the next line that would be the code name. Then the user could press A to initalize or B to skip. If A was pressed the code could be converted if not just skip to the next blank line and repeat until EOF.

**** a side note if you want to use any of these apps with HBC9 you need to convert them to supported dols. I used powerpc-gekko-objcopy -O binary boot.elf boot.dol ****

http://wiibrew.org/wiki/ELF_to_DOL_Converter

Logged
sli
Newbie
*

Karma: 0
Posts: 5

signedlongint
« Reply #2 on: November 02, 2008, 06:21:24 AM »

Yes, I know all about Wiipy. The way my script's written, it becomes less convenient to run on the Wii (especially without a text editor). As for selecting the file to use, you simply use the f command, added so people can copy and paste large codes, or even an entire forum post as the script ignores lines that aren't codes, and convert them quickly:
Code:
python gct.py f filewithcodes.txt
It's somewhat beyond the scope of this simple script to create a full on GCT manager, but I have considered rewriting CodeMgr using Python and Tkinter to essentially create a cross-platform version of CodeMgr, as Tkinter comes with Python. But Tk has plenty of limitations and isn't my GUI toolkit of choice, I prefer wxPython. The problem with that is it would require the user to install something else and that lowers simplicity.

My options become limited to simply parsing code files differently and creating a little text-based menu, which wouldn't be hard, I just haven't gotten around to it. At the moment, my tool is written to be simple and quick, especially for people like me who usually just want one or two codes (usually inf. life and inf. money Tongue), like the infinite life code for Mario Galaxy:
Code:
python gct.py c 042B1C30 60000000

This source is essentially public domain, so I invite anyone to build upon it to create something more akin to CodeMgr if they like. But since the scope of this tool is to be simple and fast, I'm probably not going to do it myself.

Another note is that you don't have to convert the ELF to a DOL to run it from the HBC. The Wii's executable format is ELF, but also supports DOL -- the Gamecube executable format -- because of its backwards compatibility. I'm sure it's more complicated than that, but that's the simple version.

I do appreciate the feedback, though! I like being able to discuss my work, it helps to show I'm not a random noob posting random source code. Cheesy
Logged
christian.remboldt
Newbie
*

Karma: 0
Posts: 12


« Reply #3 on: November 05, 2008, 05:59:20 PM »

Ive been working on a native wii port of this script using DevkitPRO. Ive created a file selection tool and a can scan the txt files looking for blank lines. Once a blank line is found the next line is printed to the screen as the title. This leaves only the encoding and writing of the data to the already open gct file. My question is does anyone know how I might write these three line in c?

data = '\x00\xd0\xc0\xde\x00\xd0\xc0\xde'
data += binascii.unhexlify(codes)
data += '\xf0\x00\x00\x00\x00\x00\x00\x00'
Logged
sli
Newbie
*

Karma: 0
Posts: 5

signedlongint
« Reply #4 on: November 07, 2008, 01:54:49 AM »

It's being a pain (doesn't compile correctly) because I'm not big on C, but here's something you can reference:
Code:
#include <stdio.h>
#include <string.h>

const char GCT_HEADER[8] = { 0x00, 0xd0, 0xc0, 0xde, 0x00, 0xd0, 0xc0, 0xde };
const char GCT_FOOTER[8] = { 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

int main()
{
char val[8] = "57696921"; /* "Wii!" in hex */
char ret[4], cur[2];
unsigned char c;
int i;

        for (i=0;i<sizeof(val);i++) {
/* Skip every other character */
if (i > 0 && i % 2 != 0) continue;

/* Grab next two bytes */
strncpy(cur, &val[i], 2);

/* Convert from hex to ascii */
sscanf(cur, "%hhx", &c);

/* Stick it in "ret" - this is the broken part */
strcat(ret, (char)c);
}

printf("ret: %s\n", ret);
return 0;
}

Why is there such an interest in porting my program to the Wii? If you want to add codes, you have to either startup ftpii and go to your computer to edit the file, or take your SD card to your computer to edit the file. Either way, porting it to the Wii will simply make it inconvenient. As it is, all you have to do is enter your codes, run, and copy (or send via ftpii), then just keep your code lists on your computer for later access.
« Last Edit: November 07, 2008, 03:52:54 AM by sli » Logged
brkirch
Hacker
Sr. Member
*****

Karma: 53
Posts: 395


« Reply #5 on: November 08, 2008, 12:24:42 AM »

I've attached to this post the source code for a C program I wrote that creates gct files.  It should compile with just about any C compiler.
Logged

christian.remboldt
Newbie
*

Karma: 0
Posts: 12


« Reply #6 on: November 08, 2008, 12:54:24 AM »

@brkirch thanks for your code. Im going to look at it now. If use it I'll give you credit, but im not much of a coder.

@sli my thought is if you save the txt cheat files to the wii, then you can use a program to create a new gct file to turn codes on and off. This way when I take my wii to a friends house I could change which codes are implemented without a computer.
Logged
christian.remboldt
Newbie
*

Karma: 0
Posts: 12


« Reply #7 on: November 09, 2008, 06:30:15 PM »

Here is the link to my completed code manager. If anyone wants it and isnt a user at tehskeen I can post it here.

http://www.tehskeen.com/forums/showthread.php?t=9498

@brkirch thanks again.



Logged
sli
Newbie
*

Karma: 0
Posts: 5

signedlongint
« Reply #8 on: November 12, 2008, 07:59:20 PM »

Working on a little something. Let me know what you guys think so far.
Logged
ratm-arm
Custom Title
Newbie
*

Karma: 10
Posts: 10


« Reply #9 on: November 16, 2008, 07:59:21 PM »

Ooh. I like yours. And since I see the XFCE environment, I'm going to guess it's for Linux? Yay!
Logged

If you don't agree with me then you are both ugly and stupid.
        ~ Linus Torvalds
sli
Newbie
*

Karma: 0
Posts: 5

signedlongint
« Reply #10 on: November 19, 2008, 01:25:39 AM »

Any platform that supports Python (the usuals plus a ton more) and PyQt (substantially fewer), actually. The only problem is that pyuic doesn't like the latest Qt Designer (ugh) so I might have to use wxPython instead. Of course it'll still be cross-platform.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!