From daea14395aefdaaa510a7f40274237b45f9af6cf Mon Sep 17 00:00:00 2001 From: ChrisMiuchiz Date: Tue, 24 Sep 2019 19:01:35 -0400 Subject: [PATCH] Fix bugs and add /name --- cwmods/cube/Creature.h | 13 +++++++++-- main.cpp | 51 +++++++++++++++++++++++++++++------------- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/cwmods/cube/Creature.h b/cwmods/cube/Creature.h index 6d8bbc9..d147e6c 100644 --- a/cwmods/cube/Creature.h +++ b/cwmods/cube/Creature.h @@ -21,7 +21,14 @@ namespace cube { float head_rotation; unsigned int flags; char stats_based_on_level; - __declspec(align(8)) unsigned int current_ability; + char field_61; + char field_62; + char field_63; + char field_64; + char field_65; + char field_66; + char field_67; + unsigned int current_ability; float time_since_ability; int hit_combo; float time_since_hit; @@ -31,7 +38,9 @@ namespace cube { unsigned int level; _BYTE gap148[4]; char classType; - _BYTE gap14D[2575]; + _BYTE gap14D[2059]; + char name[16]; + _BYTE gap968[500]; int climbing_speed; int swimming_speed; int diving_skill; diff --git a/main.cpp b/main.cpp index 03e801b..aa23f49 100644 --- a/main.cpp +++ b/main.cpp @@ -2,13 +2,14 @@ #include "cwmods/cwmods.h" #include #include +#include -float GetMilliseconds(int hour, int minute){ +float GetMilliseconds(int hour, int minute) { return (hour * 60 * 60 * 1000) + (minute * 60 * 1000); } -void CommandsModMessage(wchar_t message[]){ +void CommandsModMessage(wchar_t message[]) { cube::Game* game = cube::GetGame(); game->chat_widget->PrintMessage(L"["); game->chat_widget->PrintMessage(L"CommandsMod", 255, 140, 0); @@ -35,35 +36,55 @@ EXPORT int HandleChat(wchar_t* msg) { int targetHour, targetMinute; - if ( swscanf(msg, L"/settime %d:%d", &targetHour, &targetMinute) == 2){ + if ( swscanf(msg, L"/settime %d:%d", &targetHour, &targetMinute) == 2) { printf("%ld:%ld\n", targetHour, targetMinute); float targetMS = GetMilliseconds(targetHour, targetMinute); float maxTime = GetMilliseconds(24, 0); float minTime = GetMilliseconds(0, 0); - if (targetMS > maxTime) targetMS = maxTime; - else if (targetMS < minTime) targetMS = minTime; + if (targetMS > maxTime) + targetMS = maxTime; + else if (targetMS < minTime) + targetMS = minTime; world->time = targetMS; swprintf(response, L"Changing time to %d:%02d.\n", targetHour % 24, targetMinute % 60); CommandsModMessage(response); return 1; - } - else if (!wcscmp(msg, L"/coords")){ + + } else if (!wcscmp(msg, L"/coords")) { cube::Creature* player = game->GetPlayer(); swprintf(response, L"World coordinates:\nX: %lld\nY: %lld\nZ: %lld\n", player->position.x, player->position.y, player->position.z); CommandsModMessage(response); return 1; - } - else if ( swscanf(msg, L"/tp %d %d", &targetx, &targety) == 2){ - cube::Creature* player = game->GetPlayer(); - player->position.x = MapCoordToDots(targetx); - player->position.y = MapCoordToDots(targety); - swprintf(response, L"Teleporting.\n"); - CommandsModMessage(response); - return 1; + + } else if ( swscanf(msg, L"/tp %d %d", &targetx, &targety) == 2) { + cube::Creature* player = game->GetPlayer(); + player->position.x = MapCoordToDots(targetx); + player->position.y = MapCoordToDots(targety); + CommandsModMessage(L"Teleporting.\n"); + return 1; + + } else if ( !wcsncmp(msg, L"/name ", 6) ) { + cube::Creature* player = game->GetPlayer(); + wchar_t* wideName = &msg[6]; + char newName[18]; + memset(newName, 0, sizeof(newName)); + int len = wcstombs(newName, wideName, 16); + if (len < 1) { + CommandsModMessage(L"Invalid name.\n"); } + else if (len >= 16) { + CommandsModMessage(L"Name too long!\n"); + } + else { + strcpy(player->name, newName); + swprintf(response, L"You are now known as %s.\n", player->name); + CommandsModMessage(response); + } + return 1; + } return 0; }