Author Topic: TNS>LUA Converter  (Read 20550 times)

0 Members and 2 Guests are viewing this topic.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
TNS>LUA Converter
« on: July 07, 2011, 10:33:46 am »
I just thought a bit about it and I'm pretty sure it is possible to convert TNS files to the original LUA code. Afterall, we have programs that do the opposite.

I gave it a try and managed to do it. However, I can't particularly claim it *always* works. I think it works if one didn't use TI's Tools to create it. If one used third-party tools then it works (or so I believe). Nevertheless, it's a pretty useful tool, coded in Python.

It basically opens a TNS file and creates a new text file with the Lua Code.

Here's how it is used:

Code: [Select]
python tns2lua.py MyFile.tns MyCode.txt

Replace MyFile.tns and MyCode.txt with the name of the TNS file you want to decode and the text file you want the code to be saved in respectively.

Attached is a ZIP Archive with a ReadMe and the program.

Offline JosJuice

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1344
  • Rating: +66/-14
    • View Profile
Re: TNS>LUA Converter
« Reply #1 on: July 07, 2011, 10:43:07 am »
Nice! I don't think can test it (as I don't have any .tns files, and I forgot to install Python on this computer), but I hope that it will be useful for others. Does this only work on 3.0.1-only files, or does it also support files that support 3.0.2?

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: TNS>LUA Converter
« Reply #2 on: July 07, 2011, 10:47:11 am »
Quote
I think it works if one didn't use TI's Tools to create it. If one used third-party tools then it works (or so I believe).
Exactly, so:
Quote
Does this only work on 3.0.1-only files, or does it also support files that support 3.0.2?
It works only on 3.0.1-only files.
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline JosJuice

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1344
  • Rating: +66/-14
    • View Profile
Re: TNS>LUA Converter
« Reply #3 on: July 07, 2011, 11:25:54 am »
Ah, okay. I guess the 0D compression/encryption is quite tricky...

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: TNS>LUA Converter
« Reply #4 on: July 07, 2011, 11:39:29 am »
The nasty bit in there is TI's proprietary and patented XML compression.

Spoiler For Spoiler:
At the end of April, I coerced Phoenix 1.7.2741 CAS into producing a file that, after some manual fiddling, can be uncompressed by a standard ZIP tool. IOW, it's not encrypted. But the content of the file is not directly usable, due to TI's proprietary XML compression.
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: TNS>LUA Converter
« Reply #5 on: July 07, 2011, 03:55:02 pm »
Yes, you're right, after further testing I noticed it can decode all TNS files made using Lua for OS 3.0.1. I also understand why (0D Compression for OS 3.0.2).

Either way, should I upload this to Omnimaga Downloads and TiCalc.org Archives?

Offline apcalc

  • The Game
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1393
  • Rating: +120/-2
  • VGhlIEdhbWUh (Base 64 :))
    • View Profile
Re: TNS>LUA Converter
« Reply #6 on: July 07, 2011, 04:14:28 pm »
This looks like it could come in handy!  Excellent work! :)


Offline Jonius7

  • python! Lua!
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1918
  • Rating: +82/-18
  • Still bringing new dimensions to the TI-nspire...
    • View Profile
    • TI Stadium
Re: TNS>LUA Converter
« Reply #7 on: February 26, 2012, 08:44:03 am »
Any updates? Necroposting.
Programmed some CASIO Basic in the past
DJ Omnimaga Music Discographist ;)
DJ Omnimaga Discography
My Own Music!
My Released Projects (Updated 2015/05/08)
TI-nspire BASIC
TI-nspire Hold 'em
Health Bar
Scissors Paper Rock
TI-nspire Lua
Numstrat
TI-nspire Hold 'em Lua
Transport Chooser
Secret Project (at v0.08.2 - 2015/05/08)
Spoiler For Extra To-Be-Sorted Clutter:

Spoiler For Relegated Projects:
TI-nspire BASIC
Battle of 16s (stalled) | sTIck RPG (stalled) | Monopoly (stalled) | Cosmic Legions (stalled)
Axe Parser
Doodle God (stalled while I go and learn some Axe)

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: TNS>LUA Converter
« Reply #8 on: February 26, 2012, 03:49:17 pm »
Sadly enough there isn't a easy way for >3.0.1 files.
What I do is run it in nspire emu, and dump the entire memory of the process using gcore (In Linux).
Weird, but ok enough for me :P

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: TNS>LUA Converter
« Reply #9 on: February 26, 2012, 03:52:46 pm »
Well, now, there are several ways to do it  :
- Using a memory dumper and extract what you want from nspire_emu
- Using any Clipboard dumper while having copied a Lua widget from within the computer software. (levak made a little software for that, on Windows)
- Using the official Lua SDK (which will be released "soon" (?) ), from which you'll be able to directly edit the lua code from within the .tns file, obviously.
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline Jonius7

  • python! Lua!
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1918
  • Rating: +82/-18
  • Still bringing new dimensions to the TI-nspire...
    • View Profile
    • TI Stadium
