Add read_(w)string methods to buffer. Replace char names[20] to std::strings. Stub for save loader.

This commit is contained in:
lzwdgc 2016-06-21 18:40:22 +03:00
parent 540af823f4
commit 33368e5f3b
16 changed files with 203 additions and 106 deletions

View file

@ -36,5 +36,9 @@ target_link_libraries(tm_converter common)
file(GLOB name_generator_src "name_generator/*")
add_executable(name_generator ${name_generator_src})
file(GLOB save_loader_src "save_loader/*")
add_executable(save_loader ${save_loader_src})
target_link_libraries(save_loader common)
add_subdirectory(common)
add_subdirectory(script2txt)

View file

@ -102,6 +102,20 @@ buffer::buffer(buffer &rhs, uint32_t size, uint32_t offset)
end_ = index_ + size_;
}
std::string buffer::read_string(uint32_t blocksize) const
{
std::vector<uint8_t> data(blocksize);
read(data.data(), data.size());
return (const char *)data.data();
}
std::wstring buffer::read_wstring(uint32_t blocksize) const
{
std::vector<uint16_t> data(blocksize);
read(data.data(), data.size());
return (const wchar_t *)data.data();
}
uint32_t buffer::_read(void *dst, uint32_t size, uint32_t offset) const
{
if (!buf_)

View file

@ -25,6 +25,13 @@
#define READ(b, var) b.read(&var)
#define READ_N(b, var, sz) b.read(&var, sz)
#define READ_STRING(b, var) var = b.read_string()
#define READ_STRING_N(b, var, sz) var = b.read_string(sz)
#define READ_WSTRING(b, var) var = b.read_wstring()
#define READ_WSTRING_N(b, var, sz) var = b.read_wstring(sz)
#define WRITE(b, var) b.write(&var)
std::string version();
@ -50,6 +57,8 @@ public:
{
return _read(dst, size * sizeof(T), 0);
}
std::string read_string(uint32_t blocksize = 0x20) const;
std::wstring read_wstring(uint32_t blocksize = 0x20) const;
template <typename T>
uint32_t readfrom(T *dst, uint32_t size, uint32_t offset) const
{

View file

@ -93,7 +93,7 @@ struct Common
{
Vector4 m_rotate_z[3];
Vector4 position;
void load(buffer &b)
{
READ(b, m_rotate_z);
@ -103,15 +103,15 @@ struct Common
struct MapObject : public Common
{
char name1[0x20];
char name2[0x20];
std::string name1;
std::string name2;
void load(buffer &b)
{
Common::load(b);
READ(b, name1);
READ(b, name2);
READ_STRING(b, name1);
READ_STRING(b, name2);
}
};
@ -139,7 +139,7 @@ struct Sound : public Common
void load(buffer &b)
{
Common::load(b);
READ(b, unk1);
READ(b, name1);
}

View file

@ -22,27 +22,27 @@ GameType gameType = GameType::Aim2;
void weather::load(buffer &b)
{
READ(b, name);
READ(b, unk0);
READ_STRING(b, name);
READ_STRING(b, unk0);
READ(b, unk1);
READ(b, smoke_1);
READ(b, smoke_3);
READ(b, smokeType);
READ(b, unk2);
READ(b, cloud_layer1);
READ(b, cloud_layer2);
READ_STRING(b, cloud_layer1);
READ_STRING(b, cloud_layer2);
READ(b, cloud_layer1_speed);
READ(b, cloud_layer2_speed);
READ(b, cloud_layer1_direction);
READ(b, cloud_layer2_direction);
READ(b, sun);
READ_STRING(b, sun);
READ(b, general_color);
READ(b, sun_color);
READ(b, moon_color);
READ(b, moon);
READ_STRING(b, moon);
READ(b, probability);
READ(b, day_night_gradient_name);
READ(b, dawn_dusk_gradient_name);
READ_STRING(b, day_night_gradient_name);
READ_STRING(b, dawn_dusk_gradient_name);
READ(b, dawn_dusk_color);
READ(b, effects);
READ(b, smoke_2);
@ -64,12 +64,12 @@ void weather_group::load(buffer &b)
void water::load(buffer &b)
{
READ(b, unk0);
READ(b, name1);
READ_STRING(b, name1);
READ(b, unk1);
READ(b, unk2);
READ(b, unk3);
READ(b, unk4);
READ(b, name2);
READ_STRING(b, name2);
READ(b, unk5);
}

View file

@ -71,27 +71,27 @@ struct weather
float probability;
};
char name[0x20];
char unk0[0x20];
std::string name;
std::string unk0;
uint32_t unk1[2];
color smoke_1; //3?
color smoke_3; //1?
SmokeType smokeType;
uint32_t unk2[3];
char cloud_layer1[0x20];
char cloud_layer2[0x20];
std::string cloud_layer1;
std::string cloud_layer2;
float cloud_layer1_speed;
float cloud_layer2_speed;
vector3 cloud_layer1_direction;
vector3 cloud_layer2_direction;
char sun[0x20];
std::string sun;
color general_color;
color sun_color;
color moon_color;
char moon[0x20];
std::string moon;
float probability;
char day_night_gradient_name[0x20];
char dawn_dusk_gradient_name[0x20];
std::string day_night_gradient_name;
std::string dawn_dusk_gradient_name;
color dawn_dusk_color;
atmospheric_effects effects;
color smoke_2;
@ -115,12 +115,12 @@ struct weather_group
struct water
{
float unk0[6];
char name1[0x20];
std::string name1;
uint32_t unk1;
float unk2;
uint32_t unk3[16];
float unk4;
char name2[0x20];
std::string name2;
uint32_t unk5[16];
void load(buffer &b);
@ -135,7 +135,7 @@ struct water_group
struct Good
{
char name[0x20];
std::string name;
char unk1[0x40];
float unk1_2 = 0;
float price = 0;
@ -145,7 +145,7 @@ struct Good
void load(buffer &b)
{
READ(b, name);
READ_STRING(b, name);
if (gameType == GameType::Aim1)
READ(b, unk1);
else
@ -163,14 +163,14 @@ struct Good
struct BuildingGoods
{
char name[0x20];
std::string name;
uint32_t n = 0;
std::vector<Good> goods;
void load(buffer &b)
{
READ(b, name);
READ_STRING(b, name);
READ(b, n);
for (int i = 0; i < n; i++)
@ -184,8 +184,8 @@ struct BuildingGoods
struct MapMusic
{
char name1[0x20];
char name2[0x20];
std::string name1;
std::string name2;
uint32_t n1 = 0;
std::vector<std::string> names1;
@ -195,24 +195,20 @@ struct MapMusic
void load(buffer &b)
{
READ(b, name1);
READ(b, name2);
READ_STRING(b, name1);
READ_STRING(b, name2);
auto read_values = [&b](auto &v, auto &n)
{
for (int i = 0; i < n; i++)
v.push_back(b.read_string());
};
READ(b, n1);
for (int i = 0; i < n1; i++)
{
char name[0x20];
READ(b, name);
names1.push_back(name);
}
read_values(names1, n1);
READ(b, n2);
for (int i = 0; i < n2; i++)
{
char name[0x20];
READ(b, name);
names2.push_back(name);
}
read_values(names2, n2);
}
};
@ -233,14 +229,14 @@ struct OrganizationConfig
struct Organization
{
uint32_t unk0 = 0;
char name[0x20];
std::string name;
char unk1[0xE0];
OrganizationConfig configs[3];
void load(buffer &b)
{
READ(b, unk0);
READ(b, name);
READ_STRING(b, name);
READ(b, unk1);
for (auto &c : configs)
c.load(b);
@ -268,14 +264,14 @@ struct Organizations
struct OrganizationBase
{
char base_name[0x20];
char org_name[0x20];
std::string base_name;
std::string org_name;
uint32_t unk0 = 0;
void load(buffer &b)
{
READ(b, base_name);
READ(b, org_name);
READ_STRING(b, base_name);
READ_STRING(b, org_name);
READ(b, unk0);
}
};

View file

@ -39,7 +39,7 @@ string getSqlType(FieldType type)
void table::load(buffer &b)
{
READ(b, id);
READ(b, name);
READ_STRING(b, name);
READ(b, unk4);
}
@ -47,7 +47,7 @@ void field::load(buffer &b)
{
READ(b, table_id);
READ(b, id);
READ(b, name);
READ_STRING(b, name);
READ(b, type);
}
@ -76,7 +76,7 @@ void tab::load(buffer &b)
void value::load_index(buffer &b)
{
READ(b, table_id);
READ(b, name);
READ_STRING(b, name);
READ(b, offset);
READ(b, data_size);
}

View file

@ -39,7 +39,7 @@ string getSqlType(FieldType type);
struct table
{
uint32_t id;
char name[0x20];
std::string name;
uint32_t unk4;
void load(buffer &b);
@ -49,7 +49,7 @@ struct field
{
uint32_t table_id;
uint32_t id;
char name[0x20];
std::string name;
FieldType type;
void load(buffer &b);
@ -79,7 +79,7 @@ struct field_value
struct value
{
uint32_t table_id;
char name[0x20];
std::string name;
uint32_t offset;
uint32_t data_size;
vector<field_value> fields;

View file

@ -29,8 +29,8 @@
struct MechGroup
{
char name[0x20];
char org[0x20];
std::string name;
std::string org;
uint32_t type1 = 0;
uint32_t len1 = 0;
char name1[0x70];
@ -50,8 +50,8 @@ struct MechGroup
void load(buffer &b)
{
READ(b, name);
READ(b, org);
READ_STRING(b, name);
READ_STRING(b, org);
READ(b, type1);
READ(b, len1);
READ(b, name1);
@ -134,14 +134,14 @@ struct MapGoods
struct MapSound
{
char name[0x20];
std::string name;
float unk1[4];
uint32_t unk2 = 0;
float unk3[4];
void load(buffer &b)
{
READ(b, name);
READ_STRING(b, name);
READ(b, unk1);
READ(b, unk2);
READ(b, unk3);
@ -165,31 +165,62 @@ struct MapSounds
}
};
struct ModificatorMask
{
enum class ItemType : uint8_t
{
Glider = 1,
Weapon,
Reactor,
Engine,
EnergyShield
};
uint8_t fight:4;
uint8_t trade:4;
uint8_t courier:4;
ItemType type:4;
uint16_t:16;
};
struct Price
{
char tov_name[0x20];
uint32_t unk0 = 0;
uint32_t unk1 = 0;
float unk2[3];
enum class ItemType : uint32_t
{
Glider = 1,
Equipment,
Weapon,
Ammo,
};
std::string tov_name;
ItemType type;
ModificatorMask mask;
float price;
float unk2 = 0.0f; // count ?
float probability; // of appearence
void load(buffer &b)
{
READ(b, tov_name);
READ(b, unk0);
READ(b, unk1);
READ_STRING(b, tov_name);
READ(b, type);
READ(b, mask);
READ(b, price);
READ(b, unk2);
READ(b, probability);
}
};
struct BuildingPrice
{
char name[0x20];
uint32_t n_tov = 0;
std::string name;
std::vector<Price> prices;
void load(buffer &b)
{
READ(b, name);
READ_STRING(b, name);
uint32_t n_tov = 0;
READ(b, n_tov);
for (int i = 0; i < n_tov; i++)
{
@ -202,13 +233,12 @@ struct BuildingPrice
struct BuildingPrices
{
uint32_t n_tov = 0;
std::vector<Price> prices;
uint32_t n_bases = 0;
std::vector<BuildingPrice> buildingPrices;
void load(buffer &b)
{
uint32_t n_tov = 0;
READ(b, n_tov);
for (int i = 0; i < n_tov; i++)
{
@ -216,6 +246,7 @@ struct BuildingPrices
s.load(b);
prices.push_back(s);
}
uint32_t n_bases = 0;
READ(b, n_bases);
for (int i = 0; i < n_bases; i++)
{

View file

@ -62,13 +62,13 @@ header_segment *header::create_segment(buffer &b)
void header::load(buffer &b)
{
READ(b, unk0);
READ(b, name1);
READ(b, name2);
READ_WSTRING(b, name1);
READ_WSTRING(b, name2);
READ(b, width);
READ(b, height);
READ(b, n_header_segs);
segments.resize(n_header_segs);
READ(b, name);
READ_STRING_N(b, name, 0xA0);
for (auto &s : segments)
{
s = create_segment(b);

View file

@ -61,12 +61,12 @@ struct weather_segment : public header_segment
struct header
{
uint32_t unk0;
wchar_t name1[0x20];
wchar_t name2[0x20];
std::wstring name1;
std::wstring name2;
uint32_t width;
uint32_t height;
uint32_t n_header_segs;
char name[0xA0];
std::string name;
std::vector<header_segment*> segments;
void load(buffer &b);
@ -163,7 +163,7 @@ struct mmp
mat<uint32_t> texmap;
mat<uint32_t> texmap_colored;
mat<uint32_t> colormap;
void load(buffer &b);
void load(const std::string &filename);
void loadTextureNames(const std::string &filename);

View file

@ -44,11 +44,11 @@ void vertex::load(buffer &b, uint32_t flags)
if (flags & F_UNK0)
READ(b, unk0);
READ(b, nX);
READ(b, nZ);
READ(b, nY);
READ(b, t1);
READ(b, t2);
}
@ -130,7 +130,7 @@ void animation::segment::loadData(buffer &b)
std::string block::printMtl(const std::string &mtl_name) const
{
string s;
s += "newmtl " + mtl_name + "\n";
s += "newmtl " + mtl_name + "\n";
s += "\n";
s += "Ka " + material.ambient.print() + "\n";
s += "Kd " + material.diffuse.print() + "\n";
@ -184,21 +184,21 @@ std::string block::printObj(const std::string &mtl_name) const
z += "/" + z;
s += "f " + x + " " + y + " " + z + "\n";
}
s += "\n";
s += "\n";
return s;
}
void block::load(buffer &b)
{
// header
READ(b, type);
READ(b, name);
READ(b, tex_mask);
READ(b, tex_spec);
READ(b, tex3);
READ(b, tex4);
READ_STRING(b, name);
READ_STRING(b, tex_mask);
READ_STRING(b, tex_spec);
READ_STRING(b, tex3);
READ_STRING(b, tex4);
READ(b, LODs);
READ(b, unk1);
READ(b, unk2);
@ -208,7 +208,7 @@ void block::load(buffer &b)
if (size == 0) // critical error!!! cannot survive
throw std::runtime_error("model file has bad block size field (size == 0)");
// data
buffer data = buffer(b, size);
@ -254,7 +254,7 @@ void block::load(buffer &b)
a.load(data);
for (auto &dm : damage_models)
dm.load(data);
if (!data.eof() && triangles_mult_7)
{
// unknown end of block

View file

@ -126,7 +126,7 @@ struct damage_model
uint32_t n_triangles;
std::vector<vertex> vertices;
std::vector<uint16_t> triangles;
virtual void load(buffer &b);
};
@ -159,11 +159,11 @@ struct block
{
// header
BlockType type;
char name[0x20];
char tex_mask[0x20];
char tex_spec[0x20];
char tex3[0x20];
char tex4[0x20];
std::string name;
std::string tex_mask;
std::string tex_spec;
std::string tex3;
std::string tex4;
union // LODs
{
struct

View file

@ -99,7 +99,8 @@ void surface::load(buffer &b)
while (!b.eof())
{
value v;
READ(b, v);
READ_STRING(b, v.name);
READ(b, v.unk0);
unk1.push_back(v);
}
}

View file

@ -67,7 +67,7 @@ struct surface : public segment
{
struct value
{
char name[0x20];
std::string name;
uint32_t unk0;
};
std::vector<value> unk1;
@ -151,16 +151,16 @@ struct gliders_n_goods : public segment
{
struct Good
{
char name[0x20];
std::string name;
int unk0[3];
void load(buffer &b)
{
READ(b, name);
READ_STRING(b, name);
READ(b, unk0);
}
};
struct Goods
{
uint32_t n_goods;

View file

@ -0,0 +1,42 @@
/*
* AIM save_loader
* Copyright (C) 2016 lzwdgc
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
int main(int argc, char *argv[])
try
{
if (argc != 2)
{
printf("Usage: %s file.sav\n", argv[0]);
return 1;
}
return 0;
}
catch (std::exception &e)
{
printf("%s\n", argv[1]);
printf("error: %s\n", e.what());
return 1;
}
catch (...)
{
printf("%s\n", argv[1]);
printf("error: unknown exception\n");
return 1;
}