r8356 - autosell broken on iRO Chaos

Forum closed. All further discussion to be discussed at https://github.com/OpenKore/

Moderators: Moderators, Developers

Message
Author
User avatar
ChrstphrR
Testers Team
Testers Team
Posts: 42
Joined: 09 May 2010, 17:30
Noob?: No
Location: Northern Alberta, Canada

r8356 - autosell broken on iRO Chaos

#1 Post by ChrstphrR »

Affected versions: r8356 (current Head as of this writing, but really this problem goes back to Dec 20th, when the post merge server came online)

Issue: autosell does not work properly on iRO Chaos.

This is a hack that Splizes on our IRC channel managed to conjure up to fix the autosell problem experienced on iRO Chaos since the 3-into-1 merge in late December 2012.

Inside: /src/Network/Receive/

Code: Select all

Index: ServerType0.pm
===================================================================
--- ServerType0.pm	(revision 8356)
+++ ServerType0.pm	(working copy)
@@ -3610,6 +3610,12 @@
 	for (my $i = 0; $i < length($args->{itemsdata}); $i += 10) {
 		my ($index, $price, $price_overcharge) = unpack("v L L", substr($args->{itemsdata},$i,($i + 10)));
 		my $item = $char->inventory->getByServerIndex($index);
+		#FIXME
+		#Dirty, Dirty Hack by Splizes visiting on #openkore Jan 2 2012:
+		if ($item->{amount} == 0) {
+			$item->{amount} = 1;
+			# why that would ever be zero from the server in the first place is beyond me
+		}
 		$item->{sellable} = 1; # flag this item as sellable
 		debug "[$item->{amount} x $item->{name}] for $price_overcharge z each. \n", "info";
 	}
The correction in the full routine, all displayed for those not familiar with diffs and patches:
/src/Network/Receive/ServerType0.pm (approximately line 3598 in r8356)

Code: Select all

sub npc_sell_list {
	my ($self, $args) = @_;
	#sell list, similar to buy list
	if (length($args->{RAW_MSG}) > 4) {
		my $newmsg;
		$self->decrypt(\$newmsg, substr($args->{RAW_MSG}, 4));
		my $msg = substr($args->{RAW_MSG}, 0, 4).$newmsg;
	}
	undef $talk{buyOrSell};
	message T("Ready to start selling items\n");
	
	debug "You can sell:\n", "info";
	for (my $i = 0; $i < length($args->{itemsdata}); $i += 10) {
		my ($index, $price, $price_overcharge) = unpack("v L L", substr($args->{itemsdata},$i,($i + 10)));
		my $item = $char->inventory->getByServerIndex($index);
		#FIXME
		#Dirty, Dirty Hack by Splizes visiting on #openkore Jan 2 2012:
		if ($item->{amount} == 0) {
			$item->{amount} = 1;
			# why that would ever be zero from the server in the first place is beyond me
		}
		$item->{sellable} = 1; # flag this item as sellable
		debug "[$item->{amount} x $item->{name}] for $price_overcharge z each. \n", "info";
	}

	# continue talk sequence now
	$ai_v{npc_talk}{time} = time;
}
It IS a dirty, dirty hack like I mentioned in the comment I inserted, BUT, Splizes claims it fixed his problem.

Hope that gives other people a chance to test, to confirm a complete fix or not.
Test for multiple amounts being sold, that they're not converted into 1 item sold, etc., etc.

And, for devs, maybe this will help pinpoint the issue, so a more elegant fix can be applied.

Additional data from Splizes digging:

c9 00 08 00 15 00 00 00 - from kore
c9 00 08 00 15 00 01 00 - from iRO client

Spherical
Human
Human
Posts: 29
Joined: 03 Jan 2013, 00:05
Noob?: No

Re: r8356 - autosell broken on iRO Chaos

#2 Post by Spherical »

