I have a unique special procedures that mimics zone load. I am trying to add it to medit just as you would in Zedit.
Code:
void medit_setup_existing(struct descriptor_data *d, int rmob_num)
{
struct char_data *mob;
/* Allocate a scratch mobile structure. */
CREATE(mob, struct char_data, 1);
copy_mobile(mob, mob_proto + rmob_num);
OLC_MOB(d) = mob;
OLC_ITEM_TYPE(d) = MOB_TRIGGER;
dg_olc_script_copy(d);
/*
* The edited mob must not have a script.
* It will be assigned to the updated mob later, after editing.
*/
SCRIPT(mob) = NULL;
OLC_MOB(d)->proto_script = NULL;
OLC_PROC(d) = OLC_MOB(d)->mob_specials.func;
}
Code:
case MEDIT_PROC_MENU:
switch (tolower(*arg)) {
case 'q':
medit_disp_menu(d);
return;
case 'n':
/* New entry. */
if (OLC_PROC(d)[0].command == '~') {
/* first command */
if (new_mob_proc(OLC_MOB(d), 0) && start_change_procs(d, 0)) {
medit_spec_proc_assign(d);
OLC_SAVE(d) = 1;
return;
}
}
write_to_output(d, "What number in the list should the new command be? : ");
OLC_MODE(d) = MEDIT_NEW_ENTRY;
return;
Code:
case MEDIT_NEW_ENTRY:
/* Get the line number and insert the new line. */
pos = atoi(arg);
if (isdigit(*arg) && new_mob_proc(OLC_MOB(d), pos)) {
if (start_change_procs(d, pos))
medit_spec_proc_assign(d);
OLC_SAVE(d) = 1;
} else
medit_disp_spec_menu(d);
return;
Genmob.c
Code:
/* Error check user input and then add new (blank) command. */
int new_mob_proc(struct char_data *mob, int pos)
{
int subcmd = 0;
struct spec_proc new_com;
/* Error check to ensure users hasn't given too large an index. */
while (mob->mob_specials.func[subcmd].command != '~')
subcmd++;
if (pos < 0 || pos > subcmd)
return 0;
/* Ok, let's add a new (blank) command. */
new_com.command = 'N';
add_proc_to_list(&mob->mob_specials.func, &new_com, pos);
return 1;
}
My issue is that the minute i add a new command it crashes the game. I believe the reason to be because i impact the currently loaded mobile with that procedure. I am stuck because i want to load a copy of the procedure list, and edit it, than remove it from the mob_proto than add the updated one than update the in game mobile.
i believe that i corrupt the first memory block, which than crashes the game when the mobile goes through its live procedure calls. The line in red below should have been ch->mob_specials.func[0].func = Mob armies but as you can see it is corrupted.
Program received signal SIGSEGV, Segmentation fault.
0x000055555557ebb9 in special_procs (ch=ch@entry=0x555556f959c0, victim=victim@entry=0x0, obj=obj@entry=0x0, proc_type=proc_type@entry=3, spec_type=spec_type@entry=1,
dam=dam@entry=0x0, attacktype=0, tmp_desc=0x0) at spec_assign.c:323
323 if (spec_list[MCMD(ch, subcmd).procs].proc_type != PROC_MOB)
(gdb) back
#0 0x000055555557ebb9 in special_procs (ch=ch@entry=0x555556f959c0, victim=victim@entry=0x0, obj=obj@entry=0x0, proc_type=proc_type@entry=3, spec_type=spec_type@entry=1,
dam=dam@entry=0x0, attacktype=0, tmp_desc=0x0) at spec_assign.c:323
#1 0x00005555556c21ac in mobile_activity () at mobact.c:96
#2 0x0000555555677e45 in heartbeat (heart_pulse=179800) at comm.c:1043
#3 0x000055555567d682 in game_loop (local_mother_desc=3) at comm.c:978
#4 0x000055555556e821 in init_game (local_port=<optimized out>) at comm.c:565
#5 main (argc=<optimized out>, argv=<optimized out>) at comm.c:381
#0 0x000055555557ebb9 in special_procs (ch=ch@entry=0x555556f959c0, victim=victim@entry=0x0, obj=obj@entry=0x0, proc_type=proc_type@entry=3, spec_type=spec_type@entry=1,
dam=dam@entry=0x0, attacktype=0, tmp_desc=0x0) at spec_assign.c:323
323 if (spec_list[MCMD(ch, subcmd).procs].proc_type != PROC_MOB)
(gdb) print ch->mob_specials.func[0]
$3 = {command = 104 'h', procs = 32767, func = 0x7ffff737c068 <main_arena+1096>, freq = 1447874704, name = 0x5555564cd090 "ll.\r\n", run_type = 1, term = 0, num1 = 0, num2 = 0,
num3 = 0, num4 = 0, num5 = 0, internal = 0, line = 1, next = 0x0}
(gdb) print ch->mob_specials.func[1]
$4 = {command = 80 'P', procs = 111, func = 0x55555557b5e0 <mob_purge_pets>, freq = 100, name = 0x0, run_type = 1, term = 0, num1 = 0, num2 = 0, num3 = 0, num4 = 0, num5 = 0,
internal = 0, line = 2, next = 0x0}
(gdb) print ch->mob_specials.func[2]
$5 = {command = 80 'P', procs = 98, func = 0x55555557b740 <mob_unaffects_self>, freq = 100, name = 0x0, run_type = 1, term = 0, num1 = 0, num2 = 0, num3 = 0, num4 = 0, num5 = 0,
internal = 0, line = 3, next = 0x0}
(gdb) print ch->mob_specials.func[3]
$6 = {command = 80 'P', procs = 133, func = 0x55555557c790 <mob_heal_from_damage>, freq = 100, name = 0x0, run_type = 2, term = 1, num1 = 100, num2 = 0, num3 = 0, num4 = 0,
num5 = 0, internal = 8, line = 4, next = 0x0}
(gdb) print ch->mob_specials.func[4]
$7 = {command = 80 'P', procs = 134, func = 0x55555557c930 <mob_cap_damage>, freq = 100, name = 0x0, run_type = 2, term = 1, num1 = 100, num2 = 0, num3 = 0, num4 = 0, num5 = 0,
internal = 6, line = 5, next = 0x0}
(gdb) print ch->mob_specials.func[5]
$8 = {command = 80 'P', procs = 106, func = 0x5555555b7050 <proc_entropy_tank>, freq = 33, name = 0x0, run_type = 1, term = 1, num1 = 0, num2 = 0, num3 = 0, num4 = 0, num5 = 0,
internal = 0, line = 6, next = 0x0}