Left 4 Dead 2

Left 4 Dead 2

Not enough ratings
Mass Edit Script
By senzawa
Small python script for mass editing attach points of weapon scripts.
   
Award
Favorite
Favorited
Unfavorite
Main Body
Small Python script I made to mass-edit attachment points for weapon scripts and add in L4D1 arms support in the process so you can unpack stuff out of left4dead2/pak1_dir and use that straight out of the box. Just though I'd toss this out there in case anyone needs it.
I think the code is clear enough that it doesn't warrant a documentation, but if it does comment below and I'll add one if enough people asks.


import re
import os


attach = '"AddonAttachment"\t\t\t"%s"'
arms = '''"CharacterViewmodelAddon"
{
"Coach" "models/weapons/arms/v_arms_coach_new.mdl"
"Mechanic" "models/weapons/arms/v_arms_mechanic_new.mdl"
"Producer" "models/weapons/arms/v_arms_producer_new.mdl"
"Gambler" "models/weapons/arms/v_arms_gambler_new.mdl"


"Manager" "models/weapons/arms/v_arms_louis.mdl"
"Biker" "models/weapons/arms/v_arms_francis.mdl"
"TeenGirl" "models/weapons/arms/v_arms_zoey.mdl"
"NamVet" "models/weapons/arms/v_arms_bill.mdl"
}'''
mumbo = "MUMBO_JUMBO_c4e1d135c57403bc72c6069b1a9b24d7"
def work(fin,fout,name):
with open(fin) as f:
s = f.read()
# change attachment name
s = re.sub(r'"AddonAttachment"\s*".*?"',attach%name,s)
# fix arms
s = re.sub(r'"CharacterViewmodelAddon"\s*{[\s\S]*?}',arms,s)

with open(fout,"w") as f:
l = f.write(s)
print("Wrote %d bytes to %s."%(l,fout))

def massedit(din,dout,name=mumbo):
for i in os.listdir(din):
fin = os.path.join(din,i)
fout = os.path.join(dout,i)
if os.path.isfile(fin):
work(fin,fout,name)