Jump to content
Sign in to follow this  
zxz0O0

[Code] Fix custom asset loading for client

Recommended Posts

I noticed that custom menu and weapon files are not loaded when you join a modded server, for example with the promod_v3.3. So I said to myself why not fix this and came quickly up with this solution.

 

Index: PatchMW2DownloadCL.cpp
===================================================================
--- PatchMW2DownloadCL.cpp	(revision 122)
+++ PatchMW2DownloadCL.cpp	(working copy)
@@ -486,6 +486,8 @@

			dls.isDownloading = false;
			CL_DownloadsComplete(0);
+			//afaik iw3 also reconnects after download, cl_modVidRestart dvar should probably be changed but I'll let NTA do this 
+			Cmd_ExecuteSingleCommand(0, 0, "reconnect");
		}
	}
}
@@ -564,6 +566,59 @@
	}
}

+void GetFS_Game()
+{
+	char* msg = (char *)0x1CB7EB9;//it actually starts at 0x1CB7EB8
+
+	while(true)
+	{
+		if(msg[0]==0)
+			return; //this should never happen
+		if(memcmp("fs_game", msg, sizeof("fs_game") - 1) == 0)
+			break;
+		msg++;
+	}
+
+	msg += 8; //old value + sizeof("fs_game\\")
+	int length = 0;
+	do
+	{
+		length++;
+	}
+	while(msg[length]!='\\');
+
+	if(length==0)
+		Dvar_SetCommand("fs_game", "");
+	else
+	{
+		char* buffer = (char*)malloc(length + 1);
+		buffer[length] = 0; //terminate string
+		memcpy(buffer, msg, length);
+		Dvar_SetCommand("fs_game", buffer);
+		free(buffer);
+	}
+}
+
+void __declspec(naked) clParseGamestateHookStub()
+{
+	__asm
+	{
+		mov ebx,[esp]
+		mov [esp+4],ebx
+		//code we've overwritten
+		add esp,4
+		mov ebx,eax
+
+		test edi,edi //some kind of ID
+		jne back
+		pushad
+		call GetFS_Game
+		popad
+back:
+		ret
+	}
+}
+
// hook definitions
CallHook clInitDownloadsHook; // from CL_ParseGamestate, currently calls CL_DownloadsComplete
DWORD clInitDownloadsHookLoc = 0x5AC6E9;
@@ -574,6 +629,9 @@
CallHook connStatusDisplayHook;
DWORD connStatusDisplayHookLoc = 0x49FA39;

+DWORD clParseGamestateHookLoc = 0x5AC4B0;
+
+
#include "ExtDLL.h"
extern IExtDLL* g_extDLL;

@@ -625,6 +683,11 @@
	connStatusDisplayHook.initialize(connStatusDisplayHookLoc, DisplayConnectionStatusHookStub);
	connStatusDisplayHook.installHook();

+	if(!GAME_FLAG(GAME_FLAG_DEDICATED))
+	{
+		call(clParseGamestateHookLoc, clParseGamestateHookStub, eCallPatcher::PATCH_CALL);
+	}
+
	// switch table in CL_ParseServerMessage
	*(DWORD*)0x4A9FD8 = (DWORD)CL_ParseServerMessageHookStub - (0x4A9FD6 + 6);

Requires the reconnect patch I posted here: viewtopic.php?f=17&t=26688#p225039

 

Greetings to banz, this is for you. I want to thank you for all your contributions.

Share this post


Link to post
Share on other sites
Guest

Ah, the bug that has plauged mods that load custom assets. Nice work on fixing it, should really be implemented into the client.

Share this post


Link to post
Share on other sites
they aren't loaded because fs_game is set after fs_startup process, fix this and you won't even need to reconnect.

Seems you didn't read the code. That's exactly what I do, it's just reconnecting when you need to download the mod (not even sure if this is needed but IW3 also does it).

Share this post


Link to post
Share on other sites
Seems you didn't read the code. That's exactly what I do, it's just reconnecting when you need to download the mod (not even sure if this is needed but IW3 also does it).

 

ups, yeah, I guess you are right, the code it really messy, but thanks for showing us proof of concept

Share this post


Link to post
Share on other sites
Seems you didn't read the code. That's exactly what I do, it's just reconnecting when you need to download the mod (not even sure if this is needed but IW3 also does it).

 

ups, yeah, I guess you are right, the code it really messy, but thanks for showing us proof of concept

I'd appreciate any try to make it better.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

Основная

Основная

Please enter your display name

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.