-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcodeview.h
323 lines (250 loc) · 8.44 KB
/
codeview.h
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#pragma once
#include <activscp.h>
#include "atlcom.h"
enum SecurityLevelEnum
{
eSecurityNone = 0,
eSecurityWarnOnUnsafeType = 1,
eSecurityWarnOnType = 2,
eSecurityWarnOnAll = 3,
eSecurityNoControls = 4
};
class IScriptable
{
public:
IScriptable();
STDMETHOD(get_Name)(BSTR *pVal) = 0;
virtual IDispatch *GetDispatch() = 0;
virtual ISelect *GetISelect() = 0;
WCHAR m_wzName[MAXNAMEBUFFER];
WCHAR m_wzMatchName[MAXNAMEBUFFER]; // case-insensitive
};
class CodeViewer;
class DebuggerModule:
public CComObjectRootEx<CComSingleThreadModel>,
public IDispatchImpl<IVPDebug, &IID_IVPDebug, &LIBID_VPinballLib>,
public IScriptable
{
BEGIN_COM_MAP(DebuggerModule)
COM_INTERFACE_ENTRY(IVPDebug)
COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()
STDMETHOD(Print)(VARIANT *pvar);
void Init(CodeViewer *pcv);
virtual IDispatch *GetDispatch();
virtual ISelect *GetISelect() {return NULL;}
STDMETHOD(get_Name)(BSTR *pVal);
CodeViewer *m_pcv;
};
class IScriptableHost
{
public:
virtual void SelectItem(IScriptable *piscript) = 0;
virtual void SetDirtyScript(SaveDirtyState sds) = 0;
virtual void DoCodeViewCommand(int command) = 0;
};
class CodeViewDispatch : public ISort<CodeViewDispatch>/*Strings*/
{
public:
CodeViewDispatch();
~CodeViewDispatch();
WCHAR m_wzName[32];
IUnknown *m_punk;
IDispatch *m_pdisp;
IScriptable *m_piscript;
BOOL m_fGlobal;
virtual int SortAgainst(CodeViewDispatch *pcvd/*void *pvoid*/);
virtual int SortAgainstValue(void *pv);
};
class CodeViewer :
public CComObjectRoot,
//public IDispatchImpl<IDragPoint, &IID_IDragPoint, &LIBID_VPinballLib>,
//public CComCoClass<CodeViewer,&CLSID_DragPoint>,
//public CComObjectRootEx<CComSingleThreadModel>,
public IActiveScriptSite,
public IActiveScriptSiteWindow,
public IInternetHostSecurityManager,
public IServiceProvider
{
public:
CodeViewer();
virtual ~CodeViewer();
void Init(IScriptableHost *psh);
void Create();
void Destroy();
void SetVisible(BOOL fVisible);
void SetEnabled(BOOL fEnabled);
void SetClean(SaveDirtyState sds);
// Script Class
STDMETHOD(CleanUpScriptEngine)();
STDMETHOD(InitializeScriptEngine)();
HRESULT AddItem(IScriptable *piscript, BOOL fGlobal);
void RemoveItem(IScriptable *piscript);
HRESULT ReplaceName(IScriptable *piscript, WCHAR *wzNew);
void SelectItem(IScriptable *piscript);
void Compile();
void Start();
void EndSession();
HRESULT AddTemporaryItem(BSTR bstr, IDispatch *pdisp);
STDMETHOD(GetItemInfo)(LPCOLESTR pstrName, DWORD dwReturnMask,
IUnknown **ppiunkItem, ITypeInfo **ppti);
STDMETHOD(OnScriptError)(IActiveScriptError *pscripterror);
STDMETHOD(GetLCID)(LCID *plcid)
{ *plcid = 9; return S_OK; }
STDMETHOD(GetDocVersionString)(BSTR *pbstrVersion)
{ *pbstrVersion = SysAllocString(L""); return S_OK; }
STDMETHOD(OnScriptTerminate)(const VARIANT *pvr, const EXCEPINFO *pei)
{ return S_OK; }
STDMETHOD(OnStateChange)(SCRIPTSTATE ssScriptState)
{ return S_OK; }
STDMETHOD(OnEnterScript)();
STDMETHODIMP OnLeaveScript();
STDMETHODIMP GetWindow(HWND *phwnd)
{ *phwnd = GetDesktopWindow(); return S_OK; }
STDMETHODIMP EnableModeless(BOOL)
{ return S_OK; }
// Internet Security interface
virtual HRESULT STDMETHODCALLTYPE GetSecurityId(
/* [size_is][out] */ BYTE *pbSecurityId,
/* [out][in] */ DWORD *pcbSecurityId,
/* [in] */ DWORD_PTR dwReserved);
virtual HRESULT STDMETHODCALLTYPE ProcessUrlAction(
/* [in] */ DWORD dwAction,
/* [size_is][out] */ BYTE __RPC_FAR *pPolicy,
/* [in] */ DWORD cbPolicy,
/* [in] */ BYTE __RPC_FAR *pContext,
/* [in] */ DWORD cbContext,
/* [in] */ DWORD dwFlags,
/* [in] */ DWORD dwReserved);
virtual HRESULT STDMETHODCALLTYPE QueryCustomPolicy(
/* [in] */ REFGUID guidKey,
/* [size_is][size_is][out] */ BYTE __RPC_FAR *__RPC_FAR *ppPolicy,
/* [out] */ DWORD __RPC_FAR *pcbPolicy,
/* [in] */ BYTE __RPC_FAR *pContext,
/* [in] */ DWORD cbContext,
/* [in] */ DWORD dwReserved);
BOOL FControlAlreadyOkayed(CONFIRMSAFETY *pcs);
void AddControlToOkayedList(CONFIRMSAFETY *pcs);
BOOL FControlMarkedSafe(CONFIRMSAFETY *pcs);
BOOL FUserManuallyOkaysControl(CONFIRMSAFETY *pcs);
virtual HRESULT STDMETHODCALLTYPE QueryService(
REFGUID guidService,
REFIID riid,
void **ppv);
// Use CComObject to implement AddRef/Release/QI
BEGIN_COM_MAP(CodeViewer)
//COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(IActiveScriptSite)
COM_INTERFACE_ENTRY(IActiveScriptSiteWindow)
COM_INTERFACE_ENTRY(IInternetHostSecurityManager)
COM_INTERFACE_ENTRY(IServiceProvider)
END_COM_MAP()
IActiveScriptParse* m_pScriptParse;
IActiveScript* m_pScript;
IActiveScriptDebug* m_pScriptDebug;
VectorSortString<CodeViewDispatch> m_vcvd;
VectorSortString<CodeViewDispatch> m_vcvdTemp; // Objects added through script
FINDREPLACE m_findreplacestruct;
char szFindString[81];
char szReplaceString[81];
BOOL m_fScriptError; // Whether a script error has occured - used for polling from the game
IScriptableHost *m_psh;
// Edit Class
void ColorLine(int line);
void UncolorError();
void ColorError(int line, int nchar);
void ShowFindDialog();
void ShowFindReplaceDialog();
void Find(FINDREPLACE *pfr);
void Replace(FINDREPLACE *pfr);
void SaveToStream(IStream *pistream, HCRYPTHASH hcrypthash, HCRYPTKEY hcryptkey); //<<< modified by chris as part of table protection
void LoadFromStream(IStream *pistream, HCRYPTHASH hcrypthash, HCRYPTKEY hcryptkey); //<<< modified by chris as part of table protection
void SetCaption(char *szCaption);
void ListEventsFromItem();
void FindCodeFromEvent();
void TellHostToSelectItem();
void GetParamsFromEvent(int iEvent, char *szParams);
void MarginClick(int position, int modifiers);
void EvaluateScriptStatement(char *szScript);
void AddToDebugOutput(char *szText);
CComObject<DebuggerModule> *m_pdm; // Object to expose to script for global functions
//ULONG m_cref;
HWND m_hwndMain;
HWND m_hwndScintilla;
HWND m_hwndStatus;
HWND m_hwndFind;
HWND m_hwndItemList;
HWND m_hwndEventList;
HWND m_hwndFunctionList;
SaveDirtyState m_sdsDirty;
BOOL m_fIgnoreDirty;
HACCEL m_haccel; // Accelerator keys
FINDREPLACE m_findreplaceold; //the last thing found/replaced
int m_errorLineNumber;
};
class Collection:
public IDispatchImpl<ICollection, &IID_ICollection, &LIBID_VPinballLib>,
public CComObjectRoot,
public CComCoClass<Collection,&CLSID_Collection>,
public EventProxy<Collection, &DIID_ICollectionEvents>,
public IConnectionPointContainerImpl<Collection>,
public IProvideClassInfo2Impl<&CLSID_Collection, &DIID_ICollectionEvents, &LIBID_VPinballLib>,
public IScriptable,
public ILoadable
{
public:
Collection();
// IScriptable
STDMETHOD(get_Name)(BSTR *pVal);
virtual IDispatch *GetDispatch();
virtual ISelect *GetISelect();
//ILoadable
virtual HRESULT SaveData(IStream *pstm, HCRYPTHASH hcrypthash, HCRYPTKEY hcryptkey);
virtual HRESULT LoadData(IStream *pstm, PinTable *ppt, int version, HCRYPTHASH hcrypthash, HCRYPTKEY hcryptkey);
virtual BOOL LoadToken(int id, BiffReader *pbr);
STDMETHOD(get_Count)(long __RPC_FAR *plCount);
STDMETHOD(get_Item)(long index, IDispatch __RPC_FAR * __RPC_FAR *ppidisp);
STDMETHOD(get__NewEnum)(IUnknown** ppunk);
BEGIN_COM_MAP(Collection)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(ICollection)
COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
COM_INTERFACE_ENTRY(IProvideClassInfo)
COM_INTERFACE_ENTRY(IProvideClassInfo2)
END_COM_MAP()
BEGIN_CONNECTION_POINT_MAP(Collection)
CONNECTION_POINT_ENTRY(DIID_ICollectionEvents)
END_CONNECTION_POINT_MAP()
Vector<ISelect> m_visel;
BOOL m_fFireEvents;
BOOL m_fStopSingleEvents;
};
class OMCollectionEnum :
public CComObjectRootEx<CComSingleThreadModel>,
public IEnumVARIANT
{
public:
BEGIN_COM_MAP(OMCollectionEnum)
COM_INTERFACE_ENTRY(IEnumVARIANT)
END_COM_MAP()
OMCollectionEnum();
~OMCollectionEnum();
STDMETHOD(Init)(Collection *pcol);
STDMETHOD(Next)(ULONG celt, VARIANT __RPC_FAR *rgVar, ULONG __RPC_FAR *pCeltFetched);
STDMETHOD(Skip)(ULONG celt);
STDMETHOD(Reset)();
STDMETHOD(Clone)(IEnumVARIANT __RPC_FAR *__RPC_FAR *ppEnum);
private:
Collection *m_pcol;
int m_index;
};
inline bool FIsWhitespace(const char ch)
{
return (ch == ' ' || ch == 9/*tab*/);
}
inline void AddEventToList(char * const sz, const int index, const int dispid, const LPARAM lparam)
{
const HWND hwnd = (HWND)lparam;
const int listindex = SendMessage(hwnd, CB_ADDSTRING, 0, (int)sz);
SendMessage(hwnd, CB_SETITEMDATA, listindex, index);
}