d2txt.py: Edit TXT files in Python, convert to INI files

This would be the forum for questions about how to work with mod making tools which can be a problem of its own.

Moderator: Paul Siramy

Post Reply
User avatar
mmpx222
Junior Member
Paladin
Posts: 154
Joined: Sat Apr 26, 2014 9:19 am
Korea South

d2txt.py: Edit TXT files in Python, convert to INI files

Post by mmpx222 » Mon Jan 14, 2019 10:08 am

Project link: https://github.com/pastelmind/d2txt

What is this?

d2txt.py is a Python 3 module for editing Diablo 2 *.TXT files. It provides the D2TXT class, which can be used to read, modify, and save a TXT file. If you're into systematically balancing your mod, or want to write your own mod-making script, check it out!

I wrote several sample scripts for my own use, but they may be useful for other modders. Check them out to see how D2TXT can be used.

d2ini.py is a command-line Python script that "decompiles" a TXT file to an INI file, or "compiles" an INI file to a TXT file. INI files have several advantages over TXT files:
  • Easy to read in code editors
  • Easy to post on the forums
  • Play nice with version control (Git, Subversion, etc.)
  • Provide pretty diff logs
Compare this line copy-pasted from Missiles.txt:

Code: Select all

firewallmaker	68	6		6																	4	no light freq																															12	12			7	2	8		255	178	64	0	0	1	groundFireBig	1024	2	16		1	1	2	8			1		1	1						1																1								8																																				32	1								firewall							firewall	firesmall	firemedium					0
At a glance, you have no idea what each number does. Compare this section from the decompiled Missiles.ini:

Code: Select all


[69]
Missile=firewallmaker
Id=68
pCltDoFunc=6
pSrvDoFunc=6
CltParam1=4
*client param1 desc=no light freq
Vel=12
MaxVel=12
Range=7
LevRange=2
Light=8
Red=255
Green=178
Blue=64
InitSteps=0
Activate=0
LoopAnim=1
CelFile=groundFireBig
animrate=1024
AnimLen=2
AnimSpeed=16
SubLoop=1
SubStart=1
SubStop=2
CollideType=8
LastCollide=1
ClientCol=1
ClientSend=1
Size=1
Trans=1
HitShift=8
HitClass=32
NumDirections=1
SubMissile1=firewall
CltSubMissile1=firewall
CltSubMissile2=firesmall
CltSubMissile3=firemedium
EOL=0
Much easier to read and understand what is going on.

How do I use it?

To use d2txt.py or d2ini.py, you must install Python 3.6 or higher. If you want support for older versions, let me know.

To use d2txt.py, simply copy the d2txt directory into your script directory (You can add it to PYTHONPATH instead if you wish). Then add the following statement at the top of your python script:

Code: Select all

from d2txt.d2txt import D2TXT
To use d2ini.py, use the commands:

Code: Select all

./d2ini.py decompile <txt_to_compile> <ini_to_save_to>
./d2ini.py compile <ini_to_compile> <txt_to_save_to>
(Windows users may have to use python .\d2ini.py compile and python .\d2ini.py decompile instead, unless they're using Git Bash.)

For more information, check out the project page.
D2TXT / D2INI - Python scripts for editing TXT files, or converting between TXT ↔ INI files

User avatar
HarvestWombs
Senior Moderator
Arch-Angel
Posts: 1019
Joined: Wed May 25, 2011 11:50 pm
United States of America

Re: d2txt.py: Edit TXT files in Python, convert to INI files

Post by HarvestWombs » Mon Jan 14, 2019 10:37 am

What are the added benefits to using a scripting language to edit simple tab deliminated text files as opposed to using any of the many excel editors that are available?
Official Phrozen Keep Discord
Common Modding tools: link
My Resource Packs: link

User avatar
mmpx222
Junior Member
Paladin
Posts: 154
Joined: Sat Apr 26, 2014 9:19 am
Korea South

Re: d2txt.py: Edit TXT files in Python, convert to INI files

Post by mmpx222 » Mon Jan 14, 2019 11:46 am

HarvestWombs wrote:
Mon Jan 14, 2019 10:37 am
What are the added benefits to using a scripting language to edit simple tab deliminated text files as opposed to using any of the many excel editors that are available?
Automation. When you want to systematically balance all skills, unify the drop rates of treasureclasses, or generate hundreds of affixes from scratch, programming will help you. Excel/Google Sheets formulas are limited, prone to copy-paste mistakes, and cannot be version controlled.
D2TXT / D2INI - Python scripts for editing TXT files, or converting between TXT ↔ INI files

User avatar
Spectrum
Posts: 69
Joined: Mon May 12, 2003 12:40 pm
Location: Denmark
Denmark

Re: d2txt.py: Edit TXT files in Python, convert to INI files

Post by Spectrum » Sun Nov 07, 2021 9:48 am

mmpx222 wrote:
Mon Jan 14, 2019 11:46 am
HarvestWombs wrote:
Mon Jan 14, 2019 10:37 am
What are the added benefits to using a scripting language to edit simple tab deliminated text files as opposed to using any of the many excel editors that are available?
Automation. When you want to systematically balance all skills, unify the drop rates of treasureclasses, or generate hundreds of affixes from scratch, programming will help you. Excel/Google Sheets formulas are limited, prone to copy-paste mistakes, and cannot be version controlled.
This is actually really nice! Thanks for sharing!

It is also very useful for inspecting someone else's mod and seeing what they changed to accomplish what they did. :)

User avatar
MilesTeg
Posts: 36
Joined: Sun Jul 18, 2021 6:42 am
Germany

Re: d2txt.py: Edit TXT files in Python, convert to INI files

Post by MilesTeg » Tue Nov 09, 2021 3:13 pm

Great idea!

Just wanted to point out if s.o. is interested:
I had a similiar idea for json files & D2R. You can also use the pandas library for python for both txt and json files :)

Example from PK user Kruno of txt-editing:
https://github.com/KrunoSaho/Jupyter/bl ... ling.ipynb

The library:
https://pandas.pydata.org/

sainrishab
Posts: 6
Joined: Mon Dec 20, 2021 10:56 am
Location: Pune
Contact:
India

Re: d2txt.py: Edit TXT files in Python, convert to INI files

Post by sainrishab » Mon Dec 20, 2021 11:06 am

Choose one text file from your computer, Google Drive, or a GMail attachment to start.
The file will open in your browser, allowing you to make any required changes or edits.
Even if you've completed changing, click the "Save to Drive" right to renew the edited file to Google Drive. The configparser module in Python was used to read the. ini files, which usually contain configuration information. Using the python configparser module, generate an ini file. {Online Python Training in Pune}

Post Reply

Return to “Tools”