├── .gitignore ├── .gitmodules ├── GearboxTrolling.vcxproj ├── GearboxTrolling.vcxproj.filters ├── HL SDK (PS2).sln ├── Makefile ├── README.md ├── cl_dll ├── MOTD.cpp ├── ammo.cpp ├── ammo.h ├── ammo_secondary.cpp ├── ammohistory.cpp ├── ammohistory.h ├── battery.cpp ├── cdll_int.cpp ├── cl_dll.h ├── death.cpp ├── flashlight.cpp ├── geiger.cpp ├── health.cpp ├── health.h ├── hud.cpp ├── hud.h ├── hud_msg.cpp ├── hud_redraw.cpp ├── hud_update.cpp ├── menu.cpp ├── message.cpp ├── parsemsg.cpp ├── parsemsg.h ├── readme.txt ├── saytext.cpp ├── scoreboard.cpp ├── status_icons.cpp ├── statusbar.cpp ├── text_message.cpp ├── train.cpp ├── util.cpp ├── util.h └── util_vector.h ├── dlls └── cdll_dll.h ├── eemakefile.eeglobal ├── engine ├── Progs.h ├── cdll_int.h ├── const.h ├── custom.h ├── customentity.h ├── cvardef.h ├── eiface.h ├── progdefs.h ├── shake.h └── studio.h ├── linkfile ├── linkfile_ps2 ├── ps2 ├── common.cpp ├── common.h ├── main.c ├── mips.cpp ├── mips.h ├── ps2mem.cpp ├── ps2mem.h ├── sys_ps2.cpp └── types.h ├── rebuild.bat └── utils └── qcsg ├── brush.c ├── csg.h ├── gldraw.c ├── map.c ├── qcsg.c └── textures.c /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | *.elf 16 | 17 | # Fortran module files 18 | *.mod 19 | *.smod 20 | 21 | # Compiled Static libraries 22 | *.lai 23 | *.la 24 | *.a 25 | 26 | # Executables 27 | *.exe 28 | *.out 29 | *.app 30 | 31 | # User-specific files 32 | *.rsuser 33 | *.suo 34 | *.user 35 | *.userosscache 36 | *.sln.docstates 37 | 38 | # Build results 39 | [Dd]ebug/ 40 | [Dd]ebugPublic/ 41 | [Rr]elease/ 42 | [Rr]eleases/ 43 | x64/ 44 | x86/ 45 | [Ww][Ii][Nn]32/ 46 | [Aa][Rr][Mm]/ 47 | [Aa][Rr][Mm]64/ 48 | bld/ 49 | [Bb]in/ 50 | [Oo]bj/ 51 | [Ll]og/ 52 | [Ll]ogs/ 53 | 54 | # Visual Studio 2015/2017 cache/options directory 55 | .vs/ 56 | 57 | *.map -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "external/ps2sdk"] 2 | path = external/ps2sdk 3 | url = https://github.com/ThirteenAG/ps2sdk.git 4 | -------------------------------------------------------------------------------- /GearboxTrolling.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | 17.0 15 | Win32Proj 16 | {74effc0c-4ad2-4e73-8d26-828630868c41} 17 | GearboxTrolling 18 | 10.0 19 | 20 | 21 | 22 | Makefile 23 | true 24 | v143 25 | Unicode 26 | 27 | 28 | Makefile 29 | false 30 | v143 31 | true 32 | Unicode 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | rebuild.bat 48 | rebuild.bat 49 | del /s *.o 50 | GearboxTrolling.elf 51 | $(NMakePreprocessorDefinitions) 52 | ./engine;./cl_dll;./dlls;./ps2 53 | 54 | 55 | rebuild.bat 56 | rebuild.bat 57 | del /s *.o 58 | GearboxTrolling.elf 59 | $(NMakePreprocessorDefinitions) 60 | ./engine;./cl_dll;./dlls;./ps2 61 | 62 | 63 | 64 | Level3 65 | true 66 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 67 | true 68 | 69 | 70 | Console 71 | true 72 | 73 | 74 | 75 | 76 | Level3 77 | true 78 | true 79 | true 80 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 81 | true 82 | 83 | 84 | Console 85 | true 86 | true 87 | true 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /GearboxTrolling.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {58ce2948-6f27-4dd1-a692-c67870db9e98} 14 | 15 | 16 | {ae250706-2ecc-4658-b613-84fc9d4cfd72} 17 | 18 | 19 | {3061fbed-b7f8-4476-95f5-d4cbe2df1a79} 20 | 21 | 22 | 23 | 24 | HL SDK\cl_dll 25 | 26 | 27 | HL SDK\cl_dll 28 | 29 | 30 | HL SDK\cl_dll 31 | 32 | 33 | HL SDK\cl_dll 34 | 35 | 36 | HL SDK\cl_dll 37 | 38 | 39 | HL SDK\cl_dll 40 | 41 | 42 | HL SDK\cl_dll 43 | 44 | 45 | HL SDK\cl_dll 46 | 47 | 48 | HL SDK\cl_dll 49 | 50 | 51 | HL SDK\cl_dll 52 | 53 | 54 | HL SDK\cl_dll 55 | 56 | 57 | HL SDK\cl_dll 58 | 59 | 60 | HL SDK\cl_dll 61 | 62 | 63 | HL SDK\cl_dll 64 | 65 | 66 | HL SDK\cl_dll 67 | 68 | 69 | HL SDK\cl_dll 70 | 71 | 72 | HL SDK\cl_dll 73 | 74 | 75 | HL SDK\cl_dll 76 | 77 | 78 | HL SDK\cl_dll 79 | 80 | 81 | HL SDK\cl_dll 82 | 83 | 84 | HL SDK\cl_dll 85 | 86 | 87 | HL SDK\cl_dll 88 | 89 | 90 | HL SDK\cl_dll 91 | 92 | 93 | HL SDK\cl_dll 94 | 95 | 96 | Source Files 97 | 98 | 99 | Source Files 100 | 101 | 102 | Source Files 103 | 104 | 105 | Source Files 106 | 107 | 108 | Source Files 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | HL SDK\cl_dll 117 | 118 | 119 | HL SDK\cl_dll 120 | 121 | 122 | HL SDK\cl_dll 123 | 124 | 125 | HL SDK\cl_dll 126 | 127 | 128 | HL SDK\cl_dll 129 | 130 | 131 | HL SDK\cl_dll 132 | 133 | 134 | HL SDK\cl_dll 135 | 136 | 137 | HL SDK\cl_dll 138 | 139 | 140 | HL SDK\engine 141 | 142 | 143 | HL SDK\engine 144 | 145 | 146 | HL SDK\engine 147 | 148 | 149 | HL SDK\engine 150 | 151 | 152 | HL SDK\engine 153 | 154 | 155 | HL SDK\engine 156 | 157 | 158 | HL SDK\engine 159 | 160 | 161 | HL SDK\engine 162 | 163 | 164 | HL SDK\engine 165 | 166 | 167 | HL SDK\engine 168 | 169 | 170 | HL SDK\engine 171 | 172 | 173 | Header Files 174 | 175 | 176 | Header Files 177 | 178 | 179 | Header Files 180 | 181 | 182 | Header Files 183 | 184 | 185 | 186 | 187 | 188 | 189 | -------------------------------------------------------------------------------- /HL SDK (PS2).sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.11.35327.3 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GearboxTrolling", "GearboxTrolling.vcxproj", "{74EFFC0C-4AD2-4E73-8D26-828630868C41}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x86 = Debug|x86 11 | Release|x86 = Release|x86 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {74EFFC0C-4AD2-4E73-8D26-828630868C41}.Debug|x86.ActiveCfg = Debug|Win32 15 | {74EFFC0C-4AD2-4E73-8D26-828630868C41}.Debug|x86.Build.0 = Debug|Win32 16 | {74EFFC0C-4AD2-4E73-8D26-828630868C41}.Release|x86.ActiveCfg = Release|Win32 17 | {74EFFC0C-4AD2-4E73-8D26-828630868C41}.Release|x86.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {603B8A6C-4113-404C-B598-F9AF0F6195EE} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | EE_BIN_NAME = GearboxTrolling 2 | EE_BIN = GearboxTrolling.elf 3 | 4 | PS2_BUILD = 0 5 | NEWLIB_NANO = 0 6 | KERNEL_NOPATCH = 0 7 | 8 | PS2_DIR=$(SOURCE_DIR)/ps2 9 | 10 | # HL SDK 11 | ###################################### 12 | SOURCE_DIR=. 13 | ENGINE_SRC_DIR=$(SOURCE_DIR)/engine 14 | COMMON_SRC_DIR=$(SOURCE_DIR)/common 15 | DLLS_SRC_DIR=$(SOURCE_DIR)/dlls 16 | CL_DLL_SRC_DIR=$(SOURCE_DIR)/cl_dll 17 | 18 | INCLUDEDIRS= -I$(PS2_DIR) -I$(DLLS_SRC_DIR) -I$(COMMON_SRC_DIR) -I$(ENGINE_SRC_DIR) -I$(CL_DLL_SRC_DIR) 19 | 20 | CDLL_OBJS = \ 21 | $(CL_DLL_SRC_DIR)/hud.o \ 22 | $(CL_DLL_SRC_DIR)/ammo.o \ 23 | $(CL_DLL_SRC_DIR)/ammo_secondary.o \ 24 | $(CL_DLL_SRC_DIR)/ammohistory.o \ 25 | $(CL_DLL_SRC_DIR)/battery.o \ 26 | $(CL_DLL_SRC_DIR)/cdll_int.o \ 27 | $(CL_DLL_SRC_DIR)/death.o \ 28 | $(CL_DLL_SRC_DIR)/flashlight.o \ 29 | $(CL_DLL_SRC_DIR)/geiger.o \ 30 | $(CL_DLL_SRC_DIR)/health.o \ 31 | $(CL_DLL_SRC_DIR)/hud_msg.o \ 32 | $(CL_DLL_SRC_DIR)/hud_redraw.o \ 33 | $(CL_DLL_SRC_DIR)/hud_update.o \ 34 | $(CL_DLL_SRC_DIR)/menu.o \ 35 | $(CL_DLL_SRC_DIR)/message.o \ 36 | $(CL_DLL_SRC_DIR)/MOTD.o \ 37 | $(CL_DLL_SRC_DIR)/parsemsg.o \ 38 | $(CL_DLL_SRC_DIR)/saytext.o \ 39 | $(CL_DLL_SRC_DIR)/scoreboard.o \ 40 | $(CL_DLL_SRC_DIR)/status_icons.o \ 41 | $(CL_DLL_SRC_DIR)/statusbar.o \ 42 | $(CL_DLL_SRC_DIR)/text_message.o \ 43 | $(CL_DLL_SRC_DIR)/train.o \ 44 | $(CL_DLL_SRC_DIR)/util.o 45 | 46 | HLDLL_OBJS = \ 47 | $(DLLS_SRC_DIR)/aflock.o \ 48 | $(DLLS_SRC_DIR)/agrunt.o \ 49 | $(DLLS_SRC_DIR)/airtank.o \ 50 | $(DLLS_SRC_DIR)/animating.o \ 51 | $(DLLS_SRC_DIR)/animation.o \ 52 | $(DLLS_SRC_DIR)/apache.o \ 53 | $(DLLS_SRC_DIR)/barnacle.o \ 54 | $(DLLS_SRC_DIR)/barney.o \ 55 | $(DLLS_SRC_DIR)/bigmomma.o \ 56 | $(DLLS_SRC_DIR)/bloater.o \ 57 | $(DLLS_SRC_DIR)/bmodels.o \ 58 | $(DLLS_SRC_DIR)/bullsquid.o \ 59 | $(DLLS_SRC_DIR)/buttons.o \ 60 | $(DLLS_SRC_DIR)/cbase.o \ 61 | $(DLLS_SRC_DIR)/client.o \ 62 | $(DLLS_SRC_DIR)/combat.o \ 63 | $(DLLS_SRC_DIR)/controller.o \ 64 | $(DLLS_SRC_DIR)/crossbow.o \ 65 | $(DLLS_SRC_DIR)/crowbar.o \ 66 | $(DLLS_SRC_DIR)/defaultai.o \ 67 | $(DLLS_SRC_DIR)/doors.o \ 68 | $(DLLS_SRC_DIR)/effects.o \ 69 | $(DLLS_SRC_DIR)/egon.o \ 70 | $(DLLS_SRC_DIR)/explode.o \ 71 | $(DLLS_SRC_DIR)/flyingmonster.o \ 72 | $(DLLS_SRC_DIR)/func_break.o \ 73 | $(DLLS_SRC_DIR)/func_tank.o \ 74 | $(DLLS_SRC_DIR)/game.o \ 75 | $(DLLS_SRC_DIR)/gamerules.o \ 76 | $(DLLS_SRC_DIR)/gargantua.o \ 77 | $(DLLS_SRC_DIR)/gauss.o \ 78 | $(DLLS_SRC_DIR)/genericmonster.o \ 79 | $(DLLS_SRC_DIR)/ggrenade.o \ 80 | $(DLLS_SRC_DIR)/globals.o \ 81 | $(DLLS_SRC_DIR)/glock.o \ 82 | $(DLLS_SRC_DIR)/gman.o \ 83 | $(DLLS_SRC_DIR)/h_ai.o \ 84 | $(DLLS_SRC_DIR)/handgrenade.o \ 85 | $(DLLS_SRC_DIR)/hassassin.o \ 86 | $(DLLS_SRC_DIR)/h_battery.o \ 87 | $(DLLS_SRC_DIR)/h_cine.o \ 88 | $(DLLS_SRC_DIR)/h_cycler.o \ 89 | $(DLLS_SRC_DIR)/headcrab.o \ 90 | $(DLLS_SRC_DIR)/healthkit.o \ 91 | $(DLLS_SRC_DIR)/h_export.o \ 92 | $(DLLS_SRC_DIR)/hgrunt.o \ 93 | $(DLLS_SRC_DIR)/hornet.o \ 94 | $(DLLS_SRC_DIR)/hornetgun.o \ 95 | $(DLLS_SRC_DIR)/houndeye.o \ 96 | $(DLLS_SRC_DIR)/ichthyosaur.o \ 97 | $(DLLS_SRC_DIR)/islave.o \ 98 | $(DLLS_SRC_DIR)/items.o \ 99 | $(DLLS_SRC_DIR)/leech.o \ 100 | $(DLLS_SRC_DIR)/lights.o \ 101 | $(DLLS_SRC_DIR)/maprules.o \ 102 | $(DLLS_SRC_DIR)/monstermaker.o \ 103 | $(DLLS_SRC_DIR)/monsters.o \ 104 | $(DLLS_SRC_DIR)/monsterstate.o \ 105 | $(DLLS_SRC_DIR)/mortar.o \ 106 | $(DLLS_SRC_DIR)/mp5.o \ 107 | $(DLLS_SRC_DIR)/multiplay_gamerules.o \ 108 | $(DLLS_SRC_DIR)/nihilanth.o \ 109 | $(DLLS_SRC_DIR)/nodes.o \ 110 | $(DLLS_SRC_DIR)/osprey.o \ 111 | $(DLLS_SRC_DIR)/pathcorner.o \ 112 | $(DLLS_SRC_DIR)/plane.o \ 113 | $(DLLS_SRC_DIR)/plats.o \ 114 | $(DLLS_SRC_DIR)/player.o \ 115 | $(DLLS_SRC_DIR)/python.o \ 116 | $(DLLS_SRC_DIR)/rat.o \ 117 | $(DLLS_SRC_DIR)/roach.o \ 118 | $(DLLS_SRC_DIR)/rpg.o \ 119 | $(DLLS_SRC_DIR)/satchel.o \ 120 | $(DLLS_SRC_DIR)/schedule.o \ 121 | $(DLLS_SRC_DIR)/scientist.o \ 122 | $(DLLS_SRC_DIR)/scripted.o \ 123 | $(DLLS_SRC_DIR)/shotgun.o \ 124 | $(DLLS_SRC_DIR)/singleplay_gamerules.o \ 125 | $(DLLS_SRC_DIR)/skill.o \ 126 | $(DLLS_SRC_DIR)/sound.o \ 127 | $(DLLS_SRC_DIR)/soundent.o \ 128 | $(DLLS_SRC_DIR)/spectator.o \ 129 | $(DLLS_SRC_DIR)/squadmonster.o \ 130 | $(DLLS_SRC_DIR)/squeakgrenade.o \ 131 | $(DLLS_SRC_DIR)/subs.o \ 132 | $(DLLS_SRC_DIR)/talkmonster.o \ 133 | $(DLLS_SRC_DIR)/teamplay_gamerules.o \ 134 | $(DLLS_SRC_DIR)/tempmonster.o \ 135 | $(DLLS_SRC_DIR)/tentacle.o \ 136 | $(DLLS_SRC_DIR)/triggers.o \ 137 | $(DLLS_SRC_DIR)/tripmine.o \ 138 | $(DLLS_SRC_DIR)/turret.o \ 139 | $(DLLS_SRC_DIR)/util.o \ 140 | $(DLLS_SRC_DIR)/weapons.o \ 141 | $(DLLS_SRC_DIR)/world.o \ 142 | $(DLLS_SRC_DIR)/xen.o \ 143 | $(DLLS_SRC_DIR)/zombie.o \ 144 | ###################################### 145 | 146 | EE_OBJS = ps2/main.o \ 147 | ps2/sys_ps2.o \ 148 | ps2/mips.o \ 149 | ps2/ps2mem.o \ 150 | ps2/common.o \ 151 | $(CDLL_OBJS) 152 | #$(HLDLL_OBJS) 153 | 154 | ifeq ($(PS2_BUILD), 1) 155 | # PS2 156 | BASE_ADDRESS = 0x800000 157 | else 158 | # PC 159 | BASE_ADDRESS = 0x02100000 160 | endif 161 | 162 | ifeq ($(PS2_BUILD), 1) 163 | EE_LINKFILE = linkfile_ps2 164 | else 165 | EE_LINKFILE = linkfile 166 | endif 167 | 168 | EE_CFLAGS = $(INCLUDEDIRS) -Wno-comment -Wno-write-strings -fno-zero-initialized-in-bss -O0 169 | EE_CXXFLAGS = $(INCLUDEDIRS) -Wno-comment -Wno-reorder -Wno-write-strings -fno-use-cxa-atexit -fno-rtti -fno-exceptions -fno-zero-initialized-in-bss -O0 170 | 171 | EE_LDFLAGS = -Wl,--entry=init -Wl,-Map,$(EE_BIN_NAME).map -Wl,'--defsym=BASE_ADDRESS=$(BASE_ADDRESS)' 172 | 173 | all: $(EE_BIN) 174 | 175 | clean: 176 | -rm -f $(EE_BIN_NAME).map 177 | -rm -f $(EE_OBJS) 178 | -rm -f $(EE_BIN) 179 | 180 | PS2SDK = external/ps2sdk/ps2sdk 181 | 182 | include $(PS2SDK)/samples/Makefile.pref 183 | ifeq ($(PS2_BUILD), 1) 184 | include eemakefile.eeglobal 185 | else 186 | include $(PS2SDK)/samples/Makefile.eeglobal 187 | endif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | HL SDK for Playstation 2 2 | ====================== 3 | WIP project for Half-Life (SLUS-20066). Contains client library which can be used to replace original one. 4 | 5 | TODO list: 6 | - [ ] Fix client-side exceptions 7 | - [ ] Replace game library (server) 8 | - [ ] Reverse-engineer PS2 exclusive features/changes 9 | - [ ] Make it work on real PS2 hardware (PS2_BUILD define) 10 | 11 | README is under construction. 12 | 13 | Half Life 1 SDK LICENSE 14 | ====================== 15 | 16 | Half Life 1 SDK Copyright© Valve Corp. 17 | 18 | THIS DOCUMENT DESCRIBES A CONTRACT BETWEEN YOU AND VALVE CORPORATION (“Valve”). PLEASE READ IT BEFORE DOWNLOADING OR USING THE HALF LIFE 1 SDK (“SDK”). BY DOWNLOADING AND/OR USING THE SOURCE ENGINE SDK YOU ACCEPT THIS LICENSE. IF YOU DO NOT AGREE TO THE TERMS OF THIS LICENSE PLEASE DON’T DOWNLOAD OR USE THE SDK. 19 | 20 | You may, free of charge, download and use the SDK to develop a modified Valve game running on the Half-Life engine. You may distribute your modified Valve game in source and object code form, but only for free. Terms of use for Valve games are found in the Steam Subscriber Agreement located here: http://store.steampowered.com/subscriber_agreement/ 21 | 22 | You may copy, modify, and distribute the SDK and any modifications you make to the SDK in source and object code form, but only for free. Any distribution of this SDK must include this license.txt and third_party_licenses.txt. 23 | 24 | Any distribution of the SDK or a substantial portion of the SDK must include the above copyright notice and the following: 25 | 26 | DISCLAIMER OF WARRANTIES. THE SOURCE SDK AND ANY OTHER MATERIAL DOWNLOADED BY LICENSEE IS PROVIDED “AS IS”. VALVE AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES WITH RESPECT TO THE SDK, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT, TITLE AND FITNESS FOR A PARTICULAR PURPOSE. 27 | 28 | LIMITATION OF LIABILITY. IN NO EVENT SHALL VALVE OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE THE ENGINE AND/OR THE SDK, EVEN IF VALVE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 29 | 30 | 31 | If you would like to use the SDK for a commercial purpose, please contact Valve at sourceengine@valvesoftware.com. -------------------------------------------------------------------------------- /cl_dll/MOTD.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // 16 | // MOTD.cpp 17 | // 18 | // for displaying a server-sent message of the day 19 | // 20 | 21 | #include "hud.h" 22 | #include "util.h" 23 | #include "parsemsg.h" 24 | 25 | DECLARE_MESSAGE( m_MOTD, MOTD ); 26 | 27 | int CHudMOTD::MOTD_DISPLAY_TIME; 28 | 29 | int CHudMOTD :: Init( int player ) 30 | { 31 | gHUD.AddHudElem( this ); 32 | 33 | HOOK_MESSAGE( MOTD ); 34 | 35 | if (player == 0) 36 | { 37 | CVAR_CREATE("motd_display_time", "6", 0); 38 | } 39 | 40 | m_iFlags &= ~HUD_ACTIVE; // start out inactive 41 | m_szMOTD[0] = 0; 42 | 43 | return 1; 44 | } 45 | 46 | int CHudMOTD :: VidInit( int player ) 47 | { 48 | // Load sprites here 49 | 50 | return 1; 51 | } 52 | 53 | void CHudMOTD :: Reset( int player ) 54 | { 55 | m_iFlags &= ~HUD_ACTIVE; // start out inactive 56 | m_szMOTD[0] = 0; 57 | m_iLines = 0; 58 | m_flActiveTill = 0; 59 | } 60 | 61 | #define LINE_HEIGHT 13 62 | 63 | int CHudMOTD :: Draw( float fTime, int player ) 64 | { 65 | // Draw MOTD line-by-line 66 | 67 | if ( m_flActiveTill < gHUD.m_flTime ) 68 | { // finished with MOTD, disable it 69 | m_szMOTD[0] = 0; 70 | m_iLines = 0; 71 | m_iFlags &= ~HUD_ACTIVE; 72 | return 1; 73 | } 74 | 75 | // cap activetill time to the display time 76 | m_flActiveTill = min( gHUD.m_flTime + MOTD_DISPLAY_TIME, m_flActiveTill ); 77 | 78 | // find the top of where the MOTD should be drawn, so the whole thing is centered in the screen 79 | int ypos = max(((ScreenHeight - (m_iLines * LINE_HEIGHT)) / 2) - 40, 30 ); // shift it up slightly 80 | char *ch = m_szMOTD; 81 | while ( *ch ) 82 | { 83 | int line_length = 0; // count the length of the current line 84 | char* next_line = 0; 85 | for ( next_line = ch; *next_line != '\n' && *next_line != 0; next_line++ ) 86 | line_length += gHUD.m_scrinfo.charWidths[ *next_line ]; 87 | char *top = next_line; 88 | if ( *top == '\n' ) 89 | *top = 0; 90 | else 91 | top = NULL; 92 | 93 | // find where to start drawing the line 94 | int xpos = (ScreenWidth - line_length) / 2; 95 | 96 | gHUD.DrawHudString( xpos, ypos, ScreenWidth, ch, 255, 180, 0 ); 97 | 98 | ypos += LINE_HEIGHT; 99 | 100 | if ( top ) // restore 101 | *top = '\n'; 102 | ch = next_line; 103 | if ( *ch == '\n' ) 104 | ch++; 105 | 106 | if ( ypos > (ScreenHeight - 20) ) 107 | break; // don't let it draw too low 108 | } 109 | 110 | return 1; 111 | } 112 | 113 | int CHudMOTD :: MsgFunc_MOTD( int player, const char *pszName, int iSize, void *pbuf ) 114 | { 115 | if ( m_iFlags & HUD_ACTIVE ) 116 | { 117 | Reset(player); // clear the current MOTD in prep for this one 118 | } 119 | 120 | BEGIN_READ( pbuf, iSize ); 121 | 122 | int is_finished = READ_BYTE(); 123 | strcat( m_szMOTD, READ_STRING() ); 124 | 125 | if ( is_finished ) 126 | { 127 | m_iFlags |= HUD_ACTIVE; 128 | 129 | MOTD_DISPLAY_TIME = CVAR_GET_FLOAT( "motd_display_time" ); 130 | 131 | m_flActiveTill = gHUD.m_flTime + MOTD_DISPLAY_TIME; 132 | 133 | for ( char *sz = m_szMOTD; *sz != 0; sz++ ) // count the number of lines in the MOTD 134 | { 135 | if ( *sz == '\n' ) 136 | m_iLines++; 137 | } 138 | } 139 | 140 | return 1; 141 | } 142 | 143 | -------------------------------------------------------------------------------- /cl_dll/ammo.h: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | 16 | #ifndef __AMMO_H__ 17 | #define __AMMO_H__ 18 | 19 | #define MAX_WEAPON_NAME 128 20 | 21 | 22 | #define WEAPON_FLAGS_SELECTONEMPTY 1 23 | 24 | #define WEAPON_IS_ONTARGET 0x40 25 | 26 | struct WEAPON 27 | { 28 | char szName[MAX_WEAPON_NAME]; 29 | int iAmmoType; 30 | int iAmmo2Type; 31 | int iMax1; 32 | int iMax2; 33 | int iSlot; 34 | int iSlotPos; 35 | int iFlags; 36 | int iId; 37 | int iClip; 38 | 39 | int iCount; // # of itesm in plist 40 | 41 | HSPRITE hActive; 42 | wrect_t rcActive; 43 | HSPRITE hInactive; 44 | wrect_t rcInactive; 45 | HSPRITE hAmmo; 46 | wrect_t rcAmmo; 47 | HSPRITE hAmmo2; 48 | wrect_t rcAmmo2; 49 | HSPRITE hCrosshair; 50 | wrect_t rcCrosshair; 51 | HSPRITE hSCrosshair; 52 | wrect_t rcSCrosshair; 53 | HSPRITE hAutoaimOLD; 54 | wrect_t rcAutoaimOLD; 55 | HSPRITE hAutoaim; 56 | wrect_t rcAutoaim; 57 | HSPRITE hZoomedCrosshair; 58 | wrect_t rcZoomedCrosshair; 59 | HSPRITE hZoomedAutoaim; 60 | wrect_t rcZoomedAutoaim; 61 | }; 62 | 63 | typedef int AMMO; 64 | 65 | 66 | #endif -------------------------------------------------------------------------------- /cl_dll/ammo_secondary.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // 16 | // ammo_secondary.cpp 17 | // 18 | // implementation of CHudAmmoSecondary class 19 | // 20 | 21 | #include "hud.h" 22 | #include "util.h" 23 | #include "parsemsg.h" 24 | 25 | DECLARE_MESSAGE( m_AmmoSecondary, SecAmmoVal ); 26 | DECLARE_MESSAGE( m_AmmoSecondary, SecAmmoIcon ); 27 | 28 | int CHudAmmoSecondary :: Init( int player ) 29 | { 30 | HOOK_MESSAGE( SecAmmoVal ); 31 | HOOK_MESSAGE( SecAmmoIcon ); 32 | 33 | gHUD.AddHudElem(this); 34 | m_HUD_ammoicon = 0; 35 | 36 | for ( int i = 0; i < MAX_SEC_AMMO_VALUES; i++ ) 37 | m_iAmmoAmounts[i] = -1; // -1 means don't draw this value 38 | 39 | Reset(player); 40 | 41 | return 1; 42 | } 43 | 44 | void CHudAmmoSecondary :: Reset( int player ) 45 | { 46 | m_fFade = 0; 47 | } 48 | 49 | int CHudAmmoSecondary :: VidInit( int player ) 50 | { 51 | return 1; 52 | } 53 | 54 | int CHudAmmoSecondary :: Draw(float flTime, int player) 55 | { 56 | if ( (gHUD.m_iHideHUDDisplay & ( HIDEHUD_WEAPONS | HIDEHUD_ALL )) ) 57 | return 1; 58 | 59 | // draw secondary ammo icons above normal ammo readout 60 | int a, x, y, r, g, b, AmmoWidth; 61 | UnpackRGB( r, g, b, RGB_YELLOWISH ); 62 | a = (int) max( MIN_ALPHA, m_fFade ); 63 | if (m_fFade > 0) 64 | m_fFade -= (gHUD.m_flTimeDelta * 20); // slowly lower alpha to fade out icons 65 | ScaleColors( r, g, b, a ); 66 | 67 | AmmoWidth = gHUD.GetSpriteRect(gHUD.m_HUD_number_0).right - gHUD.GetSpriteRect(gHUD.m_HUD_number_0).left; 68 | 69 | y = ScreenHeight - (gHUD.m_iFontHeight*4); // this is one font height higher than the weapon ammo values 70 | x = ScreenWidth - AmmoWidth; 71 | 72 | if ( m_HUD_ammoicon ) 73 | { 74 | // Draw the ammo icon 75 | x -= (gHUD.GetSpriteRect(m_HUD_ammoicon).right - gHUD.GetSpriteRect(m_HUD_ammoicon).left); 76 | y -= (gHUD.GetSpriteRect(m_HUD_ammoicon).top - gHUD.GetSpriteRect(m_HUD_ammoicon).bottom); 77 | 78 | SPR_Set( gHUD.GetSprite(m_HUD_ammoicon), r, g, b ); 79 | SPR_DrawAdditive( 0, x, y, &gHUD.GetSpriteRect(m_HUD_ammoicon) ); 80 | } 81 | else 82 | { // move the cursor by the '0' char instead, since we don't have an icon to work with 83 | x -= AmmoWidth; 84 | y -= (gHUD.GetSpriteRect(gHUD.m_HUD_number_0).top - gHUD.GetSpriteRect(gHUD.m_HUD_number_0).bottom); 85 | } 86 | 87 | // draw the ammo counts, in reverse order, from right to left 88 | for ( int i = MAX_SEC_AMMO_VALUES-1; i >= 0; i-- ) 89 | { 90 | if ( m_iAmmoAmounts[i] < 0 ) 91 | continue; // negative ammo amounts imply that they shouldn't be drawn 92 | 93 | // half a char gap between the ammo number and the previous pic 94 | x -= (AmmoWidth / 2); 95 | 96 | // draw the number, right-aligned 97 | x -= (gHUD.GetNumWidth( m_iAmmoAmounts[i], DHN_DRAWZERO ) * AmmoWidth); 98 | gHUD.DrawHudNumber( x, y, DHN_DRAWZERO, m_iAmmoAmounts[i], r, g, b ); 99 | 100 | if ( i != 0 ) 101 | { 102 | // draw the divider bar 103 | x -= (AmmoWidth / 2); 104 | FillRGBA(x, y, (AmmoWidth/10), gHUD.m_iFontHeight, r, g, b, a); 105 | } 106 | } 107 | 108 | return 1; 109 | } 110 | 111 | // Message handler for Secondary Ammo Value 112 | // accepts one value: 113 | // string: sprite name 114 | int CHudAmmoSecondary :: MsgFunc_SecAmmoIcon( int player, const char *pszName, int iSize, void *pbuf ) 115 | { 116 | BEGIN_READ( pbuf, iSize ); 117 | m_HUD_ammoicon = gHUD.GetSpriteIndex( READ_STRING() ); 118 | 119 | return 1; 120 | } 121 | 122 | // Message handler for Secondary Ammo Icon 123 | // Sets an ammo value 124 | // takes two values: 125 | // byte: ammo index 126 | // byte: ammo value 127 | int CHudAmmoSecondary :: MsgFunc_SecAmmoVal( int player, const char *pszName, int iSize, void *pbuf ) 128 | { 129 | BEGIN_READ( pbuf, iSize ); 130 | 131 | int index = READ_BYTE(); 132 | if ( index < 0 || index >= MAX_SEC_AMMO_VALUES ) 133 | return 1; 134 | 135 | m_iAmmoAmounts[index] = READ_BYTE(); 136 | m_iFlags |= HUD_ACTIVE; 137 | 138 | // check to see if there is anything left to draw 139 | int count = 0; 140 | for ( int i = 0; i < MAX_SEC_AMMO_VALUES; i++ ) 141 | { 142 | count += max( 0, m_iAmmoAmounts[i] ); 143 | } 144 | 145 | if ( count == 0 ) 146 | { // the ammo fields are all empty, so turn off this hud area 147 | m_iFlags &= ~HUD_ACTIVE; 148 | return 1; 149 | } 150 | 151 | // make the icons light up 152 | m_fFade = 200.0f; 153 | 154 | return 1; 155 | } 156 | 157 | 158 | -------------------------------------------------------------------------------- /cl_dll/ammohistory.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // 16 | // ammohistory.cpp 17 | // 18 | 19 | 20 | #include "hud.h" 21 | #include "util.h" 22 | #include "parsemsg.h" 23 | 24 | #include "ammohistory.h" 25 | 26 | HistoryResource gHR; 27 | 28 | #define AMMO_PICKUP_GAP (gHR.iHistoryGap+5) 29 | #define AMMO_PICKUP_PICK_HEIGHT (32 + (gHR.iHistoryGap * 2)) 30 | #define AMMO_PICKUP_HEIGHT_MAX (ScreenHeight - 100) 31 | 32 | #define MAX_ITEM_NAME 32 33 | int HISTORY_DRAW_TIME = 5; 34 | 35 | // keep a list of items 36 | struct ITEM_INFO 37 | { 38 | char szName[MAX_ITEM_NAME]; 39 | HSPRITE spr; 40 | wrect_t rect; 41 | }; 42 | 43 | void HistoryResource :: AddToHistory( int iType, int iId, int iCount, int player ) 44 | { 45 | if ( iType == HISTSLOT_AMMO && !iCount ) 46 | return; // no amount, so don't add 47 | 48 | if ( (((AMMO_PICKUP_GAP * iCurrentHistorySlot) + AMMO_PICKUP_PICK_HEIGHT) > AMMO_PICKUP_HEIGHT_MAX) || (iCurrentHistorySlot >= MAX_HISTORY)) 49 | { // the pic would have to be drawn too high 50 | // so start from the bottom 51 | iCurrentHistorySlot = 0; 52 | } 53 | 54 | HIST_ITEM *freeslot = &rgAmmoHistory[iCurrentHistorySlot++][player]; // default to just writing to the first slot 55 | HISTORY_DRAW_TIME = CVAR_GET_FLOAT( "hud_drawhistory_time" ); 56 | 57 | freeslot->type = iType; 58 | freeslot->iId = iId; 59 | freeslot->iCount = iCount; 60 | freeslot->DisplayTime = gHUD.m_flTime + HISTORY_DRAW_TIME; 61 | } 62 | 63 | void HistoryResource :: AddToHistory( int iType, const char *szName, int iCount, int player) 64 | { 65 | if ( iType != HISTSLOT_ITEM ) 66 | return; 67 | 68 | if ( (((AMMO_PICKUP_GAP * iCurrentHistorySlot) + AMMO_PICKUP_PICK_HEIGHT) > AMMO_PICKUP_HEIGHT_MAX) || (iCurrentHistorySlot >= MAX_HISTORY) ) 69 | { // the pic would have to be drawn too high 70 | // so start from the bottom 71 | iCurrentHistorySlot = 0; 72 | } 73 | 74 | HIST_ITEM *freeslot = &rgAmmoHistory[iCurrentHistorySlot++][player]; // default to just writing to the first slot 75 | 76 | // I am really unhappy with all the code in this file 77 | 78 | int i = gHUD.GetSpriteIndex( szName ); 79 | if ( i == -1 ) 80 | return; // unknown sprite name, don't add it to history 81 | 82 | freeslot->iId = i; 83 | freeslot->type = iType; 84 | freeslot->iCount = iCount; 85 | 86 | HISTORY_DRAW_TIME = CVAR_GET_FLOAT( "hud_drawhistory_time" ); 87 | freeslot->DisplayTime = gHUD.m_flTime + HISTORY_DRAW_TIME; 88 | } 89 | 90 | 91 | void HistoryResource :: CheckClearHistory(int player) 92 | { 93 | for ( int i = 0; i < MAX_HISTORY; i++ ) 94 | { 95 | if ( rgAmmoHistory[i][player].type) 96 | return; 97 | } 98 | 99 | iCurrentHistorySlot = 0; 100 | } 101 | 102 | // 103 | // Draw Ammo pickup history 104 | // 105 | int HistoryResource :: DrawAmmoHistory( float flTime, int player ) 106 | { 107 | for ( int i = 0; i < MAX_HISTORY; i++ ) 108 | { 109 | if ( rgAmmoHistory[i][player].type) 110 | { 111 | rgAmmoHistory[i][player].DisplayTime = min(rgAmmoHistory[i][player].DisplayTime, gHUD.m_flTime + HISTORY_DRAW_TIME); 112 | 113 | if ( rgAmmoHistory[i][player].DisplayTime <= flTime) 114 | { // pic drawing time has expired 115 | memset( &rgAmmoHistory[i][player], 0, sizeof(HIST_ITEM)); 116 | CheckClearHistory(player); 117 | } 118 | else if ( rgAmmoHistory[i][player].type == HISTSLOT_AMMO) 119 | { 120 | wrect_t rcPic; 121 | HSPRITE *spr = gWR.GetAmmoPicFromWeapon( rgAmmoHistory[i][player].iId, rcPic, player); 122 | 123 | int r, g, b; 124 | UnpackRGB(r,g,b, RGB_YELLOWISH); 125 | float scale = (rgAmmoHistory[i][player].DisplayTime - flTime) * 80; 126 | ScaleColors(r, g, b, min(scale, 255) ); 127 | 128 | // Draw the pic 129 | int ypos = ScreenHeight - (AMMO_PICKUP_PICK_HEIGHT + (AMMO_PICKUP_GAP * i)); 130 | int xpos = ScreenWidth - 24; 131 | if ( spr && *spr ) // weapon isn't loaded yet so just don't draw the pic 132 | { // the dll has to make sure it has sent info the weapons you need 133 | SPR_Set( *spr, r, g, b ); 134 | SPR_DrawAdditive( 0, xpos, ypos, &rcPic ); 135 | } 136 | 137 | // Draw the number 138 | gHUD.DrawHudNumberString( xpos - 10, ypos, xpos - 100, rgAmmoHistory[i][player].iCount, r, g, b ); 139 | } 140 | else if ( rgAmmoHistory[i][player].type == HISTSLOT_WEAP) 141 | { 142 | WEAPON *weap = gWR.GetWeapon( rgAmmoHistory[i][player].iId, player); 143 | 144 | if ( !weap ) 145 | return 1; // we don't know about the weapon yet, so don't draw anything 146 | 147 | int r, g, b; 148 | UnpackRGB(r,g,b, RGB_YELLOWISH); 149 | 150 | if ( !gWR.HasAmmo( weap, player ) ) 151 | UnpackRGB(r,g,b, RGB_REDISH); // if the weapon doesn't have ammo, display it as red 152 | 153 | float scale = (rgAmmoHistory[i][player].DisplayTime - flTime) * 80; 154 | ScaleColors(r, g, b, min(scale, 255) ); 155 | 156 | int ypos = ScreenHeight - (AMMO_PICKUP_PICK_HEIGHT + (AMMO_PICKUP_GAP * i)); 157 | int xpos = ScreenWidth - (weap->rcInactive.right - weap->rcInactive.left); 158 | SPR_Set( weap->hInactive, r, g, b ); 159 | SPR_DrawAdditive( 0, xpos, ypos, &weap->rcInactive ); 160 | } 161 | else if ( rgAmmoHistory[i][player].type == HISTSLOT_ITEM ) 162 | { 163 | int r, g, b; 164 | 165 | if ( !rgAmmoHistory[i][player].iId ) 166 | continue; // sprite not loaded 167 | 168 | wrect_t rect = gHUD.GetSpriteRect( rgAmmoHistory[i][player].iId ); 169 | 170 | UnpackRGB(r,g,b, RGB_YELLOWISH); 171 | float scale = (rgAmmoHistory[i][player].DisplayTime - flTime) * 80; 172 | ScaleColors(r, g, b, min(scale, 255) ); 173 | 174 | int ypos = ScreenHeight - (AMMO_PICKUP_PICK_HEIGHT + (AMMO_PICKUP_GAP * i)); 175 | int xpos = ScreenWidth - (rect.right - rect.left) - 10; 176 | 177 | SPR_Set( gHUD.GetSprite( rgAmmoHistory[i][player].iId ), r, g, b ); 178 | SPR_DrawAdditive( 0, xpos, ypos, &rect ); 179 | } 180 | } 181 | } 182 | 183 | 184 | return 1; 185 | } 186 | 187 | 188 | -------------------------------------------------------------------------------- /cl_dll/ammohistory.h: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // 16 | // ammohistory.h 17 | // 18 | 19 | // this is the max number of items in each bucket 20 | #define MAX_WEAPON_POSITIONS MAX_WEAPON_SLOTS 21 | 22 | class WeaponsResource 23 | { 24 | private: 25 | // Information about weapons & ammo 26 | WEAPON rgWeapons[MAX_WEAPONS][2]; // Weapons Array 27 | 28 | // counts of weapons * ammo 29 | WEAPON* rgSlots[MAX_WEAPON_SLOTS+1][MAX_WEAPON_POSITIONS+1][2]; // The slots currently in use by weapons. The value is a pointer to the weapon; if it's NULL, no weapon is there 30 | int riAmmo[MAX_AMMO_TYPES][2]; // count of each ammo type 31 | 32 | public: 33 | void Init( int player ) 34 | { 35 | memset( rgWeapons, 0, sizeof rgWeapons); 36 | Reset(player); 37 | } 38 | 39 | void Reset(int player) 40 | { 41 | iOldWeaponBits[player] = 0; 42 | memset( rgSlots, 0, sizeof rgSlots ); 43 | memset( riAmmo, 0, sizeof riAmmo ); 44 | } 45 | 46 | ///// WEAPON ///// 47 | int iOldWeaponBits[2]; 48 | 49 | WEAPON *GetWeapon( int iId, int player ) { return &rgWeapons[iId][player]; } 50 | void AddWeapon( WEAPON *wp, int player) 51 | { 52 | rgWeapons[ wp->iId ][player] = *wp; 53 | LoadWeaponSprites( &rgWeapons[ wp->iId ][player]); 54 | } 55 | 56 | void PickupWeapon( WEAPON *wp, int player) 57 | { 58 | rgSlots[ wp->iSlot ][ wp->iSlotPos ][ player ] = wp; 59 | } 60 | 61 | void DropWeapon( WEAPON *wp, int player) 62 | { 63 | rgSlots[ wp->iSlot ][ wp->iSlotPos ][ player ] = NULL; 64 | } 65 | 66 | void DropAllWeapons(int player) 67 | { 68 | for ( int i = 0; i < MAX_WEAPONS; i++ ) 69 | { 70 | if ( rgWeapons[i][player].iId) 71 | DropWeapon( &rgWeapons[i][player], player); 72 | } 73 | } 74 | 75 | WEAPON* GetWeaponSlot( int slot, int pos, int player) { return rgSlots[slot][pos][player]; } 76 | 77 | void LoadWeaponSprites( WEAPON* wp ); 78 | void LoadAllWeaponSprites( int player ); 79 | WEAPON* GetFirstPos( int iSlot, int player ); 80 | void SelectSlot( int iSlot, int fAdvance, int iDirection, int player ); 81 | WEAPON* GetNextActivePos( int iSlot, int iSlotPos, int player); 82 | 83 | int HasAmmo( WEAPON *p, int player ); 84 | 85 | ///// AMMO ///// 86 | AMMO GetAmmo( int iId ) { return iId; } 87 | 88 | void SetAmmo( int iId, int iCount, int player) { riAmmo[ iId ][ player ] = iCount; } 89 | 90 | int CountAmmo( int iId, int player); 91 | 92 | HSPRITE* GetAmmoPicFromWeapon( int iAmmoId, wrect_t& rect, int player ); 93 | 94 | }; 95 | 96 | extern WeaponsResource gWR; 97 | 98 | 99 | #define MAX_HISTORY 12 100 | enum { 101 | HISTSLOT_EMPTY, 102 | HISTSLOT_AMMO, 103 | HISTSLOT_WEAP, 104 | HISTSLOT_ITEM, 105 | }; 106 | 107 | class HistoryResource 108 | { 109 | private: 110 | struct HIST_ITEM { 111 | int type; 112 | float DisplayTime; // the time at which this item should be removed from the history 113 | int iCount; 114 | int iId; 115 | }; 116 | 117 | HIST_ITEM rgAmmoHistory[MAX_HISTORY][2]; 118 | 119 | public: 120 | 121 | void Init( int player ) 122 | { 123 | Reset(player); 124 | } 125 | 126 | void Reset( int player ) 127 | { 128 | memset( rgAmmoHistory, 0, sizeof rgAmmoHistory); 129 | } 130 | 131 | int iHistoryGap; 132 | int iCurrentHistorySlot; 133 | 134 | void AddToHistory( int iType, int iId, int iCount, int player ); 135 | void AddToHistory( int iType, const char *szName, int iCount, int player ); 136 | 137 | void CheckClearHistory( int player ); 138 | int DrawAmmoHistory( float flTime, int player ); 139 | }; 140 | 141 | extern HistoryResource gHR; 142 | 143 | 144 | 145 | -------------------------------------------------------------------------------- /cl_dll/battery.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // 16 | // battery.cpp 17 | // 18 | // implementation of CHudBattery class 19 | // 20 | 21 | #include "hud.h" 22 | #include "util.h" 23 | #include "parsemsg.h" 24 | 25 | DECLARE_MESSAGE(m_Battery, Battery) 26 | 27 | int CHudBattery::Init(int player) 28 | { 29 | m_iBat = 0; 30 | m_fFade = 0; 31 | m_iFlags = 0; 32 | 33 | HOOK_MESSAGE(Battery); 34 | 35 | gHUD.AddHudElem(this); 36 | 37 | return 1; 38 | }; 39 | 40 | 41 | int CHudBattery::VidInit(int player) 42 | { 43 | int HUD_suit_empty = gHUD.GetSpriteIndex( "suit_empty" ); 44 | int HUD_suit_full = gHUD.GetSpriteIndex( "suit_full" ); 45 | 46 | m_hSprite1 = m_hSprite2 = 0; // delaying get sprite handles until we know the sprites are loaded 47 | m_prc1 = &gHUD.GetSpriteRect( HUD_suit_empty ); 48 | m_prc2 = &gHUD.GetSpriteRect( HUD_suit_full ); 49 | m_iHeight = m_prc2->bottom - m_prc1->top; 50 | m_fFade = 0; 51 | return 1; 52 | }; 53 | 54 | int CHudBattery:: MsgFunc_Battery(int player, const char *pszName, int iSize, void *pbuf ) 55 | { 56 | m_iFlags |= HUD_ACTIVE; 57 | 58 | 59 | BEGIN_READ( pbuf, iSize ); 60 | int x = READ_SHORT(); 61 | 62 | if (x != m_iBat) 63 | { 64 | m_fFade = FADE_TIME; 65 | m_iBat = x; 66 | } 67 | 68 | return 1; 69 | } 70 | 71 | 72 | int CHudBattery::Draw(float flTime, int player) 73 | { 74 | if ( gHUD.m_iHideHUDDisplay & HIDEHUD_HEALTH ) 75 | return 1; 76 | 77 | int r, g, b, x, y, a; 78 | wrect_t rc; 79 | 80 | rc = *m_prc2; 81 | rc.top += m_iHeight * ((float)(100-(min(100,m_iBat))) * 0.01); // battery can go from 0 to 100 so * 0.01 goes from 0 to 1 82 | 83 | UnpackRGB(r,g,b, RGB_YELLOWISH); 84 | 85 | if (!(gHUD.m_iWeaponBits[player] & (1<<(WEAPON_SUIT)) )) 86 | return 1; 87 | 88 | // Has health changed? Flash the health # 89 | if (m_fFade) 90 | { 91 | if (m_fFade > FADE_TIME) 92 | m_fFade = FADE_TIME; 93 | 94 | m_fFade -= (gHUD.m_flTimeDelta * 20); 95 | if (m_fFade <= 0) 96 | { 97 | a = 128; 98 | m_fFade = 0; 99 | } 100 | 101 | // Fade the health number back to dim 102 | 103 | a = MIN_ALPHA + (m_fFade/FADE_TIME) * 128; 104 | 105 | } 106 | else 107 | a = MIN_ALPHA; 108 | 109 | ScaleColors(r, g, b, a ); 110 | 111 | int iOffset = (m_prc1->bottom - m_prc1->top)/6; 112 | 113 | y = ScreenHeight - gHUD.m_iFontHeight - gHUD.m_iFontHeight / 2; 114 | x = ScreenWidth/5; 115 | 116 | // make sure we have the right sprite handles 117 | if ( !m_hSprite1 ) 118 | m_hSprite1 = gHUD.GetSprite( gHUD.GetSpriteIndex( "suit_empty" ) ); 119 | if ( !m_hSprite2 ) 120 | m_hSprite2 = gHUD.GetSprite( gHUD.GetSpriteIndex( "suit_full" ) ); 121 | 122 | SPR_Set(m_hSprite1, r, g, b ); 123 | SPR_DrawAdditive( 0, x, y - iOffset, m_prc1); 124 | 125 | if (rc.bottom > rc.top) 126 | { 127 | SPR_Set(m_hSprite2, r, g, b ); 128 | SPR_DrawAdditive( 0, x, y - iOffset + (rc.top - m_prc2->top), &rc); 129 | } 130 | 131 | x += (m_prc1->right - m_prc1->left); 132 | x = gHUD.DrawHudNumber(x, y, DHN_3DIGITS | DHN_DRAWZERO, m_iBat, r, g, b); 133 | 134 | return 1; 135 | } -------------------------------------------------------------------------------- /cl_dll/cdll_int.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // 16 | // cdll_int.c 17 | // 18 | // this implementation handles the linking of the engine to the DLL 19 | // 20 | 21 | #include "hud.h" 22 | #include "util.h" 23 | 24 | // PS2 client doesn't have any exports because of static linking - ScriptedSnark 25 | #define DLLEXPORT 26 | //#define DLLEXPORT __declspec( dllexport ) 27 | 28 | cl_enginefunc_t gEngfuncs; 29 | CHud gHUD; 30 | 31 | /* 32 | ========================== 33 | Initialize 34 | 35 | Called when the DLL is first loaded. 36 | ========================== 37 | */ 38 | extern "C" 39 | { 40 | int DLLEXPORT Initialize( cl_enginefunc_t *pEnginefuncs, int iVersion ); 41 | int DLLEXPORT HUD_VidInit( int player ); 42 | int DLLEXPORT HUD_Init( int player ); 43 | int DLLEXPORT HUD_Redraw( float flTime, int intermission, int player ); 44 | int DLLEXPORT HUD_UpdateClientData( client_data_t *cdata, int player ); 45 | } 46 | 47 | 48 | int DLLEXPORT Initialize( cl_enginefunc_t *pEnginefuncs, int iVersion ) 49 | { 50 | gEngfuncs = *pEnginefuncs; 51 | 52 | //!!! mwh UNDONE We need to think about our versioning strategy. Do we want to try to be compatible 53 | // with previous versions, especially when we're only 'bonus' functionality? Should it be the engine 54 | // that decides if the DLL is compliant? 55 | 56 | if (iVersion != CLDLL_INTERFACE_VERSION) 57 | return 0; 58 | 59 | Q_memcpy(&gEngfuncs, pEnginefuncs, sizeof(cl_enginefunc_t)); 60 | 61 | return 1; 62 | } 63 | 64 | 65 | /* 66 | ========================== 67 | HUD_VidInit 68 | 69 | Called when the game initializes 70 | and whenever the vid_mode is changed 71 | so the HUD can reinitialize itself. 72 | ========================== 73 | */ 74 | 75 | int DLLEXPORT HUD_VidInit( int player ) 76 | { 77 | gHUD.VidInit(player); 78 | return 1; 79 | } 80 | 81 | /* 82 | ========================== 83 | HUD_Init 84 | 85 | Called whenever the client connects 86 | to a server. Reinitializes all 87 | the hud variables. 88 | ========================== 89 | */ 90 | 91 | int DLLEXPORT HUD_Init( int player ) 92 | { 93 | //gEngfuncs.pfnClientCmd(";bind v \"toggleconsole\";\n"); 94 | gHUD.Init(player); 95 | return 1; 96 | } 97 | 98 | 99 | /* 100 | ========================== 101 | HUD_Redraw 102 | 103 | called every screen frame to 104 | redraw the HUD. 105 | =========================== 106 | */ 107 | 108 | int DLLEXPORT HUD_Redraw( float time, int intermission, int player ) 109 | { 110 | gHUD.Redraw( time, intermission, player ); 111 | 112 | return 1; 113 | } 114 | 115 | 116 | /* 117 | ========================== 118 | HUD_UpdateClientData 119 | 120 | called every time shared client 121 | dll/engine data gets changed, 122 | and gives the cdll a chance 123 | to modify the data. 124 | 125 | returns 1 if anything has been changed, 0 otherwise. 126 | ========================== 127 | */ 128 | 129 | int DLLEXPORT HUD_UpdateClientData(client_data_t *pcldata, int player) 130 | { 131 | return gHUD.UpdateClientData(pcldata, player); 132 | } -------------------------------------------------------------------------------- /cl_dll/cl_dll.h: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // 16 | // cl_dll.h 17 | // 18 | 19 | // 4-23-98 JOHN 20 | 21 | // 22 | // This DLL is linked by the client when they first initialize. 23 | // This DLL is responsible for the following tasks: 24 | // - Loading the HUD graphics upon initialization 25 | // - Drawing the HUD graphics every frame 26 | // - Handling the custum HUD-update packets 27 | // 28 | typedef unsigned char byte; 29 | typedef unsigned short word; 30 | typedef float vec_t; 31 | typedef int (*pfnUserMsgHook)(int player, const char *pszName, int iSize, void *pbuf); 32 | 33 | #include "util_vector.h" 34 | #define EXPORT 35 | //#define EXPORT _declspec( dllexport ) 36 | 37 | #include "cdll_int.h" 38 | #include "cdll_dll.h" 39 | 40 | extern cl_enginefunc_t gEngfuncs; 41 | -------------------------------------------------------------------------------- /cl_dll/death.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // 16 | // death notice 17 | // 18 | #include "hud.h" 19 | #include "util.h" 20 | #include "parsemsg.h" 21 | 22 | DECLARE_MESSAGE( m_DeathNotice, DeathMsg ); 23 | 24 | struct DeathNoticeItem { 25 | char szKiller[MAX_PLAYER_NAME_LENGTH]; 26 | char szVictim[MAX_PLAYER_NAME_LENGTH]; 27 | int iId; // the index number of the associated sprite 28 | int iSuicide; 29 | int iTeamKill; 30 | float flDisplayTime; 31 | }; 32 | 33 | #define MAX_DEATHNOTICES 4 34 | static int DEATHNOTICE_DISPLAY_TIME = 6; 35 | 36 | #define DEATHNOTICE_TOP 20 37 | 38 | DeathNoticeItem rgDeathNoticeList[ MAX_DEATHNOTICES + 1 ]; 39 | 40 | 41 | int CHudDeathNotice :: Init( int player ) 42 | { 43 | gHUD.AddHudElem( this ); 44 | 45 | HOOK_MESSAGE( DeathMsg ); 46 | 47 | if (player == 0) 48 | { 49 | CVAR_CREATE("hud_deathnotice_time", "6", 0); 50 | } 51 | return 1; 52 | } 53 | 54 | 55 | void CHudDeathNotice :: InitHUDData( int player ) 56 | { 57 | memset( rgDeathNoticeList, 0, sizeof(rgDeathNoticeList) ); 58 | } 59 | 60 | 61 | int CHudDeathNotice :: VidInit( int player ) 62 | { 63 | m_HUD_d_skull = gHUD.GetSpriteIndex( "d_skull" ); 64 | 65 | return 1; 66 | } 67 | 68 | int CHudDeathNotice :: Draw( float flTime, int player ) 69 | { 70 | int x, y, r, g, b; 71 | 72 | for ( int i = 0; i < MAX_DEATHNOTICES; i++ ) 73 | { 74 | if ( rgDeathNoticeList[i].iId == 0 ) 75 | break; // we've gone through them all 76 | 77 | if ( rgDeathNoticeList[i].flDisplayTime < flTime ) 78 | { // display time has expired 79 | // remove the current item from the list 80 | memmove( &rgDeathNoticeList[i], &rgDeathNoticeList[i+1], sizeof(DeathNoticeItem) * (MAX_DEATHNOTICES - i) ); 81 | i--; // continue on the next item; stop the counter getting incremented 82 | continue; 83 | } 84 | 85 | rgDeathNoticeList[i].flDisplayTime = min( rgDeathNoticeList[i].flDisplayTime, gHUD.m_flTime + DEATHNOTICE_DISPLAY_TIME ); 86 | 87 | // Draw the death notice 88 | 89 | y = DEATHNOTICE_TOP + (20 * i); //!!! 90 | 91 | int id = (rgDeathNoticeList[i].iId == -1) ? m_HUD_d_skull : rgDeathNoticeList[i].iId; 92 | x = ScreenWidth - ConsoleStringLen(rgDeathNoticeList[i].szVictim) - (gHUD.GetSpriteRect(id).right - gHUD.GetSpriteRect(id).left); 93 | 94 | if ( !rgDeathNoticeList[i].iSuicide ) 95 | { 96 | x -= (5 + ConsoleStringLen( rgDeathNoticeList[i].szKiller ) ); 97 | 98 | // Draw killers name 99 | x = 5 + DrawConsoleString( x, y, rgDeathNoticeList[i].szKiller ); 100 | } 101 | 102 | r = 255; g = 80; b = 0; 103 | if ( rgDeathNoticeList[i].iTeamKill ) 104 | { 105 | r = 10; g = 240; b = 10; // display it in sickly green 106 | } 107 | 108 | // Draw death weapon 109 | SPR_Set( gHUD.GetSprite(id), r, g, b ); 110 | SPR_DrawAdditive( 0, x, y, &gHUD.GetSpriteRect(id) ); 111 | 112 | x += (gHUD.GetSpriteRect(id).right - gHUD.GetSpriteRect(id).left); 113 | 114 | // Draw victims name 115 | x = DrawConsoleString( x, y, rgDeathNoticeList[i].szVictim ); 116 | } 117 | 118 | return 1; 119 | } 120 | 121 | // This message handler may be better off elsewhere 122 | int CHudDeathNotice :: MsgFunc_DeathMsg( int player, const char *pszName, int iSize, void *pbuf ) 123 | { 124 | m_iFlags |= HUD_ACTIVE; 125 | 126 | BEGIN_READ( pbuf, iSize ); 127 | 128 | int killer = READ_BYTE(); 129 | int victim = READ_BYTE(); 130 | 131 | char killedwith[32]; 132 | Q_strcpy( killedwith, "d_" ); 133 | strncat( killedwith, READ_STRING(), 32 ); 134 | 135 | gHUD.m_Scoreboard.DeathMsg( killer, victim ); 136 | 137 | int i = 0; 138 | for ( i = 0; i < MAX_DEATHNOTICES; i++ ) 139 | { 140 | if ( rgDeathNoticeList[i].iId == 0 ) 141 | break; 142 | } 143 | if ( i == MAX_DEATHNOTICES ) 144 | { // move the rest of the list forward to make room for this item 145 | memmove( rgDeathNoticeList, rgDeathNoticeList+1, sizeof(DeathNoticeItem) * MAX_DEATHNOTICES ); 146 | i = MAX_DEATHNOTICES - 1; 147 | } 148 | 149 | gHUD.m_Scoreboard.GetAllPlayersInfo(); 150 | 151 | char *killer_name = gHUD.m_Scoreboard.m_PlayerInfoList[ killer ].name; 152 | char *victim_name = gHUD.m_Scoreboard.m_PlayerInfoList[ victim ].name; 153 | if ( !killer_name ) 154 | killer_name = ""; 155 | if ( !victim_name ) 156 | victim_name = ""; 157 | 158 | strncpy( rgDeathNoticeList[i].szKiller, killer_name, MAX_PLAYER_NAME_LENGTH ); 159 | strncpy( rgDeathNoticeList[i].szVictim, victim_name, MAX_PLAYER_NAME_LENGTH ); 160 | 161 | if ( killer == victim || killer == 0 ) 162 | rgDeathNoticeList[i].iSuicide = TRUE; 163 | 164 | if ( !strcmp( killedwith, "d_teammate" ) ) 165 | rgDeathNoticeList[i].iTeamKill = TRUE; 166 | 167 | // Find the sprite in the list 168 | int spr = gHUD.GetSpriteIndex( killedwith ); 169 | 170 | rgDeathNoticeList[i].iId = spr; 171 | 172 | DEATHNOTICE_DISPLAY_TIME = CVAR_GET_FLOAT( "hud_deathnotice_time" ); 173 | rgDeathNoticeList[i].flDisplayTime = gHUD.m_flTime + DEATHNOTICE_DISPLAY_TIME; 174 | 175 | // record the death notice in the console 176 | if ( rgDeathNoticeList[i].iSuicide ) 177 | { 178 | ConsolePrint( rgDeathNoticeList[i].szVictim ); 179 | 180 | if ( !strcmp( killedwith, "d_world" ) ) 181 | { 182 | ConsolePrint( " died" ); 183 | } 184 | else 185 | { 186 | ConsolePrint( " killed self" ); 187 | } 188 | } 189 | else if ( rgDeathNoticeList[i].iTeamKill ) 190 | { 191 | ConsolePrint( rgDeathNoticeList[i].szKiller ); 192 | ConsolePrint( " killed his teammate " ); 193 | ConsolePrint( rgDeathNoticeList[i].szVictim ); 194 | } 195 | else 196 | { 197 | ConsolePrint( rgDeathNoticeList[i].szKiller ); 198 | ConsolePrint( " killed " ); 199 | ConsolePrint( rgDeathNoticeList[i].szVictim ); 200 | } 201 | 202 | if ( killedwith && *killedwith && (*killedwith > 13 ) && strcmp( killedwith, "d_world" ) && !rgDeathNoticeList[i].iTeamKill ) 203 | { 204 | ConsolePrint( " with " ); 205 | 206 | // replace the code names with the 'real' names 207 | if ( !strcmp( killedwith+2, "egon" ) ) 208 | Q_strcpy( killedwith, "d_gluon gun" ); 209 | if ( !strcmp( killedwith+2, "gauss" ) ) 210 | Q_strcpy( killedwith, "d_tau cannon" ); 211 | 212 | ConsolePrint( killedwith+2 ); // skip over the "d_" part 213 | } 214 | 215 | ConsolePrint( "\n" ); 216 | 217 | return 1; 218 | } 219 | 220 | 221 | 222 | 223 | -------------------------------------------------------------------------------- /cl_dll/flashlight.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // 16 | // flashlight.cpp 17 | // 18 | // implementation of CHudFlashlight class 19 | // 20 | 21 | #include "hud.h" 22 | #include "util.h" 23 | #include "parsemsg.h" 24 | 25 | 26 | 27 | DECLARE_MESSAGE(m_Flash, FlashBat) 28 | DECLARE_MESSAGE(m_Flash, Flashlight) 29 | 30 | #define BAT_NAME "sprites/%d_Flashlight.spz" 31 | 32 | int CHudFlashlight::Init(int player) 33 | { 34 | m_fFade = 0; 35 | m_fOn = 0; 36 | 37 | HOOK_MESSAGE(Flashlight); 38 | HOOK_MESSAGE(FlashBat); 39 | 40 | m_iFlags |= HUD_ACTIVE; 41 | 42 | gHUD.AddHudElem(this); 43 | 44 | return 1; 45 | }; 46 | 47 | void CHudFlashlight::Reset(int player) 48 | { 49 | m_fFade = 0; 50 | m_fOn = 0; 51 | } 52 | 53 | int CHudFlashlight::VidInit(int player) 54 | { 55 | int HUD_flash_empty = gHUD.GetSpriteIndex( "flash_empty" ); 56 | int HUD_flash_full = gHUD.GetSpriteIndex( "flash_full" ); 57 | int HUD_flash_beam = gHUD.GetSpriteIndex( "flash_beam" ); 58 | 59 | m_hSprite1 = gHUD.GetSprite(HUD_flash_empty); 60 | m_hSprite2 = gHUD.GetSprite(HUD_flash_full); 61 | m_hBeam = gHUD.GetSprite(HUD_flash_beam); 62 | m_prc1 = &gHUD.GetSpriteRect(HUD_flash_empty); 63 | m_prc2 = &gHUD.GetSpriteRect(HUD_flash_full); 64 | m_prcBeam = &gHUD.GetSpriteRect(HUD_flash_beam); 65 | m_iWidth = m_prc2->right - m_prc2->left; 66 | 67 | return 1; 68 | }; 69 | 70 | int CHudFlashlight:: MsgFunc_FlashBat(int player, const char *pszName, int iSize, void *pbuf ) 71 | { 72 | 73 | 74 | BEGIN_READ( pbuf, iSize ); 75 | int x = READ_BYTE(); 76 | m_iBat = x; 77 | m_flBat = ((float)x)/100.0; 78 | 79 | return 1; 80 | } 81 | 82 | int CHudFlashlight:: MsgFunc_Flashlight(int player, const char *pszName, int iSize, void *pbuf ) 83 | { 84 | 85 | BEGIN_READ( pbuf, iSize ); 86 | m_fOn = READ_BYTE(); 87 | int x = READ_BYTE(); 88 | m_iBat = x; 89 | m_flBat = ((float)x)/100.0; 90 | 91 | return 1; 92 | } 93 | 94 | int CHudFlashlight::Draw(float flTime, int player) 95 | { 96 | if ( gHUD.m_iHideHUDDisplay & ( HIDEHUD_FLASHLIGHT | HIDEHUD_ALL ) ) 97 | return 1; 98 | 99 | int r, g, b, x, y, a; 100 | wrect_t rc; 101 | 102 | if (!(gHUD.m_iWeaponBits[player] & (1<<(WEAPON_SUIT)) )) 103 | return 1; 104 | 105 | if (m_fOn) 106 | a = 225; 107 | else 108 | a = MIN_ALPHA; 109 | 110 | if (m_flBat < 0.20) 111 | UnpackRGB(r,g,b, RGB_REDISH); 112 | else 113 | UnpackRGB(r,g,b, RGB_YELLOWISH); 114 | 115 | ScaleColors(r, g, b, a); 116 | 117 | y = (m_prc1->bottom - m_prc2->top)/2; 118 | x = ScreenWidth - m_iWidth - m_iWidth/2 ; 119 | 120 | // Draw the flashlight casing 121 | SPR_Set(m_hSprite1, r, g, b ); 122 | SPR_DrawAdditive( 0, x, y, m_prc1); 123 | 124 | if ( m_fOn ) 125 | { // draw the flashlight beam 126 | x = ScreenWidth - m_iWidth/2; 127 | 128 | SPR_Set( m_hBeam, r, g, b ); 129 | SPR_DrawAdditive( 0, x, y, m_prcBeam ); 130 | } 131 | 132 | // draw the flashlight energy level 133 | x = ScreenWidth - m_iWidth - m_iWidth/2 ; 134 | int iOffset = m_iWidth * (1.0 - m_flBat); 135 | if (iOffset < m_iWidth) 136 | { 137 | rc = *m_prc2; 138 | rc.left += iOffset; 139 | 140 | SPR_Set(m_hSprite2, r, g, b ); 141 | SPR_DrawAdditive( 0, x + iOffset, y, &rc); 142 | } 143 | 144 | 145 | return 1; 146 | } -------------------------------------------------------------------------------- /cl_dll/geiger.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // 16 | // Geiger.cpp 17 | // 18 | // implementation of CHudAmmo class 19 | // 20 | 21 | #include "hud.h" 22 | #include "util.h" 23 | 24 | #include "parsemsg.h" 25 | 26 | DECLARE_MESSAGE(m_Geiger, Geiger ) 27 | 28 | int CHudGeiger::Init(int player) 29 | { 30 | HOOK_MESSAGE( Geiger ); 31 | 32 | m_iGeigerRange = 0; 33 | m_iFlags = 0; 34 | 35 | gHUD.AddHudElem(this); 36 | 37 | return 1; 38 | }; 39 | 40 | int CHudGeiger::VidInit(int player) 41 | { 42 | return 1; 43 | }; 44 | 45 | int CHudGeiger::MsgFunc_Geiger(int player, const char *pszName, int iSize, void *pbuf) 46 | { 47 | 48 | BEGIN_READ( pbuf, iSize ); 49 | 50 | // update geiger data 51 | m_iGeigerRange = READ_BYTE(); 52 | m_iGeigerRange = m_iGeigerRange << 2; 53 | 54 | m_iFlags |= HUD_ACTIVE; 55 | 56 | return 1; 57 | } 58 | 59 | int CHudGeiger::Draw (float flTime, int player) 60 | { 61 | int pct; 62 | float flvol; 63 | int rg[3]; 64 | int i; 65 | 66 | if (m_iGeigerRange < 1000 && m_iGeigerRange > 0) 67 | { 68 | // peicewise linear is better than continuous formula for this 69 | if (m_iGeigerRange > 800) 70 | { 71 | pct = 0; //Con_Printf ( "range > 800\n"); 72 | } 73 | else if (m_iGeigerRange > 600) 74 | { 75 | pct = 2; 76 | flvol = 0.4; //Con_Printf ( "range > 600\n"); 77 | rg[0] = 1; 78 | rg[1] = 1; 79 | i = 2; 80 | } 81 | else if (m_iGeigerRange > 500) 82 | { 83 | pct = 4; 84 | flvol = 0.5; //Con_Printf ( "range > 500\n"); 85 | rg[0] = 1; 86 | rg[1] = 2; 87 | i = 2; 88 | } 89 | else if (m_iGeigerRange > 400) 90 | { 91 | pct = 8; 92 | flvol = 0.6; //Con_Printf ( "range > 400\n"); 93 | rg[0] = 1; 94 | rg[1] = 2; 95 | rg[2] = 3; 96 | i = 3; 97 | } 98 | else if (m_iGeigerRange > 300) 99 | { 100 | pct = 8; 101 | flvol = 0.7; //Con_Printf ( "range > 300\n"); 102 | rg[0] = 2; 103 | rg[1] = 3; 104 | rg[2] = 4; 105 | i = 3; 106 | } 107 | else if (m_iGeigerRange > 200) 108 | { 109 | pct = 28; 110 | flvol = 0.78; //Con_Printf ( "range > 200\n"); 111 | rg[0] = 2; 112 | rg[1] = 3; 113 | rg[2] = 4; 114 | i = 3; 115 | } 116 | else if (m_iGeigerRange > 150) 117 | { 118 | pct = 40; 119 | flvol = 0.80; //Con_Printf ( "range > 150\n"); 120 | rg[0] = 3; 121 | rg[1] = 4; 122 | rg[2] = 5; 123 | i = 3; 124 | } 125 | else if (m_iGeigerRange > 100) 126 | { 127 | pct = 60; 128 | flvol = 0.85; //Con_Printf ( "range > 100\n"); 129 | rg[0] = 3; 130 | rg[1] = 4; 131 | rg[2] = 5; 132 | i = 3; 133 | } 134 | else if (m_iGeigerRange > 75) 135 | { 136 | pct = 80; 137 | flvol = 0.9; //Con_Printf ( "range > 75\n"); 138 | //gflGeigerDelay = cl.time + GEIGERDELAY * 0.75; 139 | rg[0] = 4; 140 | rg[1] = 5; 141 | rg[2] = 6; 142 | i = 3; 143 | } 144 | else if (m_iGeigerRange > 50) 145 | { 146 | pct = 90; 147 | flvol = 0.95; //Con_Printf ( "range > 50\n"); 148 | rg[0] = 5; 149 | rg[1] = 6; 150 | i = 2; 151 | } 152 | else 153 | { 154 | pct = 95; 155 | flvol = 1.0; //Con_Printf ( "range < 50\n"); 156 | rg[0] = 5; 157 | rg[1] = 6; 158 | i = 2; 159 | } 160 | 161 | flvol = (flvol * ((Sys_rand() & 127)) / 255) + 0.25; // UTIL_RandomFloat(0.25, 0.5); 162 | 163 | if ((Sys_rand() & 127) < pct || (Sys_rand() & 127) < pct) 164 | { 165 | //S_StartDynamicSound (-1, 0, rgsfx[Sys_rand() % i], r_origin, flvol, 1.0, 0, 100); 166 | char sz[256]; 167 | 168 | int j = Sys_rand() & 1; 169 | if (i > 2) 170 | j += Sys_rand() & 1; 171 | 172 | Sys_sprintf(sz, "player/geiger%d.wav", j + 1); 173 | PlaySound(sz, player); 174 | 175 | } 176 | } 177 | 178 | return 1; 179 | } 180 | -------------------------------------------------------------------------------- /cl_dll/health.h: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | 16 | #define DMG_IMAGE_LIFE 2 // seconds that image is up 17 | 18 | #define DMG_IMAGE_POISON 0 19 | #define DMG_IMAGE_ACID 1 20 | #define DMG_IMAGE_COLD 2 21 | #define DMG_IMAGE_DROWN 3 22 | #define DMG_IMAGE_BURN 4 23 | #define DMG_IMAGE_NERVE 5 24 | #define DMG_IMAGE_RAD 6 25 | #define DMG_IMAGE_SHOCK 7 26 | //tf defines 27 | #define DMG_IMAGE_CALTROP 8 28 | #define DMG_IMAGE_TRANQ 9 29 | #define DMG_IMAGE_CONCUSS 10 30 | #define DMG_IMAGE_HALLUC 11 31 | #define NUM_DMG_TYPES 12 32 | // instant damage 33 | 34 | #define DMG_GENERIC 0 // generic damage was done 35 | #define DMG_CRUSH (1 << 0) // crushed by falling or moving object 36 | #define DMG_BULLET (1 << 1) // shot 37 | #define DMG_SLASH (1 << 2) // cut, clawed, stabbed 38 | #define DMG_BURN (1 << 3) // heat burned 39 | #define DMG_FREEZE (1 << 4) // frozen 40 | #define DMG_FALL (1 << 5) // fell too far 41 | #define DMG_BLAST (1 << 6) // explosive blast damage 42 | #define DMG_CLUB (1 << 7) // crowbar, punch, headbutt 43 | #define DMG_SHOCK (1 << 8) // electric shock 44 | #define DMG_SONIC (1 << 9) // sound pulse shockwave 45 | #define DMG_ENERGYBEAM (1 << 10) // laser or other high energy beam 46 | #define DMG_NEVERGIB (1 << 12) // with this bit OR'd in, no damage type will be able to gib victims upon death 47 | #define DMG_ALWAYSGIB (1 << 13) // with this bit OR'd in, any damage type can be made to gib victims upon death. 48 | 49 | 50 | // time-based damage 51 | //mask off TF-specific stuff too 52 | #define DMG_TIMEBASED (~(0xff003fff)) // mask for time-based damage 53 | 54 | 55 | #define DMG_DROWN (1 << 14) // Drowning 56 | #define DMG_FIRSTTIMEBASED DMG_DROWN 57 | 58 | #define DMG_PARALYZE (1 << 15) // slows affected creature down 59 | #define DMG_NERVEGAS (1 << 16) // nerve toxins, very bad 60 | #define DMG_POISON (1 << 17) // blood poisioning 61 | #define DMG_RADIATION (1 << 18) // radiation exposure 62 | #define DMG_DROWNRECOVER (1 << 19) // drowning recovery 63 | #define DMG_ACID (1 << 20) // toxic chemicals or acid burns 64 | #define DMG_SLOWBURN (1 << 21) // in an oven 65 | #define DMG_SLOWFREEZE (1 << 22) // in a subzero freezer 66 | #define DMG_MORTAR (1 << 23) // Hit by air raid (done to distinguish grenade from mortar) 67 | 68 | //TF ADDITIONS 69 | #define DMG_IGNITE (1 << 24) // Players hit by this begin to burn 70 | #define DMG_RADIUS_MAX (1 << 25) // Radius damage with this flag doesn't decrease over distance 71 | #define DMG_RADIUS_QUAKE (1 << 26) // Radius damage is done like Quake. 1/2 damage at 1/2 radius. 72 | #define DMG_IGNOREARMOR (1 << 27) // Damage ignores target's armor 73 | #define DMG_AIMED (1 << 28) // Does Hit location damage 74 | #define DMG_WALLPIERCING (1 << 29) // Blast Damages ents through walls 75 | 76 | #define DMG_CALTROP (1<<30) 77 | #define DMG_HALLUC (1<<31) 78 | 79 | // TF Healing Additions for TakeHealth 80 | #define DMG_IGNORE_MAXHEALTH DMG_IGNITE 81 | // TF Redefines since we never use the originals 82 | #define DMG_NAIL DMG_SLASH 83 | #define DMG_NOT_SELF DMG_FREEZE 84 | 85 | 86 | #define DMG_TRANQ DMG_MORTAR 87 | #define DMG_CONCUSS DMG_SONIC 88 | 89 | 90 | 91 | typedef struct 92 | { 93 | float fExpire; 94 | float fBaseline; 95 | int x, y; 96 | } DAMAGE_IMAGE; 97 | 98 | // 99 | //----------------------------------------------------- 100 | // 101 | class CHudHealth: public CHudBase 102 | { 103 | public: 104 | virtual int Init( int player ); 105 | virtual int VidInit( int player ); 106 | virtual int Draw(float fTime, int player); 107 | virtual void Reset( int player ); 108 | int MsgFunc_Health(int player, const char *pszName, int iSize, void *pbuf); 109 | int MsgFunc_Damage(int player, const char *pszName, int iSize, void *pbuf); 110 | int m_iHealth; 111 | int m_HUD_dmg_bio; 112 | int m_HUD_cross; 113 | 114 | private: 115 | HSPRITE m_hSprite; 116 | HSPRITE m_hDamage; 117 | 118 | DAMAGE_IMAGE m_dmg[NUM_DMG_TYPES]; 119 | int m_bitsDamage; 120 | float m_fFade; 121 | void GetPainColor( int &r, int &g, int &b, int player ); 122 | int DrawPain(float fTime, int player); 123 | int DrawDamage(float fTime, int player); 124 | float m_fAttackFront, m_fAttackRear, m_fAttackLeft, m_fAttackRight; 125 | void CalcDamageDirection(vec3_t vecFrom, int player); 126 | void UpdateTiles(float fTime, long bits, int player); 127 | }; 128 | -------------------------------------------------------------------------------- /cl_dll/hud.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // 16 | // hud.cpp 17 | // 18 | // implementation of CHud class 19 | // 20 | 21 | #include "hud.h" 22 | #include "util.h" 23 | #include "parsemsg.h" 24 | 25 | extern client_sprite_t *GetSpriteList(client_sprite_t *pList, const char *psz, int iRes, int iCount); 26 | 27 | //DECLARE_MESSAGE(m_Logo, Logo) 28 | int __MsgFunc_Logo(int player, const char *pszName, int iSize, void *pbuf) 29 | { 30 | return gHUD.MsgFunc_Logo(player, pszName, iSize, pbuf ); 31 | } 32 | 33 | //DECLARE_MESSAGE(m_Logo, Logo) 34 | int __MsgFunc_ResetHUD(int player, const char *pszName, int iSize, void *pbuf) 35 | { 36 | return gHUD.MsgFunc_ResetHUD(player, pszName, iSize, pbuf ); 37 | } 38 | 39 | int __MsgFunc_InitHUD(int player, const char *pszName, int iSize, void *pbuf) 40 | { 41 | gHUD.MsgFunc_InitHUD( player, pszName, iSize, pbuf ); 42 | return 1; 43 | } 44 | 45 | int __MsgFunc_SetFOV(int player, const char *pszName, int iSize, void *pbuf) 46 | { 47 | return gHUD.MsgFunc_SetFOV( player, pszName, iSize, pbuf ); 48 | } 49 | 50 | int __MsgFunc_Concuss(int player, const char *pszName, int iSize, void *pbuf) 51 | { 52 | return gHUD.MsgFunc_Concuss( player, pszName, iSize, pbuf ); 53 | } 54 | 55 | int __MsgFunc_GameMode(int player, const char *pszName, int iSize, void *pbuf ) 56 | { 57 | return gHUD.MsgFunc_GameMode( player, pszName, iSize, pbuf ); 58 | } 59 | 60 | int __MsgFunc_HudColor(int player, const char* pszName, int iSize, void* pbuf) 61 | { 62 | return gHUD.MsgFunc_HudColor(player, pszName, iSize, pbuf); 63 | } 64 | 65 | // This is called every time the DLL is loaded 66 | void CHud :: Init( int player ) 67 | { 68 | HOOK_MESSAGE( Logo ); 69 | HOOK_MESSAGE( ResetHUD ); 70 | HOOK_MESSAGE( GameMode ); 71 | HOOK_MESSAGE( InitHUD ); 72 | HOOK_MESSAGE( SetFOV ); 73 | HOOK_MESSAGE( Concuss ); 74 | HOOK_MESSAGE( HudColor ); 75 | 76 | m_iLogo = 0; 77 | m_iFOV = 0; 78 | 79 | if (player == 0) 80 | { 81 | CVAR_CREATE("zoom_sensitivity_ratio", "1.2", 0); 82 | CVAR_CREATE("default_fov", "90", 0); 83 | } 84 | 85 | m_pSpriteList = NULL; 86 | 87 | // Clear any old HUD list 88 | if ( m_pHudList ) 89 | { 90 | HUDLIST *pList; 91 | while ( m_pHudList ) 92 | { 93 | pList = m_pHudList; 94 | m_pHudList = m_pHudList->pNext; 95 | Q_free( pList ); 96 | } 97 | m_pHudList = NULL; 98 | } 99 | 100 | // In case we get messages before the first update -- time will be valid 101 | m_flTime = 1.0; 102 | 103 | m_Ammo.Init(player); 104 | m_Health.Init(player); 105 | m_Geiger.Init(player); 106 | m_Train.Init(player); 107 | m_Battery.Init(player); 108 | m_Flash.Init(player); 109 | m_Message.Init(player); 110 | m_Scoreboard.Init(player); 111 | m_MOTD.Init(player); 112 | m_StatusBar.Init(player); 113 | m_DeathNotice.Init(player); 114 | m_AmmoSecondary.Init(player); 115 | m_TextMessage.Init(player); 116 | m_StatusIcons.Init(player); 117 | 118 | m_SayText.Init(player); 119 | m_Menu.Init(player); 120 | 121 | MsgFunc_ResetHUD(player, 0, 0, NULL ); 122 | } 123 | 124 | // CHud destructor 125 | // cleans up memory allocated for m_rg* arrays 126 | CHud :: ~CHud() 127 | { 128 | Q_free((void*)m_rghSprites); 129 | Q_free((void*)m_rgrcRects); 130 | Q_free((void*)m_rgszSpriteNames); 131 | /* 132 | delete[] m_rghSprites; 133 | delete[] m_rgrcRects; 134 | delete[] m_rgszSpriteNames; 135 | */ 136 | } 137 | 138 | // GetSpriteIndex() 139 | // searches through the sprite list loaded from hud.txt for a name matching SpriteName 140 | // returns an index into the gHUD.m_rghSprites[] array 141 | // returns 0 if sprite not found 142 | int CHud :: GetSpriteIndex( const char *SpriteName ) 143 | { 144 | // look through the loaded sprite name list for SpriteName 145 | for ( int i = 0; i < m_iSpriteCount; i++ ) 146 | { 147 | if ( strncmp( SpriteName, m_rgszSpriteNames + (i * MAX_SPRITE_NAME_LENGTH), MAX_SPRITE_NAME_LENGTH ) == 0 ) 148 | return i; 149 | } 150 | 151 | return -1; // invalid sprite 152 | } 153 | 154 | void CHud :: VidInit( int player ) 155 | { 156 | m_scrinfo.iSize = sizeof(m_scrinfo); 157 | GetScreenInfo(&m_scrinfo); 158 | 159 | // ---------- 160 | // Load Sprites 161 | // --------- 162 | // m_hsprFont = LoadSprite("sprites/%d_font.spz"); 163 | 164 | m_hsprLogo = 0; 165 | 166 | if (ScreenWidth < 512) 167 | m_iRes = 320; 168 | else 169 | m_iRes = 640; 170 | 171 | // Only load this once 172 | if ( !m_pSpriteList ) 173 | { 174 | // we need to load the hud.txt, and all sprites within 175 | m_pSpriteList = SPR_GetList("sprites/hud.txt", &m_iSpriteCountAllRes); 176 | 177 | if (m_pSpriteList) 178 | { 179 | // count the number of sprites of the appropriate res 180 | m_iSpriteCount = 0; 181 | client_sprite_t *p = m_pSpriteList; 182 | for ( int j = 0; j < m_iSpriteCountAllRes; j++ ) 183 | { 184 | if ( p->iRes == m_iRes ) 185 | m_iSpriteCount++; 186 | p++; 187 | } 188 | 189 | // allocated memory for sprite handle arrays 190 | m_rghSprites = (HSPRITE*)Q_malloc(m_iSpriteCount * sizeof(HSPRITE)); 191 | m_rgrcRects = (wrect_t*)Q_malloc(m_iSpriteCount * sizeof(wrect_t)); 192 | m_rgszSpriteNames = (char*)Q_malloc(m_iSpriteCount * MAX_SPRITE_NAME_LENGTH * sizeof(char)); 193 | 194 | p = m_pSpriteList; 195 | int index = 0; 196 | for ( int j = 0; j < m_iSpriteCountAllRes; j++ ) 197 | { 198 | if ( p->iRes == m_iRes ) 199 | { 200 | char sz[256]; 201 | Sys_sprintf(sz, "sprites/%s.spz", p->szSprite); 202 | m_rghSprites[index] = SPR_Load(sz); 203 | m_rgrcRects[index] = p->rc; 204 | Q_strncpy( &m_rgszSpriteNames[index * MAX_SPRITE_NAME_LENGTH], p->szName, MAX_SPRITE_NAME_LENGTH ); 205 | 206 | index++; 207 | } 208 | 209 | p++; 210 | } 211 | } 212 | } 213 | else 214 | { 215 | // we have already have loaded the sprite reference from hud.txt, but 216 | // we need to make sure all the sprites have been loaded (we've gone through a transition, or loaded a save game) 217 | client_sprite_t *p = m_pSpriteList; 218 | int index = 0; 219 | for ( int j = 0; j < m_iSpriteCountAllRes; j++ ) 220 | { 221 | if ( p->iRes == m_iRes ) 222 | { 223 | char sz[256]; 224 | Sys_sprintf( sz, "sprites/%s.spz", p->szSprite ); 225 | m_rghSprites[index] = SPR_Load(sz); 226 | index++; 227 | } 228 | 229 | p++; 230 | } 231 | } 232 | 233 | // assumption: number_1, number_2, etc, are all listed and loaded sequentially 234 | m_HUD_number_0 = GetSpriteIndex( "number_0" ); 235 | 236 | m_iFontHeight = m_rgrcRects[m_HUD_number_0].bottom - m_rgrcRects[m_HUD_number_0].top; 237 | 238 | m_Ammo.VidInit(player); 239 | m_Health.VidInit(player); 240 | m_Geiger.VidInit(player); 241 | m_Train.VidInit(player); 242 | m_Battery.VidInit(player); 243 | m_Flash.VidInit(player); 244 | m_Message.VidInit(player); 245 | m_Scoreboard.VidInit(player); 246 | m_MOTD.VidInit(player); 247 | m_StatusBar.VidInit(player); 248 | m_DeathNotice.VidInit(player); 249 | m_SayText.VidInit(player); 250 | m_Menu.VidInit(player); 251 | m_AmmoSecondary.VidInit(player); 252 | m_TextMessage.VidInit(player); 253 | m_StatusIcons.VidInit(player); 254 | } 255 | 256 | int CHud::MsgFunc_Logo(int player, const char *pszName, int iSize, void *pbuf) 257 | { 258 | BEGIN_READ( pbuf, iSize ); 259 | 260 | // update Train data 261 | m_iLogo = READ_BYTE(); 262 | 263 | return 1; 264 | } 265 | 266 | int CHud::MsgFunc_SetFOV(int player, const char *pszName, int iSize, void *pbuf) 267 | { 268 | BEGIN_READ( pbuf, iSize ); 269 | 270 | int newfov = READ_BYTE(); 271 | int def_fov = CVAR_GET_FLOAT( "default_fov" ); 272 | 273 | if ( newfov == 0 ) 274 | { 275 | m_iFOV = def_fov; 276 | } 277 | else 278 | { 279 | m_iFOV = newfov; 280 | } 281 | 282 | // the clients fov is actually set in the client data update section of the hud 283 | 284 | // Set a new sensitivity 285 | if ( m_iFOV == def_fov ) 286 | { 287 | // reset to saved sensitivity 288 | m_flMouseSensitivity = 0; 289 | } 290 | else 291 | { 292 | // set a new sensitivity that is proportional to the change from the FOV default 293 | m_flMouseSensitivity = CVAR_GET_FLOAT("sensitivity") * ((float)newfov / (float)def_fov) * CVAR_GET_FLOAT("zoom_sensitivity_ratio"); 294 | } 295 | 296 | return 1; 297 | } 298 | 299 | 300 | void CHud::AddHudElem(CHudBase *phudelem) 301 | { 302 | HUDLIST *pdl, *ptemp; 303 | 304 | //phudelem->Think(); 305 | 306 | if (!phudelem) 307 | return; 308 | 309 | pdl = (HUDLIST*)Q_malloc(sizeof(HUDLIST)); 310 | if (!pdl) 311 | return; 312 | 313 | memset(pdl, 0, sizeof(HUDLIST)); 314 | pdl->p = phudelem; 315 | 316 | if (!m_pHudList) 317 | { 318 | m_pHudList = pdl; 319 | return; 320 | } 321 | 322 | ptemp = m_pHudList; 323 | 324 | while (ptemp->pNext) 325 | ptemp = ptemp->pNext; 326 | 327 | ptemp->pNext = pdl; 328 | } 329 | 330 | 331 | -------------------------------------------------------------------------------- /cl_dll/hud_msg.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // 16 | // hud_msg.cpp 17 | // 18 | 19 | #include "hud.h" 20 | #include "util.h" 21 | #include "parsemsg.h" 22 | 23 | /// USER-DEFINED SERVER MESSAGE HANDLERS 24 | 25 | int CHud :: MsgFunc_ResetHUD(int player, const char *pszName, int iSize, void *pbuf ) 26 | { 27 | ASSERT( iSize == 0 ); 28 | 29 | // clear all hud data 30 | HUDLIST *pList = m_pHudList; 31 | 32 | while ( pList ) 33 | { 34 | if ( pList->p ) 35 | pList->p->Reset(player); 36 | pList = pList->pNext; 37 | } 38 | 39 | // reset sensitivity 40 | m_flMouseSensitivity = 0; 41 | 42 | // reset concussion effect 43 | m_iConcussionEffect = 0; 44 | 45 | return 1; 46 | } 47 | 48 | void CHud :: MsgFunc_InitHUD( int player, const char *pszName, int iSize, void *pbuf ) 49 | { 50 | // prepare all hud data 51 | HUDLIST *pList = m_pHudList; 52 | 53 | while (pList) 54 | { 55 | if ( pList->p ) 56 | pList->p->InitHUDData(player); 57 | pList = pList->pNext; 58 | } 59 | } 60 | 61 | 62 | int CHud :: MsgFunc_GameMode(int player, const char *pszName, int iSize, void *pbuf ) 63 | { 64 | BEGIN_READ( pbuf, iSize ); 65 | m_Teamplay = READ_BYTE(); 66 | 67 | return 1; 68 | } 69 | 70 | 71 | int CHud :: MsgFunc_Damage(int player, const char *pszName, int iSize, void *pbuf ) 72 | { 73 | int armor, blood; 74 | Vector from; 75 | int i; 76 | float count; 77 | 78 | BEGIN_READ( pbuf, iSize ); 79 | armor = READ_BYTE(); 80 | blood = READ_BYTE(); 81 | 82 | for (i=0 ; i<3 ; i++) 83 | from[i] = READ_COORD(); 84 | 85 | count = (blood * 0.5) + (armor * 0.5); 86 | 87 | if (count < 10) 88 | count = 10; 89 | 90 | // TODO: kick viewangles, show damage visually 91 | 92 | return 1; 93 | } 94 | 95 | int CHud :: MsgFunc_Concuss( int player, const char *pszName, int iSize, void *pbuf ) 96 | { 97 | BEGIN_READ( pbuf, iSize ); 98 | m_iConcussionEffect = READ_BYTE(); 99 | if (m_iConcussionEffect) 100 | this->m_StatusIcons.EnableIcon("dmg_concuss",255,160,0); 101 | else 102 | this->m_StatusIcons.DisableIcon("dmg_concuss"); 103 | return 1; 104 | } 105 | 106 | int CHud::MsgFunc_HudColor(int player, const char* pszName, int iSize, void* pbuf) 107 | { 108 | BEGIN_READ(pbuf, iSize); 109 | 110 | // TODO: use m_iHUDColor everywhere 111 | m_iHUDColor[0] = READ_BYTE(); 112 | m_iHUDColor[1] = READ_BYTE(); 113 | m_iHUDColor[2] = READ_BYTE(); 114 | 115 | return 1; 116 | } -------------------------------------------------------------------------------- /cl_dll/hud_redraw.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // 16 | // hud_redraw.cpp 17 | // 18 | #include 19 | #include "hud.h" 20 | #include "util.h" 21 | 22 | 23 | #define MAX_LOGO_FRAMES 56 24 | 25 | int grgLogoFrame[MAX_LOGO_FRAMES] = 26 | { 27 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 13, 13, 13, 13, 13, 12, 11, 10, 9, 8, 14, 15, 28 | 16, 17, 18, 19, 20, 20, 20, 20, 20, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 29 | 29, 29, 29, 29, 29, 28, 27, 26, 25, 24, 30, 31 30 | }; 31 | 32 | 33 | // Think 34 | void CHud::Think(int player) 35 | { 36 | HUDLIST *pList = m_pHudList; 37 | while (pList) 38 | { 39 | if (pList->p->m_iFlags & HUD_ACTIVE) 40 | pList->p->Think(player); 41 | pList = pList->pNext; 42 | } 43 | 44 | // think about default fov 45 | if ( m_iFOV == 0 ) 46 | { // only let players adjust up in fov, and only if they are not overriden by something else 47 | m_iFOV = max( CVAR_GET_FLOAT( "default_fov" ), 90 ); 48 | } 49 | } 50 | 51 | // Redraw 52 | // step through the local data, placing the appropriate graphics & text as appropriate 53 | // returns 1 if they've changed, 0 otherwise 54 | int CHud :: Redraw( float flTime, int intermission, int player ) 55 | { 56 | m_fOldTime = m_flTime; // save time of previous redraw 57 | m_flTime = flTime; 58 | m_flTimeDelta = (double)m_flTime - m_fOldTime; 59 | 60 | // Clock was reset, reset delta 61 | if ( m_flTimeDelta < 0 ) 62 | m_flTimeDelta = 0; 63 | 64 | m_iIntermission = intermission; 65 | 66 | // if no redrawing is necessary 67 | // return 0; 68 | 69 | HUDLIST *pList = m_pHudList; 70 | 71 | while (pList) 72 | { 73 | if ( !intermission ) 74 | { 75 | if ((pList->p->m_iFlags & HUD_ACTIVE) && !(m_iHideHUDDisplay & HIDEHUD_ALL)) 76 | pList->p->Draw(flTime, player); 77 | } 78 | else 79 | { // it's an intermission, so only draw hud elements that are set to draw during intermissions 80 | if ( pList->p->m_iFlags & HUD_INTERMISSION ) 81 | pList->p->Draw( flTime, player ); 82 | } 83 | 84 | pList = pList->pNext; 85 | } 86 | 87 | // are we in demo mode? do we need to draw the logo in the top corner? 88 | if (m_iLogo) 89 | { 90 | int x, y, i; 91 | 92 | if (m_hsprLogo == 0) 93 | m_hsprLogo = LoadSprite("sprites/%d_logo.spz"); 94 | 95 | SPR_Set(m_hsprLogo, 250, 250, 250 ); 96 | 97 | x = SPR_Width(m_hsprLogo, 0); 98 | x = ScreenWidth - x; 99 | y = SPR_Height(m_hsprLogo, 0)/2; 100 | 101 | // Draw the logo at 20 fps 102 | int iFrame = (int)(flTime * 20) % MAX_LOGO_FRAMES; 103 | i = grgLogoFrame[iFrame] - 1; 104 | 105 | SPR_DrawAdditive(i, x, y, NULL); 106 | } 107 | 108 | return 1; 109 | } 110 | 111 | void ScaleColors( int &r, int &g, int &b, int a ) 112 | { 113 | float x = (float)a / 255; 114 | r = (int)(r * x); 115 | g = (int)(g * x); 116 | b = (int)(b * x); 117 | } 118 | 119 | int CHud :: DrawHudString(int xpos, int ypos, int iMaxX, char *szIt, int r, int g, int b ) 120 | { 121 | // draw the string until we hit the null character or a newline character 122 | for ( ; *szIt != 0 && *szIt != '\n'; szIt++ ) 123 | { 124 | int next = xpos + gHUD.m_scrinfo.charWidths[ *szIt ]; // variable-width fonts look cool 125 | if ( next > iMaxX ) 126 | return xpos; 127 | 128 | TextMessageDrawChar( xpos, ypos, *szIt, r, g, b ); 129 | xpos = next; 130 | } 131 | 132 | return xpos; 133 | } 134 | 135 | int CHud :: DrawHudNumberString( int xpos, int ypos, int iMinX, int iNumber, int r, int g, int b ) 136 | { 137 | char szString[32]; 138 | Sys_sprintf( szString, "%d", iNumber ); 139 | return DrawHudStringReverse( xpos, ypos, iMinX, szString, r, g, b ); 140 | 141 | } 142 | 143 | // draws a string from right to left (right-aligned) 144 | int CHud :: DrawHudStringReverse( int xpos, int ypos, int iMinX, char *szString, int r, int g, int b ) 145 | { 146 | // find the end of the string 147 | char* szIt = szString; 148 | for ( szIt = szString; *szIt != 0; szIt++ ) 149 | { // we should count the length? 150 | } 151 | 152 | // iterate throug the string in reverse 153 | for ( szIt--; szIt != (szString-1); szIt-- ) 154 | { 155 | int next = xpos - gHUD.m_scrinfo.charWidths[ *szIt ]; // variable-width fonts look cool 156 | if ( next < iMinX ) 157 | return xpos; 158 | xpos = next; 159 | 160 | TextMessageDrawChar( xpos, ypos, *szIt, r, g, b ); 161 | } 162 | 163 | return xpos; 164 | } 165 | 166 | int CHud :: DrawHudNumber( int x, int y, int iFlags, int iNumber, int r, int g, int b) 167 | { 168 | int iWidth = GetSpriteRect(m_HUD_number_0).right - GetSpriteRect(m_HUD_number_0).left; 169 | int k; 170 | 171 | if (iNumber > 0) 172 | { 173 | // SPR_Draw 100's 174 | if (iNumber >= 100) 175 | { 176 | k = iNumber/100; 177 | SPR_Set(GetSprite(m_HUD_number_0 + k), r, g, b ); 178 | SPR_DrawAdditive( 0, x, y, &GetSpriteRect(m_HUD_number_0 + k)); 179 | x += iWidth; 180 | } 181 | else if (iFlags & (DHN_3DIGITS)) 182 | { 183 | //SPR_DrawAdditive( 0, x, y, &rc ); 184 | x += iWidth; 185 | } 186 | 187 | // SPR_Draw 10's 188 | if (iNumber >= 10) 189 | { 190 | k = (iNumber % 100)/10; 191 | SPR_Set(GetSprite(m_HUD_number_0 + k), r, g, b ); 192 | SPR_DrawAdditive( 0, x, y, &GetSpriteRect(m_HUD_number_0 + k)); 193 | x += iWidth; 194 | } 195 | else if (iFlags & (DHN_3DIGITS | DHN_2DIGITS)) 196 | { 197 | //SPR_DrawAdditive( 0, x, y, &rc ); 198 | x += iWidth; 199 | } 200 | 201 | // SPR_Draw ones 202 | k = iNumber % 10; 203 | SPR_Set(GetSprite(m_HUD_number_0 + k), r, g, b ); 204 | SPR_DrawAdditive(0, x, y, &GetSpriteRect(m_HUD_number_0 + k)); 205 | x += iWidth; 206 | } 207 | else if (iFlags & DHN_DRAWZERO) 208 | { 209 | SPR_Set(GetSprite(m_HUD_number_0), r, g, b ); 210 | 211 | // SPR_Draw 100's 212 | if (iFlags & (DHN_3DIGITS)) 213 | { 214 | //SPR_DrawAdditive( 0, x, y, &rc ); 215 | x += iWidth; 216 | } 217 | 218 | if (iFlags & (DHN_3DIGITS | DHN_2DIGITS)) 219 | { 220 | //SPR_DrawAdditive( 0, x, y, &rc ); 221 | x += iWidth; 222 | } 223 | 224 | // SPR_Draw ones 225 | 226 | SPR_DrawAdditive( 0, x, y, &GetSpriteRect(m_HUD_number_0)); 227 | x += iWidth; 228 | } 229 | 230 | return x; 231 | } 232 | 233 | 234 | int CHud::GetNumWidth( int iNumber, int iFlags ) 235 | { 236 | if (iFlags & (DHN_3DIGITS)) 237 | return 3; 238 | 239 | if (iFlags & (DHN_2DIGITS)) 240 | return 2; 241 | 242 | if (iNumber <= 0) 243 | { 244 | if (iFlags & (DHN_DRAWZERO)) 245 | return 1; 246 | else 247 | return 0; 248 | } 249 | 250 | if (iNumber < 10) 251 | return 1; 252 | 253 | if (iNumber < 100) 254 | return 2; 255 | 256 | return 3; 257 | 258 | } 259 | 260 | 261 | -------------------------------------------------------------------------------- /cl_dll/hud_update.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // 16 | // hud_update.cpp 17 | // 18 | 19 | #include 20 | #include "hud.h" 21 | #include "util.h" 22 | #include 23 | 24 | 25 | 26 | int CHud::UpdateClientData(client_data_t *cdata, int player) 27 | { 28 | Q_memcpy(m_vecOrigin[player], cdata->origin, sizeof(vec3_t)); 29 | Q_memcpy(m_vecAngles[player], cdata->viewangles, sizeof(vec3_t)); 30 | m_iKeyBits[player] = cdata->iKeyBits; 31 | m_iWeaponBits[player] = cdata->iWeaponBits; 32 | gHUD.Think(player); 33 | 34 | cdata->iKeyBits = m_iKeyBits[player]; 35 | cdata->fov = m_iFOV; 36 | cdata->view_idlescale = m_iConcussionEffect; 37 | 38 | if ( m_flMouseSensitivity ) 39 | cdata->mouse_sensitivity = m_flMouseSensitivity; 40 | 41 | // return 1 if in anything in the client_data struct has been changed, 0 otherwise 42 | return 1; 43 | } 44 | 45 | 46 | -------------------------------------------------------------------------------- /cl_dll/menu.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // 16 | // menu.cpp 17 | // 18 | // generic menu handler 19 | // 20 | #include "hud.h" 21 | #include "util.h" 22 | #include "parsemsg.h" 23 | 24 | #define MAX_MENU_STRING 512 25 | char g_szMenuString[MAX_MENU_STRING]; 26 | char g_szPrelocalisedMenuString[MAX_MENU_STRING]; 27 | 28 | DECLARE_MESSAGE( m_Menu, ShowMenu ); 29 | 30 | int CHudMenu :: Init( int player ) 31 | { 32 | gHUD.AddHudElem( this ); 33 | 34 | HOOK_MESSAGE( ShowMenu ); 35 | 36 | InitHUDData(player); 37 | 38 | return 1; 39 | } 40 | 41 | void CHudMenu :: InitHUDData( int player ) 42 | { 43 | m_fMenuDisplayed = 0; 44 | m_bitsValidSlots = 0; 45 | Reset(player); 46 | } 47 | 48 | void CHudMenu :: Reset( int player ) 49 | { 50 | g_szPrelocalisedMenuString[0] = 0; 51 | m_fWaitingForMore = FALSE; 52 | } 53 | 54 | int CHudMenu :: VidInit( int player ) 55 | { 56 | return 1; 57 | } 58 | 59 | int CHudMenu :: Draw( float flTime, int player ) 60 | { 61 | // check for if menu is set to disappear 62 | if ( m_flShutoffTime > 0 ) 63 | { 64 | if ( m_flShutoffTime <= gHUD.m_flTime ) 65 | { // times up, shutoff 66 | m_fMenuDisplayed = 0; 67 | m_iFlags &= ~HUD_ACTIVE; 68 | return 1; 69 | } 70 | } 71 | 72 | // don't draw the menu if the scoreboard is being shown 73 | if ( gHUD.m_Scoreboard.m_iShowscoresHeld ) 74 | return 1; 75 | 76 | // draw the menu, along the left-hand side of the screen 77 | 78 | // count the number of newlines 79 | int nlc = 0, i = 0; 80 | for ( i = 0; i < MAX_MENU_STRING && g_szMenuString[i] != '\0'; i++ ) 81 | { 82 | if ( g_szMenuString[i] == '\n' ) 83 | nlc++; 84 | } 85 | 86 | // center it 87 | int y = (ScreenHeight/2) - ((nlc/2)*12) - 40; // make sure it is above the say text 88 | int x = 20; 89 | 90 | i = 0; 91 | while ( i < MAX_MENU_STRING && g_szMenuString[i] != '\0' ) 92 | { 93 | gHUD.DrawHudString( x, y, 320, g_szMenuString + i, 255, 255, 255 ); 94 | y += 12; 95 | 96 | while ( i < MAX_MENU_STRING && g_szMenuString[i] != '\0' && g_szMenuString[i] != '\n' ) 97 | i++; 98 | if ( g_szMenuString[i] == '\n' ) 99 | i++; 100 | } 101 | 102 | return 1; 103 | } 104 | 105 | // selects an item from the menu 106 | void CHudMenu :: SelectMenuItem( int menu_item, int player ) 107 | { 108 | // if menu_item is in a valid slot, send a menuselect command to the server 109 | if ( (menu_item > 0) && (m_bitsValidSlots & (1 << (menu_item-1))) ) 110 | { 111 | char szbuf[32]; 112 | Sys_sprintf( szbuf, "menuselect %d\n", menu_item ); 113 | ClientCmd( szbuf ); 114 | 115 | // remove the menu 116 | m_fMenuDisplayed = 0; 117 | m_iFlags &= ~HUD_ACTIVE; 118 | } 119 | } 120 | 121 | 122 | // Message handler for ShowMenu message 123 | // takes four values: 124 | // short: a bitfield of keys that are valid input 125 | // char : the duration, in seconds, the menu should stay up. -1 means is stays until something is chosen. 126 | // byte : a boolean, TRUE if there is more string yet to be received before displaying the menu, FALSE if it's the last string 127 | // string: menu string to display 128 | // if this message is never received, then scores will simply be the combined totals of the players. 129 | int CHudMenu :: MsgFunc_ShowMenu( int player, const char *pszName, int iSize, void *pbuf ) 130 | { 131 | BEGIN_READ( pbuf, iSize ); 132 | 133 | m_bitsValidSlots = READ_SHORT(); 134 | int DisplayTime = READ_CHAR(); 135 | int NeedMore = READ_BYTE(); 136 | 137 | if ( DisplayTime > 0 ) 138 | m_flShutoffTime = DisplayTime + gHUD.m_flTime; 139 | else 140 | m_flShutoffTime = -1; 141 | 142 | if ( m_bitsValidSlots ) 143 | { 144 | if ( !m_fWaitingForMore ) // this is the start of a new menu 145 | { 146 | strncpy( g_szPrelocalisedMenuString, READ_STRING(), MAX_MENU_STRING ); 147 | } 148 | else 149 | { // append to the current menu string 150 | strncat( g_szPrelocalisedMenuString, READ_STRING(), MAX_MENU_STRING - strlen(g_szPrelocalisedMenuString) ); 151 | } 152 | g_szPrelocalisedMenuString[MAX_MENU_STRING-1] = 0; // ensure null termination (strncat/strncpy does not) 153 | 154 | if ( !NeedMore ) 155 | { // we have the whole string, so we can localise it now 156 | Q_strcpy( g_szMenuString, gHUD.m_TextMessage.BufferedLocaliseTextString( g_szPrelocalisedMenuString ) ); 157 | } 158 | 159 | m_fMenuDisplayed = 1; 160 | m_iFlags |= HUD_ACTIVE; 161 | } 162 | else 163 | { 164 | m_fMenuDisplayed = 0; // no valid slots means that the menu should be turned off 165 | m_iFlags &= ~HUD_ACTIVE; 166 | } 167 | 168 | m_fWaitingForMore = NeedMore; 169 | 170 | return 1; 171 | } 172 | -------------------------------------------------------------------------------- /cl_dll/parsemsg.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // 16 | // parsemsg.cpp 17 | // 18 | typedef unsigned char byte; 19 | #define true 1 20 | 21 | static byte *gpBuf; 22 | static int giSize; 23 | static int giRead; 24 | static int giBadRead; 25 | 26 | void BEGIN_READ( void *buf, int size ) 27 | { 28 | giRead = 0; 29 | giBadRead = 0; 30 | giSize = size; 31 | gpBuf = (byte*)buf; 32 | } 33 | 34 | 35 | int READ_CHAR( void ) 36 | { 37 | int c; 38 | 39 | if (giRead + 1 > giSize) 40 | { 41 | giBadRead = true; 42 | return -1; 43 | } 44 | 45 | c = (signed char)gpBuf[giRead]; 46 | giRead++; 47 | 48 | return c; 49 | } 50 | 51 | int READ_BYTE( void ) 52 | { 53 | int c; 54 | 55 | if (giRead+1 > giSize) 56 | { 57 | giBadRead = true; 58 | return -1; 59 | } 60 | 61 | c = (unsigned char)gpBuf[giRead]; 62 | giRead++; 63 | 64 | return c; 65 | } 66 | 67 | int READ_SHORT( void ) 68 | { 69 | int c; 70 | 71 | if (giRead+2 > giSize) 72 | { 73 | giBadRead = true; 74 | return -1; 75 | } 76 | 77 | c = (short)( gpBuf[giRead] + ( gpBuf[giRead+1] << 8 ) ); 78 | 79 | giRead += 2; 80 | 81 | return c; 82 | } 83 | 84 | int READ_WORD( void ) 85 | { 86 | return READ_SHORT(); 87 | } 88 | 89 | 90 | int READ_LONG( void ) 91 | { 92 | int c; 93 | 94 | if (giRead+4 > giSize) 95 | { 96 | giBadRead = true; 97 | return -1; 98 | } 99 | 100 | c = gpBuf[giRead] + (gpBuf[giRead + 1] << 8) + (gpBuf[giRead + 2] << 16) + (gpBuf[giRead + 3] << 24); 101 | 102 | giRead += 4; 103 | 104 | return c; 105 | } 106 | 107 | float READ_FLOAT( void ) 108 | { 109 | union 110 | { 111 | byte b[4]; 112 | float f; 113 | int l; 114 | } dat; 115 | 116 | dat.b[0] = gpBuf[giRead]; 117 | dat.b[1] = gpBuf[giRead+1]; 118 | dat.b[2] = gpBuf[giRead+2]; 119 | dat.b[3] = gpBuf[giRead+3]; 120 | giRead += 4; 121 | 122 | // dat.l = LittleLong (dat.l); 123 | 124 | return dat.f; 125 | } 126 | 127 | char* READ_STRING( void ) 128 | { 129 | static char string[2048]; 130 | int l,c; 131 | 132 | string[0] = 0; 133 | 134 | l = 0; 135 | do 136 | { 137 | if ( giRead+1 > giSize ) 138 | break; // no more characters 139 | 140 | c = READ_CHAR(); 141 | if (c == -1 || c == 0) 142 | break; 143 | string[l] = c; 144 | l++; 145 | } while (l < sizeof(string)-1); 146 | 147 | string[l] = 0; 148 | 149 | return string; 150 | } 151 | 152 | float READ_COORD( void ) 153 | { 154 | return (float)(READ_SHORT() * (1.0/8)); 155 | } 156 | 157 | float READ_ANGLE( void ) 158 | { 159 | return (float)(READ_CHAR() * (360.0/256)); 160 | } 161 | 162 | float READ_HIRESANGLE( void ) 163 | { 164 | return (float)(READ_SHORT() * (360.0/65536)); 165 | } 166 | 167 | -------------------------------------------------------------------------------- /cl_dll/parsemsg.h: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // 16 | // parsemsg.h 17 | // 18 | 19 | #define ASSERT( x ) 20 | 21 | void BEGIN_READ( void *buf, int size ); 22 | int READ_CHAR( void ); 23 | int READ_BYTE( void ); 24 | int READ_SHORT( void ); 25 | int READ_WORD( void ); 26 | int READ_LONG( void ); 27 | float READ_FLOAT( void ); 28 | char* READ_STRING( void ); 29 | float READ_COORD( void ); 30 | float READ_ANGLE( void ); 31 | float READ_HIRESANGLE( void ); 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /cl_dll/readme.txt: -------------------------------------------------------------------------------- 1 | client dll readme.txt 2 | ------------------------- 3 | 4 | This file details the structure of the half-life client dll, and 5 | how it communicates with the half-life game engine. 6 | 7 | 8 | Engine callback functions: 9 | 10 | Drawing functions: 11 | HSPRITE SPR_Load( char *picname ); 12 | Loads a sprite into memory, and returns a handle to it. 13 | 14 | int SPR_Frames( HSPRITE sprite ); 15 | Returns the number of frames stored in the specified sprite. 16 | 17 | int SPR_Height( HSPRITE x, int frame ) 18 | Returns the height, in pixels, of a sprite at the specified frame. 19 | Returns 0 is the frame number or the sprite handle is invalid. 20 | 21 | int SPR_Width( HSPRITE x, int f ) 22 | Returns the width, in pixels, of a sprite at the specified frame. 23 | Returns 0 is the frame number or the sprite handle is invalid. 24 | 25 | int SPR_Set( HSPRITE sprite, int r, int g, int b ); 26 | Prepares a sprite about to be drawn. RBG color values are applied to the sprite at this time. 27 | 28 | 29 | void SPR_Draw( int frame, int x, int y ); 30 | Precondition: SPR_Set has already been called for a sprite. 31 | Draws the currently active sprite to the screen, at position (x,y), where (0,0) is 32 | the top left-hand corner of the screen. 33 | 34 | 35 | void SPR_DrawHoles( int frame, int x, int y ); 36 | Precondition: SPR_Set has already been called for a sprite. 37 | Draws the currently active sprite to the screen. Color index #255 is treated as transparent. 38 | 39 | void SPR_DrawAdditive( int frame, int x, int y ); 40 | Precondition: SPR_Set has already been called for a sprite. 41 | Draws the currently active sprite to the screen, adding it's color values to the background. 42 | 43 | void SPR_EnableScissor( int x, int y, int width, int height ); 44 | Creates a clipping rectangle. No pixels will be drawn outside the specified area. Will 45 | stay in effect until either the next frame, or SPR_DisableScissor is called. 46 | 47 | void SPR_DisableScissor( void ); 48 | Disables the effect of an SPR_EnableScissor call. 49 | 50 | int IsHighRes( void ); 51 | returns 1 if the res mode is 640x480 or higher; 0 otherwise. 52 | 53 | int ScreenWidth( void ); 54 | returns the screen width, in pixels. 55 | 56 | int ScreenHeight( void ); 57 | returns the screen height, in pixels. 58 | 59 | // Sound functions 60 | void PlaySound( char *szSound, int volume ) 61 | plays the sound 'szSound' at the specified volume. Loads the sound if it hasn't been cached. 62 | If it can't find the sound, it displays an error message and plays no sound. 63 | 64 | void PlaySound( int iSound, int volume ) 65 | Precondition: iSound has been precached. 66 | Plays the sound, from the precache list. 67 | 68 | 69 | // Communication functions 70 | void SendClientCmd( char *szCmdString ); 71 | sends a command to the server, just as if the client had typed the szCmdString at the console. 72 | 73 | char *GetPlayerName( int entity_number ); 74 | returns a pointer to a string, that contains the name of the specified client. 75 | Returns NULL if the entity_number is not a client. 76 | 77 | 78 | DECLARE_MESSAGE(), HOOK_MESSAGE() 79 | These two macros bind the message sending between the entity DLL and the client DLL to 80 | the CHud object. 81 | 82 | HOOK_MESSAGE( message_name ) 83 | This is used inside CHud::Init(). It calls into the engine to hook that message 84 | from the incoming message stream. 85 | Precondition: There must be a function of name UserMsg_message_name declared 86 | for CHud. Eg, CHud::UserMsg_Health() must be declared if you want to 87 | use HOOK_MESSAGE( Health ); 88 | 89 | DECLARE_MESSAGE( message_name ) 90 | For each HOOK_MESSAGE you must have an equivalent DECLARE_MESSAGE. This creates 91 | a function which passes the hooked messages into the CHud object. 92 | 93 | 94 | HOOK_COMMAND(), DECLARE_COMMAND() 95 | These two functions declare and hook console commands into the client dll. 96 | 97 | HOOK_COMMAND( char *command, command_name ) 98 | Whenever the user types the 'command' at the console, the function 'command_name' 99 | will be called. 100 | Precondition: There must be a function of the name UserCmd_command_name declared 101 | for CHud. Eg, CHud::UserMsg_ShowScores() must be declared if you want to 102 | use HOOK_COMMAND( "+showscores", ShowScores ); 103 | 104 | DECLARE_COMMAND( command_name ) 105 | For each HOOK_COMMAND you must have an equivelant DECLARE_COMMAND. This creates 106 | a function which passes the hooked commands into the CHud object. 107 | 108 | -------------------------------------------------------------------------------- /cl_dll/saytext.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // 16 | // saytext.cpp 17 | // 18 | // implementation of CHudSayText class 19 | // 20 | 21 | #include "hud.h" 22 | #include "util.h" 23 | #include "parsemsg.h" 24 | 25 | #define MAX_LINES 5 26 | #define MAX_CHARS_PER_LINE 128 /* it can be less than this, depending on char size */ 27 | 28 | // allow 20 pixels on either side of the text 29 | #define MAX_LINE_WIDTH ( ScreenWidth - 40 ) 30 | #define LINE_START 10 31 | static float SCROLL_SPEED = 5; 32 | 33 | static char g_szLineBuffer[ MAX_LINES + 1 ][ MAX_CHARS_PER_LINE ]; 34 | static float flScrollTime = 0; // the time at which the lines next scroll up 35 | 36 | static int Y_START = 0; 37 | static int line_height = 0; 38 | 39 | DECLARE_MESSAGE( m_SayText, SayText ); 40 | 41 | int CHudSayText :: Init( int player ) 42 | { 43 | gHUD.AddHudElem( this ); 44 | 45 | HOOK_MESSAGE( SayText ); 46 | 47 | InitHUDData(player); 48 | 49 | if (player == 0) 50 | { 51 | CVAR_CREATE("hud_saytext_time", "5", 0); 52 | } 53 | 54 | return 1; 55 | } 56 | 57 | 58 | void CHudSayText :: InitHUDData( int player ) 59 | { 60 | memset( g_szLineBuffer, 0, sizeof g_szLineBuffer ); 61 | } 62 | 63 | int CHudSayText :: VidInit( int player ) 64 | { 65 | return 1; 66 | } 67 | 68 | 69 | void ScrollTextUp( void ) 70 | { 71 | ConsolePrint( g_szLineBuffer[0] ); // move the first line into the console buffer 72 | memmove( g_szLineBuffer[0], g_szLineBuffer[1], sizeof(g_szLineBuffer) - sizeof(g_szLineBuffer[0]) ); // overwrite the first line 73 | 74 | if ( g_szLineBuffer[0][0] == ' ' ) // also scroll up following lines 75 | { 76 | g_szLineBuffer[0][0] = 2; 77 | ScrollTextUp(); 78 | } 79 | } 80 | 81 | int CHudSayText :: Draw( float flTime, int player ) 82 | { 83 | int y = Y_START; 84 | 85 | // make sure the scrolltime is within reasonable bounds, to guard against the clock being reset 86 | flScrollTime = min( flScrollTime, flTime + SCROLL_SPEED ); 87 | 88 | // make sure the scrolltime is within reasonable bounds, to guard against the clock being reset 89 | flScrollTime = min( flScrollTime, flTime + SCROLL_SPEED ); 90 | 91 | if ( flScrollTime <= flTime ) 92 | { 93 | if ( *g_szLineBuffer[0] ) 94 | { 95 | flScrollTime = flTime + SCROLL_SPEED; 96 | // push the console up 97 | ScrollTextUp(); 98 | } 99 | else 100 | { // buffer is empty, just disable drawing of this section 101 | m_iFlags &= ~HUD_ACTIVE; 102 | } 103 | } 104 | 105 | for ( int i = 0; i < MAX_LINES; i++ ) 106 | { 107 | if ( *g_szLineBuffer[i] ) 108 | DrawConsoleString( LINE_START, y, g_szLineBuffer[i] ); 109 | 110 | y += line_height; 111 | } 112 | 113 | 114 | return 1; 115 | } 116 | 117 | int CHudSayText :: MsgFunc_SayText( int player, const char *pszName, int iSize, void *pbuf ) 118 | { 119 | BEGIN_READ( pbuf, iSize ); 120 | 121 | int client_index = READ_BYTE(); // the client who spoke the message 122 | SayTextPrint( READ_STRING(), iSize - 1, player ); 123 | 124 | return 1; 125 | } 126 | 127 | void CHudSayText :: SayTextPrint( const char *pszBuf, int iBufSize, int player ) 128 | { 129 | // find an empty string slot 130 | int i = 0; 131 | 132 | for ( i = 0; i < MAX_LINES; i++ ) 133 | { 134 | if ( ! *g_szLineBuffer[i] ) 135 | break; 136 | } 137 | if ( i == MAX_LINES ) 138 | { 139 | // force scroll buffer up 140 | ScrollTextUp(); 141 | i = MAX_LINES - 1; 142 | } 143 | 144 | strncpy( g_szLineBuffer[i], (char*)pszBuf, max(iBufSize -1, MAX_CHARS_PER_LINE-1) ); 145 | 146 | // make sure the text fits in one line 147 | EnsureTextFitsInOneLineAndWrapIfHaveTo( i ); 148 | 149 | // Set scroll time 150 | if ( i == 0 ) 151 | { 152 | SCROLL_SPEED = CVAR_GET_FLOAT( "hud_saytext_time" ); 153 | flScrollTime = gHUD.m_flTime + SCROLL_SPEED; 154 | } 155 | 156 | m_iFlags |= HUD_ACTIVE; 157 | PlaySound( "misc/talk.wav", player ); 158 | 159 | if ( ScreenHeight >= 480 ) 160 | Y_START = ScreenHeight - 45; 161 | else 162 | Y_START = ScreenHeight - 35; 163 | Y_START -= (line_height * (MAX_LINES+1)); 164 | 165 | } 166 | 167 | void CHudSayText :: EnsureTextFitsInOneLineAndWrapIfHaveTo( int line ) 168 | { 169 | int line_width = 0; 170 | GetConsoleStringSize( g_szLineBuffer[line], &line_width, &line_height ); 171 | 172 | if ( (line_width + LINE_START) > MAX_LINE_WIDTH ) 173 | { // string is too long to fit on line 174 | // scan the string until we find what word is too long, and wrap the end of the sentence after the word 175 | int length = LINE_START; 176 | int tmp_len = 0; 177 | char *last_break = NULL; 178 | for ( char *x = g_szLineBuffer[line]; *x != 0; x++ ) 179 | { 180 | char buf[2]; 181 | buf[1] = 0; 182 | 183 | if ( *x == ' ' && x != g_szLineBuffer[line] ) // store each line break, except for the very first character 184 | last_break = x; 185 | 186 | buf[0] = *x; // get the length of the current character 187 | GetConsoleStringSize( buf, &tmp_len, &line_height ); 188 | length += tmp_len; 189 | 190 | if ( length > MAX_LINE_WIDTH ) 191 | { // needs to be broken up 192 | if ( !last_break ) 193 | last_break = x-1; 194 | 195 | x = last_break; 196 | 197 | // find an empty string slot 198 | int j = 0; 199 | for ( j = 0; j < MAX_LINES; j++ ) 200 | { 201 | if ( ! *g_szLineBuffer[j] ) 202 | break; 203 | } 204 | if ( j == MAX_LINES ) 205 | { 206 | j = MAX_LINES - 1; 207 | } 208 | 209 | // copy remaining string into next buffer, making sure it starts with a space character 210 | if ( (char)*last_break == (char)' ' ) 211 | { 212 | int linelen = strlen(g_szLineBuffer[j]); 213 | int remaininglen = strlen(last_break); 214 | 215 | if ( (linelen - remaininglen) <= MAX_CHARS_PER_LINE ) 216 | strcat( g_szLineBuffer[j], last_break ); 217 | } 218 | else 219 | { 220 | if ( (strlen(g_szLineBuffer[j]) - strlen(last_break) - 2) < MAX_CHARS_PER_LINE ) 221 | { 222 | strcat( g_szLineBuffer[j], " " ); 223 | strcat( g_szLineBuffer[j], last_break ); 224 | } 225 | } 226 | 227 | *last_break = 0; // cut off the last string 228 | 229 | EnsureTextFitsInOneLineAndWrapIfHaveTo( j ); 230 | break; 231 | } 232 | } 233 | } 234 | } -------------------------------------------------------------------------------- /cl_dll/status_icons.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // 16 | // status_icons.cpp 17 | // 18 | #include "hud.h" 19 | #include "util.h" 20 | #include "parsemsg.h" 21 | 22 | DECLARE_MESSAGE( m_StatusIcons, StatusIcon ); 23 | 24 | int CHudStatusIcons::Init( int player ) 25 | { 26 | HOOK_MESSAGE( StatusIcon ); 27 | 28 | gHUD.AddHudElem( this ); 29 | 30 | Reset(player); 31 | 32 | return 1; 33 | } 34 | 35 | int CHudStatusIcons::VidInit( int player ) 36 | { 37 | 38 | return 1; 39 | } 40 | 41 | void CHudStatusIcons::Reset( int player ) 42 | { 43 | memset( m_IconList, 0, sizeof m_IconList ); 44 | m_iFlags &= ~HUD_ACTIVE; 45 | } 46 | 47 | // Draw status icons along the left-hand side of the screen 48 | int CHudStatusIcons::Draw( float flTime, int player ) 49 | { 50 | // find starting position to draw from, along right-hand side of screen 51 | int x = 5; 52 | int y = ScreenHeight / 2; 53 | 54 | // loop through icon list, and draw any valid icons drawing up from the middle of screen 55 | for ( int i = 0; i < MAX_ICONSPRITES; i++ ) 56 | { 57 | if ( m_IconList[i].spr ) 58 | { 59 | y -= ( m_IconList[i].rc.bottom - m_IconList[i].rc.top ) + 5; 60 | 61 | SPR_Set( m_IconList[i].spr, m_IconList[i].r, m_IconList[i].g, m_IconList[i].b ); 62 | SPR_DrawAdditive( 0, x, y, &m_IconList[i].rc ); 63 | } 64 | } 65 | 66 | return 1; 67 | } 68 | 69 | // Message handler for StatusIcon message 70 | // accepts five values: 71 | // byte : TRUE = ENABLE icon, FALSE = DISABLE icon 72 | // string : the sprite name to display 73 | // byte : red 74 | // byte : green 75 | // byte : blue 76 | int CHudStatusIcons::MsgFunc_StatusIcon( int player, const char *pszName, int iSize, void *pbuf ) 77 | { 78 | BEGIN_READ( pbuf, iSize ); 79 | 80 | int ShouldEnable = READ_BYTE(); 81 | char *pszIconName = READ_STRING(); 82 | if ( ShouldEnable ) 83 | { 84 | int r = READ_BYTE(); 85 | int g = READ_BYTE(); 86 | int b = READ_BYTE(); 87 | EnableIcon( pszIconName, r, g, b ); 88 | m_iFlags |= HUD_ACTIVE; 89 | } 90 | else 91 | { 92 | DisableIcon( pszIconName ); 93 | } 94 | 95 | return 1; 96 | } 97 | 98 | // add the icon to the icon list, and set it's drawing color 99 | void CHudStatusIcons::EnableIcon( char *pszIconName, unsigned char red, unsigned char green, unsigned char blue ) 100 | { 101 | // check to see if the sprite is in the current list 102 | int i = 0; 103 | 104 | for ( i = 0; i < MAX_ICONSPRITES; i++ ) 105 | { 106 | if ( !strcmp( m_IconList[i].szSpriteName, pszIconName ) ) 107 | break; 108 | } 109 | 110 | if ( i == MAX_ICONSPRITES ) 111 | { 112 | // icon not in list, so find an empty slot to add to 113 | for ( i = 0; i < MAX_ICONSPRITES; i++ ) 114 | { 115 | if ( !m_IconList[i].spr ) 116 | break; 117 | } 118 | } 119 | 120 | // if we've run out of space in the list, overwrite the first icon 121 | if ( i == MAX_ICONSPRITES ) 122 | { 123 | i = 0; 124 | } 125 | 126 | // Load the sprite and add it to the list 127 | // the sprite must be listed in hud.txt 128 | int spr_index = gHUD.GetSpriteIndex( pszIconName ); 129 | m_IconList[i].spr = gHUD.GetSprite( spr_index ); 130 | m_IconList[i].rc = gHUD.GetSpriteRect( spr_index ); 131 | m_IconList[i].r = red; 132 | m_IconList[i].g = green; 133 | m_IconList[i].b = blue; 134 | Q_strcpy( m_IconList[i].szSpriteName, pszIconName ); 135 | } 136 | 137 | void CHudStatusIcons::DisableIcon( char *pszIconName ) 138 | { 139 | // find the sprite is in the current list 140 | for ( int i = 0; i < MAX_ICONSPRITES; i++ ) 141 | { 142 | if ( !strcmp( m_IconList[i].szSpriteName, pszIconName ) ) 143 | { 144 | // clear the item from the list 145 | memset( &m_IconList[i], 0, sizeof(icon_sprite_t) ); 146 | return; 147 | } 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /cl_dll/statusbar.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // 16 | // statusbar.cpp 17 | // 18 | // generic text status bar, set by game dll 19 | // runs across bottom of screen 20 | // 21 | 22 | #include "hud.h" 23 | #include "util.h" 24 | #include "parsemsg.h" 25 | 26 | DECLARE_MESSAGE( m_StatusBar, StatusText ); 27 | DECLARE_MESSAGE( m_StatusBar, StatusValue ); 28 | 29 | #define STATUSBAR_ID_LINE 1 30 | 31 | int CHudStatusBar :: Init( int player ) 32 | { 33 | gHUD.AddHudElem( this ); 34 | 35 | HOOK_MESSAGE( StatusText ); 36 | HOOK_MESSAGE( StatusValue ); 37 | 38 | Reset(player); 39 | 40 | if (player == 0) 41 | { 42 | CVAR_CREATE("hud_centerid", "0", FCVAR_ARCHIVE); 43 | } 44 | 45 | return 1; 46 | } 47 | 48 | int CHudStatusBar :: VidInit( int player ) 49 | { 50 | // Load sprites here 51 | 52 | return 1; 53 | } 54 | 55 | void CHudStatusBar :: Reset( int player ) 56 | { 57 | m_iFlags &= ~HUD_ACTIVE; // start out inactive 58 | for ( int i = 0; i < MAX_STATUSBAR_LINES; i++ ) 59 | m_szStatusText[i][0] = 0; 60 | memset( m_iStatusValues, 0, sizeof m_iStatusValues ); 61 | 62 | m_iStatusValues[0] = 1; // 0 is the special index, which always returns true 63 | } 64 | 65 | void CHudStatusBar :: ParseStatusString( int line_num ) 66 | { 67 | // localise string first 68 | char szBuffer[MAX_STATUSTEXT_LENGTH]; 69 | memset( szBuffer, 0, sizeof szBuffer ); 70 | gHUD.m_TextMessage.LocaliseTextString( m_szStatusText[line_num], szBuffer, MAX_STATUSTEXT_LENGTH ); 71 | 72 | // parse m_szStatusText & m_iStatusValues into m_szStatusBar 73 | memset( m_szStatusBar[line_num], 0, MAX_STATUSTEXT_LENGTH ); 74 | char *src = szBuffer; 75 | char *dst = m_szStatusBar[line_num]; 76 | 77 | char *src_start = src, *dst_start = dst; 78 | 79 | while ( *src != 0 ) 80 | { 81 | while ( *src == '\n' ) 82 | src++; // skip over any newlines 83 | 84 | if ( ((src - src_start) >= MAX_STATUSTEXT_LENGTH) || ((dst - dst_start) >= MAX_STATUSTEXT_LENGTH) ) 85 | break; 86 | 87 | int index = atoi( src ); 88 | // should we draw this line? 89 | if ( (index >= 0 && index < MAX_STATUSBAR_VALUES) && (m_iStatusValues[index] != 0) ) 90 | { // parse this line and append result to the status bar 91 | while ( *src >= '0' && *src <= '9' ) 92 | src++; 93 | 94 | if ( *src == '\n' || *src == 0 ) 95 | continue; // no more left in this text line 96 | 97 | // copy the text, char by char, until we hit a % or a \n 98 | while ( *src != '\n' && *src != 0 ) 99 | { 100 | if ( *src != '%' ) 101 | { // just copy the character 102 | *dst = *src; 103 | dst++, src++; 104 | } 105 | else 106 | { 107 | // get the descriptor 108 | char valtype = *(++src); // move over % 109 | 110 | // if it's a %, draw a % sign 111 | if ( valtype == '%' ) 112 | { 113 | *dst = valtype; 114 | dst++, src++; 115 | continue; 116 | } 117 | 118 | // move over descriptor, then get and move over the index 119 | index = atoi( ++src ); 120 | while ( *src >= '0' && *src <= '9' ) 121 | src++; 122 | 123 | if ( index >= 0 && index < MAX_STATUSBAR_VALUES ) 124 | { 125 | int indexval = m_iStatusValues[index]; 126 | 127 | // get the string to substitute in place of the %XX 128 | char szRepString[MAX_PLAYER_NAME_LENGTH]; 129 | switch ( valtype ) 130 | { 131 | case 'p': // player name 132 | GetPlayerInfo( indexval, &gHUD.m_Scoreboard.m_PlayerInfoList[indexval], 0 ); 133 | if ( gHUD.m_Scoreboard.m_PlayerInfoList[indexval].name != NULL ) 134 | { 135 | strncpy( szRepString, gHUD.m_Scoreboard.m_PlayerInfoList[indexval].name, MAX_PLAYER_NAME_LENGTH ); 136 | } 137 | else 138 | { 139 | Q_strcpy( szRepString, "******" ); 140 | } 141 | break; 142 | case 'i': // number 143 | Sys_sprintf( szRepString, "%d", indexval ); 144 | break; 145 | default: 146 | szRepString[0] = 0; 147 | } 148 | 149 | for ( char *cp = szRepString; *cp != 0 && ((dst - dst_start) < MAX_STATUSTEXT_LENGTH); cp++, dst++ ) 150 | *dst = *cp; 151 | } 152 | } 153 | } 154 | } 155 | else 156 | { 157 | // skip to next line of text 158 | while ( *src != 0 && *src != '\n' ) 159 | src++; 160 | } 161 | } 162 | } 163 | 164 | int CHudStatusBar :: Draw( float fTime, int player ) 165 | { 166 | if ( m_bReparseString ) 167 | { 168 | for ( int i = 0; i < MAX_STATUSBAR_LINES; i++ ) 169 | ParseStatusString( i ); 170 | m_bReparseString = FALSE; 171 | } 172 | 173 | // Draw the status bar lines 174 | for ( int i = 0; i < MAX_STATUSBAR_LINES; i++ ) 175 | { 176 | int TextHeight, TextWidth; 177 | GetConsoleStringSize( m_szStatusBar[i], &TextWidth, &TextHeight ); 178 | 179 | int Y_START; 180 | if ( ScreenHeight >= 480 ) 181 | Y_START = ScreenHeight - 45; 182 | else 183 | Y_START = ScreenHeight - 35; 184 | 185 | int x = 5; 186 | int y = Y_START - ( TextHeight * i ); // draw along bottom of screen 187 | 188 | // let user set status ID bar centering 189 | if ( (i == STATUSBAR_ID_LINE) && CVAR_GET_FLOAT("hud_centerid") ) 190 | { 191 | x = max( 0, max(2, (ScreenWidth - TextWidth)) / 2 ); 192 | y = (ScreenHeight / 2) + (TextHeight*CVAR_GET_FLOAT("hud_centerid")); 193 | } 194 | 195 | DrawConsoleString( x, y, m_szStatusBar[i] ); 196 | } 197 | 198 | return 1; 199 | } 200 | 201 | // Message handler for StatusText message 202 | // accepts two values: 203 | // byte: line number of status bar text 204 | // string: status bar text 205 | // this string describes how the status bar should be drawn 206 | // a semi-regular expression: 207 | // ( slotnum ([a..z] [%pX] [%iX])*)* 208 | // where slotnum is an index into the Value table (see below) 209 | // if slotnum is 0, the string is always drawn 210 | // if StatusValue[slotnum] != 0, the following string is drawn, upto the next newline - otherwise the text is skipped upto next newline 211 | // %pX, where X is an integer, will substitute a player name here, getting the player index from StatusValue[X] 212 | // %iX, where X is an integer, will substitute a number here, getting the number from StatusValue[X] 213 | int CHudStatusBar :: MsgFunc_StatusText( int player, const char *pszName, int iSize, void *pbuf ) 214 | { 215 | BEGIN_READ( pbuf, iSize ); 216 | 217 | int line = READ_BYTE(); 218 | 219 | if ( line < 0 || line >= MAX_STATUSBAR_LINES ) 220 | return 1; 221 | 222 | strncpy( m_szStatusText[line], READ_STRING(), MAX_STATUSTEXT_LENGTH ); 223 | m_szStatusText[line][MAX_STATUSTEXT_LENGTH-1] = 0; // ensure it's null terminated ( strncpy() won't null terminate if read string too long) 224 | 225 | if ( m_szStatusText[0] == 0 ) 226 | m_iFlags &= ~HUD_ACTIVE; 227 | else 228 | m_iFlags |= HUD_ACTIVE; // we have status text, so turn on the status bar 229 | 230 | m_bReparseString = TRUE; 231 | 232 | return 1; 233 | } 234 | 235 | // Message handler for StatusText message 236 | // accepts two values: 237 | // byte: index into the status value array 238 | // short: value to store 239 | int CHudStatusBar :: MsgFunc_StatusValue( int player, const char *pszName, int iSize, void *pbuf ) 240 | { 241 | BEGIN_READ( pbuf, iSize ); 242 | 243 | int index = READ_BYTE(); 244 | if ( index < 1 || index >= MAX_STATUSBAR_VALUES ) 245 | return 1; // index out of range 246 | 247 | m_iStatusValues[index] = READ_SHORT(); 248 | 249 | m_bReparseString = TRUE; 250 | 251 | return 1; 252 | } -------------------------------------------------------------------------------- /cl_dll/text_message.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // 16 | // text_message.cpp 17 | // 18 | // implementation of CHudTextMessage class 19 | // 20 | // this class routes messages through titles.txt for localisation 21 | // 22 | 23 | #include "hud.h" 24 | #include "util.h" 25 | #include "parsemsg.h" 26 | 27 | DECLARE_MESSAGE( m_TextMessage, TextMsg ); 28 | 29 | int CHudTextMessage::Init(int player) 30 | { 31 | HOOK_MESSAGE( TextMsg ); 32 | 33 | gHUD.AddHudElem( this ); 34 | 35 | Reset(player); 36 | 37 | return 1; 38 | }; 39 | 40 | // Searches through the string for any msg names (indicated by a '#') 41 | // any found are looked up in titles.txt and the new message substituted 42 | // the new value is pushed into dst_buffer 43 | char *CHudTextMessage::LocaliseTextString( const char *msg, char *dst_buffer, int buffer_size ) 44 | { 45 | char *dst = dst_buffer; 46 | for ( char *src = (char*)msg; *src != 0 && buffer_size > 0; buffer_size-- ) 47 | { 48 | if ( *src == '#' ) 49 | { 50 | // cut msg name out of string 51 | static char word_buf[255]; 52 | char *wdst = word_buf, *word_start = src; 53 | for ( ++src ; *src >= 'A' && *src <= 'z'; wdst++, src++ ) 54 | { 55 | *wdst = *src; 56 | } 57 | *wdst = 0; 58 | 59 | // lookup msg name in titles.txt 60 | client_textmessage_t *clmsg = TextMessageGet( word_buf ); 61 | if ( !clmsg || !(clmsg->pMessage) ) 62 | { 63 | src = word_start; 64 | *dst = *src; 65 | dst++, src++; 66 | continue; 67 | } 68 | 69 | // copy string into message over the msg name 70 | for ( char *wsrc = (char*)clmsg->pMessage; *wsrc != 0; wsrc++, dst++ ) 71 | { 72 | *dst = *wsrc; 73 | } 74 | *dst = 0; 75 | } 76 | else 77 | { 78 | *dst = *src; 79 | dst++, src++; 80 | *dst = 0; 81 | } 82 | } 83 | 84 | dst_buffer[buffer_size-1] = 0; // ensure null termination 85 | return dst_buffer; 86 | } 87 | 88 | // As above, but with a local static buffer 89 | char *CHudTextMessage::BufferedLocaliseTextString( const char *msg ) 90 | { 91 | char dst_buffer[1024]; 92 | return LocaliseTextString( msg, dst_buffer, 1024 ); 93 | } 94 | 95 | // Simplified version of LocaliseTextString; assumes string is only one word 96 | char *CHudTextMessage::LookupString( const char *msg, int *msg_dest ) 97 | { 98 | if ( !msg ) 99 | return ""; 100 | 101 | // '#' character indicates this is a reference to a string in titles.txt, and not the string itself 102 | if ( msg[0] == '#' ) 103 | { 104 | // this is a message name, so look up the real message 105 | client_textmessage_t *clmsg = TextMessageGet( msg+1 ); 106 | 107 | if ( !clmsg || !(clmsg->pMessage) ) 108 | return (char*)msg; // lookup failed, so return the original string 109 | 110 | if ( msg_dest ) 111 | { 112 | // check to see if titles.txt info overrides msg destination 113 | // if clmsg->effect is less than 0, then clmsg->effect holds -1 * message_destination 114 | if ( clmsg->effect < 0 ) // 115 | *msg_dest = -clmsg->effect; 116 | } 117 | 118 | return (char*)clmsg->pMessage; 119 | } 120 | else 121 | { // nothing special about this message, so just return the same string 122 | return (char*)msg; 123 | } 124 | } 125 | 126 | void StripEndNewlineFromString( char *str ) 127 | { 128 | int s = strlen( str ) - 1; 129 | if ( str[s] == '\n' || str[s] == '\r' ) 130 | str[s] = 0; 131 | } 132 | 133 | // converts all '\r' characters to '\n', so that the engine can deal with the properly 134 | // returns a pointer to str 135 | char* ConvertCRtoNL( char *str ) 136 | { 137 | for ( char *ch = str; *ch != 0; ch++ ) 138 | if ( *ch == '\r' ) 139 | *ch = '\n'; 140 | return str; 141 | } 142 | 143 | // Message handler for text messages 144 | // displays a string, looking them up from the titles.txt file, which can be localised 145 | // parameters: 146 | // byte: message direction ( HUD_PRINTCONSOLE, HUD_PRINTNOTIFY, HUD_PRINTCENTER, HUD_PRINTTALK ) 147 | // string: message 148 | // optional parameters: 149 | // string: message parameter 1 150 | // string: message parameter 2 151 | // string: message parameter 3 152 | // string: message parameter 4 153 | // any string that starts with the character '#' is a message name, and is used to look up the real message in titles.txt 154 | // the next (optional) one to four strings are parameters for that string (which can also be message names if they begin with '#') 155 | int CHudTextMessage::MsgFunc_TextMsg( int player, const char *pszName, int iSize, void *pbuf ) 156 | { 157 | BEGIN_READ(pbuf, iSize); 158 | 159 | int msg_dest = READ_BYTE(); 160 | 161 | static char szBuf[6][128]; 162 | char* msg_text = LookupString(READ_STRING(), &msg_dest); 163 | msg_text = strcpy(szBuf[0], msg_text); 164 | 165 | // keep reading strings and using C format strings for subsituting the strings into the localised text string 166 | char* sstr1 = LookupString(READ_STRING()); 167 | sstr1 = strcpy(szBuf[1], sstr1); 168 | StripEndNewlineFromString(sstr1); // these strings are meant for subsitution into the main strings, so cull the automatic end newlines 169 | char* sstr2 = LookupString(READ_STRING()); 170 | sstr2 = strcpy(szBuf[2], sstr2); 171 | StripEndNewlineFromString(sstr2); 172 | char* sstr3 = LookupString(READ_STRING()); 173 | sstr3 = strcpy(szBuf[3], sstr3); 174 | StripEndNewlineFromString(sstr3); 175 | char* sstr4 = LookupString(READ_STRING()); 176 | sstr4 = strcpy(szBuf[4], sstr4); 177 | StripEndNewlineFromString(sstr4); 178 | char* psz = szBuf[5]; 179 | 180 | switch ( msg_dest ) 181 | { 182 | case HUD_PRINTCENTER: 183 | Sys_sprintf( psz, msg_text, sstr1, sstr2, sstr3, sstr4 ); 184 | CenterPrint( ConvertCRtoNL( psz ) ); 185 | break; 186 | 187 | case HUD_PRINTNOTIFY: 188 | psz[0] = 1; // mark this message to go into the notify buffer 189 | Sys_sprintf( psz+1, msg_text, sstr1, sstr2, sstr3, sstr4 ); 190 | ConsolePrint( ConvertCRtoNL( psz ) ); 191 | break; 192 | 193 | case HUD_PRINTTALK: 194 | Sys_sprintf( psz, msg_text, sstr1, sstr2, sstr3, sstr4 ); 195 | gHUD.m_SayText.SayTextPrint( ConvertCRtoNL( psz ), 128, player ); 196 | break; 197 | 198 | case HUD_PRINTCONSOLE: 199 | Sys_sprintf( psz, msg_text, sstr1, sstr2, sstr3, sstr4 ); 200 | ConsolePrint( ConvertCRtoNL( psz ) ); 201 | break; 202 | } 203 | 204 | return 1; 205 | } 206 | -------------------------------------------------------------------------------- /cl_dll/train.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // 16 | // Train.cpp 17 | // 18 | // implementation of CHudAmmo class 19 | // 20 | 21 | #include "hud.h" 22 | #include "util.h" 23 | #include "parsemsg.h" 24 | 25 | DECLARE_MESSAGE(m_Train, Train ) 26 | 27 | 28 | int CHudTrain::Init(int player) 29 | { 30 | HOOK_MESSAGE( Train ); 31 | 32 | m_iPos = 0; 33 | m_iFlags = 0; 34 | gHUD.AddHudElem(this); 35 | 36 | return 1; 37 | }; 38 | 39 | int CHudTrain::VidInit(int player) 40 | { 41 | m_hSprite = 0; 42 | 43 | return 1; 44 | }; 45 | 46 | int CHudTrain::Draw(float fTime, int player) 47 | { 48 | if ( !m_hSprite ) 49 | m_hSprite = LoadSprite("sprites/%d_train.spz"); 50 | 51 | if (m_iPos) 52 | { 53 | int r, g, b, x, y; 54 | 55 | UnpackRGB(r,g,b, RGB_YELLOWISH); 56 | SPR_Set(m_hSprite, r, g, b ); 57 | 58 | // This should show up to the right and part way up the armor number 59 | y = ScreenHeight - SPR_Height(m_hSprite,0) - gHUD.m_iFontHeight; 60 | x = ScreenWidth/3 + SPR_Width(m_hSprite,0)/4; 61 | 62 | SPR_DrawAdditive( m_iPos - 1, x, y, NULL); 63 | 64 | } 65 | 66 | return 1; 67 | } 68 | 69 | 70 | int CHudTrain::MsgFunc_Train(int player, const char *pszName, int iSize, void *pbuf) 71 | { 72 | BEGIN_READ( pbuf, iSize ); 73 | 74 | // update Train data 75 | m_iPos = READ_BYTE(); 76 | 77 | if (m_iPos) 78 | m_iFlags |= HUD_ACTIVE; 79 | else 80 | m_iFlags &= ~HUD_ACTIVE; 81 | 82 | return 1; 83 | } 84 | -------------------------------------------------------------------------------- /cl_dll/util.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // 16 | // util.cpp 17 | // 18 | // implementation of class-less helper functions 19 | // 20 | 21 | #include "STDIO.H" 22 | #include "STDLIB.H" 23 | #include "MATH.H" 24 | 25 | #include "hud.h" 26 | #include "util.h" 27 | #include 28 | 29 | 30 | 31 | HSPRITE LoadSprite(const char *pszName) 32 | { 33 | int i; 34 | char sz[256]; 35 | 36 | if (ScreenWidth < 512) 37 | i = 320; 38 | else 39 | i = 640; 40 | 41 | Sys_sprintf(sz, pszName, i); 42 | 43 | return SPR_Load(sz); 44 | } 45 | 46 | -------------------------------------------------------------------------------- /cl_dll/util.h: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // 16 | // util.h 17 | // 18 | 19 | #include "cvardef.h" 20 | 21 | // Macros to hook function calls into the HUD object 22 | #define HOOK_MESSAGE(x) gEngfuncs.pfnHookUserMsg(#x, __MsgFunc_##x, player ); 23 | 24 | #define DECLARE_MESSAGE(y, x) int __MsgFunc_##x(int player, const char *pszName, int iSize, void *pbuf) \ 25 | { \ 26 | return gHUD.y.MsgFunc_##x(player, pszName, iSize, pbuf ); \ 27 | } 28 | 29 | 30 | #define HOOK_COMMAND(x, y) gEngfuncs.pfnAddCommand( x, __CmdFunc_##y ); 31 | #define DECLARE_COMMAND(y, x) void __CmdFunc_##x( void ) \ 32 | { \ 33 | char* a1 = gEngfuncs.Cmd_Argv(1); \ 34 | int player = atoi(a1); \ 35 | gHUD.y.UserCmd_##x(player); \ 36 | } 37 | 38 | inline float CVAR_GET_FLOAT( const char *x ) { return gEngfuncs.pfnGetCvarFloat( (char*)x ); } 39 | inline char* CVAR_GET_STRING( const char *x ) { return gEngfuncs.pfnGetCvarString( (char*)x ); } 40 | inline void CVAR_CREATE( const char *cv, const char *val, const int flags ) { gEngfuncs.pfnRegisterVariable( (char*)cv, (char*)val, flags ); } 41 | 42 | #define SPR_Load (*gEngfuncs.pfnSPR_Load) 43 | #define SPR_Set (*gEngfuncs.pfnSPR_Set) 44 | #define SPR_Frames (*gEngfuncs.pfnSPR_Frames) 45 | #define SPR_GetList (*gEngfuncs.pfnSPR_GetList) 46 | 47 | // SPR_Draw draws a the current sprite as solid 48 | #define SPR_Draw (*gEngfuncs.pfnSPR_Draw) 49 | // SPR_DrawHoles draws the current sprites, with color index255 not drawn (transparent) 50 | #define SPR_DrawHoles (*gEngfuncs.pfnSPR_DrawHoles) 51 | // SPR_DrawAdditive adds the sprites RGB values to the background (additive transulency) 52 | #define SPR_DrawAdditive (*gEngfuncs.pfnSPR_DrawAdditive) 53 | 54 | // SPR_EnableScissor sets a clipping rect for HUD sprites. (0,0) is the top-left hand corner of the screen. 55 | #define SPR_EnableScissor (*gEngfuncs.pfnSPR_EnableScissor) 56 | // SPR_DisableScissor disables the clipping rect 57 | #define SPR_DisableScissor (*gEngfuncs.pfnSPR_DisableScissor) 58 | // 59 | #define FillRGBA (*gEngfuncs.pfnFillRGBA) 60 | 61 | 62 | // ScreenHeight returns the height of the screen, in pixels 63 | #define ScreenHeight (gHUD.m_scrinfo.iHeight) 64 | // ScreenWidth returns the width of the screen, in pixels 65 | #define ScreenWidth (gHUD.m_scrinfo.iWidth) 66 | 67 | #define GetScreenInfo (*gEngfuncs.pfnGetScreenInfo) 68 | #define ServerCmd (*gEngfuncs.pfnServerCmd) 69 | #define ClientCmd (*gEngfuncs.pfnClientCmd) 70 | #define SetCrosshair (*gEngfuncs.pfnSetCrosshair) 71 | #define AngleVectors (*gEngfuncs.pfnAngleVectors) 72 | 73 | 74 | // Gets the height & width of a sprite, at the specified frame 75 | inline int SPR_Height( HSPRITE x, int f ) { return gEngfuncs.pfnSPR_Height(x, f); } 76 | inline int SPR_Width( HSPRITE x, int f ) { return gEngfuncs.pfnSPR_Width(x, f); } 77 | 78 | inline client_textmessage_t *TextMessageGet( const char *pName ) { return gEngfuncs.pfnTextMessageGet( pName ); } 79 | inline int TextMessageDrawChar( int x, int y, int number, int r, int g, int b ) 80 | { 81 | return gEngfuncs.pfnDrawCharacter( x, y, number, r, g, b ); 82 | } 83 | 84 | inline int DrawConsoleString( int x, int y, const char *string ) 85 | { 86 | return gEngfuncs.pfnDrawConsoleString( x, y, (char*) string ); 87 | } 88 | 89 | inline void GetConsoleStringSize( const char *string, int *width, int *height ) 90 | { 91 | gEngfuncs.pfnDrawConsoleStringLen( string, width, height ); 92 | } 93 | 94 | inline int ConsoleStringLen( const char *string ) 95 | { 96 | int _width, _height; 97 | GetConsoleStringSize( string, &_width, &_height ); 98 | return _width; 99 | } 100 | 101 | inline void ConsolePrint( const char *string ) 102 | { 103 | gEngfuncs.pfnConsolePrint( string ); 104 | } 105 | 106 | inline void CenterPrint( const char *string ) 107 | { 108 | gEngfuncs.pfnCenterPrint( string ); 109 | } 110 | 111 | // returns the players name of entity no. 112 | #define GetPlayerInfo (*gEngfuncs.pfnGetPlayerInfo) 113 | 114 | // sound functions 115 | inline void PlaySound( char *szSound, int player ) { gEngfuncs.pfnPlaySoundByName(szSound, player); } 116 | inline void PlaySound( int iSound, float vol ) { gEngfuncs.pfnPlaySoundByIndex( iSound, vol ); } 117 | 118 | #define max(a, b) (((a) > (b)) ? (a) : (b)) 119 | #define min(a, b) (((a) < (b)) ? (a) : (b)) 120 | #define fabs(x) ((x) > 0 ? (x) : 0 - (x)) 121 | 122 | void ScaleColors( int &r, int &g, int &b, int a ); 123 | 124 | #define DotProduct(x,y) ((x)[0]*(y)[0]+(x)[1]*(y)[1]+(x)[2]*(y)[2]) 125 | #define VectorSubtract(a,b,c) {(c)[0]=(a)[0]-(b)[0];(c)[1]=(a)[1]-(b)[1];(c)[2]=(a)[2]-(b)[2];} 126 | #define VectorAdd(a,b,c) {(c)[0]=(a)[0]+(b)[0];(c)[1]=(a)[1]+(b)[1];(c)[2]=(a)[2]+(b)[2];} 127 | #define VectorCopy(a,b) {(b)[0]=(a)[0];(b)[1]=(a)[1];(b)[2]=(a)[2];} 128 | 129 | inline void UnpackRGB(int &r, int &g, int &b, unsigned long ulRGB)\ 130 | {\ 131 | r = (ulRGB & 0xFF0000) >>16;\ 132 | g = (ulRGB & 0xFF00) >> 8;\ 133 | b = ulRGB & 0xFF;\ 134 | } 135 | 136 | HSPRITE LoadSprite(const char *pszName); 137 | -------------------------------------------------------------------------------- /cl_dll/util_vector.h: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // Vector.h 16 | // A subset of the extdll.h in the project HL Entity DLL 17 | // 18 | 19 | // Misc C-runtime library headers 20 | #include "STDIO.H" 21 | #include "STDLIB.H" 22 | #include "MATH.H" 23 | 24 | // Header file containing definition of globalvars_t and entvars_t 25 | typedef int func_t; // 26 | typedef int string_t; // from engine's pr_comp.h; 27 | typedef float vec_t; // needed before including progdefs.h 28 | 29 | //========================================================= 30 | // 2DVector - used for many pathfinding and many other 31 | // operations that are treated as planar rather than 3d. 32 | //========================================================= 33 | class Vector2D 34 | { 35 | public: 36 | inline Vector2D(void) { } 37 | inline Vector2D(float X, float Y) { x = X; y = Y; } 38 | inline Vector2D operator+(const Vector2D& v) const { return Vector2D(x+v.x, y+v.y); } 39 | inline Vector2D operator-(const Vector2D& v) const { return Vector2D(x-v.x, y-v.y); } 40 | inline Vector2D operator*(float fl) const { return Vector2D(x*fl, y*fl); } 41 | inline Vector2D operator/(float fl) const { return Vector2D(x/fl, y/fl); } 42 | 43 | inline float Length(void) const { return (float)sqrt(x*x + y*y ); } 44 | 45 | inline Vector2D Normalize ( void ) const 46 | { 47 | Vector2D vec2; 48 | 49 | float flLen = Length(); 50 | if ( flLen == 0 ) 51 | { 52 | return Vector2D( (float)0, (float)0 ); 53 | } 54 | else 55 | { 56 | flLen = 1 / flLen; 57 | return Vector2D( x * flLen, y * flLen ); 58 | } 59 | } 60 | 61 | vec_t x, y; 62 | }; 63 | 64 | inline float DotProduct(const Vector2D& a, const Vector2D& b) { return( a.x*b.x + a.y*b.y ); } 65 | inline Vector2D operator*(float fl, const Vector2D& v) { return v * fl; } 66 | 67 | //========================================================= 68 | // 3D Vector 69 | //========================================================= 70 | class Vector // same data-layout as engine's vec3_t, 71 | { // which is a vec_t[3] 72 | public: 73 | // Construction/destruction 74 | inline Vector(void) { } 75 | inline Vector(float X, float Y, float Z) { x = X; y = Y; z = Z; } 76 | inline Vector(double X, double Y, double Z) { x = (float)X; y = (float)Y; z = (float)Z; } 77 | inline Vector(int X, int Y, int Z) { x = (float)X; y = (float)Y; z = (float)Z; } 78 | inline Vector(const Vector& v) { x = v.x; y = v.y; z = v.z; } 79 | inline Vector(float rgfl[3]) { x = rgfl[0]; y = rgfl[1]; z = rgfl[2]; } 80 | 81 | // Operators 82 | inline Vector operator-(void) const { return Vector(-x,-y,-z); } 83 | inline int operator==(const Vector& v) const { return x==v.x && y==v.y && z==v.z; } 84 | inline int operator!=(const Vector& v) const { return !(*this==v); } 85 | inline Vector operator+(const Vector& v) const { return Vector(x+v.x, y+v.y, z+v.z); } 86 | inline Vector operator-(const Vector& v) const { return Vector(x-v.x, y-v.y, z-v.z); } 87 | inline Vector operator*(float fl) const { return Vector(x*fl, y*fl, z*fl); } 88 | inline Vector operator/(float fl) const { return Vector(x/fl, y/fl, z/fl); } 89 | 90 | // Methods 91 | inline void CopyToArray(float* rgfl) const { rgfl[0] = x, rgfl[1] = y, rgfl[2] = z; } 92 | inline float Length(void) const { return (float)sqrt(x*x + y*y + z*z); } 93 | operator float *() { return &x; } // Vectors will now automatically convert to float * when needed 94 | operator const float *() const { return &x; } // Vectors will now automatically convert to float * when needed 95 | inline Vector Normalize(void) const 96 | { 97 | float flLen = Length(); 98 | if (flLen == 0) return Vector(0,0,1); // ???? 99 | flLen = 1 / flLen; 100 | return Vector(x * flLen, y * flLen, z * flLen); 101 | } 102 | 103 | inline Vector2D Make2D ( void ) const 104 | { 105 | Vector2D Vec2; 106 | 107 | Vec2.x = x; 108 | Vec2.y = y; 109 | 110 | return Vec2; 111 | } 112 | inline float Length2D(void) const { return (float)sqrt(x*x + y*y); } 113 | 114 | // Members 115 | vec_t x, y, z; 116 | }; 117 | inline Vector operator*(float fl, const Vector& v) { return v * fl; } 118 | inline float DotProduct(const Vector& a, const Vector& b) { return(a.x*b.x+a.y*b.y+a.z*b.z); } 119 | inline Vector CrossProduct(const Vector& a, const Vector& b) { return Vector( a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x ); } 120 | 121 | #define vec3_t Vector 122 | -------------------------------------------------------------------------------- /dlls/cdll_dll.h: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // 16 | // cdll_dll.h 17 | 18 | // this file is included by both the game-dll and the client-dll, 19 | 20 | #ifndef CDLL_DLL_H 21 | #define CDLL_DLL_H 22 | 23 | #define MAX_WEAPONS 32 // ??? 24 | 25 | #define MAX_WEAPON_SLOTS 5 // hud item selection slots 26 | #define MAX_ITEM_TYPES 6 // hud item selection slots 27 | 28 | #define MAX_ITEMS 5 // hard coded item types 29 | 30 | #define HIDEHUD_WEAPONS ( 1<<0 ) 31 | #define HIDEHUD_FLASHLIGHT ( 1<<1 ) 32 | #define HIDEHUD_ALL ( 1<<2 ) 33 | #define HIDEHUD_HEALTH ( 1<<3 ) 34 | 35 | #define MAX_AMMO_TYPES 32 // ??? 36 | #define MAX_AMMO_SLOTS 32 // not really slots 37 | 38 | #define HUD_PRINTNOTIFY 1 39 | #define HUD_PRINTCONSOLE 2 40 | #define HUD_PRINTTALK 3 41 | #define HUD_PRINTCENTER 4 42 | 43 | 44 | #define WEAPON_SUIT 31 45 | 46 | #endif -------------------------------------------------------------------------------- /eemakefile.eeglobal: -------------------------------------------------------------------------------- 1 | # _____ ___ ____ ___ ____ 2 | # ____| | ____| | | |____| 3 | # | ___| |____ ___| ____| | \ PS2DEV Open Source Project. 4 | #----------------------------------------------------------------------- 5 | # Copyright 2001-2004, ps2dev - http://www.ps2dev.org 6 | # Licenced under Academic Free License version 2.0 7 | # Review ps2sdk README & LICENSE files for further details. 8 | 9 | # Helpers to make easy the use of lkernel-nopatch and newlib-nano 10 | NODEFAULTLIBS = 0 11 | LKERNEL = -lkernel 12 | ifeq ($(KERNEL_NOPATCH), 1) 13 | NODEFAULTLIBS = 1 14 | LKERNEL = -lkernel-nopatch 15 | endif 16 | 17 | LIBC = -lc 18 | LIBM = -lm 19 | ifeq ($(NEWLIB_NANO), 1) 20 | NODEFAULTLIBS = 1 21 | LIBC = -lc_nano 22 | LIBM = -lm_nano 23 | endif 24 | 25 | EXTRA_LDFLAGS = 26 | ifeq ($(NODEFAULTLIBS), 1) 27 | EXTRA_LDFLAGS = -nodefaultlibs $(LIBM) -Wl,--start-group $(LIBC) -lps2sdkc $(LKERNEL) -Wl,--end-group -lgcc 28 | endif 29 | 30 | # Include directories 31 | EE_INCS := -I$(PS2SDK)/ee/include -I$(PS2SDK)/common/include -I. $(EE_INCS) 32 | 33 | # Optimization compiler flags 34 | EE_OPTFLAGS ?= -O2 35 | 36 | # Warning compiler flags 37 | EE_WARNFLAGS ?= -Wall 38 | 39 | # C compiler flags 40 | EE_CFLAGS := -D_EE -G0 $(EE_OPTFLAGS) $(EE_WARNFLAGS) $(EE_CFLAGS) 41 | 42 | # C++ compiler flags 43 | EE_CXXFLAGS := -D_EE -G0 $(EE_OPTFLAGS) $(EE_WARNFLAGS) $(EE_CXXFLAGS) 44 | 45 | # Linker flags 46 | EE_LDFLAGS := -L$(PS2SDK)/ee/lib -Wl,-zmax-page-size=128 $(EXTRA_LDFLAGS) $(EE_LDFLAGS) 47 | 48 | # Assembler flags 49 | EE_ASFLAGS := -G0 $(EE_ASFLAGS) 50 | 51 | # Default link file 52 | ifeq ($(EE_LINKFILE),) 53 | EE_LINKFILE := $(PS2SDK)/ee/startup/linkfile 54 | endif 55 | 56 | # Externally defined variables: EE_BIN, EE_OBJS, EE_LIB 57 | 58 | # These macros can be used to simplify certain build rules. 59 | EE_C_COMPILE = $(EE_CC) $(EE_CFLAGS) $(EE_INCS) 60 | EE_CXX_COMPILE = $(EE_CXX) $(EE_CXXFLAGS) $(EE_INCS) 61 | 62 | %.o: %.c 63 | $(EE_CC) $(EE_CFLAGS) $(EE_INCS) -c $< -o $@ 64 | 65 | %.o: %.cc 66 | $(EE_CXX) $(EE_CXXFLAGS) $(EE_INCS) -c $< -o $@ 67 | 68 | %.o: %.cpp 69 | $(EE_CXX) $(EE_CXXFLAGS) $(EE_INCS) -c $< -o $@ 70 | 71 | %.o: %.S 72 | $(EE_CC) $(EE_CFLAGS) $(EE_INCS) -c $< -o $@ 73 | 74 | %.o: %.s 75 | $(EE_AS) $(EE_ASFLAGS) $< -o $@ 76 | 77 | $(EE_BIN): $(EE_OBJS) 78 | $(EE_CC) -T$(EE_LINKFILE) $(EE_OPTFLAGS) -o $(EE_BIN) $(EE_OBJS) $(EE_LDFLAGS) $(EE_LIBS) -nostartfiles 79 | 80 | $(EE_ERL): $(EE_OBJS) 81 | $(EE_CC) -mno-crt0 $(EE_OPTFLAGS) -o $(EE_ERL) $(EE_OBJS) $(EE_LDFLAGS) -Wl,-r -Wl,-d 82 | $(EE_STRIP) --strip-unneeded -R .mdebug.eabi64 -R .reginfo -R .comment $(EE_ERL) 83 | 84 | $(EE_LIB): $(EE_OBJS) 85 | $(EE_AR) cru $(EE_LIB) $(EE_OBJS) 86 | -------------------------------------------------------------------------------- /engine/Progs.h: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | #ifndef PROGS_H 16 | #define PROGS_H 17 | 18 | #include "progdefs.h" 19 | 20 | #ifndef EIFACE_H 21 | // Forward declare this type to avoid problems 22 | typedef struct saverestore_s SAVERESTOREDATA; 23 | #endif 24 | 25 | // Entity state is used for the baseline and for delta compression of a packet of 26 | // entities that is sent to a client. 27 | typedef struct 28 | { 29 | int entityType; // Normal or Custom to know how to parse the entity. 30 | int number; // Index into cl_entities array for this entity. 31 | int flags; // The delta compression bit header. 32 | 33 | vec3_t origin; 34 | vec3_t angles; 35 | 36 | int modelindex; 37 | int sequence; 38 | float frame; 39 | int colormap; 40 | short skin; 41 | short solid; 42 | int effects; 43 | float scale; 44 | 45 | // render information 46 | int rendermode; 47 | int renderamt; 48 | color24 rendercolor; 49 | int renderfx; 50 | 51 | // Added for entity delta compression 52 | //vec3_t msg_origins[2]; 53 | //vec3_t msg_angles[2]; 54 | 55 | int movetype; 56 | float animtime; 57 | float framerate; 58 | int body; 59 | byte controller[4]; 60 | byte blending[4]; 61 | vec3_t velocity; 62 | 63 | vec3_t mins; // Send bbox down to client for use during prediction. 64 | vec3_t maxs; 65 | 66 | int aiment; 67 | } entity_state_t; 68 | 69 | #define MAX_ENT_LEAFS 24 70 | typedef struct edict_s 71 | { 72 | qboolean free; 73 | int serialnumber; 74 | link_t area; // linked to a division node or leaf 75 | 76 | int num_leafs; 77 | short leafnums[MAX_ENT_LEAFS]; 78 | 79 | entity_state_t baseline; 80 | 81 | float freetime; // sv.time when the object was freed 82 | 83 | void* pvPrivateData; // Alloced and freed by engine, used by DLLs 84 | 85 | entvars_t v; // C exported fields from progs 86 | // other fields from progs come immediately after 87 | } edict_t; 88 | #define EDICT_FROM_AREA(l) STRUCT_FROM_LINK(l,edict_t,area) 89 | 90 | //============================================================================ 91 | 92 | extern char *pr_strings; 93 | extern globalvars_t gGlobalVariables; 94 | 95 | //============================================================================ 96 | 97 | edict_t *ED_Alloc (void); 98 | void ED_Free (edict_t *ed); 99 | 100 | char *ED_NewString (const char *string); 101 | // returns a copy of the string allocated from the server's string heap 102 | 103 | void ED_Print (edict_t *ed); 104 | void ED_Write (SAVERESTOREDATA *save, edict_t *ed); 105 | char *ED_ParseEdict (char *data, edict_t *ent); 106 | 107 | 108 | //void ED_WriteGlobals ( SAVERESTOREDATA *save ); 109 | //void ED_ParseGlobals (char *data); 110 | 111 | void ED_LoadFromFile (char *data); 112 | 113 | //define EDICT_NUM(n) ((edict_t *)(sv.edicts+ (n)*pr_edict_size)) 114 | //define NUM_FOR_EDICT(e) (((byte *)(e) - sv.edicts)/pr_edict_size) 115 | 116 | edict_t *EDICT_NUM(int n); 117 | int NUM_FOR_EDICT(const edict_t *e); 118 | 119 | #define EDICT_TO_PROG(e) ((byte *)e - (byte *)sv.edicts) 120 | #define PROG_TO_EDICT(e) ((edict_t *)((byte *)sv.edicts + e)) 121 | 122 | //============================================================================ 123 | 124 | #if 0 125 | #define G_FLOAT(o) (pr_globals[o]) 126 | #define G_INT(o) (*(int *)&pr_globals[o]) 127 | #define G_EDICT(o) ((edict_t *)((byte *)sv.edicts+ *(int *)&pr_globals[o])) 128 | #define G_EDICTNUM(o) NUM_FOR_EDICT(G_EDICT(o)) 129 | #define G_VECTOR(o) (&pr_globals[o]) 130 | #define G_STRING(o) (pr_strings + *(string_t *)&pr_globals[o]) 131 | #define G_FUNCTION(o) (*(func_t *)&pr_globals[o]) 132 | 133 | #define E_FLOAT(e,o) (((float*)&e->v)[o]) 134 | #define E_INT(e,o) (*(int *)&((float*)&e->v)[o]) 135 | #define E_VECTOR(e,o) (&((float*)&e->v)[o]) 136 | #endif 137 | #define E_STRING(e,o) (pr_strings + *(string_t *)&((char *)&e->v)[o]) 138 | 139 | extern int type_size[8]; 140 | 141 | void ED_PrintEdicts (void); 142 | void ED_PrintNum (int ent); 143 | 144 | 145 | #endif // PROGS_H -------------------------------------------------------------------------------- /engine/cdll_int.h: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // 16 | // cdll_int.h 17 | // 18 | // 4-23-98 19 | // JOHN: client dll interface declarations 20 | // 21 | 22 | #ifndef CDLL_INT_H 23 | #define CDLL_INT_H 24 | 25 | // this file is included by both the engine and the client-dll, 26 | // so make sure engine declarations aren't done twice 27 | 28 | typedef int HSPRITE; // handle to a graphic 29 | 30 | #define SCRINFO_SCREENFLASH 1 31 | #define SCRINFO_STRETCHED 2 32 | 33 | typedef struct 34 | { 35 | int iSize; 36 | int iWidth; 37 | int iHeight; 38 | int iFlags; 39 | int iCharHeight; 40 | short charWidths[256]; 41 | } SCREENINFO; 42 | 43 | 44 | typedef struct client_data_s 45 | { 46 | // fields that cannot be modified (ie. have no effect if changed) 47 | vec3_t origin; 48 | 49 | // fields that can be changed by the cldll 50 | float viewheight; 51 | float maxspeed; 52 | vec3_t viewangles; 53 | vec3_t punchangle; 54 | int iKeyBits; // Keyboard bits 55 | int iWeaponBits; 56 | float fov; // field of view 57 | float view_idlescale; // view shake/rotate 58 | float mouse_sensitivity; 59 | 60 | } client_data_t; 61 | 62 | typedef struct client_sprite_s 63 | { 64 | char szName[64]; 65 | char szSprite[64]; 66 | int hspr; 67 | int iRes; 68 | wrect_t rc; 69 | } client_sprite_t; 70 | 71 | typedef struct 72 | { 73 | int effect; 74 | byte r1, g1, b1, a1; // 2 colors for effects 75 | byte r2, g2, b2, a2; 76 | float x; 77 | float y; 78 | float fadein; 79 | float fadeout; 80 | float holdtime; 81 | float fxtime; 82 | const char *pName; 83 | const char *pMessage; 84 | } client_textmessage_t; 85 | 86 | typedef struct 87 | { 88 | char *name; 89 | short ping; 90 | byte thisplayer; // TRUE if this is the calling player 91 | 92 | // stuff that's unused at the moment, but should be done 93 | byte spectator; 94 | byte packetloss; 95 | 96 | char *model; 97 | short topcolor; 98 | short bottomcolor; 99 | 100 | } hud_player_info_t; 101 | 102 | 103 | // this is by no means complete, or even accurate 104 | typedef struct cl_enginefuncs_s 105 | { 106 | // sprite handlers 107 | HSPRITE (*pfnSPR_Load) ( const char *szPicName ); 108 | int (*pfnSPR_Frames) ( HSPRITE hPic ); 109 | int (*pfnSPR_Height) ( HSPRITE hPic, int frame ); 110 | int (*pfnSPR_Width) ( HSPRITE hPic, int frame ); 111 | void (*pfnSPR_Set) ( HSPRITE hPic, int r, int g, int b ); 112 | void (*pfnSPR_Draw) ( int frame, int x, int y, const wrect_t *prc); 113 | void (*pfnSPR_DrawHoles) ( int frame, int x, int y, const wrect_t *prc ); 114 | void (*pfnSPR_DrawAdditive) ( int frame, int x, int y, const wrect_t *prc ); 115 | void (*pfnSPR_EnableScissor) ( int x, int y, int width, int height ); 116 | void (*pfnSPR_DisableScissor)( void ); 117 | client_sprite_t *(*pfnSPR_GetList) ( char *psz, int *piCount); 118 | 119 | // screen handlers 120 | void (*pfnFillRGBA) ( int x, int y, int width, int height, int r, int g, int b, int a); 121 | int (*pfnGetScreenInfo) ( SCREENINFO *pscrinfo); 122 | void (*pfnSetCrosshair) ( HSPRITE hspr, wrect_t* rc, int r, int g, int b, int player); 123 | 124 | // cvar handlers 125 | int (*pfnRegisterVariable) ( char *szName, char *szValue, int flags ); 126 | float (*pfnGetCvarFloat) ( char *szName ); 127 | char* (*pfnGetCvarString) ( char *szName ); 128 | 129 | // command handlers 130 | int (*pfnAddCommand) ( char *cmd_name, void (*function)(void) ); 131 | int (*pfnHookUserMsg) ( char *szMsgName, pfnUserMsgHook pfn, int player ); 132 | int (*pfnServerCmd) ( char *szCmdString, int player ); 133 | int (*pfnClientCmd) ( char *szCmdString ); 134 | 135 | char* (*Cmd_Argv) ( int arg ); 136 | int (*Cmd_Argc) ( ); 137 | 138 | void (*pfnGetPlayerInfo) (int ent_num, hud_player_info_t* pinfo, int player); 139 | 140 | // sound handlers 141 | void (*pfnPlaySoundByName) ( char *szSound, int player ); 142 | void (*pfnPlayGlobalSoundByName) (char* szSound, float volume); 143 | void (*pfnPlaySoundByIndex) ( int iSound, float volume ); 144 | 145 | // vector helpers 146 | void (*pfnAngleVectors) (const float * vecAngles, float * forward, float * right, float * up); 147 | 148 | // text message system 149 | client_textmessage_t* (*pfnTextMessageGet) (const char* pName); 150 | int (*pfnDrawCharacter) (int x, int y, int number, int r, int g, int b); 151 | int (*pfnDrawConsoleString) (int x, int y, char* string); 152 | void (*pfnDrawConsoleStringLen) (const char* string, int* length, int* height); 153 | void (*pfnConsolePrint) (const char* string); 154 | void (*pfnCenterPrint) (const char* string); 155 | 156 | } cl_enginefunc_t; 157 | 158 | 159 | // ! duplicate macro's! really bad coding practice 160 | // buttons 161 | #define IN_ATTACK (1 << 0) 162 | #define IN_JUMP (1 << 1) 163 | #define IN_DUCK (1 << 2) 164 | #define IN_FORWARD (1 << 3) 165 | #define IN_BACK (1 << 4) 166 | #define IN_USE (1 << 5) 167 | #define IN_CANCEL (1 << 6) 168 | #define IN_LEFT (1 << 7) 169 | #define IN_RIGHT (1 << 8) 170 | #define IN_MOVELEFT (1 << 9) 171 | #define IN_MOVERIGHT (1 << 10) 172 | #define IN_ATTACK2 (1 << 11) 173 | #define IN_RUN (1 << 12) 174 | #define IN_RELOAD (1 << 13) 175 | #define IN_ALT1 (1 << 14) 176 | #define IN_ALT2 (1 << 15) 177 | 178 | 179 | #define CLDLL_INTERFACE_VERSION 6 180 | 181 | extern void ClientDLL_Init( void ); // from cdll_int.c 182 | extern void ClientDLL_Shutdown( void ); 183 | extern void ClientDLL_HudInit( void ); 184 | extern void ClientDLL_HudVidInit( void ); 185 | extern void ClientDLL_UpdateClientData( void ); 186 | extern void ClientDLL_HudRedraw( int intermission ); 187 | 188 | 189 | #endif // CDLL_INT_H 190 | -------------------------------------------------------------------------------- /engine/custom.h: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // Customization.h 16 | 17 | #ifndef INC_CUSTOMIZATION 18 | #define INC_CUSTOMIZATION 19 | 20 | #define MAX_QPATH 64 // Must match value in quakedefs.h 21 | 22 | ///////////////// 23 | // Customization 24 | // passed to pfnPlayerCustomization 25 | // For automatic downloading. 26 | typedef enum 27 | { 28 | t_sound, 29 | t_skin, 30 | t_model, 31 | t_decal, 32 | t_generic 33 | } resourcetype_t; 34 | 35 | #define RES_FATALIFMISSING (1<<0) // Disconnect if we can't get this file. 36 | #define RES_WASMISSING (1<<1) // Do we have the file locally, did we get it ok? 37 | #define RES_CUSTOM (1<<2) // Is this resource one that corresponds to another player's customization 38 | // or is it a server startup resource. 39 | // MD5 Hash 40 | typedef struct 41 | { 42 | unsigned int buf[4]; 43 | unsigned int bits[2]; 44 | unsigned char in[64]; 45 | } MD5Context_t; 46 | 47 | typedef struct resource_s 48 | { 49 | char szFileName[MAX_QPATH]; // File name to download/precache. 50 | resourcetype_t type; // t_sound, t_skin, t_model, t_decal. 51 | int nIndex; // For t_decals 52 | int nDownloadSize; // Size in Bytes if this must be downloaded. 53 | unsigned char ucFlags; 54 | 55 | // For handling client to client resource propagation 56 | unsigned char rgucMD5_hash[16]; // To determine if we already have it. 57 | unsigned char playernum; // Which player index this resource is associated with, if it's a custom resource. 58 | 59 | struct resource_s *pNext; // Next in chain. 60 | struct resource_s *pPrev; 61 | } resource_t; 62 | 63 | typedef struct customization_s 64 | { 65 | qboolean bInUse; // Is this customization in use; 66 | resource_t resource; // The resource_t for this customization 67 | qboolean bTranslated; // Has the raw data been translated into a useable format? 68 | // (e.g., raw decal .wad make into texture_t *) 69 | int nUserData1; // Customization specific data 70 | int nUserData2; // Customization specific data 71 | void *pInfo; // Buffer that holds the data structure that references the data (e.g., the cachewad_t) 72 | void *pBuffer; // Buffer that holds the data for the customization (the raw .wad data) 73 | struct customization_s *pNext; // Next in chain 74 | } customization_t; 75 | 76 | #endif // !Customization -------------------------------------------------------------------------------- /engine/customentity.h: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | #ifndef CUSTOMENTITY_H 16 | #define CUSTOMENTITY_H 17 | 18 | 19 | // Custom Entities 20 | #define CUSTOM_TYPE ( (1<>CUSTOM_SHIFT) 24 | #define SET_CUSTOM_TYPE(customType) ( ((customType<>12)&0xF) 67 | 68 | // Beam types, encoded as a byte 69 | enum 70 | { 71 | BEAM_POINTS = 0, 72 | BEAM_ENTPOINT, 73 | BEAM_ENTS, 74 | BEAM_HOSE, 75 | }; 76 | 77 | #define BEAM_FSINE 0x10 78 | #define BEAM_FSOLID 0x20 79 | #define BEAM_FSHADEIN 0x40 80 | #define BEAM_FSHADEOUT 0x80 81 | 82 | #endif //CUSTOMENTITY_H 83 | -------------------------------------------------------------------------------- /engine/cvardef.h: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | #ifndef CVARDEF_H 16 | #define CVARDEF_H 17 | 18 | #define FCVAR_ARCHIVE 1 // set to cause it to be saved to vars.rc 19 | #define FCVAR_USERINFO 2 // changes the client's info string 20 | #define FCVAR_SERVER 4 // notifies players when changed 21 | #define FCVAR_EXTDLL 8 // defined by external DLL 22 | #define FCVAR_CLIENTDLL 16 // defined by the client dll 23 | #define FCVAR_PROTECTED 32 // It's a server cvar, but we don't send the data since it's a password, etc. Sends 1 if it's not bland/zero, 0 otherwise as value 24 | #define FCVAR_SPONLY 64 // This cvar cannot be changed by clients connected to a multiplayer server. 25 | 26 | typedef struct cvar_s 27 | { 28 | char *name; 29 | char *string; 30 | int flags; 31 | float value; 32 | struct cvar_s *next; 33 | } cvar_t; 34 | #endif -------------------------------------------------------------------------------- /engine/progdefs.h: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | #ifndef PROGDEFS_H 16 | #define PROGDEFS_H 17 | 18 | 19 | typedef struct 20 | { 21 | float time; 22 | float frametime; 23 | float force_retouch; 24 | string_t mapname; 25 | string_t startspot; 26 | float deathmatch; 27 | float coop; 28 | float teamplay; 29 | float serverflags; 30 | float found_secrets; 31 | vec3_t v_forward; 32 | vec3_t v_up; 33 | vec3_t v_right; 34 | float trace_allsolid; 35 | float trace_startsolid; 36 | float trace_fraction; 37 | vec3_t trace_endpos; 38 | vec3_t trace_plane_normal; 39 | float trace_plane_dist; 40 | edict_t *trace_ent; 41 | float trace_inopen; 42 | float trace_inwater; 43 | int trace_hitgroup; 44 | int trace_flags; 45 | int msg_entity; 46 | int cdAudioTrack; 47 | int maxClients; 48 | int maxEntities; 49 | const char *pStringBase; 50 | 51 | void *pSaveData; 52 | vec3_t vecLandmarkOffset; 53 | } globalvars_t; 54 | 55 | 56 | typedef struct 57 | { 58 | string_t classname; 59 | string_t globalname; 60 | 61 | vec3_t origin; 62 | vec3_t oldorigin; 63 | vec3_t velocity; 64 | vec3_t basevelocity; 65 | vec3_t clbasevelocity; // Base velocity that was passed in to server physics so 66 | // client can predict conveyors correctly. Server zeroes it, so we need to store here, too. 67 | vec3_t movedir; 68 | 69 | vec3_t angles; // Model angles 70 | vec3_t avelocity; // angle velocity (degrees per second) 71 | vec3_t punchangle; // auto-decaying view angle adjustment 72 | vec3_t v_angle; // Viewing angle (player only) 73 | int fixangle; // 0:nothing, 1:force view angles, 2:add avelocity 74 | float idealpitch; 75 | float pitch_speed; 76 | float ideal_yaw; 77 | float yaw_speed; 78 | 79 | int modelindex; 80 | string_t model; 81 | 82 | int viewmodel; // player's viewmodel 83 | int weaponmodel; // what other players see 84 | 85 | vec3_t absmin; // BB max translated to world coord 86 | vec3_t absmax; // BB max translated to world coord 87 | vec3_t mins; // local BB min 88 | vec3_t maxs; // local BB max 89 | vec3_t size; // maxs - mins 90 | 91 | float ltime; 92 | float nextthink; 93 | 94 | int movetype; 95 | int solid; 96 | 97 | int skin; 98 | int body; // sub-model selection for studiomodels 99 | int effects; 100 | 101 | float gravity; // % of "normal" gravity 102 | float friction; // inverse elasticity of MOVETYPE_BOUNCE 103 | 104 | int light_level; 105 | 106 | int sequence; // animation sequence 107 | int gaitsequence; // movement animation sequence for player (0 for none) 108 | float frame; // % playback position in animation sequences (0..255) 109 | float animtime; // world time when frame was set 110 | float framerate; // animation playback rate (-8x to 8x) 111 | byte controller[4]; // bone controller setting (0..255) 112 | byte blending[2]; // blending amount between sub-sequences (0..255) 113 | 114 | float scale; // sprite rendering scale (0..255) 115 | 116 | int rendermode; 117 | float renderamt; 118 | vec3_t rendercolor; 119 | int renderfx; 120 | 121 | float health; 122 | float frags; 123 | int weapons; // bit mask for available weapons 124 | float takedamage; 125 | 126 | int deadflag; 127 | vec3_t view_ofs; // eye position 128 | 129 | int button; 130 | int impulse; 131 | 132 | edict_t *chain; // Entity pointer when linked into a linked list 133 | edict_t *dmg_inflictor; 134 | edict_t *enemy; 135 | edict_t *aiment; // entity pointer when MOVETYPE_FOLLOW 136 | edict_t *owner; 137 | edict_t *groundentity; 138 | 139 | int spawnflags; 140 | int flags; 141 | 142 | int colormap; // lowbyte topcolor, highbyte bottomcolor 143 | int team; 144 | 145 | float max_health; 146 | float teleport_time; 147 | float armortype; 148 | float armorvalue; 149 | int waterlevel; 150 | int watertype; 151 | 152 | string_t target; 153 | string_t targetname; 154 | string_t netname; 155 | string_t message; 156 | 157 | float dmg_take; 158 | float dmg_save; 159 | float dmg; 160 | float dmgtime; 161 | 162 | string_t noise; 163 | string_t noise1; 164 | string_t noise2; 165 | string_t noise3; 166 | 167 | float speed; 168 | float air_finished; 169 | float pain_finished; 170 | float radsuit_finished; 171 | 172 | edict_t *pContainingEntity; 173 | } entvars_t; 174 | 175 | 176 | #endif // PROGDEFS_H -------------------------------------------------------------------------------- /engine/shake.h: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | #ifndef SHAKE_H 16 | #define SHAKE_H 17 | 18 | // Screen / View effects 19 | 20 | // screen shake 21 | extern int gmsgShake; 22 | 23 | // This structure is sent over the net to describe a screen shake event 24 | typedef struct 25 | { 26 | unsigned short amplitude; // FIXED 4.12 amount of shake 27 | unsigned short duration; // FIXED 4.12 seconds duration 28 | unsigned short frequency; // FIXED 8.8 noise frequency (low frequency is a jerk,high frequency is a rumble) 29 | } ScreenShake; 30 | 31 | extern void V_ApplyShake( vec3_t origin, vec3_t angles, float factor ); 32 | extern void V_CalcShake( void ); 33 | extern int V_ScreenShake( int player, const char *pszName, int iSize, void *pbuf ); 34 | extern int V_ScreenFade( int player, const char *pszName, int iSize, void *pbuf ); 35 | 36 | 37 | // Fade in/out 38 | extern int gmsgFade; 39 | 40 | #define FFADE_IN 0x0000 // Just here so we don't pass 0 into the function 41 | #define FFADE_OUT 0x0001 // Fade out (not in) 42 | #define FFADE_MODULATE 0x0002 // Modulate (don't blend) 43 | #define FFADE_STAYOUT 0x0004 // ignores the duration, stays faded out until new ScreenFade message received 44 | 45 | // This structure is sent over the net to describe a screen fade event 46 | typedef struct 47 | { 48 | unsigned short duration; // FIXED 4.12 seconds duration 49 | unsigned short holdTime; // FIXED 4.12 seconds duration until reset (fade & hold) 50 | short fadeFlags; // flags 51 | byte r, g, b, a; // fade to color ( max alpha ) 52 | } ScreenFade; 53 | 54 | #endif // SHAKE_H 55 | 56 | -------------------------------------------------------------------------------- /engine/studio.h: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1999, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | 16 | 17 | 18 | 19 | #ifndef _STUDIO_H_ 20 | #define _STUDIO_H_ 21 | 22 | /* 23 | ============================================================================== 24 | 25 | STUDIO MODELS 26 | 27 | Studio models are position independent, so the cache manager can move them. 28 | ============================================================================== 29 | */ 30 | 31 | 32 | #define MAXSTUDIOTRIANGLES 20000 // TODO: tune this 33 | #define MAXSTUDIOVERTS 2048 // TODO: tune this 34 | #define MAXSTUDIOSEQUENCES 256 // total animation sequences 35 | #define MAXSTUDIOSKINS 100 // total textures 36 | #define MAXSTUDIOSRCBONES 512 // bones allowed at source movement 37 | #define MAXSTUDIOBONES 128 // total bones actually used 38 | #define MAXSTUDIOMODELS 32 // sub-models per model 39 | #define MAXSTUDIOBODYPARTS 32 40 | #define MAXSTUDIOGROUPS 4 41 | #define MAXSTUDIOANIMATIONS 512 // per sequence 42 | #define MAXSTUDIOMESHES 256 43 | #define MAXSTUDIOEVENTS 1024 44 | #define MAXSTUDIOPIVOTS 256 45 | #define MAXSTUDIOCONTROLLERS 8 46 | 47 | typedef struct 48 | { 49 | int id; 50 | int version; 51 | 52 | char name[64]; 53 | int length; 54 | 55 | vec3_t eyeposition; // ideal eye position 56 | vec3_t min; // ideal movement hull size 57 | vec3_t max; 58 | 59 | vec3_t bbmin; // clipping bounding box 60 | vec3_t bbmax; 61 | 62 | int flags; 63 | 64 | int numbones; // bones 65 | int boneindex; 66 | 67 | int numbonecontrollers; // bone controllers 68 | int bonecontrollerindex; 69 | 70 | int numhitboxes; // complex bounding boxes 71 | int hitboxindex; 72 | 73 | int numseq; // animation sequences 74 | int seqindex; 75 | 76 | int numseqgroups; // demand loaded sequences 77 | int seqgroupindex; 78 | 79 | int numtextures; // raw textures 80 | int textureindex; 81 | int texturedataindex; 82 | 83 | int numskinref; // replaceable textures 84 | int numskinfamilies; 85 | int skinindex; 86 | 87 | int numbodyparts; 88 | int bodypartindex; 89 | 90 | int numattachments; // queryable attachable points 91 | int attachmentindex; 92 | 93 | int soundtable; 94 | int soundindex; 95 | int soundgroups; 96 | int soundgroupindex; 97 | 98 | int numtransitions; // animation node to animation node transition graph 99 | int transitionindex; 100 | } studiohdr_t; 101 | 102 | // header for demand loaded sequence group data 103 | typedef struct 104 | { 105 | int id; 106 | int version; 107 | 108 | char name[64]; 109 | int length; 110 | } studioseqhdr_t; 111 | 112 | // bones 113 | typedef struct 114 | { 115 | char name[32]; // bone name for symbolic links 116 | int parent; // parent bone 117 | int flags; // ?? 118 | int bonecontroller[6]; // bone controller index, -1 == none 119 | float value[6]; // default DoF values 120 | float scale[6]; // scale for delta DoF values 121 | } mstudiobone_t; 122 | 123 | 124 | // bone controllers 125 | typedef struct 126 | { 127 | int bone; // -1 == 0 128 | int type; // X, Y, Z, XR, YR, ZR, M 129 | float start; 130 | float end; 131 | int rest; // byte index value at rest 132 | int index; // 0-3 user set controller, 4 mouth 133 | } mstudiobonecontroller_t; 134 | 135 | // intersection boxes 136 | typedef struct 137 | { 138 | int bone; 139 | int group; // intersection group 140 | vec3_t bbmin; // bounding box 141 | vec3_t bbmax; 142 | } mstudiobbox_t; 143 | 144 | #ifndef ZONE_H 145 | typedef void *cache_user_t; 146 | #endif 147 | 148 | // demand loaded sequence groups 149 | typedef struct 150 | { 151 | char label[32]; // textual name 152 | char name[64]; // file name 153 | cache_user_t cache; // cache index pointer 154 | int data; // hack for group 0 155 | } mstudioseqgroup_t; 156 | 157 | // sequence descriptions 158 | typedef struct 159 | { 160 | char label[32]; // sequence label 161 | 162 | float fps; // frames per second 163 | int flags; // looping/non-looping flags 164 | 165 | int activity; 166 | int actweight; 167 | 168 | int numevents; 169 | int eventindex; 170 | 171 | int numframes; // number of frames per sequence 172 | 173 | int numpivots; // number of foot pivots 174 | int pivotindex; 175 | 176 | int motiontype; 177 | int motionbone; 178 | vec3_t linearmovement; 179 | int automoveposindex; 180 | int automoveangleindex; 181 | 182 | vec3_t bbmin; // per sequence bounding box 183 | vec3_t bbmax; 184 | 185 | int numblends; 186 | int animindex; // mstudioanim_t pointer relative to start of sequence group data 187 | // [blend][bone][X, Y, Z, XR, YR, ZR] 188 | 189 | int blendtype[2]; // X, Y, Z, XR, YR, ZR 190 | float blendstart[2]; // starting value 191 | float blendend[2]; // ending value 192 | int blendparent; 193 | 194 | int seqgroup; // sequence group for demand loading 195 | 196 | int entrynode; // transition node at entry 197 | int exitnode; // transition node at exit 198 | int nodeflags; // transition rules 199 | 200 | int nextseq; // auto advancing sequences 201 | } mstudioseqdesc_t; 202 | 203 | // events 204 | typedef struct 205 | { 206 | int frame; 207 | int event; 208 | int type; 209 | char options[64]; 210 | } mstudioevent_t; 211 | 212 | 213 | // pivots 214 | typedef struct 215 | { 216 | vec3_t org; // pivot point 217 | int start; 218 | int end; 219 | } mstudiopivot_t; 220 | 221 | // attachment 222 | typedef struct 223 | { 224 | char name[32]; 225 | int type; 226 | int bone; 227 | vec3_t org; // attachment point 228 | vec3_t vectors[3]; 229 | } mstudioattachment_t; 230 | 231 | typedef struct 232 | { 233 | unsigned short offset[6]; 234 | } mstudioanim_t; 235 | 236 | // animation frames 237 | typedef union 238 | { 239 | struct { 240 | byte valid; 241 | byte total; 242 | } num; 243 | short value; 244 | } mstudioanimvalue_t; 245 | 246 | 247 | 248 | // body part index 249 | typedef struct 250 | { 251 | char name[64]; 252 | int nummodels; 253 | int base; 254 | int modelindex; // index into models array 255 | } mstudiobodyparts_t; 256 | 257 | 258 | 259 | // skin info 260 | typedef struct 261 | { 262 | char name[64]; 263 | int flags; 264 | int width; 265 | int height; 266 | int index; 267 | } mstudiotexture_t; 268 | 269 | 270 | // skin families 271 | // short index[skinfamilies][skinref] 272 | 273 | // studio models 274 | typedef struct 275 | { 276 | char name[64]; 277 | 278 | int type; 279 | 280 | float boundingradius; 281 | 282 | int nummesh; 283 | int meshindex; 284 | 285 | int numverts; // number of unique vertices 286 | int vertinfoindex; // vertex bone info 287 | int vertindex; // vertex vec3_t 288 | int numnorms; // number of unique surface normals 289 | int norminfoindex; // normal bone info 290 | int normindex; // normal vec3_t 291 | 292 | int numgroups; // deformation groups 293 | int groupindex; 294 | } mstudiomodel_t; 295 | 296 | 297 | // vec3_t boundingbox[model][bone][2]; // complex intersection info 298 | 299 | 300 | // meshes 301 | typedef struct 302 | { 303 | int numtris; 304 | int triindex; 305 | int skinref; 306 | int numnorms; // per mesh normals 307 | int normindex; // normal vec3_t 308 | } mstudiomesh_t; 309 | 310 | // triangles 311 | #if 0 312 | typedef struct 313 | { 314 | short vertindex; // index into vertex array 315 | short normindex; // index into normal array 316 | short s,t; // s,t position on skin 317 | } mstudiotrivert_t; 318 | #endif 319 | 320 | // lighting options 321 | #define STUDIO_NF_FLATSHADE 0x0001 322 | #define STUDIO_NF_CHROME 0x0002 323 | #define STUDIO_NF_FULLBRIGHT 0x0004 324 | 325 | // motion flags 326 | #define STUDIO_X 0x0001 327 | #define STUDIO_Y 0x0002 328 | #define STUDIO_Z 0x0004 329 | #define STUDIO_XR 0x0008 330 | #define STUDIO_YR 0x0010 331 | #define STUDIO_ZR 0x0020 332 | #define STUDIO_LX 0x0040 333 | #define STUDIO_LY 0x0080 334 | #define STUDIO_LZ 0x0100 335 | #define STUDIO_AX 0x0200 336 | #define STUDIO_AY 0x0400 337 | #define STUDIO_AZ 0x0800 338 | #define STUDIO_AXR 0x1000 339 | #define STUDIO_AYR 0x2000 340 | #define STUDIO_AZR 0x4000 341 | #define STUDIO_TYPES 0x7FFF 342 | #define STUDIO_RLOOP 0x8000 // controller that wraps shortest distance 343 | 344 | // sequence flags 345 | #define STUDIO_LOOPING 0x0001 346 | 347 | // bone flags 348 | #define STUDIO_HAS_NORMALS 0x0001 349 | #define STUDIO_HAS_VERTICES 0x0002 350 | #define STUDIO_HAS_BBOX 0x0004 351 | #define STUDIO_HAS_CHROME 0x0008 // if any of the textures have chrome on them 352 | 353 | #define RAD_TO_STUDIO (32768.0/M_PI) 354 | #define STUDIO_TO_RAD (M_PI/32768.0) 355 | 356 | #endif -------------------------------------------------------------------------------- /linkfile: -------------------------------------------------------------------------------- 1 | ENTRY(__start); 2 | 3 | PHDRS { 4 | text PT_LOAD; 5 | } 6 | 7 | SECTIONS { 8 | .text BASE_ADDRESS : { 9 | _ftext = . ; 10 | *(.text) 11 | *(.text.*) 12 | *(.gnu.linkonce.t*) 13 | KEEP(*(.init)) 14 | KEEP(*(.fini)) 15 | QUAD(0) 16 | } :text 17 | 18 | PROVIDE(_etext = .); 19 | PROVIDE(etext = .); 20 | 21 | .reginfo : { *(.reginfo) } 22 | 23 | /* Global/static constructors and deconstructors. */ 24 | .ctors ALIGN(16): { 25 | KEEP(*crtbegin*.o(.ctors)) 26 | KEEP(*(EXCLUDE_FILE(*crtend*.o) .ctors)) 27 | KEEP(*(SORT(.ctors.*))) 28 | KEEP(*(.ctors)) 29 | } 30 | .dtors ALIGN(16): { 31 | KEEP(*crtbegin*.o(.dtors)) 32 | KEEP(*(EXCLUDE_FILE(*crtend*.o) .dtors)) 33 | KEEP(*(SORT(.dtors.*))) 34 | KEEP(*(.dtors)) 35 | } 36 | 37 | /* Static data. */ 38 | .rodata ALIGN(128): { 39 | *(.rodata) 40 | *(.rodata.*) 41 | *(.gnu.linkonce.r*) 42 | } 43 | 44 | .data ALIGN(128): { 45 | _fdata = . ; 46 | *(.data) 47 | *(.data.*) 48 | *(.gnu.linkonce.d*) 49 | SORT(CONSTRUCTORS) 50 | } 51 | 52 | .rdata ALIGN(128): { *(.rdata) } 53 | .gcc_except_table ALIGN(128): { *(.gcc_except_table) } 54 | 55 | _gp = ALIGN(128) + 0x7ff0; 56 | .lit4 ALIGN(128): { *(.lit4) } 57 | .lit8 ALIGN(128): { *(.lit8) } 58 | 59 | .sdata ALIGN(128): { 60 | *(.sdata) 61 | *(.sdata.*) 62 | *(.gnu.linkonce.s*) 63 | } 64 | 65 | _edata = .; 66 | PROVIDE(edata = .); 67 | 68 | /* Uninitialized data. */ 69 | .sbss ALIGN(128) : { 70 | _fbss = . ; 71 | *(.sbss) 72 | *(.sbss.*) 73 | *(.gnu.linkonce.sb*) 74 | *(.scommon) 75 | } 76 | 77 | .bss ALIGN(128) : { 78 | *(.bss) 79 | *(.bss.*) 80 | *(.gnu.linkonce.b*) 81 | *(COMMON) 82 | } 83 | _end_bss = .; 84 | 85 | _end = . ; 86 | PROVIDE(end = .); 87 | 88 | /* Symbols needed by crt0.s. */ 89 | PROVIDE(_heap_size = -1); 90 | PROVIDE(_stack = -1); 91 | PROVIDE(_stack_size = 128 * 1024); 92 | } -------------------------------------------------------------------------------- /linkfile_ps2: -------------------------------------------------------------------------------- 1 | /* 2 | # _____ ___ ____ ___ ____ 3 | # ____| | ____| | | |____| 4 | # | ___| |____ ___| ____| | \ PS2DEV Open Source Project. 5 | #----------------------------------------------------------------------- 6 | # Copyright 2001-2004, ps2dev - http://www.ps2dev.org 7 | # Licenced under Academic Free License version 2.0 8 | # Review ps2sdk README & LICENSE files for further details. 9 | # 10 | # Linkfile script for ee-ld 11 | */ 12 | 13 | ENTRY(__start); 14 | 15 | PHDRS { 16 | text PT_LOAD; 17 | } 18 | 19 | SECTIONS { 20 | 21 | 22 | .text BASE_ADDRESS : { 23 | _ftext = . ; 24 | *(.text) 25 | *(.text.*) 26 | *(.gnu.linkonce.t*) 27 | *(.rodata) 28 | *(.data) 29 | *(.rodata) 30 | *(.rodata.*) 31 | *.o(.text .rodata) 32 | KEEP(*(.init)) 33 | KEEP(*(.fini)) 34 | QUAD(0) 35 | } :text 36 | 37 | PROVIDE(_etext = .); 38 | PROVIDE(etext = .); 39 | 40 | 41 | /DISCARD/ : 42 | { 43 | *(.MIPS.abiflags) 44 | *(.reginfo) 45 | *(.gnu.attributes) 46 | } 47 | 48 | /* Static data. */ 49 | .data ALIGN(128): { 50 | _fdata = . ; 51 | *(.data) 52 | *(.data.*) 53 | *(.gnu.linkonce.d*) 54 | SORT(CONSTRUCTORS) 55 | } 56 | 57 | .rdata ALIGN(128): { *(.rdata) } 58 | .gcc_except_table ALIGN(128): { *(.gcc_except_table) } 59 | 60 | _gp = ALIGN(128) + 0x7ff0; 61 | .lit4 ALIGN(128): { *(.lit4) } 62 | .lit8 ALIGN(128): { *(.lit8) } 63 | 64 | .sdata ALIGN(128): { 65 | *(.sdata) 66 | *(.sdata.*) 67 | *(.gnu.linkonce.s*) 68 | } 69 | 70 | _edata = .; 71 | PROVIDE(edata = .); 72 | 73 | /* Uninitialized data. */ 74 | .sbss ALIGN(128) : { 75 | _fbss = . ; 76 | *(.sbss) 77 | *(.sbss.*) 78 | *(.gnu.linkonce.sb*) 79 | *(.scommon) 80 | } 81 | 82 | .bss ALIGN(128) : { 83 | *(.bss) 84 | *(.bss.*) 85 | *(.gnu.linkonce.b*) 86 | *(COMMON) 87 | } 88 | _end_bss = .; 89 | 90 | _end = . ; 91 | PROVIDE(end = .); 92 | 93 | /* Symbols needed by crt0.s. */ 94 | PROVIDE(_heap_size = -1); 95 | PROVIDE(_stack = -1); 96 | PROVIDE(_stack_size = 128 * 1024); 97 | } -------------------------------------------------------------------------------- /ps2/common.cpp: -------------------------------------------------------------------------------- 1 | typedef char byte; 2 | typedef unsigned int size_t; 3 | 4 | /* 5 | ============================================================================ 6 | 7 | LIBRARY REPLACEMENT FUNCTIONS 8 | 9 | ============================================================================ 10 | */ 11 | 12 | void Q_memset(void* dest, int fill, size_t count) 13 | { 14 | unsigned int i; 15 | 16 | if ((((long)dest | count) & 3) == 0) 17 | { 18 | count >>= 2; 19 | fill = fill | (fill << 8) | (fill << 16) | (fill << 24); 20 | for (i = 0; i < count; i++) 21 | ((int*)dest)[i] = fill; 22 | } 23 | else 24 | for (i = 0; i < count; i++) 25 | ((byte*)dest)[i] = fill; 26 | } 27 | 28 | void Q_memcpy(void* dest, void* src, size_t count) 29 | { 30 | unsigned int i; 31 | 32 | if ((((long)dest | (long)src | count) & 3) == 0) 33 | { 34 | count >>= 2; 35 | for (i = 0; i < count; i++) 36 | ((int*)dest)[i] = ((int*)src)[i]; 37 | } 38 | else 39 | for (i = 0; i < count; i++) 40 | ((byte*)dest)[i] = ((byte*)src)[i]; 41 | } 42 | 43 | int Q_memcmp(void* m1, void* m2, size_t count) 44 | { 45 | while (count) 46 | { 47 | count--; 48 | if (((byte*)m1)[count] != ((byte*)m2)[count]) 49 | return -1; 50 | } 51 | return 0; 52 | } 53 | 54 | void Q_strcpy(char* dest, char* src) 55 | { 56 | while (*src) 57 | { 58 | *dest++ = *src++; 59 | } 60 | *dest++ = 0; 61 | } 62 | 63 | void Q_strncpy(char* dest, char* src, size_t count) 64 | { 65 | while (*src && count--) 66 | { 67 | *dest++ = *src++; 68 | } 69 | if (count) 70 | *dest++ = 0; 71 | } 72 | 73 | int Q_strlen(char* str) 74 | { 75 | int count; 76 | 77 | count = 0; 78 | while (str[count]) 79 | count++; 80 | 81 | return count; 82 | } 83 | 84 | char* Q_strrchr(char* s, char c) 85 | { 86 | int len = Q_strlen(s); 87 | s += len; 88 | while (len--) 89 | if (*--s == c) return s; 90 | return 0; 91 | } 92 | 93 | void Q_strcat(char* dest, char* src) 94 | { 95 | dest += Q_strlen(dest); 96 | Q_strcpy(dest, src); 97 | } 98 | 99 | int Q_strcmp(char* s1, char* s2) 100 | { 101 | while (1) 102 | { 103 | if (*s1 != *s2) 104 | return -1; // strings not equal 105 | if (!*s1) 106 | return 0; // strings are equal 107 | s1++; 108 | s2++; 109 | } 110 | 111 | return -1; 112 | } 113 | 114 | int Q_strncmp(char* s1, char* s2, size_t count) 115 | { 116 | while (1) 117 | { 118 | if (!count--) 119 | return 0; 120 | if (*s1 != *s2) 121 | return -1; // strings not equal 122 | if (!*s1) 123 | return 0; // strings are equal 124 | s1++; 125 | s2++; 126 | } 127 | 128 | return -1; 129 | } 130 | 131 | int Q_strncasecmp(char* s1, char* s2, int n) 132 | { 133 | int c1, c2; 134 | 135 | while (1) 136 | { 137 | c1 = *s1++; 138 | c2 = *s2++; 139 | 140 | if (!n--) 141 | return 0; // strings are equal until end point 142 | 143 | if (c1 != c2) 144 | { 145 | if (c1 >= 'a' && c1 <= 'z') 146 | c1 -= ('a' - 'A'); 147 | if (c2 >= 'a' && c2 <= 'z') 148 | c2 -= ('a' - 'A'); 149 | if (c1 != c2) 150 | return -1; // strings not equal 151 | } 152 | if (!c1) 153 | return 0; // strings are equal 154 | // s1++; 155 | // s2++; 156 | } 157 | 158 | return -1; 159 | } 160 | 161 | int Q_strcasecmp(char* s1, char* s2) 162 | { 163 | return Q_strncasecmp(s1, s2, 99999); 164 | } 165 | 166 | int Q_atoi(char* str) 167 | { 168 | int val; 169 | int sign; 170 | int c; 171 | 172 | if (*str == '-') 173 | { 174 | sign = -1; 175 | str++; 176 | } 177 | else 178 | sign = 1; 179 | 180 | val = 0; 181 | 182 | // 183 | // check for hex 184 | // 185 | if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) 186 | { 187 | str += 2; 188 | while (1) 189 | { 190 | c = *str++; 191 | if (c >= '0' && c <= '9') 192 | val = (val << 4) + c - '0'; 193 | else if (c >= 'a' && c <= 'f') 194 | val = (val << 4) + c - 'a' + 10; 195 | else if (c >= 'A' && c <= 'F') 196 | val = (val << 4) + c - 'A' + 10; 197 | else 198 | return val * sign; 199 | } 200 | } 201 | 202 | // 203 | // check for character 204 | // 205 | if (str[0] == '\'') 206 | { 207 | return sign * str[1]; 208 | } 209 | 210 | // 211 | // assume decimal 212 | // 213 | while (1) 214 | { 215 | c = *str++; 216 | if (c < '0' || c > '9') 217 | return val * sign; 218 | val = val * 10 + c - '0'; 219 | } 220 | 221 | return 0; 222 | } 223 | 224 | 225 | float Q_atof(char* str) 226 | { 227 | double val; 228 | int sign; 229 | int c; 230 | int decimal, total; 231 | 232 | if (*str == '-') 233 | { 234 | sign = -1; 235 | str++; 236 | } 237 | else 238 | sign = 1; 239 | 240 | val = 0; 241 | 242 | // 243 | // check for hex 244 | // 245 | if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) 246 | { 247 | str += 2; 248 | while (1) 249 | { 250 | c = *str++; 251 | if (c >= '0' && c <= '9') 252 | val = (val * 16) + c - '0'; 253 | else if (c >= 'a' && c <= 'f') 254 | val = (val * 16) + c - 'a' + 10; 255 | else if (c >= 'A' && c <= 'F') 256 | val = (val * 16) + c - 'A' + 10; 257 | else 258 | return val * sign; 259 | } 260 | } 261 | 262 | // 263 | // check for character 264 | // 265 | if (str[0] == '\'') 266 | { 267 | return sign * str[1]; 268 | } 269 | 270 | // 271 | // assume decimal 272 | // 273 | decimal = -1; 274 | total = 0; 275 | while (1) 276 | { 277 | c = *str++; 278 | if (c == '.') 279 | { 280 | decimal = total; 281 | continue; 282 | } 283 | if (c < '0' || c > '9') 284 | break; 285 | val = val * 10 + c - '0'; 286 | total++; 287 | } 288 | 289 | if (decimal == -1) 290 | return val * sign; 291 | while (total > decimal) 292 | { 293 | val /= 10; 294 | total--; 295 | } 296 | 297 | return val * sign; 298 | } -------------------------------------------------------------------------------- /ps2/common.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_H 2 | #define COMMON_H 3 | 4 | #ifndef TRUE 5 | #define TRUE 1 6 | #define FALSE 0 7 | #endif 8 | 9 | #ifndef size_t 10 | typedef unsigned int size_t; 11 | #endif 12 | 13 | //============================================================================ 14 | 15 | 16 | void Q_memset(void* dest, int fill, size_t count); 17 | void Q_memcpy(void* dest, void* src, size_t count); 18 | int Q_memcmp(void* m1, void* m2, size_t count); 19 | void Q_strcpy(char* dest, char* src); 20 | void Q_strncpy(char* dest, char* src, size_t count); 21 | int Q_strlen(char* str); 22 | char* Q_strrchr(char* s, char c); 23 | void Q_strcat(char* dest, char* src); 24 | int Q_strcmp(char* s1, char* s2); 25 | int Q_strncmp(char* s1, char* s2, size_t count); 26 | int Q_strcasecmp(char* s1, char* s2); 27 | int Q_strncasecmp(char* s1, char* s2, int n); 28 | int Q_atoi(char* str); 29 | float Q_atof(char* str); 30 | 31 | int Sys_rand(); 32 | void Sys_sprintf(char* buffer, const char* format, ...); 33 | void* Q_malloc(int size); 34 | void Q_free(void* ptr); 35 | 36 | //============================================================================ 37 | 38 | #endif -------------------------------------------------------------------------------- /ps2/main.c: -------------------------------------------------------------------------------- 1 | void Sys_InitELF(); 2 | void __attribute__((optimize("O3"))) INVOKER(); 3 | 4 | int CompatibleCRCList[] = { 0xA880AE9B }; // SLUS_200.66 (got CRC from PCSX2 logs) 5 | 6 | void init() 7 | { 8 | Sys_InitELF(); 9 | } 10 | 11 | // needs to be 03 because O0 ironically does some funky stuff with this function 12 | void __attribute__((optimize("O3"))) INVOKER() 13 | { 14 | asm("ei\n"); 15 | asm("addiu $ra, -4\n"); 16 | 17 | init(); 18 | } 19 | 20 | int __attribute__((optimize("O3"))) main() 21 | { 22 | return 0; 23 | } -------------------------------------------------------------------------------- /ps2/ps2mem.cpp: -------------------------------------------------------------------------------- 1 | #include "ps2mem.h" 2 | 3 | void makeJal(unsigned int addr, void* func) 4 | { 5 | *(int*)addr = ((0x0C000000 | (((unsigned int)func & 0x0fffffff) >> 2))); 6 | } 7 | 8 | void patchInt(unsigned int addr, int data) 9 | { 10 | *(int*)(addr) = data; 11 | } 12 | 13 | void makeJmp(unsigned int addr, void* func) 14 | { 15 | *(int*)addr = (0x08000000 | (((unsigned int)(func) & 0x0FFFFFFC) >> 2)); 16 | } 17 | 18 | void NOP(unsigned int addr) 19 | { 20 | patchInt(addr, 0); 21 | } 22 | 23 | void patchShort(unsigned int addr, short data) 24 | { 25 | *(short*)(addr) = data; 26 | } -------------------------------------------------------------------------------- /ps2/ps2mem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define LOWORD(l) ((uint16_t)((*(uint32_t*)(&l)) & 0xffff)) 4 | #define HIWORD(l) ((uint16_t)(((*(uint32_t*)(&l)) >> 16) & 0xffff)) 5 | 6 | void makeJal(unsigned int addr, void* func); 7 | void patchInt(unsigned int addr, int data); 8 | void makeJmp(unsigned int addr, void* func); 9 | void NOP(unsigned int addr); 10 | void patchShort(unsigned int addr, short data); -------------------------------------------------------------------------------- /ps2/sys_ps2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | *********************************** 3 | * * 4 | * Half-Life SDK for Playstation 2 * 5 | * SLUS-20066 * 6 | * * 7 | *********************************** 8 | */ 9 | 10 | #include "types.h" 11 | #include "ps2mem.h" 12 | #include "mips.h" 13 | 14 | #include "hud.h" 15 | 16 | // client.dll "exports" 17 | //======================================================================= 18 | typedef int (*_Initialize)(cl_enginefunc_t* pEnginefuncs, int iVersion); 19 | typedef int (*_HUD_VidInit)(int player); 20 | typedef int (*_HUD_Init)(int player); 21 | typedef int (*_HUD_Redraw)(float flTime, int intermission, int player); 22 | typedef int (*_HUD_UpdateClientData)(client_data_t* cdata, int player); 23 | 24 | extern "C" 25 | { 26 | int Initialize(cl_enginefunc_t* pEnginefuncs, int iVersion); 27 | int HUD_VidInit(int player); 28 | int HUD_Init(int player); 29 | int HUD_Redraw(float flTime, int intermission, int player); 30 | int HUD_UpdateClientData(client_data_t* cdata, int player); 31 | } 32 | //======================================================================= 33 | 34 | int Sys_rand() 35 | { 36 | return ((int(*)())0x2E5340)(); 37 | } 38 | 39 | void Sys_sprintf(char* buffer, const char* format, ...) 40 | { 41 | ((void(*)(char*, const char*, ...))0x2E5880)(buffer, format); 42 | } 43 | 44 | void* Q_malloc(int size) 45 | { 46 | return ((void*(*)(int))0x225C58)(size); 47 | } 48 | 49 | void Q_free(void* ptr) 50 | { 51 | ((void (*)(void*))0x2261A8)(ptr); 52 | } 53 | 54 | /************************************************************************/ 55 | /* Sys_ReplaceClient 56 | /************************************************************************/ 57 | void Sys_ReplaceClient() 58 | { 59 | *(_Initialize*)0x46E4F8 = Initialize; 60 | *(_HUD_Init*)0x46E4FC = HUD_Init; 61 | *(_HUD_VidInit*)0x46E500 = HUD_VidInit; 62 | *(_HUD_Redraw*)0x46E504 = HUD_Redraw; 63 | *(_HUD_UpdateClientData*)0x46E508 = HUD_UpdateClientData; 64 | 65 | *(_HUD_VidInit*)0x46E50C = HUD_VidInit; // there is another VidInit pointer (xref -> 0x00247498, unused?) 66 | } 67 | 68 | typedef void (*_HookUserMsg)(void* a1, void* a2, void* a3); 69 | _HookUserMsg ORIG_HookUserMsg = NULL; 70 | 71 | void HOOKED_HookUserMsg(void* a1, void* a2, void* a3) 72 | { 73 | ORIG_HookUserMsg(a1, a2, a3); 74 | Sys_ReplaceClient(); 75 | } 76 | 77 | /************************************************************************/ 78 | /* Sys_InitELF 79 | /* Initialize hooks, get necessary variables/functions 80 | /************************************************************************/ 81 | extern "C" 82 | { 83 | void Sys_InitELF() 84 | { 85 | // CLIENT REPLACEMENT 86 | ORIG_HookUserMsg = (_HookUserMsg)(0x294B28); 87 | makeJal(0x246F70, (void*)HOOKED_HookUserMsg); // right before Initialize 88 | } 89 | } -------------------------------------------------------------------------------- /ps2/types.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define FALSE 0 4 | #define TRUE 1 5 | 6 | #define TRUE_FALSE(x) x ? "true" : "false" 7 | 8 | typedef unsigned char uint8; 9 | typedef int int32; -------------------------------------------------------------------------------- /rebuild.bat: -------------------------------------------------------------------------------- 1 | powershell "external/ps2sdk/ee/bin/vsmake" clean 2 | powershell "external/ps2sdk/ee/bin/vsmake" all -------------------------------------------------------------------------------- /utils/qcsg/csg.h: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1998, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | ****/ 10 | 11 | 12 | #include "cmdlib.h" 13 | #include "mathlib.h" 14 | #include "scriplib.h" 15 | #include "polylib.h" 16 | #include "threads.h" 17 | #include "bspfile.h" 18 | 19 | #include 20 | 21 | #ifndef DOUBLEVEC_T 22 | #error you must add -dDOUBLEVEC_T to the project! 23 | #endif 24 | 25 | #define BOGUS_RANGE 8192 26 | 27 | typedef struct 28 | { 29 | vec3_t normal; 30 | vec_t dist; 31 | int type; 32 | int iorigin[3]; 33 | int inormal[3]; 34 | } plane_t; 35 | 36 | extern plane_t mapplanes[MAX_MAP_PLANES]; 37 | extern int nummapplanes; 38 | 39 | 40 | typedef struct 41 | { 42 | vec_t shift[2]; 43 | vec_t rotate; 44 | vec_t scale[2]; 45 | char name[32]; 46 | } brush_texture_t; 47 | 48 | typedef struct side_s 49 | { 50 | brush_texture_t td; 51 | int planepts[3][3]; 52 | } side_t; 53 | 54 | typedef struct bface_s 55 | { 56 | struct bface_s *next; 57 | int planenum; 58 | plane_t *plane; 59 | winding_t *w; 60 | int texinfo; 61 | qboolean used; // just for face counting 62 | int contents, backcontents; 63 | vec3_t mins, maxs; 64 | } bface_t; 65 | 66 | #define NUM_HULLS 4 // no larger than MAX_MAP_HULLS 67 | typedef struct 68 | { 69 | vec3_t mins, maxs; 70 | bface_t *faces; 71 | } brushhull_t; 72 | 73 | typedef struct brush_s 74 | { 75 | int entitynum; 76 | int brushnum; 77 | 78 | int firstside; 79 | int numsides; 80 | 81 | int contents; 82 | brushhull_t hulls[NUM_HULLS]; 83 | } brush_t; 84 | 85 | 86 | extern int nummapbrushes; 87 | extern brush_t mapbrushes[MAX_MAP_BRUSHES]; 88 | 89 | #define MAX_MAP_SIDES (MAX_MAP_BRUSHES*6) 90 | 91 | extern int numbrushplanes; 92 | extern plane_t planes[MAX_MAP_PLANES]; 93 | 94 | extern int numbrushsides; 95 | extern side_t brushsides[MAX_MAP_SIDES]; 96 | 97 | extern qboolean noclip; 98 | extern qboolean wadtextures; 99 | 100 | int nWadInclude; 101 | char *pszWadInclude[]; 102 | 103 | void LoadMapFile (char *filename); 104 | 105 | //============================================================================= 106 | 107 | // textures.c 108 | 109 | extern int nummiptex; 110 | void WriteMiptex (void); 111 | int TexinfoForBrushTexture (plane_t *plane, brush_texture_t *bt, vec3_t origin); 112 | 113 | //============================================================================= 114 | 115 | // brush.c 116 | 117 | void FindGCD (int *v); 118 | 119 | brush_t *Brush_LoadEntity (entity_t *ent, int hullnum); 120 | int PlaneTypeForNormal (vec3_t normal); 121 | 122 | void CreateBrush (int brushnum); 123 | 124 | //============================================================================= 125 | 126 | // csg.c 127 | 128 | bface_t *NewFaceFromFace (bface_t *in); 129 | extern qboolean onlyents; 130 | 131 | //============================================================================= 132 | 133 | // draw.c 134 | 135 | extern vec3_t draw_mins, draw_maxs; 136 | extern qboolean drawflag; 137 | 138 | void Draw_ClearWindow (void); 139 | void DrawWinding (winding_t *w); 140 | 141 | -------------------------------------------------------------------------------- /utils/qcsg/gldraw.c: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1998, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | ****/ 10 | 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "csg.h" 18 | 19 | // can't use the glvertex3fv functions, because the vec3_t fields 20 | // could be either floats or doubles, depending on DOUBLEVEC_T 21 | 22 | qboolean drawflag; 23 | vec3_t draw_mins, draw_maxs; 24 | 25 | 26 | #define WIN_SIZE 512 27 | 28 | void InitWindow (void) 29 | { 30 | auxInitDisplayMode (AUX_SINGLE | AUX_RGB); 31 | auxInitPosition (0, 0, WIN_SIZE, WIN_SIZE); 32 | auxInitWindow ("qcsg"); 33 | } 34 | 35 | void Draw_ClearWindow (void) 36 | { 37 | static int init; 38 | int w, h, g; 39 | vec_t mx, my; 40 | 41 | if (!drawflag) 42 | return; 43 | 44 | if (!init) 45 | { 46 | init = true; 47 | InitWindow (); 48 | } 49 | 50 | glClearColor (1,0.8,0.8,0); 51 | glClear (GL_COLOR_BUFFER_BIT); 52 | 53 | w = (draw_maxs[0] - draw_mins[0]); 54 | h = (draw_maxs[1] - draw_mins[1]); 55 | 56 | mx = draw_mins[0] + w/2; 57 | my = draw_mins[1] + h/2; 58 | 59 | g = w > h ? w : h; 60 | 61 | glLoadIdentity (); 62 | gluPerspective (90, 1, 2, 16384); 63 | gluLookAt (mx, my, draw_maxs[2] + g/2, mx , my, draw_maxs[2], 0, 1, 0); 64 | 65 | glColor3f (0,0,0); 66 | // glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); 67 | glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); 68 | glDisable (GL_DEPTH_TEST); 69 | glEnable (GL_BLEND); 70 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 71 | 72 | #if 0 73 | glColor4f (1,0,0,0.5); 74 | glBegin (GL_POLYGON); 75 | 76 | glVertex3f (0, 500, 0); 77 | glVertex3f (0, 900, 0); 78 | glVertex3f (0, 900, 100); 79 | glVertex3f (0, 500, 100); 80 | 81 | glEnd (); 82 | #endif 83 | 84 | glFlush (); 85 | 86 | } 87 | 88 | void Draw_SetRed (void) 89 | { 90 | if (!drawflag) 91 | return; 92 | 93 | glColor3f (1,0,0); 94 | } 95 | 96 | void Draw_SetGrey (void) 97 | { 98 | if (!drawflag) 99 | return; 100 | 101 | glColor3f (0.5,0.5,0.5); 102 | } 103 | 104 | void Draw_SetBlack (void) 105 | { 106 | if (!drawflag) 107 | return; 108 | 109 | glColor3f (0,0,0); 110 | } 111 | 112 | void DrawWinding (winding_t *w) 113 | { 114 | int i; 115 | 116 | if (!drawflag) 117 | return; 118 | 119 | glColor4f (0,0,0,0.5); 120 | glBegin (GL_LINE_LOOP); 121 | for (i=0 ; inumpoints ; i++) 122 | glVertex3f (w->p[i][0],w->p[i][1],w->p[i][2] ); 123 | glEnd (); 124 | 125 | glColor4f (0,1,0,0.3); 126 | glBegin (GL_POLYGON); 127 | for (i=0 ; inumpoints ; i++) 128 | glVertex3f (w->p[i][0],w->p[i][1],w->p[i][2] ); 129 | glEnd (); 130 | 131 | glFlush (); 132 | } 133 | 134 | void DrawAuxWinding (winding_t *w) 135 | { 136 | int i; 137 | 138 | if (!drawflag) 139 | return; 140 | 141 | glColor4f (0,0,0,0.5); 142 | glBegin (GL_LINE_LOOP); 143 | for (i=0 ; inumpoints ; i++) 144 | glVertex3f (w->p[i][0],w->p[i][1],w->p[i][2] ); 145 | glEnd (); 146 | 147 | glColor4f (1,0,0,0.3); 148 | glBegin (GL_POLYGON); 149 | for (i=0 ; inumpoints ; i++) 150 | glVertex3f (w->p[i][0],w->p[i][1],w->p[i][2] ); 151 | glEnd (); 152 | 153 | glFlush (); 154 | } 155 | -------------------------------------------------------------------------------- /utils/qcsg/map.c: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1998, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | ****/ 10 | 11 | // map.c 12 | 13 | #include "csg.h" 14 | 15 | int nummapbrushes; 16 | brush_t mapbrushes[MAX_MAP_BRUSHES]; 17 | 18 | int numbrushsides; 19 | side_t brushsides[MAX_MAP_SIDES]; 20 | 21 | //============================================================================ 22 | 23 | 24 | /* 25 | ================== 26 | textureAxisFromPlane 27 | ================== 28 | */ 29 | vec3_t baseaxis[18] = 30 | { 31 | {0,0,1}, {1,0,0}, {0,-1,0}, // floor 32 | {0,0,-1}, {1,0,0}, {0,-1,0}, // ceiling 33 | {1,0,0}, {0,1,0}, {0,0,-1}, // west wall 34 | {-1,0,0}, {0,1,0}, {0,0,-1}, // east wall 35 | {0,1,0}, {1,0,0}, {0,0,-1}, // south wall 36 | {0,-1,0}, {1,0,0}, {0,0,-1} // north wall 37 | }; 38 | 39 | void TextureAxisFromPlane(plane_t *pln, vec3_t xv, vec3_t yv) 40 | { 41 | int bestaxis; 42 | vec_t dot,best; 43 | int i; 44 | 45 | best = 0; 46 | bestaxis = 0; 47 | 48 | for (i=0 ; i<6 ; i++) 49 | { 50 | dot = DotProduct (pln->normal, baseaxis[i*3]); 51 | if (dot > best) 52 | { 53 | best = dot; 54 | bestaxis = i; 55 | } 56 | } 57 | 58 | VectorCopy (baseaxis[bestaxis*3+1], xv); 59 | VectorCopy (baseaxis[bestaxis*3+2], yv); 60 | } 61 | 62 | 63 | 64 | /* 65 | ================= 66 | ParseBrush 67 | ================= 68 | */ 69 | void ParseBrush (entity_t *mapent) 70 | { 71 | brush_t *b; 72 | bface_t *f, *f2; 73 | int planepts[3][3]; 74 | vec3_t t1, t2, t3; 75 | int i,j; 76 | vec_t d; 77 | int planenum; 78 | side_t *side; 79 | int contents; 80 | 81 | if (nummapbrushes == MAX_MAP_BRUSHES) 82 | Error ("nummapbrushes == MAX_MAP_BRUSHES"); 83 | 84 | b = &mapbrushes[nummapbrushes]; 85 | nummapbrushes++; 86 | b->firstside = numbrushsides; 87 | b->entitynum = num_entities-1; 88 | b->brushnum = nummapbrushes - mapent->firstbrush - 1; 89 | 90 | mapent->numbrushes++; 91 | 92 | do 93 | { 94 | if (!GetToken (true)) 95 | break; 96 | if (!strcmp (token, "}") ) 97 | break; 98 | 99 | if (numbrushsides == MAX_MAP_SIDES) 100 | Error ("numbrushsides == MAX_MAP_SIDES"); 101 | side = &brushsides[numbrushsides]; 102 | numbrushsides++; 103 | 104 | b->numsides++; 105 | 106 | // read the three point plane definition 107 | for (i=0 ; i<3 ; i++) 108 | { 109 | if (i != 0) 110 | GetToken (true); 111 | if (strcmp (token, "(") ) 112 | Error ("parsing brush"); 113 | 114 | for (j=0 ; j<3 ; j++) 115 | { 116 | GetToken (false); 117 | side->planepts[i][j] = atoi(token); 118 | } 119 | 120 | GetToken (false); 121 | if (strcmp (token, ")") ) 122 | Error ("parsing brush"); 123 | 124 | } 125 | 126 | // read the texturedef 127 | GetToken (false); 128 | strcpy (side->td.name, token); 129 | 130 | GetToken (false); 131 | side->td.shift[0] = atoi(token); 132 | GetToken (false); 133 | side->td.shift[1] = atoi(token); 134 | GetToken (false); 135 | side->td.rotate = atoi(token); 136 | GetToken (false); 137 | side->td.scale[0] = atof(token); 138 | GetToken (false); 139 | side->td.scale[1] = atof(token); 140 | 141 | } while (1); 142 | 143 | b->contents = contents = BrushContents (b); 144 | 145 | // 146 | // origin brushes are removed, but they set 147 | // the rotation origin for the rest of the brushes 148 | // in the entity 149 | // 150 | if (contents == CONTENTS_ORIGIN) 151 | { 152 | char string[32]; 153 | vec3_t origin; 154 | 155 | b->contents = CONTENTS_SOLID; 156 | CreateBrush (mapent->firstbrush + b->brushnum); // to get sizes 157 | b->contents = contents; 158 | 159 | for (i = 0; i < NUM_HULLS; i++) { 160 | b->hulls[i].faces = NULL; 161 | } 162 | 163 | if (b->entitynum == 0) 164 | { 165 | printf ("Entity %i, Brush %i: origin brushes not allowed in world" 166 | , b->entitynum, b->brushnum); 167 | return; 168 | } 169 | VectorAdd (b->hulls[0].mins, b->hulls[0].maxs, origin); 170 | VectorScale (origin, 0.5, origin); 171 | 172 | sprintf (string, "%i %i %i", (int)origin[0], (int)origin[1], (int)origin[2]); 173 | SetKeyValue (&entities[b->entitynum], "origin", string); 174 | } 175 | 176 | } 177 | 178 | /* 179 | ================ 180 | ParseMapEntity 181 | ================ 182 | */ 183 | qboolean ParseMapEntity (void) 184 | { 185 | entity_t *mapent; 186 | epair_t *e; 187 | 188 | if (!GetToken (true)) 189 | return false; 190 | 191 | if (strcmp (token, "{") ) 192 | Error ("ParseEntity: { not found"); 193 | 194 | if (num_entities == MAX_MAP_ENTITIES) 195 | Error ("num_entities == MAX_MAP_ENTITIES"); 196 | 197 | mapent = &entities[num_entities]; 198 | num_entities++; 199 | mapent->firstbrush = nummapbrushes; 200 | mapent->numbrushes = 0; 201 | 202 | do 203 | { 204 | if (!GetToken (true)) 205 | Error ("ParseEntity: EOF without closing brace"); 206 | if (!strcmp (token, "}") ) 207 | break; 208 | if (!strcmp (token, "{") ) 209 | ParseBrush (mapent); 210 | else 211 | { 212 | e = ParseEpair (); 213 | e->next = mapent->epairs; 214 | mapent->epairs = e; 215 | } 216 | } while (1); 217 | 218 | if ( mapent->numbrushes == 1 && mapbrushes[mapent->firstbrush].contents == CONTENTS_ORIGIN ) 219 | { 220 | brushhull_t *hull = mapbrushes[mapent->firstbrush].hulls; 221 | Error("Found an entity with ONLY an origin brush near(%.0f,%.0f,%.0f)!\n", 222 | hull->mins[0], hull->mins[1], hull->mins[2] ); 223 | } 224 | 225 | GetVectorForKey (mapent, "origin", mapent->origin); 226 | 227 | // group entities are just for editor convenience 228 | // toss all brushes into the world entity 229 | if ( !onlyents && !strcmp ("func_group", ValueForKey (mapent, "classname"))) 230 | { 231 | // this is pretty gross, because the brushes are expected to be 232 | // in linear order for each entity 233 | brush_t *temp; 234 | int newbrushes; 235 | int worldbrushes; 236 | int i; 237 | 238 | newbrushes = mapent->numbrushes; 239 | worldbrushes = entities[0].numbrushes; 240 | 241 | temp = malloc(newbrushes*sizeof(brush_t)); 242 | memcpy (temp, mapbrushes + mapent->firstbrush, newbrushes*sizeof(brush_t)); 243 | 244 | for (i=0 ; i