summaryrefslogtreecommitdiff
path: root/csrc/cards.c
blob: 29e6a29f17e20b0a4aed0e3a2516ad49aa3e195a (plain)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
#include "player_info.h"

typedef int (*card_func)(void);

card_func card_functions[] = { // 0x475d5c
	NULL,
	average_cash_card,
	average_cash_card2,
	buy_land_card,
	swap_land_card,
	swap_house_card,
	turn_back_card,
	restruct_card,
   	0x00443225U, 0x004434c0U,
  0x004436e0U, 0x00443917U, 0x00443b0fU, 0x00443e3dU, 0x00443f80U,
  0x004440eaU, 0x004441dcU, 0x004444bfU, 0x004420d5U, 0x004420d5U,
  0x004420d5U, 0x004420d5U, 0x00444c45U, 0x00444e1aU, 0x00444f25U,
  0x0044503fU, 0x004451f0U, 0x0044542dU, 0x00445593U, 0x00445710U,
  0x004458dfU, 0x446afb00U, 0x446baa00U, 0x446c8800U, 0x446d6900U

};

uint8_t card_amount[30]; /* 0x499198 */

void consume_a_card(int p, int c)
{
	int i = 0;

	while (1) {
		int card = player_cards[p*15+i];
		if (card != c) {
			i++;
			if (i >= 15)
				return;
		} else {
			break;
		}
	}

	memcpy(&player_cards[p*15+i], &player_cards[p*15+i+1], 14-i);
	player_cards[p * 15 + 14] = 0;
	card_amount[c-1]++;
}

// 0x4420d8
int average_cash_card()
{
	int sum = 0;
	int player_count = 0;

	consume_a_card(current_player, 1);
	eax = (int)players[current_player].character * 360;
	mov ebx, dword [eax + 0x48123a] ;
	fcn.0044ef41(current_player, 3, ebx);

	for (int i = 0; i < nplayers; i++) {
		if (players[i].f21 != 0) {
			sum += players[i].cash;
			player_count++;
		}
	}
	int average = sum / player_count;
	for (int i = 0; i < nplayers; i++) {
		if (players[i].f21 == 0) {
			continue;
		}
		if (average >= players[i].cash) {
			players[i].cash = average;
			continue;
		}
		fcn.0040df69(i, current_player, average / 100);
		players[i].cash = average;
	}
	fcn.0041d433(current_player);
	return 1;
}

// 0x004421b4
int average_cash_card2()
{
	int res;
	if (players[current_player].who_plays == 1) {
		res = fcn.00446ae8(0xe0c0410);
	} else {
		res = fcn.0041e6f2(0);
	}

	if (result == 0)
		return 0;

	consume_a_card(current_player, 2);
	eax = players[current_player].character * 360;
	edi = dword [eax + 0x48123e];
	fcn.0044ef41(current_player, 3, edi);
	ebp = edi = eax = fcn.0040d293(result);
	
	edx = players[current_player].cash;
	esi = players[edi].cash;
	edx += esi;
	esi = edx / 2; /* round to zero */
	eax = players[edi].cash;
	if (esi < eax)  {
		edx = eax - esi;
		fcn.0040df69(edi, current_player, edx / 100);
	}

	players[current_player].cash = esi;
	players[ebp].cash = esi;
	if (players[current_player].who_plays != 1) {
		sub.WINMM.dll_timeGetTime_669(0, 
				players[current_player].f8, players[current_player].f10,
				players[ebp].f8, players[ebp].f10, 100);
	}
	fcn.0041d433(current_player);
	eax = players[ebp].character * 360;
	edi = dword [eax + 0x48132e];
	fcn.0044ef41(ebp, 1, edi);
	fcn_41d546();
	return result;
}

