Skip to content

Commit

Permalink
Fix RE3 MDF support, also apparently the last set of edits never got …
Browse files Browse the repository at this point in the history
…pushed?
  • Loading branch information
Silvris committed Aug 7, 2021
1 parent 2f71d76 commit 608235c
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 9 deletions.
2 changes: 1 addition & 1 deletion MDF-Manager/Classes/Material.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public TextureBinding ReadTextureBinding(BinaryReader br, MDFTypes type)
uint UTF16MMH3Hash = br.ReadUInt32();
uint ASCIIMMH3Hash = br.ReadUInt32();
Int64 FilePathOff = br.ReadInt64();
if(type >= MDFTypes.MHRise)
if(type >= MDFTypes.RE3)
{
Int64 Unkn0 = br.ReadInt64(); //value of 0 in most mdf, possible alignment?
}
Expand Down
6 changes: 6 additions & 0 deletions MDF-Manager/HelperFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,11 @@ public static float Clamp(float input, float min, float max)
}
}
}
public static void Swap<T>(IList<T> list, int indexA, int indexB)
{
T tmp = list[indexA];
list[indexA] = list[indexB];
list[indexB] = tmp;
}
}
}
10 changes: 10 additions & 0 deletions MDF-Manager/MDF-Manager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,20 @@
<UseWPF>true</UseWPF>
</PropertyGroup>

<ItemGroup>
<None Remove="Resources\downarrow.png" />
<None Remove="Resources\uparrow.png" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Dragablz" Version="0.0.3.223" />
<PackageReference Include="Extended.Wpf.Toolkit" Version="4.1.0" />
<PackageReference Include="murmurhash" Version="1.0.3" />
</ItemGroup>

<ItemGroup>
<Resource Include="Resources\downarrow.png" />
<Resource Include="Resources\uparrow.png" />
</ItemGroup>

</Project>
34 changes: 26 additions & 8 deletions MDF-Manager/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,31 @@
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ListBox x:Name="MatSelect" Grid.Column="0" SelectedIndex="0" Height="Auto" MinWidth="200" HorizontalAlignment="Stretch" Margin="40,10,10,10" ItemContainerStyle="{StaticResource ContextMatView}" ItemsSource="{Binding Path=Materials}">
<ListBox.ItemTemplate>
<DataTemplate>
<Label FontSize="12" Content="{Binding Name}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Grid Grid.Column="0" Margin="40,10,10,10" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.9*"/>
<ColumnDefinition Width="0.1*"/>
</Grid.ColumnDefinitions>
<ListBox x:Name="MatSelect" Grid.Column="0" SelectedIndex="0" Height="Auto" MinWidth="200" HorizontalAlignment="Stretch" ItemContainerStyle="{StaticResource ContextMatView}" ItemsSource="{Binding Path=Materials}">
<ListBox.ItemTemplate>
<DataTemplate>
<Label FontSize="12" Content="{Binding Name}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Grid Grid.Column="1" Margin="5,0,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Button DataContext="{Binding ElementName=MatSelect}" Grid.Row="0" Margin="0,5,0,0" Click="MoveMatUp">
<Image Source="Resources/uparrow.png"/>
</Button>
<Button DataContext="{Binding ElementName=MatSelect}" Grid.Row="1" Margin="0,5,0,0" Click="MoveMatDown">
<Image Source="Resources/downarrow.png"/>
</Button>
</Grid>
</Grid>
<ListBox x:Name="TextureView" Grid.Column="1" Height="Auto" SelectedIndex="0" MinWidth="200" HorizontalAlignment="Stretch" Margin="40,10,10,10" ItemsSource="{Binding ElementName=MatSelect, Path=SelectedItem.Textures}">
<ListBox.ItemTemplate>
<DataTemplate>
Expand Down Expand Up @@ -189,7 +207,7 @@
</Menu>
<TreeView x:Name="LibraryView" ItemsSource="{Binding lib.entries}" ItemTemplateSelector="{StaticResource LibSelector}" MouseMove="treeView_MouseMove" Grid.Column="0" Margin="10,60,10,10"/>
<Label Content="Library" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,30,10,10"/>
<StackPanel Grid.Column="0" Width="Auto" Height="20" VerticalAlignment="Top" Margin="57,31,3,0" Orientation="Horizontal">
<StackPanel Grid.Column="0" Width="Auto" Height="20" VerticalAlignment="Top" Margin="55,31,3,0" Orientation="Horizontal">
<Button Content="Add" Click="AddToLibrary" Width="60" Height="20" FontSize="10" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top"/>
<Button Content="Remove" Click="RemoveFromLibrary" Width="60" Height="20" FontSize="10" HorizontalAlignment="Left" Margin="5,0,0,0" VerticalAlignment="Top"/>
</StackPanel>
Expand Down
50 changes: 50 additions & 0 deletions MDF-Manager/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,56 @@ private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs
string jsontxt = JsonSerializer.Serialize(defs);
File.WriteAllText("defs.json",jsontxt);
}

private void MoveMatUp(object sender, RoutedEventArgs e)
{
Button send = sender as Button;
ListBox senderBox = send.DataContext as ListBox;
//this approach is weird but I'm surprised it works
if (senderBox != null)
{
Material senderMat = (Material)senderBox.SelectedItem;
if(senderMat != null)
{
int oldIndex = senderMat.materialIndex;
if (oldIndex > 0)
{
//obviously cannot go past first index
HelperFunctions.Swap(MDFs[MaterialView.SelectedIndex].Materials, oldIndex - 1, oldIndex);
senderBox.SelectedIndex = oldIndex - 1;
send.DataContext = senderBox;
}

}

}
UpdateMaterials();
}
private void MoveMatDown(object sender, RoutedEventArgs e)
{
Button send = sender as Button;
ListBox senderBox = send.DataContext as ListBox;
//this approach is weird but I'm surprised it works
if(senderBox != null)
{
Material senderMat = (Material)senderBox.SelectedItem;
if(senderMat != null)
{
int oldIndex = senderMat.materialIndex;
if (oldIndex < MDFs[MaterialView.SelectedIndex].Materials.Count - 1)
{
//obviously cannot go past last index
HelperFunctions.Swap(MDFs[MaterialView.SelectedIndex].Materials, oldIndex + 1, oldIndex);
senderBox.SelectedIndex = oldIndex + 1;
send.DataContext = senderBox;
}

}

}
UpdateMaterials();

}
}
public class PropertySelect : DataTemplateSelector
{
Expand Down
Binary file added MDF-Manager/Resources/downarrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MDF-Manager/Resources/uparrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 608235c

Please sign in to comment.