Initial AimR mod extractor.

This commit is contained in:
lzwdgc 2018-04-24 23:52:28 +03:00
parent 3d894efc5e
commit 8933e1203e
8 changed files with 84 additions and 52 deletions

View file

@ -57,6 +57,7 @@ if (DEFINED FBX_SDK_ROOT)
common common
model model
#pvt.cppan.demo.eigen #pvt.cppan.demo.eigen
pvt.cppan.demo.taywee.args
debug "${FBX_SDK_ROOT}/lib/vs2015/x86/debug/libfbxsdk-md.lib" debug "${FBX_SDK_ROOT}/lib/vs2015/x86/debug/libfbxsdk-md.lib"
optimized "${FBX_SDK_ROOT}/lib/vs2015/x86/release/libfbxsdk-md.lib" optimized "${FBX_SDK_ROOT}/lib/vs2015/x86/release/libfbxsdk-md.lib"
) )

View file

@ -26,18 +26,22 @@
enum class GameType enum class GameType
{ {
Aim1, Aim1,
Aim2 Aim2,
AimR,
}; };
inline GameType gameType = GameType::Aim2; inline GameType gameType = GameType::Aim2;
template <typename T>
struct vector3 struct vector3
{ {
float x = 0; T x;
float y = 0; T y;
float z = 0; T z;
}; };
using vector3f = vector3<float>;
struct vector4 struct vector4
{ {
float x = 0; float x = 0;
@ -65,7 +69,7 @@ struct weather
{ {
struct atmospheric_effects struct atmospheric_effects
{ {
vector3 wind; vector3f wind;
WeatherType weatherType; WeatherType weatherType;
float strength; float strength;
float duration; float duration;
@ -83,8 +87,8 @@ struct weather
std::string cloud_layer2; std::string cloud_layer2;
float cloud_layer1_speed; float cloud_layer1_speed;
float cloud_layer2_speed; float cloud_layer2_speed;
vector3 cloud_layer1_direction; vector3f cloud_layer1_direction;
vector3 cloud_layer2_direction; vector3f cloud_layer2_direction;
std::string sun; std::string sun;
color general_color; color general_color;
color sun_color; color sun_color;

View file

@ -86,8 +86,8 @@ struct segment
struct description struct description
{ {
vector3 min; vector3f min;
vector3 max; vector3f max;
float unk0[5]; float unk0[5];
uint32_t unk1[7]; uint32_t unk1[7];
}; };

View file

@ -407,7 +407,7 @@ bool CreateScene(model &model, const std::string &name, FbxManager* pSdkManager,
// Set texture properties. // Set texture properties.
lTexture = FbxFileTexture::Create(pScene, "Diffuse Texture"); lTexture = FbxFileTexture::Create(pScene, "Diffuse Texture");
lTexture->SetFileName((b.h.tex_mask + texture_extension).c_str()); // Resource file is in current directory. lTexture->SetFileName((b.h.mask.name + texture_extension).c_str()); // Resource file is in current directory.
lTexture->SetTextureUse(FbxTexture::eStandard); lTexture->SetTextureUse(FbxTexture::eStandard);
lTexture->SetMappingType(FbxTexture::eUV); lTexture->SetMappingType(FbxTexture::eUV);
lTexture->SetMaterialUse(FbxFileTexture::eModelMaterial); lTexture->SetMaterialUse(FbxFileTexture::eModelMaterial);
@ -417,7 +417,7 @@ bool CreateScene(model &model, const std::string &name, FbxManager* pSdkManager,
// Set texture properties. // Set texture properties.
lTexture = FbxFileTexture::Create(pScene, "Ambient Texture"); lTexture = FbxFileTexture::Create(pScene, "Ambient Texture");
lTexture->SetFileName((b.h.tex_mask + texture_extension).c_str()); // Resource file is in current directory. lTexture->SetFileName((b.h.mask.name + texture_extension).c_str()); // Resource file is in current directory.
lTexture->SetTextureUse(FbxTexture::eStandard); lTexture->SetTextureUse(FbxTexture::eStandard);
lTexture->SetMappingType(FbxTexture::eUV); lTexture->SetMappingType(FbxTexture::eUV);
lTexture->SetMaterialUse(FbxFileTexture::eModelMaterial); lTexture->SetMaterialUse(FbxFileTexture::eModelMaterial);
@ -427,7 +427,7 @@ bool CreateScene(model &model, const std::string &name, FbxManager* pSdkManager,
// Set texture properties. // Set texture properties.
lTexture = FbxFileTexture::Create(pScene, "Specular Texture"); lTexture = FbxFileTexture::Create(pScene, "Specular Texture");
lTexture->SetFileName((b.h.tex_spec + texture_extension).c_str()); // Resource file is in current directory. lTexture->SetFileName((b.h.spec.name + texture_extension).c_str()); // Resource file is in current directory.
lTexture->SetTextureUse(FbxTexture::eStandard); lTexture->SetTextureUse(FbxTexture::eStandard);
lTexture->SetMappingType(FbxTexture::eUV); lTexture->SetMappingType(FbxTexture::eUV);
lTexture->SetMaterialUse(FbxFileTexture::eModelMaterial); lTexture->SetMaterialUse(FbxFileTexture::eModelMaterial);

View file

@ -16,6 +16,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <buffer.h>
#include "fbx.h"
#include "model.h"
#include <primitives/filesystem.h>
#include <args.hxx>
#include <algorithm> #include <algorithm>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
@ -24,12 +31,6 @@
#include <stdint.h> #include <stdint.h>
#include <string> #include <string>
#include <buffer.h>
#include "model.h"
#include "fbx.h"
#include <primitives/filesystem.h>
using namespace std; using namespace std;
// options // options
@ -61,11 +62,18 @@ void convert_model(const path &fn)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
try try
{ {
if (argc < 2 || !parse_cmd(argc, argv)) args::ArgumentParser parser("mmo extractor");
{ args::HelpFlag help(parser, "help", "Display this help menu", { 'h', "help" });
printf("Usage: %s [OPTIONS] {model_file,model_dir}\n", argv[0]); args::Flag mr(parser, "mr", "AIM Racing MOD file", { "mr" });
return 1; args::Positional<std::string> file_path(parser, "file or directory", "MOD_ file or directory with MOD_ files");
} parser.Prog(argv[0]);
parser.ParseCLI(argc, argv);
if (mr)
gameType = GameType::AimR;
p = file_path.Get();
if (fs::is_regular_file(p)) if (fs::is_regular_file(p))
convert_model(p); convert_model(p);
else if (fs::is_directory(p)) else if (fs::is_directory(p))

View file

@ -259,14 +259,14 @@ std::string block::printMtl() const
// d 1.0 // d 1.0
// illum // illum
s += "\n"; s += "\n";
if (h.tex_mask != "_DEFAULT_") if (h.mask.name != "_DEFAULT_")
s += "map_Ka " + h.tex_mask + texture_extension + "\n"; s += "map_Ka " + h.mask.name + texture_extension + "\n";
if (h.tex_mask != "_DEFAULT_") if (h.mask.name != "_DEFAULT_")
s += "map_Kd " + h.tex_mask + texture_extension + "\n"; s += "map_Kd " + h.mask.name + texture_extension + "\n";
if (h.tex_spec != "_DEFAULT_") if (h.spec.name != "_DEFAULT_")
s += "map_Ks " + h.tex_spec + texture_extension + "\n"; s += "map_Ks " + h.spec.name + texture_extension + "\n";
if (h.tex_spec != "_DEFAULT_") if (h.spec.name != "_DEFAULT_")
s += "map_Ns " + h.tex_spec + texture_extension + "\n"; s += "map_Ns " + h.spec.name + texture_extension + "\n";
s += "\n"; s += "\n";
return s; return s;
} }
@ -306,19 +306,36 @@ std::string block::printObj(int group_offset, bool rotate_x_90) const
return s; return s;
} }
void block::header::texture::load(const buffer &b)
{
READ_STRING(b, name);
if (gameType == GameType::AimR)
READ(b, number);
}
void block::header::load(const buffer &b) void block::header::load(const buffer &b)
{ {
READ(b, type); READ(b, type);
READ_STRING(b, name); READ_STRING(b, name);
name = translate(name); name = translate(name);
READ_STRING(b, tex_mask); mask.load(b);
READ_STRING(b, tex_spec); spec.load(b);
READ_STRING(b, tex3); tex3.load(b);
READ_STRING(b, tex4); tex4.load(b);
READ(b, all_lods); READ(b, all_lods);
if (gameType == GameType::AimR)
{
READ(b, unk2[0]);
READ(b, unk2[1]);
READ(b, size);
}
else
READ(b, unk2); READ(b, unk2);
READ(b, unk3); READ(b, unk3);
if (gameType != GameType::AimR)
READ(b, size); READ(b, size);
else
READ(b, unk2[2]); // unk4_0 - related to unk4 - some vector3f
READ(b, unk4); READ(b, unk4);
} }

View file

@ -18,6 +18,8 @@
#pragma once #pragma once
#include "types.h"
#include <stdint.h> #include <stdint.h>
#include <string> #include <string>
#include <vector> #include <vector>
@ -75,14 +77,6 @@ enum class MaterialType : uint32_t
Fire2 = 0x3D, Fire2 = 0x3D,
}; };
template <typename T>
struct vector3
{
T x;
T y;
T z;
};
template <typename T> template <typename T>
struct aim_vector3 : vector3<T> struct aim_vector3 : vector3<T>
{ {
@ -199,12 +193,20 @@ struct block
{ {
struct header struct header
{ {
struct texture
{
std::string name;
uint32_t number; // AimR
void load(const buffer &b);
};
BlockType type; BlockType type;
std::string name; std::string name;
std::string tex_mask; texture mask;
std::string tex_spec; texture spec;
std::string tex3; texture tex3;
std::string tex4; texture tex4;
union // LODs union // LODs
{ {
struct struct
@ -224,7 +226,7 @@ struct block
// unk // unk
uint32_t unk2[3]; uint32_t unk2[3];
uint32_t unk3; uint32_t unk3;
uint32_t unk4[10]; float unk4[10];
void load(const buffer &b); void load(const buffer &b);
}; };

View file

@ -124,7 +124,7 @@ struct header_segment : public segment
{ {
uint32_t unk1[3]; uint32_t unk1[3];
std::string save_name; std::string save_name;
vector3 position; vector3f position;
std::string mmp_file; std::string mmp_file;
std::string location_name; std::string location_name;
Common camera; Common camera;
@ -710,7 +710,7 @@ struct groups_segment : public segment
struct group struct group
{ {
vector3 pos; vector3f pos;
std::string org; std::string org;
std::string base; std::string base;
float unk0[4]; float unk0[4];