Monster spawn Item

Joined
Mar 10, 2010
Messages
909
Reaction score
237
Next release... It's Monster Spawn Item.

example;

(item (name 4061) (Index 3161) (Image "item095") (desc 2) (class general refresh) (code 4 8 0 0) (country 2) (use 1) (plural 1) (cooltime 1300) (buy 70) (sell 14) (specialty ) )

same as Medicine med

( itemname 4061 "Summon Item")

[ItemIndex] 3161 [MonsterIndex] 434 [Amount] 5
[ItemIndex] 3162 [MonsterIndex] 435 [Amount] 5
[ItemIndex] 3163 [MonsterIndex] 211 [Amount] 5
[ItemIndex] 3164 [MonsterIndex] 210 [Amount] 5
[ItemIndex] 3165 [MonsterIndex] 436 [Amount] 5

UPDATE 2.02.14:
View attachment summonaddon01.rar


UPDATE 2.02.14:
Source code
namespace Item
{
int __fastcall SpawnMonster(int* Item, int __edx, int* Player)
{
Summon *Monster = new Summon();
KPlayer *player = new KPlayer(Player);

ifstream spawnitem;
spawnitem.open("spawnitem.ini");
int IndexItem,MonsterIndex,Amount;
string IndexItemName,MonsterIndexName,AmountName;
if(spawnitem.is_open())
{
while (!spawnitem.eof())
{
spawnitem >> IndexItemName >> IndexItem >> MonsterIndexName >> MonsterIndex >> AmountName >> Amount;

if(player->ItemIndex(Item) == IndexItem)
{
Monster->Spawn(MonsterIndex, player->GetXCoord(), player->GetYCoord()+ 50, player->GetMap(), Amount, 20);
}
}
}
spawnitem.close();
delete Monster,player;
return Server::CItem::UseItem(Item,Player);
}
 

Attachments

Last edited:
good job^^ , but what it [ItemIndex] !!
Uhm, brain on?
(item (name 4061) (Index 3161) (Image "item095") (desc 2) (class general refresh) (code 4 8 0 0) (country 2) (use 1) (plural 1) (cooltime 1300) (buy 70) (sell 14) (specialty ) )

same as Medicine med



( itemname 4061 "Summon Item")



[ItemIndex] 3161 [MonsterIndex] 434 [Amount] 5
[ItemIndex] 3162 [MonsterIndex] 435 [Amount] 5
[ItemIndex] 3163 [MonsterIndex] 211 [Amount] 5
[ItemIndex] 3164 [MonsterIndex] 210 [Amount] 5
[ItemIndex] 3165 [MonsterIndex] 436 [Amount] 5

 
I remember this one ^^:

Code:
.text:100031F0                 push    ebp
.text:100031F1                 mov     ebp, esp
.text:100031F3                 sub     esp, 8
.text:100031F6                 push    esi
.text:100031F7                 push    edi
.text:100031F8                 push    4
.text:100031FA                 call    ds:__imp_??2@YAPAXI@Z ; operator new(uint)
.text:10003200                 mov     ecx, [ebp+lpAddress]
.text:10003203                 mov     esi, ds:VirtualProtect
.text:10003209                 add     esp, 4
.text:1000320C                 lea     eax, [ebp+flOldProtect]
.text:1000320F                 push    eax             ; lpflOldProtect
.text:10003210                 push    40h             ; flNewProtect
.text:10003212                 push    1               ; dwSize
.text:10003214                 xor     edi, edi
.text:10003216                 push    ecx             ; lpAddress
.text:10003217                 mov     [ebp+flOldProtect], edi
.text:1000321A                 mov     [ebp+flNewProtect], edi
.text:1000321D                 call    esi ; VirtualProtect
.text:1000321F                 lea     edx, [ebp+flNewProtect]
.text:10003222                 push    edx             ; lpflOldProtect
.text:10003223                 push    40h             ; flNewProtect
.text:10003225                 push    1               ; dwSize
.text:10003227                 push    44402Bh         ; lpAddress
.text:1000322C                 call    esi ; VirtualProtect
.text:1000322E                 mov     eax, [ebp+lpAddress]
.text:10003231                 lea     ecx, [ebp+flNewProtect]
.text:10003234                 push    ecx             ; lpflOldProtect
.text:10003235                 mov     ds:44402Bh, eax
.text:1000323A                 mov     edx, [ebp+flNewProtect]
.text:1000323D                 push    edx             ; flNewProtect
.text:1000323E                 push    1               ; dwSize
.text:10003240                 push    44402Bh         ; lpAddress
.text:10003245                 call    esi ; VirtualProtect
.text:10003247                 mov     ecx, [ebp+flOldProtect]
.text:1000324A                 mov     edx, [ebp+lpAddress]
.text:1000324D                 lea     eax, [ebp+flOldProtect]
.text:10003250                 push    eax             ; lpflOldProtect
.text:10003251                 push    ecx             ; flNewProtect
.text:10003252                 push    1               ; dwSize
.text:10003254                 push    edx             ; lpAddress
.text:10003255                 call    esi ; VirtualProtect
.text:10003257                 mov     ecx, [ebp+arg_4]
.text:1000325A                 lea     eax, [ebp+flOldProtect]
.text:1000325D                 push    eax             ; lpflOldProtect
.text:1000325E                 push    40h             ; flNewProtect
.text:10003260                 push    1               ; dwSize
.text:10003262                 push    ecx             ; lpAddress
.text:10003263                 mov     [ebp+flOldProtect], edi
.text:10003266                 mov     [ebp+lpAddress], edi
.text:10003269                 call    esi ; VirtualProtect
.text:1000326B                 lea     edx, [ebp+lpAddress]
.text:1000326E                 push    edx             ; lpflOldProtect
.text:1000326F                 push    40h             ; flNewProtect
.text:10003271                 push    1               ; dwSize
.text:10003273                 push    4440A6h         ; lpAddress
.text:10003278                 call    esi ; VirtualProtect
.text:1000327A                 mov     eax, [ebp+arg_4]
.text:1000327D                 lea     ecx, [ebp+lpAddress]
.text:10003280                 push    ecx             ; lpflOldProtect
.text:10003281                 mov     ds:4440A6h, eax
.text:10003286                 mov     edx, [ebp+lpAddress]
.text:10003289                 push    edx             ; flNewProtect
.text:1000328A                 push    1               ; dwSize
.text:1000328C                 push    4440A6h         ; lpAddress
.text:10003291                 call    esi ; VirtualProtect
.text:10003293                 mov     ecx, [ebp+flOldProtect]
.text:10003296                 mov     edx, [ebp+arg_4]
.text:10003299                 lea     eax, [ebp+flOldProtect]
.text:1000329C                 push    eax             ; lpflOldProtect
.text:1000329D                 push    ecx             ; flNewProtect
.text:1000329E                 push    1               ; dwSize
.text:100032A0                 push    edx             ; lpAddress
.text:100032A1                 call    esi ; VirtualProtect
.text:100032A3                 mov     ecx, [ebp+arg_8]
.text:100032A6                 lea     eax, [ebp+arg_4]
.text:100032A9                 push    eax             ; lpflOldProtect
.text:100032AA                 push    40h             ; flNewProtect
.text:100032AC                 push    1               ; dwSize
.text:100032AE                 push    ecx             ; lpAddress
.text:100032AF                 mov     [ebp+arg_4], edi
.text:100032B2                 mov     [ebp+lpAddress], edi
.text:100032B5                 call    esi ; VirtualProtect
.text:100032B7                 lea     edx, [ebp+lpAddress]
.text:100032BA                 push    edx             ; lpflOldProtect
.text:100032BB                 push    40h             ; flNewProtect
.text:100032BD                 push    1               ; dwSize
.text:100032BF                 push    4440ADh         ; lpAddress
.text:100032C4                 call    esi ; VirtualProtect
.text:100032C6                 mov     eax, [ebp+arg_8]
.text:100032C9                 lea     ecx, [ebp+lpAddress]
.text:100032CC                 push    ecx             ; lpflOldProtect
.text:100032CD                 mov     ds:4440ADh, eax
.text:100032D2                 mov     edx, [ebp+lpAddress]
.text:100032D5                 push    edx             ; flNewProtect
.text:100032D6                 push    1               ; dwSize
.text:100032D8                 push    4440ADh         ; lpAddress
.text:100032DD                 call    esi ; VirtualProtect
.text:100032DF                 mov     ecx, [ebp+arg_4]
.text:100032E2                 mov     edx, [ebp+arg_8]
.text:100032E5                 lea     eax, [ebp+arg_4]
.text:100032E8                 push    eax             ; lpflOldProtect
.text:100032E9                 push    ecx             ; flNewProtect
.text:100032EA                 push    1               ; dwSize
.text:100032EC                 push    edx             ; lpAddress
.text:100032ED                 call    esi ; VirtualProtect
.text:100032EF                 lea     eax, [ebp+arg_4]
.text:100032F2                 push    eax             ; lpflOldProtect
.text:100032F3                 push    40h             ; flNewProtect
.text:100032F5                 push    1               ; dwSize
.text:100032F7                 push    ebx             ; lpAddress
.text:100032F8                 mov     [ebp+arg_4], edi
.text:100032FB                 mov     [ebp+lpAddress], edi
.text:100032FE                 call    esi ; VirtualProtect
.text:10003300                 lea     ecx, [ebp+lpAddress]
.text:10003303                 push    ecx             ; lpflOldProtect
.text:10003304                 push    40h             ; flNewProtect
.text:10003306                 push    1               ; dwSize
.text:10003308                 push    4440BAh         ; lpAddress
.text:1000330D                 call    esi ; VirtualProtect
.text:1000330F                 lea     edx, [ebp+lpAddress]
.text:10003312                 push    edx             ; lpflOldProtect
.text:10003313                 mov     ds:4440BAh, ebx
.text:10003319                 mov     eax, [ebp+lpAddress]
.text:1000331C                 push    eax             ; flNewProtect
.text:1000331D                 push    1               ; dwSize
.text:1000331F                 push    4440BAh         ; lpAddress
.text:10003324                 call    esi ; VirtualProtect
.text:10003326                 mov     edx, [ebp+arg_4]
.text:10003329                 lea     ecx, [ebp+arg_4]
.text:1000332C                 push    ecx             ; lpflOldProtect
.text:1000332D                 push    edx             ; flNewProtect
.text:1000332E                 push    1               ; dwSize
.text:10003330                 push    ebx             ; lpAddress
.text:10003331                 call    esi ; VirtualProtect
.text:10003333                 lea     eax, [ebp+arg_4]
.text:10003336                 push    eax             ; lpflOldProtect
.text:10003337                 push    40h             ; flNewProtect
.text:10003339                 push    1               ; dwSize
.text:1000333B                 push    14h             ; lpAddress
.text:1000333D                 mov     [ebp+arg_4], edi
.text:10003340                 mov     [ebp+lpAddress], edi
.text:10003343                 call    esi ; VirtualProtect
.text:10003345                 lea     ecx, [ebp+lpAddress]
.text:10003348                 push    ecx             ; lpflOldProtect
.text:10003349                 push    40h             ; flNewProtect
.text:1000334B                 push    1               ; dwSize
.text:1000334D                 push    444129h         ; lpAddress
.text:10003352                 call    esi ; VirtualProtect
.text:10003354                 lea     edx, [ebp+lpAddress]
.text:10003357                 push    edx             ; lpflOldProtect
.text:10003358                 mov     dword ptr ds:444129h, 14h
.text:10003362                 mov     eax, [ebp+lpAddress]
.text:10003365                 push    eax             ; flNewProtect
.text:10003366                 push    1               ; dwSize
.text:10003368                 push    444129h         ; lpAddress
.text:1000336D                 call    esi ; VirtualProtect
.text:1000336F                 mov     edx, [ebp+arg_4]
.text:10003372                 lea     ecx, [ebp+arg_4]
.text:10003375                 push    ecx             ; lpflOldProtect
.text:10003376                 push    edx             ; flNewProtect
.text:10003377                 push    1               ; dwSize
.text:10003379                 push    14h             ; lpAddress
.text:1000337B                 call    esi ; VirtualProtect
.text:1000337D                 mov     eax, [ebp+arg_C]
.text:10003380                 cmp     eax, edi
.text:10003382                 jle     short loc_10003395
.text:10003384                 mov     esi, eax

good job, nice to see that you release some things for the community : )
 
