I think I found a way fix Red Portal pass through Act

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
NpZ1k
Posts: 2
Joined: Fri Jun 21, 2019 2:57 pm
China

I think I found a way fix Red Portal pass through Act

Post by NpZ1k » Mon Feb 15, 2021 2:36 pm

First,We need to patch Red Portal code when we click it

Code: Select all


	{D2DLL_D2GAME, 0x6D42E, (DWORD)CrossActPortal_Stub, TRUE, 0x00 },

FUNCPTR(D2GAME, CrossAct, void, __fastcall, (Game* pGame, UnitAny* pPlayer, int nDestMap), 0x9E170)
const DWORD PortalAfter = (DLLBASE_D2GAME + 0xE19C0);

void __stdcall CrossActPortal(UnitAny* pUnit, DRLGRoom* pRoom)
{
	if(!pUnit || !pRoom)
		return;
	
	int nDestLevel = pRoom->pRoomEx->pLevel->dwLevelNo;
	Game* pGame = pUnit->pGame;
	DRLGRoom* pUnitRoom = D2COMMON_GetRoomFromUnit(pUnit);
	int nLevel = D2COMMON_GetLevelNoFromRoom(pUnitRoom);

	if(D2COMMON_GetActFromLevel(nLevel) != D2COMMON_GetActFromLevel(nDestLevel))
	{
		D2GAME_CrossAct_Stub(pGame, pUnit, nDestLevel);
	}
	return;
}

__declspec (naked) void __stdcall CrossActPortal_Stub()
{
	__asm
	{
		pushad
		push [esp + 0x14]
		push [esp + 0x2C]
		call CrossActPortal
		popad
		jmp PortalAfter
	}
}

__declspec (naked) void __stdcall D2GAME_CrossAct_Stub(Game* pGame, UnitAny* pPlayer, int DestLevel)
{
	__asm
	{
		push 0					
		push [esp + 0x8]			
		mov eax, [esp + 0x10]	
		mov edi, [esp + 0x14]		
		call D2GAME_CrossAct
		retn 0xC
	}
}
Finally,I load all Act when game is loading

Code: Select all


	{D2DLL_D2GAME, 0x9D745, (DWORD)PATCH_CALL, FALSE, 0x01 },
	{D2DLL_D2GAME, 0x9D745, (DWORD)LoadAllpAct_Asm, TRUE, 0x00 },
	
Act* __stdcall LoadAllAct(BYTE ActNumber, Game* pGame)
{
	Act* pAct[5] = {};
	for(int i = 0; !(pGame->mapAct[i]); i++)
	{
		int nTown = D2COMMON_GetTownLevel(i);
		pGame->mapAct[i] = D2COMMON_LoadAct(i, pGame->InitSeed, 0, pGame, pGame->difficultyLevel, pGame->memoryPool, nTown, NULL, NULL);
		pAct[i] = pGame->mapAct[i];
	}
	return pAct[ActNumber];
}

__declspec (naked) void __stdcall LoadAllpAct_Asm()
{
	__asm
	{
		push [esp + 0x10]
		push [esp + 0x08]
		call LoadAllAct
		retn 0x24
	}
}

Post Reply

Return to “Code Editing”