I'm sorry I couldn't find the actual fix for these issues, I'm sure it lies somewhere within the creation or maintaining of the items list (or even how it is passed through everything). The packets he posted at the end confirmed it for me that they were sending 0 quantity transactions (though the console also showed that). In addition to the above the storage bugs can be semi-"fixed" with by replacing the original functions mentioned below by the following:

Code: Select all

sub sendStorageAdd {
	my ($self, $index, $amount) = @_;
	# message TF("%s - Amount trying to add\n", $amount);
	if (!$amount) {
		$amount = 1;
	}
	$self->sendToServer($self->reconstruct({switch => 'storage_item_add', index => $index, amount => $amount}));
	debug "Sent Storage Add: $index x $amount\n", "sendPacket", 2;
}

sub sendStorageGet {
	my ($self, $index, $amount) = @_;
	# message TF("%s - Amount trying to take\n", $amount);
	if (!$amount) {
		$amount = 1;
	}
	$self->sendToServer($self->reconstruct({switch => 'storage_item_remove', index => $index, amount => $amount}));
	debug "Sent Storage Get: $index x $amount\n", "sendPacket", 2;
}

Spherical
Human
Human
Posts: 29
Joined: 03 Jan 2013, 00:05
Noob?: No

Re: r8356 - autosell broken on iRO Chaos

#3 Post by Spherical »

Ok, the following replacement will fix the issues above and most likely vending as well (I don't have a merchant to test). There must be something wrong with how non-stackable items are parsed at the moment (at least in the terms of quantity).

in src\network\receive\servertype0.pm
replace

Code: Select all

sub parse_items_nonstackable {
	my ($self, $args) = @_;

	$self->parse_items($args, $self->items_nonstackable($args), sub {
		my ($item) = @_;

		#$item->{placeEtcTab} = $item->{identified} & (1 << 2);
		$item->{broken} = $item->{identified} & (1 << 1) unless exists $item->{broken};
		$item->{idenfitied} = $item->{identified} & (1 << 0);
	})
}
with

Code: Select all

sub parse_items_nonstackable {
	my ($self, $args) = @_;

	$self->parse_items($args, $self->items_nonstackable($args), sub {
		my ($item) = @_;

		#$item->{placeEtcTab} = $item->{identified} & (1 << 2);
		$item->{amount} = 1 unless ($item->{amount}); #hax fix.... shouldn't need this
		$item->{broken} = $item->{identified} & (1 << 1) unless exists $item->{broken};
		$item->{idenfitied} = $item->{identified} & (1 << 0);
	})
}

I'd also like to point out that the following set of arguments for parsing nonstackable items does not even contain an amount value and therefore this should be defaulted to one (at least I believe so, non-stackable items that you have should always have a quantity of one). So I think that the fix I applied could be the actual fix for this problem (although it may be in the wrong spot to include this or even an improper way).

Code: Select all

		items_nonstackable => { # EQUIPMENTITEM_EXTRAINFO
			type1 => {
				len => 20,
				types => 'v2 C2 v2 C2 a8',
				keys => [qw(index nameID type identified type_equip equipped broken upgrade cards)],
			},
			type2 => {
				len => 24,
				types => 'v2 C2 v2 C2 a8 l',
				keys => [qw(index nameID type identified type_equip equipped broken upgrade cards expire)],
			},
			type3 => {
				len => 26,
				types => 'v2 C2 v2 C2 a8 l v',
				keys => [qw(index nameID type identified type_equip equipped broken upgrade cards expire bindOnEquipType)],
			},
			type4 => {
				len => 28,
				types => 'v2 C2 v2 C2 a8 l v2',
				keys => [qw(index nameID type identified type_equip equipped broken upgrade cards expire bindOnEquipType sprite_id)],
			},
			type5 => {
				len => 27,
				types => 'v2 C v2 C a8 l v2 C',
				keys => [qw(index nameID type type_equip equipped upgrade cards expire bindOnEquipType sprite_id identified)],
			},

Locked