Need a function for event timer

This forum is for discussions on how to edit what can not be edited through the txt files, needless to say this isn't about battle net hacking.

Moderators: Nefarius, Havvoric

Post Reply
User avatar
devurandom
Forum Regular
Angel
Posts: 897
Joined: Sat Mar 07, 2015 9:07 pm
United States of America

Need a function for event timer

Post by devurandom » Tue Sep 29, 2015 6:00 am

Hello,

Need a basic function I can hook for a once every XX seconds event check. Timing accuracy is not important, so I'd rather avoid hooking a top level function like StatRegen, since there's no need.

Can someone suggest another function to look for in D2game.dll ?

Thanks in Advance
Assembly Reference | 1.13d Code Edits | UVLoD | BaseMod Plugin

Fiat paper money is the most elaborate and well devised form of slavery the world has ever seen..

Cossack
Posts: 26
Joined: Sat Oct 08, 2011 2:14 pm

Re: Need a function for event timer

Post by Cossack » Tue Sep 29, 2015 8:06 am

Code: Select all

D2FUNC(D2GAME, Timer, void, __fastcall, (game *pGame, UnitAny *pUnit, int Type, DWORD Frame, (void __fastcall * CALLBACK_E)(game* pGame, UnitAny* pUnit, int Type, DWORD arg1, DWORD arg2), DWORD arg1, DWORD arg2), 0x8EA80)
for 1.13c

I hope that's what you mean

User avatar
Necrolis
Senior Admin
Throne
Posts: 9125
Joined: Sat Mar 25, 2006 1:22 pm
Location: The Land of the Dead
Contact:
South Africa

Hand-picked

Re: Need a function for event timer

Post by Necrolis » Tue Sep 29, 2015 1:28 pm

There are a few options for timers; there are the quest ones which are a little more versatile (as they are recurring, just return false):

Code: Select all

/* 
	Date: Thu May 20 09:42:07 2010
	Author: Necrolis
	Function: QUESTS_CreateTimer
	Address: D2Game.0x6FC94690
	Comments: 
*/
typedef bool (__fastcall * questupdate_t)	(D2GameStrc* pGame, D2QuestDataStrc* pQuest);
void __fastcall QUESTS_CreateTimer(D2QuestDataStrc* pQuest, questupdate_t pfCallback, int nTicks)
Then there is the event system that is used to create all delayed events (recurring events like stat regen just reset the callback in the callback). If you set a callback fn, the Event number can be anything:

Code: Select all

/* 
	Date: Wed Jun 17 18:00:47 2009
	Author: Necrolis
	Function: EVENTS_SetEvent
	Address: D2Game.0x6FC351D0 & D2Game.0x6FC35570 & D2Game.0x6FC353D0
	Comments:
*/
typedef void (__fastcall * EVENTCALLBACK)	(D2GameStrc* pGame, D2UnitStrc* pUnit, int nEvent, DWORD dwArg, DWORD dwArgEx);
void __fastcall EVENTS_SetEvent(D2GameStrc* pGame, D2UnitStrc* pUnit, int nEvent, int dwFrame, EVENTCALLBACK pfExtra, DWORD dwArg, DWORD dwArgEx)
Note: all addresses & protos are for 1.10
Image
Netiquette, Do you USE it?!?! | Nefarius' Fixed TXT Files | Terms Of Service
Blackened | Day of Death | D2GFEx
"What was yours is mine. Your land, your people, and now your life." - Lim-Dul, the Necromancer
Judgement is Final, Death is Eternal

User avatar
devurandom
Forum Regular
Angel
Posts: 897
Joined: Sat Mar 07, 2015 9:07 pm
United States of America

Re: Need a function for event timer

Post by devurandom » Tue Sep 29, 2015 5:58 pm

Thanks for the quick reply's

Sorry, for not explaining well. I'm not up to speed yet on higher level language, but starting to map function address calls, and seeing the limitations of asm.

The addresses Necrolis posted are enough though to investigate and patch in some assembly to check if bean counter stored in memory address can trigger event.

Thanks!
Assembly Reference | 1.13d Code Edits | UVLoD | BaseMod Plugin

Fiat paper money is the most elaborate and well devised form of slavery the world has ever seen..

