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
|
#include "Game/Actor/actPlayerCreateMgr.h"
#include <prim/seadRuntimeTypeInfo.h>
#include <prim/seadStringBuilder.h>
#include "Game/Actor/actPlayerCreateUtils.h"
#include "Game/Actor/actWeapon.h"
#include "Game/UI/uiPauseMenuDataMgr.h"
#include "KingSystem/ActorSystem/Profiles/actPlayerBase.h"
#include "KingSystem/ActorSystem/Profiles/actWeaponBase.h"
#include "KingSystem/ActorSystem/actActorConstDataAccess.h"
#include "KingSystem/ActorSystem/actActorCreator.h"
#include "KingSystem/ActorSystem/actActorHeapUtil.h"
#include "KingSystem/ActorSystem/actActorLinkConstDataAccess.h"
#include "KingSystem/ActorSystem/actInfoCommon.h"
#include "KingSystem/ActorSystem/actInfoData.h"
#include "KingSystem/ActorSystem/actInstParamPack.h"
#include "KingSystem/ActorSystem/actPlayerInfo.h"
#include "KingSystem/GameData/gdtCommonFlagsUtils.h"
namespace uking::act {
void PlayerCreateDebugStub::init() {
struct MsgStub {
sead::SafeString msg;
u64 unused{};
} stub{};
stub.msg = "読み込み中デバッグボード"; // Loading Debug Board
_0 = 3;
mDebugStatus = "◎読み込み中◎"; // Loading
_18 = 0.9;
_1c = 0;
mColor20 = {1.0f, 1.0f, 1.0f, 1.0f};
mColor30 = {0.2f, 0.2f, 0.2f, 1.0f};
_40.set(1.8, 0);
_48.set(198.638428, 34.742115);
mColor50 = {0.0f, 0.8f, 0.8f, 0.3f};
_60 = 0;
_68 = 0;
_70 = 0;
_78 = {-506.679992, -256.519989, 0};
mColor84 = {0.0f, 0.0f, 0.0f, 1.0f};
}
SEAD_SINGLETON_DISPOSER_IMPL(CreatePlayerEquipActorMgr)
CreatePlayerEquipActorMgr::CreatePlayerEquipActorMgr() {
mTracer.init("CreatePlayerEquipActorMgr");
}
CreatePlayerEquipActorMgr::~CreatePlayerEquipActorMgr() {
mTracer.finish();
}
void CreatePlayerEquipActorMgr::init() {
mDebugStub.init();
}
// NON_MATCHING single reorder
void CreatePlayerEquipActorMgr::postCalc() {
if (mIsLoading.isZero()) {
// nothing is loading
return;
}
auto* handle = &mProcHandles[0];
for (s32 i = 0; i < (s32)CreateEquipmentSlot::Length; ++i, ++handle) {
if (!isSlotLoading(i)) {
continue;
}
if (handle->hasProcCreationFailed()) {
handle->isProcCreationCancelled();
handle->deleteProc();
mEntries[i].reset();
mIsLoading.resetBit(i);
continue;
}
if (handle->isProcReady()) {
if (isArmorCreateEquipmentSlot(i)) {
auto* actor = sead::DynamicCast<ksys::act::Actor>(handle->releaseAndWakeProc());
mEntries[i].mProcLink.acquire(actor, false);
}
mEntries[i].mStatus = EntryStatus::Ready;
}
}
}
void CreatePlayerEquipActorMgr::resetAll() {
for (s32 i = 0; i < (s32)CreateEquipmentSlot::Length; ++i) {
reset(i);
}
mIsLoading.makeAllZero();
}
void CreatePlayerEquipActorMgr::reset(s32 slot_idx) {
auto& handle = mProcHandles[slot_idx];
if (handle.isAllocatedOrFailed()) {
handle.deleteProc();
}
mIsLoading.resetBit(slot_idx);
mEntries[slot_idx].reset();
}
bool CreatePlayerEquipActorMgr::areAllWeaponActorsReady() const {
if (mIsLoading.isZero()) {
return true;
}
auto* handle = &mProcHandles[0];
for (u32 i = 0; i < (u32)CreateEquipmentSlot::Length; ++i, ++handle) {
if (isSlotLoading((s32)i)) {
return false;
}
auto* weapon = sead::DynamicCast<ksys::act::WeaponBase>(handle->getProc());
if (weapon && !weapon->areExtraActorsReady()) {
return false;
}
}
return true;
}
bool CreatePlayerEquipActorMgr::isEquipmentProcReady(s32 slot_idx) const {
const auto& entry = mEntries[slot_idx];
if (entry.mStatus != EntryStatus::Ready) {
return false;
}
const auto& handle = mProcHandles[slot_idx];
if (handle.isAllocatedOrFailed()) {
return handle.isProcReady();
}
return false;
}
ksys::act::Actor* CreatePlayerEquipActorMgr::tryGetEquipmentActor(s32 slot_idx) {
if (mEntries[slot_idx].mStatus != EntryStatus::Ready) {
return nullptr;
}
auto& handle = mProcHandles[slot_idx];
if (handle.isAllocatedOrFailed()) {
if (handle.isProcReady()) {
auto* actor = sead::DynamicCast<ksys::act::Actor>(handle.releaseAndWakeProc());
mEntries[slot_idx].mProcLink.acquire(actor, false);
}
}
auto* actor =
sead::DynamicCast<ksys::act::Actor>(mEntries[slot_idx].mProcLink.getProc(nullptr, nullptr));
mEntries[slot_idx].reset();
return actor;
}
void CreatePlayerEquipActorMgr::requestCreateWeapon(s32 slot_idx, const sead::SafeString& name,
int value, const WeaponModifierInfo* modifier,
const sead::SafeString& caller) {
auto scope = mTracer.trace()->makeScope("requestCreateWeapon", caller, 1);
deleteLoadingProc(slot_idx);
auto* player = ksys::act::PlayerInfo::instance()->getPlayer();
sead::Matrix34f pos;
pos.makeT(player->getMtx().getTranslation());
requestCreateWeaponByRawLife(name.cstr(), pos, 1.0,
ksys::act::ActorHeapUtil::instance()->getBaseProcHeap(),
&mProcHandles[slot_idx], value, false, modifier, 2, 2);
onSlotLoadingRequested(slot_idx, name);
}
void CreatePlayerEquipActorMgr::requestCreateWeapon(const sead::SafeString& name, int value,
const WeaponModifierInfo* modifier,
const sead::SafeString& caller) {
auto scope = mTracer.trace()->makeScope("requestCreateWeapon", caller, 1);
auto* info_data = ksys::act::InfoData::instance();
if (!info_data) {
return;
}
const char* profile_raw;
if (!info_data->getActorProfile(&profile_raw, name.cstr())) {
return;
}
sead::SafeString profile = profile_raw;
auto slot = CreateEquipmentSlot::WeaponSword;
if (profile == "WeaponBow") {
slot = CreateEquipmentSlot::WeaponBow;
} else if (profile == "WeaponShield") {
slot = CreateEquipmentSlot::WeaponShield;
}
requestCreateWeapon((s32)slot, name, value, modifier, caller);
}
// TODO: initialized in sInitArmorStrings (0x7100E2D0F0)
// find a better place to put these
// NOLINTNEXTLINE(misc-use-internal-linkage) doesn't match with static
sead::SafeString ArmorDyeColor; // "ArmorDyeColor"
// NOLINTNEXTLINE(misc-use-internal-linkage) doesn't match with static
sead::SafeString EnableDynamicColorChange; // "EnableDynamicColorChange"
void CreatePlayerEquipActorMgr::requestCreateArmor(s32 slot_idx, const sead::SafeString& name,
int dye_color, const sead::SafeString& caller) {
auto scope = mTracer.trace()->makeScope("requestCreateArmor", caller, 1);
deleteLoadingProc(slot_idx);
ksys::act::InstParamPack params;
bool is_dye = ksys::act::InfoData::instance()->hasTag(name.cstr(), ksys::act::tags::ArmorDye);
if (is_dye) {
params->add(dye_color, ArmorDyeColor);
if (ksys::gdt::getFlag_ColorChange_EnablePreview()) {
params->add(true, EnableDynamicColorChange);
}
}
{
ksys::act::ActorConstDataAccess access;
ksys::act::acquireActor(&ksys::act::PlayerInfo::instance()->getPlayerLink(), &access);
sead::Vector3f pos;
access.getActorMtx().getTranslation(pos);
params->addPosition(pos);
params->addResourceLane(2);
ksys::act::ActorCreator::instance()->requestCreateActor(
name.cstr(), ksys::act::ActorHeapUtil::instance()->getBaseProcHeap(),
&mProcHandles[slot_idx], ¶ms, nullptr, 2);
}
onSlotLoadingRequested(slot_idx, name);
}
void CreatePlayerEquipActorMgr::requestCreateArmor(const sead::SafeString& name, int dye_color,
const sead::SafeString& caller) {
auto scope = mTracer.trace()->makeScope("requestCreateArmor", caller, 1);
auto* info_data = ksys::act::InfoData::instance();
if (!info_data) {
return;
}
const char* profile_raw;
if (!info_data->getActorProfile(&profile_raw, name.cstr())) {
return;
}
sead::SafeString profile = profile_raw;
auto slot = CreateEquipmentSlot::ArmorHead;
if (profile == "Armor_Upper") {
slot = CreateEquipmentSlot::ArmorUpper;
} else if (profile == "Armor_Lower") {
slot = CreateEquipmentSlot::ArmorLower;
}
requestCreateArmor((s32)slot, name, dye_color, caller);
}
void CreatePlayerEquipActorMgr::requestCreateDefaultArmor(s32 slot,
const sead::SafeString& caller) {
switch (slot) {
case (s32)CreateEquipmentSlot::ArmorHead:
requestCreateArmor(slot, "Armor_Default_Head", -1, caller);
break;
case (s32)CreateEquipmentSlot::ArmorUpper:
requestCreateArmor(slot, "Armor_Default_Upper", -1, caller);
break;
case (s32)CreateEquipmentSlot::ArmorLower:
requestCreateArmor(slot, "Armor_Default_Lower", -1, caller);
break;
default:
break;
}
}
void CreatePlayerEquipActorMgr::requestCreateArmorHeadB(const sead::SafeString& name, int dye_color,
const sead::SafeString& caller) {
sead::FixedStringBuilder<0x40> s;
s.copy(name.cstr());
s.append("_B", -1);
requestCreateArmor((s32)CreateEquipmentSlot::ArmorHead, s, dye_color, caller);
}
bool CreatePlayerEquipActorMgr::isSlotLoading(s32 slot_idx) const {
return mIsLoading.isOnBit(slot_idx) && mEntries[slot_idx].mStatus == EntryStatus::Loading;
}
void CreatePlayerEquipActorMgr::deleteLoadingProc(s32 slot_idx) {
if (mIsLoading.isOnBit(slot_idx)) {
mProcHandles[slot_idx].deleteProc();
}
}
void CreatePlayerEquipActorMgr::onSlotLoadingRequested(s32 slot_idx, const sead::SafeString& name) {
if (mProcHandles[slot_idx].isAllocatedOrFailed()) {
auto& entry = mEntries[slot_idx];
entry.mActorName.copy(name.cstr());
mIsLoading.setBit(slot_idx);
entry.mStatus = EntryStatus::Loading;
}
}
bool needsArmorHeadB(const sead::SafeString& armor_head_name,
const sead::SafeString& armor_upper_name) {
if (armor_upper_name.isEmpty()) {
return false;
}
return isArmorHeadMantleType2(armor_head_name) &&
isArmorUpperNotUseMantleType0(armor_upper_name);
}
bool isArmorHeadMantleType2(const sead::SafeString& armor_head_name) {
if (!ksys::act::InfoData::instance()) {
return false;
}
return ksys::act::getArmorHeadMantleType(ksys::act::InfoData::instance(),
armor_head_name.cstr()) == 2;
}
bool isArmorUpperNotUseMantleType0(const sead::SafeString& armor_upper_name) {
if (!ksys::act::InfoData::instance()) {
return false;
}
return ksys::act::getArmorUpperUseMantleType(ksys::act::InfoData::instance(),
armor_upper_name.cstr()) != 0;
}
} // namespace uking::act
|