Great work, but I would enjoy to have the source more for learning purposes, and making improvements to my own coding style.
ida/olly could never help me with that.
 
ye why not, it's kinda easy addon.. ;)

namespace Item
{
int __fastcall SpawnMonster(int* Item, int __edx, int* Player)
{
Summon *Monster = new Summon();
KPlayer *player = new KPlayer(Player);

ifstream spawnitem;
spawnitem.open("spawnitem.ini");
int IndexItem,MonsterIndex,Amount;
string IndexItemName,MonsterIndexName,AmountName;
if(spawnitem.is_open())
{
while (!spawnitem.eof())
{
spawnitem >> IndexItemName >> IndexItem >> MonsterIndexName >> MonsterIndex >> AmountName >> Amount;

if(player->ItemIndex(Item) == IndexItem)
{
Monster->Spawn(MonsterIndex, player->GetXCoord(), player->GetYCoord()+ 50, player->GetMap(), Amount, 20);
}
}
}
spawnitem.close();
delete Monster,player;
return Server::CItem::UseItem(Item,Player);
}
}

i did hook at UseItem function.
 
Last edited:
It was especially the UseItem hook I was curious to see ^^

this is the use item hook he just renamed it to "SpawnMonster"
int __fastcall SpawnMonster(int* Item, int __edx, int* Player)
{};

