-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInventory.cpp
More file actions
83 lines (59 loc) · 1.65 KB
/
Inventory.cpp
File metadata and controls
83 lines (59 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//================================================//
#include "Inventory.hpp"
//================================================//
Inventory::Inventory(void)
{
memset(m_weapons, 0, sizeof(m_weapons));
// Generate our first xor values
this->newXor(MAGIC_CUBES);
this->setDefaults();
}
//================================================//
Inventory::~Inventory(void)
{
}
//================================================//
void Inventory::newXor(unsigned int index)
{
// This is a simple hack to prevent easy run-time hacking
// by preventing someone from just searching for the value in memory.
m_xor[index] = Ogre::Math::RangeRandom(0, 10000);
}
//================================================//
void Inventory::setDefaults(void)
{
m_magicCubes = 0;
m_magicCubes ^= m_xor[MAGIC_CUBES];
m_weapons[0] = Weapon::NONE;
m_weapons[1] = Weapon::TEST_GUN;
m_weapons[2] = Weapon::TEST_SWORD;
m_weapons[3] = Weapon::NONE;
}
//================================================//
void Inventory::addMagicCube(void)
{
// Decrypt with current key
m_magicCubes ^= m_xor[MAGIC_CUBES];
m_magicCubes++;
// Generate new key and encrypt
this->newXor(MAGIC_CUBES);
m_magicCubes ^= m_xor[MAGIC_CUBES];
}
//================================================//
const unsigned int Inventory::getCount(int type)
{
// Decrypt the right value and return it, after encrypting it back
unsigned int count = 0;
switch(type){
default:
break;
case MAGIC_CUBES:
m_magicCubes ^= m_xor[MAGIC_CUBES];
count = m_magicCubes;
this->newXor(MAGIC_CUBES);
m_magicCubes ^= m_xor[MAGIC_CUBES];
break;
}
return count;
}
//================================================//