Fixed up the ModLoader Project; replaced the old sources with the new

This commit is contained in:
Robert MacGregor 2014-08-05 18:31:30 -04:00
parent 83b8016a30
commit a3a954b22f
12 changed files with 62 additions and 163 deletions

View file

@ -0,0 +1,39 @@
/*
* modLoader.cpp
*/
#include "stdafx.h"
#include <t2api.h>
// Mod Loader Implementation
bool conLoadMod(SimObject *obj,S32 argc, const char* argv[])
{
typedef void (*LPMODINIT)(void);
HINSTANCE hDLL = NULL;
LPMODINIT lpInitMod = NULL;
std::string raw = "mods\\";
raw += argv[1];
raw += ".dll";
std::wstring modification(raw.begin(), raw.end());
hDLL = LoadLibrary(modification.c_str());
if (hDLL == NULL)
{
Con::errorf(0, "loadMod(): Failed to load DLL '%s'. Does it exist in GameData\mods? (%u)", raw.c_str(), GetLastError());
return false; // The DLL doesn't exist
}
lpInitMod = (LPMODINIT)GetProcAddress(hDLL, "ModInitialize"); // Attempt to load our entry point
if (lpInitMod == NULL)
{
Con::errorf(0, "loadMod(): Failed to locate entry point 'ModInitialize' in mod DLL '%s'. Is it a good mod DLL? (%u)", raw.c_str(), GetLastError());
return false; // Unable to load entry point
}
lpInitMod();
Con::errorf(0, "loadMod(): Loaded and executed entry point code for mod DLL '%s'", raw.c_str());
return true;
}

View file

@ -1,84 +0,0 @@
/*
* t2ConCmds.cpp
* Original code by Linker
* Modified by Robert MacGregor
*/
#include <string>
#include "stdafx.h"
#include "t2ConCmds.h"
// Linker's implementations
const char* conGuiTsCtrlProject(SimObject *obj,S32 argc, const char* argv[]) {
Point3F pt;
Point3F rt;
dSscanf(argv[2],"%g %g %g",&pt.x,&pt.y,&pt.z);
GuiTSCtrl_project(reinterpret_cast<GuiTSCtrl *>(obj),pt,&rt);
char* buffer = Con::getReturnBuffer(255);
dSprintf(buffer,255,"%g %g %g",rt.x,rt.y,rt.z);
return buffer;
}
bool conNetObjectSetGhostable(SimObject *obj,S32 argc, const char* argv[]) {
if (dAtob(argv[2])) {
__asm {
push ecx
mov ecx, [obj]
mov eax,[ecx+40h]
or eax, 100h
mov [ecx+40h], eax
pop ecx
}
} else {
__asm {
xor eax, eax
or eax, 100h
not eax
push ecx
mov ecx,[obj]
and eax, [ecx+40h]
mov [ecx+40h],eax
push 40h
mov eax, 0x585BE0
call eax
pop ecx
}
}
return 1;
}
const char* conGetVariable(SimObject *obj,S32 argc, const char* argv[]) {
return Con::getVariable(argv[1]);
}
// Mod Loader Implementation
bool conLoadMod(SimObject *obj,S32 argc, const char* argv[])
{
typedef void (*LPMODINIT)(void);
HINSTANCE hDLL = NULL;
LPMODINIT lpInitMod = NULL;
std::string raw = argv[1];
std::wstring input(raw.begin(), raw.end());
std::wstring modification = L"mods/";
modification += input;
modification += L".dll";
hDLL = LoadLibrary(modification.c_str()); // AfxLoadLibrary is probably better.
if (hDLL == NULL)
return false; // The DLL doesn't exist
else
lpInitMod = (LPMODINIT)GetProcAddress(hDLL, "?ModInitialize@@YAXXZ"); // Attempt to load our entry point
if (lpInitMod == NULL)
return false; // Unable to load entry point
else
lpInitMod(); // The function was loaded, call TribesNext and move on to postTN Startup
return true;
}

View file

@ -1,4 +1,4 @@
#include "stdafx.h"
#include <t2api.h>
SimIdDictionary* gIdDictionary = reinterpret_cast<SimIdDictionary*>(0x009E9194);

View file

@ -4,11 +4,12 @@
* Modified by Robert MacGregor
*/
#include "stdafx.h"
#include "t2ConCmds.h"
#include "t2api.h"
#include <winsdkver.h>
#include <Windows.h>
#include <t2api.h>
#include <modLoader.h>
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
@ -19,11 +20,6 @@ BOOL APIENTRY DllMain( HMODULE hModule,
__declspec(dllexport) void initT2Dll(void)
{
// Run Linker's old implementations ...
Con::addMethodS("GuiTSCtrl","project",&conGuiTsCtrlProject,"projects a world space vector to on-screen position",3,3);
Con::addMethodB("NetObject","SetGhostable",&conNetObjectSetGhostable,"set or unset object to be ghostable",3,3);
Con::addMethodS(NULL,"getVariable",&conGetVariable,"Get a variable without restrictions",2,2);
Con::addVariable("$cpuspeed",TypeS32,reinterpret_cast<void*>(0x8477F8)); //1 - S32, this is so i can set my cpu speed to 31337 or osmething =P
Con::addVariable("$GameBase::showBoundingBox",TypeBool,reinterpret_cast<void*>(0x9ECF24));