i did it like this a while ago...hooked at 0x0042CFB0

static int (__thiscall *UseItem)(int *ItemPointer, int PlayerPointer) = (int (__thiscall*)(int*,int))0x0042CFB0;
int __fastcall Hooks::CItem::ItemUse(int *ItemPointer, void *_edx, int* PlayerPointer)
{};
 
ye why not, it's kinda easy addon.. ;)



i did hook at UseItem function.
You should use a vector or a map for the arguments of the spawnitem.ini :P. It's better for the performance, that you load it once and then dont open a filestream all the time... also you're opening the file every time an item is used.. you forgot to close it also, you forgot to delet Monster and player at the end...(could cause memory leak)
 
I'm having issues with making my hooks properly, It would not hurt if I could see the entire hook :P
 
BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
{
IExports *Exports = new IExports();
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
Exports->Initialize();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)Server::CIOServer::Start, ServerStart);
DetourAttach(&(PVOID&)Server::CItem::UseItem, Item::SpawnMonster);
DetourTransactionCommit();
break;
}
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)Server::CIOServer::Start, ServerStart);
DetourDetach(&(PVOID&)Server::CItem::UseItem, Item::SpawnMonster);
DetourTransactionCommit();
break;
}
}
delete Exports;
return TRUE;
}
.......
 
