forked from Solybum/PSOBBMod-Addons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunitxt.lua
More file actions
177 lines (150 loc) · 4.2 KB
/
unitxt.lua
File metadata and controls
177 lines (150 loc) · 4.2 KB
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
local unitxtPointer = 0x00A9CD50
local specialBaseID = 0x005E4CBB
--unitxtItemName = 0x04
--unitxtMonsterName = 0x08
--unitxtItemDesc = 0x0C
--unitxtMonsterNameUlt = 0x10
local srankSpecial =
{
"", "Jellen", "Zalure", "HP Regeneration", "TP Regeneration",
"Burning", "Tempest", "Blizzard", "Arrest", "Chaos", "Hell",
"Spirit", "Berserk", "Demon's", "Gush", "Geist", "King's",
}
local magColor =
{
"Red", "Blue", "Yellow", "Green", "Purple", "Black", "White",
"Cyan", "Brown", "Orange", "Slate Blue", "Olive", "Turquoise",
"Fuschia", "Grey", "Cream", "Pink", "Dark Green",
}
-- Internal function to read text from the unitxt
local function _Read(group, index)
address = pso.read_u32(unitxtPointer)
if address == 0 then
return nil
end
address = address + (group * 4)
address = pso.read_u32(address)
if address == 0 then
return nil
end
address = address + 4 * index
address = pso.read_u32(address)
if address == 0 then
return nil
end
return pso.read_wstr(address, 256)
end
-- Public function to read a string from a
-- given string group in the unitxt
local function Read(group, index)
return _Read(group, index)
end
-- Reads item names from the unitxt with the given id, from the PMT data
local function GetItemName(index)
if index == -1 then
return "???"
end
return _Read(1, index)
end
-- Reads a special name based on it's index
local function GetSpecialName(id)
if id == 0 then
return "None"
end
baseID = pso.read_u32(specialBaseID)
return GetItemName(baseID + id)
end
-- Reads a monster name based on it's ID.
-- If ultimate is true, ultimate names will be used
local function GetMonsterName(index, ultimate)
ultimate = ultimate or false
if ultimate then
return _Read(4, index)
else
return _Read(2, index)
end
end
-- Reads a technique names based on the technique ID
local function GetTechniqueName(id)
return _Read(5, id)
end
-- Reads class names based on the class ID
local function GetClassName(id)
return _Read(8, id)
end
-- Reads photon blast names based on it's id
-- If shortName is true, only the first character
-- of the name will be read
local function GetPhotonBlastName(id, shortName)
shortName = shortName or false
if id < 0 then
return " "
end
local result = _Read(9, id)
if shortName == true then
result = string.sub(result, 1, 1)
end
return result
end
-- Reads the encoded srank name from the item data
local function GetSRankName(itemData)
if itemData == null then
return "Null"
end
if table.getn(itemData) < 12 then
return "Invalid length"
end
local result = ""
local temp = 0
for i=1,6,2 do
local n = bit.lshift(itemData[7 + i - 1], 8) + itemData[8 + i - 1]
n = n - 0x8000
temp = math.floor(n / 0x400) + 0x40
if temp > 0x40 and temp < 0x60 and i ~= 1 then
result = result .. string.char(temp)
end
n = n % 0x400
temp = math.floor(n / 0x20) + 0x40
if temp > 0x40 and temp < 0x60 then
result = result .. string.char(temp)
end
n = n % 0x20
temp = n + 0x40
if temp > 0x40 and temp < 0x60 then
result = result .. string.char(temp)
end
end
return result
end
-- Reads srank special name
local function GetSRankSpecialName(index)
-- adjust index to lua 1 based crap
index = index + 1
if index > table.getn(srankSpecial) then
return "Invalid special"
end
return srankSpecial[index]
end
-- Reads mag color name
local function GetMagColor(index)
-- adjust index to lua 1 based crap
index = index + 1
if index > table.getn(magColor) then
return "Not set"
end
return magColor[index]
end
return
{
Read = Read,
GetItemName = GetItemName,
GetSpecialName = GetSpecialName,
GetMonsterName = GetMonsterName,
GetTechniqueName = GetTechniqueName,
GetClassName = GetClassName,
GetPhotonBlastName = GetPhotonBlastName,
-- Not actually related to unitxt
GetSRankName = GetSRankName,
GetSRankSpecialName = GetSRankSpecialName,
GetMagColor = GetMagColor,
}