1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-27 22:57:45 +00:00

const all the things for readability

- removed .mdl collision loading since game doesnt use it

fixed style issues in pcb_reader
This commit is contained in:
Tahir Akhlaq 2017-10-18 15:06:10 +01:00
parent 06271dd669
commit a90fd345dc
6 changed files with 60 additions and 58 deletions

View file

@ -6,17 +6,19 @@ before_install:
- sudo apt-get update
- sudo apt-get install -y software-properties-common
- sudo apt-get update
- sudo apt-get install gcc-4.9 g++-4.9 gcc-4.9-multilib g++-4.9-multilib cmake3 -y
- sudo apt-get install gcc-7 g++-7 gcc-7-multilib g++-7-multilib cmake3 -y
- sudo apt-get install libboost-dev libboost-all-dev libmysqlclient-dev -y
- sudo apt-get install libmysqlcppconn-dev -y
- sudo apt-get install libmysqlcppconn-dev -y
compiler:
- gcc
- g++
# Build steps
script:
- g++ --version
- mkdir build
- cd build
- cmake .. -DSAPPHIRE_BOOST_VER="1.54.0" -DCMAKE_CXX_COMPILER=g++-4.9 -DCMAKE_C_COMPILER=gcc-4.9 && make -j 3
- cmake .. -DSAPPHIRE_BOOST_VER="1.54.0" -DCMAKE_CXX_COMPILER=g++-7 && make -j 3
- cd ..
- bash sql_import.sh

View file