That's not what I was expecting to see :P


i dont get what you want to see, he posted the full hook already...
here is also an example iten use hook with teleport scrool

Code:
signed int __fastcall Hooked_UseItem(void *ItemPointer, void *_edx,  int PlayerPointer)
 {
		KPlayer Player((int*)PlayerPointer);
		KServer Server;
		int result = Server::CItem::UseItem(ItemPointer, PlayerPointer);

		int ItemIndex = *(DWORD *)(*(DWORD *)((int)ItemPointer + 40) + 64);
		int PlayerGstate = Player.GetGstate();
		int PlayerLevel = Player.GetLevel();
		int PlayerGID = Player.GetGID();
		int PlayerX = Player.GetX();
		int PlayerY = Player.GetY();
		int PlayerMap = Player.GetMap();

		for ( TeleitemIt = TeleportItem.begin(); TeleitemIt != TeleportItem.end(); TeleitemIt++ )
		{
			if(ItemIndex == TeleitemIt->MainIndex)
			{
				if(!Player.isGstate(ASSASSIN))
				{
					if(TeleitemIt->RequiredItemIndex == 0 && PlayerLevel >= TeleitemIt->RequiredLevel)
					{
						Player.Teleport(TeleitemIt->Map, TeleitemIt->X, TeleitemIt->Y);
						Player.DeleteItem(TeleitemIt->MainIndex, 1);
					}
					else if(TeleitemIt->RequiredItemIndex > 0 && PlayerLevel >= TeleitemIt->RequiredLevel)
					{
							if(Player.FindItem(TeleitemIt->RequiredItemIndex, TeleitemIt->RequiredItemAmount))
							{
								Player.Teleport(TeleitemIt->Map, TeleitemIt->X, TeleitemIt->Y);
								Player.DeleteItem(TeleitemIt->MainIndex, 1);
									if(TeleitemIt->DeleteReqiredItem == "true")
									Player.DeleteItem(TeleitemIt->RequiredItemIndex, TeleitemIt->RequiredItemAmount);
							}
							else if(!Player.FindItem(TeleitemIt->RequiredItemIndex, TeleitemIt->RequiredItemAmount))
							{
								Player.Notice(TeleitemIt->FailMessage);
							}
					}
				}
				else if(Player.isGstate(ASSASSIN))
				{
					Player.Notice(TeleitemIt->AssasinMessage);
				}
			}
		}
return result;
}


