-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlugin_TrackManiaCustomAPI.as
More file actions
80 lines (69 loc) · 2.16 KB
/
Plugin_TrackManiaCustomAPI.as
File metadata and controls
80 lines (69 loc) · 2.16 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
#name "Trackmania Custom API"
#author "Jack Venberg"
#category "Utility"
int PORT = 65432;
string URL = "127.0.0.1";
Net::Socket@ sock;
void Main()
{
bool paused = true;
ConnectSocket();
while (true) {
CSmScriptPlayer@ scriptApi = GetPlayerScriptAPI();
CGameManiaPlanetScriptAPI@ maniaApi = GetManiaScriptAPI();
if (scriptApi !is null) {
int raceTime = scriptApi.CurrentRaceTime;
auto json = Json::Object();
if (raceTime > 0 && !maniaApi.ActiveContext_InGameMenuDisplayed) {
if (paused) {
sleep(500);
}
json['speed'] = Json::Value(scriptApi.Speed * 3.6f);
if (!sock.WriteRaw(Json::Write(json) + '\n')) {
ConnectSocket();
yield();
continue;
}
print(Json::Write(json));
paused = false;
} else if (!paused) {
paused = true;
json['speed'] = Json::Value();
if (!sock.WriteRaw(Json::Write(json) + '\n')) {
ConnectSocket();
yield();
continue;
}
print(Json::Write(json));
}
}
yield();
}
print("All done!");
sock.Close();
}
CGameManiaPlanetScriptAPI@ GetManiaScriptAPI() {
CTrackMania@ app = cast<CTrackMania>(GetApp());
return app.ManiaPlanetScriptAPI;
}
CSmScriptPlayer@ GetPlayerScriptAPI() {
CTrackMania@ app = cast<CTrackMania>(GetApp());
CSmArenaClient@ playground = cast<CSmArenaClient>(app.CurrentPlayground);
if (playground !is null) {
if (playground.GameTerminals.Length > 0) {
CGameTerminal@ terminal = cast<CGameTerminal>(playground.GameTerminals[0]);
CSmPlayer@ player = cast<CSmPlayer>(terminal.GUIPlayer);
if (player !is null) {
return cast<CSmScriptPlayer>(player.ScriptAPI);
}
}
}
return null;
}
void ConnectSocket() {
if (sock !is null) {
sock.Close();
}
@sock = Net::Socket();
sock.Connect(URL, PORT);
}