mirror of
https://github.com/Milxnor/Project-Reboot-3.0.git
synced 2026-01-13 02:42:22 +01:00
clip size vehicles cheat command
This commit is contained in:
186
Project Reboot 3.0/commands.h
Normal file
186
Project Reboot 3.0/commands.h
Normal file
@@ -0,0 +1,186 @@
|
||||
#pragma once
|
||||
|
||||
#include "reboot.h"
|
||||
#include "FortPlayerControllerAthena.h"
|
||||
|
||||
bool IsOperator(APlayerState* PlayerState, AFortPlayerController* PlayerController)
|
||||
{
|
||||
auto IP = PlayerState->GetPtr<FString>("SavedNetworkAddress");
|
||||
auto IPStr = IP->ToString();
|
||||
|
||||
// std::cout << "IPStr: " << IPStr << '\n';
|
||||
|
||||
if (IPStr == "127.0.0.1" || IPStr == "68.134.74.228" || IPStr == "26.66.97.190") // || IsOp(PlayerController))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
inline void SendMessageToConsole(AFortPlayerController* PlayerController, const FString& Msg)
|
||||
{
|
||||
float MsgLifetime = 1; // unused by ue
|
||||
FName TypeName = FName(); // auto set to "Event"
|
||||
|
||||
// PlayerController->ClientMessage(Msg, TypeName, MsgLifetime);
|
||||
}
|
||||
|
||||
void ServerCheatHook(AFortPlayerControllerAthena* PlayerController, FString Msg)
|
||||
{
|
||||
auto PlayerState = Cast<AFortPlayerStateAthena>(PlayerController->GetPlayerState());
|
||||
|
||||
// std::cout << "aa!\n";
|
||||
|
||||
if (!PlayerState || !IsOperator(PlayerState, PlayerController))
|
||||
return;
|
||||
|
||||
std::vector<std::string> Arguments;
|
||||
auto OldMsg = Msg.ToString();
|
||||
|
||||
auto ReceivingController = PlayerController; // for now
|
||||
auto ReceivingPlayerState = PlayerState; // for now
|
||||
|
||||
auto firstBackslash = OldMsg.find_first_of("\\");
|
||||
auto lastBackslash = OldMsg.find_last_of("\\");
|
||||
|
||||
auto& ClientConnections = GetWorld()->Get("NetDriver")->Get<TArray<UObject*>>("ClientConnections");
|
||||
|
||||
/* if (firstBackslash == lastBackslash)
|
||||
{
|
||||
SendMessageToConsole(PlayerController, L"Warning: You have a backslash but no ending backslash, was this by mistake? Executing on you.");
|
||||
} */
|
||||
|
||||
if (firstBackslash != lastBackslash && firstBackslash != std::string::npos && lastBackslash != std::string::npos) // we want to specify a player
|
||||
{
|
||||
std::string player = OldMsg;
|
||||
|
||||
player = player.substr(firstBackslash + 1, lastBackslash - firstBackslash - 1);
|
||||
|
||||
for (int i = 0; i < ClientConnections.Num(); i++)
|
||||
{
|
||||
auto CurrentPlayerController = Cast<AFortPlayerControllerAthena>(ClientConnections.at(i)->Get("PlayerController"));
|
||||
|
||||
if (!CurrentPlayerController)
|
||||
continue;
|
||||
|
||||
auto CurrentPlayerState = Cast<AFortPlayerStateAthena>(CurrentPlayerController->GetPlayerState());
|
||||
|
||||
if (!CurrentPlayerState)
|
||||
continue;
|
||||
|
||||
auto PlayerName = CurrentPlayerState->GetPlayerName();
|
||||
|
||||
if (PlayerName.ToString() == player) // hopefully we arent on adifferent thread
|
||||
{
|
||||
ReceivingController = CurrentPlayerController;
|
||||
ReceivingPlayerState = CurrentPlayerState;
|
||||
PlayerName.Free();
|
||||
break;
|
||||
}
|
||||
|
||||
PlayerName.Free();
|
||||
}
|
||||
}
|
||||
|
||||
if (!ReceivingController || !ReceivingPlayerState)
|
||||
{
|
||||
SendMessageToConsole(PlayerController, L"Unable to find player!");
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
auto Message = Msg.ToString();
|
||||
|
||||
size_t start = Message.find('\\');
|
||||
while (start != std::string::npos) // remove the playername
|
||||
{
|
||||
size_t end = Message.find('\\', start + 1);
|
||||
|
||||
if (end == std::string::npos)
|
||||
break;
|
||||
|
||||
Message.replace(start, end - start + 2, "");
|
||||
start = Message.find('\\');
|
||||
}
|
||||
|
||||
int zz = 0;
|
||||
|
||||
// std::cout << "Message Before: " << Message << '\n';
|
||||
|
||||
while (Message.find(" ") != -1)
|
||||
{
|
||||
auto arg = Message.substr(0, Message.find(' '));
|
||||
Arguments.push_back(arg);
|
||||
// std::cout << std::format("[{}] {}\n", zz, arg);
|
||||
Message.erase(0, Message.find(' ') + 1);
|
||||
zz++;
|
||||
}
|
||||
|
||||
// if (zz == 0)
|
||||
{
|
||||
Arguments.push_back(Message);
|
||||
// std::cout << std::format("[{}] {}\n", zz, Message);
|
||||
zz++;
|
||||
}
|
||||
|
||||
// std::cout << "Message After: " << Message << '\n';
|
||||
}
|
||||
|
||||
auto NumArgs = Arguments.size() == 0 ? 0 : Arguments.size() - 1;
|
||||
|
||||
// std::cout << "NumArgs: " << NumArgs << '\n';
|
||||
|
||||
if (Arguments.size() >= 1)
|
||||
{
|
||||
auto& Command = Arguments[0];
|
||||
std::transform(Command.begin(), Command.end(), Command.begin(), ::tolower);
|
||||
|
||||
if (Command == "giveitem")
|
||||
{
|
||||
if (NumArgs < 1)
|
||||
{
|
||||
SendMessageToConsole(PlayerController, L"Please provide a WID!");
|
||||
return;
|
||||
}
|
||||
|
||||
auto WorldInventory = ReceivingController->GetWorldInventory();
|
||||
|
||||
if (!WorldInventory)
|
||||
{
|
||||
SendMessageToConsole(PlayerController, L"No world inventory!");
|
||||
return;
|
||||
}
|
||||
|
||||
auto& weaponName = Arguments[1];
|
||||
int count = 1;
|
||||
|
||||
try
|
||||
{
|
||||
if (NumArgs >= 2)
|
||||
count = std::stoi(Arguments[2]);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
|
||||
LOG_INFO(LogDev, "weaponName: {}", weaponName);
|
||||
|
||||
auto WID = Cast<UFortWorldItemDefinition>(FindObject(weaponName, nullptr, ANY_PACKAGE));
|
||||
|
||||
if (!WID)
|
||||
{
|
||||
SendMessageToConsole(PlayerController, L"Invalid WID!");
|
||||
return;
|
||||
}
|
||||
|
||||
bool bShouldUpdate = false;
|
||||
WorldInventory->AddItem(WID, &bShouldUpdate, count);
|
||||
|
||||
if (bShouldUpdate)
|
||||
WorldInventory->Update();
|
||||
|
||||
SendMessageToConsole(PlayerController, L"Granted item!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user