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

Net 8 #87

Merged
merged 6 commits into from
Sep 29, 2023
Merged
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
29 changes: 20 additions & 9 deletions Mafia2Libs/MafiaToolkit.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0-windows7.0</TargetFramework>
<TargetFramework>net8.0-windows8.0</TargetFramework>
<OutputType>WinExe</OutputType>
<RootNamespace>Mafia2Tool</RootNamespace>
<IsWebBootstrapper>false</IsWebBootstrapper>
Expand Down Expand Up @@ -34,6 +34,7 @@
<LangVersion>6</LangVersion>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<PlatformTarget>x64</PlatformTarget>
<Optimize>True</Optimize>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
Expand Down Expand Up @@ -302,24 +303,30 @@
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<PackageReference Include="DockPanelSuite.ThemeVS2015" Version="3.1.0-beta7" />
<PackageReference Include="DockPanelSuite.ThemeVS2015" Version="3.1.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="DockPanelSuite" Version="3.1.0-beta7" />
<PackageReference Include="DockPanelSuite" Version="3.1.0" />
<PackageReference Include="Octokit" Version="0.36.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0" />
<PackageReference Include="Vortice.D3DCompiler" Version="1.9.87" />
<PackageReference Include="Vortice.Direct3D11" Version="1.9.87" />
<PackageReference Include="Vortice.DXGI" Version="1.9.87" />
<PackageReference Include="Vortice.Mathematics" Version="1.3.21" />
<PackageReference Include="Vortice.XInput" Version="1.9.87" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" />
<PackageReference Include="Vortice.D3DCompiler" Version="1.9.143" />
<PackageReference Include="Vortice.Direct3D11" Version="1.9.143" />
<PackageReference Include="Vortice.DXGI" Version="1.9.143" />
<PackageReference Include="Vortice.Mathematics" Version="1.7.2" />
<PackageReference Include="Vortice.XInput" Version="3.2.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="ResourceTypes\FileTypes\M3\XBin\Types\PaintCombinations\Mafia3\" />
<Folder Include="ResourceTypes\FileTypes\Wwise\HIRC\Helpers\" />
<Folder Include="ResourceTypes\FileTypes\Wwise\HIRC\Objects\" />
</ItemGroup>
<ItemGroup>
<None Include="..\README.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>
<PropertyGroup>
<PostBuildEvent>call "$(TargetDir)build.cmd"
cd $(TargetDir)
Expand All @@ -329,5 +336,9 @@ del *.cmd</PostBuildEvent>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<AssemblyVersion>2.24</AssemblyVersion>
<FileVersion>2.24</FileVersion>
<RunAnalyzersDuringBuild>False</RunAnalyzersDuringBuild>
<PackageProjectUrl>https://github.com/Greavesy1899/MafiaToolkit</PackageProjectUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/Greavesy1899/MafiaToolkit.git</RepositoryUrl>
</PropertyGroup>
</Project>
19 changes: 10 additions & 9 deletions Mafia2Libs/Mathematics/Collision.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static bool RayIntersectsPoint(ref Ray ray, ref Vector3 point)
//Same thing as RayIntersectsSphere except that the radius of the sphere (point)
//is the epsilon for zero.
float b = Vector3.Dot(m, ray.Direction);
float c = Vector3.Dot(m, m) - MathHelper.ZeroTolerance;
float c = Vector3.Dot(m, m) - MathHelper.NearZeroEpsilon;

