-
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathSpawner.Hook.cpp
More file actions
300 lines (240 loc) · 7.81 KB
/
Spawner.Hook.cpp
File metadata and controls
300 lines (240 loc) · 7.81 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
/**
* yrpp-spawner
*
* Copyright(C) 2022-present CnCNet
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "Spawner.h"
#include "NetHack.h"
#include <HouseClass.h>
#include <SessionClass.h>
#include <BeaconManagerClass.h>
#include <Utilities/Debug.h>
#include <Utilities/Macro.h>
#include <Unsorted.h>
#include <CCINIClass.h>
DEFINE_HOOK(0x6BD7C5, WinMain_SpawnerInit, 0x6)
{
if (Spawner::Enabled)
{
Spawner::Init();
Patch::Apply_CALL(0x48CDD3, Spawner::StartGame); // Main_Game
Patch::Apply_CALL(0x48CFAA, Spawner::StartGame); // Main_Game
{ // HousesStuff
Patch::Apply_CALL(0x68745E, Spawner::AssignHouses); // Read_Scenario_INI
Patch::Apply_CALL(0x68ACFF, Spawner::AssignHouses); // ScenarioClass::Read_INI
Patch::Apply_LJMP(0x5D74A0, 0x5D7570); // MPGameModeClass_AllyTeams
Patch::Apply_LJMP(0x501721, 0x501736); // HouseClass_ComputerParanoid
//Patch::Apply_LJMP(0x686A9E, 0x686AC6); // ReadScenario_InitSomeThings - Moved to a hook to allow conditional toggling of Special house's alliances.
}
{ // NetHack
Patch::Apply_CALL(0x7B3D75, NetHack::SendTo); // UDPInterfaceClass::Message_Handler
Patch::Apply_CALL(0x7B3EEC, NetHack::RecvFrom); // UDPInterfaceClass::Message_Handler
}
{ // Skip Intro, EA_WWLOGO and LoadScreen
Patch::Apply_LJMP(0x52CB50, 0x52CB6E); // InitIntro_Skip
Patch::Apply_LJMP(0x52C5E0, 0x52C5F8); // InitGame_SkipLogoAndLoadScreen
}
{ // Cooperative
Patch::Apply_LJMP(0x553321, 0x5533C5); // LoadProgressMgr_Draw_CooperativeDescription
Patch::Apply_LJMP(0x55D0DF, 0x55D0E8); // AuxLoop_Cooperative_EndgameCrashFix
}
// Set ConnTimeout
Patch::Apply_TYPED<int>(0x6843C7, { Spawner::GetConfig()->ConnTimeout }); // Scenario_Load_Wait
// Show GameMode in DiplomacyDialog in Skirmish
Patch::Apply_LJMP(0x658117, 0x658126); // RadarClass_DiplomacyDialog
// Leaves bottom bar closed for losing players during last game frames
Patch::Apply_LJMP(0x6D1639, 0x6D1640); // TabClass_6D1610
// Skip load *.PKT, *.YRO and *.YRM map files
Patch::Apply_LJMP(0x699AD9, 0x69A1B2); // SessionClass::Read_Scenario_Descriptions
if (Spawner::GetConfig()->DisableSaveLoad)
{
Patch::Apply_LJMP(0x55DBCD, 0x55DC99); // Disable MainLoop_SaveGame (Spawner&Phobos)
Patch::Apply_RAW(0x67CEF0, { 0x33,0xC0,0xC3 }); // Corrupt savegame function
Patch::Apply_TYPED(0x83D560, { (DWORD)std::rand() }); // Corrupt save game magicn
}
}
return 0;
}
// Display UIGameMode if is set
// Otherwise use mode name from MPModesMD.ini
DEFINE_HOOK(0x65812E, RadarClass__DiplomacyDialog_UIGameMode, 0x6)
{
enum { Show = 0x65813E, DontShow = 0x65814D };
if (Spawner::Enabled && Spawner::GetConfig()->UIGameMode[0])
{
R->EBX(R->EAX());
R->EAX(Spawner::GetConfig()->UIGameMode);
return Show;
}
if (!SessionClass::Instance.MPGameMode)
return DontShow;
return 0;
}
// Clear UIGameMode on game load
DEFINE_HOOK(0x689669, ScenarioClass_Load_Suffix, 0x6)
{
if (Spawner::Enabled)
Spawner::GetConfig()->UIGameMode[0] = 0;
return 0;
}
#pragma region MPlayerDefeated
namespace MPlayerDefeated
{
HouseClass* pThis = nullptr;
}
DEFINE_HOOK(0x4FC0B6, HouseClass__MPlayerDefeated_SaveArgument, 0x5)
{
MPlayerDefeated::pThis = (Spawner::Enabled && !SessionClass::IsCampaign())
? R->ECX<HouseClass*>()
: nullptr;
return 0;
}
// Skip match-end logic if MPlayerDefeated called for observer
DEFINE_HOOK_AGAIN(0x4FC332, HouseClass__MPlayerDefeated_SkipObserver, 0x5)
DEFINE_HOOK(0x4FC262, HouseClass__MPlayerDefeated_SkipObserver, 0x6)
{
enum { ProcEpilogue = 0x4FC6BC };
if (!MPlayerDefeated::pThis)
return 0;
return MPlayerDefeated::pThis->IsInitiallyObserver()
? ProcEpilogue
: 0;
}
DEFINE_HOOK(0x4FC551, HouseClass__MPlayerDefeated_NoEnemies, 0x5)
{
enum { ProcEpilogue = 0x4FC6BC };
if (!MPlayerDefeated::pThis)
return 0;
for (const auto pHouse : HouseClass::Array)
{
if (pHouse->Defeated || pHouse == MPlayerDefeated::pThis || pHouse->Type->MultiplayPassive)
continue;
if ((pHouse->IsHumanPlayer || Spawner::GetConfig()->ContinueWithoutHumans) && pHouse->IsMutualAlly(MPlayerDefeated::pThis))
{
Debug::Log("MPlayer_Defeated() - Defeated player has a living ally");
if (Spawner::GetConfig()->DefeatedBecomesObserver)
MPlayerDefeated::pThis->MakeObserver();
return ProcEpilogue;
}
}
return 0;
}
DEFINE_HOOK(0x4FC57C, HouseClass__MPlayerDefeated_CheckAliveAndHumans, 0x7)
{
enum { ProcEpilogue = 0x4FC6BC, FinishMatch = 0x4FC591 };
if (!MPlayerDefeated::pThis)
return 0;
GET_STACK(int, numHumans, STACK_OFFSET(0xC0, -0xA8));
GET_STACK(int, numAlive, STACK_OFFSET(0xC0, -0xAC));
bool continueWithoutHumans = Spawner::GetConfig()->ContinueWithoutHumans
|| MPlayerDefeated::pThis->IsInitiallyObserver();
if (!continueWithoutHumans && !MPlayerDefeated::pThis->IsHumanPlayer)
{
bool isHasAliveHumanPlayers = false;
for (const auto pHouse : HouseClass::Array)
{
if (pHouse->IsHumanPlayer && !pHouse->Defeated)
{
isHasAliveHumanPlayers = true;
break;
}
}
if (!isHasAliveHumanPlayers)
continueWithoutHumans = true;
}
if (numAlive > 1 && (numHumans != 0 || continueWithoutHumans))
{
if (Spawner::GetConfig()->DefeatedBecomesObserver)
MPlayerDefeated::pThis->MakeObserver();
return ProcEpilogue;
}
return FinishMatch;
}
#pragma endregion MPlayerDefeated
#pragma region Save&Load
DEFINE_HOOK_AGAIN(0x624271, SomeFunc_InterceptMainLoop, 0x5);
DEFINE_HOOK_AGAIN(0x623D72, SomeFunc_InterceptMainLoop, 0x5);
DEFINE_HOOK_AGAIN(0x62314E, SomeFunc_InterceptMainLoop, 0x5);
DEFINE_HOOK_AGAIN(0x60D407, SomeFunc_InterceptMainLoop, 0x5);
DEFINE_HOOK_AGAIN(0x608206, SomeFunc_InterceptMainLoop, 0x5);
DEFINE_HOOK(0x48CE8A, SomeFunc_InterceptMainLoop, 0x5)
{
/**
* Main loop.
*/
Game::MainLoop();
/**
* After loop.
*/
Spawner::After_Main_Loop();
return R->Origin() + 0x5;
}
DEFINE_HOOK(0x52DAEF, Game_Start_ResetGlobal, 0x5)
{
Spawner::DoSave = false;
Spawner::NextAutoSaveFrame = -1;
Spawner::NextAutoSaveNumber = 0;
return 0;
}
DEFINE_HOOK(0x686B20, INIClass_ReadScenario_AutoSave, 0x6)
{
/**
* Schedule the next autosave.
*/
Spawner::NextAutoSaveFrame = Unsorted::CurrentFrame;
Spawner::NextAutoSaveFrame += Spawner::GetConfig()->AutoSaveInterval;
return 0;
}
// Do not change the address without adjusting Phobos handling
// and reading the comments in Spawner::After_Main_Loop
DEFINE_HOOK(0x4C7A14, EventClass_RespondToEvent_SaveGame, 0x5)
{
Spawner::RespondToSaveGame();
return 0x4C7B42;
}
// for some reason beacons are only inited on scenario init, which doesn't happen on load
DEFINE_HOOK(0x67E6DA, LoadGame_AfterInit, 0x6)
{
BeaconManagerClass::Instance.LoadArt();
return 0;
}
#pragma endregion
DEFINE_HOOK(0x686A9E, ReadScenario_InitSomeThings_SpecialHouseIsAlly, 0x6)
{
if (Spawner::GetConfig()->SpecialHouseIsAlly)
return 0;
return 0x686AC6;
}
DEFINE_HOOK(0x686D46, ReadScenarioINI_MissionININame, 0x5)
{
LEA_STACK(CCFileClass*, pFile, STACK_OFFSET(0x174, -0xF0));
if (Spawner::GetConfig()->ReadMissionSection)
{
pFile->SetFileName("SPAWN.INI");
return 0x686D57;
}
return 0;
}
DEFINE_HOOK(0x65F57F, BriefingDialog_MissionININame, 0x6)
{
LEA_STACK(CCFileClass*, pFile, STACK_OFFSET(0x1D4, -0x16C));
if (Spawner::GetConfig()->ReadMissionSection)
{
pFile->SetFileName("SPAWN.INI");
return 0x65F58F;
}
return 0;
}