-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
190 lines (164 loc) · 7.64 KB
/
index.js
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
/* global ngapp, xelib, registerPatcher, patcherUrl */
registerPatcher({
info: info,
gameModes: [xelib.gmSSE],
settings: {
label: 'Randomized Birthstones Patcher',
hide: true,
templateUrl: `${patcherUrl}/partials/settings.html`,
},
// optional array of required filenames. can omit if empty.
requiredFiles: ['Unofficial Skyrim Special Edition Patch.esp'],
execute: (patchFile, helpers, settings, locals) => ({
// required: array of process blocks. each process block should have both
initialize: function() {
locals.activator_references = {
'Lady' : '000DC84A',
'Apprentice' : '000E0DC2',
'Lover' : '000E0DBE',
'Steed' :'000E0E1F',
'Atronach' : '000E0F4A',
'Shadow' : '000D1E9F',
'Lord' : '000E0F22',
'Ritual' : '000D9630',
'Tower' : '000E0F6F',
'Serpent':'000E0F55'
};
locals.activators = {
'Lady' : '000D2330',
'Apprentice' : '000D2331',
'Lover' : '000D2332',
'Steed' :'000D2333',
'Atronach' : '000D2334',
'Shadow' : '000D2335',
'Lord' : '000D2336',
'Ritual' : '000D2337',
'Tower' : '000D2338',
'Serpent':'000D2339'
};
locals.locations = {
'Lady' : '000D5676',
'Apprentice' : '000D5673',
'Lover' : '000D5678',
'Steed' :'000D567D',
'Atronach' : '000D5675',
'Shadow' : '000D567C',
'Lord' : '000D5677',
'Ritual' : '000D567A',
'Tower' : '000D567E',
'Serpent':'000D567B'
};
locals.marker_references = {
'Lady' : '000DED90',
'Apprentice' : '0001BAB9',
'Lover' : '0001BABB',
'Steed' :'0001BAC0',
'Atronach' : '000E0F4C',
'Shadow' : '000D3935',
'Lord' : '000E0F47',
'Ritual' : '000DD9D5',
'Tower' : '000E0ED5',
'Serpent':'000E0F69'
};
locals.birthstone_names = Object.keys(locals.activator_references);
locals.birthstone_ref_hex_ids = Object.values(locals.activator_references);
locals.birthstone_lctn_hex_ids = Object.values(locals.locations);
locals.birthstone_map_marker_hex_ids = Object.values(locals.marker_references);
locals.ref_to_birthstone = {};
locals.lctn_to_birthstone = {};
locals.marker_to_birthstone = {};
locals.randomized_birthstones = {};
Object.keys(locals.activator_references).forEach(function(r) {
locals.ref_to_birthstone[locals.activator_references[r]] = r;
});
Object.keys(locals.locations).forEach(function(r) {
locals.lctn_to_birthstone[locals.locations[r]] = r;
});
Object.keys(locals.marker_references).forEach(function(r) {
locals.marker_to_birthstone[locals.marker_references[r]] = r;
});
locals.get_records = function(patchFile, helpers, settings, locals, birthstone_hex_ids) {
let birthstone_records = [];
for (let i = 0; i < birthstone_hex_ids.length; ++i) {
let hex_id = birthstone_hex_ids[i];
let form_id = parseInt(hex_id, 16);
let birthstone_record = xelib.GetRecord(patchFile, form_id);
birthstone_records.push(birthstone_record);
}
return birthstone_records;
};
locals.random_integer = function(max) {
return Math.floor(Math.random() * (max - 1)) + 1;
};
// randomized birthstone ids
let names = locals.birthstone_names.slice();
names.forEach(function(name) {
let r = locals.random_integer(names.length);
if (!Object.keys(locals.randomized_birthstones).includes(name)) {
let alias_to = names[r];
locals.randomized_birthstones[name] = alias_to;
locals.randomized_birthstones[alias_to] = name;
names = names.filter(function(element) {
return element !== name && element !== alias_to;
});
}
});
},
process: [
{
// Patch References to Activators
// Adds new References, disables old References
records: function (patchFile, helpers, settings, locals) {
return locals.get_records(patchFile, helpers, settings, locals, locals.birthstone_ref_hex_ids);
},
patch: function (record) {
helpers.logMessage(`Patching ${xelib.LongName(record)}`);
let hex_form_id = xelib.GetHexFormID(record);
let stone_name = locals.ref_to_birthstone[hex_form_id];
let new_stone_name = locals.randomized_birthstones[stone_name];
if (stone_name !== new_stone_name) {
let new_activator_id = locals.activators[new_stone_name];
// Copy new record
let new_record = xelib.CopyElement(record, patchFile, true);
// Disable existing record
xelib.SetRecordFlag(record, 'Initially Disabled', true);
// Rename new record with random birthstone
xelib.SetValue(new_record, 'NAME - Base', new_activator_id);
}
}
},
{
// Patch Locations
records: function (patchFile, helpers, settings, locals) {
return locals.get_records(patchFile, helpers, settings, locals, locals.birthstone_lctn_hex_ids);
},
patch: function (record) {
helpers.logMessage(`Patching ${xelib.LongName(record)}`);
let hex_form_id = xelib.GetHexFormID(record);
let stone_name = locals.lctn_to_birthstone[hex_form_id];
let new_stone_name = locals.randomized_birthstones[stone_name];
if (stone_name !== new_stone_name) {
let new_name = 'The ' + new_stone_name + ' Doomstone';
xelib.SetValue(record, 'FULL - Name', new_name);
}
}
},
{
// Patch References to Map Markers
records: function (patchFile, helpers, settings, locals) {
return locals.get_records(patchFile, helpers, settings, locals, locals.birthstone_map_marker_hex_ids);
},
patch: function (record) {
helpers.logMessage(`Patching ${xelib.LongName(record)}`);
let hex_form_id = xelib.GetHexFormID(record);
let stone_name = locals.marker_to_birthstone[hex_form_id];
let new_stone_name = locals.randomized_birthstones[stone_name];
if (stone_name !== new_stone_name) {
let new_name = 'The ' + new_stone_name + ' Doomstone';
xelib.SetValue(record, 'Map Marker\\FULL - Name', new_name);
}
}
}
]
})
});