if (c > 0f && b > 0f)
return false;
Expand Down Expand Up @@ -137,9 +137,9 @@ public static bool RayIntersectsRay(ref Ray ray1, ref Ray ray2, out Vector3 poin
if (MathHelper.IsZero(denominator))
{
//Lines are parallel and on top of each other.
if (MathHelper.NearEqual(ray2.Position.X, ray1.Position.X) &&
MathHelper.NearEqual(ray2.Position.Y, ray1.Position.Y) &&
MathHelper.NearEqual(ray2.Position.Z, ray1.Position.Z))
if (MathHelper.CompareEqual(ray2.Position.X, ray1.Position.X) &&
MathHelper.CompareEqual(ray2.Position.Y, ray1.Position.Y) &&
MathHelper.CompareEqual(ray2.Position.Z, ray1.Position.Z))
{
point = Vector3.Zero;
return true;
Expand Down Expand Up @@ -190,10 +190,11 @@ public static bool RayIntersectsRay(ref Ray ray1, ref Ray ray2, out Vector3 poin
Vector3 point1 = ray1.Position + (s * ray1.Direction);
Vector3 point2 = ray2.Position + (t * ray2.Direction);

//If the points are not equal, no intersection has occurred.
if (!MathHelper.NearEqual(point2.X, point1.X) ||
!MathHelper.NearEqual(point2.Y, point1.Y) ||
!MathHelper.NearEqual(point2.Z, point1.Z))
float epsilon = MathHelper.NearZeroEpsilon;

if (Math.Abs(point2.X) > epsilon ||
Math.Abs(point2.Y) > epsilon ||
Math.Abs(point2.Z) > epsilon)
{
point = Vector3.Zero;
return false;
Expand Down Expand Up @@ -279,7 +280,7 @@ public static bool RayIntersectsPlane(ref Ray ray, ref Plane plane, out Vector3
/// </remarks>
public static bool RayIntersectsTriangle(ref Ray ray, ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3, out float distance)
{
//Source: Fast Minimum Storage Ray / Triangle Intersection
//Source: Fast Min Storage Ray / Triangle Intersection
//Reference: http://www.cs.virginia.edu/~gfx/Courses/2003/ImageSynthesis/papers/Acceleration/Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf

//Compute vectors along two edges of the triangle.
Expand Down
4 changes: 2 additions & 2 deletions Mafia2Libs/Rendering/Graphics/DirectX11Class.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,14 @@ private void BuildDepthStencilView(int w, int h)
FrontFace = new DepthStencilOperationDescription()
{
StencilFailOp = StencilOperation.Keep,
StencilDepthFailOp = StencilOperation.Incr,
StencilDepthFailOp = StencilOperation.Increment,
StencilPassOp = StencilOperation.Keep,
StencilFunc = ComparisonFunction.Always,
},
BackFace = new DepthStencilOperationDescription()
{
StencilFailOp = StencilOperation.Keep,
StencilDepthFailOp = StencilOperation.Decr,
StencilDepthFailOp = StencilOperation.Decrement,
StencilPassOp = StencilOperation.Keep,
StencilFunc = ComparisonFunction.Always,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public RenderBoundingBox()

public bool InitSwap(BoundingBox bbox)
{
Vector3 NewMax = bbox.Maximum;
Vector3 NewMax = bbox.Max;
float y = NewMax.Y;
NewMax.Y = -NewMax.Z;
NewMax.Z = y;

Vector3 NewMin = bbox.Minimum;
Vector3 NewMin = bbox.Min;
y = NewMin.Y;
NewMin.Y = -NewMin.Z;
NewMin.Z = y;
Expand Down
6 changes: 3 additions & 3 deletions Mafia2Libs/Rendering/Graphics/RenderTypes/RenderNavCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ public void Init(KynogonRuntimeMesh.Cell cell)
{
RenderLine line = new RenderLine();
line.SetUnselectedColour(System.Drawing.Color.Turquoise);
line.InitSwap(new Vector3[2] { unk10.B1.Maximum, unk10.B1.Minimum });
line.InitSwap(new Vector3[2] { unk10.B1.Max, unk10.B1.Min });
Lines.Add(line);
}

foreach (var unk12 in set.unk12Boxes)
{
RenderLine line = new RenderLine();
line.SetUnselectedColour(System.Drawing.Color.Green);
line.InitSwap(new Vector3[2] { unk12.B1.Maximum, unk12.B1.Minimum });
line.InitSwap(new Vector3[2] { unk12.B1.Max, unk12.B1.Min });
Lines.Add(line);
}

Expand All @@ -63,7 +63,7 @@ public void Init(KynogonRuntimeMesh.Cell cell)
{
RenderLine line = new RenderLine();
line.SetUnselectedColour(System.Drawing.Color.Brown);
line.InitSwap(new Vector3[2] { unk16.Maximum, unk16.Minimum });
line.InitSwap(new Vector3[2] { unk16.Max, unk16.Min });
Lines.Add(line);
}

Expand Down
26 changes: 13 additions & 13 deletions Mafia2Libs/Rendering/Spatial/SpatialGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ public SpatialGrid(GraphicsClass InGraphics, KynogonRuntimeMesh mesh)

width = mesh.CellSizeY;
height = mesh.CellSizeX;
origin = new Vector3(gridBounds.Minimum.X, gridBounds.Minimum.Y, 0.0f);
origin = new Vector3(gridBounds.Min.X, gridBounds.Min.Y, 0.0f);
cellSize = new Vector2(gridBounds.GetWidth() / width, gridBounds.GetHeight() / height);
cells = new SpatialCell[width * height];

Vector3 TempMin = gridBounds.Minimum;
Vector3 TempMax = gridBounds.Maximum;
Vector3 TempMin = gridBounds.Min;
Vector3 TempMax = gridBounds.Max;

var index = 0;
for (int i = 0; i < width; i++)
Expand All @@ -63,20 +63,20 @@ public SpatialGrid(GraphicsClass InGraphics, KynogonRuntimeMesh mesh)

foreach (var set in cell.Sets)
{
if (gridBounds.Minimum.Z < set.X)
if (gridBounds.Min.Z < set.X)
{
TempMin.Z = set.X;
}
if (gridBounds.Maximum.Z > set.Y)
if (gridBounds.Max.Z > set.Y)
{
TempMax.Z = set.Y;
}
}

// Construct cell extents
Vector3 Minimum = new Vector3(origin.X + cellSize.X * x, origin.Y + cellSize.Y * i, 0.0f);
Vector3 Maximum = new Vector3(origin.X + cellSize.X * (x + 1), origin.Y + cellSize.Y * (i + 1), 0.0f);
BoundingBox CellExtents = new BoundingBox(Minimum, Maximum);
Vector3 Min = new Vector3(origin.X + cellSize.X * x, origin.Y + cellSize.Y * i, 0.0f);
Vector3 Max = new Vector3(origin.X + cellSize.X * (x + 1), origin.Y + cellSize.Y * (i + 1), 0.0f);
BoundingBox CellExtents = new BoundingBox(Min, Max);

// Construct Init params
SpatialCell_ObjDataParams InitParams = new SpatialCell_ObjDataParams();
Expand Down Expand Up @@ -104,16 +104,16 @@ public SpatialGrid(GraphicsClass InGraphics, TranslokatorLoader translokator)
height = translokator.Grids[0].Height;
cellSize = new Vector2(gridBounds.GetWidth() / width, gridBounds.GetHeight() / height);
cells = new SpatialCell[width * height];
origin = gridBounds.Minimum;
origin = gridBounds.Min;

var index = 0;
/*for (int i = 0; i < width; i++)
{
for (int x = 0; x < height; x++)
{
var extents = new BoundingBox();
extents.Minimum = new Vector3(origin.X + cellSize.X * x, origin.Y + cellSize.Y * i, 10.0f);
extents.Maximum = new Vector3(origin.X + cellSize.X * (x + 1), origin.Y + cellSize.Y * (i + 1), 10.0f);
extents.Min = new Vector3(origin.X + cellSize.X * x, origin.Y + cellSize.Y * i, 10.0f);
extents.Max = new Vector3(origin.X + cellSize.X * (x + 1), origin.Y + cellSize.Y * (i + 1), 10.0f);
cells[index++] = new SpatialCell(InGraphics, extents);
}
}
Expand Down Expand Up @@ -182,8 +182,8 @@ public void Render(ID3D11Device device, ID3D11DeviceContext deviceContext, Camer
if (previousCell != currentCell)
{
BoundingBox newBounds = cells[currentCell].BoundingBox;
newBounds.Minimum.Z = gridBounds.Minimum.Z;
newBounds.Maximum.Z = gridBounds.Maximum.Z;
newBounds.Min.Z = gridBounds.Min.Z;
newBounds.Max.Z = gridBounds.Max.Z;

cellBoundingBox.Update(newBounds);
cellBoundingBox.UpdateBuffers(device, deviceContext);
Expand Down
4 changes: 2 additions & 2 deletions Mafia2Libs/ResourceTypes/FileTypes/Actors/ActorTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -808,12 +808,12 @@ public HashName[] UnkHashes {
}
[TypeConverter(typeof(Vector3Converter))]
public Vector3 BoundaryBoxMinimum {
get { return boundingBox.Minimum; }
get { return boundingBox.Min; }
set { boundingBox.SetMinimum(value); }
}
[TypeConverter(typeof(Vector3Converter))]
public Vector3 BoundaryBoxMaximum {
get { return boundingBox.Maximum; }
get { return boundingBox.Max; }
set { boundingBox.SetMaximum(value); }
}
public byte UnkByte3 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,12 +604,12 @@ private void WriteBounds(BinaryWriter writer, bool platformMismatch)
WriteFloat(boundingSphere.Center.Z, writer, platformMismatch);
WriteFloat(boundingSphere.Radius, writer, platformMismatch);

WriteFloat(BoundingBox.Minimum.X, writer, platformMismatch);
WriteFloat(BoundingBox.Minimum.Y, writer, platformMismatch);
WriteFloat(BoundingBox.Minimum.Z, writer, platformMismatch);
WriteFloat(BoundingBox.Maximum.X, writer, platformMismatch);
WriteFloat(BoundingBox.Maximum.Y, writer, platformMismatch);
WriteFloat(BoundingBox.Maximum.Z, writer, platformMismatch);
WriteFloat(BoundingBox.Min.X, writer, platformMismatch);
WriteFloat(BoundingBox.Min.Y, writer, platformMismatch);
WriteFloat(BoundingBox.Min.Z, writer, platformMismatch);
WriteFloat(BoundingBox.Max.X, writer, platformMismatch);
WriteFloat(BoundingBox.Max.Y, writer, platformMismatch);
WriteFloat(BoundingBox.Max.Z, writer, platformMismatch);
}

private void WritePhysProperties(BinaryWriter writer, bool platformMismatch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public BoundingBox Bounds {
[TypeConverter(typeof(Vector3Converter))]
public Vector3 BoundaryBoxMinimum
{
get { return bounds.Minimum; }
get { return bounds.Min; }
set { bounds.SetMinimum(value); }
}
[TypeConverter(typeof(Vector3Converter))]
public Vector3 BoundaryBoxMaximum
{
get { return bounds.Maximum; }
get { return bounds.Max; }
set { bounds.SetMaximum(value); }
}

Expand Down Expand Up @@ -96,12 +96,12 @@ public override void WriteToFile(BinaryWriter writer)
public void FillPlanesArray()
{
planes = new Vector4[6];
planes[0] = new Vector4(-1, 0, 0, bounds.Maximum.X);
planes[1] = new Vector4(1, 0, 0, bounds.Maximum.X);
planes[2] = new Vector4(0, -1, 0, bounds.Maximum.Y);
planes[3] = new Vector4(0, 1, 0, bounds.Maximum.Y);
planes[4] = new Vector4(0, 0, -1, bounds.Maximum.Z);
planes[5] = new Vector4(0, 0, 1, bounds.Maximum.Z);
planes[0] = new Vector4(-1, 0, 0, bounds.Max.X);
planes[1] = new Vector4(1, 0, 0, bounds.Max.X);
planes[2] = new Vector4(0, -1, 0, bounds.Max.Y);
planes[3] = new Vector4(0, 1, 0, bounds.Max.Y);
planes[4] = new Vector4(0, 0, -1, bounds.Max.Z);
planes[5] = new Vector4(0, 0, 1, bounds.Max.Z);
}

public override string ToString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ public BoundingBox Bounds {
[TypeConverter(typeof(Vector3Converter))]
public Vector3 BoundaryBoxMinimum
{
get { return bounds.Minimum; }
get { return bounds.Min; }
set { bounds.SetMinimum(value); }
}
[TypeConverter(typeof(Vector3Converter))]
public Vector3 BoundaryBoxMaximum
{
get { return bounds.Maximum; }
get { return bounds.Max; }
set { bounds.SetMaximum(value); }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ public BoundingBox Bounds {
[TypeConverter(typeof(Vector3Converter))]
public Vector3 BoundaryBoxMinimum
{
get { return bounds.Minimum; }
get { return bounds.Min; }
set { bounds.SetMinimum(value); }
}
[TypeConverter(typeof(Vector3Converter))]
public Vector3 BoundaryBoxMaximum
{
get { return bounds.Maximum; }
get { return bounds.Max; }
set { bounds.SetMaximum(value); }
}
public Vector3 Unk13 {
Expand Down Expand Up @@ -126,24 +126,24 @@ public override void WriteToFile(BinaryWriter writer)
public void FillPlanesArray()
{
planes = new Vector4[6];
planes[0] = new Vector4(0, 0, 1, Math.Abs(bounds.Minimum.Z));
planes[1] = new Vector4(1, 0, 0, Math.Abs(bounds.Maximum.X));
planes[2] = new Vector4(0, -1, 0, Math.Abs(bounds.Maximum.Y));
planes[3] = new Vector4(0, 1, 0, Math.Abs(bounds.Maximum.Y));
planes[4] = new Vector4(0, 0, -1, Math.Abs(bounds.Maximum.Z));
planes[5] = new Vector4(-1, 0, 0, Math.Abs(bounds.Maximum.X));
//planes[0] = new Vector4(-1, 0, 0, bounds.Maximum.X);
//planes[1] = new Vector4(1, 0, 0, bounds.Maximum.X);
//planes[2] = new Vector4(0, -1, 0, bounds.Maximum.Y);
//planes[3] = new Vector4(0, 1, 0, bounds.Maximum.Y);
//planes[4] = new Vector4(0, 0, -1, bounds.Maximum.Z);
//planes[5] = new Vector4(0, 0, 1, bounds.Maximum.Z);
////planes[0] = new Vector4(0, 1, 0, Math.Abs(bounds.Minimum.X));
////planes[1] = new Vector4(1, 0, 0, Math.Abs(bounds.Minimum.Y));
////planes[2] = new Vector4(0, 0, -1, bounds.Maximum.Z);
////planes[3] = new Vector4(0, 0, 1, Math.Abs(bounds.Minimum.Y));
////planes[4] = new Vector4(-1, 0, 0, bounds.Maximum.X);
////planes[5] = new Vector4(0, -1, 0, bounds.Maximum.Y);
planes[0] = new Vector4(0, 0, 1, Math.Abs(bounds.Min.Z));
planes[1] = new Vector4(1, 0, 0, Math.Abs(bounds.Max.X));
planes[2] = new Vector4(0, -1, 0, Math.Abs(bounds.Max.Y));
planes[3] = new Vector4(0, 1, 0, Math.Abs(bounds.Max.Y));
planes[4] = new Vector4(0, 0, -1, Math.Abs(bounds.Max.Z));
planes[5] = new Vector4(-1, 0, 0, Math.Abs(bounds.Max.X));
//planes[0] = new Vector4(-1, 0, 0, bounds.Max.X);
//planes[1] = new Vector4(1, 0, 0, bounds.Max.X);
//planes[2] = new Vector4(0, -1, 0, bounds.Max.Y);
//planes[3] = new Vector4(0, 1, 0, bounds.Max.Y);
//planes[4] = new Vector4(0, 0, -1, bounds.Max.Z);
//planes[5] = new Vector4(0, 0, 1, bounds.Max.Z);
////planes[0] = new Vector4(0, 1, 0, Math.Abs(bounds.Min.X));
////planes[1] = new Vector4(1, 0, 0, Math.Abs(bounds.Min.Y));
////planes[2] = new Vector4(0, 0, -1, bounds.Max.Z);
////planes[3] = new Vector4(0, 0, 1, Math.Abs(bounds.Min.Y));
////planes[4] = new Vector4(-1, 0, 0, bounds.Max.X);
////planes[5] = new Vector4(0, -1, 0, bounds.Max.Y);
}

public override string ToString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ public void PreWriteFixup()
{
// Compute from points, then add do a stretch on the extents of the BBox.
BoundingBox NewBBox = BoundingBox.CreateFromPoints(GetPoints());
NewBBox.SetMinimum(NewBBox.Minimum - new Vector3(0.01f));
NewBBox.SetMaximum(NewBBox.Maximum + new Vector3(0.01f));
NewBBox.SetMinimum(NewBBox.Min - new Vector3(0.01f));
NewBBox.SetMaximum(NewBBox.Max + new Vector3(0.01f));
BoundingBox0 = NewBBox;

// Generate lookups for points - use flags to determine list
Expand Down
Loading