├── .gitignore ├── LICENSE.md ├── smc3k-gsrlg.py └── smc3k-gmrlg.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Nano 2 | *.swp 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2020 Ivan Kuzmenko 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /smc3k-gsrlg.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import sys 4 | import argparse 5 | import os 6 | import filecmp 7 | import shutil 8 | import ntpath 9 | 10 | ### 11 | 12 | def exit_if_is_not_folder(path): 13 | if not os.path.exists(path): 14 | print('Error: folder', path, 'does not exist!') 15 | sys.exit(1) 16 | elif not os.path.isdir(path): 17 | print('Error:', path, 'is not a folder!') 18 | sys.exit(1) 19 | 20 | def create_if_does_not_exist(path): 21 | if not os.path.exists(path): 22 | os.mkdir(path) 23 | if not os.path.exists(path): 24 | print('Error: failed to create a folder ' + path + '!') 25 | sys.exit(1) 26 | elif not os.path.isdir(path): 27 | print('Error:', path, 'is not a folder!') 28 | sys.exit(1) 29 | 30 | def recursive_search(path): 31 | temp_list = [] 32 | for dir_, _, files in os.walk(path): 33 | for fn in files: 34 | rel_dir = os.path.relpath(dir_, path) 35 | rel_file = os.path.join(rel_dir, fn) 36 | temp_list.append(rel_file) 37 | return temp_list 38 | 39 | ### 40 | 41 | parser = argparse.ArgumentParser(description='Super Map Converter 3k - Global Sound Replacement List Generator') 42 | 43 | parser.add_argument('-s', '--source', action='store', dest='source_mod_folder', help='Path to the mod for GoldSrc', required=True) 44 | parser.add_argument('-hl', '--half-life', action='store', dest='half_life_folder', help='Path to Half-Life folder', required=True) 45 | parser.add_argument('-o', '--output', action='store', dest='output_folder', help='Path to output folder', required=True) 46 | parser.add_argument('-p', '--prefix', action='store', dest='prefix', type=str, help='Prefix for converted sounds') 47 | parser.add_argument('-d', '--diff', action='store_true', dest='diff_sounds', help='Copy only sounds that are different from Half-Life') 48 | parser.add_argument('-c', '--create-folder', action='store_true', dest='cr_folder', help='Create output folder if it does not exist') 49 | parser.add_argument('-cl', '--classic-mode', action='store_true', dest='cm_override', help='Make overrides for classic mode') 50 | parser.add_argument('-t', '--dry-run', action='store_true', dest='dry', help='Do not modify files') 51 | 52 | args = parser.parse_args() 53 | 54 | ### 55 | 56 | mod_path = os.path.relpath(args.source_mod_folder) 57 | exit_if_is_not_folder(mod_path) 58 | 59 | hl_path = os.path.relpath(args.half_life_folder) 60 | exit_if_is_not_folder(hl_path) 61 | 62 | out_path = os.path.relpath(args.output_folder) 63 | if not args.dry: 64 | if args.cr_folder: 65 | create_if_does_not_exist(out_path) 66 | else: 67 | exit_if_is_not_folder(out_path) 68 | 69 | ### 70 | 71 | mod_sound_path = os.path.join(mod_path, 'sound') 72 | exit_if_is_not_folder(mod_sound_path) 73 | 74 | hl_sound_path = os.path.join(hl_path, 'sound') 75 | exit_if_is_not_folder(hl_sound_path) 76 | 77 | out_sound_path = os.path.join(out_path, 'sound', args.prefix) 78 | create_if_does_not_exist(out_sound_path) 79 | 80 | ### 81 | 82 | # PLEASE NOTE: only sound file list is generated with recursive search! 83 | 84 | mod_sounds = recursive_search(mod_sound_path) 85 | hl_sounds = recursive_search(hl_sound_path) 86 | 87 | sounds = [] 88 | 89 | if args.diff_sounds: 90 | for sound in mod_sounds: 91 | if sound in hl_sounds and not filecmp.cmp(os.path.join(mod_sound_path, sound), os.path.join(hl_sound_path, sound)): 92 | sounds.append(sound) 93 | else: 94 | sounds = mod_sounds 95 | 96 | print("Sounds that are going to be copied:", sounds) 97 | 98 | ### 99 | 100 | gsr_file = '## Generated with Super Mod Converter 3000\n' 101 | 102 | for sound in sounds: 103 | if sound[-3:] == 'txt': 104 | continue 105 | if not args.dry: 106 | shutil.copy(os.path.join(mod_sound_path, sound), os.path.join(out_sound_path, ntpath.split(sound)[0])) 107 | gsr_file += '\"{}\" \"{}\"\n'.format(os.path.join(sound), os.path.join(args.prefix, sound)) 108 | if args.cm_override: 109 | gsr_file += '\"{}\" \"{}\"\n'.format(os.path.join('hlclassic', sound), os.path.join(args.prefix, sound)) 110 | 111 | if args.dry: 112 | print('Your .gsr file:') 113 | print(gsr_file) 114 | else: 115 | gsr_path = os.path.join(out_path, 'maps', args.prefix + '.gsr') 116 | with open(gsr_path, 'w') as f: 117 | f.write(gsr_file) 118 | print('Don\'t forget to add "globalsoundlist" to you map\'s .cfg file!') 119 | 120 | print('Done.') 121 | -------------------------------------------------------------------------------- /smc3k-gmrlg.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import sys 4 | import argparse 5 | import os 6 | import filecmp 7 | import shutil 8 | 9 | ### 10 | 11 | def exit_if_is_not_folder(path): 12 | if not os.path.exists(path): 13 | print('Error: folder', path, 'does not exist!') 14 | sys.exit(1) 15 | elif not os.path.isdir(path): 16 | print('Error:', path, 'is not a folder!') 17 | sys.exit(1) 18 | 19 | def create_if_does_not_exist(path): 20 | if not os.path.exists(path): 21 | os.mkdir(path) 22 | if not os.path.exists(path): 23 | print('Error: failed to create a folder ' + path + '!') 24 | sys.exit(1) 25 | elif not os.path.isdir(path): 26 | print('Error:', path, 'is not a folder!') 27 | sys.exit(1) 28 | 29 | ### 30 | 31 | parser = argparse.ArgumentParser(description='Super Map Converter 3k - Global Model Replacement List Generator') 32 | 33 | parser.add_argument('-s', '--source', action='store', dest='source_mod_folder', help='Path to the mod for GoldSrc', required=True) 34 | parser.add_argument('-hl', '--half-life', action='store', dest='half_life_folder', help='Path to Half-Life folder', required=True) 35 | parser.add_argument('-o', '--output', action='store', dest='output_folder', help='Path to output folder', required=True) 36 | parser.add_argument('-p', '--prefix', action='store', dest='prefix', type=str, help='Prefix for converted models') 37 | parser.add_argument('-d', '--diff', action='store_true', dest='diff_models', help='Copy only models that are different from Half-Life') 38 | parser.add_argument('-c', '--create-folder', action='store_true', dest='cr_folder', help='Create output folder if it does not exist') 39 | parser.add_argument('-cl', '--classic-mode', action='store_true', dest='cm_override', help='Make overrides for classic mode') 40 | parser.add_argument('-t', '--dry-run', action='store_true', dest='dry', help='Do not modify files') 41 | 42 | args = parser.parse_args() 43 | 44 | ### 45 | 46 | mod_path = os.path.relpath(args.source_mod_folder) 47 | exit_if_is_not_folder(mod_path) 48 | 49 | hl_path = os.path.relpath(args.half_life_folder) 50 | exit_if_is_not_folder(hl_path) 51 | 52 | out_path = os.path.relpath(args.output_folder) 53 | if not args.dry: 54 | if args.cr_folder: 55 | create_if_does_not_exist(out_path) 56 | else: 57 | exit_if_is_not_folder(out_path) 58 | 59 | ### 60 | 61 | mod_model_path = os.path.join(mod_path, 'models') 62 | exit_if_is_not_folder(mod_model_path) 63 | 64 | hl_model_path = os.path.join(hl_path, 'models') 65 | exit_if_is_not_folder(hl_model_path) 66 | 67 | out_model_path = os.path.join(out_path, 'models', args.prefix) 68 | create_if_does_not_exist(out_model_path) 69 | 70 | ### 71 | 72 | # PLEASE NOTE: generated file lists are made with non-recursive search! 73 | 74 | mod_models = [f for f in os.listdir(mod_model_path) if os.path.isfile(os.path.join(mod_model_path, f))] 75 | hl_models = [f for f in os.listdir(hl_model_path) if os.path.isfile(os.path.join(hl_model_path, f))] 76 | 77 | models = [] 78 | 79 | if args.diff_models: 80 | for model in mod_models: 81 | if model in hl_models and not filecmp.cmp(os.path.join(mod_model_path, model), os.path.join(hl_model_path, model)): 82 | models.append(model) 83 | else: 84 | models = mod_models 85 | 86 | print("Models that are going to be copied:", models) 87 | 88 | ### 89 | 90 | gmr_file = '## Generated with Super Mod Converter 3000\n' 91 | 92 | for model in models: 93 | if not args.dry: 94 | shutil.copy(os.path.join(mod_model_path, model), out_model_path) 95 | # trying to find a "texture" model 96 | model_tex = os.path.join(mod_model_path, model[:-4] + 't.mdl') 97 | if os.path.exists(model_tex): 98 | print('Found a texture model for ' + model + '.') 99 | shutil.copy(model_tex, out_model_path) 100 | gmr_file += '\"{}\" \"{}\"\n'.format(os.path.join('models', model), os.path.join('models', args.prefix, model)) 101 | if args.cm_override: 102 | gmr_file += '\"{}\" \"{}\"\n'.format(os.path.join('models', 'hlclassic', model), os.path.join('models', args.prefix, model)) 103 | 104 | if args.dry: 105 | print('Your .gmr file:') 106 | print(gmr_file) 107 | else: 108 | gmr_path = os.path.join(out_path, 'maps', args.prefix + '.gmr') 109 | with open(gmr_path, 'w') as f: 110 | f.write(gmr_file) 111 | print('Don\'t forget to add "globalmodellist" to you map\'s .cfg file!') 112 | 113 | print('Done.') 114 | --------------------------------------------------------------------------------