Unverified Commit f5d30462 authored by GovanifY's avatar GovanifY
Browse files

public I guess?

parent a3c11f38
WCXX = i686-w64-mingw32.static-g++
CXX = g++
linux:
$(CXX) -std=c++11 obj2kh2v.c -o obj2kh2v
clean:
rm -rf *.vif *.o *.dsm *.exe obj2kh2v
windows:
$(WCXX) -std=c++11 obj2kh2v.c -o obj2kh2v.exe
# obj2kh2v
Model importer for Kingdom Hearts 2
It's as dirty as it can get and doesn't even include VU1 assembler
for now but eh, it kinda works.
Good luck for understanding the code btw, should stop working
with vim on 135x10(I'm using a terminal embedded in my file manager, dolphin)
#include <stdio.h>
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
int flag(int x, int y, int z) {
int flagx = x;
if (y > flagx) {flagx = y;}
if (z > flagx) {flagx = z;}
return flagx;
}
int main(int argc, char* argv[]){
printf("obj2kh2v\nPlease input only unwelded sorted models containing only triangles!\n\n");
if(argc<3){printf("Usage: obj2kh2v model.obj output.dsm"); return -1;}
std::ifstream in(argv[1], std::ios::in);
std::ofstream dsm (argv[2]);
dsm << ".align 0\n;" << argv[1] << "\n;Automatically generated by obj2kh2v\n;DO NOT EDIT IF YOU DON'T KNOW WHAT YOU ARE DOING\n\nstcycl 01, 01; We write code to memory without skips/overwrite\n\nunpack 4, 128, V4_32, 0, *; Model Part Header\n.int 1, 0, 0, 0;type 1 Model\n.int 0, 0, 0, 0\n.int 0, 0, 0, 0; Nobody care about vertices merging and colors\n.int 0, 0, 0, 0\n.EndUnpack\n\nstcycl 01, 01; We write code to memory without skips/overwrite\n\nunpack 4, 128, V2_16, 0, *; UV definition\n";
if (dsm.is_open()){
std::string line;
int vi =0;
while (getline(in, line))
{
if (line.substr(0,2) == "v ")
{
vi++;
}
}
for(int i =0; i<vi+1;i++){dsm << ".short 0xffff, 0xffff\n";}
dsm << ".EndUnpack\n\nstmask 0xf3f3f3f3; Sets mask register(3303, check EEUSER_E)\nstcycl 01, 01; We write code to memory without skips/overwrite\n\nunpack 4, 128, S_8, 0, *; Vertex indices\n";
for(int i =0; i<vi+1;i++){dsm << ".byte " << i << "\n";}
dsm << ".EndUnpack\n\nstmask 0xf3f3f3f3; Sets mask register(3303, check EEUSER_E)\nstcycl 01, 01; We write code to memory without skips/overwrite\n\nunpack 4, 128, S_32, 0, *; Flags\n";
in.clear();
in.seekg(0, std::ios::beg);
int iff =1;
int rev=0;
int stock=0;
while (getline(in, line))
{
//printf("uwot");
if (line.substr(0,2) == "f ")
{
line_process:
std::istringstream s(line.substr(2));
std::string i, n, u;
int ii, in, iu;
s >> i; s >> n; s >> u;
ii = std::stoi(i.substr(0, i.find("/")));
in = std::stoi(n.substr(0, n.find("/")));
iu = std::stoi(u.substr(0, u.find("/")));
printf("i1: %d i2: %d i3: %d\n", ii, in, iu);
printf("flag: %d\n", flag(ii, in, iu));
if(iff< flag(ii,in,iu)){dsm << ".int 0x10; stock\n"; stock=1;}
if(iff == flag(ii,in,iu)){ if(stock==1){stock=0; dsm << ".int 0x20; draw triangle\n"; rev=0;} else{if(rev==1){dsm << ".int 0x20; draw triangle\n"; rev=0;} else{dsm << ".int 0x30; draw reversed triangle\n"; rev=1;}}}
if(iff > flag(ii,in,iu)){printf("Unordonned Model! Will abort\n"); return -1;}
iff++;
printf("iff: %d\n", iff);
if(stock==1){goto line_process;}
}
}
dsm << ".EndUnpack\n\nstcol 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000; We set garbage data to 1(float) so even if nothing is referenced game doesn't go crazy\nstmask 0x02020202; Sets mask register(0002, check EEUSER_E)\nstcycl 01, 01; We write code to memory without skips/overwrite\n\nunpack 4, 128, V3_32, 0, *; Vertex definition\n";
in.clear();
in.seekg(0, std::ios::beg);
while (getline(in, line))
{
if (line.substr(0,2) == "v ")
{
std::istringstream s(line.substr(2));
float x, y, z, w;
s >> x; s >> y; s >> z; w = 1.0f;
dsm << ".float " << x << ", " << y << ", " << z << "\n";
}
}
dsm << ".EndUnpack\n\nunpack 4, 128, V4_32, 0, *; Vertex affiliation header\n.int " << vi+1 << ", 0, 0, 0\n.EndUnpack\n";
}
return 1;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment