43absl::Status
LoadCgx(uint8_t bpp, std::string_view filename,
44 std::vector<uint8_t>& cgx_data,
45 std::vector<uint8_t>& cgx_loaded,
46 std::vector<uint8_t>& cgx_header) {
47 std::ifstream file(filename.data(), std::ios::binary);
48 if (!file.is_open()) {
49 return absl::NotFoundError(
"CGX file not found.");
51 std::vector<uint8_t> file_content((std::istreambuf_iterator<char>(file)),
52 std::istreambuf_iterator<char>());
54 std::vector<uint8_t>(file_content.begin(), file_content.end() - 0x500);
55 file.seekg(cgx_data.size() + 0x100);
56 cgx_header = std::vector<uint8_t>((std::istreambuf_iterator<char>(file)),
57 std::istreambuf_iterator<char>());
62 return absl::OkStatus();
65 return absl::OkStatus();
68absl::Status
LoadScr(std::string_view filename, uint8_t input_value,
69 std::vector<uint8_t>& map_data) {
70 std::ifstream file(filename.data(), std::ios::binary);
71 if (!file.is_open()) {
72 return absl::NotFoundError(
"SCR/PNL/MAP file not found.");
77 if (filename.find(
"PNL") != std::string::npos) {
78 std::vector<uint8_t> scr_data;
79 map_data.resize(0x8000);
80 scr_data.resize(0x8000);
83 std::vector<uint8_t> file_content((std::istreambuf_iterator<char>(file)),
84 std::istreambuf_iterator<char>());
85 scr_data = std::vector<uint8_t>(file_content.begin(), file_content.end());
89 for (
int i = input_value * 0x400; i < 0x1000 + input_value * 0x400;
91 auto b1_pos = (i - (input_value * 0x400));
95 auto b2_pos = (i - (input_value * 0x400) + 1);
103 std::vector<uint8_t> scr_data;
104 map_data.resize(0x2000);
105 scr_data.resize(0x2000);
108 std::vector<uint8_t> file_content((std::istreambuf_iterator<char>(file)),
109 std::istreambuf_iterator<char>());
110 scr_data = std::vector<uint8_t>(file_content.begin(), file_content.end());
112 for (
int i = 0; i < 0x1000 - offset; i++) {
117 return absl::OkStatus();
121 std::vector<uint8_t>& map_bitmap_data,
122 std::vector<uint8_t>& cgx_loaded) {
123 const std::vector<uint16_t> dimensions = {0x000, 0x400, 0x800, 0xC00};
125 for (
const auto each_dimension : dimensions) {
128 for (
int i = 0; i < 0x400; i++) {
129 if (map_data[i + p] != 0xFF) {
132 for (
auto yl = 0; yl < 8; yl++) {
133 for (
auto xl = 0; xl < 8; xl++) {
134 int mx = xl * (1 - t.horizontal_mirror_) +
135 (7 - xl) * (t.horizontal_mirror_);
137 yl * (1 - t.vertical_mirror_) + (7 - yl) * (t.vertical_mirror_);
139 int ty = (t.id_ / 16) * 1024;
140 int tx = (t.id_ % 16) * 8;
141 auto pixel = cgx_loaded[(tx + ty) + (yl * 128) + xl];
143 int index = (((i % 32) * 8) + ((i / 32) * 2048) + mx + (my * 256));
146 map_bitmap_data[index] =
147 (uint8_t)((pixel & 0xFF) + t.palette_ * 16);
149 map_bitmap_data[index] = (uint8_t)(pixel & 0xFF);
156 return absl::OkStatus();
160 std::vector<SDL_Color> decoded_col;
161 std::ifstream file(filename.data(), std::ios::binary | std::ios::ate);
163 if (!file.is_open()) {
168 std::streamsize size = file.tellg();
169 file.seekg(0, std::ios::beg);
171 std::vector<char> buffer(size);
172 if (file.read(buffer.data(), size)) {
173 buffer.resize(size - 0x200);
176 for (
size_t i = 0; i < buffer.size() / 2; i++) {
177 uint16_t current_color =
static_cast<unsigned char>(buffer[k]) |
178 (
static_cast<unsigned char>(buffer[k + 1]) << 8);
181 color.r = (current_color & 31) << 3;
182 color.g = ((current_color >> 5) & 31) << 3;
183 color.b = ((current_color >> 10) & 31) << 3;
184 color.a = (i & 0xF) == 0 ? 0 : 255;
186 decoded_col.push_back(color);
195 std::string_view filename, std::vector<uint8_t>& obj_data,
196 std::vector<uint8_t> actual_obj_data,
197 std::unordered_map<std::string, std::vector<uint8_t>> decoded_obj,
198 std::vector<uint8_t>& decoded_extra_obj,
int& obj_loaded) {
199 std::vector<uint8_t> header_obj;
202 if (obj_loaded == 0) {
204 expected_cut = 0x500;
207 expected_cut = 0x900;
210 std::ifstream file(filename.data(), std::ios::binary);
211 if (!file.is_open()) {
212 return absl::NotFoundError(
"OBJ file not found.");
215 std::vector<uint8_t> file_content((std::istreambuf_iterator<char>(file)),
216 std::istreambuf_iterator<char>());
217 obj_data = file_content;
220 int cut = obj_data.size() & 0x0FFF;
222 std::vector<uint8_t>(obj_data.begin(), obj_data.end() - cut);
224 std::vector<uint8_t>(obj_data.begin() + actual_obj_data.size(),
225 obj_data.begin() + actual_obj_data.size() + 0x100);
226 header_obj = std::vector<uint8_t>(
227 actual_obj_data.begin() + actual_obj_data.size(), actual_obj_data.end());
229 if (cut > expected_cut) {
230 std::vector<uint8_t> scad_data;
232 int k = (obj_loaded == 0) ? 63 : 127;
234 for (
size_t i = 0; i < (actual_obj_data.size() / 6); i++) {
235 std::vector<uint8_t> data = {
236 actual_obj_data[k * 6 + 0 + j],
237 actual_obj_data[k * 6 + 1 + j],
238 actual_obj_data[k * 6 + 2 + j],
239 actual_obj_data[k * 6 + 3 + j],
240 actual_obj_data[k * 6 + 5 + j],
241 actual_obj_data[k * 6 + 4 + j]
243 scad_data.insert(scad_data.end(), data.begin(), data.end());
247 k = (obj_loaded == 0) ? 63 : 127;
248 j = j + ((k + 1) * 6);
252 int extra_data_range = 0x400 * (obj_loaded + 1) + 0x100;
253 for (
int i = 0; i < extra_data_range; i++) {
254 scad_data.push_back(header_obj[i]);
257 obj_data = scad_data;
259 std::vector<uint8_t>(obj_data.begin(), obj_data.end() - cut);
263 for (
int k = 0; k < 128; k++) {
264 decoded_obj[
"frame " + std::to_string(k)] = std::vector<uint8_t>(obj_range);
265 for (
int i = 0; i < obj_range; i++) {
267 decoded_obj[
"frame " + std::to_string(k)][i] =
268 obj_data[i + (obj_range * k)];
270 decoded_obj[
"frame " + std::to_string(k)][i] = 0;
275 return absl::OkStatus();