Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
3.9 KiB

  1. import WildcardSearch
  2. import sys
  3. import re
  4. import os
  5. curProps = {}
  6. modelsContentFallbackDir = "c:\\hl2\\hl2\\models"
  7. modelsContentDir = "c:\\hl2\\cstrike\\models"
  8. materialsFallbackDir = "c:\\hl2\\hl2\\materials"
  9. materialsDir = "c:\\hl2\\cstrike\\materials"
  10. mapsDir = "c:\\hl2\\cstrike\\maps"
  11. exeDir = "c:\\hl2\\bin"
  12. # RE to look for '$surfaceProp blah'
  13. surfacePropRE = re.compile( r'\"?\$surfaceprop\"?\s+\"?(?P<propname>[^\"]+)\"?', re.IGNORECASE )
  14. # ------------------------------------------------------------------------------------------- #
  15. # Helper functions.
  16. # ------------------------------------------------------------------------------------------- #
  17. def FileExists(f):
  18. try:
  19. file = open(f)
  20. except IOError:
  21. exists = 0
  22. else:
  23. exists = 1
  24. file.close()
  25. return exists
  26. def PrintFilename( filename ):
  27. print filename
  28. def SearchFile( filename ):
  29. f = open( filename, "rt" )
  30. PrintFilename( filename )
  31. fileData = f.read()
  32. match = surfacePropRE.search( fileData )
  33. if match:
  34. propName = match.group( 1 ).upper()
  35. curProps[propName] = 1
  36. f.close()
  37. # ------------------------------------------------------------------------------------------- #
  38. # Search all the map files for texture names and model files.
  39. # ------------------------------------------------------------------------------------------- #
  40. usedVMTFiles = {}
  41. modelFiles = {}
  42. # RE to look for 'material blah'
  43. materialRE = re.compile( r'\"?\material\"?\s+\"?(?P<matname>[^\"]+)\"?', re.IGNORECASE )
  44. # Look for a model name referenced in the VMF file.
  45. modelRE = re.compile( r'\"models\/(?P<modelname>.+)\.mdl\"', re.IGNORECASE )
  46. files = WildcardSearch.WildcardSearch( mapsDir + "\\*.vmf", 1 )
  47. for filename in files:
  48. f = open( filename, "rt" )
  49. fileData = f.read()
  50. f.close()
  51. PrintFilename( filename )
  52. # Get all the model names.
  53. allMatches = modelRE.findall( fileData )
  54. for match in allMatches:
  55. modelFiles[match.upper()] = 1
  56. # Get all the texture names.
  57. allMatches = materialRE.findall( fileData )
  58. for match in allMatches:
  59. vmtName = match
  60. usedVMTFiles[vmtName] = 1
  61. # ------------------------------------------------------------------------------------------- #
  62. # Search all the model files for surface props.
  63. # ------------------------------------------------------------------------------------------- #
  64. # Make sure we look at ALL models in the CStrike folder.
  65. for filename in WildcardSearch.WildcardSearch( modelsContentDir + "\\*.mdl", 1 ):
  66. modelFiles[filename.upper()] = 1
  67. for iModel in modelFiles.keys():
  68. iModel = iModel.replace( "/", "\\" )
  69. filename = modelsContentDir + "\\" + iModel + ".mdl"
  70. if not FileExists( filename ):
  71. filename = modelsContentFallbackDir + "\\" + iModel + ".mdl"
  72. if FileExists( filename ):
  73. PrintFilename( filename )
  74. cmd = exeDir + "\\studiomdl.exe -PrintSurfaceProps " + filename
  75. f = os.popen( cmd )
  76. if f:
  77. output = f.readlines()
  78. returnValue = f.close()
  79. if returnValue == None:
  80. for line in output:
  81. curProps[line.upper().strip()] = 1
  82. # ------------------------------------------------------------------------------------------- #
  83. # Search all the texture files for surface props.
  84. # ------------------------------------------------------------------------------------------- #
  85. for iFile in usedVMTFiles.keys():
  86. filename = materialsDir + "\\" + iFile + ".vmt"
  87. if not FileExists( filename ):
  88. filename = materialsFallbackDir + "\\" + iFile + ".vmt"
  89. if FileExists( filename ):
  90. SearchFile( filename )
  91. # ------------------------------------------------------------------------------------------- #
  92. # Output the results.
  93. # ------------------------------------------------------------------------------------------- #
  94. print "\n"
  95. print "---------------------------------"
  96. print "- Surface types found"
  97. print "---------------------------------\n"
  98. sortedList = [x for x in curProps.keys()]
  99. sortedList.sort()
  100. for x in sortedList:
  101. print x