-
Notifications
You must be signed in to change notification settings - Fork 3
/
Diff.py
83 lines (75 loc) · 2.76 KB
/
Diff.py
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
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 14 15:59:11 2019
@author: AsteriskAmpersand
"""
from Cstruct import PyCStruct
from collections import OrderedDict
from Chunk import chunkPath
class Header (PyCStruct):
fields = OrderedDict([
("IBBytes","uint32"),
("FileID", "uint32"),#
]);
class values(PyCStruct):
fields = OrderedDict([
("monHPMultiplier", "float"),#
("monDmgMultiplier", "float"),#
("playerDmgMultiplier", "float"),#
("monPartHP", "float"),#
("monStatusBase", "float"),#
("monStatusBuildup", "float"),#
("monStun", "float"),#
("monExhaust", "float"),#
("monMount", "float"),#
])
def toModifiers(self):
return [self.__getattribute__(key) for key in list(self.fields.keys())]
def __mul__(self, value):
result = values()
for field in list(self.fields.keys()):
result.__setattr__(field,self.__getattribute__(field)*value.__getattribute__(field))
return result
class unknTrail(PyCStruct):
fields = OrderedDict([
("unknownData", "int32[7]"),#
])
class Difficulty():
def __init__(self):
self.DifficultyHeader=Header()
self.soloMultipliers= [values() for _ in range(1000)]
self.mpMultipliers=[values() for _ in range(1000)]
self.unknTrail = unknTrail()
def marshall(self,data):
self.DifficultyHeader.marshall(data)
[solo.marshall(data) for solo in self.soloMultipliers]
[mult.marshall(data) for mult in self.mpMultipliers]
self.unknTrail.marshall(data)
def serialize(self):
result = self.DifficultyHeader.serialize()
result+=b''.join([solo.serialize() for solo in self.soloMultipliers])
result+=b''.join([mult.serialize() for mult in self.mpMultipliers])
result+= self.unknTrail.serialize()
return result
class DifficultyFile():
difficultyPath = r"%s\common\em\em_difficulty.dtt_dif"%chunkPath
def __init__(self):
with open(self.difficultyPath, "rb") as diff:
self.Difficulty = Difficulty()
self.Difficulty.marshall(diff)
def spMod(self):
return lambda key: self.Difficulty.soloMultipliers[key]
def mpMod(self, hr):
return lambda key: self.Difficulty.mpMultipliers[hr]*self.Difficulty.soloMultipliers[key]
def write(self,filepath):
with open(filepath,"w") as outf:
self.outputArray(outf,"soloMultipliers")
outf.write("\n")
self.outputArray(outf,"mpMultipliers")
def outputArray(self,outf,prop):
outf.write(','.join([val for val in values.fields]))
outf.write("\n")
for val in getattr(self.Difficulty,prop):
outf.write(','.join([str(getattr(val,field)) for field in values.fields]))
outf.write("\n")
return