Prechádzať zdrojové kódy

Added script checks against swapping items using third-party hacks.
- Follow-up to 416f6d7, as further protection against item exploits.

Contains a few other fixes.

Signed-off-by: Euphy <euphy.raliel@rathena.org>

Euphy 10 rokov pred
rodič
commit
14fddd3790

+ 2 - 2
npc/cities/geffen.txt

@@ -125,7 +125,7 @@ geffen,147,26,0	script	Ralphie	97,{
 }
 
 geffen,111,48,0	script	Stacey	101,{
-	if (getequipid(1) == 2299) {
+	if (getequipid(EQI_HEAD_TOP) == 2299) {
 		mes "[Stacey]";
 		mes "Oh...!";
 		mes "Is that an Orc Helm you're wearing?! That's so cool! Wow...";
@@ -141,7 +141,7 @@ geffen,111,48,0	script	Stacey	101,{
 		}
 		close;
 	}
-	else if (getequipid(1) == 5094) {
+	else if (getequipid(EQI_HEAD_TOP) == 5094) {
 		mes "[Stacey]";
 		mes "Oh...";
 		mes "Wow...";

+ 5 - 5
npc/custom/etc/marriage.txt

@@ -394,19 +394,19 @@ OnTimer55000:
 
 //Subfunction: Checks that the groom/bride is still wearing their stuff.
 function SF_equip_check {
-	if (Sex && getequipid(2) != 7170) {
+	if (Sex && getequipid(EQI_ARMOR) != 7170) {
 		mes "["+@name$+"]";
 		mes "Child, what did you do with your "+getitemname(7170)+"?";
 		emotion e_dots;
 		return 0;
 	}
-	if (Sex == 0 && getequipid(2) != 2338) {
+	if (Sex == 0 && getequipid(EQI_ARMOR) != 2338) {
 		mes "["+@name$+"]";
 		mes "Child, you are supposed to wear a "+getitemname(2338)+" at all times during the ceremony...";
 		emotion e_dots;
 		return 0;
 	}
-	if (Sex == 0 && $@wed_veil && getequipid(1) != 2206) {
+	if (Sex == 0 && $@wed_veil && getequipid(EQI_HEAD_TOP) != 2206) {
 		mes "["+@name$+"]";
 		mes "Child, you can't take off your "+getitemname(2206)+" yet....";
 		emotion e_dots;
@@ -692,12 +692,12 @@ function SF_TryRegister {
 	else
 		set @item, 2338;
 	
-	if (getequipid(2) != @item) {
+	if (getequipid(EQI_ARMOR) != @item) {
 		mes "["+@name$+"]";
 		mes "You should be wearing a "+getitemname(@item)+" if you want to get married.";
 		close;
 	}
-	if (Sex == 0 && $@wed_veil && getequipid(1) != 2206) {
+	if (Sex == 0 && $@wed_veil && getequipid(EQI_HEAD_TOP) != 2206) {
 		mes "["+@name$+"]";
 		mes "Where is your "+getitemname(2206)+"? It's a necessary complement to your dress.";
 		close;

+ 11 - 1
npc/events/RWC_2012.txt

@@ -67,6 +67,11 @@ prontera,147,61,3	script	Driller#pron	87,{
 		mes "This item has already been enchanted. I can't work on this as it is against the rules.";
 		close;
 	}
+
+	// anti-hack
+	if (callfunc("F_IsEquipIDHack", .@part, .@equip_id))
+		close;
+
 	delequip .@part;
 	if (rand(1,10) > 5) {
 		getitem .@slotted,1;
@@ -113,7 +118,6 @@ prontera,147,59,3	script	Goldberg#pron	878,{
 		mes "Alright, then, see you next time...";
 		close;
 	}
-	set .@equip_refine, getequiprefinerycnt(.@part);
 	setarray .@equip_card[0], getequipcardid(.@part,0),getequipcardid(.@part,1),getequipcardid(.@part,2),getequipcardid(.@part,3);
 	if (.@select == 1) {
 		switch(getequipid(.@part)) {
@@ -257,6 +261,11 @@ prontera,147,59,3	script	Goldberg#pron	878,{
 		else if (.@i < 301) set .@enchant, .@enc[2];
 		else set .@enchant,9;
 
+		// anti-hack
+		if (callfunc("F_IsEquipIDHack", .@part, .@equip_id) ||
+		    callfunc("F_IsEquipCardHack", .@part, .@equip_card[0], .@equip_card[1], .@equip_card[2], .@equip_card[3]))
+			close;
+
 		set .@equip_card[.@slot], .@enchant;
 		if (.@slot == 2 && .@enchant == 0) {
 			set .@equip_card[3],0;
@@ -269,6 +278,7 @@ prontera,147,59,3	script	Goldberg#pron	878,{
 			set .@equip_card[3],0;
 		}
 
+		set .@equip_refine, getequiprefinerycnt(.@part);
 		delequip .@part;
 		if (.@enchant == 9) {
 			mes "[Goldberg]";

+ 1 - 1
npc/events/valentinesday_2012.txt

@@ -118,7 +118,7 @@ mosk_in,21,244,3	script	Baker Extraordinaire	410,{
 		close;
 	} else if(#V_QUE12==1) { 
 		mes .@n$;
-		if (getequipid(1) == 5024 && getequiprefinerycnt(1) >= 8) {
+		if (getequipid(EQI_HEAD_TOP) == 5024 && getequiprefinerycnt(EQI_HEAD_TOP) >= 8) {
 			mes "Ah, so Pinkamenia told you";
 			mes "to bring me the +8 Cake";
 			mes "Hat. Now I'm going";

+ 3 - 3
npc/jobs/2-2/crusader.txt

@@ -360,7 +360,7 @@ prt_castle,164,32,1	script	Man in Anguish	733,{
 			mes "Let me take";
 			mes "a look at your face.";
 			next;
-			if(getequipid(7) != 2608 && getequipid(8) != 2608) {
+			if(getequipid(EQI_ACC_L) != 2608 && getequipid(EQI_ACC_R) != 2608) {
 				mes "[Murnak Mijoul]";
 				mes "Hmm. You wish to become a Crusader, but do not wear a Rosary? I have no business with you if you cannot uphold our customs.";
 				close;
@@ -401,7 +401,7 @@ prt_castle,164,32,1	script	Man in Anguish	733,{
 			mes "I'll let you retake the test as much as you like. But if you continuously fail, there's an inherent problem with your";
 			mes "state of mind.";
 			next;
-			if(getequipid(7) != 2608 && getequipid(8) != 2608) {
+			if(getequipid(EQI_ACC_L) != 2608 && getequipid(EQI_ACC_R) != 2608) {
 				mes "[Murnak Mijoul]";
 				mes "Wait...";
 				mes "Where have you left your Rosary? You can't let that lie around just anywhere. We are supposed to be warriors of holiness.";
@@ -888,7 +888,7 @@ prt_castle,35,151,5	script	Patron Knight	751,{
 		}
 		next;
 		if (select("I would like to begin.:Give me some time to prepare.") == 1) {
-			if(getequipid(7) != 2608 && getequipid(8) != 2608) {
+			if(getequipid(EQI_ACC_L) != 2608 && getequipid(EQI_ACC_R) != 2608) {
 				mes "[Bliant Piyord]";
 				mes "Just a second, you do not have a Rosary equipped. As a Crusader, you must always have a Rosary on your person.";
 				next;

+ 3 - 7
npc/merchants/refine.txt

@@ -708,13 +708,9 @@ function	script	refinemain	{
 		set Zeny, Zeny-.@price;
 		delitem .@material,1;
 
-		//custom checks
-		if(getequipisequiped(.@part) == 0) { // hacker has removed the item (not changed, why?)
-			mes "[" + getarg(0) + "]";
-			mes "Look here... you don't have any Items on...";
-			close;
-		}
-		if(getequiprefinerycnt(.@part) != .@refinerycnt || getequipid(.@part) != .@refineitemid) { // hacker has changed the item
+		// anti-hack
+		if (callfunc("F_IsEquipIDHack", .@part, .@refineitemid) ||
+		    callfunc("F_IsEquipRefineHack", .@part, .@refinerycnt)) {
 			mes "[" + getarg(0) + "]";
 			emotion e_an;
 			mes "Wait a second...";

+ 43 - 1
npc/other/Global_Functions.txt

@@ -3,7 +3,7 @@
 //===== By: ================================================== 
 //= Lupus, kobra_k88
 //===== Current Version: ===================================== 
-//= 2.23
+//= 2.24
 //===== Compatible With: ===================================== 
 //= rAthena Project
 //===== Description: ========================================= 
@@ -46,6 +46,7 @@
 //= 2.21 Added format string to "F_InsertPlural" and more checks to "F_GetPlural". [Euphy]
 //= 2.22 Further improvements to "F_GetPlural". [Euphy]
 //= 2.23 Completed article function and added "F_GetArticle". [Euphy]
+//= 2.24 Added functions to check for equipment swap hacks. [Euphy]
 //============================================================ 
 
 //////////////////////////////////////////////////////////////////////////////////
@@ -362,6 +363,47 @@ function	script	Time2Str	{
 }
 
 
+//////////////////////////////////////////////////////////////////////////////////
+// Checks if equipment has been swapped (i.e. via hacks).
+// The function checks the current equipment at a position against the supplied
+// values, and logs any mismatches.
+// Returns 0 if match, 1 if mismatch.
+// -- callfunc "F_IsEquipIDHack",<equip position>,<equip ID>
+// -- callfunc "F_IsEquipRefineHack",<equip position>,<refine>
+// -- callfunc "F_IsEquipCardHack",<equip position>,<card 0>,<card 1>,<card 2>,<card 3>
+//////////////////////////////////////////////////////////////////////////////////
+function	script	F_IsEquipIDHack	{
+	set .@id_chk, getequipid(getarg(0));
+	set .@id, getarg(1);
+	if (.@id != .@id_chk) {
+		logmes "Hack: Tried to swap equip " + getitemname(.@id) + " for " + getitemname(.@id_chk) + ".";
+		return 1;
+	}
+	return 0;
+}
+function	script	F_IsEquipRefineHack	{
+	set .@refine_chk, getequiprefinerycnt(getarg(0));
+	set .@refine, getarg(1);
+	if (.@refine != .@refine_chk) {
+		logmes "Hack: Tried to swap equip with refine +" + .@refine + " for +" + .@refine_chk + ".";
+		return 1;
+	}
+	return 0;
+}
+function	script	F_IsEquipCardHack	{
+	set .@pos, getarg(0);
+	for (set .@i,0; .@i < 4; set .@i, .@i+1) {
+		set .@card, getarg(.@i + 1);
+		set .@card_chk, getequipcardid(.@pos, .@i);
+		if (.@card != .@card_chk) {
+			logmes "Hack: Tried to swap card " + getitemname(.@card) + " for " + getitemname(.@card_chk) + ".";
+			return 1;
+		}
+	}
+	return 0;
+}
+
+
 //////////////////////////////////////////////////////////////////////////////////
 // Functions for text manipulation [Euphy]
 //////////////////////////////////////////////////////////////////////////////////

+ 1 - 1
npc/quests/cooking_quest.txt

@@ -79,7 +79,7 @@ prt_castle,43,30,3	script	Charles Orleans#cook	878,{
 		mes "the stairs for me, alright?";
 		goto L_End;
 	}
-	else if (getequipid(1) != 5026) {
+	else if (getequipid(EQI_HEAD_TOP) != 5026) {
 		if (Sex) {
 			cutin "orleans_5",0;
 			emotion e_an;

+ 10 - 16
npc/re/instances/WolfchevLaboratory.txt

@@ -924,20 +924,20 @@ lhz_cube,233,24,4	script	Sorcerer#Bio4Reward	4_M_UMDANCEKID,{
 	.@refine_count = getequiprefinerycnt(.@part);
 	.@equip_item = getequipid(.@part);
 	.@lhz_max_num = 4000;
-	if (.@equip_item == Agent_Katar || .@equip_item == Guillotine_Katar || .@equip_item == Ygnus_Stale || 
-	    .@equip_item == End_Sektura || .@equip_item = Cannon_Spear || .@equip_item == Giant_Lance || 
-	    .@equip_item == Aztoe_Nail || .@equip_item == Scarletto_Nail || .@equip_item == Bloody_Cross) {
+	if (.@equip_item == 13069 || .@equip_item == 1291 || .@equip_item == 1392 || 
+	    .@equip_item == 1393 || .@equip_item = 1435 || .@equip_item == 1490 || 
+	    .@equip_item == 13069 || .@equip_item == 13070 || .@equip_item == 16017) {
 		.@type = 1;
-		if (.@equip_item == Giant_Lance)
+		if (.@equip_item == 1490)
 			.@lhz_max_num = 4200;
-	} else if (.@equip_item == Catapult || .@equip_item == Big_CrossBow || .@equip_item == Creeper_Bow) {
+	} else if (.@equip_item == 18109 || .@equip_item == 18110 || .@equip_item == 18111) {
 		.@type = 2;
-	} else if (.@equip_item == Chilly_Spell_Book || .@equip_item == Recovery_Light) {
+	} else if (.@equip_item == 1584 || .@equip_item == 1659) {
 		.@type = 3;
-	} else if (.@equip_item== Giant_Shield || .@equip_item == Geffenia_Book_Water || .@equip_item == Bible_Of_Promise2 ||
-	           .@equip_item == Salvage_Cape || .@equip_item == Assassin_Handcuffs || .@equip_item == Green_Operation_Coat || 
-	           .@equip_item == Ancient_Gold_Deco) {
-		if (.@equip_item == Salvage_Cape || .@equip_item == Ancient_Gold_Deco)
+	} else if (.@equip_item == 2160 || .@equip_item == 2161 || .@equip_item == 2162 ||
+	           .@equip_item == 2582 || .@equip_item == 2892 || .@equip_item == 15044 || 
+	           .@equip_item == 18570) {
+		if (.@equip_item == 2582 || .@equip_item == 18570)
 			.@lhz_max_num = 4200;
 	} else {
 		mes "[Pudding]";
@@ -1258,12 +1258,6 @@ lhz_cube,233,24,4	script	Sorcerer#Bio4Reward	4_M_UMDANCEKID,{
 		} else {
 			specialeffect2 EF_FIREHIT;
 			getitem2 .@equip_item, 1, 1, .@refine_count, 0, .@equip_card[0], .@equip_card[1], .@equip_card[2], .@equip_card[3];
-			//dispbottom "1:"+ .@equip_item;
-			//dispbottom "1:"+ .@refine_count;
-			//dispbottom "1:"+ .@equip_card[0];
-			//dispbottom "1:"+ .@equip_card[1];
-			//dispbottom "1:"+ .@equip_card[2];
-			//dispbottom "1:"+ .@equip_card[3];
 			emotion e_ho;
 			mes "[Pudding]";
 			mes "Fortunately the power of "+((.@socket_type==3)?"'^952420Thirst for Blood^000000'":"'^F2766EWill of Warrior^000000'")+" has been dwelt well in your equipment...";

+ 5 - 0
npc/re/merchants/card_separation.txt

@@ -285,6 +285,11 @@
 
 	set .@equip_id, getequipid(.@equip_num);
 	set .@equip_refine, getequiprefinerycnt(.@equip_num);
+
+	// anti-hack
+	if (callfunc("F_IsEquipCardHack", .@equip_num, .@equip_card[0], .@equip_card[1], .@equip_card[2], .@equip_card[3]))
+		close;
+
 	delequip .@equip_num;
 
 	// Chance of retaining refine level.

+ 14 - 1
npc/re/merchants/enchan_mal.txt

@@ -318,7 +318,6 @@ L_Socket:
 	set .@select, @mal_enchant_select;
 	set .@equip_id, @mal_equip_id;
 	set .@equip_name$, getitemname(.@equip_id)+((getitemslots(.@equip_id))?"["+getitemslots(.@equip_id)+"]":"");
-	set .@equip_refine, getequiprefinerycnt(EQI_HAND_R);
 	setarray .@equip_card[0], getequipcardid(EQI_HAND_R,0),getequipcardid(EQI_HAND_R,1),getequipcardid(EQI_HAND_R,2),getequipcardid(EQI_HAND_R,3);
 	set @mal_equip_id,0;
 	set @mal_enchant_select,0;
@@ -570,6 +569,12 @@ L_Socket:
 			mes "There is something wrong. Please try again.";
 			close;
 		}
+
+		// anti-hack
+		if (callfunc("F_IsEquipIDHack", EQI_HAND_R, .@equip_id) ||
+		    callfunc("F_IsEquipCardHack", EQI_HAND_R, .@equip_card[0], .@equip_card[1], .@equip_card[2], .@equip_card[3]))
+			close;
+
 		     if (.@equip_card[3] == 0 && getarg(1) < 4) set .@equip_card[3],.@enchant;
 		else if (.@equip_card[2] == 0 && getarg(1) < 3) set .@equip_card[2],.@enchant;
 		else if (.@equip_card[1] == 0 && getarg(1) < 2) set .@equip_card[1],.@enchant;
@@ -595,6 +600,7 @@ L_Socket:
 		mes "[Mayomayo]";
 		mes "I have enchanted ^990000slot "+.@socket+"^000000 of this equipment.";
 		delitem .@coin[.@coin_select],.@total[.@coin_select];
+		set .@equip_refine, getequiprefinerycnt(EQI_HAND_R);
 		delequip EQI_HAND_R;
 
 //		GetNonSlotItemSock2 .@equip_refine .@equip_id .@equip_card[0] .@equip_card[1] .@equip_card[2] .@equip_card[3]
@@ -629,6 +635,13 @@ L_Socket:
 		mes "[Mayomayo]";
 		mes "Initialize the enchant effect from the equipment.";
 		delitem 6417,1; //Silvervine
+
+		// anti-hack
+		if (callfunc("F_IsEquipIDHack", EQI_HAND_R, .@equip_id) ||
+		    callfunc("F_IsEquipCardHack", EQI_HAND_R, .@equip_card[0], .@equip_card[1], .@equip_card[2], .@equip_card[3]))
+			close;
+
+		set .@equip_refine, getequiprefinerycnt(EQI_HAND_R);
 		delequip EQI_HAND_R;
 
 //		GetNonSlotItemSock2 .@equip_refine .@equip_id .@equip_card[0] .@equip_card[1] .@equip_card[2] .@equip_card[3]

+ 14 - 0
npc/re/merchants/enchan_mora.txt

@@ -1078,6 +1078,13 @@ L_Socket:
 			mes "Well I guess I was wrong...";
 			close;
 		}
+
+		// anti-hack
+		if (callfunc("F_IsEquipIDHack", .@part, .@equip_id) ||
+		    callfunc("F_IsEquipRefineHack", .@part, .@equip_refine) ||
+		    callfunc("F_IsEquipCardHack", .@part, .@equip_card[0], .@equip_card[1], .@equip_card[2], .@equip_card[3]))
+			close;
+
 		if (.@equip_card[3] == 0 && getarg(2) < 4) {
 			set .@equip_card[3],.@enchant;
 		} else if (.@equip_card[2] == 0 && getarg(2) < 3) {
@@ -1103,6 +1110,13 @@ L_Socket:
 		}
 		delitem 6380,1; //Mora_Coin
 		set Zeny, Zeny-100000;
+
+		// anti-hack
+		if (callfunc("F_IsEquipIDHack", .@part, .@equip_id) ||
+		    callfunc("F_IsEquipRefineHack", .@part, .@equip_refine) ||
+		    callfunc("F_IsEquipCardHack", .@part, .@equip_card[0], .@equip_card[1], .@equip_card[2], .@equip_card[3]))
+			close;
+
 		delequip .@part;
 		if (.@enchant == 9) {
 			specialeffect2 EF_SUI_EXPLOSION;

+ 14 - 1
npc/re/merchants/enchan_upg.txt

@@ -89,7 +89,6 @@ prt_in,28,73,3	script	Devil Enchant Master#prq	63,{
 		mes "I don't want to touch your equipment now!";
 		close;
 	}
-	set .@equip_refine, getequiprefinerycnt(.@part);
 
 	if (.@select == 1) {
 		if (!countitem(6484)) {
@@ -218,6 +217,7 @@ prt_in,28,73,3	script	Devil Enchant Master#prq	63,{
 			mes "Are you listening to me? I will only do for you if you bring the Enchant Book!";
 			close;
 		}
+		set .@equip_refine, getequiprefinerycnt(.@part);
 		if (.@enchant == 0) {
 			specialeffect EF_SHIELDCHARGE;
 			mes "Oh! Unbelievable!! It failed!! Please come again!";
@@ -228,6 +228,12 @@ prt_in,28,73,3	script	Devil Enchant Master#prq	63,{
 			mes "The slot ^9900004^000000 has been enchanted!";
 		}
 		delitem 6484,1; //Enchant_Book
+
+		// anti-hack
+		if (callfunc("F_IsEquipIDHack", .@part, .@equip_id) ||
+		    callfunc("F_IsEquipCardHack", .@part, .@equip_card[0], .@equip_card[1], .@equip_card[2], .@equip_card[3]))
+			close;
+
 		delequip .@part;
 
 //		GetNonSlotItemSock2 .@equip_refine .@equip_id .@equip_card[0] .@equip_card[1] .@equip_card[2] .@enchant
@@ -255,6 +261,13 @@ prt_in,28,73,3	script	Devil Enchant Master#prq	63,{
 		specialeffect EF_REPAIRWEAPON;
 		mes "I initialized the enchant effects.";
 		set Zeny, Zeny - 100000;
+
+		// anti-hack
+		if (callfunc("F_IsEquipIDHack", .@part, .@equip_id) ||
+		    callfunc("F_IsEquipCardHack", .@part, .@equip_card[0], .@equip_card[1], .@equip_card[2], .@equip_card[3]))
+			close;
+
+		set .@equip_refine, getequiprefinerycnt(.@part);
 		delequip .@part;
 
 //		GetNonSlotItemSock2 .@equip_refine .@equip_id .@equip_card[0] .@equip_card[1] .@equip_card[2] 0

+ 3 - 7
npc/re/merchants/refine.txt

@@ -157,13 +157,9 @@ function	script	refinenew	{
 		set Zeny,Zeny - .@price;
 		delitem .@material,1;
 
-		//custom checks
-		if (getequipisequiped(.@part) == 0) { // hacker has removed the item (not changed, why?)
-			mes "[" + getarg(0) + "]";
-			mes "Look here... you don't have any items on...";
-			close;
-		}
-		if (getequiprefinerycnt(.@part) != .@refinerycnt || getequipid(.@part) != .@refineitemid) { // hacker has changed the item
+		// anti-hack
+		if (callfunc("F_IsEquipIDHack", .@part, .@refineitemid) ||
+		    callfunc("F_IsEquipRefineHack", .@part, .@refinerycnt)) {
 			mes "[" + getarg(0) + "]";
 			emotion e_an;
 			mes "Wait a second...";

+ 6 - 3
npc/re/quests/quests_malaya.txt

@@ -3773,7 +3773,7 @@ ma_fild01,158,243,6	script	Tribe Blacksmith#malaya	582,{
 		break;
 	}
 	
-	if (!(.@item)) {
+	if (!getequipisequiped(.@part)) {
 		mes "[Bayani]";
 		mes "You should wear the equipment to upgrade and not come without it on you.";
 		close;
@@ -3819,11 +3819,14 @@ ma_fild01,158,243,6	script	Tribe Blacksmith#malaya	582,{
 	mes "[Bayani]";
 	mes "BAM!!";
 	next;
-	
 	delitem 6499,20; //Ancient_Grudge
+
+	// anti-hack
+	if (callfunc("F_IsEquipIDHack", .@part, .@item))
+		close;
+
 	delequip .@part;
 	getitem .@newItem, 1; 
-	
 	mes "[Bayani]";
 	mes "Ha ha. Perfect.";
 	mes "Congratulations. Your armor is better than ever.";