Re: TNS>LUA Converter
« Reply #10 on: February 26, 2012, 03:55:25 pm »
You can kinda do that with Oclua but in a roundabout fashion. Good to see.
Programmed some CASIO Basic in the past
DJ Omnimaga Music Discographist ;)
DJ Omnimaga Discography
My Own Music!
My Released Projects (Updated 2015/05/08)
TI-nspire BASIC
TI-nspire Hold 'em
Health Bar
Scissors Paper Rock
TI-nspire Lua
Numstrat
TI-nspire Hold 'em Lua
Transport Chooser
Secret Project (at v0.08.2 - 2015/05/08)
Spoiler For Extra To-Be-Sorted Clutter:

Spoiler For Relegated Projects:
TI-nspire BASIC
Battle of 16s (stalled) | sTIck RPG (stalled) | Monopoly (stalled) | Cosmic Legions (stalled)
Axe Parser
Doodle God (stalled while I go and learn some Axe)

Offline Jonius7

  • python! Lua!
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1918
  • Rating: +82/-18
  • Still bringing new dimensions to the TI-nspire...
    • View Profile
    • TI Stadium
Re: TNS>LUA Converter
« Reply #11 on: April 02, 2012, 01:49:24 am »
Oh, totally forgot to ask.
I installed python but don't quite get the instructions, this line in particular:
Code: [Select]
Also note that in order to do this you need Python 2.6 or Python 2.7 installed in your computer and they need to be in the terminal path.
I had the tns file in the same directory as the .py file, however from the instructions, it seems like I need to have the Python install files in the same directory too!
I suspected this when I saw that the command line had "python" in it
Code: [Select]
python tns2lua.py MyFile.tns MyFile.txtAny help on this?

Also I created a batch file for this for ease of use:

Code: [Select]
@echo off
set /p tnsfile= Type the tns filename (without extension):
set /p txtfile= Type the txt filename (without extension):
python tns2lua.py %tnsfile%.tns %txtfile%.txt
Though it didn't seem to work.
Help Please :D
« Last Edit: April 02, 2012, 01:50:27 am by Jonius7 »
Programmed some CASIO Basic in the past
DJ Omnimaga Music Discographist ;)
DJ Omnimaga Discography
My Own Music!
My Released Projects (Updated 2015/05/08)
TI-nspire BASIC
TI-nspire Hold 'em
Health Bar
Scissors Paper Rock
TI-nspire Lua
Numstrat
TI-nspire Hold 'em Lua
Transport Chooser
Secret Project (at v0.08.2 - 2015/05/08)
Spoiler For Extra To-Be-Sorted Clutter:

Spoiler For Relegated Projects:
TI-nspire BASIC
Battle of 16s (stalled) | sTIck RPG (stalled) | Monopoly (stalled) | Cosmic Legions (stalled)
Axe Parser
Doodle God (stalled while I go and learn some Axe)

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: TNS>LUA Converter
« Reply #12 on: April 02, 2012, 06:27:59 am »
You better use Luna to create .tns file, that any other third-party tool, since Luna is the only one generating working file for OS >= 3.0.2.

Tutorials on how to use it are everywhere, but basically :   luna.exe source.lua output.tns


EDIT : Oh wait nevermind I think I read your post wrong.....

« Last Edit: April 02, 2012, 06:31:09 am by adriweb »
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline Jonius7

  • python! Lua!
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1918
  • Rating: +82/-18
  • Still bringing new dimensions to the TI-nspire...
    • View Profile
    • TI Stadium
Re: TNS>LUA Converter
« Reply #13 on: April 04, 2012, 02:52:06 am »
You better use Luna to create .tns file, that any other third-party tool, since Luna is the only one generating working file for OS >= 3.0.2.

Tutorials on how to use it are everywhere, but basically :   luna.exe source.lua output.tns


EDIT : Oh wait nevermind I think I read your post wrong.....



No no, adriweb

On my other topic http://ourl.ca/15678/294355 I mention about Luna and stuff.

And, Luna is LUA -> TNS
But Ephan's python script is TNS -> LUA
jimbauwens did mention some ways to get the source code from the tns but I'm not sure how they work.
Also I have some suspicions that TNS>LUA Converter may not work on OS >=3.0.2 files anymore, and this was created before OS 3.0.2
Still I would like to know how to run this thing...
« Last Edit: April 04, 2012, 02:53:10 am by Jonius7 »
Programmed some CASIO Basic in the past
DJ Omnimaga Music Discographist ;)
DJ Omnimaga Discography
My Own Music!
My Released Projects (Updated 2015/05/08)
TI-nspire BASIC
TI-nspire Hold 'em
Health Bar
Scissors Paper Rock
TI-nspire Lua
Numstrat
TI-nspire Hold 'em Lua
Transport Chooser
Secret Project (at v0.08.2 - 2015/05/08)
Spoiler For Extra To-Be-Sorted Clutter:

Spoiler For Relegated Projects:
TI-nspire BASIC
Battle of 16s (stalled) | sTIck RPG (stalled) | Monopoly (stalled) | Cosmic Legions (stalled)
Axe Parser
Doodle God (stalled while I go and learn some Axe)

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: TNS>LUA Converter
« Reply #14 on: April 04, 2012, 06:21:13 pm »
If you're using Windows, add the Python install directory to your PATH environment variable. See http://docs.python.org/using/windows.html#excursus-setting-environment-variables for more information. And no, it won't work with TNS files for OS 3.0.2 and above. (By the way, BBify can also convert OS 3.0.1 TNS files to Lua source -- sorry for the thread hijack, but I thought it was relevant.)