-
Notifications
You must be signed in to change notification settings - Fork 0
/
menus.cpp
325 lines (296 loc) · 9.35 KB
/
menus.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
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
324
325
#include "common/IPrefix.h"
#include "skse/SafeWrite.h"
#include "gfxvalue_visitor.h"
#include "ext_obj.h"
//#include "gfxvalue_logdump.h"
ItemMenuData * getItemData() {
IMenu * menu;
UIStringHolder * stringHolder = UIStringHolder::GetSingleton();
MenuManager * menuManager = MenuManager::GetSingleton();
UInt32 invOffset;
BSFixedString * menuName = NULL;
if (menuManager->IsMenuOpen(&stringHolder->containerMenu)) {
invOffset = offsetof(ContainerMenu, itemData);
menuName = &stringHolder->containerMenu;
}
else if (menuManager->IsMenuOpen(&stringHolder->barterMenu)) {
invOffset = offsetof(BarterMenuExt, itemData);
menuName = &stringHolder->barterMenu;
}
else if (menuManager->IsMenuOpen(&stringHolder->inventoryMenu)) {
invOffset = offsetof(InventoryMenu, itemData);
menuName = &stringHolder->inventoryMenu;
}
else {
_MESSAGE("no menu");
return NULL;
}
menu = menuManager->GetMenu(menuName);
if (!menu) {
_MESSAGE("menu null");
return NULL;
}
ItemMenuData* data = *((ItemMenuData**)((UInt32)menu + invOffset));
return data;
}
class SendUpdate : public GFxFunctionHandler
{
public:
virtual void Invoke(Args * args)
{
ScheduleInventoryUpdate();
}
};
class EnableUpdates : public GFxFunctionHandler
{
public:
virtual void Invoke(Args * args)
{
ASSERT(args->numArgs >= 1 && (args->args[0].GetType() == GFxValue::kType_Bool || args->args[0].GetType() == GFxValue::kType_Number));
args->result->SetUndefined();
bool enable = args->args[0].GetBool();
*bDontUpdate = enable ? 0 : 1;
ItemMenuData * data = getItemData();
// flag that gets set when the menu normally wants to disallow any more changes pending an update
// set it to 0 after it gets set (ex. ItemSelect/ItemTransfer) to be able to call it again without
// waiting for an update
// checked in 841D90 (to get selected item)
data->updatePending = enable ? 1 : 0;
}
};
class GetStolenCount : public GFxFunctionHandler
{
public:
virtual void Invoke(Args * args)
{
args->result->SetUndefined();
ItemMenuData* data = getItemData();
if (!data)
return;
UInt32 index = args->args[0].GetNumber();
if (index >= data->items.count)
return;
StandardItemData * item = data->items[index];
ObjDescExt * ext = static_cast<ObjDescExt*>(item->objDesc);
UInt32 stolenCount = ext->stolenCount();
args->result->SetNumber(stolenCount);
}
};
class GetFirstExtraCount : public GFxFunctionHandler
{
public:
virtual void Invoke(Args * args)
{
args->result->SetUndefined();
ItemMenuData * data = getItemData();
if (!data)
return;
UInt32 index = args->args[0].GetNumber();
if (index >= data->items.count)
return;
StandardItemData * item = data->items[index];
ObjDescExt * ext = static_cast<ObjDescExt*>(item->objDesc);
UInt32 count = 1;
ExtraCount * extraCount = NULL;
if (ext->extraData) {
tList<BaseExtraList>::Iterator beli = ext->extraData->Begin();
if (beli.Get()) {
BaseExtraList * l = beli.Get();
count = GetExtraCount(l);
} else {
count = ext->countDelta;
}
}
args->result->SetNumber(count);
}
};
class UpdateList : public GFxFunctionHandler
{
public:
/*void dumpData(ItemMenuData * data)
{
for (int i = 0; i < data->items.count; ++i) {
StandardItemData * idata = data->items[i];
_MESSAGE("%d %08x", idata->objDesc->countDelta, idata->objDesc->form);
tList<BaseExtraList>::Iterator li;
for (li = idata->objDesc->extraData->Begin(); li.Get(); ++li) {
BaseExtraList* list = li.Get();
BSExtraData * d = list->m_data;
_MESSAGE(" xd");
while (d) {
_MESSAGE(" %x", d->GetType());
d = d->next;
}
}
}
}
void dumpObj(ItemMenuData * data)
{
for (int i = 0; i < data->itemList.GetArraySize(); ++i) {
GFxValue obj;
if (data->itemList.GetElement(i, &obj)) {
double formId = -1, count = -1, filterFlag = -1;
GFxValue val;
if (obj.GetMember("formId", &val))
formId = val.GetNumber();
if (obj.GetMember("count", &val))
count = val.GetNumber();
if (obj.GetMember("filterFlag", &val))
filterFlag = val.GetNumber();
const char * text = NULL;
if (obj.GetMember("text", &val))
text = val.GetString();
_MESSAGE("%d: %f %f %f %s", i, formId, count, filterFlag, text);
}
}
}
*/
virtual void Invoke(Args * args)
{
args->result->SetUndefined();
ItemMenuData* data = getItemData();
if (!data)
return;
UIStringHolder * stringHolder = UIStringHolder::GetSingleton();
MenuManager * menuManager = MenuManager::GetSingleton();
if (menuManager->IsMenuOpen(&stringHolder->barterMenu)) {
BarterMenuExt * t = static_cast<BarterMenuExt*>(menuManager->GetMenu(&stringHolder->barterMenu));
updateInventory(t);
}
}
};
/*
class DumpRoot : public GFxFunctionHandler
{
public:
virtual void Invoke(Args * args)
{
args->result->SetUndefined();
UIStringHolder * stringHolder = UIStringHolder::GetSingleton();
MenuManager * menuManager = MenuManager::GetSingleton();
if (menuManager->IsMenuOpen(&stringHolder->inventoryMenu)) {
InventoryMenu * t = static_cast<InventoryMenu*>(menuManager->GetMenu(&stringHolder->inventoryMenu));
_MESSAGE("flags 1: %x, 2: %x", t->unkFlag, t->sortFlag);
}
/*typedef bool (* _LookupREFRByHandle)(UInt32 * refHandle, TESObjectREFR ** refrOut);
static _LookupREFRByHandle LookupREFRByHandle = (_LookupREFRByHandle)0x004A9180;
ItemMenuData* data = getItemData();
if (!data)
return;
StandardItemData* selected = data->GetSelectedItem();
_MESSAGE("getselecteditem %08x", selected);
_MESSAGE("items %d %d", data->items.count, data->items.arr.capacity);
for (UInt32 i = 0; i < data->items.count; ++i) {
StandardItemData* item = data->items[i];
//_MESSAGE("%s count %d %s", item->GetName(), item->GetCount(), item->objDesc->form->GetFullName());
//TESObjectREFR * refr;
/*bool b = LookupREFRByHandle((UInt32*)item->unk08, &refr);
_MESSAGE(" %d", b?1:0);
if (b) {
_MESSAGE("%s", refr->GetName());
}
*/
//LogDump::dump(&item->fxValue, 1);
/* //}
}
};
class DumpVar : public GFxFunctionHandler
{
public:
virtual void Invoke(Args * args)
{
ASSERT(args->numArgs >= 1);
_MESSAGE("dump %x", &args->args[0]);
//LogDump::dump(&args->args[0], 1);
}
};
//*/
const UInt32 addr_getPlayerGold = 0x6A8190;
class GetPlayerGold : public GFxFunctionHandler
{
public:
virtual void Invoke(Args * args)
{
UInt32 gold;
__asm {
push ecx
push eax
mov ecx, g_thePlayer
mov ecx, [ecx]
call addr_getPlayerGold
mov gold, eax
pop eax
pop ecx
}
args->result->SetNumber(gold);
}
};
const UInt32 addr_vendor = 0x012E2CB8; // void ** + 0AACh
const UInt32 addr_getVendorGold = 0x0047AB00;
UInt32 * vhandle = (UInt32*) 0x01B3E518;
const _LookupREFRByHandle LookupREFRByHandle = (_LookupREFRByHandle)0x004A9180;
class GetVendorGold : public GFxFunctionHandler
{
public:
virtual void Invoke(Args * args)
{
args->result->SetUndefined();
UIStringHolder * stringHolder = UIStringHolder::GetSingleton();
MenuManager * menuManager = MenuManager::GetSingleton();
ASSERT(menuManager != NULL);
ASSERT(stringHolder != NULL);
ASSERT(menuManager->IsMenuOpen(&stringHolder->barterMenu));
BarterMenuExt * menu = static_cast<BarterMenuExt*>(menuManager->GetMenu(&stringHolder->barterMenu));
TESObjectREFR * refr;
_MESSAGE("handle %x %x", vhandle, *vhandle);
if (LookupREFRByHandle(vhandle, &refr)) {
//TES * actor = DYNAMIC_CAST(refr, TESObjectREFR, TESActorBase);
_MESSAGE("act %x",refr);
UInt32 gold;
__asm {
push ecx
push eax
mov ecx, refr
call addr_getPlayerGold
mov gold, eax
pop eax
pop ecx
}
/*__asm {
push ecx
push eax
mov ecx, addr_vendor
mov ecx, [ecx]
mov ecx, [ecx+0AACh]
call addr_getVendorGold
mov gold, eax
pop eax
pop ecx
}*/
args->result->SetNumber(menu->vendorGold);
}
}
};
// for a simple loop using ItemTransfer or ItemSelect to work:
// must call enableUpdates(false) before each ItemTransfer otherwise the transfer will silently fail
// must _not_ call transfer on same item twice (maybe, dunno, best not to)
// (after calling transfer on an item, any information in the item object or entryList at the selectedIndex will be stale)
// must call enableUpdates(true) true after otherwise no inventory updates will be sent
// must call sendUpdate() after that otherwise the inventory shown to the player will not reflect actual inventories
void RegisterUpdateControl(GFxMovieView * view, GFxValue * root) {
RegisterFunction <EnableUpdates> (root, view, "enableUpdates");
RegisterFunction <SendUpdate> (root, view, "sendUpdate");
// when selling stolen items
// shrug a dug, if the number to sell is <= the first ExtraCount (or 1 w/ no ExtraCount, doesn't
// matter if no ExtraData) it takes the items from that "sub-list", otherwise it goes to the well
// first (the well being items w/ no extra data like ownership etc)
// patching ItemSelect for BarterMenu not really an option, tracing to try to reimplement it would be painful
RegisterFunction <GetStolenCount> (root, view, "getStolenCount");
RegisterFunction <GetFirstExtraCount> (root, view, "getFirstExtraCount");
RegisterFunction <UpdateList> (root, view, "updateList");
// explaining the usage here -- well, i won't, it's fucking stupid
RegisterFunction <GetPlayerGold> (root, view, "getPlayerGold");
RegisterFunction <GetVendorGold> (root, view, "getVendorGold");
//RegisterFunction <DumpRoot> (root, view, "_debugDumpRoot");
//RegisterFunction <DumpVar> (root, view, "_debugDumpVar");
}