Advertisement
Guest User

.play decompiler 1.0.1

a guest
May 18th, 2021
878
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 16.91 KB | None | 0 0
  1. #NOTE: i'm not responsible for any emotional or psychological
  2. #damage that might be caused by the code structure below. you have been warned.
  3.  
  4. #update 1.0.1 - fixed jacket and biker being their cars and vice versa
  5.  
  6. vehicleIDs = [236, #ObjFansVan         editor ID is 1582
  7.               764, #objCopCar
  8.               1049, #objTaxi
  9.               1341, #objMilitaryJeepUSA
  10.               1366, #objSonCar
  11.               2040, #objRatBusStop
  12.               870, #objCobraCar
  13.               2349, #objPigCart
  14.               1147, #objHenchmanCar
  15.               2394, #objHammerCar
  16.               2345, #objJacketCar
  17.               2347] #objBikerBike
  18.  
  19.  
  20. playerCharacterIDs = [185, #ObjPlayerZebra         editor ID is 1583
  21.                       169, #ObjPlayerTiger
  22.                       859, #ObjPlayerBear
  23.                       1051, #objPlayerSwanChainsaw
  24.                       763, #ObjCop
  25.                       1048, #objWriter
  26.                       324, #objNicke
  27.                       1347, #objSon
  28.                       1225, #objRat
  29.                       866, #objPlayerCobra
  30.                       35, #objPigButcher
  31.                       1067, #objPlayerHenchman
  32.                       2387, #objTheHammer
  33.                       2335, #objJacket
  34.                       2334] #objBiker
  35.  
  36. enemyIDs = [1064, #objDogPatrol         editor ID is 10
  37.             170,  #objEGangMeleeRandom
  38.             183,  #objEGangRandom
  39.             184,  #objEGangPatrol
  40.             186,  #objEGangStatic
  41.             229,  #objEGangIdlePipe
  42.             230,  #objEGangIdleKnife
  43.             231,  #objEGangIdleSmoke
  44.             941,  #objEGangMeleePatrol
  45.             1144, #objEGangIdleMoney
  46.             1289, #objEGangFat
  47.             2286, #objGangDodger
  48.             875, #objEMafiaMeleeRandom
  49.             876, #objEMafiaRandom
  50.             877, #objEMafiaStatic
  51.             878, #objEMafiaPatrol
  52.             916, #objEMafiaIdlePhoneSilencer
  53.             938, #objEMafiaMeleePatrol
  54.             1464, #objEMafiaFat
  55.             2407, #objEMafiaIdleSmoke
  56.             2408, #objEMafiaIdlePipe
  57.             1354, #objColombianMeleeRandom
  58.             1355, #objColombianMeleePatrol
  59.             1356, #objColombianRandom
  60.             1357, #objColombianStatic
  61.             1358, #objColombianPatrol
  62.             1359, #objColombianIdlePipe
  63.             1737, #objColombianHiding
  64.             1886, #objColombianDodger
  65.             931, #objEPoliceMeleeRandom
  66.             932, #objEPoliceRandom
  67.             933, #objEPolicePatrol
  68.             934, #objEPoliceStatic
  69.             937, #objFatPolice
  70.             939, #objEPoliceMeleePatrol
  71.             2409, #objPoliceIdleTalk
  72.             1530, #objGuardMeleeRandom
  73.             1531, #objGuardMeleePatrol
  74.             1532, #objGuardRandom
  75.             1533, #objGuardStatic
  76.             1534, #objGuardPatrol
  77.             2168, #objGuardIdleStick
  78.             672, #objSoldierMeleeRandom
  79.             674, #objSoldierRandom
  80.             696, #objSoldierPatrol
  81.             697, #objSoldierStatic
  82.             698, #objSoldierFatKnife
  83.             704, #objSoldierFatGun
  84.             706, #objSoldierIdlePonchoSmoke
  85.             707, #objPoncho
  86.             708, #objSoldierIdleRain
  87.             1460, #objSoldierHiding
  88.             2396, #objSoldierMeleePatrol
  89.             2109, #objPrisonerMeleeRandom
  90.             2110, #objPrisonerMeleePatrol
  91.             2111, #objPrisonerRandom
  92.             2112, #objPrisonerStatic
  93.             2113, #objPrisonerPatrol
  94.             2145, #objPrisonerPsycho
  95.             2146, #objPrisonerMeleeStatic
  96.             2148, #objPrisonerFat
  97.             2167] #objPrisonerIdleGuns
  98.  
  99.  
  100. weaponIDs = [179, #obj9mm
  101.              880, #objSilencer
  102.              1352, #objMagnum
  103.              178, #objUzi
  104.              2343, #objSilencedUzi
  105.              1348, #objFamae
  106.              1349, #objMendoza
  107.              724, #objM16
  108.              723, #objKalashnikov
  109.              177, #objShotgun
  110.              150, #objDoubleBarrel
  111.              180, #objNailGun
  112.              910, #objBottle
  113.              2261, #objAcid
  114.              940, #objTaser
  115.              173, #objKnife
  116.              175, #objButterfly
  117.              936, #objStick
  118.              2337, #objDrill
  119.              83, #objBat
  120.              176, #objPipe
  121.              881, #objClub
  122.              1368, #objSword
  123.              741, #objMachete
  124.              1818, #objAxe
  125.              1351, #objSkateboard
  126.              174, #objChain
  127.              2338, #objPotFull
  128.              2339, #objPotEmpty
  129.              144, #objHammer
  130.              100, #objShotgunWall
  131.              720, #objHeavy
  132.              721, #objFlameThrower
  133.              722, #objSniperRifle
  134.              882, #objMP5
  135.              1055, #objChainsaw
  136.              1227, #objDiscardedGun
  137.              1228, #objGunClip
  138.              1350, #objShardBlade
  139.              2105, #objPipeBig
  140.              2106, #objBrush
  141.              2292, #objNickeKnife
  142.              2293, #objBottleBroken
  143.              2346] #objCleaver
  144.  
  145. doorIDs = [25, #objEditorDoorV
  146.            26, #objEditorDoorH
  147.            2254, #objEditorDoorH2
  148.            2255] #objEditorDoorV2
  149.  
  150. wallIDs = [7, #objEditorWallH #white walls
  151.            8, #objEditorWallV
  152.            31, #objEditorBrickWallV #red walls
  153.            32, #objEditorBrickWallH
  154.            33, #objEditorSoftWallV #soft walls
  155.            34, #objEditorSoftWallH
  156.            1271, #objSewerWallV #sewer green walls
  157.            1272, #objSewerWallH
  158.            101, #objEditorPorchWallV #sickly green walls
  159.            102, #objEditorPorchWallH
  160.            675, #objWoodWallV #brown wood walls
  161.            677, #objWoodWallH
  162.            682, #objWoodWindowV #normal windows, idk why wood in name
  163.            683, #objWoodWindowH
  164.            2413, #objEditorRailsLeft #brown wooden rails
  165.            56, #objEditorRailsUp
  166.            55, #objEditorRailsDown
  167.            54, #objEditorRailsRight
  168.            53, #sprEditorRailsLeft #actually unused in the editor? look at 1st rails
  169.            1511, #objRenovationWallH #shoot through "walls"
  170.            1512, #objRenovationWallV
  171.            1724, #objSubwayWallV #yellow black "danger" walls
  172.            986, #objSubwayWallH
  173.            1725, #objBoatRailingH #dead ahead
  174.            1726, #objBoatRailingV
  175.            1259, #objBalconyRailsH #idk, used in the henchman bar map
  176.            1260, #objBalconyRailsV
  177.            676, #objWoodWallInteriorV #wooden walls but sickly yellow
  178.            678, #objWoodWallInteriorH
  179.            987, #objSubwayWindowH #no V version
  180.            950, #objBarsH #prison bars
  181.            951] #objBarsV
  182.  
  183. screenTransitionID = 124         #editor ID is 2297
  184. elevatorID = 810         #editor ID is 2410
  185. barrierID = 2411         #same in editor
  186. entryIDs = [302,303]         #editor ID is 2412
  187. darknessID = 1417         #same in editor
  188. rainID = 663         #same in editor
  189. lightOverlayID = 1770         #same in editor
  190. weaponID = 2401
  191.  
  192. def generic_object_conversion(lines):
  193.     global lc
  194.     lc+=6 #a generic object in .play is 6 lines, so move 6 lines ahead in the read
  195.     objID = int(lines[0][:-1]) #grab 1st line (objectID) for finding editorID (:-1 for removing the \n)
  196.     reorder = [1,2,3,4,0,5] #order of reorder
  197.     lines = [lines[i] for i in reorder] #reordering
  198.     lines.insert(0,"dummy") #adding the editorID
  199.     #print("written "+str(lines)) #debug
  200.     return(lines)
  201.  
  202. def wall_conversion(lines): #these "change only 1 line" functions aren't really necessary tbh and only make a mess, but too late lol i already made em
  203.     global lc
  204.     lc+=6 #a wall in .play is 6 lines, so move 6 lines ahead in the read
  205.     lines = lines[:-1] #removing the last (random number) line
  206.     return lines
  207.  
  208. def screen_transition_conversion(lines):
  209.     global lc
  210.     lc+=10 #a screen transition in .play is 10 lines, so move 10 lines ahead in the read
  211.     lines[0] = "2297\n" #changing the objectID to editorID
  212.     return lines
  213.  
  214. def elevator_conversion(lines):
  215.     global lc
  216.     lc+=7 #an elevator in .play is 7 lines, so move 7 lines ahead in the read
  217.     lines[0] = "2410\n" #changing the objectID to editorID
  218.     return lines
  219.  
  220. def entry_conversion(lines):     #THIS IS A MESS
  221.     global lc
  222.     lc+=6 #an entry in .play is 6 lines, so move 6 lines ahead in the read
  223.     lines.append("0\n")
  224.     if lines[0] == "302\n": #... it means it's vertical
  225.         if debugFlag: print("inserting vertical 2nd editor id")
  226.         lines.insert(-2, "4356\n")
  227.         if lines[-2] == "-1\n": #... it means it's left
  228.             lines[-2] = "-1\n"
  229.         else: #... it means it's right
  230.             lines[-2] = "1\n"
  231.         lines[-1] = "0\n" #neutralizing horizontal direction line      
  232.     else: #... it means it's horizontal
  233.         if debugFlag: print("inserting horizontal 2nd editor id")
  234.         lines.insert(-2, "4355\n")
  235.         if lines[-2] == "-1\n": #... it means it's up
  236.             lines[-1] = "-1\n"
  237.         else: #... it means it's horizontal
  238.             lines[-1] = "1\n"
  239.         lines[-2] = "0\n" #neutralizing vertical direction line
  240.     lines[0] = "2412\n" #finally editing the objectID to editorID
  241.     return lines
  242.  
  243. magicNumber = input("gimme - ")
  244. if ("d") in magicNumber:
  245.     debugFlag = 1
  246.     magicNumber = magicNumber.replace("d","")
  247. else:
  248.     debugFlag = 0
  249. if ("e") in magicNumber:
  250.     enemyFlag = 1
  251.     magicNumber = magicNumber.replace("e","")
  252. else: enemyFlag = 0
  253. if debugFlag: print("debug flag on, printing debug info")
  254.  
  255. readPlay = open("level"+magicNumber+".play","r")
  256. inputData = readPlay.readlines()
  257. readPlay.close()
  258. inputData = inputData[2:] #getting rid of the 0 and -1
  259. inputData.append("EoF") #end of file marker, hey it works alright?
  260.  
  261. output = []
  262. playerCharactersOutput = []
  263. vehiclesOutput = []
  264. enemiesOutput = []
  265. screenTransitionsOutput = []
  266. elevatorsOutput = []
  267. barriersOutput = []
  268. entriesOutput = []
  269. doorsOutput = []
  270. rainOutput = []
  271. darknessOutput = []
  272. lightOverlayOutput = []
  273. weaponsOutput = []
  274. trueGenericObjectsOutput = []
  275.  
  276. wallsOutput = []
  277.  
  278. #print(inputData)
  279. lc = 0 #linecounter
  280. while inputData[lc] != "EoF":
  281.     if debugFlag: print("current line "+str(int(inputData[lc])))
  282.     if int(inputData[lc]) in playerCharacterIDs: #a player character is a generic object
  283.         package = inputData[lc:lc+6] #a generic object is 6 lines
  284.         if debugFlag: print("initial player character data "+str(package))
  285.         converted = generic_object_conversion(package)
  286.         converted[0] = "1582\n" #player character editor ID
  287.         if debugFlag: print("converted player character data "+str(converted))
  288.         playerCharactersOutput.append(converted)
  289.     elif int(inputData[lc]) in vehicleIDs: #a vehicle is a generic object
  290.         package = inputData[lc:lc+6] #a generic object is 6 lines
  291.         if debugFlag: print("initial vehicle data "+str(package))
  292.         converted = generic_object_conversion(package)
  293.         converted[0] = "1583\n" #vehicle editor ID
  294.         if debugFlag: print("converted vehicle data "+str(converted))
  295.         vehiclesOutput.append(converted)
  296.     elif int(inputData[lc]) in enemyIDs: #an enemy is a generic object
  297.         package = inputData[lc:lc+6] #a generic object is 6 lines
  298.         if debugFlag: print("initial enemy data "+str(package))
  299.         converted = generic_object_conversion(package)
  300.         converted[0] = "10\n" #enemy editor ID
  301.         if enemyFlag:
  302.             converted[0] = "11\n"
  303.             if debugFlag: print("enemy flag on, changing id from 10 to 11")
  304.         if debugFlag: print("converted enemy data "+str(converted))
  305.         enemiesOutput.append(converted)
  306.     elif int(inputData[lc]) == screenTransitionID: #a screen transition is a unique object
  307.         package = inputData[lc:lc+10] #a screen transition is 10 lines
  308.         if debugFlag: print("initial screen transition data "+str(package))
  309.         converted = screen_transition_conversion(package)
  310.         if debugFlag: print("converted screen transition data "+str(converted))
  311.         screenTransitionsOutput.append(converted)
  312.     elif int(inputData[lc]) == elevatorID: #an elevator is a unique object
  313.         package = inputData[lc:lc+7] #an elevator is 7 lines
  314.         if debugFlag: print("initial elevator data "+str(package))
  315.         converted = elevator_conversion(package)
  316.         if debugFlag: print("converted elevator data "+str(converted))
  317.         elevatorsOutput.append(converted)
  318.     elif int(inputData[lc]) == barrierID: #a barrier is a unique object
  319.         package = inputData[lc:lc+5] #a barrier is 5 lines
  320.         lc+=5
  321.         if debugFlag: print("general barrier data "+str(package)) #barrier structure doesn't change from play to obj
  322.         barriersOutput.append(package)
  323.     elif int(inputData[lc]) in entryIDs: #an entry is a unique object
  324.         package = inputData[lc:lc+6] #an entry is 6 lines
  325.         if debugFlag: print("initial entry data "+str(package))
  326.         converted = entry_conversion(package)
  327.         if debugFlag: print("converted entry data "+str(converted))
  328.         entriesOutput.append(converted)
  329.     elif int(inputData[lc]) in doorIDs: #a door is a unique object
  330.         package = inputData[lc:lc+7] #a door is 7 lines
  331.         lc+=7
  332.         if debugFlag: print("general door data "+str(package)) #door structure doesn't change from play to obj
  333.         doorsOutput.append(package)
  334.     elif int(inputData[lc]) == darknessID: #a darkness is a unique object
  335.         package = inputData[lc:lc+5] #a darkness is 5 lines
  336.         lc+=5
  337.         if debugFlag: print("general darkness data "+str(package)) #darkness structure doesn't change from play to obj
  338.         darknessOutput.append(package)
  339.     elif int(inputData[lc]) == rainID: #a rain is a unique object
  340.         rainAmount = int(inputData[lc+1]) #its length depends on its 2nd line
  341.         rainLength = 2 + (4 * rainAmount) #objectID and amount of rain objects + amount*4(4 lines per object)
  342.         package = inputData[lc:lc+rainLength]
  343.         if debugFlag: print("general rain data "+str(package)) #rain structure doesn't change from play to obj
  344.         lc+=rainLength #variable length, look at rainLength
  345.         rainOutput.append(package)
  346.     elif int(inputData[lc]) == lightOverlayID: #a light overlay is a unique object
  347.         package = inputData[lc:lc+2] #a light overlay is 2 lines long
  348.         lc+=2
  349.         if debugFlag: print("general light overlay data "+str(package)) #light overlay structure doesn't change from play to obj
  350.         lightOverlayOutput.append(package)
  351.     elif int(inputData[lc]) in wallIDs: #a wall is a unique object, AND it's stored in .wll, AND Trans Rights btw
  352.         package = inputData[lc:lc+6] #a wall is 6 lines long
  353.         if debugFlag: print("initial wall data "+str(package))
  354.         lc+=6
  355.         package=package[:-1] #cutting off the weird random(?) number
  356.         if debugFlag: print("converted wall data "+str(package)) #except the last line, wall structure doesn't change from play to obj
  357.         wallsOutput.append(package)
  358.     elif int(inputData[lc]) in weaponIDs: #a weapon is a generic object
  359.         package = inputData[lc:lc+6] #a generic object is 6 lines
  360.         if debugFlag: print("initial weapon data "+str(package))
  361.         converted = generic_object_conversion(package)
  362.         converted[0] = "2401\n" #editor weapon ID
  363.         if debugFlag: print("converted weapon data "+str(converted))
  364.         weaponsOutput.append(converted)
  365.     else:               #it PROBABLY AND I HOPE TO GOD it means it's a true generic object
  366.         package = inputData[lc:lc+6] #a generic object is 6 lines
  367.         if debugFlag: print("initial true generic object data "+str(package))
  368.         converted = generic_object_conversion(package)
  369.         converted[0] = "11\n" #true generic object ID
  370.         if debugFlag: print("converted true generic object data "+str(converted))
  371.         trueGenericObjectsOutput.append(converted)
  372.  
  373. if debugFlag: print("finished making output groups")
  374.  
  375. orderedOutputs = [playerCharactersOutput,
  376.                   vehiclesOutput,
  377.                   enemiesOutput,
  378.                   trueGenericObjectsOutput,
  379.                   weaponsOutput,
  380.                   screenTransitionsOutput,
  381.                   elevatorsOutput,
  382.                   barriersOutput,
  383.                   entriesOutput,
  384.                   doorsOutput,
  385.                   rainOutput,
  386.                   darknessOutput,
  387.                   lightOverlayOutput]
  388.  
  389. writeObj = open("level"+magicNumber+".obj","w")
  390. for outputGroup in orderedOutputs:
  391.     for object in outputGroup:
  392.         for line in object:
  393.             writeObj.writelines(line)
  394. if debugFlag: print("finished writing to .obj")
  395. writeObj.close()
  396.  
  397. writeWll = open("level"+magicNumber+".wll","w")
  398. for wall in wallsOutput:
  399.     for line in wall:
  400.         writeWll.writelines(line)
  401. if debugFlag: print("finished writing to .wll")
  402. writeWll.close()
  403. print("done")
  404. input("enter to close program")
  405. #made by Kataiser17, aka actually Gofer#5776 on Discord
  406. #it may be a mess but it's mine and it works darnit
  407. #you're free to edit and share this script in any way you want, just don't take all the credit for it
  408.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement