-
Notifications
You must be signed in to change notification settings - Fork 2
/
ModifyPlayer.bas
403 lines (284 loc) · 16.3 KB
/
ModifyPlayer.bas
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
Attribute VB_Name = "ModifyPlayer"
' OSE - Oblivion Save Editor
' Copyright (C) 2012, 2013 Grahame White
'
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation; either version 2 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License along
' with this program; if not, write to the Free Software Foundation, Inc.,
' 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Option Explicit
DefObj A-Z
' The routines to actually modify the player portion of the data structure
' all live in this file
Public Sub ModifyPlayerAttribute(ByVal PlayerAttribute As Integer, ByVal AttributeValue As Byte)
SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Data(SaveFileData.OSE.Player.BaseAttributes + PlayerAttribute) = AttributeValue
End Sub
Public Sub ModifyPlayerSkill(ByVal PlayerSkill As Integer, ByVal SkillValue As Byte)
SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Data(SaveFileData.OSE.Player.Skills + PlayerSkill) = SkillValue
End Sub
Public Sub ModifyPlayerBaseHealth(ByVal BaseHealthValue As Long)
Dim tmpHealth(3) As Byte
Dim i As Integer
tmpHealth(3) = CByte((BaseHealthValue And &HFF000000) / BYTE_4)
tmpHealth(2) = CByte((BaseHealthValue And &HFF0000) / BYTE_3)
tmpHealth(1) = CByte((BaseHealthValue And &HFF00&) / BYTE_2)
tmpHealth(0) = CByte(BaseHealthValue And &HFF&)
For i = 0 To 3
SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Data(SaveFileData.OSE.Player.BaseHealth + i) = tmpHealth(i)
Next i
End Sub
Public Sub ModifyPlayerBaseMagicka(ByVal BaseMagickaValue As Long)
Dim tmpMagicka(1) As Byte
Dim i As Integer
tmpMagicka(1) = CByte((BaseMagickaValue And &HFF00&) / BYTE_2)
tmpMagicka(0) = CByte(BaseMagickaValue And &HFF&)
For i = 4 To 5
SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Data(SaveFileData.OSE.Player.BaseData + i) = tmpMagicka(i - 4)
Next i
End Sub
Public Sub ModifyPlayerBaseFatigue(ByVal BaseFatigueValue As Long)
Dim tmpFatigue(1) As Byte
Dim i As Integer
tmpFatigue(1) = CByte((BaseFatigueValue And &HFF00&) / BYTE_2)
tmpFatigue(0) = CByte(BaseFatigueValue And &HFF&)
For i = 6 To 7
SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Data(SaveFileData.OSE.Player.BaseData + i) = tmpFatigue(i - 6)
Next i
End Sub
Public Sub ModifyPlayerFaction(ByVal FactionNumber As Byte, ByVal FactionRank As Byte)
' Can only modify existing factions, other routines will allow adding and removing factions
Dim Offset As Integer
Offset = (FactionNumber * 5) + 6
' If a strange rank was detected when the file was loaded then restore it when saving
If SaveFileData.OSE.Player.FactionList(FactionNumber).Suspended Then
SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Data(SaveFileData.OSE.Player.Factions + Offset) = &HFF&
Else
SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Data(SaveFileData.OSE.Player.Factions + Offset) = FactionRank
End If
End Sub
Public Sub RebuildPlayerChangeRecord()
Dim tmpPlayerChangeRecord As ChangeRecord
Dim Position As Integer
Dim Start As Integer
tmpPlayerChangeRecord.FormID = SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).FormID
tmpPlayerChangeRecord.Type = SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Type
tmpPlayerChangeRecord.Flags = SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Flags
tmpPlayerChangeRecord.Version = SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Version
tmpPlayerChangeRecord.DataSize = GetNewPlayerRecordSize
ReDim tmpPlayerChangeRecord.Data(tmpPlayerChangeRecord.DataSize - 1)
Position = 0
If ((SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Flags And BIT_0) <> 0) Then
SetPlayerChangeRecordFormFlags tmpPlayerChangeRecord, Position, 4
Position = Position + 4
End If
If ((SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Flags And BIT_3) <> 0) Then
SetPlayerChangeRecordBaseAttributes tmpPlayerChangeRecord, Position, 8
Position = Position + 8
End If
If ((SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Flags And BIT_4) <> 0) Then
SetPlayerChangeRecordBaseData tmpPlayerChangeRecord, Position, 16
Position = Position + 16
End If
If ((SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Flags And BIT_6) <> 0) Then
SetPlayerChangeRecordFactions tmpPlayerChangeRecord, Position
Position = Position + (SaveFileData.OSE.Player.FactionCount * 5) + 2
End If
If ((SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Flags And BIT_5) <> 0) Then
SetPlayerChangeRecordSpellList tmpPlayerChangeRecord, Position
Position = Position + (SaveFileData.OSE.Player.SpellCount * 4) + 2
End If
If ((SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Flags And BIT_8) <> 0) Then
SetPlayerChangeRecordAI tmpPlayerChangeRecord, Position, 4
Position = Position + 4
End If
If ((SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Flags And BIT_2) <> 0) Then
SetPlayerChangeRecordBaseHealth tmpPlayerChangeRecord, Position, 4
Position = Position + 4
End If
If ((SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Flags And BIT_28) <> 0) Then
SetPlayerChangeRecordBaseMods tmpPlayerChangeRecord, Position
Position = Position + (SaveFileData.OSE.Player.BaseModCount * 5) + 2
End If
If ((SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Flags And BIT_7) <> 0) Then
SetPlayerChangeRecordFullName tmpPlayerChangeRecord
End If
If ((SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Flags And BIT_9) <> 0) Then
SetPlayerChangeRecordSkills tmpPlayerChangeRecord, Position, 21
Position = Position + 21
End If
If ((SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Flags And BIT_10) <> 0) Then
SetPlayerChangeRecordCombatStyle tmpPlayerChangeRecord, Position, 21
Position = Position + 4
End If
SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord) = tmpPlayerChangeRecord
ScanForPlayerMarkers
End Sub
Private Function GetNewPlayerRecordSize() As Integer
If ((SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Flags And BIT_0) <> 0) Then
GetNewPlayerRecordSize = GetNewPlayerRecordSize + 4
End If
If ((SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Flags And BIT_3) <> 0) Then
GetNewPlayerRecordSize = GetNewPlayerRecordSize + 8
End If
If ((SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Flags And BIT_4) <> 0) Then
GetNewPlayerRecordSize = GetNewPlayerRecordSize + 16
End If
If ((SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Flags And BIT_6) <> 0) Then
GetNewPlayerRecordSize = GetNewPlayerRecordSize + (SaveFileData.OSE.Player.FactionCount * 5) + 2
End If
If ((SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Flags And BIT_5) <> 0) Then
GetNewPlayerRecordSize = GetNewPlayerRecordSize + (SaveFileData.OSE.Player.SpellCount * 4) + 2
End If
If ((SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Flags And BIT_8) <> 0) Then
GetNewPlayerRecordSize = GetNewPlayerRecordSize + 4
End If
If ((SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Flags And BIT_2) <> 0) Then
GetNewPlayerRecordSize = GetNewPlayerRecordSize + 4
End If
If ((SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Flags And BIT_28) <> 0) Then
GetNewPlayerRecordSize = GetNewPlayerRecordSize + (SaveFileData.OSE.Player.BaseModCount * 5) + 2
End If
If ((SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Flags And BIT_7) <> 0) Then
GetNewPlayerRecordSize = GetNewPlayerRecordSize + 1 + Len(SaveFileData.OSE.Player.FullNameString)
End If
If ((SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Flags And BIT_9) <> 0) Then
GetNewPlayerRecordSize = GetNewPlayerRecordSize + 21
End If
If ((SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Flags And BIT_10) <> 0) Then
GetNewPlayerRecordSize = GetNewPlayerRecordSize + 4
End If
End Function
Private Sub SetPlayerChangeRecordFormFlags(ByRef tmpPlayerChangeRecord As ChangeRecord, ByVal Start As Integer, ByVal Length As Integer)
Dim NewOffset As Integer
Dim OriginalOffset As Integer
OriginalOffset = 0
For NewOffset = Start To Start + (Length - 1)
tmpPlayerChangeRecord.Data(NewOffset) = SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Data(SaveFileData.OSE.Player.FormFlags + OriginalOffset)
OriginalOffset = OriginalOffset + 1
Next NewOffset
End Sub
Private Sub SetPlayerChangeRecordBaseAttributes(ByRef tmpPlayerChangeRecord As ChangeRecord, ByVal Start As Integer, ByVal Length As Integer)
Dim NewOffset As Integer
Dim OriginalOffset As Integer
OriginalOffset = 0
For NewOffset = Start To Start + (Length - 1)
tmpPlayerChangeRecord.Data(NewOffset) = SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Data(SaveFileData.OSE.Player.BaseAttributes + OriginalOffset)
OriginalOffset = OriginalOffset + 1
Next NewOffset
End Sub
Private Sub SetPlayerChangeRecordBaseData(ByRef tmpPlayerChangeRecord As ChangeRecord, ByVal Start As Integer, ByVal Length As Integer)
Dim NewOffset As Integer
Dim OriginalOffset As Integer
OriginalOffset = 0
For NewOffset = Start To Start + (Length - 1)
tmpPlayerChangeRecord.Data(NewOffset) = SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Data(SaveFileData.OSE.Player.BaseData + OriginalOffset)
OriginalOffset = OriginalOffset + 1
Next NewOffset
End Sub
Private Sub SetPlayerChangeRecordFactions(ByRef tmpPlayerChangeRecord As ChangeRecord, ByVal Start As Integer)
Dim NewOffset As Integer
Dim RecordNumber As Integer
Dim iRef As Long
NewOffset = Start
tmpPlayerChangeRecord.Data(NewOffset) = CByte(SaveFileData.OSE.Player.FactionCount And &HFF&)
tmpPlayerChangeRecord.Data(NewOffset + 1) = CByte((SaveFileData.OSE.Player.FactionCount And &HFF00&) / BYTE_2)
NewOffset = NewOffset + 2
For RecordNumber = 0 To SaveFileData.OSE.Player.FactionCount - 1
iRef = GetIref(SaveFileData.OSE.Player.FactionList(RecordNumber).FormID)
tmpPlayerChangeRecord.Data(NewOffset) = CByte(iRef And &HFF&)
tmpPlayerChangeRecord.Data(NewOffset + 1) = CByte((iRef And &HFF00&) / BYTE_2)
tmpPlayerChangeRecord.Data(NewOffset + 2) = CByte((iRef And &HFF0000) / BYTE_3)
tmpPlayerChangeRecord.Data(NewOffset + 3) = CByte((iRef And &HFF000000) / BYTE_4)
tmpPlayerChangeRecord.Data(NewOffset + 4) = CByte(SaveFileData.OSE.Player.FactionList(RecordNumber).Level)
NewOffset = NewOffset + 5
Next RecordNumber
End Sub
Private Sub SetPlayerChangeRecordSpellList(ByRef tmpPlayerChangeRecord As ChangeRecord, ByVal Start As Integer)
Dim NewOffset As Integer
Dim RecordNumber As Integer
Dim RawiRef As FourByteArray
Dim iRef As LongType
NewOffset = Start
Debug.Print UBound(tmpPlayerChangeRecord.Data())
tmpPlayerChangeRecord.Data(NewOffset) = CByte(SaveFileData.OSE.Player.SpellCount And &HFF&)
tmpPlayerChangeRecord.Data(NewOffset + 1) = CByte((SaveFileData.OSE.Player.SpellCount And &HFF00&) / BYTE_2)
NewOffset = NewOffset + 2
For RecordNumber = 0 To SaveFileData.OSE.Player.SpellCount - 1
iRef.Result = SaveFileData.OSE.Player.SpellList(RecordNumber).iRef
LSet RawiRef = iRef
tmpPlayerChangeRecord.Data(NewOffset) = RawiRef.Bytes(0)
tmpPlayerChangeRecord.Data(NewOffset + 1) = RawiRef.Bytes(1)
tmpPlayerChangeRecord.Data(NewOffset + 2) = RawiRef.Bytes(2)
tmpPlayerChangeRecord.Data(NewOffset + 3) = RawiRef.Bytes(3)
NewOffset = NewOffset + 4
Next RecordNumber
End Sub
Private Sub SetPlayerChangeRecordAI(ByRef tmpPlayerChangeRecord As ChangeRecord, ByVal Start As Integer, ByVal Length As Integer)
Dim NewOffset As Integer
Dim OriginalOffset As Integer
OriginalOffset = 0
For NewOffset = Start To Start + (Length - 1)
tmpPlayerChangeRecord.Data(NewOffset) = SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Data(SaveFileData.OSE.Player.AI + OriginalOffset)
OriginalOffset = OriginalOffset + 1
Next NewOffset
End Sub
Private Sub SetPlayerChangeRecordBaseHealth(ByRef tmpPlayerChangeRecord As ChangeRecord, ByVal Start As Integer, ByVal Length As Integer)
Dim NewOffset As Integer
Dim OriginalOffset As Integer
OriginalOffset = 0
For NewOffset = Start To Start + (Length - 1)
tmpPlayerChangeRecord.Data(NewOffset) = SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Data(SaveFileData.OSE.Player.BaseHealth + OriginalOffset)
OriginalOffset = OriginalOffset + 1
Next NewOffset
End Sub
Private Sub SetPlayerChangeRecordBaseMods(ByRef tmpPlayerChangeRecord As ChangeRecord, ByVal Start As Integer)
Dim NewOffset As Integer
Dim RecordNumber As Integer
NewOffset = Start
tmpPlayerChangeRecord.Data(NewOffset) = CByte(SaveFileData.OSE.Player.BaseModCount And &HFF&)
tmpPlayerChangeRecord.Data(NewOffset + 1) = CByte((SaveFileData.OSE.Player.BaseModCount And &HFF00&) / BYTE_2)
NewOffset = NewOffset + 2
For RecordNumber = 0 To SaveFileData.OSE.Player.BaseModCount - 1
tmpPlayerChangeRecord.Data(NewOffset) = CByte(SaveFileData.OSE.Player.BaseModList(RecordNumber).Index)
tmpPlayerChangeRecord.Data(NewOffset + 1) = CByte(SaveFileData.OSE.Player.BaseModList(RecordNumber).ModValue And &HFF&)
tmpPlayerChangeRecord.Data(NewOffset + 2) = CByte(SaveFileData.OSE.Player.BaseModList(RecordNumber).ModValue And &HFF00&) / BYTE_2
tmpPlayerChangeRecord.Data(NewOffset + 3) = CByte(SaveFileData.OSE.Player.BaseModList(RecordNumber).ModValue And &HFF0000) / BYTE_3
tmpPlayerChangeRecord.Data(NewOffset + 4) = CByte(SaveFileData.OSE.Player.BaseModList(RecordNumber).ModValue And &HFF000000) / BYTE_4
NewOffset = NewOffset + 5
Next RecordNumber
End Sub
Private Sub SetPlayerChangeRecordFullName(ByRef tmpPlayerChangeRecord As ChangeRecord)
Dim NewOffset As Integer
Dim NamePosition As Integer
tmpPlayerChangeRecord.Data(NewOffset) = CByte(Len(SaveFileData.OSE.Player.FullNameString))
For NamePosition = 1 To Len(SaveFileData.OSE.Player.FullNameString)
tmpPlayerChangeRecord.Data(NewOffset + NamePosition) = Asc(Mid(SaveFileData.OSE.Player.FullNameString, NamePosition, 1))
Next NamePosition
End Sub
Private Sub SetPlayerChangeRecordSkills(ByRef tmpPlayerChangeRecord As ChangeRecord, ByVal Start As Integer, ByVal Length As Integer)
Dim NewOffset As Integer
Dim OriginalOffset As Integer
OriginalOffset = 0
For NewOffset = Start To Start + (Length - 1)
tmpPlayerChangeRecord.Data(NewOffset) = SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Data(SaveFileData.OSE.Player.Skills + OriginalOffset)
OriginalOffset = OriginalOffset + 1
Next NewOffset
End Sub
Private Sub SetPlayerChangeRecordCombatStyle(ByRef tmpPlayerChangeRecord As ChangeRecord, ByVal Start As Integer, ByVal Length As Integer)
Dim NewOffset As Integer
Dim OriginalOffset As Integer
OriginalOffset = 0
For NewOffset = Start To Start + (Length - 1)
tmpPlayerChangeRecord.Data(NewOffset) = SaveFileData.ChangeRecords(SaveFileData.OSE.Player.PlayerRecord).Data(SaveFileData.OSE.Player.CombatStyle + OriginalOffset)
OriginalOffset = OriginalOffset + 1
Next NewOffset
End Sub