diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /devtools/CheckSurfaceProps.py | |
| download | archived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.tar.xz archived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.zip | |
Diffstat (limited to 'devtools/CheckSurfaceProps.py')
| -rw-r--r-- | devtools/CheckSurfaceProps.py | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/devtools/CheckSurfaceProps.py b/devtools/CheckSurfaceProps.py new file mode 100644 index 0000000..80ee6c7 --- /dev/null +++ b/devtools/CheckSurfaceProps.py @@ -0,0 +1,153 @@ + +import WildcardSearch +import sys +import re +import os + + +curProps = {} + + +modelsContentFallbackDir = "c:\\hl2\\hl2\\models" +modelsContentDir = "c:\\hl2\\cstrike\\models" + +materialsFallbackDir = "c:\\hl2\\hl2\\materials" +materialsDir = "c:\\hl2\\cstrike\\materials" +mapsDir = "c:\\hl2\\cstrike\\maps" +exeDir = "c:\\hl2\\bin" + + +# RE to look for '$surfaceProp blah' +surfacePropRE = re.compile( r'\"?\$surfaceprop\"?\s+\"?(?P<propname>[^\"]+)\"?', re.IGNORECASE ) + + + +# ------------------------------------------------------------------------------------------- # +# Helper functions. +# ------------------------------------------------------------------------------------------- # + +def FileExists(f): + try: + file = open(f) + except IOError: + exists = 0 + else: + exists = 1 + file.close() + return exists + + +def PrintFilename( filename ): + print filename + + +def SearchFile( filename ): + f = open( filename, "rt" ) + + PrintFilename( filename ) + + fileData = f.read() + match = surfacePropRE.search( fileData ) + if match: + propName = match.group( 1 ).upper() + curProps[propName] = 1 + + f.close() + + + +# ------------------------------------------------------------------------------------------- # +# Search all the map files for texture names and model files. +# ------------------------------------------------------------------------------------------- # + +usedVMTFiles = {} +modelFiles = {} + + +# RE to look for 'material blah' +materialRE = re.compile( r'\"?\material\"?\s+\"?(?P<matname>[^\"]+)\"?', re.IGNORECASE ) + +# Look for a model name referenced in the VMF file. +modelRE = re.compile( r'\"models\/(?P<modelname>.+)\.mdl\"', re.IGNORECASE ) + + +files = WildcardSearch.WildcardSearch( mapsDir + "\\*.vmf", 1 ) +for filename in files: + f = open( filename, "rt" ) + fileData = f.read() + f.close() + + PrintFilename( filename ) + + # Get all the model names. + allMatches = modelRE.findall( fileData ) + for match in allMatches: + modelFiles[match.upper()] = 1 + + # Get all the texture names. + allMatches = materialRE.findall( fileData ) + for match in allMatches: + vmtName = match + usedVMTFiles[vmtName] = 1 + + +# ------------------------------------------------------------------------------------------- # +# Search all the model files for surface props. +# ------------------------------------------------------------------------------------------- # + +# Make sure we look at ALL models in the CStrike folder. +for filename in WildcardSearch.WildcardSearch( modelsContentDir + "\\*.mdl", 1 ): + modelFiles[filename.upper()] = 1 + +for iModel in modelFiles.keys(): + iModel = iModel.replace( "/", "\\" ) + filename = modelsContentDir + "\\" + iModel + ".mdl" + if not FileExists( filename ): + filename = modelsContentFallbackDir + "\\" + iModel + ".mdl" + + if FileExists( filename ): + PrintFilename( filename ) + + cmd = exeDir + "\\studiomdl.exe -PrintSurfaceProps " + filename + f = os.popen( cmd ) + if f: + output = f.readlines() + returnValue = f.close() + + if returnValue == None: + for line in output: + curProps[line.upper().strip()] = 1 + + + +# ------------------------------------------------------------------------------------------- # +# Search all the texture files for surface props. +# ------------------------------------------------------------------------------------------- # + +for iFile in usedVMTFiles.keys(): + filename = materialsDir + "\\" + iFile + ".vmt" + if not FileExists( filename ): + filename = materialsFallbackDir + "\\" + iFile + ".vmt" + + if FileExists( filename ): + SearchFile( filename ) + + + + +# ------------------------------------------------------------------------------------------- # +# Output the results. +# ------------------------------------------------------------------------------------------- # + +print "\n" +print "---------------------------------" +print "- Surface types found" +print "---------------------------------\n" + +sortedList = [x for x in curProps.keys()] +sortedList.sort() + +for x in sortedList: + print x + + |