-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameMode.cpp
More file actions
366 lines (279 loc) · 13.1 KB
/
Copy pathGameMode.cpp
File metadata and controls
366 lines (279 loc) · 13.1 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
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
#include "GameMode.h"
#include "Inventory.h"
#include "Looting.h"
#include "Events.h"
#include "GameSessions.h"
bool GameMode::ReadyToStartMatchHook(AFortGameModeAthena* GameMode)
{
AFortGameStateAthena* GameState = (AFortGameStateAthena*)GameMode->GameState;
//std::cout << "ReadyToStartMatch" << std::endl;
static bool bPlaylist = false;
if (!bPlaylist)
{
static UFortPlaylistAthena* Playlist = UObject::FindObject<UFortPlaylistAthena>("FortPlaylistAthena Playlist_DefaultSolo.Playlist_DefaultSolo");
GameState->CurrentPlaylistInfo.BasePlaylist = Playlist;
GameState->CurrentPlaylistInfo.OverridePlaylist = Playlist;
GameState->CurrentPlaylistInfo.PlaylistReplicationKey++;
GameState->CurrentPlaylistInfo.MarkArrayDirty();
GameState->CurrentPlaylistId = Playlist->PlaylistId;
GameMode->CurrentPlaylistId = Playlist->PlaylistId;
GameMode->CurrentPlaylistName = Playlist->PlaylistName;
GameState->AirCraftBehavior = Playlist->AirCraftBehavior;
GameState->CachedSafeZoneStartUp = Playlist->SafeZoneStartUp;
float TimeSeconds = UGameplayStatics::GetTimeSeconds(GetWorld());
float Duration = 120.f;
GameState->bGameModeWillSkipAircraft = Playlist->bSkipAircraft;
GameMode->bSpawnAllStuff = true;
if (bGameSessionsEnabled) {
if (GameMode->GameSession) {
std::cout << "GameSessionClass: " << GameMode->GameSession->Class << std::endl;
}
else {
std::cout << "EnableGameSession" << std::endl;
TArray<AActor*> Actors;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), AFortGameSessionDedicatedAthena::StaticClass(), &Actors);
GameMode->GameSession = Actors[0]->IsDefaultObject() ? (AFortGameSessionDedicatedAthena*)Actors[1] : (AFortGameSessionDedicatedAthena*)Actors[0];
}
}
GameState->WarmupCountdownEndTime = TimeSeconds + Duration;
GameMode->WarmupCountdownDuration = Duration;
GameState->WarmupCountdownStartTime = TimeSeconds;
GameMode->WarmupEarlyCountdownDuration = Duration;
if (Playlist->bIsDefaultPlaylist) {
GameMode->ServerBotManager = (UFortServerBotManagerAthena*)UGameplayStatics::SpawnObject(UFortServerBotManagerAthena::StaticClass(), GameMode);
GameMode->ServerBotManagerClass = UFortServerBotManagerAthena::StaticClass();
GameMode->ServerBotManager->CachedGameMode = GameMode;
GameMode->ServerBotManager->CachedGameState = GameState;
GameMode->AIDirector = SpawnActor<AFortAIDirector>();
if (GameMode->AIDirector) {
GameMode->AIDirector->Activate();
}
GameMode->AIGoalManager = SpawnActor<AFortAIGoalManager>();
}
if (Playlist->AISettings) {
GameMode->AISettings = Playlist->AISettings;
auto System = (UAthenaAISystem*)GetWorld()->AISystem;
if (!System->BotManager) {
System->BotManager = (UFortBotMissionManager*)UGameplayStatics::SpawnObject(UFortBotMissionManager::StaticClass(), System);
}
else {
std::cout << System->BotManager->GetName() << std::endl;
}
if (!GameMode->AIDirector) {
GameMode->AIDirector = SpawnActor<AFortAIDirector>();
GameMode->AIDirector->Activate();
}
else {
std::cout << GameMode->AIDirector->GetName() << std::endl;
}
std::cout << System->RegisteredAISpawners.Num() << std::endl;
for (int i = 0; i < System->RegisteredAISpawners.Num();i++) {
AActor* Spawner = System->RegisteredAISpawners[i];
std::cout << "Spawner: " << Spawner->Class->GetName() << std::endl;
}
}
bPlaylist = true;
}
if (!bCreative) {
static bool bPlayerStartLcsLoaded = false;
if (!bPlayerStartLcsLoaded) {
TArray<AActor*> Actors;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), AFortPlayerStartWarmup::StaticClass(), &Actors);
int Num = Actors.Num();
Actors.Free();
if (Num == 0) {
return false;
}
bPlayerStartLcsLoaded = true;
}
}
if (!GameState->MapInfo) return false;
if (GameState->Teams.Num() == 0) return false;
static bool bListening = false;
if (!bListening) {
FName GameNetDriver = UKismetStringLibrary::Conv_StringToName(TEXT("GameNetDriver"));
UNetDriver* (*CreateNetDriver)(UEngine*, UWorld*, FName) = decltype(CreateNetDriver)(ImageBase + 0x4573990);
UNetDriver* Driver = CreateNetDriver(GEngine, GetWorld(), GameNetDriver);
Driver->World = GetWorld();
Driver->NetDriverName = GameNetDriver;
FString Error;
FURL URL;
URL.Port = 7777;
bool (*InitListen)(UNetDriver*, UWorld*, FURL&, bool, FString&) = decltype(InitListen)(ImageBase + 0xD44C40);
void (*SetWorld)(UNetDriver*, UWorld*) = decltype(SetWorld)(ImageBase + 0x42C2B20);
GameState->OnRep_CurrentPlaylistInfo();
InitListen(Driver, GetWorld(), URL, false, Error);
SetWorld(Driver, GetWorld());
GetWorld()->NetDriver = Driver;
for (int i = 0; i < GetWorld()->LevelCollections.Num(); i++)
{
GetWorld()->LevelCollections[i].NetDriver = Driver;
}
GameMode->bWorldIsReady = true;
for (int i = 0; i < CurrentPlaylist()->AdditionalLevels.Num(); i++) {
TSoftObjectPtr<UWorld> World = CurrentPlaylist()->AdditionalLevels[i];
FString LevelName = UKismetStringLibrary::Conv_NameToString(World.ObjectID.AssetPathName);
ULevelStreamingDynamic::LoadLevelInstance(GetWorld(), LevelName, {}, {}, nullptr, FString());
FAdditionalLevelStreamed NewLevel{ World.ObjectID.AssetPathName,false };
GameState->AdditionalPlaylistLevelsStreamed.Add(NewLevel);
}
for (int i = 0; i < CurrentPlaylist()->AdditionalLevelsServerOnly.Num(); i++) {
TSoftObjectPtr<UWorld> World = CurrentPlaylist()->AdditionalLevelsServerOnly[i];
FString LevelName = UKismetStringLibrary::Conv_NameToString(World.ObjectID.AssetPathName);
ULevelStreamingDynamic::LoadLevelInstance(GetWorld(), LevelName, {}, {}, nullptr, FString());
FAdditionalLevelStreamed NewLevel{ World.ObjectID.AssetPathName,true };
GameState->AdditionalPlaylistLevelsStreamed.Add(NewLevel);
}
GameState->OnFinishedShowingAdditionalPlaylistLevel();
GameState->OnRep_AdditionalPlaylistLevelsStreamed();
GameMode->HandleAllPlaylistLevelsVisible();
GameState->OnRep_CurrentPlaylistId();
SetConsoleTitleA("Listening");
JerkyLoader::GetAllJerkyObjects();
TArray<AActor*> WarmupActors;
static UClass* WarmupClass = StaticLoadObject<UClass>("/Game/Athena/Environments/Blueprints/Tiered_Athena_FloorLoot_Warmup.Tiered_Athena_FloorLoot_Warmup_C");
UGameplayStatics::GetAllActorsOfClass(GetWorld(), WarmupClass, &WarmupActors);
for (int i = 0; i < WarmupActors.Num(); i++) {
auto Container = (ABuildingContainer*)WarmupActors[i];
auto Entrys = GetItems(Container->SearchLootTierGroup);
Container->K2_GetActorLocation().Z + 50;
for (auto& item : Entrys) {
Inventory::SpawnPickup(item.ItemDefinition, Container->K2_GetActorLocation(), item.Count, EFortPickupSourceTypeFlag::FloorLoot, EFortPickupSpawnSource::Unset);
UFortWeaponRangedItemDefinition* Item = (UFortWeaponRangedItemDefinition*)item.ItemDefinition;
if (Item->IsA(UFortWeaponRangedItemDefinition::StaticClass()) && Item->GetAmmoWorldItemDefinition_BP() && Item->AmmoData.Get() != Item) {
auto AmmoDef = Item->GetAmmoWorldItemDefinition_BP();
Inventory::SpawnPickup(AmmoDef, Container->K2_GetActorLocation(), AmmoDef->DropCount, EFortPickupSourceTypeFlag::Container, EFortPickupSpawnSource::Unset);
}
}
Container->K2_DestroyActor();
}
WarmupActors.Free();
TArray<AActor*> FloorLootActors;
static UClass* FloorlootClass = StaticLoadObject<UClass>("/Game/Athena/Environments/Blueprints/Tiered_Athena_FloorLoot_01.Tiered_Athena_FloorLoot_01_C");
UGameplayStatics::GetAllActorsOfClass(GetWorld(), FloorlootClass, &FloorLootActors);
for (int i = 0; i < FloorLootActors.Num(); i++) {
auto Container = (ABuildingContainer*)FloorLootActors[i];
auto Entrys = GetItems(Container->SearchLootTierGroup);
FVector Container2 = Container->K2_GetActorLocation() + FVector(0,0,50);
for (auto& item : Entrys) {
Inventory::SpawnPickup(item.ItemDefinition, Container2, item.Count, EFortPickupSourceTypeFlag::FloorLoot, EFortPickupSpawnSource::Unset);
UFortWeaponRangedItemDefinition* Item = (UFortWeaponRangedItemDefinition*)item.ItemDefinition;
if (Item->IsA(UFortWeaponRangedItemDefinition::StaticClass()) && Item->GetAmmoWorldItemDefinition_BP() && Item->AmmoData.Get() != Item) {
auto AmmoDef = Item->GetAmmoWorldItemDefinition_BP();
Inventory::SpawnPickup(AmmoDef, Container2, AmmoDef->DropCount, EFortPickupSourceTypeFlag::Container, EFortPickupSpawnSource::Unset);
}
}
Container->K2_DestroyActor();
}
FloorLootActors.Free();
TArray<AActor*> Actors;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), AFortAthenaMutator_Bots::StaticClass(), &Actors);
for (AActor* Actor : Actors) {
static bool bFirst = false;
if (!bFirst) {
GameMode->ServerBotManager->CachedBotMutator = ((AFortAthenaMutator_Bots*)Actor);
bFirst = true;
}
}
*reinterpret_cast<bool*>(__int64(GameMode->ServerBotManager) + 0x4D0) = 1;
//*reinterpret_cast<int*>(__int64(GameMode->ServerBotManager->CachedBotMutator) + 0x430) = 1;
bListening = true;
}
bool bRet = GameMode->AlivePlayers.Num() > 0;
if (!bRet) {
float TimeSeconds = UGameplayStatics::GetTimeSeconds(GetWorld());
float Duration = 180.f;
GameState->WarmupCountdownEndTime = TimeSeconds + Duration;
GameMode->WarmupCountdownDuration = Duration;
GameState->WarmupCountdownStartTime = TimeSeconds;
GameMode->WarmupEarlyCountdownDuration = Duration;
}
return bRet;
}
inline void CreatePair(std::vector<std::pair<UFortItemDefinition*, int>> Vector, UFortItemDefinition* Def, int Count) {
std::pair<UFortItemDefinition*, int> Pair;
Pair.first = Def;
Pair.second = Count;
Vector.push_back(Pair);
}
APawn* GameMode::SpawnDefaultPawnFor(AFortGameModeAthena* GameMode, AFortPlayerControllerAthena* NewPlayer, AActor* StartSpot)
{
auto GameState = (AFortGameStateAthena*)GameMode->GameState;
for (int i = 0; i < GameMode->StartingItems.Num(); i++) {
FItemAndCount Item = GameMode->StartingItems[i];
Inventory::GiveWorldItem(NewPlayer, Item.Item, Item.Count, 0);
}
Inventory::GiveWorldItem(NewPlayer, NewPlayer->CosmeticLoadoutPC.Pickaxe->WeaponDefinition, 1, 0);
auto Pawn = (AFortPlayerPawnAthena*)GameMode->SpawnDefaultPawnAtTransform(NewPlayer, StartSpot->GetTransform());
UFortQuestManager* QuestManager = NewPlayer->GetQuestManager(GameMode->AssociatedSubGame);
QuestManager->EnableQuestStateLogging();
return Pawn;
}
//GD I Wasn't using this for a reason, it crashes on hooking
inline EFortTeam GetNextEmptyTeam(int MaxTeamCount, int MaxSquadSize) {
auto GameState = (AFortGameStateAthena*)GetWorld()->GameState;
if (GameState) {
auto Teams = GameState->Teams;
for (int i = 3; i < Teams.Num(); i++) {
auto Team = Teams[i];
if (!Team.IsValid()) continue;
if (Team.Num() <= MaxSquadSize && i <= (MaxTeamCount + 3)) return EFortTeam(i);
}
}
return EFortTeam::Spectator;
}
inline EFortTeam GetLowestTeam(int MaxTeamCount, int MaxSquadSize) {
auto GameState = (AFortGameStateAthena*)GetWorld()->GameState;
std::pair<int, int> LowestTeam = { 0,0 }; //TeamIndex,Num
if (GameState) {
auto Teams = GameState->Teams;
for (int i = 3; i < Teams.Num(); i++) {
auto Team = Teams[i];
if (!Team.IsValid()) continue;
if (Team.Num() < MaxSquadSize && i <= (MaxTeamCount + 3) && Team.Num() <= LowestTeam.second) {
LowestTeam = { i,Team.Num() };
}
}
return EFortTeam(LowestTeam.first);
}
return EFortTeam::Spectator;
}
EFortTeam GameMode::PickTeamHook(AFortGameModeAthena* GameMode, uint8_t Preferred, AFortPlayerControllerAthena* PC) {
if (!GameMode || !PC) return EFortTeam::Spectator;
UFortPlaylistAthena* Playlist = CurrentPlaylist();
bool bSpreadTeams = (Playlist->bShouldSpreadTeams || Playlist->bIsLargeTeamGame);
int MaxTeamCount = Playlist->MaxTeamCount;
int MaxSquadSize = Playlist->MaxSquadSize;
EFortTeam Ret = (bSpreadTeams ? (GetLowestTeam(MaxTeamCount, MaxSquadSize)) : (GetNextEmptyTeam(MaxTeamCount, MaxSquadSize)));
/*
if (PC->PlayerState) {
AFortPlayerStateAthena* PlayerState = (AFortPlayerStateAthena*)PC->PlayerState;
PlayerState->SquadId = ((int)Ret - 3);
if (GameMode->GameState) {
AFortGameStateAthena* GameState = (AFortGameStateAthena*)GameMode->GameState;
TWeakObjectPtr<AFortPlayerStateAthena> WeakPlayerState{ PlayerState->Index, UObject::GObjects->GetSNByIndex(PlayerState->Index) };
GameState->Teams[(int)Ret].Add(WeakPlayerState);
GameState->Squads[PlayerState->SquadId].Add(WeakPlayerState);
FGameMemberInfo MemberInfo{ -1,-1,-1 ,PlayerState->SquadId,(int)Ret,0,0,PlayerState->UniqueId};
GameState->GameMemberInfoArray.Members.Add(MemberInfo);
GameState->GameMemberInfoArray.MarkArrayDirty();
}
}
*/
return Ret;
}
void GameMode::OnAircraftEnteredDropZone(AFortGameModeAthena* GM, AFortAthenaAircraft* Aircraft) {
auto GameState = (AFortGameStateAthena*)GM->GameState;
if (bLateGame) {
static FVector AircraftLocation = ZoneLoc + FVector(0, 0, 10000);
Aircraft->FlightEndTime = 100.f;
Aircraft->FlightInfo.FlightSpeed = 1.0f;
Aircraft->FlightInfo.FlightStartLocation = (FVector_NetQuantize100)AircraftLocation;
Aircraft->FlightEndTime = 0.f;
GameState->OnRep_Aircraft();
GameState->GamePhase = EAthenaGamePhase::SafeZones;
GameState->OnRep_GamePhase(EAthenaGamePhase::Aircraft);
GameState->SafeZonesStartTime = 1;
}
return OnAircraftEnteredDropZone_OG(GM, Aircraft);
}