Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Jak 2 Support #4

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,11 @@ $RECYCLE.BIN/
Network Trash Folder
Temporary Items
.apdisk

#VS files
Debug/
*/.vs/
*.pdb
*.VC.db
*.VC.VC.opendb
*.exe
Binary file removed goaldis.exe
Binary file not shown.
64 changes: 64 additions & 0 deletions goaldis/compression.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <string.h>
#include "compression.h"

static const unsigned char magic[4] =
{ 0x6F, 0x5A, 0x6C, 0x42 };


int decompress(uint8_t **fileData, uint32_t *fileSize)
{
uint8_t *input = *fileData;
uint8_t *output;
uint8_t *out_pos;
lzo_uint out_len;
lzo_uint bufferSize;
lzo_uint decompressSize;
if (memcmp(input, magic, sizeof(magic)) != 0)
{
return COMPRESSION_INVALID_FILE;
}
input += 4;

if (lzo_init() != LZO_E_OK)
{
return COMPRESSION_LZO_ERROR;
}

decompressSize = *(uint32_t *)(input); input += 4;

output = new uint8_t[decompressSize];
out_pos = output;

while (true)
{
do
{
bufferSize = *(uint32_t *)(input); input += 4;
} while (!bufferSize);

if (bufferSize < COMPRESSION_BLOCK_SIZE)
{
int r = lzo1x_decompress(input, bufferSize, out_pos, &out_len, NULL);
if (r != LZO_E_OK)
{
delete[] output;
return COMPRESSION_LZO_ERROR;
}
}
else
{
bufferSize = out_len = COMPRESSION_BLOCK_SIZE;
memcpy(out_pos, input, bufferSize);
}

input += bufferSize;
out_pos += out_len;
if (out_pos - output == decompressSize) break;
if ((input - (*fileData)) % 4) input += 4 -((input - (*fileData)) % 4);
}

delete[] * fileData;
*fileData = output;
*fileSize = decompressSize;
return COMPRESSION_OK;
}
17 changes: 17 additions & 0 deletions goaldis/compression.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once
#ifndef COMPRESSION_H
#define COMPRESSION_H

#include <stdint.h>
#include "minilzo.h"

#define COMPRESSION_OK 0
#define COMPRESSION_INVALID_FILE 1
#define COMPRESSION_INTERNAL_ERROR 2
#define COMPRESSION_LZO_ERROR 3

#define COMPRESSION_BLOCK_SIZE 0x8000

int decompress(uint8_t **fileData, uint32_t *fileSize);

#endif // !COMPRESSION_H
73 changes: 64 additions & 9 deletions goaldis/disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ static string relocTarget(uint32_t *addr)
int16_t i = (int16_t)((*addr) & 0xffff);
return SYMBOL(s7 + ((uint16_t)i)/sizeof(symbol));
}
default: assert(0); return "";
default:
assert(0);
return "";
}
}

Expand Down Expand Up @@ -272,12 +274,51 @@ uint32_t *disasmFunc(uint32_t *obj, void *segment_end)
return end;
}

void disasmData(uint32_t *start, uint32_t *end, void *segment_end)
// Naively copy pasting!
uint32_t *disasmThread(uint32_t *obj, void *segment_end)
{
uint32_t *end;

string name = LABEL(obj);

while (true)
{
pass_finished = true;
end = doPass(obj, segment_end);
if (pass_finished)
break;
}

return end;
}

// Naively copy pasting!
uint32_t *disasmType(uint32_t *obj, void *segment_end)
{
uint32_t *end;

string name = LABEL(obj);

while (true)
{
pass_finished = true;
end = doPass(obj, segment_end);
if (pass_finished)
break;
}

return end;
}