// 0x442325
int buy_land_card()
{
	esi = 0;
	ecx = players[current_player].f12;
	eax = ecx * 5;
	ecx = dw_498e80;
	eax = word [ecx + eax*8 + 0x20] & 0xffff;
	if (eax > 2000 && eax < 4000) {
		eax -= 2000;
		eax *= 52;
		ebx = dw_498e84 + eax;
		cl = byte [ebx + 0x19];
		if (cl == 0 || cl == current_player+1) {
			if (esi != 0) {
				consume_a_card(current_player, 3);
			}
			return esi;
		}
		edi = (uint8_t) byte [ebx + 0x1a];
		ecx = (uint16_t) word [ebx + 0x1e];
		edi *= ecx; // imul edi, ecx
		ecx = (uint16_t) word [ebx + 0x1c];
		edi += ecx;
		edi *= price_index; // imul edi, dword [0x4990e8]
		if (edi > players[current_player].cash) {
			fcn.00440cac(0x46530c, 1500);
			if (esi != 0) {
				consume_a_card(current_player, 3);
			}
			return esi;
		}

		esi = cl - 1;
		eax = price_index;
		ecx *= eax; // imul ecx, eax
		[esp] = ecx;
		fild dword [esp];
		eax = (uint8_t)byte [ebx + 0x1a];
		[esp+4] = eax;
		fild word [local_4h];
		fadd dword [0x46531c];
		fdiv dword [0x465320];
		fmulp st(1);
		sub esp, 8;
		fstp qword [esp];
		fcn.0040df69(esi, current_player);
		edx = players[current_player].character;
		eax = edx * 360;
		ebp = dword [eax + 0x481242];
		fcn.0044ef41(ecx, 3, ebp);
		al = current_player + 1;
		byte [ebx + 0x19] = al;
		fcn.0040a4e1(0);
		edx = dw_499110;
		if (edx != 0) {
			ecx = dword [edx*4 + 0x4751f0];
			[ebx + 0x30] = eax = fcn.004521cb(*(uint32_t*)&global_rich4_cfg.day, ecx);
		}
		fcn.0041d2c6(current_player, esi, edi, 0);
		edx = players[esi].character;
		eax = edx * 360;
		edx = dword [eax + 0x481332];
		fcn.0044ef41(esi, 1, edx);
		fcn_41d546();
		consume_a_card(current_player, 3);
		return 1;
	}
	// 4424be
	if (eax > 4000 && eax < 6000) {
		eax -= 4000;
		eax *= 56;
		ebx = dw_498e88 + eax;
		if (byte [ebx + 0x19] != 0) {
			eax = byte [ebx + 0x19];
			edx = current_player + 1;
			if (eax != edx) {
				edx = (uint8_t)byte [ebx + 0x1a];
				ecx = (uint16_t)word [ebx + 0x24];
				edx *= ecx; // imul edx, ecx
				ecx = (uint16_t)word [ebx + 0x22];
				edi = ecx + edx;
				edi *= price_index; // imul edi, dword [0x4990e8]
				if (edi <= players[current_player].cash) {
					esi = eax - 1;
					eax = price_index;
					ecx *= eax; // imul ecx, eax
					[esp] = ecx;
					fild dword [esp];
					eax = (uint8_t) byte [ebx + 0x1a];
					[esp+4] = eax;
					fild word [local_4h];
					fadd dword [0x46531c];
					fdiv dword [0x465320];
					fmulp st(1);
					sub esp, 8;
					fstp qword [esp];
					fcn.0040df69(esi, current_player);
					edx = players[current_player].character;
					eax = edx * 360;
					ebp = dword [eax + 0x481242];
					fcn.0044ef41(ecx, 3, ebp);
					al = current_player + 1;
					byte [ebx + 0x19] = al;
					fcn.0040a4e1(0);
					edx = dw_499110;
					if (edx != 0) {
						ecx = dword [edx*4 + 0x4751f0];
						[ebx + 0x34] = eax = fcn.004521cb(*(uint32_t*)&global_rich4_cfg.day, ecx);
					}
					fcn.0041d2c6(current_player, esi, edi, 0);
					edx = players[esi].character;
					eax = edx * 360;
					edx = dword [eax + 0x481332];
					fcn.0044ef41(esi, 1, edx);
					fcn_41d546();
					consume_a_card(current_player, 3);
					return 1;
				}
				fcn.00440cac(0x46530c, 1500);
			}
		}
	}
	if (esi != 0) {
		consume_a_card(current_player, 3);
	}
	return esi;
}

