anchor.diff:  
   %% @doc Load and send the character information to the client.
   
  -char_load(CSocket, GID, Char, Options, Number) ->
  -	send_0d01(CSocket, GID, Char, Options),
  +char_load(Char, Options, Number) ->
  +	send_0d01(Char, Options),
   	% 0246
  -	send_0a0a(CSocket, GID),
  -	send_1006(CSocket, GID, 5),
  -	send_1005(CSocket, GID, Char),
  -	send_1006(CSocket, GID, 12),
  +	send_0a0a(),
  +	send_1006(5),
  +	send_1005(Char),
  +	send_1006(12),
   	% 0210
  -	send_0222(CSocket, GID),
  -	send_1500(CSocket, GID, Char, Number),
  -	send_1501(CSocket, GID),
  -	send_1512(CSocket, GID),
  +	send_0222(),
  +	send_1500(Char, Number),
  +	send_1501(),
  +	send_1512(),
   	% 0303
  -	send_1602(CSocket, GID).
  +	send_1602().
   
   %% @doc Load the given map as a mission counter.
   
  -counter_load(CSocket, GID, QuestID, ZoneID, MapID, EntryID) ->
  -	OldUser = egs_db:users_select(GID),
  +counter_load(QuestID, ZoneID, MapID, EntryID) ->
  +	OldUser = egs_db:users_select(get(gid)),
   	User = OldUser#users{areatype=counter, questid=QuestID, zoneid=ZoneID, mapid=MapID, entryid=EntryID,
   		savedquestid=OldUser#users.questid, savedzoneid=OldUser#users.zoneid, savedmapid=ZoneID, savedentryid=MapID},
   	egs_db:users_insert(User),
  
