This repository has been archived by the owner on Jul 25, 2019. It is now read-only.
/
main.cpp
146 lines (119 loc) · 3.85 KB
/
main.cpp
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "RuntimeEditorIDsInternals.h"
#include "Commands.h"
#include "VersionInfo.h"
IDebugLog gLog("RuntimeEditorIDs.log");
PluginHandle g_pluginHandle = kPluginHandle_Invalid;
OBSEStringVarInterface* g_strVarInfc = NULL;
OBSEMessagingInterface* g_msgIntfc = NULL;
OBSEScriptInterface* g_scriptIntfc = NULL;
CSEIntelliSenseInterface* g_CSEISIntfc = NULL;
CSEConsoleInterface* g_CSEConsoleIntfc = NULL;
void REIDInteropHandler(OBSEMessagingInterface::Message* Msg)
{
switch (Msg->type)
{
case 'CSEI':
{
CSEInterface* Interface = (CSEInterface*)Msg->data;
g_CSEConsoleIntfc = (CSEConsoleInterface*)Interface->InitializeInterface(CSEInterface::kCSEInterface_Console);
g_CSEISIntfc = (CSEIntelliSenseInterface*)Interface->InitializeInterface(CSEInterface::kCSEInterface_IntelliSense);
_MESSAGE("Received interface from CSE");
g_CSEConsoleIntfc->PrintToConsole("REID", "Registering command URLs ...");
g_CSEISIntfc->RegisterCommandURL("GetRuntimeEditorID", "http://cs.elderscrolls.com/constwiki/index.php/GetRuntimeEditorID");
}
break;
case 'EDID':
{
REIDInteropData* Data = (REIDInteropData*)Msg->data;
if (Data)
{
const char* EditorID = g_editorIDManager.LookupByFormID(Data->FormID);
if (EditorID)
{
Data->HasEditorID = true;
strcpy_s(Data->EditorIDBuffer, Data->kBufferSize, EditorID);
}
else
Data->HasEditorID = false;
}
}
break;
}
}
void OBSEMessageHandler(OBSEMessagingInterface::Message* Msg)
{
switch (Msg->type)
{
case OBSEMessagingInterface::kMessage_PostLoad:
g_msgIntfc->RegisterListener(g_pluginHandle, NULL, REIDInteropHandler);
g_msgIntfc->RegisterListener(g_pluginHandle, "CSE", REIDInteropHandler);
break;
case OBSEMessagingInterface::kMessage_PostPostLoad:
_MESSAGE("Requesting an interface from CSE");
g_msgIntfc->Dispatch(g_pluginHandle, 'CSEI', NULL, 0, "CSE");
break;
}
}
extern "C"
{
bool OBSEPlugin_Query(const OBSEInterface * obse, PluginInfo * info)
{
info->infoVersion = PluginInfo::kInfoVersion;
info->name = "REID";
info->version = PACKED_SME_VERSION;
if(obse->obseVersion < OBSE_VERSION_INTEGER)
{
_ERROR("OBSE version too old (got %08X expected at least %08X)", obse->obseVersion, OBSE_VERSION_INTEGER);
return false;
}
else if(obse->isEditor == false)
{
if(obse->oblivionVersion != OBLIVION_VERSION)
{
_ERROR("incorrect Oblivion version (got %08X need %08X)", obse->oblivionVersion, OBLIVION_VERSION);
return false;
}
g_strVarInfc = (OBSEStringVarInterface*)obse->QueryInterface(kInterface_StringVar);
RegisterStringVarInterface(g_strVarInfc);
if (g_strVarInfc == NULL)
{
_ERROR("Couldn't initialize string var interface");
return false;
}
g_scriptIntfc = (OBSEScriptInterface*)obse->QueryInterface(kInterface_Script);
if (g_scriptIntfc == NULL)
{
_MESSAGE("Script interface not found");
return false;
}
}
g_msgIntfc = (OBSEMessagingInterface*)obse->QueryInterface(kInterface_Messaging);
if (g_msgIntfc == NULL)
{
_ERROR("Couldn't initialize messaging interface");
return false;
}
return true;
}
bool OBSEPlugin_Load(const OBSEInterface * obse)
{
g_pluginHandle = obse->GetPluginHandle();
_MESSAGE("RuntimeEditorIDs Initializing...");
gLog.Indent();
if(!obse->isEditor)
{
for (int i = 0; i < VTBLTableSize; i++)
{
UInt32 PatchAddress = g_VTBLTable[i].Address + kTESForm_SetEditorID_VTBLOffset;
SafeWrite32(PatchAddress, (UInt32)TESForm_HandleEditorID);
_MESSAGE("Patched '%s' VTBL offset 0x%08X", g_VTBLTable[i].Class, PatchAddress);
}
}
obse->SetOpcodeBase(0x2740); // 0x2740 - 0x274F
obse->RegisterTypedCommand(&kCommandInfo_GetRuntimeEditorID, kRetnType_String);
g_msgIntfc->RegisterListener(g_pluginHandle, "OBSE", OBSEMessageHandler);
gLog.Outdent();
_MESSAGE("RuntimeEditorIDs Initialized!\n\n");
return true;
}
};