Skip to content
This repository was archived by the owner on Aug 19, 2024. It is now read-only.

Commit 539bb66

Browse files
committed
Bulk commit of sdk changes
1 parent 1aba1f8 commit 539bb66

21 files changed

Lines changed: 598 additions & 141 deletions

cwsdk/Matrix4x4.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "Matrix4x4.h"

cwsdk/Matrix4x4.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
3+
#include "Vector3.h"
4+
#include <math.h>
5+
6+
struct Matrix4x4 {
7+
// Thrown together from
8+
// https://gamedev.stackexchange.com/questions/50963/how-to-extract-euler-angles-from-transformation-matrix
9+
// and
10+
// http://nghiaho.com/?page_id=846
11+
union {
12+
struct
13+
{
14+
float _11, _12, _13, _14;
15+
float _21, _22, _23, _24;
16+
float _31, _32, _33, _34;
17+
float _41, _42, _43, _44;
18+
};
19+
float m[4][4];
20+
};
21+
};

cwsdk/Vector3.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#include "Vector3.h"
22
#include "cube_funcs.h"
33

4+
/*
45
void Vector3<int64_t>::LoadFromVector3_float(Vector3<float>* vf)
56
{
67
cube_funcs::instance()->vec3_int64_fom_vec3_float(this, vf);
78
};
9+
*/

cwsdk/Vector3.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,24 @@ class Vector3
1111
T Z = 0;
1212

1313
Vector3() {};
14+
Vector3(T x, T y, T z) : X(x), Y(y), Z(z) {}
1415
~Vector3() {};
15-
1616
};
1717

18+
/*
1819
// Class specialization for int64_t, mainly used for world positions, so special functions on there.
1920
template <>
2021
class Vector3<int64_t> {
2122
public:
2223
int64_t X = 0;
2324
int64_t Y = 0;
2425
int64_t Z = 0;
26+
Vector3() {};
27+
Vector3(int64_t x, int64_t y, int64_t z) : X(x), Y(y), Z(z) {}
28+
~Vector3() {};
2529
void LoadFromVector3_float(Vector3<float>* vf);
2630
};
27-
31+
*/
2832

2933

3034

cwsdk/cube.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,15 @@
44
#include <Windows.h>
55
#include "msvc_bincompat.h"
66
#include "cube_funcs.h"
7-
8-
#include "./cube/ChatWidget.h"
9-
#include "./cube/Chunk.h"
10-
#include "./cube/Creature.h"
11-
#include "./cube/Field.h"
12-
#include "./cube/GameController.h"
13-
#include "./cube/Region.h"
14-
#include "./cube/World.h"
15-
#include "./cube/Zone.h"
7+
#include "globals.h"
168

179
namespace cube {
1810
GameController* GetGameController() {
1911
auto imageBase = (uint32_t)GetModuleHandleA(NULL);
2012
GameController* gc = *(GameController**)(imageBase + 0x36B1C8);
2113
return gc;
2214
}
15+
void InitAPI() {
16+
InitGlobals();
17+
}
2318
};

cwsdk/cube.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
#pragma once
2-
#include "cube\GameController.h"
2+
3+
#include "memory_management.h"
4+
5+
#include "./cube/GameController.h"
6+
#include "./cube/ChatWidget.h"
7+
#include "./cube/Chunk.h"
8+
#include "./cube/Creature.h"
9+
#include "./cube/Field.h"
10+
#include "./cube/GameController.h"
11+
#include "./cube/Region.h"
12+
#include "./cube/World.h"
13+
#include "./cube/Zone.h"
14+
#include "./cube/Speech.h"
15+
16+
#include "cube_util.h"
317

418
namespace cube {
519
GameController* GetGameController();
20+
void InitAPI();
621
}

cwsdk/cube/Creature.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,69 @@
11
#include "Creature.h"
2+
#include <math.h>
3+
#include <locale>
4+
#include <codecvt>
5+
#include <string>
6+
7+
#include "../msvc_bincompat.h"
8+
#include "../cube_funcs.h"
29

310
namespace cube {
11+
std::wstring Creature::GetName()
12+
{
13+
auto len = strnlen_s(this->name, 16);
14+
if (len == 0)
15+
{
16+
17+
MSVCBinCompat::wstring compat;
18+
if (this->hostility_flags == 3 || this->movement_flags & 0x200)
19+
{
20+
// "Rare" creature names
21+
cube_funcs::instance()->generate_rare_creature_name(&compat, (uint32_t)this->GUID, this->race);
22+
return compat;
23+
}
24+
else
25+
{
26+
// "Normal" creature names.
27+
28+
// This is AWFUL for performance because it copies out the entire map. please fix me when I implement search in MSVCBinCompat::map.
29+
auto gc = cube::GetGameController();
30+
auto entity_localization_map = gc->world.EntityNames->CopyToSTDMap();
31+
auto localization_key = entity_localization_map.find(this->race);
32+
if (localization_key == entity_localization_map.end())
33+
{
34+
return compat;
35+
}
36+
else
37+
{
38+
MSVCBinCompat::wstring out;
39+
MSVCBinCompat::wstring key = localization_key->second;
40+
MSVCBinCompat::wstring word_form = L"singular";
41+
42+
cube_funcs::instance()->speech_get_localization_from_dict(&gc->world.speech, &out, &key, word_form);
43+
44+
return out;
45+
}
46+
}
47+
}
48+
else
49+
{
50+
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
51+
std::wstring wide = converter.from_bytes(this->name);
52+
return wide;
53+
}
54+
}
55+
56+
double Creature::DistanceFrom(Vector3<int64_t> point) {
57+
auto p1 = this->position;
58+
auto p2 = point;
59+
60+
auto x = p1.X - p2.X;
61+
auto y = p1.Y - p2.Y;
62+
auto z = p1.Z - p2.Z;
63+
64+
return sqrt((x*x) + (y*y) + (z*z));
65+
}
66+
double Creature::DistanceFrom(Creature* target) {
67+
return DistanceFrom(target->position);
68+
}
469
};

0 commit comments

Comments
 (0)