diff --git a/.gitignore b/.gitignore index 17756527..7514635d 100644 --- a/.gitignore +++ b/.gitignore @@ -377,6 +377,7 @@ liberty/dca-liberty-sim.elf liberty/animtool* liberty/texconv* liberty/imgtool* +liberty/coltool* liberty/extract-sfx* liberty/pack-sfx* liberty/analyze-profile* @@ -395,6 +396,7 @@ miami/dca-miami-sim.elf miami/animtool* miami/texconv* miami/imgtool* +miami/coltool* miami/extract-sfx* miami/pack-sfx* miami/analyze-profile* diff --git a/liberty/Makefile b/liberty/Makefile index c51e3eab..977ef846 100644 --- a/liberty/Makefile +++ b/liberty/Makefile @@ -293,6 +293,9 @@ texconv: $(OBJS_TEXCONV) | pvrtex # You'll have to rebuild pvrtex manually if yo animtool: ../src/tools/animtool.cpp $(CXX) -std=c++17 -o $@ -g -O0 $< +coltool: ../src/tools/coltool.cpp + $(CXX) -std=c++17 -o $@ -g -O0 $< + -include $(DEPS) #### Repacking #### @@ -520,6 +523,22 @@ $(REPACK_GTA_DIR)/%.IFP: $(GTA_DIR)/%.IFP animtool @mkdir -p $(@D) ./animtool $< $@ +# first try the mods loose directory +$(REPACK_GTA_DIR)/%.col: $(GTA_MOD_LOOSE_DIR)/%.col coltool + @mkdir -p $(@D) + ./coltool $< $@ +$(REPACK_GTA_DIR)/%.COL: $(GTA_MOD_LOOSE_DIR)/%.COL coltool + @mkdir -p $(@D) + ./coltool $< $@ + +#if not, the original files +$(REPACK_GTA_DIR)/%.col: $(GTA_DIR)/%.col coltool + @mkdir -p $(@D) + ./coltool $< $@ +$(REPACK_GTA_DIR)/%.COL: $(GTA_DIR)/%.COL coltool + @mkdir -p $(@D) + ./coltool $< $@ + $(REPACK_DIR)/packed: $(IMG_TEXTURES_DC) $(IMG_MODELS_DC) mkdir -p $(@D) mkdir -p "$(REPACK_GTA_DIR)/models/gta3" diff --git a/liberty/gta3files.mk b/liberty/gta3files.mk index f2aeaaf8..ee139b4f 100644 --- a/liberty/gta3files.mk +++ b/liberty/gta3files.mk @@ -1,3 +1,5 @@ +# models/coll/peds.col # not actually used + MISC_FILES = \ anim/cuts.dir \ anim/cuts.img \ @@ -110,7 +112,6 @@ MISC_FILES = \ models/Coll/commer.col \ models/Coll/generic.col \ models/Coll/indust.col \ - models/Coll/peds.col \ models/Coll/suburb.col \ models/Coll/vehicles.col \ models/Coll/weapons.col \ diff --git a/miami/Makefile b/miami/Makefile index bafd0ef8..74848416 100644 --- a/miami/Makefile +++ b/miami/Makefile @@ -299,7 +299,7 @@ texconv: $(OBJS_TEXCONV) | pvrtex # You'll have to rebuild pvrtex manually if yo animtool: ../src/tools/animtool.cpp $(CXX) -std=c++17 -o $@ -g -O0 $< -coltool: coltool.cpp +coltool: ../src/tools/coltool.cpp $(CXX) -std=c++17 -o $@ -g -O0 $< -include $(DEPS) diff --git a/miami/gta3files.mk b/miami/gta3files.mk index 246145d0..6bd1b88f 100644 --- a/miami/gta3files.mk +++ b/miami/gta3files.mk @@ -1,4 +1,4 @@ -# models/coll/peds.col # seems like this is corrupted +# models/coll/peds.col # not actually used MISC_FILES = \ \ diff --git a/src/liberty/collision/ColTriangle.cpp b/src/liberty/collision/ColTriangle.cpp index c025924a..f90f393c 100644 --- a/src/liberty/collision/ColTriangle.cpp +++ b/src/liberty/collision/ColTriangle.cpp @@ -2,7 +2,7 @@ #include "ColTriangle.h" void -CColTriangle::Set(const CompressedVector *, int a, int b, int c, uint8 surf, uint8 piece) +CColTriangle::Set(const CompressedVector *, uint16 a, uint16 b, uint16 c, uint8 surf, uint8 piece) { this->a = a; this->b = b; diff --git a/src/liberty/collision/ColTriangle.h b/src/liberty/collision/ColTriangle.h index 03299463..500f8baf 100644 --- a/src/liberty/collision/ColTriangle.h +++ b/src/liberty/collision/ColTriangle.h @@ -18,7 +18,7 @@ struct CColTriangle uint16 c; uint8 surface; - void Set(const CompressedVector *v, int a, int b, int c, uint8 surf, uint8 piece); + void Set(const CompressedVector *v, uint16 a, uint16 b, uint16 c, uint8 surf, uint8 piece); }; struct CColTrianglePlane diff --git a/src/liberty/collision/CompressedVector.h b/src/liberty/collision/CompressedVector.h index caf07664..3945ebf2 100644 --- a/src/liberty/collision/CompressedVector.h +++ b/src/liberty/collision/CompressedVector.h @@ -5,7 +5,7 @@ struct CompressedVector #ifdef COMPRESSED_COL_VECTORS int16 x, y, z; CVector Get(void) const { return CVector(x, y, z)/128.0f; }; - void Set(float x, float y, float z) { this->x = lroundf(x*128.0f); this->y = lroundf(y*128.0f); this->z = lroundf(z*128.0f); }; + void SetFixed(int16 x, int16 y, int16 z) { this->x = x; this->y = y; this->z = z; }; #ifdef GTA_PS2 void Unpack(uint128 &qword) const { __asm__ volatile ( diff --git a/src/liberty/core/FileLoader.cpp b/src/liberty/core/FileLoader.cpp index 8a362c11..8ebfe11c 100644 --- a/src/liberty/core/FileLoader.cpp +++ b/src/liberty/core/FileLoader.cpp @@ -215,7 +215,7 @@ CFileLoader::LoadCollisionFile(const char *filename) fd = CFileMgr::OpenFile(filename, "rb"); while(CFileMgr::Read(fd, (char*)&header, sizeof(header))){ - assert(header.ident == 'LLOC'); + assert(header.ident == 'CLOC'); CFileMgr::Read(fd, (char*)work_buff, header.size); memcpy(modelname, work_buff, 24); @@ -295,14 +295,8 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname) model.vertices = (CompressedVector*)RwMalloc(numVertices*sizeof(CompressedVector)); REGISTER_MEMPTR(&model.vertices); for(i = 0; i < numVertices; i++){ - model.vertices[i].Set(*(float*)buf, *(float*)(buf+4), *(float*)(buf+8)); - if(lroundf(Abs(*(float*)buf)) >= 256 || - lroundf(Abs(*(float*)(buf+4))) >= 256 || - lroundf(Abs(*(float*)(buf+8))) >= 256) { - dbglog(DBG_CRITICAL, "%s:Collision volume too big\n", modelname); - assert(false && "Collision volume too big"); - } - buf += 12; + model.vertices[i].SetFixed(*(int16*)buf, *(int16*)(buf+2), *(int16*)(buf+4)); + buf += 6; } }else model.vertices = nil; @@ -313,8 +307,11 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname) model.triangles = (CColTriangle*)RwMalloc(model.numTriangles*sizeof(CColTriangle)); REGISTER_MEMPTR(&model.triangles); for(i = 0; i < model.numTriangles; i++){ - model.triangles[i].Set(model.vertices, *(int32*)buf, *(int32*)(buf+4), *(int32*)(buf+8), buf[12], buf[13]); - buf += 16; + model.triangles[i].Set(model.vertices, *(uint16*)buf, *(uint16*)(buf+2), *(uint16*)(buf+4), buf[6], buf[7]); + buf += 8; + assert(model.triangles[i].a < numVertices); + assert(model.triangles[i].b < numVertices); + assert(model.triangles[i].c < numVertices); } }else model.triangles = nil; diff --git a/src/liberty/core/main.cpp b/src/liberty/core/main.cpp index 4b536d3d..9f80c19b 100644 --- a/src/liberty/core/main.cpp +++ b/src/liberty/core/main.cpp @@ -163,36 +163,36 @@ Error(char *fmt, ...) void ValidateVersion() { - int32 file = CFileMgr::OpenFile("models\\coll\\peds.col", "rb"); - char buff[128]; + // int32 file = CFileMgr::OpenFile("models\\coll\\peds.col", "rb"); + // char buff[128]; - if ( file != -1 ) - { - CFileMgr::Seek(file, 100, SEEK_SET); + // if ( file != -1 ) + // { + // CFileMgr::Seek(file, 100, SEEK_SET); - for ( int i = 0; i < 128; i++ ) - { - CFileMgr::Read(file, &buff[i], sizeof(char)); - buff[i] -= 23; - if ( buff[i] == '\0' ) - break; - CFileMgr::Seek(file, 99, SEEK_CUR); - } + // for ( int i = 0; i < 128; i++ ) + // { + // CFileMgr::Read(file, &buff[i], sizeof(char)); + // buff[i] -= 23; + // if ( buff[i] == '\0' ) + // break; + // CFileMgr::Seek(file, 99, SEEK_CUR); + // } - if ( !strncmp(buff, "grandtheftauto3", 15) ) - { - strncpy(version_name, &buff[15], 64); - CFileMgr::CloseFile(file); - return; - } - } + // if ( !strncmp(buff, "grandtheftauto3", 15) ) + // { + // strncpy(version_name, &buff[15], 64); + // CFileMgr::CloseFile(file); + // return; + // } + // } - LoadingScreen("Invalid version", NULL, NULL); + // LoadingScreen("Invalid version", NULL, NULL); - while(true) - { - ; - } + // while(true) + // { + // ; + // } } bool diff --git a/src/miami/collision/CompressedVector.h b/src/miami/collision/CompressedVector.h index db6c0560..0c2faf91 100644 --- a/src/miami/collision/CompressedVector.h +++ b/src/miami/collision/CompressedVector.h @@ -6,7 +6,6 @@ struct CompressedVector int16 x, y, z; CVector Get(void) const { return CVector(x, y, z)/128.0f; }; void SetFixed(int16 x, int16 y, int16 z) { this->x = x; this->y = y; this->z = z; }; - void Set(float x, float y, float z) { this->x = x*128.0f; this->y = y*128.0f; this->z = z*128.0f; }; #ifdef GTA_PS2 void Unpack(uint128 &qword) const { __asm__ volatile ( diff --git a/src/tools/coltool.cpp b/src/tools/coltool.cpp index 4e0a1d6c..864f36dd 100644 --- a/src/tools/coltool.cpp +++ b/src/tools/coltool.cpp @@ -140,7 +140,7 @@ int main(int argc, char* argv[]) { } out_buff.push_back(work_buff[offset]); - out_buff.push_back(0); // padding + out_buff.push_back(work_buff[offset+1]); // 'piece', not actually used offset += 4; } // === End repackaging of collision model data ===