Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
198 lines (169 loc) · 5.95 KB
/
Copy pathmain.cpp
File metadata and controls
198 lines (169 loc) · 5.95 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
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
#include <iostream>
#include <cstdio>
#include <prime1/CGameState.hpp>
#include <prime1/CStateManager.hpp>
#include <prime1/CGameGlobalObjects.hpp>
#include "prime1/Prime1JsonDumper.hpp"
#include "prime1/Prime1ConsoleDumper.hpp"
#include "CRandom16Impl.hpp"
using namespace std;
using namespace nlohmann;
char *memory;
size_t memory_size;
void readObjectList();
void testRandom();
void readAreas();
int main() {
// FILE *f = fopen("ram.raw", "rb");
FILE *f = fopen("ram_borked79.raw", "rb");
fseek(f, 0, SEEK_END);
memory_size = static_cast<size_t>(ftell(f));
fseek(f, 0, SEEK_SET);
memory = new char[memory_size];
fread(memory, 1, memory_size, f);
readAreas();
// testRandom();
// readObjectList();
// cout << Prime1JsonDumper::parseHeap().dump(2) << endl;
// cout << Prime1JsonDumper::parsePlayerRaw().dump(2) << endl;
// cout << Prime1JsonDumper::parseWorld().dump(2) << endl;
// cout << Prime1JsonDumper::parsePool().dump(2) << endl;
// cout << Prime1JsonDumper::parsePoolBasic().dump(2) << endl;
// cout << Prime1JsonDumper::parsePoolSummary().dump(2) << endl;
// cout << Prime1JsonDumper::parseHeapStats().dump(2) << endl;
// MemoryBuffer buff(0x1000);
// Prime1ConsoleDumper::dump(buff);
// cout << buff.getBuff() << endl;
// json json_message;
// //Prime 1
//// json_message["heap"] = Prime1JsonDumper::parseHeap();
// json_message["camera"] = Prime1JsonDumper::parseCamera();
//// json_message["player"] = Prime1JsonDumper::parsePlayer();
// json_message["player_raw"] = Prime1JsonDumper::parsePlayerRaw();
// json_message["world"] = Prime1JsonDumper::parseWorld();
// json_message["pool_summary"] = Prime1JsonDumper::parsePoolSummary();
//
// cout << json_message.dump(2) << endl;
return 0;
}
void readAreas() {
CStateManager manager(CStateManager::LOCATION);
CWorld world = manager.world.deref();
int areaCount = world.areas.size.read();
for (int i = 0; i < areaCount; i++) {
auto autoPtr = world.areas[i];
// cout << hex << " autoptr offset: " << autoPtr.ptr();
// cout << hex << " autoptr second value: " << autoPtr.dataPtr.read();
// cout << endl;
CGameArea area = autoPtr.dataPtr.deref();
cout << hex << "Area " << area.selfIDX.read() << "|" << area.mrea.read() << endl;
cout << (area.postConstructedBool.read() ? "C" : " ");
cout << (area.active.read() ? "A" : " ");
cout << (area.tokensReady.read() ? "T" : " ");
cout << (area.loadPaused.read() ? "P" : " ");
cout << (area.validated.read() ? "V" : " ");
cout << " phase: ";
switch (area.phase.read()) {
case EPhase::LoadHeader:
cout << "Load header";
break;
case EPhase::LoadSecSizes:
cout << "Load section sizes";
break;
case EPhase::ReserveSections:
cout << "Reserve Sections";
break;
case EPhase::LoadDataSections:
cout << "Load data sections";
break;
case EPhase::WaitForFinish:
cout << "Wait for finish";
break;
default:
cout << "Unknown";
}
cout << " chain: ";
switch (area.curChain.read()) {
case EChain::Invalid:
cout << "Invalid";
break;
case EChain::ToDeallocate:
cout << "ToDeallocate";
break;
case EChain::Deallocated:
cout << "Deallocated";
break;
case EChain::Loading:
cout << "Loading";
break;
case EChain::Alive:
cout << "Alive";
break;
case EChain::AliveJudgement:
cout << "Alive Judgement";
break;
default:
cout << "Unknown";
}
if (area.postConstructed.read() != 0) {
CPostConstructed pc = area.postConstructed.read();
cout << " Occlusion state: ";
switch (pc.occlusionState.read()) {
case EOcclusionState::Occluded:
cout << "Occluded";
break;
case EOcclusionState::Visible:
cout << "Visible";
break;
default:
cout << "Unknown";
}
}
cout << endl;
// cout << "Post constructed auto_ptr: " << (int) area.postConstructed.unknown.read() << " | " << area.postConstructed.dataPtr.read() << endl;
cout << "Load transaction offset: " << area.loadTransactions.ptr() << endl;
}
}
void testRandom() {
// CStateManager manager(CStateManager::LOCATION);
// CRandom16Impl impl(manager.random.seed.read());
CRandom16Impl impl(0x91F76E96);
for (int i = 0; i < 100; i++) {
cout << hex << impl.GetSeed() << dec << " ";
cout << impl.Float() << endl;
}
}
void readObjectList() {
CStateManager manager(CStateManager::LOCATION);
CObjectList list = manager.allObjs.deref();
cout << "Size: " << list.count.read() << endl;
int counter = 0;
int id = list.firstID.read();
cout << hex;
while (id != 0xFFFF) {
counter++;
SObjectListEntry entry = list.list[id & 0x3FF];
CEntity entity = entry.entity.deref();
// if (entity.editorID.read() == 0x340286) {
cout << "ID: " << entity.editorID.read() << endl;
cout << "Address: " << entity.editorID.ptr() << endl;
cout << "Name loc: " << entity.name.ptr() << endl;
cout << "Name string ptr: " << entity.name.data.read() << endl;
cout << "Name: " << entity.name.read_str() << endl;
cout << "Unknowns: " << entity.name.unk2.read() << " | " << entity.name.unk3.read() << " | "
<< entity.name.unk4.read() << endl;
// cout << "State flag: " << (uint32_t)entity.status.read() << endl;
//
// cout << "State flag address: " << entity.status.ptr() << endl;
cout << "------------------------------" << endl << endl;
// }
int newId = entry.next.read();
if (id == newId) break;
id = newId;
if (counter > 0x3FF) break; //somethign went wrong
}
if (counter != list.count.read()) {
cout << "Something is very wrong" << endl;
}
cout << dec;
}