int swap_land_card()
{
	ebx = 0;
	ecx = (uint16_t)players[current_player].f12;
	eax = ecx * 5;
	esi = dw_498e80;
	esi = word [esi + eax*8 + 0x20] & 0xffff;
	if (esi > 2000 && esi < 4000) {
		eax = esi - 2000;
		eax = eax * 0x34;
		edi = dw_498e84 + eax;
		if (players[current_player].who_plays == 1) {
			eax = fcn.00446ae8(0xe0c0202);
		} else {
			eax = fcn.0041e6f2(0);
		}
		ebx = eax;
		if (ebx == 0) {
			return 0;
		}
		fcn.00456c0a(dw_474938, 0x2f440, esi, 0xffff);
		fcn.00456c0a(dw_474938, 0x2f440, ebx, 0xffff);
		ebx -= 2000;
		ebx = ebx * 0x34;
		esi = dw_498e84 + ebx;
		ebx = (uint8_t)byte [edi + 0x19];
		eax = (uint8_t)bype [esi + 0x19];
		[esp] = eax;
		eax = current_player + 1;
		if (ebx == eax && eax != [esp] && byte [esi + 0x1a] >= byte [edi + 0x1a]) {
			ecx = ebx - 1;
			edx = players[ecx].character;
			eax = edx * 360;
			edx = dword [eax + 0x481246];
			fcn.0044ef41(ecx, 3, edx);
		} else {
			// 442736
			eax = current_player + 1;
			if (ebx != eax && eax == [esp] && [edi + 0x1a] >= [esi + 0x1a]) {
				ecx = [esp] - 1;
				edx = (uint8_t)players[ecx].character;
				eax = edx * 360;
				ebp = dword [eax + 0x481246];
				fcn.0044ef41(ecx, 3, ebp);
			}
		}
		// 44277f
		if (players[current_player].who_plays != 1) {
			sub.WINMM.dll_timeGetTime_669(0,
				   	(uint32_t)players[current_player].f8, (uint32_t)players[current_player].f10,
				   	(int)(int16_t)word [esi], (int)(int16_t)word [esi + 2], 100);
		}
		// 4427bb
		byte [esi + 0x19] = bl;
		al = byte [esp];
		[edi + 0x19] = al;
		fcn.0040a4e1(0);
		fcn.00451985();
		player_action_2(0, 0, 1);
		sub.WINMM.dll_timeGetTime_85e(500);
		eax = current_player + 1;
		ebp = [esp];
		if (ebx == eax && eax != ebp && ebp != 0 && byte [esi + 0x1a]  >= byte [edi + 0x1a]) {
			ecx = ebp - 1;
			edx = players[ecx].character;
			eax = edx * 360;
			ebx = dword [eax + 0x481336];
			fcn.0044ef41(ecx, 2, ebx);
		} else {
			// 442836
			eax = current_player + 1;
			if (ebx != eax && ebx != 0 && eax == [esp] && byte [edi + 0x1a] >= byte [esi + 0x1a]) {
				edx = ebx - 1;
				ebx = players[edx].character;
				eax = ebx * 360;
				ecx = dword [eax + 0x481336];
				fcn.0044ef41(edx, 2, ecx);
			}
		}
		consume_a_card(current_player, 4);
		fcn_41d546();
		return 1;
	}
	// 44288c

	if (esi > 4000 && esi < 6000) {
		eax = esi - 4000;
		eax *= 56;
		edi = dw_498e88 + eax;
		if (players[current_player].who_plays == 1) {
			eax = fcn.00446ae8(0xe0c0204);
		} else {
			eax = fcn.0041e6f2(0);
		}
		ebx = eax;
		if (ebx != 0) {
			fcn.00456c0a(dw_474938, 0x2f440, esi, 0xffff);
			fcn.00456c0a(dw_474938, 0x2f440, ebx, 0xffff);
			eax = ebx - 4000;
			eax *= 56;
			esi = dw_498e88 + eax;
			ebx = (uint8_t)byte [edi + 0x19];
			eax = (u8)byte [esi + 0x19];
			[esp] = eax;
			eax = current_player + 1;
			if (ebx == eax && eax != [esp] && byte [esi + 0x1a] >= byte [edi + 0x1a]) {
				ecx = ebx - 1;
				edx = players[current_player].character;
				eax = edx * 360;
				edx = dword [eax + 0x481246];
				fcn.0044ef41(ecx, 3, edx);
			} else {
				eax = current_player + 1;
				if (ebx != eax && eax == [esp] && byte [edi + 0x1a] >= byte [esi + 0x1a]) {
					ecx = [esp] - 1;
					edx = players[ecx].character;
					eax = edx * 360;
					ebp = dword [eax + 0x481246];
					fcn.0044ef41(ecx, 3, ebp);
				}
			}
			// 4429cd
			if (players[current_player].who_plays != 1) {
				sub.WINMM.dll_timeGetTime_669(0,
						(uint32_t)players[current_player].f8, (uint32_t)players[current_player].f10,
						(int)(int16_t)word [esi], (int)(int16_t)word [esi + 2], 100);
			}
			// 442a09
			[esi + 0x19] = bl;
			[edi + 0x19] = byte [esp];
			fcn.0040a4e1(0);
			fcn.00451985();
			player_action_2(0, 0, 1);
			sub.WINMM.dll_timeGetTime_85e(500);
			eax = current_player + 1;
			ebp = [esp];
			if (ebx == eax && eax != ebp && ebp != 0 && byte [esi + 0x1a] >= byte [edi + 0x1a]) {
				ecx = ebp - 1;
				edx = players[ecx].character;
				eax = edx * 360;
				ebx = dword [eax + 0x481336];
				fcn.0044ef41(ecx, 2, ebx);
				consume_a_card(current_player, 4);
				fcn_41d546();
				return 1;
			} else {
				eax = current_player + 1;
				if (ebx != eax && ebx != 0 && eax == [esp] && byte [edi + 0x1a] >= byte [esi + 0x1a]) {
					ebx --;
					edx = players[ebx].character;
					eax = edx * 360;
					ecx = dword [eax + 0x481336];
					fcn.0044ef41(ebx, 2, ecx);
				}
				consume_a_card(current_player, 4);
				fcn_41d546();
				return 1;
			}
		}
	}
	// 442ade
	if (ebx != 0) {
		consume_a_card(current_player, 4);
		fcn_41d546();
	}
	return ebx;
}

