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: 139
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
Angel
Posts: 944
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: 139
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

Post Reply

Return to “Tools”