Advertisement
Guest User

evtlodfix.py

a guest
Mar 24th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.17 KB | None | 0 0
  1. import os
  2. import sys
  3. import zlib
  4.  
  5. def eprint(*args, **kwargs):
  6.     print(*args, file=sys.stderr, **kwargs)
  7.  
  8.  
  9. #class Dungeon:
  10. trees="/mnt/Users/Daniel/Downloads/Enhanced Vanilla Trees New/"
  11. oldtrees="/mnt/Users/Daniel/Downloads/Enhanced Vanilla Trees Old/"
  12. bbdir="Billboards"
  13. dup="8CCD246F"
  14. duph=""
  15.    
  16. #print(coords)
  17. #sys.exit(0)
  18. i=0
  19. hashes={}
  20. def hexy(x):
  21.     hex_result=hex(x)[2:]
  22.     num_hex_chars = len(hex_result)
  23.     extra_zeros = '0' * (8 - num_hex_chars)
  24.     return (extra_zeros+hex_result).upper()
  25.  
  26. def eprint(*args, **kwargs):
  27.     print(*args, file=sys.stderr, **kwargs)
  28.  
  29. def cp(inf, outf):
  30. #    print("Moving "+inf+" to "+outf)
  31. #    os.system("mv \""+inf+"\" \""+outf+"\"")
  32.     print("mov \""+inf[11:]+"\" \""+outf[11:]+"\"")
  33.  
  34. def cp2(inf, outf):
  35. #    print("Copying "+inf+" to "+outf)
  36. #    os.system("cp \""+inf+"\" \""+outf+"\"")
  37.     print("cp \""+inf[11:]+"\" \""+outf[11:]+"\"")
  38.  
  39. for fold, subdirs, files in os.walk(trees):
  40.     #eprint(locf)
  41.     for f in files:
  42.         if f[-4:] !=".nif":
  43.             continue
  44.         oldf=open(fold.replace(trees,oldtrees)+"/"+f, 'rb')
  45.         newf=open(fold+"/"+f, 'rb')
  46.         ohash=hexy(zlib.crc32(oldf.read())&0xffffffff)
  47.         nhash=hexy(zlib.crc32(newf.read())&0xffffffff)
  48.         if ohash==dup and duph=="":
  49.             duph=nhash
  50.         else:
  51.             if ohash in hashes and hashes[ohash]!= nhash:
  52.                 print("hash collision "+ohash)
  53.             hashes[ohash]=nhash
  54. #        print(ohash+": "+hashes[ohash])
  55.        
  56. for fold, subdirs, files in os.walk(bbdir):
  57.     for f in files:
  58.         if f[-4:] !=".nif":
  59.             continue
  60.         if f[-16:] != "passthru_lod.nif":
  61.             eprint(f + " not passthru")
  62.         if f[-17:-16] == "_":
  63.             eprint(f+ " no hash")
  64.         h=f[-24:-16]
  65.         if h not in hashes:
  66.             eprint("missing "+h+" for " + fold+"/"+f)
  67.         else:
  68.             if h==dup:
  69.                 cp2(fold+"/"+f,fold+"/"+f[:-24]+duph+"passthru_lod.nif")
  70.             if h != hashes[h]:
  71.                 cp(fold+"/"+f,fold+"/"+f[:-24]+hashes[h]+"passthru_lod.nif")
  72.        
  73. #print(hashes)
  74. #            d= Dungeon()
  75. #            d.name=name
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement