Subversion Repositories WoWGM

Rev

Rev 7 | Rev 32 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 tristanc 1
#include "pch.h"
2
#pragma hdrstop
3
 
4
#include "CGlueMgr.h"
5
#include <Engine/Base/CDataStore.h>
6
#include <Console/ConsoleClient.h>
7
#include <FrameScript/FrameScript.h>
8
#include <WowSvcs/ClientServices.h>
7 tristanc 9
#include <DB/WowClientDB.h>
3 tristanc 10
 
7 tristanc 11
 
12
CVar* g_password = NULL;
13
 
14
 
3 tristanc 15
/****************************************************************************
16
*
31 tristanc 17
*   Client memory addresses
3 tristanc 18
*
19
***/
20
 
31 tristanc 21
#define  CGLUEMGR_NETDISCONNECTHANDLER  0x004DA9D0
22
#define  CGLUEMGR__RESUME               0x004DA5F0
23
#define  CGLUEMGR__SUSPEND              0x004D8930
24
#define  CGLUEMGR__SHUTDOWN             0x004DBBC0
3 tristanc 25
 
26
 
27
/****************************************************************************
28
*
31 tristanc 29
*   Client function pointers
3 tristanc 30
*
31
***/
32
 
31 tristanc 33
void (*NetDisconnectHandlerPtr)(void const*,void*) = *(void(*)(void const*,void*))CGLUEMGR_NETDISCONNECTHANDLER;
3 tristanc 34
 
31 tristanc 35
void (*ResumePtr)(int) = *(void (*)(int))CGLUEMGR__RESUME;
3 tristanc 36
 
31 tristanc 37
void (*SuspendPtr)() = *(void (*)())CGLUEMGR__SUSPEND;
38
 
39
void (*ShutdownPtr)() = *(void (*)())CGLUEMGR__SHUTDOWN;
40
 
41
 
3 tristanc 42
/****************************************************************************
43
*
31 tristanc 44
*   Detours setup
3 tristanc 45
*
46
***/
47
 
48
//===========================================================================
49
void WowGM::CGlueMgr::Initialize () {
50
	DETOUR_INIT;
51
 
7 tristanc 52
	DETOUR_ATTACH(NetDisconnectHandlerPtr,::CGlueMgr::NetDisconnectHandler);
3 tristanc 53
	DETOUR_ATTACH(ResumePtr,::CGlueMgr::Resume);
54
	DETOUR_ATTACH(SuspendPtr,::CGlueMgr::Suspend);
55
	DETOUR_ATTACH(ShutdownPtr,::CGlueMgr::Shutdown);
56
 
57
	DETOUR_COMMIT;
58
}
59
 
60
//===========================================================================
61
void WowGM::CGlueMgr::Shutdown () {
62
	DETOUR_INIT;
63
 
7 tristanc 64
	DETOUR_DETACH(NetDisconnectHandlerPtr,::CGlueMgr::NetDisconnectHandler);
3 tristanc 65
	DETOUR_DETACH(ResumePtr,::CGlueMgr::Resume);
66
	DETOUR_DETACH(SuspendPtr,::CGlueMgr::Suspend);
67
	DETOUR_DETACH(ShutdownPtr,::CGlueMgr::Shutdown);
68
 
69
	DETOUR_COMMIT;
70
}
71
 
72
//===========================================================================
73
void WowGM::CGlueMgr::RegisterConsoleCommands() {
74
	::CGlueMgr::RegisterConsoleCommands();
75
}
76
 
77
//===========================================================================
78
void WowGM::CGlueMgr::UnregisterConsoleCommands () {
79
	::CGlueMgr::UnregisterConsoleCommands();
80
}
81
 
82
 
83
/****************************************************************************
84
*
31 tristanc 85
*   Console commands and scripts
3 tristanc 86
*
87
***/
88
 
89
//===========================================================================
31 tristanc 90
int CCommand_Script2 (const char* cmd, char const* arguments) {
3 tristanc 91
	FrameScript_Execute(arguments, arguments, NULL);
92
	return 0;
93
}
94
 
31 tristanc 95
//===========================================================================
96
int CCommand_MoveCharacter (const char* command, const char* arguments) {
3 tristanc 97
  if ((*(int*)0x00B6A9E0)) {  // CGlueMgr::m_currentScreen == 2
98
    int characterIndex = (*(int*)0x00AC436C); //CCharacterSelection::s_selectionIndex
99
    int numCharacters = (*(int*)0x00B6B23C);
100
    int sumtingwong = (*(int*)0xB6B240);
101
 
102
	unsigned long long guid = *(unsigned long long*)(sumtingwong + 408 * characterIndex);
103
 
104
    CDataStore netMsg;
105
    netMsg.Put(CMSG_MOVE_CHARACTER_CHEAT);
106
    netMsg.Put(NULL);
107
    netMsg.Put(1);
108
    netMsg.Put(guid);
109
    netMsg.Put(16310.325195f);
110
    netMsg.Put(16268.939453f);
111
    netMsg.Put(69.444290f);
112
    netMsg.Put(0.00f);
113
    netMsg.Finalize();
114
    ClientServices_SendOnConnection(&netMsg);
115
    FrameScript_Execute("GetCharacterListUpdate()", "GetCharacterListUpdate()", NULL);
116
    //ClientConnection::GetCharacterList();
117
  }
118
  else {
119
    ConsoleWrite("You can only use this command on the character selection screen", ERROR_COLOR);
120
  }
121
 
122
  return 0;
123
}
124
 
125
//===========================================================================
31 tristanc 126
int Script_DebugTest (lua_State* L) {
7 tristanc 127
	ConsoleWrite("Hello from Script_DebugTest!",DEFAULT_COLOR);
3 tristanc 128
	return TRUE;
129
}
130
 
131
 
132
/****************************************************************************
133
*
31 tristanc 134
*   CGlueMgr class implementation
3 tristanc 135
*
136
***/
137
 
138
//===========================================================================
31 tristanc 139
int CGlueMgr::NetDisconnectHandler (void const *a1, void *a2) {
7 tristanc 140
	NetDisconnectHandlerPtr(a1, a2);
141
	WowGM::CGlueMgr::SetLoginPassword();
142
	return 1;
143
}
144
 
145
//===========================================================================
31 tristanc 146
void CGlueMgr::Resume (int initialized) {
3 tristanc 147
	ResumePtr(initialized);
148
	RegisterConsoleCommands();
149
}
150
 
151
//===========================================================================
31 tristanc 152
void WowGM::CGlueMgr::SetLoginPassword() {
7 tristanc 153
	char command[256] = {};
154
 
155
	// TODO: Call SStrPrintF here
156
	sprintf_s(command,
157
		sizeof(command),
158
		"AccountLoginPasswordEdit:SetText(\"%s\")",
159
		g_password->m_stringValue.m_string);
160
	FrameScript_Execute(command,command,NULL);
161
}
162
 
163
//===========================================================================
31 tristanc 164
void CGlueMgr::Suspend () {
3 tristanc 165
	SuspendPtr();
166
	UnregisterConsoleCommands();
167
}
168
 
169
//===========================================================================
31 tristanc 170
void CGlueMgr::Shutdown () {
3 tristanc 171
	ShutdownPtr();
172
}
173
 
174
//===========================================================================
31 tristanc 175
void CGlueMgr::RegisterConsoleCommands ()  {
3 tristanc 176
	ConsoleCommandRegister("script", CCommand_Script2, DEFAULT, 0);
177
  ConsoleCommandRegister("movecharacter", CCommand_MoveCharacter, GAME, NOHELP);
178
  ConsoleCommandRegister("worldport", CCommand_MoveCharacter, GAME, NOHELP);
179
 
180
	// TODO: Move the below line under FrameScript.cpp (see FrameScript_Initialize)
181
	//ConsoleCommandRegister("signalevent", CCommand_SignalEvent, DEFAULT, 0);
182
	FrameScript_RegisterFunction("debugtest",Script_DebugTest);
183
}
184
 
185
//===========================================================================
31 tristanc 186
void CGlueMgr::UnregisterConsoleCommands () {
3 tristanc 187
	ConsoleCommandUnregister("script");
188
  ConsoleCommandUnregister("movecharacter");
189
  ConsoleCommandUnregister("worldport");
190
 
191
	//ConsoleCommandUnregister("signalevent");
192
	FrameScript_UnregisterFunction("debugtest");
193
}