positive.code: 
  %% @todo Handle this packet.
  
  handle(16#0404, CSocket, GID, _, Data) ->
  	<< A:32/little-unsigned-integer, B:32/little-unsigned-integer >> = Data,
  	log(GID, "unknown command 0404: ~b ~b", [A, B]),
  	send_1205(CSocket, GID, A, B);
  
  %% @doc Map change handler.
  %%      Rooms are handled differently than normal lobbies.
  %% @todo When changing lobby to the room, 0230 must also be sent. Same when going from room to lobby.
  
  handle(16#0807, CSocket, GID, _, Data) ->
  	<< QuestID:32/little-unsigned-integer, ZoneID:16/little-unsigned-integer,
  		MapID:16/little-unsigned-integer, EntryID:16/little-unsigned-integer, _/bits >> = Data,
  	log(GID, "map change (~b,~b,~b,~b)", [QuestID, ZoneID, MapID, EntryID]),
  	area_load(CSocket, GID, QuestID, ZoneID, MapID, EntryID);
  
  %% @doc Mission counter handler.
  
  handle(16#0811, CSocket, GID, _, Data) ->
  	<< QuestID:32/little-unsigned-integer, ZoneID:16/little-unsigned-integer,
  		MapID:16/little-unsigned-integer, EntryID:16/little-unsigned-integer, _/bits >> = Data,
  	log(GID, "mission counter (~b,~b,~b,~b)", [QuestID, ZoneID, MapID, EntryID]),
  	counter_load(CSocket, GID, QuestID, ZoneID, MapID, EntryID);
  
  %% @doc Leave mission counter handler. Lobby values depend on which counter was entered.
  
  handle(16#0812, CSocket, GID, _, _) ->
  	User = egs_db:users_select(GID),
  	area_load(CSocket, GID, User#users.savedquestid, User#users.savedzoneid, User#users.zoneid, User#users.mapid);
  
  %% @doc Item description request.
  %% @todo Send something other than just "dammy".
  
  handle(16#0a10, CSocket, GID, _, << ItemID:32/unsigned-integer >>) ->
  	send_0a11(CSocket, GID, ItemID, "dammy");
  
  %% @doc Start mission handler.
  %% @todo Forward the mission start to other players of the same party, whatever their location is.
  
  handle(16#0c01, CSocket, GID, _, << QuestID:32/little-unsigned-integer >>) ->
  	log(GID, "start mission ~b", [QuestID]),
  	send_170c(CSocket, GID),
  	send_1020(CSocket, GID),
  	send_1015(CSocket, GID, QuestID),
  	send_0c02(CSocket, GID);
  
  %% @doc Counter quests files request handler? Send huge number of quest files.
  %% @todo Handle correctly.
  
  handle(16#0c05, CSocket, GID, _, _) ->
  	User = egs_db:users_select(GID),
  	[{quests, Filename}, {bg, _}, {options, _}] = proplists:get_value(User#users.entryid, ?COUNTERS),
  	send_0c06(CSocket, Filename);
  
  %% @doc Lobby transport handler? Just ignore the meseta price for now and send the player where he wanna be!
  %% @todo Handle correctly.
  
  handle(16#0c07, CSocket, GID, _, _) ->
  	send_0c08(CSocket, GID, ok);
  
  %% @doc Abort mission handler.
  
  handle(16#0c0e, CSocket, GID, _, _) ->
  	send_1006(CSocket, GID, 11),
  	User = egs_db:users_select(GID),
  	if	User#users.areatype =:= mission ->
  			area_load(CSocket, GID, User#users.savedquestid, User#users.savedzoneid, User#users.savedmapid, User#users.savedentryid);
  		true -> ignore
  	end;
  
  %% @doc Counter available mission list request handler.
  %% @todo Temporarily allow rare mission and LL all difficulties to all players.
  
  handle(16#0c0f, CSocket, GID, _, _) ->
  	User = egs_db:users_select(GID),
  	[{quests, _}, {bg, _}, {options, Options}] = proplists:get_value(User#users.entryid, ?COUNTERS),
  	send_0c10(CSocket, GID, Options);
  
  %% @doc Set flag handler. Associate a new flag with the character.
  %%      Just reply with a success value for now.
  %% @todo God save the flags.
  
  handle(16#0d04, CSocket, GID, _, Data) ->
  	<< Flag:128/bits, A:16/bits, _:8, B/bits >> = Data,
  	log(GID, "flag handler for ~s", [re:replace(Flag, "\\0+", "", [global, {return, binary}])]),
  	Packet = << 16#0d040300:32, 0:160, 16#00011300:32, GID:32/little-unsigned-integer, 0:64, Flag/binary, A/binary, 1, B/binary >>,
  	egs_proto:packet_send(CSocket, Packet);
  
  %% @doc Options changes handler.
  
  handle(16#0d07, _, GID, _, << Options/bits >>) ->
  	log(GID, "options changes"),
  	User = egs_db:users_select(GID),
  	file:write_file(io_lib:format("save/~s/~b-character.options", [User#users.folder, User#users.charnumber]), Options);
  
  %% @doc Hit handler.
  %% @todo Finish the work on it.
  %% @todo First value at 2C is the number of hits. We don't need to know it though.
  
  handle(16#0e00, CSocket, GID, _, Data) ->
  	<< _:96, Hits/bits >> = Data,
  	handle_hits(CSocket, GID, Hits);
  
  %% @doc Object event handler.
  %% @todo Handle all events appropriately.
  
  handle(16#0f0a, CSocket, GID, _, Data) ->
  	<< _:96, A:32/little-unsigned-integer, _:64, B:32/little-unsigned-integer, _:272, Action:8, _/bits >> = Data,
  	case Action of
  		0 -> % warp
  
negative.code: 	end,
  	?MODULE:accept(LSocket, SPid).
  
  %% @doc Initialize the client process by saving the socket to the process dictionary.
  
  process_init(CSocket) ->
  	put(socket, CSocket),
  	send_0202(),
  	process().
  
  %% @doc Process the new connections.
  %%      Send an hello packet, authenticate the user and send him to character select.
  
  process() ->
  	case egs_proto:packet_recv(get(socket), 5000) of
  		{ok, Orig} ->
  			{command, Command, _, Data} = egs_proto:packet_parse(Orig),
  			process_handle(Command, Data);
  		{error, timeout} ->
  			reload,
  			?MODULE:process();
  		{error, closed} ->
  			closed
  	end.
  
  %% @doc Game server auth request handler. Save the GID in the process dictionary after checking it.
  
  process_handle(16#020d, << GID:32/little-unsigned-integer, Auth:32/bits, _/bits >>) ->
  	CSocket = get(socket),
  	case egs_db:users_select(GID) of
  		error ->
  			log("can't find user, closing"),
  			ssl:close(CSocket);
  		User ->
  			case User#users.auth of
  				Auth ->
  					log("auth success"),
  					LID = 1 + egs_db:next(lobby) rem 1023,
  					Time = calendar:datetime_to_gregorian_seconds(calendar:universal_time()),
  					egs_db:users_insert(#users{gid=GID, pid=self(), socket=CSocket, auth=success, time=Time, folder=User#users.folder, lid=LID}),
  					put(gid, GID),
  					send_0d05(),
  					?MODULE:char_select();
  				_ ->
  					log("quit, auth failed"),
  					egs_db:users_delete(GID),
  					ssl:close(CSocket)
  			end
  	end;
  
  %% @doc Platform information handler. Obtain the game version and save it into the process dictionary.
  
  process_handle(16#080e, << _:64, Version:32/little-unsigned-integer, _/bits >>) ->
  	put(version, Version),
  	?MODULE:process();
  
  %% @doc Unknown command handler. Do nothing.
  
  process_handle(Command, _) ->
  	log("(process) dismissed packet ~4.16.0b", [Command]),
  	?MODULE:process().
  
  %% @doc Character selection screen loop.
  %%      The default entry point currently is first floor, near the uni cube.
  
  char_select() ->
  	case egs_proto:packet_recv(get(socket), 5000) of
  		{ok, Orig} ->
  			{command, Command, _, Data} = egs_proto:packet_parse(Orig),
  			char_select_handle(Command, Data);
  		{error, timeout} ->
  			egs_proto:send_keepalive(get(socket)),
  			reload,
  			?MODULE:char_select();
  		{error, closed} ->
  			log("quit"),
  			egs_db:users_delete(get(gid))
  	end.
  
  %% @doc Character selection handler.
  
  char_select_handle(16#020b, << Number:32/little-unsigned-integer, _/bits >>) ->
  	log("selected character ~b", [Number]),
  	char_select_load(Number);
  
  %% @doc Character creation handler.
  
  char_select_handle(16#0d02, << Number:32/little-unsigned-integer, Char/bits >>) ->
  	log("character creation"),
  	User = egs_db:users_select(get(gid)),
  	_ = file:make_dir(io_lib:format("save/~s", [User#users.folder])),
  	file:write_file(io_lib:format("save/~s/~b-character", [User#users.folder, Number]), Char),
  	file:write_file(io_lib:format("save/~s/~b-character.options", [User#users.folder, Number]), << 0:192 >>),
  	char_select_load(Number);
  
  %% @doc Character selection screen request.
  
  char_select_handle(16#0d06, _) ->
  	User = egs_db:users_select(get(gid)),
  	send_0d03(data_load(User#users.folder, 0), data_load(User#users.folder, 1), data_load(User#users.folder, 2), data_load(User#users.folder, 3)),
  	?MODULE:char_select();
  
  %% @doc Silently ignore packet 0818. Gives CPU/GPU information.
  
  char_select_handle(16#0818, _) ->
  	?MODULE:char_select();
  
  %% @doc Unknown command handler. Do nothing.
  
  char_select_handle(Command, _) ->
  	log("(char_select) dismissed packet ~4.16.0b", [Command]),
  	?MODULE:char_select().
  
  %% @doc Load the selected character in the start lobby and start the main game's loop.
  
  char_select_load(Number) ->
  	User = egs_db:users_select(get(gid)),
  	[{status, 1}, {char, Char}, {options, Options}] = data_load(User#users.folder, Number),
  	<< Name:512/bits, _/bits >> = Char,
  	NewRow = User#users{charnumber=Number, charname=Name},
  	egs_db:users_insert(NewRow),
  	char_load(Char, Options, Number),
  	send_021b(),
  	area_load(1100000, 0, 1, 1),
  	ssl:setopts(get(socket), [{active, true}]),
  	?MODULE:loop(<< >>).
  
  %% @doc Load the given character's data.
  
  