45absl::Status
LoadCgx(uint8_t bpp, std::string_view filename,
46 std::vector<uint8_t>& cgx_data,
47 std::vector<uint8_t>& cgx_loaded,
48 std::vector<uint8_t>& cgx_header) {
49 std::ifstream file(filename.data(), std::ios::binary);
50 if (!file.is_open()) {
51 return absl::NotFoundError(
"CGX file not found.");
53 std::vector<uint8_t> file_content((std::istreambuf_iterator<char>(file)),
54 std::istreambuf_iterator<char>());
56 std::vector<uint8_t>(file_content.begin(), file_content.end() - 0x500);
57 file.seekg(cgx_data.size() + 0x100);
58 cgx_header = std::vector<uint8_t>((std::istreambuf_iterator<char>(file)),
59 std::istreambuf_iterator<char>());
64 return absl::OkStatus();
67 return absl::OkStatus();
70absl::Status
LoadScr(std::string_view filename, uint8_t input_value,
71 std::vector<uint8_t>& map_data) {
72 std::ifstream file(filename.data(), std::ios::binary);
73 if (!file.is_open()) {
74 return absl::NotFoundError(
"SCR/PNL/MAP file not found.");
79 if (filename.find(
"PNL") != std::string::npos) {
80 std::vector<uint8_t> scr_data;
81 map_data.resize(0x8000);
82 scr_data.resize(0x8000);
85 std::vector<uint8_t> file_content((std::istreambuf_iterator<char>(file)),
86 std::istreambuf_iterator<char>());
87 scr_data = std::vector<uint8_t>(file_content.begin(), file_content.end());
91 for (
int i = input_value * 0x400; i < 0x1000 + input_value * 0x400;
93 auto b1_pos = (i - (input_value * 0x400));
97 auto b2_pos = (i - (input_value * 0x400) + 1);
105 std::vector<uint8_t> scr_data;
106 map_data.resize(0x2000);
107 scr_data.resize(0x2000);
110 std::vector<uint8_t> file_content((std::istreambuf_iterator<char>(file)),
111 std::istreambuf_iterator<char>());
112 scr_data = std::vector<uint8_t>(file_content.begin(), file_content.end());
114 for (
int i = 0; i < 0x1000 - offset; i++) {
119 return absl::OkStatus();
123 std::vector<uint8_t>& map_bitmap_data,
124 std::vector<uint8_t>& cgx_loaded) {
125 const std::vector<uint16_t> dimensions = {0x000, 0x400, 0x800, 0xC00};
127 for (
const auto each_dimension : dimensions) {
130 for (
int i = 0; i < 0x400; i++) {
131 if (map_data[i + p] != 0xFF) {
134 for (
auto yl = 0; yl < 8; yl++) {
135 for (
auto xl = 0; xl < 8; xl++) {
136 int mx = xl * (1 - t.horizontal_mirror_) +
137 (7 - xl) * (t.horizontal_mirror_);
139 yl * (1 - t.vertical_mirror_) + (7 - yl) * (t.vertical_mirror_);
141 int ty = (t.id_ / 16) * 1024;
142 int tx = (t.id_ % 16) * 8;
143 auto pixel = cgx_loaded[(tx + ty) + (yl * 128) + xl];
145 int index = (((i % 32) * 8) + ((i / 32) * 2048) + mx + (my * 256));
148 map_bitmap_data[index] =
149 (
uchar)((pixel & 0xFF) + t.palette_ * 16);
151 map_bitmap_data[index] = (
uchar)(pixel & 0xFF);
158 return absl::OkStatus();
162 std::vector<SDL_Color> decoded_col;
163 std::ifstream file(filename.data(), std::ios::binary | std::ios::ate);
165 if (!file.is_open()) {
170 std::streamsize size = file.tellg();
171 file.seekg(0, std::ios::beg);
173 std::vector<char> buffer(size);
174 if (file.read(buffer.data(), size)) {
175 buffer.resize(size - 0x200);
178 for (
size_t i = 0; i < buffer.size() / 2; i++) {
179 uint16_t current_color =
static_cast<unsigned char>(buffer[k]) |
180 (
static_cast<unsigned char>(buffer[k + 1]) << 8);
183 color.r = (current_color & 31) << 3;
184 color.g = ((current_color >> 5) & 31) << 3;
185 color.b = ((current_color >> 10) & 31) << 3;
186 color.a = (i & 0xF) == 0 ? 0 : 255;
188 decoded_col.push_back(color);
197 std::string_view filename, std::vector<uint8_t>& obj_data,
198 std::vector<uint8_t> actual_obj_data,
199 std::unordered_map<std::string, std::vector<uint8_t>> decoded_obj,
200 std::vector<uint8_t>& decoded_extra_obj,
int& obj_loaded) {
201 std::vector<uint8_t> header_obj;
204 if (obj_loaded == 0) {
206 expected_cut = 0x500;
209 expected_cut = 0x900;
212 std::ifstream file(filename.data(), std::ios::binary);
213 if (!file.is_open()) {
214 return absl::NotFoundError(
"OBJ file not found.");
217 std::vector<uint8_t> file_content((std::istreambuf_iterator<char>(file)),
218 std::istreambuf_iterator<char>());
219 obj_data = file_content;
222 int cut = obj_data.size() & 0x0FFF;
224 std::vector<uint8_t>(obj_data.begin(), obj_data.end() - cut);
226 std::vector<uint8_t>(obj_data.begin() + actual_obj_data.size(),
227 obj_data.begin() + actual_obj_data.size() + 0x100);
228 header_obj = std::vector<uint8_t>(
229 actual_obj_data.begin() + actual_obj_data.size(), actual_obj_data.end());
231 if (cut > expected_cut) {
232 std::vector<uint8_t> scad_data;
234 int k = (obj_loaded == 0) ? 63 : 127;
236 for (
size_t i = 0; i < (actual_obj_data.size() / 6); i++) {
237 std::vector<uint8_t> data = {
238 actual_obj_data[k * 6 + 0 + j],
239 actual_obj_data[k * 6 + 1 + j],
240 actual_obj_data[k * 6 + 2 + j],
241 actual_obj_data[k * 6 + 3 + j],
242 actual_obj_data[k * 6 + 5 + j],
243 actual_obj_data[k * 6 + 4 + j]
245 scad_data.insert(scad_data.end(), data.begin(), data.end());
249 k = (obj_loaded == 0) ? 63 : 127;
250 j = j + ((k + 1) * 6);
254 int extra_data_range = 0x400 * (obj_loaded + 1) + 0x100;
255 for (
int i = 0; i < extra_data_range; i++) {
256 scad_data.push_back(header_obj[i]);
259 obj_data = scad_data;
261 std::vector<uint8_t>(obj_data.begin(), obj_data.end() - cut);
265 for (
int k = 0; k < 128; k++) {
266 decoded_obj[
"frame " + std::to_string(k)] = std::vector<uint8_t>(obj_range);
267 for (
int i = 0; i < obj_range; i++) {
269 decoded_obj[
"frame " + std::to_string(k)][i] =
270 obj_data[i + (obj_range * k)];
272 decoded_obj[
"frame " + std::to_string(k)][i] = 0;
277 return absl::OkStatus();