Code:
BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
{
    switch (ul_reason_for_call)
    {
		case DLL_PROCESS_ATTACH:
			{
				DetourTransactionBegin();
				DetourUpdateThread(GetCurrentThread());
				DetourAttach(&(PVOID&)Server::CItem::UseItem, Hooked_UseItem);
				DetourTransactionCommit();
			break;

			}
		case DLL_PROCESS_DETACH:
			{
				DetourTransactionBegin();
				DetourUpdateThread(GetCurrentThread());
				DetourDetach(&(PVOID&)Server::CItem::UseItem, Hooked_UseItem);
				DetourTransactionCommit();
            break;
			}
	}
    return TRUE;
}
 
i dont get what you want to see, he posted the full hook already...
here is also an example iten use hook with teleport scrool

Code:
signed int __fastcall Hooked_UseItem(void *ItemPointer, void *_edx,  int PlayerPointer)
 {
        KPlayer Player((int*)PlayerPointer);
        KServer Server;
        int result = Server::CItem::UseItem(ItemPointer, PlayerPointer);

        int ItemIndex = *(DWORD *)(*(DWORD *)((int)ItemPointer + 40) + 64);
        int PlayerGstate = Player.GetGstate();
        int PlayerLevel = Player.GetLevel();
        int PlayerGID = Player.GetGID();
        int PlayerX = Player.GetX();
        int PlayerY = Player.GetY();
        int PlayerMap = Player.GetMap();

        for ( TeleitemIt = TeleportItem.begin(); TeleitemIt != TeleportItem.end(); TeleitemIt++ )
        {
            if(ItemIndex == TeleitemIt->MainIndex)
            {
                if(!Player.isGstate(ASSASSIN))
                {
                    if(TeleitemIt->RequiredItemIndex == 0 && PlayerLevel >= TeleitemIt->RequiredLevel)
                    {
                        Player.Teleport(TeleitemIt->Map, TeleitemIt->X, TeleitemIt->Y);
                        Player.DeleteItem(TeleitemIt->MainIndex, 1);
                    }
                    else if(TeleitemIt->RequiredItemIndex > 0 && PlayerLevel >= TeleitemIt->RequiredLevel)
                    {
                            if(Player.FindItem(TeleitemIt->RequiredItemIndex, TeleitemIt->RequiredItemAmount))
                            {
                                Player.Teleport(TeleitemIt->Map, TeleitemIt->X, TeleitemIt->Y);
                                Player.DeleteItem(TeleitemIt->MainIndex, 1);
                                    if(TeleitemIt->DeleteReqiredItem == "true")
                                    Player.DeleteItem(TeleitemIt->RequiredItemIndex, TeleitemIt->RequiredItemAmount);
                            }
                            else if(!Player.FindItem(TeleitemIt->RequiredItemIndex, TeleitemIt->RequiredItemAmount))
                            {
                                Player.Notice(TeleitemIt->FailMessage);
                            }
                    }
                }
                else if(Player.isGstate(ASSASSIN))
                {
                    Player.Notice(TeleitemIt->AssasinMessage);
                }
            }
        }
return result;
}


Code:
BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
{
    switch (ul_reason_for_call)
    {
        case DLL_PROCESS_ATTACH:
            {
                DetourTransactionBegin();
                DetourUpdateThread(GetCurrentThread());
                DetourAttach(&(PVOID&)Server::CItem::UseItem, Hooked_UseItem);
                DetourTransactionCommit();
            break;

            }
        case DLL_PROCESS_DETACH:
            {
                DetourTransactionBegin();
                DetourUpdateThread(GetCurrentThread());
                DetourDetach(&(PVOID&)Server::CItem::UseItem, Hooked_UseItem);
                DetourTransactionCommit();
            break;
            }
    }
    return TRUE;
}

think what he asked and you will understand :) your not posting the full code either.. ^^
 
Back