int swap_house_card()
{
	ebx = 0;
	edx = players[current_player].f12 * 40;
	eax = dw_498e80;
	eax = word [edx + eax + 0x20] & 0xffff;
	[esp+8] = eax;
	if (eax > 2000 && eax < 4000) {
		eax -= 2000;
		eax = eax * 0x34;
		edx = dw_498e84 + eax;
		[esp+4] = edx;
		if (players[current_player].who_plays == 1) {
			eax = fcn.00446ae8(0xe0c0202);
		} else {
			eax = fcn.0041e6f2(0);
		}
		ebx = eax;
		if (ebx == 0) {
			return 0;
		}
		fcn.00456c0a(dw_474938, 0x2f440, [esp+8], 0xffff);
		fcn.00456c0a(dw_474938, 0x2f440, ebx, 0xffff);
		eax = ebx - 2000;
		eax = eax * 0x34;
		ebp = dw_498e84 + eax;
		edi = [esp+4];
		edi = byte [edi + 0x19];
		esi = byte [ebp + 0x19];
		eax = current_player + 1;
		edx = [esp+4];
		if (edi == eax && esi != eax && byte [ebp+0x1a] >= byte [edx+0x1a]) {
			ecx = edi - 1;
			eax = players[ecx].character * 360;
			edx = dword [eax + 0x48124a];
			fcn.0044ef41(ecx, 3, edx);
		} else {
			eax = current_player + 1;
			int t = [esp+4];
			if (edi != eax && esi == eax && byte [t+0x1a] >= byte [ebp+0x1a]) {
				ecx = esi - 1;
				eax = players[ecx].character * 360;
				edx = dword [eax + 0x48124a];
				fcn.0044ef41(ecx, 3, edx);
			}
		}
		if (players[current_player].who_plays != 1) {
			sub.WINMM.dll_timeGetTime_669(0,
					(uint32_t)players[current_player].f8, (uint32_t)players[current_player].f10,
					(int)(int16_t)word [ebp], (int)(int16_t)word [ebp + 2], 100);
		}
		fcn.00451985();
		sub.WINMM.dll_timeGetTime_4f8([esp+8], ebx);
		eax = current_player + 1;
		t = [esp+4];
		if (edi == eax && esi != eax && esi != 0 && byte [t+0x1a] >= byte [ebp+0x1a]) {
			esi --;
			ebx = players[esi].character;
			eax = ebx * 360;
			edi = dword [eax + 0x48133a];
			fcn.0044ef41(esi, 2, edi);
		} else {
			eax = current_player + 1;
			edx = [esp+4];
			if (edi != eax && edi != 0 && esi == eax) {
				al = [ebp+0x1a];
				edx = [esp+4];
				if (al >= byte [edx + 0x1a]) {
					edi --;
					edx = players[edi].character;
					eax = edx * 360;
					esi = dword [eax + 0x48133a];
					fcn.0044ef41(edi , 2, esi);
				}
			}
		}
		consume_a_card(current_player, 5);
		fcn_41d546();
		return 1;
	}
	//442d3a
	ebp = [esp+8];
	if (ebp > 4000 && ebp < 6000) {
		eax = ebp - 4000;
		eax *= 56;
		edx = dw_498e88 + eax;
		[esp] = edx;
		if (players[current_player].who_plays == 1) {
			eax = fcn.00446ae8(0xe0c0204);
		} else {
			eax = fcn.0041e6f2(0);
		}
		ebx = eax;
		if (ebx != 0) {
			fcn.00456c0a(dw_474938, 0x2f440, [esp+8], 0xffff);
			fcn.00456c0a(dw_474938, 0x2f440, ebx, 0xffff);
			eax = ebx - 4000;
			eax *= 56;
			ebp = dw_498e88 + eax;
			edi = [esp];
			edi = byte [edi + 0x19];
			esi = byte [ebp + 0x19];
			eax = current_player + 1;
			edx = [esp];
			if (edi == eax && esi != eax && byte [ebp+0x1a] >= byte [edx+0x1a]) {
				ecx = edi - 1;
				eax = players[ecx].character * 360;
				edx = dword [eax + 0x48124a];
				fcn.0044ef41(ecx, 3, edx);
			} else {
				eax = current_player + 1;
				t = [esp];
				if (edi != eax && esi == eax && byte [t+0x1a] >= [ebp+0x1a]) {
					ecx = esi - 1;
					eax = players[ecx].character * 360;
					edx = dword [eax + 0x48124a];
					fcn.0044ef41(ecx, 3, edx);
				}
			}
			if (players[current_player].who_plays != 1) {
				sub.WINMM.dll_timeGetTime_669(0,
						(uint32_t)players[current_player].f8, (uint32_t)players[current_player].f10,
						(int)(int16_t)word [ebp], (int)(int16_t)word [ebp + 2], 100);
			}
			fcn.00451985();
			sub.WINMM.dll_timeGetTime_4f8([esp+8], ebx);
			eax = current_player + 1;
			t = [esp];
			if (edi == eax && esi != eax && esi != 0 && byte [t + 0x1a] >= byte [ebp+0x1a]) {
				esi --;
				eax = players[esi].character * 360;
				edi = dword [eax + 0x48133a];
				fcn.0044ef41(esi, 2, edi);
				consume_a_card(current_player, 5);
				fcn_41d546();
				return 1;
			}
			eax = current_player + 1;
			if (edi == eax || edi == 0 || esi != eax) {
				consume_a_card(current_player, 5);
				fcn_41d546();
				return 1;
			}
			al = byte [ebp + 0x1a];
			edx = [esp];
			if (al >= byte [edx + 0x1a]) {
				edi --;
				edx = players[edi].character;
				eax = edx * 360;
				esi = dword [eax + 0x48133a];
				fcn.0044ef41(edi , 2, esi);
			}
			consume_a_card(current_player, 5);
			fcn_41d546();
			return 1;
		}
	}
	// 442f29
	if (ebx != 0) {
		consume_a_card(current_player, 5);
		fcn_41d546();
	}
	return ebx;
}