lolet
Posts: 95
Joined: Sat Sep 04, 2010 8:43 pm

Re: Need a function for event timer

Post by lolet » Tue Sep 29, 2015 6:31 pm

If you want very simple solution for that, hook D2GAME.6FCDFF40 (1.13d) (you can find offset on other patch quickly if you search for const 0x70000000)

Code: Select all

void SERVER_ParseEvents(Game *pGame<eax>)
Then add own checks

Code: Select all

  if (!(ptGame->GameFrame % 20))  // code will run each 20 frames, 25 frames = 1 sec
    QUESTS_Update(ptGame);

User avatar
Necrolis
Senior Admin
Throne
Posts: 9125
Joined: Sat Mar 25, 2006 1:22 pm
Location: The Land of the Dead
Contact:
South Africa

Hand-picked

Re: Need a function for event timer

Post by Necrolis » Tue Sep 29, 2015 6:48 pm

lolet" wrote:If you want very simple solution for that, hook D2GAME.6FCDFF40 (1.13d) (you can find offset on other patch quickly if you search for const 0x70000000)

Code: Select all

void SERVER_ParseEvents(Game *pGame<eax>)
Then add own checks

Code: Select all

  if (!(ptGame->GameFrame % 20))  // code will run each 20 frames, 25 frames = 1 sec
    QUESTS_Update(ptGame);
