
This tutorial contains few parts. A the end of this tutorial, you will be able to find your way in every source file of Quake 2.
|
g_ai.c |
Artificial intelligence (A.I.) |
|
g_cmds.c |
Commands of the console |
|
g_combat.c |
Beginnings of detections of combats. |
|
g_func.c |
Varied functions |
|
g_items.c |
Items |
|
g_main.c |
Main functions (end of the level, ...) Not very useful to edit except for create some public variables. |
|
g_misc.c |
Varied functions |
|
g_monster.c |
Public functions of the monsters(used in files m_????.c) |
|
g_phys.c |
Physical functions(gravity, ...) |
|
g_save.c |
Functions used to save the game and during the initialization |
|
g_spawn.c |
Functions used during the revival of the player |
|
g_svcmds.c |
Server functions ??? |
|
g_target.c |
Functions used for objectives, entities of the level, ... |
|
g_trigger.c |
Functions used for the motions of the level( lift, buttons) |
|
g_turret.c |
Functions used for turrets (turret of Jail 1 ???) |
|
g_utils.c |
Varied functions (angles, vectors, ...) |
|
g_weapon.c |
Functions of weapons. Called by p_weapon.c |
|
game.h |
Contain some public variables and some structures |
|
m_?????.c |
Source code of the monsters |
|
m_?????.h |
Definition of the frames of the monsters |
|
p_client.c |
Functions client-server architecture (for the client). |
|
p_hud.c |
Functions of intermissions (video, ...) |
|
p_trail.c |
Circular list of player's last coordinates (used for monsters's pursuit) |
|
p_view.c |
Functions of the sight (high, low for example) |
|
p_weapon.c |
Functions of the weapons. |
|
q_shared.c |
Graphical functions(angles, vectors).They come from the 3d engine of the game. |
|
q_shared.h |
Structures, prototypes of functions, public variables, ...They come from the 3d engine of the game. |
Colo(u)rs of my code :
|
The new code is in light-blue |
|
The existing code is in red |
In the file p_weapon.c, there is a sub Machinegun_Fire (about the 2/3 of the file). The first seven lines are declarations of variables. After that, write gi.cprintf (ent, PRINT_HIGH, "hello");
The final result is:
|
vec3_t offset; |
|
gi.cprintf (ent, PRINT_HIGH, "hello"); |
|
if (!(ent->client->buttons & BUTTON_ATTACK)) |
Run the compilation again (to help you, see "How can I start ?". Now, when you fire with the weapon 4(machine gun) the computer writes hello at the top of the screen.
Here is an more interesting thing : if your name is "hello" then you can use "give all" !!! ( Yes, I know that is not very fair, but ...)
|
Open the file g_cmds.c. At the line 132(about the 1/6 of the document) there is this command : if (deathmatch->value && !sv_cheats->value). Let's analyze it togheter : |
|
The first part of the condition means : "if deathmatch" . |
|
The second part of the condition means : "NOT(authorized cheats)". the exclamation mark (!) represents NO. => That's equivalent at "if cheats are NOT authorized ". |
|
The complete expression means : "If deathmatch and cheats are unauthorized" |
If we simply add after this expression AND (PLAYER_NAME NO EQUAL AT "hello"), the result will be correct. In C language that's : && Q_stricmp(self->client->pers.netname, "hello") != 0
|
Analyze of this syntax : |
|
&& : AND |
|
Q_stricmp : comparaison between 2 strings. If they are equal this function return 0. |
|
self->client->pers.netname : returns player's name. |
|
!= 0 : If NOT EQUAL to 0. |
The final code is :
if (deathmatch->value && !sv_cheats->value && Q_stricmp (self->client->pers.netname, "hello") != 0 )
Note : The computer on which you have installed this patch must be the server.