int turn_back_card()
{
	if (players[current_player].who_plays == 1) {
		eax = fcn.00446ae8(0xe0c0010);
	} else {
		eax = fcn.0041e6f2(0);
	}
	ebx = eax;
	if (ebx != 0) {
		consume_a_card(current_player, 6);
		esi = players[current_player].character;
		eax = esi * 360;
		edi = dword [eax + 0x48124e];
		fcn.0044ef41(current_player, 3, edi);
		edx = esi = fcn.0040d293(ebx);
		if (players[current_player].who_plays != 1) {
			sub.WINMM.dll_timeGetTime_669(0,
					(uint32_t)players[current_player].f8, (uint32_t)players[current_player].f10,
					(uint32_t)players[edx].f8, (uint32_t)players[edx].f10, 100);

		}
		// 443024
		fcn.0040c78c(esi);
		if (esi < 4) {
			edi = current_player;
			if (esi != edi) {
				edx = players[esi].character;
				eax = edx * 360;
				ebp = dword [eax + 0x48133e];
				fcn.0044ef41(esi, 2, ebp);
				fcn_41d546();
				return ebx;
			}
			esi = players[current_player].character;
			eax = esi * 360;
			ecx = dword [eax + 0x4812c6];
			fcn.0044ef41(edi, 0, ecx);
		}
	}
	return ebx;
}

