Add tpmap/sethome/home command
This commit is contained in:
parent
cc0c31b569
commit
c2c6dec531
|
@ -2,13 +2,16 @@
|
|||
#define WORLDMAP_H
|
||||
|
||||
#include "../IDA/types.h"
|
||||
#include "../common/LongVector3.h"
|
||||
#include <windows.h>
|
||||
|
||||
namespace cube {
|
||||
class WorldMap {
|
||||
public:
|
||||
void *vtable;
|
||||
_BYTE gap8[408];
|
||||
_BYTE gap8[248];
|
||||
LongVector3 cursor_position;
|
||||
_BYTE gap9[136];
|
||||
CRITICAL_SECTION critical_section_0;
|
||||
CRITICAL_SECTION critical_section_1;
|
||||
};
|
||||
|
|
103
main.cpp
103
main.cpp
|
@ -1,15 +1,18 @@
|
|||
#include "main.h"
|
||||
#include "cwmods/cwmods.h"
|
||||
#include "cwmods/common/LongVector3.h"
|
||||
#include <wchar.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
int serverAccessState = 0;
|
||||
bool P2PRequestLogging = false;
|
||||
bool blacklisting = false;
|
||||
std::map<std::string, std::vector<long long>> home_map;
|
||||
|
||||
float GetMilliseconds(int hour, int minute) {
|
||||
return (hour * 60 * 60 * 1000) + (minute * 60 * 1000);
|
||||
|
@ -42,6 +45,47 @@ std::vector<std::string> split(const std::string &s, char delim) {
|
|||
return elems;
|
||||
}
|
||||
|
||||
void InitHomeMap(){
|
||||
std::ifstream myfile("Mods\\CommandsMod\\home.txt");
|
||||
if(!myfile.is_open()) {
|
||||
return;
|
||||
}
|
||||
std::string line;
|
||||
|
||||
while (getline(myfile, line)) {
|
||||
std::vector<std::string> elements = split(line, ' ');
|
||||
if (elements.size() == 4) {
|
||||
std::string name = elements.at(0);
|
||||
std::string x = elements.at(1);
|
||||
std::string y = elements.at(2);
|
||||
std::string z = elements.at(3);
|
||||
std::vector<long long> coords {std::stoll(x), std::stoll(y), std::stoll(z)};
|
||||
home_map[name] = coords;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SetHomeMap(std::string alias, long long x, long long y, long long z) {
|
||||
std::vector<long long> coords {x, y, z};
|
||||
home_map[alias] = coords;
|
||||
std::ofstream outfile("Mods\\CommandsMod\\home.txt");
|
||||
if(outfile.is_open()) {
|
||||
for(auto item = home_map.begin();item != home_map.end(); item++) {
|
||||
auto value = item->second;
|
||||
outfile<<item->first<<' '<<item->second[0]<<' '<<item->second[1]<<' '<<item->second[2]<<std::endl;
|
||||
}
|
||||
outfile.close();
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<long long> GetHomePosition(std::string alias) {
|
||||
auto iter = home_map.find(alias);
|
||||
if(iter != home_map.end()) {
|
||||
return iter->second;
|
||||
}
|
||||
return std::vector<long long>();
|
||||
}
|
||||
|
||||
long long GetSteamIDFromAlias(std::string alias) {
|
||||
std::ifstream myfile("Mods\\CommandsMod\\join.txt");
|
||||
if(!myfile.is_open()) {
|
||||
|
@ -137,6 +181,13 @@ void Help(int page) {
|
|||
PrintCommand(L"/server", L"blacklist", L"Enable blacklisting of new sessions");
|
||||
PrintCommand(L"/server", L"log", L"Log new session requests");
|
||||
break;
|
||||
case 3:
|
||||
swprintf(response, L"Help %d\n", page);
|
||||
CommandsModMessage(response);
|
||||
PrintCommand(L"/tpmap", L"", L"Teleport to cursor position on map");
|
||||
PrintCommand(L"/sethome", L"<alias>", L"Set player position as home");
|
||||
PrintCommand(L"/home", L"<alias>", L"Teleport to home position by alias");
|
||||
break;
|
||||
default:
|
||||
CommandsModMessage( L"Invalid page number!\n");
|
||||
break;
|
||||
|
@ -194,6 +245,54 @@ EXPORT int HandleChat(wchar_t* msg) {
|
|||
CommandsModMessage(L"Teleporting.\n");
|
||||
return 1;
|
||||
|
||||
} else if (!wcscmp(msg, L"/tpmap")) {
|
||||
if(game->worldmap->cursor_position.x != 0x7FFFFFFF0000) {
|
||||
LongVector3 position = game->worldmap->cursor_position;
|
||||
cube::Creature* player = game->GetPlayer();
|
||||
player->position.x = position.x;
|
||||
player->position.y = position.y;
|
||||
player->position.z = position.z;
|
||||
CommandsModMessage(L"Teleporting.\n");
|
||||
return 1;
|
||||
}
|
||||
CommandsModMessage(L"Please open map.\n");
|
||||
return 0;
|
||||
|
||||
} else if ( !wcsncmp(msg, L"/sethome ", 9) ) {
|
||||
wchar_t* wideAlias = &msg[9];
|
||||
char* cAlias = new char[wcslen(wideAlias)+1];
|
||||
int len = wcstombs(cAlias, wideAlias, 0x100);
|
||||
if (len < 1) {
|
||||
CommandsModMessage(L"Invalid alias.\n");
|
||||
return 1;
|
||||
}
|
||||
std::string alias(cAlias);
|
||||
cube::Creature* player = game->GetPlayer();
|
||||
SetHomeMap(alias, player->position.x, player->position.y, player->position.z);
|
||||
CommandsModMessage(L"Done.\n");
|
||||
return 1;
|
||||
|
||||
} else if ( !wcsncmp(msg, L"/home ", 6) ) {
|
||||
wchar_t* wideAlias = &msg[6];
|
||||
char* cAlias = new char[wcslen(wideAlias)+1];
|
||||
int len = wcstombs(cAlias, wideAlias, 0x100);
|
||||
if (len < 1) {
|
||||
CommandsModMessage(L"Invalid alias.\n");
|
||||
return 1;
|
||||
}
|
||||
std::string alias(cAlias);
|
||||
std::vector<long long> position = GetHomePosition(alias);
|
||||
if(position.size() < 3) {
|
||||
CommandsModMessage(L"Invalid alias.\n");
|
||||
return 1;
|
||||
}
|
||||
cube::Creature* player = game->GetPlayer();
|
||||
player->position.x = position[0];
|
||||
player->position.y = position[1];
|
||||
player->position.z = position[2];
|
||||
CommandsModMessage(L"Teleporting.\n");
|
||||
return 1;
|
||||
|
||||
} else if ( !wcsncmp(msg, L"/name ", 6) ) {
|
||||
cube::Creature* player = game->GetPlayer();
|
||||
wchar_t* wideName = &msg[6];
|
||||
|
@ -291,3 +390,7 @@ EXPORT HandleP2PRequest(long long steamID) {
|
|||
|
||||
return serverAccessState;
|
||||
}
|
||||
|
||||
EXPORT void ModInitialize() {
|
||||
InitHomeMap();
|
||||
}
|
Loading…
Reference in New Issue