core/gamedll_bridge.cpp
author Scott Ehlert <ds@alliedmods.net>
Thu Dec 10 00:59:50 2009 -0600 (2009-12-10)
changeset 689 4065ba5e9155
parent 683 b507295429f9
permissions -rw-r--r--
Rewrote user message caching code to always use IServerGameDLL::GetUserMessageInfo (bug 4117, r=dvander).

Games where the above function can crash are handled by detouring tier0's Error() function and jumping back to our own code. So in theory this should work on all games now.
dvander@608
     1
/**
ds@683
     2
 * vim: set ts=4 sw=4 tw=99 noet :
dvander@608
     3
 * ======================================================
dvander@608
     4
 * Metamod:Source
ds@683
     5
 * Copyright (C) 2004-2009 AlliedModders LLC and authors.
dvander@608
     6
 * All rights reserved.
dvander@608
     7
 * ======================================================
dvander@608
     8
 *
dvander@608
     9
 * This software is provided 'as-is', without any express or implied warranty.
dvander@608
    10
 * In no event will the authors be held liable for any damages arising from 
dvander@608
    11
 * the use of this software.
dvander@608
    12
 * 
dvander@608
    13
 * Permission is granted to anyone to use this software for any purpose, 
dvander@608
    14
 * including commercial applications, and to alter it and redistribute it 
dvander@608
    15
 * freely, subject to the following restrictions:
dvander@608
    16
 *
dvander@608
    17
 * 1. The origin of this software must not be misrepresented; you must not 
dvander@608
    18
 * claim that you wrote the original software. If you use this software in a 
dvander@608
    19
 * product, an acknowledgment in the product documentation would be 
dvander@608
    20
 * appreciated but is not required.
dvander@608
    21
 * 2. Altered source versions must be plainly marked as such, and must not be
dvander@608
    22
 * misrepresented as being the original software.
dvander@608
    23
 * 3. This notice may not be removed or altered from any source distribution.
dvander@608
    24
 */
dvander@608
    25
dvander@589
    26
#include <assert.h>
dvander@589
    27
#include "metamod.h"
dvander@589
    28
#include "metamod_plugins.h"
dvander@589
    29
#include "metamod_util.h"
dvander@589
    30
#include <loader_bridge.h>
dvander@589
    31
#include "provider/provider_ep2.h"
dvander@589
    32
dvander@589
    33
using namespace SourceMM;
dvander@589
    34
dvander@589
    35
class GameDllBridge : public IGameDllBridge
dvander@589
    36
{
dvander@589
    37
public:
dvander@589
    38
	virtual bool DLLInit_Pre(const gamedll_bridge_info *info, char *buffer, size_t maxlength)
dvander@589
    39
	{
dvander@589
    40
		if (!mm_DetectGameInformation())
dvander@589
    41
		{
dvander@589
    42
			UTIL_Format(buffer, maxlength, "Metamod:Source failed to detect game paths; cannot load.");
dvander@589
    43
			return false;
dvander@589
    44
		}
dvander@589
    45
dvander@589
    46
		server = (IServerGameDLL *)info->isgd;
dvander@589
    47
		g_Metamod.SetGameDLLInfo((CreateInterfaceFn)info->gsFactory,
dvander@589
    48
								 info->dllVersion,
dvander@589
    49
								 true);
ds@683
    50
		g_Metamod.SetVSPListener(info->vsp_listener_path);
dvander@589
    51
		mm_InitializeGlobals((CreateInterfaceFn)info->engineFactory,
dvander@589
    52
							 (CreateInterfaceFn)info->physicsFactory,
dvander@589
    53
							 (CreateInterfaceFn)info->fsFactory,
dvander@589
    54
							 (CGlobalVars*)info->pGlobals);
dvander@589
    55
		mm_InitializeForLoad();
dvander@589
    56
		mm_StartupMetamod(false);
dvander@589
    57
dvander@589
    58
		return true;
dvander@589
    59
	}
dvander@589
    60
	virtual void DLLInit_Post(int *isgdUnload)
dvander@589
    61
	{
dvander@589
    62
		SourceHook::MemFuncInfo mfi;
dvander@589
    63
dvander@589
    64
		mfi.isVirtual = false;
dvander@589
    65
		SourceHook::GetFuncInfo(&IServerGameDLL::DLLShutdown, mfi);
dvander@589
    66
		assert(mfi.isVirtual);
dvander@589
    67
		assert(mfi.vtbloffs == 0);
dvander@589
    68
		assert(mfi.thisptroffs == 0);
dvander@589
    69
		*isgdUnload = mfi.vtblindex;
dvander@589
    70
dvander@589
    71
		g_PluginMngr.SetAllLoaded();
dvander@589
    72
	}
dvander@589
    73
	virtual void *QueryInterface(const char *iface, int *ret)
dvander@589
    74
	{
dvander@589
    75
		return g_Metamod.GetServerFactory(true)(iface, ret);
dvander@589
    76
	}
dvander@589
    77
	virtual void Unload()
dvander@589
    78
	{
dvander@589
    79
		mm_UnloadMetamod();
dvander@589
    80
	}
dvander@589
    81
};
dvander@589
    82
dvander@589
    83
GameDllBridge mm16_gamedll_bridge;
dvander@589
    84
dvander@589
    85
SMM_API IGameDllBridge *
dvander@589
    86
GetGameDllBridge()
dvander@589
    87
{
dvander@589
    88
	return &mm16_gamedll_bridge;
dvander@589
    89
}
dvander@589
    90