int restruct_card()
{
	esi = 0;
	ebx = players[current_player].f12;
	eax = ebx * 5;
	ebx = dw_498e80 + eax;
	eax = word [ebx + eax*8 + 0x20];
	if (eax > 2000 && eax < 4000) {
		eax -= 2000;
		eax *= 0x34;
		ebx = dw_498e84 + eax;
		if (byte [ebx + 0x1a] == 0) {
			if (esi == 0)
				return 0;
			consume_a_card(current_player, 7);
			fcn_41d546();
			return esi;
		}
		edx = players[current_player].character;
		eax = edx * 360;
		ecx = dword [eax + 0x481252];
		fcn.0044ef41(current_player, 3, ecx);
		ah = byte [ebx + 0x18] ^ 1;
		byte [ebx + 0x18] = ah;
		if (ah != 0 && byte [ebx + 0x1a] > 1) {
			[ebx + 0x1a] = 1;
		}
		esi = 1;
		consume_a_card(current_player, 7);
		fcn_41d546();
		return 1;
	}
	//443147
	if (eax > 4000 && eax < 6000) {
		eax -= 4000;
		eax *= 56;
		ebx = dw_498e88 + eax;
		if ([ebx + 0x1a] != 0) {
			edx = players[current_player].character;
			eax = edx * 360;
			edi = dword [eax + 0x481252];
			fcn.0044ef41(current_player, 3, edi);
			if (players[current_player].who_plays == 1) {
				edx = eax = fcn.00440aac(1);
				if (eax == -1) {
					return 0;
				}
			} else {
				eax = fcn.0041e6f2(0);
			}
			byte [ebx + 0x18] = al;
			esi = 1;
			dh = byte [ebx + 0x18];
			if (dh != 0) {
				if (dh != 3) {
					if (esi == 0)
						return 0;
					consume_a_card(current_player, 7);
					fcn_41d546();
					return esi;
				}
			}
			// 4431f8
			if (byte [ebx + 0x1a] > 1) {
				byte [ebx + 0x1a] = 1;
			}
		}
	}
	// 443202
	if (esi == 0)
		return 0;
	consume_a_card(current_player, 7);
	fcn_41d546();
	return esi;
}