porting Plugins

From OpenKore Wiki
Revision as of 09:06, 23 October 2009 by 4epT (talk | contribs) (copy http://web.archive.org/web/20080611113340/http://www.openkore.com/wiki/index.php/Porting_plugins_from_OpenKore_1.6_to_2.0.1_and_higher)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

OpenKore 1.9 is, in some ways, internally incompatible with OpenKore 1.6. So some plugins for 1.6 don't work in 1.9. This guide teaches you how to port your plugins.


Network message sending

The interface for sending messages (packets) to the server has changed. So functions like sendAttack(), sendSit(), etc. must be called in a different way.

Change:

sendFoo(\$remote_socket, ...);

- and/or -

$net->sendFoo(...);

to:

$messageSender->sendFoo(...);

($messageSender is a global variable)

And change:

Network::Send::decrypt(\$newmsg, $msg);

to:

Network::Receive->decrypt(\$newmsg, $msg);

One exception is the sendMessage function. Change:

sendMessage($net, $from, $msg, $type);

or

sendMessage(\$remote_socket, $from, $msg, $type);

to:

sendMessage($messageSender, $from, $msg, $type);


Win32 functions

The 'WinUtils' module has been renamed to 'Utils::Win32'.

Original Change to
use WinUtils; use Utils::Win32;
WinUtils::foo(...); Utils::Win32::foo(...);


Field class

Don't use %field anymore, it has been replaced with $field (also a global variable), which is an object of type Field.

Original Change to
something(\%field); something($field);
message "Field name is $field{name}\n"; message "Field name is " . $field->name() . "\n";


Skill class

The 'Skills' class has been replace by the Skill class. The interface is slightly different. Here's a summary of things that have to be changed:

Original Change to
use Skills; use SKill;
Skills->new(id => ...)
new Skills(id => ...)
SKill->new(idn => ...)
new Skill(idn => ...)
$skill->handle() $skill->getHandle()
$skill->id() $skill->getIDN()
$skill->name() $skill->getName()


Character inventory

The code for maintaining the character inventory has changed since version 2.0.1. Storage inventory and cart inventory are not affected by this change. $char->{inventory} doesn't exist anymore. Instead, one should use $char->inventory, which returns an InventoryList object. Use the InventoryList methods to access the inventory.

Change things like this:

my $invIndex = findIndexString($char->{inventory}, "name", "Jellopy");
my $item = $char->{inventory}[$invIndex];

To:

my $item = $char->inventory->getByName("Jellopy");

InventoryList is a subclass of ObjectList, so you can use all the usual ObjectList methods on InventoryList. For example, getting an item by inventory index used to be done like this:

my $item = $char->{inventory}[$invIndex];

Now it is:

my $item = $char->inventory->get($invIndex);

And iteration has changed from:

for (my $i = 0; $i < @{$char->{inventory}}; $i++) {
   my $item = $char->{inventory}[$i];
   next if (!$item || !%{$item});
   # ...do something with $item...
}

To:

foreach my $item (@{$char->inventory->getItems()}) {
   # ObjectList guarantees that there are no undefined items when iterating through it

   # ...do something with $item...
}