From 5495d6702712142c5637f40470e1f43d597fa299 Mon Sep 17 00:00:00 2001 From: yangzhi <@4F!xZpJwly&KbWq> Date: Thu, 10 Oct 2019 20:18:02 +0800 Subject: [PATCH] tp command enchanted, update to latest sdk, resolve warnings --- cwmods/IDA/types.h | 6 +- cwmods/cube/ChatWidget.cpp | 6 +- cwmods/cube/ChatWidget.h | 6 +- cwmods/cube/Creature.h | 80 +++++++++-- cwmods/cube/Game.cpp | 6 +- cwmods/cube/Game.h | 6 +- cwmods/cube/Item.cpp | 9 ++ cwmods/cube/Item.h | 30 ++++ cwmods/cube/ItemStack.cpp | 9 ++ cwmods/cube/ItemStack.h | 17 +++ cwmods/cube/Spirit.cpp | 1 + cwmods/cube/Spirit.h | 14 ++ cwmods/cube/SpriteManager.cpp | 1 + cwmods/cube/SpriteManager.h | 30 ++++ cwmods/cube/World.h | 44 +++--- cwmods/cube/WorldMap.h | 64 ++++++++- cwmods/cwmods.cpp | 14 ++ cwmods/cwmods.h | 15 +- cwmods/gfx/D3D11Graphics.cpp | 1 + cwmods/gfx/D3D11Graphics.h | 15 ++ cwmods/msvc/allocator.cpp | 1 + cwmods/msvc/allocator.h | 51 +++++++ cwmods/msvc/list.cpp | 1 + cwmods/msvc/list.h | 126 ++++++++++++++++ cwmods/msvc/string.h | 6 +- cwmods/msvc/vector.cpp | 2 +- cwmods/msvc/vector.h | 216 ++++++++++++++++++++++++++-- cwmods/msvc/wstring.cpp | 3 +- cwmods/msvc/wstring.h | 8 +- cwmods/plasma/ContinuousAttribute.h | 4 +- cwmods/plasma/DiscreteAttribute.h | 4 +- cwmods/plasma/Display.cpp | 6 +- cwmods/plasma/Display.h | 6 +- cwmods/plasma/Vector.cpp | 1 + cwmods/plasma/Vector.h | 21 +++ main.cpp | 38 ++++- 36 files changed, 783 insertions(+), 85 deletions(-) create mode 100644 cwmods/cube/Item.cpp create mode 100644 cwmods/cube/Item.h create mode 100644 cwmods/cube/ItemStack.cpp create mode 100644 cwmods/cube/ItemStack.h create mode 100644 cwmods/cube/Spirit.cpp create mode 100644 cwmods/cube/Spirit.h create mode 100644 cwmods/cube/SpriteManager.cpp create mode 100644 cwmods/cube/SpriteManager.h create mode 100644 cwmods/gfx/D3D11Graphics.cpp create mode 100644 cwmods/gfx/D3D11Graphics.h create mode 100644 cwmods/msvc/allocator.cpp create mode 100644 cwmods/msvc/allocator.h create mode 100644 cwmods/msvc/list.cpp create mode 100644 cwmods/msvc/list.h create mode 100644 cwmods/plasma/Vector.cpp create mode 100644 cwmods/plasma/Vector.h diff --git a/cwmods/IDA/types.h b/cwmods/IDA/types.h index a4340d4..071764a 100644 --- a/cwmods/IDA/types.h +++ b/cwmods/IDA/types.h @@ -2,7 +2,11 @@ #define IDA_CONSTANTS_H #define _BYTE unsigned char -#define __int64 long long int + +#ifndef __int64 + #define __int64 long long int +#endif + #define __int16 short #endif diff --git a/cwmods/cube/ChatWidget.cpp b/cwmods/cube/ChatWidget.cpp index cd068f8..4727fe8 100644 --- a/cwmods/cube/ChatWidget.cpp +++ b/cwmods/cube/ChatWidget.cpp @@ -1,16 +1,16 @@ #include "ChatWidget.h" #include "../cwmods.h" -void cube::ChatWidget::PrintMessage(wchar_t* message, FloatRGBA* color){ +void cube::ChatWidget::PrintMessage(const wchar_t* message, FloatRGBA* color){ msvc::wstring str(message); ((void(*)(cube::ChatWidget*, msvc::wstring*, FloatRGBA*))CWBase()+0x26BF10)(this, &str, color); } -void cube::ChatWidget::PrintMessage(wchar_t* message) { +void cube::ChatWidget::PrintMessage(const wchar_t* message) { this->PrintMessage(message, 255, 255, 255); } -void cube::ChatWidget::PrintMessage(wchar_t* message, char red, char green, char blue){ +void cube::ChatWidget::PrintMessage(const wchar_t* message, char red, char green, char blue){ float f_red = (float)red / 255.0; float f_green = (float)green / 255.0; float f_blue = (float)blue / 255.0; diff --git a/cwmods/cube/ChatWidget.h b/cwmods/cube/ChatWidget.h index aca6941..015cbd0 100644 --- a/cwmods/cube/ChatWidget.h +++ b/cwmods/cube/ChatWidget.h @@ -12,9 +12,9 @@ class ChatWidget : public plasma::Widget { char end; - void PrintMessage(wchar_t* message, FloatRGBA* color); - void PrintMessage(wchar_t* message); - void PrintMessage(wchar_t* message, char red, char green, char blue); + void PrintMessage(const wchar_t* message, FloatRGBA* color); + void PrintMessage(const wchar_t* message); + void PrintMessage(const wchar_t* message, char red, char green, char blue); }; } diff --git a/cwmods/cube/Creature.h b/cwmods/cube/Creature.h index d147e6c..727dc00 100644 --- a/cwmods/cube/Creature.h +++ b/cwmods/cube/Creature.h @@ -5,6 +5,8 @@ #include "../common/LongVector3.h" #include "../common/FloatVector3.h" #include "../common/ByteRGBA.h" +#include "../msvc/vector.h" +#include "ItemStack.h" namespace cube { class Creature { @@ -20,27 +22,82 @@ namespace cube { FloatVector3 retreat; float head_rotation; unsigned int flags; - char stats_based_on_level; + char hostility_type; 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; + int race; + BYTE current_ability; float time_since_ability; int hit_combo; float time_since_hit; __int16 field_78; ByteRGBA hair_color; - _BYTE gap7E[198]; + char padding_7E; + char padding_7F; + unsigned int flags2; + float graphics_scale; + float hitbox_scale; + float physics_scale; + __int16 head_model; + __int16 hair_model; + __int16 hands_model; + __int16 feet_model; + __int16 chest_model; + __int16 tail_model; + __int16 shoulder_model; + __int16 wings_model; + float head_scale; + float chest_scale; + float hands_scale; + float feet_scale; + float unknown_scale; + float weapon_scale; + float tail_scale; + float shoulder_scale; + float wing_scale; + float chest_rotation; + FloatVector3 hands_rotation; + float feet_rotation; + float wings_rotation; + float unknown_rotation; + FloatVector3 chest_position; + FloatVector3 head_position; + FloatVector3 hands_position; + FloatVector3 feet_position; + FloatVector3 unknown_position; + FloatVector3 wings_position; + unsigned int movement_flags; + float roll_time; + float stun_time; + float unknown_time; + float slowed_time; + float sprint_time; + int field_140; unsigned int level; - _BYTE gap148[4]; - char classType; - _BYTE gap14D[2059]; + int XP; + unsigned __int8 classType; + char specialization; + _BYTE gap14E[10]; + char charge; + _BYTE gap159[27]; + FloatVector3 attack_rotation; + float HP; + float float_184; + float MP; + float stealth; + _BYTE gap190[552]; + cube::Item chest_armor; + cube::Item feet_armor; + cube::Item hands_armor; + cube::Item shoulder_armor; + cube::Item left_weapon; + cube::Item right_weapon; + _BYTE gap778[480]; char name[16]; - _BYTE gap968[500]; + _BYTE gap968[136]; + msvc::vector> inventory_tabs; + _BYTE gapA08[340]; int climbing_speed; int swimming_speed; int diving_skill; @@ -50,6 +107,7 @@ namespace cube { int lamp_diameter; _BYTE gapB78[2687]; char end; + }; } diff --git a/cwmods/cube/Game.cpp b/cwmods/cube/Game.cpp index 02bcaa2..d7d8690 100644 --- a/cwmods/cube/Game.cpp +++ b/cwmods/cube/Game.cpp @@ -10,12 +10,12 @@ cube::Game* cube::GetGame() { return *(cube::Game**)(CWBase() + 0x551A80); } -void cube::Game::PrintMessage(wchar_t* message, FloatRGBA* color) { +void cube::Game::PrintMessage(const wchar_t* message, FloatRGBA* color) { this->gui.chat_widget->PrintMessage(message, color); } -void cube::Game::PrintMessage(wchar_t* message) { +void cube::Game::PrintMessage(const wchar_t* message) { this->gui.chat_widget->PrintMessage(message); } -void cube::Game::PrintMessage(wchar_t* message, char red, char green, char blue) { +void cube::Game::PrintMessage(const wchar_t* message, char red, char green, char blue) { this->gui.chat_widget->PrintMessage(message, red, green, blue); } diff --git a/cwmods/cube/Game.h b/cwmods/cube/Game.h index 4288669..5d672b0 100644 --- a/cwmods/cube/Game.h +++ b/cwmods/cube/Game.h @@ -70,9 +70,9 @@ namespace cube { cube::Database database_1; cube::Creature* GetPlayer(); - void PrintMessage(wchar_t* message, FloatRGBA* color); - void PrintMessage(wchar_t* message); - void PrintMessage(wchar_t* message, char red, char green, char blue); + void PrintMessage(const wchar_t* message, FloatRGBA* color); + void PrintMessage(const wchar_t* message); + void PrintMessage(const wchar_t* message, char red, char green, char blue); }; Game* GetGame(); } diff --git a/cwmods/cube/Item.cpp b/cwmods/cube/Item.cpp new file mode 100644 index 0000000..8d82bf6 --- /dev/null +++ b/cwmods/cube/Item.cpp @@ -0,0 +1,9 @@ +#include "Item.h" + + +cube::Item::Item(){ +} +cube::Item::Item(char category, int id) { + this->category = category; + this->id = id; +} diff --git a/cwmods/cube/Item.h b/cwmods/cube/Item.h new file mode 100644 index 0000000..5bec7e4 --- /dev/null +++ b/cwmods/cube/Item.h @@ -0,0 +1,30 @@ +#ifndef ITEM_H +#define ITEM_H + +#include "Spirit.h" + +namespace cube { +class Item { + public: + char category; + char field_1; + char field_2; + char field_3; + int id; + unsigned int modifier; + int region; + int field_10; + char rarity; + int field_18; + char material; + cube::Spirit spirits[32]; + char num_spirits; + char field_9E; + char field_9F; + + Item(); + Item(char category, int id); + }; +} + +#endif // ITEM_H diff --git a/cwmods/cube/ItemStack.cpp b/cwmods/cube/ItemStack.cpp new file mode 100644 index 0000000..dc718ae --- /dev/null +++ b/cwmods/cube/ItemStack.cpp @@ -0,0 +1,9 @@ +#include "ItemStack.h" +#include "Item.h" + +cube::ItemStack::ItemStack() { +} +cube::ItemStack::ItemStack(int quantity, cube::Item item) { + this->quantity = quantity; + this->item = item; +} diff --git a/cwmods/cube/ItemStack.h b/cwmods/cube/ItemStack.h new file mode 100644 index 0000000..b1f0066 --- /dev/null +++ b/cwmods/cube/ItemStack.h @@ -0,0 +1,17 @@ +#ifndef ITEMSTACK_H +#define ITEMSTACK_H + +#include "Item.h" + +namespace cube { +class ItemStack { + public: + int quantity; + cube::Item item; + + ItemStack(); + ItemStack(int quantity, cube::Item item); + }; +} + +#endif // ITEMSTACK_H diff --git a/cwmods/cube/Spirit.cpp b/cwmods/cube/Spirit.cpp new file mode 100644 index 0000000..e3bea50 --- /dev/null +++ b/cwmods/cube/Spirit.cpp @@ -0,0 +1 @@ +#include "Spirit.h" diff --git a/cwmods/cube/Spirit.h b/cwmods/cube/Spirit.h new file mode 100644 index 0000000..16f5a0b --- /dev/null +++ b/cwmods/cube/Spirit.h @@ -0,0 +1,14 @@ +#ifndef SPIRIT_H +#define SPIRIT_H + +namespace cube { +class Spirit { + public: + char x; + char y; + char z; + char material; + }; +} + +#endif // SPIRIT_H diff --git a/cwmods/cube/SpriteManager.cpp b/cwmods/cube/SpriteManager.cpp new file mode 100644 index 0000000..0e2efe3 --- /dev/null +++ b/cwmods/cube/SpriteManager.cpp @@ -0,0 +1 @@ +#include "SpriteManager.h" diff --git a/cwmods/cube/SpriteManager.h b/cwmods/cube/SpriteManager.h new file mode 100644 index 0000000..342d210 --- /dev/null +++ b/cwmods/cube/SpriteManager.h @@ -0,0 +1,30 @@ +#ifndef SPRITEMANAGER_H +#define SPRITEMANAGER_H + +#include "../IDA/types.h" +#include +#include "../gfx/D3D11Graphics.h" + +namespace cube { + class SpriteManager { + public: + void *vtable; + gfx::D3D11Graphics *graphics; + void *sprite_map; + __int64 field_18; + __int64 field_20; + __int64 field_28; + __int64 field_30; + __int64 field_38; + __int64 field_40; + __int64 field_48; + __int64 field_50; + __int64 field_58; + __int64 field_60; + __int64 field_68; + __int64 field_70; + __int64 field_78; + }; +} + +#endif // SPRITEMANAGER_H diff --git a/cwmods/cube/World.h b/cwmods/cube/World.h index 0a41fe0..b04a63b 100644 --- a/cwmods/cube/World.h +++ b/cwmods/cube/World.h @@ -6,29 +6,35 @@ #include "Database.h" #include #include "../IDA/types.h" +#include "../msvc/list.h" +#include "SpriteManager.h" namespace cube { class World { public: - void *vtable; - int day; - float time; - _BYTE gap10[416]; - cube::World *self_ptr; - _BYTE gap1A8[72]; - msvc::string world_name; - int seed; - _BYTE gap224[404]; - cube::Database database; - CRITICAL_SECTION critical_section_0; - CRITICAL_SECTION critical_section_1; - CRITICAL_SECTION critical_section_2; - _BYTE gap440[8]; - cube::Creature *local_creature; - _BYTE gap450[16]; - BYTE zone_list[24]; - _BYTE gap478[207]; - char end; + void *vtable; + int day; + float time; + _BYTE gap10[48]; + msvc::list creatures; + _BYTE gap50[32]; + cube::SpriteManager *spritemanager; + _BYTE gap78[312]; + cube::World *self_ptr; + _BYTE gap1A8[72]; + msvc::string world_name; + int seed; + _BYTE gap224[404]; + cube::Database database; + CRITICAL_SECTION critical_section_0; + CRITICAL_SECTION critical_section_1; + CRITICAL_SECTION critical_section_2; + _BYTE gap440[8]; + cube::Creature *local_creature; + _BYTE gap450[16]; + BYTE zone_list[24]; + _BYTE gap478[207]; + char end; }; } diff --git a/cwmods/cube/WorldMap.h b/cwmods/cube/WorldMap.h index b414b9d..b600bde 100644 --- a/cwmods/cube/WorldMap.h +++ b/cwmods/cube/WorldMap.h @@ -2,16 +2,74 @@ #define WORLDMAP_H #include "../IDA/types.h" -#include "../common/LongVector3.h" #include +#include "World.h" +#include "../common/LongVector3.h" +#include "../plasma/D3D11Engine.h" namespace cube { class WorldMap { public: void *vtable; - _BYTE gap8[248]; + cube::World *world; + plasma::D3D11Engine *d3d11engine; + __int64 field_18; + __int64 field_20; + __int64 field_28; + __int64 field_30; + __int64 field_38; + __int64 field_40; + __int64 field_48; + __int64 field_50; + __int64 field_58; + __int64 field_60; + __int64 field_68; + __int64 field_70; + __int64 field_78; + __int64 field_80; + __int64 field_88; + __int64 field_90; + __int64 field_98; + __int64 field_A0; + __int64 field_A8; + __int64 field_B0; + __int64 field_B8; + __int64 field_C0; + int field_C8; + _BYTE gapCC[52]; LongVector3 cursor_position; - _BYTE gap9[136]; + int field_118; + int field_11C; + int field_120; + int field_124; + __int64 field_128; + __int64 field_130; + __int64 field_138; + __int64 field_140; + __int64 field_148; + int field_150; + int field_154; + int field_158; + int field_15C; + int field_160; + char field_164; + char field_165; + char field_166; + char field_167; + char field_168; + char field_169; + char field_16A; + char field_16B; + char field_16C; + char field_16D; + char field_16E; + char field_16F; + __int64 field_170; + __int64 field_178; + __int64 field_180; + __int64 field_188; + __int64 field_190; + __int64 field_198; CRITICAL_SECTION critical_section_0; CRITICAL_SECTION critical_section_1; }; diff --git a/cwmods/cwmods.cpp b/cwmods/cwmods.cpp index 1a20b2f..2bf3859 100644 --- a/cwmods/cwmods.cpp +++ b/cwmods/cwmods.cpp @@ -44,3 +44,17 @@ void WriteFarJMP(void* source, void* destination) { VirtualProtect(location, 14, dwOldProtection, &dwOldProtection); } + +__declspec(noinline) void* operator new(size_t size) { + return ((void*(*)(size_t))CWBase()+0x392BAC)(size); +} +__declspec(noinline) void* operator new[](size_t size) { + return ((void*(*)(size_t))CWBase()+0x392BAC)(size); +} + +__declspec(noinline) void operator delete(void* ptr) noexcept { + ((void(*)(void*))CWBase()+0x392BE8)(ptr); +} +__declspec(noinline) void operator delete[](void* ptr) noexcept { + ((void(*)(void*))CWBase()+0x392BE8)(ptr); +} diff --git a/cwmods/cwmods.h b/cwmods/cwmods.h index 77fe343..6d5002b 100644 --- a/cwmods/cwmods.h +++ b/cwmods/cwmods.h @@ -2,7 +2,7 @@ #define CWMODS_H #include -#define EXPORT extern "C" __declspec(dllexport) +#define EXPORT extern "C" __declspec(dllexport) __declspec(noinline) #include "IDA/types.h" @@ -19,21 +19,26 @@ #include "cube/Field.h" #include "cube/Game.h" #include "cube/Host.h" +#include "cube/Item.h" +#include "cube/ItemStack.h" #include "cube/PlasmaHolder.h" #include "cube/Speech.h" +#include "cube/SpriteManager.h" #include "cube/World.h" #include "cube/WorldMap.h" #include "cube/Zone.h" #include "cube/constants.h" #include "gfx/Chunk.h" +#include "gfx/D3D11Graphics.h" #include "gfx/D3D11Renderer.h" +#include "msvc/allocator.h" +#include "msvc/list.h" #include "msvc/string.h" #include "msvc/vector.h" #include "msvc/wstring.h" -#include "plasma/Array.h" #include "plasma/Attribute.h" #include "plasma/ContinuousAttribute.h" #include "plasma/D3D11Engine.h" @@ -45,6 +50,7 @@ #include "plasma/Node.h" #include "plasma/Object.h" #include "plasma/ObjectManager.h" +#include "plasma/Vector.h" #include "plasma/Widget.h" @@ -57,4 +63,9 @@ EXPORT int ModMinorVersion(); void WriteByte(void* location, char val); void WriteFarJMP(void* source, void* destination); +__declspec(noinline) void* operator new(size_t size); +__declspec(noinline) void* operator new[](size_t size); +__declspec(noinline) void operator delete(void* ptr) noexcept; +__declspec(noinline) void operator delete[](void* ptr) noexcept; + #endif // CWMODS_H diff --git a/cwmods/gfx/D3D11Graphics.cpp b/cwmods/gfx/D3D11Graphics.cpp new file mode 100644 index 0000000..cc126f3 --- /dev/null +++ b/cwmods/gfx/D3D11Graphics.cpp @@ -0,0 +1 @@ +#include "D3D11Graphics.h" diff --git a/cwmods/gfx/D3D11Graphics.h b/cwmods/gfx/D3D11Graphics.h new file mode 100644 index 0000000..7bcb99a --- /dev/null +++ b/cwmods/gfx/D3D11Graphics.h @@ -0,0 +1,15 @@ +#ifndef D3D11GRAPHICS_H +#define D3D11GRAPHICS_H + +#include "../IDA/types.h" + +namespace gfx { +class D3D11Graphics { + public: + void *vtable; + __int64 field_8; + __int64 field_10; + }; +} + +#endif // D3D11GRAPHICS_H diff --git a/cwmods/msvc/allocator.cpp b/cwmods/msvc/allocator.cpp new file mode 100644 index 0000000..30c4efa --- /dev/null +++ b/cwmods/msvc/allocator.cpp @@ -0,0 +1 @@ +#include "allocator.h" diff --git a/cwmods/msvc/allocator.h b/cwmods/msvc/allocator.h new file mode 100644 index 0000000..07020b5 --- /dev/null +++ b/cwmods/msvc/allocator.h @@ -0,0 +1,51 @@ +#ifndef MSVC_ALLOCATOR_H +#define MSVC_ALLOCATOR_H +#include +#include +#include + +#include + +namespace msvc { + template + struct allocator { + public: + typedef size_t size_type; + typedef T value_type; + typedef T& reference; + typedef T* pointer; + + T* allocate( std::size_t n ) { + const static size_type alignment_size = 32; + const static size_type alignment_offset = (alignment_size-1) + sizeof(void*); + + size_type new_allocation_size = n * sizeof(T); + pointer new_backing; + + // Large arrays + if (new_allocation_size < 0x1000) { + new_backing = (pointer)new char[new_allocation_size]; + } else { + new_allocation_size += 39; + char* large_array = new char[new_allocation_size]; + new_backing = (pointer)((long long unsigned int)(large_array + alignment_offset) & ~(alignment_size-1)); + ((char**)(new_backing))[-1] = large_array; + } + return new_backing; + } + + void deallocate( T* p, std::size_t n ) { + size_type old_allocation_size = n * sizeof(T); + if (old_allocation_size < 0x1000) { + delete[] p; + } else { + char* actual_allocation = ((char**)(p))[-1]; + delete[] actual_allocation; + } + } + + + }; +} + +#endif // MSVC_ALLOCATOR_H diff --git a/cwmods/msvc/list.cpp b/cwmods/msvc/list.cpp new file mode 100644 index 0000000..471c2a1 --- /dev/null +++ b/cwmods/msvc/list.cpp @@ -0,0 +1 @@ +#include "list.h" diff --git a/cwmods/msvc/list.h b/cwmods/msvc/list.h new file mode 100644 index 0000000..5af7614 --- /dev/null +++ b/cwmods/msvc/list.h @@ -0,0 +1,126 @@ +#ifndef MSVC_LIST_H +#define MSVC_LIST_H +#include +#include +#include +#include +#include "allocator.h" + +namespace msvc { + template + struct list { + + class node { + public: + msvc::list::node *next; + msvc::list::node *prev; + T data; + + node() { + this->next = nullptr; + this->prev = nullptr; + } + node( msvc::list::node *prev, msvc::list::node *next, T data) { + this->next = next; + this->prev = prev; + this->data = data; + } + + }; + + public: + typedef size_t size_type; + typedef T value_type; + typedef T& reference; + typedef T* pointer; + + // forward iterator + class iterator { + public: + typedef iterator self_type; + typedef int difference_type; + typedef std::forward_iterator_tag iterator_category; + + iterator() {} + iterator(msvc::list::node* ptr) : list_node(ptr) { } + + self_type operator=(const self_type& other) { list_node = other.list_node; return *this; } + self_type operator++() { list_node = list_node->next; return *this; } // ++i + self_type operator++(int junk) { self_type i = *this; list_node = list_node->next; return i; } // i++ + self_type operator--() { list_node = list_node->prev; return *this; } + self_type operator--(int junk) { self_type i = *this; list_node = list_node->prev; return i; } + reference operator*() { return list_node->data; } + pointer operator->() { return &list_node->data; } + bool operator==(const self_type& rhs) const { return list_node == rhs.list_node; } + bool operator!=(const self_type& rhs) const { return list_node != rhs.list_node; } + + msvc::list::node* list_node; + }; + + private: + msvc::list::node *head; + size_type _size; + + + public: + reference front() { + return head->next->data; + } + + reference back() { + return head->prev->data; + } + + iterator begin() { + return iterator(head->next); + } + + iterator end() { + return iterator(head); + } + + size_type size() { + return _size; + } + + size_type max_size() const noexcept { + // Silly, theoretical max container size. + return UINTPTR_MAX / sizeof(T); + } + + iterator insert( iterator pos, const T& value ) { + list::node* current_node = pos.list_node; + list::node* previous_node = current_node->prev; + + + list::node* new_node = new node(previous_node, current_node, value); + + current_node->prev = new_node; + previous_node->next = new_node; + + _size++; + + return iterator(new_node); + } + + iterator erase( iterator pos ) { + if (!size()) { + return end(); + } + list::node* current_node = pos.list_node; + list::node* previous_node = current_node->prev; + list::node* next_node = current_node->next; + + + next_node->prev = previous_node; + previous_node->next = next_node; + + delete current_node; + + return iterator(next_node); + } + + }; +} + +#endif // MSVC_LIST_H diff --git a/cwmods/msvc/string.h b/cwmods/msvc/string.h index 12d5f57..011550b 100644 --- a/cwmods/msvc/string.h +++ b/cwmods/msvc/string.h @@ -1,5 +1,5 @@ -#ifndef STRING_H -#define STRING_H +#ifndef MSVC_STRING_H +#define MSVC_STRING_H #include namespace msvc { @@ -16,4 +16,4 @@ namespace msvc { }; } -#endif // STRING_H +#endif // MSVC_STRING_H diff --git a/cwmods/msvc/vector.cpp b/cwmods/msvc/vector.cpp index 37e7137..5f4252d 100644 --- a/cwmods/msvc/vector.cpp +++ b/cwmods/msvc/vector.cpp @@ -1 +1 @@ -#include "Vector.h" +#include "vector.h" diff --git a/cwmods/msvc/vector.h b/cwmods/msvc/vector.h index 0582b9a..1471f09 100644 --- a/cwmods/msvc/vector.h +++ b/cwmods/msvc/vector.h @@ -1,21 +1,209 @@ -#ifndef VECTOR_H -#define VECTOR_H +// based on https://github.com/Andoryuuta/cwsdk/blob/master/cwsdk/msvc_bincompat/vector.h +#ifndef MSVC_VECTOR_H +#define MSVC_VECTOR_H +#include +#include +#include +#include +#include "allocator.h" namespace msvc { - template - class Vector { - public: - T elements[N]; + template + struct vector { + private: + T* _start; + T* _end; + T* _cap; - T at(int i) { - return elements[i]; - } + public: + typedef size_t size_type; + typedef T value_type; + typedef T& reference; + typedef T* pointer; - void assign(int i, T x) { - elements[i] = x; - } - }; + // forward iterator + class iterator { + public: + typedef iterator self_type; + typedef int difference_type; + typedef std::forward_iterator_tag iterator_category; + + iterator() {} + iterator(pointer ptr) : _ptr(ptr) { } + + self_type operator=(const self_type& other) { _ptr = other._ptr; return *this; } + self_type operator++() { _ptr++; return *this; } // ++i + self_type operator++(int junk) { self_type i = *this; _ptr++; return i; } // i++ + self_type operator--() { _ptr--; return *this; } + self_type operator--(int junk) { self_type i = *this; _ptr--; return i; } + reference operator*() { return *_ptr; } + pointer operator->() { return _ptr; } + bool operator==(const self_type& rhs) const { return _ptr == rhs._ptr; } + bool operator!=(const self_type& rhs) const { return _ptr != rhs._ptr; } + + private: + pointer _ptr; + }; + + // const forward iterator + class const_iterator { + public: + typedef const_iterator self_type; + typedef int difference_type; + typedef std::forward_iterator_tag iterator_category; + + const_iterator() {} + const_iterator(pointer ptr) : _ptr(ptr) { } + + self_type operator++() { _ptr++; return *this; } + self_type operator++(int junk) { self_type i = *this; _ptr++; return i; } + self_type operator--() { _ptr--; return *this; } + self_type operator--(int junk) { self_type i = *this; _ptr--; return i; } + const value_type& operator*() { return *_ptr; } + const value_type* operator->() { return _ptr; } + bool operator==(const self_type& rhs) const { return _ptr == rhs._ptr; } + bool operator!=(const self_type& rhs) const { return _ptr != rhs._ptr; } + + private: + pointer _ptr; + }; + + /* Constructors & Destructors start*/ + vector() { + auto mem = (pointer)operator new(0); + _start = mem; + _end = mem; + _cap = mem; + + reserve(1); + } + + ~vector() { + if (_start != nullptr) { + operator delete(_start); + } + } + + /* Constructors & Destructors end*/ + + /* Element access methods start*/ + reference at(size_type pos) { + if (pos > size()) { + throw std::out_of_range("index out of bounds"); + } + return operator[](pos); + } + + reference operator [](size_type pos) { + return _start[pos]; + } + + reference front() { + return *begin(); + } + + reference back() { + auto tmp = end(); + tmp--; + return *tmp; + } + + /* Element access methods end*/ + + /* Iterators methods start*/ + iterator begin() { + return iterator(_start); + } + + iterator end() { + return iterator(_end); + } + + const_iterator begin() const { + return const_iterator(_start); + } + + const_iterator end() const { + return const_iterator(_end); + } + /* Iterators methods end*/ + + /* Capacity methods start*/ + bool empty() const { + return begin() == end(); + } + + size_type size() const { + return _end - _start; + } + + size_type max_size() const { + // Silly, theoretical max container size. + return UINTPTR_MAX / sizeof(T); + } + + void reserve(size_type new_cap) { + msvc::allocator thisAllocator; + size_type old_capacity = capacity(); + + // No need to reserve more if we need less space than we have + if (new_cap <= old_capacity) { + return; + } + + if (new_cap > max_size()) { + throw std::length_error("new_cap > max_size()"); + } + + // Create new backing array + pointer new_backing = thisAllocator.allocate(new_cap); + + // Copy old contents to new array + size_type old_size = size(); + memcpy((void*)new_backing, (void*)_start, old_size * sizeof(T)); + + // Remember old array + pointer old_backing = _start; + + // Update the vector + _start = new_backing; + _end = new_backing + old_size; + _cap = new_backing + new_cap; + + // Deallocate old array + thisAllocator.deallocate(old_backing, old_capacity); + } + + size_type capacity() const { + return _cap - _start; + } + /* Capacity methods end*/ + + /* Modifer methods start*/ + void push_back(const T& value) { + if (capacity() == 0) { + reserve(1); + } + else if (size() == capacity()) { + reserve(capacity() * 2); + } + _start[size()] = value; + _end++; + } + + void pop_back() { + if (size() > 0) { + back().~T(); + _end--; + } + } + + void clear() noexcept { + _end = _start; + } + /* Modifer methods end*/ + }; } -#endif // VECTOR_H +#endif // MSVC_VECTOR_H diff --git a/cwmods/msvc/wstring.cpp b/cwmods/msvc/wstring.cpp index 5d809b4..f1ec718 100644 --- a/cwmods/msvc/wstring.cpp +++ b/cwmods/msvc/wstring.cpp @@ -1,7 +1,8 @@ #include "wstring.h" #include +#include -msvc::wstring::wstring(wchar_t* str) { +msvc::wstring::wstring(const wchar_t* str) { int len = wcslen(str) + 1; wchar_t* data; if (len >= 8) { diff --git a/cwmods/msvc/wstring.h b/cwmods/msvc/wstring.h index 25890d3..9c7dadf 100644 --- a/cwmods/msvc/wstring.h +++ b/cwmods/msvc/wstring.h @@ -1,5 +1,5 @@ -#ifndef WSTRING_H -#define WSTRING_H +#ifndef MSVC_WSTRING_H +#define MSVC_WSTRING_H #include namespace msvc { @@ -13,10 +13,10 @@ namespace msvc { int64_t size; int64_t cap; - wstring(wchar_t* str); + wstring(const wchar_t* str); ~wstring(); }; }; -#endif // WSTRING_H +#endif // MSVC_WSTRING_H diff --git a/cwmods/plasma/ContinuousAttribute.h b/cwmods/plasma/ContinuousAttribute.h index b2fa51c..d1a87c2 100644 --- a/cwmods/plasma/ContinuousAttribute.h +++ b/cwmods/plasma/ContinuousAttribute.h @@ -3,13 +3,13 @@ #include "../IDA/types.h" #include "Attribute.h" -#include "Array.h" +#include "../msvc/vector.h" namespace plasma { template class ContinuousAttribute : public plasma::Attribute { public: - plasma::Array data; + msvc::vector data; }; } diff --git a/cwmods/plasma/DiscreteAttribute.h b/cwmods/plasma/DiscreteAttribute.h index c19f27c..c5f2e7b 100644 --- a/cwmods/plasma/DiscreteAttribute.h +++ b/cwmods/plasma/DiscreteAttribute.h @@ -3,13 +3,13 @@ #include "../IDA/types.h" #include "Attribute.h" -#include "Array.h" +#include "../msvc/vector.h" namespace plasma { template class DiscreteAttribute : public plasma::Attribute { public: - plasma::Array data; + msvc::vector data; }; } diff --git a/cwmods/plasma/Display.cpp b/cwmods/plasma/Display.cpp index ac1fcea..3d9694c 100644 --- a/cwmods/plasma/Display.cpp +++ b/cwmods/plasma/Display.cpp @@ -1,13 +1,13 @@ #include "Display.h" void plasma::Display::SetVisibility(int frame, int value) { - this->visibility.data.Set(frame, value); + this->visibility.data.at(frame) = value; } int plasma::Display::GetVisibility(int frame) { - return this->visibility.data.Get(frame); + return this->visibility.data.at(frame); } int plasma::Display::GetFrameCount() { - return this->visibility.data.Length(); + return this->visibility.data.size(); } diff --git a/cwmods/plasma/Display.h b/cwmods/plasma/Display.h index 8278ded..1d9fce3 100644 --- a/cwmods/plasma/Display.h +++ b/cwmods/plasma/Display.h @@ -5,15 +5,15 @@ #include "Keyable.h" #include "DiscreteAttribute.h" #include "ContinuousAttribute.h" -#include "../msvc/vector.h" +#include "Vector.h" namespace plasma { class Display : public plasma::Keyable { public: plasma::DiscreteAttribute visibility; plasma::DiscreteAttribute clipping; - plasma::ContinuousAttribute> fill; - plasma::ContinuousAttribute> stroke; + plasma::ContinuousAttribute> fill; + plasma::ContinuousAttribute> stroke; plasma::ContinuousAttribute blurRadius; _BYTE gap318[31]; char end; diff --git a/cwmods/plasma/Vector.cpp b/cwmods/plasma/Vector.cpp new file mode 100644 index 0000000..1a0d306 --- /dev/null +++ b/cwmods/plasma/Vector.cpp @@ -0,0 +1 @@ +#include "Vector.h" diff --git a/cwmods/plasma/Vector.h b/cwmods/plasma/Vector.h new file mode 100644 index 0000000..f614b13 --- /dev/null +++ b/cwmods/plasma/Vector.h @@ -0,0 +1,21 @@ +#ifndef PLASMA_VECTOR_H +#define PLASMA_VECTOR_H + + +namespace plasma { + template + class Vector { + public: + T elements[N]; + + T Get(int i) { + return elements[i]; + } + + void Set(int i, T x) { + elements[i] = x; + } + }; +} + +#endif // PLASMA_VECTOR_H diff --git a/main.cpp b/main.cpp index bb63bfc..7f920bc 100644 --- a/main.cpp +++ b/main.cpp @@ -17,7 +17,7 @@ float GetMilliseconds(int hour, int minute) { return (hour * 60 * 60 * 1000) + (minute * 60 * 1000); } -void CommandsModMessage(wchar_t message[]) { +void CommandsModMessage(const wchar_t* message) { cube::Game* game = cube::GetGame(); game->PrintMessage(L"["); game->PrintMessage(L"CommandsMod", 255, 140, 0); @@ -138,17 +138,17 @@ bool IsBlockedID(long long steamID) { return false; } -void PrintCommandName(wchar_t* name) { +void PrintCommandName(const wchar_t* name) { cube::Game* game = cube::GetGame(); game->PrintMessage(name, 66, 161, 245); } -void PrintCommandArg(wchar_t* arg) { +void PrintCommandArg(const wchar_t* arg) { cube::Game* game = cube::GetGame(); game->PrintMessage(arg, 139, 209, 42); } -void PrintCommand(wchar_t* command, wchar_t* args, wchar_t* message) { +void PrintCommand(const wchar_t* command, const wchar_t* args, const wchar_t* message) { cube::Game* game = cube::GetGame(); PrintCommandName(command); game->PrintMessage(L" "); @@ -170,6 +170,7 @@ void Help(int page) { PrintCommand(L"/help", L"[number]", L"get help"); PrintCommand(L"/coords", L"", L"display world coords"); PrintCommand(L"/tp", L" ", L"teleport in terms of map coords"); + PrintCommand(L"/tp", L"", L"teleport to the specified player location"); PrintCommand(L"/settime", L":", L"set time"); PrintCommand(L"/name", L"", L"change your name"); break; @@ -190,6 +191,7 @@ void Help(int page) { PrintCommand(L"/tpmap", L"", L"Teleport to cursor position on map"); PrintCommand(L"/sethome", L"", L"Set player position as home"); PrintCommand(L"/home", L"", L"Teleport to home position by alias"); + PrintCommand(L"/gui", L"chat ", L"Set GUI Widget size"); break; default: CommandsModMessage( L"Invalid page number!\n"); @@ -248,6 +250,34 @@ EXPORT int HandleChat(wchar_t* msg) { CommandsModMessage(L"Teleporting.\n"); return 1; + } else if ( swscanf(msg, L"/gui chat %d %d", &targetx, &targety) == 2) { + game->gui.chat_widget->width = targetx; + game->gui.chat_widget->height = targety; + CommandsModMessage(L"GUI Chat Widget size changed.\n"); + return 1; + + } else if ( !wcsncmp(msg, L"/tp ", 4) ) { + wchar_t* wideName = &msg[4]; + char* cName = new char[wcslen(wideName)+1]; + int len = wcstombs(cName, wideName, 0x100); + if (len < 1) { + CommandsModMessage(L"Invalid name.\n"); + return 1; + } + for(cube::Creature* creature: game->world->creatures) { + if (stricmp(creature->name, cName) == 0) { + cube::Creature* player = game->GetPlayer(); + player->position.x = creature->position.x; + player->position.y = creature->position.y; + player->position.z = creature->position.z; + CommandsModMessage(L"Teleporting.\n"); + return 1; + + } + } + CommandsModMessage(L"Target not found.\n"); + return 0; + } else if (!wcscmp(msg, L"/tpmap")) { if(game->worldmap->cursor_position.x != 0x7FFFFFFF0000) { LongVector3 position = game->worldmap->cursor_position;