Strange problem with if statement

I'm pretty confused because I've written a plug in for a program before and when i wanted to remake pretty much the same plug in it won't work.

This is the current code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
void TemplateModule::OnRelayDataToClient(IPacket* packet, const IModule* owner)
{
	const unsigned char* bytes = static_cast<const unsigned char*>(packet->GetData());
	int packetId = bytes[0];
	static int andyId[3];
	static bool AndyFound = false;

	switch (packetId){
		case 0x69:{
			//if andys id is registered
			if(AndyFound){
			//if monster is dying
			if(bytes[5] == 0x08){
			//if id of the monster as dying is the same as andys id
			if(bytes[1] == andyId[0] && bytes[2] == andyId[1] && bytes[3] == andyId[2] && bytes[4] == andyId[3]){
				packet->SetFlag(IPacket::PacketFlag_Dead);
				AndyFound = false;
			}}}break;}

		case 0xAC:{
			//if assigned monster is andy
			if(bytes[5] == 0x9c && bytes[6] == 0x00){
			andyId[0] = bytes[1];
			andyId[1] = bytes[2];
			andyId[2] = bytes[3];
			andyId[3] = bytes[4];
			AndyFound = true;
			}break;}
	}
}


This is the old code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
void TemplateModule::OnRelayDataToClient(IPacket* packet, const IModule* owner)
{

	const unsigned char* bytes = static_cast<const unsigned char*>(packet->GetData());
	int packetId = bytes[0];
	static int AndyCurrId[3];

	switch (packetId)
	{
	case 0xac:
	{
		if(bytes[5] == 0x9c && bytes[6] == 0x00)
		{ 
		Chat(ChatName, false, "Andariel Found!");  
		AndyCurrId[0] = bytes[1];
		AndyCurrId[1] = bytes[2];
		AndyCurrId[2] = bytes[3];
		AndyCurrId[3] = bytes[4];
		}
	}
	case 0x69:
	{ 
		if(bytes[5] == 0x08 && bytes[11] == 0x0d && bytes[1] == AndyCurrId[0] && bytes[2] == AndyCurrId[1] && bytes[3] == AndyCurrId[2] && bytes[4] == AndyCurrId[3])
		{
		packet->SetFlag(IPacket::PacketFlag_Dead);
		Chat(ChatName, false, "Andariel Died!"); 

	int length = 12;

	unsigned char* buffer = new unsigned char[length];
	int offset = 0;

	buffer[offset++] = 0x69;

	buffer[offset++] = AndyCurrId[0];
	buffer[offset++] = AndyCurrId[1];
	buffer[offset++] = AndyCurrId[2];
	buffer[offset++] = AndyCurrId[3];

	buffer[offset++] = 0x09;

	buffer[offset++] = 0x00;
	buffer[offset++] = 0x00;

	buffer[offset++] = 0x00;
	buffer[offset++] = 0x00;

	buffer[offset++] = 0x00;
	buffer[offset++] = 0x00;

	IPacket* packet = _proxy->CreatePacket(buffer, length);
	packet->SetFlag(IPacket::PacketFlag_Hidden);
	_proxy->RelayDataToClient(packet, this);
	delete packet;

	delete[] buffer;
		}	  
	}
	}
}


This is the packet Log:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[ANDARIEL]

->ac 99 b5 ea 39 9c 00 41 58 8d 25 63 13 a1 b0 00 00 00 00 
->ac 99 b5 ea 39 9c 00 36 58 8c 25 63 13 a1 b0 00 00 00 00 
->ac 99 b5 ea 39 9c 00 36 58 8d 25 63 13 a1 b0 00 00 00 00 

ASSIGN NPC: -> ac 3b 94 00 8d 9c 00 12 58 4a 25 80 13 a1 b0 00 00 00 00 
Dying NPC: ->  69 3b 94 00 8d 08 23 58 7a 25 19 40 
Dead NPC: ->   69 3b 94 00 8d 09 31 58 7c 25 19 00 

ASSIGN NPC: -> ac d7 00 dc 2a 9c 00 12 58 4a 25 80 13 a1 b0 00 00 00 00 
Dying NPC: ->  69 d7 00 dc 2a 08 25 58 77 25 04 40 
Dead NPC: ->   69 d7 00 dc 2a 09 24 58 76 25 04 00 

[ASSIGN NPCAndariel] [19]
ac => Assign NPC[1]
99 b5 ea 39 => Id[4]
9c => Andariel[1]
00 => ?[1]
36 58 => X[2]
8d 25 => Y[2]
63 13 a1 b0 00 00 00 00 => ?[8]


The old code is pretty mashed up worsen written than the new one, i do not get a compilation error.
It just doesn't seem like the underlined code in the current code occurs, but the log says it does.

I put a MessageBox on line 14 and it's being displayed correctly when it's time for it to show up.
And between the next two rows(15-16), and it does not show up.

Another question i have is will:
1
2
3
4
int offset = 0;
while(offset<5){
andyId[offset++] = bytes[offset];
}

Return the same as:
1
2
3
4
andyId[0] = bytes[1];
andyId[1] = bytes[2];
andyId[2] = bytes[3];
andyId[3] = bytes[4];


The thing i can think of is that:
1
2
static int
const unsigned char*

Are in different forms which makes the if goes like 1=2 and return false.
Last edited on
I'm not sure what your question is, or what the title of your post is referring to, so I have no idea how to answer your question, but, while reading your code I did notice that you do not have breaks at the end of any of your cases, and I'm thinking you probably intended there to be breaks there? Without breaks, execution flows through into the next case.
What am I looking at, here? I don't understand.
You are looking at a packet filtering in to the game Diablo II, it's a plugin for the proxy called Redvex.
This plugin will block a specific packet that stops the boss from starting the "world shake" on it's death.
Last edited on
Topic archived. No new replies allowed.