@ -20,7 +20,7 @@ file(GLOB SERVER_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}*.c*")
add_executable(pcb_reader2 ${SERVER_PUBLIC_INCLUDE_FILES} ${SERVER_SOURCE_FILES})
set_target_properties(pcb_reader2 PROPERTIES
CXX_STANDARD 17
CXX_STANDARD 14
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS ON
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/../bin/"

View file

@ -1,14 +1,16 @@
#ifndef _LGB_H
#define _LGB_H
#include "matrix4.h"
#include "vec3.h"
#include <cstring>
#include <memory>
#include <cstdint>
#include <iostream>
#include <vector>
#include <map>
#include <experimental/filesystem>
#include <string>
#include "matrix4.h"
#include "vec3.h"
// all credit to
// https://github.com/ufx/SaintCoinach/blob/master/SaintCoinach/Graphics/Lgb/
@ -105,7 +107,7 @@ public:
LGB_BGPARTS_ENTRY() {};
LGB_BGPARTS_ENTRY( char* buf, uint32_t offset )
{
header = *reinterpret_cast<LGB_BGPARTS_HEADER*>(buf + offset);
header = *reinterpret_cast<LGB_BGPARTS_HEADER*>( buf + offset );
name = std::string( buf + offset + header.nameOffset );
modelFileName = std::string( buf + offset + header.modelFileOffset );
collisionFileName = std::string( buf + offset + header.collisionFileOffset );
@ -135,7 +137,7 @@ public:
LGB_GIMMICK_ENTRY( char* buf, uint32_t offset )
{
header = *reinterpret_cast<LGB_GIMMICK_HEADER*>(buf + offset);
header = *reinterpret_cast<LGB_GIMMICK_HEADER*>( buf + offset );
name = std::string( buf + offset + header.nameOffset );
};
};
@ -167,21 +169,21 @@ struct LGB_GROUP
LGB_GROUP( char* buf, LGB_FILE* parentStruct, uint32_t offset )
{
parent = parentStruct;
header = *reinterpret_cast<LGB_GROUP_HEADER*>(buf + offset);
header = *reinterpret_cast<LGB_GROUP_HEADER*>( buf + offset );
name = std::string( buf + offset + header.groupNameOffset );
//entries.resize( header.entryCount );
//std::cout << name << std::endl;
auto entriesOffset = offset + header.entriesOffset;
const auto entriesOffset = offset + header.entriesOffset;
for( auto i = 0; i < header.entryCount; ++i )
{
auto entryOffset = entriesOffset + *reinterpret_cast<int32_t*>(buf + (entriesOffset + i * 4));
const auto entryOffset = entriesOffset + *reinterpret_cast<int32_t*>( buf + ( entriesOffset + i * 4 ) );
try
{
auto type = *reinterpret_cast<LgbEntryType*>(buf + entryOffset);
const auto type = *reinterpret_cast<LgbEntryType*>( buf + entryOffset );
if( type == LgbEntryType::BgParts )
{
entries.push_back(std::make_shared<LGB_BGPARTS_ENTRY>( buf, entryOffset ));
entries.push_back( std::make_shared<LGB_BGPARTS_ENTRY>( buf, entryOffset ) );
}
/*
else if( type == LgbEntryType::Gimmick )
@ -222,22 +224,25 @@ struct LGB_FILE
LGB_FILE( char* buf )
{
header = *reinterpret_cast<LGB_FILE_HEADER*>(buf);
header = *reinterpret_cast<LGB_FILE_HEADER*>( buf );
if( strncmp( &header.magic[0], "LGB1", 4 ) != 0 || strncmp( &header.magic2[0], "LGP1", 4 ) != 0 )
throw std::exception( "Invalid LGB file!" );
throw std::runtime_error( "Invalid LGB file!" );
//groups.resize(header.groupCount);
auto baseOffset = sizeof( header );
constexpr auto baseOffset = sizeof( header );
for( auto i = 0; i < header.groupCount; ++i )
{
auto groupOffset = baseOffset + *reinterpret_cast<int32_t*>(buf + (baseOffset + i * 4));
auto group = LGB_GROUP( buf, this, groupOffset );
const auto groupOffset = baseOffset + *reinterpret_cast<int32_t*>( buf + ( baseOffset + i * 4 ) );
const auto group = LGB_GROUP( buf, this, groupOffset );
groups.push_back( group );
}
};
};
/*
#if __cplusplus >= 201703L
#include <experimental/filesystem>
std::map<std::string, LGB_FILE> getLgbFiles( const std::string& dir )
{
namespace fs = std::experimental::filesystem;
@ -246,10 +251,10 @@ std::map<std::string, LGB_FILE> getLgbFiles( const std::string& dir )
{
if( path.path().extension() == ".lgb" )
{
auto strPath = path.path().string();
const auto& strPath = path.path().string();
auto f = fopen( strPath.c_str(), "rb" );
fseek( f, 0, SEEK_END );
auto size = ftell( f );
const auto size = ftell( f );
std::vector<char> bytes( size );
rewind( f );
fread( bytes.data(), 1, size, f );
@ -267,4 +272,6 @@ std::map<std::string, LGB_FILE> getLgbFiles( const std::string& dir )
}
return fileMap;
}
#endif
#endif
*/
#endif

View file

@ -1,7 +1,6 @@
#include <stdio.h>
#include <cstdint>
#include <string>
#include <experimental/filesystem>
#include "pcb.h"
#include "lgb.h"
@ -18,7 +17,7 @@
#include <chrono>
using namespace std::chrono_literals;
namespace fs = std::experimental::filesystem;
struct face
{
int32_t f1, f2, f3;
@ -141,15 +140,15 @@ int main( int argc, char* argv[] )
const xiv::dat::Cat& test = data1.get_category( "bg" );
auto &test_file = data1.get_file( "bg/ffxiv/" + zonePath + "/level/bg.lgb" );
auto &section = test_file->access_data_sections().at( 0 );
auto test_file = data1.get_file( "bg/ffxiv/" + zonePath + "/level/bg.lgb" );
auto section = test_file->access_data_sections().at( 0 );
int32_t list_offset = *(uint32_t*)&section[0x18];
int32_t size = *(uint32_t*)&section[4];
std::vector<std::string> stringList;
auto &test_file1 = data1.get_file( "bg/ffxiv/" + zonePath + "/collision/list.pcb" );
auto &section1 = test_file1->access_data_sections().at( 0 );
auto test_file1 = data1.get_file( "bg/ffxiv/" + zonePath + "/collision/list.pcb" );
auto section1 = test_file1->access_data_sections().at( 0 );
std::string path = "bg/ffxiv/" + zonePath + "/collision/";
int offset1 = 0x20;
for( ; ; )
@ -180,7 +179,7 @@ int main( int argc, char* argv[] )
int counter = 0;
// dont bother if we cant write to a file
auto fp_out = fopen( (zoneName + ".obj").c_str(), "w" );
auto fp_out = fopen( ( zoneName + ".obj" ).c_str(), "w" );
if( fp_out )
{
fprintf( fp_out, "\n" );
@ -191,11 +190,11 @@ int main( int argc, char* argv[] )
std::string errorMessage( "Cannot create " + zoneName + ".obj\n" +
" Check no programs have a handle to file and run as admin.\n" );
std::cout << errorMessage;
throw std::exception( errorMessage.c_str() );
throw std::runtime_error( errorMessage.c_str() );
return 0;
}
fp_out = fopen( (zoneName + ".obj").c_str(), "ab+" );
fp_out = fopen( ( zoneName + ".obj" ).c_str(), "ab+" );
if( fp_out )
{
std::map<std::string, PCB_FILE> pcbFiles;
@ -212,7 +211,6 @@ int main( int argc, char* argv[] )
//std::cout << sections.size() << "\n";
uint32_t offset = 0;
uint32_t groupCount = 0;
PCB_FILE pcb_file;
memcpy( &pcb_file.header, &dataSection[0], sizeof( pcb_file.header ) );
offset += sizeof( pcb_file.header );
@ -235,7 +233,6 @@ int main( int argc, char* argv[] )
{
parseBlockEntry( &dataSection[0] + offset, pcb_file.entries, offset );
}
groupCount++;
}
pcbFiles.insert( std::make_pair( fileName, pcb_file ) );
}
@ -246,10 +243,10 @@ int main( int argc, char* argv[] )
};
auto pushVerts = [&]( const PCB_FILE& pcb_file, const std::string& name, const vec3* scale = nullptr, const vec3* rotation = nullptr, const vec3* translation = nullptr )
{
std::string name2 = (name + "_" + std::to_string( objCount[name]++ ));
std::string name2 = ( name + "_" + std::to_string( objCount[name]++ ) );
fprintf( fp_out, "o %s\n", name2.c_str() );
uint32_t groupCount = 0;
for( auto &entry : pcb_file.entries )
for( const auto &entry : pcb_file.entries )
{
float x_base = abs( float( entry.header.x1 - entry.header.x ) );
float y_base = abs( float( entry.header.y1 - entry.header.y ) );
@ -303,7 +300,7 @@ int main( int argc, char* argv[] )
index.index[1] + max_index + 1,
index.index[2] + max_index + 1 );
}
// std::cout << std::to_string( index.unknown[0] )<< " " << std::to_string( index.unknown[1] )<< " " << std::to_string( index.unknown[2]) << std::endl;
// std::cout << std::to_string( index.unknown[0] )<< " " << std::to_string( index.unknown[1] )<< " " << std::to_string( index.unknown[2]) << std::endl;
}
max_index += entry.data.vertices.size() + entry.data.vertices_i16.size();
}
@ -324,20 +321,17 @@ int main( int argc, char* argv[] )
totalGroups++;
for( const auto pEntry : group.entries )
{
auto pBgParts = dynamic_cast<LGB_BGPARTS_ENTRY*>(pEntry.get());
auto pBgParts = static_cast<LGB_BGPARTS_ENTRY*>( pEntry.get() );
auto& fileName = pBgParts->collisionFileName;
if( pBgParts )
{
if ( fileName.empty() )
fileName = pBgParts->modelFileName;
boost::replace_all( fileName, "bgparts", "collision" );
boost::replace_all( fileName, ".mdl", ".pcb" );
}
if( !pBgParts || fileName.empty() )
if( fileName.empty() )
continue;
{
//boost::replace_all( fileName, "bgparts", "collision" );
//boost::replace_all( fileName, ".mdl", ".pcb" );
}
{
const auto& it = pcbFiles.find( fileName );
if( it == pcbFiles.end() )
@ -351,8 +345,6 @@ int main( int argc, char* argv[] )
{
totalGroupEntries++;
//std::cout << pBgParts->collisionFileName << "\n";
const auto* scale = &pBgParts->header.scale;
const auto* rotation = &pBgParts->header.rotation;
const auto* translation = &pBgParts->header.translation;
@ -366,11 +358,11 @@ int main( int argc, char* argv[] )
std::cout << "Total Groups " << totalGroups << " Total entries " << totalGroupEntries << "\n";
}
std::cout << "Finished exporting " << zoneName << " in " <<
std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now() - startTime).count() << " seconds\n";
std::chrono::duration_cast<std::chrono::seconds>( std::chrono::system_clock::now() - startTime ).count() << " seconds\n";
}
catch( std::exception& e )
{
std::cout << e.what() << std::endl;
}
return 0;
}
}

View file

@ -2,6 +2,7 @@
#define _MATRIX4_H
#include <cstdint>
#include <cmath>
// https://github.com/jpd002/Play--Framework/tree/master/include/math
struct matrix4
@ -96,4 +97,4 @@ struct matrix4
return ret;
}
};
#endif
#endif

View file

@ -74,19 +74,19 @@ struct PCB_FILE
struct PCB_LIST_ENTRY
{
uint32_t id;
float x, y, z, x2, y2, z2, rot;
uint32_t id;
float x, y, z, x2, y2, z2, rot;
};
struct PCB_LIST_BASE_ENTRY
{
float x, y, z, x2, y2, z2, rot;
float x, y, z, x2, y2, z2, rot;
};
struct PCB_LIST_FILE
{
uint32_t count;
PCB_LIST_BASE_ENTRY entry;
std::vector<PCB_LIST_ENTRY> entries;
uint32_t count;
PCB_LIST_BASE_ENTRY entry;
std::vector<PCB_LIST_ENTRY> entries;
};
#endif