In 1.10 that same bit of code is here (pretty sure I've posted this before):

Code: Select all

6FC38877                                             .  8B87 A8000000                         MOV EAX,DWORD PTR DS:[EDI+A8]
6FC3887D                                             .  B9 14000000                           MOV ECX,14
6FC38882                                             .  99                                    CDQ
6FC38883                                             .  F7F9                                  IDIV ECX
6FC38885                                             .  85D2                                  TEST EDX,EDX
6FC38887                                             .  75 07                                 JNZ SHORT D2Game.6FC38890
6FC38889                                             .  8BCF                                  MOV ECX,EDI
6FC3888B                                             .  E8 F0BC0500                           CALL D2Game.6FC94580
Fun fact: that mod by 20 is a bug, its a relic of when D2 used to run at 20 fps (a relic of D1), the shrine code has a similar bug; it should actually be mod 25.
Image
Netiquette, Do you USE it?!?! | Nefarius' Fixed TXT Files | Terms Of Service
Blackened | Day of Death | D2GFEx
"What was yours is mine. Your land, your people, and now your life." - Lim-Dul, the Necromancer
Judgement is Final, Death is Eternal

User avatar
devurandom
Forum Regular
Angel
Posts: 897
Joined: Sat Mar 07, 2015 9:07 pm
United States of America

Re: Need a function for event timer

Post by devurandom » Wed Sep 30, 2015 1:08 am

lolet" wrote:If you want very simple solution for that, hook D2GAME.6FCDFF40 (1.13d) (you can find offset on other patch quickly if you search for const 0x70000000)
Necrolis" wrote: Fun fact: that mod by 20 is a bug, its a relic of when D2 used to run at 20 fps (a relic of D1), the shrine code has a similar bug; it should actually be mod 25.
Only one instance in this const in D2Game (1.13d). So correct value 8000000 to give mod 25?
All very useful information. I didn't find much searching before except for StatRegen.
How do you guys make these functions... from the code, some type of Hex-Rays analysis?
Assembly Reference | 1.13d Code Edits | UVLoD | BaseMod Plugin

Fiat paper money is the most elaborate and well devised form of slavery the world has ever seen..

User avatar
Necrolis
Senior Admin
Throne
Posts: 9125
Joined: Sat Mar 25, 2006 1:22 pm
Location: The Land of the Dead
Contact:
South Africa

Hand-picked

Re: Need a function for event timer

Post by Necrolis » Wed Sep 30, 2015 3:36 pm

devurandom" wrote:How do you guys make these functions... from the code, some type of Hex-Rays analysis?
I don everything with ollydbg, its a lot faster these days though because of the massive base I have already built up.
Image
Netiquette, Do you USE it?!?! | Nefarius' Fixed TXT Files | Terms Of Service
Blackened | Day of Death | D2GFEx
"What was yours is mine. Your land, your people, and now your life." - Lim-Dul, the Necromancer
Judgement is Final, Death is Eternal

User avatar
devurandom
Forum Regular
Angel
Posts: 897
Joined: Sat Mar 07, 2015 9:07 pm
United States of America

Re: Need a function for event timer

Post by devurandom » Wed Sep 30, 2015 11:12 pm

I think I still have a lot to learn.
Assembly Reference | 1.13d Code Edits | UVLoD | BaseMod Plugin

Fiat paper money is the most elaborate and well devised form of slavery the world has ever seen..

User avatar
kidpaddle94
Forum Legend
Principality
Posts: 2057
Joined: Thu Aug 13, 2009 2:54 pm
Location: localhost
Canada

Re: Need a function for event timer

Post by kidpaddle94 » Thu Oct 01, 2015 5:37 am

I also myself always reverse from Ollydbg. Although I also use hex-rays sometimes to get a general idea.

User avatar
kingpin
Retired Admin
Cherub
Posts: 10954
Joined: Sat Jan 11, 2003 12:51 pm
Contact:
Sweden

Hand-picked

Re: Need a function for event timer

Post by kingpin » Thu Oct 01, 2015 5:53 am

In general you learn alot by rewrite all code in a function, some of us have been here since early days (I started 2003 and coded right away). So, it's 12 years of experience with d2's code, and those of us who rewrite the code in c++ quickly build up a list of functions.

For debugging I use ollydbg, and w32dsm.

User avatar
devurandom
Forum Regular
Angel
Posts: 897
Joined: Sat Mar 07, 2015 9:07 pm
United States of America

Re: Need a function for event timer

Post by devurandom » Thu Oct 01, 2015 8:56 am

Thanks for the info. Never thought I'd see the need to learn C++ coming from Unix, but I can see the need at this point. -Necessity is the mother of all invention. ;)

@Whist.. Looking at D2Template, looks very enticing for my next dist.
Assembly Reference | 1.13d Code Edits | UVLoD | BaseMod Plugin

Fiat paper money is the most elaborate and well devised form of slavery the world has ever seen..

User avatar
a000000
Posts: 36
Joined: Mon Apr 10, 2017 6:36 am

Re: Need a function for event timer

Post by a000000 » Tue Feb 25, 2020 9:13 am

Cossack wrote:
Tue Sep 29, 2015 8:06 am
Ollydbg
How does 1.13c do this with for OllyDbg?

User avatar
a000000
Posts: 36
Joined: Mon Apr 10, 2017 6:36 am

Re: Need a function for event timer

Post by a000000 » Tue Feb 25, 2020 9:30 am

Cossack wrote:
Tue Sep 29, 2015 8:06 am

Code: Select all

D2FUNC(D2GAME, Timer, void, __fastcall, (game *pGame, UnitAny *pUnit, int Type, DWORD Frame, (void __fastcall * CALLBACK_E)(game* pGame, UnitAny* pUnit, int Type, DWORD arg1, DWORD arg2), DWORD arg1, DWORD arg2), 0x8EA80)
for 1.13c

I hope that's what you mean
How does 1.13c do this with OllyDbg?

User avatar
karlock
Posts: 42
Joined: Mon Mar 16, 2015 1:16 pm

Re: Need a function for event timer

Post by karlock » Fri Mar 13, 2020 2:51 am

devurandom wrote:
Wed Sep 30, 2015 11:12 pm
I think I still have a lot to learn.
x64dbg are more powerfull than ollydbg. Check it out! https://github.com/x64dbg/x64dbg :D

User avatar
a000000
Posts: 36
Joined: Mon Apr 10, 2017 6:36 am

Re: Need a function for event timer

Post by a000000 » Fri Mar 13, 2020 7:20 am

卡洛克 wrote:
Fri Mar 13, 2020 2:51 am
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">[quote = devurandom post_id = 484024时间= 1443651178 user_id = 43175] </font></font>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">我想我还有很多东西要学习。</font></font>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">[/ quote] </font></font>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">x64dbg比ollydbg更强大。</font><font style="vertical-align: inherit;">一探究竟!</font><font style="vertical-align: inherit;">https://github.com/x64dbg/x64dbg:D</font></font>

How to change C + + to OD and write DLL?

Post Reply

Return to “Code Editing”