Skip to content

Commit

Permalink
Complete Rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
Tupelov committed Sep 29, 2022
1 parent c97fe96 commit 9f62067
Show file tree
Hide file tree
Showing 66 changed files with 1,533 additions and 2,302 deletions.
50 changes: 38 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
# Libellus files

# Event files
*.pm1
*.pm2
*.pm3




## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore

# User-specific files
*.rsuser
Expand Down Expand Up @@ -100,6 +90,7 @@ StyleCopReport.xml
*.tmp_proj
*_wpftmp.csproj
*.log
*.tlog
*.vspscc
*.vssscc
.builds
Expand Down Expand Up @@ -303,6 +294,17 @@ node_modules/
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw

# Visual Studio 6 auto-generated project file (contains which files were open etc.)
*.vbp

# Visual Studio 6 workspace and project file (working project files containing files to include in project)
*.dsw
*.dsp

# Visual Studio 6 technical files
*.ncb
*.aps

# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
Expand Down Expand Up @@ -359,6 +361,9 @@ ASALocalRun/
# Local History for Visual Studio
.localhistory/

# Visual Studio History (VSHistory) files
.vshistory/

# BeatPulse healthcheck temp database
healthchecksdb

Expand All @@ -369,4 +374,25 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd

# VS Code files for those working on multiple tools
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

# Local History for Visual Studio Code
.history/

# Windows Installer files from build outputs
*.cab
*.msi
*.msix
*.msm
*.msp

# JetBrains Rider
*.sln.iml
31 changes: 31 additions & 0 deletions Libellus Event Editing Tool.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31919.166
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Libellus Library", "Libellus Library\Libellus Library.csproj", "{8C8535E3-BA4F-42BD-81E4-D957E5D909DD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Libellus Event Tool", "Libellus Event Tool\Libellus Event Tool.csproj", "{ECF2C9F6-3F35-4AE8-B4F6-8E9B82DB3517}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8C8535E3-BA4F-42BD-81E4-D957E5D909DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8C8535E3-BA4F-42BD-81E4-D957E5D909DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8C8535E3-BA4F-42BD-81E4-D957E5D909DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8C8535E3-BA4F-42BD-81E4-D957E5D909DD}.Release|Any CPU.Build.0 = Release|Any CPU
{ECF2C9F6-3F35-4AE8-B4F6-8E9B82DB3517}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ECF2C9F6-3F35-4AE8-B4F6-8E9B82DB3517}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ECF2C9F6-3F35-4AE8-B4F6-8E9B82DB3517}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ECF2C9F6-3F35-4AE8-B4F6-8E9B82DB3517}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1CE93346-778F-40E8-8E0A-705D29BD9440}
EndGlobalSection
EndGlobal
34 changes: 34 additions & 0 deletions Libellus Event Tool/Libellus Event Tool.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<RootNamespace>Libellus_Event_Tool</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>Libellus Event Editing Tool</AssemblyName>
<ApplicationIcon>heeho.ico</ApplicationIcon>
<AssemblyVersion>2.0.0</AssemblyVersion>
<FileVersion>2.0.0</FileVersion>
<SignAssembly>False</SignAssembly>

<TargetFramework>net6.0</TargetFramework>

</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>portable</DebugType>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>portable</DebugType>
</PropertyGroup>

<ItemGroup>
<Content Include="heeho.ico" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Libellus Library\Libellus Library.csproj" />
</ItemGroup>

</Project>
47 changes: 47 additions & 0 deletions Libellus Event Tool/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using LibellusLibrary.Event;


namespace LibellusEventTool
{
class Program
{
static async Task Main(string[] args)
{

System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
string version = fvi.FileVersion;
Console.WriteLine("Welcome to LEET!\nLibellus Event Editing Tool: v" + version + " \nNow with better syntax!\n");

if (args.Length < 1)
{
Console.WriteLine("Not Enough args!");
Console.WriteLine("Press Any Button To Exit.");
Console.ReadKey();
return;
}
foreach (string file in args)
{
string ext = Path.GetExtension(file).ToLower();
if (ext == ".pm1" || ext == ".pm2" || ext == ".pm3")
{
Console.WriteLine("Coverting to Json: ", file);;
PmdReader reader = new PmdReader();
PolyMovieData pmd = await reader.ReadPmd(file);
pmd.ExtractPmd(file, Path.GetFileNameWithoutExtension(file));
continue;
}

if (ext == ".json")
{
Console.WriteLine("Coverting to PMD: ", file);
PolyMovieData pmd = await PolyMovieData.LoadPmd(Path.Combine(file));
string pmdext = "PM" + pmd.MagicCode[3];
pmd.SavePmd(file + "." + pmdext);
}
}
Console.WriteLine("Press Any Button To Exit.");
Console.ReadKey();
}
}
}
7 changes: 7 additions & 0 deletions Libellus Event Tool/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"profiles": {
"Libellus Event Tool": {
"commandName": "Project"
}
}
}
3 changes: 3 additions & 0 deletions Libellus Event Tool/Resources/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
</configuration>
File renamed without changes.
Binary file added Libellus Event Tool/heeho.ico
Binary file not shown.
139 changes: 139 additions & 0 deletions Libellus Library/Event/PmdBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
using LibellusLibrary.Event.Types;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LibellusLibrary.Utils;
using System.Collections.Concurrent;
using LibellusLibrary.Utils.IO;

namespace LibellusLibrary.Event
{
internal class PmdBuilder
{
internal PolyMovieData Pmd;

public List<PmdTypeID> ExistingTypes = new();

internal Dictionary<PmdTypeID, List<byte[]>> ReferenceTables = new();

internal Dictionary<IReferenceType, int> nameTableReferenceIndices = new();

internal ConcurrentDictionary<PmdTypeID, List<PmdDataType>> typeTable = new();

internal PmdBuilder(PolyMovieData Pmd)
{
this.Pmd = Pmd;
}

// I sincerely apologize for the absolute hell that is the writing code
//I dont know what the fuck I was smoking but I know if I touch it, the whole thing will explode
internal async Task<MemoryStream> CreatePmd(string path)
{

MemoryStream pmdFile = new MemoryStream();
using var writer = new BinaryWriter(pmdFile);

//await using DisposableDictionaryAsync<PmdDataType, long> dataTypes = new();
Dictionary<PmdDataType,long> dataTypes = new();
// Type, offset
foreach (PmdDataType pmdData in Pmd.PmdDataTypes)
{
if(pmdData is IReferenceType reference)
{
reference.SetReferences(this);
}
}
writer.FSeek(0x20 + 0x10 * Pmd.PmdDataTypes.Count + 0x40);
foreach (var referenceType in ReferenceTables)
{
var dataType = new PmdData_RawData();
dataType.Type = referenceType.Key;
dataType.Data = referenceType.Value;
var start = writer.FTell();
dataType.SaveData(this, writer);
dataTypes.Add(dataType, start);
//writer.Write(dataTypes[dataType].Item1.ToArray());
}

List<Task<MemoryStream>> writeDataTasks = new();
foreach (PmdDataType pmdData in Pmd.PmdDataTypes)
{
var start = writer.FTell();
pmdData.SaveData(this, writer);
dataTypes.Add(pmdData, start);
//writer.Write(dataTypes[pmdData].Item1.ToArray());
}


/*
// I know this is incredibly cursed and I have no idea why this was neccessary
var reversed = dataStreams.ToDictionary(x => x.Value, x => x.Key);
//reversed.Reverse();
// Gives us plenty of space to write
pmdFile.Seek(0x20 + 0x10 * Pmd.PmdDataTypes.Count + 0x40, SeekOrigin.Begin);
List<Task> writeFileTasks = new();
foreach (var bucket in Async.Interleaved<MemoryStream>(writeDataTasks))
{ // Process tasks as they finish ie. write to file as soon as memory buffer is done
var t = await bucket;
var result = await t;
long offset = pmdFile.Position;
offsets.Add(reversed[result], offset);
writeFileTasks.Add(pmdFile.WriteAsync(result.GetBuffer()).AsTask());
}
await Task.WhenAll(writeFileTasks);
*/
// Write Header


writer.Seek(0, SeekOrigin.Begin);
writer.Write((int)0); // Filetype/format/userid
writer.Write((int)pmdFile.Length);
writer.Write(Pmd.MagicCode.ToCharArray());
writer.Write((int)0); // Expand Size
writer.Write(dataTypes.Count);
writer.Write(Pmd.Version);
writer.Write((int)0); //Reserve
writer.Write((int)0);


// Create Type table
writer.FSeek(0x20);
// Write the type table in the correct order
//IEnumerable<KeyValuePair<PmdDataType, long>> dataTypes = offsets.Reverse();
foreach (KeyValuePair<PmdDataType, long> dataType in dataTypes)
{
writer.Write((int)dataType.Key.Type);
writer.Write((int)dataType.Key.GetSize());// Size
writer.Write((int)dataType.Key.GetCount());
writer.Write((int)dataType.Value); // Offset
}


return pmdFile;
}


/// <summary>
/// Creates another datatype and returns it's index
/// </summary>
/// <param name="id"></param>
/// <param name="data"></param>
/// <returns></returns>
internal int AddReference(PmdTypeID id, byte[] data)
{
if (ReferenceTables.ContainsKey(id))
{
ReferenceTables[id].Add(data);
return ReferenceTables.Count-1;
}
ReferenceTables.Add(id, new List<byte[]>());
ReferenceTables[id].Add(data);
return ReferenceTables.Count - 1;
}

}
}
Loading

0 comments on commit 9f62067

Please sign in to comment.