C# Exception bugging me

Experienced Elementalist
Joined
Sep 4, 2009
Messages
248
Reaction score
69
I'm "kinda" new to C#, but not completely stupid. I just started to finish a GunZ emulator that was started by Team Zebra.

Problem: After selecting your character and attempting to join the "lobby", an exception is caught. The exception says "Object reference not set to an instance of an object."

After debugging the crap outta it, I believe this is the cause.
Code:
 response.writeString(lobby.name);

Which 'response' acts on a packet, and executes a function that sends/grabs packets to the client.

Here's the function.
Code:
public static void responseJoin(Client c, GunzPacket p)
        {
            p.setIndex(11);
            UID uidPlayer = new UID();
            UID uidChannel = new UID();

            uidPlayer.first = (uint)p.readInt();
            uidPlayer.second = (uint)p.readInt();
            uidChannel.first = (uint)p.readInt();
            uidChannel.second = (uint)p.readInt();

            if (uidPlayer != c.uid)
               return;

            Lobby lobby = Lobby.getLobbyByUID(uidChannel);

            GunzPacket response = new GunzPacket(0x64, 0x4B7);
            response.startHeader();

            response.writeInt(uidChannel.first);
            response.writeInt(uidChannel.second);
            response.writeInt(0x00);
            response.writeString(lobby.name); //....
            response.writeByte(0x00);
            response.writeByte(0x01);
             
            response.finishHeader();
            c.send(response);
            lobby.addClient(c);

            responseRule(c, uidChannel);
            Stage.list(c, uidChannel);
        }

I know it's something little. T_T
 
Last edited:
well in c# strings are objects, So maybe lobby.name is not initialized?
since it's trying to show you the name of the lobby which is a string and if the string was not given a value and you try to show it, it will give an exception like that.
 
Tried initializing it. No exception, but it doesn't try to join the lobby.
When I change the integer in
Code:
p.setIndex( i_integer_here ) //Where "p" is GunzPacket - functions to help decide what the packets are, decrypted/encrypted, checksum, etc.
their is no exception but also, it seems like it's not even attempting to join the lobby.

setIndex is
Code:
        /// <summary>
        /// Set the buffer's current index.
        /// </summary>
        /// <param name="index">the desired index</param>
        /// <returns>whether or not the reset was valid</returns>
        public bool setIndex(int index)
        {
            if (index > length) return false;
            this.index = index;
            return true;
        }
 
Last edited:
Are you sure it's not the
PHP:
 Lobby lobby = Lobby.getLobbyByUID(uidChannel);

that cause the exception?
 
Are you sure it's not the
PHP:
 Lobby lobby = Lobby.getLobbyByUID(uidChannel);

that cause the exception?

I've set breakpoints throughout that entire function. It seems like it gets caught at
Code:
response.writeString(lobby.name);

Edit; Wait, I think I see it. O.o
 
Code:
public static void responseJoin(Client c, GunzPacket p)
        {
            p.setIndex(11);
            UID uidPlayer = new UID();
            UID uidChannel = new UID();

            uidPlayer.first = (uint)p.readInt();
            uidPlayer.second = (uint)p.readInt();
            uidChannel.first = (uint)p.readInt();
            uidChannel.second = (uint)p.readInt();

            if (uidPlayer != c.uid)
               return;

            Lobby lobby = Lobby.getLobbyByUID(uidChannel);
            Lobby loopy = new Lobby(); //I know.. I know.....
            loopy.name = "";

            GunzPacket response = new GunzPacket(0x64, 0x4B7);
            response.startHeader();

            loopy.name = "";

            response.writeInt(uidChannel.first);
            response.writeInt(uidChannel.second);
            response.writeInt(0x00);
            response.writeString(loopy.name); //What's wrong???????????????????????// <_-------------
            response.writeByte(0x00);
            response.writeByte(0x01);
             
            response.finishHeader();
            c.send(response);
            lobby.addClient(c);

            responseRule(c, uidChannel);
            Stage.list(c, uidChannel);
        }
S.o.b, it works. Thanks Paul, and Noob for your time and help.
 
Code:
public static void responseJoin(Client c, GunzPacket p)
        {
            p.setIndex(11);
            UID uidPlayer = new UID();
            UID uidChannel = new UID();

            uidPlayer.first = (uint)p.readInt();
            uidPlayer.second = (uint)p.readInt();
            uidChannel.first = (uint)p.readInt();
            uidChannel.second = (uint)p.readInt();

            if (uidPlayer != c.uid)
               return;

            Lobby lobby = Lobby.getLobbyByUID(uidChannel);
            loopy = new Lobby(); //I know.. I know.....
            loopy.name = "";

            GunzPacket response = new GunzPacket(0x64, 0x4B7);
            response.startHeader();

            loopy.name = "";

            response.writeInt(uidChannel.first);
            response.writeInt(uidChannel.second);
            response.writeInt(0x00);
            response.writeString(loopy.name); //What's wrong???????????????????????// <_-------------
            response.writeByte(0x00);
            response.writeByte(0x01);
             
            response.finishHeader();
            c.send(response);
            lobby.addClient(c);

            responseRule(c, uidChannel);
            Stage.list(c, uidChannel);
        }
S.o.b, it works. Thanks Paul, and Noob for your time and help.

Isn't it more like :
Code:
public static void responseJoin(Client c, GunzPacket p)
        {
            p.setIndex(11);
            UID uidPlayer = new UID();
            UID uidChannel = new UID();

            uidPlayer.first = (uint)p.readInt();
            uidPlayer.second = (uint)p.readInt();
            uidChannel.first = (uint)p.readInt();
            uidChannel.second = (uint)p.readInt();

            if (uidPlayer != c.uid)
               return;

            Lobby loopy = new Lobby();
            lobby = Lobby.getLobbyByUID(uidChannel);

            GunzPacket response = new GunzPacket(0x64, 0x4B7);
            response.startHeader();

            response.writeInt(uidChannel.first);
            response.writeInt(uidChannel.second);
//bp here and check lobby.name            response.writeInt(0x00);
            response.writeString(loopy.name); //What's wrong???????????????????????// <_-------------
            response.writeByte(0x00);
            response.writeByte(0x01);
             
            response.finishHeader();
            c.send(response);
            lobby.addClient(c);

            responseRule(c, uidChannel);
            Stage.list(c, uidChannel);
        }
 
Back