-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathHook_Main_Loop.c
146 lines (115 loc) · 4.46 KB
/
Hook_Main_Loop.c
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
#include <stdbool.h>
#include "macros/patch.h"
#include "TiberianSun.h"
#include "Classes/EventClass.h"
#include "patch.h"
#define MAX_SP_AUTOSAVES 5
CALL(0x005091A5, _MainLoop_AfterRender);
CALL(0x00509388, _MainLoop_PreRemoveAllInactive);
bool HaventSetSpecTeam = true;
bool IsDoingMPSaveNextFrame = false;
bool IsSavingThisFrame = false;
int32_t PlayerEventCounts[8];
int32_t PlayerEventExecs[8];
int32_t PlayerEventLastFrame[8];
int32_t AutoSaveGame;
int32_t NextAutoSave;
int32_t NextSPAutoSaveId = 0;
int32_t ResponseTimeFrame = 0;
int32_t ResponseTimeInterval = 4;
int32_t NextAutoSS = 0;
int32_t AutoSSInterval = 4;
int32_t AutoSSGrowth = 4;
int32_t AutoSSIntervalMax = 30;
char AutoSaveNameBuf[256];
char AutoSaveDescrBuf[256];
void __thiscall
MainLoop_AfterRender(MessageListClass *msg) {
MessageListClass__Manage(msg);
if (SpawnerActive) {
if (SessionClass_this.GameSession != 0) { // GAME_CAMPAIGN
if (PlayerPtr->Defeated == true && HaventSetSpecTeam) {
set_team_spec();
HaventSetSpecTeam = false;
}
if (IntegrateMumbleSun && IntegrateMumbleSpawn) {
updateMumble();
}
if (IsHost &&
SessionClass_this.GameSession != 5 && // disable for GAME_SKIRMISH
AutoSaveGame > 0 && Frame >= NextAutoSave)
{
NextAutoSave = Frame + AutoSaveGame;
EventClass e;
EventClass__EventClass_noarg(&e, PlayerPtr->ID, EVENTTYPE_SAVEGAME);
EventClass__EnqueueEvent(&e);
}
if (UseProtocolZero && Frame >= ResponseTimeFrame)
{
ResponseTimeFrame = Frame + ResponseTimeInterval;
Send_Response_Time();
}
if (RunAutoSS && SessionClass_this.GameSession == 3 && Frame > NextAutoSS)
{
DoingAutoSS = 1;
ScreenCaptureCommandClass_Execute();
DoingAutoSS = 0;
NextAutoSS = Frame + AutoSSInterval * 60; //60fps
if (AutoSSInterval < AutoSSIntervalMax)
AutoSSInterval += AutoSSGrowth;
}
}
}
}
void __fastcall MainLoop_PreRemoveAllInactive() {
Remove_All_Inactive();
if (SpawnerActive) {
if (SessionClass_this.GameSession == 0) { // GAME_CAMPAIGN
// Auto-save for singleplayer missions
if (AutoSaveGame > 0) {
// Print message on earlier frame so it gets rendered before
// the save process starts
if (Frame == NextAutoSave) {
MessageListClass__Add_Message(&MessageListClass_this, 0, 0,
"Auto-saving...",
4, 0x4046,
(int)(Rules->MessageDuration * FramesPerMinute)/2);
}
if (Frame > NextAutoSave) {
Pause_Scenario_Timer();
Call_Back();
NextAutoSave = Frame + AutoSaveGame;
NextSPAutoSaveId++;
if (NextSPAutoSaveId > MAX_SP_AUTOSAVES)
NextSPAutoSaveId = 1;
int sprintf_result = sprintf(AutoSaveNameBuf, "AUTOSAVE%d.SAV", NextSPAutoSaveId);
int sprintf_result2 = sprintf(AutoSaveDescrBuf, "Mission Auto-Save (Slot %d)", NextSPAutoSaveId);
if (sprintf_result > 0 && sprintf_result2 > 0) {
Save_Game(AutoSaveNameBuf, AutoSaveDescrBuf, false);
}
Resume_Scenario_Timer();
}
}
} else if (SessionClass_this.GameSession == 3) {
// Auto-save for multiplayer
// We do it by ourselves here instead of letting original Westwood code save when
// the event is executed, because saving mid-frame before Remove_All_Inactive()
// has been called can lead to save corruption
// In other words, by doing it here we fix a Westwood bug/oversight
if (IsSavingThisFrame) {
Save_Game("SAVEGAME.NET", "Multiplayer Game", false);
IsSavingThisFrame = false;
}
// Print message on earlier frame so it gets rendered before
// the save process starts
if (IsDoingMPSaveNextFrame) {
MessageListClass__Add_Message(&MessageListClass_this, 0, 0,
"Saving game...",
4, 0x4046,
(int)(Rules->MessageDuration * FramesPerMinute)/2);
IsSavingThisFrame = true;
IsDoingMPSaveNextFrame = false;
}
}
}
}