100 likes | 228 Views
Introduction to Half Life 2 Modding. Seminar Seven The story so far: Creating a mod via Source SDK Introduction to Hammer Hammer techniques Importing custom art content This week: Mod organisation and starting to code Homework: See how much you can break the code. Mod Layout.
E N D
Introduction to Half Life 2 Modding • Seminar Seven • The story so far: • Creating a mod via Source SDK • Introduction to Hammer • Hammer techniques • Importing custom art content • This week: • Mod organisation and starting to code • Homework: • See how much you can break the code
Mod Layout • Folder structure • Bin – contains all DLL files • Cfg – contains all configuration files • Maps – all files relating to maps (BSP, sound caches, nav graphs) • Materials – all texture / material files (VMT / VTF) • Media – video to play at game startup • Models – all model files (MDL, PHY, VVD and VTX) • Resource – files that dictate visual appearance (HUD, menus). • Scripts – files that control everything else (weapons, audio effects etc) • Shaders – compiled shader files (VCS) – both pixel and vertex • Sound– all sound files (MP3 / WAV)
Altering the visual style • ClientScheme.res • Controls menu styles • Font type, size and colour • Setting background image • Insert VTF/VMT into materials/console • The VMT shader is “UnlitGeneric” • Create / modify scripts/ChapterBackgrounds.txt • Enter name of VMT file, minus extension and location. • Altering the HUD • Core file is scripts/HudLayout.res
Overview of code • The code base is divided into two sections • Client and Server • Client controls rendering and visual effects • Server controls game logic (it does the 'thinking') • There is communication between the two sections and some bits of code appear in both! • The code base is not a simple beast! • Over a million lines of code, only 15% of which are comments! • The Hidden has added 20,000 lines of new code and it's still not done!
Working with the code • The current code base can be opened in either Visual Studio 2003 or 2005. • It's currently easier to work in 2005! • It contains two projects, client_sdk and hl • client_sdk is all client code • hl is all server code • Some code is found in both projects • Open weapon_rpg.cpp – find it in HL2MP / weapons on the sidebar. • Note the series of statements such as#ifdef CLIENT_DLL.
Modifying the code • With weapon_rpg.cpp still open • Find the line that reads: #define RPG_SPEED 1500 • Modify the value to something significantly different • 500 or 2500 would be good! • Compile (Ctrl-Shift-B or Build | Build Solution) • This will take some time the first time you do it! • You have now successfully created a modification for HL2 – simple as it may be!
Adding code • Now we'll look at adding an item to the code • We'll copy an existing weapon • This requires new code and new items in the mod folder • Open weapon_smg1.cpp • Note there is no matching header file (this makes our life a bit easier) • Select all the code and copy it (Ctrl-A then Ctrl-C) • Add a new folder to the client project • Right Click 'client' – Add | New Folder • Add a new item to that folder • Right Click folder – Add | Add New Item • Select C++ file, enter a file name (weapon_*.cpp), create a new folder under game_shared – use that as the save location
Adding code (cont.) • In the empty window, paste the code we just copied • Now we need to rename the class – find a bit of code that says the class name (CweaponSMG1) • Copy the WeaponSMG1 part (not the C!) • Use Find and Replace (Ctrl-H) • Enter WeaponSMG1 as the Find and WeaponSMGMine as the Replace – press Replace All. • Final stage in code – add the new file to the server project!
Adding code (cont.) • Add a new folder to the 'hl' project • Rather than adding a new item, add an existing one and find the weapon_smg2.cpp file we just created. • See now why we put the file in game_shared? • One last change in code – line 85 (LINK_ENTITY_TO_CLASS) and 86, change weapon_smg1 to weapon_smg2 • This tells the game where to look for the script information and stops it getting confused
Finishing off the weapon • Find weapon_smg1.txt in the mod scripts folder • Copy and paste it • Rename it to weapon_smg2.txt • Open weapon_smg2.txt • Change bucket_position to 2 • Play with the values (alter the clip_size, change the view model etc) • Boot up the game and see your changes • Use ‘give weapon_smg2’ to play with your new weapon.