-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlugin_BlockExtractor.as
More file actions
98 lines (85 loc) · 3.14 KB
/
Plugin_BlockExtractor.as
File metadata and controls
98 lines (85 loc) · 3.14 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
#name "BlockExtractor"
#author "TMDojo"
#category "Utilities"
#perms "full"
bool g_inCustomMenu = false;
class Block {
string blockName;
int blockId;
int count;
}
vec3 getRealCoords(nat3 coords)
{
auto app = GetApp();
CGameCtnEditorFree@ editor = cast<CGameCtnEditorFree>(app.Editor);
CGameEditorPluginMapMapType@ mapType = editor.PluginMapType;
return (mapType.GetVec3FromCoord(coords));
}
void ExtractBlocks()
{
dictionary blocksDict;
array<string> blockNames;
int outStr;
uint8 blockIndex = 0;
auto app = GetApp();
if (app.PlaygroundScript != null) {
if (app.PlaygroundScript.Map != null) {
for (int i = 0; i < app.PlaygroundScript.Map.Blocks.Length; i++) {
if (!blocksDict.Exists(app.PlaygroundScript.Map.Blocks[i].BlockModel.Name)) {
blockNames.InsertLast(app.PlaygroundScript.Map.Blocks[i].BlockModel.Name);
blocksDict.Set(app.PlaygroundScript.Map.Blocks[i].BlockModel.Name, blockIndex);
blockIndex++;
}
if (app.PlaygroundScript.Map.Blocks[i].BlockModel.Name.Contains("OpenTechRoadCheckpoint")) {
vec3 coord = getRealCoords(app.PlaygroundScript.Map.Blocks[i].Coord);
}
}
auto membuff = MemoryBuffer(0);
membuff.Write(blockNames.get_Length());
print(app.PlaygroundScript.Map.Blocks.Length + " Blocks analysed");
for (int i = 0; i < blockNames.get_Length(); i++) {
uint8 id;
blocksDict.Get(blockNames[i], id);
uint8 blockNameLen = blockNames[i].get_Length();
print("Id: " + id + "\t" + blockNames[i]);
membuff.Write(id);
membuff.Write(blockNameLen);
membuff.Write(blockNames[i]);
}
for (int i = 0; i < app.PlaygroundScript.Map.Blocks.Length; i++) {
uint8 id;
uint8 dir = app.PlaygroundScript.Map.Blocks[i].BlockModel.Dir;
vec3 coord = getRealCoords(app.PlaygroundScript.Map.Blocks[i].Coord);
blocksDict.Get(app.PlaygroundScript.Map.Blocks[i].BlockModel.Name, id);
membuff.Write(id);
membuff.Write(dir);
membuff.Write(coord.x);
membuff.Write(coord.y);
membuff.Write(coord.z);
}
print("Membuff: " + membuff.GetSize());
membuff.Seek(0);
Net::HttpPost("http://localhost/maps/" + app.PlaygroundScript.Map.EdChallengeId, membuff.ReadToBase64(membuff.GetSize()), "application/octet-stream");
membuff.Resize(0);
} else {
print("app.PlaygroundScript.Map == null");
}
} else {
print("app.PlaygroundScript == null");
}
}
void RenderMenu()
{
auto app = cast<CGameManiaPlanet>(GetApp());
auto menus = cast<CTrackManiaMenus>(app.MenuManager);
if (UI::BeginMenu("Block Extractor")) {
if (UI::MenuItem("Extract Blocks", "", false, true)) {
ExtractBlocks();
}
UI::EndMenu();
}
}
void Main()
{
print("BlockExtractor: Init");
}