bool disasmData(uint32_t *start, uint32_t *end, void *segment_end)
{
if (start == end)
return;
return true;

assert(start < end);
if (start > end) {
printf("goaldis: ERROR - TODO - Disassembling out of bounds data\n");
return false;
}

// Check for uninitialized data at the end of art-group files.
// (TODO: detection not perfect)
Expand Down Expand Up @@ -352,7 +393,9 @@ uint32_t *disasmObj(uint32_t *obj, uint32_t *segment_start, uint32_t *segment_en
switch (id)
{
case s_function: end = disasmFunc(obj, segment_end); break;
case s_thread: end = disasmThread(obj, segment_end); break;
case s_string: end = disasmString(obj, segment_end); break;
case s_type: end = disasmType(obj, segment_end); break;
default:
end = obj; break;
}
Expand All @@ -368,7 +411,7 @@ void disasmEnd()
labels.clear();
}

void disasmFile(FILE *fp, MetaGoFile *go, bool final_pass)
bool disasmFile(FILE *fp, MetaGoFile *go, bool final_pass)
{
disasmBegin(fp, go, final_pass);

Expand All @@ -392,17 +435,29 @@ void disasmFile(FILE *fp, MetaGoFile *go, bool final_pass)

std::sort(objs.begin(), objs.end());

int i = 0;
for each (uint32_t *obj in objs)
{
{
i++;
if (obj < prev)
continue;

if (i == 20) {
print("hey");
}

disasmData(prev, obj - 1, end);
prev = disasmObj(obj, s.start, end);
assert(prev <= end);
if (prev > end) {
printf("goaldis: ERROR - TODO - Could not Disasm Object\n");
return false;
}
}

assert(prev <= end);
if (prev > end) {
printf("goaldis: ERROR - TODO - Could not Disasm Object\n");
return false;
}

disasmData(prev, end, end);
}

Expand Down
2 changes: 1 addition & 1 deletion goaldis/goaldis.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ using namespace std;
struct MetaGoFile;

// Custom GOAL-based MIPS disassembler
void disasmFile(FILE *_fp, MetaGoFile *go, bool final_pass);
bool disasmFile(FILE *_fp, MetaGoFile *go, bool final_pass);

// DGO linker/loader
// Ported directly from the MIPS disassembly.
Expand Down
13 changes: 11 additions & 2 deletions goaldis/goaldis.vcxproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
Expand All @@ -15,7 +15,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
Expand Down Expand Up @@ -45,16 +45,25 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="compression.cpp" />
<ClCompile Include="disasm.cpp" />
<ClCompile Include="link.cpp" />
<ClCompile Include="machine.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="meta.cpp" />
<ClCompile Include="minilzo.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="compression.h" />
<ClInclude Include="lzoconf.h" />
<ClInclude Include="lzodefs.h" />
<ClInclude Include="minilzo.h" />
<ClInclude Include="opcodes.h" />
<ClInclude Include="goaldis.h" />
</ItemGroup>
<ItemGroup>
<None Include="..\test\COMMON.CGO" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
16 changes: 16 additions & 0 deletions goaldis/goaldis.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,25 @@
<ClCompile Include="machine.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="meta.cpp" />
<ClCompile Include="minilzo.c" />
<ClCompile Include="compression.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="opcodes.h" />
<ClInclude Include="goaldis.h" />
<ClInclude Include="minilzo.h" />
<ClInclude Include="compression.h" />
<ClInclude Include="lzoconf.h" />
<ClInclude Include="lzodefs.h" />
</ItemGroup>
<ItemGroup>
<Filter Include="test">
<UniqueIdentifier>{909cafbb-981c-4ade-8d66-07223a9c4b67}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<None Include="..\test\COMMON.CGO">
<Filter>test</Filter>
</None>
</ItemGroup>
</Project>
7 changes: 7 additions & 0 deletions goaldis/goaldis.vcxproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerCommandArguments>"C:\\Users\\xtvas\\Repositories\\goaldis\\test\\COMMON.CGO" C:\\Users\\xtvas\\Repositories\\goaldis\\test\\output</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>
Loading