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
|
#include "MultiplayerWindow.h"
#include "UIWidgets.h"
#include "PortMenu.h"
#include "libultraship/src/Context.h"
#include <imgui.h>
#include <libultraship/libultraship.h>
#include "spdlog/spdlog.h"
#include <common_structs.h>
#include <defines.h>
extern "C" {
#include "main.h"
#include "networking/networking.h"
#include "actor_types.h"
#include "code_800029B0.h"
extern struct Actor gActorList[];
extern char* gCupNames[];
extern char* D_800E76A8[];
extern Network gNetwork;
extern Camera cameras[];
extern UnkStruct_800DC5EC* D_800DC5EC;
}
namespace GameUI {
extern std::shared_ptr<PortMenu> mPortMenu;
namespace Multiplayer {
static s32 sConnectedBool = false;
static s32 sReadyUpBool = false;
static s32 sCharacter = 0;
static s32 sCup = 0;
void DrawColumn1(WidgetInfo& info) {
if (gNetwork.isConnected) {
ImGui::BeginDisabled();
}
static char username[NETWORK_USERNAME_LENGTH] = "TestUser";
ImGui::Text("Username:");
ImGui::InputText("##edit", username, IM_ARRAYSIZE(username));
static char address[32] = "127.0.0.1:64010";
static char addressCopy[32];
strncpy(addressCopy, address, sizeof(addressCopy));
addressCopy[sizeof(addressCopy) - 1] = '\0'; // Ensure null termination
ImGui::Text("Host:");
ImGui::InputText("##edit3", addressCopy, IM_ARRAYSIZE(addressCopy));
if (ImGui::Button("Connect!")) {
char* ip = NULL;
uint16_t port = 0;
char* token = strtok(addressCopy, ":");
ip = token;
token = strtok(NULL, ":");
if (token != NULL) {
port = (uint16_t) atoi(token);
}
gNetwork.enabled = true;
ConnectToServer(ip, port, username);
}
if (gNetwork.isConnected) {
ImGui::EndDisabled();
}
}
void DrawColumn2(WidgetInfo& info) {
if (!gNetwork.isConnected) {
ImGui::BeginDisabled();
}
ImGui::Text("Select Character:");
ImGui::Spacing();
for (size_t i = 0; i < NUM_PLAYERS; i++) {
// These are euc-jp characters that look sort of like a hyphen -
if (D_800E76A8[i] == NULL || D_800E76A8[i] == "\xA1\xBC\xA1\xBC\xA1\xBC\xA1\xBC") {
break;
}
ImGui::SameLine();
if (ImGui::Button(D_800E76A8[i])) {
network_character_vote(i);
sCharacter = i;
}
}
ImGui::Spacing();
ImGui::Text("-- %s --", D_800E76A8[sCharacter]);
ImGui::Spacing();
ImGui::Spacing();
ImGui::Text("Course Vote:");
for (size_t i = 0; i < NUM_CUPS - 1; i++) {
if (ImGui::Button(gCupNames[i])) {
network_cup_vote(i);
sCup = i;
}
ImGui::SameLine();
}
ImGui::Spacing();
ImGui::Text("-- %s --", gCupNames[sCup]);
if (ImGui::Button("test", ImVec2(-1, 0))) {
// Add disconnect logic here
cameras[0].playerId = 2;
D_800DC5EC->player = &gPlayers[2];
}
for (size_t i = 0; i < NETWORK_MAX_PLAYERS; i++) {
ImGui::Text("Slot %d: char: %d, hasAuthority: %d", clients[i].slot, clients[i].character,
gPlayers[i].nHasAuthority);
}
/* Stick UI to the bottom of the panel */
float windowHeight = ImGui::GetWindowHeight();
// Move the cursor to a position relative to the bottom of the window
ImGui::SetCursorPosY(windowHeight -
ImGui::GetFrameHeightWithSpacing() * 2); // Adjust Y position for two buttons
char buttonLabel[32];
if (sReadyUpBool) {
strcpy(buttonLabel, "Lets Go!");
} else {
strcpy(buttonLabel, "Ready Up!");
}
// First button (Ready Up / Let's Go)
if (ImGui::Button(buttonLabel, ImVec2(-1, 0))) {
sReadyUpBool = !sReadyUpBool;
networking_ready_up(sReadyUpBool);
}
// Add some vertical spacing between the buttons
ImGui::Spacing();
// Second button (Disconnect)
if (ImGui::Button("Disconnect", ImVec2(-1, 0))) {
// Add disconnect logic here
networking_disconnect();
}
if (!gNetwork.isConnected) {
ImGui::EndDisabled();
}
}
void RegisterMultiplayerWidgets() {
// mPortMenu->AddSidebarEntry("Enhancements", "Multiplayer", 2);
// WidgetPath path = { "Enhancements", "Multiplayer", SECTION_COLUMN_1 };
// mPortMenu->AddWidget(path, "Multi Custom 1", WIDGET_CUSTOM)
// .CustomFunction(DrawColumn1);
// path.column = SECTION_COLUMN_2;
// mPortMenu->AddWidget(path, "Multi Custom 2", WIDGET_CUSTOM)
// .CustomFunction(DrawColumn2);
}
static RegisterMenuInitFunc initFunc(RegisterMultiplayerWidgets);
} // namespace Multiplayer
} // namespace GameUI
|