Advertisement
JKornev

MonsLib.cpp

Aug 20th, 2012
1,133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.37 KB | None | 0 0
  1. /*
  2. Code: Add new monsters to MuOnline client
  3. Credits: DoS.Ninja
  4. Web: ninja-researcher.blogspot.com
  5. */
  6. #include "stdafx.h"
  7. #include "MonsLib.h"
  8. #include "Hook.h"
  9.  
  10. #define ADD_MOBS_COUNT 3
  11. MonsterAdd_Struct s_AddMob[ADD_MOBS_COUNT]={
  12.     {555, MONSTER_DIR, "Monster555"},
  13.     {556, MONSTER_DIR, "Monster13"},
  14.     {557, MONSTER_DIR, "Monster13"},
  15. };
  16. DWORD dwNewMobResInx[ADD_MOBS_COUNT];
  17.  
  18. #define MOBS_PARAMS_COUNT 4
  19. MobParam_Struct s_ParamMob[MOBS_PARAMS_COUNT] = {
  20.     {555, "New mob1", NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, 0},
  21.     {556, "New mob2", 4, 5, 0, 0x057c, 1, 44, 0x0F81, 1, 22, 1},
  22.     {557, "New mob3", 4, 1, 0, NONE, NULL, NULL, -1, NULL, NULL, 1.5},
  23.     {24, "Worm Killer", 1, 7, NONE, NONE, NONE, NONE, NONE, NONE, NONE, 2}
  24. };
  25.  
  26. DWORD dwModelResInx, dwModelMobsID, dwModelResSizeof, dwModelResCount;
  27. int iTempMobID = NONE;
  28.  
  29. BOOL APIENTRY DllMain( HMODULE hModule,
  30.                        DWORD  ul_reason_for_call,
  31.                        LPVOID lpReserved
  32.                      )
  33. {
  34.     switch (ul_reason_for_call)
  35.     {
  36.     case DLL_PROCESS_ATTACH:
  37.         Init_Monsters();
  38.     case DLL_THREAD_ATTACH:
  39.     case DLL_THREAD_DETACH:
  40.     case DLL_PROCESS_DETACH:
  41.         break;
  42.     }
  43.     return TRUE;
  44. }
  45.  
  46. void Init_Monsters() {
  47.     DWORD dwResSize, dwResCount, dwTotalSize;
  48.  
  49.     // Get resource ID
  50.     dwModelResSizeof = *(DWORD*)(OFFST_MODELRES_SIZEOF + 1);
  51.     dwModelResCount = *(DWORD*)(OFFST_MODELRES_COUNT + 1);
  52.     dwModelMobsID = *(DWORD*)(OFFST_MODELRES_MOBS_ID + 2);
  53.  
  54.     // Hook some proc for calc resource id
  55.     HookAddress(HPROC_LOADPLAYERBMD, (DWORD)Hook_LoadPlayerBMD, NULL);
  56.  
  57.     // Hook zero-bull load
  58.     HookAddress(HPROC_OPENMONSTERMODEL_BULL, (DWORD)Hook_OpenMonsterModel, NULL);
  59.     memset((void*)(HARGS_BULL_PUSH), _asm_nop, 2);
  60.     MEMORY1(HARGS_BULL_PUSH) = _asm_push_eax; // Change PUSH 0 to PUSH EAX
  61.  
  62.     // Hook construct zero-bull model
  63.     HookAddress(HPROC_CONSTMONSTERMODEL_BULL, (DWORD)Hook_ConstructMonsterModel, NULL);
  64.  
  65.     // Fix load resurce id in OpenMonsterModel() HPROC_LOADBMDMODEL
  66.     HookAddress(HPROC_LOADBMDMODEL, (DWORD)Hook_FixLoadBMDModel, NULL);
  67.  
  68.     //Hook set mob name style, for change mob params
  69.     HookAddress(HPROC_SETMOBNAMESTYLE, (DWORD)Hook_SetMonsterNameStyle, NULL);
  70.  
  71. }
  72.  
  73. void __cdecl Hook_LoadPlayerBMD(DWORD dwResInx, LPSTR lpDir, LPSTR lpBaseName, DWORD Arg4){
  74. // Hook procedure only for calc model resource indexes after heapalloc memory block
  75.     DWORD dwEnd, dwDiff, dwSize;
  76.  
  77.     // calc model resource index
  78.     dwSize = dwModelResSizeof * dwModelResCount;
  79.     dwDiff = *lpModelResArray - *lpModelResBase;
  80.     dwModelResInx = (dwSize - dwDiff) / dwModelResSizeof;
  81.  
  82.     // set resource index for new monsters
  83.     for(int i=0;i<ADD_MOBS_COUNT;i++) {
  84.         dwNewMobResInx[i] = dwModelResInx - i - 1;
  85.         s_AddMob[i].dwMobID -= 1;//fix, LoadModel(mob_id) where mob_id = server_mob_id - 1
  86.     }
  87.  
  88.     //back to load player.bmd
  89.     HLoadBMDModel(dwResInx, lpDir, lpBaseName, Arg4);//original
  90. }
  91.  
  92. void __cdecl Hook_OpenMonsterModel(DWORD dwMobNumber) {
  93. // Change zero-bull to new mob (if need)
  94.     if(dwMobNumber != -1)// if not zero-bull
  95.     {
  96.         for(int i=0;i<ADD_MOBS_COUNT;i++) {
  97.             if(dwMobNumber == s_AddMob[i].dwMobID) {
  98.                 dwMobNumber = dwNewMobResInx[i] - dwModelMobsID;
  99.                 iTempMobID = i;
  100.                 break;
  101.             }
  102.         }
  103.     }
  104.     else
  105.         dwMobNumber=0;
  106.  
  107.     HOpenMonsterModel(dwMobNumber);//original
  108. }
  109.  
  110. void __cdecl Hook_FixLoadBMDModel(DWORD dwResInx, LPSTR lpDir, LPSTR lpBaseName, DWORD Arg4){
  111. // Change load bmd model params (if need)
  112.     if(iTempMobID != NONE){
  113.         lpDir = s_AddMob[iTempMobID].lpDir;
  114.         lpBaseName = s_AddMob[iTempMobID].lpFile;
  115.         Arg4 = -1;
  116.     }
  117.  
  118.     HLoadBMDModel(dwResInx, lpDir, lpBaseName, Arg4);//original
  119. }
  120.  
  121. DWORD __cdecl Hook_ConstructMonsterModel(DWORD Arg1, DWORD dwResInx, DWORD dwResOffst, DWORD Arg4, DWORD Arg5){
  122. // Change new resource ID (if need)
  123.     if(iTempMobID != NONE){
  124.         dwResInx = dwNewMobResInx[iTempMobID];
  125.         iTempMobID = NONE;
  126.     }
  127.  
  128.     return HConstructMonsterModel(Arg1, dwResInx, dwResOffst, Arg4, Arg5);//original
  129. }
  130.  
  131. void __cdecl Hook_SetMonsterNameStyle(DWORD dwMemAddr, DWORD dwMobID, DWORD Arg3, DWORD Arg4){
  132. // Hook for change monster parametres
  133.     HSetMonsterNameStyle(dwMemAddr, dwMobID, Arg3, Arg4);//original
  134.     ModifMonsParams(dwMemAddr, dwMobID);
  135. }
  136.  
  137. void ModifMonsParams(DWORD lpUnit, DWORD dwMobID){
  138.  
  139.     for(int i=0;i<MOBS_PARAMS_COUNT;i++)
  140.     {
  141.         if(s_ParamMob[i].dwMobID==dwMobID)
  142.         {
  143.             Unit_Struct *pUnit;
  144.             pUnit = (Unit_Struct*)lpUnit;
  145.  
  146.             if(s_ParamMob[i].lpName!=NULL)
  147.                 sprintf(pUnit->cName, "%s", s_ParamMob[i].lpName);
  148.            
  149.             if(s_ParamMob[i].bMoveOut != NONE)
  150.                 pUnit->bMoveOut = s_ParamMob[i].bMoveOut;
  151.  
  152.             if(s_ParamMob[i].bMobType!=NONE)
  153.                 pUnit->bMobType = s_ParamMob[i].bMobType;
  154.  
  155.             if(s_ParamMob[i].fSize!=NULL)
  156.                 pUnit->fSize = s_ParamMob[i].fSize;
  157.  
  158.             if(s_ParamMob[i].bPKStatus!=NONE)
  159.                 pUnit->bPKStatus = s_ParamMob[i].bPKStatus;
  160.  
  161.             //Hand first
  162.             if(s_ParamMob[i].sItem1ResID!=NONE)
  163.                 pUnit->sItem1ResID = s_ParamMob[i].sItem1ResID;
  164.  
  165.             if(s_ParamMob[i].bItem1IsExcl!=NONE)
  166.                 pUnit->bItem1IsExc = s_ParamMob[i].bItem1IsExcl;
  167.  
  168.             if(s_ParamMob[i].bItem1JoinID!=NONE)
  169.                 pUnit->bItem1JoinID = s_ParamMob[i].bItem1JoinID;
  170.  
  171.             //Hand second
  172.             if(s_ParamMob[i].sItem2ResID!=NONE)
  173.                 pUnit->sItem2ResID = s_ParamMob[i].sItem2ResID;
  174.  
  175.             if(s_ParamMob[i].bItem2IsExcl!=NONE)
  176.                 pUnit->bItem2IsExc = s_ParamMob[i].bItem2IsExcl;
  177.  
  178.             if(s_ParamMob[i].bItem2JoinID!=NONE)
  179.                 pUnit->bItem2JoinID = s_ParamMob[i].bItem2JoinID;
  180.  
  181.         }
  182.     }
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement