Skip to content

Commit

Permalink
Merge pull request #835 from OpenKH/mseteditor2
Browse files Browse the repository at this point in the history
OpenKh.Tools.Kh2MsetMotionEditor
  • Loading branch information
Vladabdf authored Nov 7, 2023
2 parents bfdc9dd + 178b39f commit 847eb2e
Show file tree
Hide file tree
Showing 106 changed files with 7,925 additions and 59 deletions.
10 changes: 10 additions & 0 deletions OpenKh.Engine/MathEx.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

namespace OpenKh.Engine
{
public static class MathEx
Expand All @@ -13,5 +15,13 @@ public static float CubicHermite(float t, float p0, float p1, float m0, float m1
var t3 = t2 * t;
return (2 * t3 - 3 * t2 + 1) * p0 + (t3 - 2 * t2 + t) * m0 + (-2 * t3 + 3 * t2) * p1 + (t3 - t2) * m1;
}

/// <see cref="https://stackoverflow.com/a/1971667"/>
public static float Modulus(float dividend, float divisor)
{
return (float)((Math.Abs(dividend) - (Math.Abs(divisor) *
(Math.Floor(Math.Abs(dividend) / Math.Abs(divisor))))) *
Math.Sign(dividend));
}
}
}
12 changes: 6 additions & 6 deletions OpenKh.Kh2/CodeGenerators/CodeGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ public partial class ExpressionNode
{
public int Element
{
get => (int)BitsUtil.Int.GetBits(Data, 0, 16);
set => Data = (int)BitsUtil.Int.SetBits((int)Data, 0, 16, (int)value);
get => (int)BitsUtil.Int.GetBits(Data, 16, 16);
set => Data = (int)BitsUtil.Int.SetBits((int)Data, 16, 16, (int)value);
}

public byte Type
{
get => (byte)BitsUtil.Int.GetBits(Data, 24, 8);
set => Data = (int)BitsUtil.Int.SetBits((int)Data, 24, 8, (int)value);
get => (byte)BitsUtil.Int.GetBits(Data, 0, 8);
set => Data = (int)BitsUtil.Int.SetBits((int)Data, 0, 8, (int)value);
}

public bool IsGlobal
{
get => BitsUtil.Int.GetBit(Data, 23);
set => Data = (int)BitsUtil.Int.SetBit((int)Data, 23, value);
get => BitsUtil.Int.GetBit(Data, 8);
set => Data = (int)BitsUtil.Int.SetBit((int)Data, 8, value);
}

}
Expand Down
73 changes: 73 additions & 0 deletions OpenKh.Kh2AnimEmu/BinaryResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions OpenKh.Kh2AnimEmu/BinaryResources.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="ee_mset_ram_bin" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>ee.mset.ram.bin.gz;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>
36 changes: 36 additions & 0 deletions OpenKh.Kh2AnimEmu/Mset/EmuBasedAnimMatricesProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ Stream animStream

int IAnimMatricesProvider.MatrixCount => animReader.cntb2;

public void ResetGameTimeDelta()
{
absTime = 0;
}

Matrix4x4[] IAnimMatricesProvider.ProvideMatrices(double delta)
{
absTime += delta;
Expand All @@ -67,5 +72,36 @@ Matrix4x4[] IAnimMatricesProvider.ProvideMatrices(double delta)

return matrixOut;
}

public (Matrix4x4[] Fk, Matrix4x4[] Ik) ProvideMatrices2(double gameTimeDelta)
{
absTime += gameTimeDelta;

var matrixOutStream = new MemoryStream();

emuRunner.Permit(
null, animReader.cntb1,
null, animReader.cntb2,
0, (float)absTime, matrixOutStream
);

matrixOutStream.Position = 0;

var fk = new Matrix4x4[animReader.cntb1];
for (int t = 0; t < animReader.cntb1; t++)
{
fk[t] = matrixOutStream.ReadMatrix4x4();
}

var numIk = animReader.cntb2 - animReader.cntb1;
var ik = new Matrix4x4[numIk];
for (int t = 0; t < numIk; t++)
{
ik[t] = matrixOutStream.ReadMatrix4x4();
}

return (fk, ik);
}

}
}
57 changes: 4 additions & 53 deletions OpenKh.Kh2AnimEmu/Mset/EmuRunner/Mlink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Collections;
using System.Xml;
using System.IO.Compression;
using OpenKh.Kh2AnimEmu;

namespace OpenKh.Kh2Anim.Mset.EmuRunner
{
Expand All @@ -22,32 +23,6 @@ public class Mlink
int cntPass = 0;
uint offMdlx04 = uint.MaxValue;

class CnfUt
{
public static string findeeram
{
get
{
var file = "rawData/ee.mset.ram.bin.gz";
{
string path = Path.Combine(Environment.CurrentDirectory, file);
if (File.Exists(path))
{
return path;
}
}
{
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, file);
if (File.Exists(path))
{
return path;
}
}
throw new FileNotFoundException($"Please deploy '{file}' for MSET emulation!");
}
}
}

public void Permit(Stream fsMdlx, int cnt1, Stream fsMset, int cnt2, uint offMsetRxxx, float tick, MemoryStream os)
{
if (cntPass == 0)
Expand All @@ -60,7 +35,7 @@ public void Permit(Stream fsMdlx, int cnt1, Stream fsMset, int cnt2, uint offMse
#if UsePressed_eeram
Szexp.Decode(Resources.eeramx, ee.ram, ee.ram.Length);
#else
using (FileStream fsi = File.OpenRead(CnfUt.findeeram))
using (var fsi = new MemoryStream(BinaryResources.ee_mset_ram_bin))
using (GZipStream gz = new GZipStream(fsi, CompressionMode.Decompress))
{
gz.Read(ee.ram, 0, 32 * 1024 * 1024);
Expand Down Expand Up @@ -291,6 +266,7 @@ public void Permit(Stream fsMdlx, int cnt1, Stream fsMset, int cnt2, uint offMse
}

os.Write(ee.ram, (int)tmp4, 0x40 * cnt1);
os.Write(ee.ram, (int)tmpa, 0x40 * cnt2);

cntPass++;

Expand All @@ -308,7 +284,7 @@ public void Permit_DEB(Stream fsMdlx, int cnt1, Stream fsMset, int cnt2, uint of
#if UsePressed_eeram
Szexp.Decode(Resources.eeramx, ee.ram, ee.ram.Length);
#else
using (FileStream fsi = File.OpenRead(CnfUt.findeeram))
using (var fsi = new MemoryStream(BinaryResources.ee_mset_ram_bin))
using (GZipStream gz = new GZipStream(fsi, CompressionMode.Decompress))
{
gz.Read(ee.ram, 0, 32 * 1024 * 1024);
Expand Down Expand Up @@ -567,31 +543,6 @@ void here(uint pc) { }
internal void Init1(CustEE ee) { this.ee = ee; }
}

class Uteeram
{
class CnfUt
{
public static string findeeram
{
get
{
string[] al = new string[] {
@"H:\Proj\khkh_xldM\MEMO\expSim\rc1\eeram.bin",
Path.Combine(Environment.CurrentDirectory, "eeram.bin"),
};
foreach (string s in al)
{
if (File.Exists(s))
return s;
}
return al[1];
}
}
}

public static byte[] eeram = File.ReadAllBytes(CnfUt.findeeram);
}

class MobRecUt
{
public delegate void Tx8();
Expand Down
Loading

0 comments on commit 847eb2e

Please sign in to comment.