This repository has been archived by the owner on Aug 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
memory.cpp
98 lines (88 loc) · 2.48 KB
/
memory.cpp
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
//
// Created by neo on 2019-08-15.
//
#include "pinball.h"
//----- (010054AC) --------------------------------------------------------
int memory_init(int a1)
{
int result; // eax
result = a1;
memory_critical_callback = (int (*)(void))a1;
return result;
}
// 1024F08: using guessed type int (*memory_critical_callback)(void);
//----- (010054C2) --------------------------------------------------------
int memoryallocate(unsigned int a1)
{
DWORD *v1; // eax
v1 = _malloc(a1 + 4);
if ( a1 >= 0xFFDC )
{
if ( v1 )
{
*v1 = a1 << 8;
memory_use_total += a1 + 4;
*(_BYTE *)v1 = -91;
return (int)(v1 + 1);
}
}
else if ( v1 )
{
*v1 = a1 << 8;
memory_use_total += a1 + 4;
*(_BYTE *)v1 = 90;
return (int)(v1 + 1);
}
if ( memory_critical_allocation )
{
if ( memory_critical_callback )
memory_critical_callback();
}
return 0;
}
// 1024F08: invalid function type has been ignored
// 1024F00: using guessed type int memory_use_total;
// 1024F04: using guessed type int memory_critical_allocation;
// 1024F08: using guessed type int (*memory_critical_callback)(void);
//----- (01005541) --------------------------------------------------------
void memoryfree(int a1)
{
char v1; // cl
memory_use_total += -4 - (*(DWORD *)(a1 - 4) >> 8);
v1 = *(_BYTE *)(a1 - 4);
if ( v1 == 90 || v1 == -91 )
_free((void *)(a1 - 4));
}
// 1024F00: using guessed type int memory_use_total;
//----- (01005579) --------------------------------------------------------
int memoryrealloc(int a1, unsigned int a2)
{
int result; // eax
char *v3; // eax
char v4; // cl
if ( !a1 )
return memoryallocate(a2);
v3 = (char *)(a1 - 4);
memory_use_total -= *(DWORD *)(a1 - 4) >> 8;
if ( *(_BYTE *)(a1 - 4) != 90 && *(_BYTE *)(a1 - 4) != -91 || (v3 = (char *)_realloc(v3, a2 + 4)) != 0 )
{
v4 = *v3;
*(DWORD *)v3 = a2 << 8;
memory_use_total += a2;
*v3 = v4;
result = (int)(v3 + 4);
}
else
{
if ( memory_critical_allocation )
{
if ( memory_critical_callback )
memory_critical_callback();
}
result = 0;
}
return result;
}
// 1024F00: using guessed type int memory_use_total;
// 1024F04: using guessed type int memory_critical_allocation;
// 1024F08: using guessed type int (*memory_critical_callback)(void);