This repository was archived by the owner on Mar 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCDLLMod.cpp
More file actions
88 lines (70 loc) · 2.46 KB
/
Copy pathCDLLMod.cpp
File metadata and controls
88 lines (70 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
QMM - Q3 MultiMod
Copyright 2004-2024
https://github.com/thecybermind/qmm/
3-clause BSD license: https://opensource.org/license/bsd-3-clause
Created By:
Kevin Masterson < cybermind@gmail.com >
*/
#include <string.h>
#include "osdef.h"
#include "qmm.h"
#include "CModMgr.h"
#include "CEngineMgr.h"
#include "game_api.h"
#include "qmmapi.h"
#include "CDLL.h"
#include "CDLLMod.h"
#include "util.h"
CDLLMod::CDLLMod() {
memset(this->file, 0, sizeof(this->file));
}
CDLLMod::~CDLLMod() {
this->dll.Unload();
}
// - file is either the full path or relative to the install directory
//homepath shit is all handled in CModMgr::LoadMod()
int CDLLMod::LoadMod(const char* file) {
if (!file || !*file)
return 0;
strncpy(this->file, file, sizeof(this->file));
//load dll
int x = this->dll.Load(this->file);
//file not found
if (!x) {
ENG_SYSCALL(ENG_MSG(QMM_G_PRINT), vaf("[QMM] ERROR: CDLLMod::LoadMod(\"%s\"): Unable to load mod file: %s\n", file, dlerror()));
return 0;
} else if (x == -1) {
ENG_SYSCALL(ENG_MSG(QMM_G_PRINT), vaf("[QMM] ERROR: CDLLMod::LoadMod(\"%s\"): Unable to load mod file: module already loaded\n", file));
return 0;
}
//locate dllEntry() function or fail
if ((this->pfndllEntry = (mod_dllEntry_t)this->dll.GetProc("dllEntry")) == NULL) {
ENG_SYSCALL(ENG_MSG(QMM_G_PRINT), vaf("[QMM] ERROR: CDLLMod::LoadMod(\"%s\"): Unable to locate dllEntry() mod entry point\n", file));
return 0;
}
//locate vmMain() function or fail
if ((this->pfnvmMain = (mod_vmMain_t)this->dll.GetProc("vmMain")) == NULL) {
ENG_SYSCALL(ENG_MSG(QMM_G_PRINT), vaf("[QMM] ERROR: CDLLMod::LoadMod(\"%s\"): Unable to locate vmMain() mod entry point\n", file));
return 0;
}
//call mod's dllEntry
this->pfndllEntry(g_ModMgr->QMM_SysCall());
return 1;
}
int CDLLMod::vmMain(int cmd, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11) {
return this->pfnvmMain ? this->pfnvmMain(cmd, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) : 0;
}
int CDLLMod::IsVM() {
return 0;
}
const char* CDLLMod::File() {
return this->file[0] ? this->file : NULL;
}
int CDLLMod::GetBase() {
return 0;
}
void CDLLMod::Status() {
ENG_SYSCALL(ENG_MSG(QMM_G_PRINT), vaf("[QMM] dllEntry() offset: %p\n", this->pfndllEntry));
ENG_SYSCALL(ENG_MSG(QMM_G_PRINT), vaf("[QMM] vmMain() offset: %p\n", this->pfnvmMain));
}