pvpgn-twilight 0.1.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Changes CHANGED
@@ -34,4 +34,16 @@ Version 0.1.0
34
34
  - Changed text formats to UNIX style
35
35
 
36
36
  Version 0.1.1
37
- - Changed some code to make this Linux/g++ compatable
37
+ - Changed some code to make this Linux/g++ compatable
38
+
39
+ Version 0.2.0
40
+ - Reverted to C code to avoid some weird linux linkage bug
41
+
42
+ Version 0.2.1
43
+ - Bugs fixes from the conversion
44
+
45
+ Version 0.2.2
46
+ - Added some macros for quick exporting to ruby
47
+
48
+ Version 0.2.3
49
+ - Test release
@@ -1,8 +1,8 @@
1
1
  # Loads mkmf which is used to make makefiles for Ruby extensions
2
2
  require 'mkmf'
3
3
 
4
- # Do the work
5
- $CC = 'g++'
6
- $CXX = $CC
7
- cpp_command('g++')
8
- create_makefile('pvpgn')
4
+ # C++ removed...
5
+ #$CC = 'g++'
6
+ #$CXX = $CC
7
+ #cpp_command('g++') if RUBY_VERSION < '1.9'
8
+ create_makefile('pvpgn')
@@ -0,0 +1,373 @@
1
+ #define PVPGN_TWILIGHT_VERSION "0.2.3"
2
+ #define PVPGN_TWILIGHT_MODULE "PVPGN"
3
+ //#define __TEST__
4
+ /**************************************************/
5
+ /*/ /*/
6
+ /*/ Comments & Notes /*/
7
+ /*/ /*/
8
+ /**************************************************/
9
+ /*
10
+ Sat, 2 Jan 2010, 8:43am: This is all 1 file for now so that it is easy to use
11
+ gonna fix it later when stuff gets bigger...
12
+
13
+ Mon, 1 Feb 2010, 6:12pm: converted core to ANSI C, to avoid wierd
14
+ linux/ruby linkage bug
15
+ */
16
+
17
+ #ifdef __TEST__
18
+ #include <stdio.h>
19
+ #else
20
+ //#include "d2bitstream.h"
21
+ //#include "twilight.h"
22
+ #include "ruby.h"
23
+ #endif
24
+
25
+ //bit rotation macros, instead of the MSVC _rotl and _rotr instrisics(takens from pvpgn)
26
+ #define ROTL(x,n,w) (((x) << ((n) & (w - 1))) | ((x) >> (((-(n)) & (w - 1)))))
27
+ #define ROTL32(x,n) ROTL(x,n,32)
28
+ #define ROTL16(x,n) ROTL(x,n,16)
29
+
30
+ //The Ruby Module Name
31
+ #define RUBY_Module vModule
32
+ //Register a varibale arg func
33
+ #define RUBY_RegisterFunc(x) rb_define_module_function(RUBY_Module,#x,RUBY_##x,-1)
34
+ //Register a set arg func
35
+ #define RUBY_RegisterFuncEx(x,a) rb_define_module_function(RUBY_Module,#x,RUBY_##x,a)
36
+ //Register a new class, returns a VALUE
37
+ #define RUBY_RegisterClass(c) rb_define_class_under(RUBY_Module,#c,rb_cObject)
38
+ //Register an allocator for this class
39
+ #define RUBY_RegisterClassAlloc(c,x) rb_define_alloc_func(c,x)
40
+ //Register a variable arg func for a class
41
+ #define RUBY_RegisterClassFunc(c,x) rb_define_method(c,#x,x,-1)
42
+ //Register a set arg func for a class
43
+ #define RUBY_RegisterClassFunc(c,x,a) rb_define_method(c,#x,x,a)
44
+
45
+
46
+ /**************************************************/
47
+ /*/ /*/
48
+ /*/ D2GS & Diablo II /*/
49
+ /*/ /*/
50
+ /**************************************************/
51
+ /*
52
+ //removed pending C conversion :(
53
+ class cD2SaveFile
54
+ {
55
+ public:
56
+ enum eD2GameFlags
57
+ {
58
+ GFLAG_NEWBIE = 0x001,
59
+ GFLAG_HARDCORE = 0x004,
60
+ GFLAG_HASDIED = 0x008,
61
+ GFLAG_EXPANSION = 0x020,
62
+ GFLAG_NOTLADDER = 0x040
63
+ };
64
+
65
+ protected:
66
+ char szName[16];
67
+ int nLevel;
68
+ int nClass;
69
+ uint_32 fFlags;
70
+ int nDifficulty;
71
+ int nAct;
72
+
73
+ public:
74
+ //object core
75
+ cD2SaveFile(const char* szName);
76
+ ~cD2SaveFile();
77
+
78
+ //funcs
79
+
80
+ //inlines
81
+ inline const char* GetClass() const
82
+ {
83
+ static const char* szClasses[7] =
84
+ {
85
+ "Amazon",
86
+ "Sorceress",
87
+ "Necromancer",
88
+ "Paladin",
89
+ "Barberian",
90
+ "Druid",
91
+ "Assassin"
92
+ };
93
+
94
+ return szClasses[nClass];
95
+ }
96
+
97
+ inline int GetLevel() const
98
+ {
99
+ return nLevel;
100
+ }
101
+
102
+ inline int GetDifficulty() const
103
+ {
104
+ return nDifficulty;
105
+ }
106
+
107
+ inline int GetAct() const
108
+ {
109
+ return nAct;
110
+ }
111
+
112
+ inline bool CheckFlag(uint_32 fFlag)
113
+ {
114
+ return (fFlags & fFlag);
115
+ }
116
+
117
+ //statics
118
+ };*/
119
+
120
+ /******* TODO ********/
121
+ // - base stat parsing
122
+ // - item parsing
123
+ // - skill parsing
124
+ // - merc data
125
+ // - ???
126
+ // - profit!
127
+
128
+ //needs the trading stuff - item parsing basically
129
+
130
+ //needs the shared stash stuff - more item parsing plus some block management
131
+
132
+ //needs to be converted into a struct now :/
133
+
134
+ /**************************************************/
135
+ /*/ /*/
136
+ /*/ PVPGN /*/
137
+ /*/ /*/
138
+ /**************************************************/
139
+
140
+ static void PVPGN_Hash(unsigned long* pHash, unsigned long* pTemp)
141
+ {
142
+ unsigned long i;
143
+ unsigned long a;
144
+ unsigned long b;
145
+ unsigned long c;
146
+ unsigned long d;
147
+ unsigned long e;
148
+ unsigned long g;
149
+
150
+ for(i = 0; i < 64; i++)
151
+ {
152
+ pTemp[i + 16] = ROTL32(1,pTemp[i] ^ pTemp[i + 8] ^ pTemp[i + 2] ^ pTemp[i + 13]);
153
+ }
154
+
155
+ a = pHash[0];
156
+ b = pHash[1];
157
+ c = pHash[2];
158
+ d = pHash[3];
159
+ e = pHash[4];
160
+
161
+ for(i = 0; i < 20; i++)
162
+ {
163
+ g = pTemp[i] + ROTL32(a,5) + e + ((b & c) | (~b & d)) + 0x5a827999;
164
+ e = d;
165
+ d = c;
166
+ c = ROTL32(b,30);
167
+ b = a;
168
+ a = g;
169
+ }
170
+
171
+ for(; i < 40; i++)
172
+ {
173
+ g = (d ^ c ^ b) + e + ROTL32(g,5) + pTemp[i] + 0x6ed9eba1;
174
+ e = d;
175
+ d = c;
176
+ c = ROTL32(b,30);
177
+ b = a;
178
+ a = g;
179
+ }
180
+
181
+ for (; i < 60; i++)
182
+ {
183
+ g = pTemp[i] + ROTL32(g,5) + e + ((c & b) | (d & c) | (d & b)) - 0x70e44324;
184
+ e = d;
185
+ d = c;
186
+ c = ROTL32(b,30);
187
+ b = a;
188
+ a = g;
189
+ }
190
+
191
+ for (; i < 80; i++)
192
+ {
193
+ g = (d ^ c ^ b) + e + ROTL32(g,5) + pTemp[i] - 0x359d3e2a;
194
+ e = d;
195
+ d = c;
196
+ c = ROTL32(b,30);
197
+ b = a;
198
+ a = g;
199
+ }
200
+
201
+ pHash[0] += g;
202
+ pHash[1] += b;
203
+ pHash[2] += c;
204
+ pHash[3] += d;
205
+ pHash[4] += e;
206
+ }
207
+
208
+ static void PVPGN_Set16(unsigned long* pDest, const unsigned char* pSource, signed int nSize)
209
+ {
210
+ unsigned long i;
211
+ unsigned long dwPos;
212
+
213
+ if(pDest == 0 || pSource == 0 || nSize < 0)
214
+ {
215
+ return;
216
+ }
217
+
218
+ for(dwPos = 0, i = 0; i < 16; i++)
219
+ {
220
+ pDest[i] = 0;
221
+ if(dwPos < nSize)
222
+ pDest[i] |= ((unsigned long)pSource[dwPos]);
223
+
224
+ dwPos++;
225
+ if(dwPos < nSize)
226
+ pDest[i] |= ((unsigned long)pSource[dwPos]) << 8;
227
+
228
+ dwPos++;
229
+ if(dwPos < nSize)
230
+ pDest[i] |= ((unsigned long)pSource[dwPos]) << 16;
231
+
232
+ dwPos++;
233
+ if(dwPos < nSize)
234
+ pDest[i] |= ((unsigned long)pSource[dwPos]) << 24;
235
+
236
+ dwPos++;
237
+ }
238
+ }
239
+
240
+ static void UTILITY_ToLower(char* pString)
241
+ {
242
+ char nChar;
243
+ if(pString == 0)
244
+ {
245
+ return;
246
+ }
247
+
248
+ while((nChar = *pString))
249
+ {
250
+ *pString++ = ((nChar < 'A' || nChar > 'Z') ? nChar : (nChar + 0x20));
251
+ }
252
+ }
253
+
254
+ static void UTILITY_HexToText(char* pBuffer, unsigned int dwHex, unsigned int bUpper)
255
+ {
256
+ static const char szHex[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
257
+ static const char szHexU[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
258
+ unsigned long i;
259
+
260
+ if(pBuffer == 0)
261
+ {
262
+ return;
263
+ }
264
+
265
+ if(!bUpper)
266
+ {
267
+ for(i = 7; i > -1; i--)
268
+ {
269
+ int nChar;
270
+ nChar = dwHex % 16;
271
+ dwHex >>= 4;
272
+ pBuffer[i] = szHex[nChar];
273
+ }
274
+ }
275
+ else
276
+ {
277
+ for(i = 7; i > -1; i--)
278
+ {
279
+ int nChar;
280
+ nChar = dwHex % 16;
281
+ dwHex >>= 4;
282
+ pBuffer[i] = szHexU[nChar];
283
+ }
284
+ }
285
+ }
286
+
287
+ static char* PVPGN_CreateHash(char* pHash, signed int nSize, char pHashOut[41])
288
+ {
289
+ unsigned long dwLength;
290
+ unsigned long i;
291
+ unsigned char* pData = (unsigned char*)pHash;
292
+ unsigned long dwHash[5] = {0x67452301,0xefcdab89,0x98badcfe,0x10325476,0xc3d2e1f0};
293
+ unsigned long dwTemp[80];
294
+
295
+ if(pHash == 0 || nSize < 1)
296
+ {
297
+ return 0;
298
+ }
299
+
300
+ pHashOut[40] = 0;
301
+ UTILITY_ToLower(pHash);
302
+ while(nSize > 0)
303
+ {
304
+ dwLength = (nSize > 64) ? 64 : nSize;
305
+ PVPGN_Set16(dwTemp,pData,dwLength);
306
+ PVPGN_Hash(dwHash,dwTemp);
307
+ nSize -= dwLength;
308
+ pData += dwLength;
309
+ }
310
+
311
+ for(i = 0; i < 5; i++)
312
+ {
313
+ UTILITY_HexToText(&pHashOut[i * 8],dwHash[i],0);
314
+ }
315
+
316
+ return pHashOut;
317
+ }
318
+
319
+ #ifdef __TEST__
320
+ /**************************************************/
321
+ /*/ /*/
322
+ /*/ Testing /*/
323
+ /*/ /*/
324
+ /**************************************************/
325
+ int main(int argc, char *argv[])
326
+ {
327
+ char szInput[24];
328
+ char szHashOut[41];
329
+ printf("Please Enter Password: ");
330
+ scanf("Please Enter Password: %s",szInput);
331
+ printf("Hash: %s\n",PVPGN_CreateHash(szInput,strlen(szInput),szHashOut));
332
+ system("PAUSE");
333
+ return 0;
334
+ }
335
+ #else
336
+ /**************************************************/
337
+ /*/ /*/
338
+ /*/ Ruby Interface /*/
339
+ /*/ /*/
340
+ /**************************************************/
341
+
342
+ /*
343
+ * call-seq:
344
+ * PVPGN.BNHash(string_to_hash)
345
+ *
346
+ * Creates the PVPGN hash for the give string, it is automatically
347
+ * converted to a lower case string, the input is also automatically
348
+ * converted to lower case
349
+ */
350
+ static VALUE RUBY_BNHash(int argc, VALUE* argv, VALUE klass)
351
+ {
352
+ char szHashOut[41];
353
+ VALUE vPassword;
354
+ char* szPass;
355
+
356
+ if(argc != 1)
357
+ {
358
+ rb_raise(rb_eRuntimeError,"RUBY_BNHash(): Invalid Argument Count");
359
+ }
360
+
361
+ vPassword = argv[0];
362
+ szPass = StringValuePtr(vPassword);
363
+ return rb_str_new2(PVPGN_CreateHash(szPass,strlen(szPass),szHashOut));
364
+ }
365
+
366
+ void Init_pvpgn()
367
+ {
368
+ VALUE RUBY_Module;
369
+
370
+ RUBY_Module = rb_define_module(PVPGN_TWILIGHT_MODULE);
371
+ RUBY_RegisterFunc(BNHash);
372
+ }
373
+ #endif
@@ -1,14 +1,14 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{pvpgn-twilight}
3
- s.version = "0.1.1"
4
- s.date = %q{2009-12-02}
5
- s.authors = ["Lorenzo Boccetti"]
3
+ s.version = "0.2.3"
4
+ s.date = %q{2010-02-04}
5
+ s.authors = ["Lorenzo 'Necrolis' Boccetti"]
6
6
  s.email = %q{necrolis@gamil.com}
7
7
  s.summary = %q{A ruby interface for Twilight PVPGN}
8
8
  s.homepage = %q{http://www.twilightgaming.co.za}
9
9
  s.description = %q{PVPGN-Twilight allows ruby scripts to communicate with pvpgn, while providing faster varients of certain functions, like hashing}
10
- s.files = ["pvpgn-twilight.gemspec","ext/pvpgn.cpp","examples/pvpgn_test.rb","ext/extconf.rb","Changes","docs/pvpgn-twilight.txt","pvpgn-twilight.gemspec"]
10
+ s.files = ["pvpgn-twilight.gemspec","ext/pvpgn.c","examples/pvpgn_test.rb","ext/extconf.rb","Changes","docs/pvpgn-twilight.txt","pvpgn-twilight.gemspec"]
11
11
  s.extensions << 'ext/extconf.rb'
12
12
  s.has_rdoc = true
13
- s.extra_rdoc_files = ["Changes","ext/pvpgn.cpp","docs/pvpgn-twilight.txt"]
13
+ s.extra_rdoc_files = ["Changes","ext/pvpgn.c","docs/pvpgn-twilight.txt"]
14
14
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pvpgn-twilight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
- - Lorenzo Boccetti
7
+ - Lorenzo 'Necrolis' Boccetti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-02 00:00:00 +02:00
12
+ date: 2010-02-04 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -21,11 +21,11 @@ extensions:
21
21
  - ext/extconf.rb
22
22
  extra_rdoc_files:
23
23
  - Changes
24
- - ext/pvpgn.cpp
24
+ - ext/pvpgn.c
25
25
  - docs/pvpgn-twilight.txt
26
26
  files:
27
27
  - pvpgn-twilight.gemspec
28
- - ext/pvpgn.cpp
28
+ - ext/pvpgn.c
29
29
  - examples/pvpgn_test.rb
30
30
  - ext/extconf.rb
31
31
  - Changes
@@ -1,206 +0,0 @@
1
- #define PVPGN_TWILIGHT_VERSION "0.1.0"
2
-
3
- #ifdef __TEST__
4
- #include <iostream>
5
- #else
6
- #include "ruby.h"
7
- #endif
8
-
9
- typedef unsigned int t_uint32;
10
- typedef signed int t_sint32;
11
-
12
- #define ROTL(x,n,w) (((x)<<((n)&(w-1))) | ((x)>>(((-(n))&(w-1)))))
13
-
14
- #define ROTL32(x,n) ROTL(x,n,32)
15
- #define ROTL16(x,n) ROTL(x,n,16)
16
-
17
- static void PVPGN_Hash(t_uint32* pHash, t_uint32* pTemp)
18
- {
19
- t_uint32 i;
20
-
21
- for(i = 0; i < 64; i++)
22
- pTemp[i + 16] = ROTL32(1,pTemp[i] ^ pTemp[i + 8] ^ pTemp[i + 2] ^ pTemp[i + 13]);
23
-
24
- t_uint32 a = pHash[0];
25
- t_uint32 b = pHash[1];
26
- t_uint32 c = pHash[2];
27
- t_uint32 d = pHash[3];
28
- t_uint32 e = pHash[4];
29
- t_uint32 g;
30
-
31
- for(i = 0; i < 20; i++)
32
- {
33
- g = pTemp[i] + ROTL32(a,5) + e + ((b & c) | (~b & d)) + 0x5a827999;
34
- e = d;
35
- d = c;
36
- c = ROTL32(b,30);
37
- b = a;
38
- a = g;
39
- }
40
-
41
- for(; i < 40; i++)
42
- {
43
- g = (d ^ c ^ b) + e + ROTL32(g,5) + pTemp[i] + 0x6ed9eba1;
44
- e = d;
45
- d = c;
46
- c = ROTL32(b,30);
47
- b = a;
48
- a = g;
49
- }
50
-
51
- for (; i < 60; i++)
52
- {
53
- g = pTemp[i] + ROTL32(g,5) + e + ((c & b) | (d & c) | (d & b)) - 0x70e44324;
54
- e = d;
55
- d = c;
56
- c = ROTL32(b,30);
57
- b = a;
58
- a = g;
59
- }
60
-
61
- for (; i < 80; i++)
62
- {
63
- g = (d ^ c ^ b) + e + ROTL32(g,5) + pTemp[i] - 0x359d3e2a;
64
- e = d;
65
- d = c;
66
- c = ROTL32(b,30);
67
- b = a;
68
- a = g;
69
- }
70
-
71
- pHash[0] += g;
72
- pHash[1] += b;
73
- pHash[2] += c;
74
- pHash[3] += d;
75
- pHash[4] += e;
76
- }
77
-
78
- static void PVPGN_Set16(t_uint32* pDest, const unsigned char* pSource, t_sint32 nSize)
79
- {
80
- if(pDest == NULL || pSource == NULL || nSize < 0)
81
- return;
82
-
83
- t_uint32 i, dwPos;
84
- for(dwPos = 0, i = 0; i < 16; i++)
85
- {
86
- pDest[i] = 0;
87
- if(dwPos < nSize)
88
- pDest[i] |= ((t_uint32)pSource[dwPos]);
89
-
90
- dwPos++;
91
- if(dwPos < nSize)
92
- pDest[i] |= ((t_uint32)pSource[dwPos]) << 8;
93
-
94
- dwPos++;
95
- if(dwPos < nSize)
96
- pDest[i] |= ((t_uint32)pSource[dwPos]) << 16;
97
-
98
- dwPos++;
99
- if(dwPos < nSize)
100
- pDest[i] |= ((t_uint32)pSource[dwPos]) << 24;
101
-
102
- dwPos++;
103
- }
104
- }
105
-
106
- static void UTILITY_ToLower(char* pString)
107
- {
108
- if(pString == NULL)
109
- return;
110
-
111
- char nChar = 0;
112
- while((nChar = *pString))
113
- *pString++ = ((nChar < 'A' || nChar > 'Z') ? nChar : (nChar + 0x20));
114
- }
115
-
116
- static void UTILITY_HexToText(char* pBuffer, t_uint32 dwHex, t_uint32 bUpper = 0)
117
- {
118
- if(pBuffer == NULL)
119
- return;
120
-
121
- static const char szHex[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
122
- static const char szHexU[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
123
- int i;
124
- if(!bUpper)
125
- {
126
- for(i = 7; i > -1; i--)
127
- {
128
- int nChar = dwHex % 16;
129
- dwHex >>= 4;
130
- pBuffer[i] = szHex[nChar];
131
- }
132
- }
133
- else
134
- {
135
- for(i = 7; i > -1; i--)
136
- {
137
- int nChar = dwHex % 16;
138
- dwHex >>= 4;
139
- pBuffer[i] = szHexU[nChar];
140
- }
141
- }
142
- }
143
-
144
- static char* PVPGN_CreateHash(char* pHash, t_sint32 nSize, char pHashOut[41])
145
- {
146
- if(pHash == NULL || nSize < 1)
147
- return NULL;
148
-
149
- t_uint32 dwLength = 0, i;
150
- unsigned char* pData = (unsigned char*)pHash;
151
- t_uint32 dwHash[5] = {0x67452301,0xefcdab89,0x98badcfe,0x10325476,0xc3d2e1f0};
152
- t_uint32 dwTemp[80];
153
-
154
- pHashOut[40] = 0;
155
- UTILITY_ToLower(pHash);
156
- while(nSize > 0)
157
- {
158
- dwLength = (nSize > 64) ? 64 : nSize;
159
- PVPGN_Set16(dwTemp,pData,dwLength);
160
- PVPGN_Hash(dwHash,dwTemp);
161
- nSize -= dwLength;
162
- pData += dwLength;
163
- }
164
-
165
- for(i = 0; i < 5; i++)
166
- UTILITY_HexToText(&pHashOut[i * 8],dwHash[i]);
167
-
168
- return pHashOut;
169
- }
170
- #ifdef __TEST__
171
- int main(int argc, char *argv[])
172
- {
173
- std::string sInput;
174
- std::cout << "Please Enter Password: ";
175
- std::cin >> sInput;
176
- std::cout << "Hash: " << PVPGN_CreateHash((char*)sInput.c_str(),sInput.size()) << std::endl;
177
- system("PAUSE");
178
- return 0;
179
- }
180
- #else
181
- /*
182
- * call-seq:
183
- * PVPGN.BNHash(string_to_hash)
184
- *
185
- * Creates the PVPGN hash for the give string, it is automatically
186
- * converted to a lower case string, the input is also automatically
187
- * converted to lower case
188
- */
189
- static VALUE RUBY_BNHash(int argc, VALUE* argv, VALUE klass)
190
- {
191
- char szHashOut[41];
192
- VALUE vPassword;
193
- if(argc != 1)
194
- rb_raise(rb_eRuntimeError,"RUBY_BNHash(): Invalid Amount of Arguments");
195
-
196
- vPassword = argv[0];
197
- char* szPass = StringValuePtr(vPassword);
198
- return rb_str_new2(PVPGN_CreateHash(szPass,strlen(szPass),szHashOut));
199
- }
200
-
201
- void Init_pvpgn()
202
- {
203
- static VALUE mPVPGN = rb_define_module("PVPGN");
204
- rb_define_module_function(mPVPGN,"BNHash",(VALUE (*)(...))RUBY_BNHash,-1);
205
- }
206
- #endif